|
1 | 1 | package de.rwth.idsg.ocpp.jaxb; |
2 | 2 |
|
3 | 3 | import de.rwth.idsg.ocpp.jaxb.validation.BeanValidationModule; |
| 4 | +import ocpp._2020._03.CustomData; |
| 5 | +import ocpp._2020._03.SecurityEventNotificationRequest; |
| 6 | +import ocpp.cs._2015._10.AuthorizeResponse; |
| 7 | +import ocpp.cs._2015._10.IdTagInfo; |
4 | 8 | import ocpp.cs._2015._10.StartTransactionRequest; |
5 | 9 | import org.joda.time.DateTime; |
6 | 10 | import org.junit.jupiter.api.Assertions; |
7 | 11 | import org.junit.jupiter.api.BeforeAll; |
8 | 12 | import org.junit.jupiter.api.Test; |
| 13 | +import tools.jackson.databind.DatabindException; |
9 | 14 | import tools.jackson.databind.ObjectMapper; |
10 | 15 | import tools.jackson.databind.json.JsonMapper; |
11 | 16 | import tools.jackson.datatype.joda.JodaModule; |
@@ -99,7 +104,38 @@ public void startTransactionIdTagTooLong() { |
99 | 104 |
|
100 | 105 | Assertions.assertEquals("idTag", violation.getPropertyPath().toString()); |
101 | 106 | Assertions.assertEquals("size must be between 0 and 20", violation.getMessage()); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void embeddedCustomDataEmpty() { |
| 111 | + var req = new SecurityEventNotificationRequest() |
| 112 | + .withType("type") |
| 113 | + .withTimestamp(DateTime.now()) |
| 114 | + .withCustomData(new CustomData()); |
| 115 | + |
| 116 | + String input = mapper.writeValueAsString(req); |
| 117 | + |
| 118 | + var exception = assertThrows(DatabindException.class, () -> mapper.readValue(input, SecurityEventNotificationRequest.class)); |
| 119 | + |
| 120 | + Throwable cause = exception.getCause(); |
| 121 | + Assertions.assertInstanceOf(ConstraintViolationException.class, cause); |
| 122 | + |
| 123 | + Assertions.assertEquals("vendorId: must not be null", cause.getMessage()); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void embeddedIdTagInfoEmpty() { |
| 128 | + var req = new AuthorizeResponse() |
| 129 | + .withIdTagInfo(new IdTagInfo()); |
| 130 | + |
| 131 | + String input = mapper.writeValueAsString(req); |
| 132 | + |
| 133 | + var exception = assertThrows(DatabindException.class, () -> mapper.readValue(input, AuthorizeResponse.class)); |
| 134 | + |
| 135 | + Throwable cause = exception.getCause(); |
| 136 | + Assertions.assertInstanceOf(ConstraintViolationException.class, cause); |
102 | 137 |
|
| 138 | + Assertions.assertEquals("status: must not be null", cause.getMessage()); |
103 | 139 | } |
104 | 140 |
|
105 | 141 | private static void checkViolatingNullFields(Set<String> expected, Set<ConstraintViolation<?>> violations) { |
|
0 commit comments