Skip to content

Commit 84a4fcf

Browse files
authored
Merge pull request #223 from bantu/github-221
ocpp-v1_6: BootNotificationRequest: Allow optional properties to be set null
2 parents 1c53b53 + 3bc476e commit 84a4fcf

File tree

3 files changed

+89
-8
lines changed

3 files changed

+89
-8
lines changed

.github/workflows/maven.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ jobs:
1919
- name: Set up JDK 11
2020
uses: actions/setup-java@v2
2121
with:
22-
java-version: '11'
22+
# TODO: Revert to '11'.
23+
# See https://github.com/ChargeTimeEU/Java-OCA-OCPP/pull/223#issuecomment-1328048028
24+
java-version: '11.0.16+8'
2325
distribution: 'temurin'
2426
cache: maven
2527
- name: Build with Maven

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/BootNotificationRequest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public String getChargeBoxSerialNumber() {
160160
*/
161161
@Deprecated()
162162
public void setChargeBoxSerialNumber(String chargeBoxSerialNumber) {
163-
if (!ModelUtil.validate(chargeBoxSerialNumber, STRING_25_CHAR_MAX_LENGTH)) {
163+
if (chargeBoxSerialNumber != null && !ModelUtil.validate(chargeBoxSerialNumber, STRING_25_CHAR_MAX_LENGTH)) {
164164
throw new PropertyConstraintException(
165165
chargeBoxSerialNumber.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH));
166166
}
@@ -184,7 +184,7 @@ public String getChargePointSerialNumber() {
184184
*/
185185
@XmlElement
186186
public void setChargePointSerialNumber(String chargePointSerialNumber) {
187-
if (!ModelUtil.validate(chargePointSerialNumber, STRING_25_CHAR_MAX_LENGTH)) {
187+
if (chargePointSerialNumber != null && !ModelUtil.validate(chargePointSerialNumber, STRING_25_CHAR_MAX_LENGTH)) {
188188
throw new PropertyConstraintException(
189189
chargePointSerialNumber.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH));
190190
}
@@ -208,7 +208,7 @@ public String getFirmwareVersion() {
208208
*/
209209
@XmlElement
210210
public void setFirmwareVersion(String firmwareVersion) {
211-
if (!ModelUtil.validate(firmwareVersion, STRING_50_CHAR_MAX_LENGTH)) {
211+
if (firmwareVersion != null && !ModelUtil.validate(firmwareVersion, STRING_50_CHAR_MAX_LENGTH)) {
212212
throw new PropertyConstraintException(
213213
firmwareVersion.length(), validationErrorMessage(STRING_50_CHAR_MAX_LENGTH));
214214
}
@@ -232,7 +232,7 @@ public String getIccid() {
232232
*/
233233
@XmlElement
234234
public void setIccid(String iccid) {
235-
if (!ModelUtil.validate(iccid, STRING_20_CHAR_MAX_LENGTH)) {
235+
if (iccid != null && !ModelUtil.validate(iccid, STRING_20_CHAR_MAX_LENGTH)) {
236236
throw new PropertyConstraintException(
237237
iccid.length(), validationErrorMessage(STRING_20_CHAR_MAX_LENGTH));
238238
}
@@ -256,7 +256,7 @@ public String getImsi() {
256256
*/
257257
@XmlElement
258258
public void setImsi(String imsi) {
259-
if (!ModelUtil.validate(imsi, STRING_20_CHAR_MAX_LENGTH)) {
259+
if (imsi != null && !ModelUtil.validate(imsi, STRING_20_CHAR_MAX_LENGTH)) {
260260
throw new PropertyConstraintException(
261261
imsi.length(), validationErrorMessage(STRING_20_CHAR_MAX_LENGTH));
262262
}
@@ -280,7 +280,7 @@ public String getMeterSerialNumber() {
280280
*/
281281
@XmlElement
282282
public void setMeterSerialNumber(String meterSerialNumber) {
283-
if (!ModelUtil.validate(meterSerialNumber, STRING_25_CHAR_MAX_LENGTH)) {
283+
if (meterSerialNumber != null && !ModelUtil.validate(meterSerialNumber, STRING_25_CHAR_MAX_LENGTH)) {
284284
throw new PropertyConstraintException(
285285
meterSerialNumber.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH));
286286
}
@@ -304,7 +304,7 @@ public String getMeterType() {
304304
*/
305305
@XmlElement
306306
public void setMeterType(String meterType) {
307-
if (!ModelUtil.validate(meterType, STRING_25_CHAR_MAX_LENGTH)) {
307+
if (meterType != null && !ModelUtil.validate(meterType, STRING_25_CHAR_MAX_LENGTH)) {
308308
throw new PropertyConstraintException(
309309
meterType.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH));
310310
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package eu.chargetime.ocpp.model.core.test;
2+
/*
3+
ChargeTime.eu - Java-OCA-OCPP
4+
5+
MIT License
6+
7+
Copyright (C) 2022 Andreas Fischer <[email protected]>
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
*/
27+
28+
import eu.chargetime.ocpp.model.core.BootNotificationRequest;
29+
import org.junit.Before;
30+
import org.junit.Rule;
31+
import org.junit.Test;
32+
import org.junit.rules.ExpectedException;
33+
34+
public class BootNotificationRequestTest {
35+
36+
@Rule public ExpectedException thrownException = ExpectedException.none();
37+
38+
private BootNotificationRequest request;
39+
40+
@Before
41+
public void setup() {
42+
request = new BootNotificationRequest();
43+
}
44+
45+
@Test()
46+
public void validate_setChargeBoxSerialNumber_onNull_doesNotThrowNPE() {
47+
request.setChargeBoxSerialNumber(null);
48+
}
49+
50+
@Test()
51+
public void validate_setChargePointSerialNumber_onNull_doesNotThrowNPE() {
52+
request.setChargePointSerialNumber(null);
53+
}
54+
55+
@Test()
56+
public void validate_setFirmwareVersion_onNull_doesNotThrowNPE() {
57+
request.setFirmwareVersion(null);
58+
}
59+
60+
@Test()
61+
public void validate_setIccid_onNull_doesNotThrowNPE() {
62+
request.setIccid(null);
63+
}
64+
65+
@Test()
66+
public void validate_setImsi_onNull_doesNotThrowNPE() {
67+
request.setImsi(null);
68+
}
69+
70+
@Test()
71+
public void validate_setMeterSerialNumber_onNull_doesNotThrowNPE() {
72+
request.setMeterSerialNumber(null);
73+
}
74+
75+
@Test()
76+
public void validate_setMeterType_onNull_doesNotThrowNPE() {
77+
request.setMeterType(null);
78+
}
79+
}

0 commit comments

Comments
 (0)