From af85d0eec4977b954e133722801a1febdfbdd165 Mon Sep 17 00:00:00 2001 From: Emmanuel CHEBBI Date: Thu, 27 Dec 2018 22:00:31 +0100 Subject: [PATCH 1/2] Fix Java Language tests As a remember the issue was that when testing dynamic loading of Java Runners runtime errors was occuring randomly. In the end the issue was that the Eclipse project was not properly imported. Updating ImportableProject class solved the issue. --- .../languages/java/JavaLanguageTest.java | 14 ++------ .../java/test/ImportableProject.java | 34 ++++++++++++++----- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/JavaLanguageTest.java b/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/JavaLanguageTest.java index 3e7c420..b808fba 100644 --- a/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/JavaLanguageTest.java +++ b/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/JavaLanguageTest.java @@ -3,12 +3,12 @@ import static org.mockito.Mockito.when; import java.io.File; +import java.lang.reflect.InvocationTargetException; import org.assertj.core.api.WithAssertions; import org.eclipse.core.runtime.CoreException; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Tag; @@ -92,7 +92,7 @@ void injects_resolved_scripts(String identifier, Class expectedClass) { else script = language.resolveCondition(identifier, context); - assertThat((Injectable) script).matches(r -> r.hasBeenInjected()); + assertThat((Injectable) script).matches(r -> r.hasBeenInjected(), "has been injected"); } @Nested @DisplayName("when the bundle does not exist") @@ -179,13 +179,6 @@ void does_not_inject_resolved_scripts(String identifier, Class expectedClass) } - @Disabled // Following tests have a strange behavior : - // - they pass most of the time when executed from Eclipse IDE, - // - they fail most of the time when executed from local Maven - // - they fail all the time when executed from the headless CI - // - // As manual testing has shown that the code seems to work in a real situation, - // the tests are disabled for the moment. @TestInstance(Lifecycle.PER_CLASS) @Nested @DisplayName("when resolving from a workspace project") class WhenResolvingFromAWorkspaceProject implements ProjectProvider { // ProjectProvider provides some constants @@ -198,11 +191,10 @@ void createJavaLanguage(@Mock Events events, @Mock ExecutionStatus status) { } @BeforeAll - void importFakeProjectInWorkspace() throws CoreException { + void importFakeProjectInWorkspace() throws CoreException, InvocationTargetException, InterruptedException { File fakeProjectPath = new File("./rsc/some.workspace.project/"); ImportableProject fakeProject = new ImportableProject(fakeProjectPath); - // Causes exceptions at runtime **on Eclipse IDE**, but I don't know how to avoid them fakeProject.importInWorkspace(); } diff --git a/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/test/ImportableProject.java b/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/test/ImportableProject.java index 3a7d9e9..ee9043d 100644 --- a/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/test/ImportableProject.java +++ b/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/test/ImportableProject.java @@ -1,12 +1,17 @@ package fr.kazejiyu.ekumi.languages.java.test; import java.io.File; +import java.lang.reflect.InvocationTargetException; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.ui.dialogs.IOverwriteQuery; +import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; +import org.eclipse.ui.wizards.datatransfer.ImportOperation; /** * Represents an Eclipse project that can be imported in the workspace. @@ -16,7 +21,6 @@ public class ImportableProject { private final File location; - private IProject project; /** * Creates a new importable project. @@ -32,26 +36,38 @@ public ImportableProject(File location) { * Imports the project in the workspace. * * @throws CoreException if the project cannot be imported. + * @throws InterruptedException + * @throws InvocationTargetException */ - public void importInWorkspace() throws CoreException { + public void importInWorkspace() throws CoreException, InvocationTargetException, InterruptedException { IProjectDescription description = ResourcesPlugin .getWorkspace() .loadProjectDescription(projectFile()); - project = ResourcesPlugin + IProject project = ResourcesPlugin .getWorkspace() .getRoot() .getProject(description.getName()); - // Works most of the time when executed from Eclipse IDE + // Prevent runtime errors when importing the project + description.setLocation(project.getFullPath()); + + // Create the project in the workspace project.create(description, null); project.open(null); + + // Import the content of the project + IOverwriteQuery overwriteQuery = file -> IOverwriteQuery.ALL; + + ImportOperation importOperation = new ImportOperation( + project.getFullPath(), + new File(location.getAbsolutePath()), + FileSystemStructureProvider.INSTANCE, + overwriteQuery + ); - // Bad attempt to make the import works from Maven - // Still works from Eclipse IDE, but causes Maven tests - // to fail all the time -// project.refreshLocal(IResource.DEPTH_INFINITE, null); -// project.build(IncrementalProjectBuilder.FULL_BUILD, null); + importOperation.setCreateContainerStructure(false); + importOperation.run(new NullProgressMonitor()); } /** @return the path toward the location/.project file */ From 293c85f4b861eab09db4106a4d5435ad9d62f7d8 Mon Sep 17 00:00:00 2001 From: Emmanuel CHEBBI Date: Wed, 2 Jan 2019 17:27:30 +0100 Subject: [PATCH 2/2] Import in workspace --- .../kazejiyu/ekumi/languages/java/test/ImportableProject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/test/ImportableProject.java b/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/test/ImportableProject.java index ee9043d..88a540f 100644 --- a/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/test/ImportableProject.java +++ b/tests/fr.kazejiyu.ekumi.languages.java.test/src/fr/kazejiyu/ekumi/languages/java/test/ImportableProject.java @@ -50,7 +50,7 @@ public void importInWorkspace() throws CoreException, InvocationTargetException, .getProject(description.getName()); // Prevent runtime errors when importing the project - description.setLocation(project.getFullPath()); + description.setLocation(ResourcesPlugin.getWorkspace().getRoot().getLocation().append(project.getName())); // Create the project in the workspace project.create(description, null);