Code refactoring of hawkbit-ddi-api (#2052)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -24,10 +24,26 @@
|
||||
<name>hawkBit :: DDI :: REST API</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-rest-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.hateoas</groupId>
|
||||
<artifactId>spring-hateoas</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
@@ -36,19 +52,6 @@
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-cbor</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-rest-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
|
||||
@@ -16,32 +16,34 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* After the HawkBit Target has executed an action, received by a GET(URL)
|
||||
* request it reports the completion of it to the HawkBit Server with a action
|
||||
* status message, i.e. with a PUT message to the feedback channel, i.e. PUT
|
||||
* URL/feedback. This message could be used not only at the end of execution but
|
||||
* also as status updates during a longer lasting execution period. The format
|
||||
* of each action answer message is defined below at each action. But it is
|
||||
* expected, that the contents of the message answers have all a similar
|
||||
* structure: The content starts with a generic header and additional elements.
|
||||
* *
|
||||
* After the HawkBit Target has executed an action, received by a GET(URL) request it reports the
|
||||
* completion of it to the HawkBit Server with an action status message, i.e. with a PUT message to the
|
||||
* feedback channel, i.e. PUT URL/feedback.
|
||||
* This message could be used not only at the end of execution but also as status updates during a longer lasting execution period.
|
||||
* The format of each action answer message is defined below at each action. But it is expected, that the contents of the message answers
|
||||
* have all a similar structure:
|
||||
* The content starts with a generic header and additional elements.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The answer header would look like: { "time": "20140511T121314", "status": {
|
||||
* "execution": "closed", "result": { "final": "success", "progress": {} }
|
||||
* "details": [], } }
|
||||
* The answer header would look like: {
|
||||
* "time": "20140511T121314",
|
||||
* "status": {
|
||||
* "execution": "closed",
|
||||
* "result": {
|
||||
* "final": "success",
|
||||
* "progress": {}
|
||||
* }
|
||||
* "details": []
|
||||
* }
|
||||
* }
|
||||
* </p>
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiActionFeedback {
|
||||
|
||||
|
||||
@@ -13,22 +13,18 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiActivateAutoConfirmation {
|
||||
|
||||
@JsonProperty(required = false)
|
||||
@JsonProperty
|
||||
@Schema(description = "Individual value (e.g. username) stored as initiator and automatically used as confirmed" +
|
||||
" user in future actions", example = "exampleUser")
|
||||
private final String initiator;
|
||||
|
||||
@JsonProperty(required = false)
|
||||
@JsonProperty
|
||||
@Schema(description = "Individual value to attach a remark which will be persisted when automatically " +
|
||||
"confirming future actions", example = "exampleRemark")
|
||||
private final String remark;
|
||||
@@ -40,7 +36,8 @@ public class DdiActivateAutoConfirmation {
|
||||
* @param remark can be null
|
||||
*/
|
||||
@JsonCreator
|
||||
public DdiActivateAutoConfirmation(@JsonProperty(value = "initiator") final String initiator,
|
||||
public DdiActivateAutoConfirmation(
|
||||
@JsonProperty(value = "initiator") final String initiator,
|
||||
@JsonProperty(value = "remark") final String remark) {
|
||||
this.initiator = initiator;
|
||||
this.remark = remark;
|
||||
|
||||
@@ -13,10 +13,12 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Allow a target to declare running distribution set version
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiAssignedVersion {
|
||||
|
||||
@@ -33,22 +35,15 @@ public class DdiAssignedVersion {
|
||||
* @param version Distribution set version
|
||||
*/
|
||||
@JsonCreator
|
||||
public DdiAssignedVersion(@JsonProperty(value = "name", required = true) String name,
|
||||
@JsonProperty(value = "version", required = true) String version) {
|
||||
public DdiAssignedVersion(
|
||||
@JsonProperty(value = "name", required = true) final String name,
|
||||
@JsonProperty(value = "version", required = true) final String version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DdiInstalledVersion{" + "name='" + name + '\'' + ", version='" + version + '\'' + '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,8 +33,10 @@ public class DdiAutoConfirmationState extends RepresentationModel<DdiAutoConfirm
|
||||
@NotNull
|
||||
@Schema(example = "true")
|
||||
private boolean active;
|
||||
|
||||
@Schema(example = "exampleUserId")
|
||||
private String initiator;
|
||||
|
||||
@Schema(example = "exampleRemark")
|
||||
private String remark;
|
||||
|
||||
|
||||
@@ -15,16 +15,12 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Cancel action to be provided to the target.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiCancel {
|
||||
|
||||
@@ -42,7 +38,8 @@ public class DdiCancel {
|
||||
* @param cancelAction the action
|
||||
*/
|
||||
@JsonCreator
|
||||
public DdiCancel(@JsonProperty("id") final String id,
|
||||
public DdiCancel(
|
||||
@JsonProperty("id") final String id,
|
||||
@JsonProperty("cancelAction") final DdiCancelActionToStop cancelAction) {
|
||||
this.id = id;
|
||||
this.cancelAction = cancelAction;
|
||||
|
||||
@@ -15,16 +15,12 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* The action that has to be stopped by the target.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiCancelActionToStop {
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ public class DdiChunk {
|
||||
* @param artifacts download information
|
||||
* @param metadata optional as additional information for the target/device
|
||||
*/
|
||||
public DdiChunk(final String part, final String version, final String name, final Boolean encrypted,
|
||||
public DdiChunk(
|
||||
final String part, final String version, final String name, final Boolean encrypted,
|
||||
final List<DdiArtifact> artifacts, final List<DdiMetadata> metadata) {
|
||||
this.part = part;
|
||||
this.version = version;
|
||||
|
||||
@@ -17,16 +17,12 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Feedback channel for ConfigData action.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Schema(example = """
|
||||
{
|
||||
|
||||
@@ -58,11 +58,6 @@ public class DdiConfirmationBase extends RepresentationModel<DdiConfirmationBase
|
||||
@NotNull
|
||||
private DdiAutoConfirmationState autoConfirm;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param autoConfirmState
|
||||
*/
|
||||
public DdiConfirmationBase(final DdiAutoConfirmationState autoConfirmState) {
|
||||
this.autoConfirm = autoConfirmState;
|
||||
}
|
||||
|
||||
@@ -228,11 +228,9 @@ public class DdiConfirmationBaseAction extends RepresentationModel<DdiConfirmati
|
||||
*
|
||||
* @param id of the update action
|
||||
* @param confirmation chunk details
|
||||
* @param actionHistory containing current action status and a list of feedback messages
|
||||
* received earlier from the controller.
|
||||
* @param actionHistory containing current action status and a list of feedback messages received earlier from the controller.
|
||||
*/
|
||||
public DdiConfirmationBaseAction(final String id, final DdiDeployment confirmation,
|
||||
final DdiActionHistory actionHistory) {
|
||||
public DdiConfirmationBaseAction(final String id, final DdiDeployment confirmation, final DdiActionHistory actionHistory) {
|
||||
this.id = id;
|
||||
this.confirmation = confirmation;
|
||||
this.actionHistory = actionHistory;
|
||||
|
||||
@@ -20,18 +20,14 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* New update actions require confirmation when confirmation flow is switched on. This is the feedback channel for
|
||||
* confirmation messages for DDI API. The confirmation message has a mandatory field confirmation with possible values:
|
||||
* "confirmed" and "denied".
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiConfirmationFeedback {
|
||||
|
||||
@@ -39,13 +35,15 @@ public class DdiConfirmationFeedback {
|
||||
@Valid
|
||||
@Schema(description = "Action confirmation state")
|
||||
private final Confirmation confirmation;
|
||||
|
||||
@Schema(description = "(Optional) Individual status code", example = "200")
|
||||
private final Integer code;
|
||||
|
||||
@Schema(description = "List of detailed message information", example = "[ \"Feedback message\" ]")
|
||||
private final List<String> details;
|
||||
|
||||
/**
|
||||
* Constructs an confirmation-feedback
|
||||
* Constructs a confirmation-feedback
|
||||
*
|
||||
* @param confirmation confirmation value for the action. Valid values are "Confirmed" and "Denied
|
||||
* @param code code for confirmation
|
||||
|
||||
@@ -39,14 +39,17 @@ public class DdiDeployment {
|
||||
Handling for the download part of the provisioning process ('skip': do not download yet, 'attempt': server asks
|
||||
to download, 'forced': server requests immediate download)""")
|
||||
private HandlingType download;
|
||||
|
||||
@Schema(description = """
|
||||
Handling for the update part of the provisioning process ('skip': do not update yet,
|
||||
'attempt': server asks to update, 'forced': server requests immediate update)""")
|
||||
private HandlingType update;
|
||||
|
||||
@JsonProperty("chunks")
|
||||
@NotNull
|
||||
@Schema(description = "Software chunks of an update. In server mapped by Software Module")
|
||||
private List<DdiChunk> chunks;
|
||||
|
||||
@Schema(description = """
|
||||
Separation of download and installation by defining a maintenance window for the installation. Status shows if
|
||||
currently in a window""")
|
||||
@@ -59,14 +62,12 @@ public class DdiDeployment {
|
||||
* @param update handling type
|
||||
* @param chunks to handle.
|
||||
* @param maintenanceWindow specifying whether there is a maintenance schedule associated.
|
||||
* If it is, the value is either 'available' (i.e. the
|
||||
* maintenance window is now available as per defined schedule
|
||||
* and the update can progress) or 'unavailable' (implying that
|
||||
* maintenance window is not available now and update should not
|
||||
* be attempted). If there is no maintenance schedule defined,
|
||||
* the parameter is null.
|
||||
* If it is, the value is either 'available' (i.e. the maintenance window is now available as per defined schedule
|
||||
* and the update can progress) or 'unavailable' (implying that maintenance window is not available now and update should not
|
||||
* be attempted). If there is no maintenance schedule defined, the parameter is null.
|
||||
*/
|
||||
public DdiDeployment(final HandlingType download, final HandlingType update, final List<DdiChunk> chunks,
|
||||
public DdiDeployment(
|
||||
final HandlingType download, final HandlingType update, final List<DdiChunk> chunks,
|
||||
final DdiMaintenanceWindowStatus maintenanceWindow) {
|
||||
this.download = download;
|
||||
this.update = update;
|
||||
|
||||
@@ -222,8 +222,7 @@ public class DdiDeploymentBase extends RepresentationModel<DdiDeploymentBase> {
|
||||
*
|
||||
* @param id of the update action
|
||||
* @param deployment details
|
||||
* @param actionHistory containing current action status and a list of feedback
|
||||
* messages received earlier from the controller.
|
||||
* @param actionHistory containing current action status and a list of feedback messages received earlier from the controller.
|
||||
*/
|
||||
public DdiDeploymentBase(final String id, final DdiDeployment deployment, final DdiActionHistory actionHistory) {
|
||||
this.id = id;
|
||||
|
||||
@@ -15,16 +15,12 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Additional metadata to be provided for the target/device.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiMetadata {
|
||||
|
||||
|
||||
@@ -14,10 +14,19 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Polling interval for the SP target.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PUBLIC)// needed for json create
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Schema(description = "Suggested sleep time between polls")
|
||||
@@ -35,15 +44,4 @@ public class DdiPolling {
|
||||
public DdiPolling(final String sleep) {
|
||||
this.sleep = sleep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public DdiPolling() {
|
||||
// needed for json create
|
||||
}
|
||||
|
||||
public String getSleep() {
|
||||
return sleep;
|
||||
}
|
||||
}
|
||||
@@ -15,17 +15,12 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Action fulfillment progress by means of gives the achieved amount of maximal
|
||||
* of possible levels.
|
||||
* Action fulfillment progress by means of gives the achieved amount of maximal of possible levels.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiProgress {
|
||||
|
||||
|
||||
@@ -17,17 +17,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Result information of the action progress which can by an intermediate or
|
||||
* final update.
|
||||
* Result information of the action progress which can by an intermediate or final update.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiResult {
|
||||
|
||||
@@ -35,6 +30,7 @@ public class DdiResult {
|
||||
@Valid
|
||||
@Schema(description = "Result of the action execution")
|
||||
private final FinalResult finished;
|
||||
|
||||
@Schema(description = "Progress assumption of the device (currently not supported)")
|
||||
private final DdiProgress progress;
|
||||
|
||||
@@ -45,7 +41,8 @@ public class DdiResult {
|
||||
* @param progress if not yet finished
|
||||
*/
|
||||
@JsonCreator
|
||||
public DdiResult(@JsonProperty("finished") final FinalResult finished,
|
||||
public DdiResult(
|
||||
@JsonProperty("finished") final FinalResult finished,
|
||||
@JsonProperty("progress") final DdiProgress progress) {
|
||||
this.finished = finished;
|
||||
this.progress = progress;
|
||||
|
||||
@@ -20,16 +20,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Details status information concerning the action processing.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Schema(description = "Target action status")
|
||||
public class DdiStatus {
|
||||
@@ -38,12 +34,15 @@ public class DdiStatus {
|
||||
@Valid
|
||||
@Schema(description = "Status of the action execution")
|
||||
private final ExecutionStatus execution;
|
||||
|
||||
@NotNull
|
||||
@Valid
|
||||
@Schema(description = "Result of the action execution")
|
||||
private final DdiResult result;
|
||||
|
||||
@Schema(description = "(Optional) Individual status code", example = "200")
|
||||
private final Integer code;
|
||||
|
||||
@Schema(description = "List of details message information", example = "[ \"Some feedback\" ]")
|
||||
private final List<String> details;
|
||||
|
||||
@@ -56,8 +55,10 @@ public class DdiStatus {
|
||||
* @param details as optional addition
|
||||
*/
|
||||
@JsonCreator
|
||||
public DdiStatus(@JsonProperty("execution") final ExecutionStatus execution,
|
||||
@JsonProperty("result") final DdiResult result, @JsonProperty("code") final Integer code,
|
||||
public DdiStatus(
|
||||
@JsonProperty("execution") final ExecutionStatus execution,
|
||||
@JsonProperty("result") final DdiResult result,
|
||||
@JsonProperty("code") final Integer code,
|
||||
@JsonProperty("details") final List<String> details) {
|
||||
this.execution = execution;
|
||||
this.result = result;
|
||||
@@ -74,8 +75,7 @@ public class DdiStatus {
|
||||
}
|
||||
|
||||
/**
|
||||
* The element status contains information about the execution of the
|
||||
* operation.
|
||||
* The element status contains information about the execution of the operation.
|
||||
*/
|
||||
public enum ExecutionStatus {
|
||||
/**
|
||||
@@ -118,7 +118,7 @@ public class DdiStatus {
|
||||
*/
|
||||
DOWNLOAD("download");
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
ExecutionStatus(final String name) {
|
||||
this.name = name;
|
||||
|
||||
@@ -35,7 +35,7 @@ public enum DdiUpdateMode {
|
||||
*/
|
||||
REMOVE("remove");
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
DdiUpdateMode(final String name) {
|
||||
this.name = name;
|
||||
|
||||
@@ -9,9 +9,13 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ddi.rest.api;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Constants for the direct device integration rest resources.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class DdiRestConstants {
|
||||
|
||||
/**
|
||||
@@ -77,8 +81,4 @@ public final class DdiRestConstants {
|
||||
* can reuse - even the Jackson data converter simply hardcodes this.
|
||||
*/
|
||||
public static final String MEDIA_TYPE_CBOR = "application/cbor";
|
||||
|
||||
private DdiRestConstants() {
|
||||
// constant class, private constructor.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,10 +81,10 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING
|
||||
+ "/{controllerId}/softwaremodules/{softwareModuleId}/artifacts", produces = { MediaTypes.HAL_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<List<DdiArtifact>> getSoftwareModulesArtifacts(@PathVariable("tenant") final String tenant,
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/softwaremodules/{softwareModuleId}/artifacts",
|
||||
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<List<DdiArtifact>> getSoftwareModulesArtifacts(
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") final String controllerId,
|
||||
@PathVariable("softwareModuleId") final Long softwareModuleId);
|
||||
|
||||
@@ -100,7 +100,7 @@ public interface DdiRootControllerRestApi {
|
||||
retrieve actions that need to be executed. Those are provided as a list of links to give more detailed
|
||||
information about the action. Links are only available for initial configuration, open actions, or the latest
|
||||
installed action, respectively. The resource supports Etag based modification checks in order to save traffic.
|
||||
|
||||
|
||||
Note: deployments have to be confirmed in order to move on to the next action. Cancellations have to be
|
||||
confirmed or rejected.""")
|
||||
@ApiResponses(value = {
|
||||
@@ -120,9 +120,10 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}", produces = {
|
||||
MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<DdiControllerBase> getControllerBase(@PathVariable("tenant") final String tenant,
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}",
|
||||
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<DdiControllerBase> getControllerBase(
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") final String controllerId);
|
||||
|
||||
/**
|
||||
@@ -134,8 +135,7 @@ public interface DdiRootControllerRestApi {
|
||||
* @param softwareModuleId of the parent software module
|
||||
* @param fileName of the related local artifact
|
||||
* @return response of the servlet which in case of success is status code
|
||||
* {@link HttpStatus#OK} or in case of partial download
|
||||
* {@link HttpStatus#PARTIAL_CONTENT}.
|
||||
* {@link HttpStatus#OK} or in case of partial download {@link HttpStatus#PARTIAL_CONTENT}.
|
||||
*/
|
||||
@Operation(summary = "Artifact download", description = "Handles GET DdiArtifact download request. This could be " +
|
||||
"full or partial (as specified by RFC7233 (Range Requests)) download request.")
|
||||
@@ -172,8 +172,7 @@ public interface DdiRootControllerRestApi {
|
||||
* @param controllerId of the target
|
||||
* @param softwareModuleId of the parent software module
|
||||
* @param fileName of the related local artifact
|
||||
* @return {@link ResponseEntity} with status {@link HttpStatus#OK} if
|
||||
* successful
|
||||
* @return {@link ResponseEntity} with status {@link HttpStatus#OK} if successful
|
||||
*/
|
||||
@Operation(summary = "MD5 checksum download",
|
||||
description = "Handles GET {@link DdiArtifact} MD5 checksum file download request.")
|
||||
@@ -196,10 +195,10 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING
|
||||
+ "/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{fileName}"
|
||||
+ DdiRestConstants.ARTIFACT_MD5_DWNL_SUFFIX, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
ResponseEntity<Void> downloadArtifactMd5(@PathVariable("tenant") final String tenant,
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{fileName}" +
|
||||
DdiRestConstants.ARTIFACT_MD5_DWNL_SUFFIX, produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
ResponseEntity<Void> downloadArtifactMd5(
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") final String controllerId,
|
||||
@PathVariable("softwareModuleId") final Long softwareModuleId,
|
||||
@PathVariable("fileName") final String fileName);
|
||||
@@ -209,31 +208,20 @@ public interface DdiRootControllerRestApi {
|
||||
*
|
||||
* @param tenant of the request
|
||||
* @param controllerId of the target
|
||||
* @param actionId of the {@link DdiDeploymentBase} that matches to active
|
||||
* actions.
|
||||
* @param resource an hashcode of the resource which indicates if the action has
|
||||
* been changed, e.g. from 'soft' to 'force' and the eTag needs
|
||||
* to be re-generated
|
||||
* @param actionHistoryMessageCount specifies the number of messages to be returned from action
|
||||
* history. Regardless of the passed value, in order to restrict
|
||||
* resource utilization by controllers, maximum number of
|
||||
* messages that are retrieved from database is limited by
|
||||
* {@link RepositoryConstants#MAX_ACTION_HISTORY_MSG_COUNT}.
|
||||
*
|
||||
* actionHistoryMessageCount less than zero: retrieves the
|
||||
* maximum allowed number of action status messages from history;
|
||||
*
|
||||
* actionHistoryMessageCount equal to zero: does not retrieve any
|
||||
* message;
|
||||
*
|
||||
* actionHistoryMessageCount greater than zero: retrieves the
|
||||
* specified number of messages, limited by maximum allowed
|
||||
* number.
|
||||
* @param actionId of the {@link DdiDeploymentBase} that matches to active actions.
|
||||
* @param resource a hashcode of the resource which indicates if the action has been changed, e.g. from 'soft' to 'force' and
|
||||
* the eTag needs to be re-generated
|
||||
* @param actionHistoryMessageCount specifies the number of messages to be returned from action history. Regardless of the passed value,
|
||||
* in order to restrict resource utilization by controllers, maximum number of
|
||||
* messages that are retrieved from database is limited by {@link RepositoryConstants#MAX_ACTION_HISTORY_MSG_COUNT}.
|
||||
* actionHistoryMessageCount less than zero: retrieves the maximum allowed number of action status messages from history;
|
||||
* actionHistoryMessageCount equal to zero: does not retrieve any message;
|
||||
* actionHistoryMessageCount greater than zero: retrieves the specified number of messages, limited by maximum allowed number.
|
||||
* @return the response
|
||||
*/
|
||||
@Operation(summary = "Resource for software module (Deployment Base)", description = """
|
||||
Core resource for deployment operations. Contains all information necessary in order to execute the operation.
|
||||
|
||||
|
||||
Keep in mind that the provided download links for the artifacts are generated dynamically by the update server.
|
||||
Host, port and path and not guaranteed to be similar to the provided examples below but will be defined at
|
||||
runtime.
|
||||
@@ -241,15 +229,15 @@ public interface DdiRootControllerRestApi {
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = """
|
||||
Successfully retrieved
|
||||
|
||||
|
||||
In case a device provides state information on the feedback channel and won’t store it locally,
|
||||
a query for, e.q, the last 10 messages, could be used which will include the previously provided by the
|
||||
device,
|
||||
feedback.
|
||||
|
||||
|
||||
In addition to the straight forward approach to inform the device to download and install the software
|
||||
in one transaction hawkBit supports the separation of download and installation into separate steps.
|
||||
|
||||
|
||||
This feature is called Maintenance Window where the device is informed to download the software first
|
||||
and then when it enters a defined (maintenance) window the installation triggers follows as usual.
|
||||
"""),
|
||||
@@ -270,9 +258,8 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ DdiRestConstants.DEPLOYMENT_BASE_ACTION + "/{actionId}", produces = { MediaTypes.HAL_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.DEPLOYMENT_BASE_ACTION + "/{actionId}",
|
||||
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<DdiDeploymentBase> getControllerDeploymentBaseAction(@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") @NotEmpty final String controllerId,
|
||||
@PathVariable("actionId") @NotNull final Long actionId,
|
||||
@@ -321,16 +308,13 @@ public interface DdiRootControllerRestApi {
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "415", description = "The request was attempt with a media-type which is not " +
|
||||
"supported by the server for this resource.",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(hidden = true))),
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "429", description = "Too many requests. The server will refuse further attempts " +
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json",
|
||||
schema = @Schema(hidden = true)))
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@PostMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ DdiRestConstants.DEPLOYMENT_BASE_ACTION + "/{actionId}/" + DdiRestConstants.FEEDBACK, consumes = {
|
||||
MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
@PostMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.DEPLOYMENT_BASE_ACTION +
|
||||
"/{actionId}/" + DdiRestConstants.FEEDBACK, consumes = { MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> postDeploymentBaseActionFeedback(@Valid final DdiActionFeedback feedback,
|
||||
@PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId,
|
||||
@PathVariable("actionId") @NotNull final Long actionId);
|
||||
@@ -370,11 +354,12 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@PutMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ DdiRestConstants.CONFIG_DATA_ACTION, consumes = { MediaType.APPLICATION_JSON_VALUE,
|
||||
DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> putConfigData(@Valid final DdiConfigData configData,
|
||||
@PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId);
|
||||
@PutMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CONFIG_DATA_ACTION,
|
||||
consumes = { MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> putConfigData(
|
||||
@Valid final DdiConfigData configData,
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") final String controllerId);
|
||||
|
||||
/**
|
||||
* RequestMethod.GET method for the {@link DdiCancel} action.
|
||||
@@ -404,16 +389,15 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CANCEL_ACTION
|
||||
+ "/{actionId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE,
|
||||
DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<DdiCancel> getControllerCancelAction(@PathVariable("tenant") final String tenant,
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CANCEL_ACTION + "/{actionId}",
|
||||
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<DdiCancel> getControllerCancelAction(
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") @NotEmpty final String controllerId,
|
||||
@PathVariable("actionId") @NotNull final Long actionId);
|
||||
|
||||
/**
|
||||
* RequestMethod.POST method receiving the {@link DdiActionFeedback} from
|
||||
* the target.
|
||||
* RequestMethod.POST method receiving the {@link DdiActionFeedback} from the target.
|
||||
*
|
||||
* @param feedback the {@link DdiActionFeedback} from the target.
|
||||
* @param tenant of the client
|
||||
@@ -448,46 +432,34 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@PostMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CANCEL_ACTION
|
||||
+ "/{actionId}/" + DdiRestConstants.FEEDBACK, consumes = { MediaType.APPLICATION_JSON_VALUE,
|
||||
DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> postCancelActionFeedback(@Valid final DdiActionFeedback feedback,
|
||||
@PostMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CANCEL_ACTION + "/{actionId}/" +
|
||||
DdiRestConstants.FEEDBACK, consumes = { MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> postCancelActionFeedback(
|
||||
@Valid final DdiActionFeedback feedback,
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") @NotEmpty final String controllerId,
|
||||
@PathVariable("actionId") @NotNull final Long actionId);
|
||||
|
||||
/**
|
||||
* Resource for installed distribution set to retrieve the last successfully
|
||||
* finished action.
|
||||
* Resource for installed distribution set to retrieve the last successfully finished action.
|
||||
*
|
||||
* @param tenant of the request
|
||||
* @param controllerId of the target
|
||||
* @param actionId of the {@link DdiDeploymentBase} that matches to installed
|
||||
* action.
|
||||
* @param actionId of the {@link DdiDeploymentBase} that matches to installed action.
|
||||
* @param actionHistoryMessageCount specifies the number of messages to be returned from action
|
||||
* history. Regardless of the passed value, in order to restrict
|
||||
* resource utilization by controllers, maximum number of
|
||||
* messages that are retrieved from database is limited by
|
||||
* {@link RepositoryConstants#MAX_ACTION_HISTORY_MSG_COUNT}.
|
||||
*
|
||||
* actionHistoryMessageCount less than zero: retrieves the
|
||||
* maximum allowed number of action status messages from history;
|
||||
*
|
||||
* actionHistoryMessageCount equal to zero: does not retrieve any
|
||||
* message;
|
||||
*
|
||||
* actionHistoryMessageCount greater than zero: retrieves the
|
||||
* specified number of messages, limited by maximum allowed
|
||||
* number.
|
||||
* @return the {@link DdiDeploymentBase}. The response is of same format as
|
||||
* for the /deploymentBase resource.
|
||||
* history. Regardless of the passed value, in order to restrict resource utilization by controllers, maximum number of
|
||||
* messages that are retrieved from database is limited by {@link RepositoryConstants#MAX_ACTION_HISTORY_MSG_COUNT}.
|
||||
* actionHistoryMessageCount less than zero: retrieves the maximum allowed number of action status messages from history;
|
||||
* actionHistoryMessageCount equal to zero: does not retrieve any message;
|
||||
* actionHistoryMessageCount greater than zero: retrieves the specified number of messages, limited by maximum allowed number.
|
||||
* @return the {@link DdiDeploymentBase}. The response is of same format as for the /deploymentBase resource.
|
||||
*/
|
||||
@Operation(summary = "Previously installed action", description = """
|
||||
Resource to receive information of the previous installation. Can be used to re-retrieve artifacts of
|
||||
the already finished action, for example in case a re-installation is necessary. The response will be of
|
||||
the same format as the deploymentBase operation, providing the previous action that has been finished
|
||||
successfully. As the action is already finished, no further feedback is expected.
|
||||
|
||||
|
||||
Keep in mind that the provided download links for the artifacts are generated dynamically by the update server.
|
||||
Host, port and path are not guaranteed to be similar to the provided examples below but will be defined at
|
||||
runtime.
|
||||
@@ -496,7 +468,7 @@ public interface DdiRootControllerRestApi {
|
||||
@ApiResponse(responseCode = "200", description = """
|
||||
The response body includes the detailed operation for the already finished action in the same format as
|
||||
for the deploymentBase operation.
|
||||
|
||||
|
||||
In this case the (optional) query for the last 10 messages, previously provided by the device, are included.
|
||||
"""),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request - e.g. invalid parameters",
|
||||
@@ -514,14 +486,14 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ DdiRestConstants.INSTALLED_BASE_ACTION + "/{actionId}", produces = { MediaTypes.HAL_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.INSTALLED_BASE_ACTION + "/{actionId}",
|
||||
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<DdiDeploymentBase> getControllerInstalledAction(@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") @NotEmpty final String controllerId,
|
||||
@PathVariable("actionId") @NotNull final Long actionId,
|
||||
@RequestParam(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING
|
||||
+ "actionHistory", defaultValue = DdiRestConstants.NO_ACTION_HISTORY) final Integer actionHistoryMessageCount);
|
||||
@RequestParam(
|
||||
value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "actionHistory",
|
||||
defaultValue = DdiRestConstants.NO_ACTION_HISTORY) final Integer actionHistoryMessageCount);
|
||||
|
||||
/**
|
||||
* Returns the confirmation base with the current auto-confirmation state
|
||||
@@ -559,10 +531,10 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ DdiRestConstants.CONFIRMATION_BASE, produces = { MediaTypes.HAL_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<DdiConfirmationBase> getConfirmationBase(@PathVariable("tenant") final String tenant,
|
||||
@GetMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CONFIRMATION_BASE,
|
||||
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<DdiConfirmationBase> getConfirmationBase(
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") @NotEmpty final String controllerId);
|
||||
|
||||
/**
|
||||
@@ -570,33 +542,22 @@ public interface DdiRootControllerRestApi {
|
||||
*
|
||||
* @param tenant of the request
|
||||
* @param controllerId of the target
|
||||
* @param actionId of the {@link DdiConfirmationBaseAction} that matches to
|
||||
* active actions in WAITING_FOR_CONFIRMATION status.
|
||||
* @param resource an hashcode of the resource which indicates if the action has
|
||||
* been changed, e.g. from 'soft' to 'force' and the eTag needs
|
||||
* to be re-generated
|
||||
* @param actionHistoryMessageCount specifies the number of messages to be returned from action
|
||||
* history. Regardless of the passed value, in order to restrict
|
||||
* resource utilization by controllers, maximum number of
|
||||
* messages that are retrieved from database is limited by
|
||||
* {@link RepositoryConstants#MAX_ACTION_HISTORY_MSG_COUNT}.
|
||||
*
|
||||
* actionHistoryMessageCount less than zero: retrieves the
|
||||
* maximum allowed number of action status messages from history;
|
||||
*
|
||||
* actionHistoryMessageCount equal to zero: does not retrieve any
|
||||
* message;
|
||||
*
|
||||
* actionHistoryMessageCount greater than zero: retrieves the
|
||||
* specified number of messages, limited by maximum allowed
|
||||
* number.
|
||||
* @param actionId of the {@link DdiConfirmationBaseAction} that matches to active actions in WAITING_FOR_CONFIRMATION status.
|
||||
* @param resource a hashcode of the resource which indicates if the action has been changed, e.g. from 'soft' to 'force' and the eTag
|
||||
* needs to be re-generated
|
||||
* @param actionHistoryMessageCount specifies the number of messages to be returned from action history. Regardless of the passed value,
|
||||
* in order to restrict resource utilization by controllers, maximum number of messages that are retrieved from database is limited
|
||||
* by {@link RepositoryConstants#MAX_ACTION_HISTORY_MSG_COUNT}.
|
||||
* actionHistoryMessageCount less than zero: retrieves the maximum allowed number of action status messages from history;
|
||||
* actionHistoryMessageCount equal to zero: does not retrieve any message;
|
||||
* actionHistoryMessageCount greater than zero: retrieves the specified number of messages, limited by maximum allowed number.
|
||||
* @return the response
|
||||
*/
|
||||
@Operation(summary = "Confirmation status of an action", description = """
|
||||
Resource to receive information about a pending confirmation. The response will be of the same format as the
|
||||
deploymentBase operation. The controller should provide feedback about the confirmation first, before
|
||||
processing the deployment.
|
||||
|
||||
|
||||
Keep in mind that the provided download links for the artifacts are generated dynamically by the update server.
|
||||
Host, port and path are not guaranteed to be similar to the provided examples below but will be defined at
|
||||
runtime.
|
||||
@@ -627,14 +588,13 @@ public interface DdiRootControllerRestApi {
|
||||
ResponseEntity<DdiConfirmationBaseAction> getConfirmationBaseAction(@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") @NotEmpty final String controllerId,
|
||||
@PathVariable("actionId") @NotNull final Long actionId,
|
||||
@RequestParam(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING
|
||||
+ "c", required = false, defaultValue = "-1") final int resource,
|
||||
@RequestParam(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING
|
||||
+ "actionHistory", defaultValue = DdiRestConstants.NO_ACTION_HISTORY) final Integer actionHistoryMessageCount);
|
||||
@RequestParam(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "c", required = false, defaultValue = "-1") final int resource,
|
||||
@RequestParam(
|
||||
value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "actionHistory",
|
||||
defaultValue = DdiRestConstants.NO_ACTION_HISTORY) final Integer actionHistoryMessageCount);
|
||||
|
||||
/**
|
||||
* This is the feedback channel for the {@link DdiConfirmationBaseAction}
|
||||
* action.
|
||||
* This is the feedback channel for the {@link DdiConfirmationBaseAction} action.
|
||||
*
|
||||
* @param tenant of the client
|
||||
* @param feedback to provide
|
||||
@@ -674,24 +634,22 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@PostMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ DdiRestConstants.CONFIRMATION_BASE + "/{actionId}/" + DdiRestConstants.FEEDBACK, consumes = {
|
||||
MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> postConfirmationActionFeedback(@Valid final DdiConfirmationFeedback feedback,
|
||||
@PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId,
|
||||
@PostMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CONFIRMATION_BASE + "/{actionId}/" +
|
||||
DdiRestConstants.FEEDBACK, consumes = { MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> postConfirmationActionFeedback(
|
||||
@Valid final DdiConfirmationFeedback feedback,
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") final String controllerId,
|
||||
@PathVariable("actionId") @NotNull final Long actionId);
|
||||
|
||||
/**
|
||||
* Activate auto confirmation for a given controllerId. Will use the
|
||||
* provided initiator and remark field from the provided
|
||||
* {@link DdiActivateAutoConfirmation}. If not present, the values will be
|
||||
* prefilled with a default remark and the CONTROLLER as initiator.
|
||||
* Activate auto confirmation for a given controllerId. Will use the provided initiator and remark field from the provided
|
||||
* {@link DdiActivateAutoConfirmation}. If not present, the values will be prefilled with a default remark and the CONTROLLER as initiator.
|
||||
*
|
||||
* @param tenant the controllerId is corresponding too
|
||||
* @param controllerId to activate auto-confirmation for
|
||||
* @param body as {@link DdiActivateAutoConfirmation}
|
||||
* @return {@link org.springframework.http.HttpStatus#OK} if successful or
|
||||
* {@link org.springframework.http.HttpStatus#CONFLICT} in case
|
||||
* @return {@link org.springframework.http.HttpStatus#OK} if successful or {@link org.springframework.http.HttpStatus#CONFLICT} in case
|
||||
* auto-confirmation was active already.
|
||||
*/
|
||||
@Operation(summary = "Interface to activate auto-confirmation for a specific device", description = """
|
||||
@@ -724,10 +682,10 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@PostMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ DdiRestConstants.CONFIRMATION_BASE + "/" + DdiRestConstants.AUTO_CONFIRM_ACTIVATE, consumes = {
|
||||
MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> activateAutoConfirmation(@PathVariable("tenant") final String tenant,
|
||||
@PostMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CONFIRMATION_BASE + "/" +
|
||||
DdiRestConstants.AUTO_CONFIRM_ACTIVATE, consumes = { MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> activateAutoConfirmation(
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") @NotEmpty final String controllerId,
|
||||
@Valid @RequestBody(required = false) final DdiActivateAutoConfirmation body);
|
||||
|
||||
@@ -767,16 +725,16 @@ public interface DdiRootControllerRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@PostMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ DdiRestConstants.CONFIRMATION_BASE + "/" + DdiRestConstants.AUTO_CONFIRM_DEACTIVATE)
|
||||
ResponseEntity<Void> deactivateAutoConfirmation(@PathVariable("tenant") final String tenant,
|
||||
@PostMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CONFIRMATION_BASE + "/" +
|
||||
DdiRestConstants.AUTO_CONFIRM_DEACTIVATE)
|
||||
ResponseEntity<Void> deactivateAutoConfirmation(
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") @NotEmpty final String controllerId);
|
||||
|
||||
/**
|
||||
* Assign an already installed distribution for a target
|
||||
*
|
||||
* @param tenant of the client
|
||||
* to provide
|
||||
* @param tenant of the client to provide
|
||||
* @param controllerId of the target that matches to controller id
|
||||
* @param ddiAssignedVersion as {@link DdiAssignedVersion}
|
||||
* @return the response
|
||||
@@ -787,20 +745,35 @@ public interface DdiRootControllerRestApi {
|
||||
""")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Successfully retrieved"),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request - e.g. invalid parameters", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionInfo.class))),
|
||||
@ApiResponse(responseCode = "401", description = "The request requires user authentication.", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "403", description = "Insufficient permissions, entity is not allowed to be changed (i.e. read-only) or data volume restriction applies.", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "404", description = "Target or Distribution not found", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "405", description = "The http request method is not allowed on the resource.", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "406", description = "In case accept header is specified and not application/json.", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "409", description = "E.g. in case an entity is created or modified by another user in another request at the same time. You may retry your modification request.", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "410", description = "Action is not active anymore.", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "415", description = "The request was attempt with a media-type which is not supported by the server for this resource.", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "429", description = "Too many requests. The server will refuse further attempts and the client has to wait another second.", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request - e.g. invalid parameters",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionInfo.class))),
|
||||
@ApiResponse(responseCode = "401", description = "The request requires user authentication.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "403", description = "Insufficient permissions, entity is not allowed to be changed (i.e. read-only) " +
|
||||
"or data volume restriction applies.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "404", description = "Target or Distribution not found",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "405", description = "The http request method is not allowed on the resource.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "406", description = "In case accept header is specified and not application/json.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "409", description = "E.g. in case an entity is created or modified by another user in another " +
|
||||
"request at the same time. You may retry your modification request.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "410", description = "Action is not active anymore.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "415", description = "The request was attempt with a media-type which is not supported by the server " +
|
||||
"for this resource.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "429", description = "Too many requests. The server will refuse further attempts and the client has " +
|
||||
"to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@PutMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ DdiRestConstants.INSTALLED_BASE_ACTION, consumes = {
|
||||
MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> setAsssignedOfflineVersion(@Valid DdiAssignedVersion ddiAssignedVersion,
|
||||
@PathVariable("tenant") final String tenant, @PathVariable("controllerId") final String controllerId);
|
||||
}
|
||||
@PutMapping(value = DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.INSTALLED_BASE_ACTION,
|
||||
consumes = { MediaType.APPLICATION_JSON_VALUE, DdiRestConstants.MEDIA_TYPE_CBOR })
|
||||
ResponseEntity<Void> setAsssignedOfflineVersion(
|
||||
@Valid DdiAssignedVersion ddiAssignedVersion,
|
||||
@PathVariable("tenant") final String tenant,
|
||||
@PathVariable("controllerId") final String controllerId);
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
@@ -39,7 +38,7 @@ class DdiActionFeedbackTest {
|
||||
@Description("Verify the correct serialization and deserialization of the model with minimal payload")
|
||||
void shouldSerializeAndDeserializeObjectWithoutOptionalValues() throws IOException {
|
||||
// Setup
|
||||
final DdiStatus ddiStatus = new DdiStatus(DdiStatus.ExecutionStatus.CLOSED, null, null, Lists.emptyList());
|
||||
final DdiStatus ddiStatus = new DdiStatus(DdiStatus.ExecutionStatus.CLOSED, null, null, Collections.emptyList());
|
||||
final DdiActionFeedback ddiActionFeedback = new DdiActionFeedback(null, ddiStatus);
|
||||
|
||||
// Test
|
||||
@@ -61,8 +60,7 @@ class DdiActionFeedbackTest {
|
||||
|
||||
// Test
|
||||
final String serializedDdiActionFeedback = mapper.writeValueAsString(ddiActionFeedback);
|
||||
final DdiActionFeedback deserializedDdiActionFeedback = mapper.readValue(serializedDdiActionFeedback,
|
||||
DdiActionFeedback.class);
|
||||
final DdiActionFeedback deserializedDdiActionFeedback = mapper.readValue(serializedDdiActionFeedback, DdiActionFeedback.class);
|
||||
|
||||
assertThat(serializedDdiActionFeedback).contains(time);
|
||||
assertThat(deserializedDdiActionFeedback.getTime()).isEqualTo(time);
|
||||
@@ -104,5 +102,4 @@ class DdiActionFeedbackTest {
|
||||
assertThat(deserializedDdiActionFeedback.getStatus().getDetails()).hasSize(1);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -43,9 +43,7 @@ public class DdiActionHistoryTest {
|
||||
|
||||
// Test
|
||||
final String serializedDdiActionHistory = OBJECT_MAPPER.writeValueAsString(ddiActionHistory);
|
||||
final DdiActionHistory deserializedDdiActionHistory = OBJECT_MAPPER.readValue(serializedDdiActionHistory,
|
||||
DdiActionHistory.class);
|
||||
|
||||
final DdiActionHistory deserializedDdiActionHistory = OBJECT_MAPPER.readValue(serializedDdiActionHistory, DdiActionHistory.class);
|
||||
assertThat(serializedDdiActionHistory).contains(actionStatus, messages.get(0), messages.get(1));
|
||||
assertThat(deserializedDdiActionHistory.toString()).contains(actionStatus, messages.get(0), messages.get(1));
|
||||
}
|
||||
@@ -63,7 +61,6 @@ public class DdiActionHistoryTest {
|
||||
|
||||
// Test
|
||||
final DdiActionHistory ddiActionHistory = OBJECT_MAPPER.readValue(serializedDdiActionHistory, DdiActionHistory.class);
|
||||
|
||||
assertThat(ddiActionHistory.toString()).contains("SomeAction", "Some message");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,22 +29,20 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiArtifactHashTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
String sha1Hash = "11111";
|
||||
String md5Hash = "22222";
|
||||
String sha256Hash = "33333";
|
||||
DdiArtifactHash DdiArtifact = new DdiArtifactHash(sha1Hash, md5Hash, sha256Hash);
|
||||
final String sha1Hash = "11111";
|
||||
final String md5Hash = "22222";
|
||||
final String sha256Hash = "33333";
|
||||
final DdiArtifactHash DdiArtifact = new DdiArtifactHash(sha1Hash, md5Hash, sha256Hash);
|
||||
|
||||
// Test
|
||||
String serializedDdiArtifact = mapper.writeValueAsString(DdiArtifact);
|
||||
DdiArtifactHash deserializedDdiArtifact = mapper.readValue(serializedDdiArtifact,
|
||||
DdiArtifactHash.class);
|
||||
|
||||
final String serializedDdiArtifact = OBJECT_MAPPER.writeValueAsString(DdiArtifact);
|
||||
final DdiArtifactHash deserializedDdiArtifact = OBJECT_MAPPER.readValue(serializedDdiArtifact, DdiArtifactHash.class);
|
||||
assertThat(serializedDdiArtifact).contains(sha1Hash, md5Hash, sha256Hash);
|
||||
assertThat(deserializedDdiArtifact.getSha1()).isEqualTo(sha1Hash);
|
||||
assertThat(deserializedDdiArtifact.getMd5()).isEqualTo(md5Hash);
|
||||
@@ -55,11 +53,10 @@ public class DdiArtifactHashTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiArtifact = "{\"sha1\": \"123\", \"md5\": \"456\", \"sha256\": \"789\", \"unknownProperty\": \"test\"}";
|
||||
final String serializedDdiArtifact = "{\"sha1\": \"123\", \"md5\": \"456\", \"sha256\": \"789\", \"unknownProperty\": \"test\"}";
|
||||
|
||||
// Test
|
||||
DdiArtifactHash ddiArtifact = mapper.readValue(serializedDdiArtifact, DdiArtifactHash.class);
|
||||
|
||||
final DdiArtifactHash ddiArtifact = OBJECT_MAPPER.readValue(serializedDdiArtifact, DdiArtifactHash.class);
|
||||
assertThat(ddiArtifact.getSha1()).isEqualTo("123");
|
||||
assertThat(ddiArtifact.getMd5()).isEqualTo("456");
|
||||
assertThat(ddiArtifact.getSha256()).isEqualTo("789");
|
||||
@@ -69,11 +66,10 @@ public class DdiArtifactHashTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiArtifact = "{\"sha1\": [123], \"md5\": 456, \"sha256\": \"789\"";
|
||||
final String serializedDdiArtifact = "{\"sha1\": [123], \"md5\": 456, \"sha256\": \"789\"";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiArtifact, DdiArtifactHash.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiArtifact, DdiArtifactHash.class));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -29,25 +29,24 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiArtifactTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
String filename = "testfile.txt";
|
||||
DdiArtifactHash hashes = new DdiArtifactHash("123", "456", "789");
|
||||
Long size = 12345L;
|
||||
final String filename = "testfile.txt";
|
||||
final DdiArtifactHash hashes = new DdiArtifactHash("123", "456", "789");
|
||||
final Long size = 12345L;
|
||||
|
||||
DdiArtifact ddiArtifact = new DdiArtifact();
|
||||
final DdiArtifact ddiArtifact = new DdiArtifact();
|
||||
ddiArtifact.setFilename(filename);
|
||||
ddiArtifact.setHashes(hashes);
|
||||
ddiArtifact.setSize(size);
|
||||
|
||||
// Test
|
||||
String serializedDdiArtifact = mapper.writeValueAsString(ddiArtifact);
|
||||
DdiArtifact deserializedDdiArtifact = mapper.readValue(serializedDdiArtifact, DdiArtifact.class);
|
||||
|
||||
final String serializedDdiArtifact = OBJECT_MAPPER.writeValueAsString(ddiArtifact);
|
||||
final DdiArtifact deserializedDdiArtifact = OBJECT_MAPPER.readValue(serializedDdiArtifact, DdiArtifact.class);
|
||||
assertThat(serializedDdiArtifact).contains(filename, "12345");
|
||||
assertThat(deserializedDdiArtifact.getFilename()).isEqualTo(filename);
|
||||
assertThat(deserializedDdiArtifact.getSize()).isEqualTo(size);
|
||||
@@ -60,11 +59,10 @@ public class DdiArtifactTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiArtifact = "{\"filename\":\"test.file\",\"hashes\":{\"sha1\":\"123\",\"md5\":\"456\",\"sha256\":\"789\"},\"size\":111,\"links\":[],\"unknownProperty\": \"test\"}";
|
||||
final String serializedDdiArtifact = "{\"filename\":\"test.file\",\"hashes\":{\"sha1\":\"123\",\"md5\":\"456\",\"sha256\":\"789\"},\"size\":111,\"links\":[],\"unknownProperty\": \"test\"}";
|
||||
|
||||
// Test
|
||||
DdiArtifact ddiArtifact = mapper.readValue(serializedDdiArtifact, DdiArtifact.class);
|
||||
|
||||
final DdiArtifact ddiArtifact = OBJECT_MAPPER.readValue(serializedDdiArtifact, DdiArtifact.class);
|
||||
assertThat(ddiArtifact.getFilename()).isEqualTo("test.file");
|
||||
assertThat(ddiArtifact.getSize()).isEqualTo(111);
|
||||
assertThat(ddiArtifact.getHashes().getSha1()).isEqualTo("123");
|
||||
@@ -76,10 +74,10 @@ public class DdiArtifactTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiArtifact = "{\"filename\": [\"test.file\"],\"hashes\":{\"sha1\":\"123\",\"md5\":\"456\",\"sha256\":\"789\"},\"size\":111,\"links\":[]}";
|
||||
final String serializedDdiArtifact = "{\"filename\": [\"test.file\"],\"hashes\":{\"sha1\":\"123\",\"md5\":\"456\",\"sha256\":\"789\"},\"size\":111,\"links\":[]}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiArtifact, DdiArtifact.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiArtifact, DdiArtifact.class));
|
||||
}
|
||||
}
|
||||
@@ -29,19 +29,19 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiCancelActionToStopTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
String stopId = "1234";
|
||||
DdiCancelActionToStop ddiCancelActionToStop = new DdiCancelActionToStop(stopId);
|
||||
// Test
|
||||
String serializedDdiCancelActionToStop = mapper.writeValueAsString(ddiCancelActionToStop);
|
||||
DdiCancelActionToStop deserializedDdiCancelActionToStop = mapper.readValue(serializedDdiCancelActionToStop,
|
||||
DdiCancelActionToStop.class);
|
||||
final String stopId = "1234";
|
||||
final DdiCancelActionToStop ddiCancelActionToStop = new DdiCancelActionToStop(stopId);
|
||||
|
||||
// Test
|
||||
final String serializedDdiCancelActionToStop = OBJECT_MAPPER.writeValueAsString(ddiCancelActionToStop);
|
||||
final DdiCancelActionToStop deserializedDdiCancelActionToStop = OBJECT_MAPPER.readValue(
|
||||
serializedDdiCancelActionToStop, DdiCancelActionToStop.class);
|
||||
assertThat(serializedDdiCancelActionToStop).contains(stopId);
|
||||
assertThat(deserializedDdiCancelActionToStop.getStopId()).isEqualTo(stopId);
|
||||
}
|
||||
@@ -50,12 +50,11 @@ public class DdiCancelActionToStopTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiCancelActionToStop = "{\"stopId\":\"12345\",\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiCancelActionToStop = "{\"stopId\":\"12345\",\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
DdiCancelActionToStop ddiCancelActionToStop = mapper.readValue(serializedDdiCancelActionToStop,
|
||||
DdiCancelActionToStop.class);
|
||||
|
||||
final DdiCancelActionToStop ddiCancelActionToStop = OBJECT_MAPPER.readValue(
|
||||
serializedDdiCancelActionToStop, DdiCancelActionToStop.class);
|
||||
assertThat(ddiCancelActionToStop.getStopId()).contains("12345");
|
||||
}
|
||||
|
||||
@@ -63,10 +62,10 @@ public class DdiCancelActionToStopTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiCancelActionToStop = "{\"stopId\": [\"12345\"]}";
|
||||
final String serializedDdiCancelActionToStop = "{\"stopId\": [\"12345\"]}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiCancelActionToStop, DdiCancelActionToStop.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiCancelActionToStop, DdiCancelActionToStop.class));
|
||||
}
|
||||
}
|
||||
@@ -29,20 +29,19 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiCancelTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
String ddiCancelId = "1234";
|
||||
DdiCancelActionToStop ddiCancelActionToStop = new DdiCancelActionToStop("1234");
|
||||
DdiCancel ddiCancel = new DdiCancel(ddiCancelId, ddiCancelActionToStop);
|
||||
final String ddiCancelId = "1234";
|
||||
final DdiCancelActionToStop ddiCancelActionToStop = new DdiCancelActionToStop("1234");
|
||||
final DdiCancel ddiCancel = new DdiCancel(ddiCancelId, ddiCancelActionToStop);
|
||||
|
||||
// Test
|
||||
String serializedDdiCancel = mapper.writeValueAsString(ddiCancel);
|
||||
DdiCancel deserializedDdiCancel = mapper.readValue(serializedDdiCancel, DdiCancel.class);
|
||||
|
||||
final String serializedDdiCancel = OBJECT_MAPPER.writeValueAsString(ddiCancel);
|
||||
final DdiCancel deserializedDdiCancel = OBJECT_MAPPER.readValue(serializedDdiCancel, DdiCancel.class);
|
||||
assertThat(serializedDdiCancel).contains(ddiCancelId, ddiCancelActionToStop.getStopId());
|
||||
assertThat(deserializedDdiCancel.getId()).isEqualTo(ddiCancelId);
|
||||
assertThat(deserializedDdiCancel.getCancelAction().getStopId()).isEqualTo(ddiCancelActionToStop.getStopId());
|
||||
@@ -52,11 +51,10 @@ public class DdiCancelTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiCancel = "{\"id\":\"1234\",\"cancelAction\":{\"stopId\":\"1234\"}, \"unknownProperty\": \"test\"}";
|
||||
final String serializedDdiCancel = "{\"id\":\"1234\",\"cancelAction\":{\"stopId\":\"1234\"}, \"unknownProperty\": \"test\"}";
|
||||
|
||||
// Test
|
||||
DdiCancel ddiCancel = mapper.readValue(serializedDdiCancel, DdiCancel.class);
|
||||
|
||||
final DdiCancel ddiCancel = OBJECT_MAPPER.readValue(serializedDdiCancel, DdiCancel.class);
|
||||
assertThat(ddiCancel.getId()).isEqualTo("1234");
|
||||
assertThat(ddiCancel.getCancelAction().getStopId()).matches("1234");
|
||||
}
|
||||
@@ -65,10 +63,10 @@ public class DdiCancelTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiCancel = "{\"id\":[\"1234\"],\"cancelAction\":{\"stopId\":\"1234\"}}";
|
||||
final String serializedDdiCancel = "{\"id\":[\"1234\"],\"cancelAction\":{\"stopId\":\"1234\"}}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiCancel, DdiCancel.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiCancel, DdiCancel.class));
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiChunkTest {
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
@@ -44,9 +44,8 @@ public class DdiChunkTest {
|
||||
final DdiChunk ddiChunk = new DdiChunk(part, version, name, null, dummyArtifacts, null);
|
||||
|
||||
// Test
|
||||
final String serializedDdiChunk = mapper.writeValueAsString(ddiChunk);
|
||||
final DdiChunk deserializedDdiChunk = mapper.readValue(serializedDdiChunk, DdiChunk.class);
|
||||
|
||||
final String serializedDdiChunk = OBJECT_MAPPER.writeValueAsString(ddiChunk);
|
||||
final DdiChunk deserializedDdiChunk = OBJECT_MAPPER.readValue(serializedDdiChunk, DdiChunk.class);
|
||||
assertThat(serializedDdiChunk).contains(part, version, name);
|
||||
assertThat(deserializedDdiChunk.getPart()).isEqualTo(part);
|
||||
assertThat(deserializedDdiChunk.getVersion()).isEqualTo(version);
|
||||
@@ -61,8 +60,7 @@ public class DdiChunkTest {
|
||||
final String serializedDdiChunk = "{\"part\":\"1234\",\"version\":\"1.0\",\"name\":\"Dummy-Artifact\",\"artifacts\":[],\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
final DdiChunk ddiChunk = mapper.readValue(serializedDdiChunk, DdiChunk.class);
|
||||
|
||||
final DdiChunk ddiChunk = OBJECT_MAPPER.readValue(serializedDdiChunk, DdiChunk.class);
|
||||
assertThat(ddiChunk.getPart()).isEqualTo("1234");
|
||||
assertThat(ddiChunk.getVersion()).isEqualTo("1.0");
|
||||
assertThat(ddiChunk.getName()).isEqualTo("Dummy-Artifact");
|
||||
@@ -77,6 +75,6 @@ public class DdiChunkTest {
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> mapper.readValue(serializedDdiChunk, DdiChunk.class));
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiChunk, DdiChunk.class));
|
||||
}
|
||||
}
|
||||
@@ -31,34 +31,31 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiConfigDataTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
Map<String, String> data = new HashMap<>();
|
||||
final Map<String, String> data = new HashMap<>();
|
||||
data.put("test", "data");
|
||||
DdiConfigData ddiConfigData = new DdiConfigData(data, DdiUpdateMode.REPLACE);
|
||||
final DdiConfigData ddiConfigData = new DdiConfigData(data, DdiUpdateMode.REPLACE);
|
||||
|
||||
// Test
|
||||
String serializedDdiConfigData = mapper.writeValueAsString(ddiConfigData);
|
||||
DdiConfigData deserializedDdiConfigData = mapper.readValue(serializedDdiConfigData, DdiConfigData.class);
|
||||
|
||||
final String serializedDdiConfigData = OBJECT_MAPPER.writeValueAsString(ddiConfigData);
|
||||
final DdiConfigData deserializedDdiConfigData = OBJECT_MAPPER.readValue(serializedDdiConfigData, DdiConfigData.class);
|
||||
assertThat(serializedDdiConfigData).contains("test", "data");
|
||||
assertThat(deserializedDdiConfigData.getMode()).isEqualTo(DdiUpdateMode.REPLACE);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with an additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiConfigData = "{\"data\":{\"test\":\"data\"},\"mode\":\"replace\",\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiConfigData = "{\"data\":{\"test\":\"data\"},\"mode\":\"replace\",\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
DdiConfigData ddiConfigData = mapper.readValue(serializedDdiConfigData, DdiConfigData.class);
|
||||
|
||||
final DdiConfigData ddiConfigData = OBJECT_MAPPER.readValue(serializedDdiConfigData, DdiConfigData.class);
|
||||
assertThat(ddiConfigData.getMode()).isEqualTo(DdiUpdateMode.REPLACE);
|
||||
}
|
||||
|
||||
@@ -66,11 +63,11 @@ public class DdiConfigDataTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiConfigData = "{\"data\":{\"test\":\"data\"},\"mode\":[\"replace\"],\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiConfigData = "{\"data\":{\"test\":\"data\"},\"mode\":[\"replace\"],\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiConfigData, DdiConfigData.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiConfigData, DdiConfigData.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +85,7 @@ public class DdiConfigDataTest {
|
||||
+ "\"details\":[]},\"data\":{\"test\":\"data\"},\"mode\":\"replace\"}";
|
||||
|
||||
// Test
|
||||
DdiConfigData ddiConfigData = mapper.readValue(serializedDdiConfigData, DdiConfigData.class);
|
||||
DdiConfigData ddiConfigData = OBJECT_MAPPER.readValue(serializedDdiConfigData, DdiConfigData.class);
|
||||
|
||||
assertThat(ddiConfigData.getMode()).isEqualTo(DdiUpdateMode.REPLACE);
|
||||
}
|
||||
|
||||
@@ -29,19 +29,18 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiConfigTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
DdiPolling ddiPolling = new DdiPolling("10");
|
||||
DdiConfig ddiConfig = new DdiConfig(ddiPolling);
|
||||
final DdiPolling ddiPolling = new DdiPolling("10");
|
||||
final DdiConfig ddiConfig = new DdiConfig(ddiPolling);
|
||||
|
||||
// Test
|
||||
String serializedDdiConfig = mapper.writeValueAsString(ddiConfig);
|
||||
DdiConfig deserializedDdiConfig = mapper.readValue(serializedDdiConfig, DdiConfig.class);
|
||||
|
||||
final String serializedDdiConfig = OBJECT_MAPPER.writeValueAsString(ddiConfig);
|
||||
final DdiConfig deserializedDdiConfig = OBJECT_MAPPER.readValue(serializedDdiConfig, DdiConfig.class);
|
||||
assertThat(serializedDdiConfig).contains("10");
|
||||
assertThat(deserializedDdiConfig.getPolling().getSleep()).isEqualTo("10");
|
||||
}
|
||||
@@ -50,11 +49,10 @@ public class DdiConfigTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiConfig = "{\"polling\":{\"sleep\":\"123\"},\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiConfig = "{\"polling\":{\"sleep\":\"123\"},\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
DdiConfig ddiConfig = mapper.readValue(serializedDdiConfig, DdiConfig.class);
|
||||
|
||||
final DdiConfig ddiConfig = OBJECT_MAPPER.readValue(serializedDdiConfig, DdiConfig.class);
|
||||
assertThat(ddiConfig.getPolling().getSleep()).isEqualTo("123");
|
||||
}
|
||||
|
||||
@@ -62,10 +60,10 @@ public class DdiConfigTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiConfig = "{\"polling\":{\"sleep\":[\"10\"]}}";
|
||||
final String serializedDdiConfig = "{\"polling\":{\"sleep\":[\"10\"]}}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiConfig, DdiConfig.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiConfig, DdiConfig.class));
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,8 @@ import static org.eclipse.hawkbit.ddi.json.model.DdiDeployment.HandlingType.ATTE
|
||||
import static org.eclipse.hawkbit.ddi.json.model.DdiDeployment.HandlingType.FORCED;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
@@ -43,10 +43,8 @@ class DdiConfirmationBaseTest {
|
||||
final String id = "1234";
|
||||
final DdiDeployment ddiDeployment = new DdiDeployment(FORCED, ATTEMPT, Collections.emptyList(), AVAILABLE);
|
||||
final String actionStatus = "TestAction";
|
||||
final DdiActionHistory ddiActionHistory = new DdiActionHistory(actionStatus,
|
||||
Arrays.asList("Action status message 1", "Action status message 2"));
|
||||
final DdiConfirmationBaseAction ddiConfirmationBaseAction = new DdiConfirmationBaseAction(id, ddiDeployment,
|
||||
ddiActionHistory);
|
||||
final DdiActionHistory ddiActionHistory = new DdiActionHistory(actionStatus, List.of("Action status message 1", "Action status message 2"));
|
||||
final DdiConfirmationBaseAction ddiConfirmationBaseAction = new DdiConfirmationBaseAction(id, ddiDeployment, ddiActionHistory);
|
||||
|
||||
// Test
|
||||
String serializedDdiConfirmationBase = OBJECT_MAPPER.writeValueAsString(ddiConfirmationBaseAction);
|
||||
|
||||
@@ -29,22 +29,19 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiControllerBaseTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
// Setup
|
||||
DdiPolling ddiPolling = new DdiPolling("10");
|
||||
DdiConfig ddiConfig = new DdiConfig(ddiPolling);
|
||||
DdiControllerBase ddiControllerBase = new DdiControllerBase(ddiConfig);
|
||||
final DdiPolling ddiPolling = new DdiPolling("10");
|
||||
final DdiConfig ddiConfig = new DdiConfig(ddiPolling);
|
||||
final DdiControllerBase ddiControllerBase = new DdiControllerBase(ddiConfig);
|
||||
|
||||
// Test
|
||||
String serializedDdiControllerBase = mapper.writeValueAsString(ddiControllerBase);
|
||||
DdiControllerBase deserializedDdiControllerBase = mapper.readValue(serializedDdiControllerBase,
|
||||
DdiControllerBase.class);
|
||||
|
||||
final String serializedDdiControllerBase = OBJECT_MAPPER.writeValueAsString(ddiControllerBase);
|
||||
final DdiControllerBase deserializedDdiControllerBase = OBJECT_MAPPER.readValue(serializedDdiControllerBase, DdiControllerBase.class);
|
||||
assertThat(serializedDdiControllerBase).contains(ddiPolling.getSleep());
|
||||
assertThat(deserializedDdiControllerBase.getConfig().getPolling().getSleep()).isEqualTo(ddiPolling.getSleep());
|
||||
}
|
||||
@@ -53,11 +50,10 @@ public class DdiControllerBaseTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiControllerBase = "{\"config\":{\"polling\":{\"sleep\":\"123\"}},\"links\":[],\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiControllerBase = "{\"config\":{\"polling\":{\"sleep\":\"123\"}},\"links\":[],\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
DdiControllerBase ddiControllerBase = mapper.readValue(serializedDdiControllerBase, DdiControllerBase.class);
|
||||
|
||||
final DdiControllerBase ddiControllerBase = OBJECT_MAPPER.readValue(serializedDdiControllerBase, DdiControllerBase.class);
|
||||
assertThat(ddiControllerBase.getConfig().getPolling().getSleep()).isEqualTo("123");
|
||||
}
|
||||
|
||||
@@ -65,10 +61,10 @@ public class DdiControllerBaseTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiControllerBase = "{\"config\":{\"polling\":{\"sleep\":[\"123\"]}},\"links\":[],\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiControllerBase = "{\"config\":{\"polling\":{\"sleep\":[\"123\"]}},\"links\":[],\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiControllerBase, DdiControllerBase.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiControllerBase, DdiControllerBase.class));
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import static org.eclipse.hawkbit.ddi.json.model.DdiDeployment.HandlingType.FORC
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
@@ -34,30 +35,25 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiDeploymentBaseTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
String id = "1234";
|
||||
DdiDeployment ddiDeployment = new DdiDeployment(FORCED, ATTEMPT, Collections.emptyList(), AVAILABLE);
|
||||
String actionStatus = "TestAction";
|
||||
DdiActionHistory ddiActionHistory = new DdiActionHistory(actionStatus,
|
||||
Arrays.asList("Action status message 1", "Action status message 2"));
|
||||
DdiDeploymentBase ddiDeploymentBase = new DdiDeploymentBase(id, ddiDeployment, ddiActionHistory);
|
||||
final String id = "1234";
|
||||
final DdiDeployment ddiDeployment = new DdiDeployment(FORCED, ATTEMPT, Collections.emptyList(), AVAILABLE);
|
||||
final String actionStatus = "TestAction";
|
||||
final DdiActionHistory ddiActionHistory = new DdiActionHistory(actionStatus, List.of("Action status message 1", "Action status message 2"));
|
||||
final DdiDeploymentBase ddiDeploymentBase = new DdiDeploymentBase(id, ddiDeployment, ddiActionHistory);
|
||||
|
||||
// Test
|
||||
String serializedDdiDeploymentBase = mapper.writeValueAsString(ddiDeploymentBase);
|
||||
DdiDeploymentBase deserializedDdiDeploymentBase = mapper.readValue(serializedDdiDeploymentBase,
|
||||
DdiDeploymentBase.class);
|
||||
|
||||
assertThat(serializedDdiDeploymentBase).contains(id, FORCED.getName(), ATTEMPT.getName(), AVAILABLE.getStatus(),
|
||||
actionStatus);
|
||||
final String serializedDdiDeploymentBase = OBJECT_MAPPER.writeValueAsString(ddiDeploymentBase);
|
||||
final DdiDeploymentBase deserializedDdiDeploymentBase = OBJECT_MAPPER.readValue(serializedDdiDeploymentBase, DdiDeploymentBase.class);
|
||||
assertThat(serializedDdiDeploymentBase).contains(id, FORCED.getName(), ATTEMPT.getName(), AVAILABLE.getStatus(), actionStatus);
|
||||
assertThat(deserializedDdiDeploymentBase.getDeployment().getDownload()).isEqualTo(ddiDeployment.getDownload());
|
||||
assertThat(deserializedDdiDeploymentBase.getDeployment().getUpdate()).isEqualTo(ddiDeployment.getUpdate());
|
||||
assertThat(deserializedDdiDeploymentBase.getDeployment().getMaintenanceWindow()).isEqualTo(
|
||||
ddiDeployment.getMaintenanceWindow());
|
||||
assertThat(deserializedDdiDeploymentBase.getDeployment().getMaintenanceWindow()).isEqualTo(ddiDeployment.getMaintenanceWindow());
|
||||
assertThat(deserializedDdiDeploymentBase.getActionHistory().toString()).isEqualTo(ddiActionHistory.toString());
|
||||
}
|
||||
|
||||
@@ -65,31 +61,29 @@ public class DdiDeploymentBaseTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiDeploymentBase = "{\"id\":\"1234\",\"deployment\":{\"download\":\"forced\","
|
||||
+ "\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]},"
|
||||
+ "\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\","
|
||||
+ "\"Action status message 2\"]},\"links\":[],\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiDeploymentBase = "{\"id\":\"1234\",\"deployment\":{\"download\":\"forced\"," +
|
||||
"\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]}," +
|
||||
"\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\"," +
|
||||
"\"Action status message 2\"]},\"links\":[],\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
DdiDeploymentBase ddiDeploymentBase = mapper.readValue(serializedDdiDeploymentBase, DdiDeploymentBase.class);
|
||||
|
||||
final DdiDeploymentBase ddiDeploymentBase = OBJECT_MAPPER.readValue(serializedDdiDeploymentBase, DdiDeploymentBase.class);
|
||||
assertThat(ddiDeploymentBase.getDeployment().getDownload().getName()).isEqualTo(FORCED.getName());
|
||||
assertThat(ddiDeploymentBase.getDeployment().getUpdate().getName()).isEqualTo(ATTEMPT.getName());
|
||||
assertThat(ddiDeploymentBase.getDeployment().getMaintenanceWindow().getStatus()).isEqualTo(
|
||||
AVAILABLE.getStatus());
|
||||
assertThat(ddiDeploymentBase.getDeployment().getMaintenanceWindow().getStatus()).isEqualTo(AVAILABLE.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiDeploymentBase = "{\"id\":[\"1234\"],\"deployment\":{\"download\":\"forced\","
|
||||
+ "\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]},"
|
||||
+ "\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\","
|
||||
+ "\"Action status message 2\"]},\"links\":[]}";
|
||||
final String serializedDdiDeploymentBase = "{\"id\":[\"1234\"],\"deployment\":{\"download\":\"forced\"," +
|
||||
"\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]}," +
|
||||
"\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\"," +
|
||||
"\"Action status message 2\"]},\"links\":[]}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiDeploymentBase, DdiDeploymentBase.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiDeploymentBase, DdiDeploymentBase.class));
|
||||
}
|
||||
}
|
||||
@@ -33,36 +33,33 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiDeploymentTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
DdiDeployment ddiDeployment = new DdiDeployment(FORCED, ATTEMPT, Collections.emptyList(), AVAILABLE);
|
||||
final DdiDeployment ddiDeployment = new DdiDeployment(FORCED, ATTEMPT, Collections.emptyList(), AVAILABLE);
|
||||
|
||||
// Test
|
||||
String serializedDdiDeployment = mapper.writeValueAsString(ddiDeployment);
|
||||
DdiDeployment deserializedDdiDeployment = mapper.readValue(serializedDdiDeployment, DdiDeployment.class);
|
||||
final String serializedDdiDeployment = OBJECT_MAPPER.writeValueAsString(ddiDeployment);
|
||||
final DdiDeployment deserializedDdiDeployment = OBJECT_MAPPER.readValue(serializedDdiDeployment, DdiDeployment.class);
|
||||
|
||||
assertThat(serializedDdiDeployment).contains(ddiDeployment.getDownload().getName(),
|
||||
ddiDeployment.getMaintenanceWindow().getStatus());
|
||||
assertThat(serializedDdiDeployment).contains(ddiDeployment.getDownload().getName(), ddiDeployment.getMaintenanceWindow().getStatus());
|
||||
assertThat(deserializedDdiDeployment.getDownload().getName()).isEqualTo(ddiDeployment.getDownload().getName());
|
||||
assertThat(deserializedDdiDeployment.getUpdate().getName()).isEqualTo(ddiDeployment.getUpdate().getName());
|
||||
assertThat(deserializedDdiDeployment.getMaintenanceWindow().getStatus()).isEqualTo(
|
||||
ddiDeployment.getMaintenanceWindow().getStatus());
|
||||
assertThat(deserializedDdiDeployment.getMaintenanceWindow().getStatus()).isEqualTo(ddiDeployment.getMaintenanceWindow().getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiDeployment = "{\"download\":\"forced\",\"update\":\"attempt\", "
|
||||
+ "\"maintenanceWindow\":\"available\",\"chunks\":[],\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiDeployment = "{\"download\":\"forced\",\"update\":\"attempt\", " +
|
||||
"\"maintenanceWindow\":\"available\",\"chunks\":[],\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
DdiDeployment ddiDeployment = mapper.readValue(serializedDdiDeployment, DdiDeployment.class);
|
||||
|
||||
final DdiDeployment ddiDeployment = OBJECT_MAPPER.readValue(serializedDdiDeployment, DdiDeployment.class);
|
||||
assertThat(ddiDeployment.getDownload().getName()).isEqualTo(FORCED.getName());
|
||||
assertThat(ddiDeployment.getUpdate().getName()).isEqualTo(ATTEMPT.getName());
|
||||
assertThat(ddiDeployment.getMaintenanceWindow().getStatus()).isEqualTo(AVAILABLE.getStatus());
|
||||
@@ -72,11 +69,11 @@ public class DdiDeploymentTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiDeployment = "{\"download\":[\"forced\"],\"update\":\"attempt\", "
|
||||
+ "\"maintenanceWindow\":\"available\",\"chunks\":[]}";
|
||||
final String serializedDdiDeployment = "{\"download\":[\"forced\"],\"update\":\"attempt\", " +
|
||||
"\"maintenanceWindow\":\"available\",\"chunks\":[]}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiDeployment, DdiDeployment.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiDeployment, DdiDeployment.class));
|
||||
}
|
||||
}
|
||||
@@ -29,20 +29,19 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiMetadataTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
String key = "testKey";
|
||||
String value = "testValue";
|
||||
DdiMetadata ddiMetadata = new DdiMetadata(key, value);
|
||||
final String key = "testKey";
|
||||
final String value = "testValue";
|
||||
final DdiMetadata ddiMetadata = new DdiMetadata(key, value);
|
||||
|
||||
// Test
|
||||
String serializedDdiMetadata = mapper.writeValueAsString(ddiMetadata);
|
||||
DdiMetadata deserializedDdiMetadata = mapper.readValue(serializedDdiMetadata, DdiMetadata.class);
|
||||
|
||||
final String serializedDdiMetadata = OBJECT_MAPPER.writeValueAsString(ddiMetadata);
|
||||
final DdiMetadata deserializedDdiMetadata = OBJECT_MAPPER.readValue(serializedDdiMetadata, DdiMetadata.class);
|
||||
assertThat(serializedDdiMetadata).contains(key, value);
|
||||
assertThat(deserializedDdiMetadata.getKey()).isEqualTo(ddiMetadata.getKey());
|
||||
assertThat(deserializedDdiMetadata.getValue()).isEqualTo(ddiMetadata.getValue());
|
||||
@@ -52,11 +51,10 @@ public class DdiMetadataTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiMetadata = "{\"key\":\"testKey\",\"value\":\"testValue\",\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiMetadata = "{\"key\":\"testKey\",\"value\":\"testValue\",\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
DdiMetadata ddiMetadata = mapper.readValue(serializedDdiMetadata, DdiMetadata.class);
|
||||
|
||||
final DdiMetadata ddiMetadata = OBJECT_MAPPER.readValue(serializedDdiMetadata, DdiMetadata.class);
|
||||
assertThat(ddiMetadata.getKey()).isEqualTo("testKey");
|
||||
assertThat(ddiMetadata.getValue()).isEqualTo("testValue");
|
||||
}
|
||||
@@ -65,10 +63,10 @@ public class DdiMetadataTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiMetadata = "{\"key\":[\"testKey\"],\"value\":\"testValue\"}";
|
||||
final String serializedDdiMetadata = "{\"key\":[\"testKey\"],\"value\":\"testValue\"}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiMetadata, DdiMetadata.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiMetadata, DdiMetadata.class));
|
||||
}
|
||||
}
|
||||
@@ -29,18 +29,17 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiPollingTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
DdiPolling ddiPolling = new DdiPolling("10");
|
||||
final DdiPolling ddiPolling = new DdiPolling("10");
|
||||
|
||||
// Test
|
||||
String serializedDdiPolling = mapper.writeValueAsString(ddiPolling);
|
||||
DdiPolling deserializedDdiPolling = mapper.readValue(serializedDdiPolling, DdiPolling.class);
|
||||
|
||||
final String serializedDdiPolling = OBJECT_MAPPER.writeValueAsString(ddiPolling);
|
||||
final DdiPolling deserializedDdiPolling = OBJECT_MAPPER.readValue(serializedDdiPolling, DdiPolling.class);
|
||||
assertThat(serializedDdiPolling).contains(ddiPolling.getSleep());
|
||||
assertThat(deserializedDdiPolling.getSleep()).isEqualTo(ddiPolling.getSleep());
|
||||
}
|
||||
@@ -49,11 +48,10 @@ public class DdiPollingTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiPolling = "{\"sleep\":\"10\",\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiPolling = "{\"sleep\":\"10\",\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
DdiPolling ddiPolling = mapper.readValue(serializedDdiPolling, DdiPolling.class);
|
||||
|
||||
final DdiPolling ddiPolling = OBJECT_MAPPER.readValue(serializedDdiPolling, DdiPolling.class);
|
||||
assertThat(ddiPolling.getSleep()).isEqualTo("10");
|
||||
}
|
||||
|
||||
@@ -61,10 +59,10 @@ public class DdiPollingTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiPolling = "{\"sleep\":[\"10\"]}";
|
||||
final String serializedDdiPolling = "{\"sleep\":[\"10\"]}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiPolling, DdiPolling.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiPolling, DdiPolling.class));
|
||||
}
|
||||
}
|
||||
@@ -29,18 +29,17 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiProgressTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
DdiProgress ddiProgress = new DdiProgress(30, 100);
|
||||
final DdiProgress ddiProgress = new DdiProgress(30, 100);
|
||||
|
||||
// Test
|
||||
String serializedDdiProgress = mapper.writeValueAsString(ddiProgress);
|
||||
DdiProgress deserializedDdiProgress = mapper.readValue(serializedDdiProgress, DdiProgress.class);
|
||||
|
||||
final String serializedDdiProgress = OBJECT_MAPPER.writeValueAsString(ddiProgress);
|
||||
final DdiProgress deserializedDdiProgress = OBJECT_MAPPER.readValue(serializedDdiProgress, DdiProgress.class);
|
||||
assertThat(serializedDdiProgress).contains(ddiProgress.getCnt().toString(), ddiProgress.getOf().toString());
|
||||
assertThat(deserializedDdiProgress.getCnt()).isEqualTo(ddiProgress.getCnt());
|
||||
assertThat(deserializedDdiProgress.getOf()).isEqualTo(ddiProgress.getOf());
|
||||
@@ -50,11 +49,10 @@ public class DdiProgressTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiProgress = "{\"cnt\":30,\"of\":100,\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiProgress = "{\"cnt\":30,\"of\":100,\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
DdiProgress ddiProgress = mapper.readValue(serializedDdiProgress, DdiProgress.class);
|
||||
|
||||
final DdiProgress ddiProgress = OBJECT_MAPPER.readValue(serializedDdiProgress, DdiProgress.class);
|
||||
assertThat(ddiProgress.getCnt()).isEqualTo(30);
|
||||
assertThat(ddiProgress.getOf()).isEqualTo(100);
|
||||
}
|
||||
@@ -63,10 +61,10 @@ public class DdiProgressTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiProgress = "{\"cnt\":[30],\"of\":100}";
|
||||
final String serializedDdiProgress = "{\"cnt\":[30],\"of\":100}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiProgress, DdiProgress.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiProgress, DdiProgress.class));
|
||||
}
|
||||
}
|
||||
@@ -30,21 +30,19 @@ import org.junit.jupiter.api.Test;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiResultTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject() throws IOException {
|
||||
// Setup
|
||||
DdiProgress ddiProgress = new DdiProgress(30, 100);
|
||||
DdiResult ddiResult = new DdiResult(NONE, ddiProgress);
|
||||
final DdiProgress ddiProgress = new DdiProgress(30, 100);
|
||||
final DdiResult ddiResult = new DdiResult(NONE, ddiProgress);
|
||||
|
||||
// Test
|
||||
String serializedDdiResult = mapper.writeValueAsString(ddiResult);
|
||||
DdiResult deserializedDdiResult = mapper.readValue(serializedDdiResult, DdiResult.class);
|
||||
|
||||
assertThat(serializedDdiResult).contains(NONE.getName(), ddiProgress.getCnt().toString(),
|
||||
ddiProgress.getOf().toString());
|
||||
final String serializedDdiResult = OBJECT_MAPPER.writeValueAsString(ddiResult);
|
||||
final DdiResult deserializedDdiResult = OBJECT_MAPPER.readValue(serializedDdiResult, DdiResult.class);
|
||||
assertThat(serializedDdiResult).contains(NONE.getName(), ddiProgress.getCnt().toString(), ddiProgress.getOf().toString());
|
||||
assertThat(deserializedDdiResult.getFinished()).isEqualTo(ddiResult.getFinished());
|
||||
assertThat(deserializedDdiResult.getProgress().getCnt()).isEqualTo(ddiProgress.getCnt());
|
||||
assertThat(deserializedDdiResult.getProgress().getOf()).isEqualTo(ddiProgress.getOf());
|
||||
@@ -54,11 +52,10 @@ public class DdiResultTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiResult = "{\"finished\":\"none\",\"progress\":{\"cnt\":30,\"of\":100},\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiResult = "{\"finished\":\"none\",\"progress\":{\"cnt\":30,\"of\":100},\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
DdiResult ddiResult = mapper.readValue(serializedDdiResult, DdiResult.class);
|
||||
|
||||
final DdiResult ddiResult = OBJECT_MAPPER.readValue(serializedDdiResult, DdiResult.class);
|
||||
assertThat(ddiResult.getFinished()).isEqualTo(NONE);
|
||||
assertThat(ddiResult.getProgress().getCnt()).isEqualTo(30);
|
||||
assertThat(ddiResult.getProgress().getOf()).isEqualTo(100);
|
||||
@@ -68,10 +65,10 @@ public class DdiResultTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiResult = "{\"finished\":[\"none\"],\"progress\":{\"cnt\":30,\"of\":100}}";
|
||||
final String serializedDdiResult = "{\"finished\":[\"none\"],\"progress\":{\"cnt\":30,\"of\":100}}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiResult, DdiResult.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiResult, DdiResult.class));
|
||||
}
|
||||
}
|
||||
@@ -36,24 +36,21 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
@Story("Serializability of DDI api Models")
|
||||
public class DdiStatusTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("ddiStatusPossibilities")
|
||||
@Description("Verify the correct serialization and deserialization of the model")
|
||||
public void shouldSerializeAndDeserializeObject(final DdiResult ddiResult, final DdiStatus ddiStatus) throws IOException {
|
||||
// Test
|
||||
String serializedDdiStatus = mapper.writeValueAsString(ddiStatus);
|
||||
DdiStatus deserializedDdiStatus = mapper.readValue(serializedDdiStatus, DdiStatus.class);
|
||||
|
||||
final String serializedDdiStatus = OBJECT_MAPPER.writeValueAsString(ddiStatus);
|
||||
final DdiStatus deserializedDdiStatus = OBJECT_MAPPER.readValue(serializedDdiStatus, DdiStatus.class);
|
||||
assertThat(serializedDdiStatus).contains(ddiStatus.getExecution().getName(), ddiResult.getFinished().getName(),
|
||||
ddiResult.getProgress().getCnt().toString(), ddiResult.getProgress().getOf().toString());
|
||||
assertThat(deserializedDdiStatus.getExecution()).isEqualTo(ddiStatus.getExecution());
|
||||
assertThat(deserializedDdiStatus.getResult().getFinished()).isEqualTo(ddiStatus.getResult().getFinished());
|
||||
assertThat(deserializedDdiStatus.getResult().getProgress().getCnt()).isEqualTo(
|
||||
ddiStatus.getResult().getProgress().getCnt());
|
||||
assertThat(deserializedDdiStatus.getResult().getProgress().getOf()).isEqualTo(
|
||||
ddiStatus.getResult().getProgress().getOf());
|
||||
assertThat(deserializedDdiStatus.getResult().getProgress().getCnt()).isEqualTo(ddiStatus.getResult().getProgress().getCnt());
|
||||
assertThat(deserializedDdiStatus.getResult().getProgress().getOf()).isEqualTo(ddiStatus.getResult().getProgress().getOf());
|
||||
assertThat(deserializedDdiStatus.getDetails()).isEqualTo(ddiStatus.getDetails());
|
||||
}
|
||||
|
||||
@@ -61,12 +58,11 @@ public class DdiStatusTest {
|
||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||
// Setup
|
||||
final String serializedDdiStatus = "{\"execution\":\"proceeding\",\"result\":{\"finished\":\"none\","
|
||||
+ "\"progress\":{\"cnt\":30,\"of\":100}},\"details\":[],\"unknownProperty\":\"test\"}";
|
||||
final String serializedDdiStatus = "{\"execution\":\"proceeding\",\"result\":{\"finished\":\"none\"," +
|
||||
"\"progress\":{\"cnt\":30,\"of\":100}},\"details\":[],\"unknownProperty\":\"test\"}";
|
||||
|
||||
// Test
|
||||
final DdiStatus ddiStatus = mapper.readValue(serializedDdiStatus, DdiStatus.class);
|
||||
|
||||
final DdiStatus ddiStatus = OBJECT_MAPPER.readValue(serializedDdiStatus, DdiStatus.class);
|
||||
assertThat(ddiStatus.getExecution()).isEqualTo(PROCEEDING);
|
||||
assertThat(ddiStatus.getCode()).isNull();
|
||||
assertThat(ddiStatus.getResult().getFinished()).isEqualTo(NONE);
|
||||
@@ -78,12 +74,11 @@ public class DdiStatusTest {
|
||||
@Description("Verify the correct deserialization of a model with a provided code (optional)")
|
||||
public void shouldDeserializeObjectWithOptionalCode() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiStatus = "{\"execution\":\"proceeding\",\"result\":{\"finished\":\"none\","
|
||||
+ "\"progress\":{\"cnt\":30,\"of\":100}},\"code\": 12,\"details\":[]}";
|
||||
final String serializedDdiStatus = "{\"execution\":\"proceeding\",\"result\":{\"finished\":\"none\"," +
|
||||
"\"progress\":{\"cnt\":30,\"of\":100}},\"code\": 12,\"details\":[]}";
|
||||
|
||||
// Test
|
||||
DdiStatus ddiStatus = mapper.readValue(serializedDdiStatus, DdiStatus.class);
|
||||
|
||||
final DdiStatus ddiStatus = OBJECT_MAPPER.readValue(serializedDdiStatus, DdiStatus.class);
|
||||
assertThat(ddiStatus.getExecution()).isEqualTo(PROCEEDING);
|
||||
assertThat(ddiStatus.getCode()).isEqualTo(12);
|
||||
assertThat(ddiStatus.getResult().getFinished()).isEqualTo(NONE);
|
||||
@@ -95,12 +90,12 @@ public class DdiStatusTest {
|
||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||
// Setup
|
||||
String serializedDdiStatus = "{\"execution\":[\"proceeding\"],\"result\":{\"finished\":\"none\","
|
||||
+ "\"progress\":{\"cnt\":30,\"of\":100}},\"details\":[]}";
|
||||
final String serializedDdiStatus = "{\"execution\":[\"proceeding\"],\"result\":{\"finished\":\"none\"," +
|
||||
"\"progress\":{\"cnt\":30,\"of\":100}},\"details\":[]}";
|
||||
|
||||
// Test
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiStatus, DdiStatus.class));
|
||||
assertThatExceptionOfType(MismatchedInputException.class)
|
||||
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiStatus, DdiStatus.class));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> ddiStatusPossibilities() {
|
||||
|
||||
@@ -48,8 +48,7 @@ public class JsonIgnorePropertiesAnnotationTest {
|
||||
}
|
||||
final JsonIgnoreProperties annotation = modelClass.getAnnotation(JsonIgnoreProperties.class);
|
||||
assertThat(annotation)
|
||||
.describedAs(
|
||||
"Annotation 'JsonIgnoreProperties' is missing for class: " + modelClass.getSimpleName())
|
||||
.describedAs("Annotation 'JsonIgnoreProperties' is missing for class: " + modelClass.getSimpleName())
|
||||
.isNotNull();
|
||||
assertThat(annotation.ignoreUnknown()).isTrue();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user