diff --git a/.gitignore b/.gitignore index 6ead492e3..f677b8b3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,232 @@ -/.idea -target -build -java-docs -*.project -*.settings/ -*.classpath - -# Should be ignored when using IDE-independent build system such as Maven or Gradle + +# Created by https://www.gitignore.io/api/git,java,maven,gradle,eclipse,intellij+all +# Edit at https://www.gitignore.io/?templates=git,java,maven,gradle,eclipse,intellij+all + +### Eclipse ### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +### Eclipse Patch ### +# Eclipse Core +.project + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Annotation Processing +.apt_generated + +.sts4-cache/ + +### Git ### +# Created by git for backups. To disable backups in Git: +# $ git config --global mergetool.keepBackup false +*.orig + +# Created by git when using merge tools for conflicts +*.BACKUP.* +*.BASE.* +*.LOCAL.* +*.REMOTE.* +*_BACKUP_*.txt +*_BASE_*.txt +*_LOCAL_*.txt +*_REMOTE_*.txt + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + .idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + *.iml -/.gradle -*/build +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar +.flattened-pom.xml + +### Gradle ### +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + +### Gradle Patch ### +**/build/ + +# End of https://www.gitignore.io/api/git,java,maven,gradle,eclipse,intellij+all diff --git a/OCPP-J/src/main/java/eu/chargetime/ocpp/JSONCommunicator.java b/OCPP-J/src/main/java/eu/chargetime/ocpp/JSONCommunicator.java index c781a38d0..ad2f746c6 100644 --- a/OCPP-J/src/main/java/eu/chargetime/ocpp/JSONCommunicator.java +++ b/OCPP-J/src/main/java/eu/chargetime/ocpp/JSONCommunicator.java @@ -5,23 +5,21 @@ import eu.chargetime.ocpp.model.CallMessage; import eu.chargetime.ocpp.model.CallResultMessage; import eu.chargetime.ocpp.model.Message; -import java.lang.reflect.Type; -import java.text.SimpleDateFormat; -import java.time.ZonedDateTime; -import java.time.format.DateTimeParseException; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.TimeZone; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.reflect.Type; +import java.time.ZonedDateTime; + /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -42,122 +40,119 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -/** Communicator for JSON messages */ +/** + * Communicator for JSON messages + */ public class JSONCommunicator extends Communicator { - private static final Logger logger = LoggerFactory.getLogger(JSONCommunicator.class); - - private static final int INDEX_MESSAGEID = 0; - private static final int TYPENUMBER_CALL = 2; - private static final int INDEX_CALL_ACTION = 2; - private static final int INDEX_CALL_PAYLOAD = 3; - - private static final int TYPENUMBER_CALLRESULT = 3; - private static final int INDEX_CALLRESULT_PAYLOAD = 2; - - private static final int TYPENUMBER_CALLERROR = 4; - private static final int INDEX_CALLERROR_ERRORCODE = 2; - private static final int INDEX_CALLERROR_DESCRIPTION = 3; - private static final int INDEX_CALLERROR_PAYLOAD = 4; - - private static final int INDEX_UNIQUEID = 1; - private static final String CALL_FORMAT = "[2,\"%s\",\"%s\",%s]"; - private static final String CALLRESULT_FORMAT = "[3,\"%s\",%s]"; - private static final String CALLERROR_FORMAT = "[4,\"%s\",\"%s\",\"%s\",%s]"; - private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - private static final String DATE_FORMAT_WITH_MS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; - private static final int DATE_FORMAT_WITH_MS_LENGTH = 24; - - private boolean hasLongDateFormat = false; - - /** - * Handle required injections. - * - * @param radio instance of the {@link Radio}. - */ - public JSONCommunicator(Radio radio) { - super(radio); - } - - @Override - public T unpackPayload(Object payload, Class type) throws Exception { - GsonBuilder builder = new GsonBuilder(); - builder.registerTypeAdapter(Calendar.class, new CalendarDeserializer()); - Gson gson = builder.create(); - return gson.fromJson(payload.toString(), type); - } - - @Override - public Object packPayload(Object payload) { - GsonBuilder builder = new GsonBuilder(); - builder.registerTypeAdapter(GregorianCalendar.class, new CalendarSerializer()); - Gson gson = builder.create(); - return gson.toJson(payload); - } - - private class CalendarSerializer implements JsonSerializer { - public JsonElement serialize(Calendar src, Type typeOfSrc, JsonSerializationContext context) { - SimpleDateFormat formatter = - new SimpleDateFormat(hasLongDateFormat ? DATE_FORMAT_WITH_MS : DATE_FORMAT); - formatter.setTimeZone(TimeZone.getTimeZone("GMT+00:00")); - return new JsonPrimitive(formatter.format(src.getTime())); + private static final Logger logger = LoggerFactory.getLogger(JSONCommunicator.class); + + private static final int INDEX_MESSAGEID = 0; + private static final int TYPENUMBER_CALL = 2; + private static final int INDEX_CALL_ACTION = 2; + private static final int INDEX_CALL_PAYLOAD = 3; + + private static final int TYPENUMBER_CALLRESULT = 3; + private static final int INDEX_CALLRESULT_PAYLOAD = 2; + + private static final int TYPENUMBER_CALLERROR = 4; + private static final int INDEX_CALLERROR_ERRORCODE = 2; + private static final int INDEX_CALLERROR_DESCRIPTION = 3; + private static final int INDEX_CALLERROR_PAYLOAD = 4; + + private static final int INDEX_UNIQUEID = 1; + private static final String CALL_FORMAT = "[2,\"%s\",\"%s\",%s]"; + private static final String CALLRESULT_FORMAT = "[3,\"%s\",%s]"; + private static final String CALLERROR_FORMAT = "[4,\"%s\",\"%s\",\"%s\",%s]"; + private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + private static final String DATE_FORMAT_WITH_MS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; + private static final int DATE_FORMAT_WITH_MS_LENGTH = 24; + + private boolean hasLongDateFormat = false; + + /** + * Handle required injections. + * + * @param radio instance of the {@link Radio}. + */ + public JSONCommunicator(Radio radio) { + super(radio); } - } - - private class CalendarDeserializer implements JsonDeserializer { - public Calendar deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { - try { - String dateString = json.getAsJsonPrimitive().getAsString(); - return GregorianCalendar.from(ZonedDateTime.parse(dateString)); - } catch (DateTimeParseException e) { - throw new JsonParseException(e); - } + + private class ZonedDateTimeSerializer implements JsonSerializer { + + @Override + public JsonElement serialize(ZonedDateTime zonedDateTime, Type type, JsonSerializationContext jsonSerializationContext) { + return new JsonPrimitive(zonedDateTime.toString()); + } } - } - - @Override - protected Object makeCallResult(String uniqueId, String action, Object payload) { - return String.format(CALLRESULT_FORMAT, uniqueId, payload); - } - - @Override - protected Object makeCall(String uniqueId, String action, Object payload) { - return String.format(CALL_FORMAT, uniqueId, action, payload); - } - - @Override - protected Object makeCallError( - String uniqueId, String action, String errorCode, String errorDescription) { - return String.format(CALLERROR_FORMAT, uniqueId, errorCode, errorDescription, "{}"); - } - - @Override - protected Message parse(Object json) { - Message message; - JsonParser parser = new JsonParser(); - JsonArray array = parser.parse(json.toString()).getAsJsonArray(); - - if (array.get(INDEX_MESSAGEID).getAsInt() == TYPENUMBER_CALL) { - message = new CallMessage(); - message.setAction(array.get(INDEX_CALL_ACTION).getAsString()); - message.setPayload(array.get(INDEX_CALL_PAYLOAD).toString()); - } else if (array.get(INDEX_MESSAGEID).getAsInt() == TYPENUMBER_CALLRESULT) { - message = new CallResultMessage(); - message.setPayload(array.get(INDEX_CALLRESULT_PAYLOAD).toString()); - } else if (array.get(INDEX_MESSAGEID).getAsInt() == TYPENUMBER_CALLERROR) { - message = new CallErrorMessage(); - ((CallErrorMessage) message).setErrorCode(array.get(INDEX_CALLERROR_ERRORCODE).getAsString()); - ((CallErrorMessage) message) - .setErrorDescription(array.get(INDEX_CALLERROR_DESCRIPTION).getAsString()); - ((CallErrorMessage) message).setRawPayload(array.get(INDEX_CALLERROR_PAYLOAD).toString()); - } else { - logger.error("Unknown message type of message: {}", json.toString()); - throw new IllegalArgumentException("Unknown message type"); + + public class ZonedDateTimeDeserializer implements JsonDeserializer { + + @Override + public ZonedDateTime deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { + return ZonedDateTime.parse(jsonElement.getAsJsonPrimitive().getAsString()); + } } - message.setId(array.get(INDEX_UNIQUEID).getAsString()); + @Override + public T unpackPayload(Object payload, Class type) throws Exception { + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeDeserializer()); + Gson gson = builder.create(); + return gson.fromJson(payload.toString(), type); + } - return message; - } + @Override + public Object packPayload(Object payload) { + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()); + Gson gson = builder.create(); + return gson.toJson(payload); + } + + @Override + protected Object makeCallResult(String uniqueId, String action, Object payload) { + return String.format(CALLRESULT_FORMAT, uniqueId, payload); + } + + @Override + protected Object makeCall(String uniqueId, String action, Object payload) { + return String.format(CALL_FORMAT, uniqueId, action, payload); + } + + @Override + protected Object makeCallError( + String uniqueId, String action, String errorCode, String errorDescription) { + return String.format(CALLERROR_FORMAT, uniqueId, errorCode, errorDescription, "{}"); + } + + @Override + protected Message parse(Object json) { + Message message; + JsonParser parser = new JsonParser(); + JsonArray array = parser.parse(json.toString()).getAsJsonArray(); + + if (array.get(INDEX_MESSAGEID).getAsInt() == TYPENUMBER_CALL) { + message = new CallMessage(); + message.setAction(array.get(INDEX_CALL_ACTION).getAsString()); + message.setPayload(array.get(INDEX_CALL_PAYLOAD).toString()); + } else if (array.get(INDEX_MESSAGEID).getAsInt() == TYPENUMBER_CALLRESULT) { + message = new CallResultMessage(); + message.setPayload(array.get(INDEX_CALLRESULT_PAYLOAD).toString()); + } else if (array.get(INDEX_MESSAGEID).getAsInt() == TYPENUMBER_CALLERROR) { + message = new CallErrorMessage(); + ((CallErrorMessage) message).setErrorCode(array.get(INDEX_CALLERROR_ERRORCODE).getAsString()); + ((CallErrorMessage) message) + .setErrorDescription(array.get(INDEX_CALLERROR_DESCRIPTION).getAsString()); + ((CallErrorMessage) message).setRawPayload(array.get(INDEX_CALLERROR_PAYLOAD).toString()); + } else { + logger.error("Unknown message type of message: {}", json.toString()); + throw new IllegalArgumentException("Unknown message type"); + } + + message.setId(array.get(INDEX_UNIQUEID).getAsString()); + + return message; + } } diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/ocpp-common/build.gradle b/ocpp-common/build.gradle index 97e1f7761..93e0bf579 100644 --- a/ocpp-common/build.gradle +++ b/ocpp-common/build.gradle @@ -2,10 +2,11 @@ dependencies { compile 'org.slf4j:slf4j-api:1.7.25' compile 'ch.qos.logback:logback-classic:1.2.3' + compile group: 'javax.xml.soap', name: 'javax.xml.soap-api', version: '1.4.0' testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' testCompile 'org.hamcrest:hamcrest-all:1.3' } -description = 'Java-OCA-OCPP Common' \ No newline at end of file +description = 'Java-OCA-OCPP Common' diff --git a/ocpp-common/src/main/java/eu/chargetime/ocpp/ZonedDateTimeAdapter.java b/ocpp-common/src/main/java/eu/chargetime/ocpp/ZonedDateTimeAdapter.java new file mode 100644 index 000000000..5cb67bc5d --- /dev/null +++ b/ocpp-common/src/main/java/eu/chargetime/ocpp/ZonedDateTimeAdapter.java @@ -0,0 +1,43 @@ +package eu.chargetime.ocpp; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.time.ZonedDateTime; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2019 Kevin Raddatz + * + * 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 ZonedDateTimeAdapter extends XmlAdapter { + + @Override + public ZonedDateTime unmarshal(String s) throws Exception { + return ZonedDateTime.parse(s); + } + + @Override + public String marshal(ZonedDateTime ZonedDateTime) throws Exception { + return ZonedDateTime.toString(); + } +} diff --git a/ocpp-common/src/main/java/eu/chargetime/ocpp/model/TestModel.java b/ocpp-common/src/main/java/eu/chargetime/ocpp/model/TestModel.java index 0aa5c0ad7..c4438eb16 100644 --- a/ocpp-common/src/main/java/eu/chargetime/ocpp/model/TestModel.java +++ b/ocpp-common/src/main/java/eu/chargetime/ocpp/model/TestModel.java @@ -1,16 +1,18 @@ package eu.chargetime.ocpp.model; -import java.util.Calendar; +import java.time.ZonedDateTime; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -35,7 +37,7 @@ of this software and associated documentation files (the "Software"), to deal @XmlRootElement public class TestModel { private String stringTest; - private Calendar calendarTest; + private ZonedDateTime calendarTest; private Integer integerTest; private int intTest; private Long longTest; @@ -137,12 +139,12 @@ public void setIntegerTest(Integer integerTest) { this.integerTest = integerTest; } - public Calendar getCalendarTest() { + public ZonedDateTime getCalendarTest() { return calendarTest; } @XmlElement - public void setCalendarTest(Calendar calendarTest) { + public void setCalendarTest(ZonedDateTime calendarTest) { this.calendarTest = calendarTest; } diff --git a/ocpp-common/src/main/java/eu/chargetime/ocpp/utilities/MoreObjects.java b/ocpp-common/src/main/java/eu/chargetime/ocpp/utilities/MoreObjects.java index 1b0fd31ad..93f57b79a 100644 --- a/ocpp-common/src/main/java/eu/chargetime/ocpp/utilities/MoreObjects.java +++ b/ocpp-common/src/main/java/eu/chargetime/ocpp/utilities/MoreObjects.java @@ -4,6 +4,7 @@ * Copyright (C) 2014 The Guava Authors * * Modified by Evgeny Pakhomov + * Copyright (C) 2019 Kevin Raddatz * * Changes: * * Cut Guava specific annotations @@ -22,6 +23,7 @@ * the License. */ +import java.time.ZonedDateTime; import java.util.*; /** @@ -287,7 +289,7 @@ public ToStringHelper add(String name, Object value) { * @param value field value * @return ToStringHelper instance */ - public ToStringHelper add(String name, Calendar value) { + public ToStringHelper add(String name, ZonedDateTime value) { helperImplementation.add(name, value); return this; } @@ -736,7 +738,7 @@ public ToStringHelperImpl add(String name, Object value) { } /** Adds a name/value pair to the formatted output in {@code name=value} format. */ - public ToStringHelperImpl add(String name, Calendar value) { + public ToStringHelperImpl add(String name, ZonedDateTime value) { return addHolder(name, value); } @@ -896,9 +898,9 @@ private ToStringHelperImpl addHolder(String name, Object value) { return this; } - private ToStringHelperImpl addHolder(String name, Calendar value) { + private ToStringHelperImpl addHolder(String name, ZonedDateTime value) { ValueHolder valueHolder = addHolder(); - valueHolder.value = "\"" + SugarUtil.calendarToString(value) + "\""; + valueHolder.value = "\"" + SugarUtil.zonedDateTimeToString(value) + "\""; valueHolder.name = name; return this; } 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 index 1b7c7f4ee..598334d78 100644 --- a/ocpp-common/src/main/java/eu/chargetime/ocpp/utilities/SugarUtil.java +++ b/ocpp-common/src/main/java/eu/chargetime/ocpp/utilities/SugarUtil.java @@ -6,6 +6,7 @@ Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2018 Mikhail Kladkevich + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,8 +30,7 @@ of this software and associated documentation files (the "Software"), to deal import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.StringWriter; -import java.text.SimpleDateFormat; -import java.util.Calendar; +import java.time.ZonedDateTime; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPMessage; import javax.xml.transform.Transformer; @@ -41,9 +41,9 @@ of this software and associated documentation files (the "Software"), to deal 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()); + public static String zonedDateTimeToString(ZonedDateTime zonedDateTime) { + if (zonedDateTime == null) return ""; + return zonedDateTime.toString(); } public static String docToString(Document doc) { diff --git a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java index 118f3ccae..316da97a0 100644 --- a/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java +++ b/ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/DummyHandlers.java @@ -5,6 +5,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -37,7 +38,7 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationConfirmation; import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest; import java.lang.reflect.Type; -import java.util.Calendar; +import java.time.ZonedDateTime; import java.util.UUID; import java.util.function.BiConsumer; @@ -60,8 +61,7 @@ public AuthorizeConfirmation handleAuthorizeRequest( AuthorizeConfirmation confirmation = new AuthorizeConfirmation(); IdTagInfo tagInfo = new IdTagInfo(); tagInfo.setStatus(AuthorizationStatus.Accepted); - Calendar calendar = Calendar.getInstance(); - calendar.set(2018, 1, 1, 1, 1, 1); + ZonedDateTime calendar = ZonedDateTime.parse("2018-01-01T01:01:01.988Z"); tagInfo.setExpiryDate(calendar); confirmation.setIdTagInfo(tagInfo); return failurePoint(confirmation); @@ -77,7 +77,7 @@ public BootNotificationConfirmation handleBootNotificationRequest( } catch (Exception e) { e.printStackTrace(); } - confirmation.setCurrentTime(Calendar.getInstance()); + confirmation.setCurrentTime(ZonedDateTime.now()); confirmation.setStatus(RegistrationStatus.Accepted); return failurePoint(confirmation); } @@ -96,7 +96,7 @@ public HeartbeatConfirmation handleHeartbeatRequest( UUID sessionIndex, HeartbeatRequest request) { receivedRequest = request; HeartbeatConfirmation confirmation = new HeartbeatConfirmation(); - confirmation.setCurrentTime(Calendar.getInstance()); + confirmation.setCurrentTime(ZonedDateTime.now()); return failurePoint(confirmation); } 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 388f9f9c0..58b5d996d 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 @@ -6,6 +6,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -43,10 +44,11 @@ of this software and associated documentation files (the "Software"), to deal 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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.time.ZonedDateTime; + public class FakeCentralSystem { private static final Logger logger = LoggerFactory.getLogger(FakeCentralSystem.class); @@ -309,13 +311,13 @@ public void sendGetDiagnosticsRequest(String location) throws Exception { send(request); } - public void sendUpdateFirmwareRequest(String location, Calendar retrieveDate) throws Exception { + public void sendUpdateFirmwareRequest(String location, ZonedDateTime retrieveDate) throws Exception { UpdateFirmwareRequest request = new UpdateFirmwareRequest(location, retrieveDate); send(request); } public void sendReserveNowRequest( - Integer connectorId, Calendar expiryDate, String idTag, Integer reservationId) + Integer connectorId, ZonedDateTime expiryDate, String idTag, Integer reservationId) throws Exception { ReserveNowRequest request = new ReserveNowRequest(connectorId, expiryDate, idTag, reservationId); 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 5e162f768..933d7829e 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 @@ -2,10 +2,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -38,450 +40,459 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageStatus; import eu.chargetime.ocpp.model.reservation.*; import eu.chargetime.ocpp.model.smartcharging.*; + import java.net.MalformedURLException; import java.net.URL; -import java.util.Calendar; +import java.time.ZonedDateTime; public class FakeChargePoint { - private IClientAPI client; - private Confirmation receivedConfirmation; - private Request receivedRequest; - private final ClientCoreProfile core; - 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; - - public FakeChargePoint() throws MalformedURLException { - this(clientType.JSON); - } - - public enum clientType { - JSON, - SOAP - } - - public FakeChargePoint(clientType type) throws MalformedURLException { - core = - new ClientCoreProfile( - new ClientCoreEventHandler() { - @Override - public ChangeAvailabilityConfirmation handleChangeAvailabilityRequest( - ChangeAvailabilityRequest request) { - receivedRequest = request; - return new ChangeAvailabilityConfirmation(AvailabilityStatus.Accepted); - } - - @Override - public GetConfigurationConfirmation handleGetConfigurationRequest( - GetConfigurationRequest request) { - receivedRequest = request; - return new GetConfigurationConfirmation(); - } - - @Override - public ChangeConfigurationConfirmation handleChangeConfigurationRequest( - ChangeConfigurationRequest request) { - receivedRequest = request; - ChangeConfigurationConfirmation confirmation = - new ChangeConfigurationConfirmation(); - confirmation.setStatus(ConfigurationStatus.Accepted); - return confirmation; - } - - @Override - public ClearCacheConfirmation handleClearCacheRequest(ClearCacheRequest request) { - receivedRequest = request; - ClearCacheConfirmation confirmation = new ClearCacheConfirmation(); - confirmation.setStatus(ClearCacheStatus.Accepted); - return confirmation; - } - - @Override - public DataTransferConfirmation handleDataTransferRequest( - DataTransferRequest request) { - receivedRequest = request; - DataTransferConfirmation confirmation = new DataTransferConfirmation(); - confirmation.setStatus(DataTransferStatus.Accepted); - return confirmation; - } - - @Override - public RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest( - RemoteStartTransactionRequest request) { - receivedRequest = request; - return new RemoteStartTransactionConfirmation(RemoteStartStopStatus.Accepted); - } - - @Override - public RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest( - RemoteStopTransactionRequest request) { - receivedRequest = request; - return new RemoteStopTransactionConfirmation(RemoteStartStopStatus.Accepted); - } - - @Override - public ResetConfirmation handleResetRequest(ResetRequest request) { - receivedRequest = request; - return new ResetConfirmation(ResetStatus.Accepted); - } - - @Override - public UnlockConnectorConfirmation handleUnlockConnectorRequest( - UnlockConnectorRequest request) { - receivedRequest = request; - return new UnlockConnectorConfirmation(UnlockStatus.Unlocked); - } - }); - - smartCharging = - new ClientSmartChargingProfile( - new ClientSmartChargingEventHandler() { - @Override - public SetChargingProfileConfirmation handleSetChargingProfileRequest( - SetChargingProfileRequest request) { - receivedRequest = request; - return new SetChargingProfileConfirmation(ChargingProfileStatus.Accepted); - } - - @Override - public ClearChargingProfileConfirmation handleClearChargingProfileRequest( - ClearChargingProfileRequest request) { - receivedRequest = request; - return new ClearChargingProfileConfirmation(ClearChargingProfileStatus.Accepted); - } - }); - - remoteTrigger = - new ClientRemoteTriggerProfile( - new ClientRemoteTriggerHandler() { - @Override - public TriggerMessageConfirmation handleTriggerMessageRequest( - TriggerMessageRequest request) { - receivedRequest = request; - return new TriggerMessageConfirmation(TriggerMessageStatus.Accepted); - } - }); - - firmware = - new ClientFirmwareManagementProfile( - new ClientFirmwareManagementEventHandler() { - @Override - public GetDiagnosticsConfirmation handleGetDiagnosticsRequest( - GetDiagnosticsRequest request) { - receivedRequest = request; - return new GetDiagnosticsConfirmation(); - } - - @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) { - case JSON: - client = new JSONTestClient(core); - url = "ws://127.0.0.1:8887"; - break; - case SOAP: - client = new SOAPTestClient(new URL("http://127.0.0.1:8889"), core); - url = "http://127.0.0.1:8890"; - break; - } - - client.addFeatureProfile(smartCharging); - client.addFeatureProfile(remoteTrigger); - client.addFeatureProfile(firmware); - client.addFeatureProfile(localAuthList); - client.addFeatureProfile(reservation); - } - - public void connect() { - try { - client.connect( - url, - new ClientEvents() { - @Override - public void connectionOpened() {} - - @Override - public void connectionClosed() {} - }); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void sendBootNotification(String vendor, String model) throws Exception { - Request request = core.createBootNotificationRequest(vendor, model); - send(request); - } - - public void sendAuthorizeRequest(String idToken) throws Exception { - Request request = core.createAuthorizeRequest(idToken); - send(request); - } - - public void sendIncompleteAuthorizeRequest() throws Exception { - Request request = new AuthorizeRequest(); - send(request); - } - - public void sendHeartbeatRequest() throws Exception { - Request request = core.createHeartbeatRequest(); - send(request); - } - - public void sendMeterValuesRequest() throws Exception { - try { - Request request = core.createMeterValuesRequest(42, Calendar.getInstance(), "42"); - send(request); - } catch (PropertyConstraintException ex) { - ex.printStackTrace(); - } - } - - public void sendStartTransactionRequest() throws Exception { - try { - Request request = - core.createStartTransactionRequest(41, "some id", 42, Calendar.getInstance()); - send(request); - } catch (PropertyConstraintException ex) { - ex.printStackTrace(); - } - } - - public void sendStopTransactionRequest() throws Exception { - StopTransactionRequest request = - core.createStopTransactionRequest(42, Calendar.getInstance(), 42); - send(request); - } - - public void sendDataTransferRequest(String vendorId, String messageId, String data) { - try { - DataTransferRequest request = core.createDataTransferRequest(vendorId); - request.setMessageId(messageId); - request.setData(data); - - send(request); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void sendStatusNotificationRequest() { - try { - StatusNotificationRequest request = - core.createStatusNotificationRequest( - 42, ChargePointErrorCode.NoError, ChargePointStatus.Available); - send(request); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void sendDiagnosticsStatusNotificationRequest(DiagnosticsStatus status) throws Exception { - DiagnosticsStatusNotificationRequest request = new DiagnosticsStatusNotificationRequest(status); - send(request); - } - - public void sendFirmwareStatusNotificationRequest(FirmwareStatus status) throws Exception { - FirmwareStatusNotificationRequest request = new FirmwareStatusNotificationRequest(status); - send(request); - } - - public void clearMemory() { - receivedConfirmation = null; - receivedException = null; - receivedRequest = null; - } - - private void send(Request request) throws Exception { - try { - client - .send(request) - .whenComplete( - (s, ex) -> { - receivedConfirmation = s; - receivedException = ex; - }); - } catch (UnsupportedFeatureException ex) { - ex.printStackTrace(); - } - } - - public boolean hasReceivedBootConfirmation(String status) { - if (receivedConfirmation instanceof BootNotificationConfirmation) - return ((BootNotificationConfirmation) receivedConfirmation) - .getStatus() - .toString() - .equals(status); - return false; - } - - public boolean hasReceivedAuthorizeConfirmation(String status) { - if (receivedConfirmation instanceof AuthorizeConfirmation) - return ((AuthorizeConfirmation) receivedConfirmation) - .getIdTagInfo() - .getStatus() - .toString() - .equals(status); - return false; - } - - public boolean hasReceivedDiagnosticsStatusNotificationConfirmation() { - return (receivedConfirmation instanceof DiagnosticsStatusNotificationConfirmation); - } - - public boolean hasReceivedFirmwareStatusNotificationConfirmation() { - return (receivedConfirmation instanceof FirmwareStatusNotificationConfirmation); - } - - public boolean hasReceivedDataTransferConfirmation(String status) { - if (receivedConfirmation instanceof DataTransferConfirmation) - return ((DataTransferConfirmation) receivedConfirmation) - .getStatus() - .toString() - .equals(status); - return false; - } - - public boolean hasReceivedHeartbeatConfirmation() { - return (receivedConfirmation instanceof HeartbeatConfirmation); - } - - public boolean hasReceivedMeterValuesConfirmation() { - return (receivedConfirmation instanceof MeterValuesConfirmation); - } - - public boolean hasReceivedStartTransactionConfirmation() { - return (receivedConfirmation instanceof StartTransactionConfirmation); - } - - public boolean hasReceivedStatusNotificationConfirmation() { - return (receivedConfirmation instanceof StatusNotificationConfirmation); - } - - public boolean hasReceivedStopTransactionConfirmation() { - return (receivedConfirmation instanceof StopTransactionConfirmation); - } - - public void disconnect() { - client.disconnect(); - } - - public boolean hasHandledGetDiagnosticsRequest() { - return receivedRequest instanceof GetDiagnosticsRequest; - } - - public boolean hasHandledUpdateFirmwareRequest() { - return receivedRequest instanceof UpdateFirmwareRequest; - } - - public boolean hasHandledChangeAvailabilityRequest() { - return receivedRequest instanceof ChangeAvailabilityRequest; - } - - 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; - } - - public boolean hasHandledClearCacheRequest() { - return receivedRequest instanceof ClearCacheRequest; - } - - public boolean hasHandledDataTransferRequest() { - return receivedRequest instanceof DataTransferRequest; - } - - public boolean hasHandledRemoteStartTransactionRequest() { - return receivedRequest instanceof RemoteStartTransactionRequest; - } - - public boolean hasHandledRemoteStopTransactionRequest() { - return receivedRequest instanceof RemoteStopTransactionRequest; - } - - public boolean hasHandledResetRequest() { - return receivedRequest instanceof ResetRequest; - } - - public boolean hasHandledUnlockConnectorRequest() { - return receivedRequest instanceof UnlockConnectorRequest; - } - - public boolean hasReceivedError() { - return receivedException != null; - } - - public boolean hasReceivedNotConnectedError() { - if (receivedException instanceof CallErrorException) - return ((CallErrorException) receivedException).getErrorCode().equals("Not connected"); - return false; - } + private final ClientCoreProfile core; + private final ClientSmartChargingProfile smartCharging; + private final ClientRemoteTriggerProfile remoteTrigger; + private final ClientFirmwareManagementProfile firmware; + private final ClientLocalAuthListProfile localAuthList; + private final ClientReservationProfile reservation; + private IClientAPI client; + private Confirmation receivedConfirmation; + private Request receivedRequest; + private Throwable receivedException; + private String url; + + public FakeChargePoint() throws MalformedURLException { + this(clientType.JSON); + } + + public FakeChargePoint(clientType type) throws MalformedURLException { + core = + new ClientCoreProfile( + new ClientCoreEventHandler() { + @Override + public ChangeAvailabilityConfirmation handleChangeAvailabilityRequest( + ChangeAvailabilityRequest request) { + receivedRequest = request; + return new ChangeAvailabilityConfirmation(AvailabilityStatus.Accepted); + } + + @Override + public GetConfigurationConfirmation handleGetConfigurationRequest( + GetConfigurationRequest request) { + receivedRequest = request; + return new GetConfigurationConfirmation(); + } + + @Override + public ChangeConfigurationConfirmation handleChangeConfigurationRequest( + ChangeConfigurationRequest request) { + receivedRequest = request; + ChangeConfigurationConfirmation confirmation = + new ChangeConfigurationConfirmation(); + confirmation.setStatus(ConfigurationStatus.Accepted); + return confirmation; + } + + @Override + public ClearCacheConfirmation handleClearCacheRequest(ClearCacheRequest request) { + receivedRequest = request; + ClearCacheConfirmation confirmation = new ClearCacheConfirmation(); + confirmation.setStatus(ClearCacheStatus.Accepted); + return confirmation; + } + + @Override + public DataTransferConfirmation handleDataTransferRequest( + DataTransferRequest request) { + receivedRequest = request; + DataTransferConfirmation confirmation = new DataTransferConfirmation(); + confirmation.setStatus(DataTransferStatus.Accepted); + return confirmation; + } + + @Override + public RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest( + RemoteStartTransactionRequest request) { + receivedRequest = request; + return new RemoteStartTransactionConfirmation(RemoteStartStopStatus.Accepted); + } + + @Override + public RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest( + RemoteStopTransactionRequest request) { + receivedRequest = request; + return new RemoteStopTransactionConfirmation(RemoteStartStopStatus.Accepted); + } + + @Override + public ResetConfirmation handleResetRequest(ResetRequest request) { + receivedRequest = request; + return new ResetConfirmation(ResetStatus.Accepted); + } + + @Override + public UnlockConnectorConfirmation handleUnlockConnectorRequest( + UnlockConnectorRequest request) { + receivedRequest = request; + return new UnlockConnectorConfirmation(UnlockStatus.Unlocked); + } + }); + + smartCharging = + new ClientSmartChargingProfile( + new ClientSmartChargingEventHandler() { + @Override + public SetChargingProfileConfirmation handleSetChargingProfileRequest( + SetChargingProfileRequest request) { + receivedRequest = request; + return new SetChargingProfileConfirmation(ChargingProfileStatus.Accepted); + } + + @Override + public ClearChargingProfileConfirmation handleClearChargingProfileRequest( + ClearChargingProfileRequest request) { + receivedRequest = request; + return new ClearChargingProfileConfirmation(ClearChargingProfileStatus.Accepted); + } + + @Override + public GetCompositeScheduleConfirmation handleGetCompositeScheduleRequest(GetCompositeScheduleRequest request) { + receivedRequest = request; + return new GetCompositeScheduleConfirmation(GetCompositeScheduleStatus.Accepted); + } + }); + + remoteTrigger = + new ClientRemoteTriggerProfile( + new ClientRemoteTriggerEventHandler() { + @Override + public TriggerMessageConfirmation handleTriggerMessageRequest( + TriggerMessageRequest request) { + receivedRequest = request; + return new TriggerMessageConfirmation(TriggerMessageStatus.Accepted); + } + }); + + firmware = + new ClientFirmwareManagementProfile( + new ClientFirmwareManagementEventHandler() { + @Override + public GetDiagnosticsConfirmation handleGetDiagnosticsRequest( + GetDiagnosticsRequest request) { + receivedRequest = request; + return new GetDiagnosticsConfirmation(); + } + + @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) { + case JSON: + client = new JSONTestClient(core); + url = "ws://127.0.0.1:8887"; + break; + case SOAP: + client = new SOAPTestClient(new URL("http://127.0.0.1:8889"), core); + url = "http://127.0.0.1:8890"; + break; + } + + client.addFeatureProfile(smartCharging); + client.addFeatureProfile(remoteTrigger); + client.addFeatureProfile(firmware); + client.addFeatureProfile(localAuthList); + client.addFeatureProfile(reservation); + } + + public enum clientType { + JSON, + SOAP + } + + public void connect() { + try { + client.connect( + url, + new ClientEvents() { + @Override + public void connectionOpened() { + } + + @Override + public void connectionClosed() { + } + }); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void sendBootNotification(String vendor, String model) throws Exception { + Request request = core.createBootNotificationRequest(vendor, model); + send(request); + } + + public void sendAuthorizeRequest(String idToken) throws Exception { + Request request = core.createAuthorizeRequest(idToken); + send(request); + } + + public void sendIncompleteAuthorizeRequest() throws Exception { + Request request = new AuthorizeRequest(); + send(request); + } + + public void sendHeartbeatRequest() throws Exception { + Request request = core.createHeartbeatRequest(); + send(request); + } + + public void sendMeterValuesRequest() throws Exception { + try { + Request request = core.createMeterValuesRequest(42, ZonedDateTime.now(), "42"); + send(request); + } catch (PropertyConstraintException ex) { + ex.printStackTrace(); + } + } + + public void sendStartTransactionRequest() throws Exception { + try { + Request request = + core.createStartTransactionRequest(41, "some id", 42, ZonedDateTime.now()); + send(request); + } catch (PropertyConstraintException ex) { + ex.printStackTrace(); + } + } + + public void sendStopTransactionRequest() throws Exception { + StopTransactionRequest request = + core.createStopTransactionRequest(42, ZonedDateTime.now(), 42); + send(request); + } + + public void sendDataTransferRequest(String vendorId, String messageId, String data) { + try { + DataTransferRequest request = core.createDataTransferRequest(vendorId); + request.setMessageId(messageId); + request.setData(data); + + send(request); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void sendStatusNotificationRequest() { + try { + StatusNotificationRequest request = + core.createStatusNotificationRequest( + 42, ChargePointErrorCode.NoError, ChargePointStatus.Available); + send(request); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void sendDiagnosticsStatusNotificationRequest(DiagnosticsStatus status) throws Exception { + DiagnosticsStatusNotificationRequest request = new DiagnosticsStatusNotificationRequest(status); + send(request); + } + + public void sendFirmwareStatusNotificationRequest(FirmwareStatus status) throws Exception { + FirmwareStatusNotificationRequest request = new FirmwareStatusNotificationRequest(status); + send(request); + } + + public void clearMemory() { + receivedConfirmation = null; + receivedException = null; + receivedRequest = null; + } + + private void send(Request request) throws Exception { + try { + client + .send(request) + .whenComplete( + (s, ex) -> { + receivedConfirmation = s; + receivedException = ex; + }); + } catch (UnsupportedFeatureException ex) { + ex.printStackTrace(); + } + } + + public boolean hasReceivedBootConfirmation(String status) { + if (receivedConfirmation instanceof BootNotificationConfirmation) + return ((BootNotificationConfirmation) receivedConfirmation) + .getStatus() + .toString() + .equals(status); + return false; + } + + public boolean hasReceivedAuthorizeConfirmation(String status) { + if (receivedConfirmation instanceof AuthorizeConfirmation) + return ((AuthorizeConfirmation) receivedConfirmation) + .getIdTagInfo() + .getStatus() + .toString() + .equals(status); + return false; + } + + public boolean hasReceivedDiagnosticsStatusNotificationConfirmation() { + return (receivedConfirmation instanceof DiagnosticsStatusNotificationConfirmation); + } + + public boolean hasReceivedFirmwareStatusNotificationConfirmation() { + return (receivedConfirmation instanceof FirmwareStatusNotificationConfirmation); + } + + public boolean hasReceivedDataTransferConfirmation(String status) { + if (receivedConfirmation instanceof DataTransferConfirmation) + return ((DataTransferConfirmation) receivedConfirmation) + .getStatus() + .toString() + .equals(status); + return false; + } + + public boolean hasReceivedHeartbeatConfirmation() { + return (receivedConfirmation instanceof HeartbeatConfirmation); + } + + public boolean hasReceivedMeterValuesConfirmation() { + return (receivedConfirmation instanceof MeterValuesConfirmation); + } + + public boolean hasReceivedStartTransactionConfirmation() { + return (receivedConfirmation instanceof StartTransactionConfirmation); + } + + public boolean hasReceivedStatusNotificationConfirmation() { + return (receivedConfirmation instanceof StatusNotificationConfirmation); + } + + public boolean hasReceivedStopTransactionConfirmation() { + return (receivedConfirmation instanceof StopTransactionConfirmation); + } + + public void disconnect() { + client.disconnect(); + } + + public boolean hasHandledGetDiagnosticsRequest() { + return receivedRequest instanceof GetDiagnosticsRequest; + } + + public boolean hasHandledUpdateFirmwareRequest() { + return receivedRequest instanceof UpdateFirmwareRequest; + } + + public boolean hasHandledChangeAvailabilityRequest() { + return receivedRequest instanceof ChangeAvailabilityRequest; + } + + 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; + } + + public boolean hasHandledClearCacheRequest() { + return receivedRequest instanceof ClearCacheRequest; + } + + public boolean hasHandledDataTransferRequest() { + return receivedRequest instanceof DataTransferRequest; + } + + public boolean hasHandledRemoteStartTransactionRequest() { + return receivedRequest instanceof RemoteStartTransactionRequest; + } + + public boolean hasHandledRemoteStopTransactionRequest() { + return receivedRequest instanceof RemoteStopTransactionRequest; + } + + public boolean hasHandledResetRequest() { + return receivedRequest instanceof ResetRequest; + } + + public boolean hasHandledUnlockConnectorRequest() { + return receivedRequest instanceof UnlockConnectorRequest; + } + + public boolean hasReceivedError() { + return receivedException != null; + } + + public boolean hasReceivedNotConnectedError() { + if (receivedException instanceof CallErrorException) + return ((CallErrorException) receivedException).getErrorCode().equals("Not connected"); + return false; + } } diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/features/OfflineTransactionSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/features/OfflineTransactionSpec.groovy index 2f64fc4dd..e03d41550 100644 --- a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/features/OfflineTransactionSpec.groovy +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/features/OfflineTransactionSpec.groovy @@ -6,7 +6,7 @@ import spock.util.concurrent.PollingConditions /* ChargeTime.eu - Java-OCA-OCPP - + MIT License Copyright (C) 2016-2018 Thomas Volden @@ -35,7 +35,7 @@ class OfflineTransactionSpec extends JSONBaseSpec { def "Disconnected during a transaction, stores and recovers transaction related commands"() { def conditions = new PollingConditions(timeout: 1) def acon = new AsyncConditions() - when: "Send BootNotificatonRequest" + when: "Send BootNotificationRequest" chargePoint.sendBootNotification("ChargeTimeEU", "UnstableCharger") then: "Received response" diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/core/json/JSONDataTransferSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/core/json/JSONDataTransferSpec.groovy index 382fdc24e..7d5d84671 100644 --- a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/core/json/JSONDataTransferSpec.groovy +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/core/json/JSONDataTransferSpec.groovy @@ -5,19 +5,6 @@ import spock.util.concurrent.PollingConditions class JSONDataTransferSpec extends JSONBaseSpec { - def "Central System sends a DataTransfer request and receives a response"() { - def conditions = new PollingConditions(timeout: 1) - - when: - centralSystem.sendDataTransferRequest("VendorId", "messageId", "data") - - then: - conditions.eventually { - assert chargePoint.hasHandledDataTransferRequest() - assert centralSystem.hasReceivedDataTransferConfirmation() - } - } - def "Charge point sends a DataTransfer request and receives a response"() { def conditions = new PollingConditions(timeout: 1) diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/core/soap/SOAPDataTransferSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/core/soap/SOAPDataTransferSpec.groovy index fd9ae4c9a..84bd84e5c 100644 --- a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/core/soap/SOAPDataTransferSpec.groovy +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/core/soap/SOAPDataTransferSpec.groovy @@ -4,23 +4,6 @@ import eu.chargetime.ocpp.test.base.soap.SOAPBaseSpec import spock.util.concurrent.PollingConditions class SOAPDataTransferSpec extends SOAPBaseSpec { - def "Central System sends a DataTransfer request and receives a response"() { - def conditions = new PollingConditions(timeout: 2) - given: - chargePoint.sendBootNotification("VendorX", "SingleSocketCharger") - conditions.eventually { - assert centralSystem.connected() - } - - when: - centralSystem.sendDataTransferRequest("VendorId", "messageId", "data") - - then: - conditions.eventually { - assert chargePoint.hasHandledDataTransferRequest() - assert centralSystem.hasReceivedDataTransferConfirmation() - } - } def "Charge point sends a DataTransfer request and receives a response"() { def conditions = new PollingConditions(timeout: 10) diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/firmware/json/JSONUpdateFirmwareSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/firmware/json/JSONUpdateFirmwareSpec.groovy index 67382d81a..75ed88279 100644 --- a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/firmware/json/JSONUpdateFirmwareSpec.groovy +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/firmware/json/JSONUpdateFirmwareSpec.groovy @@ -3,6 +3,8 @@ package eu.chargetime.ocpp.test.profiles.firmware.json import eu.chargetime.ocpp.test.base.json.JSONBaseSpec import spock.util.concurrent.PollingConditions +import java.time.ZonedDateTime + /* ChargeTime.eu - Java-OCA-OCPP @@ -10,6 +12,7 @@ import spock.util.concurrent.PollingConditions Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2018 Mikhail Kladkevich + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -40,7 +43,7 @@ class JSONUpdateFirmwareSpec extends JSONBaseSpec { } when: - centralSystem.sendUpdateFirmwareRequest("URI", Calendar.getInstance()) + centralSystem.sendUpdateFirmwareRequest("URI", ZonedDateTime.now()) then: conditions.eventually { diff --git a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/reservation/json/JSONReserveNowSpec.groovy b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/reservation/json/JSONReserveNowSpec.groovy index f3fb816f3..c18187845 100644 --- a/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/reservation/json/JSONReserveNowSpec.groovy +++ b/ocpp-v1_6-test/src/test/groovy/eu/chargetime/ocpp/test/profiles/reservation/json/JSONReserveNowSpec.groovy @@ -3,6 +3,8 @@ package eu.chargetime.ocpp.test.profiles.reservation.json import eu.chargetime.ocpp.test.base.json.JSONBaseSpec import spock.util.concurrent.PollingConditions +import java.time.ZonedDateTime + /* ChargeTime.eu - Java-OCA-OCPP @@ -10,6 +12,7 @@ import spock.util.concurrent.PollingConditions Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2018 Mikhail Kladkevich + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -40,7 +43,7 @@ class JSONReserveNowSpec extends JSONBaseSpec { } when: - centralSystem.sendReserveNowRequest(0, Calendar.getInstance(), "123", 2) + centralSystem.sendReserveNowRequest(0, ZonedDateTime.now(), "123", 2) then: conditions.eventually { diff --git a/ocpp-v1_6/out/production/resources/eu/chargetime/ocpp/OCPP_CentralSystemService_1.6.wsdl b/ocpp-v1_6/out/production/resources/eu/chargetime/ocpp/OCPP_CentralSystemService_1.6.wsdl new file mode 100644 index 000000000..407a63d92 --- /dev/null +++ b/ocpp-v1_6/out/production/resources/eu/chargetime/ocpp/OCPP_CentralSystemService_1.6.wsdl @@ -0,0 +1,836 @@ + + + + + + + + + + + + + + + + + + + Type of string defining identification token, e.g. RFID or credit card number. To + be treated as case insensitive. + + + + + + + + + + String of maximum 20 printable characters. To be treated as case insensitive. + + + + + + + + + + String of maximum 25 printable characters. To be treated as case insensitive. + + + + + + + + + + String of maximum 50 printable characters. To be treated as case insensitive. + + + + + + + + + + String of maximum 255 printable characters. To be treated as case insensitive. + + + + + + + + + + String of maximum 500 printable characters. To be treated as case insensitive. + + + + + + + + + + Defines the authorization-status-value + + + + + + + + + + + + + + + + + + + + + + Defines the Authorize.req PDU + + + + + + + + + Defines the Authorize.conf PDU + + + + + + + + + Defines the StartTransaction.req PDU + + + + + + + + + + + + + Defines the StartTransaction.conf PDU + + + + + + + + + + Reason for stopping a transaction + + + + + + + + + + + + + + + + + + + Defines the StopTransaction.req PDU + + + + + + + + + + + + + + Defines the StopTransaction.conf PDU + + + + + + + + + Defines the Heartbeat.req PDU + + + + + + Defines the Heartbeat.conf PDU + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Defines the SampledValue-value + + + + + + + + + + + + + + + Defines single value of the meter-value-value + + + + + + + + + + Defines the MeterValues.req PDU + + + + + + + + + + + Defines the MeterValues.conf PDU + + + + + + Defines the BootNotification.req PDU + + + + + + + + + + + + + + + + + Defines the registration-status-value + + + + + + + + + + + Defines the BootNotification.conf PDU + + + + + + + + + + + Defines the charge-point-error-value + + + + + + + + + + + + + + + + + + + + + + + + Defines the charge-point-status-value + + + + + + + + + + + + + + + + + Defines the StatusNotification.req PDU + + + + + + + + + + + + + + + Defines the StatusNotification.conf PDU + + + + + + Defines the firmware-status-value + + + + + + + + + + + + + + + Defines the FirmwareStatusNotification.req PDU + + + + + + + + + Defines the FirmwareStatusNotification.conf PDU + + + + + + Defines the diagnostics-status-value + + + + + + + + + + + + Defines the DiagnosticsStatusNotification.req PDU + + + + + + + + + Defines the DiagnosticsStatusNotification.conf PDU + + + + + + Defines the DataTransfer.req PDU + + + + + + + + + + + Defines the status returned in DataTransfer.conf + + + + + + + + + + + + Defines the DataTransfer.conf PDU + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The Central System Service for the Open Charge Point Protocol + + + + + + diff --git a/ocpp-v1_6/out/production/resources/eu/chargetime/ocpp/OCPP_ChargePointService_1.6.wsdl b/ocpp-v1_6/out/production/resources/eu/chargetime/ocpp/OCPP_ChargePointService_1.6.wsdl new file mode 100644 index 000000000..a90a63f23 --- /dev/null +++ b/ocpp-v1_6/out/production/resources/eu/chargetime/ocpp/OCPP_ChargePointService_1.6.wsdl @@ -0,0 +1,1274 @@ + + + + + + + + + + + + + + + + + + + + Type of string defining identification token, e.g. RFID or credit card number. To + be treated as case insensitive. + + + + + + + + + + Decimal with one digit fraction + + + + + + + + + String of maximum 20 printable characters. To be treated as case insensitive. + + + + + + + + + + String of maximum 25 printable characters. To be treated as case insensitive. + + + + + + + + + + String of maximum 50 printable characters. To be treated as case insensitive. + + + + + + + + + + String of maximum 255 printable characters. To be treated as case insensitive. + + + + + + + + + + String of maximum 500 printable characters. To be treated as case insensitive. + + + + + + + + + + Defines the authorization-status-value + + + + + + + + + + + + + + + + + + + + + + Defines the unlock-status-value + + + + + + + + + + + Defines the UnlockConnector.req PDU + + + + + + + + + Defines the UnlockConnector.conf PDU + + + + + + + + + Defines the reset-type-value + + + + + + + + + + Defines the Reset.req PDU + + + + + + + + + Defines the reset-status-value + + + + + + + + + + + + + + + + Defines the availability-type-value + + + + + + + + + + Defines the ChangeAvailability.req PDU + + + + + + + + + + Defines the availability-status-value + + + + + + + + + + + Defines the ChangeAvailability.conf PDU + + + + + + + + + Defines the GetDiagnostics.req PDU + + + + + + + + + + + + + Defines the GetDiagnostics.conf PDU + + + + + + + + + Defines the ClearCache.req PDU + + + + + + Defines the clear-cache-status-value + + + + + + + + + + Defines the ClearCache.conf PDU + + + + + + + + + Defines the charging-profile-purpose-type-value + + + + + + + + + + + Defines the ClearChargingProfile.req PDU + + + + + + + + + + + + Defines the clear-charging-profile-status-value + + + + + + + + + + Defines the ClearChargingProfile.conf PDU + + + + + + + + + Defines the UpdateFirmware.req PDU + + + + + + + + + + + + Defines the UpdateFirmware.conf PDU + + + + + + Defines the ChangeConfiguration.req PDU + + + + + + + + + + Defines the configuration-status-value + + + + + + + + + + + + Defines the ChangeConfiguration.conf PDU + + + + + + + + + Defines the RemoteStartTransaction.req PDU + + + + + + + + + + + Defines the remote-start-stop-status-value + + + + + + + + + + Defines the RemoteStartTransaction.conf PDU + + + + + + + + + Defines the RemoteStopTransaction.req PDU + + + + + + + + + Defines the RemoteStopTransaction.conf PDU + + + + + + + + + Defines the CancelReservation.req PDU + + + + + + + + + + + + + + + + Defines the CancelReservation.conf PDU + + + + + + + + + Defines the DataTransfer.req PDU + + + + + + + + + + + Defines the status returned in DataTransfer.conf + + + + + + + + + + + + Defines the DataTransfer.conf PDU + + + + + + + + + + Defines the GetConfiguration.req PDU + + + + + + + + + Key-Value pairs returned by GetConfiguration.conf PDU + + + + + + + + + + + Defines the GetConfiguration.req PDU + + + + + + + + + + Defines the GetLocalListVersion.req PDU + + + + + + Defines the GetLocalListVersion.conf PDU + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Defines the GetCompositeSchedule.req PDU + + + + + + + + + + + + + + + + + + Defines the GetCompositeSchedule.conf PDU + + + + + + + + + + + + Defines the ReserveNow.req PDU + + + + + + + + + + + + + + + + + + + + + + + Defines the ReserveNow.conf PDU + + + + + + + + + + + + + + + + + + + + + + + Defines the SendLocalList.req PDU + + + + + + + + + + + + + + + + + + + + Defines the SendLocalList.conf PDU + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Defines the SetChargingProfile.req PDU + + + + + + + + + + + + + + + + + + Defines the SetChargingProfile.conf PDU + + + + + + + + + + + + + + + + + + + + Defines the TriggerMessage.req PDU + + + + + + + + + + + + + + + + + + Defines the TriggerMessage.conf PDU + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The ChargePoint Service for the Open Charge Point Protocol + + + + + diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/GetCompositeScheduleFeature.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/GetCompositeScheduleFeature.java new file mode 100644 index 000000000..96a4aa7cc --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/GetCompositeScheduleFeature.java @@ -0,0 +1,59 @@ +package eu.chargetime.ocpp.feature; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2019 Kevin Raddatz + + 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.profile.Profile; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.smartcharging.GetCompositeScheduleConfirmation; +import eu.chargetime.ocpp.model.smartcharging.GetCompositeScheduleRequest; + +public class GetCompositeScheduleFeature extends ProfileFeature { + + /** + * Creates link back to the {@link Profile}. + * + * @param ownerProfile the {@link Profile} that owns the function. + */ + public GetCompositeScheduleFeature(Profile ownerProfile) { + super(ownerProfile); + } + + @Override + public Class getRequestType() { + return GetCompositeScheduleRequest.class; + } + + @Override + public Class getConfirmationType() { + return GetCompositeScheduleConfirmation.class; + } + + @Override + public String getAction() { + return "GetCompositeSchedule"; + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientCoreProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientCoreProfile.java index 611f018de..bff55d805 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientCoreProfile.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientCoreProfile.java @@ -1,59 +1,42 @@ package eu.chargetime.ocpp.feature.profile; +/* + ChargeTime.eu - Java-OCA-OCPP + Copyright (C) 2015-2016 Thomas Volden + Copyright (C) 2019 Kevin Raddatz + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz + + 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.core.AuthorizeRequest; -import eu.chargetime.ocpp.model.core.BootNotificationRequest; -import eu.chargetime.ocpp.model.core.ChangeAvailabilityRequest; -import eu.chargetime.ocpp.model.core.ChangeConfigurationRequest; -import eu.chargetime.ocpp.model.core.ChargePointErrorCode; -import eu.chargetime.ocpp.model.core.ChargePointStatus; -import eu.chargetime.ocpp.model.core.ClearCacheRequest; -import eu.chargetime.ocpp.model.core.DataTransferRequest; -import eu.chargetime.ocpp.model.core.GetConfigurationRequest; -import eu.chargetime.ocpp.model.core.HeartbeatRequest; -import eu.chargetime.ocpp.model.core.MeterValue; -import eu.chargetime.ocpp.model.core.MeterValuesRequest; -import eu.chargetime.ocpp.model.core.RemoteStartTransactionRequest; -import eu.chargetime.ocpp.model.core.RemoteStopTransactionRequest; -import eu.chargetime.ocpp.model.core.ResetRequest; -import eu.chargetime.ocpp.model.core.SampledValue; -import eu.chargetime.ocpp.model.core.StartTransactionRequest; -import eu.chargetime.ocpp.model.core.StatusNotificationRequest; -import eu.chargetime.ocpp.model.core.StopTransactionRequest; -import eu.chargetime.ocpp.model.core.UnlockConnectorRequest; +import eu.chargetime.ocpp.model.core.*; + +import java.time.ZonedDateTime; import java.util.ArrayList; -import java.util.Calendar; import java.util.UUID; -/* -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. -*/ - /** * The core feature profile contains the features from OCPP v. 1.5 * @@ -61,226 +44,211 @@ of this software and associated documentation files (the "Software"), to deal */ public class ClientCoreProfile implements Profile { - private ClientCoreEventHandler eventHandler; - ArrayList features; - - /** - * Set up handler for client core feature requests. - * - * @param handler call back methods for client events - */ - public ClientCoreProfile(ClientCoreEventHandler handler) { - features = new ArrayList<>(); - eventHandler = handler; - - features.add(new BootNotificationFeature(null)); - features.add(new AuthorizeFeature(null)); - features.add(new ChangeAvailabilityFeature(this)); - features.add(new GetConfigurationFeature(this)); - features.add(new ChangeConfigurationFeature(this)); - features.add(new ClearCacheFeature(this)); - features.add(new DataTransferFeature(this)); - features.add(new HeartbeatFeature(this)); - features.add(new MeterValuesFeature(this)); - features.add(new RemoteStartTransactionFeature(this)); - features.add(new RemoteStopTransactionFeature(this)); - features.add(new ResetFeature(this)); - features.add(new StartTransactionFeature(this)); - features.add(new StatusNotificationFeature(this)); - features.add(new StopTransactionFeature(this)); - features.add(new UnlockConnectorFeature(this)); - } - - /** - * Create a client {@link AuthorizeRequest} with required values. - * - * @param idToken required identification token. - * @return an instance of {@link AuthorizeRequest}. - * @see AuthorizeRequest - * @see AuthorizeFeature - */ - public AuthorizeRequest createAuthorizeRequest(String idToken) { - return new AuthorizeRequest(idToken); - } - - /** - * Create a client {@link BootNotificationRequest} with required values. - * - * @param vendor required. Vendor name. - * @param model required. Charge box model. - * @return an instance of {@link BootNotificationRequest} - * @see BootNotificationRequest - * @see BootNotificationFeature - */ - public BootNotificationRequest createBootNotificationRequest(String vendor, String model) { - return new BootNotificationRequest(vendor, model); - } + ArrayList features; + private ClientCoreEventHandler eventHandler; + + /** + * Set up handler for client core feature requests. + * + * @param handler call back methods for client events + */ + public ClientCoreProfile(ClientCoreEventHandler handler) { + features = new ArrayList<>(); + eventHandler = handler; + + features.add(new AuthorizeFeature(null)); + features.add(new BootNotificationFeature(null)); + features.add(new ChangeAvailabilityFeature(this)); + features.add(new ChangeConfigurationFeature(this)); + features.add(new ClearCacheFeature(this)); + features.add(new DataTransferFeature(null)); + features.add(new GetConfigurationFeature(this)); + features.add(new HeartbeatFeature(null)); + features.add(new MeterValuesFeature(null)); + features.add(new RemoteStartTransactionFeature(this)); + features.add(new RemoteStopTransactionFeature(this)); + features.add(new ResetFeature(this)); + features.add(new StartTransactionFeature(null)); + features.add(new StatusNotificationFeature(null)); + features.add(new StopTransactionFeature(null)); + features.add(new UnlockConnectorFeature(this)); + } - /** - * Create a client {@link DataTransferRequest} with required values. - * - * @param vendorId required. Vendor identification. - * @return an instance of {@link DataTransferRequest}. - * @see DataTransferRequest - * @see DataTransferFeature - */ - public DataTransferRequest createDataTransferRequest(String vendorId) { - return new DataTransferRequest(vendorId); - } + /** + * Create a client {@link AuthorizeRequest} with required values. + * + * @param idTag required, identification token. + * @return an instance of {@link AuthorizeRequest}. + * @see AuthorizeRequest + * @see AuthorizeFeature + */ + public AuthorizeRequest createAuthorizeRequest(String idTag) { + return new AuthorizeRequest(idTag); + } - /** - * Create a client {@link HeartbeatRequest}. - * - * @return an instance of {@link HeartbeatRequest} - * @see HeartbeatRequest - * @see HeartbeatFeature - */ - public HeartbeatRequest createHeartbeatRequest() { - return new HeartbeatRequest(); - } + /** + * Create a client {@link BootNotificationRequest} with required values. + * + * @param vendor required. Vendor name. + * @param model required. Charge box model. + * @return an instance of {@link BootNotificationRequest} + * @see BootNotificationRequest + * @see BootNotificationFeature + */ + public BootNotificationRequest createBootNotificationRequest(String vendor, String model) { + return new BootNotificationRequest(vendor, model); + } - /** - * Create a client {@link MeterValuesRequest} with one {@link SampledValue} and one {@link - * MeterValue} - * - * @param connectorId required. Identification of connector. - * @param timestamp required. Time of sample. - * @param value required. Value of sample. - * @return an instance of {@link MeterValuesRequest}. - * @see MeterValuesRequest - * @see MeterValuesFeature - */ - public MeterValuesRequest createMeterValuesRequest( - Integer connectorId, Calendar timestamp, String value) { - SampledValue sampledValue = new SampledValue(); - sampledValue.setValue(value); - return createMeterValuesRequest(connectorId, timestamp, sampledValue); - } + /** + * Create a client {@link DataTransferRequest} with required values. + * + * @param vendorId required. Vendor identification. + * @return an instance of {@link DataTransferRequest}. + * @see DataTransferRequest + * @see DataTransferFeature + */ + public DataTransferRequest createDataTransferRequest(String vendorId) { + return new DataTransferRequest(vendorId); + } - /** - * Create a client {@link MeterValuesRequest} with some {@link SampledValue}s and one {@link - * MeterValue}. - * - * @param connectorId required. Identification of connector. - * @param timestamp required. Time of sample. - * @param sampledValues required. Params list of {@link SampledValue}s - * @return an instance of {@link MeterValuesRequest} - * @see MeterValuesRequest - * @see MeterValuesFeature - */ - public MeterValuesRequest createMeterValuesRequest( - Integer connectorId, Calendar timestamp, SampledValue... sampledValues) { - MeterValue meterValue = new MeterValue(); - meterValue.setTimestamp(timestamp); - meterValue.setSampledValue(sampledValues); - return createMeterValuesRequest(connectorId, meterValue); - } + /** + * Create a client {@link HeartbeatRequest}. + * + * @return an instance of {@link HeartbeatRequest} + * @see HeartbeatRequest + * @see HeartbeatFeature + */ + public HeartbeatRequest createHeartbeatRequest() { + return new HeartbeatRequest(); + } - /** - * Create a client {@link MeterValuesRequest} with some {@link MeterValue}s. - * - * @param connectorId required. Identification of connector. - * @param meterValues required. Params list of {@link MeterValue}s - * @return an instance of {@link MeterValuesRequest} - * @see MeterValuesRequest - * @see MeterValuesFeature - */ - public MeterValuesRequest createMeterValuesRequest( - Integer connectorId, MeterValue... meterValues) { - MeterValuesRequest request = new MeterValuesRequest(); - request.setConnectorId(connectorId); - request.setMeterValue(meterValues); - return request; - } + /** + * Create a client {@link MeterValuesRequest} with one {@link SampledValue} and one {@link + * MeterValue} + * + * @param connectorId required. Identification of connector. + * @param timestamp required. Time of sample. + * @param value required. Value of sample. + * @return an instance of {@link MeterValuesRequest}. + * @see MeterValuesRequest + * @see MeterValuesFeature + */ + public MeterValuesRequest createMeterValuesRequest( + Integer connectorId, ZonedDateTime timestamp, String value) { + SampledValue sampledValue = new SampledValue(value); + return createMeterValuesRequest(connectorId, timestamp, sampledValue); + } - /** - * Create a client {@link StartTransactionRequest} with required values. - * - * @param connectorId required. Identification of the connector. - * @param idTag required. Authorization identification tag. - * @param meterStart required. The initial value of the meter. - * @param timestamp required. Time of start. - * @return an instance of {@link StartTransactionRequest}. - * @see StartTransactionRequest - * @see StartTransactionFeature - */ - public StartTransactionRequest createStartTransactionRequest( - Integer connectorId, String idTag, Integer meterStart, Calendar timestamp) { - StartTransactionRequest request = new StartTransactionRequest(); - request.setConnectorId(connectorId); - request.setIdTag(idTag); - request.setMeterStart(meterStart); - request.setTimestamp(timestamp); - return request; - } + /** + * Create a client {@link MeterValuesRequest} with some {@link SampledValue}s and one {@link + * MeterValue}. + * + * @param connectorId required. Identification of connector. + * @param timestamp required. Time of sample. + * @param sampledValues required. Params list of {@link SampledValue}s + * @return an instance of {@link MeterValuesRequest} + * @see MeterValuesRequest + * @see MeterValuesFeature + */ + public MeterValuesRequest createMeterValuesRequest( + Integer connectorId, ZonedDateTime timestamp, SampledValue... sampledValues) { + MeterValue meterValue = new MeterValue(timestamp, sampledValues); + return createMeterValuesRequest(connectorId, meterValue); + } - /** - * Create a client {@link StatusNotificationRequest} with required values. - * - * @param connectorId required. Identification of the connector. - * @param errorCode required. {@link ChargePointErrorCode} of the connector. - * @param status required. {@link ChargePointStatus} of the connector. - * @return an instance of {@link StatusNotificationRequest}. - * @see StatusNotificationRequest - * @see StatusNotificationFeature - */ - public StatusNotificationRequest createStatusNotificationRequest( - Integer connectorId, ChargePointErrorCode errorCode, ChargePointStatus status) { - StatusNotificationRequest request = new StatusNotificationRequest(); - request.setConnectorId(connectorId); - request.setErrorCode(errorCode); - request.setStatus(status); - return request; - } + /** + * Create a client {@link MeterValuesRequest} with some {@link MeterValue}s. + * + * @param connectorId required. Identification of connector. + * @param meterValues required. Params list of {@link MeterValue}s + * @return an instance of {@link MeterValuesRequest} + * @see MeterValuesRequest + * @see MeterValuesFeature + */ + public MeterValuesRequest createMeterValuesRequest( + Integer connectorId, MeterValue... meterValues) { + MeterValuesRequest request = new MeterValuesRequest(connectorId); + request.setMeterValue(meterValues); + return request; + } - /** - * Create a client {@link StopTransactionRequest} with required values. - * - * @param meterStop required. The final value of the meter. - * @param timestamp required. Time of stop. - * @param transactionId required. The identification of the transaction. - * @return an instance of {@link StopTransactionRequest}. - */ - public StopTransactionRequest createStopTransactionRequest( - int meterStop, Calendar timestamp, int transactionId) { - StopTransactionRequest request = new StopTransactionRequest(); - request.setMeterStop(meterStop); - request.setTimestamp(timestamp); - request.setTransactionId(transactionId); - return request; - } + /** + * Create a client {@link StartTransactionRequest} with required values. + * + * @param connectorId required. Identification of the connector. + * @param idTag required. Authorization identification tag. + * @param meterStart required. The initial value of the meter. + * @param timestamp required. Time of start. + * @return an instance of {@link StartTransactionRequest}. + * @see StartTransactionRequest + * @see StartTransactionFeature + */ + public StartTransactionRequest createStartTransactionRequest( + Integer connectorId, String idTag, Integer meterStart, ZonedDateTime timestamp) { + return new StartTransactionRequest(connectorId, idTag, meterStart, timestamp); + } - @Override - public ProfileFeature[] getFeatureList() { - return features.toArray(new ProfileFeature[0]); - } + /** + * Create a client {@link StatusNotificationRequest} with required values. + * + * @param connectorId required. Identification of the connector. + * @param errorCode required. {@link ChargePointErrorCode} of the connector. + * @param status required. {@link ChargePointStatus} of the connector. + * @return an instance of {@link StatusNotificationRequest}. + * @see StatusNotificationRequest + * @see StatusNotificationFeature + */ + public StatusNotificationRequest createStatusNotificationRequest( + Integer connectorId, ChargePointErrorCode errorCode, ChargePointStatus status) { + StatusNotificationRequest request = new StatusNotificationRequest(connectorId, errorCode, status); + return request; + } - @Override - public Confirmation handleRequest(UUID sessionIndex, Request request) { - Confirmation result = null; + /** + * Create a client {@link StopTransactionRequest} with required values. + * + * @param meterStop required. The final value of the meter. + * @param timestamp required. Time of stop. + * @param transactionId required. The identification of the transaction. + * @return an instance of {@link StopTransactionRequest}. + */ + public StopTransactionRequest createStopTransactionRequest( + int meterStop, ZonedDateTime timestamp, int transactionId) { + StopTransactionRequest request = new StopTransactionRequest(meterStop, timestamp, transactionId); + return request; + } - if (request instanceof ChangeAvailabilityRequest) { - result = eventHandler.handleChangeAvailabilityRequest((ChangeAvailabilityRequest) request); - } else if (request instanceof GetConfigurationRequest) { - result = eventHandler.handleGetConfigurationRequest((GetConfigurationRequest) request); - } else if (request instanceof ChangeConfigurationRequest) { - result = eventHandler.handleChangeConfigurationRequest((ChangeConfigurationRequest) request); - } else if (request instanceof ClearCacheRequest) { - result = eventHandler.handleClearCacheRequest((ClearCacheRequest) request); - } else if (request instanceof DataTransferRequest) { - result = eventHandler.handleDataTransferRequest((DataTransferRequest) request); - } else if (request instanceof RemoteStartTransactionRequest) { - result = - eventHandler.handleRemoteStartTransactionRequest((RemoteStartTransactionRequest) request); - } else if (request instanceof RemoteStopTransactionRequest) { - result = - eventHandler.handleRemoteStopTransactionRequest((RemoteStopTransactionRequest) request); - } else if (request instanceof ResetRequest) { - result = eventHandler.handleResetRequest((ResetRequest) request); - } else if (request instanceof UnlockConnectorRequest) { - result = eventHandler.handleUnlockConnectorRequest((UnlockConnectorRequest) request); + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); } - return result; - } + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + Confirmation result = null; + + if (request instanceof ChangeAvailabilityRequest) { + result = eventHandler.handleChangeAvailabilityRequest((ChangeAvailabilityRequest) request); + } else if (request instanceof ChangeConfigurationRequest) { + result = eventHandler.handleChangeConfigurationRequest((ChangeConfigurationRequest) request); + } else if (request instanceof ClearCacheRequest) { + result = eventHandler.handleClearCacheRequest((ClearCacheRequest) request); + } else if (request instanceof DataTransferRequest) { + result = eventHandler.handleDataTransferRequest((DataTransferRequest) request); + } else if (request instanceof GetConfigurationRequest) { + result = eventHandler.handleGetConfigurationRequest((GetConfigurationRequest) request); + } else if (request instanceof RemoteStartTransactionRequest) { + result = + eventHandler.handleRemoteStartTransactionRequest((RemoteStartTransactionRequest) request); + } else if (request instanceof RemoteStopTransactionRequest) { + result = + eventHandler.handleRemoteStopTransactionRequest((RemoteStopTransactionRequest) request); + } else if (request instanceof ResetRequest) { + result = eventHandler.handleResetRequest((ResetRequest) request); + } else if (request instanceof UnlockConnectorRequest) { + result = eventHandler.handleUnlockConnectorRequest((UnlockConnectorRequest) request); + } + + return result; + } } 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 10f79e0fc..5fc8a95ed 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 @@ -5,6 +5,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,64 +30,65 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.firmware.*; + import java.util.HashSet; import java.util.UUID; public class ClientFirmwareManagementProfile implements Profile { - private HashSet features; - private ClientFirmwareManagementEventHandler eventHandler; - - public ClientFirmwareManagementProfile(ClientFirmwareManagementEventHandler eventHandler) { - this.eventHandler = eventHandler; - features = new HashSet<>(); - features.add(new GetDiagnosticsFeature(this)); - features.add(new DiagnosticsStatusNotificationFeature(this)); - features.add(new FirmwareStatusNotificationFeature(this)); - features.add(new UpdateFirmwareFeature(this)); - } - - /** - * Create a {@link DiagnosticsStatusNotificationRequest} with required values. - * - * @param status required. Identification of the {@link DiagnosticsStatus}. - * @return an instance of {@link DiagnosticsStatusNotificationRequest}. - * @see DiagnosticsStatusNotificationRequest - * @see DiagnosticsStatusNotificationFeature - */ - public DiagnosticsStatusNotificationRequest createDiagnosticsStatusNotificationRequest( - DiagnosticsStatus status) { - return new DiagnosticsStatusNotificationRequest(status); - } - - /** - * Create a {@link FirmwareStatusNotificationRequest} with required values. - * - * @param status required. Identification of the {@link FirmwareStatus}. - * @return an instance of {@link FirmwareStatusNotificationRequest}. - * @see FirmwareStatusNotificationRequest - * @see FirmwareStatusNotificationFeature - */ - public FirmwareStatusNotificationRequest createFirmwareStatusNotificationRequest( - FirmwareStatus status) { - return new FirmwareStatusNotificationRequest(status); - } - - @Override - public ProfileFeature[] getFeatureList() { - return features.toArray(new ProfileFeature[0]); - } - - @Override - public Confirmation handleRequest(UUID sessionIndex, Request request) { - Confirmation result = null; - - if (request instanceof GetDiagnosticsRequest) { - result = eventHandler.handleGetDiagnosticsRequest((GetDiagnosticsRequest) request); - } else if (request instanceof UpdateFirmwareRequest) { - result = eventHandler.handleUpdateFirmwareRequest((UpdateFirmwareRequest) request); + private HashSet features; + private ClientFirmwareManagementEventHandler eventHandler; + + public ClientFirmwareManagementProfile(ClientFirmwareManagementEventHandler eventHandler) { + this.eventHandler = eventHandler; + features = new HashSet<>(); + features.add(new DiagnosticsStatusNotificationFeature(null)); + features.add(new FirmwareStatusNotificationFeature(null)); + features.add(new GetDiagnosticsFeature(this)); + features.add(new UpdateFirmwareFeature(this)); + } + + /** + * Create a {@link DiagnosticsStatusNotificationRequest} with required values. + * + * @param status required. Identification of the {@link DiagnosticsStatus}. + * @return an instance of {@link DiagnosticsStatusNotificationRequest}. + * @see DiagnosticsStatusNotificationRequest + * @see DiagnosticsStatusNotificationFeature + */ + public DiagnosticsStatusNotificationRequest createDiagnosticsStatusNotificationRequest( + DiagnosticsStatus status) { + return new DiagnosticsStatusNotificationRequest(status); + } + + /** + * Create a {@link FirmwareStatusNotificationRequest} with required values. + * + * @param status required. Identification of the {@link FirmwareStatus}. + * @return an instance of {@link FirmwareStatusNotificationRequest}. + * @see FirmwareStatusNotificationRequest + * @see FirmwareStatusNotificationFeature + */ + public FirmwareStatusNotificationRequest createFirmwareStatusNotificationRequest( + FirmwareStatus status) { + return new FirmwareStatusNotificationRequest(status); } - return result; - } + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); + } + + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + Confirmation result = null; + + if (request instanceof GetDiagnosticsRequest) { + result = eventHandler.handleGetDiagnosticsRequest((GetDiagnosticsRequest) 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/ClientRemoteTriggerHandler.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientRemoteTriggerEventHandler.java similarity index 97% rename from ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientRemoteTriggerHandler.java rename to ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientRemoteTriggerEventHandler.java index 46fa8ac54..526dabc2f 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientRemoteTriggerHandler.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientRemoteTriggerEventHandler.java @@ -30,7 +30,7 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageConfirmation; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest; -public interface ClientRemoteTriggerHandler { +public interface ClientRemoteTriggerEventHandler { /** * Handle a {@link TriggerMessageRequest} and return a {@link TriggerMessageConfirmation}. * diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientRemoteTriggerProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientRemoteTriggerProfile.java index 83232554a..451204a3e 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientRemoteTriggerProfile.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientRemoteTriggerProfile.java @@ -38,10 +38,10 @@ of this software and associated documentation files (the "Software"), to deal /** Callback handler for client events of the Remote Trigger feature profile. */ public class ClientRemoteTriggerProfile implements Profile { - private ClientRemoteTriggerHandler eventHandler; + private ClientRemoteTriggerEventHandler eventHandler; private ArrayList features; - public ClientRemoteTriggerProfile(ClientRemoteTriggerHandler handler) { + public ClientRemoteTriggerProfile(ClientRemoteTriggerEventHandler handler) { features = new ArrayList<>(); eventHandler = handler; 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 index 603a52908..4364512cb 100644 --- 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 @@ -7,6 +7,7 @@ Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2018 Mikhail Kladkevich + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -27,41 +28,45 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.feature.*; +import eu.chargetime.ocpp.feature.CancelReservationFeature; +import eu.chargetime.ocpp.feature.Feature; +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.ReserveNowFeature; 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; + 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)); - } + public ClientReservationProfile(ClientReservationEventHandler eventHandler) { + this.eventHandler = eventHandler; + features = new HashSet<>(); + features.add(new CancelReservationFeature(this)); + features.add(new ReserveNowFeature(this)); + } - @Override - public ProfileFeature[] getFeatureList() { - return features.toArray(new ProfileFeature[0]); - } + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); + } - @Override - public Confirmation handleRequest(UUID sessionIndex, Request request) { - Confirmation result = null; + @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); - } + if (request instanceof CancelReservationRequest) { + result = eventHandler.handleCancelReservationRequest((CancelReservationRequest) request); + } else if (request instanceof ReserveNowRequest) { + result = eventHandler.handleReserveNowRequest((ReserveNowRequest) request); + } - return result; - } + return result; + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientSmartChargingEventHandler.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientSmartChargingEventHandler.java index 3ceb386df..caea05a97 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientSmartChargingEventHandler.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientSmartChargingEventHandler.java @@ -1,9 +1,6 @@ package eu.chargetime.ocpp.feature.profile; -import eu.chargetime.ocpp.model.smartcharging.ClearChargingProfileConfirmation; -import eu.chargetime.ocpp.model.smartcharging.ClearChargingProfileRequest; -import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileConfirmation; -import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest; +import eu.chargetime.ocpp.model.smartcharging.*; /* * ChargeTime.eu - Java-OCA-OCPP @@ -11,6 +8,7 @@ * MIT License * * Copyright (C) 2017 Emil Christopher Solli Melar + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -32,21 +30,31 @@ */ public interface ClientSmartChargingEventHandler { - /** - * Handle a {@link SetChargingProfileRequest} and return a {@link SetChargingProfileConfirmation}. - * - * @param request incoming {@link SetChargingProfileRequest} to handle. - * @return outgoing {@link SetChargingProfileConfirmation} to reply with. - */ - SetChargingProfileConfirmation handleSetChargingProfileRequest(SetChargingProfileRequest request); + /** + * Handle a {@link SetChargingProfileRequest} and return a {@link SetChargingProfileConfirmation}. + * + * @param request incoming {@link SetChargingProfileRequest} to handle. + * @return outgoing {@link SetChargingProfileConfirmation} to reply with. + */ + SetChargingProfileConfirmation handleSetChargingProfileRequest(SetChargingProfileRequest request); - /** - * Handle a {@link ClearChargingProfileRequest} and return a {@link - * ClearChargingProfileConfirmation}. - * - * @param request incoming {@link ClearChargingProfileRequest} to handle. - * @return outgoing {@link ClearChargingProfileConfirmation} to reply with. - */ - ClearChargingProfileConfirmation handleClearChargingProfileRequest( - ClearChargingProfileRequest request); + /** + * Handle a {@link ClearChargingProfileRequest} and return a {@link + * ClearChargingProfileConfirmation}. + * + * @param request incoming {@link ClearChargingProfileRequest} to handle. + * @return outgoing {@link ClearChargingProfileConfirmation} to reply with. + */ + ClearChargingProfileConfirmation handleClearChargingProfileRequest( + ClearChargingProfileRequest request); + + /** + * Handle a {@link GetCompositeScheduleRequest} and return a {@link + * GetCompositeScheduleConfirmation}. + * + * @param request incoming {@link GetCompositeScheduleRequest} to handle. + * @return outgoing {@link GetCompositeScheduleConfirmation} to reply with. + */ + GetCompositeScheduleConfirmation handleGetCompositeScheduleRequest( + GetCompositeScheduleRequest request); } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientSmartChargingProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientSmartChargingProfile.java index b3586bd84..09a2ae92a 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientSmartChargingProfile.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientSmartChargingProfile.java @@ -1,22 +1,11 @@ package eu.chargetime.ocpp.feature.profile; - -import eu.chargetime.ocpp.feature.ClearChargingProfileFeature; -import eu.chargetime.ocpp.feature.Feature; -import eu.chargetime.ocpp.feature.ProfileFeature; -import eu.chargetime.ocpp.feature.SetChargingProfileFeature; -import eu.chargetime.ocpp.model.Confirmation; -import eu.chargetime.ocpp.model.Request; -import eu.chargetime.ocpp.model.smartcharging.ClearChargingProfileRequest; -import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest; -import java.util.ArrayList; -import java.util.UUID; - /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2017 Emil Christopher Solli Melar + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -37,35 +26,51 @@ * SOFTWARE. */ -/** Callback handler for client events of the Smart Charging feature profile. */ -public class ClientSmartChargingProfile implements Profile { - private ClientSmartChargingEventHandler eventHandler; - private ArrayList features; +import eu.chargetime.ocpp.feature.*; +import eu.chargetime.ocpp.model.Confirmation; +import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.smartcharging.ClearChargingProfileRequest; +import eu.chargetime.ocpp.model.smartcharging.GetCompositeScheduleRequest; +import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest; - public ClientSmartChargingProfile(ClientSmartChargingEventHandler handler) { - features = new ArrayList<>(); - eventHandler = handler; +import java.util.ArrayList; +import java.util.UUID; - features.add(new SetChargingProfileFeature(this)); - features.add(new ClearChargingProfileFeature(this)); - } +/** + * Callback handler for client events of the Smart Charging feature profile. + */ +public class ClientSmartChargingProfile implements Profile { + private ClientSmartChargingEventHandler eventHandler; + private ArrayList features; - @Override - public ProfileFeature[] getFeatureList() { - return features.toArray(new ProfileFeature[0]); - } + public ClientSmartChargingProfile(ClientSmartChargingEventHandler handler) { + features = new ArrayList<>(); + eventHandler = handler; - @Override - public Confirmation handleRequest(UUID sessionIndex, Request request) { - Confirmation result = null; + features.add(new ClearChargingProfileFeature(this)); + features.add(new GetCompositeScheduleFeature(this)); + features.add(new SetChargingProfileFeature(this)); + } - if (request instanceof SetChargingProfileRequest) { - result = eventHandler.handleSetChargingProfileRequest((SetChargingProfileRequest) request); - } else if (request instanceof ClearChargingProfileRequest) { - result = - eventHandler.handleClearChargingProfileRequest((ClearChargingProfileRequest) request); + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); } - return result; - } + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + Confirmation result = null; + + if (request instanceof ClearChargingProfileRequest) { + result = + eventHandler.handleClearChargingProfileRequest((ClearChargingProfileRequest) request); + } else if (request instanceof GetCompositeScheduleRequest) { + result = + eventHandler.handleGetCompositeScheduleRequest((GetCompositeScheduleRequest) request); + } else if (request instanceof SetChargingProfileRequest) { + result = eventHandler.handleSetChargingProfileRequest((SetChargingProfileRequest) request); + } + + return result; + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerCoreProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerCoreProfile.java index 83e237e9c..5555055e1 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerCoreProfile.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerCoreProfile.java @@ -1,164 +1,206 @@ -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. - */ +package eu.chargetime.ocpp.feature.profile; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz + + 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.core.AuthorizeRequest; -import eu.chargetime.ocpp.model.core.AvailabilityType; -import eu.chargetime.ocpp.model.core.BootNotificationRequest; -import eu.chargetime.ocpp.model.core.ChangeAvailabilityRequest; -import eu.chargetime.ocpp.model.core.ChangeConfigurationRequest; -import eu.chargetime.ocpp.model.core.ClearCacheRequest; -import eu.chargetime.ocpp.model.core.DataTransferRequest; -import eu.chargetime.ocpp.model.core.GetConfigurationRequest; -import eu.chargetime.ocpp.model.core.HeartbeatRequest; -import eu.chargetime.ocpp.model.core.MeterValuesRequest; -import eu.chargetime.ocpp.model.core.RemoteStartTransactionRequest; -import eu.chargetime.ocpp.model.core.RemoteStopTransactionRequest; -import eu.chargetime.ocpp.model.core.ResetRequest; -import eu.chargetime.ocpp.model.core.ResetType; -import eu.chargetime.ocpp.model.core.StartTransactionRequest; -import eu.chargetime.ocpp.model.core.StatusNotificationRequest; -import eu.chargetime.ocpp.model.core.StopTransactionRequest; -import eu.chargetime.ocpp.model.core.UnlockConnectorRequest; +import eu.chargetime.ocpp.model.core.*; + import java.util.HashSet; import java.util.UUID; public class ServerCoreProfile implements Profile { - private ServerCoreEventHandler handler; - private HashSet features; - - public ServerCoreProfile(ServerCoreEventHandler handler) { - this.handler = handler; - - features = new HashSet<>(); - features.add(new AuthorizeFeature(this)); - features.add(new BootNotificationFeature(this)); - features.add(new ChangeAvailabilityFeature(this)); - features.add(new ChangeConfigurationFeature(this)); - features.add(new ClearCacheFeature(this)); - features.add(new DataTransferFeature(this)); - features.add(new GetConfigurationFeature(this)); - features.add(new HeartbeatFeature(this)); - features.add(new MeterValuesFeature(this)); - features.add(new RemoteStartTransactionFeature(this)); - features.add(new RemoteStopTransactionFeature(this)); - features.add(new ResetFeature(this)); - features.add(new StartTransactionFeature(this)); - features.add(new StatusNotificationFeature(this)); - features.add(new StopTransactionFeature(this)); - features.add(new UnlockConnectorFeature(this)); - } - - @Override - public ProfileFeature[] getFeatureList() { - return features.toArray(new ProfileFeature[0]); - } - - @Override - public Confirmation handleRequest(UUID sessionIndex, Request request) { - Confirmation result = null; - - if (request instanceof AuthorizeRequest) { - result = handler.handleAuthorizeRequest(sessionIndex, (AuthorizeRequest) request); - } else if (request instanceof BootNotificationRequest) { - result = - handler.handleBootNotificationRequest(sessionIndex, (BootNotificationRequest) request); - } else if (request instanceof DataTransferRequest) { - result = handler.handleDataTransferRequest(sessionIndex, (DataTransferRequest) request); - } else if (request instanceof HeartbeatRequest) { - result = handler.handleHeartbeatRequest(sessionIndex, (HeartbeatRequest) request); - } else if (request instanceof MeterValuesRequest) { - result = handler.handleMeterValuesRequest(sessionIndex, (MeterValuesRequest) request); - } else if (request instanceof StartTransactionRequest) { - result = - handler.handleStartTransactionRequest(sessionIndex, (StartTransactionRequest) request); - } else if (request instanceof StatusNotificationRequest) { - result = - handler.handleStatusNotificationRequest( - sessionIndex, (StatusNotificationRequest) request); - } else if (request instanceof StopTransactionRequest) { - result = handler.handleStopTransactionRequest(sessionIndex, (StopTransactionRequest) request); + private ServerCoreEventHandler handler; + private HashSet features; + + public ServerCoreProfile(ServerCoreEventHandler handler) { + this.handler = handler; + + features = new HashSet<>(); + features.add(new AuthorizeFeature(this)); + features.add(new BootNotificationFeature(this)); + features.add(new ChangeAvailabilityFeature(null)); + features.add(new ChangeConfigurationFeature(null)); + features.add(new ClearCacheFeature(null)); + features.add(new DataTransferFeature(this)); + features.add(new GetConfigurationFeature(null)); + features.add(new HeartbeatFeature(this)); + features.add(new MeterValuesFeature(this)); + features.add(new RemoteStartTransactionFeature(null)); + features.add(new RemoteStopTransactionFeature(null)); + features.add(new ResetFeature(null)); + features.add(new StartTransactionFeature(this)); + features.add(new StatusNotificationFeature(this)); + features.add(new StopTransactionFeature(this)); + features.add(new UnlockConnectorFeature(null)); + } + + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); + } + + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + Confirmation result = null; + + if (request instanceof AuthorizeRequest) { + result = handler.handleAuthorizeRequest(sessionIndex, (AuthorizeRequest) request); + } else if (request instanceof BootNotificationRequest) { + result = + handler.handleBootNotificationRequest(sessionIndex, (BootNotificationRequest) request); + } else if (request instanceof DataTransferRequest) { + result = handler.handleDataTransferRequest(sessionIndex, (DataTransferRequest) request); + } else if (request instanceof HeartbeatRequest) { + result = handler.handleHeartbeatRequest(sessionIndex, (HeartbeatRequest) request); + } else if (request instanceof MeterValuesRequest) { + result = handler.handleMeterValuesRequest(sessionIndex, (MeterValuesRequest) request); + } else if (request instanceof StartTransactionRequest) { + result = + handler.handleStartTransactionRequest(sessionIndex, (StartTransactionRequest) request); + } else if (request instanceof StatusNotificationRequest) { + result = + handler.handleStatusNotificationRequest( + sessionIndex, (StatusNotificationRequest) request); + } else if (request instanceof StopTransactionRequest) { + result = handler.handleStopTransactionRequest(sessionIndex, (StopTransactionRequest) request); + } + + return result; + } + + /** + * Create a {@link ChangeAvailabilityRequest} with required values. + * + * @param connectorId integer, must be a non-negative number. + * * @param type the {@link AvailabilityType} of the connector. + * @return an instance of {@link ChangeAvailabilityRequest}. + * @see ChangeAvailabilityRequest + * @see ChangeAvailabilityFeature + */ + public ChangeAvailabilityRequest createChangeAvailabilityRequest( + AvailabilityType type, int connectorId) { + return new ChangeAvailabilityRequest(connectorId, type); + } + + /** + * Create a client {@link ChangeConfigurationRequest} with required values. + * + * @param key String, max 50 characters, case insensitive + * @param value String, max 500 characters, case insensitive + * @return an instance of {@link ChangeConfigurationRequest} + * @see ChangeConfigurationRequest + * @see ChangeConfigurationFeature + */ + public ChangeConfigurationRequest createChangeConfigurationRequest(String key, String value) { + return new ChangeConfigurationRequest(key, value); } - return result; - } - - public ChangeAvailabilityRequest createChangeAvailabilityRequest( - AvailabilityType type, int connectorId) { - ChangeAvailabilityRequest request = new ChangeAvailabilityRequest(); - request.setType(type); - request.setConnectorId(connectorId); - return request; - } - - public ChangeConfigurationRequest createChangeConfigurationRequest(String key, String value) { - ChangeConfigurationRequest request = new ChangeConfigurationRequest(); - request.setKey(key); - request.setValue(value); - return request; - } - - public ClearCacheRequest createClearCacheRequest() { - return new ClearCacheRequest(); - } - - public DataTransferRequest createDataTransferRequest(String vendorId) { - DataTransferRequest request = new DataTransferRequest(); - request.setVendorId(vendorId); - return request; - } - - public GetConfigurationRequest createGetConfigurationRequest() { - return new GetConfigurationRequest(); - } - - public RemoteStartTransactionRequest createRemoteStartTransactionRequest(String idToken) { - RemoteStartTransactionRequest request = new RemoteStartTransactionRequest(); - request.setIdTag(idToken); - return request; - } - - public RemoteStopTransactionRequest createRemoteStopTransactionRequest(Integer transactionId) { - RemoteStopTransactionRequest request = new RemoteStopTransactionRequest(); - request.setTransactionId(transactionId); - return request; - } - - public ResetRequest createResetRequest(ResetType type) { - ResetRequest request = new ResetRequest(); - request.setType(type); - return request; - } - - public UnlockConnectorRequest createUnlockConnectorRequest(int connectorId) { - UnlockConnectorRequest request = new UnlockConnectorRequest(); - request.setConnectorId(connectorId); - return request; - } + /** + * Create a client {@link ClearCacheRequest}. + * + * @return an instance of {@link ClearCacheRequest} + * @see ClearCacheRequest + * @see ClearCacheFeature + */ + public ClearCacheRequest createClearCacheRequest() { + return new ClearCacheRequest(); + } + + /** + * Create a client {@link DataTransferRequest} required values. + * + * @param vendorId Vendor identification. + * @return an instance of {@link DataTransferRequest} + * @see DataTransferRequest + * @see DataTransferFeature + */ + public DataTransferRequest createDataTransferRequest(String vendorId) { + return new DataTransferRequest(vendorId); + } + + /** + * Create a client {@link GetConfigurationRequest}. + * + * @return an instance of {@link GetConfigurationRequest} + * @see GetConfigurationRequest + * @see GetConfigurationFeature + */ + public GetConfigurationRequest createGetConfigurationRequest() { + return new GetConfigurationRequest(); + } + + /** + * Create a client {@link RemoteStartTransactionRequest} with required values. + * + * @param idTag a String with max length 20 + * @return an instance of {@link RemoteStartTransactionRequest} + * @see RemoteStartTransactionRequest + * @see RemoteStartTransactionFeature + */ + public RemoteStartTransactionRequest createRemoteStartTransactionRequest(String idTag) { + return new RemoteStartTransactionRequest(idTag); + } + + /** + * Create a client {@link RemoteStopTransactionRequest} with required values. + * + * @param transactionId integer, transaction id + * @return an instance of {@link RemoteStopTransactionRequest} + * @see RemoteStopTransactionRequest + * @see RemoteStartTransactionFeature + */ + public RemoteStopTransactionRequest createRemoteStopTransactionRequest(Integer transactionId) { + return new RemoteStopTransactionRequest(transactionId); + } + + /** + * Create a client {@link ResetRequest} with required values. + * + * @param type the {@link ResetType} + * @return an instance of {@link ResetRequest} + * @see ResetRequest + * @see ResetFeature + */ + public ResetRequest createResetRequest(ResetType type) { + return new ResetRequest(type); + } + + /** + * Create a client {@link UnlockConnectorRequest} with required values.. + * + * @param connectorId integer, value > 0 + * @return an instance of {@link UnlockConnectorRequest} + * @see UnlockConnectorRequest + * @see UnlockConnectorFeature + */ + public UnlockConnectorRequest createUnlockConnectorRequest(int connectorId) { + return new UnlockConnectorRequest(connectorId); + } } 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 69c8d2e1f..dfef09e93 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 @@ -5,6 +5,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -30,42 +31,71 @@ of this software and associated documentation files (the "Software"), to deal 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.time.ZonedDateTime; import java.util.HashSet; import java.util.UUID; public class ServerFirmwareManagementProfile implements Profile { - private final ServerFirmwareManagementEventHandler eventHandler; - private HashSet features; - - public ServerFirmwareManagementProfile(ServerFirmwareManagementEventHandler eventHandler) { - this.eventHandler = eventHandler; - features = new HashSet<>(); - features.add(new GetDiagnosticsFeature(this)); - features.add(new DiagnosticsStatusNotificationFeature(this)); - features.add(new FirmwareStatusNotificationFeature(this)); - features.add(new UpdateFirmwareFeature(this)); - } - - @Override - public ProfileFeature[] getFeatureList() { - return features.toArray(new ProfileFeature[0]); - } - - @Override - public Confirmation handleRequest(UUID sessionIndex, Request request) { - Confirmation result = null; - - if (request instanceof DiagnosticsStatusNotificationRequest) { - result = - eventHandler.handleDiagnosticsStatusNotificationRequest( - sessionIndex, (DiagnosticsStatusNotificationRequest) request); - } else if (request instanceof FirmwareStatusNotificationRequest) { - result = - eventHandler.handleFirmwareStatusNotificationRequest( - sessionIndex, (FirmwareStatusNotificationRequest) request); + private final ServerFirmwareManagementEventHandler eventHandler; + private HashSet features; + + public ServerFirmwareManagementProfile(ServerFirmwareManagementEventHandler eventHandler) { + this.eventHandler = eventHandler; + features = new HashSet<>(); + features.add(new GetDiagnosticsFeature(null)); + features.add(new DiagnosticsStatusNotificationFeature(this)); + features.add(new FirmwareStatusNotificationFeature(this)); + features.add(new UpdateFirmwareFeature(null)); + } + + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); } - return result; - } + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + Confirmation result = null; + + if (request instanceof DiagnosticsStatusNotificationRequest) { + result = + eventHandler.handleDiagnosticsStatusNotificationRequest( + sessionIndex, (DiagnosticsStatusNotificationRequest) request); + } else if (request instanceof FirmwareStatusNotificationRequest) { + result = + eventHandler.handleFirmwareStatusNotificationRequest( + sessionIndex, (FirmwareStatusNotificationRequest) request); + } + + return result; + } + + /** + * Create a client {@link GetDiagnosticsRequest} with required values. + * + * @param location String, the destination folder + * @return an instance of {@link GetDiagnosticsRequest} + * @see GetDiagnosticsRequest + * @see GetDiagnosticsFeature + */ + public GetDiagnosticsRequest createGetDiagnosticsRequest(String location) { + return new GetDiagnosticsRequest(location); + } + + /** + * Create a client {@link UpdateFirmwareRequest} with required values. + * + * @param location String, a URI with the firmware + * * @param retrieveDate ZonedDateTime, date and time of retrieving + * @return an instance of {@link UpdateFirmwareRequest} + * @see UpdateFirmwareRequest + * @see UpdateFirmwareFeature + */ + public UpdateFirmwareRequest createUpdateFirmwareRequest(String location, ZonedDateTime retrieveDate) { + return new UpdateFirmwareRequest(location, retrieveDate); + } } 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 index e9b353dae..1bdd4b12f 100644 --- 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 @@ -5,6 +5,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -25,29 +26,58 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.feature.*; +import eu.chargetime.ocpp.feature.Feature; +import eu.chargetime.ocpp.feature.GetLocalListVersionFeature; +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.SendLocalListFeature; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; +import eu.chargetime.ocpp.model.localauthlist.*; + import java.util.HashSet; import java.util.UUID; public class ServerLocalAuthListProfile implements Profile { - private HashSet featureList; + private HashSet featureList; + + public ServerLocalAuthListProfile() { + featureList = new HashSet<>(); + featureList.add(new GetLocalListVersionFeature(null)); + featureList.add(new SendLocalListFeature(null)); + } + + @Override + public ProfileFeature[] getFeatureList() { + return featureList.toArray(new ProfileFeature[0]); + } - public ServerLocalAuthListProfile() { - featureList = new HashSet<>(); - featureList.add(new GetLocalListVersionFeature(this)); - featureList.add(new SendLocalListFeature(this)); - } + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + return null; + } - @Override - public ProfileFeature[] getFeatureList() { - return featureList.toArray(new ProfileFeature[0]); - } + /** + * Create a client {@link SendLocalListRequest} with required values. + * + * @param listVersion required, version number of the list. + * @param updateType required, type of update + * @return an instance of {@link SendLocalListConfirmation}. + * @see SendLocalListRequest + * @see SendLocalListFeature + */ + public SendLocalListRequest createSendLocalListRequest(int listVersion, UpdateType updateType) { + return new SendLocalListRequest(listVersion, updateType); + } - @Override - public Confirmation handleRequest(UUID sessionIndex, Request request) { - return null; - } + /** + * Create a client {@link GetLocalListVersionRequest} with required values. + * + * @return an instance of {@link GetLocalListVersionConfirmation}. + * @see GetLocalListVersionRequest + * @see GetLocalListVersionFeature + */ + public GetLocalListVersionRequest createGetLocalListVersionRequest() { + return new GetLocalListVersionRequest(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerRemoteTriggerProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerRemoteTriggerProfile.java index 29d3b3c13..fe7cc86c3 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerRemoteTriggerProfile.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerRemoteTriggerProfile.java @@ -7,16 +7,19 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequestType; + import java.util.HashSet; import java.util.UUID; /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2017 Emil Christopher Solli Melar +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2017 Emil Christopher Solli Melar +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -39,32 +42,49 @@ of this software and associated documentation files (the "Software"), to deal public class ServerRemoteTriggerProfile implements Profile { - private HashSet features; + private HashSet features; - public ServerRemoteTriggerProfile() { + public ServerRemoteTriggerProfile() { - features = new HashSet<>(); - features.add(new TriggerMessageFeature(this)); - } + features = new HashSet<>(); + features.add(new TriggerMessageFeature(null)); + } - @Override - public ProfileFeature[] getFeatureList() { - return features.toArray(new ProfileFeature[0]); - } + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); + } - @Override - public Confirmation handleRequest(UUID sessionIndex, Request request) { - return null; - } + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + return null; + } - public TriggerMessageRequest createTriggerMessageRequest(TriggerMessageRequestType type) { - return createTriggerMessageRequest(type, null); - } + /** + * Create a client {@link TriggerMessageRequest} with required values. + * + * @param triggerMessageRequestType {@link TriggerMessageRequestType} + * @return an instance of {@link TriggerMessageRequest} + * @see TriggerMessageRequest + * @see TriggerMessageFeature + */ + public TriggerMessageRequest createTriggerMessageRequest(TriggerMessageRequestType triggerMessageRequestType) { + return createTriggerMessageRequest(triggerMessageRequestType, null); + } - public TriggerMessageRequest createTriggerMessageRequest( - TriggerMessageRequestType type, Integer connectorId) { - TriggerMessageRequest request = new TriggerMessageRequest(type); - request.setConnectorId(connectorId); - return request; - } + /** + * Create a client {@link TriggerMessageRequest} with required values. + * + * @param triggerMessageRequestType {@link TriggerMessageRequestType} + * @param connectorId integer. value > 0 + * @return an instance of {@link TriggerMessageRequest} + * @see TriggerMessageRequest + * @see TriggerMessageFeature + */ + public TriggerMessageRequest createTriggerMessageRequest( + TriggerMessageRequestType triggerMessageRequestType, Integer connectorId) { + TriggerMessageRequest request = new TriggerMessageRequest(triggerMessageRequestType); + request.setConnectorId(connectorId); + return request; + } } 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 index a507c0633..9f2c1d75e 100644 --- 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 @@ -6,6 +6,7 @@ Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2018 Mikhail Kladkevich + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -26,29 +27,66 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import eu.chargetime.ocpp.feature.*; +import eu.chargetime.ocpp.feature.CancelReservationFeature; +import eu.chargetime.ocpp.feature.Feature; +import eu.chargetime.ocpp.feature.ProfileFeature; +import eu.chargetime.ocpp.feature.ReserveNowFeature; 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.time.ZonedDateTime; import java.util.HashSet; import java.util.UUID; public class ServerReservationProfile implements Profile { - private HashSet features; + private HashSet features; + + public ServerReservationProfile() { + features = new HashSet<>(); + features.add(new ReserveNowFeature(null)); + features.add(new CancelReservationFeature(null)); + } + + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); + } + + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + return null; + } - public ServerReservationProfile() { - features = new HashSet<>(); - features.add(new ReserveNowFeature(this)); - features.add(new CancelReservationFeature(this)); - } + /** + * Create a client {@link CancelReservationRequest} with required values. + * + * @param reservationId Integer, id of the reservation + * @return an instance of {@link CancelReservationRequest} + * @see CancelReservationRequest + * @see CancelReservationFeature + */ + CancelReservationRequest createCancelReservationRequest(Integer reservationId) { + return new CancelReservationRequest(reservationId); + } - @Override - public ProfileFeature[] getFeatureList() { - return features.toArray(new ProfileFeature[0]); - } + /** + * Create a client {@link ReserveNowRequest} with required values. + * + * @param connectorId Integer, the destination connectorId + * @param expiryDate ZonedDateTime, end of reservation + * @param idTag String, the identifier + * @param reservationId Integer, id of reservation + * @return an instance of {@link ReserveNowRequest} + * @see ReserveNowRequest + * @see ReserveNowFeature + */ + ReserveNowRequest createReserveNowRequest(Integer connectorId, ZonedDateTime expiryDate, String idTag, Integer reservationId, String parentIdTag) { + ReserveNowRequest request = new ReserveNowRequest(connectorId, expiryDate, idTag, reservationId); + request.setParentIdTag(parentIdTag); - @Override - public Confirmation handleRequest(UUID sessionIndex, Request request) { - return null; - } + return request; + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerSmartChargingProfile.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerSmartChargingProfile.java index e84baa1bd..f2ba5da4e 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerSmartChargingProfile.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerSmartChargingProfile.java @@ -1,14 +1,13 @@ package eu.chargetime.ocpp.feature.profile; -import eu.chargetime.ocpp.feature.ClearChargingProfileFeature; -import eu.chargetime.ocpp.feature.Feature; -import eu.chargetime.ocpp.feature.ProfileFeature; -import eu.chargetime.ocpp.feature.SetChargingProfileFeature; +import eu.chargetime.ocpp.feature.*; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.model.core.ChargingProfile; import eu.chargetime.ocpp.model.smartcharging.ClearChargingProfileRequest; +import eu.chargetime.ocpp.model.smartcharging.GetCompositeScheduleRequest; import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest; + import java.util.HashSet; import java.util.UUID; @@ -20,6 +19,7 @@ * Copyright (C) 2017 Emil Christopher Solli Melar * Copyright (C) 2018 Fabian Röhr * Copyright (C) 2018 Robin Roscher + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -42,33 +42,61 @@ public class ServerSmartChargingProfile implements Profile { - private HashSet features; + private HashSet features; + + public ServerSmartChargingProfile() { + features = new HashSet<>(); + features.add(new ClearChargingProfileFeature(null)); + features.add(new GetCompositeScheduleFeature(null)); + features.add(new SetChargingProfileFeature(null)); + } + + @Override + public ProfileFeature[] getFeatureList() { + return features.toArray(new ProfileFeature[0]); + } - public ServerSmartChargingProfile() { - features = new HashSet<>(); - features.add(new SetChargingProfileFeature(this)); - features.add(new ClearChargingProfileFeature(this)); - } + @Override + public Confirmation handleRequest(UUID sessionIndex, Request request) { + return null; + } - @Override - public ProfileFeature[] getFeatureList() { - return features.toArray(new ProfileFeature[0]); - } + /** + * Create a client {@link SetChargingProfileRequest} with required values. + * + * @param connectorId integer. value > 0 + * @param chargingProfile the {@link ChargingProfile} + * @return an instance of {@link SetChargingProfileRequest} + * @see SetChargingProfileRequest + * @see SetChargingProfileFeature + */ + public SetChargingProfileRequest createSetChargingProfileRequest( + Integer connectorId, ChargingProfile chargingProfile) { + return new SetChargingProfileRequest(connectorId, chargingProfile); + } - @Override - public Confirmation handleRequest(UUID sessionIndex, Request request) { - return null; - } + /** + * Create a client {@link ClearChargingProfileRequest}. + * + * @return an instance of {@link ClearChargingProfileRequest} + * @see ClearChargingProfileRequest + * @see ClearChargingProfileFeature + */ + public ClearChargingProfileRequest createClearChargingProfileRequest() { + return new ClearChargingProfileRequest(); + } - public SetChargingProfileRequest createSetChargingProfileRequest( - int connectorId, ChargingProfile profile) { - SetChargingProfileRequest request = new SetChargingProfileRequest(); - request.setConnectorId(connectorId); - request.setCsChargingProfiles(profile); - return request; - } + /** + * Create a client {@link GetCompositeScheduleRequest} with required values. + * + * @param connectorId Integer + * @param duration Integer + * @return an instance of {@link GetCompositeScheduleRequest} + * @see GetCompositeScheduleRequest + * @see GetCompositeScheduleFeature + */ + public GetCompositeScheduleRequest createGetCompositeScheduleRequest(Integer connectorId, Integer duration) { + return new GetCompositeScheduleRequest(connectorId, duration); + } - public ClearChargingProfileRequest createClearChargingProfileRequest() { - return new ClearChargingProfileRequest(); - } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/AuthorizeConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/AuthorizeConfirmation.java index 6d11079eb..8104eed91 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/AuthorizeConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/AuthorizeConfirmation.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,59 +31,80 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; -/** Sent by the Central System to the Charge Point in response to a {@link AuthorizeRequest}. */ +/** + * Sent by the Central System to the Charge Point in response to a {@link AuthorizeRequest}. + */ @XmlRootElement(name = "authorizeResponse") public class AuthorizeConfirmation implements Confirmation { - private IdTagInfo idTagInfo; - - /** - * This contains information about authorization status, expiry and parent id. - * - * @return an instance of {@link IdTagInfo}. - */ - public IdTagInfo getIdTagInfo() { - return idTagInfo; - } - - /** - * Required. This contains information about authorization status, expiry and parent id. - * - * @param idTagInfo an instance of {@link IdTagInfo}. - */ - @XmlElement - public void setIdTagInfo(IdTagInfo idTagInfo) { - this.idTagInfo = idTagInfo; - } - - @Override - public boolean validate() { - boolean valid = true; - if (valid &= idTagInfo != null) valid &= idTagInfo.validate(); - return valid; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - AuthorizeConfirmation response = (AuthorizeConfirmation) o; - return Objects.equals(idTagInfo, response.idTagInfo); - } - - @Override - public int hashCode() { - return Objects.hash(idTagInfo); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("idTagInfo", idTagInfo) - .add("isValid", validate()) - .toString(); - } + + private IdTagInfo idTagInfo; + + /** + * @deprecated use {@link #AuthorizeConfirmation(IdTagInfo)} to be sure to set required fields + */ + @Deprecated + public AuthorizeConfirmation() { + + } + + /** + * Handle required fields. + * + * @param idTagInfo the {@link IdTagInfo}, see {@link #setIdTagInfo(IdTagInfo)} + */ + public AuthorizeConfirmation(IdTagInfo idTagInfo) { + setIdTagInfo(idTagInfo); + } + + /** + * This contains information about authorization status, expiry and parent id. + * + * @return an instance of {@link IdTagInfo}. + */ + public IdTagInfo getIdTagInfo() { + return idTagInfo; + } + + /** + * Required. This contains information about authorization status, expiry and parent id. + * + * @param idTagInfo an instance of {@link IdTagInfo}. + */ + @XmlElement + public void setIdTagInfo(IdTagInfo idTagInfo) { + this.idTagInfo = idTagInfo; + } + + @Override + public boolean validate() { + boolean valid = true; + if (valid &= idTagInfo != null) valid &= idTagInfo.validate(); + return valid; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AuthorizeConfirmation response = (AuthorizeConfirmation) o; + return Objects.equals(idTagInfo, response.idTagInfo); + } + + @Override + public int hashCode() { + return Objects.hash(idTagInfo); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("idTagInfo", idTagInfo) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/AuthorizeRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/AuthorizeRequest.java index 6f4feb0a9..b30707e6c 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/AuthorizeRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/AuthorizeRequest.java @@ -4,17 +4,20 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -35,77 +38,84 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -/** Sent by the Charge Point to the Central System. */ +/** + * Sent by the Charge Point to the Central System. + */ @XmlRootElement public class AuthorizeRequest implements Request { - private static final int IDTAG_MAX_LENGTH = 20; - private static final String ERROR_MESSAGE = "Exceeded limit of " + IDTAG_MAX_LENGTH + " chars"; - - private String idTag; - - public AuthorizeRequest() {} - - /** - * Handle required fields. - * - * @param idToken authorize id. - */ - public AuthorizeRequest(String idToken) { - setIdTag(idToken); - } - - /** - * This contains the identifier that needs to be authorized. - * - * @return String, max 20 characters. Case insensitive. - */ - public String getIdTag() { - return idTag; - } - - /** - * Required. This contains the identifier that needs to be authorized. - * - * @param idTag String, max 20 characters. Case insensitive. - */ - @XmlElement - public void setIdTag(String idTag) { - if (!ModelUtil.validate(idTag, IDTAG_MAX_LENGTH)) { - throw new PropertyConstraintException(idTag.length(), ERROR_MESSAGE); + private static final int IDTAG_MAX_LENGTH = 20; + private static final String ERROR_MESSAGE = "Exceeded limit of " + IDTAG_MAX_LENGTH + " chars"; + + private String idTag; + + /** + * @deprecated use {@link #AuthorizeRequest(String)} to be sure to set required fields + */ + @Deprecated + public AuthorizeRequest() { + } + + /** + * Handle required fields. + * + * @param idTag authorize id, see {@link #setIdTag(String)} + */ + public AuthorizeRequest(String idTag) { + setIdTag(idTag); + } + + /** + * This contains the identifier that needs to be authorized. + * + * @return String, max 20 characters. Case insensitive. + */ + public String getIdTag() { + return idTag; + } + + /** + * Required. This contains the identifier that needs to be authorized. + * + * @param idTag String, max 20 characters. Case insensitive. + */ + @XmlElement + public void setIdTag(String idTag) { + if (!ModelUtil.validate(idTag, IDTAG_MAX_LENGTH)) { + throw new PropertyConstraintException(idTag.length(), ERROR_MESSAGE); + } + + this.idTag = idTag; + } + + @Override + public boolean validate() { + return ModelUtil.validate(idTag, IDTAG_MAX_LENGTH); + } + + @Override + public boolean transactionRelated() { + return false; } - this.idTag = idTag; - } - - @Override - public boolean validate() { - return ModelUtil.validate(idTag, IDTAG_MAX_LENGTH); - } - - @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; - AuthorizeRequest request = (AuthorizeRequest) o; - return Objects.equals(idTag, request.idTag); - } - - @Override - public int hashCode() { - return Objects.hash(idTag); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("idTag", idTag) - .add("isValid", validate()) - .toString(); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AuthorizeRequest request = (AuthorizeRequest) o; + return Objects.equals(idTag, request.idTag); + } + + @Override + public int hashCode() { + return Objects.hash(idTag); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("idTag", idTag) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/BootNotificationConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/BootNotificationConfirmation.java index 6f6b0d6b4..3d9ea8627 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/BootNotificationConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/BootNotificationConfirmation.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -30,11 +32,12 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Objects; /** * Sent by the Central System to the Charge Point in response to a {@link BootNotificationRequest}. @@ -45,126 +48,147 @@ of this software and associated documentation files (the "Software"), to deal @XmlType(propOrder = {"status", "currentTime", "interval"}) public class BootNotificationConfirmation implements Confirmation { - private Calendar currentTime; - private int interval; - private RegistrationStatus status; - - /** - * Central System's current time. - * - * @return an instance of Calendar. - */ - public Calendar getCurrentTime() { - return currentTime; - } - - /** - * Central System's current time. - * - * @return an instance of Calendar. - */ - @Deprecated - public Calendar objCurrentTime() { - return currentTime; - } - - /** - * Required. This contains the Central System’s current time. - * - * @param currentTime Central System’s current time. - */ - @XmlElement - public void setCurrentTime(Calendar currentTime) { - this.currentTime = currentTime; - } - - /** - * When RegistrationStatus is Accepted, this contains the heartbeat interval in seconds. If the - * Central System returns something other than Accepted, the value of the interval field indicates - * the minimum wait time before sending a next BootNotification request. - * - * @return Heartbeat/delay interval in seconds. - */ - public int getInterval() { - return interval; - } - - /** - * Required. When RegistrationStatus is Accepted, this contains the heartbeat interval in seconds. - * If the Central System returns something other than Accepted, the value of the interval field - * indicates the minimum wait time before sending a next BootNotification request. - * - * @param interval heartbeat/delay interval in seconds. Min value 0. - */ - @XmlElement - public void setInterval(int interval) { - if (interval <= 0) { - throw new PropertyConstraintException(interval, "interval be a positive value"); + private ZonedDateTime currentTime; + private Integer interval; + private RegistrationStatus status; + + /** + * @deprecated use {@link #BootNotificationConfirmation(ZonedDateTime, Integer, RegistrationStatus)} to be sure to set required fields + */ + @Deprecated + public BootNotificationConfirmation() { + + } + + /** + * Handle required fields. + * + * @param currentTime Central System’s current time, see {@link #setCurrentTime(ZonedDateTime)} + * @param interval heartbeat/delay interval in seconds. Min value 0, see {@link #setInterval(Integer)} + * @param status Charge Points registration status, see {@link #setStatus(RegistrationStatus)} + */ + public BootNotificationConfirmation(ZonedDateTime currentTime, Integer interval, RegistrationStatus status) { + setCurrentTime(currentTime); + setInterval(interval); + setStatus(status); + } + + /** + * Central System's current time. + * + * @return an instance of {@link ZonedDateTime}. + */ + public ZonedDateTime getCurrentTime() { + return currentTime; + } + + /** + * Required. This contains the Central System’s current time. + * + * @param currentTime Central System’s current time. + */ + @XmlElement + public void setCurrentTime(ZonedDateTime currentTime) { + this.currentTime = currentTime; + } + + /** + * Central System's current time. + * + * @return an instance of {@link ZonedDateTime}. + */ + @Deprecated + public ZonedDateTime objCurrentTime() { + return currentTime; + } + + /** + * When RegistrationStatus is Accepted, this contains the heartbeat interval in seconds. If the + * Central System returns something other than Accepted, the value of the interval field indicates + * the minimum wait time before sending a next BootNotification request. + * + * @return Heartbeat/delay interval in seconds. + */ + public Integer getInterval() { + return interval; } - this.interval = interval; - } - - /** - * This contains whether the Charge Point has been registered within the System Central. - * - * @return Charge Points registration status as {@link RegistrationStatus}. - */ - @Deprecated - public RegistrationStatus objStatus() { - return status; - } - - /** - * This contains whether the Charge Point has been registered within the System Central. - * - * @return Charge Points registration status as {@link RegistrationStatus}. - */ - public RegistrationStatus getStatus() { - return status; - } - - /** - * Required. This contains whether the Charge Point has been registered within the System Central. - * - * @param status Charge Points registration status. - */ - @XmlElement - public void setStatus(RegistrationStatus status) { - this.status = status; - } - - @Override - public boolean validate() { - boolean valid = status != null; - valid &= currentTime != null; - valid &= interval > 0; - - return valid; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - BootNotificationConfirmation that = (BootNotificationConfirmation) o; - return interval == that.interval - && Objects.equals(currentTime, that.currentTime) - && status == that.status; - } - - @Override - public int hashCode() { - return Objects.hash(currentTime, interval, status); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("currentTime", currentTime) - .add("interval", interval) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + /** + * Required. When RegistrationStatus is Accepted, this contains the heartbeat interval in seconds. + * If the Central System returns something other than Accepted, the value of the interval field + * indicates the minimum wait time before sending a next BootNotification request. + * + * @param interval heartbeat/delay interval in seconds. Min value 0. + */ + @XmlElement + public void setInterval(Integer interval) { + if (interval <= 0) { + throw new PropertyConstraintException(interval, "interval be a positive value"); + } + + this.interval = interval; + } + + /** + * This contains whether the Charge Point has been registered within the System Central. + * + * @return Charge Points registration status as {@link RegistrationStatus}. + */ + @Deprecated + public RegistrationStatus objStatus() { + return status; + } + + /** + * This contains whether the Charge Point has been registered within the System Central. + * + * @return Charge Points registration status as {@link RegistrationStatus}. + */ + public RegistrationStatus getStatus() { + return status; + } + + /** + * Required. This contains whether the Charge Point has been registered within the System Central. + * + * @param status Charge Points registration status. + */ + @XmlElement + public void setStatus(RegistrationStatus status) { + this.status = status; + } + + @Override + public boolean validate() { + boolean valid = status != null; + valid &= currentTime != null; + valid &= interval != null && interval > 0; + + return valid; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BootNotificationConfirmation that = (BootNotificationConfirmation) o; + return interval == that.interval + && Objects.equals(currentTime, that.currentTime) + && status == that.status; + } + + @Override + public int hashCode() { + return Objects.hash(currentTime, interval, status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("currentTime", currentTime) + .add("interval", interval) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/BootNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/BootNotificationRequest.java index 0936e1a76..0be01fd03 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/BootNotificationRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/BootNotificationRequest.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -31,334 +33,342 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Objects; -/** Sent by the Charge Point to the Central System. */ +/** + * Sent by the Charge Point to the Central System. + */ @XmlRootElement @XmlType( - propOrder = { - "chargePointVendor", - "chargePointModel", - "chargePointSerialNumber", - "chargeBoxSerialNumber", - "firmwareVersion", - "iccid", - "imsi", - "meterType", - "meterSerialNumber" - }) + propOrder = { + "chargePointVendor", + "chargePointModel", + "chargePointSerialNumber", + "chargeBoxSerialNumber", + "firmwareVersion", + "iccid", + "imsi", + "meterType", + "meterSerialNumber" + }) public class BootNotificationRequest implements Request { - private static final int STRING_20_CHAR_MAX_LENGTH = 20; - private static final int STRING_25_CHAR_MAX_LENGTH = 25; - private static final int STRING_50_CHAR_MAX_LENGTH = 50; - private static final String ERROR_MESSAGE = "Exceeded limit of %s chars"; - - private String chargePointVendor; - private String chargePointModel; - private String chargeBoxSerialNumber; - private String chargePointSerialNumber; - private String firmwareVersion; - private String iccid; - private String imsi; - private String meterSerialNumber; - private String meterType; - - public BootNotificationRequest() {} - - /** - * Handle required fields. - * - * @param vendor Charge Point vendor, see {@link #setChargePointVendor(String)}. - * @param model Charge Point model, see {@link #setChargePointModel(String)}. - */ - public BootNotificationRequest(String vendor, String model) { - chargePointVendor = vendor; - chargePointModel = model; - } - - /** - * This contains a value that identifies the vendor of the ChargePoint. - * - * @return Vendor of the Charge Point. - */ - public String getChargePointVendor() { - return chargePointVendor; - } - - /** - * Required. This contains a value that identifies the vendor of the ChargePoint. - * - * @param chargePointVendor String, max 20 characters, case insensitive. - */ - @XmlElement - public void setChargePointVendor(String chargePointVendor) { - if (!ModelUtil.validate(chargePointVendor, STRING_20_CHAR_MAX_LENGTH)) { - throw new PropertyConstraintException( - chargePointVendor.length(), validationErrorMessage(STRING_20_CHAR_MAX_LENGTH)); + private static final int STRING_20_CHAR_MAX_LENGTH = 20; + private static final int STRING_25_CHAR_MAX_LENGTH = 25; + private static final int STRING_50_CHAR_MAX_LENGTH = 50; + private static final String ERROR_MESSAGE = "Exceeded limit of %s chars"; + + private String chargePointVendor; + private String chargePointModel; + private String chargeBoxSerialNumber; + private String chargePointSerialNumber; + private String firmwareVersion; + private String iccid; + private String imsi; + private String meterSerialNumber; + private String meterType; + + /** + * @deprecated use {@link #BootNotificationRequest(String, String)} to be sure to set required fields + */ + @Deprecated + public BootNotificationRequest() { + } + + /** + * Handle required fields. + * + * @param chargePointVendor Charge Point vendor, see {@link #setChargePointVendor(String)}. + * @param chargePointModel Charge Point model, see {@link #setChargePointModel(String)}. + */ + public BootNotificationRequest(String chargePointVendor, String chargePointModel) { + setChargePointModel(chargePointModel); + setChargePointVendor(chargePointVendor); + } + + private static String validationErrorMessage(int maxAllowedLength) { + return String.format(ERROR_MESSAGE, maxAllowedLength); + } + + /** + * This contains a value that identifies the vendor of the ChargePoint. + * + * @return Vendor of the Charge Point. + */ + public String getChargePointVendor() { + return chargePointVendor; + } + + /** + * Required. This contains a value that identifies the vendor of the ChargePoint. + * + * @param chargePointVendor String, max 20 characters, case insensitive. + */ + @XmlElement + public void setChargePointVendor(String chargePointVendor) { + if (!ModelUtil.validate(chargePointVendor, STRING_20_CHAR_MAX_LENGTH)) { + throw new PropertyConstraintException( + chargePointVendor.length(), validationErrorMessage(STRING_20_CHAR_MAX_LENGTH)); + } + + this.chargePointVendor = chargePointVendor; + } + + /** + * This contains a value that identifies the model of the ChargePoint. + * + * @return Model of the Charge Point. + */ + public String getChargePointModel() { + return chargePointModel; + } + + /** + * Required. This contains a value that identifies the model of the ChargePoint. + * + * @param chargePointModel String, max 20 characters, case insensitive. + */ + @XmlElement + public void setChargePointModel(String chargePointModel) { + if (!ModelUtil.validate(chargePointModel, STRING_20_CHAR_MAX_LENGTH)) { + throw new PropertyConstraintException( + chargePointModel.length(), validationErrorMessage(STRING_20_CHAR_MAX_LENGTH)); + } + + this.chargePointModel = chargePointModel; + } + + /** + * This contains a value that identifies the serial number of the Charge Box inside the Charge + * Point. + * + * @return Serial Number of the Charge Point. + * @deprecated will be removed in future version. See {@link #getChargePointSerialNumber()}. + */ + @Deprecated() + public String getChargeBoxSerialNumber() { + return chargeBoxSerialNumber; + } + + /** + * Optional. This contains a value that identifies the serial number of the Charge Box inside the + * Charge Point. + * + * @param chargeBoxSerialNumber String, max 25 characters, case insensitive. + * @deprecated will be removed in future version. See {@link #setChargePointSerialNumber(String)}. + */ + @Deprecated() + public void setChargeBoxSerialNumber(String chargeBoxSerialNumber) { + if (!ModelUtil.validate(chargeBoxSerialNumber, STRING_25_CHAR_MAX_LENGTH)) { + throw new PropertyConstraintException( + chargeBoxSerialNumber.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH)); + } + + this.chargeBoxSerialNumber = chargeBoxSerialNumber; + } + + /** + * This contains a value that identifies the serial number of the Charge Point. + * + * @return Serial Number of the Charge Point. + */ + public String getChargePointSerialNumber() { + return chargePointSerialNumber; + } + + /** + * Optional. This contains a value that identifies the serial number of the Charge Point. + * + * @param chargePointSerialNumber String, max 25 characters, case insensitive. + */ + @XmlElement + public void setChargePointSerialNumber(String chargePointSerialNumber) { + if (!ModelUtil.validate(chargePointSerialNumber, STRING_25_CHAR_MAX_LENGTH)) { + throw new PropertyConstraintException( + chargePointSerialNumber.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH)); + } + + this.chargePointSerialNumber = chargePointSerialNumber; + } + + /** + * This contains the firmware version of the Charge Point. + * + * @return Firmware version of Charge Point. + */ + public String getFirmwareVersion() { + return firmwareVersion; + } + + /** + * Optional. This contains the firmware version of the Charge Point. + * + * @param firmwareVersion String, max 50 characters, case insensitive. + */ + @XmlElement + public void setFirmwareVersion(String firmwareVersion) { + if (!ModelUtil.validate(firmwareVersion, STRING_50_CHAR_MAX_LENGTH)) { + throw new PropertyConstraintException( + firmwareVersion.length(), validationErrorMessage(STRING_50_CHAR_MAX_LENGTH)); + } + + this.firmwareVersion = firmwareVersion; } - this.chargePointVendor = chargePointVendor; - } - - /** - * This contains a value that identifies the model of the ChargePoint. - * - * @return Model of the Charge Point. - */ - public String getChargePointModel() { - return chargePointModel; - } - - /** - * Required. This contains a value that identifies the model of the ChargePoint. - * - * @param chargePointModel String, max 20 characters, case insensitive. - */ - @XmlElement - public void setChargePointModel(String chargePointModel) { - if (!ModelUtil.validate(chargePointModel, STRING_20_CHAR_MAX_LENGTH)) { - throw new PropertyConstraintException( - chargePointModel.length(), validationErrorMessage(STRING_20_CHAR_MAX_LENGTH)); + /** + * This contains the ICCID of the modem’s SIM card. + * + * @return ICCID of SIM card. + */ + public String getIccid() { + return iccid; } - this.chargePointModel = chargePointModel; - } - - /** - * This contains a value that identifies the serial number of the Charge Box inside the Charge - * Point. - * - * @return Serial Number of the Charge Point. - * @deprecated will be removed in future version. See {@link #getChargePointSerialNumber()}. - */ - @Deprecated() - public String getChargeBoxSerialNumber() { - return chargeBoxSerialNumber; - } - - /** - * Optional. This contains a value that identifies the serial number of the Charge Box inside the - * Charge Point. - * - * @param chargeBoxSerialNumber String, max 25 characters, case insensitive. - * @deprecated will be removed in future version. See {@link #setChargePointSerialNumber(String)}. - */ - @Deprecated() - public void setChargeBoxSerialNumber(String chargeBoxSerialNumber) { - if (!ModelUtil.validate(chargeBoxSerialNumber, STRING_25_CHAR_MAX_LENGTH)) { - throw new PropertyConstraintException( - chargeBoxSerialNumber.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH)); + /** + * Optional. This contains the ICCID of the modem’s SIM card. + * + * @param iccid String, max 20 characters, case insensitive. + */ + @XmlElement + public void setIccid(String iccid) { + if (!ModelUtil.validate(iccid, STRING_20_CHAR_MAX_LENGTH)) { + throw new PropertyConstraintException( + iccid.length(), validationErrorMessage(STRING_20_CHAR_MAX_LENGTH)); + } + + this.iccid = iccid; } - this.chargeBoxSerialNumber = chargeBoxSerialNumber; - } - - /** - * This contains a value that identifies the serial number of the Charge Point. - * - * @return Serial Number of the Charge Point. - */ - public String getChargePointSerialNumber() { - return chargePointSerialNumber; - } - - /** - * Optional. This contains a value that identifies the serial number of the Charge Point. - * - * @param chargePointSerialNumber String, max 25 characters, case insensitive. - */ - @XmlElement - public void setChargePointSerialNumber(String chargePointSerialNumber) { - if (!ModelUtil.validate(chargePointSerialNumber, STRING_25_CHAR_MAX_LENGTH)) { - throw new PropertyConstraintException( - chargePointSerialNumber.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH)); + /** + * This contains the IMSI of the modem’s SIM card. + * + * @return IMSI of SIM card. + */ + public String getImsi() { + return imsi; } - this.chargePointSerialNumber = chargePointSerialNumber; - } - - /** - * This contains the firmware version of the Charge Point. - * - * @return Firmware version of Charge Point. - */ - public String getFirmwareVersion() { - return firmwareVersion; - } - - /** - * Optional. This contains the firmware version of the Charge Point. - * - * @param firmwareVersion String, max 50 characters, case insensitive. - */ - @XmlElement - public void setFirmwareVersion(String firmwareVersion) { - if (!ModelUtil.validate(firmwareVersion, STRING_50_CHAR_MAX_LENGTH)) { - throw new PropertyConstraintException( - firmwareVersion.length(), validationErrorMessage(STRING_50_CHAR_MAX_LENGTH)); + /** + * Optional. This contains the IMSI of the modem’s SIM card. + * + * @param imsi String, max 20 characters, case insensitive. + */ + @XmlElement + public void setImsi(String imsi) { + if (!ModelUtil.validate(imsi, STRING_20_CHAR_MAX_LENGTH)) { + throw new PropertyConstraintException( + imsi.length(), validationErrorMessage(STRING_20_CHAR_MAX_LENGTH)); + } + + this.imsi = imsi; } - this.firmwareVersion = firmwareVersion; - } - - /** - * This contains the ICCID of the modem’s SIM card. - * - * @return ICCID of SIM card. - */ - public String getIccid() { - return iccid; - } - - /** - * Optional. This contains the ICCID of the modem’s SIM card. - * - * @param iccid String, max 20 characters, case insensitive. - */ - @XmlElement - public void setIccid(String iccid) { - if (!ModelUtil.validate(iccid, STRING_20_CHAR_MAX_LENGTH)) { - throw new PropertyConstraintException( - iccid.length(), validationErrorMessage(STRING_20_CHAR_MAX_LENGTH)); + /** + * This contains the serial number of the main power meter of the Charge Point. + * + * @return Serial number of the meter. + */ + public String getMeterSerialNumber() { + return meterSerialNumber; } - this.iccid = iccid; - } - - /** - * This contains the IMSI of the modem’s SIM card. - * - * @return IMSI of SIM card. - */ - public String getImsi() { - return imsi; - } - - /** - * Optional. This contains the IMSI of the modem’s SIM card. - * - * @param imsi String, max 20 characters, case insensitive. - */ - @XmlElement - public void setImsi(String imsi) { - if (!ModelUtil.validate(imsi, STRING_20_CHAR_MAX_LENGTH)) { - throw new PropertyConstraintException( - imsi.length(), validationErrorMessage(STRING_20_CHAR_MAX_LENGTH)); + /** + * Optional. This contains the serial number of the main power meter of the Charge Point. + * + * @param meterSerialNumber String, max 25 characters, case insensitive. + */ + @XmlElement + public void setMeterSerialNumber(String meterSerialNumber) { + if (!ModelUtil.validate(meterSerialNumber, STRING_25_CHAR_MAX_LENGTH)) { + throw new PropertyConstraintException( + meterSerialNumber.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH)); + } + + this.meterSerialNumber = meterSerialNumber; } - this.imsi = imsi; - } - - /** - * This contains the serial number of the main power meter of the Charge Point. - * - * @return Serial number of the meter. - */ - public String getMeterSerialNumber() { - return meterSerialNumber; - } - - /** - * Optional. This contains the serial number of the main power meter of the Charge Point. - * - * @param meterSerialNumber String, max 25 characters, case insensitive. - */ - @XmlElement - public void setMeterSerialNumber(String meterSerialNumber) { - if (!ModelUtil.validate(meterSerialNumber, STRING_25_CHAR_MAX_LENGTH)) { - throw new PropertyConstraintException( - meterSerialNumber.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH)); + /** + * This contains the type of the main power meter of the Charge Point. + * + * @return Type of main power meter. + */ + public String getMeterType() { + return meterType; } - this.meterSerialNumber = meterSerialNumber; - } - - /** - * This contains the type of the main power meter of the Charge Point. - * - * @return Type of main power meter. - */ - public String getMeterType() { - return meterType; - } - - /** - * Optional. This contains the type of the main power meter of the Charge Point. - * - * @param meterType String, max 25 characters, case insensitive. - */ - @XmlElement - public void setMeterType(String meterType) { - if (!ModelUtil.validate(meterType, STRING_25_CHAR_MAX_LENGTH)) { - throw new PropertyConstraintException( - meterType.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH)); + /** + * Optional. This contains the type of the main power meter of the Charge Point. + * + * @param meterType String, max 25 characters, case insensitive. + */ + @XmlElement + public void setMeterType(String meterType) { + if (!ModelUtil.validate(meterType, STRING_25_CHAR_MAX_LENGTH)) { + throw new PropertyConstraintException( + meterType.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH)); + } + + this.meterType = meterType; } - this.meterType = meterType; - } - - @Override - public boolean validate() { - return ModelUtil.validate(chargePointModel, STRING_20_CHAR_MAX_LENGTH) - && ModelUtil.validate(chargePointVendor, STRING_20_CHAR_MAX_LENGTH); - } - - @Override - public boolean transactionRelated() { - return false; - } - - private static String validationErrorMessage(int maxAllowedLength) { - return String.format(ERROR_MESSAGE, maxAllowedLength); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - BootNotificationRequest that = (BootNotificationRequest) o; - return Objects.equals(chargePointVendor, that.chargePointVendor) - && Objects.equals(chargePointModel, that.chargePointModel) - && Objects.equals(chargeBoxSerialNumber, that.chargeBoxSerialNumber) - && Objects.equals(chargePointSerialNumber, that.chargePointSerialNumber) - && Objects.equals(firmwareVersion, that.firmwareVersion) - && Objects.equals(iccid, that.iccid) - && Objects.equals(imsi, that.imsi) - && Objects.equals(meterSerialNumber, that.meterSerialNumber) - && Objects.equals(meterType, that.meterType); - } - - @Override - public int hashCode() { - return Objects.hash( - chargePointVendor, - chargePointModel, - chargeBoxSerialNumber, - chargePointSerialNumber, - firmwareVersion, - iccid, - imsi, - meterSerialNumber, - meterType); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("chargePointVendor", chargePointVendor) - .add("chargePointModel", chargePointModel) - .add("chargeBoxSerialNumber", chargeBoxSerialNumber) - .add("chargePointSerialNumber", chargePointSerialNumber) - .add("firmwareVersion", firmwareVersion) - .add("iccid", iccid) - .add("imsi", imsi) - .add("meterSerialNumber", meterSerialNumber) - .add("meterType", meterType) - .add("isValid", validate()) - .toString(); - } + @Override + public boolean validate() { + return ModelUtil.validate(chargePointModel, STRING_20_CHAR_MAX_LENGTH) + && ModelUtil.validate(chargePointVendor, STRING_20_CHAR_MAX_LENGTH); + } + + @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; + BootNotificationRequest that = (BootNotificationRequest) o; + return Objects.equals(chargePointVendor, that.chargePointVendor) + && Objects.equals(chargePointModel, that.chargePointModel) + && Objects.equals(chargeBoxSerialNumber, that.chargeBoxSerialNumber) + && Objects.equals(chargePointSerialNumber, that.chargePointSerialNumber) + && Objects.equals(firmwareVersion, that.firmwareVersion) + && Objects.equals(iccid, that.iccid) + && Objects.equals(imsi, that.imsi) + && Objects.equals(meterSerialNumber, that.meterSerialNumber) + && Objects.equals(meterType, that.meterType); + } + + @Override + public int hashCode() { + return Objects.hash( + chargePointVendor, + chargePointModel, + chargeBoxSerialNumber, + chargePointSerialNumber, + firmwareVersion, + iccid, + imsi, + meterSerialNumber, + meterType); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("chargePointVendor", chargePointVendor) + .add("chargePointModel", chargePointModel) + .add("chargeBoxSerialNumber", chargeBoxSerialNumber) + .add("chargePointSerialNumber", chargePointSerialNumber) + .add("firmwareVersion", firmwareVersion) + .add("iccid", iccid) + .add("imsi", imsi) + .add("meterSerialNumber", meterSerialNumber) + .add("meterType", meterType) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeAvailabilityConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeAvailabilityConfirmation.java index f09ab4ea3..e302bbb4f 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeAvailabilityConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeAvailabilityConfirmation.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,79 +31,87 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; -/** return by Charge Point to Central System. */ +/** + * return by Charge Point to Central System. + */ @XmlRootElement(name = "changeAvailabilityResponse") public class ChangeAvailabilityConfirmation implements Confirmation { - private AvailabilityStatus status; - - /** - * This indicates whether the Charge Point is able to perform the availability change. - * - * @return The {@link AvailabilityStatus} of the connector. - */ - public AvailabilityStatus getStatus() { - return status; - } - - /** - * This indicates whether the Charge Point is able to perform the availability change. - * - * @return The {@link AvailabilityStatus} of the connector. - */ - @Deprecated - public AvailabilityStatus objStatus() { - return status; - } - - /** - * Required. This indicates whether the Charge Point is able to perform the availability change. - * - * @param status the {@link AvailabilityStatus} of connector. - */ - @XmlElement - public void setStatus(AvailabilityStatus status) { - this.status = status; - } - - public ChangeAvailabilityConfirmation() {} - - /** - * Handle required fields. - * - * @param status the {@link AvailabilityStatus}, see {@link #setStatus(AvailabilityStatus)} - */ - public ChangeAvailabilityConfirmation(AvailabilityStatus status) { - this.status = status; - } - - @Override - public boolean validate() { - return this.status != null; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ChangeAvailabilityConfirmation that = (ChangeAvailabilityConfirmation) o; - return status == that.status; - } - - @Override - public int hashCode() { - return Objects.hash(status); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + private AvailabilityStatus status; + + /** + * @deprecated use {@link #ChangeAvailabilityConfirmation(AvailabilityStatus)} to be sure to set required fields + */ + public ChangeAvailabilityConfirmation() { + + } + + /** + * Handle required fields. + * + * @param status the {@link AvailabilityStatus}, see {@link #setStatus(AvailabilityStatus)} + */ + public ChangeAvailabilityConfirmation(AvailabilityStatus status) { + setStatus(status); + } + + /** + * This indicates whether the Charge Point is able to perform the availability change. + * + * @return The {@link AvailabilityStatus} of the connector. + */ + public AvailabilityStatus getStatus() { + return status; + } + + /** + * Required. This indicates whether the Charge Point is able to perform the availability change. + * + * @param status the {@link AvailabilityStatus} of connector. + */ + @XmlElement + public void setStatus(AvailabilityStatus status) { + this.status = status; + } + + /** + * This indicates whether the Charge Point is able to perform the availability change. + * + * @return The {@link AvailabilityStatus} of the connector. + */ + @Deprecated + public AvailabilityStatus objStatus() { + return status; + } + + @Override + public boolean validate() { + return this.status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChangeAvailabilityConfirmation that = (ChangeAvailabilityConfirmation) o; + return status == that.status; + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeAvailabilityRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeAvailabilityRequest.java index 7c5ec7942..259266b0d 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeAvailabilityRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeAvailabilityRequest.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -30,100 +32,122 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; -/** Sent by the Central System to the Charge Point. */ +/** + * Sent by the Central System to the Charge Point. + */ @XmlRootElement public class ChangeAvailabilityRequest implements Request { - private int connectorId = -1; - private AvailabilityType type; - - /** - * The id of the connector for which availability needs to change. Id '0' (zero) is used if the - * availability of the Charge Point and all its connectors needs to change. - * - * @return identification of the connector. 0 = all. - */ - public int getConnectorId() { - return connectorId; - } - - /** - * Required. The id of the connector for which availability needs to change. Id '0' (zero) is used - * if the availability of the Charge Point and all its connectors needs to change. - * - * @param connectorId integer, must be a non-negative number. - */ - @XmlElement - public void setConnectorId(int connectorId) { - if (connectorId < 0) { - throw new PropertyConstraintException(connectorId, "connectorId must be >= 0"); + private Integer connectorId = -1; + private AvailabilityType type; + + /** + * @deprecated use {@link #ChangeAvailabilityRequest(Integer, AvailabilityType)} to be sure to set required fields + */ + @Deprecated + public ChangeAvailabilityRequest() { + + } + + /** + * Handle required fields. + * + * @param connectorId integer, must be a non-negative number. + * @param type the {@link AvailabilityType} of the connector, see {@link #setType(AvailabilityType)} + */ + public ChangeAvailabilityRequest(Integer connectorId, AvailabilityType type) { + setConnectorId(connectorId); + setType(type); + } + + /** + * The id of the connector for which availability needs to change. Id '0' (zero) is used if the + * availability of the Charge Point and all its connectors needs to change. + * + * @return identification of the connector. 0 = all. + */ + public int getConnectorId() { + return connectorId; + } + + /** + * Required. The id of the connector for which availability needs to change. Id '0' (zero) is used + * if the availability of the Charge Point and all its connectors needs to change. + * + * @param connectorId integer, must be a non-negative number. + */ + @XmlElement + public void setConnectorId(int connectorId) { + if (connectorId < 0) { + throw new PropertyConstraintException(connectorId, "connectorId must be >= 0"); + } + + this.connectorId = connectorId; + } + + /** + * This contains the type of availability change that the Charge Point should perform. + * + * @return {@link AvailabilityType} of the connector. + */ + public AvailabilityType getType() { + return type; } - this.connectorId = connectorId; - } - - /** - * This contains the type of availability change that the Charge Point should perform. - * - * @return {@link AvailabilityType} of the connector. - */ - public AvailabilityType getType() { - return type; - } - - /** - * This contains the type of availability change that the Charge Point should perform. - * - * @return {@link AvailabilityType} of the connector. - */ - @Deprecated - public AvailabilityType objType() { - return type; - } - - /** - * Required. This contains the type of availability change that the Charge Point should perform. - * - * @param type {@link AvailabilityType} of the connector - */ - @XmlElement - public void setType(AvailabilityType type) { - this.type = type; - } - - @Override - public boolean validate() { - return type != null && connectorId >= 0; - } - - @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; - ChangeAvailabilityRequest that = (ChangeAvailabilityRequest) o; - return connectorId == that.connectorId && type == that.type; - } - - @Override - public int hashCode() { - return Objects.hash(connectorId, type); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("connectorId", connectorId) - .add("type", type) - .add("isValid", validate()) - .toString(); - } + /** + * Required. This contains the type of availability change that the Charge Point should perform. + * + * @param type {@link AvailabilityType} of the connector + */ + @XmlElement + public void setType(AvailabilityType type) { + this.type = type; + } + + /** + * This contains the type of availability change that the Charge Point should perform. + * + * @return {@link AvailabilityType} of the connector. + */ + @Deprecated + public AvailabilityType objType() { + return type; + } + + @Override + public boolean validate() { + return type != null && connectorId != null && connectorId >= 0; + } + + @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; + ChangeAvailabilityRequest that = (ChangeAvailabilityRequest) o; + return connectorId == that.connectorId && type == that.type; + } + + @Override + public int hashCode() { + return Objects.hash(connectorId, type); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("connectorId", connectorId) + .add("type", type) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeConfigurationConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeConfigurationConfirmation.java index ffcdde71b..15f45fea8 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeConfigurationConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeConfigurationConfirmation.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,67 +31,88 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; -/** Returned from Charge Point to Central System */ +/** + * Returned from Charge Point to Central System + */ @XmlRootElement(name = "changeConfigurationResponse") public class ChangeConfigurationConfirmation implements Confirmation { - private ConfigurationStatus status; - - /** - * Returns whether configuration change has been accepted. - * - * @return String, the {@link ConfigurationStatus}. - */ - public ConfigurationStatus getStatus() { - return status; - } - - /** - * Returns whether configuration change has been accepted. - * - * @return the {@link ConfigurationStatus}. - */ - @Deprecated - public ConfigurationStatus objStatus() { - return status; - } - - /** - * Required. Returns whether configuration change has been accepted. - * - * @param status the {@link ConfigurationStatus}. - */ - @XmlElement - public void setStatus(ConfigurationStatus status) { - this.status = status; - } - - @Override - public boolean validate() { - return status != null; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ChangeConfigurationConfirmation that = (ChangeConfigurationConfirmation) o; - return status == that.status; - } - - @Override - public int hashCode() { - return Objects.hash(status); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + + private ConfigurationStatus status; + + /** + * @deprecated use {@link #ChangeConfigurationConfirmation(ConfigurationStatus)} to be sure to set required fields + */ + @Deprecated + public ChangeConfigurationConfirmation() { + + } + + /** + * Handle required fields. + * + * @param status the {@link ConfigurationStatus}, see {@link #setStatus(ConfigurationStatus)} + */ + public ChangeConfigurationConfirmation(ConfigurationStatus status) { + setStatus(status); + } + + /** + * Returns whether configuration change has been accepted. + * + * @return String, the {@link ConfigurationStatus}. + */ + public ConfigurationStatus getStatus() { + return status; + } + + /** + * Required. Returns whether configuration change has been accepted. + * + * @param status the {@link ConfigurationStatus}. + */ + @XmlElement + public void setStatus(ConfigurationStatus status) { + this.status = status; + } + + /** + * Returns whether configuration change has been accepted. + * + * @return the {@link ConfigurationStatus}. + */ + @Deprecated + public ConfigurationStatus objStatus() { + return status; + } + + @Override + public boolean validate() { + return status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChangeConfigurationConfirmation that = (ChangeConfigurationConfirmation) o; + return status == that.status; + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeConfigurationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeConfigurationRequest.java index 81394cfec..e447b427e 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeConfigurationRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ChangeConfigurationRequest.java @@ -6,6 +6,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -30,10 +31,11 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Objects; /** * Sent by Central System to Charge Point. @@ -45,100 +47,119 @@ of this software and associated documentation files (the "Software"), to deal @XmlType(propOrder = {"key", "value"}) public class ChangeConfigurationRequest implements Request { - private static final String ERROR_MESSAGE = "Exceeded limit of %s chars"; - private static final int KEY_MAX_LENGTH = 50; - private static final int VALUE_MAX_LENGTH = 500; - - private String key; - private String value; - - /** - * The name of the configuration setting to change. - * - * @return Name of the configuration setting. - */ - public String getKey() { - return key; - } - - /** - * Required. The name of the configuration setting to change. - * - * @param key String, max 50 characters, case insensitive. - */ - @XmlElement - public void setKey(String key) { - if (!isValidKey(key)) { - throw new PropertyConstraintException(key.length(), createErrorMessage(KEY_MAX_LENGTH)); + private static final String ERROR_MESSAGE = "Exceeded limit of %s chars"; + private static final int KEY_MAX_LENGTH = 50; + private static final int VALUE_MAX_LENGTH = 500; + + private String key; + private String value; + + /** + * @deprecated use {@link #ChangeConfigurationRequest(String, String)} to be sure to set required fields + */ + @Deprecated + public ChangeConfigurationRequest() { + + } + + /** + * Handle required fields. + * + * @param key String, max 50 characters, case insensitive, see {@link #setKey(String)} + * @param value String, max 500 characters, case insensitive, see {@link #setValue(String)} + */ + public ChangeConfigurationRequest(String key, String value) { + setKey(key); + setValue(value); } - this.key = key; - } - - private boolean isValidKey(String key) { - return ModelUtil.validate(key, KEY_MAX_LENGTH); - } - - /** - * The new value as string for the setting. - * - * @return Value of the configuration setting. - */ - public String getValue() { - return value; - } - - /** - * Required. The new value as string for the setting. - * - * @param value String, max 500 characters, case insensitive. - */ - @XmlElement - public void setValue(String value) { - if (!isValidValue(value)) { - throw new PropertyConstraintException(value.length(), createErrorMessage(VALUE_MAX_LENGTH)); + private static String createErrorMessage(int valueMaxLength) { + return String.format(ERROR_MESSAGE, valueMaxLength); } - this.value = value; - } - - private boolean isValidValue(String value) { - return ModelUtil.validate(value, VALUE_MAX_LENGTH); - } - - @Override - public boolean validate() { - return isValidKey(this.key) && isValidValue(this.value); - } - - @Override - public boolean transactionRelated() { - return false; - } - - private static String createErrorMessage(int valueMaxLength) { - return String.format(ERROR_MESSAGE, valueMaxLength); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ChangeConfigurationRequest that = (ChangeConfigurationRequest) o; - return Objects.equals(key, that.key) && Objects.equals(value, that.value); - } - - @Override - public int hashCode() { - return Objects.hash(key, value); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("key", key) - .add("value", value) - .add("isValid", validate()) - .toString(); - } + /** + * The name of the configuration setting to change. + * + * @return Name of the configuration setting. + */ + public String getKey() { + return key; + } + + /** + * Required. The name of the configuration setting to change. + * + * @param key String, max 50 characters, case insensitive. + */ + @XmlElement + public void setKey(String key) { + if (!isValidKey(key)) { + throw new PropertyConstraintException(key.length(), createErrorMessage(KEY_MAX_LENGTH)); + } + + this.key = key; + } + + private boolean isValidKey(String key) { + return ModelUtil.validate(key, KEY_MAX_LENGTH); + } + + /** + * The new value as string for the setting. + * + * @return Value of the configuration setting. + */ + public String getValue() { + return value; + } + + /** + * Required. The new value as string for the setting. + * + * @param value String, max 500 characters, case insensitive. + */ + @XmlElement + public void setValue(String value) { + if (!isValidValue(value)) { + throw new PropertyConstraintException(value.length(), createErrorMessage(VALUE_MAX_LENGTH)); + } + + this.value = value; + } + + private boolean isValidValue(String value) { + return ModelUtil.validate(value, VALUE_MAX_LENGTH); + } + + @Override + public boolean validate() { + return isValidKey(this.key) && isValidValue(this.value); + } + + @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; + ChangeConfigurationRequest that = (ChangeConfigurationRequest) o; + return Objects.equals(key, that.key) && Objects.equals(value, that.value); + } + + @Override + public int hashCode() { + return Objects.hash(key, value); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("key", key) + .add("value", value) + .add("isValid", validate()) + .toString(); + } } 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 f38f27ffd..f7280886b 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 @@ -3,11 +3,12 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Validatable; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Objects; /* * ChargeTime.eu - Java-OCA-OCPP @@ -15,6 +16,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -36,223 +38,381 @@ */ @XmlRootElement @XmlType( - propOrder = { - "chargingProfileId", - "transactionId", - "stackLevel", - "chargingProfilePurpose", - "chargingProfileKind", - "recurrencyKind", - "validFrom", - "validTo", - "chargingSchedule" - }) + propOrder = { + "chargingProfileId", + "transactionId", + "stackLevel", + "chargingProfilePurpose", + "chargingProfileKind", + "recurrencyKind", + "validFrom", + "validTo", + "chargingSchedule" + }) public class ChargingProfile implements Validatable { - private Integer chargingProfileId; - private Integer transactionId; - private Integer stackLevel; - private ChargingProfilePurposeType chargingProfilePurpose; - private ChargingProfileKindType chargingProfileKind; - private RecurrencyKindType recurrencyKind; - private Calendar validFrom; - 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 = chargingProfileId != null; - valid &= (stackLevel != null && stackLevel >= 0); - valid &= chargingProfilePurpose != null; - valid &= - (transactionId == null || chargingProfilePurpose == ChargingProfilePurposeType.TxProfile); - valid &= chargingProfileKind != null; - valid &= (chargingSchedule != null && chargingSchedule.validate()); - return valid; - } - - @XmlElement - public void setChargingProfileId(Integer chargingProfileId) { - if (chargingProfileId == null) { - throw new PropertyConstraintException(null, "chargingProfileId must be present"); + private Integer chargingProfileId; + private Integer transactionId; + private Integer stackLevel; + private ChargingProfilePurposeType chargingProfilePurpose; + private ChargingProfileKindType chargingProfileKind; + private RecurrencyKindType recurrencyKind; + private ZonedDateTime validFrom; + private ZonedDateTime validTo; + private ChargingSchedule chargingSchedule; + + /** + * @deprecated use {@link #ChargingProfile(Integer, Integer, ChargingProfilePurposeType, ChargingProfileKindType, ChargingSchedule)} to be sure to set required fields + */ + @Deprecated + public ChargingProfile() { + } + + /** + * Handle required values + * + * @param chargingProfileId Integer, see {@link #setChargingProfileId(Integer)} + * @param stackLevel Integer, see {@link #setStackLevel(Integer)} + * @param chargingProfilePurpose the {@link ChargingProfilePurposeType}, see {@link #setChargingProfilePurpose(ChargingProfilePurposeType)} + * @param chargingProfileKind the {@link ChargingProfileKindType}, see {@link #setChargingProfileKind(ChargingProfileKindType)} + * @param chargingSchedule the {@link ChargingSchedule}, see {@link #setChargingSchedule(ChargingSchedule)} + */ + 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; + } + + /** + * Handle required values + * + * @param chargingProfileId Integer, see {@link #setChargingProfileId(Integer)} + * @param stackLevel Integer, see {@link #setStackLevel(Integer)} + * @param chargingProfilePurpose the {@link ChargingProfilePurposeType}, see {@link #setChargingProfilePurpose(ChargingProfilePurposeType)} + * @param chargingProfileKind the {@link ChargingProfileKindType}, see {@link #setChargingProfileKind(ChargingProfileKindType)} + * @deprecated use {@link #ChargingProfile(Integer, Integer, ChargingProfilePurposeType, ChargingProfileKindType, ChargingSchedule)} to be sure to set required fields + */ + @Deprecated + 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 = chargingProfileId != null; + valid &= (stackLevel != null && stackLevel >= 0); + valid &= chargingProfilePurpose != null; + valid &= + (transactionId == null || chargingProfilePurpose == ChargingProfilePurposeType.TxProfile); + valid &= chargingProfileKind != null; + valid &= (chargingSchedule != null && chargingSchedule.validate()); + return valid; + } + + /** + * Unique identifier for this profile + * + * @return identifier for this profile + */ + public Integer getChargingProfileId() { + return chargingProfileId; + } + + /** + * Required. Unique identifier for this profile + * + * @param chargingProfileId Integer + */ + @XmlElement + public void setChargingProfileId(Integer chargingProfileId) { + if (chargingProfileId == null) { + throw new PropertyConstraintException(null, "chargingProfileId must be present"); + } + + this.chargingProfileId = chargingProfileId; + } + + /** + * Only valid if ChargingProfilePurpose is set to TxProfile, + * the transactionId MAY be used to match the profile to a specific + * transaction. + * + * @return the transactionId + */ + public Integer getTransactionId() { + return transactionId; + } + + /** + * Optional. Only valid if ChargingProfilePurpose is set to TxProfile, + * the transactionId MAY be used to match the profile to a specific + * transaction. + * + * @param transactionId Integer + */ + @XmlElement + public void setTransactionId(Integer transactionId) { + this.transactionId = transactionId; + } + + /** + * Value determining level in hierarchy stack of profiles. + * Higher values have precedence over lower values. Lowest level is + * 0. + * + * @return level in hierarchy stack of profiles + */ + public Integer getStackLevel() { + return stackLevel; + } + + /** + * Required. Value determining level in hierarchy stack of profiles. + * Higher values have precedence over lower values. Lowest level is + * 0. + * + * @param stackLevel Integer + */ + @XmlElement + public void setStackLevel(Integer stackLevel) { + if (stackLevel == null || stackLevel < 0) { + throw new PropertyConstraintException(stackLevel, "stackLevel must be >= 0"); + } + + this.stackLevel = stackLevel; + } + + /** + * Unique identifier for this profile. + * + * @return identifier for this profile + */ + public ChargingProfilePurposeType getChargingProfilePurpose() { + return chargingProfilePurpose; + } + + /** + * Required. Unique identifier for this profile. + * + * @param chargingProfilePurpose the {@link ChargingProfilePurposeType} + */ + @XmlElement + public void setChargingProfilePurpose(ChargingProfilePurposeType chargingProfilePurpose) { + this.chargingProfilePurpose = chargingProfilePurpose; + } + + /** + * Unique identifier for this profile. + * + * @return identifier for this profile + */ + @Deprecated + public ChargingProfilePurposeType objChargingProfilePurpose() { + return chargingProfilePurpose; } - this.chargingProfileId = chargingProfileId; - } + /** + * Indicates the kind of schedule. + * + * @return kind of schedule + */ + public ChargingProfileKindType getChargingProfileKind() { + return chargingProfileKind; + } + + /** + * Required. Indicates the kind of schedule + * + * @param chargingProfileKind the {@link ChargingProfileKindType} + */ + @XmlElement + public void setChargingProfileKind(ChargingProfileKindType chargingProfileKind) { + this.chargingProfileKind = chargingProfileKind; + } + + /** + * Indicates the kind of schedule. + * + * @return kind of schedule + */ + @Deprecated + public ChargingProfileKindType objChargingProfileKind() { + return chargingProfileKind; + } + + /** + * Indicates the start point of a recurrence. + * + * @return start point of a recurrency + */ + public RecurrencyKindType getRecurrencyKind() { + return recurrencyKind; + } - public Integer getChargingProfileId() { - return chargingProfileId; - } + /** + * Required. Indicates the kind of schedule. + * + * @param recurrencyKind the {@link RecurrencyKindType} + */ + @XmlElement + public void setRecurrencyKind(RecurrencyKindType recurrencyKind) { + this.recurrencyKind = recurrencyKind; + } + + /** + * Indicates the start point of a recurrence. + * + * @return start point of a recurrency + */ + @Deprecated + public RecurrencyKindType objRecurrencyKind() { + return recurrencyKind; + } - @XmlElement - public void setTransactionId(Integer transactionId) { - this.transactionId = transactionId; - } + /** + * Point in time at which the profile starts to be valid. If + * absent, the profile is valid as soon as it is received by the Charge + * Point. + * + * @return Point in time at which the profile starts to be valid + */ + public ZonedDateTime getValidFrom() { + return validFrom; + } - public Integer getTransactionId() { - return transactionId; - } + /** + * Optional. Point in time at which the profile starts to be valid. If + * absent, the profile is valid as soon as it is received by the Charge + * Point. + * + * @param validFrom the {@link ZonedDateTime} + */ + @XmlElement + public void setValidFrom(ZonedDateTime validFrom) { + this.validFrom = validFrom; + } + + /** + * Point in time at which the profile starts to be valid. If + * absent, the profile is valid as soon as it is received by the Charge + * Point. + * + * @return Point in time at which the profile starts to be valid + */ + @Deprecated + public ZonedDateTime objValidFrom() { + return this.validFrom; + } - @XmlElement - public void setStackLevel(Integer stackLevel) { - if (stackLevel == null || stackLevel < 0) { - throw new PropertyConstraintException(stackLevel, "stackLevel must be >= 0"); + /** + * Point in time at which the profile stops to be valid. If + * absent, the profile is valid until it is replaced by another profile + * + * @return Point in time at which the profile stops to be valid + */ + public ZonedDateTime getValidTo() { + return validTo; } - this.stackLevel = stackLevel; - } - - public Integer getStackLevel() { - return stackLevel; - } - - @XmlElement - public void setChargingProfilePurpose(ChargingProfilePurposeType chargingProfilePurpose) { - this.chargingProfilePurpose = chargingProfilePurpose; - } - - public ChargingProfilePurposeType getChargingProfilePurpose() { - return chargingProfilePurpose; - } - - @Deprecated - public ChargingProfilePurposeType objChargingProfilePurpose() { - return chargingProfilePurpose; - } - - @XmlElement - public void setChargingProfileKind(ChargingProfileKindType chargingProfileKind) { - this.chargingProfileKind = chargingProfileKind; - } - - public ChargingProfileKindType getChargingProfileKind() { - return chargingProfileKind; - } - - @Deprecated - public ChargingProfileKindType objChargingProfileKind() { - return chargingProfileKind; - } - - @XmlElement - public void setRecurrencyKind(RecurrencyKindType recurrencyKind) { - this.recurrencyKind = recurrencyKind; - } - - public RecurrencyKindType getRecurrencyKind() { - return recurrencyKind; - } - - @Deprecated - public RecurrencyKindType objRecurrencyKind() { - return recurrencyKind; - } - - @XmlElement - public void setValidFrom(Calendar validFrom) { - this.validFrom = validFrom; - } - - public Calendar getValidFrom() { - return validFrom; - } - - @Deprecated - public Calendar objValidFrom() { - return this.validFrom; - } - - @XmlElement - public void setValidTo(Calendar validTo) { - this.validTo = validTo; - } - - public Calendar getValidTo() { - return validTo; - } - - @Deprecated - public Calendar objValidTo() { - return validTo; - } - - @XmlElement - public void setChargingSchedule(ChargingSchedule chargingSchedule) { - this.chargingSchedule = chargingSchedule; - } - - public ChargingSchedule getChargingSchedule() { - return chargingSchedule; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ChargingProfile that = (ChargingProfile) o; - return Objects.equals(chargingProfileId, that.chargingProfileId) - && Objects.equals(transactionId, that.transactionId) - && Objects.equals(stackLevel, that.stackLevel) - && chargingProfilePurpose == that.chargingProfilePurpose - && chargingProfileKind == that.chargingProfileKind - && recurrencyKind == that.recurrencyKind - && Objects.equals(validFrom, that.validFrom) - && Objects.equals(validTo, that.validTo) - && Objects.equals(chargingSchedule, that.chargingSchedule); - } - - @Override - public int hashCode() { - return Objects.hash( - chargingProfileId, - transactionId, - stackLevel, - chargingProfilePurpose, - chargingProfileKind, - recurrencyKind, - validFrom, - validTo, - chargingSchedule); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("chargingProfileId", chargingProfileId) - .add("transactionId", transactionId) - .add("stackLevel", stackLevel) - .add("chargingProfilePurpose", chargingProfilePurpose) - .add("chargingProfileKind", chargingProfileKind) - .add("recurrencyKind", recurrencyKind) - .add("validFrom", validFrom) - .add("validTo", validTo) - .add("chargingSchedule", chargingSchedule) - .add("isValid", validate()) - .toString(); - } + /** + * Optional. Point in time at which the profile stops to be valid. If + * absent, the profile is valid until it is replaced by another profile + * + * @param validTo the {@link ZonedDateTime} + */ + @XmlElement + public void setValidTo(ZonedDateTime validTo) { + this.validTo = validTo; + } + + /** + * Point in time at which the profile stops to be valid. If + * absent, the profile is valid until it is replaced by another profile + * + * @return Point in time at which the profile stops to be valid + */ + @Deprecated + public ZonedDateTime objValidTo() { + return validTo; + } + + /** + * Contains limits for the available power or current over + * time. + * + * @return charging schedule + */ + public ChargingSchedule getChargingSchedule() { + return chargingSchedule; + } + + /** + * Required. Contains limits for the available power or current over + * time. + * + * @param chargingSchedule the {@link ChargingSchedule} + */ + @XmlElement + public void setChargingSchedule(ChargingSchedule chargingSchedule) { + this.chargingSchedule = chargingSchedule; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChargingProfile that = (ChargingProfile) o; + return Objects.equals(chargingProfileId, that.chargingProfileId) + && Objects.equals(transactionId, that.transactionId) + && Objects.equals(stackLevel, that.stackLevel) + && chargingProfilePurpose == that.chargingProfilePurpose + && chargingProfileKind == that.chargingProfileKind + && recurrencyKind == that.recurrencyKind + && Objects.equals(validFrom, that.validFrom) + && Objects.equals(validTo, that.validTo) + && Objects.equals(chargingSchedule, that.chargingSchedule); + } + + @Override + public int hashCode() { + return Objects.hash( + chargingProfileId, + transactionId, + stackLevel, + chargingProfilePurpose, + chargingProfileKind, + recurrencyKind, + validFrom, + validTo, + chargingSchedule); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("chargingProfileId", chargingProfileId) + .add("transactionId", transactionId) + .add("stackLevel", stackLevel) + .add("chargingProfilePurpose", chargingProfilePurpose) + .add("chargingProfileKind", chargingProfileKind) + .add("recurrencyKind", recurrencyKind) + .add("validFrom", validFrom) + .add("validTo", validTo) + .add("chargingSchedule", chargingSchedule) + .add("isValid", validate()) + .toString(); + } } 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 f6a6f7b14..aa566acd3 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 @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,197 +29,212 @@ import eu.chargetime.ocpp.model.Validatable; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Arrays; +import java.util.Objects; -/** Class type used with {@link ChargingProfile} */ +/** + * Class type used with {@link ChargingProfile} + */ @XmlRootElement @XmlType( - propOrder = { - "duration", - "startSchedule", - "chargingRateUnit", - "chargingSchedulePeriod", - "minChargingRate" - }) + propOrder = { + "duration", + "startSchedule", + "chargingRateUnit", + "chargingSchedulePeriod", + "minChargingRate" + }) public class ChargingSchedule implements Validatable { - private Integer duration; - private Calendar startSchedule; - private ChargingRateUnitType chargingRateUnit; - 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 = chargingRateUnit != null; - if (valid &= chargingSchedulePeriod != null) { - for (ChargingSchedulePeriod period : chargingSchedulePeriod) valid &= period.validate(); - } - return valid; - } - - /** - * Duration of the charging schedule in seconds. - * - * @return duration in seconds. - */ - public Integer getDuration() { - return duration; - } - - /** - * Optional. Duration of the charging schedule in seconds. If the duration is left empty, the last - * period will continue indefinitely or until end of the transaction in case startSchedule is - * absent. - * - * @param duration integer, duration in seconds. - */ - @XmlElement - public void setDuration(Integer duration) { - this.duration = duration; - } - - /** - * Starting point of an absolute schedule. - * - * @return start time. - */ - public Calendar getStartSchedule() { - return startSchedule; - } - - /** - * Starting point of an absolute schedule. - * - * @return start time. - */ - @Deprecated - public Calendar objStartSchedule() { - return startSchedule; - } - - /** - * Optional. Starting point of an absolute schedule. If absent the schedule will be relative to - * start of charging. - * - * @param startSchedule Calendar, start time. - */ - @XmlElement - public void setStartSchedule(Calendar startSchedule) { - this.startSchedule = startSchedule; - } - - /** - * The unit of measure Limit is expressed in. - * - * @return the {@link ChargingRateUnitType}. - */ - public ChargingRateUnitType getChargingRateUnit() { - return chargingRateUnit; - } - - /** - * The unit of measure Limit is expressed in. - * - * @return the {@link ChargingRateUnitType}. - */ - @Deprecated - public ChargingRateUnitType objChargingRateUnit() { - return chargingRateUnit; - } - - /** - * Required. The unit of measure Limit is expressed in. - * - * @param chargingRateUnit the {@link ChargingRateUnitType}. - */ - @XmlElement - public void setChargingRateUnit(ChargingRateUnitType chargingRateUnit) { - this.chargingRateUnit = chargingRateUnit; - } - - /** - * List of ChargingSchedulePeriod elements defining maximum power or current usage over time. - * - * @return array of {@link ChargingSchedulePeriod}. - */ - public ChargingSchedulePeriod[] getChargingSchedulePeriod() { - return chargingSchedulePeriod; - } - - /** - * Required. List of ChargingSchedulePeriod elements defining maximum power or current usage over - * time. - * - * @param chargingSchedulePeriod array of {@link ChargingSchedulePeriod}. - */ - @XmlElement - public void setChargingSchedulePeriod(ChargingSchedulePeriod[] chargingSchedulePeriod) { - this.chargingSchedulePeriod = chargingSchedulePeriod; - } - - /** - * Minimum charging rate supported by the electric vehicle. The unit of measure is defined by - * {@link #getChargingRateUnit()}. - * - * @return min charge rate. - */ - public Double getMinChargingRate() { - return minChargingRate; - } - - /** - * Optional. Minimum charging rate supported by the electric vehicle. The unit of measure is - * defined by {@link #getChargingRateUnit()}. This parameter is intended to be used by a local - * smart charging algorithm to optimize the power allocation for in the case a charging process is - * inefficient at lower charging rates. Accepts at most one digit fraction (e.g. 8.1) - * - * @param minChargingRate decimal, min charge rate. - */ - @XmlElement - public void setMinChargingRate(Double minChargingRate) { - this.minChargingRate = minChargingRate; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ChargingSchedule that = (ChargingSchedule) o; - return Objects.equals(duration, that.duration) - && Objects.equals(startSchedule, that.startSchedule) - && chargingRateUnit == that.chargingRateUnit - && Arrays.equals(chargingSchedulePeriod, that.chargingSchedulePeriod) - && Objects.equals(minChargingRate, that.minChargingRate); - } - - @Override - public int hashCode() { - return Objects.hash( - duration, startSchedule, chargingRateUnit, chargingSchedulePeriod, minChargingRate); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("duration", duration) - .add("startSchedule", startSchedule) - .add("chargingRateUnit", chargingRateUnit) - .add("chargingSchedulePeriod", chargingSchedulePeriod) - .add("minChargingRate", minChargingRate) - .add("isValid", validate()) - .toString(); - } + + private Integer duration; + private ZonedDateTime startSchedule; + private ChargingRateUnitType chargingRateUnit; + private ChargingSchedulePeriod[] chargingSchedulePeriod; + private Double minChargingRate; + + /** + * @deprecated use {@link #ChargingSchedule(ChargingRateUnitType, ChargingSchedulePeriod[])} to be sure to set required fields + */ + @Deprecated + public ChargingSchedule() { + } + + /** + * Handle required fields. + * + * @param chargingRateUnit the {@link ChargingRateUnitType}, see {@link #setChargingRateUnit(ChargingRateUnitType)} + * @param chargingSchedulePeriod array of {@link ChargingSchedulePeriod}, see {@link #setChargingSchedulePeriod(ChargingSchedulePeriod[])} + */ + public ChargingSchedule( + ChargingRateUnitType chargingRateUnit, ChargingSchedulePeriod[] chargingSchedulePeriod) { + setChargingRateUnit(chargingRateUnit); + setChargingSchedulePeriod(chargingSchedulePeriod); + } + + @Override + public boolean validate() { + boolean valid = chargingRateUnit != null; + if (valid &= chargingSchedulePeriod != null) { + for (ChargingSchedulePeriod period : chargingSchedulePeriod) valid &= period.validate(); + } + return valid; + } + + /** + * Duration of the charging schedule in seconds. + * + * @return duration in seconds. + */ + public Integer getDuration() { + return duration; + } + + /** + * Optional. Duration of the charging schedule in seconds. If the duration is left empty, the last + * period will continue indefinitely or until end of the transaction in case startSchedule is + * absent. + * + * @param duration integer, duration in seconds. + */ + @XmlElement + public void setDuration(Integer duration) { + this.duration = duration; + } + + /** + * Starting point of an absolute schedule. + * + * @return start time. + */ + public ZonedDateTime getStartSchedule() { + return startSchedule; + } + + /** + * Optional. Starting point of an absolute schedule. If absent the schedule will be relative to + * start of charging. + * + * @param startSchedule ZonedDateTime, start time. + */ + @XmlElement + public void setStartSchedule(ZonedDateTime startSchedule) { + this.startSchedule = startSchedule; + } + + /** + * Starting point of an absolute schedule. + * + * @return start time. + */ + @Deprecated + public ZonedDateTime objStartSchedule() { + return startSchedule; + } + + /** + * The unit of measure Limit is expressed in. + * + * @return the {@link ChargingRateUnitType}. + */ + public ChargingRateUnitType getChargingRateUnit() { + return chargingRateUnit; + } + + /** + * Required. The unit of measure Limit is expressed in. + * + * @param chargingRateUnit the {@link ChargingRateUnitType}. + */ + @XmlElement + public void setChargingRateUnit(ChargingRateUnitType chargingRateUnit) { + this.chargingRateUnit = chargingRateUnit; + } + + /** + * The unit of measure Limit is expressed in. + * + * @return the {@link ChargingRateUnitType}. + */ + @Deprecated + public ChargingRateUnitType objChargingRateUnit() { + return chargingRateUnit; + } + + /** + * List of ChargingSchedulePeriod elements defining maximum power or current usage over time. + * + * @return array of {@link ChargingSchedulePeriod}. + */ + public ChargingSchedulePeriod[] getChargingSchedulePeriod() { + return chargingSchedulePeriod; + } + + /** + * Required. List of ChargingSchedulePeriod elements defining maximum power or current usage over + * time. + * + * @param chargingSchedulePeriod array of {@link ChargingSchedulePeriod}. + */ + @XmlElement + public void setChargingSchedulePeriod(ChargingSchedulePeriod[] chargingSchedulePeriod) { + this.chargingSchedulePeriod = chargingSchedulePeriod; + } + + /** + * Minimum charging rate supported by the electric vehicle. The unit of measure is defined by + * {@link #getChargingRateUnit()}. + * + * @return min charge rate. + */ + public Double getMinChargingRate() { + return minChargingRate; + } + + /** + * Optional. Minimum charging rate supported by the electric vehicle. The unit of measure is + * defined by {@link #getChargingRateUnit()}. This parameter is intended to be used by a local + * smart charging algorithm to optimize the power allocation for in the case a charging process is + * inefficient at lower charging rates. Accepts at most one digit fraction (e.g. 8.1) + * + * @param minChargingRate decimal, min charge rate. + */ + @XmlElement + public void setMinChargingRate(Double minChargingRate) { + this.minChargingRate = minChargingRate; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChargingSchedule that = (ChargingSchedule) o; + return Objects.equals(duration, that.duration) + && Objects.equals(startSchedule, that.startSchedule) + && chargingRateUnit == that.chargingRateUnit + && Arrays.equals(chargingSchedulePeriod, that.chargingSchedulePeriod) + && Objects.equals(minChargingRate, that.minChargingRate); + } + + @Override + public int hashCode() { + return Objects.hash( + duration, startSchedule, chargingRateUnit, chargingSchedulePeriod, minChargingRate); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("duration", duration) + .add("startSchedule", startSchedule) + .add("chargingRateUnit", chargingRateUnit) + .add("chargingSchedulePeriod", chargingSchedulePeriod) + .add("minChargingRate", minChargingRate) + .add("isValid", validate()) + .toString(); + } } 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 b4b6efad8..806e3262a 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 @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,117 +29,131 @@ import eu.chargetime.ocpp.model.Validatable; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Objects; -/** Class Type used with {@link ChargingSchedule}. */ +/** + * Class Type used with {@link ChargingSchedule}. + */ @XmlRootElement @XmlType(propOrder = {"startPeriod", "limit", "numberPhases"}) public class ChargingSchedulePeriod implements Validatable { - private Integer startPeriod; - 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; - valid &= startPeriod != null; - valid &= limit != null; - return valid; - } - - /** - * Required. Start of the period, in seconds from the start of schedule. The value of StartPeriod - * also defines the stop time of the previous period. - * - * @param startPeriod integer, seconds from start of schedule. - */ - @XmlElement - public void setStartPeriod(Integer startPeriod) { - this.startPeriod = startPeriod; - } - - /** - * Start of the period, in seconds from the start of schedule. The value of StartPeriod also - * defines the stop time of the previous period. - * - * @return Seconds from start of schedule. - */ - public Integer getStartPeriod() { - return startPeriod; - } - - /** - * Required. Power limit during the schedule period, expressed in Amperes. Accepts at most one - * digit fraction (e.g. 8.1). - * - * @param limit decimal, power limit. - */ - @XmlElement - public void setLimit(Double limit) { - this.limit = limit; - } - - /** - * Power limit during the schedule period, expressed in Amperes. Accepts at most one digit - * fraction (e.g. 8.1). - * - * @return Power limit. - */ - public Double getLimit() { - return limit; - } - - /** - * Optional. The number of phases that can be used for charging. Value is set to 3 by default. - * - * @param numberPhases integer, default is 3. - */ - @XmlElement - public void setNumberPhases(Integer numberPhases) { - this.numberPhases = numberPhases; - } - - /** - * The number of phases that can be used for charging. Value is set to 3 by default. - * - * @return Number of phases. - */ - public Integer getNumberPhases() { - return numberPhases; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ChargingSchedulePeriod that = (ChargingSchedulePeriod) o; - return Objects.equals(startPeriod, that.startPeriod) - && Objects.equals(limit, that.limit) - && Objects.equals(numberPhases, that.numberPhases); - } - - @Override - public int hashCode() { - return Objects.hash(startPeriod, limit, numberPhases); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("startPeriod", startPeriod) - .add("limit", limit) - .add("numberPhases", numberPhases) - .add("isValid", validate()) - .toString(); - } + private Integer startPeriod; + private Double limit; + private Integer numberPhases = 3; + + /** + * @deprecated use {@link #ChargingSchedulePeriod(Integer, Double)} to be sure to set required fields + */ + @Deprecated + public ChargingSchedulePeriod() { + } + + /** + * Handle required fields. + * + * @param startPeriod integer, seconds from start of schedule, see {@link #setStartPeriod(Integer)} + * @param limit decimal, power limit, see {@link #setLimit(Double)} + */ + public ChargingSchedulePeriod(Integer startPeriod, Double limit) { + setStartPeriod(startPeriod); + setLimit(limit); + } + + @Override + public boolean validate() { + boolean valid = true; + valid &= startPeriod != null; + valid &= limit != null; + return valid; + } + + /** + * Start of the period, in seconds from the start of schedule. The value of StartPeriod also + * defines the stop time of the previous period. + * + * @return Seconds from start of schedule. + */ + public Integer getStartPeriod() { + return startPeriod; + } + + /** + * Required. Start of the period, in seconds from the start of schedule. The value of StartPeriod + * also defines the stop time of the previous period. + * + * @param startPeriod integer, seconds from start of schedule. + */ + @XmlElement + public void setStartPeriod(Integer startPeriod) { + this.startPeriod = startPeriod; + } + + /** + * Power limit during the schedule period, expressed in Amperes. Accepts at most one digit + * fraction (e.g. 8.1). + * + * @return Power limit. + */ + public Double getLimit() { + return limit; + } + + /** + * Required. Power limit during the schedule period, expressed in Amperes. Accepts at most one + * digit fraction (e.g. 8.1). + * + * @param limit decimal, power limit. + */ + @XmlElement + public void setLimit(Double limit) { + this.limit = limit; + } + + /** + * The number of phases that can be used for charging. Value is set to 3 by default. + * + * @return Number of phases. + */ + public Integer getNumberPhases() { + return numberPhases; + } + + /** + * Optional. The number of phases that can be used for charging. Value is set to 3 by default. + * + * @param numberPhases integer, default is 3. + */ + @XmlElement + public void setNumberPhases(Integer numberPhases) { + this.numberPhases = numberPhases; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChargingSchedulePeriod that = (ChargingSchedulePeriod) o; + return Objects.equals(startPeriod, that.startPeriod) + && Objects.equals(limit, that.limit) + && Objects.equals(numberPhases, that.numberPhases); + } + + @Override + public int hashCode() { + return Objects.hash(startPeriod, limit, numberPhases); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("startPeriod", startPeriod) + .add("limit", limit) + .add("numberPhases", numberPhases) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ClearCacheConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ClearCacheConfirmation.java index f1fd1011b..db40f84e4 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ClearCacheConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ClearCacheConfirmation.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,68 +31,88 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + 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 a {@link ClearCacheRequest}. */ +/** + * Sent by the Charge Point to the Central System in response to a {@link ClearCacheRequest}. + */ @XmlRootElement(name = "clearCacheResponse") public class ClearCacheConfirmation implements Confirmation { - private ClearCacheStatus status; - - /** - * Accepted if the Charge Point has executed the request, otherwise rejected. - * - * @return the {@link ClearCacheStatus}. - */ - public ClearCacheStatus getStatus() { - return status; - } - - /** - * Accepted if the Charge Point has executed the request, otherwise rejected. - * - * @return the {@link ClearCacheStatus}. - */ - @Deprecated - public ClearCacheStatus objStatus() { - return status; - } - - /** - * Required. Accepted if the Charge Point has executed the request, otherwise rejected. - * - * @param status the {@link ClearCacheStatus}. - */ - @XmlElement - public void setStatus(ClearCacheStatus status) { - this.status = status; - } - - @Override - public boolean validate() { - return this.status != null; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ClearCacheConfirmation that = (ClearCacheConfirmation) o; - return status == that.status; - } - - @Override - public int hashCode() { - return Objects.hash(status); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + private ClearCacheStatus status; + + /** + * @deprecated use {@link #ClearCacheConfirmation(ClearCacheStatus)} to be sure to set required fields + */ + @Deprecated + public ClearCacheConfirmation() { + + } + + /** + * Handle required fields. + * + * @param status the {@link ClearCacheStatus}, see {@link #setStatus(ClearCacheStatus)} + */ + public ClearCacheConfirmation(ClearCacheStatus status) { + setStatus(status); + } + + /** + * Accepted if the Charge Point has executed the request, otherwise rejected. + * + * @return the {@link ClearCacheStatus}. + */ + public ClearCacheStatus getStatus() { + return status; + } + + /** + * Required. Accepted if the Charge Point has executed the request, otherwise rejected. + * + * @param status the {@link ClearCacheStatus}. + */ + @XmlElement + public void setStatus(ClearCacheStatus status) { + this.status = status; + } + + /** + * Accepted if the Charge Point has executed the request, otherwise rejected. + * + * @return the {@link ClearCacheStatus}. + */ + @Deprecated + public ClearCacheStatus objStatus() { + return status; + } + + @Override + public boolean validate() { + return this.status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ClearCacheConfirmation that = (ClearCacheConfirmation) o; + return status == that.status; + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/DataTransferConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/DataTransferConfirmation.java index 0d625ad04..394d1b5ea 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/DataTransferConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/DataTransferConfirmation.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,10 +29,11 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Objects; /** * Sent by the Charge Point to the Central System or vice versa in response to a {@link @@ -41,81 +43,98 @@ @XmlType(propOrder = {"status", "data"}) public class DataTransferConfirmation implements Confirmation { - private DataTransferStatus status; - private String data; - - /** - * This indicates the success or failure of the data transfer. - * - * @return the {@link DataTransferStatus}. - */ - public DataTransferStatus getStatus() { - return status; - } - - /** - * This indicates the success or failure of the data transfer. - * - * @return the {@link DataTransferStatus}. - */ - @Deprecated - public DataTransferStatus objStatus() { - return status; - } - - /** - * Required. This indicates the success or failure of the data transfer. - * - * @param status the {@link DataTransferStatus}. - */ - @XmlElement - public void setStatus(DataTransferStatus status) { - this.status = status; - } - - /** - * Optional. Data in response to request. - * - * @return data. - */ - public String getData() { - return data; - } - - /** - * Optional. Data in response to request. - * - * @param data String, data - */ - @XmlElement - public void setData(String data) { - this.data = data; - } - - @Override - public boolean validate() { - return this.status != null; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - DataTransferConfirmation that = (DataTransferConfirmation) o; - return status == that.status && Objects.equals(data, that.data); - } - - @Override - public int hashCode() { - return Objects.hash(status, data); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("data", data) - .add("isValid", validate()) - .toString(); - } + private DataTransferStatus status; + private String data; + + /** + * @deprecated use {@link #DataTransferConfirmation(DataTransferStatus)} to be sure to set required fields + */ + @Deprecated + public DataTransferConfirmation() { + + } + + /** + * Handle required fields. + * + * @param status the {@link DataTransferStatus}, see {@link #setStatus(DataTransferStatus)} + */ + public DataTransferConfirmation(DataTransferStatus status) { + setStatus(status); + } + + /** + * This indicates the success or failure of the data transfer. + * + * @return the {@link DataTransferStatus}. + */ + public DataTransferStatus getStatus() { + return status; + } + + /** + * Required. This indicates the success or failure of the data transfer. + * + * @param status the {@link DataTransferStatus}. + */ + @XmlElement + public void setStatus(DataTransferStatus status) { + this.status = status; + } + + /** + * This indicates the success or failure of the data transfer. + * + * @return the {@link DataTransferStatus}. + */ + @Deprecated + public DataTransferStatus objStatus() { + return status; + } + + /** + * Optional. Data in response to request. + * + * @return data. + */ + public String getData() { + return data; + } + + /** + * Optional. Data in response to request. + * + * @param data String, data + */ + @XmlElement + public void setData(String data) { + this.data = data; + } + + @Override + public boolean validate() { + return this.status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DataTransferConfirmation that = (DataTransferConfirmation) o; + return status == that.status && Objects.equals(data, that.data); + } + + @Override + public int hashCode() { + return Objects.hash(status, data); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("data", data) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/DataTransferRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/DataTransferRequest.java index b9f06d6bf..a8a899b30 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/DataTransferRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/DataTransferRequest.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,142 +31,150 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Objects; -/** Sent either by the Central System to the Charge Point or vice versa. */ +/** + * Sent either by the Central System to the Charge Point or vice versa. + */ @XmlRootElement @XmlType(propOrder = {"vendorId", "messageId", "data"}) public class DataTransferRequest implements Request { - private static final String ERROR_MESSAGE = "Exceeded limit of %s chars"; - - private String vendorId; - private String messageId; - private String data; - - public DataTransferRequest() {} - - /** - * Set required fields. - * - * @param vendorId Vendor identification, see {@link #setVendorId(String)}. - */ - public DataTransferRequest(String vendorId) { - this.vendorId = vendorId; - } - - @Override - public boolean validate() { - return isValidVendorId(this.vendorId); - } - - /** - * This identifies the Vendor specific implementation. - * - * @return String, Vendor identification. - */ - public String getVendorId() { - return vendorId; - } - - /** - * Required. This identifies the Vendor specific implementation. - * - * @param vendorId String, max 255 characters, case insensitive. - */ - @XmlElement - public void setVendorId(String vendorId) { - if (!isValidVendorId(vendorId)) { - throw new PropertyConstraintException(vendorId.length(), createErrorMessage(255)); - } - - this.vendorId = vendorId; - } - - private boolean isValidVendorId(String vendorId) { - return ModelUtil.validate(vendorId, 255); - } - - /** - * Additional identification field. - * - * @return Additional identification. - */ - public String getMessageId() { - return messageId; - } - - /** - * Optional. Additional identification field. - * - * @param messageId String, max 50 characters, case insensitive. - */ - @XmlElement - public void setMessageId(String messageId) { - if (!isValidMessageId(messageId)) { - throw new PropertyConstraintException(messageId.length(), createErrorMessage(50)); - } - - this.messageId = messageId; - } - - private boolean isValidMessageId(String messageId) { - return ModelUtil.validate(messageId, 50); - } - - /** - * Data without specified length or format. - * - * @return data. - */ - public String getData() { - return data; - } - - /** - * Optional. Data without specified length or format. - * - * @param data String, data. - */ - @XmlElement - public void setData(String data) { - this.data = data; - } - - @Override - public boolean transactionRelated() { - return false; - } - - private String createErrorMessage(int maxLength) { - return String.format(ERROR_MESSAGE, maxLength); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - DataTransferRequest that = (DataTransferRequest) o; - return Objects.equals(vendorId, that.vendorId) - && Objects.equals(messageId, that.messageId) - && Objects.equals(data, that.data); - } - - @Override - public int hashCode() { - return Objects.hash(vendorId, messageId, data); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("vendorId", vendorId) - .add("messageId", messageId) - .add("data", data) - .add("isValid", validate()) - .toString(); - } + private static final String ERROR_MESSAGE = "Exceeded limit of %s chars"; + + private String vendorId; + private String messageId; + private String data; + + /** + * @deprecated use {@link #DataTransferRequest(String)} to be sure to set required fields + */ + @Deprecated + public DataTransferRequest() { + } + + /** + * Handle required fields. + * + * @param vendorId Vendor identification, see {@link #setVendorId(String)}. + */ + public DataTransferRequest(String vendorId) { + this.vendorId = vendorId; + } + + @Override + public boolean validate() { + return isValidVendorId(this.vendorId); + } + + /** + * This identifies the Vendor specific implementation. + * + * @return String, Vendor identification. + */ + public String getVendorId() { + return vendorId; + } + + /** + * Required. This identifies the Vendor specific implementation. + * + * @param vendorId String, max 255 characters, case insensitive. + */ + @XmlElement + public void setVendorId(String vendorId) { + if (!isValidVendorId(vendorId)) { + throw new PropertyConstraintException(vendorId.length(), createErrorMessage(255)); + } + + this.vendorId = vendorId; + } + + private boolean isValidVendorId(String vendorId) { + return ModelUtil.validate(vendorId, 255); + } + + /** + * Additional identification field. + * + * @return Additional identification. + */ + public String getMessageId() { + return messageId; + } + + /** + * Optional. Additional identification field. + * + * @param messageId String, max 50 characters, case insensitive. + */ + @XmlElement + public void setMessageId(String messageId) { + if (!isValidMessageId(messageId)) { + throw new PropertyConstraintException(messageId.length(), createErrorMessage(50)); + } + + this.messageId = messageId; + } + + private boolean isValidMessageId(String messageId) { + return ModelUtil.validate(messageId, 50); + } + + /** + * Data without specified length or format. + * + * @return data. + */ + public String getData() { + return data; + } + + /** + * Optional. Data without specified length or format. + * + * @param data String, data. + */ + @XmlElement + public void setData(String data) { + this.data = data; + } + + @Override + public boolean transactionRelated() { + return false; + } + + private String createErrorMessage(int maxLength) { + return String.format(ERROR_MESSAGE, maxLength); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DataTransferRequest that = (DataTransferRequest) o; + return Objects.equals(vendorId, that.vendorId) + && Objects.equals(messageId, that.messageId) + && Objects.equals(data, that.data); + } + + @Override + public int hashCode() { + return Objects.hash(vendorId, messageId, data); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("vendorId", vendorId) + .add("messageId", messageId) + .add("data", data) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/HeartbeatConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/HeartbeatConfirmation.java index d62e54037..b3edf3aae 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/HeartbeatConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/HeartbeatConfirmation.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,68 +29,88 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.time.ZonedDateTime; +import java.util.Objects; -/** Sent by the Central System to the Charge Point in response to a {@link HeartbeatRequest}. */ +/** + * Sent by the Central System to the Charge Point in response to a {@link HeartbeatRequest}. + */ @XmlRootElement(name = "heartbeatResponse") public class HeartbeatConfirmation implements Confirmation { - private Calendar currentTime; + private ZonedDateTime currentTime; + + /** + * @deprecated use {@link #HeartbeatConfirmation(ZonedDateTime)} to be sure to set required fields + */ + @Deprecated + public HeartbeatConfirmation() { + + } + + /** + * Handle required fields. + * + * @param currentTime ZonedDateTime, current time, see {@link #setCurrentTime(ZonedDateTime)} + */ + public HeartbeatConfirmation(ZonedDateTime currentTime) { + setCurrentTime(currentTime); + } - /** - * This contains the current time of the Central System. - * - * @return The current time. - */ - @Deprecated - public Calendar objCurrentTime() { - return currentTime; - } + /** + * This contains the current time of the Central System. + * + * @return The current time. + */ + @Deprecated + public ZonedDateTime objCurrentTime() { + return currentTime; + } - /** - * This contains the current time of the Central System. - * - * @return The current time. - */ - public Calendar getCurrentTime() { - return currentTime; - } + /** + * This contains the current time of the Central System. + * + * @return The current time. + */ + public ZonedDateTime getCurrentTime() { + return currentTime; + } - /** - * Required. This contains the current time of the Central System. - * - * @param currentTime Calendar, current time. - */ - @XmlElement - public void setCurrentTime(Calendar currentTime) { - this.currentTime = currentTime; - } + /** + * Required. This contains the current time of the Central System. + * + * @param currentTime ZonedDateTime, current time. + */ + @XmlElement + public void setCurrentTime(ZonedDateTime currentTime) { + this.currentTime = currentTime; + } - @Override - public boolean validate() { - return currentTime != null; - } + @Override + public boolean validate() { + return currentTime != null; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - HeartbeatConfirmation that = (HeartbeatConfirmation) o; - return Objects.equals(currentTime, that.currentTime); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + HeartbeatConfirmation that = (HeartbeatConfirmation) o; + return Objects.equals(currentTime, that.currentTime); + } - @Override - public int hashCode() { - return Objects.hash(currentTime); - } + @Override + public int hashCode() { + return Objects.hash(currentTime); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("currentTime", currentTime) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("currentTime", currentTime) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/IdTagInfo.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/IdTagInfo.java index 1fc6e703d..b374bc682 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/IdTagInfo.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/IdTagInfo.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,11 +31,12 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Validatable; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Objects; /** * Contains status information about an identifier. It is returned in {@link AuthorizeConfirmation}, @@ -44,116 +47,133 @@ of this software and associated documentation files (the "Software"), to deal @XmlRootElement @XmlType(propOrder = {"status", "expiryDate", "parentIdTag"}) public class IdTagInfo implements Validatable { - private Calendar expiryDate; - private String parentIdTag; - private AuthorizationStatus status; - - /** - * This contains the date at which idTag should be removed from the Authorization Cache. - * - * @return Expiry date. - */ - public Calendar getExpiryDate() { - return expiryDate; - } - - /** - * This contains the date at which idTag should be removed from the Authorization Cache. - * - * @return Expiry date. - */ - @Deprecated - public Calendar objExpiryDate() { - return expiryDate; - } - - /** - * Optional. This contains the date at which idTag should be removed from the Authorization Cache. - * - * @param expiryDate Calendar, expire date. - */ - @XmlElement - public void setExpiryDate(Calendar expiryDate) { - this.expiryDate = expiryDate; - } - - /** - * This contains the parent-identifier. - * - * @return the IdToken of the parent. - */ - public String getParentIdTag() { - return parentIdTag; - } - - /** - * Optional. This contains the parent-identifier. - * - * @param parentIdTag an IdToken. - */ - @XmlElement - public void setParentIdTag(String parentIdTag) { - this.parentIdTag = parentIdTag; - } - - /** - * This contains whether the idTag has been accepted or not by the Central System. - * - * @return the {@link AuthorizationStatus} for IdTag. - */ - public AuthorizationStatus getStatus() { - return status; - } - - /** - * This contains whether the idTag has been accepted or not by the Central System. - * - * @return the {@link AuthorizationStatus} for IdTag. - */ - @Deprecated - public AuthorizationStatus objStatus() { - return status; - } - - /** - * Required. This contains whether the idTag has been accepted or not by the Central System. - * - * @param status the {@link AuthorizationStatus} for IdTag. - */ - @XmlElement - public void setStatus(AuthorizationStatus status) { - this.status = status; - } - - @Override - public boolean validate() { - boolean valid = true; - valid &= this.status != null; - return valid; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - IdTagInfo idTagInfo = (IdTagInfo) o; - return Objects.equals(expiryDate, idTagInfo.expiryDate) - && Objects.equals(parentIdTag, idTagInfo.parentIdTag) - && status == idTagInfo.status; - } - - @Override - public int hashCode() { - - return Objects.hash(expiryDate, parentIdTag, status); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("expiryDate", expiryDate) - .add("parentIdTag", parentIdTag) - .add("status", status) - .toString(); - } + private ZonedDateTime expiryDate; + private String parentIdTag; + private AuthorizationStatus status; + + /** + * @deprecated use {@link #IdTagInfo(AuthorizationStatus)} to be sure to set required fields + */ + @Deprecated + public IdTagInfo() { + + } + + /** + * Handle required fields. + * + * @param status the {@link AuthorizationStatus} for IdTag, see {@link #setStatus(AuthorizationStatus)} + */ + public IdTagInfo(AuthorizationStatus status) { + setStatus(status); + } + + /** + * This contains the date at which idTag should be removed from the Authorization Cache. + * + * @return Expiry date. + */ + public ZonedDateTime getExpiryDate() { + return expiryDate; + } + + /** + * Optional. This contains the date at which idTag should be removed from the Authorization Cache. + * + * @param expiryDate ZonedDateTime, expire date. + */ + @XmlElement + public void setExpiryDate(ZonedDateTime expiryDate) { + this.expiryDate = expiryDate; + } + + /** + * This contains the date at which idTag should be removed from the Authorization Cache. + * + * @return Expiry date. + */ + @Deprecated + public ZonedDateTime objExpiryDate() { + return expiryDate; + } + + /** + * This contains the parent-identifier. + * + * @return the IdToken of the parent. + */ + public String getParentIdTag() { + return parentIdTag; + } + + /** + * Optional. This contains the parent-identifier. + * + * @param parentIdTag an IdToken. + */ + @XmlElement + public void setParentIdTag(String parentIdTag) { + this.parentIdTag = parentIdTag; + } + + /** + * This contains whether the idTag has been accepted or not by the Central System. + * + * @return the {@link AuthorizationStatus} for IdTag. + */ + public AuthorizationStatus getStatus() { + return status; + } + + /** + * Required. This contains whether the idTag has been accepted or not by the Central System. + * + * @param status the {@link AuthorizationStatus} for IdTag. + */ + @XmlElement + public void setStatus(AuthorizationStatus status) { + this.status = status; + } + + /** + * This contains whether the idTag has been accepted or not by the Central System. + * + * @return the {@link AuthorizationStatus} for IdTag. + */ + @Deprecated + public AuthorizationStatus objStatus() { + return status; + } + + @Override + public boolean validate() { + boolean valid = true; + valid &= this.status != null; + return valid; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + IdTagInfo idTagInfo = (IdTagInfo) o; + return Objects.equals(expiryDate, idTagInfo.expiryDate) + && Objects.equals(parentIdTag, idTagInfo.parentIdTag) + && status == idTagInfo.status; + } + + @Override + public int hashCode() { + + return Objects.hash(expiryDate, parentIdTag, status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("expiryDate", expiryDate) + .add("parentIdTag", parentIdTag) + .add("status", status) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/KeyValueType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/KeyValueType.java index e497ae413..c56ed8000 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/KeyValueType.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/KeyValueType.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -31,10 +33,11 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Validatable; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Objects; /** * Contains information about a specific configuration key. It is returned in {@link @@ -44,123 +47,142 @@ of this software and associated documentation files (the "Software"), to deal @XmlType(propOrder = {"key", "readonly", "value"}) public class KeyValueType implements Validatable { - private static final String ERROR_MESSAGE = "Exceeds limit of %s chars"; - - private String key; - private Boolean readonly; - private String value; - - /** - * Name of the key. - * - * @return key. - */ - public String getKey() { - return key; - } - - /** - * Required. Name of the key. - * - * @param key String, max 50 characters, case insensitive. - */ - @XmlElement - public void setKey(String key) { - if (!isValidKey(key)) { - throw new PropertyConstraintException(key.length(), createErrorMessage(50)); - } - - this.key = key; - } - - private boolean isValidKey(String key) { - return ModelUtil.validate(key, 50); - } - - /** - * False if the value can be set with a {@link ChangeConfigurationRequest}. - * - * @return Is configuration read only. - */ - public Boolean getReadonly() { - return readonly; - } - - /** - * Required. False if the value can be set with a {@link ChangeConfigurationRequest}. - * - * @param readonly Boolean, configuration is read only. - */ - @XmlElement - public void setReadonly(Boolean readonly) { - if (!isValidReadonly(readonly)) { - throw new PropertyConstraintException(null, "readonly must be present"); - } - - this.readonly = readonly; - } - - private boolean isValidReadonly(Boolean readonly) { - return readonly != null; - } - - /** - * If key is known but not set, this field may be absent. - * - * @return Value associated to the key. - */ - public String getValue() { - return value; - } - - /** - * Optional. If key is known but not set, this field may be absent. - * - * @param value String, max 500 characters, case insensitive. - */ - @XmlElement - public void setValue(String value) { - if (!isValidValue(value)) { - throw new PropertyConstraintException(value.length(), createErrorMessage(500)); - } - - this.value = value; - } - - private boolean isValidValue(String value) { - return ModelUtil.validate(value, 500); - } - - @Override - public boolean validate() { - return isValidKey(this.key) && isValidReadonly(this.readonly); - } - - private static String createErrorMessage(int maxLength) { - return String.format(ERROR_MESSAGE, maxLength); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - KeyValueType that = (KeyValueType) o; - return Objects.equals(key, that.key) - && Objects.equals(readonly, that.readonly) - && Objects.equals(value, that.value); - } - - @Override - public int hashCode() { - return Objects.hash(key, readonly, value); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("key", key) - .add("readonly", readonly) - .add("value", value) - .toString(); - } + private static final String ERROR_MESSAGE = "Exceeds limit of %s chars"; + + private String key; + private Boolean readonly; + private String value; + + /** + * @deprecated use {@link #KeyValueType(String, Boolean)} to be sure to set required fields + */ + @Deprecated + public KeyValueType() { + + } + + /** + * Handle required fields. + * + * @param key String, max 50 characters, case insensitive, see {@link #setKey(String)} + * @param readonly Boolean, configuration is read only, see {@link #setReadonly(Boolean)} + */ + public KeyValueType(String key, Boolean readonly) { + setKey(key); + setReadonly(readonly); + } + + private static String createErrorMessage(int maxLength) { + return String.format(ERROR_MESSAGE, maxLength); + } + + /** + * Name of the key. + * + * @return key. + */ + public String getKey() { + return key; + } + + /** + * Required. Name of the key. + * + * @param key String, max 50 characters, case insensitive. + */ + @XmlElement + public void setKey(String key) { + if (!isValidKey(key)) { + throw new PropertyConstraintException(key.length(), createErrorMessage(50)); + } + + this.key = key; + } + + private boolean isValidKey(String key) { + return ModelUtil.validate(key, 50); + } + + /** + * False if the value can be set with a {@link ChangeConfigurationRequest}. + * + * @return Is configuration read only. + */ + public Boolean getReadonly() { + return readonly; + } + + /** + * Required. False if the value can be set with a {@link ChangeConfigurationRequest}. + * + * @param readonly Boolean, configuration is read only. + */ + @XmlElement + public void setReadonly(Boolean readonly) { + if (!isValidReadonly(readonly)) { + throw new PropertyConstraintException(null, "readonly must be present"); + } + + this.readonly = readonly; + } + + private boolean isValidReadonly(Boolean readonly) { + return readonly != null; + } + + /** + * If key is known but not set, this field may be absent. + * + * @return Value associated to the key. + */ + public String getValue() { + return value; + } + + /** + * Optional. If key is known but not set, this field may be absent. + * + * @param value String, max 500 characters, case insensitive. + */ + @XmlElement + public void setValue(String value) { + if (!isValidValue(value)) { + throw new PropertyConstraintException(value.length(), createErrorMessage(500)); + } + + this.value = value; + } + + private boolean isValidValue(String value) { + return ModelUtil.validate(value, 500); + } + + @Override + public boolean validate() { + return isValidKey(this.key) && isValidReadonly(this.readonly); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + KeyValueType that = (KeyValueType) o; + return Objects.equals(key, that.key) + && Objects.equals(readonly, that.readonly) + && Objects.equals(value, that.value); + } + + @Override + public int hashCode() { + return Objects.hash(key, readonly, value); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("key", key) + .add("readonly", readonly) + .add("value", value) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/MeterValue.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/MeterValue.java index 2827e55d7..73fd865a9 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/MeterValue.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/MeterValue.java @@ -2,12 +2,13 @@ import eu.chargetime.ocpp.model.Validatable; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Arrays; +import java.util.Objects; /* * ChargeTime.eu - Java-OCA-OCPP @@ -15,6 +16,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -43,89 +45,108 @@ @XmlType(propOrder = {"timestamp", "sampledValue"}) public class MeterValue implements Validatable { - private Calendar timestamp; - private SampledValue[] sampledValue; + private ZonedDateTime timestamp; + private SampledValue[] sampledValue; + + /** + * @deprecated use {@link #MeterValue(ZonedDateTime, SampledValue[])} to be sure to set required fields + */ + @Deprecated + public MeterValue() { + + } + + /** + * Handle required fields. + * + * @param timestamp {@link ZonedDateTime} timestamp, see {@link #setTimestamp(ZonedDateTime)} + * @param sampledValue Array of {@link SampledValue}, see {@link #setSampledValue(SampledValue[])} + */ + public MeterValue(ZonedDateTime timestamp, SampledValue[] sampledValue) { + setTimestamp(timestamp); + setSampledValue(sampledValue); + } + + @Override + public boolean validate() { + boolean valid = timestamp != null && sampledValue != null; + + if (valid) { + for (SampledValue value : sampledValue) { + valid &= value.validate(); + } + } + return valid; + } + + /** + * Timestamp for measured value(s). + * + * @return original timestamp. + */ + public ZonedDateTime getTimestamp() { + return timestamp; + } + + /** + * Required. Timestamp for measured value(s). + * + * @param timestamp {@link ZonedDateTime} timestamp + */ + @XmlElement + public void setTimestamp(ZonedDateTime timestamp) { + this.timestamp = timestamp; + } - @Override - public boolean validate() { - boolean valid = timestamp != null && sampledValue != null; + /** + * Timestamp for measured value(s). + * + * @return original timestamp. + */ + @Deprecated + public ZonedDateTime objTimestamp() { + return timestamp; + } + + /** + * One or more measured values. + * + * @return Array of {@link SampledValue}. + */ + public SampledValue[] getSampledValue() { + return sampledValue; + } + + /** + * Required. One or more measured values. + * + * @param sampledValue Array of {@link SampledValue}. + */ + @XmlElement + public void setSampledValue(SampledValue[] sampledValue) { + this.sampledValue = sampledValue; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MeterValue that = (MeterValue) o; + return Objects.equals(timestamp, that.timestamp) + && Arrays.equals(sampledValue, that.sampledValue); + } + + @Override + public int hashCode() { + return Objects.hash(timestamp, sampledValue); + } - if (valid) { - for (SampledValue value : sampledValue) { - valid &= value.validate(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("timestamp", timestamp) + .add("sampledValue", sampledValue) + .add("isValid", validate()) + .toString(); } - return valid; - } - - /** - * Timestamp for measured value(s). - * - * @return original timestamp. - */ - public Calendar getTimestamp() { - return timestamp; - } - - /** - * Timestamp for measured value(s). - * - * @return original timestamp. - */ - @Deprecated - public Calendar objTimestamp() { - return timestamp; - } - - /** - * Required. Timestamp for measured value(s). - * - * @param timestamp {@link Calendar} timestamp - */ - @XmlElement - public void setTimestamp(Calendar timestamp) { - this.timestamp = timestamp; - } - - /** - * One or more measured values. - * - * @return Array of {@link SampledValue}. - */ - public SampledValue[] getSampledValue() { - return sampledValue; - } - - /** - * Required. One or more measured values. - * - * @param sampledValue Array of {@link SampledValue}. - */ - @XmlElement - public void setSampledValue(SampledValue[] sampledValue) { - this.sampledValue = sampledValue; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - MeterValue that = (MeterValue) o; - return Objects.equals(timestamp, that.timestamp) - && Arrays.equals(sampledValue, that.sampledValue); - } - - @Override - public int hashCode() { - return Objects.hash(timestamp, sampledValue); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("timestamp", timestamp) - .add("sampledValue", sampledValue) - .add("isValid", validate()) - .toString(); - } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/MeterValuesRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/MeterValuesRequest.java index 3f6fa9fae..af8ab0dff 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/MeterValuesRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/MeterValuesRequest.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,11 +30,12 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Arrays; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Arrays; +import java.util.Objects; /** * Sent by the Charge Point to the Central System. @@ -44,113 +46,130 @@ @XmlType(propOrder = {"connectorId", "transactionId", "meterValue"}) public class MeterValuesRequest implements Request { - private int connectorId; - private int transactionId; - private MeterValue[] meterValue; + private Integer connectorId; + private Integer transactionId; + private MeterValue[] meterValue; + + /** + * @deprecated use {@link #MeterValuesRequest(Integer)} to be sure to set required fields + */ + @Deprecated + public MeterValuesRequest() { + + } + + /** + * Handle required fields. + * + * @param connectorId integer, connector, see {@link #setConnectorId(Integer)} + */ + public MeterValuesRequest(Integer connectorId) { + setConnectorId(connectorId); + } + + @Override + public boolean validate() { + boolean valid = this.connectorId != null && this.connectorId >= 0 && this.meterValue != null; + + if (valid) { + for (MeterValue current : this.meterValue) { + valid &= (current != null && current.validate()); + } + } + + return valid; + } + + /** + * This contains a number (>0) designating a connector of the Charge Point. ‘0’ (zero) is used + * to designate the main power meter. + * + * @return Connector + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Required. This contains a number (>0) designating a connector of the Charge Point. ‘0’ + * (zero) is used to designate the main power meter. + * + * @param connectorId integer, connector + */ + @XmlElement + public void setConnectorId(Integer connectorId) { + if (connectorId < 0) { + throw new PropertyConstraintException(connectorId, "connectorId must be >= 0"); + } + + this.connectorId = connectorId; + } + + /** + * The transaction to which these meter samples are related. + * + * @return transaction id. + */ + public Integer getTransactionId() { + return transactionId; + } + + /** + * Optional. The transaction to which these meter samples are related. + * + * @param transactionId integer, transaction id. + */ + @XmlElement + public void setTransactionId(Integer transactionId) { + this.transactionId = transactionId; + } + + /** + * The sampled meter values with timestamps. + * + * @return Array of {@link MeterValue}. + */ + public MeterValue[] getMeterValue() { + return meterValue; + } - @Override - public boolean validate() { - boolean valid = this.connectorId >= 0 && this.meterValue != null; + /** + * Required. The sampled meter values with timestamps. + * + * @param meterValue Array of {@link MeterValue}. + */ + @XmlElement + public void setMeterValue(MeterValue[] meterValue) { + this.meterValue = meterValue; + } - if (valid) { - for (MeterValue current : this.meterValue) { - valid &= (current != null && current.validate()); - } + @Override + public boolean transactionRelated() { + return true; } - return valid; - } - - /** - * This contains a number (>0) designating a connector of the Charge Point. ‘0’ (zero) is used - * to designate the main power meter. - * - * @return Connector - */ - public int getConnectorId() { - return connectorId; - } - - /** - * Required. This contains a number (>0) designating a connector of the Charge Point. ‘0’ - * (zero) is used to designate the main power meter. - * - * @param connectorId integer, connector - */ - @XmlElement - public void setConnectorId(int connectorId) { - if (connectorId < 0) { - throw new PropertyConstraintException(connectorId, "connectorId must be >= 0"); + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MeterValuesRequest that = (MeterValuesRequest) o; + return connectorId == that.connectorId + && transactionId == that.transactionId + && Arrays.equals(meterValue, that.meterValue); } - this.connectorId = connectorId; - } - - /** - * The transaction to which these meter samples are related. - * - * @return transaction id. - */ - public int getTransactionId() { - return transactionId; - } - - /** - * Optional. The transaction to which these meter samples are related. - * - * @param transactionId integer, transaction id. - */ - @XmlElement - public void setTransactionId(int transactionId) { - this.transactionId = transactionId; - } - - /** - * Required. The sampled meter values with timestamps. - * - * @param meterValue Array of {@link MeterValue}. - */ - @XmlElement - public void setMeterValue(MeterValue[] meterValue) { - this.meterValue = meterValue; - } - - /** - * The sampled meter values with timestamps. - * - * @return Array of {@link MeterValue}. - */ - public MeterValue[] getMeterValue() { - return meterValue; - } - - @Override - public boolean transactionRelated() { - return true; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - MeterValuesRequest that = (MeterValuesRequest) o; - return connectorId == that.connectorId - && transactionId == that.transactionId - && Arrays.equals(meterValue, that.meterValue); - } - - @Override - public int hashCode() { - return Objects.hash(connectorId, transactionId, meterValue); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("connectorId", connectorId) - .add("transactionId", transactionId) - .add("meterValue", meterValue) - .add("isValid", validate()) - .toString(); - } + @Override + public int hashCode() { + return Objects.hash(connectorId, transactionId, meterValue); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("connectorId", connectorId) + .add("transactionId", transactionId) + .add("meterValue", meterValue) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStartTransactionConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStartTransactionConfirmation.java index c4084c9a1..6f4039752 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStartTransactionConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStartTransactionConfirmation.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,78 +29,86 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; -/** Sent from Charge Point to Central System. */ +/** + * Sent from Charge Point to Central System. + */ @XmlRootElement(name = "remoteStartTransactionResponse") public class RemoteStartTransactionConfirmation implements Confirmation { - private RemoteStartStopStatus status; + private RemoteStartStopStatus status; - public RemoteStartTransactionConfirmation() {} + /** + * @deprecated use {@link #RemoteStartTransactionConfirmation(RemoteStartStopStatus)} to be sure to set required fields + */ + @Deprecated + public RemoteStartTransactionConfirmation() { + } - /** - * Set required fields. - * - * @param status status for request, see {@link #setStatus(RemoteStartStopStatus)}. - */ - public RemoteStartTransactionConfirmation(RemoteStartStopStatus status) { - setStatus(status); - } + /** + * Handle required fields. + * + * @param status status for request, see {@link #setStatus(RemoteStartStopStatus)} + */ + public RemoteStartTransactionConfirmation(RemoteStartStopStatus status) { + setStatus(status); + } - /** - * Status indicating whether Charge Point accepts the request to start a transaction. - * - * @return the {@link RemoteStartStopStatus}. - */ - public RemoteStartStopStatus getStatus() { - return status; - } + /** + * Status indicating whether Charge Point accepts the request to start a transaction. + * + * @return the {@link RemoteStartStopStatus}. + */ + public RemoteStartStopStatus getStatus() { + return status; + } - /** - * Status indicating whether Charge Point accepts the request to start a transaction. - * - * @return the {@link RemoteStartStopStatus}. - */ - @Deprecated - public RemoteStartStopStatus objStatus() { - return status; - } + /** + * Required. Status indicating whether Charge Point accepts the request to start a transaction. + * + * @param status the {@link RemoteStartStopStatus}. + */ + @XmlElement + public void setStatus(RemoteStartStopStatus status) { + this.status = status; + } - /** - * Required. Status indicating whether Charge Point accepts the request to start a transaction. - * - * @param status the {@link RemoteStartStopStatus}. - */ - @XmlElement - public void setStatus(RemoteStartStopStatus status) { - this.status = status; - } + /** + * Status indicating whether Charge Point accepts the request to start a transaction. + * + * @return the {@link RemoteStartStopStatus}. + */ + @Deprecated + public RemoteStartStopStatus objStatus() { + return status; + } - @Override - public boolean validate() { - return status != null; - } + @Override + public boolean validate() { + return status != null; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RemoteStartTransactionConfirmation that = (RemoteStartTransactionConfirmation) o; - return status == that.status; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RemoteStartTransactionConfirmation that = (RemoteStartTransactionConfirmation) o; + return status == that.status; + } - @Override - public int hashCode() { - return Objects.hash(status); - } + @Override + public int hashCode() { + return Objects.hash(status); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStartTransactionRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStartTransactionRequest.java index d0a64653e..98349d089 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStartTransactionRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStartTransactionRequest.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,130 +31,150 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Objects; -/** Sent to Charge Point by Central System. */ +/** + * Sent to Charge Point by Central System. + */ @XmlRootElement @XmlType(propOrder = {"connectorId", "idTag", "chargingProfile"}) public class RemoteStartTransactionRequest implements Request { - private Integer connectorId; - private String idTag; - private ChargingProfile chargingProfile; + private Integer connectorId; + private String idTag; + private ChargingProfile chargingProfile; + + /** + * @deprecated use {@link #RemoteStartTransactionRequest(String)} to be sure to set required fields + */ + @Deprecated + public RemoteStartTransactionRequest() { + + } + + /** + * Handle required fields. + * + * @param idTag a String with max length 20, see {@link #setIdTag(String)} + */ + public RemoteStartTransactionRequest(String idTag) { + setIdTag(idTag); + } + + @Override + public boolean validate() { + boolean valid = ModelUtil.validate(idTag, 20); + + if (chargingProfile != null) { + valid &= chargingProfile.validate(); + } + + if (connectorId != null) { + valid &= connectorId > 0; + } - @Override - public boolean validate() { - boolean valid = ModelUtil.validate(idTag, 20); + return valid; + } + + /** + * Number of the connector on which to start the transaction. connectorId SHALL be > 0. + * + * @return Connector. + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Optional. Number of the connector on which to start the transaction. connectorId SHALL be > + * 0. + * + * @param connectorId integer, connector + */ + @XmlElement + public void setConnectorId(Integer connectorId) { + if (connectorId <= 0) { + throw new PropertyConstraintException(connectorId, "connectorId must be > 0"); + } + + this.connectorId = connectorId; + } + + /** + * The identifier that Charge Point must use to start a transaction. + * + * @return an IdToken. + */ + public String getIdTag() { + return idTag; + } + + /** + * Required. The identifier that Charge Point must use to start a transaction. + * + * @param idTag a String with max length 20 + */ + @XmlElement + public void setIdTag(String idTag) { + if (!ModelUtil.validate(idTag, 20)) { + throw new PropertyConstraintException(idTag.length(), "Exceeded limit of 20 chars"); + } + + this.idTag = idTag; + } - if (chargingProfile != null) { - valid &= chargingProfile.validate(); + /** + * Charging Profile to be used by the Charge Point for the requested transaction. + * + * @return the {@link ChargingProfile}. + */ + public ChargingProfile getChargingProfile() { + return chargingProfile; } - if (connectorId != null) { - valid &= connectorId > 0; + /** + * Optional. Charging Profile to be used by the Charge Point for the requested transaction. {@link + * ChargingProfile#setChargingProfilePurpose(ChargingProfilePurposeType)} MUST be set to + * TxProfile. + * + * @param chargingProfile the {@link ChargingProfile}. + */ + @XmlElement + public void setChargingProfile(ChargingProfile chargingProfile) { + this.chargingProfile = chargingProfile; } - return valid; - } - - /** - * Number of the connector on which to start the transaction. connectorId SHALL be > 0. - * - * @return Connector. - */ - public Integer getConnectorId() { - return connectorId; - } - - /** - * Optional. Number of the connector on which to start the transaction. connectorId SHALL be > - * 0. - * - * @param connectorId integer, connector - */ - @XmlElement - public void setConnectorId(Integer connectorId) { - if (connectorId <= 0) { - throw new PropertyConstraintException(connectorId, "connectorId must be > 0"); + @Override + public boolean transactionRelated() { + return false; } - this.connectorId = connectorId; - } - - /** - * The identifier that Charge Point must use to start a transaction. - * - * @return an IdToken. - */ - public String getIdTag() { - return idTag; - } - - /** - * Required. The identifier that Charge Point must use to start a transaction. - * - * @param idTag a String with max length 20 - */ - @XmlElement - public void setIdTag(String idTag) { - if (!ModelUtil.validate(idTag, 20)) { - throw new PropertyConstraintException(idTag.length(), "Exceeded limit of 20 chars"); + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RemoteStartTransactionRequest that = (RemoteStartTransactionRequest) o; + return Objects.equals(connectorId, that.connectorId) + && Objects.equals(idTag, that.idTag) + && Objects.equals(chargingProfile, that.chargingProfile); } - this.idTag = idTag; - } - - /** - * Charging Profile to be used by the Charge Point for the requested transaction. - * - * @return the {@link ChargingProfile}. - */ - public ChargingProfile getChargingProfile() { - return chargingProfile; - } - - /** - * Optional. Charging Profile to be used by the Charge Point for the requested transaction. {@link - * ChargingProfile#setChargingProfilePurpose(ChargingProfilePurposeType)} MUST be set to - * TxProfile. - * - * @param chargingProfile the {@link ChargingProfile}. - */ - @XmlElement - public void setChargingProfile(ChargingProfile chargingProfile) { - this.chargingProfile = chargingProfile; - } - - @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; - RemoteStartTransactionRequest that = (RemoteStartTransactionRequest) o; - return Objects.equals(connectorId, that.connectorId) - && Objects.equals(idTag, that.idTag) - && Objects.equals(chargingProfile, that.chargingProfile); - } - - @Override - public int hashCode() { - return Objects.hash(connectorId, idTag, chargingProfile); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("connectorId", connectorId) - .add("idTag", idTag) - .add("chargingProfile", chargingProfile) - .add("isValid", validate()) - .toString(); - } + @Override + public int hashCode() { + return Objects.hash(connectorId, idTag, chargingProfile); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("connectorId", connectorId) + .add("idTag", idTag) + .add("chargingProfile", chargingProfile) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStopTransactionConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStopTransactionConfirmation.java index c5b5e8afd..883b36b30 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStopTransactionConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStopTransactionConfirmation.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,78 +29,87 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; -/** sent from Charge Point to Central System. */ +/** + * sent from Charge Point to Central System. + */ @XmlRootElement(name = "remoteStopTransactionResponse") public class RemoteStopTransactionConfirmation implements Confirmation { - private RemoteStartStopStatus status; - public RemoteStopTransactionConfirmation() {} + private RemoteStartStopStatus status; + + /** + * @deprecated use {@link #RemoteStopTransactionConfirmation(RemoteStartStopStatus)} to be sure to set required fields + */ + @Deprecated + public RemoteStopTransactionConfirmation() { + } - /** - * Set required fields. - * - * @param status the {@link RemoteStartStopStatus}, see {@link #setStatus(RemoteStartStopStatus)}. - */ - public RemoteStopTransactionConfirmation(RemoteStartStopStatus status) { - setStatus(status); - } + /** + * Handle required fields. + * + * @param status the {@link RemoteStartStopStatus}, see {@link #setStatus(RemoteStartStopStatus)} + */ + public RemoteStopTransactionConfirmation(RemoteStartStopStatus status) { + setStatus(status); + } - @Override - public boolean validate() { - return status != null; - } + @Override + public boolean validate() { + return status != null; + } - /** - * Status indicating whether Charge Point accepts the request to stop a transaction. - * - * @return the {@link RemoteStartStopStatus}. - */ - public RemoteStartStopStatus getStatus() { - return status; - } + /** + * Status indicating whether Charge Point accepts the request to stop a transaction. + * + * @return the {@link RemoteStartStopStatus}. + */ + public RemoteStartStopStatus getStatus() { + return status; + } - /** - * Status indicating whether Charge Point accepts the request to stop a transaction. - * - * @return the {@link RemoteStartStopStatus}. - */ - @Deprecated - public RemoteStartStopStatus objStatus() { - return status; - } + /** + * Required. Status indicating whether Charge Point accepts the request to stop a transaction. + * + * @param status the {@link RemoteStartStopStatus}. + */ + @XmlElement + public void setStatus(RemoteStartStopStatus status) { + this.status = status; + } - /** - * Required. Status indicating whether Charge Point accepts the request to stop a transaction. - * - * @param status the {@link RemoteStartStopStatus}. - */ - @XmlElement - public void setStatus(RemoteStartStopStatus status) { - this.status = status; - } + /** + * Status indicating whether Charge Point accepts the request to stop a transaction. + * + * @return the {@link RemoteStartStopStatus}. + */ + @Deprecated + public RemoteStartStopStatus objStatus() { + return status; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RemoteStopTransactionConfirmation that = (RemoteStopTransactionConfirmation) o; - return status == that.status; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RemoteStopTransactionConfirmation that = (RemoteStopTransactionConfirmation) o; + return status == that.status; + } - @Override - public int hashCode() { - return Objects.hash(status); - } + @Override + public int hashCode() { + return Objects.hash(status); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStopTransactionRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStopTransactionRequest.java index 2ee2a938d..6bcb5c029 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStopTransactionRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStopTransactionRequest.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,62 +29,83 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; -/** sent to Charge Point by Central System. */ +/** + * sent to Charge Point by Central System. + */ @XmlRootElement public class RemoteStopTransactionRequest implements Request { - private Integer transactionId; - @Override - public boolean validate() { - return transactionId != null; - } + private Integer transactionId; + + /** + * @deprecated use {@link #RemoteStopTransactionRequest(Integer)} to be sure to set required fields + */ + @Deprecated + public RemoteStopTransactionRequest() { + + } + + /** + * Handle required fields. + * + * @param transactionId integer, transaction id, see {@link #setTransactionId(Integer)} + */ + public RemoteStopTransactionRequest(Integer transactionId) { + setTransactionId(transactionId); + } + + @Override + public boolean validate() { + return transactionId != null; + } - /** - * The identifier of the transaction which Charge Point is requested to stop. - * - * @return transaction id. - */ - public Integer getTransactionId() { - return transactionId; - } + /** + * The identifier of the transaction which Charge Point is requested to stop. + * + * @return transaction id. + */ + public Integer getTransactionId() { + return transactionId; + } - /** - * Required. The identifier of the transaction which Charge Point is requested to stop. - * - * @param transactionId integer, transaction id. - */ - @XmlElement - public void setTransactionId(Integer transactionId) { - this.transactionId = transactionId; - } + /** + * Required. The identifier of the transaction which Charge Point is requested to stop. + * + * @param transactionId integer, transaction id. + */ + @XmlElement + public void setTransactionId(Integer transactionId) { + this.transactionId = transactionId; + } - @Override - public boolean transactionRelated() { - return false; - } + @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; - RemoteStopTransactionRequest that = (RemoteStopTransactionRequest) o; - return Objects.equals(transactionId, that.transactionId); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RemoteStopTransactionRequest that = (RemoteStopTransactionRequest) o; + return Objects.equals(transactionId, that.transactionId); + } - @Override - public int hashCode() { - return Objects.hash(transactionId); - } + @Override + public int hashCode() { + return Objects.hash(transactionId); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("transactionId", transactionId) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("transactionId", transactionId) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ResetConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ResetConfirmation.java index 9185f8a2f..d3df8e2c3 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ResetConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ResetConfirmation.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,78 +29,87 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + 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 a {@link ResetRequest}. */ +/** + * Sent by the Charge Point to the Central System in response to a {@link ResetRequest}. + */ @XmlRootElement public class ResetConfirmation implements Confirmation { - private ResetStatus status; - public ResetConfirmation() {} + private ResetStatus status; + + /** + * @deprecated use {@link #ResetConfirmation(ResetStatus)} to be sure to set required fields + */ + @Deprecated + public ResetConfirmation() { + } - /** - * Set required fields. - * - * @param status the {@link ResetStatus}, see {@link #setStatus(ResetStatus)}. - */ - public ResetConfirmation(ResetStatus status) { - setStatus(status); - } + /** + * Handle required fields. + * + * @param status the {@link ResetStatus}, see {@link #setStatus(ResetStatus)} + */ + public ResetConfirmation(ResetStatus status) { + setStatus(status); + } - @Override - public boolean validate() { - return status != null; - } + @Override + public boolean validate() { + return status != null; + } - /** - * This indicates whether the Charge Point is able to perform the reset. - * - * @return the {@link ResetStatus}. - */ - public ResetStatus getStatus() { - return status; - } + /** + * This indicates whether the Charge Point is able to perform the reset. + * + * @return the {@link ResetStatus}. + */ + public ResetStatus getStatus() { + return status; + } - /** - * This indicates whether the Charge Point is able to perform the reset. - * - * @return the {@link ResetStatus}. - */ - @Deprecated - public ResetStatus objStatus() { - return status; - } + /** + * Required. This indicates whether the Charge Point is able to perform the reset. + * + * @param status the {@link ResetStatus}. + */ + @XmlElement + public void setStatus(ResetStatus status) { + this.status = status; + } - /** - * Required. This indicates whether the Charge Point is able to perform the reset. - * - * @param status the {@link ResetStatus}. - */ - @XmlElement - public void setStatus(ResetStatus status) { - this.status = status; - } + /** + * This indicates whether the Charge Point is able to perform the reset. + * + * @return the {@link ResetStatus}. + */ + @Deprecated + public ResetStatus objStatus() { + return status; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ResetConfirmation that = (ResetConfirmation) o; - return status == that.status; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ResetConfirmation that = (ResetConfirmation) o; + return status == that.status; + } - @Override - public int hashCode() { - return Objects.hash(status); - } + @Override + public int hashCode() { + return Objects.hash(status); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ResetRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ResetRequest.java index 00bb55a4f..ebb17b315 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ResetRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/ResetRequest.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,69 +29,90 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; -/** Sent by the Central System to the Charge Point. */ +/** + * Sent by the Central System to the Charge Point. + */ @XmlRootElement public class ResetRequest implements Request { - private ResetType type; - - /** - * This contains the type of reset that the Charge Point should perform. - * - * @return the {@link ResetType}. - */ - public ResetType getType() { - return type; - } - - /** - * This contains the type of reset that the Charge Point should perform. - * - * @return the {@link ResetType}. - */ - @Deprecated - public ResetType objType() { - return type; - } - - /** - * Required. This contains the type of reset that the Charge Point should perform. - * - * @param type the {@link ResetType}. - */ - @XmlElement - public void setType(ResetType type) { - this.type = type; - } - - @Override - public boolean validate() { - return type != null; - } - - @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; - ResetRequest that = (ResetRequest) o; - return type == that.type; - } - - @Override - public int hashCode() { - return Objects.hash(type); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this).add("type", type).add("isValid", validate()).toString(); - } + + private ResetType type; + + /** + * @deprecated use {@link #ResetRequest(ResetType)} to be sure to set required fields + */ + @Deprecated + public ResetRequest() { + + } + + /** + * Handle required fields. + * + * @param type the {@link ResetType}, see {@link #setType(ResetType)} + */ + public ResetRequest(ResetType type) { + setType(type); + } + + /** + * This contains the type of reset that the Charge Point should perform. + * + * @return the {@link ResetType}. + */ + public ResetType getType() { + return type; + } + + /** + * Required. This contains the type of reset that the Charge Point should perform. + * + * @param type the {@link ResetType}. + */ + @XmlElement + public void setType(ResetType type) { + this.type = type; + } + + /** + * This contains the type of reset that the Charge Point should perform. + * + * @return the {@link ResetType}. + */ + @Deprecated + public ResetType objType() { + return type; + } + + @Override + public boolean validate() { + return type != null; + } + + @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; + ResetRequest that = (ResetRequest) o; + return type == that.type; + } + + @Override + public int hashCode() { + return Objects.hash(type); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("type", type).add("isValid", validate()).toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/SampledValue.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/SampledValue.java index feaa18f29..f8cb90adb 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/SampledValue.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/SampledValue.java @@ -5,6 +5,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,343 +30,368 @@ import eu.chargetime.ocpp.model.Validatable; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.util.Objects; -/** Single sampled value in {@link MeterValue}. Each value can be accompanied by optional fields. */ +/** + * Single sampled value in {@link MeterValue}. Each value can be accompanied by optional fields. + */ @XmlRootElement @XmlType(propOrder = {"value", "context", "format", "measurand", "phase", "location", "unit"}) public class SampledValue implements Validatable { - private static final Logger logger = LoggerFactory.getLogger(SampledValue.class); - - private String value; - private String context; - private ValueFormat format; - private String measurand; - private String phase; - private Location location; - private String unit; - - public SampledValue() { - try { - setContext("Sample.Periodic"); - setFormat(ValueFormat.Raw); - setMeasurand("Energy.Active.Import.Register"); - setLocation(Location.Outlet); - setUnit("Wh"); - } catch (PropertyConstraintException ex) { - logger.error("constructor of SampledValue failed", ex); + private static final Logger logger = LoggerFactory.getLogger(SampledValue.class); + + private String value; + private String context; + private ValueFormat format; + private String measurand; + private String phase; + private Location location; + private String unit; + + /** + * @deprecated use {@link #SampledValue(String)} to be sure to set required fields + */ + @Deprecated + public SampledValue() { + try { + setContext("Sample.Periodic"); + setFormat(ValueFormat.Raw); + setMeasurand("Energy.Active.Import.Register"); + setLocation(Location.Outlet); + setUnit("Wh"); + } catch (PropertyConstraintException ex) { + logger.error("constructor of SampledValue failed", ex); + } + } + + /** + * Handle required fields. + * + * @param value String, the value, see {@link #setValue(String)} + */ + public SampledValue(String value) { + try { + setValue(value); + setContext("Sample.Periodic"); + setFormat(ValueFormat.Raw); + setMeasurand("Energy.Active.Import.Register"); + setLocation(Location.Outlet); + setUnit("Wh"); + } catch (PropertyConstraintException ex) { + logger.error("constructor of SampledValue failed", ex); + } + } + + @Override + public boolean validate() { + return this.value != null; + } + + /** + * Value as a Raw (@code decimal) number or {@code SignedData}. Field Type is String to allow for + * digitally signed data readings. Decimal numeric values are also acceptable to allow fractional + * values for measurands such as Temperature and Current. + * + * @return String, the value. + */ + public String getValue() { + return value; + } + + /** + * Required. Value as a {@code Raw} (decimal) number or {@code SignedData}. Field Type is String + * to allow for digitally signed data readings. Decimal numeric values are also acceptable to + * allow fractional values for measurands such as Temperature and Current. + * + * @param value String, the value. + */ + @XmlElement + public void setValue(String value) { + this.value = value; + } + + /** + * Type of detail value: start, end or sample. + * + * @return enum value for context. + */ + public String getContext() { + return context; + } + + /** + * Optional. Type of detail value: start, end or sample. Default = {@code Sample.Periodic} + * + *

Enum value with accepted values: {@code Interruption.Begin}, {@code Interruption.End}, + * {@code Other}, {@code Sample.Clock}, {@code Sample.Periodic}, {@code Transaction.Begin}, {@code + * Transaction.End}, {@code Trigger} + * + * @param context String, see description for accepted values. + */ + // TODO: Change to enum, solve format issue and change exception message. + @XmlElement + public void setContext(String context) { + if (!isValidContext(context)) { + throw new PropertyConstraintException(context, "context is not properly defined"); + } + + this.context = context; + } + + private boolean isValidContext(String context) { + String[] readingContext = { + "Interruption.Begin", + "Interruption.End", + "Other", + "Sample.Clock", + "Sample.Periodic", + "Transaction.Begin", + "Transaction.End", + "Trigger" + }; + return ModelUtil.isAmong(context, readingContext); + } + + /** + * Raw or signed data. + * + * @return the {@link ValueFormat}. + */ + public ValueFormat getFormat() { + return format; + } + + /** + * Optional. Raw or signed data. Default = {@code Raw}. + * + * @param format the {@link ValueFormat}. + */ + @XmlElement + public void setFormat(ValueFormat format) { + this.format = format; } - } - - @Override - public boolean validate() { - return this.value != null; - } - - /** - * Value as a Raw (@code decimal) number or {@code SignedData}. Field Type is String to allow for - * digitally signed data readings. Decimal numeric values are also acceptable to allow fractional - * values for measurands such as Temperature and Current. - * - * @return String, the value. - */ - public String getValue() { - return value; - } - - /** - * Required. Value as a {@code Raw} (decimal) number or {@code SignedData}. Field Type is String - * to allow for digitally signed data readings. Decimal numeric values are also acceptable to - * allow fractional values for measurands such as Temperature and Current. - * - * @param value String, the value. - */ - @XmlElement - public void setValue(String value) { - this.value = value; - } - - /** - * Type of detail value: start, end or sample. - * - * @return enum value for context. - */ - public String getContext() { - return context; - } - - /** - * Optional. Type of detail value: start, end or sample. Default = {@code Sample.Periodic} - * - *

Enum value with accepted values: {@code Interruption.Begin}, {@code Interruption.End}, - * {@code Other}, {@code Sample.Clock}, {@code Sample.Periodic}, {@code Transaction.Begin}, {@code - * Transaction.End}, {@code Trigger} - * - * @param context String, see description for accepted values. - */ - // TODO: Change to enum, solve format issue and change exception message. - @XmlElement - public void setContext(String context) { - if (!isValidContext(context)) { - throw new PropertyConstraintException(context, "context is not properly defined"); + + /** + * Raw or signed data. + * + * @return the {@link ValueFormat}. + */ + @Deprecated + public ValueFormat objFormat() { + return format; + } + + /** + * Type of measurement. + * + * @return enum value of measurand. + */ + public String getMeasurand() { + return measurand; + } + + /** + * Optional. Type of measurement. Default = {@code Energy.Active.Import.Register}. + * + *

Enum value with accepted values: {@code Current.Export}, {@code Current.Import}, {@code + * Current.Offered}, {@code Energy.Active.Export.Register}, {@code Energy.Active.Import.Register}, + * {@code Energy.Reactive.Export.Register}, {@code Energy.Reactive.Import.Register}, {@code + * Energy.Active.Export.Interval}, {@code Energy.Active.Import.Interval}, {@code + * Energy.Reactive.Export.Interval}, {@code Energy.Reactive.Import.Interval}, {@code Frequency}, + * {@code Power.Active.Export}, {@code Power.Active.Import}, {@code Power.Factor}, {@code + * Power.Offered}, {@code Power.Reactive.Export}, {@code Power.Reactive.Import}, {@code RPM}, + * {@code SoC}, {@code Temperature}, {@code Voltage} + * + * @param measurand String, enum value of measurand. + */ + // TODO: Change to enum, solve format issue and change exception message. + @XmlElement + public void setMeasurand(String measurand) { + if (!isValidMeasurand(measurand)) + throw new PropertyConstraintException(measurand, "measurand value is not properly defined"); + + this.measurand = measurand; + } + + private boolean isValidMeasurand(String measurand) { + String[] measurandValues = { + "Current.Export", + "Current.Import", + "Current.Offered", + "Energy.Active.Export.Register", + "Energy.Active.Import.Register", + "Energy.Reactive.Export.Register", + "Energy.Reactive.Import.Register", + "Energy.Active.Export.Interval", + "Energy.Active.Import.Interval", + "Energy.Reactive.Export.Interval", + "Energy.Reactive.Import.Interval", + "Frequency", + "Power.Active.Export", + "Power.Active.Import", + "Power.Factor", + "Power.Offered", + "Power.Reactive.Export", + "Power.Reactive.Import", + "RPM", + "SoC", + "Temperature", + "Voltage" + }; + return ModelUtil.isAmong(measurand, measurandValues); + } + + /** + * Indicates how the measured value is to be interpreted. For instance between L1 and neutral + * (L1-N). + * + * @return enum value of phase. + */ + public String getPhase() { + return phase; + } + + /** + * Optional. Indicates how the measured value is to be interpreted. For instance between L1 and + * neutral (L1-N). Please note that not all values of phase are applicable to all Measurands. When + * phase is absent, the measured value is interpreted as an overall value. + * + *

Enum value with accepted values: {@code L1}, {@code L2}, {@code L3}, {@code N}, {@code + * L1-N}, {@code L2-N}, {@code L3-N}, {@code L1-L2}, {@code L2-L3}, {@code L3-L1} + * + * @param phase String, enum value of phase. + */ + // TODO: Change to enum, solve format issue and change exception message. + @XmlElement + public void setPhase(String phase) { + if (!isValidPhase(phase)) { + throw new PropertyConstraintException(phase, "phase is not properly defined"); + } + + this.phase = phase; + } + + private boolean isValidPhase(String phase) { + return ModelUtil.isAmong( + phase, "L1", "L2", "L3", "N", "L1-N", "L2-N", "L3-N", "L1-L2", "L2-L3", "L3-L1"); } - this.context = context; - } - - private boolean isValidContext(String context) { - String[] readingContext = { - "Interruption.Begin", - "Interruption.End", - "Other", - "Sample.Clock", - "Sample.Periodic", - "Transaction.Begin", - "Transaction.End", - "Trigger" - }; - return ModelUtil.isAmong(context, readingContext); - } - - /** - * Raw or signed data. - * - * @return the {@link ValueFormat}. - */ - public ValueFormat getFormat() { - return format; - } - - /** - * Raw or signed data. - * - * @return the {@link ValueFormat}. - */ - @Deprecated - public ValueFormat objFormat() { - return format; - } - - /** - * Optional. Raw or signed data. Default = {@code Raw}. - * - * @param format the {@link ValueFormat}. - */ - @XmlElement - public void setFormat(ValueFormat format) { - this.format = format; - } - - /** - * Type of measurement. - * - * @return enum value of measurand. - */ - public String getMeasurand() { - return measurand; - } - - /** - * Optional. Type of measurement. Default = {@code Energy.Active.Import.Register}. - * - *

Enum value with accepted values: {@code Current.Export}, {@code Current.Import}, {@code - * Current.Offered}, {@code Energy.Active.Export.Register}, {@code Energy.Active.Import.Register}, - * {@code Energy.Reactive.Export.Register}, {@code Energy.Reactive.Import.Register}, {@code - * Energy.Active.Export.Interval}, {@code Energy.Active.Import.Interval}, {@code - * Energy.Reactive.Export.Interval}, {@code Energy.Reactive.Import.Interval}, {@code Frequency}, - * {@code Power.Active.Export}, {@code Power.Active.Import}, {@code Power.Factor}, {@code - * Power.Offered}, {@code Power.Reactive.Export}, {@code Power.Reactive.Import}, {@code RPM}, - * {@code SoC}, {@code Temperature}, {@code Voltage} - * - * @param measurand String, enum value of measurand. - */ - // TODO: Change to enum, solve format issue and change exception message. - @XmlElement - public void setMeasurand(String measurand) { - if (!isValidMeasurand(measurand)) - throw new PropertyConstraintException(measurand, "measurand value is not properly defined"); - - this.measurand = measurand; - } - - private boolean isValidMeasurand(String measurand) { - String[] measurandValues = { - "Current.Export", - "Current.Import", - "Current.Offered", - "Energy.Active.Export.Register", - "Energy.Active.Import.Register", - "Energy.Reactive.Export.Register", - "Energy.Reactive.Import.Register", - "Energy.Active.Export.Interval", - "Energy.Active.Import.Interval", - "Energy.Reactive.Export.Interval", - "Energy.Reactive.Import.Interval", - "Frequency", - "Power.Active.Export", - "Power.Active.Import", - "Power.Factor", - "Power.Offered", - "Power.Reactive.Export", - "Power.Reactive.Import", - "RPM", - "SoC", - "Temperature", - "Voltage" - }; - return ModelUtil.isAmong(measurand, measurandValues); - } - - /** - * Indicates how the measured value is to be interpreted. For instance between L1 and neutral - * (L1-N). - * - * @return enum value of phase. - */ - public String getPhase() { - return phase; - } - - /** - * Optional. Indicates how the measured value is to be interpreted. For instance between L1 and - * neutral (L1-N). Please note that not all values of phase are applicable to all Measurands. When - * phase is absent, the measured value is interpreted as an overall value. - * - *

Enum value with accepted values: {@code L1}, {@code L2}, {@code L3}, {@code N}, {@code - * L1-N}, {@code L2-N}, {@code L3-N}, {@code L1-L2}, {@code L2-L3}, {@code L3-L1} - * - * @param phase String, enum value of phase. - */ - // TODO: Change to enum, solve format issue and change exception message. - @XmlElement - public void setPhase(String phase) { - if (!isValidPhase(phase)) { - throw new PropertyConstraintException(phase, "phase is not properly defined"); + /** + * Location of measurement. + * + * @return the {@link Location}. + */ + public Location getLocation() { + return location; } - this.phase = phase; - } - - private boolean isValidPhase(String phase) { - return ModelUtil.isAmong( - phase, "L1", "L2", "L3", "N", "L1-N", "L2-N", "L3-N", "L1-L2", "L2-L3", "L3-L1"); - } - - /** - * Location of measurement. - * - * @return the {@link Location}. - */ - public Location getLocation() { - return location; - } - - /** - * Location of measurement. - * - * @return the {@link Location}. - */ - @Deprecated - public Location objLocation() { - return location; - } - - /** - * Optional. Location of measurement. Default={@code Outlet} - * - * @param location the {@link Location}. - */ - @XmlElement - public void setLocation(Location location) { - this.location = location; - } - - /** - * Unit of the value. - * - * @return Unit of Measure. - */ - public String getUnit() { - return unit; - } - - /** - * Optional. Unit of the value. Default = {@code Wh} if the (default) measurand is an {@code - * Energy} type. - * - *

Enum value with accepted values: {@code Wh}, {@code kWh}, {@code varh}, {@code kvarh}, - * {@code W}, {@code kW}, {@code VA}, {@code kVA}, {@code var}, {@code kvar}, {@code A}, {@code - * V}, {@code Celsius}, {@code Fahrenheit}, {@code K}, {@code Percent} - * - * @param unit String, enum value, Unit of Measure. - */ - // TODO: Change to enum, solve format issue and change exception message. - @XmlElement - public void setUnit(String unit) { - if (!isValidUnit(unit)) { - throw new PropertyConstraintException(unit, "unit is not properly defined"); + /** + * Optional. Location of measurement. Default={@code Outlet} + * + * @param location the {@link Location}. + */ + @XmlElement + public void setLocation(Location location) { + this.location = location; } - this.unit = unit; - } - - private boolean isValidUnit(String unit) { - String[] unitOfMeasure = { - "Wh", - "kWh", - "varh", - "kvarh", - "W", - "kW", - "VA", - "kVA", - "var", - "kvar", - "A", - "V", - "Celsius", - "Fahrenheit", - "K", - "Percent" - }; - return ModelUtil.isAmong(unit, unitOfMeasure); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SampledValue that = (SampledValue) o; - return Objects.equals(value, that.value) - && Objects.equals(context, that.context) - && format == that.format - && Objects.equals(measurand, that.measurand) - && Objects.equals(phase, that.phase) - && location == that.location - && Objects.equals(unit, that.unit); - } - - @Override - public int hashCode() { - return Objects.hash(value, context, format, measurand, phase, location, unit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("value", value) - .add("context", context) - .add("format", format) - .add("measurand", measurand) - .add("phase", phase) - .add("location", location) - .add("unit", unit) - .add("isValid", validate()) - .toString(); - } + /** + * Location of measurement. + * + * @return the {@link Location}. + */ + @Deprecated + public Location objLocation() { + return location; + } + + /** + * Unit of the value. + * + * @return Unit of Measure. + */ + public String getUnit() { + return unit; + } + + /** + * Optional. Unit of the value. Default = {@code Wh} if the (default) measurand is an {@code + * Energy} type. + * + *

Enum value with accepted values: {@code Wh}, {@code kWh}, {@code varh}, {@code kvarh}, + * {@code W}, {@code kW}, {@code VA}, {@code kVA}, {@code var}, {@code kvar}, {@code A}, {@code + * V}, {@code Celsius}, {@code Fahrenheit}, {@code K}, {@code Percent} + * + * @param unit String, enum value, Unit of Measure. + */ + // TODO: Change to enum, solve format issue and change exception message. + @XmlElement + public void setUnit(String unit) { + if (!isValidUnit(unit)) { + throw new PropertyConstraintException(unit, "unit is not properly defined"); + } + + this.unit = unit; + } + + private boolean isValidUnit(String unit) { + String[] unitOfMeasure = { + "Wh", + "kWh", + "varh", + "kvarh", + "W", + "kW", + "VA", + "kVA", + "var", + "kvar", + "A", + "V", + "Celsius", + "Fahrenheit", + "K", + "Percent" + }; + return ModelUtil.isAmong(unit, unitOfMeasure); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SampledValue that = (SampledValue) o; + return Objects.equals(value, that.value) + && Objects.equals(context, that.context) + && format == that.format + && Objects.equals(measurand, that.measurand) + && Objects.equals(phase, that.phase) + && location == that.location + && Objects.equals(unit, that.unit); + } + + @Override + public int hashCode() { + return Objects.hash(value, context, format, measurand, phase, location, unit); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("value", value) + .add("context", context) + .add("format", format) + .add("measurand", measurand) + .add("phase", phase) + .add("location", location) + .add("unit", unit) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionConfirmation.java index 3fb39aec6..22bde917e 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionConfirmation.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,10 +29,11 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Objects; /** * Sent by the Central System to the Charge Point in response to a {@link StartTransactionRequest}. @@ -39,75 +41,95 @@ @XmlRootElement(name = "startTransactionResponse") @XmlType(propOrder = {"transactionId", "idTagInfo"}) public class StartTransactionConfirmation implements Confirmation { - private IdTagInfo idTagInfo; - private Integer transactionId; - - @Override - public boolean validate() { - boolean valid = true; - if (valid &= idTagInfo != null) valid &= idTagInfo.validate(); - valid &= transactionId != null; - return valid; - } - - /** - * This contains information about authorization status, expiry and parent id. - * - * @return the {@link IdTagInfo}. - */ - public IdTagInfo getIdTagInfo() { - return idTagInfo; - } - - /** - * Required. This contains information about authorization status, expiry and parent id. - * - * @param idTagInfo the {@link IdTagInfo}. - */ - @XmlElement - public void setIdTagInfo(IdTagInfo idTagInfo) { - this.idTagInfo = idTagInfo; - } - - /** - * This contains the transaction id supplied by the Central System. - * - * @return transaction id. - */ - public Integer getTransactionId() { - return transactionId; - } - - /** - * Required. This contains the transaction id supplied by the Central System. - * - * @param transactionId integer, transaction. - */ - @XmlElement - public void setTransactionId(Integer transactionId) { - this.transactionId = transactionId; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - StartTransactionConfirmation that = (StartTransactionConfirmation) o; - return Objects.equals(idTagInfo, that.idTagInfo) - && Objects.equals(transactionId, that.transactionId); - } - - @Override - public int hashCode() { - return Objects.hash(idTagInfo, transactionId); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("idTagInfo", idTagInfo) - .add("transactionId", transactionId) - .add("isValid", validate()) - .toString(); - } + + private IdTagInfo idTagInfo; + private Integer transactionId; + + /** + * @deprecated use {@link #StartTransactionConfirmation(IdTagInfo, Integer)} to be sure to set required fields + */ + @Deprecated + public StartTransactionConfirmation() { + + } + + /** + * Handle required fields. + * + * @param idTagInfo the {@link IdTagInfo}, see {@link #setIdTagInfo(IdTagInfo)} + * @param transactionId integer, transaction, see {@link #setTransactionId(Integer)} + */ + public StartTransactionConfirmation(IdTagInfo idTagInfo, Integer transactionId) { + setIdTagInfo(idTagInfo); + setTransactionId(transactionId); + } + + @Override + public boolean validate() { + boolean valid = true; + if (valid &= idTagInfo != null) valid &= idTagInfo.validate(); + valid &= transactionId != null; + return valid; + } + + /** + * This contains information about authorization status, expiry and parent id. + * + * @return the {@link IdTagInfo}. + */ + public IdTagInfo getIdTagInfo() { + return idTagInfo; + } + + /** + * Required. This contains information about authorization status, expiry and parent id. + * + * @param idTagInfo the {@link IdTagInfo}. + */ + @XmlElement + public void setIdTagInfo(IdTagInfo idTagInfo) { + this.idTagInfo = idTagInfo; + } + + /** + * This contains the transaction id supplied by the Central System. + * + * @return transaction id. + */ + public Integer getTransactionId() { + return transactionId; + } + + /** + * Required. This contains the transaction id supplied by the Central System. + * + * @param transactionId integer, transaction. + */ + @XmlElement + public void setTransactionId(Integer transactionId) { + this.transactionId = transactionId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + StartTransactionConfirmation that = (StartTransactionConfirmation) o; + return Objects.equals(idTagInfo, that.idTagInfo) + && Objects.equals(transactionId, that.transactionId); + } + + @Override + public int hashCode() { + return Objects.hash(idTagInfo, transactionId); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("idTagInfo", idTagInfo) + .add("transactionId", transactionId) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionRequest.java index 0d9e69c57..dceb6385e 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StartTransactionRequest.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,181 +31,207 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Objects; -/** Sent by the Charge Point to the Central System. */ +/** + * Sent by the Charge Point to the Central System. + */ @XmlRootElement @XmlType(propOrder = {"connectorId", "idTag", "timestamp", "meterStart", "reservationId"}) public class StartTransactionRequest implements Request { - private static final int IDTAG_MAX_LENGTH = 20; - private static final String IDTAG_ERROR_MESSAGE = - "Exceeded limit of " + IDTAG_MAX_LENGTH + " chars"; - - private Integer connectorId; - private String idTag; - private Integer meterStart; - private Integer reservationId; - private Calendar timestamp; - - @Override - public boolean validate() { - boolean valid = connectorId != null && connectorId > 0; - valid &= ModelUtil.validate(idTag, 20); - valid &= meterStart != null; - valid &= timestamp != null; - return valid; - } - - /** - * This identifies which connector of the Charge Point is used. - * - * @return connector. - */ - public Integer getConnectorId() { - return connectorId; - } - - /** - * Required. This identifies which connector of the Charge Point is used. - * - * @param connectorId integer. value > 0 - */ - @XmlElement - public void setConnectorId(Integer connectorId) { - if (connectorId == null || connectorId <= 0) { - throw new PropertyConstraintException(connectorId, "connectorId must be > 0"); - } - - this.connectorId = connectorId; - } - - /** - * This contains the identifier for which a transaction has to be started. - * - * @return the IdToken. - */ - public String getIdTag() { - return idTag; - } - - /** - * Required. This contains the identifier for which a transaction has to be started. - * - * @param idTag a String with max length 20 - */ - @XmlElement - public void setIdTag(String idTag) { - if (!ModelUtil.validate(idTag, IDTAG_MAX_LENGTH)) { - throw new PropertyConstraintException(idTag.length(), IDTAG_ERROR_MESSAGE); - } - - this.idTag = idTag; - } - - /** - * This contains the meter value in Wh for the connector at start of the transaction. - * - * @return Wh at start. - */ - public Integer getMeterStart() { - return meterStart; - } - - /** - * Required. This contains the meter value in Wh for the connector at start of the transaction. - * - * @param meterStart integer, Wh at start. - */ - @XmlElement - public void setMeterStart(Integer meterStart) { - this.meterStart = meterStart; - } - - /** - * This contains the id of the reservation that terminates as a result of this transaction. - * - * @return reservation. - */ - public Integer getReservationId() { - return reservationId; - } - - /** - * Optional. This contains the id of the reservation that terminates as a result of this - * transaction. - * - * @param reservationId integer, reservation. - */ - @XmlElement - public void setReservationId(Integer reservationId) { - this.reservationId = reservationId; - } - - /** - * This contains the date and time on which the transaction is started. - * - * @return start time. - */ - public Calendar getTimestamp() { - return timestamp; - } - - /** - * This contains the date and time on which the transaction is started. - * - * @return start time. - */ - @Deprecated - public Calendar objTimestamp() { - return timestamp; - } - - /** - * Required. This contains the date and time on which the transaction is started. - * - * @param timestamp Calendar, start time. - */ - @XmlElement - public void setTimestamp(Calendar timestamp) { - this.timestamp = timestamp; - } - - @Override - public boolean transactionRelated() { - return true; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - StartTransactionRequest that = (StartTransactionRequest) o; - return Objects.equals(connectorId, that.connectorId) - && Objects.equals(idTag, that.idTag) - && Objects.equals(meterStart, that.meterStart) - && Objects.equals(reservationId, that.reservationId) - && Objects.equals(timestamp, that.timestamp); - } - - @Override - public int hashCode() { - return Objects.hash(connectorId, idTag, meterStart, reservationId, timestamp); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("connectorId", connectorId) - .add("idTag", idTag) - .add("meterStart", meterStart) - .add("reservationId", reservationId) - .add("timestamp", timestamp) - .add("isValid", validate()) - .toString(); - } + private static final int IDTAG_MAX_LENGTH = 20; + private static final String IDTAG_ERROR_MESSAGE = + "Exceeded limit of " + IDTAG_MAX_LENGTH + " chars"; + + private Integer connectorId; + private String idTag; + private Integer meterStart; + private Integer reservationId; + private ZonedDateTime timestamp; + + /** + * @deprecated use {@link #StartTransactionRequest(Integer, String, Integer, ZonedDateTime)} to be sure to set required fields + */ + @Deprecated + public StartTransactionRequest() { + + } + + /** + * Handle required fields. + * + * @param connectorId integer. value > 0, see {@link #setConnectorId(Integer)} + * @param idTag a String with max length 20, see {@link #setIdTag(String)} + * @param meterStart integer, Wh at start, see {@link #setMeterStart(Integer)} + * @param timestamp ZonedDateTime, start time, see {@link #setTimestamp(ZonedDateTime)} + */ + public StartTransactionRequest(Integer connectorId, String idTag, Integer meterStart, ZonedDateTime timestamp) { + setConnectorId(connectorId); + setIdTag(idTag); + setMeterStart(meterStart); + setTimestamp(timestamp); + } + + @Override + public boolean validate() { + boolean valid = connectorId != null && connectorId > 0; + valid &= ModelUtil.validate(idTag, 20); + valid &= meterStart != null; + valid &= timestamp != null; + return valid; + } + + /** + * This identifies which connector of the Charge Point is used. + * + * @return connector. + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Required. This identifies which connector of the Charge Point is used. + * + * @param connectorId integer. value > 0 + */ + @XmlElement + public void setConnectorId(Integer connectorId) { + if (connectorId == null || connectorId <= 0) { + throw new PropertyConstraintException(connectorId, "connectorId must be > 0"); + } + + this.connectorId = connectorId; + } + + /** + * This contains the identifier for which a transaction has to be started. + * + * @return the IdToken. + */ + public String getIdTag() { + return idTag; + } + + /** + * Required. This contains the identifier for which a transaction has to be started. + * + * @param idTag a String with max length 20 + */ + @XmlElement + public void setIdTag(String idTag) { + if (!ModelUtil.validate(idTag, IDTAG_MAX_LENGTH)) { + throw new PropertyConstraintException(idTag.length(), IDTAG_ERROR_MESSAGE); + } + + this.idTag = idTag; + } + + /** + * This contains the meter value in Wh for the connector at start of the transaction. + * + * @return Wh at start. + */ + public Integer getMeterStart() { + return meterStart; + } + + /** + * Required. This contains the meter value in Wh for the connector at start of the transaction. + * + * @param meterStart integer, Wh at start. + */ + @XmlElement + public void setMeterStart(Integer meterStart) { + this.meterStart = meterStart; + } + + /** + * This contains the id of the reservation that terminates as a result of this transaction. + * + * @return reservation. + */ + public Integer getReservationId() { + return reservationId; + } + + /** + * Optional. This contains the id of the reservation that terminates as a result of this + * transaction. + * + * @param reservationId integer, reservation. + */ + @XmlElement + public void setReservationId(Integer reservationId) { + this.reservationId = reservationId; + } + + /** + * This contains the date and time on which the transaction is started. + * + * @return start time. + */ + public ZonedDateTime getTimestamp() { + return timestamp; + } + + /** + * Required. This contains the date and time on which the transaction is started. + * + * @param timestamp ZonedDateTime, start time. + */ + @XmlElement + public void setTimestamp(ZonedDateTime timestamp) { + this.timestamp = timestamp; + } + + /** + * This contains the date and time on which the transaction is started. + * + * @return start time. + */ + @Deprecated + public ZonedDateTime objTimestamp() { + return timestamp; + } + + @Override + public boolean transactionRelated() { + return true; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + StartTransactionRequest that = (StartTransactionRequest) o; + return Objects.equals(connectorId, that.connectorId) + && Objects.equals(idTag, that.idTag) + && Objects.equals(meterStart, that.meterStart) + && Objects.equals(reservationId, that.reservationId) + && Objects.equals(timestamp, that.timestamp); + } + + @Override + public int hashCode() { + return Objects.hash(connectorId, idTag, meterStart, reservationId, timestamp); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("connectorId", connectorId) + .add("idTag", idTag) + .add("meterStart", meterStart) + .add("reservationId", reservationId) + .add("timestamp", timestamp) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StatusNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StatusNotificationRequest.java index 4d783a5fb..f62a902d4 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StatusNotificationRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StatusNotificationRequest.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,270 +31,294 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Objects; -/** Sent by the Charge Point to the Central System. */ +/** + * Sent by the Charge Point to the Central System. + */ @XmlRootElement @XmlType( - propOrder = { - "connectorId", - "status", - "errorCode", - "info", - "timestamp", - "vendorId", - "vendorErrorCode" - }) + propOrder = { + "connectorId", + "status", + "errorCode", + "info", + "timestamp", + "vendorId", + "vendorErrorCode" + }) public class StatusNotificationRequest implements Request { - private static final String ERROR_MESSAGE = "Exceeds limit of %s chars"; - - private Integer connectorId; - private ChargePointErrorCode errorCode; - private String info; - private ChargePointStatus status; - private Calendar timestamp; - private String vendorId; - private String vendorErrorCode; - - @Override - public boolean validate() { - boolean valid = isValidConnectorId(connectorId); - valid &= errorCode != null; - valid &= status != null; - return valid; - } - - /** - * The id of the connector for which the status is reported. Id '0' (zero) is used if the status - * is for the Charge Point main controller. - * - * @return connector id. 0 = main controller. - */ - public Integer getConnectorId() { - return connectorId; - } - - /** - * Required. The id of the connector for which the status is reported. Id '0' (zero) is used if - * the status is for the Charge Point main controller. - * - * @param connectorId integer, connector id. 0 = main controller. - */ - @XmlElement - public void setConnectorId(Integer connectorId) { - if (!isValidConnectorId(connectorId)) { - throw new PropertyConstraintException(connectorId, "connectorId >= 0"); + private static final String ERROR_MESSAGE = "Exceeds limit of %s chars"; + + private Integer connectorId; + private ChargePointErrorCode errorCode; + private String info; + private ChargePointStatus status; + private ZonedDateTime timestamp; + private String vendorId; + private String vendorErrorCode; + + /** + * @deprecated use {@link #StatusNotificationRequest(Integer, ChargePointErrorCode, ChargePointStatus)} to be sure to set required fields + */ + @Deprecated + public StatusNotificationRequest() { + + } + + /** + * Handle required fields. + * + * @param connectorId integer, connector id. 0 = main controller, see {@link #setConnectorId(Integer)} + * @param errorCode the {@link ChargePointErrorCode}, see {@link #setErrorCode(ChargePointErrorCode)} + * @param status the {@link ChargePointStatus}, see {@link #setStatus(ChargePointStatus)} + */ + public StatusNotificationRequest(Integer connectorId, ChargePointErrorCode errorCode, ChargePointStatus status) { + setConnectorId(connectorId); + setErrorCode(errorCode); + setStatus(status); + } + + private static String createErrorMessage(int maxLength) { + return String.format(ERROR_MESSAGE, maxLength); + } + + @Override + public boolean validate() { + boolean valid = isValidConnectorId(connectorId); + valid &= errorCode != null; + valid &= status != null; + return valid; + } + + /** + * The id of the connector for which the status is reported. Id '0' (zero) is used if the status + * is for the Charge Point main controller. + * + * @return connector id. 0 = main controller. + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Required. The id of the connector for which the status is reported. Id '0' (zero) is used if + * the status is for the Charge Point main controller. + * + * @param connectorId integer, connector id. 0 = main controller. + */ + @XmlElement + public void setConnectorId(Integer connectorId) { + if (!isValidConnectorId(connectorId)) { + throw new PropertyConstraintException(connectorId, "connectorId >= 0"); + } + + this.connectorId = connectorId; + } + + private boolean isValidConnectorId(Integer connectorId) { + return connectorId != null && connectorId >= 0; + } + + /** + * This contains the error code reported by the Charge Point. + * + * @return the {@link ChargePointErrorCode}. + */ + public ChargePointErrorCode getErrorCode() { + return errorCode; + } + + /** + * Required. This contains the error code reported by the Charge Point. + * + * @param errorCode the {@link ChargePointErrorCode}. + */ + @XmlElement + public void setErrorCode(ChargePointErrorCode errorCode) { + this.errorCode = errorCode; + } + + /** + * This contains the error code reported by the Charge Point. + * + * @return the {@link ChargePointErrorCode}. + */ + @Deprecated + public ChargePointErrorCode objErrorCode() { + return errorCode; + } + + /** + * Additional free format information related to the error. + * + * @return Additional information. + */ + public String getInfo() { + return info; + } + + /** + * Optional. Additional free format information related to the error. + * + * @param info String, max 50 characters, case insensitive. + */ + @XmlElement + public void setInfo(String info) { + if (!ModelUtil.validate(info, 50)) { + throw new PropertyConstraintException(info.length(), createErrorMessage(50)); + } + + this.info = info; + } + + /** + * This contains the current status of the Charge Point. + * + * @return the {@link ChargePointStatus}. + */ + public ChargePointStatus getStatus() { + return status; + } + + /** + * Required. This contains the current status of the Charge Point. + * + * @param status the {@link ChargePointStatus}. + */ + @XmlElement + public void setStatus(ChargePointStatus status) { + this.status = status; + } + + /** + * This contains the current status of the Charge Point. + * + * @return the {@link ChargePointStatus}. + */ + @Deprecated + public ChargePointStatus objStatus() { + return status; + } + + /** + * The time for which the status is reported. If absent time of receipt of the message will be + * assumed. + * + * @return status time. + */ + public ZonedDateTime getTimestamp() { + return timestamp; + } + + /** + * Optional. The time for which the status is reported. If absent time of receipt of the message + * will be assumed. + * + * @param timestamp ZonedDateTime, status time. + */ + @XmlElement + public void setTimestamp(ZonedDateTime timestamp) { + this.timestamp = timestamp; } - this.connectorId = connectorId; - } - - private boolean isValidConnectorId(Integer connectorId) { - return connectorId != null && connectorId >= 0; - } - - /** - * This contains the error code reported by the Charge Point. - * - * @return the {@link ChargePointErrorCode}. - */ - public ChargePointErrorCode getErrorCode() { - return errorCode; - } - - /** - * This contains the error code reported by the Charge Point. - * - * @return the {@link ChargePointErrorCode}. - */ - @Deprecated - public ChargePointErrorCode objErrorCode() { - return errorCode; - } - - /** - * Required. This contains the error code reported by the Charge Point. - * - * @param errorCode the {@link ChargePointErrorCode}. - */ - @XmlElement - public void setErrorCode(ChargePointErrorCode errorCode) { - this.errorCode = errorCode; - } - - /** - * Additional free format information related to the error. - * - * @return Additional information. - */ - public String getInfo() { - return info; - } - - /** - * Optional. Additional free format information related to the error. - * - * @param info String, max 50 characters, case insensitive. - */ - @XmlElement - public void setInfo(String info) { - if (!ModelUtil.validate(info, 50)) { - throw new PropertyConstraintException(info.length(), createErrorMessage(50)); + /** + * The time for which the status is reported. If absent time of receipt of the message will be + * assumed. + * + * @return status time. + */ + @Deprecated + public ZonedDateTime objTimestamp() { + return timestamp; } - this.info = info; - } - - /** - * This contains the current status of the Charge Point. - * - * @return the {@link ChargePointStatus}. - */ - public ChargePointStatus getStatus() { - return status; - } - - /** - * This contains the current status of the Charge Point. - * - * @return the {@link ChargePointStatus}. - */ - @Deprecated - public ChargePointStatus objStatus() { - return status; - } - - /** - * Required. This contains the current status of the Charge Point. - * - * @param status the {@link ChargePointStatus}. - */ - @XmlElement - public void setStatus(ChargePointStatus status) { - this.status = status; - } - - /** - * The time for which the status is reported. If absent time of receipt of the message will be - * assumed. - * - * @return status time. - */ - public Calendar getTimestamp() { - return timestamp; - } - - /** - * The time for which the status is reported. If absent time of receipt of the message will be - * assumed. - * - * @return status time. - */ - @Deprecated - public Calendar objTimestamp() { - return timestamp; - } - - /** - * Optional. The time for which the status is reported. If absent time of receipt of the message - * will be assumed. - * - * @param timestamp Calendar, status time. - */ - @XmlElement - public void setTimestamp(Calendar timestamp) { - this.timestamp = timestamp; - } - - /** - * This identifies the vendor-specific implementation. - * - * @return Identification of the vendor. - */ - public String getVendorId() { - return vendorId; - } - - /** - * Optional. This identifies the vendor-specific implementation. - * - * @param vendorId String, max 255 characters, case insensitive. - */ - @XmlElement - public void setVendorId(String vendorId) { - if (!ModelUtil.validate(vendorId, 255)) { - throw new PropertyConstraintException(vendorId.length(), createErrorMessage(255)); + /** + * This identifies the vendor-specific implementation. + * + * @return Identification of the vendor. + */ + public String getVendorId() { + return vendorId; } - this.vendorId = vendorId; - } - - /** - * This contains the vendor-specific error code. - * - * @return Custom vendor error code. - */ - public String getVendorErrorCode() { - return vendorErrorCode; - } - - /** - * Optional. This contains the vendor-specific error code. - * - * @param vendorErrorCode String, max 50 characters, case insensitive. - */ - @XmlElement - public void setVendorErrorCode(String vendorErrorCode) { - if (!ModelUtil.validate(vendorErrorCode, 50)) - throw new PropertyConstraintException(vendorErrorCode.length(), createErrorMessage(50)); - - this.vendorErrorCode = vendorErrorCode; - } - - @Override - public boolean transactionRelated() { - return false; - } - - private static String createErrorMessage(int maxLength) { - return String.format(ERROR_MESSAGE, maxLength); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - StatusNotificationRequest that = (StatusNotificationRequest) o; - return Objects.equals(connectorId, that.connectorId) - && errorCode == that.errorCode - && Objects.equals(info, that.info) - && status == that.status - && Objects.equals(timestamp, that.timestamp) - && Objects.equals(vendorId, that.vendorId) - && Objects.equals(vendorErrorCode, that.vendorErrorCode); - } - - @Override - public int hashCode() { - return Objects.hash(connectorId, errorCode, info, status, timestamp, vendorId, vendorErrorCode); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("connectorId", connectorId) - .add("errorCode", errorCode) - .add("info", info) - .add("status", status) - .add("timestamp", timestamp) - .add("vendorId", vendorId) - .add("vendorErrorCode", vendorErrorCode) - .add("isValid", validate()) - .toString(); - } + /** + * Optional. This identifies the vendor-specific implementation. + * + * @param vendorId String, max 255 characters, case insensitive. + */ + @XmlElement + public void setVendorId(String vendorId) { + if (!ModelUtil.validate(vendorId, 255)) { + throw new PropertyConstraintException(vendorId.length(), createErrorMessage(255)); + } + + this.vendorId = vendorId; + } + + /** + * This contains the vendor-specific error code. + * + * @return Custom vendor error code. + */ + public String getVendorErrorCode() { + return vendorErrorCode; + } + + /** + * Optional. This contains the vendor-specific error code. + * + * @param vendorErrorCode String, max 50 characters, case insensitive. + */ + @XmlElement + public void setVendorErrorCode(String vendorErrorCode) { + if (!ModelUtil.validate(vendorErrorCode, 50)) + throw new PropertyConstraintException(vendorErrorCode.length(), createErrorMessage(50)); + + this.vendorErrorCode = vendorErrorCode; + } + + @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; + StatusNotificationRequest that = (StatusNotificationRequest) o; + return Objects.equals(connectorId, that.connectorId) + && errorCode == that.errorCode + && Objects.equals(info, that.info) + && status == that.status + && Objects.equals(timestamp, that.timestamp) + && Objects.equals(vendorId, that.vendorId) + && Objects.equals(vendorErrorCode, that.vendorErrorCode); + } + + @Override + public int hashCode() { + return Objects.hash(connectorId, errorCode, info, status, timestamp, vendorId, vendorErrorCode); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("connectorId", connectorId) + .add("errorCode", errorCode) + .add("info", info) + .add("status", status) + .add("timestamp", timestamp) + .add("vendorId", vendorId) + .add("vendorErrorCode", vendorErrorCode) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StopTransactionRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StopTransactionRequest.java index f8e5fdae4..e7201a3a4 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StopTransactionRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StopTransactionRequest.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,214 +31,239 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Arrays; +import java.util.Objects; -/** Sent by the Charge Point to the Central System. */ +/** + * Sent by the Charge Point to the Central System. + */ @XmlRootElement @XmlType( - propOrder = {"transactionId", "idTag", "timestamp", "meterStop", "reason", "transactionData"}) + propOrder = {"transactionId", "idTag", "timestamp", "meterStop", "reason", "transactionData"}) public class StopTransactionRequest implements Request { - private String idTag; - private Integer meterStop; - private Calendar timestamp; - private Integer transactionId; - private Reason reason; - private MeterValue[] transactionData; - - @Override - public boolean validate() { - boolean valid = meterStop != null; - valid &= timestamp != null; - valid &= transactionId != null; - if (transactionData != null) { - for (MeterValue meterValue : transactionData) { - valid &= meterValue.validate(); - } - } - - return valid; - } - - /** - * This contains the identifier which requested to stop the charging. - * - * @return the IdToken. - */ - public String getIdTag() { - return idTag; - } - - /** - * Optional. This contains the identifier which requested to stop the charging. It is optional - * because a Charge Point may terminate charging without the presence of an idTag, e.g. in case of - * a reset. A Charge Point SHALL send the idTag if known. - * - * @param idTag a String with max length 20 - */ - @XmlElement - public void setIdTag(String idTag) { - if (!ModelUtil.validate(idTag, 20)) { - throw new PropertyConstraintException(idTag.length(), "Exceeded limit of 20 chars"); - } - - this.idTag = idTag; - } - - /** - * This contains the meter value in Wh for the connector at end of the transaction. - * - * @return meter value in Wh. - */ - public Integer getMeterStop() { - return meterStop; - } - - /** - * Required. This contains the meter value in Wh for the connector at end of the transaction. - * - * @param meterStop integer, meter value in Wh. - */ - @XmlElement - public void setMeterStop(Integer meterStop) { - this.meterStop = meterStop; - } - - /** - * This contains the date and time on which the transaction is stopped. - * - * @return stop time. - */ - public Calendar getTimestamp() { - return timestamp; - } - - /** - * This contains the date and time on which the transaction is stopped. - * - * @return stop time. - */ - @Deprecated - public Calendar objTimestamp() { - return timestamp; - } - - /** - * Required. This contains the date and time on which the transaction is stopped. - * - * @param timestamp Calendar, stop time. - */ - @XmlElement - public void setTimestamp(Calendar timestamp) { - this.timestamp = timestamp; - } - - /** - * This contains the transaction-id as received by the {@link StartTransactionConfirmation}. - * - * @return transaction id. - */ - public Integer getTransactionId() { - return transactionId; - } - - /** - * Required. This contains the transaction-id as received by the {@link - * StartTransactionConfirmation}. - * - * @param transactionId integer, transaction id. - */ - @XmlElement - public void setTransactionId(Integer transactionId) { - this.transactionId = transactionId; - } - - /** - * This contains the reason why the transaction was stopped. - * - * @return the {@link Reason}. - */ - public Reason getReason() { - return reason; - } - - /** - * This contains the reason why the transaction was stopped. - * - * @return the {@link Reason}. - */ - @Deprecated - public Reason objReason() { - return reason; - } - - /** - * Optional. This contains the reason why the transaction was stopped. MAY only be omitted when - * the {@link Reason} is "Local". - * - * @param reason the {@link Reason}. - */ - @XmlElement - public void setReason(Reason reason) { - this.reason = reason; - } - - /** - * This contains transaction usage details relevant for billing purposes. - * - * @return the {@link MeterValue}. - */ - public MeterValue[] getTransactionData() { - return transactionData; - } - - /** - * Optional. This contains transaction usage details relevant for billing purposes. - * - * @param transactionData the {@link MeterValue}. - */ - @XmlElement - public void setTransactionData(MeterValue[] transactionData) { - this.transactionData = transactionData; - } - - @Override - public boolean transactionRelated() { - return true; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - StopTransactionRequest that = (StopTransactionRequest) o; - return Objects.equals(idTag, that.idTag) - && Objects.equals(meterStop, that.meterStop) - && Objects.equals(timestamp, that.timestamp) - && Objects.equals(transactionId, that.transactionId) - && reason == that.reason - && Arrays.equals(transactionData, that.transactionData); - } - - @Override - public int hashCode() { - return Objects.hash(idTag, meterStop, timestamp, transactionId, reason, transactionData); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("idTag", idTag) - .add("meterStop", meterStop) - .add("timestamp", timestamp) - .add("transactionId", transactionId) - .add("reason", reason) - .add("transactionData", transactionData) - .add("isValid", validate()) - .toString(); - } + + private String idTag; + private Integer meterStop; + private ZonedDateTime timestamp; + private Integer transactionId; + private Reason reason; + private MeterValue[] transactionData; + + /** + * @deprecated use {@link #StopTransactionRequest(Integer, ZonedDateTime, Integer)} to be sure to set required fields + */ + @Deprecated + public StopTransactionRequest() { + + } + + /** + * Handle required fields. + * + * @param meterStop integer, meter value in Wh, see {@link #setMeterStop(Integer)} + * @param timestamp ZonedDateTime, stop time, see {@link #setTimestamp(ZonedDateTime)} + * @param transactionId integer, transaction id, see {@link #setTransactionId(Integer)} + */ + public StopTransactionRequest(Integer meterStop, ZonedDateTime timestamp, Integer transactionId) { + setMeterStop(meterStop); + setTimestamp(timestamp); + setTransactionId(transactionId); + } + + @Override + public boolean validate() { + boolean valid = meterStop != null; + valid &= timestamp != null; + valid &= transactionId != null; + if (transactionData != null) { + for (MeterValue meterValue : transactionData) { + valid &= meterValue.validate(); + } + } + + return valid; + } + + /** + * This contains the identifier which requested to stop the charging. + * + * @return the IdToken. + */ + public String getIdTag() { + return idTag; + } + + /** + * Optional. This contains the identifier which requested to stop the charging. It is optional + * because a Charge Point may terminate charging without the presence of an idTag, e.g. in case of + * a reset. A Charge Point SHALL send the idTag if known. + * + * @param idTag a String with max length 20 + */ + @XmlElement + public void setIdTag(String idTag) { + if (!ModelUtil.validate(idTag, 20)) { + throw new PropertyConstraintException(idTag.length(), "Exceeded limit of 20 chars"); + } + + this.idTag = idTag; + } + + /** + * This contains the meter value in Wh for the connector at end of the transaction. + * + * @return meter value in Wh. + */ + public Integer getMeterStop() { + return meterStop; + } + + /** + * Required. This contains the meter value in Wh for the connector at end of the transaction. + * + * @param meterStop integer, meter value in Wh. + */ + @XmlElement + public void setMeterStop(Integer meterStop) { + this.meterStop = meterStop; + } + + /** + * This contains the date and time on which the transaction is stopped. + * + * @return stop time. + */ + public ZonedDateTime getTimestamp() { + return timestamp; + } + + /** + * Required. This contains the date and time on which the transaction is stopped. + * + * @param timestamp ZonedDateTime, stop time. + */ + @XmlElement + public void setTimestamp(ZonedDateTime timestamp) { + this.timestamp = timestamp; + } + + /** + * This contains the date and time on which the transaction is stopped. + * + * @return stop time. + */ + @Deprecated + public ZonedDateTime objTimestamp() { + return timestamp; + } + + /** + * This contains the transaction-id as received by the {@link StartTransactionConfirmation}. + * + * @return transaction id. + */ + public Integer getTransactionId() { + return transactionId; + } + + /** + * Required. This contains the transaction-id as received by the {@link + * StartTransactionConfirmation}. + * + * @param transactionId integer, transaction id. + */ + @XmlElement + public void setTransactionId(Integer transactionId) { + this.transactionId = transactionId; + } + + /** + * This contains the reason why the transaction was stopped. + * + * @return the {@link Reason}. + */ + public Reason getReason() { + return reason; + } + + /** + * Optional. This contains the reason why the transaction was stopped. MAY only be omitted when + * the {@link Reason} is "Local". + * + * @param reason the {@link Reason}. + */ + @XmlElement + public void setReason(Reason reason) { + this.reason = reason; + } + + /** + * This contains the reason why the transaction was stopped. + * + * @return the {@link Reason}. + */ + @Deprecated + public Reason objReason() { + return reason; + } + + /** + * This contains transaction usage details relevant for billing purposes. + * + * @return the {@link MeterValue}. + */ + public MeterValue[] getTransactionData() { + return transactionData; + } + + /** + * Optional. This contains transaction usage details relevant for billing purposes. + * + * @param transactionData the {@link MeterValue}. + */ + @XmlElement + public void setTransactionData(MeterValue[] transactionData) { + this.transactionData = transactionData; + } + + @Override + public boolean transactionRelated() { + return true; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + StopTransactionRequest that = (StopTransactionRequest) o; + return Objects.equals(idTag, that.idTag) + && Objects.equals(meterStop, that.meterStop) + && Objects.equals(timestamp, that.timestamp) + && Objects.equals(transactionId, that.transactionId) + && reason == that.reason + && Arrays.equals(transactionData, that.transactionData); + } + + @Override + public int hashCode() { + return Objects.hash(idTag, meterStop, timestamp, transactionId, reason, transactionData); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("idTag", idTag) + .add("meterStop", meterStop) + .add("timestamp", timestamp) + .add("transactionId", transactionId) + .add("reason", reason) + .add("transactionData", transactionData) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/UnlockConnectorConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/UnlockConnectorConfirmation.java index 3e9775d02..205cb6c10 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/UnlockConnectorConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/UnlockConnectorConfirmation.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,80 +29,87 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + 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 UnlockConnectorRequest}. */ @XmlRootElement(name = "unlockConnectorResponse") public class UnlockConnectorConfirmation implements Confirmation { - private UnlockStatus status; - public UnlockConnectorConfirmation() {} + private UnlockStatus status; + + /** + * @deprecated use {@link #UnlockConnectorConfirmation(UnlockStatus)} to be sure to set required fields + */ + @Deprecated + public UnlockConnectorConfirmation() { + } - /** - * Set required values. - * - * @param status the {@link UnlockStatus}, see {@link #setStatus(UnlockStatus)}. - */ - public UnlockConnectorConfirmation(UnlockStatus status) { - setStatus(status); - } + /** + * Handle required fields. + * + * @param status the {@link UnlockStatus}, see {@link #setStatus(UnlockStatus)}. + */ + public UnlockConnectorConfirmation(UnlockStatus status) { + setStatus(status); + } - @Override - public boolean validate() { - return status != null; - } + @Override + public boolean validate() { + return status != null; + } - /** - * This indicates whether the Charge Point has unlocked the connector. - * - * @return the {@link UnlockStatus} - */ - public UnlockStatus getStatus() { - return status; - } + /** + * This indicates whether the Charge Point has unlocked the connector. + * + * @return the {@link UnlockStatus} + */ + public UnlockStatus getStatus() { + return status; + } - /** - * This indicates whether the Charge Point has unlocked the connector. - * - * @return the {@link UnlockStatus} - */ - @Deprecated - public UnlockStatus objStatus() { - return status; - } + /** + * Required. This indicates whether the Charge Point has unlocked the connector. + * + * @param status the {@link UnlockStatus}. + */ + @XmlElement + public void setStatus(UnlockStatus status) { + this.status = status; + } - /** - * Required. This indicates whether the Charge Point has unlocked the connector. - * - * @param status the {@link UnlockStatus}. - */ - @XmlElement - public void setStatus(UnlockStatus status) { - this.status = status; - } + /** + * This indicates whether the Charge Point has unlocked the connector. + * + * @return the {@link UnlockStatus} + */ + @Deprecated + public UnlockStatus objStatus() { + return status; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - UnlockConnectorConfirmation that = (UnlockConnectorConfirmation) o; - return status == that.status; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + UnlockConnectorConfirmation that = (UnlockConnectorConfirmation) o; + return status == that.status; + } - @Override - public int hashCode() { - return Objects.hash(status); - } + @Override + public int hashCode() { + return Objects.hash(status); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/UnlockConnectorRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/UnlockConnectorRequest.java index a5f507d4a..906db5b30 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/UnlockConnectorRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/UnlockConnectorRequest.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,66 +30,87 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; -/** Sent by the Central System to the Charge Point. */ +/** + * Sent by the Central System to the Charge Point. + */ @XmlRootElement public class UnlockConnectorRequest implements Request { - private Integer connectorId; - - @Override - public boolean validate() { - return connectorId != null && connectorId > 0; - } - - /** - * This contains the identifier of the connector to be unlocked. - * - * @return connector. - */ - public Integer getConnectorId() { - return connectorId; - } - - /** - * Required. This contains the identifier of the connector to be unlocked. - * - * @param connectorId integer, value > 0. - */ - @XmlElement - public void setConnectorId(Integer connectorId) { - if (connectorId == null || connectorId <= 0) { - throw new PropertyConstraintException(connectorId, "connectorId must be > 0"); + + private Integer connectorId; + + /** + * @deprecated use {@link #UnlockConnectorRequest(Integer)} to be sure to set required fields + */ + @Deprecated + public UnlockConnectorRequest() { + + } + + /** + * Handle required fields. + * + * @param connectorId integer, value > 0, see {@link #setConnectorId(Integer)} + */ + public UnlockConnectorRequest(Integer connectorId) { + setConnectorId(connectorId); } - this.connectorId = connectorId; - } - - @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; - UnlockConnectorRequest that = (UnlockConnectorRequest) o; - return Objects.equals(connectorId, that.connectorId); - } - - @Override - public int hashCode() { - return Objects.hash(connectorId); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("connectorId", connectorId) - .add("isValid", validate()) - .toString(); - } + @Override + public boolean validate() { + return connectorId != null && connectorId > 0; + } + + /** + * This contains the identifier of the connector to be unlocked. + * + * @return connector. + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Required. This contains the identifier of the connector to be unlocked. + * + * @param connectorId integer, value > 0. + */ + @XmlElement + public void setConnectorId(Integer connectorId) { + if (connectorId == null || connectorId <= 0) { + throw new PropertyConstraintException(connectorId, "connectorId must be > 0"); + } + + this.connectorId = connectorId; + } + + @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; + UnlockConnectorRequest that = (UnlockConnectorRequest) o; + return Objects.equals(connectorId, that.connectorId); + } + + @Override + public int hashCode() { + return Objects.hash(connectorId); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("connectorId", connectorId) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/package-info.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/package-info.java index 8b9650da6..38954b0a8 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/package-info.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/package-info.java @@ -4,6 +4,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,8 +24,17 @@ of this software and associated documentation files (the "Software"), to deal OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +@XmlJavaTypeAdapters({ + @XmlJavaTypeAdapter(type = ZonedDateTime.class, + value = ZonedDateTimeAdapter.class), +}) @XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED, namespace = "urn://Ocpp/Cs/2015/10/") package eu.chargetime.ocpp.model.core; +import eu.chargetime.ocpp.ZonedDateTimeAdapter; + import javax.xml.bind.annotation.XmlNsForm; import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters; +import java.time.ZonedDateTime; 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 index aade5a6b5..30b3db7ba 100644 --- 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 @@ -6,6 +6,7 @@ * * Copyright (C) 2016-2018 Thomas Volden * Copyright (C) 2018 Mikhail Kladkevich + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,78 +30,86 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + 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. */ +/** + * Sent by the Charge Point to the Central System. + */ @XmlRootElement public class DiagnosticsStatusNotificationRequest implements Request { - private DiagnosticsStatus status; + private DiagnosticsStatus status; - public DiagnosticsStatusNotificationRequest() {} - - /** - * Set required fields. - * - * @param status Diagnostics status, see {@link #setStatus(DiagnosticsStatus)}. - */ - public DiagnosticsStatusNotificationRequest(DiagnosticsStatus status) { - this.status = status; - } + /** + * @deprecated use {@link #DiagnosticsStatusNotificationRequest(DiagnosticsStatus)} to be sure to set required fields + */ + @Deprecated + public DiagnosticsStatusNotificationRequest() { + } - @Override - public boolean validate() { - return status != null; - } + /** + * Set required fields. + * + * @param status Diagnostics status, see {@link #setStatus(DiagnosticsStatus)}. + */ + public DiagnosticsStatusNotificationRequest(DiagnosticsStatus status) { + this.status = status; + } - /** - * This contains the status. - * - * @return connector. - */ - public DiagnosticsStatus getStatus() { - return status; - } + @Override + public boolean validate() { + return status != null; + } - /** - * Required. This contains the identifier of the status. - * - * @param status {@link DiagnosticsStatus}. - */ - @XmlElement - public void setStatus(DiagnosticsStatus status) { - if (status == null) { - throw new PropertyConstraintException(null, "Diagnostic status must be present"); + /** + * This contains the status. + * + * @return connector. + */ + public DiagnosticsStatus getStatus() { + return status; } - this.status = status; - } + /** + * Required. This contains the identifier of the status. + * + * @param status {@link DiagnosticsStatus}. + */ + @XmlElement + public void setStatus(DiagnosticsStatus status) { + if (status == null) { + throw new PropertyConstraintException(null, "Diagnostic status must be present"); + } - @Override - public boolean transactionRelated() { - return false; - } + this.status = status; + } - @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 boolean transactionRelated() { + return false; + } - @Override - public int hashCode() { - return Objects.hash(status); - } + @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 String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/FirmwareStatusNotificationRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/FirmwareStatusNotificationRequest.java index 4b790f42c..dbf84927d 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/FirmwareStatusNotificationRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/FirmwareStatusNotificationRequest.java @@ -6,6 +6,7 @@ * * Copyright (C) 2016-2018 Thomas Volden * Copyright (C) 2018 Mikhail Kladkevich + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,78 +30,86 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + 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. */ +/** + * Sent by the Charge Point to the Central System. + */ @XmlRootElement public class FirmwareStatusNotificationRequest implements Request { - private FirmwareStatus status; + private FirmwareStatus status; - public FirmwareStatusNotificationRequest() {} - - /** - * Set required fields. - * - * @param status Firmware status, see {@link #setStatus(FirmwareStatus)}. - */ - public FirmwareStatusNotificationRequest(FirmwareStatus status) { - this.status = status; - } + /** + * @deprecated use {@link #FirmwareStatusNotificationRequest(FirmwareStatus)} to be sure to set required fields + */ + @Deprecated + public FirmwareStatusNotificationRequest() { + } - @Override - public boolean validate() { - return status != null; - } + /** + * Handle required fields. + * + * @param status Firmware status, see {@link #setStatus(FirmwareStatus)}. + */ + public FirmwareStatusNotificationRequest(FirmwareStatus status) { + this.status = status; + } - /** - * This contains the status. - * - * @return connector. - */ - public FirmwareStatus getStatus() { - return status; - } + @Override + public boolean validate() { + return status != null; + } - /** - * Required. This contains the identifier of the status. - * - * @param status {@link FirmwareStatus} - */ - @XmlElement - public void setStatus(FirmwareStatus status) { - if (status == null) { - throw new PropertyConstraintException(null, "FirmwareStatus must be present"); + /** + * This contains the status. + * + * @return connector. + */ + public FirmwareStatus getStatus() { + return status; } - this.status = status; - } + /** + * Required. This contains the identifier of the status. + * + * @param status {@link FirmwareStatus} + */ + @XmlElement + public void setStatus(FirmwareStatus status) { + if (status == null) { + throw new PropertyConstraintException(null, "FirmwareStatus must be present"); + } - @Override - public boolean transactionRelated() { - return false; - } + this.status = status; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - FirmwareStatusNotificationRequest that = (FirmwareStatusNotificationRequest) o; - return status == that.status; - } + @Override + public boolean transactionRelated() { + return false; + } - @Override - public int hashCode() { - return Objects.hash(status); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + FirmwareStatusNotificationRequest that = (FirmwareStatusNotificationRequest) o; + return status == that.status; + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/GetDiagnosticsRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/GetDiagnosticsRequest.java index c1de2e0cd..374d59d87 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/GetDiagnosticsRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/GetDiagnosticsRequest.java @@ -1,189 +1,209 @@ -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. - */ +package eu.chargetime.ocpp.model.firmware; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz + + 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.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Objects; @XmlRootElement @XmlType(propOrder = {"location", "startTime", "stopTime", "retries", "retryInterval"}) public class GetDiagnosticsRequest implements Request { - private String location; - private int retries; - private int retryInterval; - private Calendar startTime; - private Calendar stopTime; - - @Override - public boolean transactionRelated() { - return false; - } - - @Override - public boolean validate() { - return location != null; - } - - /** - * This contains the location (directory) where the diagnostics file shall be uploaded to. - * - * @return String, the destination folder. - */ - public String getLocation() { - return location; - } - - /** - * Required. This contains the location (directory) where the diagnostics file shall be uploaded - * to. - * - * @param location String, the destination folder. - */ - @XmlElement - public void setLocation(String location) { - this.location = location; - } - - /** - * This specifies how many times Charge Point must try to upload the diagnostics 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, minimum number of tries. - */ - public int getRetries() { - return retries; - } - - /** - * Optional. This specifies how many times Charge Point must try to upload the diagnostics 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, minimum number of tries. - */ - @XmlElement - public void setRetries(int retries) { - this.retries = retries; - } - - /** - * 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, seconds - */ - 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, seconds - */ - @XmlElement - public void setRetryInterval(int retryInterval) { - this.retryInterval = retryInterval; - } - - /** - * This contains the date and time of the oldest logging information to include in the - * diagnostics. - * - * @return Calendar, oldest log entry - */ - public Calendar getStartTime() { - return startTime; - } - - /** - * Optional. This contains the date and time of the oldest logging information to include in the - * diagnostics. - * - * @param startTime Calendar, oldest log entry - */ - @XmlElement - public void setStartTime(Calendar startTime) { - this.startTime = startTime; - } - - /** - * This contains the date and time of the latest logging information to include in the - * diagnostics. - * - * @return Calendar, latest log entry - */ - public Calendar getStopTime() { - return stopTime; - } - - /** - * Optional. This contains the date and time of the latest logging information to include in the - * diagnostics. - * - * @param stopTime Calendar, latest log entry - */ - @XmlElement - public void setStopTime(Calendar stopTime) { - this.stopTime = stopTime; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - GetDiagnosticsRequest that = (GetDiagnosticsRequest) o; - return retries == that.retries - && retryInterval == that.retryInterval - && Objects.equals(location, that.location) - && Objects.equals(startTime, that.startTime) - && Objects.equals(stopTime, that.stopTime); - } - - @Override - public int hashCode() { - return Objects.hash(location, retries, retryInterval, startTime, stopTime); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("location", location) - .add("retries", retries) - .add("retryInterval", retryInterval) - .add("startTime", startTime) - .add("stopTime", stopTime) - .add("isValid", validate()) - .toString(); - } + private String location; + private Integer retries; + private Integer retryInterval; + private ZonedDateTime startTime; + private ZonedDateTime stopTime; + + /** + * @deprecated use {@link #GetDiagnosticsRequest(String)} to be sure to set required fields + */ + @Deprecated + public GetDiagnosticsRequest() { + + } + + /** + * Handle required fields. + * + * @param location String, the destination folder, see {@link #setLocation(String)} + */ + public GetDiagnosticsRequest(String location) { + setLocation(location); + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + return location != null; + } + + /** + * This contains the location (directory) where the diagnostics file shall be uploaded to. + * + * @return String, the destination folder. + */ + public String getLocation() { + return location; + } + + /** + * Required. This contains the location (directory) where the diagnostics file shall be uploaded + * to. + * + * @param location String, the destination folder. + */ + @XmlElement + public void setLocation(String location) { + this.location = location; + } + + /** + * This specifies how many times Charge Point must try to upload the diagnostics 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, minimum number of tries. + */ + public Integer getRetries() { + return retries; + } + + /** + * Optional. This specifies how many times Charge Point must try to upload the diagnostics 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, minimum number of tries. + */ + @XmlElement + public void setRetries(Integer retries) { + this.retries = retries; + } + + /** + * 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, seconds + */ + public Integer 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, seconds + */ + @XmlElement + public void setRetryInterval(Integer retryInterval) { + this.retryInterval = retryInterval; + } + + /** + * This contains the date and time of the oldest logging information to include in the + * diagnostics. + * + * @return ZonedDateTime, oldest log entry + */ + public ZonedDateTime getStartTime() { + return startTime; + } + + /** + * Optional. This contains the date and time of the oldest logging information to include in the + * diagnostics. + * + * @param startTime ZonedDateTime, oldest log entry + */ + @XmlElement + public void setStartTime(ZonedDateTime startTime) { + this.startTime = startTime; + } + + /** + * This contains the date and time of the latest logging information to include in the + * diagnostics. + * + * @return ZonedDateTime, latest log entry + */ + public ZonedDateTime getStopTime() { + return stopTime; + } + + /** + * Optional. This contains the date and time of the latest logging information to include in the + * diagnostics. + * + * @param stopTime ZonedDateTime, latest log entry + */ + @XmlElement + public void setStopTime(ZonedDateTime stopTime) { + this.stopTime = stopTime; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetDiagnosticsRequest that = (GetDiagnosticsRequest) o; + return retries == that.retries + && retryInterval == that.retryInterval + && Objects.equals(location, that.location) + && Objects.equals(startTime, that.startTime) + && Objects.equals(stopTime, that.stopTime); + } + + @Override + public int hashCode() { + return Objects.hash(location, retries, retryInterval, startTime, stopTime); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("location", location) + .add("retries", retries) + .add("retryInterval", retryInterval) + .add("startTime", startTime) + .add("stopTime", stopTime) + .add("isValid", validate()) + .toString(); + } } 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 index f7149cf73..c663fc8a1 100644 --- 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 @@ -7,6 +7,7 @@ * * Copyright (C) 2016 Thomas Volden * Copyright (C) 2018 Mikhail Kladkevich + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,155 +31,170 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Objects; -/** Sent by the Central System to the Charge Point. */ +/** + * 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 Integer 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 Integer 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) { - if (retries <= 0) { - throw new PropertyConstraintException(retries, "retries must be > 0"); + + private String location; + private Integer retries; + private ZonedDateTime retrieveDate; + private Integer retryInterval; + + /** + * @deprecated use {@link #UpdateFirmwareRequest(String, ZonedDateTime)} to be sure to set required fields + */ + @Deprecated + public UpdateFirmwareRequest() { + } + + /** + * Handle required fields. + * + * @param location String, a URI with the firmware, see {@link #setLocation(String)} + * @param retrieveDate ZonedDateTime, date and time of retrieving, see {@link #setRetrieveDate(ZonedDateTime)} + */ + public UpdateFirmwareRequest(String location, ZonedDateTime retrieveDate) { + setLocation(location); + setRetrieveDate(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 Integer getRetries() { + return 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 Integer 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. - */ - @XmlElement - public void setRetryInterval(int retryInterval) { - if (retryInterval <= 0) { - throw new PropertyConstraintException(retryInterval, "retryInterval must be > 0"); + /** + * 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) { + if (retries <= 0) { + throw new PropertyConstraintException(retries, "retries must be > 0"); + } + + this.retries = retries; } - 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.equals(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 MoreObjects.toStringHelper(this) - .add("location", location) - .add("retries", retries) - .add("retrieveDate", retrieveDate) - .add("retryInterval", retryInterval) - .add("isValid", validate()) - .toString(); - } + /** + * This contains the date and time after which the Charge Point must retrieve the (new) firmware. + * + * @return ZonedDateTime, date and time of retrieving. + */ + public ZonedDateTime getRetrieveDate() { + return retrieveDate; + } + + /** + * Required. This contains the date and time after which the Charge Point must retrieve the (new) + * firmware. + * + * @param retrieveDate ZonedDateTime, date and time of retrieving. + */ + @XmlElement + public void setRetrieveDate(ZonedDateTime 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 Integer 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. + */ + @XmlElement + public void setRetryInterval(int retryInterval) { + if (retryInterval <= 0) { + throw new PropertyConstraintException(retryInterval, "retryInterval must be > 0"); + } + + 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.equals(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 MoreObjects.toStringHelper(this) + .add("location", location) + .add("retries", retries) + .add("retrieveDate", retrieveDate) + .add("retryInterval", retryInterval) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/package-info.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/package-info.java index e069878f8..34822e5f1 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/package-info.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/package-info.java @@ -4,6 +4,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,9 +24,18 @@ of this software and associated documentation files (the "Software"), to deal OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +@XmlJavaTypeAdapters({ + @XmlJavaTypeAdapter(type = ZonedDateTime.class, + value = ZonedDateTimeAdapter.class), +}) @XmlSchema( elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, namespace = "urn://Ocpp/Cs/2015/10/") package eu.chargetime.ocpp.model.firmware; +import eu.chargetime.ocpp.ZonedDateTimeAdapter; + import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters; +import java.time.ZonedDateTime; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/AuthorizationData.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/AuthorizationData.java index 0502ae472..9ffca0079 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/AuthorizationData.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/AuthorizationData.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,59 +32,88 @@ import eu.chargetime.ocpp.model.core.IdTagInfo; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; + import java.util.Objects; public class AuthorizationData implements Validatable { - private String idTag; - private IdTagInfo idTagInfo; - public void setIdTag(String idTag) { - if (!ModelUtil.validate(idTag, 20)) { - throw new PropertyConstraintException(idTag, "Exceeds limit of 20 chars"); + private String idTag; + private IdTagInfo idTagInfo; + + /** + * @deprecated use {@link #AuthorizationData(String)} be sure to set required fields + */ + @Deprecated + public AuthorizationData() { + + } + + /** + * Handle required fields. + * + * @param idTag String, the idTag, see {@link #setIdTag(String)} + */ + public AuthorizationData(String idTag) { + setIdTag(idTag); + } + + /** + * The identifier to which this authorization applies + * + * @return String the idTag + */ + public String getIdTag() { + return idTag; + } + + /** + * Required. The identifier to which this authorization applies + * + * @param idTag String, the idTag + */ + public void setIdTag(String idTag) { + if (!ModelUtil.validate(idTag, 20)) { + throw new PropertyConstraintException(idTag, "Exceeds limit of 20 chars"); + } + + this.idTag = idTag; } - this.idTag = idTag; - } + public IdTagInfo getIdTagInfo() { + return idTagInfo; + } - public String getIdTag() { - return idTag; - } + public void setIdTagInfo(IdTagInfo idTagInfo) { + if (!idTagInfo.validate()) { + throw new PropertyConstraintException(idTagInfo, "Failed Validation"); + } - public void setIdTagInfo(IdTagInfo idTagInfo) { - if (!idTagInfo.validate()) { - throw new PropertyConstraintException(idTagInfo, "Failed Validation"); + this.idTagInfo = idTagInfo; } - this.idTagInfo = idTagInfo; - } - - public IdTagInfo getIdTagInfo() { - return idTagInfo; - } - - @Override - public boolean validate() { - return ModelUtil.validate(idTag, 20) && idTagInfo.validate(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - AuthorizationData that = (AuthorizationData) o; - return Objects.equals(idTag, that.idTag) && Objects.equals(idTagInfo, that.idTagInfo); - } - - @Override - public int hashCode() { - return Objects.hash(idTag, idTagInfo); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("idTag", idTag) - .add("idTagInfo", idTagInfo) - .toString(); - } + @Override + public boolean validate() { + return ModelUtil.validate(idTag, 20) && idTagInfo.validate(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AuthorizationData that = (AuthorizationData) o; + return Objects.equals(idTag, that.idTag) && Objects.equals(idTagInfo, that.idTagInfo); + } + + @Override + public int hashCode() { + return Objects.hash(idTag, idTagInfo); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("idTag", idTag) + .add("idTagInfo", idTagInfo) + .toString(); + } } 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 0145b7f4b..186293a53 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 @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,67 +30,78 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; + import java.util.Objects; public class GetLocalListVersionConfirmation implements Confirmation { - private int listVersion = -2; + private Integer listVersion = -2; - public GetLocalListVersionConfirmation() {} + /** + * @deprecated use {@link #GetLocalListVersionConfirmation(Integer)} to be sure to set required fields + */ + @Deprecated + public GetLocalListVersionConfirmation() { + } - public GetLocalListVersionConfirmation(int listVersion) { - this.listVersion = listVersion; - } + /** + * Handle required fields. + * + * @param listVersion int, version of localAuthList, see {@link #setListVersion(Integer)} + */ + public GetLocalListVersionConfirmation(Integer 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; - } + /** + * This contains the current version number of the local authorization list in the Charge Point. + * + * @return String, version of localAuthList. + */ + public Integer getListVersion() { + return listVersion; + } - /** - * Required. This contains the current version number of the local authorization list in the - * Charge Point. - * - *

A version number of 0 (zero) SHALL be used to indicate that the local authorization list is - * empty, and a version number of -1 SHALL be used to indicate that the Charge Point does not - * support Local Authorization Lists. - * - * @param listVersion int, version of localAuthList. - */ - public void setListVersion(int listVersion) { - if (listVersion < -1) { - throw new PropertyConstraintException(listVersion, "listVersion must be >= -1"); + /** + * Required. This contains the current version number of the local authorization list in the + * Charge Point. + * + *

A version number of 0 (zero) SHALL be used to indicate that the local authorization list is + * empty, and a version number of -1 SHALL be used to indicate that the Charge Point does not + * support Local Authorization Lists. + * + * @param listVersion int, version of localAuthList. + */ + public void setListVersion(Integer listVersion) { + if (listVersion < -1) { + throw new PropertyConstraintException(listVersion, "listVersion must be >= -1"); + } + this.listVersion = listVersion; } - this.listVersion = listVersion; - } - @Override - public boolean validate() { - return listVersion >= -1; - } + @Override + public boolean validate() { + return listVersion != null && listVersion >= -1; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - GetLocalListVersionConfirmation that = (GetLocalListVersionConfirmation) o; - return Objects.equals(listVersion, that.listVersion); - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetLocalListVersionConfirmation that = (GetLocalListVersionConfirmation) o; + return Objects.equals(listVersion, that.listVersion); + } - @Override - public int hashCode() { - return Objects.hash(listVersion); - } + @Override + public int hashCode() { + return Objects.hash(listVersion); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("listVersion", listVersion) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("listVersion", listVersion) + .add("isValid", validate()) + .toString(); + } } 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 253aa1a0e..4cc8d7eae 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 @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,66 +30,77 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; + import java.util.Objects; public class SendLocalListConfirmation implements Confirmation { - private UpdateStatus status; - - public SendLocalListConfirmation() {} + private UpdateStatus status; - public SendLocalListConfirmation(UpdateStatus status) { - this.status = status; - } + /** + * @deprecated use {@link #SendLocalListConfirmation(UpdateStatus)} to be sure to set required fields + */ + @Deprecated + public SendLocalListConfirmation() { + } - /** - * 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; - } + /** + * Handle required fields. + * + * @param status {@link UpdateStatus}, status of localAuthList updating, see {@link #setStatus(UpdateStatus)} + */ + public SendLocalListConfirmation(UpdateStatus status) { + setStatus(status); + } - /** - * Required. This indicates whether the Charge Point has successfully received and applied the - * update of the local authorization list. - * - * @param status {@link UpdateStatus}, status of localAuthList updating. - */ - public void setStatus(UpdateStatus status) { - if (status == null) { - throw new PropertyConstraintException(null, "updateStatus must be present"); + /** + * 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; } - this.status = status; - } + /** + * Required. This indicates whether the Charge Point has successfully received and applied the + * update of the local authorization list. + * + * @param status {@link UpdateStatus}, status of localAuthList updating. + */ + public void setStatus(UpdateStatus status) { + if (status == null) { + throw new PropertyConstraintException(null, "updateStatus must be present"); + } + + this.status = status; + } - @Override - public boolean validate() { - return status != null; - } + @Override + public boolean validate() { + return status != null; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SendLocalListConfirmation that = (SendLocalListConfirmation) o; - return status == that.status; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SendLocalListConfirmation that = (SendLocalListConfirmation) o; + return status == that.status; + } - @Override - public int hashCode() { + @Override + public int hashCode() { - return Objects.hash(status); - } + return Objects.hash(status); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } 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 e11046c11..5c874e8b3 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 @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,89 +30,143 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; + import java.util.Arrays; import java.util.Objects; public class SendLocalListRequest implements Request { - private int listVersion = 0; - private AuthorizationData[] localAuthorizationList = null; - private UpdateType updateType = null; + private Integer listVersion = 0; + private AuthorizationData[] localAuthorizationList = null; + private UpdateType updateType = null; + + /** + * @deprecated use {@link #SendLocalListRequest(Integer, UpdateType)} to be sure to set required fields + */ + @Deprecated + public SendLocalListRequest() { + } + + /** + * Handle required fields. + * + * @param listVersion, the version number of the list, see {@link #setListVersion(Integer)} + * @param updateType, {@link UpdateType}}, see {@link #setUpdateType(UpdateType)} + */ + public SendLocalListRequest(Integer listVersion, UpdateType updateType) { + this.listVersion = listVersion; + this.updateType = updateType; + } + + /** + * In case of a full update this is the version number of the + * full list. In case of a differential update it is the version number of + * the list after the update has been applied. + * + * @return Integer, the version number of the list + */ + public Integer getListVersion() { + return listVersion; + } + + /** + * Required. In case of a full update this is the version number of the + * full list. In case of a differential update it is the version number of + * the list after the update has been applied. + * + * @param listVersion, the version number of the list + */ + public void setListVersion(Integer listVersion) { + if (listVersion < 1) { + throw new PropertyConstraintException(listVersion, "listVersion must be > 0"); + } + this.listVersion = listVersion; + } - public SendLocalListRequest() {} + /** + * In case of a full update this contains the list of values + * that form the new local authorization list. In case of a differential + * update it contains the changes to be applied to the local + * authorization list in the Charge Point. + * + * @return Array of {@link AuthorizationData} + */ + public AuthorizationData[] getLocalAuthorizationList() { + return localAuthorizationList; + } - public SendLocalListRequest(int listVersion, UpdateType updateType) { - this.listVersion = listVersion; - this.updateType = updateType; - } + /** + * Optional. In case of a full update this contains the list of values + * that form the new local authorization list. In case of a differential + * update it contains the changes to be applied to the local + * authorization list in the Charge Point. + * + * @param localAuthorizationList, Array of {@link AuthorizationData} + */ + public void setLocalAuthorizationList(AuthorizationData[] localAuthorizationList) { + this.localAuthorizationList = localAuthorizationList; + } - public void setListVersion(int listVersion) { - if (listVersion < 1) { - throw new PropertyConstraintException(listVersion, "listVersion must be > 0"); + /** + * Required. This contains the type of update (full or differential) of + * this request. + * + * @return {@link UpdateType} + */ + public UpdateType getUpdateType() { + return updateType; } - this.listVersion = listVersion; - } - public int getListVersion() { - return listVersion; - } + /** + * Required. This contains the type of update (full or differential) of + * this request. + * + * @param updateType, {@link UpdateType}} + */ + public void setUpdateType(UpdateType updateType) { + this.updateType = updateType; + } - public void setLocalAuthorizationList(AuthorizationData[] localAuthorizationList) { - this.localAuthorizationList = localAuthorizationList; - } + @Override + public boolean validate() { + boolean valid = listVersion != null && (listVersion >= 1) && (updateType != null); - public AuthorizationData[] getLocalAuthorizationList() { - return localAuthorizationList; - } + if (localAuthorizationList != null) { + for (AuthorizationData data : localAuthorizationList) { + valid &= data.validate(); + } + } - public void setUpdateType(UpdateType updateType) { - this.updateType = updateType; - } + return valid; + } - public UpdateType getUpdateType() { - return updateType; - } + @Override + public boolean transactionRelated() { + return false; + } - @Override - public boolean validate() { - boolean valid = (listVersion >= 1) && (updateType != null); + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SendLocalListRequest that = (SendLocalListRequest) o; + return Objects.equals(listVersion, that.listVersion) + && Arrays.equals(localAuthorizationList, that.localAuthorizationList) + && updateType == that.updateType; + } - if (localAuthorizationList != null) { - for (AuthorizationData data : localAuthorizationList) { - valid &= data.validate(); - } + @Override + public int hashCode() { + return Objects.hash(listVersion, localAuthorizationList, updateType); } - return valid; - } - - @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; - SendLocalListRequest that = (SendLocalListRequest) o; - return Objects.equals(listVersion, that.listVersion) - && Arrays.equals(localAuthorizationList, that.localAuthorizationList) - && updateType == that.updateType; - } - - @Override - public int hashCode() { - return Objects.hash(listVersion, localAuthorizationList, updateType); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("listVersion", listVersion) - .add("localAuthorizationList", localAuthorizationList) - .add("updateType", updateType) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("listVersion", listVersion) + .add("localAuthorizationList", localAuthorizationList) + .add("updateType", updateType) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/package-info.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/package-info.java index 8c390ab36..47bf83abd 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/package-info.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/package-info.java @@ -4,6 +4,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,9 +24,18 @@ of this software and associated documentation files (the "Software"), to deal OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +@XmlJavaTypeAdapters({ + @XmlJavaTypeAdapter(type = ZonedDateTime.class, + value = ZonedDateTimeAdapter.class), +}) @XmlSchema( elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, namespace = "urn://Ocpp/Cs/2015/10/") package eu.chargetime.ocpp.model.localauthlist; +import eu.chargetime.ocpp.ZonedDateTimeAdapter; + import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters; +import java.time.ZonedDateTime; diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/TriggerMessageConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/TriggerMessageConfirmation.java index 0efa672e2..ecd56dc67 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/TriggerMessageConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/TriggerMessageConfirmation.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2017 Emil Christopher Solli Melar +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2017 Emil Christopher Solli Melar +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,67 +31,74 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; @XmlRootElement(name = "triggerMessageResponse") public class TriggerMessageConfirmation implements Confirmation { - private TriggerMessageStatus status; - - public TriggerMessageConfirmation() {} - - /** - * Set required values. - * - * @param status the {@link TriggerMessageStatus}, see {@link #setStatus(TriggerMessageStatus)}. - */ - public TriggerMessageConfirmation(TriggerMessageStatus status) { - setStatus(status); - } - - /** - * This indicates the success or failure of the trigger message request. - * - * @return the {@link TriggerMessageStatus}. - */ - public TriggerMessageStatus getStatus() { - return status; - } - - /** - * Required. This indicates the success or failure of trigger message request. - * - * @param status the {@link TriggerMessageStatus}. - */ - @XmlElement - public void setStatus(TriggerMessageStatus status) { - this.status = status; - } - - @Override - public boolean validate() { - return this.status != null; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - TriggerMessageConfirmation that = (TriggerMessageConfirmation) o; - return status == that.status; - } - - @Override - public int hashCode() { - return Objects.hash(status); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + + private TriggerMessageStatus status; + + /** + * @deprecated use {@link #TriggerMessageConfirmation(TriggerMessageStatus)} to be sure to set required fields + */ + @Deprecated + public TriggerMessageConfirmation() { + } + + /** + * Handle required fields. + * + * @param status the {@link TriggerMessageStatus}, see {@link #setStatus(TriggerMessageStatus)}. + */ + public TriggerMessageConfirmation(TriggerMessageStatus status) { + setStatus(status); + } + + /** + * This indicates the success or failure of the trigger message request. + * + * @return the {@link TriggerMessageStatus}. + */ + public TriggerMessageStatus getStatus() { + return status; + } + + /** + * Required. This indicates the success or failure of trigger message request. + * + * @param status the {@link TriggerMessageStatus}. + */ + @XmlElement + public void setStatus(TriggerMessageStatus status) { + this.status = status; + } + + @Override + public boolean validate() { + return this.status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TriggerMessageConfirmation that = (TriggerMessageConfirmation) o; + return status == that.status; + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/TriggerMessageRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/TriggerMessageRequest.java index 96bbafa67..e5a8d6081 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/TriggerMessageRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/TriggerMessageRequest.java @@ -3,10 +3,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2017 Emil Christopher Solli Melar +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2017 Emil Christopher Solli Melar +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -30,99 +32,110 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Objects; @XmlRootElement @XmlType(propOrder = {"requestedMessage", "connectorId"}) public class TriggerMessageRequest implements Request { - private Integer connectorId; - private TriggerMessageRequestType requestedMessage; - - public TriggerMessageRequest() {} - - public TriggerMessageRequest(TriggerMessageRequestType requestedMessage) { - this.requestedMessage = requestedMessage; - } - - /** - * This identifies which connector of the Charge Point is used. - * - * @return connector. - */ - public Integer getConnectorId() { - return connectorId; - } - - /** - * Optional. This identifies which connector of the Charge Point is used. - * - * @param connectorId integer. value > 0 - */ - @XmlElement - public void setConnectorId(Integer connectorId) { - if (connectorId != null && connectorId <= 0) { - throw new PropertyConstraintException(connectorId, "connectorId must be > 0"); + private Integer connectorId; + private TriggerMessageRequestType requestedMessage; + + /** + * @deprecated use {@link #TriggerMessageRequest(TriggerMessageRequestType)} to be sure to set required fields + */ + @Deprecated + public TriggerMessageRequest() { + } + + /** + * Handle required fields. + * + * @param triggerMessageRequestType {@link TriggerMessageRequestType}, see {@link #setRequestedMessage(TriggerMessageRequestType)} + */ + public TriggerMessageRequest(TriggerMessageRequestType triggerMessageRequestType) { + this.requestedMessage = triggerMessageRequestType; + } + + /** + * This identifies which connector of the Charge Point is used. + * + * @return connector. + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Optional. This identifies which connector of the Charge Point is used. + * + * @param connectorId integer. value > 0 + */ + @XmlElement + public void setConnectorId(Integer connectorId) { + if (connectorId != null && connectorId <= 0) { + throw new PropertyConstraintException(connectorId, "connectorId must be > 0"); + } + + this.connectorId = connectorId; + } + + public TriggerMessageRequestType getRequestedMessage() { + return requestedMessage; } - this.connectorId = connectorId; - } - - public TriggerMessageRequestType getRequestedMessage() { - return requestedMessage; - } - - /** - * Required. This identifies which type of message you want to trigger. - * - * @param requestedMessage {@link TriggerMessageRequestType}. - */ - @XmlElement - public void setRequestedMessage(TriggerMessageRequestType requestedMessage) { - this.requestedMessage = requestedMessage; - } - - /** - * This identifies which type of message you want to trigger. - * - * @return connector. - */ - @Override - public boolean transactionRelated() { - return false; - } - - @Override - public boolean validate() { - boolean valid = requestedMessage != null; - valid &= (connectorId == null || connectorId > 0); - - return valid; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - TriggerMessageRequest that = (TriggerMessageRequest) o; - return Objects.equals(connectorId, that.connectorId) - && requestedMessage == that.requestedMessage; - } - - @Override - public int hashCode() { - return Objects.hash(connectorId, requestedMessage); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("connectorId", connectorId) - .add("requestedMessage", requestedMessage) - .add("isValid", validate()) - .toString(); - } + /** + * Required. This identifies which type of message you want to trigger. + * + * @param requestedMessage {@link TriggerMessageRequestType}. + */ + @XmlElement + public void setRequestedMessage(TriggerMessageRequestType requestedMessage) { + this.requestedMessage = requestedMessage; + } + + /** + * This identifies which type of message you want to trigger. + * + * @return connector. + */ + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + boolean valid = requestedMessage != null; + valid &= (connectorId == null || connectorId > 0); + + return valid; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TriggerMessageRequest that = (TriggerMessageRequest) o; + return Objects.equals(connectorId, that.connectorId) + && requestedMessage == that.requestedMessage; + } + + @Override + public int hashCode() { + return Objects.hash(connectorId, requestedMessage); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("connectorId", connectorId) + .add("requestedMessage", requestedMessage) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/package-info.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/package-info.java index f4711434d..83c77c216 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/package-info.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/remotetrigger/package-info.java @@ -4,6 +4,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,9 +24,18 @@ of this software and associated documentation files (the "Software"), to deal OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +@XmlJavaTypeAdapters({ + @XmlJavaTypeAdapter(type = ZonedDateTime.class, + value = ZonedDateTimeAdapter.class), +}) @XmlSchema( elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, namespace = "urn://Ocpp/Cs/2015/10/") package eu.chargetime.ocpp.model.remotetrigger; +import eu.chargetime.ocpp.ZonedDateTimeAdapter; + import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters; +import java.time.ZonedDateTime; 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 index c641772e9..e8385e71c 100644 --- 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 @@ -7,6 +7,7 @@ * * Copyright (C) 2016 Thomas Volden * Copyright (C) 2018 Mikhail Kladkevich + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,9 +30,10 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + 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 @@ -39,57 +41,68 @@ */ @XmlRootElement(name = "cancelReservationResponse") public class CancelReservationConfirmation implements Confirmation { - private CancelReservationStatus status; - public CancelReservationConfirmation() {} + private CancelReservationStatus status; + + /** + * @deprecated use {@link #CancelReservationConfirmation(CancelReservationStatus)} to be sure to set required fields + */ + @Deprecated + public CancelReservationConfirmation() { + } - public CancelReservationConfirmation(CancelReservationStatus status) { - setStatus(status); - } + /** + * Handle required fields. + * + * @param status CancelReservationStatus, status of the request, see {@link #setStatus(CancelReservationStatus)} + */ + public CancelReservationConfirmation(CancelReservationStatus status) { + setStatus(status); + } - @Override - public boolean validate() { - return status != null; - } + @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; - } + /** + * 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; - } + /** + * 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 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 int hashCode() { + return Objects.hash(status); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } 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 index 319028431..b9cd2f287 100644 --- 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 @@ -2,9 +2,10 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; /* * ChargeTime.eu - Java-OCA-OCPP @@ -13,6 +14,7 @@ * * Copyright (C) 2016 Thomas Volden * Copyright (C) 2018 Mikhail Kladkevich + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,64 +35,77 @@ * SOFTWARE. */ -/** Sent by the Central System to the Charge Point. */ +/** + * Sent by the Central System to the Charge Point. + */ @XmlRootElement public class CancelReservationRequest implements Request { - private Integer reservationId; - public CancelReservationRequest() {} + private Integer reservationId; + + /** + * @deprecated use {@link #CancelReservationRequest(Integer)} to be sure to set required fields + */ + @Deprecated + public CancelReservationRequest() { + } - public CancelReservationRequest(Integer reservationId) { - this.reservationId = reservationId; - } + /** + * Handle required fields. + * + * @param reservationId Integer, id of the reservation, see {@link #setReservationId(Integer)} + */ + public CancelReservationRequest(Integer reservationId) { + setReservationId(reservationId); + } - @Override - public boolean validate() { - return reservationId != null; - } + @Override + public boolean validate() { + return reservationId != null; + } - /** - * Id of the reservation to cancel. - * - * @return Integer, id of the reservation. - */ - public Integer getReservationId() { - return reservationId; - } + /** + * 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; - } + /** + * 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 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 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 int hashCode() { + return Objects.hash(reservationId); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("reservationId", reservationId) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("reservationId", reservationId) + .add("isValid", validate()) + .toString(); + } } 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 index 5a2009d3b..93add51cf 100644 --- 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 @@ -7,6 +7,7 @@ * * Copyright (C) 2016 Thomas Volden * Copyright (C) 2018 Mikhail Kladkevich + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,63 +30,77 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + 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}. */ +/** + * 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() {} + private ReservationStatus status; + + /** + * @deprecated use {@link #ReserveNowConfirmation(ReservationStatus)} to be sure to set required fields + */ + @Deprecated + public ReserveNowConfirmation() { + } - public ReserveNowConfirmation(ReservationStatus status) { - setStatus(status); - } + /** + * Handle required fields. + * + * @param status ReservationStatus, status of the reservation, see {@link #setStatus(ReservationStatus)} + */ + public ReserveNowConfirmation(ReservationStatus status) { + setStatus(status); + } - @Override - public boolean validate() { - return status != null; - } + @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; - } + /** + * 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; - } + /** + * 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 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 int hashCode() { + return Objects.hash(status); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } 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 index fe307444d..9bf736970 100644 --- 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 @@ -4,11 +4,12 @@ import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.ModelUtil; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Calendar; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.time.ZonedDateTime; +import java.util.Objects; /* * ChargeTime.eu - Java-OCA-OCPP @@ -17,6 +18,7 @@ * * Copyright (C) 2016 Thomas Volden * Copyright (C) 2018 Mikhail Kladkevich + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -37,178 +39,193 @@ * SOFTWARE. */ -/** Sent by the Central System to the Charge Point. */ +/** + * Sent by the Central System to the Charge Point. + */ @XmlRootElement @XmlType(propOrder = {"connectorId", "expiryDate", "idTag", "parentIdTag", "reservationId"}) public class ReserveNowRequest implements Request { - private static final int ID_TAG_MAX_LENGTH = 20; - private static final String ERROR_MESSAGE = "Exceeded limit of " + ID_TAG_MAX_LENGTH + " chars"; - - 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, ID_TAG_MAX_LENGTH); - 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) { - if (connectorId < 0) { - throw new PropertyConstraintException(connectorId, "connectorId must be >= 0"); - } - - 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) { - if (!ModelUtil.validate(idTag, ID_TAG_MAX_LENGTH)) { - throw new PropertyConstraintException(idTag.length(), ERROR_MESSAGE); - } - - 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) { - if (!ModelUtil.validate(parentIdTag, ID_TAG_MAX_LENGTH)) { - throw new PropertyConstraintException(parentIdTag.length(), ERROR_MESSAGE); - } - 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 MoreObjects.toStringHelper(this) - .add("connectorId", connectorId) - .add("expiryDate", expiryDate) - .add("idTag", idTag) - .add("parentIdTag", parentIdTag) - .add("reservationId", reservationId) - .add("isValid", validate()) - .toString(); - } + private static final int ID_TAG_MAX_LENGTH = 20; + private static final String ERROR_MESSAGE = "Exceeded limit of " + ID_TAG_MAX_LENGTH + " chars"; + + private Integer connectorId; + private ZonedDateTime expiryDate; + private String idTag; + private String parentIdTag; + private Integer reservationId; + + /** + * @deprecated use {@link #ReserveNowRequest(Integer, ZonedDateTime, String, Integer)} to be sure to set required fields + */ + @Deprecated + public ReserveNowRequest() { + } + + /** + * Handle required fields. + * + * @param connectorId Integer, the destination connectorId, see {@link #setConnectorId(Integer)} + * @param expiryDate ZonedDateTime, end of reservation, see {@link #setExpiryDate(ZonedDateTime)} + * @param idTag String, the identifier, see {@link #setIdTag(String)} + * @param reservationId Integer, id of reservation, see {@link #setReservationId(Integer)} + */ + public ReserveNowRequest( + Integer connectorId, ZonedDateTime expiryDate, String idTag, Integer reservationId) { + setConnectorId(connectorId); + setExpiryDate(expiryDate); + setIdTag(idTag); + setReservationId(reservationId); + } + + @Override + public boolean validate() { + boolean valid = (connectorId != null && connectorId >= 0); + valid &= expiryDate != null; + valid &= ModelUtil.validate(idTag, ID_TAG_MAX_LENGTH); + 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) { + if (connectorId < 0) { + throw new PropertyConstraintException(connectorId, "connectorId must be >= 0"); + } + + this.connectorId = connectorId; + } + + /** + * This contains the date and time when the reservation ends. + * + * @return ZonedDateTime, end of reservation. + */ + public ZonedDateTime getExpiryDate() { + return expiryDate; + } + + /** + * Required. This contains the date and time when the reservation ends. + * + * @param expiryDate ZonedDateTime, end of reservation. + */ + @XmlElement + public void setExpiryDate(ZonedDateTime 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) { + if (!ModelUtil.validate(idTag, ID_TAG_MAX_LENGTH)) { + throw new PropertyConstraintException(idTag.length(), ERROR_MESSAGE); + } + + 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) { + if (!ModelUtil.validate(parentIdTag, ID_TAG_MAX_LENGTH)) { + throw new PropertyConstraintException(parentIdTag.length(), ERROR_MESSAGE); + } + 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 MoreObjects.toStringHelper(this) + .add("connectorId", connectorId) + .add("expiryDate", expiryDate) + .add("idTag", idTag) + .add("parentIdTag", parentIdTag) + .add("reservationId", reservationId) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/ChangingRateUnitType.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/ChangingRateUnitType.java new file mode 100644 index 000000000..477cc4c74 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/ChangingRateUnitType.java @@ -0,0 +1,31 @@ +package eu.chargetime.ocpp.model.smartcharging; +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2019 Kevin Raddatz + + 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 enum ChangingRateUnitType { + W, + A +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/ClearChargingProfileConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/ClearChargingProfileConfirmation.java index 4294f96e1..fa00ea194 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/ClearChargingProfileConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/ClearChargingProfileConfirmation.java @@ -7,6 +7,7 @@ * * Copyright (C) 2018 Fabian Röhr * Copyright (C) 2018 Robin Roscher + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,69 +30,75 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; @XmlRootElement(name = "clearChargingProfileResponse") public class ClearChargingProfileConfirmation implements Confirmation { - private ClearChargingProfileStatus status; + private ClearChargingProfileStatus status; - public ClearChargingProfileConfirmation() {} + /** + * @deprecated use {@link #ClearChargingProfileConfirmation(ClearChargingProfileStatus)} to be sure to set required fields + */ + @Deprecated + public ClearChargingProfileConfirmation() { + } - /** - * Set required values. - * - * @param status the {@link ChargingProfileStatus}, see {@link - * #setStatus(ClearChargingProfileStatus)}. - */ - public ClearChargingProfileConfirmation(ClearChargingProfileStatus status) { - setStatus(status); - } + /** + * Handle required fields. + * + * @param status the {@link ChargingProfileStatus}, see {@link + * #setStatus(ClearChargingProfileStatus)}. + */ + public ClearChargingProfileConfirmation(ClearChargingProfileStatus status) { + setStatus(status); + } - /** - * This indicates the success or failure of the change of the charging profile. - * - * @return the {@link ClearChargingProfileStatus}. - */ - public ClearChargingProfileStatus getStatus() { - return status; - } + /** + * This indicates the success or failure of the change of the charging profile. + * + * @return the {@link ClearChargingProfileStatus}. + */ + public ClearChargingProfileStatus getStatus() { + return status; + } - /** - * Required. This indicates the success or failure of the change of the charging profile. - * - * @param status the {@link ClearChargingProfileStatus}. - */ - @XmlElement - public void setStatus(ClearChargingProfileStatus status) { - this.status = status; - } + /** + * Required. This indicates the success or failure of the change of the charging profile. + * + * @param status the {@link ClearChargingProfileStatus}. + */ + @XmlElement + public void setStatus(ClearChargingProfileStatus status) { + this.status = status; + } - @Override - public boolean validate() { - return this.status != null; - } + @Override + public boolean validate() { + return this.status != null; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ClearChargingProfileConfirmation that = (ClearChargingProfileConfirmation) o; - return status == that.status; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ClearChargingProfileConfirmation that = (ClearChargingProfileConfirmation) o; + return status == that.status; + } - @Override - public int hashCode() { - return Objects.hash(status); - } + @Override + public int hashCode() { + return Objects.hash(status); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/GetCompositeScheduleConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/GetCompositeScheduleConfirmation.java new file mode 100644 index 000000000..fb39db9a0 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/GetCompositeScheduleConfirmation.java @@ -0,0 +1,169 @@ +package eu.chargetime.ocpp.model.smartcharging; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2019 Kevin Raddatz + + 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 eu.chargetime.ocpp.model.core.ChargingSchedule; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import javax.xml.bind.annotation.XmlElement; +import java.time.ZonedDateTime; +import java.util.Objects; + +public class GetCompositeScheduleConfirmation implements Confirmation { + + private GetCompositeScheduleStatus status; + private Integer connectorId; + private ZonedDateTime scheduleStart; + private ChargingSchedule chargingSchedule; + + /** + * @deprecated use {@link #GetCompositeScheduleConfirmation(GetCompositeScheduleStatus)} to be sure to set required fields + */ + @Deprecated + public GetCompositeScheduleConfirmation() { + + } + + /** + * Handle required fields. + * + * @param status {@link GetCompositeScheduleStatus}, see {@link #setStatus(GetCompositeScheduleStatus)} + */ + public GetCompositeScheduleConfirmation(GetCompositeScheduleStatus status) { + setStatus(status); + } + + @Override + public boolean validate() { + return this.status != null; + } + + /** + * Status of the request. The Charge Point will indicate if it + * was able to process the request + * + * @return status of the request + */ + public GetCompositeScheduleStatus getStatus() { + return status; + } + + /** + * Required. Status of the request. The Charge Point will indicate if it + * was able to process the request + * + * @param status {@link GetCompositeScheduleStatus} + */ + @XmlElement + public void setStatus(final GetCompositeScheduleStatus status) { + this.status = status; + } + + /** + * The charging schedule contained in this notification + * applies to a Connector. + * + * @return Integer ID of the connector + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Optional. The charging schedule contained in this notification + * applies to a Connector. + * + * @param connectorId Integer + */ + @XmlElement + public void setConnectorId(final Integer connectorId) { + this.connectorId = connectorId; + } + + /** + * Time. Periods contained in the charging profile are + * relative to this point in time. + * If status is "Rejected", this field may be absent. + * + * @return {@link ZonedDateTime} start of the schedule + */ + public ZonedDateTime getScheduleStart() { + return scheduleStart; + } + + /** + * Optional. Time. Periods contained in the charging profile are + * relative to this point in time. + * If status is "Rejected", this field may be absent. + * + * @param scheduleStart {@link ZonedDateTime} + */ + @XmlElement + public void setScheduleStart(final ZonedDateTime scheduleStart) { + this.scheduleStart = scheduleStart; + } + + /** + * Planned Composite Charging Schedule, the energy + * consumption over time. Always relative to ScheduleStart. + * If status is "Rejected", this field may be absent. + * + * @return {@link ChargingSchedule} planned charging schedule + */ + public ChargingSchedule getChargingSchedule() { + return chargingSchedule; + } + + /** + * Optional. Planned Composite Charging Schedule, the energy + * consumption over time. Always relative to ScheduleStart. + * If status is "Rejected", this field may be absent. + * + * @param chargingSchedule {@link ChargingSchedule} + */ + @XmlElement + public void setChargingSchedule(final ChargingSchedule chargingSchedule) { + this.chargingSchedule = chargingSchedule; + } + + @Override + public int hashCode() { + return Objects.hash(status, connectorId, scheduleStart, chargingSchedule); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("compositeScheduleStatus", status) + .add("connectorId", connectorId) + .add("scheduleStart", scheduleStart) + .add("chargingSchedule", chargingSchedule) + .add("isValid", validate()) + .toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/GetCompositeScheduleRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/GetCompositeScheduleRequest.java new file mode 100644 index 000000000..0e21844ca --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/GetCompositeScheduleRequest.java @@ -0,0 +1,156 @@ +package eu.chargetime.ocpp.model.smartcharging; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2019 Kevin Raddatz + + 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.Request; +import eu.chargetime.ocpp.utilities.MoreObjects; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; + +@XmlRootElement +public class GetCompositeScheduleRequest implements Request { + + private Integer connectorId; + private Integer duration; + private ChangingRateUnitType changingRateUnitType; + + /** + * @deprecated use {@link #GetCompositeScheduleRequest(Integer, Integer)} to be sure to set required fields + */ + @Deprecated + public GetCompositeScheduleRequest() { + + } + + /** + * Handle required fields. + * + * @param connectorId Integer, see {@link #setConnectorId(Integer)} + * @param duration Integer, see {@link #setDuration(Integer)} + */ + public GetCompositeScheduleRequest(Integer connectorId, Integer duration) { + setConnectorId(connectorId); + setDuration(duration); + } + + /** + * The ID of the Connector for which the schedule is + * requested. When ConnectorId=0, the Charge Point will calculate + * the expected consumption for the grid connection. + * + * @return ID of the connector. + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Required. The ID of the Connector for which the schedule is + * requested. When ConnectorId=0, the Charge Point will calculate + * the expected consumption for the grid connection. + * + * @param connectorId Integer + */ + @XmlElement + public void setConnectorId(Integer connectorId) { + if (connectorId == null || connectorId < 0) { + throw new PropertyConstraintException(connectorId, "connectorId must be >= 0"); + } + + this.connectorId = connectorId; + } + + /** + * Time in seconds. length of requested schedule + * + * @return length of requested schedule + */ + public Integer getDuration() { + return duration; + } + + /** + * Required. Time in seconds. length of requested schedule + * + * @param duration Integer + */ + @XmlElement + public void setDuration(Integer duration) { + this.duration = duration; + } + + /** + * Can be used to force a power or current profile + * + * @return current profile + */ + public ChangingRateUnitType getChangingRateUnitType() { + return changingRateUnitType; + } + + /** + * Optional. Can be used to force a power or current profile + * + * @param changingRateUnitType the {@link ChangingRateUnitType} + */ + @XmlElement + public void setChangingRateUnitType(ChangingRateUnitType changingRateUnitType) { + this.changingRateUnitType = changingRateUnitType; + } + + @Override + public boolean validate() { + boolean valid = connectorId != null && connectorId >= 0; + valid &= duration != null; + valid &= changingRateUnitType != null; + + return valid; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public int hashCode() { + return Objects.hash(connectorId, duration, changingRateUnitType); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("connectorId", connectorId) + .add("duration", duration) + .add("changingRateUnitType", changingRateUnitType) + .add("isValid", validate()) + .toString(); + } +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/GetCompositeScheduleStatus.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/GetCompositeScheduleStatus.java new file mode 100644 index 000000000..eaf228c51 --- /dev/null +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/GetCompositeScheduleStatus.java @@ -0,0 +1,32 @@ +package eu.chargetime.ocpp.model.smartcharging; + +/* + ChargeTime.eu - Java-OCA-OCPP + + MIT License + + Copyright (C) 2019 Kevin Raddatz + + 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 enum GetCompositeScheduleStatus { + Accepted, + Rejected +} diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/SetChargingProfileConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/SetChargingProfileConfirmation.java index 567a1c981..507d9f36f 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/SetChargingProfileConfirmation.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/SetChargingProfileConfirmation.java @@ -6,6 +6,7 @@ * MIT License * * Copyright (C) 2017 Emil Christopher Solli Melar + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,78 +29,84 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; @XmlRootElement(name = "setChargingProfileResponse") public class SetChargingProfileConfirmation implements Confirmation { - private ChargingProfileStatus status; + private ChargingProfileStatus status; - public SetChargingProfileConfirmation() {} + /** + * @deprecated use {@link #SetChargingProfileConfirmation(ChargingProfileStatus)} to be sure to set required fields + */ + @Deprecated + public SetChargingProfileConfirmation() { + } - /** - * Set required values. - * - * @param status the {@link ChargingProfileStatus}, see {@link #setStatus(ChargingProfileStatus)}. - */ - public SetChargingProfileConfirmation(ChargingProfileStatus status) { - setStatus(status); - } + /** + * Handle required fields. + * + * @param status the {@link ChargingProfileStatus}, see {@link #setStatus(ChargingProfileStatus)}. + */ + public SetChargingProfileConfirmation(ChargingProfileStatus status) { + setStatus(status); + } - /** - * This indicates the success or failure of the change of the charging profile. - * - * @return the {@link ChargingProfileStatus}. - */ - public ChargingProfileStatus getStatus() { - return status; - } + /** + * This indicates the success or failure of the change of the charging profile. + * + * @return the {@link ChargingProfileStatus}. + */ + public ChargingProfileStatus getStatus() { + return status; + } - /** - * This indicates the success or failure of the change of the charging profile. - * - * @return the {@link ChargingProfileStatus}. - */ - @Deprecated - public ChargingProfileStatus objStatus() { - return status; - } + /** + * Required. This indicates the success or failure of the change of the charging profile. + * + * @param status the {@link ChargingProfileStatus}. + */ + @XmlElement + public void setStatus(ChargingProfileStatus status) { + this.status = status; + } - /** - * Required. This indicates the success or failure of the change of the charging profile. - * - * @param status the {@link ChargingProfileStatus}. - */ - @XmlElement - public void setStatus(ChargingProfileStatus status) { - this.status = status; - } + /** + * This indicates the success or failure of the change of the charging profile. + * + * @return the {@link ChargingProfileStatus}. + */ + @Deprecated + public ChargingProfileStatus objStatus() { + return status; + } - @Override - public boolean validate() { - return this.status != null; - } + @Override + public boolean validate() { + return this.status != null; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SetChargingProfileConfirmation that = (SetChargingProfileConfirmation) o; - return status == that.status; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SetChargingProfileConfirmation that = (SetChargingProfileConfirmation) o; + return status == that.status; + } - @Override - public int hashCode() { - return Objects.hash(status); - } + @Override + public int hashCode() { + return Objects.hash(status); + } - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("status", status) - .add("isValid", validate()) - .toString(); - } + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("status", status) + .add("isValid", validate()) + .toString(); + } } 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 24205d077..e94e9f3d2 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 @@ -5,9 +5,10 @@ import eu.chargetime.ocpp.model.core.ChargingProfile; import eu.chargetime.ocpp.model.core.ChargingProfilePurposeType; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Objects; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Objects; /* * ChargeTime.eu - Java-OCA-OCPP @@ -15,6 +16,7 @@ * MIT License * * Copyright (C) 2017 Emil Christopher Solli Melar + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -37,96 +39,108 @@ @XmlRootElement public class SetChargingProfileRequest implements Request { - private Integer connectorId; - private ChargingProfile csChargingProfiles; - - public SetChargingProfileRequest() {} - - public SetChargingProfileRequest(Integer connectorId, ChargingProfile csChargingProfiles) { - this.connectorId = connectorId; - this.csChargingProfiles = csChargingProfiles; - } - - /** - * This identifies which connector of the Charge Point is used. - * - * @return connector. - */ - public Integer getConnectorId() { - return connectorId; - } - - /** - * Required. This identifies which connector of the Charge Point is used. - * - * @param connectorId integer. value > 0 - */ - @XmlElement - public void setConnectorId(Integer connectorId) { - if (connectorId == null || connectorId < 0) { - throw new PropertyConstraintException(connectorId, "connectorId must be >= 0"); + + private Integer connectorId; + private ChargingProfile csChargingProfiles; + + /** + * @deprecated use {@link #SetChargingProfileRequest(Integer, ChargingProfile)} to be sure to set required fields + */ + @Deprecated + public SetChargingProfileRequest() { + } + + /** + * Handle required fields. + * + * @param connectorId integer. value > 0, see {@link #setConnectorId(Integer)} + * @param chargingProfile the {@link ChargingProfile}, see {@link #setCsChargingProfiles(ChargingProfile)} + */ + public SetChargingProfileRequest(Integer connectorId, ChargingProfile chargingProfile) { + setConnectorId(connectorId); + setCsChargingProfiles(chargingProfile); + } + + /** + * This identifies which connector of the Charge Point is used. + * + * @return connector. + */ + public Integer getConnectorId() { + return connectorId; + } + + /** + * Required. This identifies which connector of the Charge Point is used. + * + * @param connectorId integer. value > 0 + */ + @XmlElement + public void setConnectorId(Integer connectorId) { + if (connectorId == null || connectorId < 0) { + throw new PropertyConstraintException(connectorId, "connectorId must be >= 0"); + } + + this.connectorId = connectorId; + } + + /** + * Charging Profile to be used by the Charge Point for the requested transaction. + * + * @return the {@link ChargingProfile}. + */ + public ChargingProfile getCsChargingProfiles() { + return csChargingProfiles; + } + + /** + * Optional. Charging Profile to be used by the Charge Point for the requested transaction. {@link + * ChargingProfile#setChargingProfilePurpose(ChargingProfilePurposeType)} MUST be set to + * TxProfile. + * + * @param csChargingProfiles the {@link ChargingProfile}. + */ + @XmlElement(name = "csChargingProfiles") + public void setCsChargingProfiles(ChargingProfile csChargingProfiles) { + this.csChargingProfiles = csChargingProfiles; + } + + @Override + public boolean transactionRelated() { + return false; + } + + @Override + public boolean validate() { + boolean valid = connectorId != null && connectorId >= 0; + + if (csChargingProfiles != null) { + valid &= csChargingProfiles.validate(); + } + + return valid; } - this.connectorId = connectorId; - } - - /** - * Charging Profile to be used by the Charge Point for the requested transaction. - * - * @return the {@link ChargingProfile}. - */ - public ChargingProfile getCsChargingProfiles() { - return csChargingProfiles; - } - - /** - * Optional. Charging Profile to be used by the Charge Point for the requested transaction. {@link - * ChargingProfile#setChargingProfilePurpose(ChargingProfilePurposeType)} MUST be set to - * TxProfile. - * - * @param csChargingProfiles the {@link ChargingProfile}. - */ - @XmlElement(name = "csChargingProfiles") - public void setCsChargingProfiles(ChargingProfile csChargingProfiles) { - this.csChargingProfiles = csChargingProfiles; - } - - @Override - public boolean transactionRelated() { - return false; - } - - @Override - public boolean validate() { - boolean valid = connectorId != null && connectorId >= 0; - - if (csChargingProfiles != null) { - valid &= csChargingProfiles.validate(); + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SetChargingProfileRequest that = (SetChargingProfileRequest) o; + return Objects.equals(connectorId, that.connectorId) + && Objects.equals(csChargingProfiles, that.csChargingProfiles); } - return valid; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SetChargingProfileRequest that = (SetChargingProfileRequest) o; - return Objects.equals(connectorId, that.connectorId) - && Objects.equals(csChargingProfiles, that.csChargingProfiles); - } - - @Override - public int hashCode() { - return Objects.hash(connectorId, csChargingProfiles); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("connectorId", connectorId) - .add("csChargingProfiles", csChargingProfiles) - .add("isValid", validate()) - .toString(); - } + @Override + public int hashCode() { + return Objects.hash(connectorId, csChargingProfiles); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("connectorId", connectorId) + .add("csChargingProfiles", csChargingProfiles) + .add("isValid", validate()) + .toString(); + } } diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/package-info.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/package-info.java index 405df690d..34b9df727 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/package-info.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/smartcharging/package-info.java @@ -4,6 +4,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,9 +24,18 @@ of this software and associated documentation files (the "Software"), to deal OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +@XmlJavaTypeAdapters({ + @XmlJavaTypeAdapter(type = ZonedDateTime.class, + value = ZonedDateTimeAdapter.class), +}) @XmlSchema( elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, namespace = "urn://Ocpp/Cs/2015/10/") package eu.chargetime.ocpp.model.smartcharging; +import eu.chargetime.ocpp.ZonedDateTimeAdapter; + import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters; +import java.time.ZonedDateTime; diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientCoreProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientCoreProfileTest.java index 73d72e7f4..d7addb5f0 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientCoreProfileTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientCoreProfileTest.java @@ -1,73 +1,34 @@ package eu.chargetime.ocpp.feature.profile.test; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import eu.chargetime.ocpp.feature.AuthorizeFeature; -import eu.chargetime.ocpp.feature.BootNotificationFeature; -import eu.chargetime.ocpp.feature.ChangeAvailabilityFeature; -import eu.chargetime.ocpp.feature.ChangeConfigurationFeature; -import eu.chargetime.ocpp.feature.ClearCacheFeature; -import eu.chargetime.ocpp.feature.DataTransferFeature; -import eu.chargetime.ocpp.feature.Feature; -import eu.chargetime.ocpp.feature.GetConfigurationFeature; -import eu.chargetime.ocpp.feature.HeartbeatFeature; -import eu.chargetime.ocpp.feature.MeterValuesFeature; -import eu.chargetime.ocpp.feature.RemoteStartTransactionFeature; -import eu.chargetime.ocpp.feature.RemoteStopTransactionFeature; -import eu.chargetime.ocpp.feature.ResetFeature; -import eu.chargetime.ocpp.feature.StartTransactionFeature; -import eu.chargetime.ocpp.feature.StatusNotificationFeature; -import eu.chargetime.ocpp.feature.StopTransactionFeature; -import eu.chargetime.ocpp.feature.UnlockConnectorFeature; +import eu.chargetime.ocpp.feature.*; import eu.chargetime.ocpp.feature.profile.ClientCoreEventHandler; import eu.chargetime.ocpp.feature.profile.ClientCoreProfile; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.Request; -import eu.chargetime.ocpp.model.core.AuthorizeRequest; -import eu.chargetime.ocpp.model.core.BootNotificationRequest; -import eu.chargetime.ocpp.model.core.ChangeAvailabilityConfirmation; -import eu.chargetime.ocpp.model.core.ChangeAvailabilityRequest; -import eu.chargetime.ocpp.model.core.ChangeConfigurationConfirmation; -import eu.chargetime.ocpp.model.core.ChangeConfigurationRequest; -import eu.chargetime.ocpp.model.core.ChargePointErrorCode; -import eu.chargetime.ocpp.model.core.ChargePointStatus; -import eu.chargetime.ocpp.model.core.ClearCacheConfirmation; -import eu.chargetime.ocpp.model.core.ClearCacheRequest; -import eu.chargetime.ocpp.model.core.DataTransferConfirmation; -import eu.chargetime.ocpp.model.core.DataTransferRequest; -import eu.chargetime.ocpp.model.core.GetConfigurationConfirmation; -import eu.chargetime.ocpp.model.core.GetConfigurationRequest; -import eu.chargetime.ocpp.model.core.HeartbeatRequest; -import eu.chargetime.ocpp.model.core.MeterValuesRequest; -import eu.chargetime.ocpp.model.core.RemoteStartTransactionRequest; -import eu.chargetime.ocpp.model.core.RemoteStopTransactionRequest; -import eu.chargetime.ocpp.model.core.ResetRequest; -import eu.chargetime.ocpp.model.core.StartTransactionRequest; -import eu.chargetime.ocpp.model.core.StatusNotificationRequest; -import eu.chargetime.ocpp.model.core.StopTransactionRequest; -import eu.chargetime.ocpp.model.core.UnlockConnectorRequest; -import java.util.Calendar; -import java.util.UUID; +import eu.chargetime.ocpp.model.core.*; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.time.ZonedDateTime; +import java.util.UUID; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.*; + /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -89,426 +50,426 @@ of this software and associated documentation files (the "Software"), to deal */ @RunWith(MockitoJUnitRunner.class) public class ClientCoreProfileTest extends ProfileTest { - private static final UUID SESSION_NULL = null; - - private ClientCoreProfile core; - - @Mock private ClientCoreEventHandler handler; - - @Before - public void setup() { - core = new ClientCoreProfile(handler); - } - - @Test - public void createAuthorizeRequest_withIdToken_returnsAuthorizeRequestWithIdTag() { - // Given - String legalIdToken = "test123"; - - // When - AuthorizeRequest result = core.createAuthorizeRequest(legalIdToken); - - // Then - assertThat(result.getIdTag(), is(legalIdToken)); - } - - @Test - public void - createBootNotificationRequest_withVendorAndModel_returnsBootNotificationRequestWithVendorAndModel() { - // Given - String legalVendor = "vendor"; - String legalModel = "model"; - - // When - BootNotificationRequest result = core.createBootNotificationRequest(legalVendor, legalModel); - - // Then - assertThat(result.getChargePointVendor(), is(legalVendor)); - assertThat(result.getChargePointModel(), is(legalModel)); - } - - @Test - public void createHeartbeatRequest_returnsHeartbeatRequest() { - // When - Request result = core.createHeartbeatRequest(); - - // Then - assertThat(result, instanceOf(HeartbeatRequest.class)); - } - - @Test - public void createMeterValuesRequest_returnsMeterValuesRequest() { - // When - Request result = core.createMeterValuesRequest(42, Calendar.getInstance(), "42"); - - // Then - assertThat(result, instanceOf(MeterValuesRequest.class)); - } - - @Test - public void createStartTransactionRequest_returnsStartTransactionRequest() { - // When - Request result = - core.createStartTransactionRequest(42, "some token", 42, Calendar.getInstance()); - - // Then - assertThat(result, instanceOf(StartTransactionRequest.class)); - } - - @Test - public void createStatusNotificationRequest_returnsStatusNotificationRequest() { - // When - Request result = - core.createStatusNotificationRequest( - 42, ChargePointErrorCode.NoError, ChargePointStatus.Available); - - // Then - assertThat(result, instanceOf(StatusNotificationRequest.class)); - } - - @Test - public void createStopTransactionRequest_returnsStopTransactionRequest() { - // When - Request result = core.createStopTransactionRequest(42, Calendar.getInstance(), 42); - - // Then - assertThat(result, instanceOf(StopTransactionRequest.class)); - } - - @Test - public void getFeatureList_containsBootNotificationFeature() { - // When - Feature[] features = core.getFeatureList(); - - // then - assertThat( - findFeature(features, "BootNotification"), is(instanceOf(BootNotificationFeature.class))); - } - - @Test - public void getFeatureList_containsAuthorizeFeature() { - // When - Feature[] features = core.getFeatureList(); - - // then - assertThat(findFeature(features, "Authorize"), is(instanceOf(AuthorizeFeature.class))); - } - - @Test - public void getFeatureList_containsHeartbeatFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat(findFeature(features, "Heartbeat"), is(instanceOf(HeartbeatFeature.class))); - } - - @Test - public void getFeatureList_containsMeterValuesFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat(findFeature(features, "MeterValues"), is(instanceOf(MeterValuesFeature.class))); - } - - @Test - public void getFeatureList_containsRemoteStartTransactionFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "RemoteStartTransaction"), - is(instanceOf(RemoteStartTransactionFeature.class))); - } - - @Test - public void getFeatureList_containsRemoteStopTransactionFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "RemoteStopTransaction"), - is(instanceOf(RemoteStopTransactionFeature.class))); - } - - @Test - public void getFeatureList_containsResetFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat(findFeature(features, "Reset"), is(instanceOf(ResetFeature.class))); - } - - @Test - public void getFeatureList_containsStartTransactionFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "StartTransaction"), is(instanceOf(StartTransactionFeature.class))); - } - - @Test - public void getFeatureList_containsStatusNotificationFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "StatusNotification"), - is(instanceOf(StatusNotificationFeature.class))); - } - - @Test - public void getFeatureList_containsStopTransactionFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "StopTransaction"), is(instanceOf(StopTransactionFeature.class))); - } - - @Test - public void getFeatureList_containsUnlockConnectorFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "UnlockConnector"), is(instanceOf(UnlockConnectorFeature.class))); - } - - @Test - public void handleRequest_aChangeAvailabilityRequest_callsHandleChangeAvailabilityRequest() { - // Given - ChangeAvailabilityRequest request = new ChangeAvailabilityRequest(); - - // When - core.handleRequest(SESSION_NULL, request); - - // Then - verify(handler, times(1)).handleChangeAvailabilityRequest(eq(request)); - } - - @Test - public void - handleRequest_aRemoteStartTransactionRequest_callsHandleRemoteStartTransactionRequest() { - // Given - RemoteStartTransactionRequest request = new RemoteStartTransactionRequest(); - - // When - core.handleRequest(SESSION_NULL, request); - - // Then - verify(handler, times(1)).handleRemoteStartTransactionRequest(eq(request)); - } - - @Test - public void - handleRequest_aRemoteStopTransactionRequest_callsHandleRemoteStopTransactionRequest() { - // Given - RemoteStopTransactionRequest request = new RemoteStopTransactionRequest(); - - // When - core.handleRequest(SESSION_NULL, request); - - // Then - verify(handler, times(1)).handleRemoteStopTransactionRequest(eq(request)); - } - - @Test - public void handleRequest_aResetRequest_callsHandleResetRequest() { - // Given - ResetRequest request = new ResetRequest(); - - // When - core.handleRequest(SESSION_NULL, request); - - // Then - verify(handler, times(1)).handleResetRequest(eq(request)); - } - - @Test - public void handleRequest_anUnlockConnectorRequest_callsHandleUnlockConnectorRequest() { - // Given - UnlockConnectorRequest request = new UnlockConnectorRequest(); - - // When - core.handleRequest(SESSION_NULL, request); - - // Then - verify(handler, times(1)).handleUnlockConnectorRequest(eq(request)); - } - - @Test - public void handleRequest_aChangeAvailabilityRequest_returnsChangeAvailabilityConfirmation() { - // Given - when(handler.handleChangeAvailabilityRequest(any())) - .thenReturn(new ChangeAvailabilityConfirmation()); - ChangeAvailabilityRequest request = new ChangeAvailabilityRequest(); - - // When - Confirmation conf = core.handleRequest(SESSION_NULL, request); - - // Then - assertThat(conf, instanceOf(ChangeAvailabilityConfirmation.class)); - } - - @Test - public void getFeatureList_containsChangeAvailabilityFeature() { - // When - Feature[] features = core.getFeatureList(); - - // then - assertThat( - findFeature(features, "ChangeAvailability"), - is(instanceOf(ChangeAvailabilityFeature.class))); - } - - @Test - public void handleRequest_aGetConfigurationRequest_callsHandleGetConfigurationRequest() { - // Given - GetConfigurationRequest request = new GetConfigurationRequest(); - - // When - core.handleRequest(SESSION_NULL, request); - - // Then - verify(handler, times(1)).handleGetConfigurationRequest(eq(request)); - } - - @Test - public void handleRequest_aGetConfigurationRequest_returnGetConfigurationConfirmation() { - // Given - when(handler.handleGetConfigurationRequest(any())) - .thenReturn(new GetConfigurationConfirmation()); - GetConfigurationRequest request = new GetConfigurationRequest(); - - // When - Confirmation conf = core.handleRequest(SESSION_NULL, request); - - // Then - assertThat(conf, instanceOf(GetConfigurationConfirmation.class)); - } - - @Test - public void handleRequest_aDataTransferRequest_callsHandleDataTransferRequest() { - // Given - DataTransferRequest request = new DataTransferRequest(); - - // When - core.handleRequest(SESSION_NULL, request); - - // Then - verify(handler, times(1)).handleDataTransferRequest(eq(request)); - } - - @Test - public void handleRequest_aDataTransferRequest_returnDataTransferConfirmation() { - // Given - when(handler.handleDataTransferRequest(any())).thenReturn(new DataTransferConfirmation()); - DataTransferRequest request = new DataTransferRequest(); - - // When - Confirmation conf = core.handleRequest(SESSION_NULL, request); - - // Then - assertThat(conf, instanceOf(DataTransferConfirmation.class)); - } - - @Test - public void getFeatureList_containsGetConfigurationFeature() { - // When - Feature[] features = core.getFeatureList(); - - // then - assertThat( - findFeature(features, "GetConfiguration"), is(instanceOf(GetConfigurationFeature.class))); - } - - @Test - public void handleRequest_aChangeConfigurationRequest_callsHandleChangeConfigurationRequest() { - // Given - ChangeConfigurationRequest request = new ChangeConfigurationRequest(); - - // When - core.handleRequest(SESSION_NULL, request); - - // Then - verify(handler, times(1)).handleChangeConfigurationRequest(eq(request)); - } - - @Test - public void handleRequest_aChangeConfigurationRequest_returnsChangeConfigurationConfirmation() { - // Given - when(handler.handleChangeConfigurationRequest(any())) - .thenReturn(new ChangeConfigurationConfirmation()); - ChangeConfigurationRequest request = new ChangeConfigurationRequest(); - - // When - Confirmation conf = core.handleRequest(SESSION_NULL, request); - - // Then - assertThat(conf, instanceOf(ChangeConfigurationConfirmation.class)); - } - - @Test - public void getFeatureList_containsChangeConfigurationFeature() { - // When - Feature[] features = core.getFeatureList(); - - // then - assertThat( - findFeature(features, "ChangeConfiguration"), - is(instanceOf(ChangeConfigurationFeature.class))); - } - - @Test - public void handleRequest_aClearCacheRequest_callsHandleClearCacheRequest() { - // Given - ClearCacheRequest request = new ClearCacheRequest(); - - // When - core.handleRequest(SESSION_NULL, request); - - // Then - verify(handler, times(1)).handleClearCacheRequest(request); - } - - @Test - public void handleRequest_aClearCacheRequest_returnsClearCacheConfirmation() { - // Given - when(handler.handleClearCacheRequest(any())).thenReturn(new ClearCacheConfirmation()); - ClearCacheRequest request = new ClearCacheRequest(); - - // When - Confirmation conf = core.handleRequest(SESSION_NULL, request); - - // Then - assertThat(conf, instanceOf(ClearCacheConfirmation.class)); - } - - @Test - public void getFeatureList_containsClearCacheFeature() { - // When - Feature[] features = core.getFeatureList(); - - // then - assertThat(findFeature(features, "ClearCache"), is(instanceOf(ClearCacheFeature.class))); - } - - @Test - public void getFeatureList_containsDataTransfer() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat(findFeature(features, "DataTransfer"), is(instanceOf(DataTransferFeature.class))); - } + private static final UUID SESSION_NULL = null; + + private ClientCoreProfile core; + + @Mock private ClientCoreEventHandler handler; + + @Before + public void setup() { + core = new ClientCoreProfile(handler); + } + + @Test + public void createAuthorizeRequest_withIdToken_returnsAuthorizeRequestWithIdTag() { + // Given + String legalIdTag = "test123"; + + // When + AuthorizeRequest result = core.createAuthorizeRequest(legalIdTag); + + // Then + assertThat(result.getIdTag(), is(legalIdTag)); + } + + @Test + public void + createBootNotificationRequest_withVendorAndModel_returnsBootNotificationRequestWithVendorAndModel() { + // Given + String legalVendor = "vendor"; + String legalModel = "model"; + + // When + BootNotificationRequest result = core.createBootNotificationRequest(legalVendor, legalModel); + + // Then + assertThat(result.getChargePointVendor(), is(legalVendor)); + assertThat(result.getChargePointModel(), is(legalModel)); + } + + @Test + public void createHeartbeatRequest_returnsHeartbeatRequest() { + // When + Request result = core.createHeartbeatRequest(); + + // Then + assertThat(result, instanceOf(HeartbeatRequest.class)); + } + + @Test + public void createMeterValuesRequest_returnsMeterValuesRequest() { + // When + Request result = core.createMeterValuesRequest(42, ZonedDateTime.now(), "42"); + + // Then + assertThat(result, instanceOf(MeterValuesRequest.class)); + } + + @Test + public void createStartTransactionRequest_returnsStartTransactionRequest() { + // When + Request result = + core.createStartTransactionRequest(42, "some token", 42, ZonedDateTime.now()); + + // Then + assertThat(result, instanceOf(StartTransactionRequest.class)); + } + + @Test + public void createStatusNotificationRequest_returnsStatusNotificationRequest() { + // When + Request result = + core.createStatusNotificationRequest( + 42, ChargePointErrorCode.NoError, ChargePointStatus.Available); + + // Then + assertThat(result, instanceOf(StatusNotificationRequest.class)); + } + + @Test + public void createStopTransactionRequest_returnsStopTransactionRequest() { + // When + Request result = core.createStopTransactionRequest(42, ZonedDateTime.now(), 42); + + // Then + assertThat(result, instanceOf(StopTransactionRequest.class)); + } + + @Test + public void getFeatureList_containsAuthorizeFeature() { + // When + Feature[] features = core.getFeatureList(); + + // then + assertThat(findFeature(features, "Authorize"), is(instanceOf(AuthorizeFeature.class))); + } + + @Test + public void getFeatureList_containsBootNotificationFeature() { + // When + Feature[] features = core.getFeatureList(); + + // then + assertThat( + findFeature(features, "BootNotification"), is(instanceOf(BootNotificationFeature.class))); + } + + @Test + public void getFeatureList_containsChangeAvailabilityFeature() { + // When + Feature[] features = core.getFeatureList(); + + // then + assertThat( + findFeature(features, "ChangeAvailability"), + is(instanceOf(ChangeAvailabilityFeature.class))); + } + + @Test + public void getFeatureList_containsChangeConfigurationFeature() { + // When + Feature[] features = core.getFeatureList(); + + // then + assertThat( + findFeature(features, "ChangeConfiguration"), + is(instanceOf(ChangeConfigurationFeature.class))); + } + + @Test + public void getFeatureList_containsClearCacheFeature() { + // When + Feature[] features = core.getFeatureList(); + + // then + assertThat(findFeature(features, "ClearCache"), is(instanceOf(ClearCacheFeature.class))); + } + + @Test + public void getFeatureList_containsDataTransfer() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat(findFeature(features, "DataTransfer"), is(instanceOf(DataTransferFeature.class))); + } + + @Test + public void getFeatureList_containsGetConfigurationFeature() { + // When + Feature[] features = core.getFeatureList(); + + // then + assertThat( + findFeature(features, "GetConfiguration"), is(instanceOf(GetConfigurationFeature.class))); + } + + @Test + public void getFeatureList_containsHeartbeatFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat(findFeature(features, "Heartbeat"), is(instanceOf(HeartbeatFeature.class))); + } + + @Test + public void getFeatureList_containsMeterValuesFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat(findFeature(features, "MeterValues"), is(instanceOf(MeterValuesFeature.class))); + } + + @Test + public void getFeatureList_containsRemoteStartTransactionFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "RemoteStartTransaction"), + is(instanceOf(RemoteStartTransactionFeature.class))); + } + + @Test + public void getFeatureList_containsRemoteStopTransactionFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "RemoteStopTransaction"), + is(instanceOf(RemoteStopTransactionFeature.class))); + } + + @Test + public void getFeatureList_containsResetFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat(findFeature(features, "Reset"), is(instanceOf(ResetFeature.class))); + } + + @Test + public void getFeatureList_containsStartTransactionFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "StartTransaction"), is(instanceOf(StartTransactionFeature.class))); + } + + @Test + public void getFeatureList_containsStatusNotificationFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "StatusNotification"), + is(instanceOf(StatusNotificationFeature.class))); + } + + @Test + public void getFeatureList_containsStopTransactionFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "StopTransaction"), is(instanceOf(StopTransactionFeature.class))); + } + + @Test + public void getFeatureList_containsUnlockConnectorFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "UnlockConnector"), is(instanceOf(UnlockConnectorFeature.class))); + } + + @Test + public void handleRequest_aChangeAvailabilityRequest_callsHandleChangeAvailabilityRequest() { + // Given + ChangeAvailabilityRequest request = new ChangeAvailabilityRequest(0, AvailabilityType.Operative); + + // When + core.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleChangeAvailabilityRequest(eq(request)); + } + + @Test + public void + handleRequest_aRemoteStartTransactionRequest_callsHandleRemoteStartTransactionRequest() { + // Given + RemoteStartTransactionRequest request = new RemoteStartTransactionRequest("test123"); + + // When + core.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleRemoteStartTransactionRequest(eq(request)); + } + + @Test + public void + handleRequest_aRemoteStopTransactionRequest_callsHandleRemoteStopTransactionRequest() { + // Given + RemoteStopTransactionRequest request = new RemoteStopTransactionRequest(0); + + // When + core.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleRemoteStopTransactionRequest(eq(request)); + } + + @Test + public void handleRequest_aResetRequest_callsHandleResetRequest() { + // Given + ResetRequest request = new ResetRequest(ResetType.Hard); + + // When + core.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleResetRequest(eq(request)); + } + + @Test + public void handleRequest_anUnlockConnectorRequest_callsHandleUnlockConnectorRequest() { + // Given + UnlockConnectorRequest request = new UnlockConnectorRequest(1); + + // When + core.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleUnlockConnectorRequest(eq(request)); + } + + @Test + public void handleRequest_aChangeAvailabilityRequest_returnsChangeAvailabilityConfirmation() { + // Given + when(handler.handleChangeAvailabilityRequest(any())) + .thenReturn(new ChangeAvailabilityConfirmation(AvailabilityStatus.Accepted)); + ChangeAvailabilityRequest request = new ChangeAvailabilityRequest(0, AvailabilityType.Operative); + + // When + Confirmation conf = core.handleRequest(SESSION_NULL, request); + + // Then + assertThat(conf, instanceOf(ChangeAvailabilityConfirmation.class)); + } + + @Test + public void handleRequest_aGetConfigurationRequest_callsHandleGetConfigurationRequest() { + // Given + GetConfigurationRequest request = new GetConfigurationRequest(); + + // When + core.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleGetConfigurationRequest(eq(request)); + } + + @Test + public void handleRequest_aGetConfigurationRequest_returnGetConfigurationConfirmation() { + // Given + when(handler.handleGetConfigurationRequest(any())) + .thenReturn(new GetConfigurationConfirmation()); + GetConfigurationRequest request = new GetConfigurationRequest(); + + // When + Confirmation conf = core.handleRequest(SESSION_NULL, request); + + // Then + assertThat(conf, instanceOf(GetConfigurationConfirmation.class)); + } + + @Test + public void handleRequest_aDataTransferRequest_callsHandleDataTransferRequest() { + // Given + DataTransferRequest request = new DataTransferRequest("vendorId"); + + // When + core.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleDataTransferRequest(eq(request)); + } + + @Test + public void handleRequest_aDataTransferRequest_returnDataTransferConfirmation() { + // Given + when(handler.handleDataTransferRequest(any())).thenReturn(new DataTransferConfirmation()); + DataTransferRequest request = new DataTransferRequest("vendorId"); + + // When + Confirmation conf = core.handleRequest(SESSION_NULL, request); + + // Then + assertThat(conf, instanceOf(DataTransferConfirmation.class)); + } + + @Test + public void handleRequest_aChangeConfigurationRequest_callsHandleChangeConfigurationRequest() { + // Given + ChangeConfigurationRequest request = new ChangeConfigurationRequest("key", "value"); + + // When + core.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleChangeConfigurationRequest(eq(request)); + } + + @Test + public void handleRequest_aChangeConfigurationRequest_returnsChangeConfigurationConfirmation() { + // Given + when(handler.handleChangeConfigurationRequest(any())) + .thenReturn(new ChangeConfigurationConfirmation(ConfigurationStatus.Accepted)); + ChangeConfigurationRequest request = new ChangeConfigurationRequest("key", "value"); + + // When + Confirmation conf = core.handleRequest(SESSION_NULL, request); + + // Then + assertThat(conf, instanceOf(ChangeConfigurationConfirmation.class)); + } + + @Test + public void handleRequest_aClearCacheRequest_callsHandleClearCacheRequest() { + // Given + ClearCacheRequest request = new ClearCacheRequest(); + + // When + core.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleClearCacheRequest(request); + } + + @Test + public void handleRequest_aClearCacheRequest_returnsClearCacheConfirmation() { + // Given + when(handler.handleClearCacheRequest(any())).thenReturn(new ClearCacheConfirmation()); + ClearCacheRequest request = new ClearCacheRequest(); + + // When + Confirmation conf = core.handleRequest(SESSION_NULL, request); + + // Then + assertThat(conf, instanceOf(ClearCacheConfirmation.class)); + } } 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 45db720fb..8fee5b04a 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 @@ -5,6 +5,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -25,127 +26,129 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -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; - 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.*; -import java.util.UUID; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.time.ZonedDateTime; +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 ClientFirmwareManagementProfileTest extends ProfileTest { - private static final UUID SESSION_NULL = null; - ClientFirmwareManagementProfile profile; - - @Mock private ClientFirmwareManagementEventHandler handler; - - @Before - public void setup() { - profile = new ClientFirmwareManagementProfile(handler); - } - - @Test - public void getFeatureList_containsGetDiagnosticsFeature() { - // When - Feature[] features = profile.getFeatureList(); - - // Then - 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 - GetDiagnosticsRequest request = new GetDiagnosticsRequest(); - - // When - profile.handleRequest(SESSION_NULL, request); - - // Then - verify(handler, times(1)).handleGetDiagnosticsRequest(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)); - } - - @Test - public void - createDiagnosticsStatusNotificationRequest_withStatus_returnsDiagnosticsStatusNotificationRequestWithStatus() { - // Given - DiagnosticsStatus status = DiagnosticsStatus.Idle; - - // When - DiagnosticsStatusNotificationRequest result = - profile.createDiagnosticsStatusNotificationRequest(status); - - // Then - assertThat(result.getStatus(), is(status)); - } - - @Test - public void - createFirmwareStatusNotificationRequest_withStatus_returnsFirmwareStatusNotificationRequestWithStatus() { - // Given - FirmwareStatus status = FirmwareStatus.Idle; - - // When - FirmwareStatusNotificationRequest result = - profile.createFirmwareStatusNotificationRequest(status); - - // Then - assertThat(result.getStatus(), is(status)); - } + private static final UUID SESSION_NULL = null; + ClientFirmwareManagementProfile profile; + + @Mock private ClientFirmwareManagementEventHandler handler; + + @Before + public void setup() { + profile = new ClientFirmwareManagementProfile(handler); + } + + @Test + public void getFeatureList_containsGetDiagnosticsFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + 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 + GetDiagnosticsRequest request = new GetDiagnosticsRequest("location"); + + // When + profile.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleGetDiagnosticsRequest(eq(request)); + } + + @Test + public void handleRequest_aUpdateFirmwareRequest_callsHandleUpdateFirmwareRequest() { + // Given + UpdateFirmwareRequest request = new UpdateFirmwareRequest("location", ZonedDateTime.now()); + + // When + profile.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleUpdateFirmwareRequest(eq(request)); + } + + @Test + public void + createDiagnosticsStatusNotificationRequest_withStatus_returnsDiagnosticsStatusNotificationRequestWithStatus() { + // Given + DiagnosticsStatus status = DiagnosticsStatus.Idle; + + // When + DiagnosticsStatusNotificationRequest result = + profile.createDiagnosticsStatusNotificationRequest(status); + + // Then + assertThat(result.getStatus(), is(status)); + } + + @Test + public void + createFirmwareStatusNotificationRequest_withStatus_returnsFirmwareStatusNotificationRequestWithStatus() { + // Given + FirmwareStatus status = FirmwareStatus.Idle; + + // When + FirmwareStatusNotificationRequest result = + profile.createFirmwareStatusNotificationRequest(status); + + // Then + assertThat(result.getStatus(), is(status)); + } } 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 c641c2357..bd1be7f39 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 @@ -1,11 +1,29 @@ package eu.chargetime.ocpp.feature.profile.test; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.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; +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2019 Kevin Raddatz + * + * 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; @@ -14,66 +32,75 @@ import eu.chargetime.ocpp.feature.profile.ClientLocalAuthListProfile; import eu.chargetime.ocpp.model.localauthlist.GetLocalListVersionRequest; import eu.chargetime.ocpp.model.localauthlist.SendLocalListRequest; -import java.util.UUID; +import eu.chargetime.ocpp.model.localauthlist.UpdateType; 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.CoreMatchers.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 ClientLocalAuthListProfileTest extends ProfileTest { - private static final UUID SESSION_NULL = null; + private static final UUID SESSION_NULL = null; - private ClientLocalAuthListProfile profile; + private ClientLocalAuthListProfile profile; - @Mock private ClientLocalAuthListEventHandler handler; + @Mock private ClientLocalAuthListEventHandler handler; - @Before - public void setup() { - profile = new ClientLocalAuthListProfile(handler); - } + @Before + public void setup() { + profile = new ClientLocalAuthListProfile(handler); + } - @Test - public void getFeatureList_containsGetLocalListVersionFeature() { - // When - Feature[] featureList = profile.getFeatureList(); + @Test + public void getFeatureList_containsGetLocalListVersionFeature() { + // When + Feature[] featureList = profile.getFeatureList(); - // Then - assertThat( - findFeature(featureList, "GetLocalListVersion"), - is(instanceOf(GetLocalListVersionFeature.class))); - } + // Then + assertThat( + findFeature(featureList, "GetLocalListVersion"), + is(instanceOf(GetLocalListVersionFeature.class))); + } - @Test - public void getFeatureList_containsSendLocalListFeature() { - // When - Feature[] featureList = profile.getFeatureList(); + @Test + public void getFeatureList_containsSendLocalListFeature() { + // When + Feature[] featureList = profile.getFeatureList(); - // Then - assertThat( - findFeature(featureList, "SendLocalList"), is(instanceOf(SendLocalListFeature.class))); - } + // Then + assertThat( + findFeature(featureList, "SendLocalList"), is(instanceOf(SendLocalListFeature.class))); + } - public void handleRequest_GetLocalListVersion_callsHandleGetLocalListVersionRequest() { - // Given - GetLocalListVersionRequest request = new GetLocalListVersionRequest(); + public void handleRequest_GetLocalListVersion_callsHandleGetLocalListVersionRequest() { + // Given + GetLocalListVersionRequest request = new GetLocalListVersionRequest(); - // When - profile.handleRequest(SESSION_NULL, request); + // When + profile.handleRequest(SESSION_NULL, request); - // Then - verify(handler, times(1)).handleGetLocalListVersionRequest(eq(request)); - } + // Then + verify(handler, times(1)).handleGetLocalListVersionRequest(eq(request)); + } - public void handleRequest_SendLocalList_callsHandleSendLocalListRequest() { - // Given - SendLocalListRequest request = new SendLocalListRequest(); + public void handleRequest_SendLocalList_callsHandleSendLocalListRequest() { + // Given + SendLocalListRequest request = new SendLocalListRequest(0, UpdateType.Full); - // When - profile.handleRequest(SESSION_NULL, request); + // When + profile.handleRequest(SESSION_NULL, request); - // Then - verify(handler, times(1)).handleSendLocalListRequest(eq(request)); - } + // Then + verify(handler, times(1)).handleSendLocalListRequest(eq(request)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientRemoteTriggerProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientRemoteTriggerProfileTest.java index 3b627802c..3a5fd5e20 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientRemoteTriggerProfileTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientRemoteTriggerProfileTest.java @@ -1,27 +1,31 @@ package eu.chargetime.ocpp.feature.profile.test; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; - -import eu.chargetime.ocpp.feature.profile.ClientRemoteTriggerHandler; +import eu.chargetime.ocpp.feature.profile.ClientRemoteTriggerEventHandler; import eu.chargetime.ocpp.feature.profile.ClientRemoteTriggerProfile; import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageConfirmation; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest; -import java.util.UUID; +import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequestType; +import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageStatus; 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.junit.Assert.assertThat; +import static org.mockito.Mockito.*; + /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2017 Emil Christopher Solli Melar + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -45,38 +49,38 @@ @RunWith(MockitoJUnitRunner.class) public class ClientRemoteTriggerProfileTest { - private static final UUID SESSION_NULL = null; - private ClientRemoteTriggerProfile profile; + private static final UUID SESSION_NULL = null; + private ClientRemoteTriggerProfile profile; - @Mock private ClientRemoteTriggerHandler handler; + @Mock private ClientRemoteTriggerEventHandler handler; - @Before - public void setup() { - profile = new ClientRemoteTriggerProfile(handler); - } + @Before + public void setup() { + profile = new ClientRemoteTriggerProfile(handler); + } - @Test - public void handleRequest_TriggerMessageReqest_callsHandleTriggerMessageReqestRequest() { - // Given - TriggerMessageRequest request = new TriggerMessageRequest(); + @Test + public void handleRequest_TriggerMessageReqest_callsHandleTriggerMessageReqestRequest() { + // Given + TriggerMessageRequest request = new TriggerMessageRequest(TriggerMessageRequestType.BootNotification); - // When - profile.handleRequest(SESSION_NULL, request); + // When + profile.handleRequest(SESSION_NULL, request); - // Then - verify(handler, times(1)).handleTriggerMessageRequest(request); - } + // Then + verify(handler, times(1)).handleTriggerMessageRequest(request); + } - @Test - public void handleRequest_SetTriggerMessageRequest_returnsTriggerMessageRequest() { - // Given - when(handler.handleTriggerMessageRequest(any())).thenReturn(new TriggerMessageConfirmation()); - TriggerMessageRequest request = new TriggerMessageRequest(); + @Test + public void handleRequest_SetTriggerMessageRequest_returnsTriggerMessageRequest() { + // Given + when(handler.handleTriggerMessageRequest(any())).thenReturn(new TriggerMessageConfirmation(TriggerMessageStatus.Accepted)); + TriggerMessageRequest request = new TriggerMessageRequest(TriggerMessageRequestType.BootNotification); - // When - Confirmation conf = profile.handleRequest(SESSION_NULL, request); + // When + Confirmation conf = profile.handleRequest(SESSION_NULL, request); - // Then - assertThat(conf, instanceOf(TriggerMessageConfirmation.class)); - } + // Then + assertThat(conf, instanceOf(TriggerMessageConfirmation.class)); + } } 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 index e6b83e854..8ae7e2c21 100644 --- 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 @@ -6,6 +6,7 @@ Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2018 Mikhail Kladkevich + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -26,77 +27,81 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -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; - -import eu.chargetime.ocpp.feature.*; +import eu.chargetime.ocpp.feature.CancelReservationFeature; +import eu.chargetime.ocpp.feature.Feature; +import eu.chargetime.ocpp.feature.ReserveNowFeature; 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 java.util.UUID; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.time.ZonedDateTime; +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)); - } + 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(0, ZonedDateTime.now(), "idTag", 0); + + // 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(0); + + // When + profile.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleCancelReservationRequest(eq(request)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientSmartChargingProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientSmartChargingProfileTest.java index 5ac7c3577..1316b2f73 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientSmartChargingProfileTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ClientSmartChargingProfileTest.java @@ -1,27 +1,29 @@ package eu.chargetime.ocpp.feature.profile.test; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; - import eu.chargetime.ocpp.feature.profile.ClientSmartChargingEventHandler; import eu.chargetime.ocpp.feature.profile.ClientSmartChargingProfile; import eu.chargetime.ocpp.model.Confirmation; -import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileConfirmation; -import eu.chargetime.ocpp.model.smartcharging.SetChargingProfileRequest; -import java.util.UUID; +import eu.chargetime.ocpp.model.core.ChargingProfile; +import eu.chargetime.ocpp.model.smartcharging.*; 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.junit.Assert.assertThat; +import static org.mockito.Mockito.*; + /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2017 Emil Christopher Solli Melar + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -45,39 +47,66 @@ @RunWith(MockitoJUnitRunner.class) public class ClientSmartChargingProfileTest { - private static final UUID SESSION_NULL = null; - private ClientSmartChargingProfile smartCharging; + private static final UUID SESSION_NULL = null; + private ClientSmartChargingProfile smartCharging; + + @Mock private ClientSmartChargingEventHandler handler; + + @Before + public void setup() { + smartCharging = new ClientSmartChargingProfile(handler); + } + + @Test + public void handleRequest_SetChargingProfileRequest_callsHandleSetChargingProfileRequest() { + // Given + SetChargingProfileRequest request = new SetChargingProfileRequest(0, new ChargingProfile()); + + // When + smartCharging.handleRequest(SESSION_NULL, request); + + // Then + verify(handler, times(1)).handleSetChargingProfileRequest(request); + } + + @Test + public void handleRequest_SetChargingProfileRequest_returnsSetChargingProfileConfirmation() { + // Given + when(handler.handleSetChargingProfileRequest(any())) + .thenReturn(new SetChargingProfileConfirmation()); + SetChargingProfileRequest request = new SetChargingProfileRequest(); + + // When + Confirmation conf = smartCharging.handleRequest(SESSION_NULL, request); - @Mock private ClientSmartChargingEventHandler handler; + // Then + assertThat(conf, instanceOf(SetChargingProfileConfirmation.class)); + } - @Before - public void setup() { - smartCharging = new ClientSmartChargingProfile(handler); - } + @Test + public void handleRequest_GetCompositeSchedule_callsHandleGetCompositeScheduleRequest() { + // Given + GetCompositeScheduleRequest request = new GetCompositeScheduleRequest(0, 0); - @Test - public void handleRequest_SetChargingProfileRequest_callsHandleSetChargingProfileRequest() { - // Given - SetChargingProfileRequest request = new SetChargingProfileRequest(); + // When + smartCharging.handleRequest(SESSION_NULL, request); - // When - smartCharging.handleRequest(SESSION_NULL, request); + // Then + verify(handler, times(1)).handleGetCompositeScheduleRequest(request); + } - // Then - verify(handler, times(1)).handleSetChargingProfileRequest(request); - } + @Test + public void handleRequest_GetCompositeScheduleRequest_returnGetCompositeScheduleConfirmation() { + // Given + when(handler.handleGetCompositeScheduleRequest(any())) + .thenReturn(new GetCompositeScheduleConfirmation(GetCompositeScheduleStatus.Accepted)); + GetCompositeScheduleRequest request = new GetCompositeScheduleRequest(0, 0); - @Test - public void handleRequest_SetChargingProfileRequest_returnsSetChargingProfileRequest() { - // Given - when(handler.handleSetChargingProfileRequest(any())) - .thenReturn(new SetChargingProfileConfirmation()); - SetChargingProfileRequest request = new SetChargingProfileRequest(); + // When + Confirmation conf = smartCharging.handleRequest(SESSION_NULL, request); - // When - Confirmation conf = smartCharging.handleRequest(SESSION_NULL, request); + // Then + assertThat(conf, instanceOf(GetCompositeScheduleConfirmation.class)); + } - // Then - assertThat(conf, instanceOf(SetChargingProfileConfirmation.class)); - } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerCoreProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerCoreProfileTest.java index 2b1f0ce42..e8aeea74e 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerCoreProfileTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/feature/profile/test/ServerCoreProfileTest.java @@ -1,62 +1,32 @@ package eu.chargetime.ocpp.feature.profile.test; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.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; - -import eu.chargetime.ocpp.feature.AuthorizeFeature; -import eu.chargetime.ocpp.feature.BootNotificationFeature; -import eu.chargetime.ocpp.feature.ChangeAvailabilityFeature; -import eu.chargetime.ocpp.feature.ChangeConfigurationFeature; -import eu.chargetime.ocpp.feature.ClearCacheFeature; -import eu.chargetime.ocpp.feature.DataTransferFeature; -import eu.chargetime.ocpp.feature.Feature; -import eu.chargetime.ocpp.feature.GetConfigurationFeature; -import eu.chargetime.ocpp.feature.HeartbeatFeature; -import eu.chargetime.ocpp.feature.MeterValuesFeature; -import eu.chargetime.ocpp.feature.RemoteStartTransactionFeature; -import eu.chargetime.ocpp.feature.RemoteStopTransactionFeature; -import eu.chargetime.ocpp.feature.ResetFeature; -import eu.chargetime.ocpp.feature.StartTransactionFeature; -import eu.chargetime.ocpp.feature.StatusNotificationFeature; -import eu.chargetime.ocpp.feature.StopTransactionFeature; -import eu.chargetime.ocpp.feature.UnlockConnectorFeature; +import eu.chargetime.ocpp.feature.*; import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler; import eu.chargetime.ocpp.feature.profile.ServerCoreProfile; -import eu.chargetime.ocpp.model.core.AuthorizeRequest; -import eu.chargetime.ocpp.model.core.AvailabilityType; -import eu.chargetime.ocpp.model.core.BootNotificationRequest; -import eu.chargetime.ocpp.model.core.ChangeAvailabilityRequest; -import eu.chargetime.ocpp.model.core.ChangeConfigurationRequest; -import eu.chargetime.ocpp.model.core.ClearCacheRequest; -import eu.chargetime.ocpp.model.core.DataTransferRequest; -import eu.chargetime.ocpp.model.core.GetConfigurationRequest; -import eu.chargetime.ocpp.model.core.HeartbeatRequest; -import eu.chargetime.ocpp.model.core.MeterValuesRequest; -import eu.chargetime.ocpp.model.core.RemoteStartTransactionRequest; -import eu.chargetime.ocpp.model.core.RemoteStopTransactionRequest; -import eu.chargetime.ocpp.model.core.ResetRequest; -import eu.chargetime.ocpp.model.core.ResetType; -import eu.chargetime.ocpp.model.core.StartTransactionRequest; -import eu.chargetime.ocpp.model.core.StatusNotificationRequest; -import eu.chargetime.ocpp.model.core.StopTransactionRequest; -import eu.chargetime.ocpp.model.core.UnlockConnectorRequest; -import java.util.UUID; +import eu.chargetime.ocpp.model.core.*; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.time.ZonedDateTime; +import java.util.UUID; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.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; + /* ChargeTime.eu - Java-OCA-OCPP MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -80,384 +50,384 @@ of this software and associated documentation files (the "Software"), to deal @RunWith(MockitoJUnitRunner.class) public class ServerCoreProfileTest extends ProfileTest { - private ServerCoreProfile core; - - @Mock private ServerCoreEventHandler handler; - - @Before - public void setup() { - core = new ServerCoreProfile(handler); - } - - @Test - public void getFeatureList_containsAuthorizeFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat(findFeature(features, "Authorize"), is(instanceOf(AuthorizeFeature.class))); - } - - @Test - public void handleRequest_anAuthorizeRequest_callsHandleAuthorizeRequest() { - // Given - AuthorizeRequest request = new AuthorizeRequest(); - UUID sessionId = UUID.randomUUID(); - - // When - core.handleRequest(sessionId, request); - - // Then - verify(handler, times(1)).handleAuthorizeRequest(eq(sessionId), eq(request)); - } - - @Test - public void getFeatureList_containsBootNotificatonFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "BootNotification"), is(instanceOf(BootNotificationFeature.class))); - } - - @Test - public void handleRequest_aBootNotificationRequest_callsHandleBootNotificationRequest() { - // Given - BootNotificationRequest request = new BootNotificationRequest(); - UUID sessionId = UUID.randomUUID(); - - // When - core.handleRequest(sessionId, request); - - // Then - verify(handler, times(1)).handleBootNotificationRequest(eq(sessionId), eq(request)); - } - - @Test - public void getFeatureList_containsChangeAvailabilityFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "ChangeAvailability"), - is(instanceOf(ChangeAvailabilityFeature.class))); - } - - @Test - public void - createChangeAvailabilityRequest_withTypeAndConnectorId_returnsValidChangeAvailabilityRequest() { - // Given - AvailabilityType type = AvailabilityType.Operative; - int connectorId = 1; - - // When - ChangeAvailabilityRequest result = core.createChangeAvailabilityRequest(type, connectorId); - - // Then - assertThat(result.validate(), is(true)); - } - - @Test - public void getFeatureList_containsChangeConfigurationFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "ChangeConfiguration"), - is(instanceOf(ChangeConfigurationFeature.class))); - } - - @Test - public void - createChangeConfigurationRequest_withKeyAndValue_returnsValidChangeConfigurationRequest() { - // Given - String key = "some key"; - String value = "some value"; - - // When - ChangeConfigurationRequest result = core.createChangeConfigurationRequest(key, value); - - // Then - assertThat(result.validate(), is(true)); - } - - @Test - public void getFeatureList_containsClearCacheFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat(findFeature(features, "ClearCache"), is(instanceOf(ClearCacheFeature.class))); - } - - @Test - public void createClearCacheRequest_returnsValidClearCacheRequest() { - // When - ClearCacheRequest result = core.createClearCacheRequest(); - - // Then - assertThat(result.validate(), is(true)); - } - - @Test - public void getFeatureList_containsDataTransferFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat(findFeature(features, "DataTransfer"), is(instanceOf(DataTransferFeature.class))); - } - - @Test - public void createChangeConfigurationRequest_withVendorId_returnsValidDataTransferRequest() { - // Given - String vendorId = "some vendorId"; - - // When - DataTransferRequest result = core.createDataTransferRequest(vendorId); - - // Then - assertThat(result.validate(), is(true)); - } - - @Test - public void handleRequest_aDataTransferRequest_callsHandleDataTransferRequest() { - // Given - DataTransferRequest request = new DataTransferRequest(); - UUID sessionId = UUID.randomUUID(); - - // When - core.handleRequest(sessionId, request); - - // Then - verify(handler, times(1)).handleDataTransferRequest(eq(sessionId), eq(request)); - } - - @Test - public void getFeatureList_containsGetConfigurationFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "GetConfiguration"), is(instanceOf(GetConfigurationFeature.class))); - } - - @Test - public void createGetConfigurationRequest_returnsValidGetConfigurationRequest() { - - // When - GetConfigurationRequest result = core.createGetConfigurationRequest(); - - // Then - assertThat(result.validate(), is(true)); - } - - @Test - public void getFeatureList_containsHeartbeatFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat(findFeature(features, "Heartbeat"), is(instanceOf(HeartbeatFeature.class))); - } - - @Test - public void handleRequest_aHeartbeatRequest_callsHandleHeartbeatRequest() { - // Given - HeartbeatRequest request = new HeartbeatRequest(); - UUID sessionId = UUID.randomUUID(); - - // When - core.handleRequest(sessionId, request); - - // Then - verify(handler, times(1)).handleHeartbeatRequest(eq(sessionId), eq(request)); - } - - @Test - public void getFeatureList_containsMeterValuesFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat(findFeature(features, "MeterValues"), is(instanceOf(MeterValuesFeature.class))); - } - - @Test - public void handleRequest_aMeterValuesRequest_callsHandleMeterValuesRequest() { - // Given - MeterValuesRequest request = new MeterValuesRequest(); - UUID sessionId = UUID.randomUUID(); - - // When - core.handleRequest(sessionId, request); - - // Then - verify(handler, times(1)).handleMeterValuesRequest(eq(sessionId), eq(request)); - } - - @Test - public void getFeatureList_containsRemoteStartTransactionFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "RemoteStartTransaction"), - is(instanceOf(RemoteStartTransactionFeature.class))); - } - - @Test - public void - createRemoteStartTransactionRequest_withIdToken_returnsValidRemoteStartTransactionRequest() { - // Given - String idToken = "Some IdToken"; - - // When - RemoteStartTransactionRequest result = core.createRemoteStartTransactionRequest(idToken); - - // Then - assertThat(result.validate(), is(true)); - } - - @Test - public void getFeatureList_containsRemoteStopTransactionFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "RemoteStopTransaction"), - is(instanceOf(RemoteStopTransactionFeature.class))); - } - - @Test - public void - createRemoteStopTransactionRequest_withTransactionId_returnsValidRemoteStopTransactionRequest() { - // Given - Integer transactionId = 42; - - // When - RemoteStopTransactionRequest result = core.createRemoteStopTransactionRequest(transactionId); - - // Then - assertThat(result.validate(), is(true)); - } - - @Test - public void getFeatureList_containsResetFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat(findFeature(features, "Reset"), is(instanceOf(ResetFeature.class))); - } - - @Test - public void createResetRequest_withType_returnsValidResetRequest() { - // Given - ResetType type = ResetType.Hard; - - // When - ResetRequest result = core.createResetRequest(type); - - // Then - assertThat(result.validate(), is(true)); - } - - @Test - public void getFeatureList_containsStartTransactionFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "StartTransaction"), is(instanceOf(StartTransactionFeature.class))); - } - - @Test - public void handleRequest_aStartTransactionRequest_callsHandleStartTransactionRequest() { - // Given - StartTransactionRequest request = new StartTransactionRequest(); - UUID sessionId = UUID.randomUUID(); - - // When - core.handleRequest(sessionId, request); - - // Then - verify(handler, times(1)).handleStartTransactionRequest(eq(sessionId), eq(request)); - } - - @Test - public void getFeatureList_containsStatusNotificationFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "StatusNotification"), - is(instanceOf(StatusNotificationFeature.class))); - } - - @Test - public void handleRequest_aStatusNotificationRequest_callsHandleStatusNotificationRequest() { - // Given - StatusNotificationRequest request = new StatusNotificationRequest(); - UUID sessionId = UUID.randomUUID(); - - // When - core.handleRequest(sessionId, request); - - // Then - verify(handler, times(1)).handleStatusNotificationRequest(eq(sessionId), eq(request)); - } - - @Test - public void getFeatureList_containsStopTransactionFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "StopTransaction"), is(instanceOf(StopTransactionFeature.class))); - } - - @Test - public void handleRequest_aStopTransactionRequest_callsHandleStopTransactionRequest() { - // Given - StopTransactionRequest request = new StopTransactionRequest(); - UUID sessionId = UUID.randomUUID(); - - // When - core.handleRequest(sessionId, request); - - // Then - verify(handler, times(1)).handleStopTransactionRequest(eq(sessionId), eq(request)); - } - - @Test - public void getFeatureList_containsUnlockConnectorFeature() { - // When - Feature[] features = core.getFeatureList(); - - // Then - assertThat( - findFeature(features, "UnlockConnector"), is(instanceOf(UnlockConnectorFeature.class))); - } - - @Test - public void createUnlockConnectorRequest_withConnectorId_returnsValidUnlockConnectorRequest() { - // Given - int connectorId = 42; - - // When - UnlockConnectorRequest result = core.createUnlockConnectorRequest(connectorId); - - // Then - assertThat(result.validate(), is(true)); - } + private ServerCoreProfile core; + + @Mock private ServerCoreEventHandler handler; + + @Before + public void setup() { + core = new ServerCoreProfile(handler); + } + + @Test + public void getFeatureList_containsAuthorizeFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat(findFeature(features, "Authorize"), is(instanceOf(AuthorizeFeature.class))); + } + + @Test + public void handleRequest_anAuthorizeRequest_callsHandleAuthorizeRequest() { + // Given + AuthorizeRequest request = new AuthorizeRequest("idTag"); + UUID sessionId = UUID.randomUUID(); + + // When + core.handleRequest(sessionId, request); + + // Then + verify(handler, times(1)).handleAuthorizeRequest(eq(sessionId), eq(request)); + } + + @Test + public void getFeatureList_containsBootNotificatonFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "BootNotification"), is(instanceOf(BootNotificationFeature.class))); + } + + @Test + public void handleRequest_aBootNotificationRequest_callsHandleBootNotificationRequest() { + // Given + BootNotificationRequest request = new BootNotificationRequest("vendor", "model"); + UUID sessionId = UUID.randomUUID(); + + // When + core.handleRequest(sessionId, request); + + // Then + verify(handler, times(1)).handleBootNotificationRequest(eq(sessionId), eq(request)); + } + + @Test + public void getFeatureList_containsChangeAvailabilityFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "ChangeAvailability"), + is(instanceOf(ChangeAvailabilityFeature.class))); + } + + @Test + public void + createChangeAvailabilityRequest_withTypeAndConnectorId_returnsValidChangeAvailabilityRequest() { + // Given + AvailabilityType type = AvailabilityType.Operative; + int connectorId = 1; + + // When + ChangeAvailabilityRequest result = core.createChangeAvailabilityRequest(type, connectorId); + + // Then + assertThat(result.validate(), is(true)); + } + + @Test + public void getFeatureList_containsChangeConfigurationFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "ChangeConfiguration"), + is(instanceOf(ChangeConfigurationFeature.class))); + } + + @Test + public void + createChangeConfigurationRequest_withKeyAndValue_returnsValidChangeConfigurationRequest() { + // Given + String key = "some key"; + String value = "some value"; + + // When + ChangeConfigurationRequest result = core.createChangeConfigurationRequest(key, value); + + // Then + assertThat(result.validate(), is(true)); + } + + @Test + public void getFeatureList_containsClearCacheFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat(findFeature(features, "ClearCache"), is(instanceOf(ClearCacheFeature.class))); + } + + @Test + public void createClearCacheRequest_returnsValidClearCacheRequest() { + // When + ClearCacheRequest result = core.createClearCacheRequest(); + + // Then + assertThat(result.validate(), is(true)); + } + + @Test + public void getFeatureList_containsDataTransferFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat(findFeature(features, "DataTransfer"), is(instanceOf(DataTransferFeature.class))); + } + + @Test + public void createChangeConfigurationRequest_withVendorId_returnsValidDataTransferRequest() { + // Given + String vendorId = "some vendorId"; + + // When + DataTransferRequest result = core.createDataTransferRequest(vendorId); + + // Then + assertThat(result.validate(), is(true)); + } + + @Test + public void handleRequest_aDataTransferRequest_callsHandleDataTransferRequest() { + // Given + DataTransferRequest request = new DataTransferRequest("vendor"); + UUID sessionId = UUID.randomUUID(); + + // When + core.handleRequest(sessionId, request); + + // Then + verify(handler, times(1)).handleDataTransferRequest(eq(sessionId), eq(request)); + } + + @Test + public void getFeatureList_containsGetConfigurationFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "GetConfiguration"), is(instanceOf(GetConfigurationFeature.class))); + } + + @Test + public void createGetConfigurationRequest_returnsValidGetConfigurationRequest() { + + // When + GetConfigurationRequest result = core.createGetConfigurationRequest(); + + // Then + assertThat(result.validate(), is(true)); + } + + @Test + public void getFeatureList_containsHeartbeatFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat(findFeature(features, "Heartbeat"), is(instanceOf(HeartbeatFeature.class))); + } + + @Test + public void handleRequest_aHeartbeatRequest_callsHandleHeartbeatRequest() { + // Given + HeartbeatRequest request = new HeartbeatRequest(); + UUID sessionId = UUID.randomUUID(); + + // When + core.handleRequest(sessionId, request); + + // Then + verify(handler, times(1)).handleHeartbeatRequest(eq(sessionId), eq(request)); + } + + @Test + public void getFeatureList_containsMeterValuesFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat(findFeature(features, "MeterValues"), is(instanceOf(MeterValuesFeature.class))); + } + + @Test + public void handleRequest_aMeterValuesRequest_callsHandleMeterValuesRequest() { + // Given + MeterValuesRequest request = new MeterValuesRequest(0); + UUID sessionId = UUID.randomUUID(); + + // When + core.handleRequest(sessionId, request); + + // Then + verify(handler, times(1)).handleMeterValuesRequest(eq(sessionId), eq(request)); + } + + @Test + public void getFeatureList_containsRemoteStartTransactionFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "RemoteStartTransaction"), + is(instanceOf(RemoteStartTransactionFeature.class))); + } + + @Test + public void + createRemoteStartTransactionRequest_withIdToken_returnsValidRemoteStartTransactionRequest() { + // Given + String idToken = "Some IdToken"; + + // When + RemoteStartTransactionRequest result = core.createRemoteStartTransactionRequest(idToken); + + // Then + assertThat(result.validate(), is(true)); + } + + @Test + public void getFeatureList_containsRemoteStopTransactionFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "RemoteStopTransaction"), + is(instanceOf(RemoteStopTransactionFeature.class))); + } + + @Test + public void + createRemoteStopTransactionRequest_withTransactionId_returnsValidRemoteStopTransactionRequest() { + // Given + Integer transactionId = 42; + + // When + RemoteStopTransactionRequest result = core.createRemoteStopTransactionRequest(transactionId); + + // Then + assertThat(result.validate(), is(true)); + } + + @Test + public void getFeatureList_containsResetFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat(findFeature(features, "Reset"), is(instanceOf(ResetFeature.class))); + } + + @Test + public void createResetRequest_withType_returnsValidResetRequest() { + // Given + ResetType type = ResetType.Hard; + + // When + ResetRequest result = core.createResetRequest(type); + + // Then + assertThat(result.validate(), is(true)); + } + + @Test + public void getFeatureList_containsStartTransactionFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "StartTransaction"), is(instanceOf(StartTransactionFeature.class))); + } + + @Test + public void handleRequest_aStartTransactionRequest_callsHandleStartTransactionRequest() { + // Given + StartTransactionRequest request = new StartTransactionRequest(1, "idTag", 0, ZonedDateTime.now()); + UUID sessionId = UUID.randomUUID(); + + // When + core.handleRequest(sessionId, request); + + // Then + verify(handler, times(1)).handleStartTransactionRequest(eq(sessionId), eq(request)); + } + + @Test + public void getFeatureList_containsStatusNotificationFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "StatusNotification"), + is(instanceOf(StatusNotificationFeature.class))); + } + + @Test + public void handleRequest_aStatusNotificationRequest_callsHandleStatusNotificationRequest() { + // Given + StatusNotificationRequest request = new StatusNotificationRequest(0, ChargePointErrorCode.InternalError, ChargePointStatus.Charging); + UUID sessionId = UUID.randomUUID(); + + // When + core.handleRequest(sessionId, request); + + // Then + verify(handler, times(1)).handleStatusNotificationRequest(eq(sessionId), eq(request)); + } + + @Test + public void getFeatureList_containsStopTransactionFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "StopTransaction"), is(instanceOf(StopTransactionFeature.class))); + } + + @Test + public void handleRequest_aStopTransactionRequest_callsHandleStopTransactionRequest() { + // Given + StopTransactionRequest request = new StopTransactionRequest(0, ZonedDateTime.now(), 0); + UUID sessionId = UUID.randomUUID(); + + // When + core.handleRequest(sessionId, request); + + // Then + verify(handler, times(1)).handleStopTransactionRequest(eq(sessionId), eq(request)); + } + + @Test + public void getFeatureList_containsUnlockConnectorFeature() { + // When + Feature[] features = core.getFeatureList(); + + // Then + assertThat( + findFeature(features, "UnlockConnector"), is(instanceOf(UnlockConnectorFeature.class))); + } + + @Test + public void createUnlockConnectorRequest_withConnectorId_returnsValidUnlockConnectorRequest() { + // Given + int connectorId = 42; + + // When + UnlockConnectorRequest result = core.createUnlockConnectorRequest(connectorId); + + // Then + assertThat(result.validate(), is(true)); + } } 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 59f563b51..315254962 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 @@ -5,6 +5,7 @@ MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -25,18 +26,13 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - import eu.chargetime.ocpp.feature.*; import eu.chargetime.ocpp.feature.profile.ServerFirmwareManagementEventHandler; import eu.chargetime.ocpp.feature.profile.ServerFirmwareManagementProfile; +import eu.chargetime.ocpp.model.firmware.DiagnosticsStatus; import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest; +import eu.chargetime.ocpp.model.firmware.FirmwareStatus; import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest; -import java.util.UUID; import org.hamcrest.core.Is; import org.junit.Before; import org.junit.Test; @@ -44,85 +40,93 @@ of this software and associated documentation files (the "Software"), to deal import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.util.UUID; + +import static org.hamcrest.CoreMatchers.instanceOf; +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 ServerFirmwareManagementProfileTest extends ProfileTest { - ServerFirmwareManagementProfile profile; - - @Mock private ServerFirmwareManagementEventHandler handler; - - @Before - public void setup() { - profile = new ServerFirmwareManagementProfile(handler); - } - - @Test - public void getFeatureList_containsGetDiagnosticsFeature() { - // When - Feature[] features = profile.getFeatureList(); - - // Then - 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))); - } - - @Test - public void - handleRequest_aDiagnosticsStatusNotificationRequest_callsHandleDiagnosticsStatusNotificationRequest() { - // Given - DiagnosticsStatusNotificationRequest request = new DiagnosticsStatusNotificationRequest(); - UUID sessionId = UUID.randomUUID(); - - // When - profile.handleRequest(sessionId, request); - - // Then - verify(handler, times(1)) - .handleDiagnosticsStatusNotificationRequest(eq(sessionId), eq(request)); - } - - @Test - public void - handleRequest_aFirmwareStatusNotificationRequest_callsHandleFirmwareStatusNotificationRequest() { - // Given - FirmwareStatusNotificationRequest request = new FirmwareStatusNotificationRequest(); - UUID sessionId = UUID.randomUUID(); - - // When - profile.handleRequest(sessionId, request); - - // Then - verify(handler, times(1)).handleFirmwareStatusNotificationRequest(eq(sessionId), eq(request)); - } + ServerFirmwareManagementProfile profile; + + @Mock private ServerFirmwareManagementEventHandler handler; + + @Before + public void setup() { + profile = new ServerFirmwareManagementProfile(handler); + } + + @Test + public void getFeatureList_containsGetDiagnosticsFeature() { + // When + Feature[] features = profile.getFeatureList(); + + // Then + 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))); + } + + @Test + public void + handleRequest_aDiagnosticsStatusNotificationRequest_callsHandleDiagnosticsStatusNotificationRequest() { + // Given + DiagnosticsStatusNotificationRequest request = new DiagnosticsStatusNotificationRequest(DiagnosticsStatus.Idle); + UUID sessionId = UUID.randomUUID(); + + // When + profile.handleRequest(sessionId, request); + + // Then + verify(handler, times(1)) + .handleDiagnosticsStatusNotificationRequest(eq(sessionId), eq(request)); + } + + @Test + public void + handleRequest_aFirmwareStatusNotificationRequest_callsHandleFirmwareStatusNotificationRequest() { + // Given + FirmwareStatusNotificationRequest request = new FirmwareStatusNotificationRequest(FirmwareStatus.Downloaded); + UUID sessionId = UUID.randomUUID(); + + // When + profile.handleRequest(sessionId, request); + + // Then + verify(handler, times(1)).handleFirmwareStatusNotificationRequest(eq(sessionId), eq(request)); + } } 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 index 64929b75c..4082b75a5 100644 --- 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 @@ -6,6 +6,7 @@ Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2018 Mikhail Kladkevich + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -26,120 +27,119 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.firmware.UpdateFirmwareRequest; -import java.util.Calendar; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import java.time.ZonedDateTime; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + public class UpdateFirmwareRequestTest { - @Rule public ExpectedException thrownException = ExpectedException.none(); + @Rule public ExpectedException thrownException = ExpectedException.none(); - private UpdateFirmwareRequest request; + private UpdateFirmwareRequest request; - @Before - public void setup() { - request = new UpdateFirmwareRequest(); - } + @Before + public void setup() { + request = new UpdateFirmwareRequest(); + } - @Test - public void validate_locationIsNotSet_returnsFalse() { - // When - boolean result = request.validate(); + @Test + public void validate_locationIsNotSet_returnsFalse() { + // When + boolean result = request.validate(); - // Then - assertThat(result, is(false)); - } + // Then + assertThat(result, is(false)); + } - @Test - public void validate_retrieveDateIsNotSet_returnsFalse() { + @Test + public void validate_retrieveDateIsNotSet_returnsFalse() { - // Given - String aLocation = "/"; - request.setLocation(aLocation); + // Given + String aLocation = "/"; + request.setLocation(aLocation); - // When - boolean result = request.validate(); + // When + boolean result = request.validate(); - // Then - assertThat(result, is(false)); - } + // Then + assertThat(result, is(false)); + } - @Test - public void validate_locationAndRetrieveDateIsSet_returnsTrue() { - // Given - String aLocation = "/"; - Calendar aRetrieveDate = Calendar.getInstance(); - request.setLocation(aLocation); - request.setRetrieveDate(aRetrieveDate); + @Test + public void validate_locationAndRetrieveDateIsSet_returnsTrue() { + // Given + String aLocation = "/"; + ZonedDateTime aRetrieveDate = ZonedDateTime.now(); + request.setLocation(aLocation); + request.setRetrieveDate(aRetrieveDate); - // When - boolean result = request.validate(); + // When + boolean result = request.validate(); - // Then - assertThat(result, is(true)); - } + // Then + assertThat(result, is(true)); + } - @Test - public void setRetries_asNegative_throwsPropertyConstraintException() { - testInvalidRetries(-42); - } + @Test + public void setRetries_asNegative_throwsPropertyConstraintException() { + testInvalidRetries(-42); + } - @Test - public void setRetries_asZero_throwsPropertyConstraintException() { - testInvalidRetries(0); - } + @Test + public void setRetries_asZero_throwsPropertyConstraintException() { + testInvalidRetries(0); + } - private void testInvalidRetries(int retryInvalidRetries) { - defineThrownException( - "Validation failed: [retries must be > 0]. Current Value: [" + retryInvalidRetries + "]"); + private void testInvalidRetries(int retryInvalidRetries) { + defineThrownException( + "Validation failed: [retries must be > 0]. Current Value: [" + retryInvalidRetries + "]"); - request.setRetries(retryInvalidRetries); - } + request.setRetries(retryInvalidRetries); + } - private void defineThrownException(String expectedExceptionMessage) { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage(equalTo(expectedExceptionMessage)); - } + private void defineThrownException(String expectedExceptionMessage) { + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage(equalTo(expectedExceptionMessage)); + } - @Test - public void setRetries_asPositive_isAccepted() { - request.setRetries(42); + @Test + public void setRetries_asPositive_isAccepted() { + request.setRetries(42); - assertThat(request.getRetries(), equalTo(42)); - } + assertThat(request.getRetries(), equalTo(42)); + } - @Test - public void setRetryInterval_asNegative_throwsPropertyConstraintException() { - testInvalidRetryInterval(-42); - } + @Test + public void setRetryInterval_asNegative_throwsPropertyConstraintException() { + testInvalidRetryInterval(-42); + } - @Test - public void setRetryInterval_asZero_throwsPropertyConstraintException() { - testInvalidRetryInterval(0); - } + @Test + public void setRetryInterval_asZero_throwsPropertyConstraintException() { + testInvalidRetryInterval(0); + } - private void testInvalidRetryInterval(int invalidRetryValue) { - defineThrownException( - "Validation failed: [retryInterval must be > 0]. Current Value: [" - + invalidRetryValue - + "]"); + private void testInvalidRetryInterval(int invalidRetryValue) { + defineThrownException( + "Validation failed: [retryInterval must be > 0]. Current Value: [" + + invalidRetryValue + + "]"); - request.setRetryInterval(invalidRetryValue); - } + request.setRetryInterval(invalidRetryValue); + } - @Test - public void setRetryInterval_asPositive_isAccepted() { - request.setRetryInterval(42); + @Test + public void setRetryInterval_asPositive_isAccepted() { + request.setRetryInterval(42); - assertThat(request.getRetryInterval(), equalTo(42)); - } + assertThat(request.getRetryInterval(), equalTo(42)); + } } 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 index d005c39df..b4e72a563 100644 --- 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 @@ -6,6 +6,7 @@ Copyright (C) 2016-2018 Thomas Volden Copyright (C) 2018 Mikhail Kladkevich + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -26,99 +27,98 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.reservation.ReserveNowRequest; -import java.util.Calendar; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import java.time.ZonedDateTime; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + public class ReserveNowRequestTest { - @Rule public ExpectedException thrownException = ExpectedException.none(); - - 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() { - // 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)); - } - - @Test - public void setIdTag_withMoreThan20Chars_throwsPropertyConstraintException() { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage( - equalTo("Validation failed: [Exceeded limit of 20 chars]. Current Value: [26]")); - - request.setIdTag("abcdefghijklmnopqrstuvwxyz"); - } - - @Test - public void setParentIdTag_withMoreThan20Chars_throwsPropertyConstraintException() { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage( - equalTo("Validation failed: [Exceeded limit of 20 chars]. Current Value: [26]")); - - request.setParentIdTag("abcdefghijklmnopqrstuvwxyz"); - } - - @Test - public void setConnectorId_asNegative_throwsPropertyConstraintException() { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage( - equalTo("Validation failed: [connectorId must be >= 0]. Current Value: [-42]")); - - request.setConnectorId(-42); - } - - @Test - public void setConnectorId_asPositive_isValid() { - testValidConnectorId(42); - } - - @Test - public void setConnectorId_asZero_isValid() { - testValidConnectorId(0); - } - - private void testValidConnectorId(int validConnectorId) { - request.setConnectorId(validConnectorId); - - assertThat(request.getConnectorId(), equalTo(validConnectorId)); - } + @Rule public ExpectedException thrownException = ExpectedException.none(); + + 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() { + // Given + Integer connectorId = 0; + ZonedDateTime expiryDate = ZonedDateTime.now(); + 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)); + } + + @Test + public void setIdTag_withMoreThan20Chars_throwsPropertyConstraintException() { + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage( + equalTo("Validation failed: [Exceeded limit of 20 chars]. Current Value: [26]")); + + request.setIdTag("abcdefghijklmnopqrstuvwxyz"); + } + + @Test + public void setParentIdTag_withMoreThan20Chars_throwsPropertyConstraintException() { + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage( + equalTo("Validation failed: [Exceeded limit of 20 chars]. Current Value: [26]")); + + request.setParentIdTag("abcdefghijklmnopqrstuvwxyz"); + } + + @Test + public void setConnectorId_asNegative_throwsPropertyConstraintException() { + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage( + equalTo("Validation failed: [connectorId must be >= 0]. Current Value: [-42]")); + + request.setConnectorId(-42); + } + + @Test + public void setConnectorId_asPositive_isValid() { + testValidConnectorId(42); + } + + @Test + public void setConnectorId_asZero_isValid() { + testValidConnectorId(0); + } + + private void testValidConnectorId(int validConnectorId) { + request.setConnectorId(validConnectorId); + + assertThat(request.getConnectorId(), equalTo(validConnectorId)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/BootNotificationConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/BootNotificationConfirmationTest.java index f54924f0c..5eb3a0915 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/BootNotificationConfirmationTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/BootNotificationConfirmationTest.java @@ -8,7 +8,8 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.core.BootNotificationConfirmation; import eu.chargetime.ocpp.model.core.RegistrationStatus; -import java.util.Calendar; + +import java.time.ZonedDateTime; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -17,10 +18,12 @@ /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -53,7 +56,7 @@ public void setUp() { @Test public void setCurrentTime_now_currentTimeIsSet() { // Given - Calendar now = Calendar.getInstance(); + ZonedDateTime now = ZonedDateTime.now(); // When confirmation.setCurrentTime(now); @@ -101,7 +104,7 @@ public void setStatus_enumValue_statusIsAccepted() { @Test public void validate_currentTimeAndIntervalAndStatusIsSet_returnTrue() { // Given - confirmation.setCurrentTime(Calendar.getInstance()); + confirmation.setCurrentTime(ZonedDateTime.now()); confirmation.setInterval(42); confirmation.setStatus(RegistrationStatus.Accepted); diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/ChargingProfileTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/ChargingProfileTest.java index 3fe8c8d3a..0ba7e9376 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/ChargingProfileTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/ChargingProfileTest.java @@ -1,30 +1,26 @@ package eu.chargetime.ocpp.model.test; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import eu.chargetime.ocpp.PropertyConstraintException; -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.ChargingSchedule; -import eu.chargetime.ocpp.model.core.RecurrencyKindType; -import java.util.Calendar; +import eu.chargetime.ocpp.model.core.*; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import java.time.ZonedDateTime; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -46,189 +42,189 @@ */ public class ChargingProfileTest { - @Rule public ExpectedException thrownException = ExpectedException.none(); + @Rule public ExpectedException thrownException = ExpectedException.none(); - private ChargingProfile chargingProfile; + private ChargingProfile chargingProfile; - @Before - public void setUp() { - chargingProfile = new ChargingProfile(); - } + @Before + public void setUp() { + chargingProfile = new ChargingProfile(); + } - @Test - public void setChargingProfileId_nullValue_throwsPropertyConstraintException() { - defineExpectedException( - "Validation failed: [chargingProfileId must be present]. Current Value: [null]"); + @Test + public void setChargingProfileId_nullValue_throwsPropertyConstraintException() { + defineExpectedException( + "Validation failed: [chargingProfileId must be present]. Current Value: [null]"); - chargingProfile.setChargingProfileId(null); - } + chargingProfile.setChargingProfileId(null); + } - private void defineExpectedException(String expectedExceptionMessage) { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage(equalTo(expectedExceptionMessage)); - } + private void defineExpectedException(String expectedExceptionMessage) { + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage(equalTo(expectedExceptionMessage)); + } - @Test - public void setChargingProfileId_positiveInteger_chargingProfileIdIsSet() { - // Given - int someInteger = 42; + @Test + public void setChargingProfileId_positiveInteger_chargingProfileIdIsSet() { + // Given + int someInteger = 42; - // When - chargingProfile.setChargingProfileId(someInteger); + // When + chargingProfile.setChargingProfileId(someInteger); - // Then - assertThat(chargingProfile.getChargingProfileId(), equalTo(someInteger)); - } + // Then + assertThat(chargingProfile.getChargingProfileId(), equalTo(someInteger)); + } - @Test - public void setTransactionId_someInteger_transactionIdIsSet() { - // Given - Integer someInteger = 42; + @Test + public void setTransactionId_someInteger_transactionIdIsSet() { + // Given + Integer someInteger = 42; - // When - chargingProfile.setTransactionId(someInteger); + // When + chargingProfile.setTransactionId(someInteger); - // Then - assertThat(chargingProfile.getTransactionId(), equalTo(someInteger)); - } + // Then + assertThat(chargingProfile.getTransactionId(), equalTo(someInteger)); + } - @Test - public void setStackLevel_negativeInteger_throwsPropertyConstraintException() { - testStackLeverInvalidValues(-42); - } + @Test + public void setStackLevel_negativeInteger_throwsPropertyConstraintException() { + testStackLeverInvalidValues(-42); + } - @Test - public void setStackLevel_asNullValue_throwsPropertyConstraintException() { - testStackLeverInvalidValues(null); - } - - private void testStackLeverInvalidValues(Integer erroneousValue) { - defineExpectedException( - "Validation failed: [stackLevel must be >= 0]. Current Value: [" + erroneousValue + "]"); - - chargingProfile.setStackLevel(erroneousValue); - } - - @Test - public void setStackLevel_zeroInteger_stackLevelIsSet() { - // Given - int zero = 0; - - // When - chargingProfile.setStackLevel(zero); - - // Then - assertThat(chargingProfile.getStackLevel(), equalTo(zero)); - } - - @Test - public void setChargingProfilePurpose_chargingProfilePurposeType_chargingProfilePurposeIsSet() { - // Given - ChargingProfilePurposeType chargingProfilePurposeType = - ChargingProfilePurposeType.ChargePointMaxProfile; - - // When - chargingProfile.setChargingProfilePurpose(chargingProfilePurposeType); - - // Then - assertThat(chargingProfile.getChargingProfilePurpose(), equalTo(chargingProfilePurposeType)); - } - - @Test - public void setChargingProfileKind_chargingProfileKindType_chargingProfileKindIsSet() { - // Given - ChargingProfileKindType chargingProfileKindType = ChargingProfileKindType.Absolute; - - // When - chargingProfile.setChargingProfileKind(chargingProfileKindType); - - // Then - assertThat(chargingProfile.getChargingProfileKind(), equalTo(chargingProfileKindType)); - } - - @Test - public void setRecurrencyKind_recurrencyKindType_recurrencyKindIsSet() { - // Given - RecurrencyKindType recurrencyKindType = RecurrencyKindType.Daily; - - // When - chargingProfile.setRecurrencyKind(recurrencyKindType); - - // Then - assertThat(chargingProfile.getRecurrencyKind(), equalTo(recurrencyKindType)); - } - - @Test - public void setValidFrom_calendarNow_validFromIsSet() { - // Given - Calendar now = Calendar.getInstance(); - - // When - chargingProfile.setValidFrom(now); - - // Then - assertThat(chargingProfile.getValidFrom(), equalTo(now)); - } - - @Test - public void setValidTo_calendarNow_validToIsSet() { - // Given - Calendar now = Calendar.getInstance(); - - // When - chargingProfile.setValidTo(now); - - // Then - assertThat(chargingProfile.getValidTo(), equalTo(now)); - } - - @Test - public void setChargingSchedule_aChargingSchedule_chargingScheduleIsSet() { - // Given - ChargingSchedule chargingSchedule = mock(ChargingSchedule.class); - - // When - chargingProfile.setChargingSchedule(chargingSchedule); - - // Then - assertThat(chargingProfile.getChargingSchedule(), equalTo(chargingSchedule)); - } - - @Test - public void validate_mandatoryFieldsIsSet_returnTrue() { - // Given - chargingProfile.setChargingProfileId(42); - chargingProfile.setStackLevel(0); - chargingProfile.setChargingProfilePurpose(ChargingProfilePurposeType.TxProfile); - chargingProfile.setChargingProfileKind(ChargingProfileKindType.Absolute); - ChargingSchedule chargingSchedule = mock(ChargingSchedule.class); - when(chargingSchedule.validate()).thenReturn(true); - chargingProfile.setChargingSchedule(chargingSchedule); - - // When - boolean isValid = chargingProfile.validate(); - - // Then - assertThat(isValid, is(true)); - } - - @Test - public void validate_transactionIdIsSetAndChargingProfilePurposeIsNotTxProfile_returnFalse() { - // Given - chargingProfile.setChargingProfileId(42); - chargingProfile.setStackLevel(0); - chargingProfile.setChargingProfileKind(ChargingProfileKindType.Absolute); - ChargingSchedule chargingSchedule = mock(ChargingSchedule.class); - when(chargingSchedule.validate()).thenReturn(true); - chargingProfile.setChargingSchedule(chargingSchedule); - - chargingProfile.setTransactionId(42); - chargingProfile.setChargingProfilePurpose(ChargingProfilePurposeType.TxDefaultProfile); - - // When - boolean isValid = chargingProfile.validate(); - - // Then - assertThat(isValid, is(false)); - } + @Test + public void setStackLevel_asNullValue_throwsPropertyConstraintException() { + testStackLeverInvalidValues(null); + } + + private void testStackLeverInvalidValues(Integer erroneousValue) { + defineExpectedException( + "Validation failed: [stackLevel must be >= 0]. Current Value: [" + erroneousValue + "]"); + + chargingProfile.setStackLevel(erroneousValue); + } + + @Test + public void setStackLevel_zeroInteger_stackLevelIsSet() { + // Given + int zero = 0; + + // When + chargingProfile.setStackLevel(zero); + + // Then + assertThat(chargingProfile.getStackLevel(), equalTo(zero)); + } + + @Test + public void setChargingProfilePurpose_chargingProfilePurposeType_chargingProfilePurposeIsSet() { + // Given + ChargingProfilePurposeType chargingProfilePurposeType = + ChargingProfilePurposeType.ChargePointMaxProfile; + + // When + chargingProfile.setChargingProfilePurpose(chargingProfilePurposeType); + + // Then + assertThat(chargingProfile.getChargingProfilePurpose(), equalTo(chargingProfilePurposeType)); + } + + @Test + public void setChargingProfileKind_chargingProfileKindType_chargingProfileKindIsSet() { + // Given + ChargingProfileKindType chargingProfileKindType = ChargingProfileKindType.Absolute; + + // When + chargingProfile.setChargingProfileKind(chargingProfileKindType); + + // Then + assertThat(chargingProfile.getChargingProfileKind(), equalTo(chargingProfileKindType)); + } + + @Test + public void setRecurrencyKind_recurrencyKindType_recurrencyKindIsSet() { + // Given + RecurrencyKindType recurrencyKindType = RecurrencyKindType.Daily; + + // When + chargingProfile.setRecurrencyKind(recurrencyKindType); + + // Then + assertThat(chargingProfile.getRecurrencyKind(), equalTo(recurrencyKindType)); + } + + @Test + public void setValidFrom_calendarNow_validFromIsSet() { + // Given + ZonedDateTime now = ZonedDateTime.now(); + + // When + chargingProfile.setValidFrom(now); + + // Then + assertThat(chargingProfile.getValidFrom(), equalTo(now)); + } + + @Test + public void setValidTo_calendarNow_validToIsSet() { + // Given + ZonedDateTime now = ZonedDateTime.now(); + + // When + chargingProfile.setValidTo(now); + + // Then + assertThat(chargingProfile.getValidTo(), equalTo(now)); + } + + @Test + public void setChargingSchedule_aChargingSchedule_chargingScheduleIsSet() { + // Given + ChargingSchedule chargingSchedule = mock(ChargingSchedule.class); + + // When + chargingProfile.setChargingSchedule(chargingSchedule); + + // Then + assertThat(chargingProfile.getChargingSchedule(), equalTo(chargingSchedule)); + } + + @Test + public void validate_mandatoryFieldsIsSet_returnTrue() { + // Given + chargingProfile.setChargingProfileId(42); + chargingProfile.setStackLevel(0); + chargingProfile.setChargingProfilePurpose(ChargingProfilePurposeType.TxProfile); + chargingProfile.setChargingProfileKind(ChargingProfileKindType.Absolute); + ChargingSchedule chargingSchedule = mock(ChargingSchedule.class); + when(chargingSchedule.validate()).thenReturn(true); + chargingProfile.setChargingSchedule(chargingSchedule); + + // When + boolean isValid = chargingProfile.validate(); + + // Then + assertThat(isValid, is(true)); + } + + @Test + public void validate_transactionIdIsSetAndChargingProfilePurposeIsNotTxProfile_returnFalse() { + // Given + chargingProfile.setChargingProfileId(42); + chargingProfile.setStackLevel(0); + chargingProfile.setChargingProfileKind(ChargingProfileKindType.Absolute); + ChargingSchedule chargingSchedule = mock(ChargingSchedule.class); + when(chargingSchedule.validate()).thenReturn(true); + chargingProfile.setChargingSchedule(chargingSchedule); + + chargingProfile.setTransactionId(42); + chargingProfile.setChargingProfilePurpose(ChargingProfilePurposeType.TxDefaultProfile); + + // When + boolean isValid = chargingProfile.validate(); + + // Then + assertThat(isValid, is(false)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/ChargingScheduleTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/ChargingScheduleTest.java index ca83ae8e4..41ad0ca6d 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/ChargingScheduleTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/ChargingScheduleTest.java @@ -1,24 +1,26 @@ package eu.chargetime.ocpp.model.test; -import static eu.chargetime.ocpp.utilities.TestUtilities.aList; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; - import eu.chargetime.ocpp.model.core.ChargingRateUnitType; import eu.chargetime.ocpp.model.core.ChargingSchedule; import eu.chargetime.ocpp.model.core.ChargingSchedulePeriod; -import java.util.Calendar; import org.junit.Before; import org.junit.Test; +import java.time.ZonedDateTime; + +import static eu.chargetime.ocpp.utilities.TestUtilities.aList; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.*; + /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -39,111 +41,111 @@ * SOFTWARE. */ public class ChargingScheduleTest { - ChargingSchedule chargingSchedule; - - @Before - public void setUp() throws Exception { - chargingSchedule = new ChargingSchedule(); - } - - @Test - public void setDuration_anInteger_durationIsSet() { - // Given - Integer anInteger = 42; - - // When - chargingSchedule.setDuration(anInteger); - - // Then - assertThat(chargingSchedule.getDuration(), equalTo(anInteger)); - } - - @Test - public void setStartSchedule_calendarNow_startScheduleIsSet() { - // Given - Calendar now = Calendar.getInstance(); - - // When - chargingSchedule.setStartSchedule(now); - - // Then - assertThat(chargingSchedule.getStartSchedule(), equalTo(now)); - } - - @Test - public void setChargingRateUnit_chargingRateUnitType_chargingRateUnitIsSet() throws Exception { - // Given - ChargingRateUnitType chargingRateUnitType = ChargingRateUnitType.A; - - // When - chargingSchedule.setChargingRateUnit(chargingRateUnitType); - - // Then - assertThat(chargingSchedule.getChargingRateUnit(), equalTo(chargingRateUnitType)); - } - - @Test - public void - setChargingSchedulePeriod_listOfChargingSchedulePeriods_chargingSchedulePeriodIsSet() { - // Given - ChargingSchedulePeriod[] chargingSchedulePeriod = aList(mock(ChargingSchedulePeriod.class)); - - // When - chargingSchedule.setChargingSchedulePeriod(chargingSchedulePeriod); - - // Then - assertThat(chargingSchedule.getChargingSchedulePeriod(), equalTo(chargingSchedulePeriod)); - } - - @Test - public void setMinChargingRate_aDouble_minChargingRate() { - // Given - Double aDouble = 4.2; - - // When - chargingSchedule.setMinChargingRate(aDouble); - - // Then - assertThat(chargingSchedule.getMinChargingRate(), equalTo(aDouble)); - } - - @Test - public void validate_chargingSchedulePeriodIsSet_chargingSchedulePeriodIsValidated() - throws Exception { - // Given - chargingSchedule.setChargingRateUnit(ChargingRateUnitType.W); - ChargingSchedulePeriod chargingSchedulePeriod = mock(ChargingSchedulePeriod.class); - chargingSchedule.setChargingSchedulePeriod(aList(chargingSchedulePeriod)); - - // When - chargingSchedule.validate(); - - // Then - verify(chargingSchedulePeriod, times(1)).validate(); - } - - @Test - public void validate_chargingRateUnitAndChargingSchedulePeriodIsSet_returnTrue() - throws Exception { - // Given - ChargingSchedulePeriod chargingSchedulePeriod = mock(ChargingSchedulePeriod.class); - chargingSchedule.setChargingRateUnit(ChargingRateUnitType.W); - chargingSchedule.setChargingSchedulePeriod(aList(chargingSchedulePeriod)); - when(chargingSchedulePeriod.validate()).thenReturn(true); - - // When - boolean isValid = chargingSchedule.validate(); - - // Then - assertThat(isValid, is(true)); - } - - @Test - public void validate_returnFalse() { - // When - boolean isValid = chargingSchedule.validate(); - - // Then - assertThat(isValid, is(false)); - } + ChargingSchedule chargingSchedule; + + @Before + public void setUp() throws Exception { + chargingSchedule = new ChargingSchedule(); + } + + @Test + public void setDuration_anInteger_durationIsSet() { + // Given + Integer anInteger = 42; + + // When + chargingSchedule.setDuration(anInteger); + + // Then + assertThat(chargingSchedule.getDuration(), equalTo(anInteger)); + } + + @Test + public void setStartSchedule_calendarNow_startScheduleIsSet() { + // Given + ZonedDateTime now = ZonedDateTime.now(); + + // When + chargingSchedule.setStartSchedule(now); + + // Then + assertThat(chargingSchedule.getStartSchedule(), equalTo(now)); + } + + @Test + public void setChargingRateUnit_chargingRateUnitType_chargingRateUnitIsSet() throws Exception { + // Given + ChargingRateUnitType chargingRateUnitType = ChargingRateUnitType.A; + + // When + chargingSchedule.setChargingRateUnit(chargingRateUnitType); + + // Then + assertThat(chargingSchedule.getChargingRateUnit(), equalTo(chargingRateUnitType)); + } + + @Test + public void + setChargingSchedulePeriod_listOfChargingSchedulePeriods_chargingSchedulePeriodIsSet() { + // Given + ChargingSchedulePeriod[] chargingSchedulePeriod = aList(mock(ChargingSchedulePeriod.class)); + + // When + chargingSchedule.setChargingSchedulePeriod(chargingSchedulePeriod); + + // Then + assertThat(chargingSchedule.getChargingSchedulePeriod(), equalTo(chargingSchedulePeriod)); + } + + @Test + public void setMinChargingRate_aDouble_minChargingRate() { + // Given + Double aDouble = 4.2; + + // When + chargingSchedule.setMinChargingRate(aDouble); + + // Then + assertThat(chargingSchedule.getMinChargingRate(), equalTo(aDouble)); + } + + @Test + public void validate_chargingSchedulePeriodIsSet_chargingSchedulePeriodIsValidated() + throws Exception { + // Given + chargingSchedule.setChargingRateUnit(ChargingRateUnitType.W); + ChargingSchedulePeriod chargingSchedulePeriod = mock(ChargingSchedulePeriod.class); + chargingSchedule.setChargingSchedulePeriod(aList(chargingSchedulePeriod)); + + // When + chargingSchedule.validate(); + + // Then + verify(chargingSchedulePeriod, times(1)).validate(); + } + + @Test + public void validate_chargingRateUnitAndChargingSchedulePeriodIsSet_returnTrue() + throws Exception { + // Given + ChargingSchedulePeriod chargingSchedulePeriod = mock(ChargingSchedulePeriod.class); + chargingSchedule.setChargingRateUnit(ChargingRateUnitType.W); + chargingSchedule.setChargingSchedulePeriod(aList(chargingSchedulePeriod)); + when(chargingSchedulePeriod.validate()).thenReturn(true); + + // When + boolean isValid = chargingSchedule.validate(); + + // Then + assertThat(isValid, is(true)); + } + + @Test + public void validate_returnFalse() { + // When + boolean isValid = chargingSchedule.validate(); + + // Then + assertThat(isValid, is(false)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/GetCompositeScheduleRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/GetCompositeScheduleRequestTest.java new file mode 100644 index 000000000..e736b255d --- /dev/null +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/GetCompositeScheduleRequestTest.java @@ -0,0 +1,132 @@ +package eu.chargetime.ocpp.model.test; + +import eu.chargetime.ocpp.PropertyConstraintException; +import eu.chargetime.ocpp.model.smartcharging.ChangingRateUnitType; +import eu.chargetime.ocpp.model.smartcharging.GetCompositeScheduleRequest; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + +/* + * ChargeTime.eu - Java-OCA-OCPP + * + * MIT License + * + * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz + * + * 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. + */ +@RunWith(MockitoJUnitRunner.class) +public class GetCompositeScheduleRequestTest { + + @Rule public ExpectedException thrownException = ExpectedException.none(); + + private GetCompositeScheduleRequest request; + + @Before + public void setUp() { + request = new GetCompositeScheduleRequest(); + } + + @Test + public void setConnectorId_negativeInteger_throwsPropertyConstraintException() { + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage( + equalTo("Validation failed: [connectorId must be >= 0]. Current Value: [-1]")); + + int negativeValue = -1; + + request.setConnectorId(negativeValue); + } + + @Test + public void setConnectorId_zeroInteger_connectorIdIsSet() { + // Given + int zeroValue = 0; + + // When + request.setConnectorId(zeroValue); + + // Then + assertThat(request.getConnectorId(), equalTo(zeroValue)); + } + + @Test + public void setDuration_zeroInteger_durationIsSet() { + // Given + int zeroValue = 0; + + // When + request.setDuration(zeroValue); + + // Then + assertThat(request.getDuration(), equalTo(zeroValue)); + } + + @Test + public void setChangingRateUnitType_A_changingRateUnitTypeIsSet() { + // Given + ChangingRateUnitType chargingRateUnitType = ChangingRateUnitType.A; + + // When + request.setChangingRateUnitType(chargingRateUnitType); + + // Then + assertThat(request.getChangingRateUnitType(), equalTo(chargingRateUnitType)); + } + + @Test + public void validate_returnFalse() { + // When + boolean isValid = request.validate(); + + // Then + assertThat(isValid, is(false)); + } + + @Test + public void validate_connectorIdAndMeterValueIsValid_returnTrue() { + // Given + request.setConnectorId(42); + request.setDuration(0); + request.setChangingRateUnitType(ChangingRateUnitType.A); + + // When + boolean isValid = request.validate(); + + // Then + assertThat(isValid, is(true)); + } + + @Test + public void isTransactionRelated_returnsFalse() { + // When + boolean isTransactionRelated = request.transactionRelated(); + + // Then + assertThat(isTransactionRelated, is(false)); + } +} diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/HeartbeatConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/HeartbeatConfirmationTest.java index e5fc221cc..e8505ffa7 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/HeartbeatConfirmationTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/HeartbeatConfirmationTest.java @@ -1,20 +1,22 @@ package eu.chargetime.ocpp.model.test; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - import eu.chargetime.ocpp.model.core.HeartbeatConfirmation; -import java.util.Calendar; import org.junit.Before; import org.junit.Test; +import java.time.ZonedDateTime; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -35,43 +37,43 @@ * SOFTWARE. */ public class HeartbeatConfirmationTest { - HeartbeatConfirmation confirmation; + HeartbeatConfirmation confirmation; - @Before - public void setUp() throws Exception { - confirmation = new HeartbeatConfirmation(); - } + @Before + public void setUp() throws Exception { + confirmation = new HeartbeatConfirmation(); + } - @Test - public void setCurrentTime_now_currentTimeIsSet() { - // Given - Calendar now = Calendar.getInstance(); + @Test + public void setCurrentTime_now_currentTimeIsSet() { + // Given + ZonedDateTime now = ZonedDateTime.now(); - // When - confirmation.setCurrentTime(now); + // When + confirmation.setCurrentTime(now); - // Then - assertThat(confirmation.getCurrentTime(), equalTo(now)); - } + // Then + assertThat(confirmation.getCurrentTime(), equalTo(now)); + } - @Test - public void validate_currentTimeIsSet_returnsTrue() { - // Given - confirmation.setCurrentTime(Calendar.getInstance()); + @Test + public void validate_currentTimeIsSet_returnsTrue() { + // Given + confirmation.setCurrentTime(ZonedDateTime.now()); - // When - boolean isValid = confirmation.validate(); + // When + boolean isValid = confirmation.validate(); - // Then - assertThat(isValid, is(true)); - } + // Then + assertThat(isValid, is(true)); + } - @Test - public void validate_returnFalse() { - // When - boolean isValid = confirmation.validate(); + @Test + public void validate_returnFalse() { + // When + boolean isValid = confirmation.validate(); - // Then - assertThat(isValid, is(false)); - } + // Then + assertThat(isValid, is(false)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/MeterValueTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/MeterValueTest.java index c6e559d01..5b422e8e2 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/MeterValueTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/MeterValueTest.java @@ -1,28 +1,28 @@ package eu.chargetime.ocpp.model.test; -import static eu.chargetime.ocpp.utilities.TestUtilities.aList; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import eu.chargetime.ocpp.model.core.MeterValue; import eu.chargetime.ocpp.model.core.SampledValue; -import java.util.Calendar; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.time.ZonedDateTime; + +import static eu.chargetime.ocpp.utilities.TestUtilities.aList; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.*; + /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -45,87 +45,87 @@ @RunWith(MockitoJUnitRunner.class) public class MeterValueTest { - private MeterValue meterValue; + private MeterValue meterValue; - @Mock private SampledValue sampledValueMock; + @Mock private SampledValue sampledValueMock; - @Before - public void setUp() { - meterValue = new MeterValue(); - } + @Before + public void setUp() { + meterValue = new MeterValue(); + } - @Test - public void setTimestamp_now_timestampIsSet() { - // Given - Calendar now = Calendar.getInstance(); + @Test + public void setTimestamp_now_timestampIsSet() { + // Given + ZonedDateTime now = ZonedDateTime.now(); - // When - meterValue.setTimestamp(now); + // When + meterValue.setTimestamp(now); - // Then - assertThat(meterValue.getTimestamp(), equalTo(now)); - } + // Then + assertThat(meterValue.getTimestamp(), equalTo(now)); + } - @Test - public void validate_returnFalse() { - // When - boolean isValid = meterValue.validate(); + @Test + public void validate_returnFalse() { + // When + boolean isValid = meterValue.validate(); - // Then - assertThat(isValid, is(false)); - } + // Then + assertThat(isValid, is(false)); + } - @Test - public void validate_sampledValueIsSet_validatesSampledValue() { - // Given - meterValue.setTimestamp(Calendar.getInstance()); - meterValue.setSampledValue(aList(sampledValueMock)); + @Test + public void validate_sampledValueIsSet_validatesSampledValue() { + // Given + meterValue.setTimestamp(ZonedDateTime.now()); + meterValue.setSampledValue(aList(sampledValueMock)); - // When - meterValue.validate(); + // When + meterValue.validate(); - // Then - verify(sampledValueMock, times(1)).validate(); - } + // Then + verify(sampledValueMock, times(1)).validate(); + } - @Test - public void validate_TimestampAndSampledValueIsValid_returnTrue() { - // Given - meterValue.setTimestamp(Calendar.getInstance()); - meterValue.setSampledValue(aList(sampledValueMock)); + @Test + public void validate_TimestampAndSampledValueIsValid_returnTrue() { + // Given + meterValue.setTimestamp(ZonedDateTime.now()); + meterValue.setSampledValue(aList(sampledValueMock)); - when(sampledValueMock.validate()).thenReturn(true); + when(sampledValueMock.validate()).thenReturn(true); - // When - boolean isValid = meterValue.validate(); + // When + boolean isValid = meterValue.validate(); - // Then - assertThat(isValid, is(true)); - } + // Then + assertThat(isValid, is(true)); + } - @Test - public void validate_missingTimestamp_returnFalse() { - // Given - meterValue.setSampledValue(aList(sampledValueMock)); + @Test + public void validate_missingTimestamp_returnFalse() { + // Given + meterValue.setSampledValue(aList(sampledValueMock)); - when(sampledValueMock.validate()).thenReturn(true); + when(sampledValueMock.validate()).thenReturn(true); - // When - boolean isValid = meterValue.validate(); + // When + boolean isValid = meterValue.validate(); - // Then - assertThat(isValid, is(false)); - } + // Then + assertThat(isValid, is(false)); + } - @Test - public void validate_missingSampleValue_returnFalse() { - // Given - meterValue.setSampledValue(null); + @Test + public void validate_missingSampleValue_returnFalse() { + // Given + meterValue.setSampledValue(null); - // When - boolean isValid = meterValue.validate(); + // When + boolean isValid = meterValue.validate(); - // Then - assertThat(isValid, is(false)); - } + // Then + assertThat(isValid, is(false)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/MeterValuesRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/MeterValuesRequestTest.java index b02174c3c..cd7b768a8 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/MeterValuesRequestTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/MeterValuesRequestTest.java @@ -1,14 +1,5 @@ package eu.chargetime.ocpp.model.test; -import static eu.chargetime.ocpp.utilities.TestUtilities.aList; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.core.MeterValue; import eu.chargetime.ocpp.model.core.MeterValuesRequest; @@ -20,12 +11,18 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import static eu.chargetime.ocpp.utilities.TestUtilities.aList; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.*; + /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -48,105 +45,107 @@ @RunWith(MockitoJUnitRunner.class) public class MeterValuesRequestTest { - @Rule public ExpectedException thrownException = ExpectedException.none(); + @Rule public ExpectedException thrownException = ExpectedException.none(); - private MeterValuesRequest request; + private MeterValuesRequest request; - @Mock private MeterValue meterValueMock; + @Mock private MeterValue meterValueMock; - @Before - public void setUp() { - request = new MeterValuesRequest(); - } + @Before + public void setUp() { + request = new MeterValuesRequest(); + } - @Test - public void setConnectorId_negativeInteger_throwsPropertyConstraintException() { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage( - equalTo("Validation failed: [connectorId must be >= 0]. Current Value: [-1]")); + @Test + public void setConnectorId_negativeInteger_throwsPropertyConstraintException() { + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage( + equalTo("Validation failed: [connectorId must be >= 0]. Current Value: [-1]")); - int negativeValue = -1; + int negativeValue = -1; - request.setConnectorId(negativeValue); - } + request.setConnectorId(negativeValue); + } - @Test - public void setConnectorId_zeroInteger_connectorIdIsSet() { - // Given - int zeroValue = 0; + @Test + public void setConnectorId_zeroInteger_connectorIdIsSet() { + // Given + int zeroValue = 0; - // When - request.setConnectorId(zeroValue); + // When + request.setConnectorId(zeroValue); - // Then - assertThat(request.getConnectorId(), equalTo(zeroValue)); - } + // Then + assertThat(request.getConnectorId(), equalTo(zeroValue)); + } - @Test - public void setTransactionId_transactionIdIsSet() { - // Given - int anyValue = 42; + @Test + public void setTransactionId_transactionIdIsSet() { + // Given + int anyValue = 42; - // When - request.setTransactionId(anyValue); + // When + request.setTransactionId(anyValue); - // Then - assertThat(request.getTransactionId(), equalTo(anyValue)); - } + // Then + assertThat(request.getTransactionId(), equalTo(anyValue)); + } - @Test - public void setMeterValue_aMeterValueArray_meterValueIsSet() { - // Given - MeterValue[] listOfMeterValues = aList(new MeterValue()); + @Test + public void setMeterValue_aMeterValueArray_meterValueIsSet() { + // Given + MeterValue[] listOfMeterValues = aList(new MeterValue()); - // When - request.setMeterValue(listOfMeterValues); + // When + request.setMeterValue(listOfMeterValues); - // Then - assertThat(request.getMeterValue(), equalTo(listOfMeterValues)); - } + // Then + assertThat(request.getMeterValue(), equalTo(listOfMeterValues)); + } - @Test - public void validate_returnFalse() { - // When - boolean isValid = request.validate(); + @Test + public void validate_returnFalse() { + // When + boolean isValid = request.validate(); - // Then - assertThat(isValid, is(false)); - } + // Then + assertThat(isValid, is(false)); + } - @Test - public void validate_meterValueIsSet_validatesMeterValue() { - // Given - request.setMeterValue(aList(meterValueMock)); + @Test + public void validate_meterValueIsSet_validatesMeterValue() { + // Given + request.setMeterValue(aList(meterValueMock)); + request.setConnectorId(1); + when(meterValueMock.validate()).thenReturn(true); - // When - request.validate(); + // When + request.validate(); - // Then - verify(meterValueMock, times(1)).validate(); - } + // Then + verify(meterValueMock, times(1)).validate(); + } - @Test - public void validate_connectorIdAndMeterValueIsValid_returnTrue() { - // Given - request.setConnectorId(42); - request.setMeterValue(aList(meterValueMock)); - when(meterValueMock.validate()).thenReturn(true); + @Test + public void validate_connectorIdAndMeterValueIsValid_returnTrue() { + // Given + request.setConnectorId(42); + request.setMeterValue(aList(meterValueMock)); + when(meterValueMock.validate()).thenReturn(true); - // When - boolean isValid = request.validate(); + // When + boolean isValid = request.validate(); - // Then - assertThat(isValid, is(true)); - } + // Then + assertThat(isValid, is(true)); + } - @Test - public void isTransactionRelated_returnsFalse() { - // When - boolean isTransactionRelated = request.transactionRelated(); + @Test + public void isTransactionRelated_returnsFalse() { + // When + boolean isTransactionRelated = request.transactionRelated(); - // Then - assertThat(isTransactionRelated, is(true)); - } + // Then + assertThat(isTransactionRelated, is(true)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StartTransactionRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StartTransactionRequestTest.java index 12bcf3064..aa57cb31d 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StartTransactionRequestTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StartTransactionRequestTest.java @@ -1,25 +1,25 @@ package eu.chargetime.ocpp.model.test; -import static eu.chargetime.ocpp.utilities.TestUtilities.aString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.core.StartTransactionRequest; -import java.util.Calendar; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import java.time.ZonedDateTime; + +import static eu.chargetime.ocpp.utilities.TestUtilities.aString; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -41,137 +41,137 @@ */ public class StartTransactionRequestTest { - @Rule public ExpectedException thrownException = ExpectedException.none(); + @Rule public ExpectedException thrownException = ExpectedException.none(); - private StartTransactionRequest request; - - @Before - public void setUp() { - request = new StartTransactionRequest(); - } - - @Test - public void setConnectorId_asZeroInteger_throwsPropertyConstraintException() { - testConnectorIdInvalidValue(0); - } - - @Test - public void setConnectorId_asNegativeInteger_throwsPropertyConstraintException() { - testConnectorIdInvalidValue(-1); - } - - @Test - public void setConnectorId_asNullInteger_throwsPropertyConstraintException() { - testConnectorIdInvalidValue(null); - } - - private void testConnectorIdInvalidValue(Integer invalidValue) { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage( - equalTo( - "Validation failed: [connectorId must be > 0]. Current Value: [" + invalidValue + "]")); - - request.setConnectorId(invalidValue); - } - - @Test - public void setIdTag_exceeds20Chars_throwsPropertyConstraintException() { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage( - equalTo("Validation failed: [Exceeded limit of 20 chars]. Current Value: [21]")); - - request.setIdTag(aString(21)); - } - - @Test - public void setIdTag_string20_isSet() { - // Given - String validString = aString(20); - - // When - request.setIdTag(validString); - - // Then - assertThat(request.getIdTag(), equalTo(validString)); - } - - @Test - public void setConnectorId_positiveInteger_connectorIdIsSet() { - // Given - Integer positive = 42; - - // When - request.setConnectorId(positive); - - // Then - assertThat(request.getConnectorId(), equalTo(positive)); - } - - @Test - public void setMeterStart_anInteger_meterStartIsSet() { - // Given - Integer meterStart = 42; - - // When - request.setMeterStart(meterStart); - - // Then - assertThat(request.getMeterStart(), equalTo(meterStart)); - } - - @Test - public void setReservationId_anInteger_reservationIdIsSet() { - // Given - Integer anInteger = 42; - - // When - request.setReservationId(anInteger); - - // Then - assertThat(request.getReservationId(), equalTo(anInteger)); - } - - @Test - public void setTimestamp_calendarNow_timestampIsSet() { - // Given - Calendar now = Calendar.getInstance(); - - // When - request.setTimestamp(now); - // Then - assertThat(request.getTimestamp(), equalTo(now)); - } - - @Test - public void validate_returnFalse() { - // When - boolean isValid = request.validate(); - - // Then - assertThat(isValid, is(false)); - } - - @Test - public void validate_requiredFieldsAreSet_returnTrue() { - // Given - request.setConnectorId(42); - request.setIdTag("xxx"); - request.setMeterStart(42); - request.setTimestamp(Calendar.getInstance()); - - // When - boolean isValid = request.validate(); - - // Then - assertThat(isValid, is(true)); - } - - @Test - public void isTransactionRelated_returnsFalse() { - // When - boolean isTransactionRelated = request.transactionRelated(); - - // Then - assertThat(isTransactionRelated, is(true)); - } + private StartTransactionRequest request; + + @Before + public void setUp() { + request = new StartTransactionRequest(); + } + + @Test + public void setConnectorId_asZeroInteger_throwsPropertyConstraintException() { + testConnectorIdInvalidValue(0); + } + + @Test + public void setConnectorId_asNegativeInteger_throwsPropertyConstraintException() { + testConnectorIdInvalidValue(-1); + } + + @Test + public void setConnectorId_asNullInteger_throwsPropertyConstraintException() { + testConnectorIdInvalidValue(null); + } + + private void testConnectorIdInvalidValue(Integer invalidValue) { + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage( + equalTo( + "Validation failed: [connectorId must be > 0]. Current Value: [" + invalidValue + "]")); + + request.setConnectorId(invalidValue); + } + + @Test + public void setIdTag_exceeds20Chars_throwsPropertyConstraintException() { + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage( + equalTo("Validation failed: [Exceeded limit of 20 chars]. Current Value: [21]")); + + request.setIdTag(aString(21)); + } + + @Test + public void setIdTag_string20_isSet() { + // Given + String validString = aString(20); + + // When + request.setIdTag(validString); + + // Then + assertThat(request.getIdTag(), equalTo(validString)); + } + + @Test + public void setConnectorId_positiveInteger_connectorIdIsSet() { + // Given + Integer positive = 42; + + // When + request.setConnectorId(positive); + + // Then + assertThat(request.getConnectorId(), equalTo(positive)); + } + + @Test + public void setMeterStart_anInteger_meterStartIsSet() { + // Given + Integer meterStart = 42; + + // When + request.setMeterStart(meterStart); + + // Then + assertThat(request.getMeterStart(), equalTo(meterStart)); + } + + @Test + public void setReservationId_anInteger_reservationIdIsSet() { + // Given + Integer anInteger = 42; + + // When + request.setReservationId(anInteger); + + // Then + assertThat(request.getReservationId(), equalTo(anInteger)); + } + + @Test + public void setTimestamp_calendarNow_timestampIsSet() { + // Given + ZonedDateTime now = ZonedDateTime.now(); + + // When + request.setTimestamp(now); + // Then + assertThat(request.getTimestamp(), equalTo(now)); + } + + @Test + public void validate_returnFalse() { + // When + boolean isValid = request.validate(); + + // Then + assertThat(isValid, is(false)); + } + + @Test + public void validate_requiredFieldsAreSet_returnTrue() { + // Given + request.setConnectorId(42); + request.setIdTag("xxx"); + request.setMeterStart(42); + request.setTimestamp(ZonedDateTime.now()); + + // When + boolean isValid = request.validate(); + + // Then + assertThat(isValid, is(true)); + } + + @Test + public void isTransactionRelated_returnsFalse() { + // When + boolean isTransactionRelated = request.transactionRelated(); + + // Then + assertThat(isTransactionRelated, is(true)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StatusNotificationRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StatusNotificationRequestTest.java index d5358f203..e6c130be3 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StatusNotificationRequestTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StatusNotificationRequestTest.java @@ -1,27 +1,27 @@ package eu.chargetime.ocpp.model.test; -import static eu.chargetime.ocpp.utilities.TestUtilities.aString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.core.ChargePointErrorCode; import eu.chargetime.ocpp.model.core.ChargePointStatus; import eu.chargetime.ocpp.model.core.StatusNotificationRequest; -import java.util.Calendar; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import java.time.ZonedDateTime; + +import static eu.chargetime.ocpp.utilities.TestUtilities.aString; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -43,180 +43,180 @@ */ public class StatusNotificationRequestTest { - private static final String EXCEPTION_MESSAGE_TEMPLATE = - "Validation failed: [Exceeds limit of %s chars]. Current Value: [%s]"; + private static final String EXCEPTION_MESSAGE_TEMPLATE = + "Validation failed: [Exceeds limit of %s chars]. Current Value: [%s]"; - @Rule public ExpectedException thrownException = ExpectedException.none(); + @Rule public ExpectedException thrownException = ExpectedException.none(); - private StatusNotificationRequest request; + private StatusNotificationRequest request; - @Before - public void setUp() { - request = new StatusNotificationRequest(); - } + private static String createExpectedExceptionMessage(int maxAllowedLength, int currentLength) { + return String.format(EXCEPTION_MESSAGE_TEMPLATE, maxAllowedLength, currentLength); + } - @Test - public void setConnectorId_negativeInteger_throwsPropertyConstraintException() { + @Before + public void setUp() { + request = new StatusNotificationRequest(); + } - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage( - equalTo("Validation failed: [connectorId >= 0]. Current Value: [-42]")); + @Test + public void setConnectorId_negativeInteger_throwsPropertyConstraintException() { - Integer negativeValue = -42; + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage( + equalTo("Validation failed: [connectorId >= 0]. Current Value: [-42]")); - request.setConnectorId(negativeValue); - } + Integer negativeValue = -42; - @Test - public void setConnectorId_zeroInteger_connectorIdIsSet() { - // Given - Integer zeroValue = 0; + request.setConnectorId(negativeValue); + } - // When - request.setConnectorId(zeroValue); + @Test + public void setConnectorId_zeroInteger_connectorIdIsSet() { + // Given + Integer zeroValue = 0; - // Then - assertThat(request.getConnectorId(), equalTo(zeroValue)); - } + // When + request.setConnectorId(zeroValue); - @Test - public void setErrorCode_chargePointErrorCode_errorCodeIsSet() { - // Given - ChargePointErrorCode chargePointErrorCode = ChargePointErrorCode.NoError; + // Then + assertThat(request.getConnectorId(), equalTo(zeroValue)); + } - // When - request.setErrorCode(chargePointErrorCode); + @Test + public void setErrorCode_chargePointErrorCode_errorCodeIsSet() { + // Given + ChargePointErrorCode chargePointErrorCode = ChargePointErrorCode.NoError; - // Then - assertThat(request.getErrorCode(), equalTo(chargePointErrorCode)); - } + // When + request.setErrorCode(chargePointErrorCode); - @Test - public void setInfo_stringLength51_throwsPropertyConstraintException() { + // Then + assertThat(request.getErrorCode(), equalTo(chargePointErrorCode)); + } - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage(equalTo(createExpectedExceptionMessage(50, 51))); + @Test + public void setInfo_stringLength51_throwsPropertyConstraintException() { - String length51 = aString(51); + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage(equalTo(createExpectedExceptionMessage(50, 51))); - request.setInfo(length51); - } + String length51 = aString(51); - private static String createExpectedExceptionMessage(int maxAllowedLength, int currentLength) { - return String.format(EXCEPTION_MESSAGE_TEMPLATE, maxAllowedLength, currentLength); - } + request.setInfo(length51); + } - @Test - public void setInfo_stringLength50_infoIsSet() { - // Given - String length50 = aString(50); + @Test + public void setInfo_stringLength50_infoIsSet() { + // Given + String length50 = aString(50); - // When - request.setInfo(length50); + // When + request.setInfo(length50); - // Then - assertThat(request.getInfo(), equalTo(length50)); - } + // Then + assertThat(request.getInfo(), equalTo(length50)); + } - @Test - public void setStatus_chargePointStatus_statusIsSet() { - // Given - ChargePointStatus chargePointStatus = ChargePointStatus.Available; + @Test + public void setStatus_chargePointStatus_statusIsSet() { + // Given + ChargePointStatus chargePointStatus = ChargePointStatus.Available; - // When - request.setStatus(chargePointStatus); + // When + request.setStatus(chargePointStatus); - // Then - assertThat(request.getStatus(), equalTo(chargePointStatus)); - } + // Then + assertThat(request.getStatus(), equalTo(chargePointStatus)); + } - @Test - public void setTimestamp_calendarNow_timestampIsSet() { - // Given - Calendar now = Calendar.getInstance(); + @Test + public void setTimestamp_calendarNow_timestampIsSet() { + // Given + ZonedDateTime now = ZonedDateTime.now(); - // When - request.setTimestamp(now); + // When + request.setTimestamp(now); - // Then - assertThat(request.getTimestamp(), equalTo(now)); - } + // Then + assertThat(request.getTimestamp(), equalTo(now)); + } - @Test - public void setVendorId_stringLength256_throwsPropertyConstraintException() { + @Test + public void setVendorId_stringLength256_throwsPropertyConstraintException() { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage(equalTo(createExpectedExceptionMessage(255, 256))); + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage(equalTo(createExpectedExceptionMessage(255, 256))); - String length256 = aString(256); + String length256 = aString(256); - request.setVendorId(length256); - } + request.setVendorId(length256); + } - @Test - public void setVendorId_stringLength255_vendorIdIsSet() { - // Given - String length255 = aString(255); + @Test + public void setVendorId_stringLength255_vendorIdIsSet() { + // Given + String length255 = aString(255); - // When - request.setVendorId(length255); + // When + request.setVendorId(length255); - // Then - assertThat(request.getVendorId(), equalTo(length255)); - } + // Then + assertThat(request.getVendorId(), equalTo(length255)); + } - @Test - public void setVendorErrorCode_stringLength51_throwsPropertyConstraintException() { + @Test + public void setVendorErrorCode_stringLength51_throwsPropertyConstraintException() { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage(equalTo(createExpectedExceptionMessage(50, 51))); + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage(equalTo(createExpectedExceptionMessage(50, 51))); - String length51 = aString(51); + String length51 = aString(51); - request.setVendorErrorCode(length51); - } + request.setVendorErrorCode(length51); + } - @Test - public void setVendorErrorCode_stringLength50_vendorErrorCodeIsSet() { - // Given - String length50 = aString(50); + @Test + public void setVendorErrorCode_stringLength50_vendorErrorCodeIsSet() { + // Given + String length50 = aString(50); - // When - request.setVendorErrorCode(length50); + // When + request.setVendorErrorCode(length50); - // Then - assertThat(request.getVendorErrorCode(), equalTo(length50)); - } + // Then + assertThat(request.getVendorErrorCode(), equalTo(length50)); + } - @Test - public void validate_returnFalse() { - // When - boolean isValid = request.validate(); + @Test + public void validate_returnFalse() { + // When + boolean isValid = request.validate(); - // Then - assertThat(isValid, is(false)); - } + // Then + assertThat(isValid, is(false)); + } - @Test - public void validate_connectorIdAndErrorCodeAndStatusIsSet_returnTrue() { - // Given - request.setConnectorId(42); - request.setErrorCode(ChargePointErrorCode.NoError); - request.setStatus(ChargePointStatus.Available); + @Test + public void validate_connectorIdAndErrorCodeAndStatusIsSet_returnTrue() { + // Given + request.setConnectorId(42); + request.setErrorCode(ChargePointErrorCode.NoError); + request.setStatus(ChargePointStatus.Available); - // When - boolean isValid = request.validate(); + // When + boolean isValid = request.validate(); - // Then - assertThat(isValid, is(true)); - } + // Then + assertThat(isValid, is(true)); + } - @Test - public void isTransactionRelated_returnsFalse() { - // When - boolean isTransactionRelated = request.transactionRelated(); + @Test + public void isTransactionRelated_returnsFalse() { + // When + boolean isTransactionRelated = request.transactionRelated(); - // Then - assertThat(isTransactionRelated, is(false)); - } + // Then + assertThat(isTransactionRelated, is(false)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StopTransactionRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StopTransactionRequestTest.java index 26848107a..45d35475e 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StopTransactionRequestTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StopTransactionRequestTest.java @@ -1,33 +1,30 @@ package eu.chargetime.ocpp.model.test; -import static eu.chargetime.ocpp.utilities.TestUtilities.aList; -import static eu.chargetime.ocpp.utilities.TestUtilities.aString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.core.MeterValue; import eu.chargetime.ocpp.model.core.Reason; import eu.chargetime.ocpp.model.core.StopTransactionRequest; -import java.util.Calendar; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import java.time.ZonedDateTime; + +import static eu.chargetime.ocpp.utilities.TestUtilities.aList; +import static eu.chargetime.ocpp.utilities.TestUtilities.aString; +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.*; + /* * ChargeTime.eu - Java-OCA-OCPP * * MIT License * * Copyright (C) 2016-2018 Thomas Volden + * Copyright (C) 2019 Kevin Raddatz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -49,156 +46,156 @@ */ public class StopTransactionRequestTest { - @Rule public ExpectedException thrownException = ExpectedException.none(); + @Rule public ExpectedException thrownException = ExpectedException.none(); - private StopTransactionRequest request; + private StopTransactionRequest request; - @Before - public void setUp() { - request = new StopTransactionRequest(); - } + @Before + public void setUp() { + request = new StopTransactionRequest(); + } - @Test - public void setIdTag_anIdToken_idTagIsSet() { - // Given - String idTag = "xxx"; + @Test + public void setIdTag_anIdToken_idTagIsSet() { + // Given + String idTag = "xxx"; - // When - request.setIdTag(idTag); + // When + request.setIdTag(idTag); - // Then - assertThat(request.getIdTag(), equalTo(idTag)); - } + // Then + assertThat(request.getIdTag(), equalTo(idTag)); + } - @Test - public void setIdTag_moreThan20Chars_throwsPropertyConstraintException() { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage( - equalTo("Validation failed: [Exceeded limit of 20 chars]. Current Value: [42]")); + @Test + public void setIdTag_moreThan20Chars_throwsPropertyConstraintException() { + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage( + equalTo("Validation failed: [Exceeded limit of 20 chars]. Current Value: [42]")); - request.setIdTag(aString(42)); - } + request.setIdTag(aString(42)); + } - @Test - public void setMeterStop_anInteger_meterStopIsSet() { - // Given - Integer anInteger = 42; - - // When - request.setMeterStop(anInteger); + @Test + public void setMeterStop_anInteger_meterStopIsSet() { + // Given + Integer anInteger = 42; + + // When + request.setMeterStop(anInteger); - // Then - assertThat(request.getMeterStop(), equalTo(anInteger)); - } + // Then + assertThat(request.getMeterStop(), equalTo(anInteger)); + } - @Test - public void setTimestamp_calendarNow_timestampIsSet() { - // Given - Calendar now = Calendar.getInstance(); - - // When - request.setTimestamp(now); + @Test + public void setTimestamp_calendarNow_timestampIsSet() { + // Given + ZonedDateTime now = ZonedDateTime.now(); + + // When + request.setTimestamp(now); - // Then - assertThat(request.getTimestamp(), equalTo(now)); - } - - @Test - public void setTransactionId_anInteger_transactionIdIsSet() { - // Given - Integer anInteger = 42; - - // When - request.setTransactionId(anInteger); - - // Then - assertThat(request.getTransactionId(), equalTo(anInteger)); - } - - @Test - public void setReason_reason_throwsPropertyConstraintException() { - // Given - Reason reason = Reason.DeAuthorized; - - // When - request.setReason(reason); - - // Then - assertThat(request.getReason(), equalTo(reason)); - } - - @Test - public void setTransactionData_listOfMeterValues_transactionDataIsSet() { - // Given - MeterValue[] meterValues = aList(mock(MeterValue.class)); - - // When - request.setTransactionData(meterValues); - - // Then - assertThat(request.getTransactionData(), equalTo(meterValues)); - } - - @Test - public void validate_returnFalse() { - // When - boolean isValid = request.validate(); - - // Then - assertThat(isValid, is(false)); - } - - @Test - public void validate_meterStopAndTimestampAndTransactionIdIsSet_returnTrue() { - // Given - request.setMeterStop(42); - request.setTimestamp(Calendar.getInstance()); - request.setTransactionId(42); - - // When - boolean isValid = request.validate(); - - // Then - assertThat(isValid, is(true)); - } - - @Test - public void validate_transactionDataIsSet_transactionDataIsValidated() { - // Given - MeterValue meterValue = mock(MeterValue.class); - request.setTransactionData(aList(meterValue)); - - // When - request.validate(); - - // Then - verify(meterValue, times(1)).validate(); - } - - @Test - public void validate_aMeterValueIsNotValid_returnFalse() { - // Given - request.setMeterStop(42); - request.setTimestamp(Calendar.getInstance()); - request.setTransactionId(42); - - MeterValue meterValue = mock(MeterValue.class); - request.setTransactionData(aList(meterValue)); - - // When - when(meterValue.validate()).thenReturn(false); - boolean isValid = request.validate(); - - // Then - assertThat(isValid, is(false)); - } - - @Test - public void isTransactionRelated_returnsFalse() { - // When - boolean isTransactionRelated = request.transactionRelated(); - - // Then - Assert.assertThat(isTransactionRelated, is(true)); - } + // Then + assertThat(request.getTimestamp(), equalTo(now)); + } + + @Test + public void setTransactionId_anInteger_transactionIdIsSet() { + // Given + Integer anInteger = 42; + + // When + request.setTransactionId(anInteger); + + // Then + assertThat(request.getTransactionId(), equalTo(anInteger)); + } + + @Test + public void setReason_reason_throwsPropertyConstraintException() { + // Given + Reason reason = Reason.DeAuthorized; + + // When + request.setReason(reason); + + // Then + assertThat(request.getReason(), equalTo(reason)); + } + + @Test + public void setTransactionData_listOfMeterValues_transactionDataIsSet() { + // Given + MeterValue[] meterValues = aList(mock(MeterValue.class)); + + // When + request.setTransactionData(meterValues); + + // Then + assertThat(request.getTransactionData(), equalTo(meterValues)); + } + + @Test + public void validate_returnFalse() { + // When + boolean isValid = request.validate(); + + // Then + assertThat(isValid, is(false)); + } + + @Test + public void validate_meterStopAndTimestampAndTransactionIdIsSet_returnTrue() { + // Given + request.setMeterStop(42); + request.setTimestamp(ZonedDateTime.now()); + request.setTransactionId(42); + + // When + boolean isValid = request.validate(); + + // Then + assertThat(isValid, is(true)); + } + + @Test + public void validate_transactionDataIsSet_transactionDataIsValidated() { + // Given + MeterValue meterValue = mock(MeterValue.class); + request.setTransactionData(aList(meterValue)); + + // When + request.validate(); + + // Then + verify(meterValue, times(1)).validate(); + } + + @Test + public void validate_aMeterValueIsNotValid_returnFalse() { + // Given + request.setMeterStop(42); + request.setTimestamp(ZonedDateTime.now()); + request.setTransactionId(42); + + MeterValue meterValue = mock(MeterValue.class); + request.setTransactionData(aList(meterValue)); + + // When + when(meterValue.validate()).thenReturn(false); + boolean isValid = request.validate(); + + // Then + assertThat(isValid, is(false)); + } + + @Test + public void isTransactionRelated_returnsFalse() { + // When + boolean isTransactionRelated = request.transactionRelated(); + + // Then + Assert.assertThat(isTransactionRelated, is(true)); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/test/JSONCommunicatorTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/test/JSONCommunicatorTest.java index 2aa5b1a32..d7ce883d3 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/test/JSONCommunicatorTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/test/JSONCommunicatorTest.java @@ -1,33 +1,36 @@ package eu.chargetime.ocpp.test; -import static eu.chargetime.ocpp.utilities.TestUtilities.join; -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.*; - import eu.chargetime.ocpp.JSONCommunicator; import eu.chargetime.ocpp.Transmitter; import eu.chargetime.ocpp.model.TestModel; import eu.chargetime.ocpp.model.core.BootNotificationConfirmation; import eu.chargetime.ocpp.model.core.BootNotificationRequest; import eu.chargetime.ocpp.model.core.RegistrationStatus; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.TimeZone; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; +import java.time.Instant; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.Locale; + +import static eu.chargetime.ocpp.utilities.TestUtilities.join; +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.*; + /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden +Copyright (C) 2019 Kevin Raddatz MIT License Copyright (C) 2016-2018 Thomas Volden +Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -49,284 +52,272 @@ of this software and associated documentation files (the "Software"), to deal */ @RunWith(MockitoJUnitRunner.class) public class JSONCommunicatorTest { - private JSONCommunicator communicator; - - @Mock private Transmitter transmitter; - - @Before - public void setup() { - communicator = new JSONCommunicator(transmitter); - } - - @Test - public void unpackPayload_emptyPayload_returnRequestedType() throws Exception { - // Given - String payload = "{}"; - Class type = BootNotificationRequest.class; - - // When - Object result = communicator.unpackPayload(payload, type); - - // Then - assertThat(result, instanceOf(type)); - } - - @Test - public void unpackPayload_aStringPayload_returnsTestModelWithAString() throws Exception { - // Given - String aString = "Some string"; - String payload = "{\"stringTest\":\"%s\"}"; - - // When - TestModel model = communicator.unpackPayload(String.format(payload, aString), TestModel.class); - - // Then - assertThat(model.getStringTest(), equalTo(aString)); - } - - @Test - public void unpackPayload_aCalendarPayload_returnsTestModelWithACalendar() throws Exception { - // Given - String aCalendar = "2016-04-28T07:16:11.988Z"; - String payload = "{\"calendarTest\":\"%s\"}"; - - Calendar someDate = - new Calendar.Builder() - .setDate(2016, 03, 28) - .setTimeOfDay(07, 16, 11, 988) - .setTimeZone(TimeZone.getTimeZone("GMT+00:00")) - .build(); - - // When - TestModel model = - communicator.unpackPayload(String.format(payload, aCalendar), TestModel.class); - - // Then - assertThat(model.getCalendarTest().compareTo(someDate), is(0)); - } - - @Test - public void unpackPayload_anIntegerPayload_returnsTestModelWithAnInteger() throws Exception { - // Given - Integer anInteger = 1337; - String payload = "{\"integerTest\":%d}"; - - // When - TestModel model = - communicator.unpackPayload(String.format(payload, anInteger), TestModel.class); - - // Then - assertThat(model.getIntegerTest(), equalTo(anInteger)); - } - - @Test - public void unpackPayload_aGenericIntPayload_returnsTestModelWithAGenericInt() throws Exception { - // Given - int anInteger = 1337; - String payload = "{\"intTest\":%d}"; - - // When - TestModel model = - communicator.unpackPayload(String.format(payload, anInteger), TestModel.class); - - // Then - assertThat(model.getIntTest(), equalTo(anInteger)); - } - - @Test - public void unpackPayload_aLongPayload_returnsTestModelWithALong() throws Exception { - // Given - Long aLong = 1337L; - String payload = "{\"longTest\":%d}"; - - // When - TestModel model = communicator.unpackPayload(String.format(payload, aLong), TestModel.class); - - // Then - assertThat(model.getLongTest(), equalTo(aLong)); - } - - @Test - public void unpackPayload_aGenericLongPayload_returnsTestModelWithAGenericLong() - throws Exception { - // Given - long aLong = 1337; - String payload = "{\"genericLongTest\":%d}"; - - // When - TestModel model = communicator.unpackPayload(String.format(payload, aLong), TestModel.class); - - // Then - assertThat(model.getGenericLongTest(), equalTo(aLong)); - } - - @Test - public void unpackPayload_aDoublePayload_returnsTestModelWithADouble() throws Exception { - // Given - Double aDouble = 13.37D; - String payload = "{\"doubleTest\":%f}"; - - // When - TestModel model = - communicator.unpackPayload(String.format(Locale.US, payload, aDouble), TestModel.class); - - // Then - assertThat(model.getDoubleTest(), equalTo(aDouble)); - } - - @Test - public void unpackPayload_aGenericDoublePayload_returnsTestModelWithAGenericDouble() - throws Exception { - // Given - double aDouble = 13.37; - String payload = "{\"genericDoubleTest\":%f}"; - - // When - TestModel model = - communicator.unpackPayload(String.format(Locale.US, payload, aDouble), TestModel.class); - - // Then - assertThat(model.getGenericDoubleTest(), equalTo(aDouble)); - } - - @Test - public void unpackPayload_aBooleanPayload_returnsTestModelWithABoolean() throws Exception { - // Given - Boolean aBoolean = false; - String payload = "{\"booleanTest\":%b}"; - - // When - TestModel model = communicator.unpackPayload(String.format(payload, aBoolean), TestModel.class); - - // Then - assertThat(model.getBooleanTest(), equalTo(aBoolean)); - } - - @Test - public void unpackPayload_aGenericBooleanPayload_returnsTestModelWithAGenericBoolean() - throws Exception { - // Given - boolean aBoolean = false; - String payload = "{\"genericBooleanTest\":%b}"; - - // When - TestModel model = communicator.unpackPayload(String.format(payload, aBoolean), TestModel.class); - - // Then - assertThat(model.isGenericBoleanTest(), equalTo(aBoolean)); - } - - @Test - public void unpackPayload_anObjectPayload_returnsTestModelWithAnObject() throws Exception { - // Given - String payload = "{\"objectTest\":{}}"; - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getObjectTest(), instanceOf(TestModel.class)); - } - - @Test - public void unpackPayload_anArrayOfInts_returnsTestModelWithAnArrayOfInts() throws Exception { - // Given - Integer[] anArray = {1, 2, 3}; - String payload = "{\"arrayTest\": [%s]}"; - - // When - TestModel model = - communicator.unpackPayload(String.format(payload, join(",", anArray)), TestModel.class); - - // Then - assertThat(model.getArrayTest(), equalTo(anArray)); - } - - @Test - public void unpackPayload_bootNotificationCallResultPayload_returnBootNotificationConfirmation() - throws Exception { - // Given - String currentTime = "2016-04-28T07:16:11.988Z"; - Calendar someDate = - new Calendar.Builder() - .setDate(2016, 03, 28) - .setTimeOfDay(07, 16, 11, 988) - .setTimeZone(TimeZone.getTimeZone("GMT+00:00")) - .build(); - - int interval = 300; - RegistrationStatus status = RegistrationStatus.Accepted; - String payload = "{\"currentTime\": \"%s\", \"interval\": %d, \"status\": \"%s\"}"; - Class type = BootNotificationConfirmation.class; - - // When - Object result = - communicator.unpackPayload(String.format(payload, currentTime, interval, status), type); - - // Then - assertThat(result, instanceOf(type)); - assertThat(((BootNotificationConfirmation) result).getCurrentTime().compareTo(someDate), is(0)); - assertThat(((BootNotificationConfirmation) result).getInterval(), is(interval)); - assertThat(((BootNotificationConfirmation) result).getStatus(), is(status)); - } - - @Test - public void pack_bootNotificationRequest_returnsBootNotificationRequestPayload() { - // Given - String expected = - "{\"chargePointVendor\":\"VendorX\",\"chargePointModel\":\"SingleSocketCharger\"}"; - BootNotificationRequest request = new BootNotificationRequest("VendorX", "SingleSocketCharger"); - - // When - Object payload = communicator.packPayload(request); - - // Then - assertThat(payload, equalTo(expected)); - } - - @Test - public void pack_bootNotificationConfirmation_returnsBootNotificationConfirmationPayload() - throws Exception { - // Given - String expected = - "{\"currentTime\":\"2016-04-28T06:41:13Z\",\"interval\":300,\"status\":\"Accepted\"}"; - BootNotificationConfirmation confirmation = new BootNotificationConfirmation(); - confirmation.setCurrentTime(createDateTimeInMillis(1461825673720L)); - confirmation.setInterval(300); - confirmation.setStatus(RegistrationStatus.Accepted); - - // When - Object payload = communicator.packPayload(confirmation); - - // Then - assertThat(payload, equalTo(expected)); - } - - @Test - public void disconnect_disconnects() { - // When - communicator.disconnect(); - - // Then - verify(transmitter, times(1)).disconnect(); - } - - @Test - public void sendError_transmitsError() throws Exception { - // Given - String errorCode = "NotImplemented"; - String errorDescription = "Requested Action is not known by receiver"; - - // When - communicator.sendCallError(null, null, errorCode, errorDescription); - - // Then - verify(transmitter, times(1)).send(anyString()); - } - - private Calendar createDateTimeInMillis(long dateInMillis) { - Calendar dateTime = new GregorianCalendar(TimeZone.getTimeZone("GMT+00:00")); - dateTime.setTimeInMillis(dateInMillis); - return dateTime; - } + private JSONCommunicator communicator; + + @Mock private Transmitter transmitter; + + @Before + public void setup() { + communicator = new JSONCommunicator(transmitter); + } + + @Test + public void unpackPayload_emptyPayload_returnRequestedType() throws Exception { + // Given + String payload = "{}"; + Class type = BootNotificationRequest.class; + + // When + Object result = communicator.unpackPayload(payload, type); + + // Then + assertThat(result, instanceOf(type)); + } + + @Test + public void unpackPayload_aStringPayload_returnsTestModelWithAString() throws Exception { + // Given + String aString = "Some string"; + String payload = "{\"stringTest\":\"%s\"}"; + + // When + TestModel model = communicator.unpackPayload(String.format(payload, aString), TestModel.class); + + // Then + assertThat(model.getStringTest(), equalTo(aString)); + } + + @Test + public void unpackPayload_aCalendarPayload_returnsTestModelWithACalendar() throws Exception { + // Given + String aCalendar = "2016-04-28T07:16:11.988Z"; + String payload = "{\"calendarTest\":\"%s\"}"; + + ZonedDateTime someDate = ZonedDateTime.parse("2016-04-28T07:16:11.988Z"); + + // When + TestModel model = + communicator.unpackPayload(String.format(payload, aCalendar), TestModel.class); + + // Then + assertThat(model.getCalendarTest().compareTo(someDate), is(0)); + } + + @Test + public void unpackPayload_anIntegerPayload_returnsTestModelWithAnInteger() throws Exception { + // Given + Integer anInteger = 1337; + String payload = "{\"integerTest\":%d}"; + + // When + TestModel model = + communicator.unpackPayload(String.format(payload, anInteger), TestModel.class); + + // Then + assertThat(model.getIntegerTest(), equalTo(anInteger)); + } + + @Test + public void unpackPayload_aGenericIntPayload_returnsTestModelWithAGenericInt() throws Exception { + // Given + int anInteger = 1337; + String payload = "{\"intTest\":%d}"; + + // When + TestModel model = + communicator.unpackPayload(String.format(payload, anInteger), TestModel.class); + + // Then + assertThat(model.getIntTest(), equalTo(anInteger)); + } + + @Test + public void unpackPayload_aLongPayload_returnsTestModelWithALong() throws Exception { + // Given + Long aLong = 1337L; + String payload = "{\"longTest\":%d}"; + + // When + TestModel model = communicator.unpackPayload(String.format(payload, aLong), TestModel.class); + + // Then + assertThat(model.getLongTest(), equalTo(aLong)); + } + + @Test + public void unpackPayload_aGenericLongPayload_returnsTestModelWithAGenericLong() + throws Exception { + // Given + long aLong = 1337; + String payload = "{\"genericLongTest\":%d}"; + + // When + TestModel model = communicator.unpackPayload(String.format(payload, aLong), TestModel.class); + + // Then + assertThat(model.getGenericLongTest(), equalTo(aLong)); + } + + @Test + public void unpackPayload_aDoublePayload_returnsTestModelWithADouble() throws Exception { + // Given + Double aDouble = 13.37D; + String payload = "{\"doubleTest\":%f}"; + + // When + TestModel model = + communicator.unpackPayload(String.format(Locale.US, payload, aDouble), TestModel.class); + + // Then + assertThat(model.getDoubleTest(), equalTo(aDouble)); + } + + @Test + public void unpackPayload_aGenericDoublePayload_returnsTestModelWithAGenericDouble() + throws Exception { + // Given + double aDouble = 13.37; + String payload = "{\"genericDoubleTest\":%f}"; + + // When + TestModel model = + communicator.unpackPayload(String.format(Locale.US, payload, aDouble), TestModel.class); + + // Then + assertThat(model.getGenericDoubleTest(), equalTo(aDouble)); + } + + @Test + public void unpackPayload_aBooleanPayload_returnsTestModelWithABoolean() throws Exception { + // Given + Boolean aBoolean = false; + String payload = "{\"booleanTest\":%b}"; + + // When + TestModel model = communicator.unpackPayload(String.format(payload, aBoolean), TestModel.class); + + // Then + assertThat(model.getBooleanTest(), equalTo(aBoolean)); + } + + @Test + public void unpackPayload_aGenericBooleanPayload_returnsTestModelWithAGenericBoolean() + throws Exception { + // Given + boolean aBoolean = false; + String payload = "{\"genericBooleanTest\":%b}"; + + // When + TestModel model = communicator.unpackPayload(String.format(payload, aBoolean), TestModel.class); + + // Then + assertThat(model.isGenericBoleanTest(), equalTo(aBoolean)); + } + + @Test + public void unpackPayload_anObjectPayload_returnsTestModelWithAnObject() throws Exception { + // Given + String payload = "{\"objectTest\":{}}"; + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getObjectTest(), instanceOf(TestModel.class)); + } + + @Test + public void unpackPayload_anArrayOfInts_returnsTestModelWithAnArrayOfInts() throws Exception { + // Given + Integer[] anArray = {1, 2, 3}; + String payload = "{\"arrayTest\": [%s]}"; + + // When + TestModel model = + communicator.unpackPayload(String.format(payload, join(",", anArray)), TestModel.class); + + // Then + assertThat(model.getArrayTest(), equalTo(anArray)); + } + + @Test + public void unpackPayload_bootNotificationCallResultPayload_returnBootNotificationConfirmation() + throws Exception { + // Given + String currentTime = "2016-04-28T07:16:11.988Z"; + ZonedDateTime someDate = ZonedDateTime.parse("2016-04-28T07:16:11.988Z"); + + int interval = 300; + RegistrationStatus status = RegistrationStatus.Accepted; + String payload = "{\"currentTime\": \"%s\", \"interval\": %d, \"status\": \"%s\"}"; + Class type = BootNotificationConfirmation.class; + + // When + Object result = + communicator.unpackPayload(String.format(payload, currentTime, interval, status), type); + + // Then + assertThat(result, instanceOf(type)); + assertThat(((BootNotificationConfirmation) result).getCurrentTime().compareTo(someDate), is(0)); + assertThat(((BootNotificationConfirmation) result).getInterval(), is(interval)); + assertThat(((BootNotificationConfirmation) result).getStatus(), is(status)); + } + + @Test + public void pack_bootNotificationRequest_returnsBootNotificationRequestPayload() { + // Given + String expected = + "{\"chargePointVendor\":\"VendorX\",\"chargePointModel\":\"SingleSocketCharger\"}"; + BootNotificationRequest request = new BootNotificationRequest("VendorX", "SingleSocketCharger"); + + // When + Object payload = communicator.packPayload(request); + + // Then + assertThat(payload, equalTo(expected)); + } + + @Test + public void pack_bootNotificationConfirmation_returnsBootNotificationConfirmationPayload() + throws Exception { + // Given + String expected = + "{\"currentTime\":\"2016-04-28T06:41:13.720Z\",\"interval\":300,\"status\":\"Accepted\"}"; + BootNotificationConfirmation confirmation = new BootNotificationConfirmation(); + confirmation.setCurrentTime(createDateTimeInMillis(1461825673720L)); + confirmation.setInterval(300); + confirmation.setStatus(RegistrationStatus.Accepted); + + // When + Object payload = communicator.packPayload(confirmation); + + // Then + assertThat(payload, equalTo(expected)); + } + + @Test + public void disconnect_disconnects() { + // When + communicator.disconnect(); + + // Then + verify(transmitter, times(1)).disconnect(); + } + + @Test + public void sendError_transmitsError() throws Exception { + // Given + String errorCode = "NotImplemented"; + String errorDescription = "Requested Action is not known by receiver"; + + // When + communicator.sendCallError(null, null, errorCode, errorDescription); + + // Then + verify(transmitter, times(1)).send(anyString()); + } + + private ZonedDateTime createDateTimeInMillis(long dateInMillis) { + return Instant.ofEpochMilli(dateInMillis).atOffset(ZoneOffset.UTC).toZonedDateTime(); + } } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/test/SOAPCommunicatorTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/test/SOAPCommunicatorTest.java index d5ed341b4..d93b32917 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/test/SOAPCommunicatorTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/test/SOAPCommunicatorTest.java @@ -1,8 +1,5 @@ package eu.chargetime.ocpp.test; -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.MatcherAssert.assertThat; - import eu.chargetime.ocpp.SOAPCommunicator; import eu.chargetime.ocpp.Transmitter; import eu.chargetime.ocpp.model.SOAPHostInfo; @@ -10,17 +7,6 @@ import eu.chargetime.ocpp.model.core.BootNotificationConfirmation; import eu.chargetime.ocpp.model.core.BootNotificationRequest; import eu.chargetime.ocpp.model.core.RegistrationStatus; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.Calendar; -import java.util.Locale; -import java.util.TimeZone; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -30,12 +16,27 @@ import org.w3c.dom.Document; import org.xml.sax.InputSource; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.StringReader; +import java.io.StringWriter; +import java.time.ZonedDateTime; +import java.util.Locale; + +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; + /* ChargeTime.eu - Java-OCA-OCPP MIT License Copyright (C) 2016-2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -58,290 +59,280 @@ of this software and associated documentation files (the "Software"), to deal @RunWith(MockitoJUnitRunner.class) public class SOAPCommunicatorTest { - private SOAPCommunicator communicator; - private String chargeBoxIdentity = "testIdentity"; - private String fromUrl = "http://localhost"; - private String namespace = "urn://Ocpp/Cs/2015/10"; - - @Mock private Transmitter transmitter; - - @Before - public void setup() { - SOAPHostInfo hostInfo = - new SOAPHostInfo.Builder() - .chargeBoxIdentity(chargeBoxIdentity) - .fromUrl(fromUrl) - .namespace(namespace) - .build(); - communicator = new SOAPCommunicator(hostInfo, transmitter); - } - - @Test - public void unpackPayload_emptyPayload_returnRequestedType() throws Exception { - // Given - Document payload = - stringToDocument( - ""); - Class type = BootNotificationRequest.class; - - // When - Object result = communicator.unpackPayload(payload, type); - - // Then - assertThat(result, instanceOf(type)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_aStringPayload_returnsTestModelWithAString() throws Exception { - // Given - String aString = "Some string"; - String xml = "%s"; - Document payload = stringToDocument(String.format(xml, aString)); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getStringTest(), equalTo(aString)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_aCalendarPayload_returnsTestModelWithACalendar() throws Exception { - // Given - String aCalendar = "2016-04-28T07:16:11.988Z"; - String xml = "%s"; - Document payload = stringToDocument(String.format(xml, aCalendar)); - - Calendar someDate = - new Calendar.Builder() - .setDate(2016, 03, 28) - .setTimeOfDay(07, 16, 11, 988) - .setTimeZone(TimeZone.getTimeZone("GMT+00:00")) - .build(); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getCalendarTest().compareTo(someDate), is(0)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_anIntegerPayload_returnsTestModelWithAnInteger() throws Exception { - // Given - Integer anInteger = 1337; - String xml = "%d"; - Document payload = stringToDocument(String.format(xml, anInteger)); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getIntegerTest(), equalTo(anInteger)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_aGenericIntPayload_returnsTestModelWithAGenericInt() throws Exception { - // Given - int anInteger = 1337; - String xml = "%d"; - Document payload = stringToDocument(String.format(xml, anInteger)); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getIntTest(), equalTo(anInteger)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_aLongPayload_returnsTestModelWithALong() throws Exception { - // Given - Long aLong = 1337L; - String xml = "%d"; - Document payload = stringToDocument(String.format(xml, aLong)); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getLongTest(), equalTo(aLong)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_aGenericLongPayload_returnsTestModelWithAGenericLong() - throws Exception { - // Given - long aLong = 1337; - String xml = "%d"; - Document payload = stringToDocument(String.format(xml, aLong)); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getGenericLongTest(), equalTo(aLong)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_aDoublePayload_returnsTestModelWithADouble() throws Exception { - // Given - Double aDouble = 13.37D; - String xml = "%f"; - Document payload = stringToDocument(String.format(Locale.US, xml, aDouble)); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getDoubleTest(), equalTo(aDouble)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_aGenericDoublePayload_returnsTestModelWithAGenericDouble() - throws Exception { - // Given - double aDouble = 13.37; - String xml = "%f"; - Document payload = stringToDocument(String.format(Locale.US, xml, aDouble)); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getGenericDoubleTest(), equalTo(aDouble)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_aBooleanPayload_returnsTestModelWithABoolean() throws Exception { - // Given - Boolean aBoolean = false; - String xml = "%b"; - Document payload = stringToDocument(String.format(xml, aBoolean)); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getBooleanTest(), equalTo(aBoolean)); - } - - @Test - public void unpackPayload_aGenericBooleanPayload_returnsTestModelWithAGenericBoolean() - throws Exception { - // Given - boolean aBoolean = false; - String xml = "%b"; - Document payload = stringToDocument(String.format(xml, aBoolean)); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.isGenericBoleanTest(), equalTo(aBoolean)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_anObjectPayload_returnsTestModelWithAnObject() throws Exception { - // Given - String xml = ""; - Document payload = stringToDocument(xml); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getObjectTest(), instanceOf(TestModel.class)); - } - - @Test - @Ignore("Only works for ocpp namespaces") - public void unpackPayload_anArrayOfInts_returnsTestModelWithAnArrayOfInts() throws Exception { - // Given - Integer[] anArray = {1, 2, 3}; - String xml = - "123"; - Document payload = stringToDocument(xml); - - // When - TestModel model = communicator.unpackPayload(payload, TestModel.class); - - // Then - assertThat(model.getArrayTest(), equalTo(anArray)); - } - - @Test - public void unpackPayload_bootNotificationCallResultPayload_returnBootNotificationConfirmation() - throws Exception { - // Given - String currentType = "2016-04-28T07:16:11.988Z"; - Calendar someDate = - new Calendar.Builder() - .setDate(2016, 03, 28) - .setTimeOfDay(07, 16, 11, 988) - .setTimeZone(TimeZone.getTimeZone("GMT+00:00")) - .build(); - int interval = 300; - RegistrationStatus status = RegistrationStatus.Accepted; - String xml = - "%s%d%s"; - Document payload = stringToDocument(String.format(xml, currentType, interval, status)); - Class type = BootNotificationConfirmation.class; - - // When - Object result = communicator.unpackPayload(payload, type); - - // Then - assertThat(result, instanceOf(type)); - assertThat(((BootNotificationConfirmation) result).getCurrentTime().compareTo(someDate), is(0)); - assertThat(((BootNotificationConfirmation) result).getStatus(), is(status)); - assertThat(((BootNotificationConfirmation) result).getInterval(), is(interval)); - } - - @Test - public void pack_bootNotificationRequest_returnsBootNotificationRequestPayload() { - // Given - String expected = - "VendorXSingleSocketCharger"; - - BootNotificationRequest request = new BootNotificationRequest("VendorX", "SingleSocketCharger"); - - // When - Document payload = (Document) communicator.packPayload(request); - - // Then - assertThat(docToString(payload), equalTo(expected)); - } - - public static String docToString(Document doc) { - try { - StringWriter sw = new StringWriter(); - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - transformer.transform(new DOMSource(doc), new StreamResult(sw)); - return sw.toString(); - } catch (Exception ex) { - throw new RuntimeException("Error converting to String", ex); + private SOAPCommunicator communicator; + private String chargeBoxIdentity = "testIdentity"; + private String fromUrl = "http://localhost"; + private String namespace = "urn://Ocpp/Cs/2015/10"; + + @Mock private Transmitter transmitter; + + public static String docToString(Document doc) { + try { + StringWriter sw = new StringWriter(); + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer = tf.newTransformer(); + transformer.transform(new DOMSource(doc), new StreamResult(sw)); + return sw.toString(); + } catch (Exception ex) { + throw new RuntimeException("Error converting to String", ex); + } + } + + public static Document stringToDocument(String xml) throws Exception { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + DocumentBuilder db = factory.newDocumentBuilder(); + + InputSource is = new InputSource(); + is.setCharacterStream(new StringReader(xml)); + return db.parse(is); + } + + @Before + public void setup() { + SOAPHostInfo hostInfo = + new SOAPHostInfo.Builder() + .chargeBoxIdentity(chargeBoxIdentity) + .fromUrl(fromUrl) + .namespace(namespace) + .build(); + communicator = new SOAPCommunicator(hostInfo, transmitter); + } + + @Test + public void unpackPayload_emptyPayload_returnRequestedType() throws Exception { + // Given + Document payload = + stringToDocument( + ""); + Class type = BootNotificationRequest.class; + + // When + Object result = communicator.unpackPayload(payload, type); + + // Then + assertThat(result, instanceOf(type)); + } + + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_aStringPayload_returnsTestModelWithAString() throws Exception { + // Given + String aString = "Some string"; + String xml = "%s"; + Document payload = stringToDocument(String.format(xml, aString)); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getStringTest(), equalTo(aString)); + } + + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_aCalendarPayload_returnsTestModelWithACalendar() throws Exception { + // Given + String aCalendar = "2016-04-28T07:16:11.988Z"; + String xml = "%s"; + Document payload = stringToDocument(String.format(xml, aCalendar)); + + ZonedDateTime someDate = ZonedDateTime.parse("2016.04.28T07:16:11.988Z"); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getCalendarTest().compareTo(someDate), is(0)); + } + + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_anIntegerPayload_returnsTestModelWithAnInteger() throws Exception { + // Given + Integer anInteger = 1337; + String xml = "%d"; + Document payload = stringToDocument(String.format(xml, anInteger)); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getIntegerTest(), equalTo(anInteger)); + } + + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_aGenericIntPayload_returnsTestModelWithAGenericInt() throws Exception { + // Given + int anInteger = 1337; + String xml = "%d"; + Document payload = stringToDocument(String.format(xml, anInteger)); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getIntTest(), equalTo(anInteger)); + } + + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_aLongPayload_returnsTestModelWithALong() throws Exception { + // Given + Long aLong = 1337L; + String xml = "%d"; + Document payload = stringToDocument(String.format(xml, aLong)); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getLongTest(), equalTo(aLong)); + } + + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_aGenericLongPayload_returnsTestModelWithAGenericLong() + throws Exception { + // Given + long aLong = 1337; + String xml = "%d"; + Document payload = stringToDocument(String.format(xml, aLong)); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getGenericLongTest(), equalTo(aLong)); + } + + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_aDoublePayload_returnsTestModelWithADouble() throws Exception { + // Given + Double aDouble = 13.37D; + String xml = "%f"; + Document payload = stringToDocument(String.format(Locale.US, xml, aDouble)); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getDoubleTest(), equalTo(aDouble)); + } + + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_aGenericDoublePayload_returnsTestModelWithAGenericDouble() + throws Exception { + // Given + double aDouble = 13.37; + String xml = "%f"; + Document payload = stringToDocument(String.format(Locale.US, xml, aDouble)); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getGenericDoubleTest(), equalTo(aDouble)); + } + + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_aBooleanPayload_returnsTestModelWithABoolean() throws Exception { + // Given + Boolean aBoolean = false; + String xml = "%b"; + Document payload = stringToDocument(String.format(xml, aBoolean)); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getBooleanTest(), equalTo(aBoolean)); + } + + @Test + public void unpackPayload_aGenericBooleanPayload_returnsTestModelWithAGenericBoolean() + throws Exception { + // Given + boolean aBoolean = false; + String xml = "%b"; + Document payload = stringToDocument(String.format(xml, aBoolean)); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.isGenericBoleanTest(), equalTo(aBoolean)); + } + + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_anObjectPayload_returnsTestModelWithAnObject() throws Exception { + // Given + String xml = ""; + Document payload = stringToDocument(xml); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); + + // Then + assertThat(model.getObjectTest(), instanceOf(TestModel.class)); } - } - public static Document stringToDocument(String xml) throws Exception { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder db = factory.newDocumentBuilder(); + @Test + @Ignore("Only works for ocpp namespaces") + public void unpackPayload_anArrayOfInts_returnsTestModelWithAnArrayOfInts() throws Exception { + // Given + Integer[] anArray = {1, 2, 3}; + String xml = + "123"; + Document payload = stringToDocument(xml); + + // When + TestModel model = communicator.unpackPayload(payload, TestModel.class); - InputSource is = new InputSource(); - is.setCharacterStream(new StringReader(xml)); - return db.parse(is); - } + // Then + assertThat(model.getArrayTest(), equalTo(anArray)); + } + + @Test + public void unpackPayload_bootNotificationCallResultPayload_returnBootNotificationConfirmation() + throws Exception { + // Given + String currentType = "2016-04-28T07:16:11.988Z"; + ZonedDateTime someDate = ZonedDateTime.parse("2016-04-28T07:16:11.988Z"); + int interval = 300; + RegistrationStatus status = RegistrationStatus.Accepted; + String xml = + "%s%d%s"; + Document payload = stringToDocument(String.format(xml, currentType, interval, status)); + Class type = BootNotificationConfirmation.class; + + // When + Object result = communicator.unpackPayload(payload, type); + + // Then + assertThat(result, instanceOf(type)); + assertThat(((BootNotificationConfirmation) result).getCurrentTime().compareTo(someDate), is(0)); + assertThat(((BootNotificationConfirmation) result).getStatus(), is(status)); + assertThat(((BootNotificationConfirmation) result).getInterval(), is(interval)); + } + + @Test + public void pack_bootNotificationRequest_returnsBootNotificationRequestPayload() { + // Given + String expected = + "VendorXSingleSocketCharger"; + + BootNotificationRequest request = new BootNotificationRequest("VendorX", "SingleSocketCharger"); + + // When + Document payload = (Document) communicator.packPayload(request); + + // Then + assertThat(docToString(payload), equalTo(expected)); + } } diff --git a/ocpp-v2_0-test/src/main/java/eu/chargetime/ocpp/test/features/BootNotification.java b/ocpp-v2_0-test/src/main/java/eu/chargetime/ocpp/test/features/BootNotification.java index b56b49f63..f55d025e3 100644 --- a/ocpp-v2_0-test/src/main/java/eu/chargetime/ocpp/test/features/BootNotification.java +++ b/ocpp-v2_0-test/src/main/java/eu/chargetime/ocpp/test/features/BootNotification.java @@ -5,6 +5,7 @@ MIT License Copyright (C) 2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -33,45 +34,45 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.basic.types.BootReasonEnumType; import eu.chargetime.ocpp.model.basic.types.ChargingStationType; import eu.chargetime.ocpp.model.basic.types.RegistrationStatusEnumType; -import java.util.Calendar; + +import java.time.ZonedDateTime; import java.util.UUID; public class BootNotification implements IServerBootNotificationRequestHandler { - private BootNotificationFeature feature; - private BootNotificationConfirmation confirmation; + private BootNotificationFeature feature; + private BootNotificationConfirmation confirmation; - public BootNotification() { - feature = new BootNotificationFeature(this); + public BootNotification() { + feature = new BootNotificationFeature(this); - confirmation = new BootNotificationConfirmation(); - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.MILLISECOND, 0); // Make it testable - confirmation.setCurrentTime(calendar); - confirmation.setInterval(42); - confirmation.setStatus(RegistrationStatusEnumType.Accepted); - } + confirmation = new BootNotificationConfirmation(); + ZonedDateTime calendar = ZonedDateTime.now(); + confirmation.setCurrentTime(calendar); + confirmation.setInterval(42); + confirmation.setStatus(RegistrationStatusEnumType.Accepted); + } - @Override - public BootNotificationConfirmation handleBootNotificationRequest( - UUID sessionIndex, BootNotificationRequest request) { - return confirmation; - } + @Override + public BootNotificationConfirmation handleBootNotificationRequest( + UUID sessionIndex, BootNotificationRequest request) { + return confirmation; + } - public BootNotificationConfirmation getConfirmation() { - return confirmation; - } + public BootNotificationConfirmation getConfirmation() { + return confirmation; + } - public BootNotificationRequest createRequest() { - BootNotificationRequest request = new BootNotificationRequest(); - request.setReason(BootReasonEnumType.Unknown); - ChargingStationType chargingStationType = new ChargingStationType(); - request.setChargingStation(chargingStationType); - chargingStationType.setVendorName("ChargeTimeEU"); - chargingStationType.setModel("Test"); - return request; - } + public BootNotificationRequest createRequest() { + BootNotificationRequest request = new BootNotificationRequest(); + request.setReason(BootReasonEnumType.Unknown); + ChargingStationType chargingStationType = new ChargingStationType(); + request.setChargingStation(chargingStationType); + chargingStationType.setVendorName("ChargeTimeEU"); + chargingStationType.setModel("Test"); + return request; + } - public Feature getFeature() { - return feature; - } + public Feature getFeature() { + return feature; + } } diff --git a/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/model/basic/BootNotificationConfirmation.java b/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/model/basic/BootNotificationConfirmation.java index 6866650d1..cbcef2889 100644 --- a/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/model/basic/BootNotificationConfirmation.java +++ b/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/model/basic/BootNotificationConfirmation.java @@ -5,6 +5,7 @@ MIT License Copyright (C) 2018 Thomas Volden + Copyright (C) 2019 Kevin Raddatz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,103 +30,106 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.model.basic.types.RegistrationStatusEnumType; import eu.chargetime.ocpp.model.validation.RequiredValidator; import eu.chargetime.ocpp.utilities.MoreObjects; -import java.util.Calendar; + +import java.time.ZonedDateTime; import java.util.Objects; -/** sent by the CSMS to the Charging Station in response to a {@link BootNotificationRequest}. */ +/** + * sent by the CSMS to the Charging Station in response to a {@link BootNotificationRequest}. + */ public class BootNotificationConfirmation implements Confirmation { - private transient RequiredValidator validator = new RequiredValidator(); - - private Calendar currentTime; - private int interval; - private RegistrationStatusEnumType status; - - /** - * This contains the CSMS’s current time. - * - * @return {@link Calendar} - */ - public Calendar getCurrentTime() { - return currentTime; - } - - /** - * Required. This contains the CSMS’s current time. - * - * @param currentTime {@link Calendar} - */ - public void setCurrentTime(Calendar currentTime) { - validator.validate(currentTime); - this.currentTime = currentTime; - } - - /** - * When Status is Accepted, this contains the heartbeat interval in seconds. If the CSMS returns - * something other than Accepted, the value of the interval field indicates the minimum wait time - * before sending a next BootNotification request. - * - * @return integer - */ - public int getInterval() { - return interval; - } - - /** - * Required. When Status is Accepted, this contains the heartbeat interval in seconds. If the CSMS - * returns something other than Accepted, the value of the interval field indicates the minimum - * wait time before sending a next BootNotification request. - * - * @param interval integer - */ - public void setInterval(int interval) { - this.interval = interval; - } - - /** - * This contains whether the Charging Station has been registered within the CSMS. - * - * @return {@link RegistrationStatusEnumType}. - */ - public RegistrationStatusEnumType getStatus() { - return status; - } - - /** - * Required. This contains whether the Charging Station has been registered within the CSMS. - * - * @param status {@link RegistrationStatusEnumType}. - */ - public void setStatus(RegistrationStatusEnumType status) { - validator.validate(status); - this.status = status; - } - - @Override - public boolean validate() { - return currentTime != null && interval > 0 && status != null; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - BootNotificationConfirmation that = (BootNotificationConfirmation) o; - return currentTime.compareTo(that.currentTime) == 0 - && Objects.equals(interval, that.interval) - && Objects.equals(status, that.status); - } - - @Override - public int hashCode() { - return Objects.hash(currentTime, interval, status); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("currentTime", currentTime) - .add("interval", interval) - .add("status", status) - .toString(); - } + private transient RequiredValidator validator = new RequiredValidator(); + + private ZonedDateTime currentTime; + private int interval; + private RegistrationStatusEnumType status; + + /** + * This contains the CSMS’s current time. + * + * @return {@link ZonedDateTime} + */ + public ZonedDateTime getCurrentTime() { + return currentTime; + } + + /** + * Required. This contains the CSMS’s current time. + * + * @param currentTime {@link ZonedDateTime} + */ + public void setCurrentTime(ZonedDateTime currentTime) { + validator.validate(currentTime); + this.currentTime = currentTime; + } + + /** + * When Status is Accepted, this contains the heartbeat interval in seconds. If the CSMS returns + * something other than Accepted, the value of the interval field indicates the minimum wait time + * before sending a next BootNotification request. + * + * @return integer + */ + public int getInterval() { + return interval; + } + + /** + * Required. When Status is Accepted, this contains the heartbeat interval in seconds. If the CSMS + * returns something other than Accepted, the value of the interval field indicates the minimum + * wait time before sending a next BootNotification request. + * + * @param interval integer + */ + public void setInterval(int interval) { + this.interval = interval; + } + + /** + * This contains whether the Charging Station has been registered within the CSMS. + * + * @return {@link RegistrationStatusEnumType}. + */ + public RegistrationStatusEnumType getStatus() { + return status; + } + + /** + * Required. This contains whether the Charging Station has been registered within the CSMS. + * + * @param status {@link RegistrationStatusEnumType}. + */ + public void setStatus(RegistrationStatusEnumType status) { + validator.validate(status); + this.status = status; + } + + @Override + public boolean validate() { + return currentTime != null && interval > 0 && status != null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BootNotificationConfirmation that = (BootNotificationConfirmation) o; + return currentTime.compareTo(that.currentTime) == 0 + && Objects.equals(interval, that.interval) + && Objects.equals(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hash(currentTime, interval, status); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("currentTime", currentTime) + .add("interval", interval) + .add("status", status) + .toString(); + } }