add option to filter actions using _externalref_ property Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -64,7 +64,13 @@ public enum ActionFields implements FieldNameProvider, FieldValueConverter<Actio
|
||||
/**
|
||||
* The rollout field
|
||||
*/
|
||||
ROLLOUTGROUP("rolloutGroup", RolloutGroupFields.ID.getFieldName(), RolloutGroupFields.NAME.getFieldName());
|
||||
ROLLOUTGROUP("rolloutGroup", RolloutGroupFields.ID.getFieldName(), RolloutGroupFields.NAME.getFieldName()),
|
||||
|
||||
|
||||
/**
|
||||
* The weight field.
|
||||
*/
|
||||
EXTERNALREF("externalRef");
|
||||
|
||||
private static final String ACTIVE = "pending";
|
||||
private static final String INACTIVE = "finished";
|
||||
@@ -119,5 +125,4 @@ public enum ActionFields implements FieldNameProvider, FieldValueConverter<Actio
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,11 @@ public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
|
||||
newAction.setTarget(target);
|
||||
newAction.setWeight(45);
|
||||
newAction.setInitiatedBy(tenantAware.getCurrentUsername());
|
||||
if ((i % 2) == 0) {
|
||||
newAction.setExternalRef("extRef");
|
||||
} else {
|
||||
newAction.setExternalRef("extRef2");
|
||||
}
|
||||
actionRepository.save(newAction);
|
||||
target.addAction(newAction);
|
||||
}
|
||||
@@ -100,6 +105,14 @@ public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
|
||||
fail("Missing expected RSQLParameterUnsupportedFieldException because status cannot be compared with 'true'");
|
||||
} catch (final RSQLParameterUnsupportedFieldException e) {
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
@Description("Test action by status")
|
||||
public void testFilterByParameterExtRef() {
|
||||
assertRSQLQuery(ActionFields.EXTERNALREF.name() + "==extRef", 5);
|
||||
assertRSQLQuery(ActionFields.EXTERNALREF.name() + "!=extRef", 6);
|
||||
assertRSQLQuery(ActionFields.EXTERNALREF.name() + "==extRef*", 10);
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
@@ -128,6 +128,48 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies that actions can be filtered based on extRef.")
|
||||
void filterActionsByExternalRef() throws Exception {
|
||||
// prepare test
|
||||
final String knownTargetId = "targetId";
|
||||
final List<Action> actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId);
|
||||
|
||||
final Action action0 = actions.get(0);
|
||||
final Action action1 = actions.get(1);
|
||||
|
||||
final List<String> externalRefs = new ArrayList<>(2);
|
||||
externalRefs.add("extRef");
|
||||
externalRefs.add("extRef#123_1");
|
||||
controllerManagement.updateActionExternalRef(action0.getId(), externalRefs.get(0));
|
||||
controllerManagement.updateActionExternalRef(action1.getId(), externalRefs.get(1));
|
||||
|
||||
final String rsqlExtRef = "externalref==extRef";
|
||||
final String rsqlExtRefWildcard = "externalref==extRef*";
|
||||
final String rsqlExtRefNoMatch = "externalref==234extRef";
|
||||
|
||||
// pending status one result
|
||||
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlExtRef))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("total", equalTo(1)))
|
||||
.andExpect(jsonPath("size", equalTo(1)))
|
||||
.andExpect(jsonPath("content[0].externalRef", equalTo(externalRefs.get(0))));
|
||||
|
||||
// finished status none result
|
||||
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlExtRefWildcard))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("total", equalTo(2)))
|
||||
.andExpect(jsonPath("size", equalTo(2)));
|
||||
|
||||
// pending or finished status one result
|
||||
mvc.perform(get(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING + "?q=" + rsqlExtRefNoMatch))
|
||||
.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 the action status code that was reported last.")
|
||||
void filterActionsByLastStatusCode() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user