Skip to content

Commit b1235c7

Browse files
committed
Added RemoteStopTransaction feature to core profile.
1 parent 11ba5d4 commit b1235c7

File tree

15 files changed

+443
-21
lines changed

15 files changed

+443
-21
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ public void hasReceivedRemoteStartTransactionConfirmation(String status) {
193193
assertThat(getCallResultPayload().getString("status"), equalTo(status));
194194
}
195195

196+
public void hasReceivedRemoteStopTransactionConfirmation(String status) {
197+
assertThat(getUniqueId(), equalTo("RemoteStopTransaction"));
198+
assertThat(getCallResultPayload().getString("status"), equalTo(status));
199+
}
200+
196201
public void sendGetConfigurationRequest(String... keys) {
197202
String payload = "\"key\":%s";
198203
sendRequest("GetConfiguration", String.format(payload, formatList(keys)));
@@ -224,6 +229,11 @@ public void sendRemoteStartTransactionRequest(String idTag) {
224229
sendRequest("RemoteStartTransaction", String.format(payload, idTag));
225230
}
226231

232+
public void sendRemoteStopTransactionRequest(int transactionId) {
233+
String payload = "\"transactionId\": %d";
234+
sendRequest("RemoteStopTransaction", String.format(payload, transactionId));
235+
}
236+
227237
public enum AvailabilityType {
228238
Inoperative, Operative
229239
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ public RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest(Re
8080
receivedRequest = request;
8181
return new RemoteStartTransactionConfirmation("Accepted");
8282
}
83+
84+
@Override
85+
public RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest(RemoteStopTransactionRequest request) {
86+
receivedRequest = request;
87+
return new RemoteStopTransactionConfirmation("Accepted");
88+
}
8389
});
8490
client = new Client(new Session(new JSONCommunicator(new WebSocketTransmitter()), new Queue()));
8591
client.addFeatureProfile(core);
@@ -191,4 +197,8 @@ public void hasHandledDataTransferRequest() {
191197
public void hasHandledRemoteStartTransactionRequest() {
192198
confirmRequest(RemoteStartTransactionRequest.class);
193199
}
200+
201+
public void hasHandledRemoteStopTransactionRequest() {
202+
confirmRequest(RemoteStopTransactionRequest.class);
203+
}
194204
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package core_features
2+
3+
import eu.chargetime.ocpp.test.FakeCentralSystem
4+
import eu.chargetime.ocpp.test.FakeChargePoint
5+
import spock.lang.Shared
6+
import spock.lang.Specification
7+
import spock.util.concurrent.PollingConditions
8+
9+
class RemoteStopTransaction extends Specification {
10+
@Shared
11+
FakeCentralSystem centralSystem = FakeCentralSystem.getInstance();
12+
@Shared
13+
FakeChargePoint chargePoint = new FakeChargePoint();
14+
15+
def setupSpec() {
16+
// When a Central System is running
17+
centralSystem.started();
18+
}
19+
20+
def setup() {
21+
chargePoint.connect();
22+
}
23+
24+
def cleanup() {
25+
chargePoint.disconnect();
26+
}
27+
28+
def "Central System sends a RemoteStopTransaction request and receives a response"() {
29+
def conditions = new PollingConditions(timeout: 1)
30+
when:
31+
centralSystem.sendRemoteStopTransactionRequest(0);
32+
33+
then:
34+
conditions.eventually {
35+
chargePoint.hasHandledRemoteStopTransactionRequest();
36+
centralSystem.hasReceivedRemoteStopTransactionConfirmation("Accepted");
37+
}
38+
}
39+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package eu.chargetime.ocpp.feature;
2+
3+
import eu.chargetime.ocpp.feature.profile.Profile;
4+
import eu.chargetime.ocpp.model.Confirmation;
5+
import eu.chargetime.ocpp.model.RemoteStopTransactionConfirmation;
6+
import eu.chargetime.ocpp.model.RemoteStopTransactionRequest;
7+
import eu.chargetime.ocpp.model.Request;
8+
9+
/**
10+
* ChargeTime.eu - Java-OCA-OCPP
11+
* <p>
12+
* MIT License
13+
* <p>
14+
* Copyright (C) 2016 Thomas Volden <[email protected]>
15+
* <p>
16+
* Permission is hereby granted, free of charge, to any person obtaining a copy
17+
* of this software and associated documentation files (the "Software"), to deal
18+
* in the Software without restriction, including without limitation the rights
19+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20+
* copies of the Software, and to permit persons to whom the Software is
21+
* furnished to do so, subject to the following conditions:
22+
* <p>
23+
* The above copyright notice and this permission notice shall be included in all
24+
* copies or substantial portions of the Software.
25+
* <p>
26+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32+
* SOFTWARE.
33+
*/
34+
public class RemoteStopTransactionFeature extends Feature {
35+
public RemoteStopTransactionFeature(Profile ownerProfile) {
36+
super(ownerProfile);
37+
}
38+
39+
@Override
40+
public Class<? extends Request> getRequestType() {
41+
return RemoteStopTransactionRequest.class;
42+
}
43+
44+
@Override
45+
public Class<? extends Confirmation> getConfirmationType() {
46+
return RemoteStopTransactionConfirmation.class;
47+
}
48+
49+
@Override
50+
public String getAction() {
51+
return "RemoteStopTransaction";
52+
}
53+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public interface ClientCoreEventHandler {
3434
ChangeConfigurationConfirmation handleChangeConfigurationRequest(ChangeConfigurationRequest request);
3535
ClearCacheConfirmation handleClearCacheRequest(ClearCacheRequest request);
3636
DataTransferConfirmation handleDataTransferRequest(DataTransferRequest request);
37-
3837
RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest(RemoteStartTransactionRequest request);
38+
39+
RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest(RemoteStopTransactionRequest request);
3940
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public CoreProfile(ClientCoreEventHandler handler) {
5252
features.add(new HeartbeatFeature(this));
5353
features.add(new MeterValuesFeature(this));
5454
features.add(new RemoteStartTransactionFeature(this));
55+
features.add(new RemoteStopTransactionFeature(this));
5556
}
5657

5758
public AuthorizeRequest createAuthorizeRequest(String idToken) throws PropertyConstraintException {
@@ -115,6 +116,8 @@ else if (request instanceof DataTransferRequest) {
115116
result = eventHandler.handleDataTransferRequest((DataTransferRequest)request);
116117
} else if (request instanceof RemoteStartTransactionRequest) {
117118
result = eventHandler.handleRemoteStartTransactionRequest((RemoteStartTransactionRequest) request);
119+
} else if (request instanceof RemoteStopTransactionRequest) {
120+
result = eventHandler.handleRemoteStopTransactionRequest((RemoteStopTransactionRequest) request);
118121
}
119122

120123
return result;

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/ChargingProfile.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99

1010
/**
1111
* ChargeTime.eu - Java-OCA-OCPP
12-
* <p>
12+
*
1313
* MIT License
14-
* <p>
14+
*
1515
* Copyright (C) 2016 Thomas Volden <[email protected]>
16-
* <p>
16+
*
1717
* Permission is hereby granted, free of charge, to any person obtaining a copy
1818
* of this software and associated documentation files (the "Software"), to deal
1919
* in the Software without restriction, including without limitation the rights
2020
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2121
* copies of the Software, and to permit persons to whom the Software is
2222
* furnished to do so, subject to the following conditions:
23-
* <p>
23+
*
2424
* The above copyright notice and this permission notice shall be included in all
2525
* copies or substantial portions of the Software.
26-
* <p>
26+
*
2727
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2828
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2929
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/RemoteStartTransactionConfirmation.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55

66
/**
77
* ChargeTime.eu - Java-OCA-OCPP
8-
* <p>
8+
*
99
* MIT License
10-
* <p>
10+
*
1111
* Copyright (C) 2016 Thomas Volden <[email protected]>
12-
* <p>
12+
*
1313
* Permission is hereby granted, free of charge, to any person obtaining a copy
1414
* of this software and associated documentation files (the "Software"), to deal
1515
* in the Software without restriction, including without limitation the rights
1616
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1717
* copies of the Software, and to permit persons to whom the Software is
1818
* furnished to do so, subject to the following conditions:
19-
* <p>
19+
*
2020
* The above copyright notice and this permission notice shall be included in all
2121
* copies or substantial portions of the Software.
22-
* <p>
22+
*
2323
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2424
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2525
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package eu.chargetime.ocpp.model;
2+
3+
import eu.chargetime.ocpp.PropertyConstraintException;
4+
import eu.chargetime.ocpp.utilities.ModelUtil;
5+
6+
/**
7+
* ChargeTime.eu - Java-OCA-OCPP
8+
* <p>
9+
* MIT License
10+
* <p>
11+
* Copyright (C) 2016 Thomas Volden <[email protected]>
12+
* <p>
13+
* Permission is hereby granted, free of charge, to any person obtaining a copy
14+
* of this software and associated documentation files (the "Software"), to deal
15+
* in the Software without restriction, including without limitation the rights
16+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17+
* copies of the Software, and to permit persons to whom the Software is
18+
* furnished to do so, subject to the following conditions:
19+
* <p>
20+
* The above copyright notice and this permission notice shall be included in all
21+
* copies or substantial portions of the Software.
22+
* <p>
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29+
* SOFTWARE.
30+
*/
31+
public class RemoteStopTransactionConfirmation implements Confirmation {
32+
private String status;
33+
34+
public RemoteStopTransactionConfirmation() {
35+
}
36+
37+
public RemoteStopTransactionConfirmation(String status) {
38+
this.status = status;
39+
}
40+
41+
@Override
42+
public boolean validate() {
43+
return isValidStatus(status);
44+
}
45+
46+
public void setStatus(String status) throws PropertyConstraintException {
47+
if (!isValidStatus(status))
48+
throw new PropertyConstraintException("status", status);
49+
50+
this.status = status;
51+
}
52+
53+
private boolean isValidStatus(String status) {
54+
return ModelUtil.isAmong(status, "Accepted", "Rejected");
55+
}
56+
57+
public String getStatus() {
58+
return status;
59+
}
60+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package eu.chargetime.ocpp.model;
2+
3+
/**
4+
* ChargeTime.eu - Java-OCA-OCPP
5+
* <p>
6+
* MIT License
7+
* <p>
8+
* Copyright (C) 2016 Thomas Volden <[email protected]>
9+
* <p>
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
* <p>
17+
* The above copyright notice and this permission notice shall be included in all
18+
* copies or substantial portions of the Software.
19+
* <p>
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* SOFTWARE.
27+
*/
28+
public class RemoteStopTransactionRequest implements Request {
29+
private Integer transactionId;
30+
31+
@Override
32+
public boolean validate() {
33+
return transactionId != null;
34+
}
35+
36+
public void setTransactionId(Integer transactionId) {
37+
this.transactionId = transactionId;
38+
}
39+
40+
public Integer getTransactionId() {
41+
return transactionId;
42+
}
43+
}

0 commit comments

Comments
 (0)