コード例 #1
0
  /** Test getting children. */
  public void testGetChildren() {
    CoreFactory coreFactory = Model.getCoreFactory();
    // Create a generalizable element with an element without children.
    Object ge = coreFactory.createClass();

    assertTrue(Model.getCoreHelper().getChildren(ge).size() == 0);

    // Add one child.
    Object g1 = coreFactory.createGeneralization();
    Model.getCoreHelper().setParent(g1, ge);
    Model.getCoreHelper().setChild(g1, coreFactory.createClass());

    assertTrue(Model.getCoreHelper().getChildren(ge).size() == 1);

    // Add another child.
    Object g2 = coreFactory.createGeneralization();
    Model.getCoreHelper().setParent(g2, ge);
    Object ge2 = coreFactory.createClass();
    Model.getCoreHelper().setChild(g2, ge2);

    assertTrue(Model.getCoreHelper().getChildren(ge).size() == 2);

    // Add grandchild.
    Object g3 = coreFactory.createGeneralization();
    Model.getCoreHelper().setParent(g3, ge2);
    Model.getCoreHelper().setChild(g3, coreFactory.createClass());

    assertTrue(Model.getCoreHelper().getChildren(ge).size() == 3);
  }
コード例 #2
0
 /** Test subtype check. */
 public void testIsSubType() {
   assertTrue(
       "Is not a subtype",
       Model.getCoreHelper()
           .isSubType(Model.getMetaTypes().getClassifier(), Model.getMetaTypes().getUMLClass()));
   assertTrue(
       "Is not a parent type",
       !Model.getCoreHelper()
           .isSubType(Model.getMetaTypes().getUMLClass(), Model.getMetaTypes().getClassifier()));
   assertTrue(
       "Is not a parent type",
       !Model.getCoreHelper()
           .isSubType(
               Model.getMetaTypes().getUMLClass(), Model.getMetaTypes().getAggregationKind()));
 }
コード例 #3
0
 /** Test if adding a client to a binary dependency actually increases the client count. */
 public void testAddClient() {
   Object model = Model.getModelManagementFactory().createModel();
   Object class1 = Model.getCoreFactory().buildClass(model);
   Object class2 = Model.getCoreFactory().buildClass(model);
   Object dep = Model.getCoreFactory().buildDependency(class1, class2);
   Object class3 = Model.getCoreFactory().buildClass(model);
   Model.getCoreHelper().addClient(dep, class3);
   Collection clients = Model.getFacade().getClients(dep);
   assertEquals(2, Model.getFacade().getClients(dep).size());
   Iterator it = clients.iterator();
   assertEquals(class1, it.next());
   assertEquals(class3, it.next());
 }
コード例 #4
0
 /*
  * Populate our namespace hierarchy to the requested depth.  Total number
  * of created elements is children^maxLevel, so be careful not to increase
  * parameters too much.
  */
 private List createChildren(
     List children, Object parent, int currentLevel, int maxLevel, int numChildren) {
   currentLevel++;
   if (currentLevel > maxLevel) {
     return children;
   }
   Object child;
   for (int i = 0; i < numChildren; i++) {
     child = Model.getCoreFactory().buildClass("l" + currentLevel + "n" + i);
     children.add(child);
     Model.getCoreHelper().setNamespace(child, parent);
     createChildren(children, child, currentLevel, maxLevel, numChildren);
   }
   return children;
 }
コード例 #5
0
  /** Test the getFirstSharedNamespace method for correctness and, optionally, performance. */
  public void testGetFirstSharedNamespace() {
    Object model = Model.getModelManagementFactory().createModel();
    CoreFactory cf = Model.getCoreFactory();

    // Build namespace hierarchy like this:
    //   g     a
    //         /\
    //        b  c
    //           /\
    //          d  e f

    Object a = cf.buildClass("a", model);
    Object b = cf.buildClass("b", a);
    Object c = cf.buildClass("c", a);
    Object d = cf.buildClass("d", c);
    Object e = cf.buildClass("e", c);
    Object f = cf.buildClass("f", c);
    Object g = cf.buildClass();

    CoreHelper ch = Model.getCoreHelper();

    assertEquals("Got wrong namespace for first shared", a, ch.getFirstSharedNamespace(b, e));
    assertEquals("Got wrong namespace for first shared", c, ch.getFirstSharedNamespace(d, e));
    assertEquals("Got wrong namespace for first shared", a, ch.getFirstSharedNamespace(a, e));
    assertEquals("Got wrong namespace for first shared", a, ch.getFirstSharedNamespace(a, c));
    assertEquals("Got wrong namespace for first shared", a, ch.getFirstSharedNamespace(b, c));
    assertNull(
        "getFirstSharedNamespace didn't return null" + " when none shared",
        ch.getFirstSharedNamespace(g, a));

    // Try changing namespace of element and make sure results track
    assertEquals("Got wrong namespace for first shared", c, ch.getFirstSharedNamespace(d, f));
    ch.setNamespace(f, b);
    ch.setNamespace(g, f);
    assertEquals("Got wrong namespace after setNamespace", a, ch.getFirstSharedNamespace(d, f));
    assertEquals("Got wrong namespace after setNamespace", a, ch.getFirstSharedNamespace(g, e));

    if (PERFORMANCE_TEST) {
      List children = new ArrayList();
      Object root = cf.buildClass();
      children.add(root);
      createChildren(children, root, 0, NAMESPACE_LEVELS, CHILDREN_PER_NAMESPACE);
      // Tree is created depth first, so this should be at the bottom
      Object base = children.get(NAMESPACE_LEVELS);
      long startTime = System.currentTimeMillis();
      int i;
      for (i = 0; i < children.size(); i++) {
        Object o = ch.getFirstSharedNamespace(base, children.get(i));
        if (i % 100 == 0) {
          // Check periodically to see if we've exceeded time limit
          if ((System.currentTimeMillis() - startTime) > TIME_LIMIT) {
            break;
          }
        }
      }
      long endTime = System.currentTimeMillis();
      System.out.println(
          "Iterations: " + i + ", time: " + (endTime - startTime) / 1.0e3 + " seconds.");
      System.out.println(
          "Average time for getFirstSharedNameSpace = "
              + (endTime - startTime) * 1.0 / i
              + " millisecs searching in "
              + children.size()
              + " total elements.");
    }
  }