Skip to content

Commit ff33ea6

Browse files
committed
Added GetDiagnostics feature (including the profile).
1 parent 309a905 commit ff33ea6

19 files changed

+856
-58
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package eu.chargetime.ocpp.test;
22

33
import eu.chargetime.ocpp.*;
4-
import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler;
5-
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile;
6-
import eu.chargetime.ocpp.feature.profile.ServerRemoteTriggerProfile;
7-
import eu.chargetime.ocpp.feature.profile.ServerSmartChargingProfile;
4+
import eu.chargetime.ocpp.feature.profile.*;
85
import eu.chargetime.ocpp.model.Confirmation;
96
import eu.chargetime.ocpp.model.Request;
107
import eu.chargetime.ocpp.model.core.*;
8+
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation;
9+
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
1110
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
1211
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequestType;
1312

@@ -184,6 +183,8 @@ public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionInde
184183

185184
ServerRemoteTriggerProfile remoteTriggerProfile = new ServerRemoteTriggerProfile();
186185

186+
ServerFirmwareManagementProfile firmwareManagementProfile = new ServerFirmwareManagementProfile();
187+
187188
int port = 0;
188189
switch (type) {
189190
case JSON:
@@ -198,6 +199,7 @@ public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionInde
198199

199200
server.addFeatureProfile(smartChargingProfile);
200201
server.addFeatureProfile(remoteTriggerProfile);
202+
server.addFeatureProfile(firmwareManagementProfile);
201203

202204
server.open("localhost", port, new ServerEvents() {
203205
@Override
@@ -217,10 +219,6 @@ public void lostSession(UUID identity) {
217219
});
218220
}
219221

220-
public boolean hasReceivedGetDiagnosticsConfirmation() {
221-
return false;
222-
}
223-
224222
public boolean hasHandledAuthorizeRequest() {
225223
return receivedRequest instanceof AuthorizeRequest;
226224
}
@@ -247,6 +245,10 @@ public void sendChangeAvailabilityRequest(int connectorId, AvailabilityType type
247245

248246
}
249247

248+
public boolean hasReceivedGetDiagnosticsConfirmation() {
249+
return receivedConfirmation instanceof GetDiagnosticsConfirmation;
250+
}
251+
250252
public boolean hasReceivedChangeAvailabilityConfirmation(String status) {
251253
boolean result = receivedConfirmation instanceof ChangeAvailabilityConfirmation;
252254
if (result)
@@ -341,6 +343,12 @@ public void sendResetRequest(ResetType type) throws Exception {
341343
server.send(currentSessionIndex, request).whenComplete((confirmation, throwable) -> receivedConfirmation = confirmation);
342344
}
343345

346+
public void sendGetDiagnosticsRequest(String location) throws Exception {
347+
GetDiagnosticsRequest request = new GetDiagnosticsRequest();
348+
request.setLocation(location);
349+
server.send(currentSessionIndex, request).whenComplete((confirmation, throwable) -> receivedConfirmation = confirmation);
350+
}
351+
344352
public boolean hasReceivedResetConfirmation(String status) {
345353
boolean result = receivedConfirmation instanceof ResetConfirmation;
346354
if (result)

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import eu.chargetime.ocpp.model.Confirmation;
66
import eu.chargetime.ocpp.model.Request;
77
import eu.chargetime.ocpp.model.core.*;
8+
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation;
9+
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
810
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageConfirmation;
911
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
1012
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageStatus;
@@ -50,6 +52,7 @@ public class FakeChargePoint
5052
private final ClientCoreProfile core;
5153
private final ClientSmartChargingProfile smartCharging;
5254
private final ClientRemoteTriggerProfile remoteTrigger;
55+
private final ClientFirmwareManagementProfile firmware;
5356
private Throwable receivedException;
5457
private String url;
5558

@@ -140,6 +143,14 @@ public TriggerMessageConfirmation handleTriggerMessageRequest(TriggerMessageRequ
140143
}
141144
});
142145

146+
firmware = new ClientFirmwareManagementProfile(new ClientFirmwareManagementEventHandler() {
147+
@Override
148+
public GetDiagnosticsConfirmation handleGetDiagnosticsRequest(GetDiagnosticsRequest request) {
149+
receivedRequest = request;
150+
return new GetDiagnosticsConfirmation();
151+
}
152+
});
153+
143154
switch (type) {
144155
case JSON:
145156
client = new JSONClient(core, "test");
@@ -153,6 +164,7 @@ public TriggerMessageConfirmation handleTriggerMessageRequest(TriggerMessageRequ
153164

154165
client.addFeatureProfile(smartCharging);
155166
client.addFeatureProfile(remoteTrigger);
167+
client.addFeatureProfile(firmware);
156168
}
157169

158170
public void connect() {
@@ -290,6 +302,10 @@ public void disconnect() {
290302
client.disconnect();
291303
}
292304

305+
public boolean hasHandledGetDiagnosticsRequest() {
306+
return receivedRequest instanceof GetDiagnosticsRequest;
307+
}
308+
293309
public boolean hasHandledChangeAvailabilityRequest() {
294310
return receivedRequest instanceof ChangeAvailabilityRequest;
295311
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package eu.chargetime.ocpp.test.firmware.json
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+
8+
/*
9+
ChargeTime.eu - Java-OCA-OCPP
10+
11+
MIT License
12+
13+
Copyright (C) 2016 Thomas Volden <[email protected]>
14+
15+
Permission is hereby granted, free of charge, to any person obtaining a copy
16+
of this software and associated documentation files (the "Software"), to deal
17+
in the Software without restriction, including without limitation the rights
18+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+
copies of the Software, and to permit persons to whom the Software is
20+
furnished to do so, subject to the following conditions:
21+
22+
The above copyright notice and this permission notice shall be included in all
23+
copies or substantial portions of the Software.
24+
25+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+
SOFTWARE.
32+
*/
33+
import spock.util.concurrent.PollingConditions
34+
35+
class JSONGetDiagnosticsSpec extends Specification {
36+
@Shared
37+
FakeCentralSystem centralSystem = FakeCentralSystem.getInstance()
38+
@Shared
39+
FakeChargePoint chargePoint = new FakeChargePoint()
40+
41+
def setupSpec() {
42+
// When a Central System is running
43+
centralSystem.started()
44+
}
45+
46+
def setup() {
47+
chargePoint.connect()
48+
}
49+
50+
def cleanup() {
51+
chargePoint.disconnect()
52+
}
53+
54+
def "Central System sends a GetDiagnostics request and receives a response"() {
55+
def conditions = new PollingConditions(timeout: 1)
56+
given:
57+
conditions.eventually {
58+
assert centralSystem.connected()
59+
}
60+
61+
when:
62+
centralSystem.sendGetDiagnosticsRequest("/")
63+
64+
then:
65+
conditions.eventually {
66+
assert chargePoint.hasHandledGetDiagnosticsRequest()
67+
assert centralSystem.hasReceivedGetDiagnosticsConfirmation()
68+
}
69+
}
70+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package eu.chargetime.ocpp.feature;
2+
/*
3+
ChargeTime.eu - Java-OCA-OCPP
4+
5+
MIT License
6+
7+
Copyright (C) 2016 Thomas Volden <[email protected]>
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
*/
27+
28+
import eu.chargetime.ocpp.feature.profile.Profile;
29+
import eu.chargetime.ocpp.model.Confirmation;
30+
import eu.chargetime.ocpp.model.Request;
31+
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation;
32+
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
33+
34+
public class GetDiagnosticsFeature extends Feature {
35+
36+
/**
37+
* Creates link back to the {@link Profile}.
38+
*
39+
* @param ownerProfile the {@link Profile} that owns the function.
40+
*/
41+
public GetDiagnosticsFeature(Profile ownerProfile) {
42+
super(ownerProfile);
43+
}
44+
45+
@Override
46+
public Class<? extends Request> getRequestType() {
47+
return GetDiagnosticsRequest.class;
48+
}
49+
50+
@Override
51+
public Class<? extends Confirmation> getConfirmationType() {
52+
return GetDiagnosticsConfirmation.class;
53+
}
54+
55+
@Override
56+
public String getAction() {
57+
return "GetDiagnostics";
58+
}
59+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package eu.chargetime.ocpp.feature.profile;
2+
/*
3+
ChargeTime.eu - Java-OCA-OCPP
4+
5+
MIT License
6+
7+
Copyright (C) 2016 Thomas Volden <[email protected]>
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
*/
27+
28+
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation;
29+
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
30+
31+
public interface ClientFirmwareManagementEventHandler {
32+
GetDiagnosticsConfirmation handleGetDiagnosticsRequest(GetDiagnosticsRequest request);
33+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package eu.chargetime.ocpp.feature.profile;/*
2+
ChargeTime.eu - Java-OCA-OCPP
3+
4+
MIT License
5+
6+
Copyright (C) 2016 Thomas Volden <[email protected]>
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in all
16+
copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
SOFTWARE.
25+
*/
26+
27+
import eu.chargetime.ocpp.feature.Feature;
28+
import eu.chargetime.ocpp.feature.GetDiagnosticsFeature;
29+
import eu.chargetime.ocpp.model.Confirmation;
30+
import eu.chargetime.ocpp.model.Request;
31+
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
32+
33+
import java.util.HashSet;
34+
import java.util.UUID;
35+
36+
public class ClientFirmwareManagementProfile implements Profile {
37+
38+
private HashSet<Feature> features;
39+
private ClientFirmwareManagementEventHandler eventHandler;
40+
41+
public ClientFirmwareManagementProfile(ClientFirmwareManagementEventHandler eventHandler) {
42+
this.eventHandler = eventHandler;
43+
features = new HashSet<>();
44+
features.add(new GetDiagnosticsFeature(this));
45+
}
46+
47+
@Override
48+
public Feature[] getFeatureList() {
49+
return features.toArray(new Feature[0]);
50+
}
51+
52+
@Override
53+
public Confirmation handleRequest(UUID sessionIndex, Request request) {
54+
Confirmation result = null;
55+
56+
if (request instanceof GetDiagnosticsRequest) {
57+
result = eventHandler.handleGetDiagnosticsRequest((GetDiagnosticsRequest) request);
58+
}
59+
60+
return result;
61+
}
62+
}

0 commit comments

Comments
 (0)