Skip to content

Commit

Permalink
refactor (gradle-plugin-it): Migrate tests from JUnit4 to JUnit5 (ecl…
Browse files Browse the repository at this point in the history
…ipse-jkube#1583)

Signed-off-by: Anurag Rajawat <[email protected]>
  • Loading branch information
anurag-rajawat authored and manusa committed Nov 2, 2022
1 parent 8271c24 commit 3724101
Show file tree
Hide file tree
Showing 36 changed files with 436 additions and 584 deletions.
10 changes: 8 additions & 2 deletions gradle-plugin/it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@
</dependency>
<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class AutoTLSIT {
@Rule
public final ITGradleRunner gradleRunner = new ITGradleRunner();
class AutoTLSIT {
@RegisterExtension
private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension();

@Test
public void ocResource_whenRun_generatesOpenShiftManifestsWithExpectedTLSAnnotationsAndInitContainer() throws IOException, ParseException {
void ocResource_whenRun_generatesOpenShiftManifestsWithExpectedTLSAnnotationsAndInitContainer() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("autotls").withArguments("ocResource").build();
// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class ConfigMapIT {
@Rule
public final ITGradleRunner gradleRunner = new ITGradleRunner();
class ConfigMapIT {
@RegisterExtension
private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension();

@Test
public void k8sResource_whenRun_generatesK8sManifestsContainingConfigMap() throws IOException, ParseException {
void k8sResource_whenRun_generatesK8sManifestsContainingConfigMap() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("configmap")
.withArguments("build", "k8sResource", "--stacktrace")
Expand All @@ -47,7 +47,7 @@ public void k8sResource_whenRun_generatesK8sManifestsContainingConfigMap() throw
}

@Test
public void ocResource_whenRun_generatesOpenShiftManifestsContainingConfigMap() throws IOException, ParseException {
void ocResource_whenRun_generatesOpenShiftManifestsContainingConfigMap() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("configmap")
.withArguments("build", "ocResource", "--stacktrace")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class DebugModeIT {
@Rule
public final ITGradleRunner gradleRunner = new ITGradleRunner();
class DebugModeIT {

@RegisterExtension
private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension();

@Test
public void k8sResource_whenRun_generatesK8sManifests() throws IOException, ParseException {
void k8sResource_whenRun_generatesK8sManifests() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("debug-mode").withArguments("k8sResource").build();
// Then
Expand All @@ -43,7 +44,7 @@ public void k8sResource_whenRun_generatesK8sManifests() throws IOException, Pars
}

@Test
public void ocResource_whenRun_generatesK8sManifests() throws IOException, ParseException {
void ocResource_whenRun_generatesK8sManifests() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("debug-mode").withArguments("ocResource").build();
// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class DefaultControllerIT {
@Rule
public final ITGradleRunner gradleRunner = new ITGradleRunner();
class DefaultControllerIT {
@RegisterExtension
private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension();

@Test
public void k8sResourceTask_whenRun_generatesK8sManifestWithDeployment() throws IOException, ParseException {
void k8sResourceTask_whenRun_generatesK8sManifestWithDeployment() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("controller")
.withArguments("k8sResource", "--stacktrace")
Expand All @@ -44,7 +44,7 @@ public void k8sResourceTask_whenRun_generatesK8sManifestWithDeployment() throws
}

@Test
public void ocResourceTask_whenRun_generatesOpenShiftManifestWithDeploymentConfig() throws IOException, ParseException {
void ocResourceTask_whenRun_generatesOpenShiftManifestWithDeploymentConfig() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("controller")
.withArguments("ocResource", "--stacktrace")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class DefaultMetadataIT {
@Rule
public final ITGradleRunner gradleRunner = new ITGradleRunner();
class DefaultMetadataIT {
@RegisterExtension
private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension();

@Test
public void k8sResource_whenRun_generatesK8sManifestsWithExpectedLabelsAndAnnotations() throws IOException, ParseException {
void k8sResource_whenRun_generatesK8sManifestsWithExpectedLabelsAndAnnotations() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("metadata").withArguments("k8sResource").build();
// Then
Expand All @@ -43,7 +43,7 @@ public void k8sResource_whenRun_generatesK8sManifestsWithExpectedLabelsAndAnnota
}

@Test
public void k8sResource_whenRunWithReplicaSetConfiguredController_generatesK8sManifestsWithExpectedLabelsAndAnnotations() throws IOException, ParseException {
void k8sResource_whenRunWithReplicaSetConfiguredController_generatesK8sManifestsWithExpectedLabelsAndAnnotations() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("metadata")
.withArguments("-Pjkube.enricher.jkube-controller.type=ReplicaSet", "k8sResource")
Expand All @@ -60,7 +60,7 @@ public void k8sResource_whenRunWithReplicaSetConfiguredController_generatesK8sMa
}

@Test
public void ocResource_whenRun_generatesK8sManifestsWithExpectedLabelsAndAnnotations() throws IOException, ParseException {
void ocResource_whenRun_generatesK8sManifestsWithExpectedLabelsAndAnnotations() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("metadata").withArguments("ocResource").build();
// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class DependencyResourcesIT {
class DependencyResourcesIT {

@Rule
public final ITGradleRunner gradleRunner = new ITGradleRunner();
@RegisterExtension
private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension();

@Test
public void k8sResource_whenRun_generatesK8sManifestsIncludingDependencies() throws IOException, ParseException {
void k8sResource_whenRun_generatesK8sManifestsIncludingDependencies() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("dependency-resources")
.withArguments("clean", "jar", "k8sResource", "--stacktrace")
Expand All @@ -46,7 +46,7 @@ public void k8sResource_whenRun_generatesK8sManifestsIncludingDependencies() thr
}

@Test
public void k8sResource_whenRunWithReplicas_generatesK8sManifestsIncludingDependencies() throws IOException, ParseException {
void k8sResource_whenRunWithReplicas_generatesK8sManifestsIncludingDependencies() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("dependency-resources")
.withArguments("-Pjkube.replicas=1337", "clean", "jar", "k8sResource", "--stacktrace")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class DockerfileSimpleIT {
@Rule
public final ITGradleRunner gradleRunner = new ITGradleRunner();
class DockerfileSimpleIT {
@RegisterExtension
private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension();

@Test
public void k8sResource_whenRun_generatesK8sManifests() throws IOException, ParseException {
void k8sResource_whenRun_generatesK8sManifests() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("dockerfile-simple").withArguments("k8sResource", "--stacktrace")
.build();
Expand All @@ -44,7 +44,7 @@ public void k8sResource_whenRun_generatesK8sManifests() throws IOException, Pars
}

@Test
public void ocResource_whenRun_generatesOpenShiftManifests() throws IOException, ParseException {
void ocResource_whenRun_generatesOpenShiftManifests() throws IOException, ParseException {
// When
final BuildResult result = gradleRunner.withITProject("dockerfile-simple").withArguments("ocResource").build();
// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
import net.minidev.json.parser.ParseException;
import org.eclipse.jkube.kit.common.ResourceVerify;
import org.gradle.testkit.runner.BuildResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;

/**
* Checks that Services and Ingresses/Routes are handled according to the following conditions:
Expand All @@ -47,43 +48,33 @@
* Services are created, Ingresses are not created, Routes are created</li>
* </ul>
*/
@RunWith(Parameterized.class)
public class ExposeIT {
class ExposeIT {

@Rule
public final ITGradleRunner gradleRunner = new ITGradleRunner();
@RegisterExtension
private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension();

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[] {"Image has no ports", "no-ports", new String[] {"-Pjkube.environment=none"}},
new Object[] {"Image has FTP port", "ftp-port", new String[]{"-Pexpose-it.port=21", "-Pjkube.environment=none"}},
new Object[] {"Image has Web port", "http-port", new String[]{"-Pexpose-it.port=80", "-Pjkube.environment=none"}},
new Object[] {"Image has Web port and createExternalUrls", "http-port-external",
new String[]{"-Pexpose-it.port=80", "-Pjkube.createExternalUrls=true", "-Pjkube.environment=none"}},
new Object[] {"Image has FTP port and createExternalUrls", "ftp-port-external",
new String[]{"-Pexpose-it.port=21", "-Pjkube.createExternalUrls=true", "-Pjkube.environment=none"}},
new Object[] {"Image has FTP port, and expose annotation in service (from Fragment)",
"ftp-port-expose-annotation", new String[]{"-Pexpose-it.port=21", "-Pjkube.environment=label-expose"}},
new Object[] {"Image has FTP port, and expose annotation in service (from Service Enricher)",
"ftp-port-expose-annotation-enricher",
new String[]{"-Pexpose-it.port=21", "-Pjkube.enricher.jkube-service.expose=true", "-Pjkube.environment=none"}},
new Object[] {"Image has HTTPS port, and multiple services", "multiple-services",
new String[]{"-Pexpose-it.port=443", "-Pjkube.environment=multiple-services"}}
static Stream<Arguments> data() {
return Stream.of(
arguments("Image has no ports", "no-ports", new String[] { "-Pjkube.environment=none" }),
arguments("Image has FTP port", "ftp-port", new String[] { "-Pexpose-it.port=21", "-Pjkube.environment=none" }),
arguments("Image has Web port", "http-port", new String[] { "-Pexpose-it.port=80", "-Pjkube.environment=none" }),
arguments("Image has Web port and createExternalUrls", "http-port-external",
new String[] { "-Pexpose-it.port=80", "-Pjkube.createExternalUrls=true", "-Pjkube.environment=none" }),
arguments("Image has FTP port and createExternalUrls", "ftp-port-external",
new String[] { "-Pexpose-it.port=21", "-Pjkube.createExternalUrls=true", "-Pjkube.environment=none" }),
arguments("Image has FTP port, and expose annotation in service (from Fragment)",
"ftp-port-expose-annotation", new String[] { "-Pexpose-it.port=21", "-Pjkube.environment=label-expose" }),
arguments("Image has FTP port, and expose annotation in service (from Service Enricher)",
"ftp-port-expose-annotation-enricher",
new String[] { "-Pexpose-it.port=21", "-Pjkube.enricher.jkube-service.expose=true", "-Pjkube.environment=none" }),
arguments("Image has HTTPS port, and multiple services", "multiple-services",
new String[] { "-Pexpose-it.port=443", "-Pjkube.environment=multiple-services" })
);
}

@Parameterized.Parameter
public String description;

@Parameterized.Parameter(1)
public String expectedDir;

@Parameterized.Parameter (2)
public String[] arguments;

@Test
public void k8sResource_whenRun_generatesK8sManifestsWithProjectLabels() throws IOException, ParseException {
@ParameterizedTest(name = "{0}")
@MethodSource("data")
void k8sResource_whenRun_generatesK8sManifestsWithProjectLabels(String description, String expectedDir, String[] arguments) throws IOException, ParseException {
// When
List<String> gradleArgs = new ArrayList<>(Arrays.asList(arguments));
gradleArgs.add("k8sResource");
Expand All @@ -100,8 +91,9 @@ public void k8sResource_whenRun_generatesK8sManifestsWithProjectLabels() throws
.contains("validating");
}

@Test
public void ocResource_whenRun_generatesOpenShiftManifestsWithProjectLabels() throws IOException, ParseException {
@ParameterizedTest(name = "{0}")
@MethodSource("data")
void ocResource_whenRun_generatesOpenShiftManifestsWithProjectLabels(String description, String expectedDir, String[] arguments) throws IOException, ParseException {
// When
List<String> gradleArgs = new ArrayList<>(Arrays.asList(arguments));
gradleArgs.add("ocResource");
Expand Down
Loading

0 comments on commit 3724101

Please sign in to comment.