Skip to content

Commit ec79d05

Browse files
author
Mathias Oben
committed
Add tests for maximum length strings
1 parent ae02468 commit ec79d05

File tree

8 files changed

+135
-4
lines changed

8 files changed

+135
-4
lines changed

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/CertificateSignedRequestTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ public void constructor_nullCertificateChain_throwsPropertyConstraintException()
5656
// Then throws
5757
}
5858

59+
@Test
60+
public void setCertificateChain_maximumLengthString_nothingThrown() {
61+
// Given
62+
String certificateChain = TestUtilities.aString(10000);
63+
64+
// When
65+
new CertificateSignedRequest(certificateChain);
66+
67+
// Then nothing thrown
68+
}
69+
5970
@Test(expected = PropertyConstraintException.class)
6071
public void setCertificateChain_exceedingLengthString_throwsPropertyConstraintException() {
6172
// Given

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/GetLogConfirmationTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
2828

2929
import eu.chargetime.ocpp.PropertyConstraintException;
3030
import eu.chargetime.ocpp.model.securityext.GetLogConfirmation;
31+
import eu.chargetime.ocpp.model.securityext.types.CertificateHashDataType;
3132
import eu.chargetime.ocpp.model.securityext.types.LogStatusEnumType;
3233
import eu.chargetime.ocpp.utilities.TestUtilities;
3334
import org.junit.Test;
@@ -92,6 +93,18 @@ public void validate_setRequiredAndOptional_returnsTrue() {
9293
assertTrue(actual);
9394
}
9495

96+
@Test
97+
public void setFilename_maximumLengthString_nothingThrown() {
98+
// Given
99+
String filename = TestUtilities.aString(255);
100+
GetLogConfirmation confirmation = new GetLogConfirmation(null);
101+
102+
// When
103+
confirmation.setFilename(filename);
104+
105+
// Then nothing thrown
106+
}
107+
95108
@Test(expected = PropertyConstraintException.class)
96109
public void setFilename_exceedingLengthString_throwsPropertyConstraintException() {
97110
// Given

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/InstallCertificateRequestTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,24 @@ public void constructor_nullCertificate_throwsPropertyConstraintException() {
6161
// Then throws
6262
}
6363

64+
@Test
65+
public void setCertificate_maximumLengthString_nothingThrown() {
66+
// Given
67+
String certificate = TestUtilities.aString(5500);
68+
69+
// When
70+
new InstallCertificateRequest(null, certificate);
71+
72+
// Then nothing thrown
73+
}
74+
6475
@Test(expected = PropertyConstraintException.class)
6576
public void setCertificate_exceedingLengthString_throwsPropertyConstraintException() {
6677
// Given
6778
String certificate = TestUtilities.aString(5501);
68-
InstallCertificateRequest request = new InstallCertificateRequest(null, null);
6979

7080
// When
71-
request.setCertificate(certificate);
81+
new InstallCertificateRequest(null, certificate);
7282

7383
// Then throws
7484
}

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SecurityEventNotificationRequestTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ public void validate_returnFalse() {
7676
assertFalse(actual);
7777
}
7878

79+
@Test
80+
public void setType_maximumLengthString_nothingThrown() {
81+
// Given
82+
String type = TestUtilities.aString(50);
83+
ZonedDateTime timestamp = ZonedDateTime.now();
84+
85+
// When
86+
new SecurityEventNotificationRequest(type, timestamp);
87+
88+
// Then nothing thrown
89+
}
90+
7991
@Test(expected = PropertyConstraintException.class)
8092
public void setType_exceedingLengthString_throwsPropertyConstraintException() {
8193
// Given
@@ -88,6 +100,20 @@ public void setType_exceedingLengthString_throwsPropertyConstraintException() {
88100
// Then throws
89101
}
90102

103+
@Test
104+
public void setTechInfo_maximumLengthString_nothingThrown() {
105+
// Given
106+
String type = givenType();
107+
ZonedDateTime timestamp = ZonedDateTime.now();
108+
String techInfo = TestUtilities.aString(255);
109+
SecurityEventNotificationRequest request = new SecurityEventNotificationRequest(type, timestamp);
110+
111+
// When
112+
request.setTechInfo(techInfo);
113+
114+
// Then nothing thrown
115+
}
116+
91117
@Test(expected = PropertyConstraintException.class)
92118
public void setTechInfo_exceedingLengthString_throwsPropertyConstraintException() {
93119
// Given

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/SignCertificateRequestTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ public void constructor_nullCsr_throwsPropertyConstraintException() {
5656
// Then throws
5757
}
5858

59+
@Test
60+
public void setType_maximumLengthString_nothingThrown() {
61+
// Given
62+
String csr = TestUtilities.aString(5500);
63+
64+
// When
65+
new SignCertificateRequest(csr);
66+
67+
// Then nothing thrown
68+
}
69+
5970
@Test(expected = PropertyConstraintException.class)
6071
public void setCsr_exceedingLengthString_throwsPropertyConstraintException() {
6172
// Given

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/CertificateHashDataTypeTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ public void setIssuerKeyHash_nonIdentifierString_throwsPropertyConstraintExcepti
9494
// Then throws
9595
}
9696

97+
@Test
98+
public void setSerialNumber_maximumLengthString_nothingThrown() {
99+
// Given
100+
String serialNumber = TestUtilities.aString(40);
101+
CertificateHashDataType dataType = new CertificateHashDataType();
102+
103+
// When
104+
dataType.setSerialNumber(serialNumber);
105+
106+
// Then nothing thrown
107+
}
108+
97109
@Test(expected = PropertyConstraintException.class)
98110
public void setSerialNumber_exceedingLengthString_throwsPropertyConstraintException() {
99111
// Given

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/FirmwareTypeTest.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ public void validate_setRequired_returnsTrue() {
7171
assertTrue(actual);
7272
}
7373

74+
@Test
75+
public void setLocation_maximumLengthString_nothingThrown() {
76+
// Given
77+
String location = TestUtilities.aString(512);
78+
FirmwareType type = new FirmwareType();
79+
80+
// When
81+
type.setLocation(location);
82+
83+
// Then nothing thrown
84+
}
85+
7486
@Test(expected = PropertyConstraintException.class)
7587
public void setLocation_exceedingLengthString_throwsPropertyConstraintException() {
7688
// Given
@@ -83,6 +95,18 @@ public void setLocation_exceedingLengthString_throwsPropertyConstraintException(
8395
// Then throws
8496
}
8597

98+
@Test
99+
public void setSigningCertificate_maximumLengthString_nothingThrown() {
100+
// Given
101+
String signingCertificate = TestUtilities.aString(5500);
102+
FirmwareType type = new FirmwareType();
103+
104+
// When
105+
type.setSigningCertificate(signingCertificate);
106+
107+
// Then nothing thrown
108+
}
109+
86110
@Test(expected = PropertyConstraintException.class)
87111
public void setSigningCertificate_exceedingLengthString_throwsPropertyConstraintException() {
88112
// Given
@@ -95,6 +119,18 @@ public void setSigningCertificate_exceedingLengthString_throwsPropertyConstraint
95119
// Then throws
96120
}
97121

122+
@Test
123+
public void setSignature_maximumLengthString_nothingThrown() {
124+
// Given
125+
String signature = TestUtilities.aString(800);
126+
FirmwareType type = new FirmwareType();
127+
128+
// When
129+
type.setSignature(signature);
130+
131+
// Then nothing thrown
132+
}
133+
98134
@Test(expected = PropertyConstraintException.class)
99135
public void setSignature_exceedingLengthString_throwsPropertyConstraintException() {
100136
// Given
@@ -108,11 +144,11 @@ public void setSignature_exceedingLengthString_throwsPropertyConstraintException
108144
}
109145

110146
private String givenSigningCertificate() {
111-
return "an-identifier-string";
147+
return "PEM encoded X.509 certificate";
112148
}
113149

114150
private String givenSignature() {
115-
return "PEM encoded X.509 certificate";
151+
return "Base64 encoded firmware signature";
116152
}
117153

118154
private String givenLocation() {

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/securityext/test/types/LogParametersTypeTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ public void validate_setRequiredAndOptional_returnsTrue() {
8484
assertTrue(actual);
8585
}
8686

87+
@Test
88+
public void setLocation_maximumLengthString_nothingThrown() {
89+
// Given
90+
String location = TestUtilities.aString(512);
91+
LogParametersType type = new LogParametersType();
92+
93+
// When
94+
type.setRemoteLocation(location);
95+
96+
// Then nothing thrown
97+
}
98+
8799
@Test(expected = PropertyConstraintException.class)
88100
public void setLocation_exceedingLengthString_throwsPropertyConstraintException() {
89101
// Given

0 commit comments

Comments
 (0)