|
3 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; |
4 | 4 | import it.aboutbits.springboot.toolbox._support.HttpTest; |
5 | 5 | import it.aboutbits.springboot.toolbox.autoconfiguration.mvc.body.BodyWithEntityId; |
| 6 | +import it.aboutbits.springboot.toolbox.autoconfiguration.mvc.body.BodyWithEnumEntityId; |
| 7 | +import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.impl.jpa.CustomTypeEnumTestModel; |
6 | 8 | import it.aboutbits.springboot.toolbox.autoconfiguration.persistence.impl.jpa.CustomTypeTestModel; |
7 | 9 | import lombok.NonNull; |
8 | 10 | import org.junit.jupiter.api.Nested; |
@@ -67,6 +69,51 @@ void emailAddressAsBody() throws Exception { |
67 | 69 | } |
68 | 70 | } |
69 | 71 |
|
| 72 | + @Nested |
| 73 | + class EnumEntityId { |
| 74 | + @Test |
| 75 | + void emailAddressAsPathVariable() throws Exception { |
| 76 | + var value = new CustomTypeEnumTestModel.ID(CustomTypeEnumTestModel.CustomTypeEnum.ENUM_FIRST); |
| 77 | + |
| 78 | + var resultAsString = performGetAndReturnResult( |
| 79 | + String.format("/test/entity-id/CustomTypeEnumTestModel.ID/as-path-variable/%s", value) |
| 80 | + ); |
| 81 | + |
| 82 | + var actual = objectMapper.readValue(resultAsString, CustomTypeEnumTestModel.ID.class); |
| 83 | + |
| 84 | + assertThat(actual).isEqualTo(value); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + void emailAddressAsRequestParameter() throws Exception { |
| 89 | + var value = new CustomTypeEnumTestModel.ID(CustomTypeEnumTestModel.CustomTypeEnum.ENUM_OTHER); |
| 90 | + |
| 91 | + var resultAsString = performGetAndReturnResult( |
| 92 | + String.format("/test/entity-id/CustomTypeEnumTestModel.ID/as-request-parameter?value=%s", value) |
| 93 | + ); |
| 94 | + |
| 95 | + var actual = objectMapper.readValue(resultAsString, CustomTypeEnumTestModel.ID.class); |
| 96 | + |
| 97 | + assertThat(actual).isEqualTo(value); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + void emailAddressAsBody() throws Exception { |
| 102 | + var value = new BodyWithEnumEntityId( |
| 103 | + new CustomTypeEnumTestModel.ID(CustomTypeEnumTestModel.CustomTypeEnum.ENUM_LAST) |
| 104 | + ); |
| 105 | + |
| 106 | + var resultAsString = performPostAndReturnResult( |
| 107 | + "/test/entity-id/CustomTypeEnumTestModel.ID/as-body", |
| 108 | + value |
| 109 | + ); |
| 110 | + |
| 111 | + var actual = objectMapper.readValue(resultAsString, BodyWithEnumEntityId.class); |
| 112 | + |
| 113 | + assertThat(actual).isEqualTo(value); |
| 114 | + } |
| 115 | + } |
| 116 | + |
70 | 117 | private @NonNull String performGetAndReturnResult(@NonNull String url) throws Exception { |
71 | 118 | var requestBuilder = MockMvcRequestBuilders.get(url) |
72 | 119 | .contentType(MediaType.APPLICATION_JSON); |
|
0 commit comments