Skip to content

Commit

Permalink
Merge pull request #55 from eupakhomov/0.5_cleanup_spec_added_to_json…
Browse files Browse the repository at this point in the history
…_tests

0.5 cleanup spec added to json tests
  • Loading branch information
TVolden authored Apr 22, 2018
2 parents 905759c + 6790105 commit ad7c414
Show file tree
Hide file tree
Showing 49 changed files with 382 additions and 1,081 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.IServerAPI;
import eu.chargetime.ocpp.JSONServer;
import eu.chargetime.ocpp.PropertyConstraintException;
import eu.chargetime.ocpp.SOAPServer;
import eu.chargetime.ocpp.*;
import eu.chargetime.ocpp.feature.profile.*;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.*;
Expand All @@ -44,10 +41,14 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileConfirmation;
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest;
import eu.chargetime.ocpp.test.FakeCentral.serverType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Calendar;

public class FakeCentralSystem {
private static final Logger logger = LoggerFactory.getLogger(FakeCentralSystem.class);

private IServerAPI server;

private DummyHandlers dummyHandlers;
Expand All @@ -59,7 +60,10 @@ public class FakeCentralSystem {
ServerCoreProfile serverCoreProfile = new ServerCoreProfile(dummyHandlers.createServerCoreEventHandler());

if (type == serverType.JSON) {
server = new JSONServer(serverCoreProfile);
JSONConfiguration configuration =
JSONConfiguration.get()
.setParameter(JSONConfiguration.REUSE_ADDR_PARAMETER, true);
server = new JSONServer(serverCoreProfile, configuration);
} else {
server = new SOAPServer(serverCoreProfile);
}
Expand All @@ -85,6 +89,10 @@ private void initializeServer() {
server.addFeatureProfile(serverReservationProfile);
}

public boolean isClosed() {
return server.isClosed();
}

public boolean connected() {
return dummyHandlers.getCurrentIdentifier() != null;
}
Expand All @@ -94,19 +102,22 @@ public void clientLost() {
}

public void started() throws Exception {

if (!isStarted) {
int port = 8890;
if (server instanceof JSONServer)
if (server instanceof JSONServer) {
port = 8887;
}

server.open("127.0.0.1", port, dummyHandlers.generateServerEventsHandler());
logger.info("Server started on port: {}", port);
isStarted = true;
}
}

public void stopped() {
server.close();
logger.info("Server stopped");
isStarted = false;
}

public boolean hasHandledAuthorizeRequest() {
Expand Down Expand Up @@ -347,6 +358,10 @@ public void rigNextRequestToFail() {
dummyHandlers.setRiggedToFail(true);
}

public void clearRiggedToFailFlag() {
dummyHandlers.setRiggedToFail(false);
}

public void sendTriggerMessage(TriggerMessageRequestType type, Integer connectorId) throws Exception {
TriggerMessageRequest request = new TriggerMessageRequest(type);
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package eu.chargetime.ocpp.test.base.json

import eu.chargetime.ocpp.test.FakeCentral
import eu.chargetime.ocpp.test.FakeCentralSystem
import eu.chargetime.ocpp.test.FakeChargePoint
import spock.lang.Shared
import spock.lang.Specification
import spock.util.concurrent.PollingConditions

abstract class JSONBaseSpec extends Specification {
@Shared
FakeCentralSystem centralSystem = FakeCentral.getSystem(FakeCentral.serverType.JSON)
@Shared
FakeChargePoint chargePoint = new FakeChargePoint()

def setupSpec() {
def conditions = new PollingConditions(timeout: 10)

// When a Central System is running
centralSystem.started()

conditions.eventually {
assert !centralSystem.isClosed()
}
}

def setup() {
Thread.sleep(100);

chargePoint.connect()
}

def cleanup() {
chargePoint.disconnect()
centralSystem.clearRiggedToFailFlag()
}

def cleanupSpec() {
def conditions = new PollingConditions(timeout: 10)

centralSystem.stopped()

conditions.eventually {
assert centralSystem.isClosed()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package eu.chargetime.ocpp.test.base.soap

import eu.chargetime.ocpp.test.FakeCentral
import eu.chargetime.ocpp.test.FakeCentralSystem
import eu.chargetime.ocpp.test.FakeChargePoint
import spock.lang.Shared
import spock.lang.Specification


abstract class SOAPBaseSpec extends Specification
{
@Shared
FakeCentralSystem centralSystem = new FakeCentralSystem(FakeCentral.serverType.SOAP)
@Shared
FakeChargePoint chargePoint = new FakeChargePoint(FakeChargePoint.clientType.SOAP)

def setupSpec() {
// When a Central System is running
centralSystem.started()
}

def setup() {
chargePoint.connect()
}

def cleanup() {
chargePoint.disconnect()
}

def cleanupSpec() {
centralSystem.stopped()
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
package eu.chargetime.ocpp.test.core.json

import eu.chargetime.ocpp.OccurenceConstraintException
import eu.chargetime.ocpp.test.FakeCentral
import eu.chargetime.ocpp.test.FakeCentralSystem
import eu.chargetime.ocpp.test.FakeChargePoint
import spock.lang.Shared
import spock.lang.Specification
import eu.chargetime.ocpp.test.base.json.JSONBaseSpec
import spock.util.concurrent.PollingConditions

class JSONAuthorizeSpec extends Specification {
@Shared
FakeCentralSystem centralSystem = FakeCentral.getSystem(FakeCentral.serverType.JSON)
@Shared
FakeChargePoint chargePoint = new FakeChargePoint()

def setupSpec() {
// When a Central System is running
centralSystem.started()
}

def setup() {
chargePoint.connect()
}

def cleanup() {
chargePoint.disconnect()
}
class JSONAuthorizeSpec extends JSONBaseSpec {

def "Charge point sends Authorize request and receives a response"() {
def conditions = new PollingConditions(timeout: 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
package eu.chargetime.ocpp.test.core.json

import eu.chargetime.ocpp.test.FakeCentral
import eu.chargetime.ocpp.test.FakeCentralSystem
import eu.chargetime.ocpp.test.FakeChargePoint
import spock.lang.Shared
import spock.lang.Specification
import eu.chargetime.ocpp.test.base.json.JSONBaseSpec
import spock.util.concurrent.PollingConditions

class JSONBootNotificationSpec extends Specification
class JSONBootNotificationSpec extends JSONBaseSpec
{
@Shared
FakeCentralSystem centralSystem = FakeCentral.getSystem(FakeCentral.serverType.JSON)
@Shared
FakeChargePoint chargePoint = new FakeChargePoint()

def setupSpec() {
// When a Central System is running
centralSystem.started()
}

def setup() {
chargePoint.connect()
}

def cleanup() {
chargePoint.disconnect()
}

def "Charge point sends Boot Notification and receives a response"() {
def conditions = new PollingConditions(timeout: 1)

when:
chargePoint.sendBootNotification("VendorX", "SingleSocketCharger")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
package eu.chargetime.ocpp.test.core.json

import eu.chargetime.ocpp.model.core.AvailabilityType
import eu.chargetime.ocpp.test.FakeCentral
import eu.chargetime.ocpp.test.FakeCentralSystem
import eu.chargetime.ocpp.test.FakeChargePoint
import spock.lang.Shared
import spock.lang.Specification
import eu.chargetime.ocpp.test.base.json.JSONBaseSpec
import spock.util.concurrent.PollingConditions

class JSONChangeAvailabilitySpec extends Specification
class JSONChangeAvailabilitySpec extends JSONBaseSpec
{
@Shared
FakeCentralSystem centralSystem = FakeCentral.getSystem(FakeCentral.serverType.JSON)
@Shared
FakeChargePoint chargePoint = new FakeChargePoint()

def setupSpec() {
// When a Central System is running
centralSystem.started()
}

def setup() {
chargePoint.connect()
}

def cleanup() {
chargePoint.disconnect()
}

def "Central System sends a ChangeAvailability request and receives a response"() {
def conditions = new PollingConditions(timeout: 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
package eu.chargetime.ocpp.test.core.json

import eu.chargetime.ocpp.test.FakeCentral
import eu.chargetime.ocpp.test.FakeCentralSystem
import eu.chargetime.ocpp.test.FakeChargePoint
import spock.lang.Shared
import spock.lang.Specification
import eu.chargetime.ocpp.test.base.json.JSONBaseSpec
import spock.util.concurrent.PollingConditions

class JSONChangeConfigurationSpec extends Specification
class JSONChangeConfigurationSpec extends JSONBaseSpec
{
@Shared
FakeCentralSystem centralSystem = FakeCentral.getSystem(FakeCentral.serverType.JSON)
@Shared
FakeChargePoint chargePoint = new FakeChargePoint()

def setupSpec() {
// When a Central System is running
centralSystem.started()
}

def setup() {
chargePoint.connect()
}

def cleanup() {
chargePoint.disconnect()
}

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

given:
conditions.eventually {
assert centralSystem.connected()
assert !centralSystem.isClosed()
}
when:
centralSystem.sendChangeConfigurationRequest("key", "value")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
package eu.chargetime.ocpp.test.core.json

import eu.chargetime.ocpp.test.FakeCentral
import eu.chargetime.ocpp.test.FakeCentralSystem
import eu.chargetime.ocpp.test.FakeChargePoint
import spock.lang.Shared
import spock.lang.Specification
import eu.chargetime.ocpp.test.base.json.JSONBaseSpec
import spock.util.concurrent.PollingConditions

class JSONClearCacheSpec extends Specification
class JSONClearCacheSpec extends JSONBaseSpec
{
@Shared
FakeCentralSystem centralSystem = FakeCentral.getSystem(FakeCentral.serverType.JSON)
@Shared
FakeChargePoint chargePoint = new FakeChargePoint()

def setupSpec() {
// When a Central System is running
centralSystem.started()
}

def setup() {
chargePoint.connect()
}

def cleanup() {
chargePoint.disconnect()
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
package eu.chargetime.ocpp.test.core.json

import eu.chargetime.ocpp.test.FakeCentral
import eu.chargetime.ocpp.test.FakeCentralSystem
import eu.chargetime.ocpp.test.FakeChargePoint
import spock.lang.Shared
import spock.lang.Specification
import eu.chargetime.ocpp.test.base.json.JSONBaseSpec
import spock.util.concurrent.PollingConditions

class JSONDataTransferSpec extends Specification
class JSONDataTransferSpec extends JSONBaseSpec
{
@Shared
FakeCentralSystem centralSystem = FakeCentral.getSystem(FakeCentral.serverType.JSON)
@Shared
FakeChargePoint chargePoint = new FakeChargePoint()

def setupSpec() {
// When a Central System is running
centralSystem.started()
}

def setup() {
chargePoint.connect()
}

def cleanup() {
chargePoint.disconnect()
}

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

Expand Down
Loading

0 comments on commit ad7c414

Please sign in to comment.