fuzzy.emf.test: added command when saving failure files
diff --git a/org.eclipse.emf.emfstore.fuzzy.emf.test/src/org/eclipse/emf/emfstore/fuzzy/emf/test/FuzzyProjectTest.java b/org.eclipse.emf.emfstore.fuzzy.emf.test/src/org/eclipse/emf/emfstore/fuzzy/emf/test/FuzzyProjectTest.java index f6bf3be..7e255c4 100644 --- a/org.eclipse.emf.emfstore.fuzzy.emf.test/src/org/eclipse/emf/emfstore/fuzzy/emf/test/FuzzyProjectTest.java +++ b/org.eclipse.emf.emfstore.fuzzy.emf.test/src/org/eclipse/emf/emfstore/fuzzy/emf/test/FuzzyProjectTest.java
@@ -47,28 +47,31 @@ * Abstract super class for tests handling EMFStore projects. * * @author Julian Sommerfeldt - * + * */ @RunWith(FuzzyRunner.class) @DataProvider(EMFDataProvider.class) public abstract class FuzzyProjectTest { - + @Data private Project project; - + @Util private MutateUtil util; - + @SuppressWarnings({ "serial", "unused" }) @Options - private Map<String, Object> options = new HashMap<String, Object>(){{ - put(EMFDataProvider.MUTATOR_EDITINGDOMAIN, WorkspaceManager.getInstance().getCurrentWorkspace().getEditingDomain()); - }}; + private Map<String, Object> options = new HashMap<String, Object>() { + { + put(EMFDataProvider.MUTATOR_EDITINGDOMAIN, WorkspaceManager.getInstance().getCurrentWorkspace() + .getEditingDomain()); + } + }; private ProjectSpace projectSpace; private ProjectSpace copyProjectSpace; - + /** * Init the testclasses. */ @@ -76,48 +79,49 @@ public static void init() { // call once to avoid wrong time in first run CommonUtil.setTesting(true); - WorkspaceManager.init(); + WorkspaceManager.init(); } - + /***/ @Before - public void setup() { + public void setup() { // set testing to true so it uses test profile CommonUtil.setTesting(true); - - // necessary to avoid saving of each projectspace - // which leads to a very slow performance + + // necessary to avoid saving of each projectspace + // which leads to a very slow performance Configuration.setAutoSave(false); - + // import projects WorkspaceManager.init(); new EMFStoreCommand() { @Override - protected void doRun() { - projectSpace = WorkspaceManager.getInstance().getCurrentWorkspace().importProject(project, "", ""); - if(projectSpaceCopyNeeded()) { - copyProjectSpace = WorkspaceManager.getInstance().getCurrentWorkspace().importProject(ModelUtil.clone(project), "", ""); + protected void doRun() { + projectSpace = WorkspaceManager.getInstance().getCurrentWorkspace().importProject(project, "", ""); + if (projectSpaceCopyNeeded()) { + copyProjectSpace = WorkspaceManager.getInstance().getCurrentWorkspace() + .importProject(ModelUtil.clone(project), "", ""); } } }.run(false); } - + /***/ @After - public void tearDown() { + public void tearDown() { new EMFStoreCommand() { @Override - protected void doRun() { - try{ + protected void doRun() { + try { Workspace currentWorkspace = WorkspaceManager.getInstance().getCurrentWorkspace(); EList<ProjectSpace> projectSpaces = currentWorkspace.getProjectSpaces(); - if(projectSpace != null && projectSpaces.contains(projectSpace)){ + if (projectSpace != null && projectSpaces.contains(projectSpace)) { currentWorkspace.deleteProjectSpace(projectSpace); } - if(copyProjectSpace != null && projectSpaces.contains(copyProjectSpace)){ - currentWorkspace.deleteProjectSpace(copyProjectSpace); + if (copyProjectSpace != null && projectSpaces.contains(copyProjectSpace)) { + currentWorkspace.deleteProjectSpace(copyProjectSpace); } - } catch (FileNotFoundException e){ + } catch (FileNotFoundException e) { // do nothing } catch (IOException e) { // do nothing @@ -127,17 +131,17 @@ } }.run(false); } - + /** * Constructs a new {@link ModelMutatorConfiguration} based on the existing one and the given project. * * @param project The root object of the {@link ModelMutatorConfiguration}. * @return The new {@link ModelMutatorConfiguration}. */ - public ModelMutatorConfiguration getModelMutatorConfiguration(Project project){ + public ModelMutatorConfiguration getModelMutatorConfiguration(Project project) { return getModelMutatorConfiguration(project, util); } - + /** * Constructs a new {@link ModelMutatorConfiguration} based on the given {@link MutateUtil} and the given project. * @@ -145,7 +149,7 @@ * @param util The {@link MutateUtil} connected to the {@link EMFDataProvider}. * @return The new {@link ModelMutatorConfiguration}. */ - public static ModelMutatorConfiguration getModelMutatorConfiguration(Project project, MutateUtil util){ + public static ModelMutatorConfiguration getModelMutatorConfiguration(Project project, MutateUtil util) { final ModelMutatorConfiguration mmc = new ModelMutatorConfiguration(util.getEPackages(), project, 1L); mmc.seteStructuralFeaturesToIgnore(util.getEStructuralFeaturesToIgnore()); mmc.seteClassesToIgnore(util.getEClassesToIgnore()); @@ -153,67 +157,73 @@ mmc.setMinObjectsCount(util.getMinObjectsCount()); return mmc; } - + /** * Can be overridden by subclasses to modify behavior. Default is <code>true</code>. * * @return Should this class handle/provide also a copy of the projectSpace? */ - public boolean projectSpaceCopyNeeded(){ + public boolean projectSpaceCopyNeeded() { return true; } - + /** - * Notify that a test has failed. Saves the projects for later comparison. + * Notify that a test has failed. Saves the projects for later comparison. * * @param project1 The first {@link Project}. * @param project2 The second {@link Project}. */ - public void fail(Project project1, Project project2){ + public void fail(Project project1, Project project2) { fail(project1, project2, util); } - + /** - * Notify that a test has failed. Saves the projects for later comparison. + * Notify that a test has failed. Saves the projects for later comparison. * * @param project1 The first {@link Project}. * @param project2 The second {@link Project}. * @param util The {@link MutateUtil} connected to the {@link EMFDataProvider}. */ - public static void fail(Project project1, Project project2, MutateUtil util){ + public static void fail(Project project1, Project project2, MutateUtil util) { save(project1, project2, util); Assert.fail(); } - + /** - * Saves the projects for e.g. later comparison. + * Saves the projects for e.g. later comparison. * * @param project1 The first {@link Project}. * @param project2 The second {@link Project}. * @param util The {@link MutateUtil} connected to the {@link EMFDataProvider}. */ - public static void save(Project project1, Project project2, MutateUtil util){ - Map<Object, Object> options = new HashMap<Object, Object>(); + public static void save(final Project project1, final Project project2, final MutateUtil util) { + final Map<Object, Object> options = new HashMap<Object, Object>(); options.put(XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_DISCARD); - - try { - ModelUtil.saveEObjectToResource(Arrays.asList(project1), util.getRunResourceURI("original"), options); - ModelUtil.saveEObjectToResource(Arrays.asList(project2), util.getRunResourceURI("copy"), options); - } catch (IOException e) { - throw new RuntimeException(e); - } + + new EMFStoreCommand() { + @Override + protected void doRun() { + try { + ModelUtil.saveEObjectToResource(Arrays.asList(project1), util.getRunResourceURI("original"), + options); + ModelUtil.saveEObjectToResource(Arrays.asList(project2), util.getRunResourceURI("copy"), options); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }.run(false); } - + /** * Compare two projects but ignore the order of the elements. * * @param project1 The first {@link Project}. * @param project2 The second {@link Project}. */ - public void compareIgnoreOrder(Project project1, Project project2){ + public void compareIgnoreOrder(Project project1, Project project2) { compareIgnoreOrder(project1, project2, util); } - + /** * Compare two projects but ignore the order of the elements. * @@ -221,13 +231,13 @@ * @param project2 The second {@link Project}. * @param util The {@link MutateUtil} connected to the {@link EMFDataProvider}. */ - public static void compareIgnoreOrder(Project project1, Project project2, MutateUtil util){ + public static void compareIgnoreOrder(Project project1, Project project2, MutateUtil util) { if (project1.getModelElements().size() != project2.getModelElements().size()) { fail(project1, project2, util); } - + int index = 0; - //sort elements in modelElement reference of projects to avoid differences only in indices. + // sort elements in modelElement reference of projects to avoid differences only in indices. for (EObject eObject1 : project1.getModelElements()) { ModelElementId modelElementId1 = project1.getModelElementId(eObject1); EObject eObject2 = project2.getModelElement(modelElementId1); @@ -242,45 +252,45 @@ fail(project1, project2, util); } } - + /** * @return The {@link MutateUtil} connected with the {@link EMFDataProvider}. */ public MutateUtil getUtil() { return util; } - + /** * @return The {@link ProjectSpace} imported into the WorkSpace. */ public ProjectSpace getProjectSpace() { return projectSpace; } - + /** * @param projectSpace The {@link ProjectSpace} of the test. */ public void setProjectSpace(ProjectSpace projectSpace) { this.projectSpace = projectSpace; } - + /** * @return The {@link ProjectSpace} copied from the original one. * @throws IllegalStateException When {@link #projectSpaceCopyNeeded()} returns false. */ public ProjectSpace getCopyProjectSpace() throws IllegalStateException { - if(!projectSpaceCopyNeeded()){ + if (!projectSpaceCopyNeeded()) { throw new IllegalStateException("This test does not have a copied projectSpace!"); } return copyProjectSpace; } - + /** * @param copyProjectSpace The {@link ProjectSpace} copied from the original one. * @throws IllegalStateException When {@link #projectSpaceCopyNeeded()} returns false. */ public void setCopyProjectSpace(ProjectSpace copyProjectSpace) throws IllegalStateException { - if(!projectSpaceCopyNeeded()){ + if (!projectSpaceCopyNeeded()) { throw new IllegalStateException("This test does not have a copied projectSpace!"); } this.copyProjectSpace = copyProjectSpace;