added missing JsonIgnoreProperties annotation for DDI Api model classes (#881)

* added missing JsonIgnoreProperties annotation for DDI model classes
* added Copyright Headers & serialization tests for all Ddi model classes
* fixed typo in test
* fixed review findings
* added missing test descriptions

Signed-off-by: Robert Sing <Robert.Sing@bosch-si.com>
This commit is contained in:
Robert Sing
2019-08-27 09:27:20 +02:00
committed by Stefan Behl
parent e841dc6a8a
commit 9f76f6c371
32 changed files with 1453 additions and 18 deletions

View File

@@ -10,15 +10,15 @@
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-rest-parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
</parent>
<artifactId>hawkbit-ddi-api</artifactId>
<name>hawkBit :: REST :: DDI API</name>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-rest-parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
</parent>
<artifactId>hawkbit-ddi-api</artifactId>
<name>hawkBit :: REST :: DDI API</name>
<dependencies>
<dependency>
@@ -37,5 +37,32 @@
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<!-- TEST -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -13,6 +13,7 @@ import java.util.List;
import org.eclipse.hawkbit.ddi.rest.api.DdiRootControllerRestApi;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -24,6 +25,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
* {@link DdiActionFeedback}.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({ "status", "messages" })
public class DdiActionHistory {

View File

@@ -12,12 +12,14 @@ import javax.validation.constraints.NotNull;
import org.springframework.hateoas.ResourceSupport;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Download information for all artifacts related to a specific {@link DdiChunk}
* .
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiArtifact extends ResourceSupport {
@NotNull

View File

@@ -8,15 +8,15 @@
*/
package org.eclipse.hawkbit.ddi.json.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Hashes for given Artifact.
*
*
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiArtifactHash {
@JsonProperty
@@ -40,11 +40,11 @@ public class DdiArtifactHash {
* Public constructor.
*
* @param sha1
* sha1 hash of the artifact
* sha1 hash of the artifact
* @param md5
* md5 hash of the artifact
* md5 hash of the artifact
* @param sha256
* sha256 hash of the artifact
* sha256 hash of the artifact
*/
public DdiArtifactHash(final String sha1, final String md5, final String sha256) {
this.sha1 = sha1;

View File

@@ -10,9 +10,14 @@ package org.eclipse.hawkbit.ddi.json.model;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Cancel action to be provided to the target.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiCancel {
private final String id;
@@ -28,7 +33,9 @@ public class DdiCancel {
* @param cancelAction
* the action
*/
public DdiCancel(final String id, final DdiCancelActionToStop cancelAction) {
@JsonCreator
public DdiCancel(@JsonProperty("id") final String id,
@JsonProperty("cancelAction") final DdiCancelActionToStop cancelAction) {
this.id = id;
this.cancelAction = cancelAction;
}

View File

@@ -10,9 +10,14 @@ package org.eclipse.hawkbit.ddi.json.model;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* The action that has to be stopped by the target.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiCancelActionToStop {
@NotNull
@@ -22,9 +27,10 @@ public class DdiCancelActionToStop {
* Parameterized constructor.
*
* @param stopId
* ID of the action to be stoppedW
* ID of the action to be stopped
*/
public DdiCancelActionToStop(final String stopId) {
@JsonCreator
public DdiCancelActionToStop(@JsonProperty("stopId") final String stopId) {
this.stopId = stopId;
}

View File

@@ -13,12 +13,14 @@ import java.util.List;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Deployment chunks.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiChunk {
@JsonProperty("part")

View File

@@ -13,11 +13,13 @@ import java.util.Map;
import javax.validation.constraints.NotEmpty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Feedback channel for ConfigData action.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiConfigData extends DdiActionFeedback {
@NotEmpty

View File

@@ -13,6 +13,7 @@ import java.util.List;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
@@ -21,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
* Detailed update action information.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiDeployment {
private HandlingType download;

View File

@@ -12,6 +12,7 @@ import javax.validation.constraints.NotNull;
import org.springframework.hateoas.ResourceSupport;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -19,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
/**
* Update action resource.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({ "id", "deployment", "actionHistory" })
public class DdiDeploymentBase extends ResourceSupport {

View File

@@ -10,12 +10,15 @@ package org.eclipse.hawkbit.ddi.json.model;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Additional metadata to be provided for the target/device.
*
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiMetadata {
@JsonProperty
@NotNull
@@ -25,7 +28,8 @@ public class DdiMetadata {
@NotNull
private final String value;
public DdiMetadata(final String key, final String value) {
@JsonCreator
public DdiMetadata(@JsonProperty("key") final String key, @JsonProperty("value")final String value) {
this.key = key;
this.value = value;
}

View File

@@ -11,12 +11,14 @@ package org.eclipse.hawkbit.ddi.json.model;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Action fulfillment progress by means of gives the achieved amount of maximal
* of possible levels.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiProgress {
@NotNull

View File

@@ -12,6 +12,7 @@ import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
@@ -19,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
* Result information of the action progress which can by an intermediate or
* final update.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiResult {
@NotNull

View File

@@ -15,12 +15,14 @@ import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* Details status information concerning the action processing.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class DdiStatus {
@NotNull

View File

@@ -0,0 +1,77 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.assertj.core.util.Lists;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiActionFeedback'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiActionFeedbackTest {
private ObjectMapper mapper = new ObjectMapper();
@Test
@Description("Verify the correct serialization and deserialization of the model")
public void shouldSerializeAndDeserializeObject() throws IOException {
// Setup
Long id = 123L;
String time = "20190809T121314";
DdiStatus ddiStatus = new DdiStatus(DdiStatus.ExecutionStatus.CLOSED, null, Lists.emptyList());
DdiActionFeedback ddiActionFeedback = new DdiActionFeedback(id, time, ddiStatus);
// Test
String serializedDdiActionFeedback = mapper.writeValueAsString(ddiActionFeedback);
DdiActionFeedback deserializedDdiActionFeedback = mapper.readValue(serializedDdiActionFeedback,
DdiActionFeedback.class);
assertThat(serializedDdiActionFeedback).contains(id.toString(), time);
assertThat(deserializedDdiActionFeedback.getId()).isEqualTo(id);
assertThat(deserializedDdiActionFeedback.getTime()).isEqualTo(time);
assertThat(deserializedDdiActionFeedback.getStatus().toString()).isEqualTo(ddiStatus.toString());
}
@Test
@Description("Verify the correct deserialization of a model with a additional unknown property")
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
// Setup
String serializedDdiActionFeedback = "{\"id\":1, \"time\":\"20190809T121314\", \"status\":{\"execution\":\"closed\", \"result\":null, \"details\":[]}, \"unknownProperty\": \"test\"}";
// Test
DdiActionFeedback ddiActionFeedback = mapper.readValue(serializedDdiActionFeedback, DdiActionFeedback.class);
assertThat(ddiActionFeedback.getId()).isEqualTo(1L);
assertThat(ddiActionFeedback.getTime()).matches("20190809T121314");
}
@Test(expected = MismatchedInputException.class)
@Description("Verify that deserialization fails for known properties with a wrong datatype")
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
// Setup
String serializedDdiActionFeedback = "{\"id\": [1],\"time\":\"20190809T121314\",\"status\":{\"execution\":\"closed\",\"result\":null,\"details\":[]}}";
// Test
mapper.readValue(serializedDdiActionFeedback, DdiActionFeedback.class);
}
}

View File

@@ -0,0 +1,74 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiActionHistory'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiActionHistoryTest {
private ObjectMapper mapper = new ObjectMapper();
@Test
@Description("Verify the correct serialization and deserialization of the model")
public void shouldSerializeAndDeserializeObject() throws IOException {
// Setup
String actionStatus = "TestAction";
List<String> messages = Arrays.asList("Action status message 1", "Action status message 2");
DdiActionHistory ddiActionHistory = new DdiActionHistory(actionStatus, messages);
// Test
String serializedDdiActionHistory = mapper.writeValueAsString(ddiActionHistory);
DdiActionHistory deserializedDdiActionHistory = 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));
}
@Test
@Description("Verify the correct deserialization of a model with a additional unknown property")
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
// Setup
String serializedDdiActionHistory = "{\"status\":\"SomeAction\", \"messages\":[\"Some message\"], \"unknownProperty\": \"test\"}";
// Test
DdiActionHistory ddiActionHistory = mapper.readValue(serializedDdiActionHistory, DdiActionHistory.class);
assertThat(ddiActionHistory.toString()).contains("SomeAction", "Some message");
}
@Test(expected = MismatchedInputException.class)
@Description("Verify that deserialization fails for known properties with a wrong datatype")
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
// Setup
String serializedDdiActionFeedback = "{\"status\": [SomeAction], \"messages\": [\"Some message\"]}";
// Test
mapper.readValue(serializedDdiActionFeedback, DdiActionHistory.class);
}
}

View File

@@ -0,0 +1,78 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiArtifactHash'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiArtifactHashTest {
private ObjectMapper 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);
// Test
String serializedDdiArtifact = mapper.writeValueAsString(DdiArtifact);
DdiArtifactHash deserializedDdiArtifact = mapper.readValue(serializedDdiArtifact,
DdiArtifactHash.class);
assertThat(serializedDdiArtifact).contains(sha1Hash, md5Hash, sha256Hash);
assertThat(deserializedDdiArtifact.getSha1()).isEqualTo(sha1Hash);
assertThat(deserializedDdiArtifact.getMd5()).isEqualTo(md5Hash);
assertThat(deserializedDdiArtifact.getSha256()).isEqualTo(sha256Hash);
}
@Test
@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\"}";
// Test
DdiArtifactHash ddiArtifact = mapper.readValue(serializedDdiArtifact, DdiArtifactHash.class);
assertThat(ddiArtifact.getSha1()).isEqualTo("123");
assertThat(ddiArtifact.getMd5()).isEqualTo("456");
assertThat(ddiArtifact.getSha256()).isEqualTo("789");
}
@Test(expected = MismatchedInputException.class)
@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\"";
// Test
mapper.readValue(serializedDdiArtifact, DdiArtifactHash.class);
}
}

View File

@@ -0,0 +1,84 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiArtifact'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiArtifactTest {
private ObjectMapper 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;
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);
assertThat(serializedDdiArtifact).contains(filename, "12345");
assertThat(deserializedDdiArtifact.getFilename()).isEqualTo(filename);
assertThat(deserializedDdiArtifact.getSize()).isEqualTo(size);
assertThat(deserializedDdiArtifact.getHashes().getSha1()).isEqualTo(hashes.getSha1());
assertThat(deserializedDdiArtifact.getHashes().getMd5()).isEqualTo(hashes.getMd5());
assertThat(deserializedDdiArtifact.getHashes().getSha256()).isEqualTo(hashes.getSha256());
}
@Test
@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\"}";
// Test
DdiArtifact ddiArtifact = mapper.readValue(serializedDdiArtifact, DdiArtifact.class);
assertThat(ddiArtifact.getFilename()).isEqualTo("test.file");
assertThat(ddiArtifact.getSize()).isEqualTo(111);
assertThat(ddiArtifact.getHashes().getSha1()).isEqualTo("123");
assertThat(ddiArtifact.getHashes().getMd5()).isEqualTo("456");
assertThat(ddiArtifact.getHashes().getSha256()).isEqualTo("789");
}
@Test(expected = MismatchedInputException.class)
@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\":[]}";
// Test
mapper.readValue(serializedDdiArtifact, DdiArtifact.class);
}
}

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiCancelActionToStop'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiCancelActionToStopTest {
private ObjectMapper 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);
assertThat(serializedDdiCancelActionToStop).contains(stopId);
assertThat(deserializedDdiCancelActionToStop.getStopId()).isEqualTo(stopId);
}
@Test
@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\"}";
// Test
DdiCancelActionToStop ddiCancelActionToStop = mapper.readValue(serializedDdiCancelActionToStop,
DdiCancelActionToStop.class);
assertThat(ddiCancelActionToStop.getStopId()).contains("12345");
}
@Test(expected = MismatchedInputException.class)
@Description("Verify that deserialization fails for known properties with a wrong datatype")
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
// Setup
String serializedDdiCancelActionToStop = "{\"stopId\": [\"12345\"]}";
// Test
mapper.readValue(serializedDdiCancelActionToStop, DdiCancelActionToStop.class);
}
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiArtifact'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiCancelTest {
private ObjectMapper 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);
// Test
String serializedDdiCancel = mapper.writeValueAsString(ddiCancel);
DdiCancel deserializedDdiCancel = mapper.readValue(serializedDdiCancel, DdiCancel.class);
assertThat(serializedDdiCancel).contains(ddiCancelId, ddiCancelActionToStop.getStopId());
assertThat(deserializedDdiCancel.getId()).isEqualTo(ddiCancelId);
assertThat(deserializedDdiCancel.getCancelAction().getStopId()).isEqualTo(ddiCancelActionToStop.getStopId());
}
@Test
@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\"}";
// Test
DdiCancel ddiCancel = mapper.readValue(serializedDdiCancel, DdiCancel.class);
assertThat(ddiCancel.getId()).isEqualTo("1234");
assertThat(ddiCancel.getCancelAction().getStopId()).matches("1234");
}
@Test(expected = MismatchedInputException.class)
@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\"}}";
// Test
mapper.readValue(serializedDdiCancel, DdiCancel.class);
}
}

View File

@@ -0,0 +1,81 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiChunk'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiChunkTest {
private ObjectMapper mapper = new ObjectMapper();
@Test
@Description("Verify the correct serialization and deserialization of the model")
public void shouldSerializeAndDeserializeObject() throws IOException {
// Setup
String part = "1234";
String version = "1.0";
String name = "Dummy-Artifact";
List<DdiArtifact> dummyArtifacts = Collections.emptyList();
DdiChunk ddiChunk = new DdiChunk(part, version, name, dummyArtifacts, null);
// Test
String serializedDdiChunk = mapper.writeValueAsString(ddiChunk);
DdiChunk deserializedDdiChunk = mapper.readValue(serializedDdiChunk, DdiChunk.class);
assertThat(serializedDdiChunk).contains(part, version, name);
assertThat(deserializedDdiChunk.getPart()).isEqualTo(part);
assertThat(deserializedDdiChunk.getVersion()).isEqualTo(version);
assertThat(deserializedDdiChunk.getName()).isEqualTo(name);
assertThat(deserializedDdiChunk.getArtifacts().size()).isEqualTo(0);
}
@Test
@Description("Verify the correct deserialization of a model with a additional unknown property")
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
// Setup
String serializedDdiChunk = "{\"part\":\"1234\",\"version\":\"1.0\",\"name\":\"Dummy-Artifact\",\"artifacts\":[],\"unknownProperty\":\"test\"}";
// Test
DdiChunk ddiChunk = mapper.readValue(serializedDdiChunk, DdiChunk.class);
assertThat(ddiChunk.getPart()).isEqualTo("1234");
assertThat(ddiChunk.getVersion()).isEqualTo("1.0");
assertThat(ddiChunk.getName()).isEqualTo("Dummy-Artifact");
assertThat(ddiChunk.getArtifacts().size()).isEqualTo(0);
}
@Test(expected = MismatchedInputException.class)
@Description("Verify that deserialization fails for known properties with a wrong datatype")
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
// Setup
String serializedDdiChunk = "{\"part\":[\"1234\"],\"version\":\"1.0\",\"name\":\"Dummy-Artifact\",\"artifacts\":[]}";
// Test
mapper.readValue(serializedDdiChunk, DdiChunk.class);
}
}

View File

@@ -0,0 +1,92 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiConfigData'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiConfigDataTest {
private ObjectMapper mapper = new ObjectMapper();
@Test
@Description("Verify the correct serialization and deserialization of the model")
public void shouldSerializeAndDeserializeObject() throws IOException {
// Setup
Long id = 123L;
String time = "20190809T121314";
DdiStatus ddiStatus = new DdiStatus(DdiStatus.ExecutionStatus.CLOSED,
new DdiResult(DdiResult.FinalResult.SUCCESS, null), null);
Map<String, String> data = new HashMap<>();
data.put("test", "data");
DdiConfigData ddiConfigData = new DdiConfigData(id, time, ddiStatus, data, DdiUpdateMode.REPLACE);
// Test
String serializedDdiConfigData = mapper.writeValueAsString(ddiConfigData);
DdiConfigData deserializedDdiConfigData = mapper.readValue(serializedDdiConfigData, DdiConfigData.class);
assertThat(serializedDdiConfigData).contains(id.toString(), time, ddiStatus.getExecution().getName(),
ddiStatus.getResult().getFinished().getName(), "test", "data");
assertThat(deserializedDdiConfigData.getId()).isEqualTo(id);
assertThat(deserializedDdiConfigData.getTime()).isEqualTo(time);
assertThat(deserializedDdiConfigData.getStatus().getExecution()).isEqualTo(DdiStatus.ExecutionStatus.CLOSED);
assertThat(deserializedDdiConfigData.getStatus().getResult().getFinished()).isEqualTo(
DdiResult.FinalResult.SUCCESS);
assertThat(deserializedDdiConfigData.getMode()).isEqualTo(DdiUpdateMode.REPLACE);
}
@Test
@Description("Verify the correct deserialization of a model with a additional unknown property")
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
// Setup
String serializedDdiConfigData = "{\"id\":123,\"time\":\"20190809T121314\","
+ "\"status\":{\"execution\":\"closed\",\"result\":{\"finished\":\"success\",\"progress\":null},"
+ "\"details\":[]},\"data\":{\"test\":\"data\"},\"mode\":\"replace\",\"unknownProperty\":\"test\"}";
// Test
DdiConfigData ddiConfigData = mapper.readValue(serializedDdiConfigData, DdiConfigData.class);
assertThat(ddiConfigData.getId()).isEqualTo(123);
assertThat(ddiConfigData.getTime()).isEqualTo("20190809T121314");
assertThat(ddiConfigData.getStatus().getExecution()).isEqualTo(DdiStatus.ExecutionStatus.CLOSED);
assertThat(ddiConfigData.getStatus().getResult().getFinished()).isEqualTo(DdiResult.FinalResult.SUCCESS);
assertThat(ddiConfigData.getMode()).isEqualTo(DdiUpdateMode.REPLACE);
}
@Test(expected = MismatchedInputException.class)
@Description("Verify that deserialization fails for known properties with a wrong datatype")
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
// Setup
String serializedDdiConfigData = "{\"id\":[123],\"time\":\"20190809T121314\","
+ "\"status\":{\"execution\":\"closed\",\"result\":{\"finished\":\"success\",\"progress\":null},"
+ "\"details\":[]},\"data\":{\"test\":\"data\"},\"mode\":\"replace\",\"unknownProperty\":\"test\"}";
// Test
mapper.readValue(serializedDdiConfigData, DdiConfigData.class);
}
}

View File

@@ -0,0 +1,70 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiConfig'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiConfigTest {
private ObjectMapper 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);
// Test
String serializedDdiConfig = mapper.writeValueAsString(ddiConfig);
DdiConfig deserializedDdiConfig = mapper.readValue(serializedDdiConfig, DdiConfig.class);
assertThat(serializedDdiConfig).contains("10");
assertThat(deserializedDdiConfig.getPolling().getSleep()).isEqualTo("10");
}
@Test
@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\"}";
// Test
DdiConfig ddiConfig = mapper.readValue(serializedDdiConfig, DdiConfig.class);
assertThat(ddiConfig.getPolling().getSleep()).isEqualTo("123");
}
@Test(expected = MismatchedInputException.class)
@Description("Verify that deserialization fails for known properties with a wrong datatype")
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
// Setup
String serializedDdiConfig = "{\"polling\":{\"sleep\":[\"10\"]}}";
// Test
mapper.readValue(serializedDdiConfig, DdiConfig.class);
}
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiControllerBase'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiControllerBaseTest {
private ObjectMapper 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);
// Test
String serializedDdiControllerBase = mapper.writeValueAsString(ddiControllerBase);
DdiControllerBase deserializedDdiControllerBase = mapper.readValue(serializedDdiControllerBase,
DdiControllerBase.class);
assertThat(serializedDdiControllerBase).contains(ddiPolling.getSleep());
assertThat(deserializedDdiControllerBase.getConfig().getPolling().getSleep()).isEqualTo(ddiPolling.getSleep());
}
@Test
@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\"}";
// Test
DdiControllerBase ddiControllerBase = mapper.readValue(serializedDdiControllerBase, DdiControllerBase.class);
assertThat(ddiControllerBase.getConfig().getPolling().getSleep()).isEqualTo("123");
}
@Test(expected = MismatchedInputException.class)
@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\"}";
// Test
mapper.readValue(serializedDdiControllerBase, DdiControllerBase.class);
}
}

View File

@@ -0,0 +1,94 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.hawkbit.ddi.json.model.DdiDeployment.DdiMaintenanceWindowStatus.AVAILABLE;
import static org.eclipse.hawkbit.ddi.json.model.DdiDeployment.HandlingType.ATTEMPT;
import static org.eclipse.hawkbit.ddi.json.model.DdiDeployment.HandlingType.FORCED;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiDeploymentBase'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiDeploymentBaseTest {
private ObjectMapper 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);
// Test
String serializedDdiDeploymentBase = mapper.writeValueAsString(ddiDeploymentBase);
DdiDeploymentBase deserializedDdiDeploymentBase = 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.getActionHistory().toString()).isEqualTo(ddiActionHistory.toString());
}
@Test
@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\"}";
// Test
DdiDeploymentBase ddiDeploymentBase = 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());
}
@Test(expected = MismatchedInputException.class)
@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\":[]}";
// Test
mapper.readValue(serializedDdiDeploymentBase, DdiDeploymentBase.class);
}
}

View File

@@ -0,0 +1,81 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.hawkbit.ddi.json.model.DdiDeployment.DdiMaintenanceWindowStatus.AVAILABLE;
import static org.eclipse.hawkbit.ddi.json.model.DdiDeployment.HandlingType.ATTEMPT;
import static org.eclipse.hawkbit.ddi.json.model.DdiDeployment.HandlingType.FORCED;
import java.io.IOException;
import java.util.Collections;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiDeployment'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiDeploymentTest {
private ObjectMapper 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);
// Test
String serializedDdiDeployment = mapper.writeValueAsString(ddiDeployment);
DdiDeployment deserializedDdiDeployment = mapper.readValue(serializedDdiDeployment, DdiDeployment.class);
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());
}
@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\"}";
// Test
DdiDeployment ddiDeployment = 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());
}
@Test(expected = MismatchedInputException.class)
@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\":[]}";
// Test
mapper.readValue(serializedDdiDeployment, DdiDeployment.class);
}
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiMetadata'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiMetadataTest {
private ObjectMapper 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);
// Test
String serializedDdiMetadata = mapper.writeValueAsString(ddiMetadata);
DdiMetadata deserializedDdiMetadata = mapper.readValue(serializedDdiMetadata, DdiMetadata.class);
assertThat(serializedDdiMetadata).contains(key, value);
assertThat(deserializedDdiMetadata.getKey()).isEqualTo(ddiMetadata.getKey());
assertThat(deserializedDdiMetadata.getValue()).isEqualTo(ddiMetadata.getValue());
}
@Test
@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\"}";
// Test
DdiMetadata ddiMetadata = mapper.readValue(serializedDdiMetadata, DdiMetadata.class);
assertThat(ddiMetadata.getKey()).isEqualTo("testKey");
assertThat(ddiMetadata.getValue()).isEqualTo("testValue");
}
@Test(expected = MismatchedInputException.class)
@Description("Verify that deserialization fails for known properties with a wrong datatype")
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
// Setup
String serializedDdiMetadata = "{\"key\":[\"testKey\"],\"value\":\"testValue\"}";
// Test
mapper.readValue(serializedDdiMetadata, DdiMetadata.class);
}
}

View File

@@ -0,0 +1,69 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiPolling'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiPollingTest {
private ObjectMapper 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");
// Test
String serializedDdiPolling = mapper.writeValueAsString(ddiPolling);
DdiPolling deserializedDdiPolling = mapper.readValue(serializedDdiPolling, DdiPolling.class);
assertThat(serializedDdiPolling).contains(ddiPolling.getSleep());
assertThat(deserializedDdiPolling.getSleep()).isEqualTo(ddiPolling.getSleep());
}
@Test
@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\"}";
// Test
DdiPolling ddiPolling = mapper.readValue(serializedDdiPolling, DdiPolling.class);
assertThat(ddiPolling.getSleep()).isEqualTo("10");
}
@Test(expected = MismatchedInputException.class)
@Description("Verify that deserialization fails for known properties with a wrong datatype")
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
// Setup
String serializedDdiPolling = "{\"sleep\":[\"10\"]}";
// Test
mapper.readValue(serializedDdiPolling, DdiPolling.class);
}
}

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiProgress'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiProgressTest {
private ObjectMapper 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);
// Test
String serializedDdiProgress = mapper.writeValueAsString(ddiProgress);
DdiProgress deserializedDdiProgress = 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());
}
@Test
@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\"}";
// Test
DdiProgress ddiProgress = mapper.readValue(serializedDdiProgress, DdiProgress.class);
assertThat(ddiProgress.getCnt()).isEqualTo(30);
assertThat(ddiProgress.getOf()).isEqualTo(100);
}
@Test(expected = MismatchedInputException.class)
@Description("Verify that deserialization fails for known properties with a wrong datatype")
public void shouldFailForObjectWithWrongDataTypes() throws IOException {
// Setup
String serializedDdiProgress = "{\"cnt\":[30],\"of\":100}";
// Test
mapper.readValue(serializedDdiProgress, DdiProgress.class);
}
}

View File

@@ -0,0 +1,76 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.hawkbit.ddi.json.model.DdiResult.FinalResult.NONE;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiResult'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiResultTest {
private ObjectMapper 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);
// Test
String serializedDdiResult = mapper.writeValueAsString(ddiResult);
DdiResult deserializedDdiResult = 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());
}
@Test
@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\"}";
// Test
DdiResult ddiResult = mapper.readValue(serializedDdiResult, DdiResult.class);
assertThat(ddiResult.getFinished()).isEqualTo(NONE);
assertThat(ddiResult.getProgress().getCnt()).isEqualTo(30);
assertThat(ddiResult.getProgress().getOf()).isEqualTo(100);
}
@Test(expected = MismatchedInputException.class)
@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}}";
// Test
mapper.readValue(serializedDdiResult, DdiResult.class);
}
}

View File

@@ -0,0 +1,85 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.hawkbit.ddi.json.model.DdiResult.FinalResult.NONE;
import static org.eclipse.hawkbit.ddi.json.model.DdiStatus.ExecutionStatus.PROCEEDING;
import java.io.IOException;
import java.util.Collections;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Test serializability of DDI api model 'DdiStatus'
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class DdiStatusTest {
private ObjectMapper 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);
DdiStatus ddiStatus = new DdiStatus(PROCEEDING, ddiResult, Collections.emptyList());
// Test
String serializedDdiStatus = mapper.writeValueAsString(ddiStatus);
DdiStatus deserializedDdiStatus = 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());
}
@Test
@Description("Verify the correct deserialization of a model with a additional unknown property")
public void shouldDeserializeObjectWithUnknownProperty() throws IOException {
// Setup
String serializedDdiStatus = "{\"execution\":\"proceeding\",\"result\":{\"finished\":\"none\","
+ "\"progress\":{\"cnt\":30,\"of\":100}},\"details\":[],\"unknownProperty\":\"test\"}";
// Test
DdiStatus ddiStatus = mapper.readValue(serializedDdiStatus, DdiStatus.class);
assertThat(ddiStatus.getExecution()).isEqualTo(PROCEEDING);
assertThat(ddiStatus.getResult().getFinished()).isEqualTo(NONE);
assertThat(ddiStatus.getResult().getProgress().getCnt()).isEqualTo(30);
assertThat(ddiStatus.getResult().getProgress().getOf()).isEqualTo(100);
}
@Test(expected = MismatchedInputException.class)
@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\":[]}";
// Test
mapper.readValue(serializedDdiStatus, DdiStatus.class);
}
}

View File

@@ -0,0 +1,51 @@
/**
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ddi.json.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import org.junit.Test;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.ClassPath;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
/**
* Check DDI api model classes for '@JsonIgnoreProperties' annotation
*/
@Feature("Unit Tests - Direct Device Integration API")
@Story("Serializability of DDI api Models")
public class JsonIgnorePropertiesAnnotationTest {
@Test
@Description(
"This test verifies that all model classes within the 'org.eclipse.hawkbit.ddi.json.model' package are annotated with '@JsonIgnoreProperties(ignoreUnknown = true)'")
public void shouldCheckAnnotationsForAllModelClasses() throws IOException {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
String packageName = this.getClass().getPackage().getName();
ImmutableSet<ClassPath.ClassInfo> topLevelClasses = ClassPath.from(loader).getTopLevelClasses(packageName);
for (ClassPath.ClassInfo classInfo : topLevelClasses) {
Class<?> modelClass = classInfo.load();
if (modelClass.getSimpleName().contains("Test") || modelClass.isEnum()) {
continue;
}
JsonIgnoreProperties annotation = modelClass.getAnnotation(JsonIgnoreProperties.class);
assertThat(annotation).isNotNull();
assertThat(annotation.ignoreUnknown()).isTrue();
}
}
}