use common ObjectMapper instance in model unit tests
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d9dbdad75b
commit
7a813cdda3
@ -1,5 +1,6 @@
|
|||||||
package de.stklcode.jvault.connector.model;
|
package de.stklcode.jvault.connector.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractModelTest<T> {
|
public abstract class AbstractModelTest<T> {
|
||||||
protected final Class<?> modelClass;
|
protected final Class<?> modelClass;
|
||||||
|
protected final ObjectMapper objectMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case constructor.
|
* Test case constructor.
|
||||||
@ -24,6 +26,7 @@ public abstract class AbstractModelTest<T> {
|
|||||||
*/
|
*/
|
||||||
protected AbstractModelTest(Class<T> modelClass) {
|
protected AbstractModelTest(Class<T> modelClass) {
|
||||||
this.modelClass = modelClass;
|
this.modelClass = modelClass;
|
||||||
|
this.objectMapper = new ObjectMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package de.stklcode.jvault.connector.model;
|
package de.stklcode.jvault.connector.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -116,16 +115,14 @@ class AppRoleSecretTest extends AbstractModelTest<AppRoleSecret> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
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..
|
// A simple roundtrip first. All set fields should be present afterwards..
|
||||||
AppRoleSecret secret = new AppRoleSecret(TEST_ID, TEST_META, TEST_CIDR);
|
AppRoleSecret secret = new AppRoleSecret(TEST_ID, TEST_META, TEST_CIDR);
|
||||||
String secretJson = assertDoesNotThrow(() -> mapper.writeValueAsString(secret), "Serialization failed");
|
String secretJson = assertDoesNotThrow(() -> objectMapper.writeValueAsString(secret), "Serialization failed");
|
||||||
// CIDR list is comma-separated when used as input, but List otherwise, hence convert string to list.
|
// CIDR list is comma-separated when used as input, but List otherwise, hence convert string to list.
|
||||||
String secretJson2 = commaSeparatedToList(secretJson);
|
String secretJson2 = commaSeparatedToList(secretJson);
|
||||||
|
|
||||||
AppRoleSecret secret2 = assertDoesNotThrow(
|
AppRoleSecret secret2 = assertDoesNotThrow(
|
||||||
() -> mapper.readValue(secretJson2, AppRoleSecret.class),
|
() -> objectMapper.readValue(secretJson2, AppRoleSecret.class),
|
||||||
"Deserialization failed"
|
"Deserialization failed"
|
||||||
);
|
);
|
||||||
assertEquals(secret2.getId(), secret.getId());
|
assertEquals(secret2.getId(), secret.getId());
|
||||||
@ -145,9 +142,9 @@ class AppRoleSecretTest extends AbstractModelTest<AppRoleSecret> {
|
|||||||
assumeTrue(secret.getNumUses() == 678);
|
assumeTrue(secret.getNumUses() == 678);
|
||||||
setPrivateField(secret, "ttl", 12345);
|
setPrivateField(secret, "ttl", 12345);
|
||||||
assumeTrue(secret.getTtl() == 12345);
|
assumeTrue(secret.getTtl() == 12345);
|
||||||
String secretJson3 = assertDoesNotThrow(() -> mapper.writeValueAsString(secret), "Serialization failed");
|
String secretJson3 = assertDoesNotThrow(() -> objectMapper.writeValueAsString(secret), "Serialization failed");
|
||||||
secret2 = assertDoesNotThrow(
|
secret2 = assertDoesNotThrow(
|
||||||
() -> mapper.readValue(commaSeparatedToList(secretJson3), AppRoleSecret.class),
|
() -> objectMapper.readValue(commaSeparatedToList(secretJson3), AppRoleSecret.class),
|
||||||
"Deserialization failed"
|
"Deserialization failed"
|
||||||
);
|
);
|
||||||
assertEquals(secret2.getId(), secret.getId());
|
assertEquals(secret2.getId(), secret.getId());
|
||||||
@ -165,7 +162,7 @@ class AppRoleSecretTest extends AbstractModelTest<AppRoleSecret> {
|
|||||||
"\"cidr_list\":[\"203.0.113.0/24\",\"198.51.100.0/24\"],\"secret_id_accessor\":\"TEST_ACCESSOR\"," +
|
"\"cidr_list\":[\"203.0.113.0/24\",\"198.51.100.0/24\"],\"secret_id_accessor\":\"TEST_ACCESSOR\"," +
|
||||||
"\"creation_time\":\"TEST_CREATION\",\"expiration_time\":\"TEST_EXPIRATION\"," +
|
"\"creation_time\":\"TEST_CREATION\",\"expiration_time\":\"TEST_EXPIRATION\"," +
|
||||||
"\"last_updated_time\":\"TEST_LASTUPDATE\",\"secret_id_num_uses\":678,\"secret_id_ttl\":12345}";
|
"\"last_updated_time\":\"TEST_LASTUPDATE\",\"secret_id_num_uses\":678,\"secret_id_ttl\":12345}";
|
||||||
secret2 = assertDoesNotThrow(() -> mapper.readValue(secretJson4, AppRoleSecret.class), "Deserialization failed");
|
secret2 = assertDoesNotThrow(() -> objectMapper.readValue(secretJson4, AppRoleSecret.class), "Deserialization failed");
|
||||||
assertEquals("TEST_ACCESSOR", secret2.getAccessor());
|
assertEquals("TEST_ACCESSOR", secret2.getAccessor());
|
||||||
assertEquals("TEST_CREATION", secret2.getCreationTime());
|
assertEquals("TEST_CREATION", secret2.getCreationTime());
|
||||||
assertEquals("TEST_EXPIRATION", secret2.getExpirationTime());
|
assertEquals("TEST_EXPIRATION", secret2.getExpirationTime());
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model;
|
package de.stklcode.jvault.connector.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -110,7 +109,7 @@ class AppRoleTest extends AbstractModelTest<AppRole> {
|
|||||||
assertNull(role.getTokenType());
|
assertNull(role.getTokenType());
|
||||||
|
|
||||||
// Optional fields should be ignored, so JSON string should only contain role_name.
|
// Optional fields should be ignored, so JSON string should only contain role_name.
|
||||||
assertEquals(JSON_MIN, new ObjectMapper().writeValueAsString(role));
|
assertEquals(JSON_MIN, objectMapper.writeValueAsString(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,7 +136,7 @@ class AppRoleTest extends AbstractModelTest<AppRole> {
|
|||||||
assertEquals(TOKEN_TYPE.value(), role.getTokenType());
|
assertEquals(TOKEN_TYPE.value(), role.getTokenType());
|
||||||
|
|
||||||
// Verify that all parameters are included in JSON string.
|
// Verify that all parameters are included in JSON string.
|
||||||
assertEquals(JSON_FULL, new ObjectMapper().writeValueAsString(role));
|
assertEquals(JSON_FULL, objectMapper.writeValueAsString(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model;
|
package de.stklcode.jvault.connector.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -133,7 +132,7 @@ class TokenRoleTest extends AbstractModelTest<TokenRole> {
|
|||||||
assertNull(role.getTokenType());
|
assertNull(role.getTokenType());
|
||||||
|
|
||||||
// Optional fields should be ignored, so JSON string should be empty.
|
// Optional fields should be ignored, so JSON string should be empty.
|
||||||
assertEquals("{}", new ObjectMapper().writeValueAsString(role));
|
assertEquals("{}", objectMapper.writeValueAsString(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,7 +176,7 @@ class TokenRoleTest extends AbstractModelTest<TokenRole> {
|
|||||||
assertEquals(role, new TokenRole());
|
assertEquals(role, new TokenRole());
|
||||||
|
|
||||||
// Optional fields should be ignored, so JSON string should be empty.
|
// Optional fields should be ignored, so JSON string should be empty.
|
||||||
assertEquals("{}", new ObjectMapper().writeValueAsString(role));
|
assertEquals("{}", objectMapper.writeValueAsString(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -208,6 +207,6 @@ class TokenRoleTest extends AbstractModelTest<TokenRole> {
|
|||||||
assertEquals(TOKEN_TYPE.value(), role.getTokenType());
|
assertEquals(TOKEN_TYPE.value(), role.getTokenType());
|
||||||
|
|
||||||
// Verify that all parameters are included in JSON string.
|
// Verify that all parameters are included in JSON string.
|
||||||
assertEquals(JSON_FULL, new ObjectMapper().writeValueAsString(role));
|
assertEquals(JSON_FULL, objectMapper.writeValueAsString(role));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model;
|
package de.stklcode.jvault.connector.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -103,7 +102,7 @@ class TokenTest extends AbstractModelTest<Token> {
|
|||||||
assertNull(token.getEntityAlias());
|
assertNull(token.getEntityAlias());
|
||||||
|
|
||||||
// Optional fields should be ignored, so JSON string should be empty.
|
// Optional fields should be ignored, so JSON string should be empty.
|
||||||
assertEquals("{}", new ObjectMapper().writeValueAsString(token));
|
assertEquals("{}", objectMapper.writeValueAsString(token));
|
||||||
|
|
||||||
// Empty builder should be equal to no-arg construction.
|
// Empty builder should be equal to no-arg construction.
|
||||||
assertEquals(token, new Token());
|
assertEquals(token, new Token());
|
||||||
@ -129,7 +128,7 @@ class TokenTest extends AbstractModelTest<Token> {
|
|||||||
assertEquals(PERIOD, token.getPeriod());
|
assertEquals(PERIOD, token.getPeriod());
|
||||||
|
|
||||||
// Verify that all parameters are included in JSON string.
|
// Verify that all parameters are included in JSON string.
|
||||||
assertEquals(JSON_FULL, new ObjectMapper().writeValueAsString(token));
|
assertEquals(JSON_FULL, objectMapper.writeValueAsString(token));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import de.stklcode.jvault.connector.model.AppRole;
|
import de.stklcode.jvault.connector.model.AppRole;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -69,7 +68,7 @@ class AppRoleResponseTest extends AbstractModelTest<AppRoleResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected AppRoleResponse createFull() {
|
protected AppRoleResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(RES_JSON, AppRoleResponse.class);
|
return objectMapper.readValue(RES_JSON, AppRoleResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -92,7 +91,7 @@ class AppRoleResponseTest extends AbstractModelTest<AppRoleResponse> {
|
|||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
AppRoleResponse res = assertDoesNotThrow(
|
AppRoleResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(RES_JSON, AppRoleResponse.class),
|
() -> objectMapper.readValue(RES_JSON, AppRoleResponse.class),
|
||||||
"AuthResponse deserialization failed"
|
"AuthResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import de.stklcode.jvault.connector.model.AuthBackend;
|
import de.stklcode.jvault.connector.model.AuthBackend;
|
||||||
import de.stklcode.jvault.connector.model.response.embedded.AuthMethod;
|
import de.stklcode.jvault.connector.model.response.embedded.AuthMethod;
|
||||||
@ -83,7 +82,7 @@ class AuthMethodsResponseTest extends AbstractModelTest<AuthMethodsResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected AuthMethodsResponse createFull() {
|
protected AuthMethodsResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(RES_JSON, AuthMethodsResponse.class);
|
return objectMapper.readValue(RES_JSON, AuthMethodsResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -106,7 +105,7 @@ class AuthMethodsResponseTest extends AbstractModelTest<AuthMethodsResponse> {
|
|||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
AuthMethodsResponse res = assertDoesNotThrow(
|
AuthMethodsResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(RES_JSON, AuthMethodsResponse.class),
|
() -> objectMapper.readValue(RES_JSON, AuthMethodsResponse.class),
|
||||||
"AuthResponse deserialization failed"
|
"AuthResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import de.stklcode.jvault.connector.model.response.embedded.AuthData;
|
import de.stklcode.jvault.connector.model.response.embedded.AuthData;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -76,7 +75,7 @@ class AuthResponseTest extends AbstractModelTest<AuthResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected AuthResponse createFull() {
|
protected AuthResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(RES_JSON, AuthResponse.class);
|
return objectMapper.readValue(RES_JSON, AuthResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -89,7 +88,7 @@ class AuthResponseTest extends AbstractModelTest<AuthResponse> {
|
|||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
AuthResponse res = assertDoesNotThrow(
|
AuthResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(RES_JSON, AuthResponse.class),
|
() -> objectMapper.readValue(RES_JSON, AuthResponse.class),
|
||||||
"AuthResponse deserialization failed"
|
"AuthResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
import de.stklcode.jvault.connector.exception.InvalidResponseException;
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -52,7 +51,7 @@ class CredentialsResponseTest extends AbstractModelTest<CredentialsResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected CredentialsResponse createFull() {
|
protected CredentialsResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(JSON, CredentialsResponse.class);
|
return objectMapper.readValue(JSON, CredentialsResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -72,7 +71,7 @@ class CredentialsResponseTest extends AbstractModelTest<CredentialsResponse> {
|
|||||||
assertNull(res.getPassword(), "Password not present in data map should not return anything");
|
assertNull(res.getPassword(), "Password not present in data map should not return anything");
|
||||||
|
|
||||||
res = assertDoesNotThrow(
|
res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(JSON, CredentialsResponse.class),
|
() -> objectMapper.readValue(JSON, CredentialsResponse.class),
|
||||||
"Deserialization of CredentialsResponse failed"
|
"Deserialization of CredentialsResponse failed"
|
||||||
);
|
);
|
||||||
assertEquals(VAL_USER, res.getUsername(), "Incorrect username");
|
assertEquals(VAL_USER, res.getUsername(), "Incorrect username");
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ class ErrorResponseTest extends AbstractModelTest<ErrorResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected ErrorResponse createFull() {
|
protected ErrorResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(JSON, ErrorResponse.class);
|
return objectMapper.readValue(JSON, ErrorResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -56,16 +55,15 @@ class ErrorResponseTest extends AbstractModelTest<ErrorResponse> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
ObjectMapper om = new ObjectMapper();
|
|
||||||
ErrorResponse res = assertDoesNotThrow(
|
ErrorResponse res = assertDoesNotThrow(
|
||||||
() -> om.readValue(JSON, ErrorResponse.class),
|
() -> objectMapper.readValue(JSON, ErrorResponse.class),
|
||||||
"ErrorResponse deserialization failed"
|
"ErrorResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
assertEquals(List.of(ERROR_1, ERROR_2), res.getErrors(), "Unexpected error messages");
|
assertEquals(List.of(ERROR_1, ERROR_2), res.getErrors(), "Unexpected error messages");
|
||||||
assertEquals(
|
assertEquals(
|
||||||
JSON,
|
JSON,
|
||||||
assertDoesNotThrow(() -> om.writeValueAsString(res), "ErrorResponse serialization failed"),
|
assertDoesNotThrow(() -> objectMapper.writeValueAsString(res), "ErrorResponse serialization failed"),
|
||||||
"Unexpected JSON string after serialization"
|
"Unexpected JSON string after serialization"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -74,13 +72,13 @@ class ErrorResponseTest extends AbstractModelTest<ErrorResponse> {
|
|||||||
@Test
|
@Test
|
||||||
void testToString() {
|
void testToString() {
|
||||||
ErrorResponse res = assertDoesNotThrow(
|
ErrorResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(JSON, ErrorResponse.class),
|
() -> objectMapper.readValue(JSON, ErrorResponse.class),
|
||||||
"ErrorResponse deserialization failed"
|
"ErrorResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertEquals(ERROR_1, res.toString());
|
assertEquals(ERROR_1, res.toString());
|
||||||
|
|
||||||
res = assertDoesNotThrow(
|
res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(JSON_EMPTY, ErrorResponse.class),
|
() -> objectMapper.readValue(JSON_EMPTY, ErrorResponse.class),
|
||||||
"ErrorResponse deserialization failed with empty list"
|
"ErrorResponse deserialization failed with empty list"
|
||||||
);
|
);
|
||||||
assertEquals("error response", res.toString());
|
assertEquals("error response", res.toString());
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -61,7 +60,7 @@ class HealthResponseTest extends AbstractModelTest<HealthResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected HealthResponse createFull() {
|
protected HealthResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(RES_JSON, HealthResponse.class);
|
return objectMapper.readValue(RES_JSON, HealthResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -74,7 +73,7 @@ class HealthResponseTest extends AbstractModelTest<HealthResponse> {
|
|||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
HealthResponse res = assertDoesNotThrow(
|
HealthResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(RES_JSON, HealthResponse.class),
|
() -> objectMapper.readValue(RES_JSON, HealthResponse.class),
|
||||||
"Health deserialization failed"
|
"Health deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ class HelpResponseTest extends AbstractModelTest<HelpResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected HelpResponse createFull() {
|
protected HelpResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(JSON, HelpResponse.class);
|
return objectMapper.readValue(JSON, HelpResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -52,16 +51,15 @@ class HelpResponseTest extends AbstractModelTest<HelpResponse> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
ObjectMapper om = new ObjectMapper();
|
|
||||||
HelpResponse res = assertDoesNotThrow(
|
HelpResponse res = assertDoesNotThrow(
|
||||||
() -> om.readValue(JSON, HelpResponse.class),
|
() -> objectMapper.readValue(JSON, HelpResponse.class),
|
||||||
"HelpResponse deserialization failed"
|
"HelpResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
assertEquals(HELP, res.getHelp(), "Unexpected help text");
|
assertEquals(HELP, res.getHelp(), "Unexpected help text");
|
||||||
assertEquals(
|
assertEquals(
|
||||||
JSON,
|
JSON,
|
||||||
assertDoesNotThrow(() -> om.writeValueAsString(res), "HelpResponse serialization failed"),
|
assertDoesNotThrow(() -> objectMapper.writeValueAsString(res), "HelpResponse serialization failed"),
|
||||||
"Unexpected JSON string after serialization"
|
"Unexpected JSON string after serialization"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -89,7 +88,7 @@ class MetaSecretResponseTest extends AbstractModelTest<MetaSecretResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected MetaSecretResponse createFull() {
|
protected MetaSecretResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(SECRET_JSON_V2, MetaSecretResponse.class);
|
return objectMapper.readValue(SECRET_JSON_V2, MetaSecretResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -103,7 +102,7 @@ class MetaSecretResponseTest extends AbstractModelTest<MetaSecretResponse> {
|
|||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
// KV v2 secret.
|
// KV v2 secret.
|
||||||
MetaSecretResponse res = assertDoesNotThrow(
|
MetaSecretResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(SECRET_JSON_V2, MetaSecretResponse.class),
|
() -> objectMapper.readValue(SECRET_JSON_V2, MetaSecretResponse.class),
|
||||||
"SecretResponse deserialization failed"
|
"SecretResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertSecretData(res);
|
assertSecretData(res);
|
||||||
@ -117,7 +116,7 @@ class MetaSecretResponseTest extends AbstractModelTest<MetaSecretResponse> {
|
|||||||
|
|
||||||
// Deleted KV v2 secret.
|
// Deleted KV v2 secret.
|
||||||
res = assertDoesNotThrow(
|
res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(SECRET_JSON_V2_2, MetaSecretResponse.class),
|
() -> objectMapper.readValue(SECRET_JSON_V2_2, MetaSecretResponse.class),
|
||||||
"SecretResponse deserialization failed"
|
"SecretResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertSecretData(res);
|
assertSecretData(res);
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -71,7 +70,7 @@ class MetadataResponseTest extends AbstractModelTest<MetadataResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected MetadataResponse createFull() {
|
protected MetadataResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(META_JSON, MetadataResponse.class);
|
return objectMapper.readValue(META_JSON, MetadataResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -84,7 +83,7 @@ class MetadataResponseTest extends AbstractModelTest<MetadataResponse> {
|
|||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
MetadataResponse res = assertDoesNotThrow(
|
MetadataResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(META_JSON, MetadataResponse.class),
|
() -> objectMapper.readValue(META_JSON, MetadataResponse.class),
|
||||||
"MetadataResponse deserialization failed"
|
"MetadataResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -60,7 +59,7 @@ class PlainSecretResponseTest extends AbstractModelTest<PlainSecretResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected PlainSecretResponse createFull() {
|
protected PlainSecretResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(SECRET_JSON, PlainSecretResponse.class);
|
return objectMapper.readValue(SECRET_JSON, PlainSecretResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -73,7 +72,7 @@ class PlainSecretResponseTest extends AbstractModelTest<PlainSecretResponse> {
|
|||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
SecretResponse res = assertDoesNotThrow(
|
SecretResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(SECRET_JSON, PlainSecretResponse.class),
|
() -> objectMapper.readValue(SECRET_JSON, PlainSecretResponse.class),
|
||||||
"SecretResponse deserialization failed"
|
"SecretResponse deserialization failed"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -80,7 +79,7 @@ class SealResponseTest extends AbstractModelTest<SealResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected SealResponse createFull() {
|
protected SealResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(RES_UNSEALED, SealResponse.class);
|
return objectMapper.readValue(RES_UNSEALED, SealResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -94,7 +93,7 @@ class SealResponseTest extends AbstractModelTest<SealResponse> {
|
|||||||
void jsonRoundtripSealed() {
|
void jsonRoundtripSealed() {
|
||||||
// First test sealed Vault's response.
|
// First test sealed Vault's response.
|
||||||
SealResponse res = assertDoesNotThrow(
|
SealResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(RES_SEALED, SealResponse.class),
|
() -> objectMapper.readValue(RES_SEALED, SealResponse.class),
|
||||||
"SealResponse deserialization failed"
|
"SealResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
@ -116,7 +115,7 @@ class SealResponseTest extends AbstractModelTest<SealResponse> {
|
|||||||
|
|
||||||
// Not test unsealed Vault's response.
|
// Not test unsealed Vault's response.
|
||||||
res = assertDoesNotThrow(
|
res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(RES_UNSEALED, SealResponse.class),
|
() -> objectMapper.readValue(RES_UNSEALED, SealResponse.class),
|
||||||
"SealResponse deserialization failed"
|
"SealResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ class SecretListResponseTest extends AbstractModelTest<SecretListResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected SecretListResponse createFull() {
|
protected SecretListResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(JSON, SecretListResponse.class);
|
return objectMapper.readValue(JSON, SecretListResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -67,7 +66,7 @@ class SecretListResponseTest extends AbstractModelTest<SecretListResponse> {
|
|||||||
@Test
|
@Test
|
||||||
void getKeysTest() {
|
void getKeysTest() {
|
||||||
SecretListResponse res = assertDoesNotThrow(
|
SecretListResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(JSON, SecretListResponse.class),
|
() -> objectMapper.readValue(JSON, SecretListResponse.class),
|
||||||
"SecretListResponse deserialization failed"
|
"SecretListResponse deserialization failed"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ class SecretVersionResponseTest extends AbstractModelTest<SecretVersionResponse>
|
|||||||
@Override
|
@Override
|
||||||
protected SecretVersionResponse createFull() {
|
protected SecretVersionResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(META_JSON, SecretVersionResponse.class);
|
return objectMapper.readValue(META_JSON, SecretVersionResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -63,7 +62,7 @@ class SecretVersionResponseTest extends AbstractModelTest<SecretVersionResponse>
|
|||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
SecretVersionResponse res = assertDoesNotThrow(
|
SecretVersionResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(META_JSON, SecretVersionResponse.class),
|
() -> objectMapper.readValue(META_JSON, SecretVersionResponse.class),
|
||||||
"SecretVersionResponse deserialization failed"
|
"SecretVersionResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package de.stklcode.jvault.connector.model.response;
|
package de.stklcode.jvault.connector.model.response;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
import de.stklcode.jvault.connector.model.AbstractModelTest;
|
||||||
import de.stklcode.jvault.connector.model.response.embedded.TokenData;
|
import de.stklcode.jvault.connector.model.response.embedded.TokenData;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -96,7 +95,7 @@ class TokenResponseTest extends AbstractModelTest<TokenResponse> {
|
|||||||
@Override
|
@Override
|
||||||
protected TokenResponse createFull() {
|
protected TokenResponse createFull() {
|
||||||
try {
|
try {
|
||||||
return new ObjectMapper().readValue(RES_JSON, TokenResponse.class);
|
return objectMapper.readValue(RES_JSON, TokenResponse.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
fail("Creation of full model instance failed", e);
|
fail("Creation of full model instance failed", e);
|
||||||
return null;
|
return null;
|
||||||
@ -119,7 +118,7 @@ class TokenResponseTest extends AbstractModelTest<TokenResponse> {
|
|||||||
@Test
|
@Test
|
||||||
void jsonRoundtrip() {
|
void jsonRoundtrip() {
|
||||||
TokenResponse res = assertDoesNotThrow(
|
TokenResponse res = assertDoesNotThrow(
|
||||||
() -> new ObjectMapper().readValue(RES_JSON, TokenResponse.class),
|
() -> objectMapper.readValue(RES_JSON, TokenResponse.class),
|
||||||
"TokenResponse deserialization failed"
|
"TokenResponse deserialization failed"
|
||||||
);
|
);
|
||||||
assertNotNull(res, "Parsed response is NULL");
|
assertNotNull(res, "Parsed response is NULL");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user