From a68f54be9a79887453b4e4d570afeeae502c646b Mon Sep 17 00:00:00 2001 From: DB Date: Sat, 29 Feb 2020 12:32:03 +0000 Subject: [PATCH] Update to fix verifyGoogleJavaFormat exception issue ChargeTimeEU #106 --- .../model/core/AuthorizeConfirmation.java | 133 ++- .../ocpp/model/core/AuthorizeRequest.java | 148 ++- .../core/BootNotificationConfirmation.java | 288 +++--- .../model/core/BootNotificationRequest.java | 621 +++++++------ .../model/core/HeartbeatConfirmation.java | 135 ++- .../chargetime/ocpp/model/core/IdTagInfo.java | 260 +++--- .../RemoteStopTransactionConfirmation.java | 133 ++- .../core/RemoteStopTransactionRequest.java | 124 ++- .../model/firmware/UpdateFirmwareRequest.java | 306 ++++--- .../localauthlist/AuthorizationData.java | 143 ++- .../profile/test/ClientCoreProfileTest.java | 860 +++++++++--------- .../ClientFirmwareManagementProfileTest.java | 225 +++-- .../test/ClientLocalAuthListProfileTest.java | 97 +- .../test/ClientRemoteTriggerProfileTest.java | 66 +- .../test/ClientReservationProfileTest.java | 123 ++- .../test/ClientSmartChargingProfileTest.java | 106 ++- .../profile/test/ServerCoreProfileTest.java | 782 ++++++++-------- .../ServerFirmwareManagementProfileTest.java | 175 ++-- .../test/UpdateFirmwareRequestTest.java | 163 ++-- .../test/ReserveNowRequestTest.java | 169 ++-- .../BootNotificationConfirmationTest.java | 1 - .../ocpp/model/test/ChargingProfileTest.java | 357 ++++---- .../ocpp/model/test/ChargingScheduleTest.java | 229 +++-- .../test/GetCompositeScheduleRequestTest.java | 138 +-- .../model/test/HeartbeatConfirmationTest.java | 71 +- .../ocpp/model/test/MeterValueTest.java | 139 ++- .../model/test/MeterValuesRequestTest.java | 166 ++-- .../test/StartTransactionRequestTest.java | 275 +++--- .../test/StatusNotificationRequestTest.java | 267 +++--- .../test/StopTransactionRequestTest.java | 297 +++--- .../ocpp/test/JSONCommunicatorTest.java | 555 ++++++----- .../ocpp/test/SOAPCommunicatorTest.java | 577 ++++++------ 32 files changed, 4039 insertions(+), 4090 deletions(-) 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 8104eed91..6d3011669 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 @@ -31,80 +31,73 @@ 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; - - /** - * @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(); - } + 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 b30707e6c..2d8f35a31 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,10 +4,9 @@ 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 @@ -38,84 +37,79 @@ 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; - - /** - * @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; + 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); } - @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(); - } + 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(); + } } 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 afe21cc70..1d34cf423 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 @@ -32,12 +32,11 @@ 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.time.ZonedDateTime; +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}. @@ -48,147 +47,148 @@ of this software and associated documentation files (the "Software"), to deal @XmlType(propOrder = {"status", "currentTime", "interval"}) public class BootNotificationConfirmation implements Confirmation { - 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; + 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; + } + + /** + * 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"); } - /** - * 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(); - } + 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 0be01fd03..6c02099e3 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 @@ -33,342 +33,339 @@ 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; - - /** - * @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; + 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 contains the ICCID of the modem’s SIM card. - * - * @return ICCID of SIM card. - */ - public String getIccid() { - return iccid; + 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)); } - /** - * 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.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 contains the IMSI of the modem’s SIM card. - * - * @return IMSI of SIM card. - */ - public String getImsi() { - return imsi; + 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)); } - /** - * 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.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 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.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)); } - /** - * 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.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)); } - /** - * 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.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)); } - /** - * 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.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)); } - @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(); - } + 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; + } + + @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/HeartbeatConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/HeartbeatConfirmation.java index b3edf3aae..bd55de04f 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 @@ -29,88 +29,83 @@ import eu.chargetime.ocpp.model.Confirmation; import eu.chargetime.ocpp.utilities.MoreObjects; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; import java.time.ZonedDateTime; import java.util.Objects; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; -/** - * 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 ZonedDateTime currentTime; - - /** - * @deprecated use {@link #HeartbeatConfirmation(ZonedDateTime)} to be sure to set required fields - */ - @Deprecated - public HeartbeatConfirmation() { + 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); - } + /** + * 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 ZonedDateTime 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 ZonedDateTime 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 ZonedDateTime, current time. - */ - @XmlElement - public void setCurrentTime(ZonedDateTime 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 b374bc682..7ffb76dc5 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 @@ -31,12 +31,11 @@ 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.time.ZonedDateTime; +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}, @@ -47,133 +46,130 @@ of this software and associated documentation files (the "Software"), to deal @XmlRootElement @XmlType(propOrder = {"status", "expiryDate", "parentIdTag"}) public class IdTagInfo implements Validatable { - 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(); - } + 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/RemoteStopTransactionConfirmation.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/RemoteStopTransactionConfirmation.java index 883b36b30..5e3c14e4d 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 @@ -29,87 +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; -/** - * 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; + private RemoteStartStopStatus status; - /** - * @deprecated use {@link #RemoteStopTransactionConfirmation(RemoteStartStopStatus)} to be sure to set required fields - */ - @Deprecated - public RemoteStopTransactionConfirmation() { - } + /** + * @deprecated use {@link #RemoteStopTransactionConfirmation(RemoteStartStopStatus)} to be sure to + * set required fields + */ + @Deprecated + public RemoteStopTransactionConfirmation() {} - /** - * Handle 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; + } - /** - * 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; - } + /** + * 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 6bcb5c029..b48009a74 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 @@ -29,83 +29,79 @@ 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; - - /** - * @deprecated use {@link #RemoteStopTransactionRequest(Integer)} to be sure to set required fields - */ - @Deprecated - public RemoteStopTransactionRequest() { + 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); - } + /** + * 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; - } + @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/firmware/UpdateFirmwareRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/firmware/UpdateFirmwareRequest.java index c663fc8a1..931c0aa9b 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 @@ -31,170 +31,168 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.Request; import eu.chargetime.ocpp.utilities.MoreObjects; - +import java.time.ZonedDateTime; +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 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; - } - - /** - * 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 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); + 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; + } + + /** + * 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"); } - @Override - public int hashCode() { - return Objects.hash(location, retries, retrieveDate, retryInterval); + this.retries = retries; + } + + /** + * 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"); } - @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.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/localauthlist/AuthorizationData.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/localauthlist/AuthorizationData.java index 9ffca0079..28e93c95a 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 @@ -32,88 +32,83 @@ 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; - - /** - * @deprecated use {@link #AuthorizationData(String)} be sure to set required fields - */ - @Deprecated - public AuthorizationData() { - + 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"); } - /** - * Handle required fields. - * - * @param idTag String, the idTag, see {@link #setIdTag(String)} - */ - public AuthorizationData(String idTag) { - setIdTag(idTag); - } + this.idTag = idTag; + } - /** - * The identifier to which this authorization applies - * - * @return String the idTag - */ - public String getIdTag() { - return idTag; - } + public IdTagInfo getIdTagInfo() { + return idTagInfo; + } - /** - * 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; + public void setIdTagInfo(IdTagInfo idTagInfo) { + if (!idTagInfo.validate()) { + throw new PropertyConstraintException(idTagInfo, "Failed Validation"); } - public IdTagInfo getIdTagInfo() { - return idTagInfo; - } - - public void setIdTagInfo(IdTagInfo idTagInfo) { - if (!idTagInfo.validate()) { - throw new PropertyConstraintException(idTagInfo, "Failed Validation"); - } - - this.idTagInfo = 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(); - } + this.idTagInfo = 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(); + } } 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 d7addb5f0..997d96537 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,25 +1,24 @@ 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.*; + 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.*; +import java.time.ZonedDateTime; +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.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; - /* ChargeTime.eu - Java-OCA-OCPP Copyright (C) 2015-2016 Thomas Volden @@ -50,426 +49,427 @@ 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 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)); - } + 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 8fee5b04a..c4f00ab13 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 @@ -26,129 +26,128 @@ 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.time.ZonedDateTime; +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("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)); - } + 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 bd1be7f39..e4286b89e 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 @@ -25,6 +25,13 @@ * SOFTWARE. */ +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.Feature; import eu.chargetime.ocpp.feature.GetLocalListVersionFeature; import eu.chargetime.ocpp.feature.SendLocalListFeature; @@ -33,74 +40,66 @@ import eu.chargetime.ocpp.model.localauthlist.GetLocalListVersionRequest; import eu.chargetime.ocpp.model.localauthlist.SendLocalListRequest; import eu.chargetime.ocpp.model.localauthlist.UpdateType; +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.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(0, UpdateType.Full); + 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 3a5fd5e20..f8b4d1800 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,5 +1,9 @@ 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.ClientRemoteTriggerEventHandler; import eu.chargetime.ocpp.feature.profile.ClientRemoteTriggerProfile; import eu.chargetime.ocpp.model.Confirmation; @@ -7,18 +11,13 @@ import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequest; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageRequestType; import eu.chargetime.ocpp.model.remotetrigger.TriggerMessageStatus; +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.util.UUID; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; - /* * ChargeTime.eu - Java-OCA-OCPP * @@ -49,38 +48,41 @@ @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 ClientRemoteTriggerEventHandler 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(TriggerMessageRequestType.BootNotification); + @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(TriggerMessageStatus.Accepted)); - TriggerMessageRequest request = new TriggerMessageRequest(TriggerMessageRequestType.BootNotification); + @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 8ae7e2c21..4edc50d6e 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 @@ -27,6 +27,13 @@ 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.CancelReservationFeature; import eu.chargetime.ocpp.feature.Feature; import eu.chargetime.ocpp.feature.ReserveNowFeature; @@ -34,74 +41,66 @@ of this software and associated documentation files (the "Software"), to deal import eu.chargetime.ocpp.feature.profile.ClientReservationProfile; import eu.chargetime.ocpp.model.reservation.CancelReservationRequest; import eu.chargetime.ocpp.model.reservation.ReserveNowRequest; +import java.time.ZonedDateTime; +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(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)); - } + 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 1316b2f73..47e74d51d 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,22 +1,21 @@ 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.core.ChargingProfile; import eu.chargetime.ocpp.model.smartcharging.*; +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.util.UUID; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; - /* * ChargeTime.eu - Java-OCA-OCPP * @@ -47,66 +46,65 @@ @RunWith(MockitoJUnitRunner.class) public class ClientSmartChargingProfileTest { - private static final UUID SESSION_NULL = null; - private ClientSmartChargingProfile smartCharging; - - @Mock private ClientSmartChargingEventHandler handler; + private static final UUID SESSION_NULL = null; + private ClientSmartChargingProfile smartCharging; - @Before - public void setup() { - smartCharging = new ClientSmartChargingProfile(handler); - } + @Mock private ClientSmartChargingEventHandler handler; - @Test - public void handleRequest_SetChargingProfileRequest_callsHandleSetChargingProfileRequest() { - // Given - SetChargingProfileRequest request = new SetChargingProfileRequest(0, new ChargingProfile()); + @Before + public void setup() { + smartCharging = new ClientSmartChargingProfile(handler); + } - // When - smartCharging.handleRequest(SESSION_NULL, request); + @Test + public void handleRequest_SetChargingProfileRequest_callsHandleSetChargingProfileRequest() { + // Given + SetChargingProfileRequest request = new SetChargingProfileRequest(0, new ChargingProfile()); - // Then - verify(handler, times(1)).handleSetChargingProfileRequest(request); - } + // When + smartCharging.handleRequest(SESSION_NULL, request); - @Test - public void handleRequest_SetChargingProfileRequest_returnsSetChargingProfileConfirmation() { - // Given - when(handler.handleSetChargingProfileRequest(any())) - .thenReturn(new SetChargingProfileConfirmation()); - SetChargingProfileRequest request = new SetChargingProfileRequest(); + // Then + verify(handler, times(1)).handleSetChargingProfileRequest(request); + } - // When - Confirmation conf = smartCharging.handleRequest(SESSION_NULL, request); + @Test + public void handleRequest_SetChargingProfileRequest_returnsSetChargingProfileConfirmation() { + // Given + when(handler.handleSetChargingProfileRequest(any())) + .thenReturn(new SetChargingProfileConfirmation()); + SetChargingProfileRequest request = new SetChargingProfileRequest(); - // Then - assertThat(conf, instanceOf(SetChargingProfileConfirmation.class)); - } + // When + Confirmation conf = smartCharging.handleRequest(SESSION_NULL, request); - @Test - public void handleRequest_GetCompositeSchedule_callsHandleGetCompositeScheduleRequest() { - // Given - GetCompositeScheduleRequest request = new GetCompositeScheduleRequest(0, 0); + // Then + assertThat(conf, instanceOf(SetChargingProfileConfirmation.class)); + } - // When - smartCharging.handleRequest(SESSION_NULL, request); + @Test + public void handleRequest_GetCompositeSchedule_callsHandleGetCompositeScheduleRequest() { + // Given + GetCompositeScheduleRequest request = new GetCompositeScheduleRequest(0, 0); - // Then - verify(handler, times(1)).handleGetCompositeScheduleRequest(request); - } + // When + smartCharging.handleRequest(SESSION_NULL, request); - @Test - public void handleRequest_GetCompositeScheduleRequest_returnGetCompositeScheduleConfirmation() { - // Given - when(handler.handleGetCompositeScheduleRequest(any())) - .thenReturn(new GetCompositeScheduleConfirmation(GetCompositeScheduleStatus.Accepted)); - GetCompositeScheduleRequest request = new GetCompositeScheduleRequest(0, 0); + // Then + verify(handler, times(1)).handleGetCompositeScheduleRequest(request); + } - // When - Confirmation conf = smartCharging.handleRequest(SESSION_NULL, request); + @Test + public void handleRequest_GetCompositeScheduleRequest_returnGetCompositeScheduleConfirmation() { + // Given + when(handler.handleGetCompositeScheduleRequest(any())) + .thenReturn(new GetCompositeScheduleConfirmation(GetCompositeScheduleStatus.Accepted)); + GetCompositeScheduleRequest request = new GetCompositeScheduleRequest(0, 0); - // Then - assertThat(conf, instanceOf(GetCompositeScheduleConfirmation.class)); - } + // When + Confirmation conf = smartCharging.handleRequest(SESSION_NULL, request); + // Then + assertThat(conf, instanceOf(GetCompositeScheduleConfirmation.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 e8aeea74e..9e8c6370c 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,25 +1,24 @@ 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.*; import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler; import eu.chargetime.ocpp.feature.profile.ServerCoreProfile; import eu.chargetime.ocpp.model.core.*; +import java.time.ZonedDateTime; +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.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 @@ -50,384 +49,387 @@ 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("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)); - } + 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 315254962..d6f06736c 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 @@ -26,6 +26,12 @@ 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; @@ -33,6 +39,7 @@ of this software and associated documentation files (the "Software"), to deal 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; @@ -40,93 +47,87 @@ 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(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)); - } + 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 4082b75a5..75736b1f3 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 @@ -27,119 +27,118 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.firmware.UpdateFirmwareRequest; +import java.time.ZonedDateTime; 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 = "/"; - ZonedDateTime aRetrieveDate = ZonedDateTime.now(); - 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 b4e72a563..3133b0244 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 @@ -27,98 +27,97 @@ of this software and associated documentation files (the "Software"), to deal SOFTWARE. */ +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.reservation.ReserveNowRequest; +import java.time.ZonedDateTime; 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; - 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)); - } + @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 5eb3a0915..86f01a043 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,6 @@ import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.core.BootNotificationConfirmation; import eu.chargetime.ocpp.model.core.RegistrationStatus; - import java.time.ZonedDateTime; import org.junit.Before; import org.junit.Rule; 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 0ba7e9376..0d2aa437d 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,19 +1,18 @@ package eu.chargetime.ocpp.model.test; +import static org.hamcrest.CoreMatchers.*; +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.*; +import java.time.ZonedDateTime; 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 * @@ -42,189 +41,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 - 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)); - } + @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 41ad0ca6d..2088c6b8a 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,19 +1,18 @@ package eu.chargetime.ocpp.model.test; -import eu.chargetime.ocpp.model.core.ChargingRateUnitType; -import eu.chargetime.ocpp.model.core.ChargingSchedule; -import eu.chargetime.ocpp.model.core.ChargingSchedulePeriod; -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.*; +import eu.chargetime.ocpp.model.core.ChargingRateUnitType; +import eu.chargetime.ocpp.model.core.ChargingSchedule; +import eu.chargetime.ocpp.model.core.ChargingSchedulePeriod; +import java.time.ZonedDateTime; +import org.junit.Before; +import org.junit.Test; + /* * ChargeTime.eu - Java-OCA-OCPP * @@ -41,111 +40,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 - 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)); - } + 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 index e736b255d..78b953bbc 100644 --- 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 @@ -1,5 +1,8 @@ package eu.chargetime.ocpp.model.test; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.smartcharging.ChangingRateUnitType; import eu.chargetime.ocpp.model.smartcharging.GetCompositeScheduleRequest; @@ -10,9 +13,6 @@ 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 * @@ -42,91 +42,91 @@ @RunWith(MockitoJUnitRunner.class) public class GetCompositeScheduleRequestTest { - @Rule public ExpectedException thrownException = ExpectedException.none(); + @Rule public ExpectedException thrownException = ExpectedException.none(); - private GetCompositeScheduleRequest request; + private GetCompositeScheduleRequest request; - @Before - public void setUp() { - request = new GetCompositeScheduleRequest(); - } + @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]")); + @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 setDuration_zeroInteger_durationIsSet() { - // Given - int zeroValue = 0; + @Test + public void setDuration_zeroInteger_durationIsSet() { + // Given + int zeroValue = 0; - // When - request.setDuration(zeroValue); + // When + request.setDuration(zeroValue); - // Then - assertThat(request.getDuration(), equalTo(zeroValue)); - } + // Then + assertThat(request.getDuration(), equalTo(zeroValue)); + } - @Test - public void setChangingRateUnitType_A_changingRateUnitTypeIsSet() { - // Given - ChangingRateUnitType chargingRateUnitType = ChangingRateUnitType.A; + @Test + public void setChangingRateUnitType_A_changingRateUnitTypeIsSet() { + // Given + ChangingRateUnitType chargingRateUnitType = ChangingRateUnitType.A; - // When - request.setChangingRateUnitType(chargingRateUnitType); + // When + request.setChangingRateUnitType(chargingRateUnitType); - // Then - assertThat(request.getChangingRateUnitType(), equalTo(chargingRateUnitType)); - } + // Then + assertThat(request.getChangingRateUnitType(), equalTo(chargingRateUnitType)); + } - @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_connectorIdAndMeterValueIsValid_returnTrue() { - // Given - request.setConnectorId(42); - request.setDuration(0); - request.setChangingRateUnitType(ChangingRateUnitType.A); + @Test + public void validate_connectorIdAndMeterValueIsValid_returnTrue() { + // Given + request.setConnectorId(42); + request.setDuration(0); + request.setChangingRateUnitType(ChangingRateUnitType.A); - // 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/HeartbeatConfirmationTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/HeartbeatConfirmationTest.java index e8505ffa7..18677492b 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,15 +1,14 @@ package eu.chargetime.ocpp.model.test; -import eu.chargetime.ocpp.model.core.HeartbeatConfirmation; -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; +import eu.chargetime.ocpp.model.core.HeartbeatConfirmation; +import java.time.ZonedDateTime; +import org.junit.Before; +import org.junit.Test; + /* * ChargeTime.eu - Java-OCA-OCPP * @@ -37,43 +36,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 - ZonedDateTime now = ZonedDateTime.now(); + @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(ZonedDateTime.now()); + @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 5b422e8e2..f5643ad0b 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,21 +1,20 @@ 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.MeterValue; import eu.chargetime.ocpp.model.core.SampledValue; +import java.time.ZonedDateTime; 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 * @@ -45,87 +44,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 - ZonedDateTime now = ZonedDateTime.now(); + @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(ZonedDateTime.now()); - 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(ZonedDateTime.now()); - 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 cd7b768a8..bcb50c849 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,5 +1,10 @@ package eu.chargetime.ocpp.model.test; +import static eu.chargetime.ocpp.utilities.TestUtilities.aList; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.*; + import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.core.MeterValue; import eu.chargetime.ocpp.model.core.MeterValuesRequest; @@ -11,11 +16,6 @@ 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 * @@ -45,107 +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)); - request.setConnectorId(1); - when(meterValueMock.validate()).thenReturn(true); + @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 aa57cb31d..a74a3c213 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,18 +1,17 @@ package eu.chargetime.ocpp.model.test; +import static eu.chargetime.ocpp.utilities.TestUtilities.aString; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; + import eu.chargetime.ocpp.PropertyConstraintException; import eu.chargetime.ocpp.model.core.StartTransactionRequest; +import java.time.ZonedDateTime; 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 * @@ -41,137 +40,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 - 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)); - } + 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 e6c130be3..1fca0829e 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,20 +1,19 @@ package eu.chargetime.ocpp.model.test; +import static eu.chargetime.ocpp.utilities.TestUtilities.aString; +import static org.hamcrest.CoreMatchers.*; +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.time.ZonedDateTime; 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 * @@ -43,180 +42,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; - private static String createExpectedExceptionMessage(int maxAllowedLength, int currentLength) { - return String.format(EXCEPTION_MESSAGE_TEMPLATE, maxAllowedLength, currentLength); - } + private static String createExpectedExceptionMessage(int maxAllowedLength, int currentLength) { + return String.format(EXCEPTION_MESSAGE_TEMPLATE, maxAllowedLength, currentLength); + } - @Before - public void setUp() { - request = new StatusNotificationRequest(); - } + @Before + public void setUp() { + request = new StatusNotificationRequest(); + } - @Test - public void setConnectorId_negativeInteger_throwsPropertyConstraintException() { + @Test + public void setConnectorId_negativeInteger_throwsPropertyConstraintException() { - thrownException.expect(instanceOf(PropertyConstraintException.class)); - thrownException.expectMessage( - equalTo("Validation failed: [connectorId >= 0]. Current Value: [-42]")); + thrownException.expect(instanceOf(PropertyConstraintException.class)); + thrownException.expectMessage( + equalTo("Validation failed: [connectorId >= 0]. Current Value: [-42]")); - Integer negativeValue = -42; + Integer negativeValue = -42; - request.setConnectorId(negativeValue); - } + request.setConnectorId(negativeValue); + } - @Test - public void setConnectorId_zeroInteger_connectorIdIsSet() { - // Given - Integer zeroValue = 0; + @Test + public void setConnectorId_zeroInteger_connectorIdIsSet() { + // Given + Integer 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 setErrorCode_chargePointErrorCode_errorCodeIsSet() { - // Given - ChargePointErrorCode chargePointErrorCode = ChargePointErrorCode.NoError; + @Test + public void setErrorCode_chargePointErrorCode_errorCodeIsSet() { + // Given + ChargePointErrorCode chargePointErrorCode = ChargePointErrorCode.NoError; - // When - request.setErrorCode(chargePointErrorCode); + // When + request.setErrorCode(chargePointErrorCode); - // Then - assertThat(request.getErrorCode(), equalTo(chargePointErrorCode)); - } + // Then + assertThat(request.getErrorCode(), equalTo(chargePointErrorCode)); + } - @Test - public void setInfo_stringLength51_throwsPropertyConstraintException() { + @Test + public void setInfo_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.setInfo(length51); - } + 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 - ZonedDateTime now = ZonedDateTime.now(); + @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 45d35475e..2f2734ad1 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,23 +1,22 @@ 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.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.*; + 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.time.ZonedDateTime; 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 * @@ -46,156 +45,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 - ZonedDateTime now = ZonedDateTime.now(); - - // 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(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)); - } + // 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 d7ce883d3..20aba0130 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,27 +1,26 @@ 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.time.Instant; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.Locale; 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 @@ -52,272 +51,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\"}"; - - 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(); - } + 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 d93b32917..1c9035af5 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,5 +1,8 @@ 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; @@ -7,6 +10,16 @@ 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.time.ZonedDateTime; +import java.util.Locale; +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; @@ -16,20 +29,6 @@ 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 @@ -59,280 +58,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; - - 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)); - } - - @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"; - 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)); + 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)); + } + + @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"; + 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)); + } }