Merge remote-tracking branch 'origin/master' into fix_migration_to_new_spring_boot_version_merge_master

Signed-off-by: Ammar Bikic <ammar.bikic@bosch.io>
This commit is contained in:
Ammar Bikic
2021-01-15 16:44:31 +01:00
45 changed files with 709 additions and 167 deletions

View File

@@ -64,12 +64,15 @@ import org.eclipse.hawkbit.util.IpUtil;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.test.web.servlet.MvcResult;
import com.jayway.jsonpath.JsonPath;
@@ -113,6 +116,9 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
private static final String JSON_PATH_DESCRIPTION = JSON_PATH_ROOT + JSON_PATH_FIELD_DESCRIPTION;
private static final String JSON_PATH_LAST_REQUEST_AT = JSON_PATH_ROOT + JSON_PATH_FIELD_LAST_REQUEST_AT;
@Autowired
private JpaProperties jpaProperties;
@Test
@Description("Ensures that actions list is in exptected order.")
public void getActionStatusReturnsCorrectType() throws Exception {
@@ -2015,11 +2021,22 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
assignDistributionSet(dsId, targetId, customWeightHigh);
assignDistributionSet(dsId, targetId, customWeightLow);
mvc.perform(get("/rest/v1/targets/{targetId}/actions", targetId)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "WEIGHT:ASC")).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("content.[0].weight").doesNotExist())
.andExpect(jsonPath("content.[1].weight", equalTo(customWeightLow)))
.andExpect(jsonPath("content.[2].weight", equalTo(customWeightHigh)));
// POSTGRESQL sets null values at the end, not the beginning
if (Database.POSTGRESQL.equals(jpaProperties.getDatabase())) {
mvc.perform(get("/rest/v1/targets/{targetId}/actions", targetId)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "WEIGHT:ASC"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("content.[0].weight", equalTo(customWeightLow)))
.andExpect(jsonPath("content.[1].weight", equalTo(customWeightHigh)))
.andExpect(jsonPath("content.[2].weight").doesNotExist());
} else {
mvc.perform(get("/rest/v1/targets/{targetId}/actions", targetId)
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "WEIGHT:ASC"))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("content.[0].weight").doesNotExist())
.andExpect(jsonPath("content.[1].weight", equalTo(customWeightLow)))
.andExpect(jsonPath("content.[2].weight", equalTo(customWeightHigh)));
}
}

View File

@@ -225,14 +225,11 @@ public abstract class JsonBuilder {
public static String deploymentActionFeedback(final String id, final String execution, final String finished,
final Collection<String> messages) throws JSONException {
return new JSONObject().put("id", id).put("time", "20140511T121314")
.put("status",
new JSONObject().put("execution", execution)
.put("result",
new JSONObject().put("finished", finished).put("progress",
new JSONObject().put("cnt", 2).put("of", 5)))
.put("details", new JSONArray(messages)))
.toString();
return new JSONObject().put("id", id).put("status", new JSONObject().put("execution", execution)
.put("result",
new JSONObject().put("finished", finished).put("progress",
new JSONObject().put("cnt", 2).put("of", 5)))
.put("details", new JSONArray(messages))).toString();
}
/**
@@ -566,7 +563,7 @@ public abstract class JsonBuilder {
public static String cancelActionFeedback(final String id, final String execution, final String message)
throws JSONException {
return new JSONObject().put("id", id).put("time", "20140511T121314")
return new JSONObject().put("id", id)
.put("status",
new JSONObject().put("execution", execution)
.put("result", new JSONObject().put("finished", "success"))

View File

@@ -373,11 +373,11 @@ include::{snippets}/targets/delete-action-from-target/path-parameters.adoc[]
==== Request query parameter
include::{snippets}/targets/delete-actions-from-target-with-parameters/request-parameters.adoc[]
include::{snippets}/targets/delete-action-from-target-with-parameters/request-parameters.adoc[]
==== Request parameter example
include::{snippets}/targets/delete-actions-from-target-with-parameters/http-request.adoc[]
include::{snippets}/targets/delete-action-from-target-with-parameters/http-request.adoc[]
=== Response (Status 204)

View File

@@ -16,8 +16,6 @@ final class DdiApiModelProperties {
// Direct Device Integration API
static final String CONTROLLER_ID = "id of the controller";
static final String TARGET_TIME = "time on the target device";
static final String TARGET_STATUS = "target action status";
static final String TARGET_EXEC_STATUS = "status of the action execution";

View File

@@ -182,7 +182,6 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
parameterWithName("actionId").description(DdiApiModelProperties.ACTION_ID_CANCELED)),
requestFields(optionalRequestFieldWithPath("id").description(DdiApiModelProperties.ACTION_ID),
optionalRequestFieldWithPath("time").description(DdiApiModelProperties.TARGET_TIME),
requestFieldWithPath("status").description(DdiApiModelProperties.TARGET_STATUS),
requestFieldWithPath("status.execution")
.description(DdiApiModelProperties.TARGET_EXEC_STATUS).type("enum")
@@ -386,7 +385,6 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
parameterWithName("actionId").description(DdiApiModelProperties.ACTION_ID)),
requestFields(optionalRequestFieldWithPath("id").description(DdiApiModelProperties.ACTION_ID),
optionalRequestFieldWithPath("time").description(DdiApiModelProperties.TARGET_TIME),
requestFieldWithPath("status").description(DdiApiModelProperties.TARGET_STATUS),
requestFieldWithPath("status.execution")
.description(DdiApiModelProperties.TARGET_EXEC_STATUS).type("enum")

View File

@@ -308,13 +308,17 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
}
@Test
@Description("Handles the GET request of retrieving all targets within SP based by parameter. Required Permission: READ_TARGET.")
public void deleteActionsFromTargetWithParameters() throws Exception {
generateActionForTarget(targetId);
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetId + "/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "?force=true")).andExpect(status().isOk())
.andDo(MockMvcResultPrinter.print()).andDo(this.document.document(
@Description("Optionally force quits an active action, only active actions can be deleted. Required Permission: UPDATE_TARGET.")
public void deleteActionFromTargetWithParameters() throws Exception {
final Action action = generateActionForTarget(targetId, false);
deploymentManagement.cancelAction(action.getId());
mockMvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}?force=true", targetId, action.getId()))
.andExpect(status().isNoContent()).andDo(MockMvcResultPrinter.print())
.andDo(this.document.document(
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
parameterWithName("actionId").description(ApiModelPropertiesGeneric.ITEM_ID)),
requestParameters(parameterWithName("force").description(MgmtApiModelProperties.FORCE))));
}