Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tests): convert junit4 based test cases to junit5, clean up and unpin mockito in orca #4484

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions orca-api-tck/orca-api-tck.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dependencies {

// Test framework dependencies
api("org.junit.jupiter:junit-jupiter-api")
api("org.junit.platform:junit-platform-runner")
// testImplementation "org.assertj:assertj-core"
api("io.strikt:strikt-core")
api("dev.minutest:minutest")
Expand All @@ -36,7 +35,6 @@ dependencies {
api("org.springframework.security:spring-security-config")
api("com.ninja-squad:springmockk")

testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

Expand Down
7 changes: 1 addition & 6 deletions orca-api/orca-api.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ dependencies {
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")

testRuntimeOnly("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")

dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.4.32")

sampleImplementation(sourceSets.main.runtimeClasspath)
Expand All @@ -58,7 +55,5 @@ tasks.withType(JavaCompile) {
}

test {
useJUnitPlatform {
includeEngines "junit-vintage", "junit-jupiter"
}
useJUnitPlatform()
}
7 changes: 5 additions & 2 deletions orca-bakery/orca-bakery.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ dependencies {
testImplementation("com.github.tomakehurst:wiremock:2.15.0")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.assertj:assertj-core")
testImplementation("org.mockito:mockito-core:2.25.0")
testImplementation("org.mockito:mockito-core")

testRuntimeOnly("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
test {
useJUnitPlatform()
}

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,25 @@

package com.netflix.spinnaker.orca.bakery.api

import com.github.tomakehurst.wiremock.junit.WireMockRule
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import com.github.tomakehurst.wiremock.WireMockServer
import com.netflix.spinnaker.orca.bakery.config.BakeryConfiguration
import com.netflix.spinnaker.orca.jackson.OrcaObjectMapper
import org.junit.Rule
import retrofit.RequestInterceptor
import retrofit.RetrofitError
import retrofit.client.OkClient
import spock.lang.Specification
import spock.lang.Subject
import static com.github.tomakehurst.wiremock.client.WireMock.*
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
import static com.google.common.net.HttpHeaders.LOCATION
import static java.net.HttpURLConnection.*
import static retrofit.Endpoints.newFixedEndpoint
import static retrofit.RestAdapter.LogLevel.FULL

class BakeryServiceSpec extends Specification {

@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort())
public WireMockServer wireMockServer = new WireMockServer()

@Subject BakeryService bakery

Expand All @@ -51,16 +50,23 @@ class BakeryServiceSpec extends Specification {

def mapper = OrcaObjectMapper.newInstance()

@BeforeAll
def setup() {
bakeURI = wireMockRule.url(bakePath)
statusURI = wireMockRule.url(statusPath)
wireMockServer.start()
bakeURI = wireMockServer.url(bakePath)
statusURI = wireMockServer.url(statusPath)

bakery = new BakeryConfiguration(
retrofitClient: new OkClient(),
retrofitLogLevel: FULL,
spinnakerRequestInterceptor: Mock(RequestInterceptor)
)
.buildService(wireMockRule.url("/"))
.buildService(wireMockServer.url("/"))
}

@AfterAll
def cleanup() {
wireMockServer.stop()
}

def "can lookup a bake status"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class BakeCloudFoundryManifestTaskTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
apply from: "$rootDir/gradle/groovy.gradle"

test {
useJUnitPlatform {
includeEngines "junit-vintage", "junit-jupiter"
}
useJUnitPlatform()
}

dependencies {
Expand All @@ -30,6 +28,5 @@ dependencies {
testImplementation(project(":orca-test"))
testImplementation(project(":orca-test-groovy"))

testRuntimeOnly("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
9 changes: 2 additions & 7 deletions orca-clouddriver/orca-clouddriver.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ apply from: "$rootDir/gradle/groovy.gradle"
apply from: "$rootDir/gradle/kotlin.gradle"

test {
useJUnitPlatform {
includeEngines "junit-vintage", "junit-jupiter"
}
useJUnitPlatform()
}

dependencies {
Expand Down Expand Up @@ -53,9 +51,7 @@ dependencies {
testImplementation("com.github.tomakehurst:wiremock:2.15.0")
testImplementation("org.springframework:spring-test")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.platform:junit-platform-runner")
testImplementation("org.assertj:assertj-core")
testImplementation("org.mockito:mockito-core:2.25.0")
testImplementation("org.mockito:mockito-junit-jupiter")
testImplementation("io.spinnaker.fiat:fiat-core:$fiatVersion")
testImplementation("dev.minutest:minutest")
Expand All @@ -66,8 +62,7 @@ dependencies {
testCompileOnly("org.projectlombok:lombok")
testAnnotationProcessor("org.projectlombok:lombok")

testRuntimeOnly("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,28 @@

package com.netflix.spinnaker.orca.clouddriver

import com.github.tomakehurst.wiremock.junit.WireMockRule
import com.github.tomakehurst.wiremock.WireMockServer
import com.netflix.spinnaker.config.ServiceEndpoint
import com.netflix.spinnaker.config.okhttp3.OkHttpClientBuilderProvider
import com.netflix.spinnaker.config.okhttp3.OkHttpClientProvider
import com.netflix.spinnaker.orca.clouddriver.config.CloudDriverConfiguration
import com.netflix.spinnaker.orca.clouddriver.config.CloudDriverConfigurationProperties
import com.netflix.spinnaker.orca.jackson.OrcaObjectMapper
import okhttp3.OkHttpClient
import org.junit.Rule
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import retrofit.RequestInterceptor
import retrofit.client.OkClient
import spock.lang.Specification
import spock.lang.Subject
import static com.github.tomakehurst.wiremock.client.WireMock.*
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
import static java.net.HttpURLConnection.HTTP_ACCEPTED
import static java.net.HttpURLConnection.HTTP_OK
import static retrofit.RestAdapter.LogLevel.FULL

class KatoRestServiceSpec extends Specification {

@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort())
public WireMockServer wireMockServer = new WireMockServer()

@Subject
KatoRestService service
Expand All @@ -57,7 +56,9 @@ class KatoRestServiceSpec extends Specification {

private static final taskId = "e1jbn3"

@BeforeAll
def setup() {
wireMockServer.start()
def cfg = new CloudDriverConfiguration()
def builder = cfg.clouddriverRetrofitBuilder(
mapper,
Expand All @@ -73,11 +74,16 @@ class KatoRestServiceSpec extends Specification {
}]),
FULL,
noopInterceptor,
new CloudDriverConfigurationProperties(clouddriver: new CloudDriverConfigurationProperties.CloudDriver(baseUrl: wireMockRule.url("/"))))
new CloudDriverConfigurationProperties(clouddriver: new CloudDriverConfigurationProperties.CloudDriver(baseUrl: wireMockServer.url("/"))))
service = cfg.katoDeployService(builder)
taskStatusService = cfg.cloudDriverTaskStatusService(builder)
}

@AfterAll
def cleanup() {
wireMockServer.stop()
}

def "can interpret the response from an operation request"() {
given: "kato accepts an operations request"
stubFor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import java.io.IOException;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
final class ManifestTest {
private static final ObjectMapper objectMapper = OrcaObjectMapper.newInstance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
public class ShrinkClusterStageTest {

private PipelineExecutionImpl pipeline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import static com.netflix.spinnaker.orca.TestUtils.getResource;
import static com.netflix.spinnaker.orca.TestUtils.getResourceAsStream;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -51,12 +53,9 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import retrofit.client.Response;
import retrofit.mime.TypedByteArray;

@RunWith(JUnitPlatform.class)
public final class WaitOnJobCompletionTest {
private ObjectMapper objectMapper;
private RetrySupport retrySupport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
import com.netflix.spinnaker.orca.pipeline.model.StageExecutionImpl;
import java.util.*;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
final class ResolveDeploySourceManifestTaskTest {

private static final Map<Object, Object> MANIFEST_1 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@
import java.util.Optional;
import org.assertj.core.api.AssertionsForClassTypes;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
final class WaitForManifestStableTaskTest {
private static final String UNSTABLE_MESSAGE = "manifest is unstable";
private static final String FAILED_MESSAGE = "manifest failed";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import static com.netflix.spinnaker.orca.api.pipeline.models.ExecutionType.PIPELINE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -36,7 +36,7 @@
import com.netflix.spinnaker.orca.pipeline.model.StageExecutionImpl;
import com.netflix.spinnaker.orca.pipeline.util.ArtifactUtils;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DeployAppEngineConfigurationTaskTest {
private final String CLOUD_OPERATION_TYPE = "deployAppengineConfiguration";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
final class FindArtifactFromPipelineExecutionTaskTest {
private static final String PIPELINE = "my pipeline";
private static final Artifact ARTIFACT_A =
Expand Down
2 changes: 0 additions & 2 deletions orca-core/orca-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ dependencies {
testImplementation(project(":orca-test-groovy"))
testImplementation("com.github.tomakehurst:wiremock:2.15.0")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.platform:junit-platform-runner")
testImplementation("org.assertj:assertj-core")
testImplementation("org.mockito:mockito-core")
testImplementation("org.mockito:mockito-junit-jupiter")
testImplementation("org.springframework.boot:spring-boot-starter-test")

testRuntimeOnly("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly "org.junit.vintage:junit-vintage-engine"
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
final class CompoundExecutionOperatorTest {
private static final String APPLICATION = "myapp";
private static final String PIPELINE = "mypipeline";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionType;
import com.netflix.spinnaker.orca.pipeline.model.PipelineExecutionImpl;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
final class PipelineExecutionRepositoryTest {
private static final String APPLICATION = "myapp";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import com.netflix.spinnaker.kork.web.exceptions.InvalidRequestException;
import com.netflix.spinnaker.orca.pipeline.util.ArtifactResolver.ResolveResult;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
final class ArtifactResolverTest {
private static final Artifact DOCKER_ARTIFACT =
Artifact.builder().name("my-docker-image").type("docker/image").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
final class ArtifactUtilsTest {
@Test
void withAccountNonNullAccount() {
Expand Down
Loading