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

pipelines-control-service: upgrade JUnit 4 to JUnit 5 #208

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ dependencies { // Implementation dependencies are found on compile classpath of
implementation versions.'net.javacrumbs.shedlock:shedlock-provider-jdbc-template'



testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation versions.'com.mmnaseri.utils:spring-data-mock'
Expand All @@ -75,6 +74,8 @@ dependencies { // Implementation dependencies are found on compile classpath of
testImplementation versions.'org.testcontainers:testcontainers'
testImplementation versions.'org.springframework.security.kerberos:spring-security-kerberos-test'
testImplementation versions.'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'


// transitive dependencies version force
Expand Down Expand Up @@ -113,10 +114,12 @@ test {

testSets {
integrationTest { dirName = 'integration-test' }
tasks.integrationTest { useJUnitPlatform() }
}

configurations {
runtime.exclude group: "javax.servlet", module: "servlet-api" //exclude Servlet 2 (comes as transitive dependency from remotefs module)
runtime.exclude group: "javax.servlet", module: "servlet-api"
//exclude Servlet 2 (comes as transitive dependency from remotefs module)
runtime.exclude group: "org.slf4j", module: "slf4j-log4j12" //log4j and slf4j cannot co-exist
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@
import com.vmware.taurus.service.credentials.JobCredentialsService;
import com.vmware.taurus.service.model.DataJob;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;

import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;


// TODO: move to junit 5
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ControlplaneApplication.class)
public class DataJobCrudIT extends BaseIT {

Expand All @@ -48,7 +43,7 @@ public void testDataJobCrud() throws Exception {
lambdaMatcher(s -> s.endsWith(String.format("/data-jobs/for-team/%s/jobs/%s", TEST_TEAM_NAME,
TEST_JOB_NAME)))));
//Validate - the job is created
Assert.assertTrue(jobsRepository.existsById(TEST_JOB_NAME));
Assertions.assertTrue(jobsRepository.existsById(TEST_JOB_NAME));

// Execute create job with no user
mockMvc.perform(post(String.format("/data-jobs/for-team/%s/jobs", TEST_TEAM_NAME))
Expand All @@ -68,15 +63,15 @@ public void testDataJobCrud() throws Exception {
// Validate keytab created
var keytabSecretName = JobCredentialsService.getJobKeytabKubernetesSecretName(TEST_JOB_NAME);
var keytabSecretData = dataJobsKubernetesService.getSecretData(keytabSecretName);
Assert.assertFalse(keytabSecretData.isEmpty());
Assert.assertTrue(keytabSecretData.containsKey("keytab"));
Assert.assertTrue(ArrayUtils.isNotEmpty(keytabSecretData.get("keytab")));
Assertions.assertFalse(keytabSecretData.isEmpty());
Assertions.assertTrue(keytabSecretData.containsKey("keytab"));
Assertions.assertTrue(ArrayUtils.isNotEmpty(keytabSecretData.get("keytab")));

// Validate persisted job
var jobFromDbOptional= jobsRepository.findById(TEST_JOB_NAME);
Assert.assertTrue(jobFromDbOptional.isPresent());
Assertions.assertTrue(jobFromDbOptional.isPresent());
var jobFromDb = jobFromDbOptional.get();
Assert.assertEquals(TEST_JOB_SCHEDULE, jobFromDb.getJobConfig().getSchedule());
Assertions.assertEquals(TEST_JOB_SCHEDULE, jobFromDb.getJobConfig().getSchedule());

// Execute list jobs
// deprecated jobsList in favour of jobsQuery
Expand Down Expand Up @@ -183,10 +178,10 @@ public void testDataJobCrud() throws Exception {

// Validate keytab deleted
keytabSecretData = dataJobsKubernetesService.getSecretData(keytabSecretName);
Assert.assertTrue(keytabSecretData.isEmpty());
Assertions.assertTrue(keytabSecretData.isEmpty());

// Validate job deleted from db
Assert.assertFalse(jobsRepository.existsById(TEST_JOB_NAME));
Assertions.assertFalse(jobsRepository.existsById(TEST_JOB_NAME));

testDataJobPostDeleteWebHooks();
}
Expand All @@ -201,7 +196,7 @@ private void testDataJobPostCreateWebHooks() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
// Validate - the job is NOT created
Assert.assertFalse(jobsRepository.existsById(TEST_CLIENT_ERROR_JOB_NAME));
Assertions.assertFalse(jobsRepository.existsById(TEST_CLIENT_ERROR_JOB_NAME));

// Post Create WebHook will prevent job creation and the result will be error 503 with no job created
String internalServerErrorDataJobRequestBody = getDataJobRequestBody(TEST_INTERNAL_ERROR_TEAM,
Expand All @@ -212,7 +207,7 @@ private void testDataJobPostCreateWebHooks() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isServiceUnavailable());
// Validate - the job is NOT created
Assert.assertFalse(jobsRepository.existsById(TEST_INTERNAL_ERROR_JOB_NAME));
Assertions.assertFalse(jobsRepository.existsById(TEST_INTERNAL_ERROR_JOB_NAME));

// Post Create WebHook will retry 2 times and finally will allow job creation
String retriedErrorDataJobRequestBody = getDataJobRequestBody(TEST_INTERNAL_ERROR_RETRIED_TEAM,
Expand All @@ -223,7 +218,7 @@ private void testDataJobPostCreateWebHooks() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated());
// Validate - the job is created
Assert.assertTrue(jobsRepository.existsById(TEST_INTERNAL_ERROR_RETRIED_JOB_NAME));
Assertions.assertTrue(jobsRepository.existsById(TEST_INTERNAL_ERROR_RETRIED_JOB_NAME));
}

private void testDataJobPostDeleteWebHooks() throws Exception {
Expand All @@ -238,7 +233,7 @@ private void testDataJobPostDeleteWebHooks() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
// Validate - the job is NOT deleted
Assert.assertTrue(jobsRepository.existsById(TEST_CLIENT_ERROR_JOB_NAME));
Assertions.assertTrue(jobsRepository.existsById(TEST_CLIENT_ERROR_JOB_NAME));
//Clean Up
jobsRepository.delete(clientErrorEntity);

Expand All @@ -253,7 +248,7 @@ private void testDataJobPostDeleteWebHooks() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isServiceUnavailable());
// Validate - the job is NOT deleted
Assert.assertTrue(jobsRepository.existsById(TEST_INTERNAL_ERROR_JOB_NAME));
Assertions.assertTrue(jobsRepository.existsById(TEST_INTERNAL_ERROR_JOB_NAME));
//Clean Up
jobsRepository.delete(internalServerEntity);

Expand All @@ -268,7 +263,7 @@ private void testDataJobPostDeleteWebHooks() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
// Validate - the job is deleted
Assert.assertFalse(jobsRepository.existsById(TEST_INTERNAL_ERROR_RETRIED_JOB_NAME));
Assertions.assertFalse(jobsRepository.existsById(TEST_INTERNAL_ERROR_RETRIED_JOB_NAME));
//Clean Up
jobsRepository.delete(internalServerEntity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import com.vmware.taurus.service.model.JobDeploymentStatus;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.StringUtils;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
Expand All @@ -29,7 +28,6 @@
import org.springframework.core.task.TaskExecutor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MvcResult;

import java.util.Optional;
Expand All @@ -40,8 +38,6 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

// TODO: move to junit 5
@RunWith(SpringRunner.class)
@Import({DataJobDeploymentCrudIT.TaskExecutorConfig.class})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ControlplaneApplication.class)
public class DataJobDeploymentCrudIT extends BaseIT {
Expand All @@ -63,7 +59,7 @@ public TaskExecutor taskExecutor() {

}

@Before
@BeforeEach
public void setup() throws Exception {
String dataJobRequestBody = getDataJobRequestBody(TEST_TEAM_NAME, TEST_JOB_NAME);

Expand Down Expand Up @@ -105,10 +101,10 @@ public void testDataJobDeploymentCrud() throws Exception {

DataJobVersion testDataJobVersion = new ObjectMapper()
.readValue(jobUploadResult.getResponse().getContentAsString(), DataJobVersion.class);
Assert.assertNotNull(testDataJobVersion);
Assertions.assertNotNull(testDataJobVersion);

String testJobVersionSha = testDataJobVersion.getVersionSha();
Assert.assertFalse(StringUtils.isBlank(testJobVersionSha));
Assertions.assertFalse(StringUtils.isBlank(testJobVersionSha));

// Setup
String dataJobDeploymentRequestBody = getDataJobDeploymentRequestBody(testJobVersionSha);
Expand Down Expand Up @@ -145,13 +141,13 @@ public void testDataJobDeploymentCrud() throws Exception {
String jobDeploymentName = JobImageDeployer.getCronJobName(TEST_JOB_NAME);
// Verify job deployment created
Optional<JobDeploymentStatus> cronJobOptional = dataJobsKubernetesService.readCronJob(jobDeploymentName);
Assert.assertTrue(cronJobOptional.isPresent());
Assertions.assertTrue(cronJobOptional.isPresent());
JobDeploymentStatus cronJob = cronJobOptional.get();
Assert.assertEquals(testJobVersionSha, cronJob.getGitCommitSha());
Assert.assertEquals(DataJobMode.RELEASE.toString(), cronJob.getMode());
Assert.assertEquals(true, cronJob.getEnabled());
Assert.assertTrue(cronJob.getImageName().endsWith(testJobVersionSha));
Assert.assertEquals("user", cronJob.getLastDeployedBy());
Assertions.assertEquals(testJobVersionSha, cronJob.getGitCommitSha());
Assertions.assertEquals(DataJobMode.RELEASE.toString(), cronJob.getMode());
Assertions.assertEquals(true, cronJob.getEnabled());
Assertions.assertTrue(cronJob.getImageName().endsWith(testJobVersionSha));
Assertions.assertEquals("user", cronJob.getLastDeployedBy());

// Execute get job deployment with no user
mockMvc.perform(get(String.format("/data-jobs/for-team/%s/jobs/%s/deployments/%s",
Expand Down Expand Up @@ -183,9 +179,9 @@ public void testDataJobDeploymentCrud() throws Exception {
// Verify response
DataJobDeploymentStatus jobDeployment = mapper.readValue(result.getResponse().getContentAsString(),
DataJobDeploymentStatus.class);
Assert.assertEquals(testJobVersionSha, jobDeployment.getJobVersion());
Assert.assertEquals(DataJobMode.RELEASE, jobDeployment.getMode());
Assert.assertEquals(true, jobDeployment.getEnabled());
Assertions.assertEquals(testJobVersionSha, jobDeployment.getJobVersion());
Assertions.assertEquals(DataJobMode.RELEASE, jobDeployment.getMode());
Assertions.assertEquals(true, jobDeployment.getEnabled());

// Execute disable deployment no user
mockMvc.perform(patch(String.format("/data-jobs/for-team/%s/jobs/%s/deployments/%s",
Expand Down Expand Up @@ -218,9 +214,9 @@ public void testDataJobDeploymentCrud() throws Exception {

// Verify deployment disabled
cronJobOptional = dataJobsKubernetesService.readCronJob(jobDeploymentName);
Assert.assertTrue(cronJobOptional.isPresent());
Assertions.assertTrue(cronJobOptional.isPresent());
cronJob = cronJobOptional.get();
Assert.assertEquals(false, cronJob.getEnabled());
Assertions.assertEquals(false, cronJob.getEnabled());

// Execute delete deployment with no user
mockMvc.perform(delete(String.format("/data-jobs/for-team/%s/jobs/%s/deployments/%s",
Expand Down Expand Up @@ -252,10 +248,10 @@ public void testDataJobDeploymentCrud() throws Exception {

// Verify deployment deleted
cronJobOptional = dataJobsKubernetesService.readCronJob(jobDeploymentName);
Assert.assertTrue(cronJobOptional.isEmpty());
Assertions.assertTrue(cronJobOptional.isEmpty());
}

@After
@AfterEach
public void cleanUp() throws Exception {
mockMvc.perform(delete(String.format("/data-jobs/for-team/%s/jobs/%s/sources",
TEST_TEAM_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

import com.vmware.taurus.ControlplaneApplication;
import com.vmware.taurus.datajobs.it.common.BaseIT;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.ResultActions;

import static org.hamcrest.Matchers.greaterThan;
Expand All @@ -22,8 +20,6 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

// TODO: move to junit 5
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ControlplaneApplication.class)
public class DataJobGraphQLIT extends BaseIT {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,18 @@
import com.vmware.taurus.ControlplaneApplication;
import com.vmware.taurus.datajobs.it.common.BaseIT;
import com.vmware.taurus.properties.service.PropertiesRepository;
import com.vmware.taurus.service.JobsRepository;
import com.vmware.taurus.service.credentials.JobCredentialsService;
import com.vmware.taurus.service.model.DataJob;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;

import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;


// TODO: move to junit 5
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ControlplaneApplication.class)
public class DataJobPropertiesIT extends BaseIT {

Expand Down Expand Up @@ -71,5 +61,4 @@ public void testDataJobProperties() throws Exception {


}

}
Loading