Skip to content

Commit 5935ba9

Browse files
committed
Make invalid FakeChargingStation responses explicit
The FakeChargingStation implementations were implicitly sending invalid responses to a GetVariablesRequest. Make this behavior configurable and explicit with a setter method.
1 parent ee4b661 commit 5935ba9

5 files changed

Lines changed: 50 additions & 22 deletions

File tree

ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class FakeChargePoint {
6464
String receivedConfirmationError;
6565
String receivedConfirmationErrorDescription;
6666
String receivedConfirmationErrorUniqueId;
67+
boolean riggedToSendInvalidResponse = false;
6768
String url;
6869

6970
public FakeChargePoint() throws MalformedURLException {
@@ -653,4 +654,12 @@ public String getReceivedConfirmationErrorDescription() {
653654
public String getReceivedConfirmationErrorUniqueId() {
654655
return receivedConfirmationErrorUniqueId;
655656
}
657+
658+
public void setRiggedToSendInvalidResponse(boolean riggedToSendInvalidResponse) {
659+
this.riggedToSendInvalidResponse = riggedToSendInvalidResponse;
660+
}
661+
662+
public boolean isRiggedToSendInvalidResponse() {
663+
return riggedToSendInvalidResponse;
664+
}
656665
}

ocpp-v2-test/src/main/java/eu/chargetime/ocpp/test/FakeChargingStation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ public interface FakeChargingStation {
4747
String getReceivedConfirmationErrorDescription();
4848

4949
String getReceivedConfirmationErrorUniqueId();
50+
51+
void setRiggedToSendInvalidResponse(boolean riggedToSendInvalidResponse);
5052
}

ocpp-v2-test/src/main/java/eu/chargetime/ocpp/test/OCPP201MultiProtocolFakeChargingStation.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,24 @@ public GetReportResponse handleGetReportRequest(GetReportRequest request) {
8787
@Override
8888
public GetVariablesResponse handleGetVariablesRequest(GetVariablesRequest request) {
8989
receivedRequest = request;
90-
return new GetVariablesResponse(
91-
new GetVariableResult[] {
92-
new GetVariableResult(
93-
GetVariableStatusEnum.UnknownVariable,
94-
new Component(""),
95-
new Variable("")),
96-
new GetVariableResult(
97-
GetVariableStatusEnum.UnknownVariable,
98-
new Component(""),
99-
new Variable(""))
100-
});
90+
int results =
91+
isRiggedToSendInvalidResponse()
92+
? request.getGetVariableData().length + 1
93+
: request.getGetVariableData().length;
94+
GetVariableResult[] result = new GetVariableResult[results];
95+
for (int i = 0; i < results; i++) {
96+
result[i] =
97+
i < request.getGetVariableData().length
98+
? new GetVariableResult(
99+
GetVariableStatusEnum.UnknownVariable,
100+
request.getGetVariableData()[i].getComponent(),
101+
request.getGetVariableData()[i].getVariable())
102+
: new GetVariableResult(
103+
GetVariableStatusEnum.UnknownVariable,
104+
new Component(""),
105+
new Variable(""));
106+
}
107+
return new GetVariablesResponse(result);
101108
}
102109

103110
@Override

ocpp-v2-test/src/main/java/eu/chargetime/ocpp/test/OCPP21MultiProtocolFakeChargingStation.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,24 @@ public GetReportResponse handleGetReportRequest(GetReportRequest request) {
7070
@Override
7171
public GetVariablesResponse handleGetVariablesRequest(GetVariablesRequest request) {
7272
receivedRequest = request;
73-
return new GetVariablesResponse(
74-
new GetVariableResult[] {
75-
new GetVariableResult(
76-
GetVariableStatusEnum.UnknownVariable,
77-
new Component(""),
78-
new Variable("")),
79-
new GetVariableResult(
80-
GetVariableStatusEnum.UnknownVariable,
81-
new Component(""),
82-
new Variable(""))
83-
});
73+
int results =
74+
isRiggedToSendInvalidResponse()
75+
? request.getGetVariableData().length + 1
76+
: request.getGetVariableData().length;
77+
GetVariableResult[] result = new GetVariableResult[results];
78+
for (int i = 0; i < results; i++) {
79+
result[i] =
80+
i < request.getGetVariableData().length
81+
? new GetVariableResult(
82+
GetVariableStatusEnum.UnknownVariable,
83+
request.getGetVariableData()[i].getComponent(),
84+
request.getGetVariableData()[i].getVariable())
85+
: new GetVariableResult(
86+
GetVariableStatusEnum.UnknownVariable,
87+
new Component(""),
88+
new Variable(""));
89+
}
90+
return new GetVariablesResponse(result);
8491
}
8592

8693
@Override

ocpp-v2-test/src/test/java/eu/chargetime/ocpp/test/OCPP21MultiProtocolIntegrationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ public void testInvalidOCPP21ClientResponseTriggersCALLRESULTERROR() throws Inte
170170
(OCPP21MultiProtocolFakeCSMS) setupAndStartCSMS(OCPP2_1_FIRST);
171171
FakeChargingStation cs = buildAndConnectChargingStation(OCPP2_1_ONLY, csms);
172172
cs.sendBootNotification("vendor", "model");
173+
cs.setRiggedToSendInvalidResponse(true);
173174

174175
csms.sendGetVariablesRequest();
175176
Thread.sleep(100);
177+
assertThat(cs.getReceivedConfirmationError(), is(notNullValue()));
176178
assertThat(cs.getReceivedConfirmationError(), is("PropertyConstraintViolation"));
177179
assertThat(
178180
cs.getReceivedConfirmationErrorDescription(),
@@ -187,6 +189,7 @@ public void testInvalidOCPP201ClientResponseTriggersNoMessage() throws Interrupt
187189
(OCPP21MultiProtocolFakeCSMS) setupAndStartCSMS(OCPP2_1_FIRST);
188190
FakeChargingStation cs = buildAndConnectChargingStation(OCPP2_0_1_ONLY, csms);
189191
cs.sendBootNotification("vendor", "model");
192+
cs.setRiggedToSendInvalidResponse(true);
190193

191194
csms.sendGetVariablesRequest();
192195
Thread.sleep(100);

0 commit comments

Comments
 (0)