Skip to content

Commit 75706bb

Browse files
committed
Fixed test, removed dead code. Fixed periodic fail in integration.
1 parent e132d51 commit 75706bb

File tree

4 files changed

+4
-130
lines changed

4 files changed

+4
-130
lines changed

ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/soap/SOAPDataTransferSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class SOAPDataTransferSpec extends Specification {
1919

2020
def setup() {
2121
chargePoint.connect()
22-
chargePoint.sendBootNotification("VendorX", "SingleSocketCharger")
2322
}
2423

2524
def cleanup() {
@@ -29,6 +28,7 @@ class SOAPDataTransferSpec extends Specification {
2928
def "Central System sends a DataTransfer request and receives a response"() {
3029
def conditions = new PollingConditions(timeout: 2)
3130
given:
31+
chargePoint.sendBootNotification("VendorX", "SingleSocketCharger")
3232
conditions.eventually {
3333
assert centralSystem.connected()
3434
}

ocpp-v1_6/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<executions>
9090
<execution>
9191
<id>attach-sources</id>
92+
<phase>verify</phase>
9293
<goals>
9394
<goal>jar-no-fork</goal>
9495
</goals>

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

Lines changed: 1 addition & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected Message parse(Object json) {
144144

145145
if (array.get(INDEX_MESSAGEID).getAsInt() == TYPENUMBER_CALL) {
146146
message = new CallMessage();
147-
((CallMessage) message).setAction(array.get(INDEX_CALL_ACTION).getAsString());
147+
message.setAction(array.get(INDEX_CALL_ACTION).getAsString());
148148
message.setPayload(array.get(INDEX_CALL_PAYLOAD).toString());
149149
} else if (array.get(INDEX_MESSAGEID).getAsInt() == TYPENUMBER_CALLRESULT) {
150150
message = new CallResultMessage();
@@ -160,131 +160,4 @@ protected Message parse(Object json) {
160160
return message;
161161
}
162162

163-
/*
164-
private <T> T parseJSON(JSONObject json, Class<T> type) throws Exception {
165-
T object = type.newInstance();
166-
167-
for (Method method: type.getDeclaredMethods()) {
168-
String key;
169-
if ((key = extractKey(method)) == null)
170-
continue; // Skip non-setter method
171-
172-
if (json.has(key)) {
173-
method.invoke(object, parseValue(key, json, method));
174-
}
175-
}
176-
return object;
177-
}
178-
179-
private Object parseValue(String key, JSONObject json, Method method) throws Exception
180-
{
181-
Class<?> type = setterParameterType(method);
182-
Type genericType = setterGenericParameterType(method);
183-
184-
return parseValue(key, json, type, genericType);
185-
}
186-
187-
private Object parseValue(String key, JSONObject json, Class<?> type, Type genericType) throws Exception {
188-
Object output;
189-
190-
if (type.isArray()) {
191-
output = parseArray(json.getJSONArray(key), type.getComponentType());
192-
}
193-
else if (type == String.class) {
194-
output = json.getString(key);
195-
}
196-
else if (type == Calendar.class) {
197-
output = DatatypeConverter.parseDateTime(json.getString(key));
198-
}
199-
else if (type == Integer.class || genericType == Integer.TYPE) {
200-
output = json.getInt(key);
201-
}
202-
else if (type == Long.class || genericType == Long.TYPE) {
203-
output = json.getLong(key);
204-
}
205-
else if (type == Double.class || genericType == Double.TYPE) {
206-
output = json.getDouble(key);
207-
}
208-
else if (type == Boolean.class || genericType == Boolean.TYPE) {
209-
output = json.getBoolean(key);
210-
} else if (type.isEnum()) {
211-
output = Enum.valueOf((Class<Enum>) type, json.getString(key));
212-
}
213-
else {
214-
output = parseJSON(json.optJSONObject(key), type);
215-
}
216-
217-
return output;
218-
}
219-
220-
private <T> T[] parseArray(JSONArray array, Class<?> type) throws Exception {
221-
T[] output = (T[]) Array.newInstance(type, array.length());
222-
for(int i = 0; i < array.length(); i++)
223-
output[i] = (T)parseArrayItem(array, i, type);
224-
return output;
225-
}
226-
227-
private Object parseArrayItem(JSONArray array, int index, Class<?> type) throws Exception {
228-
Object output;
229-
230-
if (type == String.class) {
231-
output = array.getString(index);
232-
}
233-
else if (type == Calendar.class) {
234-
output = DatatypeConverter.parseDateTime(array.getString(index));
235-
}
236-
else if (type == Integer.class || type == Integer.TYPE) {
237-
output = array.getInt(index);
238-
}
239-
else if (type == Long.class || type == Long.TYPE) {
240-
output = array.getLong(index);
241-
}
242-
else if (type == Double.class || type == Double.TYPE) {
243-
output = array.getDouble(index);
244-
}
245-
else if (type == Boolean.class || type == Boolean.TYPE) {
246-
output = array.getBoolean(index);
247-
}
248-
else {
249-
output = parseJSON(array.optJSONObject(index), type);
250-
}
251-
252-
return output;
253-
}
254-
255-
private Type setterGenericParameterType(Method method) {
256-
Type[] types = method.getGenericParameterTypes();
257-
return types.length > 0 ? types[0]: null;
258-
}
259-
260-
private Class<?> setterParameterType(Method method) {
261-
Class<?>[] types = method.getParameterTypes();
262-
return types.length > 0 ? types[0]: null;
263-
}
264-
265-
private String extractKey(Method method) {
266-
String key = null;
267-
if (methodIsSetter(method)) {
268-
key = method.getName().substring(3);
269-
key = key.substring(0, 1).toLowerCase() + key.substring(1);
270-
}
271-
return key;
272-
}
273-
274-
private boolean methodIsSetter(Method method) {
275-
boolean isSetter;
276-
String methodName = method.getName();
277-
278-
// Setter must take one parameter and no return type
279-
isSetter = method.getParameterCount() == 1;
280-
isSetter &= method.getReturnType().equals(Void.TYPE);
281-
282-
// Name convention must be set<ValueName>
283-
isSetter &= methodName.length() > 3;
284-
isSetter &= methodName.startsWith("set");
285-
isSetter &= Character.isUpperCase(methodName.charAt(3));
286-
287-
return isSetter;
288-
}
289-
*/
290163
}

ocpp-v1_6/src/test/java/eu/chargetime/ocpp/test/JSONCommunicatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void pack_bootNotificationRequest_returnsBootNotificationRequestPayload()
268268
@Test
269269
public void pack_bootNotificationConfirmation_returnsBootNotificationConfirmationPayload() throws Exception {
270270
// Given
271-
String expected = "{\"currentTime\":\"2016-04-28T06:41:13.720Z\",\"interval\":300,\"status\":\"Accepted\"}";
271+
String expected = "{\"currentTime\":\"2016-04-28T06:41:13Z\",\"interval\":300,\"status\":\"Accepted\"}";
272272
BootNotificationConfirmation confirmation = new BootNotificationConfirmation();
273273
confirmation.setCurrentTime(createDateTimeInMillis(1461825673720L));
274274
confirmation.setInterval(300);

0 commit comments

Comments
 (0)