/** * 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); }
/** * 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!"); } }
/** * Set up environment. * * @throws Exception to JUnit */ public void setUp() throws Exception { UnitTestHelper.loadConfig(UnitTestHelper.CONFIG_FILE); this.freeTextGraphNode = new GraphNode(); SimpleSemanticModelElement ssme = new SimpleSemanticModelElement(); ssme.setTypeInfo("FreeText"); this.freeTextGraphNode.setSemanticModel(ssme); this.freeTextGraphNode.addContained(new TextElement()); this.diagram = new Diagram(); this.manager = new UMLModelManager(); this.manager.setProjectConfigurationManager(new ProjectConfigurationManager(this.manager)); this.action = new AddFreeTextAction(this.freeTextGraphNode, this.diagram, this.manager); }
/** * 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 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); }