model: implement Serializable with model classes
implement equals() and hashCode()
This commit is contained in:
@ -17,11 +17,10 @@
|
||||
package de.stklcode.jvault.connector.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -37,13 +36,11 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
*/
|
||||
class AppRoleSecretTest {
|
||||
private static final String TEST_ID = "abc123";
|
||||
private static final Map<String, Object> TEST_META = new HashMap<>();
|
||||
private static final List<String> TEST_CIDR = Arrays.asList("203.0.113.0/24", "198.51.100.0/24");
|
||||
|
||||
static {
|
||||
TEST_META.put("foo", "bar");
|
||||
TEST_META.put("number", 1337);
|
||||
}
|
||||
private static final Map<String, Object> TEST_META = Map.of(
|
||||
"foo", "bar",
|
||||
"number", 1337
|
||||
);
|
||||
private static final List<String> TEST_CIDR = List.of("203.0.113.0/24", "198.51.100.0/24");
|
||||
|
||||
/**
|
||||
* Test constructors.
|
||||
@ -167,7 +164,11 @@ class AppRoleSecretTest {
|
||||
assertEquals("TEST_LASTUPDATE", secret2.getLastUpdatedTime());
|
||||
assertEquals(678, secret2.getNumUses());
|
||||
assertEquals(12345, secret2.getTtl());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(AppRoleSecret.class).verify();
|
||||
}
|
||||
|
||||
private static void setPrivateField(Object object, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException {
|
||||
@ -182,5 +183,4 @@ class AppRoleSecretTest {
|
||||
return json.replaceAll("\"cidr_list\":\"([^\"]*)\"", "\"cidr_list\":\\[$1\\]")
|
||||
.replaceAll("(\\d+\\.\\d+\\.\\d+\\.\\d+/\\d+)", "\"$1\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package de.stklcode.jvault.connector.model;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -172,4 +173,9 @@ class AppRoleTest {
|
||||
assertEquals(2, role.getTokenPolicies().size());
|
||||
assertTrue(role.getTokenPolicies().containsAll(List.of(POLICY, POLICY_2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(AppRole.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package de.stklcode.jvault.connector.model;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -26,12 +27,12 @@ import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Unit Test for {@link Token.Builder}
|
||||
* Unit Test for {@link TokenRole} and {@link TokenRole.Builder}.
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
* @since 0.9
|
||||
*/
|
||||
class TokenRoleBuilderTest {
|
||||
class TokenRoleTest {
|
||||
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";
|
||||
@ -132,6 +133,9 @@ class TokenRoleBuilderTest {
|
||||
assertNull(role.getTokenPeriod());
|
||||
assertNull(role.getTokenType());
|
||||
|
||||
// Empty builder should be equal to no-arg construction.
|
||||
assertEquals(role, new TokenRole());
|
||||
|
||||
// Optional fields should be ignored, so JSON string should be empty.
|
||||
assertEquals("{}", new ObjectMapper().writeValueAsString(role));
|
||||
}
|
||||
@ -180,4 +184,9 @@ class TokenRoleBuilderTest {
|
||||
// Verify that all parameters are included in JSON string.
|
||||
assertEquals(JSON_FULL, new ObjectMapper().writeValueAsString(role));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(TokenRole.class).verify();
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ package de.stklcode.jvault.connector.model;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -81,6 +82,9 @@ class TokenTest {
|
||||
|
||||
// Optional fields should be ignored, so JSON string should be empty.
|
||||
assertEquals("{}", new ObjectMapper().writeValueAsString(token));
|
||||
|
||||
// Empty builder should be equal to no-arg construction.
|
||||
assertEquals(token, new Token());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,4 +171,9 @@ class TokenTest {
|
||||
assertEquals(META_VALUE, token.getMeta().get(META_KEY));
|
||||
assertEquals(META_VALUE_2, token.getMeta().get(META_KEY_2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(Token.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ package de.stklcode.jvault.connector.model.response;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||
import de.stklcode.jvault.connector.model.AppRole;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -63,11 +63,7 @@ class AppRoleResponseTest {
|
||||
" \"lease_id\": \"\"\n" +
|
||||
"}";
|
||||
|
||||
private static final Map<String, Object> INVALID_DATA = new HashMap<>();
|
||||
|
||||
static {
|
||||
INVALID_DATA.put("token_policies", "fancy-policy");
|
||||
}
|
||||
private static final Map<String, Object> INVALID_DATA = Map.of("token_policies", "fancy-policy");
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
@ -109,4 +105,9 @@ class AppRoleResponseTest {
|
||||
assertNull(role.getTokenBoundCidrs(), "Incorrect bound CIDR list");
|
||||
assertEquals("", role.getTokenBoundCidrsString(), "Incorrect bound CIDR list string");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(AppRoleResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||
import de.stklcode.jvault.connector.model.AuthBackend;
|
||||
import de.stklcode.jvault.connector.model.response.embedded.AuthMethod;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ -62,11 +63,7 @@ class AuthMethodsResponseTest {
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
private static final Map<String, Object> INVALID_DATA = new HashMap<>();
|
||||
|
||||
static {
|
||||
INVALID_DATA.put("dummy/", new Dummy());
|
||||
}
|
||||
private static final Map<String, Object> INVALID_DATA = Map.of("dummy/", new Dummy());
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
@ -119,7 +116,12 @@ class AuthMethodsResponseTest {
|
||||
assertEquals(TK_MAX_LEASE_TTL.toString(), method.getConfig().get("max_lease_ttl"), "Incorrect max lease TTL config");
|
||||
}
|
||||
|
||||
private static class Dummy {
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(AuthMethodsResponse.class).verify();
|
||||
}
|
||||
|
||||
private static class Dummy implements Serializable {
|
||||
private static final long serialVersionUID = 9075949348402246139L;
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ package de.stklcode.jvault.connector.model.response;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||
import de.stklcode.jvault.connector.model.response.embedded.AuthData;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ -69,11 +69,7 @@ class AuthResponseTest {
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
private static final Map<String, Object> INVALID_AUTH_DATA = new HashMap<>();
|
||||
|
||||
static {
|
||||
INVALID_AUTH_DATA.put("policies", "fancy-policy");
|
||||
}
|
||||
private static final Map<String, Object> INVALID_AUTH_DATA = Map.of("policies", "fancy-policy");
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
@ -122,4 +118,9 @@ class AuthResponseTest {
|
||||
assertTrue(data.getTokenPolicies().containsAll(Set.of(AUTH_POLICY_2, AUTH_POLICY_1)), "Incorrect token policies");
|
||||
assertEquals(Map.of(AUTH_META_KEY, AUTH_META_VALUE), data.getMetadata(), "Incorrect auth metadata");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(AuthResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,9 @@
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -32,14 +32,12 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
* @since 0.8
|
||||
*/
|
||||
class CredentialsResponseTest {
|
||||
private static final Map<String, Object> DATA = new HashMap<>();
|
||||
private static final String VAL_USER = "testUserName";
|
||||
private static final String VAL_PASS = "5up3r5ecr3tP455";
|
||||
|
||||
static {
|
||||
DATA.put("username", VAL_USER);
|
||||
DATA.put("password", VAL_PASS);
|
||||
}
|
||||
private static final Map<String, Object> DATA = Map.of(
|
||||
"username", VAL_USER,
|
||||
"password", VAL_PASS
|
||||
);
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
@ -47,7 +45,6 @@ class CredentialsResponseTest {
|
||||
* @throws InvalidResponseException Should not occur
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void getCredentialsTest() throws InvalidResponseException {
|
||||
// Create empty Object.
|
||||
CredentialsResponse res = new CredentialsResponse();
|
||||
@ -59,4 +56,9 @@ class CredentialsResponseTest {
|
||||
assertEquals(VAL_USER, res.getUsername(), "Incorrect username");
|
||||
assertEquals(VAL_PASS, res.getPassword(), "Incorrect password");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(CredentialsResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2016-2021 Stefan Kalscheuer
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* JUnit Test for {@link ErrorResponse} model.
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
*/
|
||||
class ErrorResponseTest {
|
||||
private static final String ERROR_1 = "Error #1";
|
||||
private static final String ERROR_2 = "Error #2";
|
||||
|
||||
private static final String JSON = "{\"errors\":[\"" + ERROR_1 + "\",\"" + ERROR_2 + "\"]}";
|
||||
private static final String JSON_EMPTY = "{\"errors\":[]}";
|
||||
|
||||
/**
|
||||
* Test creation from JSON value as returned by Vault.
|
||||
*/
|
||||
@Test
|
||||
void jsonRoundtrip() {
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
ErrorResponse res = assertDoesNotThrow(
|
||||
() -> om.readValue(JSON, ErrorResponse.class),
|
||||
"ErrorResponse deserialization failed"
|
||||
);
|
||||
assertNotNull(res, "Parsed response is NULL");
|
||||
assertEquals(List.of(ERROR_1, ERROR_2), res.getErrors(), "Unexpected error messages");
|
||||
assertEquals(
|
||||
JSON,
|
||||
assertDoesNotThrow(() -> om.writeValueAsString(res), "ErrorResponse serialization failed"),
|
||||
"Unexpected JSON string after serialization"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
ErrorResponse res = assertDoesNotThrow(
|
||||
() -> new ObjectMapper().readValue(JSON, ErrorResponse.class),
|
||||
"ErrorResponse deserialization failed"
|
||||
);
|
||||
assertEquals(ERROR_1, res.toString());
|
||||
|
||||
res = assertDoesNotThrow(
|
||||
() -> new ObjectMapper().readValue(JSON_EMPTY, ErrorResponse.class),
|
||||
"ErrorResponse deserialization failed with empty list"
|
||||
);
|
||||
assertEquals("error response", res.toString());
|
||||
|
||||
assertEquals("error response", new ErrorResponse().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(ErrorResponse.class).verify();
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -73,4 +74,9 @@ class HealthResponseTest {
|
||||
assertEquals(REPL_PERF_MODE, res.getReplicationPerfMode(), "Incorrect replication perf mode");
|
||||
assertEquals(REPL_DR_MODE, res.getReplicationDrMode(), "Incorrect replication DR mode");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(HealthResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2016-2021 Stefan Kalscheuer
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* JUnit Test for {@link HelpResponse} model.
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
*/
|
||||
class HelpResponseTest {
|
||||
private static final String HELP = "Help Text.";
|
||||
|
||||
private static final String JSON = "{\"help\":\"" + HELP + "\"}";
|
||||
|
||||
/**
|
||||
* Test creation from JSON value as returned by Vault.
|
||||
*/
|
||||
@Test
|
||||
void jsonRoundtrip() {
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
HelpResponse res = assertDoesNotThrow(
|
||||
() -> om.readValue(JSON, HelpResponse.class),
|
||||
"HelpResponse deserialization failed"
|
||||
);
|
||||
assertNotNull(res, "Parsed response is NULL");
|
||||
assertEquals(HELP, res.getHelp(), "Unexpected help text");
|
||||
assertEquals(
|
||||
JSON,
|
||||
assertDoesNotThrow(() -> om.writeValueAsString(res), "HelpResponse serialization failed"),
|
||||
"Unexpected JSON string after serialization"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(HelpResponse.class).verify();
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -88,4 +89,9 @@ class MetadataResponseTest {
|
||||
assertNotNull(res.getMetadata().getVersions().get(2).getCreatedTime(), "Parsing version created failed");
|
||||
assertFalse(res.getMetadata().getVersions().get(3).isDestroyed(), "Incorrect version 3 destroyed state");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(MetadataResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -79,7 +80,7 @@ class SealResponseTest {
|
||||
// First test sealed Vault's response.
|
||||
SealResponse res = assertDoesNotThrow(
|
||||
() -> new ObjectMapper().readValue(RES_SEALED, SealResponse.class),
|
||||
"TokenResponse deserialization failed"
|
||||
"SealResponse deserialization failed"
|
||||
);
|
||||
assertNotNull(res, "Parsed response is NULL");
|
||||
assertEquals(TYPE, res.getType(), "Incorrect seal type");
|
||||
@ -101,7 +102,7 @@ class SealResponseTest {
|
||||
// Not test unsealed Vault's response.
|
||||
res = assertDoesNotThrow(
|
||||
() -> new ObjectMapper().readValue(RES_UNSEALED, SealResponse.class),
|
||||
"TokenResponse deserialization failed"
|
||||
"SealResponse deserialization failed"
|
||||
);
|
||||
assertNotNull(res, "Parsed response is NULL");
|
||||
assertEquals(TYPE, res.getType(), "Incorrect seal type");
|
||||
@ -118,4 +119,9 @@ class SealResponseTest {
|
||||
assertEquals(RECOVERY_SEAL, res.getRecoverySeal(), "Incorrect recovery seal");
|
||||
assertEquals(STORAGE_TYPE, res.getStorageType(), "Incorrect storage type");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(SealResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,13 @@
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@ -30,14 +34,10 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @since 0.8
|
||||
*/
|
||||
class SecretListResponseTest {
|
||||
private static final Map<String, Object> DATA = new HashMap<>();
|
||||
private static final String KEY1 = "key1";
|
||||
private static final String KEY2 = "key-2";
|
||||
private static final List<String> KEYS = Arrays.asList(KEY1, KEY2);
|
||||
|
||||
static {
|
||||
DATA.put("keys", KEYS);
|
||||
}
|
||||
private static final Map<String, Object> DATA = Map.of("keys", KEYS);
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
@ -51,8 +51,7 @@ class SecretListResponseTest {
|
||||
assertNull(res.getKeys(), "Keys should be null without initialization");
|
||||
|
||||
// Provoke internal ClassCastException.
|
||||
Map<String, Object> invalidData = new HashMap<>();
|
||||
invalidData.put("keys", "some string");
|
||||
Map<String, Object> invalidData = Map.of("keys", "some string");
|
||||
assertThrows(
|
||||
InvalidResponseException.class,
|
||||
() -> res.setData(invalidData),
|
||||
@ -65,4 +64,9 @@ class SecretListResponseTest {
|
||||
assertEquals(2, res.getKeys().size(), "Unexpected number of keys");
|
||||
assertTrue(res.getKeys().containsAll(Set.of(KEY1, KEY2)), "Unexpected keys");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(SecretListResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -34,7 +34,6 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
* @since 0.6.2
|
||||
*/
|
||||
class SecretResponseTest {
|
||||
private static final Map<String, Object> DATA = new HashMap<>();
|
||||
private static final String KEY_UNKNOWN = "unknown";
|
||||
private static final String KEY_STRING = "test1";
|
||||
private static final String VAL_STRING = "testvalue";
|
||||
@ -43,6 +42,12 @@ class SecretResponseTest {
|
||||
private static final String KEY_LIST = "list";
|
||||
private static final String VAL_LIST = "[\"first\",\"second\"]";
|
||||
|
||||
private static final Map<String, Object> DATA = Map.of(
|
||||
KEY_STRING, VAL_STRING,
|
||||
KEY_INTEGER, VAL_INTEGER,
|
||||
KEY_LIST, VAL_LIST
|
||||
);
|
||||
|
||||
private static final String SECRET_REQUEST_ID = "68315073-6658-e3ff-2da7-67939fb91bbd";
|
||||
private static final String SECRET_LEASE_ID = "";
|
||||
private static final Integer SECRET_LEASE_DURATION = 2764800;
|
||||
@ -104,13 +109,6 @@ class SecretResponseTest {
|
||||
" \"warnings\": " + SECRET_WARNINGS + "\n" +
|
||||
"}";
|
||||
|
||||
|
||||
static {
|
||||
DATA.put(KEY_STRING, VAL_STRING);
|
||||
DATA.put(KEY_INTEGER, VAL_INTEGER);
|
||||
DATA.put(KEY_LIST, VAL_LIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
*
|
||||
@ -171,7 +169,7 @@ class SecretResponseTest {
|
||||
assertNotNull(res.getMetadata().getCreatedTime(), "Creation date parsing failed");
|
||||
assertEquals("", res.getMetadata().getDeletionTimeString(), "Incorrect deletion date string");
|
||||
assertNull(res.getMetadata().getDeletionTime(), "Incorrect deletion date");
|
||||
assertEquals(false, res.getMetadata().isDestroyed(), "Secret destroyed when not expected");
|
||||
assertFalse(res.getMetadata().isDestroyed(), "Secret destroyed when not expected");
|
||||
assertEquals(1, res.getMetadata().getVersion(), "Incorrect secret version");
|
||||
|
||||
// Deleted KV v2 secret.
|
||||
@ -185,10 +183,15 @@ class SecretResponseTest {
|
||||
assertNotNull(res.getMetadata().getCreatedTime(), "Creation date parsing failed");
|
||||
assertEquals(SECRET_META_DELETED, res.getMetadata().getDeletionTimeString(), "Incorrect deletion date string");
|
||||
assertNotNull(res.getMetadata().getDeletionTime(), "Incorrect deletion date");
|
||||
assertEquals(true, res.getMetadata().isDestroyed(), "Secret destroyed when not expected");
|
||||
assertTrue(res.getMetadata().isDestroyed(), "Secret destroyed when not expected");
|
||||
assertEquals(2, res.getMetadata().getVersion(), "Incorrect secret version");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(SecretResponse.class).verify();
|
||||
}
|
||||
|
||||
private void assertSecretData(SecretResponse res) {
|
||||
assertNotNull(res, "Parsed response is NULL");
|
||||
assertEquals(SECRET_LEASE_ID, res.getLeaseId(), "Incorrect lease ID");
|
||||
|
@ -17,6 +17,7 @@
|
||||
package de.stklcode.jvault.connector.model.response;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@ -54,7 +55,12 @@ class SecretVersionResponseTest {
|
||||
assertNotNull(res.getMetadata(), "Parsed metadata is NULL");
|
||||
assertEquals(CREATION_TIME, res.getMetadata().getCreatedTimeString(), "Incorrect created time");
|
||||
assertEquals(DELETION_TIME, res.getMetadata().getDeletionTimeString(), "Incorrect deletion time");
|
||||
assertEquals(false, res.getMetadata().isDestroyed(), "Incorrect destroyed state");
|
||||
assertFalse(res.getMetadata().isDestroyed(), "Incorrect destroyed state");
|
||||
assertEquals(VERSION, res.getMetadata().getVersion(), "Incorrect version");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(SecretVersionResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,10 @@ package de.stklcode.jvault.connector.model.response;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||
import de.stklcode.jvault.connector.model.response.embedded.TokenData;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -89,11 +89,7 @@ class TokenResponseTest {
|
||||
" \"auth\": null\n" +
|
||||
"}";
|
||||
|
||||
private static final Map<String, Object> INVALID_TOKEN_DATA = new HashMap<>();
|
||||
|
||||
static {
|
||||
INVALID_TOKEN_DATA.put("num_uses", "fourtytwo");
|
||||
}
|
||||
private static final Map<String, Object> INVALID_TOKEN_DATA = Map.of("num_uses", "fourtytwo");
|
||||
|
||||
/**
|
||||
* Test getter, setter and get-methods for response data.
|
||||
@ -149,4 +145,9 @@ class TokenResponseTest {
|
||||
assertEquals(RES_TTL, data.getTtl(), "Incorrect token TTL");
|
||||
assertEquals(TOKEN_TYPE, data.getType(), "Incorrect token type");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEqualsHashcode() {
|
||||
EqualsVerifier.simple().forClass(TokenResponse.class).verify();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user