Feature/java11 build (#1280)
* hawkBit on Java 11 Signed-off-by: Dominic Schabel <dominic.schabel@bosch.io> * Preparing java 11 build - Update eclipse-link maven plugin dependencies - Fixing warnings, adopt to java-11 style Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io> * Preparing java 11 build - Fixing warnings, adapt to java-11 style - Added since to deprecated Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io> * Fixing sonar warnings - removed deprecated API Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io> * Fixing sonar warnings & failing test - Added suppressWarning - added WithSpringAuthorityRule to clean-up listener Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io> * Compile warnings - Test if final causes issues in tests Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io> * Removed deprecated code Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io> * Reverted changes Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io> * Removed final as this causes invalid reflective access exceptions - The eclipselink generated classes seem to modify the field directly - update plugin version Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io> * Upgrade eclipselink from 2.7.9 to 2.7.10 * Remove @deprecated endpoints from MgmtTargetTagResource * Remove dependencies already defined in eclipselink-maven-plugin * Try eclipselink 2.7.11-RC1 * Set project encoding to UTF-8 * Upgrade surefire and failsafe plugins to 3.0.0-M7 * Try fixed string instead of a random generated one * Replace JsonBuilder by Jackson ObjectMapper usage * Use JsonBuilder again * Use APPLICATION_JSON_UTF8 instead of APPLICATION_JSON * Try to replace com.vaadin.external.google:android-json by org.json:json * Add debugging outputs * Improve debugging outputs * Improve debugging outputs * Use Jackson instead of JsonBuilder * Use Jackson instead of JsonBuilder 2nd part * Use Spring json dependency * Use eclipselink 2.7.11 * Fix RootControllerDocumentationTest * Improve helper methods of AbstractDDiApiIntegrationTest * Upgrade SpringBoot and SpringCloud versions * Improve deprecation notice for 0.3.0M8 * Fix BaseAmqpServiceTest * Fix SpecificationsBuilderTest * Removed deprecated code * Define maven-enforcer-plugin version * Remove com.google.code.findbugs.jsr305 Signed-off-by: Florian Ruschbaschan <florian.ruschbaschan@bosch.io> * Update circleci image to openjdk:openjdk:11.0.13-jdk-buster Signed-off-by: Florian Ruschbaschan <florian.ruschbaschan@bosch.io> * Fix javadoc generation and license check Signed-off-by: Florian Ruschbaschan <florian.ruschbaschan@bosch.io> * Fix review findings Signed-off-by: Florian Ruschbaschan <florian.ruschbaschan@bosch.io> Signed-off-by: Dominic Schabel <dominic.schabel@bosch.io> Signed-off-by: Peter Vigier <Peter.Vigier@bosch.io> Signed-off-by: Florian Ruschbaschan <florian.ruschbaschan@bosch.io> Co-authored-by: Dominic Schabel <dominic.schabel@bosch.io> Co-authored-by: Peter Vigier <Peter.Vigier@bosch.io> Co-authored-by: Markus Block <markus.block@bosch-si.com>
This commit is contained in:
committed by
GitHub
parent
537548defb
commit
32718676a4
@@ -29,21 +29,15 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* The answer header would look like: { "id": "51659181", "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>
|
||||
*
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiActionFeedback {
|
||||
/**
|
||||
* @deprecated
|
||||
* This ID is always given by the actionId path variable.
|
||||
* Will be removed in future versions.
|
||||
*/
|
||||
@Deprecated
|
||||
private final Long id;
|
||||
|
||||
private final String time;
|
||||
|
||||
@NotNull
|
||||
@@ -51,27 +45,20 @@ public class DdiActionFeedback {
|
||||
private final DdiStatus status;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param id
|
||||
* of the actions the feedback is for
|
||||
* Constructs an action-feedback
|
||||
*
|
||||
* @param time
|
||||
* of the feedback
|
||||
* time of feedback
|
||||
* @param status
|
||||
* is the feedback itself
|
||||
* status to be appended to the action
|
||||
*/
|
||||
@JsonCreator
|
||||
public DdiActionFeedback(@JsonProperty("id") final Long id, @JsonProperty("time") final String time,
|
||||
@JsonProperty("status") final DdiStatus status) {
|
||||
this.id = id;
|
||||
public DdiActionFeedback(@JsonProperty(value = "time", required = true) final String time,
|
||||
@JsonProperty(value = "status", required = true) final DdiStatus status) {
|
||||
this.time = time;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
@@ -82,7 +69,7 @@ public class DdiActionFeedback {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ActionFeedback [id=" + id + ", time=" + time + ", status=" + status + "]";
|
||||
return "ActionFeedback [time=" + time + ", status=" + status + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,16 +61,6 @@ public final class DdiRestConstants {
|
||||
*/
|
||||
public static final String MEDIA_TYPE_CBOR = "application/cbor";
|
||||
|
||||
/**
|
||||
* Media type for CBOR content with strings encoded as UTF-8. Technically
|
||||
* redundant since CBOR always uses UTF-8, but Spring will append it
|
||||
* regardless.
|
||||
* @deprecated Since the Spring Framework (v5.2.4.RELEASE) dropped the charset attribute
|
||||
* from content type headers, please use {@link DdiRestConstants#MEDIA_TYPE_CBOR} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String MEDIA_TYPE_CBOR_UTF8 = "application/cbor;charset=UTF-8";
|
||||
|
||||
private DdiRestConstants() {
|
||||
// constant class, private constructor.
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
@@ -22,57 +24,41 @@ import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test serializability of DDI api model 'DdiActionFeedback'
|
||||
* Test serialization of DDI api model 'DdiActionFeedback'
|
||||
*/
|
||||
@Feature("Unit Tests - Direct Device Integration API")
|
||||
@Story("Serializability of DDI api Models")
|
||||
@Story("Serialization of DDI api Models")
|
||||
public class DdiActionFeedbackTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
private final 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);
|
||||
final String time = Instant.now().toString();
|
||||
final DdiStatus ddiStatus = new DdiStatus(DdiStatus.ExecutionStatus.CLOSED, null, Lists.emptyList());
|
||||
final DdiActionFeedback ddiActionFeedback = new DdiActionFeedback(time, ddiStatus);
|
||||
|
||||
// Test
|
||||
String serializedDdiActionFeedback = mapper.writeValueAsString(ddiActionFeedback);
|
||||
DdiActionFeedback deserializedDdiActionFeedback = mapper.readValue(serializedDdiActionFeedback,
|
||||
final String serializedDdiActionFeedback = mapper.writeValueAsString(ddiActionFeedback);
|
||||
final DdiActionFeedback deserializedDdiActionFeedback = mapper.readValue(serializedDdiActionFeedback,
|
||||
DdiActionFeedback.class);
|
||||
|
||||
assertThat(serializedDdiActionFeedback).contains(id.toString(), time);
|
||||
assertThat(deserializedDdiActionFeedback.getId()).isEqualTo(id);
|
||||
assertThat(serializedDdiActionFeedback).contains(time);
|
||||
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");
|
||||
assertThat(deserializedDdiActionFeedback.getStatus()).hasToString(ddiStatus.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@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\":[]}}";
|
||||
final String serializedDdiActionFeedback = "{\"time\":\"20190809T121314\",\"status\":{\"execution\": [closed],\"result\":null,\"details\":[]}}";
|
||||
|
||||
assertThatExceptionOfType(MismatchedInputException.class).isThrownBy(
|
||||
() -> mapper.readValue(serializedDdiActionFeedback, DdiActionFeedback.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ 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")
|
||||
@Story("Serialization of DDI api Models")
|
||||
public class JsonIgnorePropertiesAnnotationTest {
|
||||
|
||||
@Test
|
||||
@@ -35,15 +35,15 @@ public class JsonIgnorePropertiesAnnotationTest {
|
||||
"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();
|
||||
final String packageName = this.getClass().getPackage().getName();
|
||||
|
||||
ImmutableSet<ClassPath.ClassInfo> topLevelClasses = ClassPath.from(loader).getTopLevelClasses(packageName);
|
||||
for (ClassPath.ClassInfo classInfo : topLevelClasses) {
|
||||
Class<?> modelClass = classInfo.load();
|
||||
final ImmutableSet<ClassPath.ClassInfo> topLevelClasses = ClassPath.from(loader).getTopLevelClasses(packageName);
|
||||
for (final ClassPath.ClassInfo classInfo : topLevelClasses) {
|
||||
final Class<?> modelClass = classInfo.load();
|
||||
if (modelClass.getSimpleName().contains("Test") || modelClass.isEnum()) {
|
||||
continue;
|
||||
}
|
||||
JsonIgnoreProperties annotation = modelClass.getAnnotation(JsonIgnoreProperties.class);
|
||||
final JsonIgnoreProperties annotation = modelClass.getAnnotation(JsonIgnoreProperties.class);
|
||||
assertThat(annotation).isNotNull();
|
||||
assertThat(annotation.ignoreUnknown()).isTrue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user