Add new endpoint for single action (#1316)

* Add new endpoint for single action
* Adding the new endpoint to the documentation
+ reverse the representation mode to FULL

Signed-off-by: Stanislav Trailov <stanislav.trailov@bosch.io>
This commit is contained in:
Stanislav Trailov
2023-02-06 14:13:58 +02:00
committed by GitHub
parent a64c2bc28e
commit 64bc0417b1
5 changed files with 137 additions and 12 deletions

View File

@@ -65,6 +65,44 @@ include::../errors/406.adoc[]
include::../errors/429.adoc[]
|===
== GET /rest/v1/actions/{actionId}
=== Implementation notes
Handles the GET request of retrieving a single action within Hawkbit by actionId.
=== Get single action
==== CURL
include::{snippets}/actions/get-action/curl-request.adoc[]
==== Request URL
A `GET` request is used to access a single action
include::{snippets}/actions/get-action/http-request.adoc[]
=== Response (Status 200)
==== Response fields
include::{snippets}/actions/get-action/response-fields.adoc[]
==== Response example
include::{snippets}/actions/get-action/http-response.adoc[]
|===
| HTTP Status Code | Reason | Response Model
include::../errors/400.adoc[]
include::../errors/401.adoc[]
include::../errors/404.adoc[]
include::../errors/406.adoc[]
include::../errors/429.adoc[]
|===
== Additional content
[[error-body]]

View File

@@ -11,8 +11,7 @@ package org.eclipse.hawkbit.rest.mgmt.documentation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.restdocs.request.RequestDocumentation.*;
import static org.springframework.restdocs.snippet.Attributes.key;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -103,6 +102,47 @@ public class ActionResourceDocumentationTest extends AbstractApiRestDocumentatio
parameterWithName("representation").description(MgmtApiModelProperties.REPRESENTATION_MODE))));
}
@Test
@Description("Handles the GET request of retrieving a specific action.")
public void getAction() throws Exception {
final Action action = generateRolloutActionForTarget(targetId);
provideCodeFeedback(action, 200);
assertThat(deploymentManagement.findAction(action.getId()).get().getActionType())
.isEqualTo(Action.ActionType.FORCED);
mockMvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "/{actionId}", action.getId()))
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
.andDo(this.document.document(
pathParameters(parameterWithName("actionId").description(ApiModelPropertiesGeneric.ITEM_ID)),
responseFields(fieldWithPath("createdBy").description(ApiModelPropertiesGeneric.CREATED_BY),
fieldWithPath("createdAt").description(ApiModelPropertiesGeneric.CREATED_AT),
fieldWithPath("id").description(MgmtApiModelProperties.ACTION_ID),
fieldWithPath("lastModifiedBy").description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY)
.type("String"),
fieldWithPath("lastModifiedAt").description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT)
.type("String"),
fieldWithPath("type").description(MgmtApiModelProperties.ACTION_TYPE)
.attributes(key("value").value("['update', 'cancel']")),
fieldWithPath("forceType").description(MgmtApiModelProperties.ACTION_FORCE_TYPE)
.attributes(key("value").value("['forced', 'soft', 'timeforced']")),
fieldWithPath("status").description(MgmtApiModelProperties.ACTION_EXECUTION_STATUS)
.attributes(key("value").value("['finished', 'pending']")),
fieldWithPath("detailStatus").description(MgmtApiModelProperties.ACTION_DETAIL_STATUS)
.attributes(key("value").value(
"['finished', 'error', 'running', 'warning', 'scheduled', 'canceling', 'canceled', 'download', 'downloaded', 'retrieved', 'cancel_rejected']")),
optionalRequestFieldWithPath("lastStatusCode")
.description(MgmtApiModelProperties.ACTION_LAST_STATUS_CODE).type("Integer"),
fieldWithPath("rollout").description(MgmtApiModelProperties.ACTION_ROLLOUT),
fieldWithPath("rolloutName").description(MgmtApiModelProperties.ACTION_ROLLOUT_NAME),
fieldWithPath("_links.self").ignored(),
fieldWithPath("_links.distributionset").description(MgmtApiModelProperties.LINK_TO_DS),
fieldWithPath("_links.status")
.description(MgmtApiModelProperties.LINKS_ACTION_STATUSES),
fieldWithPath("_links.rollout").description(MgmtApiModelProperties.LINK_TO_ROLLOUT),
fieldWithPath("_links.target").description(MgmtApiModelProperties.LINK_TO_TARGET))));
}
private Action generateRolloutActionForTarget(final String knownControllerId) throws Exception {
return generateActionForTarget(knownControllerId, true, false, null, null, null, true);
}