diff --git a/bom/pom.xml b/bom/pom.xml index 377b65f275..316fcc39b9 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -114,6 +114,20 @@ + + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + + + junit + junit + + + + release diff --git a/env/pom.xml b/env/pom.xml index 69542b9d20..e34f3d6fd6 100644 --- a/env/pom.xml +++ b/env/pom.xml @@ -53,18 +53,6 @@ spotbugs-annotations true - - - - junit - junit - test - - - org.junit.vintage - junit-vintage-engine - test - org.junit.jupiter junit-jupiter-engine @@ -80,6 +68,12 @@ assertj-core test + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + org.mockito mockito-core diff --git a/env/src/test/java/com/sap/cloud/security/config/OAuth2ServiceConfigurationBuilderTest.java b/env/src/test/java/com/sap/cloud/security/config/OAuth2ServiceConfigurationBuilderTest.java index 59fed2ebd9..4aace4a225 100644 --- a/env/src/test/java/com/sap/cloud/security/config/OAuth2ServiceConfigurationBuilderTest.java +++ b/env/src/test/java/com/sap/cloud/security/config/OAuth2ServiceConfigurationBuilderTest.java @@ -5,8 +5,8 @@ */ package com.sap.cloud.security.config; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.net.URI; import java.util.Collections; @@ -19,7 +19,7 @@ public class OAuth2ServiceConfigurationBuilderTest { private OAuth2ServiceConfigurationBuilder cut; - @Before + @BeforeEach public void setUp() { cut = OAuth2ServiceConfigurationBuilder.forService(Service.XSUAA); } @@ -221,4 +221,4 @@ public void x509IntegrationTest() { assertThat(configuration.getCertUrl()).isEqualTo(URI.create(url)); assertThat(configuration.getCredentialType()).isEqualTo(CredentialType.X509); } -} \ No newline at end of file +} diff --git a/env/src/test/java/com/sap/cloud/security/json/DefaultJsonObjectTest.java b/env/src/test/java/com/sap/cloud/security/json/DefaultJsonObjectTest.java index 36f5de983f..9b11c79cc8 100644 --- a/env/src/test/java/com/sap/cloud/security/json/DefaultJsonObjectTest.java +++ b/env/src/test/java/com/sap/cloud/security/json/DefaultJsonObjectTest.java @@ -5,9 +5,9 @@ */ package com.sap.cloud.security.json; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.time.Instant; import java.time.LocalDate; @@ -31,7 +31,7 @@ public class DefaultJsonObjectTest { private DefaultJsonObject cut; - @Before + @BeforeEach public void setUp() { cut = createJsonParser(KEY_1, STRING_VALUE); } @@ -227,7 +227,7 @@ public void notVulnerableToStackOverflowException() { try { new DefaultJsonObject(deeplyNestedJsonObject); } catch (StackOverflowError e) { - Assert.fail("Encountered StackoverflowError."); + Assertions.fail("Encountered StackoverflowError."); } catch (Exception ignored) { } } @@ -251,4 +251,4 @@ private DefaultJsonObject createJsonParser(String key, Object value) { private String createJsonObjectString(String key, Object value) { return String.format("{%s : %s}", key, value); } -} \ No newline at end of file +} diff --git a/java-api/pom.xml b/java-api/pom.xml index cb5bb9427d..7056865d64 100644 --- a/java-api/pom.xml +++ b/java-api/pom.xml @@ -33,18 +33,6 @@ jakarta.servlet-api provided - - - - junit - junit - test - - - org.junit.vintage - junit-vintage-engine - test - org.junit.jupiter junit-jupiter-engine @@ -65,6 +53,12 @@ assertj-core test + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + commons-io commons-io diff --git a/java-api/src/test/java/com/sap/cloud/security/config/ClientCredentialsTest.java b/java-api/src/test/java/com/sap/cloud/security/config/ClientCredentialsTest.java index 1641b3f791..a32323ebbc 100644 --- a/java-api/src/test/java/com/sap/cloud/security/config/ClientCredentialsTest.java +++ b/java-api/src/test/java/com/sap/cloud/security/config/ClientCredentialsTest.java @@ -5,12 +5,12 @@ */ package com.sap.cloud.security.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class ClientCredentialsTest { ClientIdentity cut = new ClientCredentials("clientId", "clientSecret"); diff --git a/java-api/src/test/java/com/sap/cloud/security/config/CredentialTypeTest.java b/java-api/src/test/java/com/sap/cloud/security/config/CredentialTypeTest.java index 5bd51109f8..82bc11eee5 100644 --- a/java-api/src/test/java/com/sap/cloud/security/config/CredentialTypeTest.java +++ b/java-api/src/test/java/com/sap/cloud/security/config/CredentialTypeTest.java @@ -5,19 +5,19 @@ */ package com.sap.cloud.security.config; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CredentialTypeTest { @Test public void from() { - Assert.assertEquals(CredentialType.X509, CredentialType.from("x509")); - Assert.assertEquals(CredentialType.X509_GENERATED, CredentialType.from("X509_GENERATED")); - Assert.assertEquals(CredentialType.X509_PROVIDED, CredentialType.from("X509_PROVIDED")); - Assert.assertEquals(CredentialType.X509_ATTESTED, CredentialType.from("X509_ATTESTED")); - Assert.assertEquals(CredentialType.X509_ATTESTED, CredentialType.from("x509_attested")); - Assert.assertEquals(CredentialType.INSTANCE_SECRET, CredentialType.from("instance-secret")); - Assert.assertEquals(CredentialType.BINDING_SECRET, CredentialType.from("binding-secret")); + Assertions.assertEquals(CredentialType.X509, CredentialType.from("x509")); + Assertions.assertEquals(CredentialType.X509_GENERATED, CredentialType.from("X509_GENERATED")); + Assertions.assertEquals(CredentialType.X509_PROVIDED, CredentialType.from("X509_PROVIDED")); + Assertions.assertEquals(CredentialType.X509_ATTESTED, CredentialType.from("X509_ATTESTED")); + Assertions.assertEquals(CredentialType.X509_ATTESTED, CredentialType.from("x509_attested")); + Assertions.assertEquals(CredentialType.INSTANCE_SECRET, CredentialType.from("instance-secret")); + Assertions.assertEquals(CredentialType.BINDING_SECRET, CredentialType.from("binding-secret")); } } \ No newline at end of file diff --git a/java-api/src/test/java/com/sap/cloud/security/config/ServiceTest.java b/java-api/src/test/java/com/sap/cloud/security/config/ServiceTest.java index 447a30a579..0c24686362 100644 --- a/java-api/src/test/java/com/sap/cloud/security/config/ServiceTest.java +++ b/java-api/src/test/java/com/sap/cloud/security/config/ServiceTest.java @@ -5,7 +5,7 @@ */ package com.sap.cloud.security.config; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -21,4 +21,4 @@ public void getCFNameOfXsuaa_shouldReturnCorrectName() { assertThat(Service.XSUAA.getCFName()).isEqualTo("xsuaa"); } -} \ No newline at end of file +} diff --git a/java-api/src/test/java/com/sap/cloud/security/token/TokenTest.java b/java-api/src/test/java/com/sap/cloud/security/token/TokenTest.java index 96b0d60332..1dff114f9b 100644 --- a/java-api/src/test/java/com/sap/cloud/security/token/TokenTest.java +++ b/java-api/src/test/java/com/sap/cloud/security/token/TokenTest.java @@ -5,10 +5,10 @@ */ package com.sap.cloud.security.token; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class TokenTest { diff --git a/java-security-test/pom.xml b/java-security-test/pom.xml index 0c75767d16..049c5e8ef2 100644 --- a/java-security-test/pom.xml +++ b/java-security-test/pom.xml @@ -22,10 +22,6 @@ com.sap.cloud.security java-security - - junit - junit - org.junit.jupiter junit-jupiter-api @@ -76,6 +72,18 @@ assertj-core test + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + + + junit + junit + + + diff --git a/java-security-test/src/test/java/com/sap/cloud/security/test/JwtGeneratorTest.java b/java-security-test/src/test/java/com/sap/cloud/security/test/JwtGeneratorTest.java index 5277346b84..ccd16d5ec8 100644 --- a/java-security-test/src/test/java/com/sap/cloud/security/test/JwtGeneratorTest.java +++ b/java-security-test/src/test/java/com/sap/cloud/security/test/JwtGeneratorTest.java @@ -12,11 +12,10 @@ import com.sap.cloud.security.token.Token; import com.sap.cloud.security.token.TokenClaims; import com.sap.cloud.security.token.TokenHeader; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mockito; import java.io.File; @@ -52,15 +51,15 @@ public class JwtGeneratorTest { private static final Path RESOURCES_PATH = Paths.get(JwtGeneratorTest.class.getResource("/").getPath()); - @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(RESOURCES_PATH.toFile()); + @TempDir + public static File temporaryFolder; - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { keys = RSAKeys.fromKeyFiles("/publicKey.txt", "/privateKey.txt"); } - @Before + @BeforeEach public void setUp() { cut = JwtGenerator.getInstance(XSUAA, DEFAULT_CLIENT_ID) .withPrivateKey(keys.getPrivate()); @@ -293,7 +292,7 @@ public void withClaimValue_asJsonObjectContainingList() { @Test public void loadClaimsFromFile_doesNotContainValidJson_throwsException() throws IOException { - File emptyFile = temporaryFolder.newFile("empty"); + File emptyFile = File.createTempFile("empty", null, temporaryFolder); String temporaryFolderName = emptyFile.getParentFile().getName(); String resourcePath = "/" + temporaryFolderName + "/empty"; diff --git a/java-security-test/src/test/java/com/sap/cloud/security/test/RSAKeysTest.java b/java-security-test/src/test/java/com/sap/cloud/security/test/RSAKeysTest.java index 7f54518de0..81c9532f05 100644 --- a/java-security-test/src/test/java/com/sap/cloud/security/test/RSAKeysTest.java +++ b/java-security-test/src/test/java/com/sap/cloud/security/test/RSAKeysTest.java @@ -5,7 +5,7 @@ */ package com.sap.cloud.security.test; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.security.NoSuchAlgorithmException; @@ -31,4 +31,4 @@ public void fromKeyFiles() throws IOException, InvalidKeySpecException, assertThat(keys.getPrivate()).isNotNull(); assertThat(keys.getPublic()).isNotNull(); } -} \ No newline at end of file +} diff --git a/java-security-test/src/test/java/com/sap/cloud/security/test/SecurityTestRuleTest.java b/java-security-test/src/test/java/com/sap/cloud/security/test/SecurityTestRuleTest.java index 9ef9776af7..26fa6e9688 100644 --- a/java-security-test/src/test/java/com/sap/cloud/security/test/SecurityTestRuleTest.java +++ b/java-security-test/src/test/java/com/sap/cloud/security/test/SecurityTestRuleTest.java @@ -24,7 +24,8 @@ import org.eclipse.jetty.ee10.servlet.ServletHolder; import org.junit.ClassRule; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.io.IOException; @@ -152,7 +153,8 @@ public void getContext() { assertThat(cut.getContext()).isNotNull(); } - public static class SecurityTestRuleWithMockServlet { + @Nested + public class SecurityTestRuleWithMockServlet { private HttpServlet mockServlet = Mockito.mock(HttpServlet.class); @@ -172,7 +174,8 @@ public void testThatServletMethodIsNotCalled() throws ServletException, IOExcept } - public static class SecurityTestRuleWithoutApplicationServer { + @Nested + public class SecurityTestRuleWithoutApplicationServer { @Rule public SecurityTestRule rule = SecurityTestRule.getInstance(XSUAA); @@ -184,7 +187,8 @@ public void testRuleIsInitializedCorrectly() { } } - public static class SecurityTestRuleApplicationServer_IAS { + @Nested + public class SecurityTestRuleApplicationServer_IAS { @Rule public SecurityTestRule rule = SecurityTestRule.getInstance(IAS); diff --git a/java-security-test/src/test/java/com/sap/cloud/security/test/SecurityTestTest.java b/java-security-test/src/test/java/com/sap/cloud/security/test/SecurityTestTest.java index a62d804316..361401bfbe 100644 --- a/java-security-test/src/test/java/com/sap/cloud/security/test/SecurityTestTest.java +++ b/java-security-test/src/test/java/com/sap/cloud/security/test/SecurityTestTest.java @@ -6,7 +6,7 @@ package com.sap.cloud.security.test; import com.sap.cloud.security.config.Service; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -21,4 +21,4 @@ public void wireMockServerIsNotRunningAfterTearDown() throws Exception { assertThat(cut.wireMockServer.isRunning()).isFalse(); } -} \ No newline at end of file +} diff --git a/java-security/pom.xml b/java-security/pom.xml index 17ca1b6918..331fa5228a 100644 --- a/java-security/pom.xml +++ b/java-security/pom.xml @@ -65,18 +65,6 @@ spring-beans provided - - - - junit - junit - test - - - org.junit.vintage - junit-vintage-engine - test - org.junit.jupiter junit-jupiter-engine @@ -97,6 +85,12 @@ assertj-core test + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + com.sap.cloud.security.xsuaa spring-xsuaa diff --git a/java-security/src/test/java/com/sap/cloud/security/core/AssertionsTest.java b/java-security/src/test/java/com/sap/cloud/security/core/AssertionsTest.java index 2f0578e92f..43f799191a 100644 --- a/java-security/src/test/java/com/sap/cloud/security/core/AssertionsTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/core/AssertionsTest.java @@ -5,7 +5,7 @@ */ package com.sap.cloud.security.core; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.sap.cloud.security.xsuaa.Assertions.assertHasText; import static com.sap.cloud.security.xsuaa.Assertions.assertNotNull; @@ -16,9 +16,8 @@ public class AssertionsTest { @Test public void assertNotNull_throwsIllegalArgumentExceptionContainingMessage() { String message = "A message"; - assertThatThrownBy(() -> { - assertNotNull(null, message); - }).isInstanceOf(IllegalArgumentException.class).hasMessage(message); + assertThatThrownBy(() -> + assertNotNull(null, message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message); } @Test @@ -29,17 +28,14 @@ public void assertNotNull_doesNotThrow() { @Test public void assertNotEmpty_throwsIllegalArgumentExceptionContainingMessage() { String message = "A message"; - assertThatThrownBy(() -> { - assertHasText(null, message); - }).isInstanceOf(IllegalArgumentException.class).hasMessage(message); + assertThatThrownBy(() -> + assertHasText(null, message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message); - assertThatThrownBy(() -> { - assertHasText("", message); - }).isInstanceOf(IllegalArgumentException.class).hasMessage(message); + assertThatThrownBy(() -> + assertHasText("", message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message); - assertThatThrownBy(() -> { - assertHasText(" ", message); - }).isInstanceOf(IllegalArgumentException.class).hasMessage(message); + assertThatThrownBy(() -> + assertHasText(" ", message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message); } @Test diff --git a/java-security/src/test/java/com/sap/cloud/security/token/SapIdTokenTest.java b/java-security/src/test/java/com/sap/cloud/security/token/SapIdTokenTest.java index 168a9312d6..e767d223b4 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/SapIdTokenTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/SapIdTokenTest.java @@ -7,7 +7,7 @@ import com.sap.cloud.security.config.Service; import org.apache.commons.io.IOUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -61,4 +61,4 @@ public void getCnfThumbprint() { public void getAppTid() { assertThat(cut.getAppTid()).isEqualTo("the-app-tid"); } -} \ No newline at end of file +} diff --git a/java-security/src/test/java/com/sap/cloud/security/token/SecurityContextTest.java b/java-security/src/test/java/com/sap/cloud/security/token/SecurityContextTest.java index 2bec7882b8..b1f0be099b 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/SecurityContextTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/SecurityContextTest.java @@ -14,15 +14,15 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SecurityContextTest { private static final Token TOKEN = new MockTokenBuilder().build(); private final ExecutorService executorService = Executors.newSingleThreadExecutor(); - @Before + @BeforeEach public void setUp() { SecurityContext.clear(); } @@ -94,4 +94,4 @@ public void setGetRemoveServicePlans() { SecurityContext.clearServicePlans(); assertThat(SecurityContext.getServicePlans()).isNull(); } -} \ No newline at end of file +} diff --git a/java-security/src/test/java/com/sap/cloud/security/token/XsuaaScopeConverterTest.java b/java-security/src/test/java/com/sap/cloud/security/token/XsuaaScopeConverterTest.java index 432b7b42c3..5b49ae2c18 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/XsuaaScopeConverterTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/XsuaaScopeConverterTest.java @@ -5,8 +5,8 @@ */ package com.sap.cloud.security.token; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Collection; @@ -19,7 +19,7 @@ public class XsuaaScopeConverterTest { private XsuaaScopeConverter cut; private String appId = "myAppId!t1785"; - @Before + @BeforeEach public void setUp() { cut = new XsuaaScopeConverter(appId); } diff --git a/java-security/src/test/java/com/sap/cloud/security/token/XsuaaTokenTest.java b/java-security/src/test/java/com/sap/cloud/security/token/XsuaaTokenTest.java index 2a17b0dc94..93db6b8973 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/XsuaaTokenTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/XsuaaTokenTest.java @@ -8,7 +8,7 @@ import com.sap.cloud.security.config.Service; import com.sap.cloud.security.json.DefaultJsonObject; import org.apache.commons.io.IOUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.io.IOException; @@ -190,4 +190,4 @@ public void checkAppTidFallback() { assertThat(token.getAppTid()).isEqualTo("zid"); } -} \ No newline at end of file +} diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/CombiningValidatorTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/CombiningValidatorTest.java index 107637038c..bc610b1f27 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/CombiningValidatorTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/CombiningValidatorTest.java @@ -6,7 +6,7 @@ package com.sap.cloud.security.token.validation; import com.sap.cloud.security.token.Token; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; @@ -116,4 +116,4 @@ public void getValidators() { assertThat(cut.getValidators()).containsExactly(validator1, validator2); } -} \ No newline at end of file +} diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/ValidationResultsTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/ValidationResultsTest.java index 7c77af7b30..14567fb9d1 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/ValidationResultsTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/ValidationResultsTest.java @@ -5,7 +5,7 @@ */ package com.sap.cloud.security.token.validation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -59,4 +59,4 @@ public void createInvalidWithTemplateString_tooManyArguments_areIgnored() { assertThat(validationResult.getErrorDescription()).isEqualTo("An error message first"); } -} \ No newline at end of file +} diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/IdTokenSignatureValidatorTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/IdTokenSignatureValidatorTest.java index bb4658a9a0..da3386f191 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/IdTokenSignatureValidatorTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/IdTokenSignatureValidatorTest.java @@ -16,8 +16,8 @@ import com.sap.cloud.security.xsuaa.client.OidcConfigurationService; import com.sap.cloud.security.xsuaa.http.HttpHeaders; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.io.IOException; @@ -52,7 +52,7 @@ public class IdTokenSignatureValidatorTest { HttpHeaders.X_CLIENT_ID, CLIENT_ID, HttpHeaders.X_AZP, AZP); - @Before + @BeforeEach public void setup() throws IOException { /** * Header -------- { "alg": "RS256" } Payload -------- { "iss": diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeySetFactoryTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeySetFactoryTest.java index a0f4305ae5..5f19709027 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeySetFactoryTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeySetFactoryTest.java @@ -6,8 +6,8 @@ package com.sap.cloud.security.token.validation.validators; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -22,7 +22,7 @@ public class JsonWebKeySetFactoryTest { private String jsonWebTokenKeys; - @Before + @BeforeEach public void setup() throws IOException { jsonWebTokenKeys = IOUtils.resourceToString("/jsonWebTokenKeys.json", StandardCharsets.UTF_8); } diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeySetTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeySetTest.java index 44717ae752..3fb0531b38 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeySetTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeySetTest.java @@ -5,9 +5,9 @@ */ package com.sap.cloud.security.token.validation.validators; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import static com.sap.cloud.security.token.validation.validators.JsonWebKey.DEFAULT_KEY_ID; import static org.assertj.core.api.Assertions.assertThat; @@ -18,7 +18,7 @@ public class JsonWebKeySetTest { private JsonWebKeySet cut; - @Before + @BeforeEach public void setUp() { cut = new JsonWebKeySet(); } @@ -37,7 +37,7 @@ public void getKeyByAlgorithmAndId_returnsNull_onEmptyJSONWebKeySet() { } @Test - @Ignore + @Disabled public void getKeyByAlgorithmAndId_returnsNull_whenKeyTypeDoesNotMatch() { JwtSignatureAlgorithm differentKeyAlgorithm = JwtSignatureAlgorithm.RS256; // ES256 @@ -111,4 +111,4 @@ public void stringify() { cut.put(JSON_WEB_KEY); assertThat(cut.toString()).isEqualTo("key-id-1(RS256)"); } -} \ No newline at end of file +} diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeyTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeyTest.java index 9c5a5bac18..0191a1500e 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeyTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JsonWebKeyTest.java @@ -5,8 +5,8 @@ */ package com.sap.cloud.security.token.validation.validators; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; @@ -15,7 +15,7 @@ public class JsonWebKeyTest { private JsonWebKey cut; - @Before + @BeforeEach public void setup() { cut = JsonWebKeyTestFactory.create(); } diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtAudienceValidatorTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtAudienceValidatorTest.java index 486d57b359..f0e35e55d6 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtAudienceValidatorTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtAudienceValidatorTest.java @@ -10,8 +10,8 @@ import com.sap.cloud.security.token.TokenClaims; import com.sap.cloud.security.token.validation.ValidationResult; import org.assertj.core.util.Sets; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; @@ -25,7 +25,7 @@ public class JwtAudienceValidatorTest { private Token token; private String XSUAA_BROKER_XSAPPNAME = "brokerplanmasterapp!b123"; - @Before + @BeforeEach public void setUp() { token = Mockito.mock(Token.class); Mockito.when(token.getAudiences()).thenReturn( @@ -196,4 +196,4 @@ public void extractAudiencesFromTokenScopes() { assertThat(audiences).containsExactlyInAnyOrder("test1!t1", "client", "xsappid"); } -} \ No newline at end of file +} diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtTimestampValidatorTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtTimestampValidatorTest.java index 8fbc9cec94..a697014223 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtTimestampValidatorTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtTimestampValidatorTest.java @@ -8,8 +8,8 @@ import com.sap.cloud.security.token.MockTokenBuilder; import com.sap.cloud.security.token.Token; import com.sap.cloud.security.token.validation.ValidationResult; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.time.Duration; import java.time.Instant; @@ -23,7 +23,7 @@ public class JwtTimestampValidatorTest { private JwtTimestampValidator cut; private MockTokenBuilder tokenFactory; - @Before + @BeforeEach public void setUp() { cut = new JwtTimestampValidator(() -> NOW, ONE_MINUTE); tokenFactory = new MockTokenBuilder(); @@ -133,4 +133,4 @@ public void tokenNotExpiredButNotBeforeNotReachedYet_isNotValid() { assertThat(validationResult.isErroneous()).isTrue(); } -} \ No newline at end of file +} diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtValidatorBuilderTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtValidatorBuilderTest.java index 5e8ba8feef..7878c20ef4 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtValidatorBuilderTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/JwtValidatorBuilderTest.java @@ -17,12 +17,12 @@ import com.sap.cloud.security.xsuaa.client.OAuth2TokenKeyService; import com.sap.cloud.security.xsuaa.client.OidcConfigurationService; import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.io.IOException; import java.net.URI; @@ -38,7 +38,7 @@ import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class JwtValidatorBuilderTest { OAuth2ServiceConfigurationBuilder xsuaaConfigBuilder = OAuth2ServiceConfigurationBuilder.forService(XSUAA) @@ -46,7 +46,7 @@ public class JwtValidatorBuilderTest { .withProperty(ServiceConstants.XSUAA.APP_ID, "test-app!t123") .withClientId("sb-test-app!t123"); - @Before + @BeforeEach public void setUp() { Mockito.mockitoSession().initMocks(); } @@ -181,7 +181,7 @@ public void configureOtherServiceInstances() { return; } } - Assert.fail("No JwtAudienceValidator found that contains all clientIds!"); // should never be called + Assertions.fail("No JwtAudienceValidator found that contains all clientIds!"); // should never be called } } \ No newline at end of file diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/OAuth2TokenKeyServiceWithCacheTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/OAuth2TokenKeyServiceWithCacheTest.java index d42cc44b2a..e19b55921d 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/OAuth2TokenKeyServiceWithCacheTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/OAuth2TokenKeyServiceWithCacheTest.java @@ -11,8 +11,8 @@ import com.sap.cloud.security.xsuaa.client.OAuth2TokenKeyService; import com.sap.cloud.security.xsuaa.http.HttpHeaders; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.URI; @@ -47,7 +47,7 @@ public class OAuth2TokenKeyServiceWithCacheTest { HttpHeaders.X_CLIENT_ID, CLIENT_ID, HttpHeaders.X_AZP, AZP); - @Before + @BeforeEach public void setup() throws IOException { tokenKeyServiceMock = mock(OAuth2TokenKeyService.class); when(tokenKeyServiceMock.retrieveTokenKeys(eq(TOKEN_KEYS_URI), anyMap())) diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/OidcConfigurationServiceWithCacheTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/OidcConfigurationServiceWithCacheTest.java index d59e2fc28b..ff50a88f0c 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/OidcConfigurationServiceWithCacheTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/OidcConfigurationServiceWithCacheTest.java @@ -9,8 +9,8 @@ import com.sap.cloud.security.xsuaa.client.OAuth2ServiceException; import com.sap.cloud.security.xsuaa.client.OidcConfigurationService; import org.assertj.core.api.Assertions; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.io.IOException; @@ -29,7 +29,7 @@ public class OidcConfigurationServiceWithCacheTest { OAuth2ServiceEndpointsProvider oidcEndpointsProviderMock; URI DISCOVERY_URI = URI.create("https://myauth.com/.well-known/oidc-config"); - @Before + @BeforeEach public void setup() throws IOException { oidcEndpointsProviderMock = Mockito.mock(OAuth2ServiceEndpointsProvider.class); oidcConfigServiceMock = Mockito.mock(OidcConfigurationService.class); @@ -95,9 +95,8 @@ public void requestFails_throwsException() throws OAuth2ServiceException { when(oidcConfigServiceMock.retrieveEndpoints(any())) .thenThrow(new OAuth2ServiceException("Currently unavailable")); - assertThatThrownBy(() -> { - cut.getOrRetrieveEndpoints(DISCOVERY_URI); - }).isInstanceOf(OAuth2ServiceException.class).hasMessageStartingWith("Currently unavailable"); + assertThatThrownBy(() -> + cut.getOrRetrieveEndpoints(DISCOVERY_URI)).isInstanceOf(OAuth2ServiceException.class).hasMessageStartingWith("Currently unavailable"); } @Test diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/SapIdJwtSignatureValidatorTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/SapIdJwtSignatureValidatorTest.java index 59c202368f..e915d45d81 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/SapIdJwtSignatureValidatorTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/SapIdJwtSignatureValidatorTest.java @@ -20,9 +20,9 @@ import com.sap.cloud.security.xsuaa.client.OidcConfigurationService; import com.sap.cloud.security.xsuaa.http.HttpHeaders; import org.apache.commons.io.IOUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; @@ -36,7 +36,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; @@ -52,7 +52,7 @@ public class SapIdJwtSignatureValidatorTest { private OidcConfigurationService oidcConfigServiceMock; private OAuth2ServiceEndpointsProvider endpointsProviderMock; - @Before + @BeforeEach public void setup() throws IOException { // no zone-id but iss host == jwks host iasPaasToken = new SapIdToken( @@ -81,7 +81,7 @@ public void setup() throws IOException { .withOidcConfigurationService(oidcConfigServiceMock)); } - @After + @AfterEach public void tearDown() { SecurityContext.clear(); } diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/XsaJwtSignatureValidatorTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/XsaJwtSignatureValidatorTest.java index 52bf16e101..7c299eea56 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/XsaJwtSignatureValidatorTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/XsaJwtSignatureValidatorTest.java @@ -12,8 +12,8 @@ import com.sap.cloud.security.xsuaa.client.OAuth2TokenKeyService; import com.sap.cloud.security.xsuaa.client.OidcConfigurationService; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.io.IOException; @@ -35,7 +35,7 @@ public class XsaJwtSignatureValidatorTest { private static final URI PROVIDER_URI = URI.create("https://myauth.com"); private static final URI JKU_URI = URI.create("https://myauth.com/token_keys"); - @Before + @BeforeEach public void setup() throws IOException { /** * Header -------- { "alg": "RS256", } Payload -------- { "iss": diff --git a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/XsuaaJwtSignatureValidatorTest.java b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/XsuaaJwtSignatureValidatorTest.java index b0e7cf86d3..24d212fa3c 100644 --- a/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/XsuaaJwtSignatureValidatorTest.java +++ b/java-security/src/test/java/com/sap/cloud/security/token/validation/validators/XsuaaJwtSignatureValidatorTest.java @@ -15,8 +15,8 @@ import com.sap.cloud.security.xsuaa.client.OidcConfigurationService; import com.sap.cloud.security.xsuaa.http.HttpHeaders; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.io.IOException; @@ -38,7 +38,7 @@ public class XsuaaJwtSignatureValidatorTest { private OAuth2TokenKeyService tokenKeyServiceMock; private OAuth2ServiceConfiguration mockConfiguration; - @Before + @BeforeEach public void setup() throws IOException { /** * Header -------- { "alg": "RS256", "jku": diff --git a/pom.xml b/pom.xml index 10f36af2a2..bcf5407de4 100644 --- a/pom.xml +++ b/pom.xml @@ -302,6 +302,20 @@ + + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + + + junit + junit + + + + diff --git a/spring-security-compatibility/pom.xml b/spring-security-compatibility/pom.xml index cc870408a3..173ec050a2 100644 --- a/spring-security-compatibility/pom.xml +++ b/spring-security-compatibility/pom.xml @@ -46,11 +46,12 @@ com.sap.cloud.security java-security-test test - - - junit - junit - test + + + junit + junit + + org.junit.jupiter @@ -62,6 +63,12 @@ assertj-core test + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + org.junit.jupiter junit-jupiter-params diff --git a/spring-security-starter/pom.xml b/spring-security-starter/pom.xml index 36687d85db..ec026e1078 100644 --- a/spring-security-starter/pom.xml +++ b/spring-security-starter/pom.xml @@ -58,6 +58,18 @@ httpclient5 provided + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + + + junit + junit + + + diff --git a/spring-security/pom.xml b/spring-security/pom.xml index 5bae3e084d..2f47913f34 100644 --- a/spring-security/pom.xml +++ b/spring-security/pom.xml @@ -77,6 +77,10 @@ com.sap.cloud.security java-security + + junit + junit + @@ -94,6 +98,12 @@ reactor-test test + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + diff --git a/spring-xsuaa-starter/pom.xml b/spring-xsuaa-starter/pom.xml index 8e5a2100a1..502e2d5a54 100644 --- a/spring-xsuaa-starter/pom.xml +++ b/spring-xsuaa-starter/pom.xml @@ -51,6 +51,18 @@ org.springframework.security spring-security-oauth2-resource-server + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + + + junit + junit + + + diff --git a/spring-xsuaa-test/pom.xml b/spring-xsuaa-test/pom.xml index 3e65099256..2e122e6c8e 100644 --- a/spring-xsuaa-test/pom.xml +++ b/spring-xsuaa-test/pom.xml @@ -42,13 +42,25 @@ commons-io - junit - junit + org.hamcrest + hamcrest-all test org.hamcrest - hamcrest-all + hamcrest-junit + 2.0.0.0 + test + + + junit + junit + + + + + org.junit.jupiter + junit-jupiter test diff --git a/spring-xsuaa-test/src/test/java/com/sap/cloud/security/xsuaa/test/JwtGeneratorTest.java b/spring-xsuaa-test/src/test/java/com/sap/cloud/security/xsuaa/test/JwtGeneratorTest.java index 984c6bb0ba..ca61cb6bbb 100644 --- a/spring-xsuaa-test/src/test/java/com/sap/cloud/security/xsuaa/test/JwtGeneratorTest.java +++ b/spring-xsuaa-test/src/test/java/com/sap/cloud/security/xsuaa/test/JwtGeneratorTest.java @@ -9,8 +9,8 @@ import com.sap.cloud.security.xsuaa.test.JwtGenerator.TokenClaims; import com.sap.cloud.security.xsuaa.test.JwtGenerator.TokenHeaders; import org.json.JSONArray; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.security.oauth2.jwt.Jwt; import java.io.IOException; @@ -28,7 +28,7 @@ public class JwtGeneratorTest { private static final String MY_USER_NAME = "UserName"; private static final String MY_SUBDOMAIN = "my-subaccount-subdomain"; - @Before + @BeforeEach public void setUp() { jwtGenerator = new JwtGenerator(MY_CLIENT_ID, MY_SUBDOMAIN); } diff --git a/spring-xsuaa/pom.xml b/spring-xsuaa/pom.xml index 0b95c3daf1..074af876dc 100644 --- a/spring-xsuaa/pom.xml +++ b/spring-xsuaa/pom.xml @@ -105,17 +105,17 @@ commons-io compile - - - - junit - junit - test - - org.junit.vintage - junit-vintage-engine + org.hamcrest + hamcrest-junit + 2.0.0.0 test + + + junit + junit + + org.junit.jupiter diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/CustomPropertySourceFactoryTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/CustomPropertySourceFactoryTest.java index c9fcaed6f9..415651e34c 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/CustomPropertySourceFactoryTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/CustomPropertySourceFactoryTest.java @@ -7,8 +7,8 @@ import com.sap.cloud.security.config.Environment; import com.sap.cloud.security.config.Environments; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -36,28 +36,28 @@ public class CustomPropertySourceFactoryTest { @Test public void testXsuaaServiceConfiguration() { - Assert.assertEquals("https://auth.com", serviceConfiguration.getUaaUrl()); // vcap.json - Assert.assertEquals("overwriteUaaDomain", serviceConfiguration.getUaaDomain()); // vcap.json + Assertions.assertEquals("https://auth.com", serviceConfiguration.getUaaUrl()); // vcap.json + Assertions.assertEquals("overwriteUaaDomain", serviceConfiguration.getUaaDomain()); // vcap.json } @Test public void testOverwrittenXsuaaServiceConfiguration() { - Assert.assertEquals("customClientId", serviceConfiguration.getClientId()); - Assert.assertEquals("customClientSecret", serviceConfiguration.getClientSecret()); - Assert.assertEquals("customAppId!t2344", serviceConfiguration.getAppId()); + Assertions.assertEquals("customClientId", serviceConfiguration.getClientId()); + Assertions.assertEquals("customClientSecret", serviceConfiguration.getClientSecret()); + Assertions.assertEquals("customAppId!t2344", serviceConfiguration.getAppId()); } @Test public void testInjectedPropertyValue() { - Assert.assertEquals("https://auth.com", customConfiguration.xsuaaUrl); // vcap.json - Assert.assertEquals("overwriteUaaDomain", customConfiguration.xsuaaDomain); // vcap.json + Assertions.assertEquals("https://auth.com", customConfiguration.xsuaaUrl); // vcap.json + Assertions.assertEquals("overwriteUaaDomain", customConfiguration.xsuaaDomain); // vcap.json } @Test public void testOverwrittenInjectedPropertyValue() { - Assert.assertEquals("customClientId", customConfiguration.xsuaaClientId); - Assert.assertEquals("customClientSecret", customConfiguration.xsuaaClientSecret); - Assert.assertEquals("customAppId!t2344", customConfiguration.xsappId); + Assertions.assertEquals("customClientId", customConfiguration.xsuaaClientId); + Assertions.assertEquals("customClientSecret", customConfiguration.xsuaaClientSecret); + Assertions.assertEquals("customAppId!t2344", customConfiguration.xsappId); } } @@ -102,4 +102,4 @@ public org.springframework.core.env.PropertySource createPropertySource(Strin return XsuaaServicePropertySourceFactory.create("custom", properties); } -} \ No newline at end of file +} diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServiceConfigurationDefaultTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServiceConfigurationDefaultTest.java index 8342a99681..688bd02229 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServiceConfigurationDefaultTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServiceConfigurationDefaultTest.java @@ -1,7 +1,7 @@ package com.sap.cloud.security.xsuaa; import com.sap.cloud.security.config.CredentialType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -69,4 +69,4 @@ public void getPropertyRequiresEnvironmentVar() { .isInstanceOf(NullPointerException.class) .hasMessageContaining(VCAP_SERVICES_CREDENTIALS); } -} \ No newline at end of file +} diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServicePropertySourceFactoryMultipleBindingsTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServicePropertySourceFactoryMultipleBindingsTest.java index 03fc71fad9..500418622d 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServicePropertySourceFactoryMultipleBindingsTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServicePropertySourceFactoryMultipleBindingsTest.java @@ -1,7 +1,7 @@ package com.sap.cloud.security.xsuaa; import org.apache.commons.io.IOUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.env.PropertySource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.InputStreamResource; @@ -15,6 +15,7 @@ import static com.sap.cloud.security.xsuaa.XsuaaServicePropertySourceFactory.CLIENT_ID; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; public class XsuaaServicePropertySourceFactoryMultipleBindingsTest { XsuaaServicePropertySourceFactory cut = new XsuaaServicePropertySourceFactory(); @@ -27,13 +28,15 @@ public void ignoreApiAccessPlan() throws IOException { assertThat(propertySource.getProperty(CLIENT_ID)).isEqualTo("client-id"); } - @Test(expected = IllegalStateException.class) - public void doNotAllowBrokerAndApplicationPlan() throws IOException { - String vcapMultipleBindings = IOUtils.resourceToString("/vcap_multipleBindings.json", StandardCharsets.UTF_8); - vcapMultipleBindings = vcapMultipleBindings.replace("apiaccess", "broker"); - Resource resource = new InputStreamResource( - new ByteArrayInputStream(vcapMultipleBindings.getBytes(StandardCharsets.UTF_8))); - cut.createPropertySource(null, new EncodedResource(resource)); + @Test + public void doNotAllowBrokerAndApplicationPlan() { + assertThrows(IllegalStateException.class, () -> { + String vcapMultipleBindings = IOUtils.resourceToString("/vcap_multipleBindings.json", StandardCharsets.UTF_8); + vcapMultipleBindings = vcapMultipleBindings.replace("apiaccess", "broker"); + Resource resource = new InputStreamResource( + new ByteArrayInputStream(vcapMultipleBindings.getBytes(StandardCharsets.UTF_8))); + cut.createPropertySource(null, new EncodedResource(resource)); + }); } @Test diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServicePropertySourceFactoryTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServicePropertySourceFactoryTest.java index eb03578a81..0674d329b0 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServicePropertySourceFactoryTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/XsuaaServicePropertySourceFactoryTest.java @@ -5,7 +5,7 @@ */ package com.sap.cloud.security.xsuaa; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -18,7 +18,7 @@ import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; @RunWith(SpringRunner.class) @ContextConfiguration(classes = { TestConfiguration.class, XsuaaServiceConfigurationDefault.class }) @@ -87,4 +87,4 @@ class TestConfiguration { @Value("${xsuaa.certurl:}") public String certUrl; -} \ No newline at end of file +} diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfigurationTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfigurationTest.java index 842f72b764..5534b86beb 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfigurationTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaAutoConfigurationTest.java @@ -10,8 +10,8 @@ import com.sap.cloud.security.xsuaa.XsuaaServiceConfigurationDefault; import org.apache.commons.io.IOUtils; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -47,7 +47,7 @@ public class XsuaaAutoConfigurationTest { @Autowired private ApplicationContext context; - @Before + @BeforeEach public void setup() throws IOException { cert = IOUtils.resourceToString("/certificate.txt", StandardCharsets.UTF_8); key = IOUtils.resourceToString("/key.txt", StandardCharsets.UTF_8); @@ -211,4 +211,4 @@ public XsuaaServiceConfiguration userDefinedServiceConfiguration() { return new DummyXsuaaServiceConfiguration(); } } -} \ No newline at end of file +} diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaResourceServerJwkAutoConfigurationTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaResourceServerJwkAutoConfigurationTest.java index 7403613e75..19d301d21a 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaResourceServerJwkAutoConfigurationTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaResourceServerJwkAutoConfigurationTest.java @@ -6,8 +6,8 @@ package com.sap.cloud.security.xsuaa.autoconfiguration; import com.sap.cloud.security.xsuaa.token.authentication.XsuaaJwtDecoder; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -24,8 +24,8 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestTemplate; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; @RunWith(SpringRunner.class) @SpringBootTest(classes = { XsuaaResourceServerJwkAutoConfiguration.class, XsuaaAutoConfiguration.class }) @@ -38,7 +38,7 @@ public class XsuaaResourceServerJwkAutoConfigurationTest { @Autowired private ApplicationContext context; - @Before + @BeforeEach public void setup() { contextRunner = new WebApplicationContextRunner() .withConfiguration( @@ -68,18 +68,16 @@ public void autoConfigurationActiveInclProperties() { @Test public void autoConfigurationDisabledByProperty() { - contextRunner.withPropertyValues("spring.xsuaa.auto:false").run((context) -> { - assertThat(context.containsBean("xsuaaJwtDecoder"), is(false)); - }); + contextRunner.withPropertyValues("spring.xsuaa.auto:false").run((context) -> + assertThat(context.containsBean("xsuaaJwtDecoder"), is(false))); } @Test public void autoConfigurationWithoutXsuaaServiceConfigurationOnClasspathInactive() { contextRunner.withClassLoader( new FilteredClassLoader(Jwt.class)) // make sure Jwt.class is not on the classpath - .run((context) -> { - assertThat(context.containsBean("xsuaaJwtDecoder"), is(false)); - }); + .run((context) -> + assertThat(context.containsBean("xsuaaJwtDecoder"), is(false))); } @Test @@ -96,9 +94,8 @@ public void userConfigurationCanOverrideDefaultBeans() { @Test public void userConfigurationCanOverrideDefaultRestClientBeans() { contextRunner.withUserConfiguration(RestClientConfiguration.class) - .run((context) -> { - assertThat(context.containsBean("xsuaaJwtDecoder"), is(true)); - }); + .run((context) -> + assertThat(context.containsBean("xsuaaJwtDecoder"), is(true))); } @Test @@ -108,9 +105,8 @@ public void autoConfigurationDisabledWhenSpringReactorIsActive() { AutoConfigurations.of(XsuaaResourceServerJwkAutoConfiguration.class, XsuaaAutoConfiguration.class)); - contextRunner.run((context) -> { - assertThat(context.containsBean("xsuaaJwtDecoder"), is(false)); - }); + contextRunner.run((context) -> + assertThat(context.containsBean("xsuaaJwtDecoder"), is(false))); } @Configuration diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaTokenFlowAutoConfigurationTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaTokenFlowAutoConfigurationTest.java index c9ff2bd3d1..0ca023c89d 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaTokenFlowAutoConfigurationTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/autoconfiguration/XsuaaTokenFlowAutoConfigurationTest.java @@ -11,7 +11,7 @@ import com.sap.cloud.security.xsuaa.client.XsuaaDefaultEndpoints; import com.sap.cloud.security.xsuaa.client.XsuaaOAuth2TokenService; import com.sap.cloud.security.xsuaa.tokenflows.XsuaaTokenFlows; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigurations; diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/extractor/LocalAuthoritiesExtractorTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/extractor/LocalAuthoritiesExtractorTest.java index 48acf3a590..60dd5dc9f9 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/extractor/LocalAuthoritiesExtractorTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/extractor/LocalAuthoritiesExtractorTest.java @@ -6,8 +6,8 @@ package com.sap.cloud.security.xsuaa.extractor; import com.sap.cloud.security.xsuaa.token.XsuaaToken; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -21,7 +21,7 @@ public class LocalAuthoritiesExtractorTest { XsuaaToken token; Collection scopes = new HashSet<>(); - @Before + @BeforeEach public void setup() { cut = new LocalAuthoritiesExtractor("appId!1234"); @@ -40,4 +40,4 @@ public void extractLocalScopes() { new SimpleGrantedAuthority("Scope2")); } -} \ No newline at end of file +} diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/extractor/TokenUtilTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/extractor/TokenUtilTest.java index bce0981dc9..405f039b0b 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/extractor/TokenUtilTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/extractor/TokenUtilTest.java @@ -8,8 +8,8 @@ import com.sap.cloud.security.xsuaa.jwt.DecodedJwt; import org.apache.commons.io.IOUtils; import org.json.JSONException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.oauth2.jwt.Jwt; @@ -34,7 +34,7 @@ public class TokenUtilTest { private static String encodedXsuaaToken; private static final String invalidToken = "eyJqa3UiOiJodHRwOi8vbG9jYWxob3N0OjY0MzEyL3Rva2VuX2tleXMiLCJraWQiOiJkZWZhdWx0LWtpZCIsImFsZyI6IkhTMjU2In0.eyJjbGllbnRfaWQiOiJzYi1qYXZhLWhlbGxvLXdvcmxkIiwiY2lkIjoic2ItamF2YS1oZWxsby13b3JsZCIsImF6cCI6InNiLWphdmEtaGVsbG8td29ybGQiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvdWFhL29hdXRoL3Rva2VuIiwiemlkIjoidWFhIn0.6cACH-Z8Kr0p6prBYd2gp7nEfOJsA4OsXO_Hkj99XyU"; - @Before + @BeforeEach public void setup() throws IOException { encodedIasToken = IOUtils.resourceToString("/token_cc.txt", StandardCharsets.UTF_8); encodedXsuaaToken = IOUtils.resourceToString("/token_xsuaa.txt", StandardCharsets.UTF_8); @@ -64,4 +64,4 @@ public void tokenWithMissingExpClaim() { DecodedJwt decodedJwt = TokenUtil.decodeJwt(invalidToken); assertThrows(JSONException.class, () -> TokenUtil.parseJwt(decodedJwt)); } -} \ No newline at end of file +} diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/ReactiveSecurityContextTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/ReactiveSecurityContextTest.java index 586d8d4fd2..5e5d1fc945 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/ReactiveSecurityContextTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/ReactiveSecurityContextTest.java @@ -6,8 +6,8 @@ package com.sap.cloud.security.xsuaa.token; import com.sap.cloud.security.xsuaa.test.JwtGenerator; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.authentication.TestingAuthenticationToken; import org.springframework.security.core.context.ReactiveSecurityContextHolder; @@ -30,7 +30,7 @@ public void unauthenticated() { } @Test - @Ignore + @Disabled public void authenticated() { XsuaaToken jwt = new XsuaaToken(new JwtGenerator().setUserName("user").getToken()); SecurityContext expectedContext = new SecurityContextImpl( diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/SpringSecurityContextTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/SpringSecurityContextTest.java index dd1fcd783b..0d54ba52ca 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/SpringSecurityContextTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/SpringSecurityContextTest.java @@ -8,8 +8,8 @@ import com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor; import com.sap.cloud.security.xsuaa.test.JwtGenerator; import com.sap.cloud.security.xsuaa.token.authentication.XsuaaJwtDecoder; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.oauth2.jwt.Jwt; @@ -19,7 +19,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; public class SpringSecurityContextTest { @@ -31,20 +32,22 @@ public class SpringSecurityContextTest { private static final String SUBDOMAIN_2 = "subdomain-2"; private static final String CLIENT_ID = "sb-xsappname!t123"; - @Before + @BeforeEach public void setup() { token_1 = new JwtGenerator(CLIENT_ID, SUBDOMAIN_1).getToken(); token_2 = new JwtGenerator(CLIENT_ID, SUBDOMAIN_2).getToken(); } - @Test(expected = AccessDeniedException.class) // Access forbidden: not authenticated + @Test // Access forbidden: not authenticated public void getSecurityContextRaiseAccessDeniedExceptionIfNotInitialized() { - SpringSecurityContext.getToken(); + assertThrows(AccessDeniedException.class, () -> + SpringSecurityContext.getToken()); } - @Test(expected = IllegalArgumentException.class) // Passed JwtDecoder instance must be of type 'XsuaaJwtDecoder' + @Test // Passed JwtDecoder instance must be of type 'XsuaaJwtDecoder' public void initSecurityContextRaiseExceptionIfNotXsuaaJwtDecoder() { - SpringSecurityContext.init(token_1.getTokenValue(), s -> token_1, new DefaultAuthoritiesExtractor()); + assertThrows(IllegalArgumentException.class, () -> + SpringSecurityContext.init(token_1.getTokenValue(), s -> token_1, new DefaultAuthoritiesExtractor())); } /** @@ -83,4 +86,4 @@ private static void initSecurityContextWithToken(Jwt token) throws InterruptedEx // initialize SpringSecurityContext with provided token SpringSecurityContext.init(token.getTokenValue(), mockXsuaaJwtDecoder, new DefaultAuthoritiesExtractor()); } -} \ No newline at end of file +} diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/TokenAuthenticationConverterTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/TokenAuthenticationConverterTest.java index c6caa5ccd6..067419c2f9 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/TokenAuthenticationConverterTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/TokenAuthenticationConverterTest.java @@ -9,8 +9,8 @@ import com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor; import com.sap.cloud.security.xsuaa.extractor.LocalAuthoritiesExtractor; import com.sap.cloud.security.xsuaa.test.JwtGenerator; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -21,7 +21,7 @@ import java.util.Set; import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class TokenAuthenticationConverterTest { private String xsAppName = "my-app-name!400"; @@ -31,7 +31,7 @@ public class TokenAuthenticationConverterTest { String scopeRead = xsAppName + "." + "Read"; String scopeOther = "other-app!234" + "." + "Other"; - @Before + @BeforeEach public void setup() { tokenConverterDefault = new TokenAuthenticationConverter(xsAppName); diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaAudienceValidatorForCloneTokenTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaAudienceValidatorForCloneTokenTest.java index 845c207622..3348f6415c 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaAudienceValidatorForCloneTokenTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaAudienceValidatorForCloneTokenTest.java @@ -10,9 +10,9 @@ import com.sap.cloud.security.xsuaa.XsuaaServiceConfiguration; import com.sap.cloud.security.xsuaa.test.JwtGenerator; import com.sap.cloud.security.xsuaa.token.TokenClaims; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.security.oauth2.core.OAuth2Error; import org.springframework.security.oauth2.core.OAuth2ErrorCodes; import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult; @@ -22,6 +22,7 @@ import java.util.List; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; public class XsuaaAudienceValidatorForCloneTokenTest { @@ -30,7 +31,7 @@ public class XsuaaAudienceValidatorForCloneTokenTest { private String XSUAA_BROKER_CLIENT_ID = "sb-" + XSUAA_BROKER_XSAPPNAME; private XsuaaAudienceValidator cut; - @Before + @BeforeEach public void setup() { XsuaaServiceConfiguration serviceConfiguration = new DummyXsuaaServiceConfiguration("sb-test1!t1", "test1!t1"); cut = new XsuaaAudienceValidator(serviceConfiguration); @@ -44,7 +45,7 @@ public void tokenWithClientId_like_brokerClientId_shouldBeIgnored() { claimsBuilder.claim(TokenClaims.CLAIM_CLIENT_ID, XSUAA_BROKER_CLIENT_ID); OAuth2TokenValidatorResult result = cut.validate(JwtGenerator.createFromClaims(claimsBuilder.build())); - Assert.assertFalse(result.hasErrors()); + Assertions.assertFalse(result.hasErrors()); } @Test @@ -52,7 +53,7 @@ public void cloneTokenClientId_like_brokerClientId_shouldBeAccepted() { claimsBuilder.claim(TokenClaims.CLAIM_CLIENT_ID, "sb-clone1!b22|" + XSUAA_BROKER_XSAPPNAME); OAuth2TokenValidatorResult result = cut.validate(JwtGenerator.createFromClaims(claimsBuilder.build())); - Assert.assertFalse(result.hasErrors()); + Assertions.assertFalse(result.hasErrors()); } @Test @@ -60,12 +61,12 @@ public void cloneTokenClientId_unlike_brokerClientId_raisesError() { claimsBuilder.claim(TokenClaims.CLAIM_CLIENT_ID, "sb-clone1!b22|ANOTHERAPP!b12"); OAuth2TokenValidatorResult result = cut.validate(JwtGenerator.createFromClaims(claimsBuilder.build())); - Assert.assertTrue(result.hasErrors()); + Assertions.assertTrue(result.hasErrors()); List errors = new ArrayList<>(result.getErrors()); - Assert.assertThat(errors.get(0).getDescription(), + assertThat(errors.get(0).getDescription(), is("Jwt token with allowed audiences [] matches none of these: [test1!t1, brokerplanmasterapp!b123]")); - Assert.assertThat(errors.get(0).getErrorCode(), is(OAuth2ErrorCodes.INVALID_CLIENT)); + assertThat(errors.get(0).getErrorCode(), is(OAuth2ErrorCodes.INVALID_CLIENT)); } } diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaAudienceValidatorTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaAudienceValidatorTest.java index 0fb6e18122..6b567ef575 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaAudienceValidatorTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaAudienceValidatorTest.java @@ -10,9 +10,9 @@ import com.sap.cloud.security.xsuaa.XsuaaServiceConfiguration; import com.sap.cloud.security.xsuaa.test.JwtGenerator; import com.sap.cloud.security.xsuaa.token.TokenClaims; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.security.oauth2.core.OAuth2Error; import org.springframework.security.oauth2.core.OAuth2ErrorCodes; import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult; @@ -26,6 +26,7 @@ import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; public class XsuaaAudienceValidatorTest { @@ -40,7 +41,7 @@ public class XsuaaAudienceValidatorTest { private JWTClaimsSet.Builder claimsBuilder; - @Before + @BeforeEach public void setup() throws IOException { serviceConfigurationSameClientId = new DummyXsuaaServiceConfiguration("sb-test1!t1", "test1!t1"); serviceConfigurationOtherGrantedClientId = new DummyXsuaaServiceConfiguration("sb-test2!t1", "test2!t1"); @@ -58,14 +59,14 @@ public void setup() throws IOException { public void testSameClientId() { OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationSameClientId) .validate(tokenWithAudience); - Assert.assertFalse(result.hasErrors()); + Assertions.assertFalse(result.hasErrors()); } @Test public void testSameClientIdWithoutAudience() { OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationSameClientId) .validate(tokenWithoutAudience); - Assert.assertFalse(result.hasErrors()); + Assertions.assertFalse(result.hasErrors()); } @Test @@ -73,37 +74,37 @@ public void testExtractAudiencesFromTokenScopes() { Jwt token = new JwtGenerator() .addScopes("test1!t1.read", "test2!t1.read", "test2!t1.write", ".scopeWithoutAppId").getToken(); Set audiences = XsuaaAudienceValidator.getAllowedAudiences(token); - Assert.assertThat(audiences.size(), is(2)); - Assert.assertThat(audiences, hasItem("test1!t1")); - Assert.assertThat(audiences, hasItem("test2!t1")); + assertThat(audiences.size(), is(2)); + assertThat(audiences, hasItem("test1!t1")); + assertThat(audiences, hasItem("test2!t1")); } @Test public void testOtherGrantedClientIdWithoutAudience() { OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationOtherGrantedClientId) .validate(tokenWithoutAudience); - Assert.assertFalse(result.hasErrors()); + Assertions.assertFalse(result.hasErrors()); } @Test public void testOtherGrantedClientIdWithoutAudienceAndDot() { OAuth2TokenValidatorResult result = new XsuaaAudienceValidator( new DummyXsuaaServiceConfiguration("sb-test4!t1", "test4!t1")).validate(tokenWithAudience); - Assert.assertFalse(result.hasErrors()); + Assertions.assertFalse(result.hasErrors()); } @Test public void testOtherGrantedClientId() { OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationUnGrantedClientId) .validate(tokenWithAudience); - Assert.assertTrue(result.hasErrors()); + Assertions.assertTrue(result.hasErrors()); } @Test public void testUnGrantedClientId() { OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationUnGrantedClientId) .validate(tokenWithAudience); - Assert.assertTrue(result.hasErrors()); + Assertions.assertTrue(result.hasErrors()); } @Test @@ -115,7 +116,7 @@ public void testOtherGrantedClientIdWithoutAudienceButScopes() { Jwt tokenWithoutAudienceButScopes = JwtGenerator.createFromClaims(claimsBuilder.build()); OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationOtherGrantedClientId) .validate(tokenWithoutAudienceButScopes); - Assert.assertFalse(result.hasErrors()); + Assertions.assertFalse(result.hasErrors()); } @Test @@ -127,11 +128,11 @@ public void testOtherGrantedClientIdWithoutAudienceAndMatchingScopes() { Jwt tokenWithoutAudienceButScopes = JwtGenerator.createFromClaims(claimsBuilder.build()); OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationOtherGrantedClientId) .validate(tokenWithoutAudienceButScopes); - Assert.assertTrue(result.hasErrors()); + Assertions.assertTrue(result.hasErrors()); List errors = new ArrayList<>(result.getErrors()); String expectedDescription = "Jwt token with allowed audiences [test3!t1] matches none of these: [test2!t1]"; - Assert.assertThat(errors.get(0).getDescription(), is(expectedDescription)); - Assert.assertThat(errors.get(0).getErrorCode(), is(OAuth2ErrorCodes.INVALID_CLIENT)); + assertThat(errors.get(0).getDescription(), is(expectedDescription)); + assertThat(errors.get(0).getErrorCode(), is(OAuth2ErrorCodes.INVALID_CLIENT)); } @Test @@ -139,7 +140,7 @@ public void testOtherGrantedClientIdWithoutAudienceAndScopes() { Jwt tokenWithoutAudienceAndScopes = JwtGenerator.createFromClaims(claimsBuilder.build()); OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationOtherGrantedClientId) .validate(tokenWithoutAudienceAndScopes); - Assert.assertTrue(result.hasErrors()); + Assertions.assertTrue(result.hasErrors()); } @Test @@ -148,7 +149,7 @@ public void testOtherGrantedClientIdWithoutAudienceAndEmptyScopes() { Jwt tokenWithoutAudienceAndScopes = JwtGenerator.createFromClaims(claimsBuilder.build()); OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationOtherGrantedClientId) .validate(tokenWithoutAudienceAndScopes); - Assert.assertTrue(result.hasErrors()); + Assertions.assertTrue(result.hasErrors()); } @Test @@ -157,21 +158,21 @@ public void testTokenWithoutClientId() { Jwt tokenWithoutClientId = JwtGenerator.createFromClaims(claimsBuilder.build()); OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationSameClientId) .validate(tokenWithoutClientId); - Assert.assertTrue(result.hasErrors()); + Assertions.assertTrue(result.hasErrors()); } @Test public void testBrokerCloneWithAudience() { OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationBrokerPlan) .validate(cloneTokenWithAudience); - Assert.assertFalse(result.hasErrors()); + Assertions.assertFalse(result.hasErrors()); } @Test public void testBrokerCloneWithoutAudience() { OAuth2TokenValidatorResult result = new XsuaaAudienceValidator(serviceConfigurationBrokerPlan) .validate(cloneTokenWithAudience); - Assert.assertFalse(result.hasErrors()); + Assertions.assertFalse(result.hasErrors()); } } diff --git a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaJwtDecoderTest.java b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaJwtDecoderTest.java index b3cded9d8a..ae0e7abe32 100644 --- a/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaJwtDecoderTest.java +++ b/spring-xsuaa/src/test/java/com/sap/cloud/security/xsuaa/token/authentication/XsuaaJwtDecoderTest.java @@ -11,8 +11,8 @@ import com.sap.cloud.security.xsuaa.XsuaaServiceConfigurationDefault; import com.sap.cloud.security.xsuaa.token.TokenClaims; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -47,7 +47,7 @@ public class XsuaaJwtDecoderTest { private String ccToken; private String jwks; - @Before + @BeforeEach public void setUp() throws IOException { rsaToken = IOUtils.resourceToString("/accessTokenRSA256WithVerificationKey.txt", StandardCharsets.UTF_8); ccToken = IOUtils.resourceToString("/token_cc.txt", StandardCharsets.UTF_8); @@ -126,4 +126,4 @@ public void decode_withNonMatchingVerificationKey_throwsException() { .hasMessageContaining("Cannot verify with online token key, kid, uaadomain is null"); } -} \ No newline at end of file +} diff --git a/token-client/pom.xml b/token-client/pom.xml index 2dc9f331a5..af2b3c4ea6 100644 --- a/token-client/pom.xml +++ b/token-client/pom.xml @@ -53,17 +53,6 @@ com.github.ben-manes.caffeine caffeine - - - junit - junit - test - - - org.junit.vintage - junit-vintage-engine - test - org.junit.jupiter junit-jupiter-engine @@ -79,6 +68,12 @@ hamcrest-all test + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + org.mockito mockito-core diff --git a/token-client/src/test/java/com/sap/cloud/security/client/HttpClientFactoryTest.java b/token-client/src/test/java/com/sap/cloud/security/client/HttpClientFactoryTest.java index 190c8f2a16..cf55443cef 100644 --- a/token-client/src/test/java/com/sap/cloud/security/client/HttpClientFactoryTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/client/HttpClientFactoryTest.java @@ -7,9 +7,9 @@ import com.sap.cloud.security.config.ClientCredentials; import org.apache.http.impl.client.CloseableHttpClient; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class HttpClientFactoryTest { @@ -24,4 +24,4 @@ public void create() { assertTrue(cut.getClass().getName().contains("CloseableHttpClient$MockitoMock")); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/mtls/SSLContextFactoryTest.java b/token-client/src/test/java/com/sap/cloud/security/mtls/SSLContextFactoryTest.java index 4a8db97b84..a5a88137d4 100644 --- a/token-client/src/test/java/com/sap/cloud/security/mtls/SSLContextFactoryTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/mtls/SSLContextFactoryTest.java @@ -8,8 +8,8 @@ import com.sap.cloud.security.config.ClientCertificate; import com.sap.cloud.security.config.ClientCredentials; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -28,7 +28,7 @@ public class SSLContextFactoryTest { String certificates; String eccCertificate; - @Before + @BeforeEach public void setup() throws IOException { cut = SSLContextFactory.getInstance(); diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/AssertionsTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/AssertionsTest.java index 1b1ee9f1ba..e941ae1c5a 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/AssertionsTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/AssertionsTest.java @@ -5,7 +5,7 @@ */ package com.sap.cloud.security.xsuaa; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Collections; @@ -17,9 +17,8 @@ public class AssertionsTest { @Test public void assertNotNull_throwsIllegalArgumentExceptionContainingMessage() { String message = "A message"; - assertThatThrownBy(() -> { - Assertions.assertNotNull(null, message); - }).isInstanceOf(IllegalArgumentException.class).hasMessage(message); + assertThatThrownBy(() -> + Assertions.assertNotNull(null, message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message); } @Test @@ -30,17 +29,14 @@ public void assertNotNull_doesNotThrow() { @Test public void assertHasText_throwsIllegalArgumentExceptionContainingMessage() { String message = "A message"; - assertThatThrownBy(() -> { - Assertions.assertHasText(null, message); - }).isInstanceOf(IllegalArgumentException.class).hasMessage(message); + assertThatThrownBy(() -> + Assertions.assertHasText(null, message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message); - assertThatThrownBy(() -> { - Assertions.assertHasText("", message); - }).isInstanceOf(IllegalArgumentException.class).hasMessage(message); + assertThatThrownBy(() -> + Assertions.assertHasText("", message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message); - assertThatThrownBy(() -> { - Assertions.assertHasText(" ", message); - }).isInstanceOf(IllegalArgumentException.class).hasMessage(message); + assertThatThrownBy(() -> + Assertions.assertHasText(" ", message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message); } @Test @@ -56,12 +52,10 @@ public void assertNotEmpty_doesNotThrow() { @Test public void assertNotEmpty_throwsIllegalArgumentExceptionContainingMessage() { String message = "A message"; - assertThatThrownBy(() -> { - Assertions.assertNotEmpty(null, message); - }).isInstanceOf(IllegalArgumentException.class).hasMessage(message); + assertThatThrownBy(() -> + Assertions.assertNotEmpty(null, message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message); - assertThatThrownBy(() -> { - Assertions.assertNotEmpty(new ArrayList<>(), message); - }).isInstanceOf(IllegalArgumentException.class).hasMessage(message); + assertThatThrownBy(() -> + Assertions.assertNotEmpty(new ArrayList<>(), message)).isInstanceOf(IllegalArgumentException.class).hasMessage(message); } } diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/AbstractOAuth2TokenServiceTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/AbstractOAuth2TokenServiceTest.java index 0b1b3f256e..912d272a83 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/AbstractOAuth2TokenServiceTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/AbstractOAuth2TokenServiceTest.java @@ -12,8 +12,8 @@ import com.sap.cloud.security.xsuaa.http.HttpHeaders; import com.sap.cloud.security.xsuaa.tokenflows.TokenCacheConfiguration; import org.assertj.core.util.Maps; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.net.URI; import java.time.Clock; @@ -38,7 +38,7 @@ public class AbstractOAuth2TokenServiceTest { private TestOAuth2TokenService cut; - @Before + @BeforeEach public void setUp() { cut = new TestOAuth2TokenService(TEST_CACHE_CONFIGURATION); } @@ -373,4 +373,4 @@ public void reset() { elapsed = 0; } } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOAuth2TokenKeyServiceTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOAuth2TokenKeyServiceTest.java index 2c6c2d4503..5b941fa82d 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOAuth2TokenKeyServiceTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOAuth2TokenKeyServiceTest.java @@ -15,8 +15,8 @@ import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.message.BasicHeader; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; import org.springframework.http.HttpMethod; @@ -31,7 +31,7 @@ import static com.sap.cloud.security.xsuaa.http.HttpHeaders.X_OSB_PLAN; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.times; @@ -56,7 +56,7 @@ public DefaultOAuth2TokenKeyServiceTest() throws IOException { jsonWebKeysAsString = IOUtils.resourceToString("/jsonWebTokenKeys.json", StandardCharsets.UTF_8); } - @Before + @BeforeEach public void setUp() { httpClient = Mockito.mock(CloseableHttpClient.class); cut = new DefaultOAuth2TokenKeyService(httpClient); @@ -182,4 +182,4 @@ private ArgumentMatcher isCorrectHttpGetRequest() { return hasCorrectURI && correctMethod && correctTenantHeader && correctClientId && correctAzp; }; } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOAuth2TokenServiceTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOAuth2TokenServiceTest.java index b62f0c43d2..954d0ccc16 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOAuth2TokenServiceTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOAuth2TokenServiceTest.java @@ -22,12 +22,12 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; import org.assertj.core.util.Maps; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.LoggerFactory; import org.slf4j.MDC; @@ -41,11 +41,11 @@ import static java.util.Collections.emptyMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DefaultOAuth2TokenServiceTest { private static final String ACCESS_TOKEN = "abc123"; @@ -59,7 +59,7 @@ public class DefaultOAuth2TokenServiceTest { private CloseableHttpClient mockHttpClient; private DefaultOAuth2TokenService cut; - @Before + @BeforeEach public void setup() { mockHttpClient = Mockito.mock(CloseableHttpClient.class); cut = new DefaultOAuth2TokenService(mockHttpClient); @@ -179,4 +179,4 @@ private OAuth2TokenResponse requestAccessToken(Map optionalParam return cut.requestAccessToken(TOKEN_ENDPOINT_URI, withoutAuthorizationHeader, optionalParameters); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOidcConfigurationServiceTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOidcConfigurationServiceTest.java index bf4fea6df8..70e0033693 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOidcConfigurationServiceTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/DefaultOidcConfigurationServiceTest.java @@ -12,8 +12,8 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.CloseableHttpClient; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; import org.springframework.http.HttpMethod; @@ -42,7 +42,7 @@ public DefaultOidcConfigurationServiceTest() throws IOException { jsonOidcConfiguration = IOUtils.resourceToString("/oidcConfiguration.json", StandardCharsets.UTF_8); } - @Before + @BeforeEach public void setUp() { httpClientMock = Mockito.mock(CloseableHttpClient.class); cut = new DefaultOidcConfigurationService(httpClientMock); @@ -148,4 +148,4 @@ private ArgumentMatcher isHttpGetAndContainsCorrectURI() { return hasCorrectURI && correctMethod; }; } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/OAuth2TokenResponseTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/OAuth2TokenResponseTest.java index 44fc349d68..61c8ec3f59 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/OAuth2TokenResponseTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/OAuth2TokenResponseTest.java @@ -6,14 +6,14 @@ package com.sap.cloud.security.xsuaa.client; import org.hamcrest.number.OrderingComparison; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.Instant; import java.util.concurrent.TimeUnit; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class OAuth2TokenResponseTest { diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/SpringOAuth2TokenKeyServiceTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/SpringOAuth2TokenKeyServiceTest.java index c69ef0e1be..e43c58e3d2 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/SpringOAuth2TokenKeyServiceTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/SpringOAuth2TokenKeyServiceTest.java @@ -7,8 +7,8 @@ import com.sap.cloud.security.xsuaa.http.HttpHeaders; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; import org.springframework.http.HttpEntity; @@ -25,7 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; @@ -51,7 +51,7 @@ public SpringOAuth2TokenKeyServiceTest() throws IOException { jsonWebKeysAsString = IOUtils.resourceToString("/jsonWebTokenKeys.json", StandardCharsets.UTF_8); } - @Before + @BeforeEach public void setUp() { restOperationsMock = mock(RestOperations.class); cut = new SpringOAuth2TokenKeyService(restOperationsMock); @@ -123,4 +123,4 @@ private ArgumentMatcher httpEntityContainsMandatoryHeaders() { }; } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/SpringOidcConfigurationServiceTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/SpringOidcConfigurationServiceTest.java index b2d53dc9c4..c46467f8ed 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/SpringOidcConfigurationServiceTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/SpringOidcConfigurationServiceTest.java @@ -6,8 +6,8 @@ package com.sap.cloud.security.xsuaa.client; import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; @@ -37,7 +37,7 @@ public SpringOidcConfigurationServiceTest() throws IOException { jsonOidcConfiguration = IOUtils.resourceToString("/oidcConfiguration.json", StandardCharsets.UTF_8); } - @Before + @BeforeEach public void setUp() throws Exception { restOperationsMock = mock(RestOperations.class); cut = new SpringOidcConfigurationService(restOperationsMock); @@ -102,4 +102,4 @@ private OAuth2ServiceEndpointsProvider retrieveEndpoints() throws OAuth2ServiceE private OAuth2ServiceEndpointsProvider retrieveEndpoints(URI endpointsEndpointUri) throws OAuth2ServiceException { return cut.retrieveEndpoints(endpointsEndpointUri); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaDefaultEndpointsTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaDefaultEndpointsTest.java index 78bf9a5958..bcf708fdfe 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaDefaultEndpointsTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaDefaultEndpointsTest.java @@ -6,8 +6,8 @@ package com.sap.cloud.security.xsuaa.client; import com.sap.cloud.security.config.OAuth2ServiceConfiguration; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.net.URI; @@ -16,6 +16,7 @@ import static com.sap.cloud.security.config.CredentialType.X509; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; public class XsuaaDefaultEndpointsTest { @@ -24,7 +25,7 @@ public class XsuaaDefaultEndpointsTest { private static final String CERT_URL = "https://subdomain.cert.myauth.com"; private OAuth2ServiceEndpointsProvider cut; - @Before + @BeforeEach public void setUp() { oAuth2ServiceConfiguration = Mockito.mock(OAuth2ServiceConfiguration.class); } @@ -61,20 +62,24 @@ public void getEndpoint_forCertUrl() { assertThat(cut.getTokenEndpoint().toString(), is(CERT_URL + "/oauth/token")); } - @Test(expected = IllegalArgumentException.class) + @Test public void getEndpoint_throwsException_whenBaseUriIsNull() { - new XsuaaDefaultEndpoints(null, CERT_URL); + assertThrows(IllegalArgumentException.class, () -> { + new XsuaaDefaultEndpoints(null, CERT_URL); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void getJwksUri_throwsException_whenBaseUriIsNull() { - Mockito.when(oAuth2ServiceConfiguration.getCertUrl()).thenReturn(URI.create(CERT_URL)); - Mockito.when(oAuth2ServiceConfiguration.getCredentialType()).thenReturn(X509); + assertThrows(IllegalArgumentException.class, () -> { + Mockito.when(oAuth2ServiceConfiguration.getCertUrl()).thenReturn(URI.create(CERT_URL)); + Mockito.when(oAuth2ServiceConfiguration.getCredentialType()).thenReturn(X509); - cut = new XsuaaDefaultEndpoints(oAuth2ServiceConfiguration); + cut = new XsuaaDefaultEndpoints(oAuth2ServiceConfiguration); - assertThat(cut.getTokenEndpoint().toString(), is(CERT_URL + "/oauth/token")); // ok - cut.getJwksUri(); // raise exception + assertThat(cut.getTokenEndpoint().toString(), is(CERT_URL + "/oauth/token")); // ok + cut.getJwksUri(); // raise exception + }); // raise exception } @Test diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceClientCredentialsTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceClientCredentialsTest.java index 287f638541..1d262815b3 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceClientCredentialsTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceClientCredentialsTest.java @@ -13,12 +13,12 @@ import com.sap.cloud.security.config.ClientIdentity; import com.sap.cloud.security.servlet.MDCHelper; import org.assertj.core.api.Assertions; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.LoggerFactory; import org.slf4j.MDC; import org.springframework.http.HttpEntity; @@ -39,11 +39,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class XsuaaOAuth2TokenServiceClientCredentialsTest { OAuth2TokenService cut; @@ -54,7 +55,7 @@ public class XsuaaOAuth2TokenServiceClientCredentialsTest { @Mock RestOperations mockRestOperations; - @Before + @BeforeEach public void setup() { cut = new XsuaaOAuth2TokenService(mockRestOperations); clientIdentity = new ClientCredentials("clientid", "mysecretpassword"); @@ -77,20 +78,24 @@ public void retrieveToken_throwsOnNullValues() { .isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("clientIdentity"); } - @Test(expected = OAuth2ServiceException.class) - public void retrieveToken_throwsIfHttpStatusUnauthorized() throws OAuth2ServiceException { - Mockito.when(mockRestOperations.postForEntity(any(URI.class), any(HttpEntity.class), eq(Map.class))) - .thenThrow(new HttpClientErrorException(HttpStatus.UNAUTHORIZED)); - cut.retrieveAccessTokenViaClientCredentialsGrant(tokenEndpoint, clientIdentity, null, - null, null, false); + @Test + public void retrieveToken_throwsIfHttpStatusUnauthorized() { + assertThrows(OAuth2ServiceException.class, () -> { + Mockito.when(mockRestOperations.postForEntity(any(URI.class), any(HttpEntity.class), eq(Map.class))) + .thenThrow(new HttpClientErrorException(HttpStatus.UNAUTHORIZED)); + cut.retrieveAccessTokenViaClientCredentialsGrant(tokenEndpoint, clientIdentity, null, + null, null, false); + }); } - @Test(expected = OAuth2ServiceException.class) - public void retrieveToken_throwsIfHttpStatusNotOk() throws OAuth2ServiceException { - Mockito.when(mockRestOperations.postForEntity(any(URI.class), any(HttpEntity.class), eq(Map.class))) - .thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); - cut.retrieveAccessTokenViaClientCredentialsGrant(tokenEndpoint, clientIdentity, - null, null, null, false); + @Test + public void retrieveToken_throwsIfHttpStatusNotOk() { + assertThrows(OAuth2ServiceException.class, () -> { + Mockito.when(mockRestOperations.postForEntity(any(URI.class), any(HttpEntity.class), eq(Map.class))) + .thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); + cut.retrieveAccessTokenViaClientCredentialsGrant(tokenEndpoint, clientIdentity, + null, null, null, false); + }); } @Test @@ -192,4 +197,4 @@ public void correlationIdProvisioning() throws IOException { MDC.clear(); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceJwtBearerTokenTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceJwtBearerTokenTest.java index 8e2928e971..9595608fd9 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceJwtBearerTokenTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceJwtBearerTokenTest.java @@ -7,13 +7,13 @@ import com.sap.cloud.security.config.ClientCredentials; import com.sap.cloud.security.config.ClientIdentity; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.*; import org.springframework.util.MultiValueMap; import org.springframework.web.client.HttpClientErrorException; @@ -28,11 +28,12 @@ import static java.util.Collections.emptyMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class XsuaaOAuth2TokenServiceJwtBearerTokenTest { private OAuth2TokenService cut; @@ -47,7 +48,7 @@ public class XsuaaOAuth2TokenServiceJwtBearerTokenTest { @Mock private RestOperations mockRestOperations; - @Before + @BeforeEach public void setup() { response = new HashMap<>(); response.putIfAbsent(ACCESS_TOKEN, "f529.dd6e30.d454677322aaabb0"); @@ -59,20 +60,24 @@ public void setup() { cut = new XsuaaOAuth2TokenService(mockRestOperations); } - @Test(expected = OAuth2ServiceException.class) - public void retrieveToken_httpStatusUnauthorized_throwsException() throws OAuth2ServiceException { - throwExceptionOnPost(HttpStatus.UNAUTHORIZED); + @Test + public void retrieveToken_httpStatusUnauthorized_throwsException() { + assertThrows(OAuth2ServiceException.class, () -> { + throwExceptionOnPost(HttpStatus.UNAUTHORIZED); - cut.retrieveAccessTokenViaJwtBearerTokenGrant(tokenEndpoint, clientIdentity, - jwtToken, null, null, false); + cut.retrieveAccessTokenViaJwtBearerTokenGrant(tokenEndpoint, clientIdentity, + jwtToken, null, null, false); + }); } - @Test(expected = OAuth2ServiceException.class) - public void retrieveToken_httpStatusNotOk_throwsException() throws OAuth2ServiceException { - throwExceptionOnPost(HttpStatus.BAD_REQUEST); + @Test + public void retrieveToken_httpStatusNotOk_throwsException() { + assertThrows(OAuth2ServiceException.class, () -> { + throwExceptionOnPost(HttpStatus.BAD_REQUEST); - cut.retrieveAccessTokenViaJwtBearerTokenGrant(tokenEndpoint, clientIdentity, - jwtToken, null, null, false); + cut.retrieveAccessTokenViaJwtBearerTokenGrant(tokenEndpoint, clientIdentity, + jwtToken, null, null, false); + }); } @Test @@ -197,4 +202,4 @@ private void throwExceptionOnPost(HttpStatus unauthorized) { .thenThrow(new HttpClientErrorException(unauthorized)); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServicePasswordTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServicePasswordTest.java index dd18abf17d..7a0ebac378 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServicePasswordTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServicePasswordTest.java @@ -7,13 +7,13 @@ import com.sap.cloud.security.config.ClientCredentials; import com.sap.cloud.security.config.ClientIdentity; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.*; import org.springframework.util.MultiValueMap; import org.springframework.web.client.HttpClientErrorException; @@ -28,11 +28,12 @@ import static java.util.Collections.emptyMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class XsuaaOAuth2TokenServicePasswordTest { private OAuth2TokenService cut; @@ -50,7 +51,7 @@ public class XsuaaOAuth2TokenServicePasswordTest { @Mock private RestOperations mockRestOperations; - @Before + @BeforeEach public void setup() { response = new HashMap(); response.putIfAbsent(ACCESS_TOKEN, "f529.dd6e30.d454677322aaabb0"); @@ -62,20 +63,24 @@ public void setup() { cut = new XsuaaOAuth2TokenService(mockRestOperations); } - @Test(expected = OAuth2ServiceException.class) - public void retrieveToken_httpStatusUnauthorized_throwsException() throws OAuth2ServiceException { - throwExceptionOnPost(HttpStatus.UNAUTHORIZED); + @Test + public void retrieveToken_httpStatusUnauthorized_throwsException() { + assertThrows(OAuth2ServiceException.class, () -> { + throwExceptionOnPost(HttpStatus.UNAUTHORIZED); - cut.retrieveAccessTokenViaPasswordGrant(tokenEndpoint, clientIdentity, - username, password, null, null, false); + cut.retrieveAccessTokenViaPasswordGrant(tokenEndpoint, clientIdentity, + username, password, null, null, false); + }); } - @Test(expected = OAuth2ServiceException.class) - public void retrieveToken_httpStatusNotOk_throwsException() throws OAuth2ServiceException { - throwExceptionOnPost(HttpStatus.BAD_REQUEST); + @Test + public void retrieveToken_httpStatusNotOk_throwsException() { + assertThrows(OAuth2ServiceException.class, () -> { + throwExceptionOnPost(HttpStatus.BAD_REQUEST); - cut.retrieveAccessTokenViaPasswordGrant(tokenEndpoint, clientIdentity, - username, password, null, null, false); + cut.retrieveAccessTokenViaPasswordGrant(tokenEndpoint, clientIdentity, + username, password, null, null, false); + }); } @Test @@ -213,4 +218,4 @@ private void throwExceptionOnPost(HttpStatus unauthorized) { .thenThrow(new HttpClientErrorException(unauthorized)); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceRefreshTokenTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceRefreshTokenTest.java index 246cb57a39..53f2dc3cfe 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceRefreshTokenTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceRefreshTokenTest.java @@ -7,12 +7,12 @@ import com.sap.cloud.security.config.ClientCredentials; import com.sap.cloud.security.config.ClientIdentity; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.HttpEntity; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -27,12 +27,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.eq; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class XsuaaOAuth2TokenServiceRefreshTokenTest { private static final String refreshToken = "d2faefe7ea834ba895d20730f106128c-r"; @@ -45,7 +46,7 @@ public class XsuaaOAuth2TokenServiceRefreshTokenTest { @Mock RestOperations mockRestOperations; - @Before + @BeforeEach public void setup() { cut = new XsuaaOAuth2TokenService(mockRestOperations); clientIdentity = new ClientCredentials("clientid", "mysecretpassword"); @@ -71,20 +72,24 @@ public void retrieveToken_throwsOnNullValues() { .isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("refreshToken"); } - @Test(expected = OAuth2ServiceException.class) - public void retrieveToken_throwsIfHttpStatusUnauthorized() throws OAuth2ServiceException { - Mockito.when(mockRestOperations.postForEntity(eq(tokenEndpoint), any(HttpEntity.class), eq(Map.class))) - .thenThrow(new HttpClientErrorException(HttpStatus.UNAUTHORIZED)); - cut.retrieveAccessTokenViaRefreshToken(tokenEndpoint, clientIdentity, - refreshToken, null, true); + @Test + public void retrieveToken_throwsIfHttpStatusUnauthorized() { + assertThrows(OAuth2ServiceException.class, () -> { + Mockito.when(mockRestOperations.postForEntity(eq(tokenEndpoint), any(HttpEntity.class), eq(Map.class))) + .thenThrow(new HttpClientErrorException(HttpStatus.UNAUTHORIZED)); + cut.retrieveAccessTokenViaRefreshToken(tokenEndpoint, clientIdentity, + refreshToken, null, true); + }); } - @Test(expected = OAuth2ServiceException.class) - public void retrieveToken_throwsIfHttpStatusNotOk() throws OAuth2ServiceException { - Mockito.when(mockRestOperations.postForEntity(eq(tokenEndpoint), any(HttpEntity.class), eq(Map.class))) - .thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); - cut.retrieveAccessTokenViaRefreshToken(tokenEndpoint, clientIdentity, - refreshToken, null, true); + @Test + public void retrieveToken_throwsIfHttpStatusNotOk() { + assertThrows(OAuth2ServiceException.class, () -> { + Mockito.when(mockRestOperations.postForEntity(eq(tokenEndpoint), any(HttpEntity.class), eq(Map.class))) + .thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST)); + cut.retrieveAccessTokenViaRefreshToken(tokenEndpoint, clientIdentity, + refreshToken, null, true); + }); } @Test @@ -108,4 +113,4 @@ public void retrieveToken() throws OAuth2ServiceException { assertThat(accessToken.getTokenType(), is(responseMap.get(TOKEN_TYPE))); assertNotNull(accessToken.getExpiredAt()); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceTest.java index 5b045a2782..fe58798a08 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/client/XsuaaOAuth2TokenServiceTest.java @@ -6,20 +6,26 @@ package com.sap.cloud.security.xsuaa.client; import com.sap.cloud.security.xsuaa.tokenflows.TokenCacheConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.web.client.RestOperations; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class XsuaaOAuth2TokenServiceTest { - @Test(expected = IllegalArgumentException.class) + @Test public void initialize_throwsIfRestOperationsIsNull() { - new XsuaaOAuth2TokenService(null, TokenCacheConfiguration.cacheDisabled()); + assertThrows(IllegalArgumentException.class, () -> { + new XsuaaOAuth2TokenService(null, TokenCacheConfiguration.cacheDisabled()); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void initialize_throwsIfCacheConfigurationIsNull() { - new XsuaaOAuth2TokenService(Mockito.mock(RestOperations.class), null); + assertThrows(IllegalArgumentException.class, () -> { + new XsuaaOAuth2TokenService(Mockito.mock(RestOperations.class), null); + }); } } \ No newline at end of file diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersFactoryTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersFactoryTest.java index 638863a98b..f8e1f98374 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersFactoryTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersFactoryTest.java @@ -5,7 +5,7 @@ */ package com.sap.cloud.security.xsuaa.http; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.sap.cloud.security.xsuaa.http.HttpHeaders.*; import static com.sap.cloud.security.xsuaa.http.MediaType.APPLICATION_FORM_URLENCODED; @@ -44,4 +44,4 @@ public void createWithXzidHeader() { assertThat(headers.getHeaders()).containsExactlyInAnyOrder(X_ZID, ACCEPT_JSON_HEADER, CONTENT_TYPE_URL_ENCODED); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersTest.java index 2e0d76e1cc..2065cf6510 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/http/HttpHeadersTest.java @@ -5,7 +5,7 @@ */ package com.sap.cloud.security.xsuaa.http; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.util.Lists.newArrayList; @@ -47,4 +47,4 @@ public void toStringTest() { HttpHeaders headers = new HttpHeaders(header, anotherHeader); assertThat(headers).hasToString("HttpHeaders: [ \"a: a_value\", \"b: b_value\" ]"); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/jwt/Base64JwtDecoderTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/jwt/Base64JwtDecoderTest.java index 0fef806a98..b299cadb96 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/jwt/Base64JwtDecoderTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/jwt/Base64JwtDecoderTest.java @@ -6,13 +6,11 @@ package com.sap.cloud.security.xsuaa.jwt; import com.sap.cloud.security.xsuaa.test.JwtGenerator; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.security.oauth2.jwt.Jwt; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; public class Base64JwtDecoderTest { @@ -27,9 +25,6 @@ public class Base64JwtDecoderTest { .setJku(JKU_HEADER) .getToken(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Test public void itDecodesAnEncodedJwtString() { String expectedDecodedJWTPayload = "{\"jti\":\"e3c30e2474cd46609a262eda9d9dc26d\",\"ext_attr\":{\"enhancer\":\"XSUAA\",\"zdn\":\"acme-enterprises\"},\"xs.system.attributes\":{\"xs.rolecollections\":[]},\"given_name\":\"Andrea Maria\",\"xs.user.attributes\":{},\"family_name\":\"Millsap\",\"sub\":\"1234\",\"scope\":[\"openid\",\"uaa.user\"],\"client_id\":\"my-app1\",\"cid\":\"my-app1\",\"azp\":\"my-app1\",\"grant_type\":\"authorization_code\",\"user_id\":\"1234\",\"origin\":\"ldap\",\"user_name\":\"am.millsap@sap.com\",\"email\":\"am.millsap@sap.com\",\"auth_time\":1564785720,\"rev_sig\":\"87e7c016\",\"iat\":1564785720,\"exp\":1564785721,\"iss\":\"http://acme-enterprises.example.com/uaa/oauth/token\",\"zid\":\"2345\",\"aud\":[\"my-app1\",\"uaa\",\"openid\"]}"; @@ -43,10 +38,10 @@ public void itDecodesAnEncodedJwtString() { @Test public void itThrowsIfJwtDoesNotConsistOfThreeSegments() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("JWT token does not consist of 'header'.'payload'.'signature'."); + Throwable exception = assertThrows(IllegalArgumentException.class, () -> - Base64JwtDecoder.getInstance().decode("invalid"); + Base64JwtDecoder.getInstance().decode("invalid")); + assertTrue(exception.getMessage().contains("JWT token does not consist of 'header'.'payload'.'signature'.")); } @Test diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/ClientCredentialsTokenFlowTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/ClientCredentialsTokenFlowTest.java index 581c924319..10efc5558c 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/ClientCredentialsTokenFlowTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/ClientCredentialsTokenFlowTest.java @@ -9,13 +9,13 @@ import com.sap.cloud.security.config.ClientIdentity; import com.sap.cloud.security.config.OAuth2ServiceConfiguration; import com.sap.cloud.security.xsuaa.client.*; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.HashMap; import java.util.Map; @@ -27,10 +27,9 @@ import static java.util.Collections.emptyMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ClientCredentialsTokenFlowTest { @Mock @@ -42,7 +41,7 @@ public class ClientCredentialsTokenFlowTest { private static final String JWT_ACCESS_TOKEN = "4bfad399ca10490da95c2b5eb4451d53"; - @Before + @BeforeEach public void setup() { OAuth2ServiceConfiguration oAuth2ServiceConfiguration = Mockito.mock(OAuth2ServiceConfiguration.class); Mockito.when(oAuth2ServiceConfiguration.getUrl()).thenReturn(XSUAA_BASE_URI); @@ -87,9 +86,8 @@ public void execute_throwsIfServiceRaisesException() throws OAuth2ServiceExcepti isNull(), isNull(), anyMap(), anyBoolean())) .thenThrow(new OAuth2ServiceException("exception executed REST call")); - assertThatThrownBy(() -> { - cut.execute(); - }).isInstanceOf(TokenFlowException.class) + assertThatThrownBy(() -> + cut.execute()).isInstanceOf(TokenFlowException.class) .hasMessageContaining( "Error requesting technical user token with grant_type 'client_credentials': exception executed REST call"); } diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/JwtBearerTokenFlowTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/JwtBearerTokenFlowTest.java index f5226bc2b5..e4615b0c45 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/JwtBearerTokenFlowTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/JwtBearerTokenFlowTest.java @@ -10,11 +10,11 @@ import com.sap.cloud.security.xsuaa.client.OAuth2ServiceException; import com.sap.cloud.security.xsuaa.client.OAuth2TokenResponse; import com.sap.cloud.security.xsuaa.client.OAuth2TokenService; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.HashMap; import java.util.Map; @@ -22,17 +22,16 @@ import static com.sap.cloud.security.xsuaa.tokenflows.TestConstants.*; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class JwtBearerTokenFlowTest { private OAuth2TokenService tokenService; private OAuth2ServiceEndpointsProvider endpointsProvider; private JwtBearerTokenFlow cut; - @Before + @BeforeEach public void setUp() { tokenService = mock(OAuth2TokenService.class); endpointsProvider = mock(OAuth2ServiceEndpointsProvider.class); @@ -240,4 +239,4 @@ private void verifyThatDisableCacheIs(boolean disableCache) throws OAuth2Service verify(tokenService, times(1)) .retrieveAccessTokenViaJwtBearerTokenGrant(any(), any(), any(), any(), any(), eq(disableCache)); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/PasswordTokenFlowTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/PasswordTokenFlowTest.java index 9257ee8abf..5e2382892d 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/PasswordTokenFlowTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/PasswordTokenFlowTest.java @@ -10,27 +10,26 @@ import com.sap.cloud.security.xsuaa.client.OAuth2TokenResponse; import com.sap.cloud.security.xsuaa.client.OAuth2TokenService; import org.assertj.core.util.Maps; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.Map; import static com.sap.cloud.security.xsuaa.tokenflows.TestConstants.*; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PasswordTokenFlowTest { private OAuth2TokenService tokenService; private OAuth2ServiceEndpointsProvider endpointsProvider; private PasswordTokenFlow cut; - @Before + @BeforeEach public void setUp() { tokenService = mock(OAuth2TokenService.class); endpointsProvider = mock(OAuth2ServiceEndpointsProvider.class); @@ -178,4 +177,4 @@ private void verifyThatDisableCacheIs(boolean disableCache) throws OAuth2Service .retrieveAccessTokenViaPasswordGrant(any(), any(), any(), any(), any(), any(), eq(disableCache)); } -} \ No newline at end of file +} diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/RefreshTokenFlowTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/RefreshTokenFlowTest.java index 54cccaac09..5c542f590a 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/RefreshTokenFlowTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/RefreshTokenFlowTest.java @@ -9,22 +9,21 @@ import com.sap.cloud.security.config.ClientIdentity; import com.sap.cloud.security.config.OAuth2ServiceConfiguration; import com.sap.cloud.security.xsuaa.client.*; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import static com.sap.cloud.security.xsuaa.tokenflows.TestConstants.TOKEN_ENDPOINT_URI; import static com.sap.cloud.security.xsuaa.tokenflows.TestConstants.XSUAA_BASE_URI; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class RefreshTokenFlowTest { @Mock @@ -37,7 +36,7 @@ public class RefreshTokenFlowTest { private static final String REFRESH_TOKEN = "99e2cecfa54f4957a782f07168915b69-r"; private OAuth2ServiceEndpointsProvider endpointsProvider; - @Before + @BeforeEach public void setup() { OAuth2ServiceConfiguration oAuth2ServiceConfiguration = Mockito.mock(OAuth2ServiceConfiguration.class); Mockito.when(oAuth2ServiceConfiguration.getUrl()).thenReturn(XSUAA_BASE_URI); diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/TokenFlowExceptionTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/TokenFlowExceptionTest.java index 98177ee8ab..d791d43bf2 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/TokenFlowExceptionTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/TokenFlowExceptionTest.java @@ -5,10 +5,10 @@ */ package com.sap.cloud.security.xsuaa.tokenflows; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class TokenFlowExceptionTest { @@ -19,20 +19,20 @@ public class TokenFlowExceptionTest { public void constructors() { TokenFlowException ex = new TokenFlowException(); - assertNull("Exception should not have any message.", ex.getMessage()); - assertNull("Exception should not have any cause.", ex.getCause()); + assertNull(ex.getMessage(), "Exception should not have any message."); + assertNull(ex.getCause(), "Exception should not have any cause."); ex = new TokenFlowException(MESSAGE); - assertNotNull("Exception should have a message.", ex.getMessage()); - assertNull("Exception should not have any cause.", ex.getCause()); + assertNotNull(ex.getMessage(), "Exception should have a message."); + assertNull(ex.getCause(), "Exception should not have any cause."); ex = new TokenFlowException(CAUSE); - assertNotNull("Exception should not have a default message.", ex.getMessage()); - assertNotNull("Exception should have a cause.", ex.getCause()); + assertNotNull(ex.getMessage(), "Exception should not have a default message."); + assertNotNull(ex.getCause(), "Exception should have a cause."); ex = new TokenFlowException(MESSAGE, CAUSE); - assertNotNull("Exception should have a message.", ex.getMessage()); - assertNotNull("Exception should have a cause.", ex.getCause()); + assertNotNull(ex.getMessage(), "Exception should have a message."); + assertNotNull(ex.getCause(), "Exception should have a cause."); } } diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/XsuaaTokenFlowsTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/XsuaaTokenFlowsTest.java index 44840ce61d..d2b1b57346 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/XsuaaTokenFlowsTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/tokenflows/XsuaaTokenFlowsTest.java @@ -8,11 +8,11 @@ import com.sap.cloud.security.config.ClientCredentials; import com.sap.cloud.security.config.OAuth2ServiceConfiguration; import com.sap.cloud.security.xsuaa.client.*; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.HttpEntity; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -27,12 +27,12 @@ import static com.sap.cloud.security.xsuaa.tokenflows.TestConstants.CLIENT_CREDENTIALS; import static com.sap.cloud.security.xsuaa.tokenflows.TestConstants.XSUAA_BASE_URI; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class XsuaaTokenFlowsTest { private static OAuth2ServiceConfiguration oAuth2ServiceConfiguration; @@ -41,7 +41,7 @@ public class XsuaaTokenFlowsTest { private OAuth2TokenService oAuth2TokenService; private RestOperations restOperations; - @Before + @BeforeEach public void setup() { oAuth2ServiceConfiguration = Mockito.mock(OAuth2ServiceConfiguration.class); Mockito.when(oAuth2ServiceConfiguration.getUrl()).thenReturn(XSUAA_BASE_URI); @@ -76,19 +76,19 @@ public void constructor_throwsOnNullValues() { @Test public void startRefreshTokenFlow() { RefreshTokenFlow flow = cut.refreshTokenFlow(); - assertNotNull("RefreshTokenFlow must not be null.", flow); + assertNotNull(flow, "RefreshTokenFlow must not be null."); } @Test public void startClientCredentialsFlow() { ClientCredentialsTokenFlow flow = cut.clientCredentialsTokenFlow(); - assertNotNull("ClientCredentialsTokenFlow must not be null.", flow); + assertNotNull(flow, "ClientCredentialsTokenFlow must not be null."); } @Test public void startPasswordTokenFlow() { PasswordTokenFlow flow = cut.passwordTokenFlow(); - assertNotNull("PasswordTokenFlow must not be null.", flow); + assertNotNull(flow, "PasswordTokenFlow must not be null."); } @Test diff --git a/token-client/src/test/java/com/sap/cloud/security/xsuaa/util/UriUtilTest.java b/token-client/src/test/java/com/sap/cloud/security/xsuaa/util/UriUtilTest.java index 8ede8893b1..bf6ee1f18a 100644 --- a/token-client/src/test/java/com/sap/cloud/security/xsuaa/util/UriUtilTest.java +++ b/token-client/src/test/java/com/sap/cloud/security/xsuaa/util/UriUtilTest.java @@ -5,7 +5,7 @@ */ package com.sap.cloud.security.xsuaa.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.URI;