Skip to content

Commit 63b124e

Browse files
committed
For story TG-1: Implemented Server Stop Transaction feature.
1 parent 5555363 commit 63b124e

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ public StatusNotificationConfirmation handleStatusNotificationRequest(int sessio
121121
StatusNotificationConfirmation confirmation = new StatusNotificationConfirmation();
122122
return confirmation;
123123
}
124+
125+
@Override
126+
public StopTransactionConfirmation handleStopTransactionRequest(int sessionIndex, StopTransactionRequest request) {
127+
receivedRequest = request;
128+
StopTransactionConfirmation confirmation = new StopTransactionConfirmation();
129+
return confirmation;
130+
}
124131
}));
125132
server.open("localhost", 8887, new ServerEvents() {
126133
@Override
@@ -271,4 +278,8 @@ public boolean hasHandledStartTransactionRequest() {
271278
public boolean hasHandledStatusNotificationRequest() {
272279
return receivedRequest instanceof StatusNotificationRequest;
273280
}
281+
282+
public boolean hasHandledStopTransactionRequest() {
283+
return receivedRequest instanceof StopTransactionRequest;
284+
}
274285
}

ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/StopTransaction.groovy renamed to ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/StopTransactionSpec.groovy

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package eu.chargetime.ocpp.test.core
22

3+
import eu.chargetime.ocpp.test.FakeCentralSystem
34
import eu.chargetime.ocpp.test.FakeChargePoint
4-
import eu.chargetime.ocpp.test.OldFakeCentralSystem
55
import spock.lang.Shared
66
import spock.lang.Specification
77
import spock.util.concurrent.PollingConditions
88

9-
class StopTransaction extends Specification {
9+
class StopTransactionSpec extends Specification {
1010
@Shared
11-
OldFakeCentralSystem centralSystem = OldFakeCentralSystem.getInstance();
11+
FakeCentralSystem centralSystem = FakeCentralSystem.getInstance();
1212
@Shared
1313
FakeChargePoint chargePoint = new FakeChargePoint();
1414

@@ -32,12 +32,9 @@ class StopTransaction extends Specification {
3232

3333
then:
3434
conditions.eventually {
35-
assert centralSystem.hasReceivedStopTransactionRequest();
35+
assert centralSystem.hasHandledStopTransactionRequest();
3636
}
3737

38-
when:
39-
centralSystem.sendStopTransactionConfirmation();
40-
4138
then:
4239
conditions.eventually {
4340
assert chargePoint.hasReceivedStopTransactionConfirmation();

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerCoreEventHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public interface ServerCoreEventHandler {
3333
HeartbeatConfirmation handleHeartbeatRequest(int sessionIndex, HeartbeatRequest request);
3434
MeterValuesConfirmation handleMeterValuesRequest(int sessionIndex, MeterValuesRequest request);
3535
StartTransactionConfirmation handleStartTransactionRequest(int sessionIndex, StartTransactionRequest request);
36-
3736
StatusNotificationConfirmation handleStatusNotificationRequest(int sessionIndex, StatusNotificationRequest request);
37+
38+
StopTransactionConfirmation handleStopTransactionRequest(int sessionIndex, StopTransactionRequest request);
3839
}

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerCoreProfile.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public ServerCoreProfile(ServerCoreEventHandler handler) {
5454
features.add(new ResetFeature(this));
5555
features.add(new StartTransactionFeature(this));
5656
features.add(new StatusNotificationFeature(this));
57+
features.add(new StopTransactionFeature(this));
5758
}
5859

5960
@Override
@@ -79,6 +80,8 @@ public Confirmation handleRequest(int sessionIndex, Request request) {
7980
result = handler.handleStartTransactionRequest(sessionIndex, (StartTransactionRequest) request);
8081
} else if (request instanceof StatusNotificationRequest) {
8182
result = handler.handleStatusNotificationRequest(sessionIndex, (StatusNotificationRequest) request);
83+
} else if (request instanceof StopTransactionRequest) {
84+
result = handler.handleStopTransactionRequest(sessionIndex, (StopTransactionRequest) request);
8285
}
8386

8487
return result;

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerCoreProfileTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,28 @@ public void handleRequest_aStatusNotificationRequest_callsHandleStatusNotificati
268268
verify(handler, times(1)).handleStatusNotificationRequest(eq(sessionId), eq(request));
269269
}
270270

271+
@Test
272+
public void getFeatureList_containsStopTransactionFeature() {
273+
// When
274+
Feature[] features = core.getFeatureList();
275+
276+
// Then
277+
assertThat(findFeature(features, "StopTransaction"), is(instanceOf(StopTransactionFeature.class)));
278+
}
279+
280+
@Test
281+
public void handleRequest_aStopTransactionRequest_callsHandleStopTransactionRequest() {
282+
// Given
283+
StopTransactionRequest request = new StopTransactionRequest();
284+
int sessionId = 42;
285+
286+
// When
287+
core.handleRequest(sessionId, request);
288+
289+
// Then
290+
verify(handler, times(1)).handleStopTransactionRequest(eq(sessionId), eq(request));
291+
}
292+
271293
private Feature findFeature(Feature[] features, String action) {
272294
Feature output = null;
273295
for (Feature feature : features) {

0 commit comments

Comments
 (0)