public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) {
    Object[] childImagePair = (Object[]) this.get(listField, index);
    Child child = (Child) childImagePair[0];
    Bitmap image = (Bitmap) childImagePair[1];

    drawStatusBox(listField, graphics, index, child);

    drawChildImage(graphics, listField, index, image);

    graphics.setColor(Color.BLACK);

    graphics.setFont(titleFont);

    // Takes 5 params 1:display text, 2:horizontal position,
    // 3: vertical position, 4: flags, 5: text display width
    graphics.drawText(
        (String) child.getField("name"),
        firstRowPosition,
        y,
        (DrawStyle.LEFT | DrawStyle.ELLIPSIS | DrawStyle.TOP),
        screenWidth - firstRowPosition - 4);

    int yStartForText = y + (this.getFont()).getHeight() + 1;
    drawFieldRow(graphics, width, child, yStartForText, "age");

    yStartForText = yStartForText + (this.getFont()).getHeight() + 1;
    drawFieldRow(
        graphics, width - secondRowPosition - 4, child, yStartForText, "last_known_location");

    yStartForText = yStartForText + (this.getFont()).getHeight() + 1;
    graphics.drawLine(
        0, (index * listField.getRowHeight()), width, (index * listField.getRowHeight()));
  }
Exemplo n.º 2
0
 /** Test of renderChildren method, of class Activity. */
 @Test
 public void testCreateChildren() throws Exception {
   System.out.println("renderChildren");
   // Setup
   ChildPane childPane = new ChildPane();
   childPane.setChild("Child");
   VBox vbox = VBoxBuilder.create().children(childPane).build();
   Parent parent = new Parent();
   parent.setScene(vbox);
   Data data = new Data();
   Map<Field, Object> fieldParams = new HashMap<Field, Object>();
   for (Field field : data.getClass().getDeclaredFields()) {
     field.setAccessible(true);
     fieldParams.put(field, field.get(data));
   }
   RenderParameter renderParam = new RenderParameter();
   String id = renderParam.putParam("checkForLabel", "CheckForLabel");
   childPane.setId(id);
   parent.createChildren(fieldParams, renderParam, ValidationResult.getEmptyResult());
   // Assertoin
   Child child = (Child) parent.getChildActivities(Child.class).get(0);
   assertNotNull(child);
   assertNotNull(child.getScene());
   assertEquals(childPane, child.getScene());
   assertEquals(parent, child.getParent());
   VBox cvbox = (VBox) child.getScene().getChildren().get(0);
   assertTrue(cvbox.getChildren().get(0) instanceof Button);
   assertTrue(cvbox.getChildren().get(1) instanceof Label);
   assertEquals(data.checkForButton, ((Button) cvbox.getChildren().get(0)).getText());
   assertEquals("CheckForLabel", ((Label) cvbox.getChildren().get(1)).getText());
 }
Exemplo n.º 3
0
  @Test
  public void shouldReturnShortID() throws JSONException {
    Child child = new Child();
    child.setUniqueId("987654321");

    assertThat(child.getShortId(), equalTo("7654321"));
  }
  @Test
  public void testFail() {
    MapperFactory factory = new DefaultMapperFactory.Builder().build();

    factory.registerClassMap(
        factory
            .classMap(Base.class, BaseDto.class)
            .customize(
                new CustomMapper<Base, BaseDto>() {
                  @Override
                  public void mapAtoB(Base base, BaseDto baseDto, MappingContext context) {
                    baseDto.setBaseField(base.getBaseTrickField());
                  }
                })
            .toClassMap());
    factory.registerClassMap(
        factory.classMap(Child.class, ChildDto.class).byDefault().toClassMap());

    Child child = new Child();
    child.setChildField("CHILD FIELD");
    child.setBaseTrickField("BASE FIELD");

    ChildDto dto = factory.getMapperFacade(Child.class, ChildDto.class).map(child);

    Assert.assertNotNull(dto);
    Assert.assertEquals(child.getChildField(), dto.getChildField());
    Assert.assertEquals(child.getBaseTrickField(), dto.getBaseField());
  }
Exemplo n.º 5
0
 @Test
 public void shouldDecodeArrayOfStrings() throws JSONException {
   Child child = new Child("{ 'test1' : ['value1', 'value2', 'value3' ]}");
   assertThat(
       child.getJSONArray("test1").toString(),
       is(new JSONArray(Arrays.asList("value1", "value2", "value3")).toString()));
 }
Exemplo n.º 6
0
  /* (non-Javadoc)
   * @see org.fireflow.pvm.pdllogic.WorkflowBehavior#execute(org.fireflow.engine.WorkflowSession, org.fireflow.pvm.kernel.Token, java.lang.Object)
   */
  public ExecuteResult execute(WorkflowSession session, Token token, Object workflowElement) {
    if (this.getChildren() == null || this.getChildren().size() == 0) {
      ExecuteResult result = new ExecuteResult();
      result.setStatus(BusinessStatus.COMPLETED);
      return result;
    }

    RuntimeContext ctx = ((WorkflowSessionLocalImpl) session).getRuntimeContext();
    KernelManager kernelManager = ctx.getDefaultEngineModule(KernelManager.class);

    List<Token> closedChildTokens = kernelManager.getChildren(token);
    boolean isRunning = false;
    for (Child child : this.getChildren()) {
      if (!this.hasBeenExecuted(child.getChildBpelActivity(), closedChildTokens)) {
        isRunning = true;
        this.executeChildActivity(session, token, child.getChildBpelActivity());
        break;
      }
    }
    if (isRunning) {
      ExecuteResult result = new ExecuteResult();
      result.setStatus(BusinessStatus.RUNNING);
      return result;
    } else {
      ExecuteResult result = new ExecuteResult();
      result.setStatus(BusinessStatus.COMPLETED);
      return result;
    }
  }
Exemplo n.º 7
0
 public void testManyToOneGeneratedIds() {
   // NOTES: Child defines a many-to-one back to its Parent.  This
   // association does not define persist cascading (which is natural;
   // a child should not be able to create its parent).
   try {
     Session s = openSession();
     s.beginTransaction();
     Parent p = new Parent("parent");
     Child c = new Child("child");
     c.setParent(p);
     s.persist(c);
     try {
       s.getTransaction().commit();
       fail("expecting TransientObjectException on flush");
     } catch (TransientObjectException e) {
       // expected result
       log.trace("handled expected exception", e);
       s.getTransaction().rollback();
     } finally {
       s.close();
     }
   } finally {
     cleanupData();
   }
 }
Exemplo n.º 8
0
 @Test
 public void shouldGenerateWithIdAndOwnerAndContent() throws JSONException {
   Child child = new Child("id1", "owner1", "{ 'test1' : 'value1' }");
   assertThat(child.getUniqueId(), is("id1"));
   assertThat(child.getOwner(), is("owner1"));
   assertThat(child.getString("test1"), is("value1"));
 }
  @Test
  @SuppressWarnings({"unchecked"})
  public void testIterateWithEvictBottomOfLoop() {
    Session s = openSession();
    s.beginTransaction();
    Set parents = new HashSet();
    for (int i = 0; i < 5; i++) {
      Parent p = new Parent(String.valueOf(i + 100));
      Child child = new Child("child" + i);
      child.setParent(p);
      p.getChildren().add(child);
      s.save(p);
      parents.add(p);
    }
    s.getTransaction().commit();
    s.close();

    s = openSession();
    s.beginTransaction();
    for (Iterator it = s.createQuery("from Parent").iterate(); it.hasNext(); ) {
      Parent p = (Parent) it.next();
      assertEquals(1, p.getChildren().size());
      s.evict(p);
    }
    s.getTransaction().commit();
    s.close();

    s = openSession();
    s.beginTransaction();
    for (Object parent : parents) {
      s.delete(parent);
    }
    s.getTransaction().commit();
    s.close();
  }
Exemplo n.º 10
0
 @Test
 public void shouldNotOverwriteCreatedAtIfGiven() throws JSONException {
   Child child =
       new Child(
           String.format(
               "{ 'created_at' :  '%s' }", new RapidFtrDateTime(10, 2, 2012).defaultFormat()));
   assertThat(child.getCreatedAt(), is("2012-02-10 00:00:00"));
 }
Exemplo n.º 11
0
  @Test
  public void shouldRemoveFieldIfBlank() throws JSONException {
    Child child = new Child();
    child.put("name", "test");
    assertThat(child.values().names().length(), equalTo(1));

    child.put("name", "\r  \n  \r  \n");
    assertNull(child.values().names());
  }
Exemplo n.º 12
0
  @Test
  public void shouldRemoveFieldIfJSONArrayIsEmtpy() throws JSONException {
    Child child = new Child();
    child.put("name", new JSONArray(Arrays.asList("one")));
    assertThat(child.values().names().length(), equalTo(1));

    child.put("name", new JSONArray());
    assertNull(child.values().names());
  }
Exemplo n.º 13
0
 /**
  * Copy constructor, used to get a deep copy of the passed instance
  *
  * @param source the instance to copy
  */
 public Dom(Dom source, Dom parent) {
   this(source.getHabitat(), source.document, parent, source.model);
   List<Child> newChildren = new ArrayList<Child>();
   for (Child child : source.children) {
     newChildren.add(child.deepCopy(this));
   }
   setChildren(newChildren);
   attributes.putAll(source.attributes);
 }
Exemplo n.º 14
0
  @Test
  public void testBackRef() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Parent p = new Parent("Marc");
    Parent p2 = new Parent("Nathalie");
    Child c = new Child("Elvira");
    Child c2 = new Child("Blase");
    p.getChildren().add(c);
    p.getChildren().add(c2);
    s.persist(p);
    s.persist(p2);
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    c = (Child) s.get(Child.class, "Elvira");
    c.setAge(2);
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    p = (Parent) s.get(Parent.class, "Marc");
    c = (Child) s.get(Child.class, "Elvira");
    c.setAge(18);
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    p = (Parent) s.get(Parent.class, "Marc");
    p2 = (Parent) s.get(Parent.class, "Nathalie");
    c = (Child) s.get(Child.class, "Elvira");
    assertEquals(p.getChildren().indexOf(c), 0);
    p.getChildren().remove(c);
    p2.getChildren().add(c);
    t.commit();

    s.close();
    s = openSession();
    t = s.beginTransaction();
    Parent p3 = new Parent("Marion");
    p3.getChildren().add(new Child("Gavin"));
    s.merge(p3);
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    s.createQuery("delete from Child").executeUpdate();
    s.createQuery("delete from Parent").executeUpdate();
    t.commit();
    s.close();
  }
Exemplo n.º 15
0
  @Test
  public void valuesShouldReturnAllExceptSystemFields() throws JSONException, IOException {
    Child child = new Child();
    child.put("test1", "value1");
    for (Database.ChildTableColumn column : Database.ChildTableColumn.systemFields()) {
      child.put(column.getColumnName(), "test");
    }

    assertThat(child.values(), equalJSONIgnoreOrder("{\"test1\":\"value1\"}"));
  }
Exemplo n.º 16
0
  @Test
  public void shouldGenerateUniqueId() throws JSONException {
    Child child = new Child(null, "rapidftr", null);
    child = spy(child);

    doReturn("xyz").when(child).createUniqueId();

    child.generateUniqueId();
    assertThat(child.getUniqueId(), equalTo("xyz"));
  }
Exemplo n.º 17
0
  @Test
  public void shouldRemoveFieldIfNull() throws JSONException {
    Child child = new Child();
    child.put("name", "test");

    assertEquals(child.get("name"), "test");

    Object value = null;
    child.put("name", value);
    assertNull(child.opt("name"));
  }
Exemplo n.º 18
0
  /**
   * Test method.
   *
   * @throws Exception For any exception thrown.
   */
  public void testLoadChild() throws Exception {
    Database db = _category.getDatabase();
    db.begin();

    Child child = (Child) db.load(Child.class, new Integer(1));

    assertNotNull(child);
    assertEquals(new Integer(1), child.getId());

    db.commit();
    db.close();
  }
Exemplo n.º 19
0
Arquivo: test.java Projeto: tbian7/pst
  public static void main(String[] args) {
    //		Base ins = new Child();
    //		ins.methodA();
    //		Base ins = new Child();
    //		ins.callPrivateFinal();

    Child ins = new Child();
    ins.publicStaticMethod();

    //		MyBaseInterface ins = new ImplClass();
    //		ins.callmela();
  }
  public Object getControlObject() {
    Root root = new Root();

    XMLRoot xmlroot = new XMLRoot();
    Child child = new Child();
    child.setContent("child's text");
    xmlroot.setObject(child);
    xmlroot.setLocalName("myns:someChild");
    xmlroot.setNamespaceURI("www.example.com/some-dir/some.xsd");

    root.setAny(xmlroot);
    return root;
  }
 public Object getControlObject() {
   Root root = new Root();
   Vector any = new Vector();
   Child child = new Child();
   child.setContent("Child1");
   any.addElement(child);
   any.addElement("Root Text!!");
   child = new Child();
   child.setContent("Child2");
   any.addElement(child);
   any.addElement("More Text!!");
   root.setAny(any);
   return root;
 }
Exemplo n.º 22
0
  public void shouldReturnListOfChangeLogsBasedOnChanges() throws JSONException {
    Child oldChild = new Child("id", "user", "{'name' : 'old-name'}");
    Child updatedChild = new Child("id", "user", "{'name' : 'updated-name'}");
    List<Child.History> histories = updatedChild.changeLogs(oldChild);

    JSONObject changesMap = (JSONObject) histories.get(0).get(CHANGES);
    HashMap fromTo = (HashMap) changesMap.get("name");

    assertThat(histories.size(), is(1));
    assertThat(histories.get(0).get(USER_NAME).toString(), is(updatedChild.getOwner()));
    assertThat(changesMap.names().get(0).toString(), is("name"));
    assertThat(fromTo.get(FROM).toString(), is("old-name"));
    assertThat(fromTo.get(TO).toString(), is("updated-name"));
  }
Exemplo n.º 23
0
  @Test
  @Priority(10)
  public void initData() {
    // Revision 1 - Create indexed entries.
    TransactionUtil.doInJPA(
        this::entityManagerFactory,
        entityManager -> {
          Parent p = new Parent(1);
          p.addChild(new Child(1, "child1"));
          p.addChild(new Child(2, "child2"));
          entityManager.persist(p);
          p.getChildren().forEach(entityManager::persist);
        });

    // Revision 2 - remove an indexed entry, resetting positions.
    TransactionUtil.doInJPA(
        this::entityManagerFactory,
        entityManager -> {
          final Parent p = entityManager.find(Parent.class, 1);
          // should remove child with id 1
          p.removeChild(p.getChildren().get(0));
          entityManager.merge(p);
        });

    // Revision 3 - add new indexed entity to reset positions
    TransactionUtil.doInJPA(
        this::entityManagerFactory,
        entityManager -> {
          final Parent p = entityManager.find(Parent.class, 1);
          // add child with id 3
          final Child child = new Child(3, "child3");
          p.getChildren().add(0, child);
          child.getParents().add(p);
          entityManager.persist(child);
          entityManager.merge(p);
        });

    // Revision 4 - remove all children
    TransactionUtil.doInJPA(
        this::entityManagerFactory,
        entityManager -> {
          final Parent p = entityManager.find(Parent.class, 1);
          while (!p.getChildren().isEmpty()) {
            Child child = p.getChildren().get(0);
            p.removeChild(child);
            entityManager.remove(child);
          }
          entityManager.merge(p);
        });
  }
  @Test
  @TestForIssue(jiraKey = "HHH-11179")
  public void testNonExistentLazyInitOutsideTransaction() {
    Session s = openSession();
    s.beginTransaction();
    Child loadedChild = s.load(Child.class, -1L);
    s.getTransaction().commit();
    s.close();

    try {
      loadedChild.getParent();
      fail("lazy init did not fail on non-existent proxy");
    } catch (LazyInitializationException e) {
      assertNotNull(e.getMessage());
    }
  }
Exemplo n.º 25
0
 public void addToStepSibling(Child stepSibling) {
   if (stepSibling != null && !this.getStepSibling().contains(stepSibling)) {
     SiblingStepSibling newLink = new SiblingStepSibling((StepChild) this, (Child) stepSibling);
     this.z_internalAddToSiblingStepSibling_stepSibling(newLink);
     stepSibling.z_internalAddToSiblingStepSibling_stepSibling(newLink);
   }
 }
Exemplo n.º 26
0
  public HomeFolderType modelToXml() {

    HomeFolderType homeFolderType = HomeFolderType.Factory.newInstance();
    if (this.id != null) homeFolderType.setId(this.id.longValue());
    if (this.adress != null) homeFolderType.setAddress(Address.modelToXml(this.adress));

    IndividualType[] individualsArray = new IndividualType[individuals.size()];
    int i = 0;
    for (Individual individual : individuals) {
      if (individual instanceof Adult) {
        Adult adult = (Adult) individual;
        individualsArray[i] = Adult.modelToXml(adult);
      } else if (individual instanceof Child) {
        Child child = (Child) individual;
        individualsArray[i] = Child.modelToXml(child);
      }
      i++;
    }
    homeFolderType.setIndividualsArray(individualsArray);

    if (this.state != null)
      homeFolderType.setState(
          fr.cg95.cvq.xml.common.ActorStateType.Enum.forString(this.state.toString()));
    if (this.familyQuotient != null) homeFolderType.setFamilyQuotient(this.familyQuotient);

    return homeFolderType;
  }
Exemplo n.º 27
0
 public void removeFromStepSibling(Child stepSibling) {
   if (stepSibling != null) {
     SiblingStepSibling oldLink = getSiblingStepSibling_stepSiblingFor(stepSibling);
     if (oldLink != null) {
       stepSibling.z_internalRemoveFromSiblingStepSibling_stepSibling(oldLink);
       oldLink.clear();
       z_internalRemoveFromSiblingStepSibling_stepSibling(oldLink);
     }
   }
 }
 private void drawFieldRow(
     Graphics graphics, int width, Child child, int yStartForText, String field) {
   graphics.setFont(rowFont);
   graphics.drawText(
       (String) child.getField(field),
       secondRowPosition,
       yStartForText,
       (DrawStyle.LEFT | DrawStyle.ELLIPSIS | DrawStyle.TOP),
       width);
 }
Exemplo n.º 29
0
  /** 类转型异常处理(ClassCastException) */
  public static void main(String[] args) {

    Father f = new Father();
    Child c = null;
    try {

      c = (Child) f; // 不安全的向下转型
      return;

    } catch (Exception e) {

      e.printStackTrace();
      c = new Child();
    } finally {

      System.out.println("这是作业2-2(try 内含有return)的finally");
    }

    c.print();
    System.out.println("over");
  }
  private void drawStatusBox(ListField listField, Graphics graphics, int index, Child child) {

    String childStatusString = child.childStatus().getStatusString();
    int boxHeight = getFont().getHeight() + 4;
    int boxWidth = getFont().getAdvance(childStatusString) + 4;
    int boxX = screenWidth - 10 - boxWidth;
    int boxY = ((index) * listField.getRowHeight()) + getFont().getHeight() + 2;

    graphics.setColor(child.childStatus().getStatusColor());
    graphics.drawRoundRect(boxX, boxY, boxWidth, boxHeight, 10, 10);
    graphics.fillRoundRect(boxX, boxY, boxWidth, boxHeight, 10, 10);

    graphics.setColor(16777215);
    graphics.setFont(rowFont);
    graphics.drawText(
        childStatusString,
        boxX,
        boxY + 2,
        (DrawStyle.HCENTER | DrawStyle.ELLIPSIS | DrawStyle.TOP),
        boxWidth);
  }