Fixed wrong status content generation in mgmt API.
Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -297,8 +297,8 @@ final public class TargetMapper {
|
|||||||
final ActionStatusRest result = new ActionStatusRest();
|
final ActionStatusRest result = new ActionStatusRest();
|
||||||
|
|
||||||
result.setMessages(actionStatus.getMessages());
|
result.setMessages(actionStatus.getMessages());
|
||||||
result.setReportedAt(action.getCreatedAt());
|
result.setReportedAt(actionStatus.getCreatedAt());
|
||||||
result.setStatusId(action.getId());
|
result.setStatusId(actionStatus.getId());
|
||||||
result.setType(getNameOfActionStatusType(actionStatus.getStatus()));
|
result.setType(getNameOfActionStatusType(actionStatus.getStatus()));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.rest.resource;
|
|||||||
import static org.fest.assertions.api.Assertions.assertThat;
|
import static org.fest.assertions.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
|
import static org.hamcrest.Matchers.hasItem;
|
||||||
import static org.hamcrest.Matchers.hasKey;
|
import static org.hamcrest.Matchers.hasKey;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
@@ -229,7 +230,7 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void cancelActionOK() throws Exception {
|
public void cancelActionOK() throws Exception {
|
||||||
// prepare test
|
// prepare test
|
||||||
Target tA = createTargetAndStartAction();
|
final Target tA = createTargetAndStartAction();
|
||||||
|
|
||||||
// test - cancel the active action
|
// test - cancel the active action
|
||||||
mvc.perform(delete(RestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}",
|
mvc.perform(delete(RestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}",
|
||||||
@@ -252,7 +253,7 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void cancelAnCancelActionIsNotAllowed() throws Exception {
|
public void cancelAnCancelActionIsNotAllowed() throws Exception {
|
||||||
// prepare test
|
// prepare test
|
||||||
Target tA = createTargetAndStartAction();
|
final Target tA = createTargetAndStartAction();
|
||||||
|
|
||||||
// cancel the active action
|
// cancel the active action
|
||||||
deploymentManagement.cancelAction(tA.getActions().get(0), tA);
|
deploymentManagement.cancelAction(tA.getActions().get(0), tA);
|
||||||
@@ -272,7 +273,7 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
|||||||
@Description("Force Quit an Action, which is already canceled. Expected Result is an HTTP response code 204.")
|
@Description("Force Quit an Action, which is already canceled. Expected Result is an HTTP response code 204.")
|
||||||
public void forceQuitAnCanceledActionReturnsOk() throws Exception {
|
public void forceQuitAnCanceledActionReturnsOk() throws Exception {
|
||||||
|
|
||||||
Target tA = createTargetAndStartAction();
|
final Target tA = createTargetAndStartAction();
|
||||||
|
|
||||||
// cancel the active action
|
// cancel the active action
|
||||||
deploymentManagement.cancelAction(tA.getActions().get(0), tA);
|
deploymentManagement.cancelAction(tA.getActions().get(0), tA);
|
||||||
@@ -293,7 +294,7 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
|||||||
@Description("Force Quit an Action, which is not canceled. Expected Result is an HTTP response code 405.")
|
@Description("Force Quit an Action, which is not canceled. Expected Result is an HTTP response code 405.")
|
||||||
public void forceQuitAnNotCanceledActionReturnsMethodNotAllowed() throws Exception {
|
public void forceQuitAnNotCanceledActionReturnsMethodNotAllowed() throws Exception {
|
||||||
|
|
||||||
Target tA = createTargetAndStartAction();
|
final Target tA = createTargetAndStartAction();
|
||||||
|
|
||||||
// test - cancel an cancel action returns forbidden
|
// test - cancel an cancel action returns forbidden
|
||||||
mvc.perform(delete(RestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}?force=true",
|
mvc.perform(delete(RestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}?force=true",
|
||||||
@@ -851,6 +852,72 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
|||||||
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(2)));
|
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Description("Verfies that the API returns the status list with expected content.")
|
||||||
|
public void getMultipleActionStatus() throws Exception {
|
||||||
|
final String knownTargetId = "targetId";
|
||||||
|
final List<Action> actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId);
|
||||||
|
|
||||||
|
mvc.perform(get(
|
||||||
|
RestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + RestConstants.TARGET_V1_ACTIONS
|
||||||
|
+ "/" + actions.get(0).getId() + "/" + RestConstants.TARGET_V1_ACTION_STATUS))
|
||||||
|
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||||
|
.andExpect(
|
||||||
|
jsonPath("content.[0].id", equalTo(actions.get(0).getActionStatus().get(1).getId().intValue())))
|
||||||
|
.andExpect(jsonPath("content.[0].type", equalTo("canceling")))
|
||||||
|
.andExpect(jsonPath("content.[0].messages", hasItem("manual cancelation requested")))
|
||||||
|
.andExpect(jsonPath("content.[0].reportedAt",
|
||||||
|
equalTo(actions.get(0).getActionStatus().get(1).getCreatedAt())))
|
||||||
|
.andExpect(
|
||||||
|
jsonPath("content.[1].id", equalTo(actions.get(0).getActionStatus().get(0).getId().intValue())))
|
||||||
|
.andExpect(jsonPath("content.[1].type", equalTo("running")))
|
||||||
|
.andExpect(jsonPath("content.[1].reportedAt",
|
||||||
|
equalTo(actions.get(0).getActionStatus().get(0).getCreatedAt())))
|
||||||
|
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
|
||||||
|
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(2)))
|
||||||
|
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Description("Verfies that the API resturns the status list with expected content split into two pages.")
|
||||||
|
public void getMultipleActionStatusWithPagingLimitRequestParameter() throws Exception {
|
||||||
|
final String knownTargetId = "targetId";
|
||||||
|
|
||||||
|
final List<Action> actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId);
|
||||||
|
|
||||||
|
// Page 1
|
||||||
|
mvc.perform(get(
|
||||||
|
RestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + RestConstants.TARGET_V1_ACTIONS
|
||||||
|
+ "/" + actions.get(0).getId() + "/" + RestConstants.TARGET_V1_ACTION_STATUS)
|
||||||
|
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(1)))
|
||||||
|
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||||
|
.andExpect(
|
||||||
|
jsonPath("content.[0].id", equalTo(actions.get(0).getActionStatus().get(1).getId().intValue())))
|
||||||
|
.andExpect(jsonPath("content.[0].type", equalTo("canceling")))
|
||||||
|
.andExpect(jsonPath("content.[0].messages", hasItem("manual cancelation requested")))
|
||||||
|
.andExpect(jsonPath("content.[0].reportedAt",
|
||||||
|
equalTo(actions.get(0).getActionStatus().get(1).getCreatedAt())))
|
||||||
|
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
|
||||||
|
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(1)))
|
||||||
|
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(1)));
|
||||||
|
|
||||||
|
// Page 2
|
||||||
|
mvc.perform(get(
|
||||||
|
RestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + RestConstants.TARGET_V1_ACTIONS
|
||||||
|
+ "/" + actions.get(0).getId() + "/" + RestConstants.TARGET_V1_ACTION_STATUS)
|
||||||
|
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(1))
|
||||||
|
.param(RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(1)))
|
||||||
|
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||||
|
.andExpect(
|
||||||
|
jsonPath("content.[0].id", equalTo(actions.get(0).getActionStatus().get(0).getId().intValue())))
|
||||||
|
.andExpect(jsonPath("content.[0].type", equalTo("running")))
|
||||||
|
.andExpect(jsonPath("content.[0].reportedAt",
|
||||||
|
equalTo(actions.get(0).getActionStatus().get(0).getCreatedAt())))
|
||||||
|
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
|
||||||
|
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(1)))
|
||||||
|
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(1)));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMultipleActionsWithPagingLimitRequestParameter() throws Exception {
|
public void getMultipleActionsWithPagingLimitRequestParameter() throws Exception {
|
||||||
final String knownTargetId = "targetId";
|
final String knownTargetId = "targetId";
|
||||||
@@ -874,6 +941,7 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
|||||||
mvc.perform(get(
|
mvc.perform(get(
|
||||||
RestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + RestConstants.TARGET_V1_ACTIONS)
|
RestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + RestConstants.TARGET_V1_ACTIONS)
|
||||||
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(1))
|
.param(RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(1))
|
||||||
|
.param(RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(1))
|
||||||
.param(RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(1)))
|
.param(RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(1)))
|
||||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("content.[0].id", equalTo(actions.get(1).getId().intValue())))
|
.andExpect(jsonPath("content.[0].id", equalTo(actions.get(1).getId().intValue())))
|
||||||
@@ -1232,7 +1300,8 @@ public class TargetResourceTest extends AbstractIntegrationTest {
|
|||||||
// prepare test
|
// prepare test
|
||||||
final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement,
|
||||||
distributionSetManagement);
|
distributionSetManagement);
|
||||||
Target tA = targetManagement.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
final Target tA = targetManagement
|
||||||
|
.createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description"));
|
||||||
// assign a distribution set so we get an active update action
|
// assign a distribution set so we get an active update action
|
||||||
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(tA));
|
deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(tA));
|
||||||
// verify active action
|
// verify active action
|
||||||
|
|||||||
Reference in New Issue
Block a user