Remove target tag to target reference (#1772)

* Remove target tag to target reference

it is not used and could lead to extensive memory usage if JPA provider load targets while loading tags

Also, remove search field controller id as not meaningful

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>

* Fix review findings

---------

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-07-19 13:56:30 +03:00
committed by GitHub
parent 119d1b5c50
commit c1de86b29e
11 changed files with 98 additions and 252 deletions

View File

@@ -53,8 +53,7 @@ import io.qameta.allure.Story;
@Story("Target Tag Resource")
public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationTest {
private static final String TARGETTAGS_ROOT = "http://localhost" + MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING
+ "/";
private static final String TARGETTAGS_ROOT = "http://localhost" + MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/";
@Test
@Description("Verfies that a paged result list of target tags reflects the content on the repository side.")
@@ -86,49 +85,9 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print());
}
@Test
@Description("Verifies that a paged result list of target tags reflects on the content of assigned tags for specific controller/target ID")
public void getTargetTagsByTargetId() throws Exception {
final String controllerId1 = "controllerTestId1";
final String controllerId2 = "controllerTestId2";
testdataFactory.createTarget(controllerId1);
testdataFactory.createTarget(controllerId2);
final List<TargetTag> tags = testdataFactory.createTargetTags(2, "");
final TargetTag tag1 = tags.get(0);
final TargetTag tag2 = tags.get(1);
targetManagement.toggleTagAssignment(List.of(controllerId1, controllerId2), tag1.getName());
targetManagement.toggleTagAssignment(List.of(controllerId2), tag2.getName());
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
.queryParam(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "target.controllerId==" + controllerId2)
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyTagMatcherOnPagedResult(tag1))
.andExpect(applyTagMatcherOnPagedResult(tag2))
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, TARGETTAGS_ROOT + tag1.getId()))
.andExpect(applySelfLinkMatcherOnPagedResult(tag2, TARGETTAGS_ROOT + tag2.getId()))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(2)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(2)));
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
.queryParam(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "target.controllerId==" + controllerId1)
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyTagMatcherOnPagedResult(tag1))
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, TARGETTAGS_ROOT + tag1.getId()))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(1)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(1)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(1)));
}
@Test
@Description("Verifies that a page result when listing tags reflects on the content in the repository when filtered by 2 fields - one tag field and one target field")
public void getTargetTagsFilteredByColorAndTargetId() throws Exception {
public void getTargetTagsFilteredByColor() throws Exception {
final String controllerId1 = "controllerTestId1";
final String controllerId2 = "controllerTestId2";
testdataFactory.createTarget(controllerId1);
@@ -139,21 +98,22 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
final TargetTag tag2 = tags.get(1);
targetManagement.toggleTagAssignment(List.of(controllerId1, controllerId2), tag1.getName());
targetManagement.toggleTagAssignment(List.of(controllerId2), tag2.getName());
targetManagement.toggleTagAssignment(List.of(controllerId2), tag2.getName())
;
// pass here q directly as a pure string because .queryParam method delimiters the parameters in q with ,
// which is logical OR, we want AND here
mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING +
"?" + MgmtRestConstants.REQUEST_PARAMETER_SEARCH + "=target.controllerId==" + controllerId2 + ";colour==" + tag1.getColour())
"?" + MgmtRestConstants.REQUEST_PARAMETER_SEARCH + "=colour==" + tag2.getColour())
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(applyTagMatcherOnPagedResult(tag1))
.andExpect(applySelfLinkMatcherOnPagedResult(tag1, TARGETTAGS_ROOT + tag1.getId()))
.andExpect(applyTagMatcherOnPagedResult(tag2))
.andExpect(applySelfLinkMatcherOnPagedResult(tag2, TARGETTAGS_ROOT + tag2.getId()))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(1)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(1)))
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(1)));
}
@Test
@Description("Verfies that a single result of a target tag reflects the content on the repository side.")
@ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 2) })