Sonar findings - fix DdiConfirmationBaseTest, public & no asssert (#1994)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -34,7 +34,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
@Story("CHeck JSON serialization of DDI api confirmation models")
|
@Story("CHeck JSON serialization of DDI api confirmation models")
|
||||||
class DdiConfirmationBaseTest {
|
class DdiConfirmationBaseTest {
|
||||||
|
|
||||||
private final ObjectMapper mapper = new ObjectMapper();
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verify the correct serialization and deserialization of the model")
|
@Description("Verify the correct serialization and deserialization of the model")
|
||||||
@@ -49,8 +49,8 @@ class DdiConfirmationBaseTest {
|
|||||||
ddiActionHistory);
|
ddiActionHistory);
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
String serializedDdiConfirmationBase = mapper.writeValueAsString(ddiConfirmationBaseAction);
|
String serializedDdiConfirmationBase = OBJECT_MAPPER.writeValueAsString(ddiConfirmationBaseAction);
|
||||||
final DdiConfirmationBaseAction deserializedDdiConfigurationBase = mapper
|
final DdiConfirmationBaseAction deserializedDdiConfigurationBase = OBJECT_MAPPER
|
||||||
.readValue(serializedDdiConfirmationBase, DdiConfirmationBaseAction.class);
|
.readValue(serializedDdiConfirmationBase, DdiConfirmationBaseAction.class);
|
||||||
|
|
||||||
assertThat(serializedDdiConfirmationBase).contains(id, FORCED.getName(), ATTEMPT.getName(),
|
assertThat(serializedDdiConfirmationBase).contains(id, FORCED.getName(), ATTEMPT.getName(),
|
||||||
@@ -68,13 +68,15 @@ class DdiConfirmationBaseTest {
|
|||||||
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
@Description("Verify the correct deserialization of a model with a additional unknown property")
|
||||||
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
void shouldDeserializeObjectWithUnknownProperty() throws IOException {
|
||||||
// Setup
|
// Setup
|
||||||
String serializedDdiConfirmationBase = "{\"id\":\"1234\",\"confirmation\":{\"download\":\"forced\","
|
final String serializedDdiConfirmationBase = "{" +
|
||||||
+ "\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]},"
|
"\"id\":\"1234\",\"confirmation\":{\"download\":\"forced\"," +
|
||||||
+ "\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\","
|
"\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]}," +
|
||||||
+ "\"Action status message 2\"]},\"links\":[],\"unknownProperty\":\"test\"}";
|
"\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\"," +
|
||||||
|
"\"Action status message 2\"]},\"links\":[],\"unknownProperty\":\"test\"" +
|
||||||
|
"}";
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
DdiConfirmationBaseAction ddiConfirmationBaseAction = mapper.readValue(serializedDdiConfirmationBase,
|
final DdiConfirmationBaseAction ddiConfirmationBaseAction = OBJECT_MAPPER.readValue(serializedDdiConfirmationBase,
|
||||||
DdiConfirmationBaseAction.class);
|
DdiConfirmationBaseAction.class);
|
||||||
|
|
||||||
assertThat(ddiConfirmationBaseAction.getConfirmation().getDownload().getName()).isEqualTo(FORCED.getName());
|
assertThat(ddiConfirmationBaseAction.getConfirmation().getDownload().getName()).isEqualTo(FORCED.getName());
|
||||||
@@ -87,13 +89,15 @@ class DdiConfirmationBaseTest {
|
|||||||
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
@Description("Verify that deserialization fails for known properties with a wrong datatype")
|
||||||
void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
void shouldFailForObjectWithWrongDataTypes() throws IOException {
|
||||||
// Setup
|
// Setup
|
||||||
String serializedDdiConfirmationBase = "{\"id\":[\"1234\"],\"confirmation\":{\"download\":\"forced\","
|
final String serializedDdiConfirmationBase = "{" +
|
||||||
+ "\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]},"
|
"\"id\":[\"1234\"],\"confirmation\":{\"download\":\"forced\"," +
|
||||||
+ "\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\","
|
"\"update\":\"attempt\",\"maintenanceWindow\":\"available\",\"chunks\":[]}," +
|
||||||
+ "\"Action status message 2\"]},\"links\":[]}";
|
"\"actionHistory\":{\"status\":\"TestAction\",\"messages\":[\"Action status message 1\"," +
|
||||||
|
"\"Action status message 2\"]},\"links\":[]" +
|
||||||
|
"}";
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
assertThatExceptionOfType(MismatchedInputException.class)
|
assertThatExceptionOfType(MismatchedInputException.class)
|
||||||
.isThrownBy(() -> mapper.readValue(serializedDdiConfirmationBase, DdiConfirmationBaseAction.class));
|
.isThrownBy(() -> OBJECT_MAPPER.readValue(serializedDdiConfirmationBase, DdiConfirmationBaseAction.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,14 +69,13 @@ import org.springframework.test.web.servlet.ResultActions;
|
|||||||
*/
|
*/
|
||||||
@Feature("Component Tests - Direct Device Integration API")
|
@Feature("Component Tests - Direct Device Integration API")
|
||||||
@Story("Confirmation Action Resource")
|
@Story("Confirmation Action Resource")
|
||||||
public class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest {
|
class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest {
|
||||||
|
|
||||||
private static final String DEFAULT_CONTROLLER_ID = "4747";
|
private static final String DEFAULT_CONTROLLER_ID = "4747";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Forced deployment to a controller. Checks if the confirmation resource response payload for a given"
|
@Description("Forced deployment to a controller. Checks if the confirmation resource response payload for a given deployment is as expected.")
|
||||||
+ " deployment is as expected.")
|
void verifyConfirmationReferencesInControllerBase(@Autowired ActionStatusRepository actionStatusRepository) throws Exception {
|
||||||
public void verifyConfirmationReferencesInControllerBase(@Autowired ActionStatusRepository actionStatusRepository) throws Exception {
|
|
||||||
enableConfirmationFlow();
|
enableConfirmationFlow();
|
||||||
// Prepare test data
|
// Prepare test data
|
||||||
final DistributionSet ds = testdataFactory.createDistributionSet("", true);
|
final DistributionSet ds = testdataFactory.createDistributionSet("", true);
|
||||||
@@ -142,7 +141,7 @@ public class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensure that the deployment resource is available as CBOR")
|
@Description("Ensure that the deployment resource is available as CBOR")
|
||||||
public void confirmationResourceCbor() throws Exception {
|
void confirmationResourceCbor() throws Exception {
|
||||||
enableConfirmationFlow();
|
enableConfirmationFlow();
|
||||||
final Target target = testdataFactory.createTarget();
|
final Target target = testdataFactory.createTarget();
|
||||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("");
|
final DistributionSet distributionSet = testdataFactory.createDistributionSet("");
|
||||||
@@ -156,19 +155,23 @@ public class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest {
|
|||||||
.getContent().get(0);
|
.getContent().get(0);
|
||||||
|
|
||||||
// get confirmation base
|
// get confirmation base
|
||||||
performGet(CONFIRMATION_BASE_ACTION, MediaType.parseMediaType(DdiRestConstants.MEDIA_TYPE_CBOR),
|
assertThat(
|
||||||
status().isOk(), tenantAware.getCurrentTenant(), target.getControllerId(), action.getId().toString());
|
performGet(
|
||||||
|
CONFIRMATION_BASE_ACTION, MediaType.parseMediaType(DdiRestConstants.MEDIA_TYPE_CBOR),
|
||||||
|
status().isOk(), tenantAware.getCurrentTenant(), target.getControllerId(), action.getId().toString()))
|
||||||
|
.isNotNull();
|
||||||
|
|
||||||
// get artifacts
|
// get artifacts
|
||||||
performGet(SOFTWARE_MODULE_ARTIFACTS, MediaType.parseMediaType(DdiRestConstants.MEDIA_TYPE_CBOR),
|
assertThat(
|
||||||
status().isOk(), tenantAware.getCurrentTenant(), target.getControllerId(),
|
performGet(SOFTWARE_MODULE_ARTIFACTS, MediaType.parseMediaType(DdiRestConstants.MEDIA_TYPE_CBOR),
|
||||||
String.valueOf(softwareModuleId));
|
status().isOk(), tenantAware.getCurrentTenant(), target.getControllerId(),
|
||||||
|
String.valueOf(softwareModuleId)))
|
||||||
|
.isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensure that the confirmation endpoint is not available.")
|
@Description("Ensure that the confirmation endpoint is not available.")
|
||||||
public void confirmationEndpointNotExposed() throws Exception {
|
void confirmationEndpointNotExposed() throws Exception {
|
||||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||||
Target savedTarget = testdataFactory.createTarget("988");
|
Target savedTarget = testdataFactory.createTarget("988");
|
||||||
savedTarget = getFirstAssignedTarget(assignDistributionSet(ds.getId(), savedTarget.getControllerId()));
|
savedTarget = getFirstAssignedTarget(assignDistributionSet(ds.getId(), savedTarget.getControllerId()));
|
||||||
@@ -190,7 +193,7 @@ public class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensure that the deploymentBase endpoint is not available for action ins WFC state.")
|
@Description("Ensure that the deploymentBase endpoint is not available for action ins WFC state.")
|
||||||
public void deploymentEndpointNotAccessibleForActionsWFC() throws Exception {
|
void deploymentEndpointNotAccessibleForActionsWFC() throws Exception {
|
||||||
enableConfirmationFlow();
|
enableConfirmationFlow();
|
||||||
|
|
||||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||||
@@ -218,7 +221,7 @@ public class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensure that the confirmation endpoints are still available after deactivating the confirmation flow.")
|
@Description("Ensure that the confirmation endpoints are still available after deactivating the confirmation flow.")
|
||||||
public void verifyConfirmationBaseEndpointsArePresentAfterDisablingConfirmationFlow() throws Exception {
|
void verifyConfirmationBaseEndpointsArePresentAfterDisablingConfirmationFlow() throws Exception {
|
||||||
enableConfirmationFlow();
|
enableConfirmationFlow();
|
||||||
|
|
||||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||||
|
|||||||
Reference in New Issue
Block a user