From 448d6e5c56f90aabbb9dcaaabdb32f6c451fb0af Mon Sep 17 00:00:00 2001 From: Mikhail Kladkevich Date: Sun, 15 Apr 2018 13:28:05 +0300 Subject: [PATCH] Add DiagnosticsStatusNotification support. --- .../ocpp/test/FakeCentralSystem.java | 16 ++- .../chargetime/ocpp/test/FakeChargePoint.java | 8 ++ ...ONDiagnosticsStatusNotificationSpec.groovy | 72 ++++++++++++ .../DiagnosticsStatusNotificationFeature.java | 56 +++++++++ .../ClientFirmwareManagementEventHandler.java | 5 + .../ClientFirmwareManagementProfile.java | 5 + .../ServerFirmwareManagementProfile.java | 2 + .../model/firmware/DiagnosticsStatus.java | 37 ++++++ ...nosticsStatusNotificationConfirmation.java | 61 ++++++++++ .../DiagnosticsStatusNotificationRequest.java | 108 ++++++++++++++++++ ...icsStatusNotificationConfirmationTest.java | 54 +++++++++ ...gnosticsStatusNotificationRequestTest.java | 68 +++++++++++ 12 files changed, 489 insertions(+), 3 deletions(-) create mode 100644 ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/firmware/json/JSONDiagnosticsStatusNotificationSpec.groovy create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/DiagnosticsStatusNotificationFeature.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatus.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatusNotificationConfirmation.java create mode 100644 ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatusNotificationRequest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/DiagnosticsStatusNotificationConfirmationTest.java create mode 100644 ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/DiagnosticsStatusNotificationRequestTest.java 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 09c9bfb41..552a23463 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 @@ -36,8 +36,7 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.feature.profile.ServerSmartChargingProfile; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.core.*; -import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation; -import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest; +import eu.chargetime.ocpp.model.firmware.*; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequestType; import eu.chargetime.ocpp.test.FakeCentral.serverType; @@ -45,7 +44,7 @@ of this software and associated documentation files (the "Software"), to deal public class FakeCentralSystem { private IServerAPI server; - DummyHandlers dummyHandlers; + private DummyHandlers dummyHandlers; private boolean isStarted; FakeCentralSystem(serverType type) { @@ -123,6 +122,11 @@ public boolean hasReceivedGetDiagnosticsConfirmation() { return dummyHandlers.wasLatestConfirmation(GetDiagnosticsConfirmation.class); } + + public boolean hasReceivedDiagnosticsStatusNotificationConfirmation() { + return dummyHandlers.wasLatestConfirmation(DiagnosticsStatusNotificationConfirmation.class); + } + public boolean hasReceivedChangeAvailabilityConfirmation(String status) { boolean result = false; ChangeAvailabilityConfirmation confirmation = dummyHandlers.getReceivedConfirmation(new ChangeAvailabilityConfirmation()); @@ -226,6 +230,12 @@ public void sendGetDiagnosticsRequest(String location) throws Exception { send(request); } + + public void sendDiagnosticsStatusNotificationRequest(DiagnosticsStatus status) throws Exception { + DiagnosticsStatusNotificationRequest request = new DiagnosticsStatusNotificationRequest(status); + 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 bdef3d001..df46b7020 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 @@ -5,6 +5,8 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.core.*; +import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationConfirmation; +import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest; import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation; import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageConfirmation; @@ -149,6 +151,12 @@ public GetDiagnosticsConfirmation handleGetDiagnosticsRequest(GetDiagnosticsRequ receivedRequest = request; return new GetDiagnosticsConfirmation(); } + + @Override + public DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(DiagnosticsStatusNotificationRequest request) { + receivedRequest = request; + return new DiagnosticsStatusNotificationConfirmation(); + } }); switch (type) { diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/firmware/json/JSONDiagnosticsStatusNotificationSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/firmware/json/JSONDiagnosticsStatusNotificationSpec.groovy new file mode 100644 index 000000000..8a38fad7b --- /dev/null +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/firmware/json/JSONDiagnosticsStatusNotificationSpec.groovy @@ -0,0 +1,72 @@ +package eu.chargetime.ocpp.test.firmware.json + +import eu.chargetime.ocpp.model.firmware.DiagnosticsStatus +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 + + 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 JSONDiagnosticsStatusNotificationSpec 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 DiagnosticsStatusNotification request and receives a response"() { + def conditions = new PollingConditions(timeout: 1) + given: + conditions.eventually { + assert centralSystem.connected() + } + + when: + centralSystem.sendDiagnosticsStatusNotificationRequest(DiagnosticsStatus.Uploading) + + then: + conditions.eventually { + assert chargePoint.hasHandledDiagnosticsStatusNotificationRequest() + assert centralSystem.hasReceivedDiagnosticsStatusNotificationConfirmation() + } + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/DiagnosticsStatusNotificationFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/DiagnosticsStatusNotificationFeature.java new file mode 100644 index 000000000..abc003620 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/DiagnosticsStatusNotificationFeature.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.DiagnosticsStatusNotificationConfirmation; +import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest; + +/* + ChargeTime.eu - Java-OCA-OCPP + Copyright (C) 2015-2016 Thomas Volden + + 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. + */ + +public class DiagnosticsStatusNotificationFeature extends Feature { + + public DiagnosticsStatusNotificationFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return DiagnosticsStatusNotificationRequest.class; + } + + @Override + public Class getConfirmationType() { + return DiagnosticsStatusNotificationConfirmation.class; + } + + @Override + public String getAction() { + return "DiagnosticsStatusNotification"; + } +} 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 62090d842..d297f4d1b 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 @@ -25,9 +25,14 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ +import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationConfirmation; +import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest; import eu.chargetime.ocpp.model.firmware.GetDiagnosticsConfirmation; import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest; public interface ClientFirmwareManagementEventHandler { GetDiagnosticsConfirmation handleGetDiagnosticsRequest(GetDiagnosticsRequest request); + + DiagnosticsStatusNotificationConfirmation handleDiagnosticsStatusNotificationRequest(DiagnosticsStatusNotificationRequest 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 ccbde50ef..4999fa55b 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,10 +24,12 @@ 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.GetDiagnosticsFeature; 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.GetDiagnosticsRequest; import java.util.HashSet; @@ -42,6 +44,7 @@ public ClientFirmwareManagementProfile(ClientFirmwareManagementEventHandler even this.eventHandler = eventHandler; features = new HashSet<>(); features.add(new GetDiagnosticsFeature(this)); + features.add(new DiagnosticsStatusNotificationFeature(this)); } @Override @@ -55,6 +58,8 @@ public Confirmation handleRequest(UUID sessionIndex, Request request) { if (request instanceof GetDiagnosticsRequest) { result = eventHandler.handleGetDiagnosticsRequest((GetDiagnosticsRequest) request); + } else if (request instanceof DiagnosticsStatusNotificationRequest) { + result = eventHandler.handleDiagnosticsStatusNotificationRequest((DiagnosticsStatusNotificationRequest) 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 5a1fa3126..de26e33c5 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,6 +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.GetDiagnosticsFeature; import eu.chargetime.ocpp.model.Confirmation; @@ -40,6 +41,7 @@ public class ServerFirmwareManagementProfile implements Profile { public ServerFirmwareManagementProfile() { features = new HashSet<>(); features.add(new GetDiagnosticsFeature(this)); + features.add(new DiagnosticsStatusNotificationFeature(this)); } @Override diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatus.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatus.java new file mode 100644 index 000000000..871eef202 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatus.java @@ -0,0 +1,37 @@ +package eu.chargetime.ocpp.model.firmware; + +/* + * 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. + */ + +/** + * Accepted values used with {@link DiagnosticsStatusNotificationRequest}. + */ +public enum DiagnosticsStatus { + Idle, + Uploaded, + UploadFailed, + Uploading +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatusNotificationConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatusNotificationConfirmation.java new file mode 100644 index 000000000..1cb5c03b3 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatusNotificationConfirmation.java @@ -0,0 +1,61 @@ +package eu.chargetime.ocpp.model.firmware; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2016 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.model.Confirmation; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Sent by the Charge Point to the Central System in response to an {@link DiagnosticsStatusNotificationRequest}. + */ +@XmlRootElement(name = "diagnosticsStatusNotificationResponse") +public class DiagnosticsStatusNotificationConfirmation implements Confirmation { + + public DiagnosticsStatusNotificationConfirmation() { + } + + @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 5; + } + + @Override + public String toString() { + return "DiagnosticsStatusNotificationConfirmation{}" + "{isValid=" + String.valueOf(validate()) + "}"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatusNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatusNotificationRequest.java new file mode 100644 index 000000000..97f4f6008 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/DiagnosticsStatusNotificationRequest.java @@ -0,0 +1,108 @@ +package eu.chargetime.ocpp.model.firmware; + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.Request; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import java.util.Objects; + +/* + * 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. + */ + +/** + * Sent by the Central System to the Charge Point. + */ +@XmlRootElement +public class DiagnosticsStatusNotificationRequest implements Request { + private DiagnosticsStatus status; + + public DiagnosticsStatusNotificationRequest() { } + + /** + * Set required fields. + * + * @param status Diagnostics status, see {@link #setStatus(DiagnosticsStatus)}. + */ + public DiagnosticsStatusNotificationRequest(DiagnosticsStatus status) { + this.status = status; + } + + @Override + public boolean validate() { + return status != null; + } + + /** + * This contains the status. + * + * @return connector. + */ + public DiagnosticsStatus getStatus() { + return status; + } + + /** + * Required. This contains the identifier of the status. + * + * @param status DiagnosticsStatus, value != 0. + * @throws PropertyConstraintException Value was zero or negative. + */ + @XmlElement + public void setStatus(DiagnosticsStatus status) throws PropertyConstraintException { + if (status == null) + throw new PropertyConstraintException("status", null); + + this.status = status; + } + + @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; + DiagnosticsStatusNotificationRequest that = (DiagnosticsStatusNotificationRequest) o; + return status == that.status; + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return "DiagnosticsStatusNotificationRequest{" + + "status=" + status + + ", isValid=" + String.valueOf(validate()) + + '}'; + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/DiagnosticsStatusNotificationConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/DiagnosticsStatusNotificationConfirmationTest.java new file mode 100644 index 000000000..40823b7d3 --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/DiagnosticsStatusNotificationConfirmationTest.java @@ -0,0 +1,54 @@ +package eu.chargetime.ocpp.model.firmware.test; +/* + 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.model.firmware.DiagnosticsStatusNotificationConfirmation; +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 DiagnosticsStatusNotificationConfirmationTest extends TestUtilities { + + private DiagnosticsStatusNotificationConfirmation confirmation; + + @Before + public void setup() { + confirmation = new DiagnosticsStatusNotificationConfirmation(); + } + + @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/DiagnosticsStatusNotificationRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/DiagnosticsStatusNotificationRequestTest.java new file mode 100644 index 000000000..5b3c536fb --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/firmware/test/DiagnosticsStatusNotificationRequestTest.java @@ -0,0 +1,68 @@ +package eu.chargetime.ocpp.model.firmware.test; +/* + 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.PropertyConstraintException; +import eu.chargetime.ocpp.model.firmware.DiagnosticsStatus; +import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class DiagnosticsStatusNotificationRequestTest { + + private DiagnosticsStatusNotificationRequest request; + + @Before + public void setup() { + request = new DiagnosticsStatusNotificationRequest(); + } + + @Test + public void validate_statusIsNotSet_returnsFalse() { + // When + boolean result = request.validate(); + + // Then + assertThat(result, is(false)); + } + + @Test + public void validate_statusIsSet_returnsTrue() throws PropertyConstraintException { + // Given + DiagnosticsStatus status = DiagnosticsStatus.Uploading; + request.setStatus(status); + + // When + boolean result = request.validate(); + + // Then + assertThat(result, is(true)); + } + +} \ No newline at end of file