From 985079f03779b411def139c2f9c5fb136606549c Mon Sep 17 00:00:00 2001 From: Mikhail Kladkevich Date: Sun, 15 Apr 2018 13:28:05 +0300 Subject: [PATCH] Add DiagnosticsStatusNotification support. --- .../DiagnosticsStatusNotificationFeature.java | 56 +++++++++ .../model/firmware/DiagnosticsStatus.java | 37 ++++++ ...nosticsStatusNotificationConfirmation.java | 61 ++++++++++ .../DiagnosticsStatusNotificationRequest.java | 108 ++++++++++++++++++ ...icsStatusNotificationConfirmationTest.java | 54 +++++++++ ...gnosticsStatusNotificationRequestTest.java | 68 +++++++++++ 6 files changed, 384 insertions(+) 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/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/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