diff --git a/ocpp-common/src/main/java/eu/chargetime/ocpp/ConfirmatinHandler.java b/ocpp-common/src/main/java/eu/chargetime/ocpp/ConfirmationHandler.java similarity index 100% rename from ocpp-common/src/main/java/eu/chargetime/ocpp/ConfirmatinHandler.java rename to ocpp-common/src/main/java/eu/chargetime/ocpp/ConfirmationHandler.java diff --git a/ocpp-common/src/main/java/eu/chargetime/ocpp/utilities/SugarUtil.java b/ocpp-common/src/main/java/eu/chargetime/ocpp/utilities/SugarUtil.java new file mode 100644 index 000000000..71b120e03 --- /dev/null +++ b/ocpp-common/src/main/java/eu/chargetime/ocpp/utilities/SugarUtil.java @@ -0,0 +1,39 @@ +package eu.chargetime.ocpp.utilities; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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()); + } +} \ No newline at end of file diff --git a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java index 2e5cc6537..106e4ff19 100644 --- a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java +++ b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java @@ -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; @@ -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() { @@ -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()); @@ -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()); diff --git a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java index 129aa9cbd..c9825c746 100644 --- a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java +++ b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java @@ -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; @@ -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; @@ -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) { @@ -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() { @@ -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; } @@ -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; } diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/firmware/json/JSONUpdateFirmwareSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/firmware/json/JSONUpdateFirmwareSpec.groovy new file mode 100644 index 000000000..163f0d36e --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/firmware/json/JSONUpdateFirmwareSpec.groovy @@ -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 + Copyright (C) 2018 Mikhail Kladkevich + + 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() + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/localauthlist/json/JSONGetLocalListVersionSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/localauthlist/json/JSONGetLocalListVersionSpec.groovy new file mode 100644 index 000000000..9493e496a --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/localauthlist/json/JSONGetLocalListVersionSpec.groovy @@ -0,0 +1,72 @@ +package eu.chargetime.ocpp.test.localauthlist.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 + Copyright (C) 2018 Mikhail Kladkevich + + 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 JSONGetLocalListVersionSpec 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 GetLocalListVersion request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + given: + conditions.eventually { + assert centralSystem.connected() + } + + when: + centralSystem.sendGetLocalListVersionRequest() + + then: + conditions.eventually { + assert chargePoint.hasHandledGetLocalListVersionRequest() + assert centralSystem.hasReceivedGetLocalListVersionConfirmation() + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/localauthlist/json/JSONSendLocalListSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/localauthlist/json/JSONSendLocalListSpec.groovy new file mode 100644 index 000000000..76e6a20f3 --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/localauthlist/json/JSONSendLocalListSpec.groovy @@ -0,0 +1,73 @@ +package eu.chargetime.ocpp.test.localauthlist.json + +import eu.chargetime.ocpp.model.localauthlist.UpdateType +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 + Copyright (C) 2018 Mikhail Kladkevich + + 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 JSONSendLocalListSpec 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 SendLocalList request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + given: + conditions.eventually { + assert centralSystem.connected() + } + + when: + centralSystem.sendSendLocalListRequest(1, UpdateType.Differential) + + then: + conditions.eventually { + assert chargePoint.hasHandledSendLocalListRequest() + assert centralSystem.hasReceivedSendLocalListConfirmation() + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/reservation/json/JSONCancelReservationSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/reservation/json/JSONCancelReservationSpec.groovy new file mode 100644 index 000000000..5bcda4953 --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/reservation/json/JSONCancelReservationSpec.groovy @@ -0,0 +1,72 @@ +package eu.chargetime.ocpp.test.reservation.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 + Copyright (C) 2018 Mikhail Kladkevich + + 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 JSONCancelReservationSpec 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 CancelReservation request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + given: + conditions.eventually { + assert centralSystem.connected() + } + + when: + centralSystem.sendCancelReservationRequest(1) + + then: + conditions.eventually { + assert chargePoint.hasHandledCancelReservationRequest() + assert centralSystem.hasReceivedCancelReservationConfirmation() + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/reservation/json/JSONReserveNowSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/reservation/json/JSONReserveNowSpec.groovy new file mode 100644 index 000000000..61f102a25 --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/reservation/json/JSONReserveNowSpec.groovy @@ -0,0 +1,72 @@ +package eu.chargetime.ocpp.test.reservation.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 + Copyright (C) 2018 Mikhail Kladkevich + + 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 JSONReserveNowSpec 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 ReserveNow request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + given: + conditions.eventually { + assert centralSystem.connected() + } + + when: + centralSystem.sendReserveNowRequest(0, Calendar.getInstance(), "123", 2) + + then: + conditions.eventually { + assert chargePoint.hasHandledReserveNowRequest() + assert centralSystem.hasReceivedReserveNowConfirmation() + } + } +} diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/smartcharging/json/JSONSetChargingProfileSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/smartcharging/json/JSONSetChargingProfileSpec.groovy new file mode 100644 index 000000000..14d4b7311 --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/smartcharging/json/JSONSetChargingProfileSpec.groovy @@ -0,0 +1,81 @@ +package eu.chargetime.ocpp.test.smartcharging.json + +import eu.chargetime.ocpp.model.core.ChargingProfile +import eu.chargetime.ocpp.model.core.ChargingProfileKindType +import eu.chargetime.ocpp.model.core.ChargingProfilePurposeType +import eu.chargetime.ocpp.model.core.ChargingRateUnitType +import eu.chargetime.ocpp.model.core.ChargingSchedule +import eu.chargetime.ocpp.model.core.ChargingSchedulePeriod +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 + Copyright (C) 2018 Mikhail Kladkevich + + 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 JSONSetChargingProfileSpec 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 SetChargingProfile request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + given: + conditions.eventually { + assert centralSystem.connected() + } + + when: + ChargingSchedulePeriod[] chargingSchedulePeriod = new ChargingSchedulePeriod[1] + chargingSchedulePeriod[0] = new ChargingSchedulePeriod(1, 2D) + centralSystem.sendSetChargingProfileRequest(1, new ChargingProfile(1, 2, ChargingProfilePurposeType.ChargePointMaxProfile, ChargingProfileKindType.Recurring, + new ChargingSchedule(ChargingRateUnitType.A, chargingSchedulePeriod))) + + then: + conditions.eventually { + assert chargePoint.hasHandledSetChargingProfileRequest() + assert centralSystem.hasReceivedSetChargingProfileConfirmation() + } + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/CancelReservationFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/CancelReservationFeature.java new file mode 100644 index 000000000..73327eb6f --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/CancelReservationFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature; + +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.reservation.CancelReservationConfirmation; +import eu.chargetime.ocpp.model.reservation.CancelReservationRequest; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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. + */ + +public class CancelReservationFeature extends Feature { + + public CancelReservationFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return CancelReservationRequest.class; + } + + @Override + public Class getConfirmationType() { + return CancelReservationConfirmation.class; + } + + @Override + public String getAction() { + return "CancelReservation"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/ReserveNowFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/ReserveNowFeature.java new file mode 100644 index 000000000..729e55813 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/ReserveNowFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature; + +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.reservation.ReserveNowConfirmation; +import eu.chargetime.ocpp.model.reservation.ReserveNowRequest; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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. + */ + +public class ReserveNowFeature extends Feature { + + public ReserveNowFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return ReserveNowRequest.class; + } + + @Override + public Class getConfirmationType() { + return ReserveNowConfirmation.class; + } + + @Override + public String getAction() { + return "ReserveNow"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/UpdateFirmwareFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/UpdateFirmwareFeature.java new file mode 100644 index 000000000..fd8f52026 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/UpdateFirmwareFeature.java @@ -0,0 +1,56 @@ +package eu.chargetime.ocpp.feature; + +import eu.chargetime.ocpp.feature.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.firmware.UpdateFirmwareConfirmation; +import eu.chargetime.ocpp.model.firmware.UpdateFirmwareRequest; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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. + */ + +public class UpdateFirmwareFeature extends Feature { + + public UpdateFirmwareFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return UpdateFirmwareRequest.class; + } + + @Override + public Class getConfirmationType() { + return UpdateFirmwareConfirmation.class; + } + + @Override + public String getAction() { + return "UpdateFirmware"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientFirmwareManagementEventHandler.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientFirmwareManagementEventHandler.java index df8277430..022a80ce3 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientFirmwareManagementEventHandler.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientFirmwareManagementEventHandler.java @@ -34,4 +34,6 @@ public interface ClientFirmwareManagementEventHandler { FirmwareStatusNotificationConfirmation handleFirmwareStatusNotificationRequest(FirmwareStatusNotificationRequest request); + UpdateFirmwareConfirmation handleUpdateFirmwareRequest(UpdateFirmwareRequest request); + } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientFirmwareManagementProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientFirmwareManagementProfile.java index 7330f4f37..b74ae0b3e 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientFirmwareManagementProfile.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientFirmwareManagementProfile.java @@ -24,15 +24,13 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.feature.DiagnosticsStatusNotificationFeature; -import eu.chargetime.ocpp.feature.Feature; -import eu.chargetime.ocpp.feature.FirmwareStatusNotificationFeature; -import eu.chargetime.ocpp.feature.GetDiagnosticsFeature; +import eu.chargetime.ocpp.feature.*; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest; import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest; import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest; +import eu.chargetime.ocpp.model.firmware.UpdateFirmwareRequest; import java.util.HashSet; import java.util.UUID; @@ -48,6 +46,7 @@ public ClientFirmwareManagementProfile(ClientFirmwareManagementEventHandler even features.add(new GetDiagnosticsFeature(this)); features.add(new DiagnosticsStatusNotificationFeature(this)); features.add(new FirmwareStatusNotificationFeature(this)); + features.add(new UpdateFirmwareFeature(this)); } @Override @@ -65,6 +64,8 @@ public Confirmation handleRequest(UUID sessionIndex, Request request) { result = eventHandler.handleDiagnosticsStatusNotificationRequest((DiagnosticsStatusNotificationRequest) request); } else if (request instanceof FirmwareStatusNotificationRequest) { result = eventHandler.handleFirmwareStatusNotificationRequest((FirmwareStatusNotificationRequest) request); + } else if (request instanceof UpdateFirmwareRequest) { + result = eventHandler.handleUpdateFirmwareRequest((UpdateFirmwareRequest) request); } return result; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientLocalAuthListEventHandler.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientLocalAuthListEventHandler.java index 08829d37e..2fa3ff9d3 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientLocalAuthListEventHandler.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientLocalAuthListEventHandler.java @@ -20,5 +20,5 @@ public interface ClientLocalAuthListEventHandler { * @param request incoming {@link SendLocalListRequest} to handle. * @return outgoing {@link SendLocalListConfirmation} to reply with. */ - SendLocalListConfirmation handleSendLocalListReqeust(SendLocalListRequest request); + SendLocalListConfirmation handleSendLocalListRequest(SendLocalListRequest request); } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientLocalAuthListProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientLocalAuthListProfile.java index be696d00a..724bc7eba 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientLocalAuthListProfile.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientLocalAuthListProfile.java @@ -13,8 +13,8 @@ public class ClientLocalAuthListProfile implements Profile { - ClientLocalAuthListEventHandler eventHandler; - ArrayList featureList; + private ClientLocalAuthListEventHandler eventHandler; + private ArrayList featureList; public ClientLocalAuthListProfile(ClientLocalAuthListEventHandler handler) { eventHandler = handler; @@ -36,7 +36,7 @@ public Confirmation handleRequest(UUID sessionIndex, Request request) { if(request instanceof GetLocalListVersionRequest) { result = eventHandler.handleGetLocalListVersionRequest((GetLocalListVersionRequest)request); } else if (request instanceof SendLocalListRequest) { - result = eventHandler.handleSendLocalListReqeust((SendLocalListRequest) request); + result = eventHandler.handleSendLocalListRequest((SendLocalListRequest) request); } return result; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientReservationEventHandler.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientReservationEventHandler.java new file mode 100644 index 000000000..5502ed81f --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientReservationEventHandler.java @@ -0,0 +1,39 @@ +package eu.chargetime.ocpp.feature.profile; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 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; + +public interface ClientReservationEventHandler { + ReserveNowConfirmation handleReserveNowRequest(ReserveNowRequest request); + + CancelReservationConfirmation handleCancelReservationRequest(CancelReservationRequest request); + +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientReservationProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientReservationProfile.java new file mode 100644 index 000000000..0ce96dd50 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientReservationProfile.java @@ -0,0 +1,66 @@ +package eu.chargetime.ocpp.feature.profile;/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.feature.*; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.reservation.CancelReservationRequest; +import eu.chargetime.ocpp.model.reservation.ReserveNowRequest; + +import java.util.HashSet; +import java.util.UUID; + +public class ClientReservationProfile implements Profile { + + private HashSet features; + private ClientReservationEventHandler eventHandler; + + public ClientReservationProfile(ClientReservationEventHandler eventHandler) { + this.eventHandler = eventHandler; + features = new HashSet<>(); + features.add(new ReserveNowFeature(this)); + features.add(new CancelReservationFeature(this)); + } + + @Override + public Feature[] getFeatureList() { + return features.toArray(new Feature[0]); + } + + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + Confirmation result = null; + + if (request instanceof ReserveNowRequest) { + result = eventHandler.handleReserveNowRequest((ReserveNowRequest) request); + } else if (request instanceof CancelReservationRequest) { + result = eventHandler.handleCancelReservationRequest((CancelReservationRequest) request); + } + + return result; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerFirmwareManagementProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerFirmwareManagementProfile.java index 71eaf953d..8f81bea50 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerFirmwareManagementProfile.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerFirmwareManagementProfile.java @@ -25,10 +25,7 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.feature.DiagnosticsStatusNotificationFeature; -import eu.chargetime.ocpp.feature.Feature; -import eu.chargetime.ocpp.feature.FirmwareStatusNotificationFeature; -import eu.chargetime.ocpp.feature.GetDiagnosticsFeature; +import eu.chargetime.ocpp.feature.*; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; @@ -44,6 +41,7 @@ public ServerFirmwareManagementProfile() { features.add(new GetDiagnosticsFeature(this)); features.add(new DiagnosticsStatusNotificationFeature(this)); features.add(new FirmwareStatusNotificationFeature(this)); + features.add(new UpdateFirmwareFeature(this)); } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerLocalAuthListProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerLocalAuthListProfile.java new file mode 100644 index 000000000..cb383b901 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerLocalAuthListProfile.java @@ -0,0 +1,54 @@ +package eu.chargetime.ocpp.feature.profile; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + + 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 eu.chargetime.ocpp.feature.*; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; + +import java.util.HashSet; +import java.util.UUID; + +public class ServerLocalAuthListProfile implements Profile { + + private HashSet featureList; + + public ServerLocalAuthListProfile() { + featureList = new HashSet<>(); + featureList.add(new GetLocalListVersionFeature(this)); + featureList.add(new SendLocalListFeature(this)); + } + + @Override + public Feature[] getFeatureList() { + return featureList.toArray(new Feature[0]); + } + + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + return null; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerReservationProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerReservationProfile.java new file mode 100644 index 000000000..a064d5bd2 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerReservationProfile.java @@ -0,0 +1,55 @@ +package eu.chargetime.ocpp.feature.profile; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.feature.*; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; + +import java.util.HashSet; +import java.util.UUID; + +public class ServerReservationProfile implements Profile { + + private HashSet features; + + public ServerReservationProfile() { + features = new HashSet<>(); + features.add(new ReserveNowFeature(this)); + features.add(new CancelReservationFeature(this)); + } + + @Override + public Feature[] getFeatureList() { + return features.toArray(new Feature[0]); + } + + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + return null; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingProfile.java index ae847c352..66f3f519c 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingProfile.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingProfile.java @@ -46,10 +46,26 @@ public class ChargingProfile implements Validatable { private Calendar validTo; private ChargingSchedule chargingSchedule; + public ChargingProfile() { } + + public ChargingProfile(Integer chargingProfileId, Integer stackLevel, ChargingProfilePurposeType chargingProfilePurpose, ChargingProfileKindType chargingProfileKind, ChargingSchedule chargingSchedule) { + this.chargingProfileId = chargingProfileId; + this.stackLevel = stackLevel; + this.chargingProfilePurpose = chargingProfilePurpose; + this.chargingProfileKind = chargingProfileKind; + this.chargingSchedule = chargingSchedule; + } + + public ChargingProfile(Integer chargingProfileId, Integer stackLevel, ChargingProfilePurposeType chargingProfilePurpose, ChargingProfileKindType chargingProfileKind) { + this.chargingProfileId = chargingProfileId; + this.stackLevel = stackLevel; + this.chargingProfilePurpose = chargingProfilePurpose; + this.chargingProfileKind = chargingProfileKind; + } + @Override public boolean validate() { - boolean valid = true; - valid &= chargingProfileId != null; + boolean valid = chargingProfileId != null; valid &= stackLevel >= 0; valid &= chargingProfilePurpose != null; valid &= transactionId == null || chargingProfilePurpose == ChargingProfilePurposeType.TxProfile; @@ -61,7 +77,7 @@ public boolean validate() { @XmlElement public void setChargingProfileId(Integer chargingProfileId) throws PropertyConstraintException { if (chargingProfileId == null) - throw new PropertyConstraintException("chargingProfileId", chargingProfileId); + throw new PropertyConstraintException("chargingProfileId", null); this.chargingProfileId = chargingProfileId; } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingSchedule.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingSchedule.java index 6448da175..ebed93518 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingSchedule.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingSchedule.java @@ -45,10 +45,16 @@ public class ChargingSchedule implements Validatable { private ChargingSchedulePeriod[] chargingSchedulePeriod; private Double minChargingRate; + public ChargingSchedule() { } + + public ChargingSchedule(ChargingRateUnitType chargingRateUnit, ChargingSchedulePeriod[] chargingSchedulePeriod) { + this.chargingRateUnit = chargingRateUnit; + this.chargingSchedulePeriod = chargingSchedulePeriod; + } + @Override public boolean validate() { - boolean valid = true; - valid &= chargingRateUnit != null; + boolean valid = chargingRateUnit != null; if (valid &= chargingSchedulePeriod != null) { for (ChargingSchedulePeriod period : chargingSchedulePeriod) valid &= period.validate(); diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingSchedulePeriod.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingSchedulePeriod.java index 25d5821ee..53f9fbfac 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingSchedulePeriod.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChargingSchedulePeriod.java @@ -42,6 +42,13 @@ public class ChargingSchedulePeriod implements Validatable { private Double limit; private Integer numberPhases = 3; + public ChargingSchedulePeriod() { } + + public ChargingSchedulePeriod(Integer startPeriod, Double limit) { + this.startPeriod = startPeriod; + this.limit = limit; + } + @Override public boolean validate() { boolean valid = true; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/UpdateFirmwareConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/UpdateFirmwareConfirmation.java new file mode 100644 index 000000000..3a45daa5e --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/UpdateFirmwareConfirmation.java @@ -0,0 +1,63 @@ +package eu.chargetime.ocpp.model.firmware; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2018 Mikhail Kladkevich + * + * 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 eu.chargetime.ocpp.model.Confirmation; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Sent by the Charge Point to the Central System in response to an {@link UpdateFirmwareRequest}. + */ +@XmlRootElement(name = "updateFirmwareResponse") +public class UpdateFirmwareConfirmation implements Confirmation { + + public UpdateFirmwareConfirmation() { + } + + @Override + public boolean validate() { + return true; + } + + @Override + public boolean equals(Object o) { + return this == o || o != null && getClass() == o.getClass(); + } + + @Override + public int hashCode() { + return 7; + } + + @Override + public String toString() { + return "UpdateFirmwareConfirmation{}" + "{isValid=" + String.valueOf(validate()) + "}"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/UpdateFirmwareRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/UpdateFirmwareRequest.java new file mode 100644 index 000000000..384419671 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/UpdateFirmwareRequest.java @@ -0,0 +1,186 @@ +package eu.chargetime.ocpp.model.firmware; + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.utilities.SugarUtil; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import java.util.Calendar; +import java.util.Objects; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2016 Thomas Volden + * Copyright (C) 2018 Mikhail Kladkevich + * + * 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. + */ + +/** + * Sent by the Central System to the Charge Point. + */ +@XmlRootElement +@XmlType(propOrder = {"location", "retries", "retrieveDate", "retryInterval"}) +public class UpdateFirmwareRequest implements Request { + private String location; + private Integer retries; + private Calendar retrieveDate; + private int retryInterval; + + public UpdateFirmwareRequest() {} + + public UpdateFirmwareRequest(String location, Calendar retrieveDate) { + this.location = location; + this.retrieveDate = retrieveDate; + } + + @Override + public boolean validate() { + return (location != null) & (retrieveDate != null); + } + + /** + * This contains a string containing a URI pointing to a location from which to retrieve the firmware. + * + * @return String, a URI with the firmware. + */ + public String getLocation() { + return location; + } + + /** + * Required. + * This contains a string containing a URI pointing to a location from which to retrieve the firmware. + * + * @param location String, a URI with the firmware. + */ + @XmlElement + public void setLocation(String location) { + this.location = location; + } + + /** + * This specifies how many times Charge Point must try to download the firmware before giving up. + * If this field is not present, it is left to Charge Point to decide how many times it wants to retry. + * + * @return int, retry times. + */ + public int getRetries() { + return retries; + } + + /** + * Optional. + * This specifies how many times Charge Point must try to download the firmware before giving up. + * If this field is not present, it is left to Charge Point to decide how many times it wants to retry. + * + * @param retries int, retry times. + */ + @XmlElement + public void setRetries(int retries) throws PropertyConstraintException { + if (retries <= 0) + throw new PropertyConstraintException("retries", retries); + + this.retries = retries; + } + + /** + * This contains the date and time after which the Charge Point must retrieve the (new) firmware. + * + * @return Calendar, date and time of retrieving. + */ + public Calendar getRetrieveDate() { + return retrieveDate; + } + + /** + * Required. + * This contains the date and time after which the Charge Point must retrieve the (new) firmware. + * + * @param retrieveDate Calendar, date and time of retrieving. + */ + @XmlElement + public void setRetrieveDate(Calendar retrieveDate) { + this.retrieveDate = retrieveDate; + } + + /** + * The interval in seconds after which a retry may be attempted. If this field is not present, + * it is left to Charge Point to decide how long to wait between attempts. + * + * @return int, retry interval. + */ + public int getRetryInterval() { + return retryInterval; + } + + /** + * Optional. + * The interval in seconds after which a retry may be attempted. If this field is not present, + * it is left to Charge Point to decide how long to wait between attempts. + * + * @param retryInterval int, retry interval. + * @throws PropertyConstraintException Value was zero or negative. + * + */ + @XmlElement + public void setRetryInterval(int retryInterval) throws PropertyConstraintException { + if (retryInterval <= 0) + throw new PropertyConstraintException("retryInterval", retryInterval); + + this.retryInterval = retryInterval; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + UpdateFirmwareRequest that = (UpdateFirmwareRequest) o; + return retryInterval == that.retryInterval && + Objects.equals(location, that.location) && + Objects.equals(retries, that.retries) && + Objects.equals(retrieveDate, that.retrieveDate); + } + + @Override + public int hashCode() { + return Objects.hash(location, retries, retrieveDate, retryInterval); + } + + @Override + public String toString() { + return "UpdateFirmwareRequest{" + + "location='" + location + '\'' + + ", retries=" + retries + + ", retrieveDate='" + SugarUtil.calendarToString(retrieveDate) + + ", retryInterval=" + retryInterval + + ", isValid=" + String.valueOf(validate()) + + '}'; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/GetLocalListVersionConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/GetLocalListVersionConfirmation.java index 1cc910249..5a63df98f 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/GetLocalListVersionConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/GetLocalListVersionConfirmation.java @@ -5,21 +5,35 @@ public class GetLocalListVersionConfirmation implements Confirmation { - private int listVersion; - - public GetLocalListVersionConfirmation() { - listVersion = -2; - } - - public void setListVersion(int listVersion) throws PropertyConstraintException { - if (listVersion < -1) throw new PropertyConstraintException("listVersion", listVersion, "Exceeded limit"); - this.listVersion = listVersion; - } + private int listVersion = -2; + public GetLocalListVersionConfirmation() { } + + public GetLocalListVersionConfirmation(int listVersion) { + this.listVersion = listVersion; + } + + /** + * This contains the current version number of the local authorization list in the Charge Point. + * + * @return String, version of localAuthList. + */ public int getListVersion() { return listVersion; } - + + /** + * Required. + * This contains the current version number of the local authorization list in the Charge Point. + * + * @param listVersion int, version of localAuthList. + */ + public void setListVersion(int listVersion) throws PropertyConstraintException { + if (listVersion < -1) + throw new PropertyConstraintException("listVersion", listVersion, "Exceeded limit"); + this.listVersion = listVersion; + } + @Override public boolean validate() { return listVersion >= -1; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/SendLocalListConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/SendLocalListConfirmation.java index 4727ebca2..a0632983c 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/SendLocalListConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/SendLocalListConfirmation.java @@ -5,17 +5,38 @@ public class SendLocalListConfirmation implements Confirmation { - private UpdateStatus status = null; - - public void setStatus(UpdateStatus status) { - if(status != null) new PropertyConstraintException("status", status, "is null"); + private UpdateStatus status; + + public SendLocalListConfirmation() { } + + public SendLocalListConfirmation(UpdateStatus status) { + this.status = status; + } + + /** + * This indicates whether the Charge Point has successfully received and applied the update of + * the local authorization list. + * + * @return UpdateStatus, status of localAuthList updating. + */ + public UpdateStatus getStatus() { + return status; + } + + /** + * Required. + * This indicates whether the Charge Point has successfully received and applied the update of + * the local authorization list. + * + * @param status UpdateStatus, status of localAuthList updating. + */ + public void setStatus(UpdateStatus status) throws PropertyConstraintException { + if (status == null) + throw new PropertyConstraintException("status", null); + this.status = status; } - - public UpdateStatus getStatus() { - return status; - } - + @Override public boolean validate() { return status != null; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/SendLocalListRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/SendLocalListRequest.java index e749153cd..bfe4007f6 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/SendLocalListRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/SendLocalListRequest.java @@ -8,8 +8,15 @@ public class SendLocalListRequest implements Request { private int listVersion = 0; private AuthorizationData [] localAuthorizationList = null; private UpdateType updateType = null; - - public void setListVersion(int listVersion) throws PropertyConstraintException { + + public SendLocalListRequest() { } + + public SendLocalListRequest(int listVersion, UpdateType updateType) { + this.listVersion = listVersion; + this.updateType = updateType; + } + + public void setListVersion(int listVersion) throws PropertyConstraintException { if(listVersion < 1) throw new PropertyConstraintException("listVersion", listVersion, "Should be greater than 0"); this.listVersion = listVersion; } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/CancelReservationConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/CancelReservationConfirmation.java new file mode 100644 index 000000000..9f3b0a622 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/CancelReservationConfirmation.java @@ -0,0 +1,94 @@ +package eu.chargetime.ocpp.model.reservation; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2016 Thomas Volden + * Copyright (C) 2018 Mikhail Kladkevich + * + * 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 eu.chargetime.ocpp.model.Confirmation; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; + +/** + * Sent by the Charge Point to the Central System in response to an {@link CancelReservationRequest}. + */ +@XmlRootElement(name = "cancelReservationResponse") +public class CancelReservationConfirmation implements Confirmation { + private CancelReservationStatus status; + + public CancelReservationConfirmation() { } + + public CancelReservationConfirmation(CancelReservationStatus status) { + setStatus(status); + } + + @Override + public boolean validate() { + return status != null; + } + + /** + * This indicates the success or failure of the cancelling of a reservation by Central System. + * + * @return CancelReservationStatus, status of the request. + */ + public CancelReservationStatus getStatus() { + return status; + } + + /** + * Required. + * This indicates the success or failure of the cancelling of a reservation by Central System. + * + * @param status CancelReservationStatus, status of the request. + */ + @XmlElement + public void setStatus(CancelReservationStatus status) { + this.status = status; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CancelReservationConfirmation that = (CancelReservationConfirmation) o; + return status == that.status; + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return "CancelReservationConfirmation{" + + "status=" + status + + ", isValid=" + String.valueOf(validate()) + + '}'; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/CancelReservationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/CancelReservationRequest.java new file mode 100644 index 000000000..d36e9ce0c --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/CancelReservationRequest.java @@ -0,0 +1,99 @@ +package eu.chargetime.ocpp.model.reservation; + +import eu.chargetime.ocpp.model.Request; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2016 Thomas Volden + * Copyright (C) 2018 Mikhail Kladkevich + * + * 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. + */ + +/** + * Sent by the Central System to the Charge Point. + */ +@XmlRootElement +public class CancelReservationRequest implements Request { + private Integer reservationId; + + public CancelReservationRequest() {} + + public CancelReservationRequest(Integer reservationId) { + this.reservationId = reservationId; + } + + @Override + public boolean validate() { + return reservationId != null; + } + + /** + * Id of the reservation to cancel. + * + * @return Integer, id of the reservation. + */ + public Integer getReservationId() { + return reservationId; + } + + /** + * Required. + * Id of the reservation to cancel. + * + * @param reservationId Integer, id of the reservation. + */ + @XmlElement + public void setReservationId(Integer reservationId) { + this.reservationId = reservationId; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CancelReservationRequest that = (CancelReservationRequest) o; + return Objects.equals(reservationId, that.reservationId); + } + + @Override + public int hashCode() { + return Objects.hash(reservationId); + } + + @Override + public String toString() { + return "CancelReservationRequest{" + + "reservationId=" + reservationId + + ", isValid=" + String.valueOf(validate()) + + '}'; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/CancelReservationStatus.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/CancelReservationStatus.java new file mode 100644 index 000000000..3adb9bc61 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/CancelReservationStatus.java @@ -0,0 +1,36 @@ +package eu.chargetime.ocpp.model.reservation; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2016 Thomas Volden + * Copyright (C) 2018 Mikhail Kladkevich + * + * 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. + */ + +/** + * Accepted values used with {@link CancelReservationRequest} + */ +public enum CancelReservationStatus { + Accepted, + Rejected +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/ReservationStatus.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/ReservationStatus.java new file mode 100644 index 000000000..a5c31dea5 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/ReservationStatus.java @@ -0,0 +1,39 @@ +package eu.chargetime.ocpp.model.reservation; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2016 Thomas Volden + * Copyright (C) 2018 Mikhail Kladkevich + * + * 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. + */ + +/** + * Accepted values used with {@link ReserveNowRequest} + */ +public enum ReservationStatus { + Accepted, + Faulted, + Occupied, + Rejected, + Unavailable +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/ReserveNowConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/ReserveNowConfirmation.java new file mode 100644 index 000000000..9b62d55f9 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/ReserveNowConfirmation.java @@ -0,0 +1,95 @@ +package eu.chargetime.ocpp.model.reservation; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2016 Thomas Volden + * Copyright (C) 2018 Mikhail Kladkevich + * + * 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 eu.chargetime.ocpp.model.Confirmation; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; + +/** + * Sent by the Charge Point to the Central System in response to an {@link ReserveNowRequest}. + */ +@XmlRootElement(name = "reserveNowResponse") +public class ReserveNowConfirmation implements Confirmation { + private ReservationStatus status; + + public ReserveNowConfirmation() { + } + + public ReserveNowConfirmation(ReservationStatus status) { + setStatus(status); + } + + @Override + public boolean validate() { + return status != null; + } + + /** + * This indicates the success or failure of the reservation. + * + * @return ReservationStatus, status of the reservation. + */ + public ReservationStatus getStatus() { + return status; + } + + /** + * Required. + * This indicates the success or failure of the reservation. + * + * @param status ReservationStatus, status of the reservation. + */ + @XmlElement + public void setStatus(ReservationStatus status) { + this.status = status; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReserveNowConfirmation that = (ReserveNowConfirmation) o; + return status == that.status; + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return "ReserveNowConfirmation{" + + "status=" + status + + ", isValid=" + String.valueOf(validate()) + + '}'; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/ReserveNowRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/ReserveNowRequest.java new file mode 100644 index 000000000..f4ba14bcb --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/reservation/ReserveNowRequest.java @@ -0,0 +1,213 @@ +package eu.chargetime.ocpp.model.reservation; + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.utilities.ModelUtil; +import eu.chargetime.ocpp.utilities.SugarUtil; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import java.util.Calendar; +import java.util.Objects; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2016 Thomas Volden + * Copyright (C) 2018 Mikhail Kladkevich + * + * 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. + */ + +/** + * Sent by the Central System to the Charge Point. + */ +@XmlRootElement +@XmlType(propOrder = {"connectorId", "expiryDate", "idTag", "parentIdTag", "reservationId"}) +public class ReserveNowRequest implements Request { + private Integer connectorId; + private Calendar expiryDate; + private String idTag; + private String parentIdTag; + private Integer reservationId; + + public ReserveNowRequest() {} + + public ReserveNowRequest(Integer connectorId, Calendar expiryDate, String idTag, Integer reservationId) { + this.connectorId = connectorId; + this.expiryDate = expiryDate; + this.idTag = idTag; + this.reservationId = reservationId; + } + + @Override + public boolean validate() { + boolean valid = connectorId != null && connectorId >= 0; + valid &= expiryDate != null; + valid &= ModelUtil.validate(idTag, 20); + valid &= reservationId != null; + return valid; + } + + /** + * This contains the id of the connector to be reserved. + * A value of 0 means that the reservation is not for a specific connector. + * + * @return Integer, the destination connectorId. + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Required. + * This contains the id of the connector to be reserved. + * A value of 0 means that the reservation is not for a specific connector. + * + * @param connectorId Integer, the destination connectorId. + */ + @XmlElement + public void setConnectorId(Integer connectorId) throws PropertyConstraintException { + if (connectorId < 0) + throw new PropertyConstraintException("connectorId", connectorId); + + this.connectorId = connectorId; + } + + /** + * This contains the date and time when the reservation ends. + * + * @return Calendar, end of reservation. + */ + public Calendar getExpiryDate() { + return expiryDate; + } + + /** + * Required. + * This contains the date and time when the reservation ends. + * + * @param expiryDate Calendar, end of reservation. + */ + @XmlElement + public void setExpiryDate(Calendar expiryDate) { + this.expiryDate = expiryDate; + } + + /** + * The identifier for which the Charge Point has to reserve a connector. + * + * @return String, the identifier. + */ + public String getIdTag() { + return idTag; + } + + /** + * Required. + * The identifier for which the Charge Point has to reserve a connector. + * + * @param idTag String, the identifier. + */ + @XmlElement + public void setIdTag(String idTag) throws PropertyConstraintException { + if (!ModelUtil.validate(idTag, 20)) + throw new PropertyConstraintException("idTag", idTag, "Exceeded limit"); + this.idTag = idTag; + } + + /** + * The parent idTag. + * + * @return String, the parent identifier. + */ + public String getParentIdTag() { + return parentIdTag; + } + + /** + * Optional. + * The parent idTag. + * + * @param parentIdTag String, the parent identifier. + */ + @XmlElement + public void setParentIdTag(String parentIdTag) throws PropertyConstraintException { + if (!ModelUtil.validate(idTag, 20)) + throw new PropertyConstraintException("idTag", idTag, "Exceeded limit"); + this.parentIdTag = parentIdTag; + } + + /** + * Unique id for this reservation. + * + * @return Integer, id of reservation. + */ + public Integer getReservationId() { + return reservationId; + } + + /** + * Required. + * Unique id for this reservation. + * + * @param reservationId Integer, id of reservation. + */ + @XmlElement + public void setReservationId(Integer reservationId) { + this.reservationId = reservationId; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ReserveNowRequest that = (ReserveNowRequest) o; + return Objects.equals(connectorId, that.connectorId) && + Objects.equals(expiryDate, that.expiryDate) && + Objects.equals(idTag, that.idTag) && + Objects.equals(parentIdTag, that.parentIdTag) && + Objects.equals(reservationId, that.reservationId); + } + + @Override + public int hashCode() { + return Objects.hash(connectorId, expiryDate, idTag, parentIdTag, reservationId); + } + + @Override + public String toString() { + return "ReserveNowRequest{" + + "connectorId=" + connectorId + + ", expiryDate='" + SugarUtil.calendarToString(expiryDate) + + ", idTag='" + idTag + '\'' + + ", parentIdTag='" + parentIdTag + '\'' + + ", reservationId=" + reservationId + + ", isValid=" + String.valueOf(validate()) + + '}'; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/SetChargingProfileRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/SetChargingProfileRequest.java index b94f8b994..bdd463685 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/SetChargingProfileRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/SetChargingProfileRequest.java @@ -39,6 +39,13 @@ public class SetChargingProfileRequest implements Request { private Integer connectorId; private ChargingProfile chargingProfile; + public SetChargingProfileRequest() { } + + public SetChargingProfileRequest(Integer connectorId, ChargingProfile chargingProfile) { + this.connectorId = connectorId; + this.chargingProfile = chargingProfile; + } + /** * This identifies which connector of the Charge Point is used. * @@ -77,7 +84,7 @@ public ChargingProfile getChargingProfile() { * * @param chargingProfile the {@link ChargingProfile}. */ - @XmlElement + @XmlElement(name = "csChargingProfiles") public void setChargingProfile(ChargingProfile chargingProfile) { this.chargingProfile = chargingProfile; } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientFirmwareManagementProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientFirmwareManagementProfileTest.java index d407d6cf3..54076e1e4 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientFirmwareManagementProfileTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientFirmwareManagementProfileTest.java @@ -25,11 +25,10 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.feature.Feature; -import eu.chargetime.ocpp.feature.GetDiagnosticsFeature; +import eu.chargetime.ocpp.feature.*; import eu.chargetime.ocpp.feature.profile.ClientFirmwareManagementEventHandler; import eu.chargetime.ocpp.feature.profile.ClientFirmwareManagementProfile; -import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest; +import eu.chargetime.ocpp.model.firmware.*; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,6 +50,7 @@ public class ClientFirmwareManagementProfileTest extends ProfileTest { ClientFirmwareManagementProfile profile; @Mock + private ClientFirmwareManagementEventHandler handler; @Before @@ -67,6 +67,33 @@ public void getFeatureList_containsGetDiagnosticsFeature() { assertThat(findFeature(features, "GetDiagnostics"), is(instanceOf(GetDiagnosticsFeature.class))); } + @Test + public void getFeatureList_containsDiagnosticsStatusNotificationFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + assertThat(findFeature(features, "DiagnosticsStatusNotification"), is(instanceOf(DiagnosticsStatusNotificationFeature.class))); + } + + @Test + public void getFeatureList_containsFirmwareStatusNotificationFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + assertThat(findFeature(features, "FirmwareStatusNotification"), is(instanceOf(FirmwareStatusNotificationFeature.class))); + } + + @Test + public void getFeatureList_containsUpdateFirmwareFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + assertThat(findFeature(features, "UpdateFirmware"), is(instanceOf(UpdateFirmwareFeature.class))); + } + @Test public void handleRequest_aGetDiagnosticsRequest_callsHandleGetDiagnosticsRequest() { // Given @@ -79,4 +106,41 @@ public void handleRequest_aGetDiagnosticsRequest_callsHandleGetDiagnosticsReques verify(handler, times(1)).handleGetDiagnosticsRequest(eq(request)); } + + @Test + public void handleRequest_aDiagnosticsStatusNotificationRequest_callsHandleDiagnosticsStatusNotificationRequest() { + // Given + DiagnosticsStatusNotificationRequest request = new DiagnosticsStatusNotificationRequest(); + + // When + profile.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleDiagnosticsStatusNotificationRequest(eq(request)); + } + + @Test + public void handleRequest_aFirmwareStatusNotificationRequest_callsHandleFirmwareStatusNotificationRequest() { + // Given + FirmwareStatusNotificationRequest request = new FirmwareStatusNotificationRequest(); + + // When + profile.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleFirmwareStatusNotificationRequest(eq(request)); + } + + @Test + public void handleRequest_aUpdateFirmwareRequest_callsHandleUpdateFirmwareRequest() { + // Given + UpdateFirmwareRequest request = new UpdateFirmwareRequest(); + + // When + profile.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleUpdateFirmwareRequest(eq(request)); + } + } \ No newline at end of file diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientLocalAuthListProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientLocalAuthListProfileTest.java index 1b88e7abc..90de086fc 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientLocalAuthListProfileTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientLocalAuthListProfileTest.java @@ -75,7 +75,7 @@ public void handleRequest_SendLocalList_callsHandleSendLocalListRequest() { profile.handleRequest(SESSION_NULL, request); // Then - verify(handler, times(1)).handleSendLocalListReqeust(eq(request)); + verify(handler, times(1)).handleSendLocalListRequest(eq(request)); } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientReservationProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientReservationProfileTest.java new file mode 100644 index 000000000..1f7ecefdb --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientReservationProfileTest.java @@ -0,0 +1,106 @@ +package eu.chargetime.ocpp.feature.profile.test; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.feature.*; +import eu.chargetime.ocpp.feature.profile.ClientReservationEventHandler; +import eu.chargetime.ocpp.feature.profile.ClientReservationProfile; +import eu.chargetime.ocpp.model.reservation.CancelReservationRequest; +import eu.chargetime.ocpp.model.reservation.ReserveNowRequest; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.util.UUID; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class ClientReservationProfileTest extends ProfileTest { + private static final UUID SESSION_NULL = null; + ClientReservationProfile profile; + + @Mock + private + ClientReservationEventHandler handler; + + @Before + public void setup() { + profile = new ClientReservationProfile(handler); + } + + @Test + public void getFeatureList_containsReserveNowFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + assertThat(findFeature(features, "ReserveNow"), is(instanceOf(ReserveNowFeature.class))); + } + + @Test + public void getFeatureList_containsCancelReservationFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + assertThat(findFeature(features, "CancelReservation"), is(instanceOf(CancelReservationFeature.class))); + } + + @Test + public void handleRequest_aReserveNowRequest_callsHandleReserveNowRequest() { + // Given + ReserveNowRequest request = new ReserveNowRequest(); + + // When + profile.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleReserveNowRequest(eq(request)); + } + + + @Test + public void handleRequest_aCancelReservationRequest_callsHandleCancelReservationRequest() { + // Given + CancelReservationRequest request = new CancelReservationRequest(); + + // When + profile.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleCancelReservationRequest(eq(request)); + } + +} \ No newline at end of file diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerFirmwareManagementProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerFirmwareManagementProfileTest.java index 31355e3a0..0b46cdab5 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerFirmwareManagementProfileTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerFirmwareManagementProfileTest.java @@ -25,9 +25,9 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.feature.Feature; -import eu.chargetime.ocpp.feature.GetDiagnosticsFeature; +import eu.chargetime.ocpp.feature.*; import eu.chargetime.ocpp.feature.profile.ServerFirmwareManagementProfile; +import org.hamcrest.core.Is; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,7 +53,35 @@ public void getFeatureList_containsGetDiagnosticsFeature() { Feature[] features = profile.getFeatureList(); // Then - assertThat(findFeature(features, "GetDiagnostics"), is(instanceOf(GetDiagnosticsFeature.class))); + assertThat(findFeature(features, "GetDiagnostics"), Is.is(instanceOf(GetDiagnosticsFeature.class))); } + @Test + public void getFeatureList_containsDiagnosticsStatusNotificationFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + assertThat(findFeature(features, "DiagnosticsStatusNotification"), Is.is(instanceOf(DiagnosticsStatusNotificationFeature.class))); + } + + @Test + public void getFeatureList_containsFirmwareStatusNotificationFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + assertThat(findFeature(features, "FirmwareStatusNotification"), Is.is(instanceOf(FirmwareStatusNotificationFeature.class))); + } + + @Test + public void getFeatureList_containsUpdateFirmwareFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + assertThat(findFeature(features, "UpdateFirmware"), Is.is(instanceOf(UpdateFirmwareFeature.class))); + } + + } \ No newline at end of file diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerLocalAuthListProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerLocalAuthListProfileTest.java new file mode 100644 index 000000000..31129ce8e --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerLocalAuthListProfileTest.java @@ -0,0 +1,71 @@ +package eu.chargetime.ocpp.feature.profile.test; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.feature.Feature; +import eu.chargetime.ocpp.feature.GetLocalListVersionFeature; +import eu.chargetime.ocpp.feature.SendLocalListFeature; +import eu.chargetime.ocpp.feature.profile.ServerLocalAuthListProfile; +import org.hamcrest.CoreMatchers; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.junit.Assert.assertThat; + +@RunWith(MockitoJUnitRunner.class) +public class ServerLocalAuthListProfileTest extends ProfileTest { + + ServerLocalAuthListProfile profile; + + @Before + public void setup() { + profile = new ServerLocalAuthListProfile(); + } + + @Test + public void getFeatureList_containsGetLocalListVersionFeature() { + // When + Feature[] featureList = profile.getFeatureList(); + + // Then + assertThat(findFeature(featureList, "GetLocalListVersion"), CoreMatchers.is(instanceOf(GetLocalListVersionFeature.class))); + } + + + @Test + public void getFeatureList_containsSendLocalListFeature() { + // When + Feature[] featureList = profile.getFeatureList(); + + // Then + assertThat(findFeature(featureList, "SendLocalList"), CoreMatchers.is(instanceOf(SendLocalListFeature.class))); + } + +} \ No newline at end of file diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerReservationProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerReservationProfileTest.java new file mode 100644 index 000000000..f40371e1d --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerReservationProfileTest.java @@ -0,0 +1,69 @@ +package eu.chargetime.ocpp.feature.profile.test; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.feature.*; +import eu.chargetime.ocpp.feature.profile.ServerReservationProfile; +import org.hamcrest.core.Is; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +@RunWith(MockitoJUnitRunner.class) +public class ServerReservationProfileTest extends ProfileTest { + + ServerReservationProfile profile; + + @Before + public void setup() { + profile = new ServerReservationProfile(); + } + + @Test + public void getFeatureList_containsReserveNowFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + assertThat(findFeature(features, "ReserveNow"), Is.is(instanceOf(ReserveNowFeature.class))); + } + + @Test + public void getFeatureList_containsCancelReservationFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + assertThat(findFeature(features, "CancelReservation"), is(instanceOf(CancelReservationFeature.class))); + } + +} \ No newline at end of file diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/GetDiagnosticsRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/GetDiagnosticsRequestTest.java index 24ead1b07..997801250 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/GetDiagnosticsRequestTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/GetDiagnosticsRequestTest.java @@ -34,7 +34,7 @@ of this software and associated documentation files (the "Software"), to deal public class GetDiagnosticsRequestTest { - GetDiagnosticsRequest request; + private GetDiagnosticsRequest request; @Before public void setup() { diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/UpdateFirmwareConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/UpdateFirmwareConfirmationTest.java new file mode 100644 index 000000000..8b1043571 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/UpdateFirmwareConfirmationTest.java @@ -0,0 +1,55 @@ +package eu.chargetime.ocpp.model.firmware.test; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.model.firmware.UpdateFirmwareConfirmation; +import eu.chargetime.ocpp.utilities.TestUtilities; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class UpdateFirmwareConfirmationTest extends TestUtilities { + + private UpdateFirmwareConfirmation confirmation; + + @Before + public void setup() { + confirmation = new UpdateFirmwareConfirmation(); + } + + @Test + public void validate_returnsTrue() { + // When + boolean result = confirmation.validate(); + + // Then + assertThat(result, is(true)); + } + +} \ No newline at end of file diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/UpdateFirmwareRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/UpdateFirmwareRequestTest.java new file mode 100644 index 000000000..eb376b42f --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/UpdateFirmwareRequestTest.java @@ -0,0 +1,71 @@ +package eu.chargetime.ocpp.model.firmware.test; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.model.firmware.UpdateFirmwareRequest; +import org.junit.Before; +import org.junit.Test; + +import java.util.Calendar; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class UpdateFirmwareRequestTest { + + private UpdateFirmwareRequest request; + + @Before + public void setup() { + request = new UpdateFirmwareRequest(); + } + + @Test + public void validate_locationIsNotSet_returnsFalse() { + // When + boolean result = request.validate(); + + // Then + assertThat(result, is(false)); + } + + @Test + public void validate_locationAndRetrieveDateIsSet_returnsTrue() { + // Given + String aLocation = "/"; + Calendar aRetrieveDate = Calendar.getInstance(); + request.setLocation(aLocation); + request.setRetrieveDate(aRetrieveDate); + + // When + boolean result = request.validate(); + + // Then + assertThat(result, is(true)); + } + +} \ No newline at end of file diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/localauthlist/test/GetLocalListVersionConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/localauthlist/test/GetLocalListVersionConfirmationTest.java index 315dd48f9..039191a28 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/localauthlist/test/GetLocalListVersionConfirmationTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/localauthlist/test/GetLocalListVersionConfirmationTest.java @@ -13,7 +13,7 @@ @RunWith(MockitoJUnitRunner.class) public class GetLocalListVersionConfirmationTest { - GetLocalListVersionConfirmation confirmation; + private GetLocalListVersionConfirmation confirmation; @Before public void setUp() { diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/localauthlist/test/SendLocalListConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/localauthlist/test/SendLocalListConfirmationTest.java index f99771259..5c1c0f1c8 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/localauthlist/test/SendLocalListConfirmationTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/localauthlist/test/SendLocalListConfirmationTest.java @@ -3,6 +3,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; +import eu.chargetime.ocpp.PropertyConstraintException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -21,7 +22,7 @@ public void setUp() { } @Test - public void setStatus_allStatus_allCorrect() { + public void setStatus_allStatus_allCorrect() throws PropertyConstraintException { for(UpdateStatus status : UpdateStatus.values()) { // When diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/CancelReservationConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/CancelReservationConfirmationTest.java new file mode 100644 index 000000000..8be23c78b --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/CancelReservationConfirmationTest.java @@ -0,0 +1,68 @@ +package eu.chargetime.ocpp.model.reservation.test; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.model.reservation.CancelReservationConfirmation; +import eu.chargetime.ocpp.model.reservation.CancelReservationStatus; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class CancelReservationConfirmationTest { + + private CancelReservationConfirmation request; + + @Before + public void setup() { + request = new CancelReservationConfirmation(); + } + + @Test + public void validate_statusIsNotSet_returnsFalse() { + // When + boolean result = request.validate(); + + // Then + assertThat(result, is(false)); + } + + @Test + public void validate_statusIsSet_returnsTrue() { + // Given + CancelReservationStatus status = CancelReservationStatus.Accepted; + request.setStatus(status); + + // When + boolean result = request.validate(); + + // Then + assertThat(result, is(true)); + } + +} \ No newline at end of file diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/CancelReservationRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/CancelReservationRequestTest.java new file mode 100644 index 000000000..f549cef4a --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/CancelReservationRequestTest.java @@ -0,0 +1,68 @@ +package eu.chargetime.ocpp.model.reservation.test; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.reservation.CancelReservationRequest; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class CancelReservationRequestTest { + + private CancelReservationRequest request; + + @Before + public void setup() { + request = new CancelReservationRequest(); + } + + @Test + public void validate_statusIsNotSet_returnsFalse() { + // When + boolean result = request.validate(); + + // Then + assertThat(result, is(false)); + } + + @Test + public void validate_reservationIdIsSet_returnsTrue() { + // Given + Integer reservationId = 1; + request.setReservationId(reservationId); + + // When + boolean result = request.validate(); + + // Then + assertThat(result, is(true)); + } + +} \ No newline at end of file diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/ReserveNowConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/ReserveNowConfirmationTest.java new file mode 100644 index 000000000..c6df53f5a --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/ReserveNowConfirmationTest.java @@ -0,0 +1,74 @@ +package eu.chargetime.ocpp.model.reservation.test; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.reservation.ReservationStatus; +import eu.chargetime.ocpp.model.reservation.ReserveNowConfirmation; +import eu.chargetime.ocpp.utilities.TestUtilities; +import org.hamcrest.CoreMatchers; +import org.junit.Before; +import org.junit.Test; + +import java.util.Calendar; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class ReserveNowConfirmationTest extends TestUtilities { + + private ReserveNowConfirmation confirmation; + + @Before + public void setup() { + confirmation = new ReserveNowConfirmation(); + } + + @Test + public void validate_statusIsNotSet_returnsFalse() { + // When + boolean result = confirmation.validate(); + + // Then + assertThat(result, CoreMatchers.is(false)); + } + + @Test + public void validate_statusIsSet_returnsTrue() { + // Given + ReservationStatus status = ReservationStatus.Occupied; + + confirmation.setStatus(status); + + // When + boolean result = confirmation.validate(); + + // Then + assertThat(result, CoreMatchers.is(true)); + } + +} \ No newline at end of file diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/ReserveNowRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/ReserveNowRequestTest.java new file mode 100644 index 000000000..7407c8f74 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/reservation/test/ReserveNowRequestTest.java @@ -0,0 +1,77 @@ +package eu.chargetime.ocpp.model.reservation.test; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2018 Mikhail Kladkevich + + 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 eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.reservation.ReserveNowRequest; +import org.junit.Before; +import org.junit.Test; + +import java.util.Calendar; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class ReserveNowRequestTest { + + private ReserveNowRequest request; + + @Before + public void setup() { + request = new ReserveNowRequest(); + } + + @Test + public void validate_statusIsNotSet_returnsFalse() { + // When + boolean result = request.validate(); + + // Then + assertThat(result, is(false)); + } + + @Test + public void validate_requiredFieldsAreSet_returnTrue() throws PropertyConstraintException { + // Given + Integer connectorId = 0; + Calendar expiryDate = Calendar.getInstance(); + String idTag = "row"; + Integer reservationId = 2; + + request.setConnectorId(connectorId); + request.setExpiryDate(expiryDate); + request.setIdTag(idTag); + request.setReservationId(reservationId); + + // When + boolean result = request.validate(); + + // Then + assertThat(result, is(true)); + } + +} \ No newline at end of file