diff --git a/spring-cloud-dataflow-registry/src/test/java/org/springframework/cloud/dataflow/registry/support/AppResourceCommonTests.java b/spring-cloud-dataflow-registry/src/test/java/org/springframework/cloud/dataflow/registry/support/AppResourceCommonTests.java index c51c2ca679..a98fb182cc 100644 --- a/spring-cloud-dataflow-registry/src/test/java/org/springframework/cloud/dataflow/registry/support/AppResourceCommonTests.java +++ b/spring-cloud-dataflow-registry/src/test/java/org/springframework/cloud/dataflow/registry/support/AppResourceCommonTests.java @@ -47,7 +47,7 @@ class AppResourceCommonTests { private AppResourceCommon appResourceCommon = new AppResourceCommon(new MavenProperties(), resourceLoader); @Test - public void testBadNamedJars() throws Exception { + void badNamedJars() throws Exception { UrlResource urlResource = new UrlResource("https://repo.maven.apache.org/maven2/org/springframework/cloud/stream/app/file-sink-rabbit/5.0.0/file-sink-rabbit.jar"); assertThatIllegalArgumentException().isThrownBy( () -> appResourceCommon.getUrlResourceVersion(urlResource)); } @@ -91,7 +91,7 @@ void dockerUriString() throws Exception { } @Test - public void testJarMetadataUriDockerApp() throws Exception { + void jarMetadataUriDockerApp() throws Exception { String appUri = "docker:springcloudstream/log-sink-rabbit:5.0.0"; String metadataUri = "https://repo.maven.apache.org/maven2/org/springframework/cloud/stream/app/file-sink-rabbit/5.0.0/file-sink-rabbit-5.0.0.jar"; appResourceCommon.getMetadataResource(new URI(appUri), new URI(metadataUri)); @@ -99,7 +99,7 @@ public void testJarMetadataUriDockerApp() throws Exception { } @Test - public void testMetadataUriHttpApp() throws Exception { + void metadataUriHttpApp() throws Exception { String appUri = "https://repo.maven.apache.org/maven2/org/springframework/cloud/stream/app/file-sink-rabbit/5.0.0/file-sink-rabbit-5.0.0.jar"; Resource metadataResource = appResourceCommon.getMetadataResource(new URI(appUri), null); assertThat(metadataResource instanceof UrlResource).isTrue(); @@ -107,7 +107,7 @@ public void testMetadataUriHttpApp() throws Exception { } @Test - public void testMetadataUriDockerApp() throws Exception { + void metadataUriDockerApp() throws Exception { String appUri = "docker:springcloudstream/log-sink-rabbit:5.0.0"; Resource metadataResource = appResourceCommon.getMetadataResource(new URI(appUri), null); assertThat(metadataResource).isNotNull(); @@ -168,7 +168,7 @@ void jars() throws MalformedURLException { } @Test - public void testGetResourceWithoutVersion() { + void testGetResourceWithoutVersion() { assertThat(appResourceCommon.getResourceWithoutVersion( MavenResource.parse("org.springframework.cloud.stream.app:aggregate-counter-sink-rabbit:war:exec:5.0.0"))) .isEqualTo("maven://org.springframework.cloud.stream.app:aggregate-counter-sink-rabbit:war:exec"); @@ -181,21 +181,21 @@ public void testGetResourceWithoutVersion() { } @Test - public void testGetResource() { + void testGetResource() { String mavenUri = "maven://org.springframework.cloud.stream.app:aggregate-counter-sink-rabbit:5.0.0"; Resource resource = appResourceCommon.getResource(mavenUri); assertThat(resource).isInstanceOf(MavenResource.class); } @Test - public void testGetResourceVersion() { + void testGetResourceVersion() { String mavenUri = "maven://org.springframework.cloud.stream.app:aggregate-counter-sink-rabbit:5.0.0"; String version = appResourceCommon.getResourceVersion(appResourceCommon.getResource(mavenUri)); assertThat(version).isEqualTo("5.0.0"); } @Test - public void testGetMetadataResourceVersion() { + void getMetadataResourceVersion() { String httpUri = "http://repo.maven.apache.org/maven2/org/springframework/cloud/stream/app/cassandra-sink-rabbit/5.0.1-SNAPSHOT/cassandra-sink-rabbit-5.0.1-SNAPSHOT-metadata.jar"; String version = appResourceCommon.getResourceVersion(appResourceCommon.getResource(httpUri)); assertThat(version).isEqualTo("5.0.1-SNAPSHOT"); diff --git a/spring-cloud-dataflow-registry/src/test/java/org/springframework/cloud/dataflow/registry/support/DockerImageTests.java b/spring-cloud-dataflow-registry/src/test/java/org/springframework/cloud/dataflow/registry/support/DockerImageTests.java index eb4ae58cd6..49ff0ee8a5 100644 --- a/spring-cloud-dataflow-registry/src/test/java/org/springframework/cloud/dataflow/registry/support/DockerImageTests.java +++ b/spring-cloud-dataflow-registry/src/test/java/org/springframework/cloud/dataflow/registry/support/DockerImageTests.java @@ -115,7 +115,7 @@ public static List data() { @MethodSource("data") @ParameterizedTest - public void dockerImageParsing(String description, String fullImageName, String expectedHost, String expectedNamespace, String expectedRepo, String expectedNamespaceAndRepo, String expectedTag) { + void dockerImageParsing(String description, String fullImageName, String expectedHost, String expectedNamespace, String expectedRepo, String expectedNamespaceAndRepo, String expectedTag) { initDockerImageTests(description, fullImageName, expectedHost, expectedNamespace, expectedRepo, expectedNamespaceAndRepo, expectedTag); diff --git a/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/support/DatabaseTypeTests.java b/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/support/DatabaseTypeTests.java index 7e267f4194..fae0d79b11 100644 --- a/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/support/DatabaseTypeTests.java +++ b/spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/db/support/DatabaseTypeTests.java @@ -20,7 +20,6 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; -import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; import org.springframework.cloud.dataflow.server.db.DB2_11_5_ContainerSupport; import org.springframework.cloud.dataflow.server.db.MariaDB_10_6_ContainerSupport; import org.springframework.cloud.dataflow.server.db.MariaDB_11_ContainerSupport; @@ -31,8 +30,6 @@ import org.springframework.cloud.dataflow.server.db.SqlServer_2019_ContainerSupport; import org.springframework.cloud.dataflow.server.db.SqlServer_2022_ContainerSupport; -import static org.assertj.core.api.Assertions.assertThat; - class DatabaseTypeTests { @Nested diff --git a/spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/JobCommandTests.java b/spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/JobCommandTests.java index ab4b8b9504..d341da75cb 100644 --- a/spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/JobCommandTests.java +++ b/spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/JobCommandTests.java @@ -51,8 +51,8 @@ import org.springframework.shell.table.Table; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Glenn Renfro @@ -159,8 +159,9 @@ void viewExecution() { logger.info("Retrieve Job Execution Detail by Id"); Table table = getTable(job().executionDisplay(getFirstJobExecutionIdFromTable())); verifyColumnNumber(table, 2); - assertEquals("Number of expected rows returned from the table is incorrect", 19, - table.getModel().getRowCount()); + assertEquals(19, + table.getModel().getRowCount(), + "Number of expected rows returned from the table is incorrect"); int rowNumber = 0; checkCell(table, rowNumber++, 0, "Key "); checkCell(table, rowNumber++, 0, "Job Execution Id "); @@ -180,14 +181,14 @@ void viewExecution() { checkCell(table, rowNumber++, 0, "Job Parameters "); int paramRowOne = rowNumber; - assertTrue("the table did not contain the correct job parameters for job parameter value foo", - checkModelColumn(paramRowOne, table, "-foo(java.lang.String) ")); + assertTrue(checkModelColumn(paramRowOne, table, "-foo(java.lang.String) "), + "the table did not contain the correct job parameters for job parameter value foo"); - assertTrue("the table did not contain the correct job parameters for job parameter value bar", - checkModelColumn(paramRowOne, table, "bar(java.lang.String) ")); + assertTrue(checkModelColumn(paramRowOne, table, "bar(java.lang.String) "), + "the table did not contain the correct job parameters for job parameter value bar"); - assertTrue("the table did not contain the correct job parameters for job parameter value baz", - checkModelColumn(paramRowOne, table, "baz(java.lang.Long) ")); + assertTrue(checkModelColumn(paramRowOne, table, "baz(java.lang.Long) "), + "the table did not contain the correct job parameters for job parameter value baz"); } diff --git a/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/AbstractIntegrationTest.java b/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/AbstractIntegrationTest.java index 85d9abb5a3..565c47e0c5 100644 --- a/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/AbstractIntegrationTest.java +++ b/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/AbstractIntegrationTest.java @@ -20,9 +20,9 @@ import javax.sql.DataSource; -import org.junit.After; -import org.junit.Rule; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,7 +69,7 @@ public abstract class AbstractIntegrationTest extends AbstractAssertReleaseDeplo private final Logger logger = LoggerFactory.getLogger(getClass()); - @Rule + @RegisterExtension public LogTestNameRule logTestName = new LogTestNameRule(); @Autowired @@ -102,7 +102,7 @@ public void beforeDumpSchema() { dbScriptFile.deleteOnExit(); } - @After + @AfterEach public void restoreEmptySchema() { // Add a sleep for now to give the local deployer a chance to install the app. This // should go away once we introduce spring state machine. diff --git a/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/LogTestNameRule.java b/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/LogTestNameRule.java index bb958b44b4..51468cdbd4 100644 --- a/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/LogTestNameRule.java +++ b/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/LogTestNameRule.java @@ -15,25 +15,27 @@ */ package org.springframework.cloud.skipper.server; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Mark Pollack */ -public class LogTestNameRule extends TestWatcher { +public class LogTestNameRule implements BeforeEachCallback, AfterEachCallback { private final static Logger log = LoggerFactory.getLogger("junit.logTestName"); @Override - protected void starting(Description description) { - log.info("Starting Test {}", description.getMethodName()); + public void afterEach(ExtensionContext extensionContext) throws Exception { + log.info("Finished Test: {}", extensionContext.getRequiredTestMethod().getName()); } @Override - protected void finished(Description description) { - log.info("Finished Test {}", description.getMethodName()); + public void beforeEach(ExtensionContext extensionContext) throws Exception { + log.info("Starting Test {}", extensionContext.getRequiredTestMethod().getName()); } + } diff --git a/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/controller/AbstractControllerTests.java b/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/controller/AbstractControllerTests.java index 86b1ec749a..4e59f87248 100644 --- a/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/controller/AbstractControllerTests.java +++ b/spring-cloud-skipper/spring-cloud-skipper-server-core/src/test/java/org/springframework/cloud/skipper/server/controller/AbstractControllerTests.java @@ -15,7 +15,7 @@ */ package org.springframework.cloud.skipper.server.controller; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,7 +68,7 @@ public void cleanupReleaseRepository() { this.releaseRepository.deleteAll(); } - @After + @AfterEach public void cleanupReleases() throws Exception { // Add a sleep for now to give the local deployer a chance to install the app. // This diff --git a/spring-cloud-starter-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/local/security/LdapServerResource.java b/spring-cloud-starter-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/local/security/LdapServerResource.java deleted file mode 100644 index 10f8a07ed3..0000000000 --- a/spring-cloud-starter-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/local/security/LdapServerResource.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2016-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.cloud.dataflow.server.local.security; - -import java.io.File; -import java.io.FileOutputStream; -import java.util.UUID; - -import org.junit.rules.ExternalResource; -import org.junit.rules.TemporaryFolder; - -import org.springframework.core.io.ClassPathResource; -import org.springframework.security.ldap.server.ApacheDSContainer; -import org.springframework.test.util.TestSocketUtils; -import org.springframework.util.Assert; -import org.springframework.util.FileCopyUtils; - -/** - * @author Marius Bogoevici - * @author Gunnar Hillert - */ -public class LdapServerResource extends ExternalResource { - - private static final String LDAP_PORT_PROPERTY = "ldap.port"; - - private static final ClassPathResource keyStoreResource = new ClassPathResource( - "/org/springframework/cloud/dataflow/server/local/security/dataflow.keystore"); - - private static final ClassPathResource trustStoreResource = new ClassPathResource( - "/org/springframework/cloud/dataflow/server/local/security/dataflow.truststore"); - - private static final String TRUST_STORE_PASSWORD = "dataflow"; - - private static final String KEY_STORE_PASSWORD = "dataflow"; - - private String originalLdapPort; - - private ApacheDSContainer apacheDSContainer; - - private TemporaryFolder temporaryFolder = new TemporaryFolder(); - - private File workingDir; - - private boolean enabledSsl = false; - - private final String ldapFileName; - - public LdapServerResource() { - super(); - this.ldapFileName = "testUsers.ldif"; - } - - public LdapServerResource(String ldapFileName) { - super(); - this.ldapFileName = ldapFileName; - } - - public LdapServerResource(boolean enabledSsl) { - this.enabledSsl = true; - this.ldapFileName = "testUsers.ldif"; - } - - @Override - protected void before() throws Throwable { - - originalLdapPort = System.getProperty(LDAP_PORT_PROPERTY); - - temporaryFolder.create(); - apacheDSContainer = new ApacheDSContainer("dc=springframework,dc=org", - "classpath:org/springframework/cloud/dataflow/server/local/security/" + this.ldapFileName); - int ldapPort = TestSocketUtils.findAvailableTcpPort(); - if (enabledSsl) { - - apacheDSContainer.setLdapOverSslEnabled(true); - - final File temporaryKeyStoreFile = new File(temporaryFolder.getRoot(), "dataflow.keystore"); - final File temporaryTrustStoreFile = new File(temporaryFolder.getRoot(), "dataflow.truststore"); - - FileCopyUtils.copy(keyStoreResource.getInputStream(), new FileOutputStream(temporaryKeyStoreFile)); - FileCopyUtils.copy(trustStoreResource.getInputStream(), new FileOutputStream(temporaryTrustStoreFile)); - - Assert.isTrue(temporaryKeyStoreFile.isFile(), "temporaryKeyStoreFile.isFile can not be null"); - Assert.isTrue(temporaryTrustStoreFile.isFile(), "temporaryTrustStoreFile.isfile can not be null"); - - apacheDSContainer.setKeyStoreFile(temporaryKeyStoreFile); - apacheDSContainer.setCertificatePassord(KEY_STORE_PASSWORD); - - System.setProperty("javax.net.ssl.trustStorePassword", TRUST_STORE_PASSWORD); - System.setProperty("javax.net.ssl.trustStore", temporaryTrustStoreFile.getAbsolutePath()); - System.setProperty("javax.net.ssl.trustStoreType", "jks"); - } - - apacheDSContainer.setPort(ldapPort); - apacheDSContainer.afterPropertiesSet(); - workingDir = new File(temporaryFolder.getRoot(), UUID.randomUUID().toString()); - apacheDSContainer.setWorkingDirectory(workingDir); - apacheDSContainer.start(); - System.setProperty(LDAP_PORT_PROPERTY, Integer.toString(ldapPort)); - } - - @Override - protected void after() { - apacheDSContainer.stop(); - try { - apacheDSContainer.destroy(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally { - - if (originalLdapPort != null) { - System.setProperty(LDAP_PORT_PROPERTY, originalLdapPort); - } - else { - System.clearProperty(LDAP_PORT_PROPERTY); - } - - System.clearProperty("javax.net.ssl.trustStorePassword"); - System.clearProperty("javax.net.ssl.trustStore"); - System.clearProperty("javax.net.ssl.trustStoreType"); - - temporaryFolder.delete(); - } - } - -} diff --git a/spring-cloud-starter-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/single/LocalConfigurationTests.java b/spring-cloud-starter-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/single/LocalConfigurationTests.java index ae22c29d30..e11918b451 100644 --- a/spring-cloud-starter-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/single/LocalConfigurationTests.java +++ b/spring-cloud-starter-dataflow-server/src/test/java/org/springframework/cloud/dataflow/server/single/LocalConfigurationTests.java @@ -40,11 +40,11 @@ import org.springframework.core.io.ResourceLoader; import org.springframework.test.util.TestSocketUtils; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for {@link LocalTestDataFlowServer}. @@ -56,19 +56,19 @@ * @author Corneil du Plessis */ @Disabled -public class LocalConfigurationTests { +class LocalConfigurationTests { private ConfigurableApplicationContext context; @AfterEach - public void tearDown() { + void tearDown() { if (context != null) { context.close(); } } @Test - public void testConfig() { + void config() { SpringApplication app = new SpringApplication(LocalTestDataFlowServer.class); int randomPort = TestSocketUtils.findAvailableTcpPort(); String dataSourceUrl = String.format("jdbc:h2:tcp://localhost:%s/mem:dataflow;DATABASE_TO_UPPER=FALSE", randomPort); @@ -80,7 +80,7 @@ public void testConfig() { } @Test - public void testLocalAutoConfigApplied() throws Exception { + void localAutoConfigApplied() throws Exception { SpringApplication app = new SpringApplication(LocalTestDataFlowServer.class); context = app.run(new String[] { "--spring.cloud.kubernetes.enabled=false", "--server.port=0" }); // LocalDataFlowServerAutoConfiguration also adds docker and maven resource loaders. @@ -92,7 +92,7 @@ public void testLocalAutoConfigApplied() throws Exception { } @Test - public void testConfigWithStreamsDisabled() { + void configWithStreamsDisabled() { SpringApplication app = new SpringApplication(LocalTestDataFlowServer.class); context = app.run(new String[] { "--spring.cloud.kubernetes.enabled=false", "--server.port=0", "--" + FeaturesProperties.FEATURES_PREFIX + "." + FeaturesProperties.STREAMS_ENABLED + "=false" }); @@ -108,7 +108,7 @@ public void testConfigWithStreamsDisabled() { } @Test - public void testConfigWithTasksDisabled() { + void configWithTasksDisabled() { SpringApplication app = new SpringApplication(LocalTestDataFlowServer.class); context = app.run(new String[] { "--spring.cloud.kubernetes.enabled=false", "--server.port=0", "--" + FeaturesProperties.FEATURES_PREFIX + "." + FeaturesProperties.TASKS_ENABLED + "=false" }); @@ -124,7 +124,7 @@ public void testConfigWithTasksDisabled() { } @Test - public void testNoDataflowConfig() { + void noDataflowConfig() { SpringApplication app = new SpringApplication(LocalTestNoDataFlowServer.class); context = app.run(new String[] { "--spring.cloud.kubernetes.enabled=false", "--server.port=0", "--spring.jpa.database=H2", "--spring.flyway.enabled=false" }); assertThat(context.containsBean("appRegistry"), is(false));