/** * 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()); }
/** * 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()); }
public void removeSearchPathDirectory(String path) { if (path != null) { searchDirectories.remove(path); updateSearchDirectoriesConfiguration(); try { Model.getXmiReader().removeSearchPath(path); } catch (UmlException e) { LOG.error("Couldn't retrive XMI Reader from Model.", e); } } }
/** * 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()); }
/** * @param inputStream the stream from where the model should be loaded * @param publicReference the URL to be used as the public reference of the profile that will be * loaded. * @return the model * @throws ProfileException if the XMIReader couldn't read the input stream */ public Collection loadModel(InputStream inputStream, URL publicReference) throws ProfileException { if (inputStream == null) { LOG.error("Profile not found"); throw new ProfileException("Profile not found!"); } try { XmiReader xmiReader = Model.getXmiReader(); InputSource inputSource = new InputSource(inputStream); inputSource.setPublicId(publicReference.toString()); Collection elements = xmiReader.parse(inputSource, true); return elements; } catch (UmlException e) { throw new ProfileException("Invalid XMI data!", e); } }