Management REST API: Allow to filter actions by last status code (#1311)

* Introduce sorting /filtering field for "lastActionStatusCode"

* Rename new sort /filter field to "lastStatusCode"
This commit is contained in:
Stefan Behl
2023-01-13 12:12:51 +01:00
committed by GitHub
parent 9d929e014b
commit b919ceda5c
2 changed files with 38 additions and 0 deletions

View File

@@ -26,6 +26,11 @@ public enum ActionFields implements FieldNameProvider, FieldValueConverter<Actio
* The detailed action status
*/
DETAILSTATUS("status"),
/**
* The last action status code
*/
LASTSTATUSCODE("lastActionStatusCode"),
/**
* The id field.

View File

@@ -30,7 +30,9 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtActionRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
@@ -118,6 +120,37 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
}
@Test
@Description("Verifies that actions can be filtered based on the action status code that was reported last.")
void filterActionsByLastStatusCode() throws Exception {
// assign a distribution set to three targets
final DistributionSet dsA = testdataFactory.createDistributionSet("");
final DistributionSetAssignmentResult assignmentResult = assignDistributionSet(dsA,
testdataFactory.createTargets("target1", "target2", "target3"));
final List<Action> actions = assignmentResult.getAssignedEntity();
assertThat(actions).hasSize(3);
// then simulate a status update with code 200 for the first action
final Action action = actions.get(0);
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).code(200)
.message("Update succeeded").status(Status.FINISHED));
// verify that one result is returned if the actions are filtered for
// status code 200
final String rsqlStatusCode = "lastStatusCode==200";
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlStatusCode))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1))).andExpect(jsonPath("content[0].status", equalTo("finished")));
// verify no result is returned if we filter for a non-existing status
// code
final String rsqlWrongStatusCode = "lastStatusCode==999";
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlWrongStatusCode))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(0)))
.andExpect(jsonPath("size", equalTo(0)));
}
@Test
@Description("Verifies that actions can be filtered based on distribution set fields.")
void filterActionsByDistributionSet() throws Exception {