Exemple #1
0
 /**
  * Validate if the freeTextGraphNode is valid for actions that relates to Free Text graph nodes.
  *
  * @param freeTextGraphNode the freeTextGraphNode to validate
  * @throws IllegalArgumentException If freeTextGraphNode is null, or the freeTextGraphNode doesn't
  *     contain a semanticModel attribute (<code>SimpleSemanticModelElement</code> object) with
  *     typeInfo attribute equal to "FreeText", or it doesn't contain a <code>TextElement</code>
  *     object in its contained attribute.
  */
 static void validateGraphNodeForFreeTextAction(GraphNode freeTextGraphNode) {
   if (freeTextGraphNode == null) {
     throw new IllegalArgumentException("freeTextGraphNode cannot be null!");
   }
   // Validate the SemanticModel
   SemanticModelBridge smb = freeTextGraphNode.getSemanticModel();
   if (!(smb instanceof SimpleSemanticModelElement)) {
     throw new IllegalArgumentException(
         "SemanticModel of the freeTextGraphNode should be SimpleSemanticModelElement!");
   }
   SimpleSemanticModelElement ssme = (SimpleSemanticModelElement) smb;
   if (!FREE_TEXT.equals(ssme.getTypeInfo())) {
     throw new IllegalArgumentException(
         "typeInfo of freeTextGraphNode's SemanticModel should be '" + FREE_TEXT + "'!");
   }
   // Validate if the freeTextGraphNode contains a TextElement
   boolean valid = false;
   for (DiagramElement de : freeTextGraphNode.getContaineds()) {
     if (de instanceof TextElement) {
       valid = true;
       break;
     }
   }
   if (!valid) {
     throw new IllegalArgumentException("freeTextGraphNode should contain a TextElement!");
   }
 }
  /**
   * Basic stress test of <code>notifyGraphNodeChange()</code> method.
   *
   * @throws Exception if if any exception occurs when testing.
   */
  public void testUseCaseNode_notifyGraphNodeChange_AbsolutePosition() throws Exception {
    GraphNode dv = new GraphNode();
    dv.setPosition(StressTestHelper.createPoint(0, 0));
    GraphNode ssNode = StressTestHelper.getGraphNode(1);
    ssNode.setSize(StressTestHelper.createDimension(400, 800));
    ssNode.setPosition(StressTestHelper.createPoint(100, 200));
    ssNode.setContainer(dv);
    graphNode.setContainer(ssNode);
    ssNode.addContained(graphNode);

    // create a use case node here.
    node = new UseCaseNode(graphNode, properties);

    // change the node and test it.
    for (int i = 0; i < LOOPTIMES; i++) {
      int width = 40 + i;
      int height = 80 + i;
      graphNode.setSize(StressTestHelper.createDimension(width, height));

      int x = 10 + i;
      int y = 20 + i;
      graphNode.setPosition(StressTestHelper.createPoint(x, y));

      // notify the node change here.
      node.notifyGraphNodeChange("node changed.");

      // check the Node here.

      // get the location to test.
      assertEquals("The notifyGraphNodeChange method is incorrect.", 105 + i, node.getLocation().x);
      assertEquals("The notifyGraphNodeChange method is incorrect.", 215 + i, node.getLocation().y);
    }
  }
 /**
  * Test constructor <code>PasteCommentGraphNodeAction(Object content, GraphNode diagram)</code>
  * for failure with invalid commentGraphNode that contains illegal semantic
  * model(non-Uml1SemanticModelBridge), <code>IllegalArgumentException</code> is expected.
  */
 public void testCtor_CommentGraphNodeWithIllegalSemanticModel1() {
   GraphNode node = new GraphNode();
   node.setSemanticModel(new SimpleSemanticModelElement());
   try {
     new PasteCommentGraphNodeAction(node, this.diagram);
     fail("IllegalArgumentException is expected!");
   } catch (IllegalArgumentException e) {
     // expected
   }
 }
 /**
  * Test constructor <code>AddFreeTextAction(GraphNode freeTextGraphNode, GraphNode diagram,
  * UMLModelManager modelManager)</code> for failure with freeTextGraphNode which has no semantic
  * model, <code>IllegalArgumentException</code> is expected.
  */
 public void testCtor_FreeTextGraphNodeWithoutSemanticModel() {
   GraphNode node = new GraphNode();
   node.addContained(new TextElement());
   try {
     new AddFreeTextAction(node, this.diagram, this.manager);
     fail("IllegalArgumentException is expected!");
   } catch (IllegalArgumentException e) {
     // expected
   }
 }
 /**
  * Test constructor <code>PasteCommentGraphNodeAction(Object content, GraphNode diagram)</code>
  * for failure with invalid commentGraphNode that contains illegal semantic model(without Comment
  * element), <code>IllegalArgumentException</code> is expected.
  */
 public void testCtor_CommentGraphNodeWithIllegalSemanticModel2() {
   GraphNode node = new GraphNode();
   Uml1SemanticModelBridge usmb = new Uml1SemanticModelBridge();
   node.setSemanticModel(usmb);
   try {
     new PasteCommentGraphNodeAction(node, this.diagram);
     fail("IllegalArgumentException is expected!");
   } catch (IllegalArgumentException e) {
     // expected
   }
 }
 /**
  * Test constructor <code>AddFreeTextAction(GraphNode freeTextGraphNode, GraphNode diagram,
  * UMLModelManager modelManager)</code> for failure with freeTextGraphNode has no TextElement,
  * <code>IllegalArgumentException</code> is expected.
  */
 public void testCtor_FreeTextGraphNodeWithoutTextElement() {
   GraphNode node = new GraphNode();
   SimpleSemanticModelElement ssme = new SimpleSemanticModelElement();
   ssme.setTypeInfo("FreeText");
   node.setSemanticModel(ssme);
   try {
     new AddFreeTextAction(node, this.diagram, this.manager);
     fail("IllegalArgumentException is expected!");
   } catch (IllegalArgumentException e) {
     // expected
   }
 }
 /**
  * Tests constructor CutFreeTextAction(freeTextGraphNode, clipboard) if freeTextGraphNode contains
  * a semanticModel attribute, but not SimpleSemanticModelElement object. IllegalArgumentException
  * is expected.
  */
 public void testCtorIfFreeTextNodeContainInvalidSemanticModelAttribute() {
   try {
     freeTextGraphNode.addContained(new TextElement());
     freeTextGraphNode.setSemanticModel(new Uml1SemanticModelBridge());
     new CutFreeTextAction(freeTextGraphNode, null);
     fail(
         "IllegalArgumentException is expected because freeTextGraphNode contains invalid semanticModel"
             + "attribute (non-SimpleSemanticModelElement object).");
   } catch (IllegalArgumentException e) {
     // success
   }
 }
  /**
   * Test method <code>GraphElement extractStereotype() </code>.
   *
   * <p>Mainly check the size of the stereotype node.
   *
   * @throws Exception to junit.
   */
  public void testExtractStereotype() throws Exception {
    GraphEdge root = HelperUtil.createGraphEdgeInstance();

    extractor = new DefaultEdgeCompartmentExtractor(root);

    GraphNode back = (GraphNode) extractor.extractStereotype();

    Dimension d = back.getSize();

    assertTrue("The height should be 100.", d.getHeight() == 100);
    assertTrue("The width should be 1000.", d.getWidth() == 1000);
  }
 /**
  * Setup test environment.
  *
  * @throws Exception to JUnit
  */
 protected void setUp() throws Exception {
   TestHelper.loadXMLConfig(TestHelper.CONFIG_FILE);
   mapping = new PropertyMapping(VALID_NAMESPACE);
   graphNode = new GraphNode();
   usmb = new Uml1SemanticModelBridge();
   usmb.setElement(new CommentImpl());
   graphNode.setSemanticModel(usmb);
   graphNode.setPosition(new com.topcoder.diagraminterchange.Point());
   graphNode.setSize(new com.topcoder.diagraminterchange.Dimension());
   node = new CommentNode(graphNode, mapping);
   connector = new CommentConnector(node);
 }
 /**
  * Tests method copyToClipboard(node, clipboard) if node is null. IllegalArgumentException is
  * expected
  *
  * @throws Exception exception
  */
 public void testCopyToClipboardIfNodeNull() throws Exception {
   SimpleSemanticModelElement semanticModelBridge = new SimpleSemanticModelElement();
   semanticModelBridge.setTypeInfo("FreeText");
   freeTextGraphNode.setSemanticModel(semanticModelBridge);
   freeTextGraphNode.addContained(new TextElement());
   CutFreeTextActionExt cutFreeTextAction = new CutFreeTextActionExt(freeTextGraphNode, null);
   try {
     cutFreeTextAction.copyToClipboard(null, null);
     fail("IllegalArgumentException is expected because node cannot be null.");
   } catch (IllegalArgumentException e) {
     // success
   }
 }
  /** Helper method use to add some textField to the edge. */
  public void addTextFieldToEdge() {
    graphNode1 = new GraphNode();
    graphNode1.setContainer(graphEdge);
    graphNode1.setPosition(TestHelper.getWaypoint(25, 13));

    textField1 = test.addTextField(graphNode1, text, AnchorType.LeftEnding);

    graphNode2 = new GraphNode();
    graphNode2.setContainer(graphEdge);
    graphNode2.setPosition(TestHelper.getWaypoint(12, 13));

    // the anchorage will be set to (12, 10).
    textField2 = test.addTextField(graphNode2, text, AnchorType.Line);

    graphNode3 = new GraphNode();
    graphNode3.setContainer(graphEdge);
    graphNode3.setPosition(TestHelper.getWaypoint(8, 6));

    // the anchorage will be set to (7, 7).
    textField3 = test.addTextField(graphNode3, text, AnchorType.Line);

    graphNode4 = new GraphNode();
    graphNode4.setContainer(graphEdge);
    graphNode4.setPosition(TestHelper.getWaypoint(5, 7));

    textField4 = test.addTextField(graphNode4, text, AnchorType.RightEnding);
  }
 /**
  * Tests constructor CutFreeTextAction(freeTextGraphNode, clipboard) if freeTextGraphNode contains
  * a semanticModel attribute (SimpleSemanticModelElement object), but its typeInfo attribute is
  * not equal to "FreeText". IllegalArgumentException is expected.
  */
 public void testCtorITypeInfoInvalid() {
   try {
     freeTextGraphNode.addContained(new TextElement());
     SimpleSemanticModelElement semanticModelBridge = new SimpleSemanticModelElement();
     semanticModelBridge.setTypeInfo("invalid_type_info");
     freeTextGraphNode.setSemanticModel(semanticModelBridge);
     new CutFreeTextAction(freeTextGraphNode, null);
     fail(
         "IllegalArgumentException is expected because semanticModel's typeInfo is not equal "
             + "to 'FreeText'.");
   } catch (IllegalArgumentException e) {
     // success
   }
 }
  /** Accuracy Test of the <code>addTextField()</code> method. */
  public void testAddTextField_Line() {
    graphNode.setPosition(TestHelper.getWaypoint(12, 13));
    graphNode.setContainer(graphEdge);

    TextField textField = test.addTextField(graphNode, text, AnchorType.Line);
    // get the contained graphNode to check the constructor.
    assertEquals("The contained graphNode should be equals.", graphNode, textField.getGraphNode());

    // get the anchorage point.
    Point anchorage = textField.getAnchorage();
    //  get the position of the anchorage point to check the method.
    assertEquals("The anchorage point should be at (12, 10).", 12, anchorage.x);
    assertEquals("The anchorage point should be at (12, 10).", 10, anchorage.y);
  }
  /**
   * Set up environment.
   *
   * @throws Exception exception
   */
  public void setUp() throws Exception {
    Helper.clearNamespace();
    Helper.initNamespace();

    freeTextGraphNode = new GraphNode();
    freeTextGraphNode.setContainer(new GraphElement() {});
  }
  /**
   * Basic stress test of <code>notifyGraphNodeChange()</code> method.
   *
   * @throws Exception if if any exception occurs when testing.
   */
  public void testUseCaseNode_notifyGraphNodeChange_Text() throws Exception {
    for (int i = 0; i < LOOPTIMES; i++) {
      int width = 50 + i;
      int height = 30 + i;
      graphNode.setSize(StressTestHelper.createDimension(width, height));
      node = new UseCaseNode(graphNode, properties);

      //  notify the node change here.
      node.notifyGraphNodeChange("node changed.");

      // check the result here.
      assertEquals(
          "The UseCaseNode notifyGraphNodeChange method is incorrect.",
          "topcoderSoft",
          node.getNameCompartment().getText());
      assertEquals(
          "The UseCaseNode notifyGraphNodeChange method is incorrect.",
          "<<type1, type2>>",
          node.getStereotypeCompartment().getText());
      assertEquals(
          "The UseCaseNode notifyGraphNodeChange method is incorrect.",
          "com.topcoder.soft",
          node.getNamespaceCompartment().getText());
    }
  }
  /**
   * Test method <code>void updateName(GraphElement newElement) </code>.
   *
   * <p>In this test case, the logic is simple. First creat a valid GraphNode instance. Set the
   * visible to true (the default value should be false), and expected that the extractor graph
   * element has the visible value of true.
   *
   * <p>For update, an element with visible false is created and should be updated correctly.
   *
   * <p>Also the dimension size should be updated too.
   *
   * @throws Exception to junit.
   */
  public void testUpdateName() throws Exception {
    GraphEdge root = HelperUtil.createGraphEdgeInstance();

    extractor = new DefaultEdgeCompartmentExtractor(root);

    GraphNode back = (GraphNode) extractor.extractName();
    assertTrue("The visible should be true for this GraphElement.", back.isVisible());

    GraphNode node = new GraphNode();

    SimpleSemanticModelElement semanticModel = new SimpleSemanticModelElement();
    semanticModel.setTypeinfo(EnumUtil.NAME);

    node.setSemanticModel(semanticModel);

    Dimension dimension = new Dimension();
    dimension.setHeight(new Double(10));
    dimension.setWidth(new Double(100));

    node.setSize(dimension);

    // update the Name compartment.
    extractor.updateName(node);

    back = (GraphNode) extractor.extractName();

    assertFalse("The visible should be false as it is updated.", back.isVisible());

    // check the dimension size.

    Dimension d = back.getSize();

    assertTrue("The height should be 10.", d.getHeight() == 10);
    assertTrue("The width should be 100.", d.getWidth() == 100);
  }
  /** Creates the graph node for new node. */
  protected void createGraphNode() {
    graphNode = DeployHelper.createGraphNodeForClass(element, position, size);

    NodeContainer nodeContainer = getNodeContainer();
    if (nodeContainer != null) {
      GraphNode container = nodeContainer.getGraphNode();
      GraphNode bodyCompartment = (GraphNode) container.getContaineds().get(1);
      setAddDiagramElementAction(
          new AddDiagramElementAction(
              bodyCompartment, graphNode, modelManager.getProjectConfigurationManager()));
    } else {
      setAddDiagramElementAction(
          new AddDiagramElementAction(
              getDiagramView().getDiagram(),
              graphNode,
              modelManager.getProjectConfigurationManager()));
    }
  }
 /**
  * Tests constructor CutFreeTextAction(freeTextGraphNode, clipboard) if freeTextGraphNode doesn't
  * contain a semanticModel attribute (SimpleSemanticModelElement object). IllegalArgumentException
  * is expected.
  */
 public void testCtorIfFreeTextNodeNotContainSemanticModelAttribute() {
   try {
     freeTextGraphNode.addContained(new TextElement());
     new CutFreeTextAction(freeTextGraphNode, null);
     fail(
         "IllegalArgumentException is expected because freeTextGraphNode doesn't contain a semanticModel"
             + "attribute (SimpleSemanticModelElement object).");
   } catch (IllegalArgumentException e) {
     // success
   }
 }
  /** Accuracy Test of the <code>addTextField()</code> method. */
  public void testAddTextField_RightEnding() {
    graphNode.setPosition(TestHelper.getWaypoint(5, 7));

    TextField textField = test.addTextField(graphNode, text, AnchorType.RightEnding);
    // get the contained graphNode to check the constructor.
    assertEquals("The contained graphNode should be equals.", graphNode, textField.getGraphNode());

    // get the anchorage point.
    Point anchorage = textField.getAnchorage();
    //  get the position of the anchorage point to check the method.
    assertEquals("The anchorage point should be at (30, 0).", 30, anchorage.x);
    assertEquals("The anchorage point should be at (0, 0).", 0, anchorage.y);
  }
 /**
  * Tests constructor CutFreeTextAction(freeTextGraphNode, clipboard) if freeTextGraphNode doesn't
  * contain a TextElement object in its contained attribute. IllegalArgumentException is expected.
  */
 public void testCtorIfFreeTextNotContainedTextElementObject() {
   try {
     SimpleSemanticModelElement semanticModelBridge = new SimpleSemanticModelElement();
     semanticModelBridge.setTypeInfo("FreeText");
     freeTextGraphNode.setSemanticModel(semanticModelBridge);
     new CutFreeTextAction(freeTextGraphNode, null);
     fail(
         "IllegalArgumentException is expected because freeTextGraphNode must contain a TextElement "
             + "object in its contained attribute.");
   } catch (IllegalArgumentException e) {
     // success
   }
 }
  /**
   * Basic stress test of <code>UseCaseNode</code>'s constructor.
   *
   * @throws Exception if if any exception occurs when testing.
   */
  public void testUseCaseNodeCtor_Times() throws Exception {
    for (int i = 0; i < LOOPTIMES; i++) {
      int width = 50 + i;
      int height = 30 + i;
      graphNode.setSize(StressTestHelper.createDimension(width, height));
      node = new UseCaseNode(graphNode, properties);

      // check the result here.
      assertNotNull("The UseCaseNode constructor is incorrect.", node);
      assertEquals(
          "The UseCaseNode constructor is incorrect.",
          nameNode,
          node.getNameCompartment().getGraphNode());
      assertEquals(
          "The UseCaseNode constructor is incorrect.",
          stereotypeNode,
          node.getStereotypeCompartment().getGraphNode());
      assertEquals(
          "The UseCaseNode constructor is incorrect.",
          namespaceNode,
          node.getNamespaceCompartment().getGraphNode());

      // check the compartment text here.
      assertEquals(
          "The UseCaseNode constructor is incorrect.",
          "topcoderSoft",
          node.getNameCompartment().getText());
      assertEquals(
          "The UseCaseNode constructor is incorrect.",
          "<<type1, type2>>",
          node.getStereotypeCompartment().getText());
      assertEquals(
          "The UseCaseNode constructor is incorrect.",
          "com.topcoder.soft",
          node.getNamespaceCompartment().getText());
    }
  }
  /**
   * Test method <code>void updateStereotype(GraphElement newElement) </code>.
   *
   * @throws Exception to junit.
   */
  public void testUpdateStereotype() throws Exception {

    GraphEdge root = HelperUtil.createGraphEdgeInstance();

    extractor = new DefaultEdgeCompartmentExtractor(root);

    GraphNode back = (GraphNode) extractor.extractStereotype();

    Dimension d = back.getSize();

    assertTrue("The height should be 100.", d.getHeight() == 100);
    assertTrue("The width should be 1000.", d.getWidth() == 1000);

    GraphNode node = new GraphNode();

    SimpleSemanticModelElement semanticModel = new SimpleSemanticModelElement();
    semanticModel.setTypeinfo(EnumUtil.STEREOTYPE_COMPARTMENT);

    node.setSemanticModel(semanticModel);

    Dimension dimension = new Dimension();
    dimension.setHeight(new Double(10));
    dimension.setWidth(new Double(100));

    node.setSize(dimension);

    // update the stereotype node.
    extractor.updateStereotype(node);

    back = (GraphNode) extractor.extractStereotype();

    d = back.getSize();

    assertTrue("The height should be 10.", d.getHeight() == 10);
    assertTrue("The width should be 100.", d.getWidth() == 100);
  }
  /**
   * Creates a new GraphNode instance for stereotype compartment to update.
   *
   * @return a new GraphNode instance for stereotype compartment to update.
   */
  private GraphNode getStereotypeNodeForUpdate() {
    GraphNode stereotypeNode = new GraphNode();
    stereotypeNode.setSemanticModel(TestHelper.createSimpleSemanticModel("StereotypeCompartment"));

    return stereotypeNode;
  }
  /**
   * Creates a new GraphNode instance for name compartment to update.
   *
   * @return a new GraphNode instance for name compartment to update.
   */
  private GraphNode getNameNodeForUpdate() {
    GraphNode nameNode = new GraphNode();
    nameNode.setSemanticModel(TestHelper.createSimpleSemanticModel("Name"));

    return nameNode;
  }
  /**
   * Creates a new GraphNode instance for association end compartment to update.
   *
   * @return a new GraphNode instance for association end compartment to update.
   */
  private GraphNode getAssociationEndNodeForUpdate() {
    GraphNode node = new GraphNode();
    node.setSemanticModel(TestHelper.createUmlSemanticModel(new AssociationEndImpl()));

    return node;
  }
  /** Set up the stress testing environment. */
  protected void setUp() {
    // create the properties map of BaseNode.
    properties = StressTestHelper.getProperties();

    // get the graphNode here.
    graphNode = StressTestHelper.getGraphNode(2);

    // create the structure of the Subsystem here.
    nameNode = new GraphNode();
    stereotypeNode = new GraphNode();
    namespaceNode = new GraphNode();

    // set the initializing size and position.
    nameNode.setPosition(StressTestHelper.createPoint(0, 0));
    nameNode.setSize(StressTestHelper.createDimension(10, 10));
    stereotypeNode.setPosition(StressTestHelper.createPoint(0, 0));
    stereotypeNode.setSize(StressTestHelper.createDimension(10, 10));
    namespaceNode.setPosition(StressTestHelper.createPoint(0, 0));
    namespaceNode.setSize(StressTestHelper.createDimension(10, 10));

    // create the NameCompartment here.
    GraphNode nameCompartment = new GraphNode();

    nameCompartment.addContained(stereotypeNode);
    nameCompartment.addContained(nameNode);
    nameCompartment.addContained(namespaceNode);

    graphNode.addContained(nameCompartment);
  }