From ab61b168bde5b3922850b07bad9ccc09adf12e9c Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Mon, 19 Feb 2024 17:23:56 +0200 Subject: [PATCH] [#1650] Expose externalRef via search filters (#1657) add option to filter actions using _externalref_ property Signed-off-by: Marinov Avgustin --- .../hawkbit/repository/ActionFields.java | 11 +++-- .../jpa/rsql/RSQLActionFieldsTest.java | 13 ++++++ .../rest/resource/MgmtActionResourceTest.java | 42 +++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java index 6cacbe1ea..6692be0aa 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/ActionFields.java @@ -64,7 +64,13 @@ public enum ActionFields implements FieldNameProvider, FieldValueConverter actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId); + + final Action action0 = actions.get(0); + final Action action1 = actions.get(1); + + final List 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 {