/** * Test deleting a package with a Class with a Activity diagram. The diagram should be deleted, * too. */ public void testDeletePackageWithClassWithActivityDiagram() { Project p = ProjectManager.getManager().getOpenProjects().get(0); assertEquals(2, p.getDiagramList().size()); int sizeMembers = p.getMembers().size(); int sizeDiagrams = p.getDiagramList().size(); // test with a package and a class and activity diagram Object package1 = Model.getModelManagementFactory().buildPackage("test1"); Object aClass = Model.getCoreFactory().buildClass(package1); // build the Activity Diagram Object actgrph = Model.getActivityGraphsFactory().buildActivityGraph(aClass); UMLActivityDiagram d = new UMLActivityDiagram(Model.getFacade().getNamespace(actgrph), actgrph); p.addMember(d); assertEquals(sizeDiagrams + 1, p.getDiagramList().size()); assertEquals(sizeMembers + 1, p.getMembers().size()); p.moveToTrash(package1); Model.getPump().flushModelEvents(); assertTrue("Class not in trash", Model.getUmlFactory().isRemoved(aClass)); assertTrue("ActivityGraph not in trash", Model.getUmlFactory().isRemoved(actgrph)); assertEquals(sizeDiagrams, p.getDiagramList().size()); assertEquals(sizeMembers, p.getMembers().size()); }
/** Test the moveToTrash function for package and content. */ public void testTrashcanPackageContent() { Project p = ProjectManager.getManager().getOpenProjects().get(0); // test with a class in a package Object package1 = Model.getModelManagementFactory().buildPackage("test1"); Model.getCoreHelper().setNamespace(package1, p.getRoot()); Object cls1 = Model.getCoreFactory().buildClass(package1); Object cls2 = Model.getCoreFactory().buildClass(package1); Object cls3 = Model.getCoreFactory().buildClass(package1); Object cls4 = Model.getCoreFactory().buildClass(p.getRoot()); Object c1 = Model.getFacade().getOwnedElements(p.getRoot()); assertTrue(c1 instanceof Collection); // Let's make it a bit more difficult by setting the target: TargetManager.getInstance().setTarget(cls2); p.moveToTrash(package1); Model.getPump().flushModelEvents(); // TODO: We should also test that the object // have been removed from their namespace. // Collection c = Model.getFacade().getOwnedElements(p.getRoot()); assertTrue("Package not in trash", p.isInTrash(package1)); assertTrue("Package not deleted", Model.getUmlFactory().isRemoved(package1)); assertTrue("Class 1 not deleted", Model.getUmlFactory().isRemoved(cls1)); assertTrue("Class 2 not deleted", Model.getUmlFactory().isRemoved(cls2)); assertTrue("Class 3 not deleted", Model.getUmlFactory().isRemoved(cls3)); assertTrue("Class 4 has been deleted", !Model.getUmlFactory().isRemoved(cls4)); }
/** * Test deleting a package with a package with a Activity diagram. The diagram should be deleted, * too. */ public void testDeletePackageWithPackageWithActivityDiagram() { Project p = ProjectManager.getManager().getCurrentProject(); assertEquals(2, p.getDiagrams().size()); int sizeMembers = p.getMembers().size(); int sizeDiagrams = p.getDiagrams().size(); // test with a package and a class and activity diagram Object package1 = Model.getModelManagementFactory().buildPackage("test1", null); Model.getCoreHelper().setNamespace(package1, p.getModel()); Object package2 = Model.getModelManagementFactory().buildPackage("test2", null); Model.getCoreHelper().setNamespace(package2, package1); // build the Activity Diagram Object actgrph = Model.getActivityGraphsFactory().buildActivityGraph(package2); UMLActivityDiagram d = new UMLActivityDiagram(Model.getFacade().getNamespace(actgrph), actgrph); p.addMember(d); assertEquals(sizeDiagrams + 1, p.getDiagrams().size()); assertEquals(sizeMembers + 1, p.getMembers().size()); p.moveToTrash(package1); assertTrue("Package 2 not in trash", Model.getUmlFactory().isRemoved(package2)); assertTrue("ActivityGraph not in trash", Model.getUmlFactory().isRemoved(actgrph)); assertEquals(sizeDiagrams, p.getDiagrams().size()); assertEquals(sizeMembers, p.getMembers().size()); }
/** * Test deleting a package that contains a Class with Statechart diagram. The diagram should be * deleted, too. */ public void testDeletePackageWithStateDiagram() { Project p = ProjectManager.getManager().getOpenProjects().get(0); assertEquals(2, p.getDiagramList().size()); int sizeMembers = p.getMembers().size(); int sizeDiagrams = p.getDiagramList().size(); // test with a class and class diagram Object package1 = Model.getModelManagementFactory().buildPackage("test1"); Object aClass = Model.getCoreFactory().buildClass(package1); // try with Statediagram Object machine = Model.getStateMachinesFactory().buildStateMachine(aClass); UMLStateDiagram d = new UMLStateDiagram(Model.getFacade().getNamespace(machine), machine); p.addMember(d); assertEquals(sizeDiagrams + 1, p.getDiagramList().size()); assertEquals(sizeMembers + 1, p.getMembers().size()); p.moveToTrash(package1); Model.getPump().flushModelEvents(); assertTrue("Class not in trash", Model.getUmlFactory().isRemoved(aClass)); assertTrue("Statemachine not in trash", Model.getUmlFactory().isRemoved(machine)); assertEquals(sizeDiagrams, p.getDiagramList().size()); assertEquals(sizeMembers, p.getMembers().size()); }
/** * Test the creation of a profile which depends on another profile. Doesn't use the {@link * ProfileMother#createXmiDependentProfile(File, ProfileMother.DependencyCreator, File, String)} * method, but, it serves as good executable documentation of how this is done as a whole. * * @throws IOException When saving the profile models fails. * @throws UmlException When something in the model subsystem goes wrong. */ public void testXmiDependentProfile() throws IOException, UmlException { Object model = mother.createSimpleProfileModel(); File file = File.createTempFile("simple-profile", ".xmi"); mother.saveProfileModel(model, file); XmiReader xmiReader = Model.getXmiReader(); xmiReader.addSearchPath(file.getParent()); InputSource pIs = new InputSource(file.toURI().toURL().toExternalForm()); pIs.setPublicId(file.getName()); Collection simpleModelTopElements = xmiReader.parse(pIs, true); Object model2 = mother.createSimpleProfileModel(); Object theClass = Model.getCoreFactory().buildClass("TheClass", model2); Collection stereotypes = getFacade().getStereotypes(simpleModelTopElements.iterator().next()); Object stereotype = stereotypes.iterator().next(); Model.getCoreHelper().addStereotype(theClass, stereotype); File dependentProfileFile = File.createTempFile("dependent-profile", ".xmi"); mother.saveProfileModel(model2, dependentProfileFile); assertTrue( "The file to where the file was supposed to be saved " + "doesn't exist.", dependentProfileFile.exists()); assertStringInLineOfFile( "The name of the file which contains the profile " + "from which the dependent profile depends must occur in the " + "file.", file.getName(), dependentProfileFile); // Clean up our two models and the extent that we read profile in to Model.getUmlFactory().delete(model); Model.getUmlFactory().delete(model2); Model.getUmlFactory().deleteExtent(simpleModelTopElements.iterator().next()); }
/* * @see junit.framework.TestCase#tearDown() */ @Override protected void tearDown() throws Exception { super.tearDown(); Model.getUmlFactory().delete(elem); Model.getUmlFactory().delete(ns); model = null; }
/* * @see junit.framework.TestCase#tearDown() */ @Override protected void tearDown() throws Exception { super.tearDown(); Model.getUmlFactory().delete(elem); for (int i = 0; i < NO_OF_ELEMENTS; i++) { Model.getUmlFactory().delete(signals[i]); } model = null; }
/** @see junit.framework.TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); Model.getUmlFactory().delete(elem); Model.getUmlFactory().delete(child); Model.getUmlFactory().delete(parent); Model.getUmlFactory().delete(namespace); for (int i = 0; i < 10; i++) { Model.getUmlFactory().delete(types[i]); } model = null; }
/** * Test deleting an operation that contains a statechart diagram. The diagram should be deleted, * too. */ public void testDeleteOperationWithStateDiagram() { Project p = ProjectManager.getManager().getCurrentProject(); assertEquals(2, p.getDiagrams().size()); int sizeMembers = p.getMembers().size(); int sizeDiagrams = p.getDiagrams().size(); // test with a class and class diagram Object package1 = Model.getModelManagementFactory().buildPackage("test1", null); Object aClass = Model.getCoreFactory().buildClass(package1); Collection propertyChangeListeners = p.findFigsForMember(aClass); Object model = p.getModel(); Object voidType = p.findType("void"); Object oper = Model.getCoreFactory().buildOperation(aClass, model, voidType, propertyChangeListeners); // try with Statediagram Object machine = Model.getStateMachinesFactory().buildStateMachine(oper); UMLStateDiagram d = new UMLStateDiagram(Model.getFacade().getNamespace(machine), machine); p.addMember(d); assertEquals(sizeDiagrams + 1, p.getDiagrams().size()); assertEquals(sizeMembers + 1, p.getMembers().size()); p.moveToTrash(oper); assertTrue("Operation not in trash", p.isInTrash(oper)); assertTrue("Statemachine not in trash", Model.getUmlFactory().isRemoved(machine)); assertEquals(sizeDiagrams, p.getDiagrams().size()); assertEquals(sizeMembers, p.getMembers().size()); }
/** * Test removing signals. * * @throws InvocationTargetException test failure * @throws InterruptedException test failure */ public void testRemoveSignal() throws InterruptedException, InvocationTargetException { Model.getUmlFactory().delete(signals[NO_OF_ELEMENTS - 1]); ThreadHelper.synchronize(); assertEquals(NO_OF_ELEMENTS - 1, model.getSize()); assertTrue(!model.contains(signals[NO_OF_ELEMENTS - 1])); }
/** * Test deleting an operation that contains a statechart diagram. The diagram should be deleted, * too. */ public void testDeleteOperationWithStateDiagram() { Project p = ProjectManager.getManager().getOpenProjects().get(0); assertEquals(2, p.getDiagramList().size()); int sizeMembers = p.getMembers().size(); int sizeDiagrams = p.getDiagramList().size(); // test with a class and class diagram Object package1 = Model.getModelManagementFactory().buildPackage("test1"); Object aClass = Model.getCoreFactory().buildClass(package1); Object voidType = p.getDefaultReturnType(); Object oper = Model.getCoreFactory().buildOperation(aClass, voidType); // try with Statediagram Object machine = Model.getStateMachinesFactory().buildStateMachine(oper); UMLStateDiagram d = new UMLStateDiagram(Model.getFacade().getNamespace(machine), machine); p.addMember(d); assertEquals(sizeDiagrams + 1, p.getDiagramList().size()); assertEquals(sizeMembers + 1, p.getMembers().size()); p.moveToTrash(oper); Model.getPump().flushModelEvents(); assertTrue("Operation not in trash", p.isInTrash(oper)); /* Changed by issue 4281: */ assertTrue("Statemachine in trash", !Model.getUmlFactory().isRemoved(machine)); assertEquals(sizeDiagrams + 1, p.getDiagramList().size()); assertEquals(sizeMembers + 1, p.getMembers().size()); /* After issue 4284 will be solved, we * may even delete the class, and the diagram * should still exist. */ }
/** * Test saving a profile model. * * @throws Exception when saving the profile model fails */ public void testSaveProfileModel() throws Exception { Object model = mother.createSimpleProfileModel(); File file = File.createTempFile("testSaveProfileModel", ".xmi"); mother.saveProfileModel(model, file); assertTrue( "The file to where the file was supposed to be saved " + "doesn't exist.", file.exists()); Model.getUmlFactory().delete(model); }
/** * Test the creation of a profile which depends on another profile. * * @throws IOException When saving the profile models fails. * @throws UmlException When something in the model subsystem goes wrong. */ public void testCreateXmiDependentProfile() throws IOException, UmlException { File profilesDir = FileHelper.createTempDirectory(); File profileFromWhichDependsFile = File.createTempFile("simple-profile", ".xmi", profilesDir); Object model = mother.createSimpleProfileModel(); mother.saveProfileModel(model, profileFromWhichDependsFile); Model.getUmlFactory().deleteExtent(model); // setting up the dependent profile creation ProfileMother.DependencyCreator dependencyCreator = new ProfileMother.DependencyCreator() { public void create(Object profileFromWhichDepends, Object dependentProfile) { Object theClass = Model.getCoreFactory().buildClass("TheClass", dependentProfile); Collection stereotypes = getFacade().getStereotypes(profileFromWhichDepends); Object stereotype = stereotypes.iterator().next(); Model.getCoreHelper().addStereotype(theClass, stereotype); } }; String dependentProfileFilenamePrefix = "dependent-profile"; // actual call that executes everything File dependentProfileFile = mother.createXmiDependentProfile( profileFromWhichDependsFile, dependencyCreator, profilesDir, dependentProfileFilenamePrefix); // verifications assertTrue( "The file to where the file was supposed to be saved " + "doesn't exist.", dependentProfileFile.exists()); assertStringInLineOfFile( "The name of the file which contains the profile " + "from which the dependent profile depends must occur in the " + "file.", profileFromWhichDependsFile.getName(), dependentProfileFile); XmiReader xmiReader = Model.getXmiReader(); xmiReader.addSearchPath(profilesDir.getAbsolutePath()); InputSource pIs = new InputSource(dependentProfileFile.toURI().toURL().toExternalForm()); pIs.setPublicId(dependentProfileFile.getName()); Collection dependentProfileModelTopElements = xmiReader.parse(pIs, true); assertEquals( "There should exist only one top level element.", 1, dependentProfileModelTopElements.size()); // Clean up our model and the extent that we read profile in to Model.getUmlFactory().delete(model); Model.getUmlFactory().deleteExtent(dependentProfileModelTopElements.iterator().next()); }
/** Test the moveToTrash function for class and content. */ public void testTrashcanClassContent() { Project p = ProjectManager.getManager().getCurrentProject(); // test with a class and an inner class Object aClass = Model.getCoreFactory().buildClass("Test", p.getRoot()); Object cls1 = Model.getCoreFactory().buildClass(aClass); Object cls2 = Model.getCoreFactory().buildClass(aClass); Object cls3 = Model.getCoreFactory().buildClass(aClass); Object typ = Model.getCoreFactory().buildClass(p.getRoot()); Object oper2a = Model.getCoreFactory().buildOperation(cls2, p.getRoot(), cls3, new ArrayList()); Object oper2b = Model.getCoreFactory().buildOperation(cls2, p.getRoot(), typ, new ArrayList()); p.moveToTrash(aClass); // Collection c = Model.getFacade().getOwnedElements(p.getRoot()); assertTrue("Package not in trash", p.isInTrash(aClass)); assertTrue("Package not deleted", Model.getUmlFactory().isRemoved(aClass)); assertTrue("Class 1 not deleted", Model.getUmlFactory().isRemoved(cls1)); assertTrue("Class 2 not deleted", Model.getUmlFactory().isRemoved(cls2)); assertTrue("Class 3 not deleted", Model.getUmlFactory().isRemoved(cls3)); }
/** Test the creation of a profile model. */ public void testCreateProfileModel() { Object model = mother.createSimpleProfileModel(); assertNotNull(model); Collection profileStereotypes = getFacade().getStereotypes(model); assertEquals(1, profileStereotypes.size()); assertEquals( ProfileMother.STEREOTYPE_NAME_PROFILE, getFacade().getName(profileStereotypes.iterator().next())); Model.getUmlFactory().delete(model); }
/** * Test {@link ProfileMother#createUnloadedSimpleProfile()}. * * @throws IOException when file IO goes wrong... * @throws UmlException when UML manipulation goes wrong... */ public void testCreateUnloadedSimpleProfile() throws IOException, UmlException { File profileFile = mother.createUnloadedSimpleProfile(); profileFile.deleteOnExit(); assertTrue("It doesn't exist or isn't a file.", profileFile.exists() && profileFile.isFile()); XmiReader xmiReader = Model.getXmiReader(); InputSource inputSource = new InputSource(profileFile.toURI().toURL().toExternalForm()); Collection topModelElements = xmiReader.parse(inputSource, true); assertEquals("Unexpected number of top model elements.", 1, topModelElements.size()); Model.getUmlFactory().deleteExtent(topModelElements.iterator().next()); }
/** Test deleting a package that contains a Class. The class should be deleted, too. */ public void testDeletePackageWithClass() { Project p = ProjectManager.getManager().getCurrentProject(); assertEquals(2, p.getDiagrams().size()); // test with a class and class diagram Object package1 = Model.getModelManagementFactory().buildPackage("test1", null); Object aClass = Model.getCoreFactory().buildClass(package1); p.moveToTrash(package1); assertTrue("Class not in trash", Model.getUmlFactory().isRemoved(aClass)); }
/** Test deleting a class that contains a Class. The class should be deleted, too. */ public void testDeleteClassWithInnerClass() { Project p = ProjectManager.getManager().getCurrentProject(); assertEquals(2, p.getDiagrams().size()); // test with a class and an inner class Object aClass = Model.getCoreFactory().buildClass("Test"); Object bClass = Model.getCoreFactory().buildClass(aClass); p.moveToTrash(aClass); assertTrue("Class not in trash", p.isInTrash(aClass)); assertTrue("Inner Class not in trash", Model.getUmlFactory().isRemoved(bClass)); }
/** Test the moveToTrash function for class and content. */ public void testTrashcanClassContent() { Project p = ProjectManager.getManager().getOpenProjects().get(0); // test with a class and an inner class Object aClass = Model.getCoreFactory().buildClass("Test", p.getRoot()); Object cls1 = Model.getCoreFactory().buildClass(aClass); Object cls2 = Model.getCoreFactory().buildClass(aClass); Object cls3 = Model.getCoreFactory().buildClass(aClass); Object typ = Model.getCoreFactory().buildClass(p.getRoot()); Object oper2a = Model.getCoreFactory().buildOperation(cls2, cls3); assertNotNull(oper2a); Object oper2b = Model.getCoreFactory().buildOperation(cls2, typ); assertNotNull(oper2b); p.moveToTrash(aClass); Model.getPump().flushModelEvents(); assertTrue("Package not in trash", p.isInTrash(aClass)); assertTrue("Package not deleted", Model.getUmlFactory().isRemoved(aClass)); assertTrue("Class 1 not deleted", Model.getUmlFactory().isRemoved(cls1)); assertTrue("Class 2 not deleted", Model.getUmlFactory().isRemoved(cls2)); assertTrue("Class 3 not deleted", Model.getUmlFactory().isRemoved(cls3)); }
public void removeProfile(Profile p) { if (p != null && p != profileUML) { profiles.remove(p); defaultProfiles.remove(p); } try { Collection packages = p.getLoadedPackages(); if (packages != null && !packages.isEmpty()) { // We assume profile is contained in a single extent Model.getUmlFactory().deleteExtent(packages.iterator().next()); } } catch (ProfileException e) { // Nothing to delete if we couldn't get the packages } }
/** * Tests if the list with namespaces defined in getValidNamespaceClasses contains only valid * namespaces. * * <p>TODO: This test does not test anything, really! */ public void testValidNamespaces() { Iterator it = validNamespaces.iterator(); while (it.hasNext()) { Object type = it.next(); Object o = Model.getUmlFactory().buildNode(type); String objDesc = "" + o; if (o != null) { objDesc += " (" + o.getClass() + ")"; } TargetManager.getInstance().setTarget(o); Model.getPump().flushModelEvents(); action.actionPerformed(null); Object d = TargetManager.getInstance().getTarget(); assertTrue(objDesc + " is not valid namespace for the diagram", d instanceof ArgoDiagram); } }
/** * Create an edge of the given type and connect it to the given nodes. * * @param graphModel the graph model in which to create the connection element * @param edgeType the UML object type of the connection * @param sourceFig the FigNode for the source element * @param destFig the FigNode for the destination element * @return The FigEdge representing the newly created model element */ @Override protected FigEdge buildConnection( MutableGraphModel graphModel, Object edgeType, Fig sourceFig, Fig destFig) { try { Object associationEnd = Model.getUmlFactory() .buildConnection( edgeType, sourceFig.getOwner(), null, destFig.getOwner(), null, null, null); final FigNode sourceFigNode = convertToFigNode(sourceFig); final FigNode destFigNode = convertToFigNode(destFig); graphModel.addEdge(associationEnd); setNewEdge(associationEnd); // Calling connect() will add the edge to the GraphModel and // any LayerPersectives on that GraphModel will get a // edgeAdded event and will add an appropriate FigEdge // (determined by the GraphEdgeRenderer). if (getNewEdge() != null) { sourceFigNode.damage(); destFigNode.damage(); Layer lay = editor.getLayerManager().getActiveLayer(); FigEdge fe = (FigEdge) lay.presentationFor(getNewEdge()); _newItem.setLineColor(Color.black); fe.setFig(_newItem); fe.setSourcePortFig(sourceFigNode); fe.setSourceFigNode(sourceFigNode); fe.setDestPortFig(destFigNode); fe.setDestFigNode(destFigNode); return fe; } else { return null; } } catch (IllegalModelElementConnectionException e) { // We have already confirmed the connection is valid return null; } }
/** * Test the creation of a simple profile model and check that specific model elements are * contained in it. */ public void testCreateSimpleProfileModel() { final Object model = mother.createSimpleProfileModel(); Collection<Object> models = new ArrayList<Object>() { { add(model); } }; Collection stereotypes = getExtensionMechanismsHelper().getStereotypes(models); Object st = null; for (Object stereotype : stereotypes) { if (ProfileMother.STEREOTYPE_NAME_ST.equals(getFacade().getName(stereotype))) { st = stereotype; break; } } assertNotNull("\"st\" stereotype not found in model.", st); assertTrue( Model.getExtensionMechanismsHelper() .isStereotype(st, ProfileMother.STEREOTYPE_NAME_ST, "Class")); Model.getUmlFactory().delete(model); }
/** @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent pve) { Object src = pve.getSource(); String pName = pve.getPropertyName(); if (pve instanceof DeleteInstanceEvent && src == getOwner()) { removeFromDiagram(); return; } // We handle and consume editing events if (pName.equals("editing") && Boolean.FALSE.equals(pve.getNewValue())) { LOG.debug("finished editing"); // parse the text that was edited textEdited((FigText) src); calcBounds(); endTrans(); } else if (pName.equals("editing") && Boolean.TRUE.equals(pve.getNewValue())) { textEditStarted((FigText) src); } else { // Add/remove name change listeners for applied stereotypes if (src == getOwner() && "stereotype".equals(pName)) { if (pve instanceof RemoveAssociationEvent) { removeElementListener(pve.getOldValue()); } else if (pve instanceof AddAssociationEvent) { addElementListener(pve.getNewValue(), "name"); } } // Pass everything except editing events to superclass super.propertyChange(pve); } if (Model.getFacade().isAModelElement(src) && getOwner() != null && !Model.getUmlFactory().isRemoved(getOwner())) { /* If the source of the event is an UML object, * then the UML model has been changed.*/ modelChanged(pve); } damage(); // TODO: (MVW) Is this required? // After all these events? I doubt it... }
/** * This is only called if we already know that the values differ. * * @param lang the language of the expression * @param body the body text of the expression */ private void setExpression(String lang, String body) { if (Model.getFacade().getUmlVersion().charAt(0) == '1') { // Expressions are DataTypes, not independent model elements // be careful not to reuse them final Object currentExpression = getExpression(); if (currentExpression != null) { LOG.log(Level.INFO, "Deleting the current expression {0}", currentExpression); Model.getUmlFactory().delete(currentExpression); } final Object newExpression; if (lang.length() == 0 && body.length() == 0) { newExpression = null; } else { newExpression = newExpression(lang, body); } setExpression(newExpression); } else { // reuse Opaque..., just set it's attributes Object expression = getExpression(); Model.getDataTypesHelper().setBody(expression, body); Model.getDataTypesHelper().setLanguage(expression, lang); } }
/** Test deletion. */ public void testRemovePowertype() { Model.getUmlFactory().delete(types[9]); Model.getPump().flushModelEvents(); assertTrue(!model.contains(types[9])); }
/** * This deletes modelelements, and swallows null without barking. * * @author Michiel * @param obj the modelelement to be deleted */ private void delete(Object obj) { if (obj != null) { Model.getUmlFactory().delete(obj); } }
/** @see junit.framework.TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); Model.getUmlFactory().delete(base); }