/**
   * 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);
  }
 /**
  * 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
  * non-SimpleSemanticModelElement semantic model, <code>IllegalArgumentException</code> is
  * expected.
  */
 public void testCtor_FreeTextGraphNodeWithIllegalSemanticModel1() {
   GraphNode node = new GraphNode();
   node.setSemanticModel(new Uml1SemanticModelBridge());
   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
   }
 }
 /**
  * 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);
 }
 /**
  * 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
   }
 }
 /**
  * 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
   }
 }
 /**
  * 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
   }
 }
 /**
  * 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
   }
 }
  /**
   * 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;
  }