From 600f3d0d0f572d82621ce0d334c07c6828c8ca0c Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Sun, 24 Jan 2021 14:52:48 +0100 Subject: [PATCH] test classes package-private; use mockStatic() --- .../HTTPVaultConnectorOfflineTest.java | 52 ++++++----------- .../connector/HTTPVaultConnectorTest.java | 58 +++++++++---------- .../HTTPVaultConnectorBuilderTest.java | 2 +- .../VaultConnectorExceptionTest.java | 14 ++--- .../HTTPVaultConnectorFactoryTest.java | 4 +- .../connector/model/AppRoleBuilderTest.java | 16 ++--- .../connector/model/AppRoleSecretTest.java | 8 +-- .../connector/model/AuthBackendTest.java | 4 +- .../connector/model/TokenBuilderTest.java | 16 ++--- .../connector/model/TokenRoleBuilderTest.java | 8 +-- .../model/response/AppRoleResponseTest.java | 6 +- .../response/AuthMethodsResponseTest.java | 6 +- .../model/response/AuthResponseTest.java | 6 +- .../response/CredentialsResponseTest.java | 4 +- .../model/response/HealthResponseTest.java | 4 +- .../model/response/MetadataResponseTest.java | 4 +- .../model/response/SealResponseTest.java | 4 +- .../response/SecretListResponseTest.java | 4 +- .../model/response/SecretResponseTest.java | 6 +- .../response/SecretVersionResponseTest.java | 4 +- .../model/response/TokenResponseTest.java | 6 +- 21 files changed, 109 insertions(+), 127 deletions(-) diff --git a/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorOfflineTest.java b/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorOfflineTest.java index 8c930b5..b9df727 100644 --- a/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorOfflineTest.java +++ b/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorOfflineTest.java @@ -20,9 +20,6 @@ import de.stklcode.jvault.connector.exception.InvalidRequestException; import de.stklcode.jvault.connector.exception.InvalidResponseException; import de.stklcode.jvault.connector.exception.PermissionDeniedException; import de.stklcode.jvault.connector.exception.VaultConnectorException; -import net.bytebuddy.ByteBuddy; -import net.bytebuddy.agent.ByteBuddyAgent; -import net.bytebuddy.dynamic.loading.ClassReloadingStrategy; import org.apache.http.ProtocolVersion; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.entity.ContentType; @@ -33,6 +30,7 @@ import org.apache.http.message.BasicStatusLine; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; import java.io.IOException; import java.io.InputStream; @@ -42,8 +40,6 @@ import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.Collections; -import static net.bytebuddy.implementation.MethodDelegation.to; -import static net.bytebuddy.matcher.ElementMatchers.named; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -59,45 +55,31 @@ import static org.mockito.Mockito.*; * @author Stefan Kalscheuer * @since 0.7.0 */ -public class HTTPVaultConnectorOfflineTest { +class HTTPVaultConnectorOfflineTest { private static final String INVALID_URL = "foo:/\\1nv4l1d_UrL"; - private static CloseableHttpClient httpMock = mock(CloseableHttpClient.class); - private CloseableHttpResponse responseMock = mock(CloseableHttpResponse.class); + private static CloseableHttpClient httpMock; + private final CloseableHttpResponse responseMock = mock(CloseableHttpResponse.class); @BeforeAll - public static void initByteBuddy() { - // Install ByteBuddy Agent. - ByteBuddyAgent.install(); - } - - /** - * Helper method for redefinition of {@link HttpClientBuilder#create()} from {@link #initHttpMock()}. - * - * @return Mocked HTTP client builder. - */ - public static HttpClientBuilder create() { - return new MockedHttpClientBuilder(); + static void prepare() { + // Mock the static HTTPClient creation. + MockedStatic hcbMock = mockStatic(HttpClientBuilder.class); + hcbMock.when(HttpClientBuilder::create).thenReturn(new MockedHttpClientBuilder()); } @BeforeEach - public void initHttpMock() { - // Redefine static method to return Mock on HttpClientBuilder creation. - new ByteBuddy().redefine(HttpClientBuilder.class) - .method(named("create")) - .intercept(to(HTTPVaultConnectorOfflineTest.class)) - .make() - .load(HttpClientBuilder.class.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent()); - + void init() { // Re-initialize HTTP mock to ensure fresh (empty) results. httpMock = mock(CloseableHttpClient.class); } + /** * Test exceptions thrown during request. */ @Test - public void requestExceptionTest() throws IOException { + void requestExceptionTest() throws IOException { HTTPVaultConnector connector = new HTTPVaultConnector("http://127.0.0.1", null, 0, 250); // Test invalid response code. @@ -154,7 +136,7 @@ public class HTTPVaultConnectorOfflineTest { * Test constructors of the {@link HTTPVaultConnector} class. */ @Test - public void constructorTest() throws IOException, CertificateException { + void constructorTest() throws IOException, CertificateException { final String url = "https://vault.example.net/test/"; final String hostname = "vault.example.com"; final Integer port = 1337; @@ -206,7 +188,7 @@ public class HTTPVaultConnectorOfflineTest { * This test is designed to test exceptions caught and thrown by seal-methods if Vault is not reachable. */ @Test - public void sealExceptionTest() throws IOException { + void sealExceptionTest() throws IOException { HTTPVaultConnector connector = new HTTPVaultConnector(INVALID_URL); try { connector.sealStatus(); @@ -233,7 +215,7 @@ public class HTTPVaultConnectorOfflineTest { * This test is designed to test exceptions caught and thrown by seal-methods if Vault is not reachable. */ @Test - public void healthExceptionTest() throws IOException { + void healthExceptionTest() throws IOException { HTTPVaultConnector connector = new HTTPVaultConnector(INVALID_URL); try { connector.getHealth(); @@ -259,7 +241,7 @@ public class HTTPVaultConnectorOfflineTest { * Test behavior on unparsable responses. */ @Test - public void parseExceptionTest() throws IOException { + void parseExceptionTest() throws IOException { HTTPVaultConnector connector = new HTTPVaultConnector("https://127.0.0.1", null, 0, 250); // Mock authorization. setPrivate(connector, "authorized", true); @@ -382,7 +364,7 @@ public class HTTPVaultConnectorOfflineTest { * Test requests that expect an empty response with code 204, but receive a 200 body. */ @Test - public void nonEmpty204ResponseTest() throws IOException { + void nonEmpty204ResponseTest() throws IOException { HTTPVaultConnector connector = new HTTPVaultConnector("https://127.0.0.1", null, 0, 250); // Mock authorization. setPrivate(connector, "authorized", true); @@ -454,7 +436,7 @@ public class HTTPVaultConnectorOfflineTest { } } - private Object getRequestHelperPrivate(HTTPVaultConnector connector, String fieldName) { + private Object getRequestHelperPrivate(HTTPVaultConnector connector, String fieldName) { try { return getPrivate(getPrivate(connector, "request"), fieldName); } catch (NoSuchFieldException | IllegalAccessException e) { diff --git a/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java b/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java index 214db72..6c4d265 100644 --- a/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java +++ b/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java @@ -52,7 +52,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; * @since 0.1 */ @Tag("online") -public class HTTPVaultConnectorTest { +class HTTPVaultConnectorTest { private static String VAULT_VERSION = "1.6.1"; // the vault version this test is supposed to run against private static final String KEY1 = "E38bkCm0VhUvpdCKGQpcohhD9XmcHJ/2hreOSY019Lho"; private static final String KEY2 = "O5OHwDleY3IiPdgw61cgHlhsrEm6tVJkrxhF6QAnILd1"; @@ -78,7 +78,7 @@ public class HTTPVaultConnectorTest { * Requires "vault" binary to be in current user's executable path. Not using MLock, so no extended rights required. */ @BeforeEach - public void setUp(TestInfo testInfo, @TempDir File tempDir) throws VaultConnectorException, IOException { + void setUp(TestInfo testInfo, @TempDir File tempDir) throws VaultConnectorException, IOException { /* Determine, if TLS is required */ boolean isTls = testInfo.getTags().contains("tls"); @@ -111,7 +111,7 @@ public class HTTPVaultConnectorTest { } @AfterEach - public void tearDown() { + void tearDown() { if (vaultProcess != null && vaultProcess.isAlive()) vaultProcess.destroy(); } @@ -133,7 +133,7 @@ public class HTTPVaultConnectorTest { @Order(10) @DisplayName("Read secrets") @SuppressWarnings("deprecation") - public void readSecretTest() { + void readSecretTest() { authUser(); assumeTrue(connector.isAuthorized()); @@ -210,7 +210,7 @@ public class HTTPVaultConnectorTest { @Test @Order(20) @DisplayName("List secrets") - public void listSecretsTest() { + void listSecretsTest() { authRoot(); assumeTrue(connector.isAuthorized()); /* Try to list secrets from valid path */ @@ -230,7 +230,7 @@ public class HTTPVaultConnectorTest { @Order(30) @DisplayName("Write secrets") @SuppressWarnings("deprecation") - public void writeSecretTest() { + void writeSecretTest() { authUser(); assumeTrue(connector.isAuthorized()); @@ -275,7 +275,7 @@ public class HTTPVaultConnectorTest { @Test @Order(40) @DisplayName("Delete secrets") - public void deleteSecretTest() { + void deleteSecretTest() { authUser(); assumeTrue(connector.isAuthorized()); @@ -316,7 +316,7 @@ public class HTTPVaultConnectorTest { @Test @Order(50) @DisplayName("Revoke secrets") - public void revokeTest() { + void revokeTest() { authRoot(); assumeTrue(connector.isAuthorized()); @@ -361,7 +361,7 @@ public class HTTPVaultConnectorTest { @Test @Order(10) @DisplayName("Read v2 secret") - public void readSecretTest() { + void readSecretTest() { authUser(); assumeTrue(connector.isAuthorized()); @@ -392,7 +392,7 @@ public class HTTPVaultConnectorTest { @Test @Order(20) @DisplayName("Write v2 secret") - public void writeSecretTest() { + void writeSecretTest() { authUser(); assumeTrue(connector.isAuthorized()); @@ -450,7 +450,7 @@ public class HTTPVaultConnectorTest { @Test @Order(30) @DisplayName("Read v2 metadata") - public void readSecretMetadataTest() { + void readSecretMetadataTest() { authUser(); assumeTrue(connector.isAuthorized()); @@ -487,7 +487,7 @@ public class HTTPVaultConnectorTest { @Test @Order(40) @DisplayName("Update v2 metadata") - public void updateSecretMetadataTest() { + void updateSecretMetadataTest() { authUser(); assumeTrue(connector.isAuthorized()); @@ -511,7 +511,7 @@ public class HTTPVaultConnectorTest { @Test @Order(50) @DisplayName("Version handling") - public void handleSecretVersionsTest() { + void handleSecretVersionsTest() { authUser(); assumeTrue(connector.isAuthorized()); @@ -588,7 +588,7 @@ public class HTTPVaultConnectorTest { @Order(10) @DisplayName("Authenticate with App-ID") @SuppressWarnings("deprecation") - public void authAppIdTest() { + void authAppIdTest() { /* Try unauthorized access first. */ assumeFalse(connector.isAuthorized()); @@ -613,7 +613,7 @@ public class HTTPVaultConnectorTest { @Order(20) @DisplayName("Register App-ID") @SuppressWarnings("deprecation") - public void registerAppIdTest() { + void registerAppIdTest() { /* Authorize. */ authRoot(); assumeTrue(connector.isAuthorized()); @@ -664,7 +664,7 @@ public class HTTPVaultConnectorTest { @Test @Order(10) @DisplayName("Authenticate with AppRole") - public void authAppRole() { + void authAppRole() { assumeFalse(connector.isAuthorized()); /* Authenticate with correct credentials */ @@ -724,7 +724,7 @@ public class HTTPVaultConnectorTest { @Test @Order(20) @DisplayName("List AppRoles") - public void listAppRoleTest() { + void listAppRoleTest() { /* Try unauthorized access first. */ assumeFalse(connector.isAuthorized()); @@ -772,7 +772,7 @@ public class HTTPVaultConnectorTest { @Test @Order(30) @DisplayName("Create AppRole") - public void createAppRoleTest() { + void createAppRoleTest() { /* Try unauthorized access first. */ assumeFalse(connector.isAuthorized()); try { @@ -974,7 +974,7 @@ public class HTTPVaultConnectorTest { @Test @Order(40) @DisplayName("Create AppRole secrets") - public void createAppRoleSecretTest() { + void createAppRoleSecretTest() { authRoot(); assumeTrue(connector.isAuthorized()); @@ -1028,7 +1028,7 @@ public class HTTPVaultConnectorTest { @Test @Order(10) @DisplayName("Authenticate with token") - public void authTokenTest() { + void authTokenTest() { TokenResponse res; final String invalidToken = "52135869df23a5e64c5d33a9785af5edb456b8a4a235d1fe135e6fba1c35edf6"; try { @@ -1054,7 +1054,7 @@ public class HTTPVaultConnectorTest { @Test @Order(20) @DisplayName("Create token") - public void createTokenTest() { + void createTokenTest() { authRoot(); assumeTrue(connector.isAuthorized()); @@ -1156,7 +1156,7 @@ public class HTTPVaultConnectorTest { @Test @Order(30) @DisplayName("Lookup token") - public void lookupTokenTest() { + void lookupTokenTest() { authRoot(); assumeTrue(connector.isAuthorized()); @@ -1192,7 +1192,7 @@ public class HTTPVaultConnectorTest { @Test @Order(40) @DisplayName("Token roles") - public void tokenRolesTest() { + void tokenRolesTest() { authRoot(); assumeTrue(connector.isAuthorized()); @@ -1281,7 +1281,7 @@ public class HTTPVaultConnectorTest { */ @Test @DisplayName("List auth methods") - public void authMethodsTest() { + void authMethodsTest() { /* Authenticate as valid user */ try { connector.authToken(TOKEN_ROOT); @@ -1304,7 +1304,7 @@ public class HTTPVaultConnectorTest { */ @Test @DisplayName("Authenticate with UserPass") - public void authUserPassTest() { + void authUserPassTest() { AuthResponse res = null; final String invalidUser = "foo"; final String invalidPass = "bar"; @@ -1332,7 +1332,7 @@ public class HTTPVaultConnectorTest { @Test @Tag("tls") @DisplayName("TLS connection test") - public void tlsConnectionTest() { + void tlsConnectionTest() { TokenResponse res; try { connector.authToken("52135869df23a5e64c5d33a9785af5edb456b8a4a235d1fe135e6fba1c35edf6"); @@ -1354,7 +1354,7 @@ public class HTTPVaultConnectorTest { */ @Test @DisplayName("Seal test") - public void sealTest() throws VaultConnectorException { + void sealTest() throws VaultConnectorException { SealResponse sealStatus = connector.sealStatus(); assumeFalse(sealStatus.isSealed()); @@ -1387,7 +1387,7 @@ public class HTTPVaultConnectorTest { */ @Test @DisplayName("Health test") - public void healthTest() { + void healthTest() { HealthResponse res = null; try { res = connector.getHealth(); @@ -1422,7 +1422,7 @@ public class HTTPVaultConnectorTest { */ @Test @DisplayName("Connector close test") - public void closeTest() { + void closeTest() { authUser(); assumeTrue(connector.isAuthorized()); diff --git a/src/test/java/de/stklcode/jvault/connector/builder/HTTPVaultConnectorBuilderTest.java b/src/test/java/de/stklcode/jvault/connector/builder/HTTPVaultConnectorBuilderTest.java index 0becec9..c9b2c79 100644 --- a/src/test/java/de/stklcode/jvault/connector/builder/HTTPVaultConnectorBuilderTest.java +++ b/src/test/java/de/stklcode/jvault/connector/builder/HTTPVaultConnectorBuilderTest.java @@ -38,7 +38,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.8.0 */ -public class HTTPVaultConnectorBuilderTest { +class HTTPVaultConnectorBuilderTest { private static final String VAULT_ADDR = "https://localhost:8201"; private static final Integer VAULT_MAX_RETRIES = 13; private static final String VAULT_TOKEN = "00001111-2222-3333-4444-555566667777"; diff --git a/src/test/java/de/stklcode/jvault/connector/exception/VaultConnectorExceptionTest.java b/src/test/java/de/stklcode/jvault/connector/exception/VaultConnectorExceptionTest.java index 74e1a26..8d2f433 100644 --- a/src/test/java/de/stklcode/jvault/connector/exception/VaultConnectorExceptionTest.java +++ b/src/test/java/de/stklcode/jvault/connector/exception/VaultConnectorExceptionTest.java @@ -29,19 +29,19 @@ import static org.hamcrest.core.Is.is; * @author Stefan Kalscheuer * @since 0.6.2 */ -public class VaultConnectorExceptionTest { +class VaultConnectorExceptionTest { private static final String MSG = "This is a test exception!"; private static final Throwable CAUSE = new Exception("Test-Cause"); private static final Integer STATUS_CODE = 1337; private static final String RESPONSE = "Dummy response"; @Test - public void authorizationRequiredExceptionTest() { + void authorizationRequiredExceptionTest() { assertEmptyConstructor(new AuthorizationRequiredException()); } @Test - public void connectionExceptionTest() { + void connectionExceptionTest() { assertEmptyConstructor(new ConnectionException()); assertMsgConstructor(new ConnectionException(MSG)); assertCauseConstructor(new ConnectionException(CAUSE)); @@ -49,7 +49,7 @@ public class VaultConnectorExceptionTest { } @Test - public void invalidRequestExceptionTest() { + void invalidRequestExceptionTest() { assertEmptyConstructor(new InvalidRequestException()); assertMsgConstructor(new InvalidRequestException(MSG)); assertCauseConstructor(new InvalidRequestException(CAUSE)); @@ -57,7 +57,7 @@ public class VaultConnectorExceptionTest { } @Test - public void invalidResponseExceptionTest() { + void invalidResponseExceptionTest() { assertEmptyConstructor(new InvalidResponseException()); assertMsgConstructor(new InvalidResponseException(MSG)); assertCauseConstructor(new InvalidResponseException(CAUSE)); @@ -93,7 +93,7 @@ public class VaultConnectorExceptionTest { } @Test - public void permissionDeniedExceptionTest() { + void permissionDeniedExceptionTest() { // Default message overwritten. PermissionDeniedException e = new PermissionDeniedException(); assertThat(e, is(instanceOf(VaultConnectorException.class))); @@ -108,7 +108,7 @@ public class VaultConnectorExceptionTest { } @Test - public void tlsExceptionTest() { + void tlsExceptionTest() { assertEmptyConstructor(new TlsException()); assertMsgConstructor(new TlsException(MSG)); assertCauseConstructor(new TlsException(CAUSE)); diff --git a/src/test/java/de/stklcode/jvault/connector/factory/HTTPVaultConnectorFactoryTest.java b/src/test/java/de/stklcode/jvault/connector/factory/HTTPVaultConnectorFactoryTest.java index 5cdbfc3..e136b26 100644 --- a/src/test/java/de/stklcode/jvault/connector/factory/HTTPVaultConnectorFactoryTest.java +++ b/src/test/java/de/stklcode/jvault/connector/factory/HTTPVaultConnectorFactoryTest.java @@ -38,7 +38,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.6.0 */ -public class HTTPVaultConnectorFactoryTest { +class HTTPVaultConnectorFactoryTest { private static String VAULT_ADDR = "https://localhost:8201"; private static Integer VAULT_MAX_RETRIES = 13; private static String VAULT_TOKEN = "00001111-2222-3333-4444-555566667777"; @@ -50,7 +50,7 @@ public class HTTPVaultConnectorFactoryTest { * Test building from environment variables */ @Test - public void testFromEnv() throws NoSuchFieldException, IllegalAccessException, IOException { + void testFromEnv() throws NoSuchFieldException, IllegalAccessException, IOException { /* Provide address only should be enough */ setenv(VAULT_ADDR, null, null, null); diff --git a/src/test/java/de/stklcode/jvault/connector/model/AppRoleBuilderTest.java b/src/test/java/de/stklcode/jvault/connector/model/AppRoleBuilderTest.java index 7dec796..6c4b7c7 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/AppRoleBuilderTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/AppRoleBuilderTest.java @@ -33,7 +33,7 @@ import static org.hamcrest.Matchers.*; * @author Stefan Kalscheuer * @since 0.4.0 */ -public class AppRoleBuilderTest { +class AppRoleBuilderTest { private static final String NAME = "TestRole"; private static final String ID = "test-id"; private static final Boolean BIND_SECRET_ID = true; @@ -58,7 +58,7 @@ public class AppRoleBuilderTest { NAME, ID, BIND_SECRET_ID, CIDR_1, SECRET_ID_NUM_USES, SECRET_ID_TTL, ENABLE_LOCAL_SECRET_IDS, TOKEN_TTL, TOKEN_MAX_TTL, POLICY, CIDR_1, TOKEN_EXPLICIT_MAX_TTL, TOKEN_NO_DEFAULT_POLICY, TOKEN_NUM_USES, TOKEN_PERIOD, TOKEN_TYPE.value()); @BeforeAll - public static void init() { + static void init() { BOUND_CIDR_LIST.add(CIDR_1); POLICIES.add(POLICY); } @@ -67,7 +67,7 @@ public class AppRoleBuilderTest { * Build role with only a name. */ @Test - public void buildDefaultTest() throws JsonProcessingException { + void buildDefaultTest() throws JsonProcessingException { AppRole role = AppRole.builder(NAME).build(); assertThat(role.getId(), is(nullValue())); assertThat(role.getBindSecretId(), is(nullValue())); @@ -95,7 +95,7 @@ public class AppRoleBuilderTest { * Build role with only a name. */ @Test - public void legacyBuildDefaultTest() throws JsonProcessingException { + void legacyBuildDefaultTest() throws JsonProcessingException { AppRole role = new AppRoleBuilder(NAME).build(); assertThat(role.getId(), is(nullValue())); assertThat(role.getBindSecretId(), is(nullValue())); @@ -123,7 +123,7 @@ public class AppRoleBuilderTest { * Build token without all parameters set. */ @Test - public void buildFullTest() throws JsonProcessingException { + void buildFullTest() throws JsonProcessingException { AppRole role = AppRole.builder(NAME) .withId(ID) .withBindSecretID(BIND_SECRET_ID) @@ -168,7 +168,7 @@ public class AppRoleBuilderTest { * Build token without all parameters set. */ @Test - public void legacyBuildFullTest() throws JsonProcessingException { + void legacyBuildFullTest() throws JsonProcessingException { AppRole role = new AppRoleBuilder(NAME) .withId(ID) .withBindSecretID(BIND_SECRET_ID) @@ -213,7 +213,7 @@ public class AppRoleBuilderTest { * Test convenience methods */ @Test - public void convenienceMethodsTest() { + void convenienceMethodsTest() { /* bind_secret_id */ AppRole role = AppRole.builder(NAME).build(); assertThat(role.getBindSecretId(), is(nullValue())); @@ -257,7 +257,7 @@ public class AppRoleBuilderTest { * Test convenience methods */ @Test - public void legacyConvenienceMethodsTest() { + void legacyConvenienceMethodsTest() { /* bind_secret_id */ AppRole role = new AppRoleBuilder(NAME).build(); assertThat(role.getBindSecretId(), is(nullValue())); diff --git a/src/test/java/de/stklcode/jvault/connector/model/AppRoleSecretTest.java b/src/test/java/de/stklcode/jvault/connector/model/AppRoleSecretTest.java index dbe13f8..ea4ed18 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/AppRoleSecretTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/AppRoleSecretTest.java @@ -39,7 +39,7 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; * @author Stefan Kalscheuer * @since 0.5.0 */ -public class AppRoleSecretTest { +class AppRoleSecretTest { private static final String TEST_ID = "abc123"; private static final Map TEST_META = new HashMap<>(); @@ -54,7 +54,7 @@ public class AppRoleSecretTest { * Test constructors. */ @Test - public void constructorTest() { + void constructorTest() { /* Empty constructor */ AppRoleSecret secret = new AppRoleSecret(); assertThat(secret.getId(), is(nullValue())); @@ -99,7 +99,7 @@ public class AppRoleSecretTest { * Test setter. */ @Test - public void setterTest() { + void setterTest() { AppRoleSecret secret = new AppRoleSecret(TEST_ID); assertThat(secret.getCidrList(), is(nullValue())); assertThat(secret.getCidrListString(), is(emptyString())); @@ -115,7 +115,7 @@ public class AppRoleSecretTest { * Test JSON (de)serialization. */ @Test - public void jsonTest() throws NoSuchFieldException, IllegalAccessException { + void jsonTest() throws NoSuchFieldException, IllegalAccessException { ObjectMapper mapper = new ObjectMapper(); /* A simple roundtrip first. All set fields should be present afterwards. */ diff --git a/src/test/java/de/stklcode/jvault/connector/model/AuthBackendTest.java b/src/test/java/de/stklcode/jvault/connector/model/AuthBackendTest.java index fbd3019..8cd1fcc 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/AuthBackendTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/AuthBackendTest.java @@ -27,13 +27,13 @@ import static org.hamcrest.Matchers.is; * @author Stefan Kalscheuer * @since 0.4.0 */ -public class AuthBackendTest { +class AuthBackendTest { /** * Test forType() method. */ @Test - public void forTypeTest() { + void forTypeTest() { assertThat(AuthBackend.forType("token"), is(AuthBackend.TOKEN)); assertThat(AuthBackend.forType("app-id"), is(AuthBackend.APPID)); assertThat(AuthBackend.forType("userpass"), is(AuthBackend.USERPASS)); diff --git a/src/test/java/de/stklcode/jvault/connector/model/TokenBuilderTest.java b/src/test/java/de/stklcode/jvault/connector/model/TokenBuilderTest.java index ae649e9..bee4cdb 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/TokenBuilderTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/TokenBuilderTest.java @@ -35,7 +35,7 @@ import static org.hamcrest.Matchers.*; * @author Stefan Kalscheuer * @since 0.4.0 */ -public class TokenBuilderTest { +class TokenBuilderTest { private static final String ID = "test-id"; private static final String DISPLAY_NAME = "display-name"; private static final Boolean NO_PARENT = false; @@ -59,7 +59,7 @@ public class TokenBuilderTest { private static final String JSON_FULL = "{\"id\":\"test-id\",\"type\":\"service\",\"display_name\":\"display-name\",\"no_parent\":false,\"no_default_policy\":false,\"ttl\":123,\"explicit_max_ttl\":456,\"num_uses\":4,\"policies\":[\"policy\"],\"meta\":{\"key\":\"value\"},\"renewable\":true,\"period\":3600,\"entity_alias\":\"alias-value\"}"; @BeforeAll - public static void init() { + static void init() { POLICIES.add(POLICY); META.put(META_KEY, META_VALUE); } @@ -68,7 +68,7 @@ public class TokenBuilderTest { * Build token without any parameters. */ @Test - public void buildDefaultTest() throws JsonProcessingException { + void buildDefaultTest() throws JsonProcessingException { Token token = Token.builder().build(); assertThat(token.getId(), is(nullValue())); assertThat(token.getType(), is(nullValue())); @@ -92,7 +92,7 @@ public class TokenBuilderTest { * Build token without any parameters. */ @Test - public void legacyBuildDefaultTest() throws JsonProcessingException { + void legacyBuildDefaultTest() throws JsonProcessingException { Token token = new TokenBuilder().build(); assertThat(token.getId(), is(nullValue())); assertThat(token.getType(), is(nullValue())); @@ -113,7 +113,7 @@ public class TokenBuilderTest { * Build token without all parameters set. */ @Test - public void buildFullTest() throws JsonProcessingException { + void buildFullTest() throws JsonProcessingException { Token token = Token.builder() .withId(ID) .withType(Token.Type.SERVICE) @@ -150,7 +150,7 @@ public class TokenBuilderTest { * Build token without all parameters set. */ @Test - public void legacyBuildFullTest() throws JsonProcessingException { + void legacyBuildFullTest() throws JsonProcessingException { Token token = new TokenBuilder() .withId(ID) .withType(Token.Type.SERVICE) @@ -182,7 +182,7 @@ public class TokenBuilderTest { * Test convenience methods */ @Test - public void convenienceMethodsTest() { + void convenienceMethodsTest() { /* Parent */ Token token = Token.builder().asOrphan().build(); assertThat(token.getNoParent(), is(true)); @@ -230,7 +230,7 @@ public class TokenBuilderTest { * Test convenience methods */ @Test - public void legacyConvenienceMethodsTest() { + void legacyConvenienceMethodsTest() { /* Parent */ Token token = new TokenBuilder().asOrphan().build(); assertThat(token.getNoParent(), is(true)); diff --git a/src/test/java/de/stklcode/jvault/connector/model/TokenRoleBuilderTest.java b/src/test/java/de/stklcode/jvault/connector/model/TokenRoleBuilderTest.java index 3546a29..448c33a 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/TokenRoleBuilderTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/TokenRoleBuilderTest.java @@ -32,7 +32,7 @@ import static org.hamcrest.Matchers.*; * @author Stefan Kalscheuer * @since 0.9 */ -public class TokenRoleBuilderTest { +class TokenRoleBuilderTest { private static final String NAME = "test-role"; private static final String ALLOWED_POLICY_1 = "apol-1"; private static final String ALLOWED_POLICY_2 = "apol-2"; @@ -78,7 +78,7 @@ public class TokenRoleBuilderTest { * Build token without any parameters. */ @Test - public void buildDefaultTest() throws JsonProcessingException { + void buildDefaultTest() throws JsonProcessingException { TokenRole role = TokenRole.builder().build(); assertThat(role.getAllowedPolicies(), is(nullValue())); assertThat(role.getDisallowedPolicies(), is(nullValue())); @@ -100,7 +100,7 @@ public class TokenRoleBuilderTest { * Build token without all parameters NULL. */ @Test - public void buildNullTest() throws JsonProcessingException { + void buildNullTest() throws JsonProcessingException { TokenRole role = TokenRole.builder() .forName(null) .withAllowedPolicies(null) @@ -141,7 +141,7 @@ public class TokenRoleBuilderTest { * Build token without all parameters set. */ @Test - public void buildFullTest() throws JsonProcessingException { + void buildFullTest() throws JsonProcessingException { TokenRole role = TokenRole.builder() .forName(NAME) .withAllowedPolicies(ALLOWED_POLICIES) diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/AppRoleResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/AppRoleResponseTest.java index 8b848be..98b7a07 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/AppRoleResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/AppRoleResponseTest.java @@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.6.2 */ -public class AppRoleResponseTest { +class AppRoleResponseTest { private static final Integer ROLE_TOKEN_TTL = 1200; private static final Integer ROLE_TOKEN_MAX_TTL = 1800; private static final Integer ROLE_SECRET_TTL = 600; @@ -75,7 +75,7 @@ public class AppRoleResponseTest { * Test getter, setter and get-methods for response data. */ @Test - public void getDataRoundtrip() { + void getDataRoundtrip() { // Create empty Object. AppRoleResponse res = new AppRoleResponse(); assertThat("Initial data should be empty", res.getRole(), is(nullValue())); @@ -93,7 +93,7 @@ public class AppRoleResponseTest { * Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation). */ @Test - public void jsonRoundtrip() { + void jsonRoundtrip() { try { AppRoleResponse res = new ObjectMapper().readValue(RES_JSON, AppRoleResponse.class); assertThat("Parsed response is NULL", res, is(notNullValue())); diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/AuthMethodsResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/AuthMethodsResponseTest.java index 7302551..9698910 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/AuthMethodsResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/AuthMethodsResponseTest.java @@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.6.2 */ -public class AuthMethodsResponseTest { +class AuthMethodsResponseTest { private static final String GH_PATH = "github/"; private static final String GH_TYPE = "github"; private static final String GH_DESCR = "GitHub auth"; @@ -73,7 +73,7 @@ public class AuthMethodsResponseTest { * Test getter, setter and get-methods for response data. */ @Test - public void getDataRoundtrip() { + void getDataRoundtrip() { // Create empty Object. AuthMethodsResponse res = new AuthMethodsResponse(); assertThat("Initial method map should be empty", res.getSupportedMethods(), is(anEmptyMap())); @@ -91,7 +91,7 @@ public class AuthMethodsResponseTest { * Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation). */ @Test - public void jsonRoundtrip() { + void jsonRoundtrip() { try { AuthMethodsResponse res = new ObjectMapper().readValue(RES_JSON, AuthMethodsResponse.class); assertThat("Parsed response is NULL", res, is(notNullValue())); diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/AuthResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/AuthResponseTest.java index a042740..1be3169 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/AuthResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/AuthResponseTest.java @@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.6.2 */ -public class AuthResponseTest { +class AuthResponseTest { private static final String AUTH_ACCESSOR = "2c84f488-2133-4ced-87b0-570f93a76830"; private static final String AUTH_CLIENT_TOKEN = "ABCD"; private static final String AUTH_POLICY_1 = "web"; @@ -81,7 +81,7 @@ public class AuthResponseTest { * Test getter, setter and get-methods for response data. */ @Test - public void getDataRoundtrip() { + void getDataRoundtrip() { // Create empty Object. AuthResponse res = new AuthResponse(); assertThat("Initial data should be empty", res.getData(), is(nullValue())); @@ -103,7 +103,7 @@ public class AuthResponseTest { * Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation). */ @Test - public void jsonRoundtrip() { + void jsonRoundtrip() { try { AuthResponse res = new ObjectMapper().readValue(RES_JSON, AuthResponse.class); assertThat("Parsed response is NULL", res, is(notNullValue())); diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/CredentialsResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/CredentialsResponseTest.java index 8c61e40..ee193b3 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/CredentialsResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/CredentialsResponseTest.java @@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.8 */ -public class CredentialsResponseTest { +class CredentialsResponseTest { private static final Map DATA = new HashMap<>(); private static final String VAL_USER = "testUserName"; private static final String VAL_PASS = "5up3r5ecr3tP455"; @@ -52,7 +52,7 @@ public class CredentialsResponseTest { */ @Test @SuppressWarnings("unchecked") - public void getCredentialsTest() throws InvalidResponseException { + void getCredentialsTest() throws InvalidResponseException { // Create empty Object. CredentialsResponse res = new CredentialsResponse(); assertThat("Username not present in data map should not return anything", res.getUsername(), is(nullValue())); diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/HealthResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/HealthResponseTest.java index bc54140..f5c9ad3 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/HealthResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/HealthResponseTest.java @@ -32,7 +32,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.7.0 */ -public class HealthResponseTest { +class HealthResponseTest { private static final String CLUSTER_ID = "c9abceea-4f46-4dab-a688-5ce55f89e228"; private static final String CLUSTER_NAME = "vault-cluster-5515c810"; private static final String VERSION = "0.9.2"; @@ -60,7 +60,7 @@ public class HealthResponseTest { * Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation). */ @Test - public void jsonRoundtrip() { + void jsonRoundtrip() { try { HealthResponse res = new ObjectMapper().readValue(RES_JSON, HealthResponse.class); assertThat("Parsed response is NULL", res, is(notNullValue())); diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/MetadataResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/MetadataResponseTest.java index b7dfed2..e64d2b3 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/MetadataResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/MetadataResponseTest.java @@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.8 */ -public class MetadataResponseTest { +class MetadataResponseTest { private static final String V1_TIME = "2018-03-22T02:24:06.945319214Z"; private static final String V3_TIME = "2018-03-22T02:36:43.986212308Z"; private static final String V2_TIME = "2018-03-22T02:36:33.954880664Z"; @@ -73,7 +73,7 @@ public class MetadataResponseTest { * Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation). */ @Test - public void jsonRoundtrip() { + void jsonRoundtrip() { try { MetadataResponse res = new ObjectMapper().readValue(META_JSON, MetadataResponse.class); assertThat("Parsed response is NULL", res, is(notNullValue())); diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/SealResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/SealResponseTest.java index 1e1320f..02428f8 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/SealResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/SealResponseTest.java @@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.8 */ -public class SealResponseTest { +class SealResponseTest { private static final String TYPE = "shamir"; private static final Integer THRESHOLD = 3; private static final Integer SHARES = 5; @@ -70,7 +70,7 @@ public class SealResponseTest { * Test creation from JSON value as returned by Vault when sealed (JSON example close to Vault documentation). */ @Test - public void jsonRoundtripSealed() { + void jsonRoundtripSealed() { // First test sealed Vault's response. try { SealResponse res = new ObjectMapper().readValue(RES_SEALED, SealResponse.class); diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/SecretListResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/SecretListResponseTest.java index e400b74..1394c61 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/SecretListResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/SecretListResponseTest.java @@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.8 */ -public class SecretListResponseTest { +class SecretListResponseTest { private static final Map DATA = new HashMap<>(); private static final String KEY1 = "key1"; private static final String KEY2 = "key-2"; @@ -50,7 +50,7 @@ public class SecretListResponseTest { * @throws InvalidResponseException Should not occur */ @Test - public void getKeysTest() throws InvalidResponseException { + void getKeysTest() throws InvalidResponseException { // Create empty Object. SecretListResponse res = new SecretListResponse(); assertThat("Keys should be null without initialization", res.getKeys(), is(nullValue())); diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/SecretResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/SecretResponseTest.java index ae2eb6b..07f83a8 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/SecretResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/SecretResponseTest.java @@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.6.2 */ -public class SecretResponseTest { +class SecretResponseTest { private static final Map DATA = new HashMap<>(); private static final String KEY_UNKNOWN = "unknown"; private static final String KEY_STRING = "test1"; @@ -120,7 +120,7 @@ public class SecretResponseTest { */ @Test @SuppressWarnings("unchecked") - public void getDataRoundtrip() throws InvalidResponseException { + void getDataRoundtrip() throws InvalidResponseException { // Create empty Object. SecretResponse res = new SecretResponse(); assertThat("Initial data should be Map", res.getData(), is(instanceOf(Map.class))); @@ -156,7 +156,7 @@ public class SecretResponseTest { * Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation). */ @Test - public void jsonRoundtrip() { + void jsonRoundtrip() { try { assertSecretData(new ObjectMapper().readValue(SECRET_JSON, SecretResponse.class)); } catch (IOException e) { diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/SecretVersionResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/SecretVersionResponseTest.java index 0a39504..9e211b4 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/SecretVersionResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/SecretVersionResponseTest.java @@ -32,7 +32,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.8 */ -public class SecretVersionResponseTest { +class SecretVersionResponseTest { private static final String CREATION_TIME = "2018-03-22T02:24:06.945319214Z"; private static final String DELETION_TIME = "2018-03-22T02:36:43.986212308Z"; private static final Integer VERSION = 42; @@ -50,7 +50,7 @@ public class SecretVersionResponseTest { * Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation). */ @Test - public void jsonRoundtrip() { + void jsonRoundtrip() { try { SecretVersionResponse res = new ObjectMapper().readValue(META_JSON, SecretVersionResponse.class); assertThat("Parsed response is NULL", res, is(notNullValue())); diff --git a/src/test/java/de/stklcode/jvault/connector/model/response/TokenResponseTest.java b/src/test/java/de/stklcode/jvault/connector/model/response/TokenResponseTest.java index d1c25bd..cafc39a 100644 --- a/src/test/java/de/stklcode/jvault/connector/model/response/TokenResponseTest.java +++ b/src/test/java/de/stklcode/jvault/connector/model/response/TokenResponseTest.java @@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.fail; * @author Stefan Kalscheuer * @since 0.6.2 */ -public class TokenResponseTest { +class TokenResponseTest { private static final Integer TOKEN_CREATION_TIME = 1457533232; private static final Integer TOKEN_TTL = 2764800; private static final Integer TOKEN_EXPLICIT_MAX_TTL = 0; @@ -101,7 +101,7 @@ public class TokenResponseTest { * Test getter, setter and get-methods for response data. */ @Test - public void getDataRoundtrip() { + void getDataRoundtrip() { // Create empty Object. TokenResponse res = new TokenResponse(); assertThat("Initial data should be empty", res.getData(), is(nullValue())); @@ -119,7 +119,7 @@ public class TokenResponseTest { * Test creation from JSON value as returned by Vault (JSON example copied from Vault documentation). */ @Test - public void jsonRoundtrip() { + void jsonRoundtrip() { try { TokenResponse res = new ObjectMapper().readValue(RES_JSON, TokenResponse.class); assertThat("Parsed response is NULL", res, is(notNullValue()));