Skip to content

Commit 67586ac

Browse files
committed
Added UnlockConnector feature to core profile.
1 parent be45b68 commit 67586ac

File tree

13 files changed

+473
-3
lines changed

13 files changed

+473
-3
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
@@ -215,6 +215,11 @@ public void hasReceivedResetConfirmation(String status) {
215215
assertThat(getCallResultPayload().getString("status"), equalTo(status));
216216
}
217217

218+
public void hasReceivedUnlockConnectorConfirmation(String status) {
219+
assertThat(getUniqueId(), equalTo("UnlockConnector"));
220+
assertThat(getCallResultPayload().getString("status"), equalTo(status));
221+
}
222+
218223
public void sendGetConfigurationRequest(String... keys) {
219224
String payload = "\"key\":%s";
220225
sendRequest("GetConfiguration", String.format(payload, formatList(keys)));
@@ -256,6 +261,11 @@ public void sendResetRequest(String type) {
256261
sendRequest("Reset", String.format(payload, type));
257262
}
258263

264+
public void sendUnlockConnectorRequest(int connectorId) {
265+
String payload = "\"connectorId\": %d";
266+
sendRequest("UnlockConnector", String.format(payload, connectorId));
267+
}
268+
259269
public enum AvailabilityType {
260270
Inoperative, Operative
261271
}

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
@@ -92,6 +92,12 @@ public ResetConfirmation handleResetRequest(ResetRequest request) {
9292
receivedRequest = request;
9393
return new ResetConfirmation("Accepted");
9494
}
95+
96+
@Override
97+
public UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorRequest request) {
98+
receivedRequest = request;
99+
return new UnlockConnectorConfirmation("Unlocked");
100+
}
95101
});
96102
client = new Client(new Session(new JSONCommunicator(new WebSocketTransmitter()), new Queue()));
97103
client.addFeatureProfile(core);
@@ -250,4 +256,8 @@ public void hasHandledRemoteStopTransactionRequest() {
250256
public void hasHandledResetRequest() {
251257
confirmRequest(ResetRequest.class);
252258
}
259+
260+
public void hasHandledUnlockConnectorRequest() {
261+
confirmRequest(UnlockConnectorRequest.class);
262+
}
253263
}
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 UnlockConnector 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 UnlockConnector request and receives a response"() {
29+
def conditions = new PollingConditions(timeout: 1)
30+
when:
31+
centralSystem.sendUnlockConnectorRequest(1);
32+
33+
then:
34+
conditions.eventually {
35+
chargePoint.hasHandledUnlockConnectorRequest();
36+
centralSystem.hasReceivedUnlockConnectorConfirmation("Unlocked");
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.UnlockConnectorConfirmation;
7+
import eu.chargetime.ocpp.model.UnlockConnectorRequest;
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 UnlockConnectorFeature extends Feature {
35+
public UnlockConnectorFeature(Profile ownerProfile) {
36+
super(ownerProfile);
37+
}
38+
39+
@Override
40+
public Class<? extends Request> getRequestType() {
41+
return UnlockConnectorRequest.class;
42+
}
43+
44+
@Override
45+
public Class<? extends Confirmation> getConfirmationType() {
46+
return UnlockConnectorConfirmation.class;
47+
}
48+
49+
@Override
50+
public String getAction() {
51+
return "UnlockConnector";
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
@@ -36,6 +36,7 @@ public interface ClientCoreEventHandler {
3636
DataTransferConfirmation handleDataTransferRequest(DataTransferRequest request);
3737
RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest(RemoteStartTransactionRequest request);
3838
RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest(RemoteStopTransactionRequest request);
39-
4039
ResetConfirmation handleResetRequest(ResetRequest request);
40+
41+
UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorRequest request);
4142
}

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
@@ -57,6 +57,7 @@ public CoreProfile(ClientCoreEventHandler handler) {
5757
features.add(new StartTransactionFeature(this));
5858
features.add(new StatusNotificationFeature(this));
5959
features.add(new StopTransactionFeature(this));
60+
features.add(new UnlockConnectorFeature(this));
6061
}
6162

6263
public AuthorizeRequest createAuthorizeRequest(String idToken) throws PropertyConstraintException {
@@ -151,6 +152,8 @@ else if (request instanceof DataTransferRequest) {
151152
result = eventHandler.handleRemoteStopTransactionRequest((RemoteStopTransactionRequest) request);
152153
} else if (request instanceof ResetRequest) {
153154
result = eventHandler.handleResetRequest((ResetRequest) request);
155+
} else if (request instanceof UnlockConnectorRequest) {
156+
result = eventHandler.handleUnlockConnectorRequest((UnlockConnectorRequest) request);
154157
}
155158

156159
return result;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public RemoteStopTransactionConfirmation() {
3535
}
3636

3737
public RemoteStopTransactionConfirmation(String status) {
38-
this.status = status;
38+
try {
39+
setStatus(status);
40+
} catch (PropertyConstraintException e) {
41+
e.printStackTrace();
42+
}
3943
}
4044

4145
@Override

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public ResetConfirmation() {
3535
}
3636

3737
public ResetConfirmation(String status) {
38-
this.status = status;
38+
try {
39+
setStatus(status);
40+
} catch (PropertyConstraintException e) {
41+
e.printStackTrace();
42+
}
3943
}
4044

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

0 commit comments

Comments
 (0)