Skip to content

Commit c0cdd59

Browse files
committed
Added Reset feature to core profile.
1 parent b1235c7 commit c0cdd59

File tree

11 files changed

+463
-1
lines changed

11 files changed

+463
-1
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
@@ -198,6 +198,11 @@ public void hasReceivedRemoteStopTransactionConfirmation(String status) {
198198
assertThat(getCallResultPayload().getString("status"), equalTo(status));
199199
}
200200

201+
public void hasReceivedResetConfirmation(String status) {
202+
assertThat(getUniqueId(), equalTo("Reset"));
203+
assertThat(getCallResultPayload().getString("status"), equalTo(status));
204+
}
205+
201206
public void sendGetConfigurationRequest(String... keys) {
202207
String payload = "\"key\":%s";
203208
sendRequest("GetConfiguration", String.format(payload, formatList(keys)));
@@ -234,6 +239,11 @@ public void sendRemoteStopTransactionRequest(int transactionId) {
234239
sendRequest("RemoteStopTransaction", String.format(payload, transactionId));
235240
}
236241

242+
public void sendResetRequest(String type) {
243+
String payload = "\"type\": \"%s\"";
244+
sendRequest("Reset", String.format(payload, type));
245+
}
246+
237247
public enum AvailabilityType {
238248
Inoperative, Operative
239249
}

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
@@ -86,6 +86,12 @@ public RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest(Remo
8686
receivedRequest = request;
8787
return new RemoteStopTransactionConfirmation("Accepted");
8888
}
89+
90+
@Override
91+
public ResetConfirmation handleResetRequest(ResetRequest request) {
92+
receivedRequest = request;
93+
return new ResetConfirmation("Accepted");
94+
}
8995
});
9096
client = new Client(new Session(new JSONCommunicator(new WebSocketTransmitter()), new Queue()));
9197
client.addFeatureProfile(core);
@@ -201,4 +207,8 @@ public void hasHandledRemoteStartTransactionRequest() {
201207
public void hasHandledRemoteStopTransactionRequest() {
202208
confirmRequest(RemoteStopTransactionRequest.class);
203209
}
210+
211+
public void hasHandledResetRequest() {
212+
confirmRequest(ResetRequest.class);
213+
}
204214
}
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 Reset 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 Reset request and receives a response"() {
29+
def conditions = new PollingConditions(timeout: 1)
30+
when:
31+
centralSystem.sendResetRequest("Soft");
32+
33+
then:
34+
conditions.eventually {
35+
chargePoint.hasHandledResetRequest();
36+
centralSystem.hasReceivedResetConfirmation("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.Request;
6+
import eu.chargetime.ocpp.model.ResetConfirmation;
7+
import eu.chargetime.ocpp.model.ResetRequest;
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 ResetFeature extends Feature {
35+
public ResetFeature(Profile ownerProfile) {
36+
super(ownerProfile);
37+
}
38+
39+
@Override
40+
public Class<? extends Request> getRequestType() {
41+
return ResetRequest.class;
42+
}
43+
44+
@Override
45+
public Class<? extends Confirmation> getConfirmationType() {
46+
return ResetConfirmation.class;
47+
}
48+
49+
@Override
50+
public String getAction() {
51+
return "Reset";
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
@@ -35,6 +35,7 @@ public interface ClientCoreEventHandler {
3535
ClearCacheConfirmation handleClearCacheRequest(ClearCacheRequest request);
3636
DataTransferConfirmation handleDataTransferRequest(DataTransferRequest request);
3737
RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest(RemoteStartTransactionRequest request);
38-
3938
RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest(RemoteStopTransactionRequest request);
39+
40+
ResetConfirmation handleResetRequest(ResetRequest request);
4041
}

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
@@ -53,6 +53,7 @@ public CoreProfile(ClientCoreEventHandler handler) {
5353
features.add(new MeterValuesFeature(this));
5454
features.add(new RemoteStartTransactionFeature(this));
5555
features.add(new RemoteStopTransactionFeature(this));
56+
features.add(new ResetFeature(this));
5657
}
5758

5859
public AuthorizeRequest createAuthorizeRequest(String idToken) throws PropertyConstraintException {
@@ -118,6 +119,8 @@ else if (request instanceof DataTransferRequest) {
118119
result = eventHandler.handleRemoteStartTransactionRequest((RemoteStartTransactionRequest) request);
119120
} else if (request instanceof RemoteStopTransactionRequest) {
120121
result = eventHandler.handleRemoteStopTransactionRequest((RemoteStopTransactionRequest) request);
122+
} else if (request instanceof ResetRequest) {
123+
result = eventHandler.handleResetRequest((ResetRequest) request);
121124
}
122125

123126
return result;
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 ResetConfirmation implements Confirmation {
32+
private String status;
33+
34+
public ResetConfirmation() {
35+
}
36+
37+
public ResetConfirmation(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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 ResetRequest implements Request {
32+
private String type;
33+
34+
@Override
35+
public boolean validate() {
36+
return isValidType(type);
37+
}
38+
39+
public void setType(String type) throws PropertyConstraintException {
40+
if (!isValidType(type))
41+
throw new PropertyConstraintException("type", type);
42+
this.type = type;
43+
}
44+
45+
private boolean isValidType(String type) {
46+
return ModelUtil.isAmong(type, "Hard", "Soft");
47+
}
48+
49+
public String getType() {
50+
return type;
51+
}
52+
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ public void getFeatureList_containsRemoteStopTransactionFeature() {
151151
assertThat(findFeature(features, "RemoteStopTransaction"), is(instanceOf(RemoteStopTransactionFeature.class)));
152152
}
153153

154+
@Test
155+
public void getFeatureList_containsResetFeature() {
156+
// When
157+
Feature[] features = core.getFeatureList();
158+
159+
// Then
160+
assertThat(findFeature(features, "Reset"), is(instanceOf(ResetFeature.class)));
161+
}
162+
154163
@Test
155164
public void handleRequest_aChangeAvailabilityRequest_callsHandleChangeAvailabilityRequest() {
156165
// Given
@@ -187,6 +196,19 @@ public void handleRequest_aRemoteStopTransactionRequest_callsHandleRemoteStopTra
187196
verify(handler, times(1)).handleRemoteStopTransactionRequest(eq(request));
188197
}
189198

199+
@Test
200+
public void handleRequest_aResetRequest_callsHandleResetRequest() {
201+
// Given
202+
ResetRequest request = new ResetRequest();
203+
204+
// When
205+
core.handleRequest(request);
206+
207+
// Then
208+
verify(handler, times(1)).handleResetRequest(eq(request));
209+
}
210+
211+
190212
@Test
191213
public void handleRequest_aChangeAvailabilityRequest_returnsChangeAvailabilityConfirmation() {
192214
// Given

0 commit comments

Comments
 (0)