diff --git a/openshift-maven-plugin/plugin/pom.xml b/openshift-maven-plugin/plugin/pom.xml index 063bfaee16..99d63a2f9e 100644 --- a/openshift-maven-plugin/plugin/pom.xml +++ b/openshift-maven-plugin/plugin/pom.xml @@ -42,8 +42,14 @@ - junit - junit + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test org.mockito diff --git a/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/OpenShiftGeneratedPluginDescriptorTest.java b/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/OpenShiftGeneratedPluginDescriptorTest.java index 6486e27dd8..9a350d2b3d 100644 --- a/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/OpenShiftGeneratedPluginDescriptorTest.java +++ b/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/OpenShiftGeneratedPluginDescriptorTest.java @@ -13,10 +13,10 @@ */ package org.eclipse.jkube.maven.plugin.mojo; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.w3c.dom.Document; import javax.xml.parsers.DocumentBuilder; @@ -26,50 +26,39 @@ import java.io.File; import java.io.FileInputStream; import java.net.URL; -import java.util.Arrays; -import java.util.Collection; +import java.util.stream.Stream; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -@RunWith(Parameterized.class) -public class OpenShiftGeneratedPluginDescriptorTest { +class OpenShiftGeneratedPluginDescriptorTest { private File pluginDescriptor; - @Parameterized.Parameter - public String mojo; - - @Parameterized.Parameter(1) - public String expectedRequiresDependencyResolution; - - @Parameterized.Parameter(2) - public String expectedPhase; - - @Before - public void setUp() { + @BeforeEach + void setUp() { URL pluginDescriptorUrl = getClass().getResource("/META-INF/maven/plugin.xml"); assertThat(pluginDescriptorUrl).isNotNull(); pluginDescriptor = new File(pluginDescriptorUrl.getFile()); } - @Parameterized.Parameters(name = "{index} {0}, should have {1} requiresDependencyResolution and {2} phase") - public static Collection data() { - return Arrays.asList( - new Object[] { "build", "compile", "pre-integration-test"}, - new Object[] { "resource", "compile", "process-resources"}, - new Object[] { "apply", "compile+runtime", "install"}, - new Object[] { "deploy", "compile+runtime", "validate"}, - new Object[] { "watch", "compile+runtime", "package"}, - new Object[] { "undeploy", "compile", "install"}, - new Object[] { "debug", "compile+runtime", "package"}, - new Object[] { "log", "compile+runtime", "validate"}, - new Object[] { "push", "compile", "install"}, - new Object[] { "helm", "", "pre-integration-test"}, - new Object[] { "helm-push", "compile", "install"} + public static Stream data() { + return Stream.of( + Arguments.of("build", "compile", "pre-integration-test"), + Arguments.of("resource", "compile", "process-resources"), + Arguments.of("apply", "compile+runtime", "install"), + Arguments.of("deploy", "compile+runtime", "validate"), + Arguments.of("watch", "compile+runtime", "package"), + Arguments.of("undeploy", "compile", "install"), + Arguments.of("debug", "compile+runtime", "package"), + Arguments.of("log", "compile+runtime", "validate"), + Arguments.of("push", "compile", "install"), + Arguments.of("helm", "", "pre-integration-test"), + Arguments.of("helm-push", "compile", "install") ); } - @Test - public void verifyPhaseAndRequiresDependencyResolution() throws Exception { + @ParameterizedTest(name = "{0}, should have {1} requiresDependencyResolution and {2} phase") + @MethodSource("data") + void verifyPhaseAndRequiresDependencyResolution(String mojo, String expectedRequiresDependencyResolution, String expectedPhase) throws Exception { assertThat(getField(pluginDescriptor, "/plugin/mojos/mojo[goal='" + mojo + "']/requiresDependencyResolution")) .isEqualTo(expectedRequiresDependencyResolution); assertThat(getField(pluginDescriptor, "/plugin/mojos/mojo[goal='" + mojo + "']/phase")) diff --git a/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenShiftResourceMojoTest.java b/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenShiftResourceMojoTest.java index b631570f88..d52acce4ac 100644 --- a/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenShiftResourceMojoTest.java +++ b/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/OpenShiftResourceMojoTest.java @@ -25,33 +25,31 @@ import org.eclipse.jkube.kit.config.image.ImageConfiguration; import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; import org.eclipse.jkube.kit.config.service.JKubeServiceHub; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Collections; import java.util.Properties; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class OpenShiftResourceMojoTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - +class OpenShiftResourceMojoTest { private ClusterAccess mockedClusterAccess; private ImageConfigResolver mockedImageConfigResolver; private OpenshiftResourceMojo openShiftResourceMojo; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp(@TempDir Path temporaryFolder) throws IOException { mockedClusterAccess = mock(ClusterAccess.class, RETURNS_DEEP_STUBS); mockedImageConfigResolver = mock(ImageConfigResolver.class, RETURNS_DEEP_STUBS); Properties properties = new Properties(); @@ -74,15 +72,15 @@ public void setUp() throws IOException { this.openShiftResourceMojo.imageConfigResolver = mockedImageConfigResolver; this.openShiftResourceMojo.javaProject = javaProject; this.openShiftResourceMojo.interpolateTemplateParameters = true; - this.openShiftResourceMojo.resourceDir = temporaryFolder.newFolder("src", "main", "jkube"); + this.openShiftResourceMojo.resourceDir = Files.createDirectories(temporaryFolder.resolve("src").resolve("main").resolve("jkube")).toFile(); when(mockedMavenProject.getProperties()).thenReturn(properties); when(mockedJKubeServiceHub.getConfiguration().getProject()).thenReturn(javaProject); - when(mockedJKubeServiceHub.getConfiguration().getBasedir()).thenReturn(temporaryFolder.getRoot()); + when(mockedJKubeServiceHub.getConfiguration().getBasedir()).thenReturn(temporaryFolder.toFile()); } @Test - public void executeInternal_resolvesGroupInImageNameToClusterAccessNamespace_whenNamespaceDetected() throws MojoExecutionException, MojoFailureException { + void executeInternal_resolvesGroupInImageNameToClusterAccessNamespace_whenNamespaceDetected() throws MojoExecutionException, MojoFailureException { // Given ImageConfiguration imageConfiguration = ImageConfiguration.builder() .name("%g/%a") @@ -92,7 +90,7 @@ public void executeInternal_resolvesGroupInImageNameToClusterAccessNamespace_whe .build(); when(mockedClusterAccess.getNamespace()).thenReturn("test-custom-namespace"); when(mockedImageConfigResolver.resolve(eq(imageConfiguration), any())).thenReturn(Collections.singletonList(imageConfiguration)); - this.openShiftResourceMojo.images = Collections.singletonList(imageConfiguration); + openShiftResourceMojo.images = Collections.singletonList(imageConfiguration); openShiftResourceMojo.skip = true; // When @@ -100,12 +98,12 @@ public void executeInternal_resolvesGroupInImageNameToClusterAccessNamespace_whe openShiftResourceMojo.executeInternal(); // Then - assertEquals(1, openShiftResourceMojo.resolvedImages.size()); - assertEquals("test-custom-namespace/test-project", openShiftResourceMojo.resolvedImages.get(0).getName()); + assertThat(openShiftResourceMojo.resolvedImages).singleElement() + .hasFieldOrPropertyWithValue("name", "test-custom-namespace/test-project"); } @Test - public void executeInternal_resolvesGroupInImageNameToNamespaceSetViaConfiguration_whenNoNamespaceDetected() throws Exception { + void executeInternal_resolvesGroupInImageNameToNamespaceSetViaConfiguration_whenNoNamespaceDetected() throws Exception { // Given ImageConfiguration imageConfiguration = ImageConfiguration.builder() .name("%g/%a") @@ -123,7 +121,7 @@ public void executeInternal_resolvesGroupInImageNameToNamespaceSetViaConfigurati openShiftResourceMojo.executeInternal(); // Then - assertEquals(1, openShiftResourceMojo.resolvedImages.size()); - assertEquals("namespace-configured-via-plugin/test-project", openShiftResourceMojo.resolvedImages.get(0).getName()); + assertThat(openShiftResourceMojo.resolvedImages).singleElement() + .hasFieldOrPropertyWithValue("name", "namespace-configured-via-plugin/test-project"); } } diff --git a/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/develop/OpenshiftUndeployMojoTest.java b/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/develop/OpenshiftUndeployMojoTest.java index a176fc910a..5422256ff6 100644 --- a/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/develop/OpenshiftUndeployMojoTest.java +++ b/openshift-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/develop/OpenshiftUndeployMojoTest.java @@ -16,10 +16,9 @@ import io.fabric8.openshift.client.OpenShiftClient; import org.eclipse.jkube.kit.config.resource.RuntimeMode; import org.eclipse.jkube.kit.config.service.JKubeServiceHub; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.io.IOException; @@ -30,22 +29,19 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class OpenshiftUndeployMojoTest { - - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); +class OpenshiftUndeployMojoTest { private JKubeServiceHub mockServiceHub; private File kubernetesManifestFile; private File openShiftManifestFile; private File openShiftISManifestFile; private OpenshiftUndeployMojo undeployMojo; - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp(@TempDir File temporaryFolder) throws IOException { mockServiceHub = mock(JKubeServiceHub.class, RETURNS_DEEP_STUBS); - kubernetesManifestFile = temporaryFolder.newFile(); - openShiftManifestFile = temporaryFolder.newFile(); - openShiftISManifestFile = temporaryFolder.newFile(); + kubernetesManifestFile = File.createTempFile("junit", "ext", temporaryFolder); + openShiftManifestFile = File.createTempFile("junit", "ext", temporaryFolder); + openShiftISManifestFile = File.createTempFile("junit", "ext", temporaryFolder); // @formatter:off undeployMojo = new OpenshiftUndeployMojo() {{ kubernetesManifest = kubernetesManifestFile; @@ -57,7 +53,7 @@ public void setUp() throws IOException { } @Test - public void getManifestsToUndeploy() { + void getManifestsToUndeploy() { // Given final OpenShiftClient client = mock(OpenShiftClient.class); when(mockServiceHub.getClient()).thenReturn(client); @@ -70,12 +66,12 @@ public void getManifestsToUndeploy() { } @Test - public void getRuntimeMode() { + void getRuntimeMode() { assertThat(undeployMojo.getRuntimeMode()).isEqualTo(RuntimeMode.OPENSHIFT); } @Test - public void getLogPrefix() { + void getLogPrefix() { assertThat(undeployMojo.getLogPrefix()).isEqualTo("oc: "); } }