diff --git a/pom.xml b/pom.xml index 5279aa1..9204d62 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,12 @@ - + 4.0.0 org.springframework.boot spring-boot-starter-parent - 3.5.7 + 4.0.0 @@ -52,7 +53,7 @@ io.github.classgraph classgraph - 4.8.181 + 4.8.184 @@ -61,7 +62,7 @@ commons-validator commons-validator - 1.10.0 + 1.10.1 commons-collections @@ -78,7 +79,7 @@ org.springdoc springdoc-openapi-starter-webmvc-ui - 2.8.14 + 3.0.0 @@ -98,13 +99,18 @@ spring-boot-starter-web test - - - org.liquibase - liquibase-core + org.springframework.boot + spring-boot-webmvc-test + test + + + org.springframework.boot + spring-boot-starter-liquibase test + + org.postgresql postgresql @@ -117,22 +123,6 @@ testcontainers 2.0.2 test - - - org.hamcrest - hamcrest-core - - - org.hamcrest - hamcrest-library - - - - - junit - junit - - org.testcontainers @@ -195,12 +185,12 @@ com.puppycrawl.tools checkstyle - 11.1.0 + 12.3.0 it.aboutbits java-checkstyle-config - 1.0.1 + 1.1.0 diff --git a/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeConfiguration.java b/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeConfiguration.java index 323609c..eeaadfd 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeConfiguration.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/autoconfiguration/web/CustomTypeConfiguration.java @@ -7,12 +7,13 @@ import it.aboutbits.springboot.toolbox.type.identity.EntityId; import it.aboutbits.springboot.toolbox.web.CustomTypePropertyEditor; import it.aboutbits.springboot.toolbox.web.EntityIdPropertyEditor; -import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.InitBinder; +import tools.jackson.databind.module.SimpleModule; import java.util.Set; @@ -37,19 +38,23 @@ public void initBinder(WebDataBinder binder) { } @Bean - public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer(CustomTypeScanner configuration) { - var types = configuration.getRelevantTypes(); + public JsonMapperBuilderCustomizer jsonCustomizer(CustomTypeScanner configuration) { + var module = new SimpleModule(); - var deserializers = types.stream() - .map(CustomTypeDeserializer::new) - .toList() - .toArray(new CustomTypeDeserializer[types.size()]); + // serializers + module.addSerializer(new CustomTypeSerializer()); + // dynamic deserializers + configuration.getRelevantTypes() + .forEach(type -> + module.addDeserializer(type, new CustomTypeDeserializer(type)) + ); + + // type-based deserializer + module.addDeserializer(EntityId.class, new EntityIdDeserializer()); return builder -> builder - .serializers(new CustomTypeSerializer()) - .deserializers(deserializers) - .deserializerByType(EntityId.class, new EntityIdDeserializer()); + .addModule(module); } } diff --git a/src/main/java/it/aboutbits/springboot/toolbox/exception/ExceptionMessageDefinition.java b/src/main/java/it/aboutbits/springboot/toolbox/exception/ExceptionMessageDefinition.java index d5b1357..5c6da3f 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/exception/ExceptionMessageDefinition.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/exception/ExceptionMessageDefinition.java @@ -6,15 +6,15 @@ *

* Example: * {@snippet : + * * @Getter * @Accessors(fluent = true) - * @RequiredArgsConstructor - * enum MyExceptionMessages implements ExceptionMessageDefinition { - * SHARED_ERROR_GENERAL("shared.error.general"); - * - * private final String code; - * } + * @RequiredArgsConstructor enum MyExceptionMessages implements ExceptionMessageDefinition { + * SHARED_ERROR_GENERAL("shared.error.general"); + *

+ * private final String code; * } + *} */ public interface ExceptionMessageDefinition { String code(); diff --git a/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java b/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java index c50e6e5..56ee436 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeDeserializer.java @@ -1,13 +1,16 @@ package it.aboutbits.springboot.toolbox.jackson; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; import it.aboutbits.springboot.toolbox.reflection.util.CustomTypeReflectionUtil; import it.aboutbits.springboot.toolbox.type.CustomType; import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; +import tools.jackson.core.JacksonException; +import tools.jackson.core.JsonParser; +import tools.jackson.core.TokenStreamLocation; +import tools.jackson.core.exc.InputCoercionException; +import tools.jackson.databind.DeserializationContext; +import tools.jackson.databind.ValueDeserializer; -import java.io.IOException; +import java.io.Closeable; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; @@ -15,7 +18,7 @@ import java.util.UUID; import java.util.function.Function; -public class CustomTypeDeserializer> extends JsonDeserializer { +public class CustomTypeDeserializer> extends ValueDeserializer { private final Class customType; private final Constructor constructor; private final Function typeConverter; @@ -43,7 +46,7 @@ public Class handledType() { } @Override - public T deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + public T deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) { var value = typeConverter.apply(jsonParser); try { @@ -52,7 +55,46 @@ public T deserialize(JsonParser jsonParser, DeserializationContext deserializati IllegalAccessException | InvocationTargetException | InstantiationException e) { - throw new IOException(e); + throw new Ex(e); + } + } + + public static class Ex extends JacksonException { + + protected Ex(String msg) { + super(msg); + } + + protected Ex(Throwable rootCause) { + super(rootCause); + } + + protected Ex(String msg, Throwable rootCause) { + super(msg, rootCause); + } + + protected Ex(String msg, TokenStreamLocation loc, Throwable rootCause) { + super(msg, loc, rootCause); + } + + protected Ex(Closeable processor, Throwable rootCause) { + super(processor, rootCause); + } + + protected Ex(Closeable processor, String msg, TokenStreamLocation loc, Throwable rootCause) { + super(processor, msg, loc, rootCause); + } + + protected Ex(Closeable processor, String msg) { + super(processor, msg); + } + + protected Ex(Closeable processor, String msg, Throwable problem) { + super(processor, msg, problem); + } + + protected Ex(Closeable processor, String msg, TokenStreamLocation loc) { + super(processor, msg, loc); } } @@ -106,7 +148,7 @@ private static Function getByteConverter() { return jsonParser -> { try { return jsonParser.getByteValue(); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as Byte.", e); } }; @@ -116,7 +158,7 @@ private static Function getBooleanConverter() { return jsonParser -> { try { return jsonParser.getBooleanValue(); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as Boolean.", e); } }; @@ -126,7 +168,7 @@ private static Function getScaledBigDecimalConverter() { return jsonParser -> { try { return new ScaledBigDecimal(jsonParser.getDecimalValue()); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as ScaledBigDecimal.", e); } }; @@ -136,7 +178,7 @@ private static Function getBigDecimalConverter() { return jsonParser -> { try { return jsonParser.getDecimalValue(); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as BigDecimal.", e); } }; @@ -146,7 +188,7 @@ private static Function getDoubleConverter() { return jsonParser -> { try { return jsonParser.getDoubleValue(); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as Double.", e); } }; @@ -156,7 +198,7 @@ private static Function getFloatConverter() { return jsonParser -> { try { return jsonParser.getFloatValue(); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as Float.", e); } }; @@ -166,7 +208,7 @@ private static Function getBigIntegerConverter() { return jsonParser -> { try { return jsonParser.getBigIntegerValue(); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as BigInteger.", e); } }; @@ -176,7 +218,7 @@ private static Function getLongConverter() { return jsonParser -> { try { return jsonParser.getLongValue(); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as Long.", e); } }; @@ -186,7 +228,7 @@ private static Function getIntegerConverter() { return jsonParser -> { try { return jsonParser.getIntValue(); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as Integer.", e); } }; @@ -196,7 +238,7 @@ private static Function getShortConverter() { return jsonParser -> { try { return jsonParser.getShortValue(); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as Short.", e); } }; @@ -206,7 +248,7 @@ private static Function getStringConverter() { return jsonParser -> { try { return jsonParser.getValueAsString(); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as String.", e); } }; @@ -217,10 +259,15 @@ private static Function getCharConverter() { try { var value = jsonParser.getValueAsString(); if (value == null || value.length() != 1) { - throw new IOException(); + throw new InputCoercionException( + jsonParser, + "Not a Char.", + jsonParser.currentToken(), + String.class + ); } return value.charAt(0); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as Char.", e); } }; @@ -231,10 +278,15 @@ private static Function getUUIDConverter() { try { var value = jsonParser.getValueAsString(); if (value == null || value.length() != 36) { - throw new IOException(); + throw new InputCoercionException( + jsonParser, + "Not a UUID.", + jsonParser.currentToken(), + String.class + ); } return UUID.fromString(value); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as UUID.", e); } }; @@ -255,7 +307,7 @@ private static Function getEnumConverter(Class wrappedTyp "Failed to read value as Enum: " + enumClass.getName(), e ); - } catch (IOException e) { + } catch (InputCoercionException e) { throw new CustomTypeDeserializerException("Failed to read value as Enum.", e); } }; diff --git a/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeSerializer.java b/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeSerializer.java index bd21229..1e97a8a 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeSerializer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/jackson/CustomTypeSerializer.java @@ -1,14 +1,14 @@ package it.aboutbits.springboot.toolbox.jackson; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; + import it.aboutbits.springboot.toolbox.type.CustomType; +import tools.jackson.core.JsonGenerator; +import tools.jackson.databind.SerializationContext; +import tools.jackson.databind.ValueSerializer; -import java.io.IOException; import java.util.UUID; -public class CustomTypeSerializer extends JsonSerializer> { +public class CustomTypeSerializer extends ValueSerializer> { @SuppressWarnings("unchecked") @Override public Class> handledType() { @@ -19,8 +19,8 @@ public Class> handledType() { public void serialize( CustomType customType, JsonGenerator jsonGenerator, - SerializerProvider serializerProvider - ) throws IOException { + SerializationContext ctx + ) { var value = customType.value(); switch (value) { diff --git a/src/main/java/it/aboutbits/springboot/toolbox/jackson/EntityIdDeserializer.java b/src/main/java/it/aboutbits/springboot/toolbox/jackson/EntityIdDeserializer.java index 14113f6..04029bc 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/jackson/EntityIdDeserializer.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/jackson/EntityIdDeserializer.java @@ -1,14 +1,12 @@ package it.aboutbits.springboot.toolbox.jackson; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; import it.aboutbits.springboot.toolbox.type.identity.EntityId; +import tools.jackson.core.JsonParser; +import tools.jackson.core.exc.InputCoercionException; +import tools.jackson.databind.DeserializationContext; +import tools.jackson.databind.ValueDeserializer; -import java.io.IOException; - -public class EntityIdDeserializer extends JsonDeserializer> { +public class EntityIdDeserializer extends ValueDeserializer> { /* This is needed because EntityId is just the interface. Jackson does not know what implementation to take. So we use this generic implementation. @@ -17,7 +15,7 @@ public class EntityIdDeserializer extends JsonDeserializer> { public EntityId deserialize( JsonParser jsonParser, DeserializationContext deserializationContext - ) throws IOException { + ) { // We need to do this because due to type erasure we don't actually know the wrapped type. So we try a number first and fallback to a string. try { var theValue = jsonParser.getLongValue(); @@ -32,7 +30,7 @@ public String toString() { return String.valueOf(value()); } }; - } catch (JsonParseException e) { + } catch (InputCoercionException _) { var theValue = jsonParser.getValueAsString(); return new EntityId() { @Override diff --git a/src/main/java/it/aboutbits/springboot/toolbox/persistence/transformer/TransformerRuntimeException.java b/src/main/java/it/aboutbits/springboot/toolbox/persistence/transformer/TransformerRuntimeException.java index 316072f..95a17d9 100644 --- a/src/main/java/it/aboutbits/springboot/toolbox/persistence/transformer/TransformerRuntimeException.java +++ b/src/main/java/it/aboutbits/springboot/toolbox/persistence/transformer/TransformerRuntimeException.java @@ -16,7 +16,12 @@ public TransformerRuntimeException(final Throwable cause) { super(cause); } - public TransformerRuntimeException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { + public TransformerRuntimeException( + final String message, + final Throwable cause, + final boolean enableSuppression, + final boolean writableStackTrace + ) { super(message, cause, enableSuppression, writableStackTrace); } } diff --git a/src/test/java/it/aboutbits/springboot/toolbox/_support/HttpTest.java b/src/test/java/it/aboutbits/springboot/toolbox/_support/HttpTest.java index 49e7427..30c0520 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/_support/HttpTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/_support/HttpTest.java @@ -1,6 +1,6 @@ package it.aboutbits.springboot.toolbox._support; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/mvc/CustomTypeBindingsForControllerTest.java b/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/mvc/CustomTypeBindingsForControllerTest.java index ca022ce..b3c0c73 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/mvc/CustomTypeBindingsForControllerTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/mvc/CustomTypeBindingsForControllerTest.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.autoconfiguration.mvc; -import com.fasterxml.jackson.databind.ObjectMapper; import it.aboutbits.springboot.toolbox._support.HttpTest; import it.aboutbits.springboot.toolbox.autoconfiguration.mvc.body.BodyWithEmailAddress; import it.aboutbits.springboot.toolbox.autoconfiguration.mvc.body.BodyWithIban; @@ -18,6 +17,7 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import tools.jackson.databind.json.JsonMapper; import java.util.UUID; @@ -29,7 +29,7 @@ public class CustomTypeBindingsForControllerTest { protected MockMvc mockMvc; @Autowired - protected ObjectMapper objectMapper; + protected JsonMapper jsonMapper; @Nested class EmailAddressType { @@ -41,7 +41,7 @@ void emailAddressAsPathVariable() throws Exception { String.format("/test/type/EmailAddress/as-path-variable/%s", value) ); - var actual = objectMapper.readValue(resultAsString, EmailAddress.class); + var actual = jsonMapper.readValue(resultAsString, EmailAddress.class); assertThat(actual).isEqualTo(value); } @@ -54,7 +54,7 @@ void emailAddressAsRequestParameter() throws Exception { String.format("/test/type/EmailAddress/as-request-parameter?value=%s", value) ); - var actual = objectMapper.readValue(resultAsString, EmailAddress.class); + var actual = jsonMapper.readValue(resultAsString, EmailAddress.class); assertThat(actual).isEqualTo(value); } @@ -70,7 +70,7 @@ void emailAddressAsBody() throws Exception { value ); - var actual = objectMapper.readValue(resultAsString, BodyWithEmailAddress.class); + var actual = jsonMapper.readValue(resultAsString, BodyWithEmailAddress.class); assertThat(actual).isEqualTo(value); } @@ -86,7 +86,7 @@ void IbanAsPathVariable() throws Exception { String.format("/test/type/Iban/as-path-variable/%s", value) ); - var actual = objectMapper.readValue(resultAsString, Iban.class); + var actual = jsonMapper.readValue(resultAsString, Iban.class); assertThat(actual).isEqualTo(value); } @@ -99,7 +99,7 @@ void IbanAsRequestParameter() throws Exception { String.format("/test/type/Iban/as-request-parameter?value=%s", value) ); - var actual = objectMapper.readValue(resultAsString, Iban.class); + var actual = jsonMapper.readValue(resultAsString, Iban.class); assertThat(actual).isEqualTo(value); } @@ -115,7 +115,7 @@ void IbanAsBody() throws Exception { value ); - var actual = objectMapper.readValue(resultAsString, BodyWithIban.class); + var actual = jsonMapper.readValue(resultAsString, BodyWithIban.class); assertThat(actual).isEqualTo(value); } @@ -132,7 +132,7 @@ void ScaledBigDecimalAsPathVariable(double doubleValue) throws Exception { String.format("/test/type/ScaledBigDecimal/as-path-variable/%s", value) ); - var actual = objectMapper.readValue(resultAsString, ScaledBigDecimal.class); + var actual = jsonMapper.readValue(resultAsString, ScaledBigDecimal.class); assertThat(actual).isEqualTo(value); } @@ -146,7 +146,7 @@ void ScaledBigDecimalAsRequestParameter(double doubleValue) throws Exception { String.format("/test/type/ScaledBigDecimal/as-request-parameter?value=%s", value) ); - var actual = objectMapper.readValue(resultAsString, ScaledBigDecimal.class); + var actual = jsonMapper.readValue(resultAsString, ScaledBigDecimal.class); assertThat(actual).isEqualTo(value); } @@ -163,7 +163,7 @@ void ScaledBigDecimalAsBody(double doubleValue) throws Exception { value ); - var actual = objectMapper.readValue(resultAsString, BodyWithScaledBigDecimal.class); + var actual = jsonMapper.readValue(resultAsString, BodyWithScaledBigDecimal.class); assertThat(actual).isEqualTo(value); } @@ -180,7 +180,7 @@ void UUIDAsPathVariable(String uuidStringValue) throws Exception { String.format("/test/type/UUID/as-path-variable/%s", value) ); - var actual = objectMapper.readValue(resultAsString, UUID.class); + var actual = jsonMapper.readValue(resultAsString, UUID.class); assertThat(actual).isEqualTo(value); } @@ -194,7 +194,7 @@ void UUIDAsRequestParameter(String uuidStringValue) throws Exception { String.format("/test/type/UUID/as-request-parameter?value=%s", value) ); - var actual = objectMapper.readValue(resultAsString, UUID.class); + var actual = jsonMapper.readValue(resultAsString, UUID.class); assertThat(actual).isEqualTo(value); } @@ -211,7 +211,7 @@ void UUIDAsBody(String uuidStringValue) throws Exception { value ); - var actual = objectMapper.readValue(resultAsString, BodyWithUUID.class); + var actual = jsonMapper.readValue(resultAsString, BodyWithUUID.class); assertThat(actual).isEqualTo(value); } @@ -229,7 +229,7 @@ void UUIDAsBody(String uuidStringValue) throws Exception { private @NonNull String performPostAndReturnResult(@NonNull String url, @NonNull Object body) throws Exception { var requestBuilder = MockMvcRequestBuilders.post(url) - .content(objectMapper.writeValueAsString(body)) + .content(jsonMapper.writeValueAsString(body)) .contentType(MediaType.APPLICATION_JSON); return mockMvc.perform(requestBuilder) diff --git a/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/mvc/EntityIdBindingsForControllerTest.java b/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/mvc/EntityIdBindingsForControllerTest.java index 6d243b9..e2213d3 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/mvc/EntityIdBindingsForControllerTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/mvc/EntityIdBindingsForControllerTest.java @@ -1,6 +1,5 @@ package it.aboutbits.springboot.toolbox.autoconfiguration.mvc; -import com.fasterxml.jackson.databind.ObjectMapper; import it.aboutbits.springboot.toolbox._support.HttpTest; import it.aboutbits.springboot.toolbox.autoconfiguration.mvc.body.BodyWithEntityId; import it.aboutbits.springboot.toolbox.autoconfiguration.mvc.body.BodyWithEnumEntityId; @@ -13,6 +12,7 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import tools.jackson.databind.json.JsonMapper; import static org.assertj.core.api.Assertions.assertThat; @@ -22,7 +22,7 @@ public class EntityIdBindingsForControllerTest { protected MockMvc mockMvc; @Autowired - protected ObjectMapper objectMapper; + protected JsonMapper jsonMapper; @Nested class EntityId { @@ -34,7 +34,7 @@ void emailAddressAsPathVariable() throws Exception { String.format("/test/entity-id/CustomTypeTestModel.ID/as-path-variable/%s", value) ); - var actual = objectMapper.readValue(resultAsString, CustomTypeTestModel.ID.class); + var actual = jsonMapper.readValue(resultAsString, CustomTypeTestModel.ID.class); assertThat(actual).isEqualTo(value); } @@ -47,7 +47,7 @@ void emailAddressAsRequestParameter() throws Exception { String.format("/test/entity-id/CustomTypeTestModel.ID/as-request-parameter?value=%s", value) ); - var actual = objectMapper.readValue(resultAsString, CustomTypeTestModel.ID.class); + var actual = jsonMapper.readValue(resultAsString, CustomTypeTestModel.ID.class); assertThat(actual).isEqualTo(value); } @@ -63,7 +63,7 @@ void emailAddressAsBody() throws Exception { value ); - var actual = objectMapper.readValue(resultAsString, BodyWithEntityId.class); + var actual = jsonMapper.readValue(resultAsString, BodyWithEntityId.class); assertThat(actual).isEqualTo(value); } @@ -79,7 +79,7 @@ void emailAddressAsPathVariable() throws Exception { String.format("/test/entity-id/CustomTypeEnumTestModel.ID/as-path-variable/%s", value) ); - var actual = objectMapper.readValue(resultAsString, CustomTypeEnumTestModel.ID.class); + var actual = jsonMapper.readValue(resultAsString, CustomTypeEnumTestModel.ID.class); assertThat(actual).isEqualTo(value); } @@ -92,7 +92,7 @@ void emailAddressAsRequestParameter() throws Exception { String.format("/test/entity-id/CustomTypeEnumTestModel.ID/as-request-parameter?value=%s", value) ); - var actual = objectMapper.readValue(resultAsString, CustomTypeEnumTestModel.ID.class); + var actual = jsonMapper.readValue(resultAsString, CustomTypeEnumTestModel.ID.class); assertThat(actual).isEqualTo(value); } @@ -108,7 +108,7 @@ void emailAddressAsBody() throws Exception { value ); - var actual = objectMapper.readValue(resultAsString, BodyWithEnumEntityId.class); + var actual = jsonMapper.readValue(resultAsString, BodyWithEnumEntityId.class); assertThat(actual).isEqualTo(value); } @@ -126,7 +126,7 @@ void emailAddressAsBody() throws Exception { private @NonNull String performPostAndReturnResult(@NonNull String url, @NonNull Object body) throws Exception { var requestBuilder = MockMvcRequestBuilders.post(url) - .content(objectMapper.writeValueAsString(body)) + .content(jsonMapper.writeValueAsString(body)) .contentType(MediaType.APPLICATION_JSON); return mockMvc.perform(requestBuilder) diff --git a/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/CustomTypeTestModelRepository.java b/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/CustomTypeTestModelRepository.java index cd89b75..bbd6270 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/CustomTypeTestModelRepository.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/autoconfiguration/persistence/impl/jpa/CustomTypeTestModelRepository.java @@ -16,6 +16,7 @@ public interface CustomTypeTestModelRepository extends JpaRepository findByAccountBalance(ScaledBigDecimal accountBalance); Optional findByUuid(UUID uuid); + Optional findByUuidAsString(UUID uuidAsString); Optional findByReferencedId(ReferencedTestModel.ID otherId); diff --git a/src/test/java/it/aboutbits/springboot/toolbox/type/EmailAddressTest.java b/src/test/java/it/aboutbits/springboot/toolbox/type/EmailAddressTest.java index bbed40e..1efb6fa 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/type/EmailAddressTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/type/EmailAddressTest.java @@ -21,7 +21,21 @@ void validValues_shouldSucceed(String value) { } @ParameterizedTest - @ValueSource(strings = {"", " ", " ", "\t", "\r", "\n", "sepp", "x@ y", "@aboutbits.it", "hans mueller@aboutbits.it", "peter@pansky@aboutbits.it"}) + @ValueSource( + strings = { + "", + " ", + " ", + "\t", + "\r", + "\n", + "sepp", + "x@ y", + "@aboutbits.it", + "hans mueller@aboutbits.it", + "peter@pansky@aboutbits.it" + } + ) void invalidValues_shouldFail(String value) { assertThatIllegalArgumentException().isThrownBy( () -> new EmailAddress(value) diff --git a/src/test/java/it/aboutbits/springboot/toolbox/type/IbanTest.java b/src/test/java/it/aboutbits/springboot/toolbox/type/IbanTest.java index 3b9fe55..8311a93 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/type/IbanTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/type/IbanTest.java @@ -13,7 +13,15 @@ class IbanTest { @Nested class Constructor { @ParameterizedTest - @ValueSource(strings = {"NL08INGB3330533676", "HR3425000097537651489", "IT37G0300203280237914848919", "AT705400073311799347", "DE60500105175378199617"}) + @ValueSource( + strings = { + "NL08INGB3330533676", + "HR3425000097537651489", + "IT37G0300203280237914848919", + "AT705400073311799347", + "DE60500105175378199617" + } + ) void validValues_shouldSucceed(String value) { assertThatCode( () -> new Iban(value) @@ -21,7 +29,18 @@ void validValues_shouldSucceed(String value) { } @ParameterizedTest - @ValueSource(strings = {"IT60X0542811101000000123450", "some-wrong-stuff", "", " ", " ", "\t", "\r", "\n"}) + @ValueSource( + strings = { + "IT60X0542811101000000123450", + "some-wrong-stuff", + "", + " ", + " ", + "\t", + "\r", + "\n" + } + ) void invalidValues_shouldFail(String value) { assertThatIllegalArgumentException().isThrownBy( () -> new Iban(value) diff --git a/src/test/java/it/aboutbits/springboot/toolbox/validation/util/EmailAddressValidatorTest.java b/src/test/java/it/aboutbits/springboot/toolbox/validation/util/EmailAddressValidatorTest.java index 3e3a189..1ee4cc9 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/validation/util/EmailAddressValidatorTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/validation/util/EmailAddressValidatorTest.java @@ -19,7 +19,21 @@ void validValues_shouldSucceed(String value) { } @ParameterizedTest - @ValueSource(strings = {"", " ", " ", "\t", "\r", "\n", "sepp", "x@ y", "@aboutbits.it", "hans mueller@aboutbits.it", "peter@pansky@aboutbits.it"}) + @ValueSource( + strings = { + "", + " ", + " ", + "\t", + "\r", + "\n", + "sepp", + "x@ y", + "@aboutbits.it", + "hans mueller@aboutbits.it", + "peter@pansky@aboutbits.it" + } + ) void invalidValues_shouldFail(String value) { assertThat( EmailAddressValidator.isValid(value) @@ -45,7 +59,21 @@ void validValues_shouldSucceed(String value) { } @ParameterizedTest - @ValueSource(strings = {"", " ", " ", "\t", "\r", "\n", "sepp", "x@ y", "@aboutbits.it", "hans mueller@aboutbits.it", "peter@pansky@aboutbits.it"}) + @ValueSource( + strings = { + "", + " ", + " ", + "\t", + "\r", + "\n", + "sepp", + "x@ y", + "@aboutbits.it", + "hans mueller@aboutbits.it", + "peter@pansky@aboutbits.it" + } + ) void invalidValues_shouldFail(String value) { assertThat( EmailAddressValidator.isNotValid(value) diff --git a/src/test/java/it/aboutbits/springboot/toolbox/validation/util/IbanValidatorTest.java b/src/test/java/it/aboutbits/springboot/toolbox/validation/util/IbanValidatorTest.java index d70ea11..7fbe7b1 100644 --- a/src/test/java/it/aboutbits/springboot/toolbox/validation/util/IbanValidatorTest.java +++ b/src/test/java/it/aboutbits/springboot/toolbox/validation/util/IbanValidatorTest.java @@ -11,7 +11,15 @@ class IbanValidatorTest { @Nested class IsValid { @ParameterizedTest - @ValueSource(strings = {"NL08INGB3330533676", "HR3425000097537651489", "IT37G0300203280237914848919", "AT705400073311799347", "DE60500105175378199617"}) + @ValueSource( + strings = { + "NL08INGB3330533676", + "HR3425000097537651489", + "IT37G0300203280237914848919", + "AT705400073311799347", + "DE60500105175378199617" + } + ) void validValues_shouldSucceed(String value) { assertThat( IbanValidator.isValid(value) @@ -19,7 +27,18 @@ void validValues_shouldSucceed(String value) { } @ParameterizedTest - @ValueSource(strings = {"IT60X0542811101000000123450", "some-wrong-stuff", "", " ", " ", "\t", "\r", "\n"}) + @ValueSource( + strings = { + "IT60X0542811101000000123450", + "some-wrong-stuff", + "", + " ", + " ", + "\t", + "\r", + "\n" + } + ) void invalidValues_shouldFail(String value) { assertThat( IbanValidator.isValid(value) @@ -37,7 +56,15 @@ void null_shouldFail() { @Nested class IsNotValid { @ParameterizedTest - @ValueSource(strings = {"NL08INGB3330533676", "HR3425000097537651489", "IT37G0300203280237914848919", "AT705400073311799347", "DE60500105175378199617"}) + @ValueSource( + strings = { + "NL08INGB3330533676", + "HR3425000097537651489", + "IT37G0300203280237914848919", + "AT705400073311799347", + "DE60500105175378199617" + } + ) void validValues_shouldSucceed(String value) { assertThat( IbanValidator.isNotValid(value) @@ -45,7 +72,18 @@ void validValues_shouldSucceed(String value) { } @ParameterizedTest - @ValueSource(strings = {"IT60X0542811101000000123450", "some-wrong-stuff", "", " ", " ", "\t", "\r", "\n"}) + @ValueSource( + strings = { + "IT60X0542811101000000123450", + "some-wrong-stuff", + "", + " ", + " ", + "\t", + "\r", + "\n" + } + ) void invalidValues_shouldFail(String value) { assertThat( IbanValidator.isNotValid(value)