Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cancel reservation #52

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package eu.chargetime.ocpp.utilities;
/*
ChargeTime.eu - Java-OCA-OCPP

MIT License

Copyright (C) 2016-2018 Thomas Volden <tv@chargetime.eu>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import java.util.Calendar;
import java.text.SimpleDateFormat;

public class SugarUtil {

public static String calendarToString(Calendar calendar) {
if (calendar == null)
return "";
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(calendar.getTime());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.JSONServer;
import eu.chargetime.ocpp.PropertyConstraintException;
import eu.chargetime.ocpp.SOAPServer;
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile;
import eu.chargetime.ocpp.feature.profile.ServerFirmwareManagementProfile;
import eu.chargetime.ocpp.feature.profile.ServerRemoteTriggerProfile;
import eu.chargetime.ocpp.feature.profile.ServerSmartChargingProfile;
import eu.chargetime.ocpp.feature.profile.*;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.*;
import eu.chargetime.ocpp.model.firmware.*;
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequestType;
import eu.chargetime.ocpp.model.reservation.CancelReservationConfirmation;
import eu.chargetime.ocpp.model.reservation.CancelReservationRequest;
import eu.chargetime.ocpp.model.reservation.ReserveNowConfirmation;
import eu.chargetime.ocpp.model.reservation.ReserveNowRequest;
import eu.chargetime.ocpp.test.FakeCentral.serverType;

import java.util.Calendar;

public class FakeCentralSystem {
private IServerAPI server;

Expand All @@ -51,13 +54,15 @@ public class FakeCentralSystem {
dummyHandlers = new DummyHandlers();

ServerCoreProfile serverCoreProfile = new ServerCoreProfile(dummyHandlers.createServerCoreEventHandler());
ServerReservationProfile serverReservationProfile = new ServerReservationProfile();

if (type == serverType.JSON) {
server = new JSONServer(serverCoreProfile);
} else {
server = new SOAPServer(serverCoreProfile);
}

server.addFeatureProfile(serverReservationProfile);
initializeServer();
isStarted = false;
}
Expand Down Expand Up @@ -122,11 +127,26 @@ public boolean hasReceivedGetDiagnosticsConfirmation() {
return dummyHandlers.wasLatestConfirmation(GetDiagnosticsConfirmation.class);
}


public boolean hasReceivedDiagnosticsStatusNotificationConfirmation() {
return dummyHandlers.wasLatestConfirmation(DiagnosticsStatusNotificationConfirmation.class);
}

public boolean hasReceivedFirmwareStatusNotificationConfirmation() {
return dummyHandlers.wasLatestConfirmation(FirmwareStatusNotificationConfirmation.class);
}

public boolean hasReceivedReserveNowConfirmation() {
return dummyHandlers.wasLatestConfirmation(ReserveNowConfirmation.class);
}

public boolean hasReceivedCancelReservationConfirmation() {
return dummyHandlers.wasLatestConfirmation(CancelReservationConfirmation.class);
}

public boolean hasReceivedUpdateFirmwareConfirmation() {
return dummyHandlers.wasLatestConfirmation(UpdateFirmwareConfirmation.class);
}

public boolean hasReceivedChangeAvailabilityConfirmation(String status) {
boolean result = false;
ChangeAvailabilityConfirmation confirmation = dummyHandlers.getReceivedConfirmation(new ChangeAvailabilityConfirmation());
Expand Down Expand Up @@ -230,12 +250,31 @@ public void sendGetDiagnosticsRequest(String location) throws Exception {
send(request);
}


public void sendDiagnosticsStatusNotificationRequest(DiagnosticsStatus status) throws Exception {
DiagnosticsStatusNotificationRequest request = new DiagnosticsStatusNotificationRequest(status);
send(request);
}

public void sendFirmwareStatusNotificationRequest(FirmwareStatus status) throws Exception {
FirmwareStatusNotificationRequest request = new FirmwareStatusNotificationRequest(status);
send(request);
}

public void sendUpdateFirmwareRequest(String location, Calendar retrieveDate) throws Exception {
UpdateFirmwareRequest request = new UpdateFirmwareRequest(location, retrieveDate);
send(request);
}

public void sendReserveNowRequest(Integer connectorId, Calendar expiryDate, String idTag, Integer reservationId) throws Exception {
ReserveNowRequest request = new ReserveNowRequest(connectorId, expiryDate, idTag, reservationId);
send(request);
}

public void sendCancelReservationRequest(Integer reservationId) throws Exception {
CancelReservationRequest request = new CancelReservationRequest(reservationId);
send(request);
}

public boolean hasReceivedResetConfirmation(String status) {
boolean result = false;
ResetConfirmation confirmation = dummyHandlers.getReceivedConfirmation(new ResetConfirmation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.*;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation;
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
import eu.chargetime.ocpp.model.firmware.*;
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageConfirmation;
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest;
import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageStatus;
import eu.chargetime.ocpp.model.reservation.*;
import eu.chargetime.ocpp.model.smartcharging.ChargingProfileStatus;
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileConfirmation;
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest;
Expand Down Expand Up @@ -55,6 +53,7 @@ public class FakeChargePoint
private final ClientSmartChargingProfile smartCharging;
private final ClientRemoteTriggerProfile remoteTrigger;
private final ClientFirmwareManagementProfile firmware;
private final ClientReservationProfile reservation;
private Throwable receivedException;
private String url;

Expand Down Expand Up @@ -157,6 +156,32 @@ public DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotifica
receivedRequest = request;
return new DiagnosticsStatusNotificationConfirmation();
}

@Override
public FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRequest(FirmwareStatusNotificationRequest request) {
receivedRequest = request;
return new FirmwareStatusNotificationConfirmation();
}

@Override
public UpdateFirmwareConfirmation handleUpdateFirmwareRequest(UpdateFirmwareRequest request) {
receivedRequest = request;
return new UpdateFirmwareConfirmation();
}
});

reservation = new ClientReservationProfile(new ClientReservationEventHandler() {
@Override
public ReserveNowConfirmation handleReserveNowRequest(ReserveNowRequest request) {
receivedRequest = request;
return new ReserveNowConfirmation(ReservationStatus.Accepted);
}

@Override
public CancelReservationConfirmation handleCancelReservationRequest(CancelReservationRequest request) {
receivedRequest = request;
return new CancelReservationConfirmation(CancelReservationStatus.Accepted);
}
});

switch (type) {
Expand All @@ -173,6 +198,7 @@ public DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotifica
client.addFeatureProfile(smartCharging);
client.addFeatureProfile(remoteTrigger);
client.addFeatureProfile(firmware);
client.addFeatureProfile(reservation);
}

public void connect() {
Expand Down Expand Up @@ -318,6 +344,14 @@ public boolean hasHandledDiagnosticsStatusNotificationRequest() {
return receivedRequest instanceof DiagnosticsStatusNotificationRequest;
}

public boolean hasHandledFirmwareStatusNotificationRequest() {
return receivedRequest instanceof FirmwareStatusNotificationRequest;
}

public boolean hasHandledUpdateFirmwareRequest() {
return receivedRequest instanceof UpdateFirmwareRequest;
}

public boolean hasHandledChangeAvailabilityRequest() {
return receivedRequest instanceof ChangeAvailabilityRequest;
}
Expand All @@ -326,6 +360,14 @@ public boolean hasHandledGetConfigurationRequest() {
return receivedRequest instanceof GetConfigurationRequest;
}

public boolean hasHandledReserveNowRequest() {
return receivedRequest instanceof ReserveNowRequest;
}

public boolean hasHandledCancelReservationRequest() {
return receivedRequest instanceof CancelReservationRequest;
}

public boolean hasHandledChangeConfigurationRequest() {
return receivedRequest instanceof ChangeConfigurationRequest;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package eu.chargetime.ocpp.test.firmware.json

import eu.chargetime.ocpp.model.firmware.FirmwareStatus
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

/*
ChargeTime.eu - Java-OCA-OCPP

MIT License

Copyright (C) 2016-2018 Thomas Volden <tv@chargetime.eu>
Copyright (C) 2018 Mikhail Kladkevich <kladmv@ecp-share.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

class JSONFirmwareStatusNotificationSpec 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()
}

def "Central System sends a FirmwareStatusNotification request and receives a response"() {
def conditions = new PollingConditions(timeout: 1)
given:
conditions.eventually {
assert centralSystem.connected()
}

when:
centralSystem.sendFirmwareStatusNotificationRequest(FirmwareStatus.Downloading)

then:
conditions.eventually {
assert chargePoint.hasHandledFirmwareStatusNotificationRequest()
assert centralSystem.hasReceivedFirmwareStatusNotificationConfirmation()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package eu.chargetime.ocpp.test.firmware.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

/*
ChargeTime.eu - Java-OCA-OCPP

MIT License

Copyright (C) 2016-2018 Thomas Volden <tv@chargetime.eu>
Copyright (C) 2018 Mikhail Kladkevich <kladmv@ecp-share.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

class JSONUpdateFirmwareSpec 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()
}

def "Central System sends a UpdateFirmware request and receives a response"() {
def conditions = new PollingConditions(timeout: 1)
given:
conditions.eventually {
assert centralSystem.connected()
}

when:
centralSystem.sendUpdateFirmwareRequest("URI", Calendar.getInstance())

then:
conditions.eventually {
assert chargePoint.hasHandledUpdateFirmwareRequest()
assert centralSystem.hasReceivedUpdateFirmwareConfirmation()
}
}
}
Loading