Skip to content

Commit e175eda

Browse files
committed
Fixed parser to identify responses.
Split acceptance tests into JSON and SOAP. - SOAP not parsing right now *Sigh* Fixed blocking request calls for transmitter.
1 parent f104ada commit e175eda

40 files changed

+986
-215
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![Build Status](https://travis-ci.org/ChargeTimeEU/Java-OCA-OCPP.svg?branch=master)](https://travis-ci.org/ChargeTimeEU/Java-OCA-OCPP)
2+
[![codecov](https://codecov.io/gh/ChargeTimeEU/Java-OCA-OCPP/branch/master/graph/badge.svg)](https://codecov.io/gh/ChargeTimeEU/Java-OCA-OCPP)
23

34
Java-OCA-OCPP
45
=============
@@ -30,7 +31,7 @@ Java-OCA-OCPP uses the following libraries:
3031

3132
To use version 1.6 you need the following libraries:
3233

33-
* [org.json:json:20160212](https://github.com/stleary/JSON-java)
34+
* [com.google.code.gson](https://github.com/google/gson)
3435
* [org.java_websocket](https://github.com/TooTallNate/Java-WebSocket)
3536

3637
License

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,28 @@ public void started() throws Exception
7373
started(serverType.JSON);
7474
}
7575

76+
private boolean matchServerType(serverType type)
77+
{
78+
boolean result = false;
79+
switch (type) {
80+
case JSON:
81+
result = server instanceof JSONServer;
82+
break;
83+
case SOAP:
84+
result = server instanceof SOAPServer;
85+
}
86+
return result;
87+
}
88+
7689
public void started(serverType type) throws Exception
7790
{
78-
if (server != null)
79-
return;
91+
if (server != null) {
92+
if (matchServerType(type)) {
93+
return;
94+
} else {
95+
server.close();
96+
}
97+
}
8098

8199
ServerCoreProfile serverCoreProfile = new ServerCoreProfile(new ServerCoreEventHandler() {
82100
@Override
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package eu.chargetime.ocpp.test.core.json
2+
3+
import eu.chargetime.ocpp.OccurenceConstraintException
4+
import eu.chargetime.ocpp.test.FakeCentralSystem
5+
import eu.chargetime.ocpp.test.FakeChargePoint
6+
import spock.lang.Shared
7+
import spock.lang.Specification
8+
import spock.util.concurrent.PollingConditions
9+
10+
class JSONAuthorizeSpec extends Specification {
11+
@Shared
12+
FakeCentralSystem centralSystem = FakeCentralSystem.instance
13+
@Shared
14+
FakeChargePoint chargePoint = new FakeChargePoint()
15+
16+
def setupSpec() {
17+
// When a Central System is running
18+
centralSystem.started()
19+
}
20+
21+
def setup() {
22+
chargePoint.connect()
23+
}
24+
25+
def cleanup() {
26+
chargePoint.disconnect()
27+
}
28+
29+
def "Charge point sends Authorize request and receives a response"() {
30+
def conditions = new PollingConditions(timeout: 1)
31+
when:
32+
chargePoint.sendAuthorizeRequest("test123")
33+
34+
then:
35+
conditions.eventually {
36+
assert centralSystem.hasHandledAuthorizeRequest()
37+
}
38+
39+
then:
40+
conditions.eventually {
41+
assert chargePoint.hasReceivedAuthorizeConfirmation("Accepted")
42+
}
43+
}
44+
45+
def "Try to send incomplete Authorize request, get local exception"() {
46+
when:
47+
chargePoint.sendIncompleteAuthorizeRequest()
48+
49+
then:
50+
thrown OccurenceConstraintException
51+
}
52+
53+
def "Send Authorize request to a server that's rigged to fail"() {
54+
def conditions = new PollingConditions(timeout: 1)
55+
56+
given:
57+
centralSystem.isRiggedToFailOnNextRequest()
58+
59+
when:
60+
chargePoint.sendAuthorizeRequest("")
61+
62+
then:
63+
conditions.eventually {
64+
chargePoint.hasReceivedError()
65+
}
66+
}
67+
}

ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/BootNotificationSpec.groovy renamed to ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/json/JSONBootNotificationSpec.groovy

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
1-
package eu.chargetime.ocpp.test.core
1+
package eu.chargetime.ocpp.test.core.json
22

33
import eu.chargetime.ocpp.test.FakeCentralSystem
44
import eu.chargetime.ocpp.test.FakeChargePoint
55
import spock.lang.Shared
66
import spock.lang.Specification
77
import spock.util.concurrent.PollingConditions
88

9-
class BootNotificationSpec extends Specification
9+
class JSONBootNotificationSpec extends Specification
1010
{
1111
@Shared
12-
FakeCentralSystem centralSystem = FakeCentralSystem.instance;
13-
@Shared FakeChargePoint chargePoint = new FakeChargePoint();
12+
FakeCentralSystem centralSystem = FakeCentralSystem.instance
13+
@Shared
14+
FakeChargePoint chargePoint = new FakeChargePoint()
1415

1516
def setupSpec() {
1617
// When a Central System is running
17-
centralSystem.started();
18+
centralSystem.started()
1819
}
1920

2021
def setup() {
21-
chargePoint.connect();
22+
chargePoint.connect()
2223
}
2324

2425
def cleanup() {
25-
chargePoint.disconnect();
26+
chargePoint.disconnect()
2627
}
2728

2829
def "Charge point sends Boot Notification and receives a response"() {
2930
def conditions = new PollingConditions(timeout: 1)
3031
when:
31-
chargePoint.sendBootNotification("VendorX", "SingleSocketCharger");
32+
chargePoint.sendBootNotification("VendorX", "SingleSocketCharger")
3233

3334
then:
3435
conditions.eventually {
35-
assert centralSystem.hasHandledBootNotification("VendorX", "SingleSocketCharger");
36+
assert centralSystem.hasHandledBootNotification("VendorX", "SingleSocketCharger")
3637
}
3738

3839
then:
3940
conditions.eventually {
40-
assert chargePoint.hasReceivedBootConfirmation("Accepted");
41+
assert chargePoint.hasReceivedBootConfirmation("Accepted")
4142
}
4243
}
4344
}

ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/ChangeAvailabilitySpec.groovy renamed to ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/json/JSONChangeAvailabilitySpec.groovy

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package eu.chargetime.ocpp.test.core
1+
package eu.chargetime.ocpp.test.core.json
22

33
import eu.chargetime.ocpp.model.core.AvailabilityType
44
import eu.chargetime.ocpp.test.FakeCentralSystem
@@ -7,34 +7,35 @@ import spock.lang.Shared
77
import spock.lang.Specification
88
import spock.util.concurrent.PollingConditions
99

10-
class ChangeAvailabilitySpec extends Specification
10+
class JSONChangeAvailabilitySpec extends Specification
1111
{
1212
@Shared
13-
FakeCentralSystem centralSystem = FakeCentralSystem.instance;
14-
@Shared FakeChargePoint chargePoint = new FakeChargePoint();
13+
FakeCentralSystem centralSystem = FakeCentralSystem.instance
14+
@Shared
15+
FakeChargePoint chargePoint = new FakeChargePoint()
1516

1617
def setupSpec() {
1718
// When a Central System is running
18-
centralSystem.started();
19+
centralSystem.started()
1920
}
2021

2122
def setup() {
22-
chargePoint.connect();
23+
chargePoint.connect()
2324
}
2425

2526
def cleanup() {
26-
chargePoint.disconnect();
27+
chargePoint.disconnect()
2728
}
2829

2930
def "Central System sends a ChangeAvailability request and receives a response"() {
3031
def conditions = new PollingConditions(timeout: 1)
3132
when:
32-
centralSystem.sendChangeAvailabilityRequest(1, AvailabilityType.Inoperative);
33+
centralSystem.sendChangeAvailabilityRequest(1, AvailabilityType.Inoperative)
3334

3435
then:
3536
conditions.eventually {
36-
assert chargePoint.hasHandledChangeAvailabilityRequest();
37-
assert centralSystem.hasReceivedChangeAvailabilityConfirmation("Accepted");
37+
assert chargePoint.hasHandledChangeAvailabilityRequest()
38+
assert centralSystem.hasReceivedChangeAvailabilityConfirmation("Accepted")
3839
}
3940
}
4041
}

ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/ChangeConfigurationSpec.groovy renamed to ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/json/JSONChangeConfigurationSpec.groovy

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
package eu.chargetime.ocpp.test.core
1+
package eu.chargetime.ocpp.test.core.json
22

33
import eu.chargetime.ocpp.test.FakeCentralSystem
44
import eu.chargetime.ocpp.test.FakeChargePoint
55
import spock.lang.Shared
66
import spock.lang.Specification
77
import spock.util.concurrent.PollingConditions
88

9-
class ChangeConfigurationSpec extends Specification
9+
class JSONChangeConfigurationSpec extends Specification
1010
{
1111
@Shared
12-
FakeCentralSystem centralSystem = FakeCentralSystem.instance;
13-
@Shared FakeChargePoint chargePoint = new FakeChargePoint();
12+
FakeCentralSystem centralSystem = FakeCentralSystem.instance
13+
@Shared
14+
FakeChargePoint chargePoint = new FakeChargePoint()
1415

1516
def setupSpec() {
1617
// When a Central System is running
17-
centralSystem.started();
18+
centralSystem.started()
1819
}
1920

2021
def setup() {
21-
chargePoint.connect();
22+
chargePoint.connect()
2223
}
2324

2425
def cleanup() {
25-
chargePoint.disconnect();
26+
chargePoint.disconnect()
2627
}
2728

2829
def "Central System sends a ChangeConfiguration request and receives a response"() {
2930
def conditions = new PollingConditions(timeout: 1)
3031

3132
when:
32-
centralSystem.sendChangeConfigurationRequest("key", "value");
33+
centralSystem.sendChangeConfigurationRequest("key", "value")
3334

3435
then:
3536
conditions.eventually {
36-
assert chargePoint.hasHandledChangeConfigurationRequest();
37-
assert centralSystem.hasReceivedChangeConfigurationConfirmation();
37+
assert chargePoint.hasHandledChangeConfigurationRequest()
38+
assert centralSystem.hasReceivedChangeConfigurationConfirmation()
3839
}
3940
}
4041
}

ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/ClearCacheSpec.groovy renamed to ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/json/JSONClearCacheSpec.groovy

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
package eu.chargetime.ocpp.test.core
1+
package eu.chargetime.ocpp.test.core.json
22

33
import eu.chargetime.ocpp.test.FakeCentralSystem
44
import eu.chargetime.ocpp.test.FakeChargePoint
55
import spock.lang.Shared
66
import spock.lang.Specification
77
import spock.util.concurrent.PollingConditions
88

9-
class ClearCacheSpec extends Specification
9+
class JSONClearCacheSpec extends Specification
1010
{
1111
@Shared
12-
FakeCentralSystem centralSystem = FakeCentralSystem.getInstance();
13-
@Shared FakeChargePoint chargePoint = new FakeChargePoint();
12+
FakeCentralSystem centralSystem = FakeCentralSystem.getInstance()
13+
@Shared
14+
FakeChargePoint chargePoint = new FakeChargePoint()
1415

1516
def setupSpec() {
1617
// When a Central System is running
17-
centralSystem.started();
18+
centralSystem.started()
1819
}
1920

2021
def setup() {
21-
chargePoint.connect();
22+
chargePoint.connect()
2223
}
2324

2425
def cleanup() {
25-
chargePoint.disconnect();
26+
chargePoint.disconnect()
2627
}
2728

2829
def "Central System sends a ClearCache request and receives a response"() {
2930
def conditions = new PollingConditions(timeout: 1)
3031

3132
when:
32-
centralSystem.sendClearCacheRequest();
33+
centralSystem.sendClearCacheRequest()
3334

3435
then:
3536
conditions.eventually {
36-
assert chargePoint.hasHandledClearCacheRequest();
37-
assert centralSystem.hasReceivedClearCacheConfirmation();
37+
assert chargePoint.hasHandledClearCacheRequest()
38+
assert centralSystem.hasReceivedClearCacheConfirmation()
3839
}
3940
}
4041
}

ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/DataTransferSpec.groovy renamed to ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/core/json/JSONDataTransferSpec.groovy

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,58 @@
1-
package eu.chargetime.ocpp.test.core
1+
package eu.chargetime.ocpp.test.core.json
22

33
import eu.chargetime.ocpp.test.FakeCentralSystem
44
import eu.chargetime.ocpp.test.FakeChargePoint
55
import spock.lang.Shared
66
import spock.lang.Specification
77
import spock.util.concurrent.PollingConditions
88

9-
class DataTransferSpec extends Specification
9+
class JSONDataTransferSpec extends Specification
1010
{
1111
@Shared
12-
FakeCentralSystem centralSystem = FakeCentralSystem.getInstance();
13-
@Shared FakeChargePoint chargePoint = new FakeChargePoint();
12+
FakeCentralSystem centralSystem = FakeCentralSystem.getInstance()
13+
@Shared
14+
FakeChargePoint chargePoint = new FakeChargePoint()
1415

1516
def setupSpec() {
1617
// When a Central System is running
17-
centralSystem.started();
18+
centralSystem.started()
1819
}
1920

2021
def setup() {
21-
chargePoint.connect();
22+
chargePoint.connect()
2223
}
2324

2425
def cleanup() {
25-
chargePoint.disconnect();
26+
chargePoint.disconnect()
2627
}
2728

2829
def "Central System sends a DataTransfer request and receives a response"() {
2930
def conditions = new PollingConditions(timeout: 1)
3031

3132
when:
32-
centralSystem.sendDataTransferRequest("VendorId", "messageId", "data");
33+
centralSystem.sendDataTransferRequest("VendorId", "messageId", "data")
3334

3435
then:
3536
conditions.eventually {
36-
assert chargePoint.hasHandledDataTransferRequest();
37-
assert centralSystem.hasReceivedDataTransferConfirmation();
37+
assert chargePoint.hasHandledDataTransferRequest()
38+
assert centralSystem.hasReceivedDataTransferConfirmation()
3839
}
3940
}
4041

4142
def "Charge point sends a DataTransfer request and receives a response"() {
4243
def conditions = new PollingConditions(timeout: 1)
4344

4445
when:
45-
chargePoint.sendDataTransferRequest("VendorId", "messageId", "data");
46+
chargePoint.sendDataTransferRequest("VendorId", "messageId", "data")
4647

4748
then:
4849
conditions.eventually {
49-
assert centralSystem.hasHandledDataTransferRequest();
50+
assert centralSystem.hasHandledDataTransferRequest()
5051
}
5152

5253
then:
5354
conditions.eventually {
54-
assert chargePoint.hasReceivedDataTransferConfirmation("Accepted");
55+
assert chargePoint.hasReceivedDataTransferConfirmation("Accepted")
5556
}
5657
}
5758
}

0 commit comments

Comments
 (0)