Skip to content

Commit e33c28a

Browse files
committed
Changed enum values to actual enums. There were some enums that couldn't be easily converted.
1 parent 9f16447 commit e33c28a

File tree

72 files changed

+1009
-1566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1009
-1566
lines changed

ocpp-v1_6-test/src/it/groovy/eu/chargetime/ocpp/test/core/BootNotification.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package eu.chargetime.ocpp.test.core
22

3+
import eu.chargetime.ocpp.model.RegistrationStatus
34
import eu.chargetime.ocpp.test.FakeCentralSystem
45
import eu.chargetime.ocpp.test.FakeChargePoint
56
import spock.lang.Shared
@@ -35,11 +36,11 @@ class BootNotification extends Specification
3536
}
3637

3738
when:
38-
centralSystem.sendBootConfirmation(FakeCentralSystem.RegistrationStatus.Accepted);
39+
centralSystem.sendBootConfirmation(RegistrationStatus.Accepted);
3940

4041
then:
4142
conditions.eventually {
42-
chargePoint.hasReceivedBootConfirmation("Accepted");
43+
chargePoint.hasReceivedBootConfirmation(RegistrationStatus.Accepted);
4344
}
4445
}
4546
}

ocpp-v1_6-test/src/it/groovy/eu/chargetime/ocpp/test/core/ChangeAvailability.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package eu.chargetime.ocpp.test.core
22

3+
import eu.chargetime.ocpp.model.AvailabilityType
34
import eu.chargetime.ocpp.test.FakeCentralSystem
45
import eu.chargetime.ocpp.test.FakeChargePoint
56
import spock.lang.Shared
@@ -27,7 +28,7 @@ class ChangeAvailability extends Specification
2728
def "Central System sends a ChangeAvailability request and receives a response"() {
2829
def conditions = new PollingConditions(timeout: 1)
2930
when:
30-
centralSystem.sendChangeAvailabilityRequest(0, FakeCentralSystem.AvailabilityType.Inoperative);
31+
centralSystem.sendChangeAvailabilityRequest(0, AvailabilityType.Inoperative);
3132

3233
then:
3334
conditions.eventually {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package eu.chargetime.ocpp.test;
22

3+
import eu.chargetime.ocpp.model.AvailabilityType;
4+
import eu.chargetime.ocpp.model.RegistrationStatus;
35
import org.java_websocket.WebSocket;
46
import org.java_websocket.handshake.ClientHandshake;
57
import org.java_websocket.server.WebSocketServer;
@@ -266,18 +268,12 @@ public void sendUnlockConnectorRequest(int connectorId) {
266268
sendRequest("UnlockConnector", String.format(payload, connectorId));
267269
}
268270

269-
public enum AvailabilityType {
270-
Inoperative, Operative
271-
}
272271
public void sendChangeAvailabilityRequest(int connectorId, AvailabilityType type)
273272
{
274273
String payload = "\"connectorId\":%d,\"type\":\"%s\"";
275274
sendRequest("ChangeAvailability", String.format(payload, connectorId, type));
276275
}
277276

278-
public enum RegistrationStatus {
279-
Accepted, Pending, Rejected
280-
}
281277
public void sendHeartbeatConfirmation() {
282278
String payload = "\"currentTime\": \"%s\"";
283279
sendConfirmation(String.format(payload, now()));

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public FakeChargePoint() {
4848
@Override
4949
public ChangeAvailabilityConfirmation handleChangeAvailabilityRequest(ChangeAvailabilityRequest request) {
5050
receivedRequest = request;
51-
return new ChangeAvailabilityConfirmation("Accepted");
51+
return new ChangeAvailabilityConfirmation(AvailabilityStatus.Accepted);
5252
}
5353

5454
@Override
@@ -78,25 +78,25 @@ public DataTransferConfirmation handleDataTransferRequest(DataTransferRequest re
7878
@Override
7979
public RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest(RemoteStartTransactionRequest request) {
8080
receivedRequest = request;
81-
return new RemoteStartTransactionConfirmation("Accepted");
81+
return new RemoteStartTransactionConfirmation(RemoteStartStopStatus.Accepted);
8282
}
8383

8484
@Override
8585
public RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest(RemoteStopTransactionRequest request) {
8686
receivedRequest = request;
87-
return new RemoteStopTransactionConfirmation("Accepted");
87+
return new RemoteStopTransactionConfirmation(RemoteStartStopStatus.Accepted);
8888
}
8989

9090
@Override
9191
public ResetConfirmation handleResetRequest(ResetRequest request) {
9292
receivedRequest = request;
93-
return new ResetConfirmation("Accepted");
93+
return new ResetConfirmation(ResetStatus.Accepted);
9494
}
9595

9696
@Override
9797
public UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorRequest request) {
9898
receivedRequest = request;
99-
return new UnlockConnectorConfirmation("Unlocked");
99+
return new UnlockConnectorConfirmation(UnlockStatus.Unlocked);
100100
}
101101
});
102102
client = new Client(new Session(new JSONCommunicator(new WebSocketTransmitter()), new Queue()));
@@ -167,7 +167,7 @@ public void sendDataTransferRequest(String vendorId, String messageId, String da
167167

168168
public void sendStatusNotificationRequest() {
169169
try {
170-
StatusNotificationRequest request = core.createStatusNotificationRequest(42, "NoError", "Available");
170+
StatusNotificationRequest request = core.createStatusNotificationRequest(42, ChargePointErrorCode.NoError, ChargePointStatus.Available);
171171
send(request);
172172
} catch (Exception ex) {
173173
ex.printStackTrace();
@@ -182,9 +182,9 @@ private void send(Request request) {
182182
}
183183
}
184184

185-
public void hasReceivedBootConfirmation(String status) {
185+
public void hasReceivedBootConfirmation(RegistrationStatus status) {
186186
assertThat(receivedConfirmation, instanceOf(BootNotificationConfirmation.class));
187-
assertThat(((BootNotificationConfirmation)receivedConfirmation).getStatus(), is(status));
187+
assertThat(((BootNotificationConfirmation) receivedConfirmation).objStatus(), is(status));
188188
}
189189

190190
public void hasReceivedAuthorizeConfirmation(String status) {

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONCommunicator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ else if (type == Double.class || genericType == Double.TYPE) {
145145
}
146146
else if (type == Boolean.class || genericType == Boolean.TYPE) {
147147
output = json.getBoolean(key);
148+
} else if (type.isEnum()) {
149+
output = Enum.valueOf((Class<Enum>) type, json.getString(key));
148150
}
149151
else {
150152
output = parseJSON(json.optJSONObject(key), type);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public StartTransactionRequest createStartTransactionRequest(Integer connectorId
107107
return request;
108108
}
109109

110-
public StatusNotificationRequest createStatusNotificationRequest(Integer connectorId, String errorCode, String status) throws PropertyConstraintException {
110+
public StatusNotificationRequest createStatusNotificationRequest(Integer connectorId, ChargePointErrorCode errorCode, ChargePointStatus status) throws PropertyConstraintException {
111111
StatusNotificationRequest request = new StatusNotificationRequest();
112112
request.setConnectorId(connectorId);
113113
request.setErrorCode(errorCode);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 enum AuthorizationStatus {
29+
Accepted, Blocked, Expired, Invalid, ConcurrentTx
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 enum AvailabilityStatus {
29+
Accepted, Rejected, Scheduled
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 enum AvailabilityType {
29+
Inoperative, Operative
30+
}

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package eu.chargetime.ocpp.model;
22

33
import eu.chargetime.ocpp.PropertyConstraintException;
4-
import eu.chargetime.ocpp.utilities.ModelUtil;
54

65
import java.text.SimpleDateFormat;
76
import java.util.Calendar;
@@ -37,7 +36,7 @@ public class BootNotificationConfirmation implements Confirmation
3736
{
3837
private Calendar currentTime;
3938
private int interval;
40-
private String status;
39+
private RegistrationStatus status;
4140

4241
public String getCurrentTime()
4342
{
@@ -67,26 +66,24 @@ public void setInterval(int interval) throws PropertyConstraintException {
6766
this.interval = interval;
6867
}
6968

70-
public String getStatus()
69+
public RegistrationStatus objStatus()
7170
{
7271
return status;
7372
}
7473

75-
public void setStatus(String status) throws PropertyConstraintException {
76-
if (!isValidStatus(status))
77-
throw new PropertyConstraintException("status", status);
78-
79-
this.status = status;
74+
public String getStatus()
75+
{
76+
return status.toString();
8077
}
8178

82-
private boolean isValidStatus(String status) {
83-
return ModelUtil.isAmong(status, "Accepted", "Pending", "Rejected");
79+
public void setStatus(RegistrationStatus status) throws PropertyConstraintException {
80+
this.status = status;
8481
}
8582

8683
@Override
8784
public boolean validate() {
8885
boolean valid = true;
89-
valid &= isValidStatus(this.status);
86+
valid &= status != null;
9087
valid &= currentTime != null;
9188
valid &= interval > 0;
9289
return valid;

0 commit comments

Comments
 (0)