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

Resolve all conflicts for these commits #56

Merged
merged 11 commits into from
Apr 22, 2018
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package eu.chargetime.ocpp.utilities;
/*
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.
*/

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,23 @@ 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.localauthlist.*;
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.model.smartcharging.SetChargingProfileConfirmation;
import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest;
import eu.chargetime.ocpp.test.FakeCentral.serverType;

import java.util.Calendar;

public class FakeCentralSystem {
private IServerAPI server;

Expand Down Expand Up @@ -71,6 +77,12 @@ private void initializeServer() {

ServerFirmwareManagementProfile firmwareManagementProfile = new ServerFirmwareManagementProfile();
server.addFeatureProfile(firmwareManagementProfile);

ServerLocalAuthListProfile localAuthListProfile = new ServerLocalAuthListProfile();
server.addFeatureProfile(localAuthListProfile);

ServerReservationProfile serverReservationProfile = new ServerReservationProfile();
server.addFeatureProfile(serverReservationProfile);
}

public boolean connected() {
Expand Down Expand Up @@ -130,6 +142,30 @@ 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 hasReceivedSendLocalListConfirmation() {
return dummyHandlers.wasLatestConfirmation(SendLocalListConfirmation.class);
}

public boolean hasReceivedGetLocalListVersionConfirmation() {
return dummyHandlers.wasLatestConfirmation(GetLocalListVersionConfirmation.class);
}

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

public boolean hasReceivedSetChargingProfileConfirmation() {
return dummyHandlers.wasLatestConfirmation(SetChargingProfileConfirmation.class);
}

public boolean hasReceivedChangeAvailabilityConfirmation(String status) {
boolean result = false;
ChangeAvailabilityConfirmation confirmation = dummyHandlers.getReceivedConfirmation(new ChangeAvailabilityConfirmation());
Expand Down Expand Up @@ -243,6 +279,36 @@ public void sendFirmwareStatusNotificationRequest(FirmwareStatus status) throws
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 void sendGetLocalListVersionRequest() throws Exception {
GetLocalListVersionRequest request = new GetLocalListVersionRequest();
send(request);
}

public void sendSendLocalListRequest(int listVersion, UpdateType updateType) throws Exception {
SendLocalListRequest request = new SendLocalListRequest(listVersion, updateType);
send(request);
}

public void sendSetChargingProfileRequest(Integer connectorId, ChargingProfile chargingProfile) throws Exception {
SetChargingProfileRequest request = new SetChargingProfileRequest(connectorId, chargingProfile);
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 @@ -6,9 +6,11 @@
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.*;
import eu.chargetime.ocpp.model.firmware.*;
import eu.chargetime.ocpp.model.localauthlist.*;
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 @@ -52,6 +54,8 @@ public class FakeChargePoint
private final ClientSmartChargingProfile smartCharging;
private final ClientRemoteTriggerProfile remoteTrigger;
private final ClientFirmwareManagementProfile firmware;
private final ClientLocalAuthListProfile localAuthList;
private final ClientReservationProfile reservation;
private Throwable receivedException;
private String url;

Expand Down Expand Up @@ -160,6 +164,40 @@ public FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRe
receivedRequest = request;
return new FirmwareStatusNotificationConfirmation();
}

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

localAuthList = new ClientLocalAuthListProfile(new ClientLocalAuthListEventHandler() {
@Override
public SendLocalListConfirmation handleSendLocalListRequest(SendLocalListRequest request) {
receivedRequest = request;
return new SendLocalListConfirmation(UpdateStatus.VersionMismatch);
}

@Override
public GetLocalListVersionConfirmation handleGetLocalListVersionRequest(GetLocalListVersionRequest request) {
receivedRequest = request;
return new GetLocalListVersionConfirmation(2);
}
});

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 @@ -176,6 +214,8 @@ public FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRe
client.addFeatureProfile(smartCharging);
client.addFeatureProfile(remoteTrigger);
client.addFeatureProfile(firmware);
client.addFeatureProfile(localAuthList);
client.addFeatureProfile(reservation);
}

public void connect() {
Expand Down Expand Up @@ -325,6 +365,10 @@ public boolean hasHandledFirmwareStatusNotificationRequest() {
return receivedRequest instanceof FirmwareStatusNotificationRequest;
}

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

public boolean hasHandledChangeAvailabilityRequest() {
return receivedRequest instanceof ChangeAvailabilityRequest;
}
Expand All @@ -333,6 +377,26 @@ public boolean hasHandledGetConfigurationRequest() {
return receivedRequest instanceof GetConfigurationRequest;
}

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

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

public boolean hasHandledSendLocalListRequest() {
return receivedRequest instanceof SendLocalListRequest;
}

public boolean hasHandledGetLocalListVersionRequest() {
return receivedRequest instanceof GetLocalListVersionRequest;
}

public boolean hasHandledSetChargingProfileRequest() {
return receivedRequest instanceof SetChargingProfileRequest;
}

public boolean hasHandledChangeConfigurationRequest() {
return receivedRequest instanceof ChangeConfigurationRequest;
}
Expand Down
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