diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java index e2fb94a49..d70a62860 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java @@ -164,10 +164,15 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest targets.stream().map(Target::getControllerId).collect(Collectors.toList()), tag.getId()); } - public DistributionSetTagAssignmentResult toggleTagAssignment(final Collection sets, + protected List assignTag(final Collection sets, final DistributionSetTag tag) { - return distributionSetManagement.toggleTagAssignment( - sets.stream().map(DistributionSet::getId).collect(Collectors.toList()), tag.getName()); + return distributionSetManagement.assignTag( + sets.stream().map(DistributionSet::getId).collect(Collectors.toList()), tag.getId()); + } + protected List unassignTag(final Collection sets, + final DistributionSetTag tag) { + return distributionSetManagement.unassignTag( + sets.stream().map(DistributionSet::getId).collect(Collectors.toList()), tag.getId()); } protected TargetTypeAssignmentResult initiateTypeAssignment(final Collection targets, final TargetType type) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/DistributionSetAccessControllerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/DistributionSetAccessControllerTest.java index 456c25843..d56099373 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/DistributionSetAccessControllerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/DistributionSetAccessControllerTest.java @@ -210,22 +210,23 @@ class DistributionSetAccessControllerTest extends AbstractAccessControllerTest { assertThat(distributionSetManagement.findByRsqlAndTag(Pageable.unpaged(), "id==*", dsTag.getId()).get() .map(Identifiable::getId).toList()).containsOnly(permitted.getId(), readOnly.getId()); - // verify distributionSetManagement#toggleTagAssignment on permitted target + // verify distributionSetManagement#unassignTag on permitted target assertThat(distributionSetManagement - .toggleTagAssignment(Collections.singletonList(permitted.getId()), dsTag.getName()).getUnassigned()) + .unassignTag(Collections.singletonList(permitted.getId()), dsTag.getId())) + .size() .isEqualTo(1); // verify distributionSetManagement#assignTag on permitted target assertThat(distributionSetManagement.assignTag(Collections.singletonList(permitted.getId()), dsTag.getId())) .hasSize(1); // verify distributionSetManagement#unAssignTag on permitted target - assertThat(distributionSetManagement.unassignTag(permitted.getId(), dsTag.getId()).getId()) + assertThat(distributionSetManagement.unassignTag(List.of(permitted.getId()), dsTag.getId()) + .get(0).getId()) .isEqualTo(permitted.getId()); // assignment is denied for readOnlyTarget (read, but no update permissions) - assertThatThrownBy(() -> { - distributionSetManagement.toggleTagAssignment(Collections.singletonList(readOnly.getId()), dsTag.getName()) - .getUnassigned(); - }).as("Missing update permissions for target to toggle tag assignment.") + assertThatThrownBy(() -> + distributionSetManagement.unassignTag(Collections.singletonList(readOnly.getId()), dsTag.getId())) + .as("Missing update permissions for target to toggle tag assignment.") .isInstanceOf(InsufficientPermissionException.class); // assignment is denied for readOnlyTarget (read, but no update permissions) @@ -235,16 +236,13 @@ class DistributionSetAccessControllerTest extends AbstractAccessControllerTest { .isInstanceOf(InsufficientPermissionException.class); // assignment is denied for readOnlyTarget (read, but no update permissions) - assertThatThrownBy(() -> { - distributionSetManagement.unassignTag(readOnly.getId(), dsTag.getId()); - }).as("Missing update permissions for target to toggle tag assignment.") + assertThatThrownBy(() -> distributionSetManagement.unassignTag(List.of(readOnly.getId()), dsTag.getId())) + .as("Missing update permissions for target to toggle tag assignment.") .isInstanceOf(InsufficientPermissionException.class); // assignment is denied for hiddenTarget since it's hidden - assertThatThrownBy(() -> { - distributionSetManagement.toggleTagAssignment(Collections.singletonList(hidden.getId()), dsTag.getName()) - .getUnassigned(); - }).as("Missing update permissions for target to toggle tag assignment.") + assertThatThrownBy(() -> distributionSetManagement.unassignTag(Collections.singletonList(hidden.getId()), dsTag.getId())) + .as("Missing update permissions for target to toggle tag assignment.") .isInstanceOf(EntityNotFoundException.class); // assignment is denied for hiddenTarget since it's hidden diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/TargetAccessControllerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/TargetAccessControllerTest.java index 186f44f91..06d4ea4b0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/TargetAccessControllerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/TargetAccessControllerTest.java @@ -168,7 +168,7 @@ class TargetAccessControllerTest extends AbstractAccessControllerTest { // No exception has been thrown - because no real change is done // assertThatThrownBy(() -> { // targetManagement -// .toggleTagAssignment(List.of(readOnlyTarget.getControllerId()), myTag.getName()) +// .assignTag(List.of(readOnlyTarget.getControllerId()), myTag.getId()) // .getUnassigned(); // }).as("Missing update permissions for target to toggle tag assignment.") // .isInstanceOf(InsufficientPermissionException.class); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java index daa1b27d6..944b9b6dd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetManagementTest.java @@ -138,10 +138,10 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest { "DistributionSetTag"); verifyThrownExceptionBy( - () -> distributionSetManagement.toggleTagAssignment(singletonList(NOT_EXIST_IDL), dsTag.getName()), + () -> distributionSetManagement.assignTag(singletonList(NOT_EXIST_IDL), dsTag.getId()), "DistributionSet"); verifyThrownExceptionBy( - () -> distributionSetManagement.toggleTagAssignment(singletonList(set.getId()), NOT_EXIST_ID), + () -> distributionSetManagement.assignTag(singletonList(set.getId()), Long.parseLong(NOT_EXIST_ID)), "DistributionSetTag"); verifyThrownExceptionBy(() -> distributionSetManagement.unassignTag(set.getId(), NOT_EXIST_IDL), @@ -741,11 +741,11 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest { distributionSetManagement.delete(dsDeleted.getId()); dsDeleted = getOrThrow(distributionSetManagement.get(dsDeleted.getId())); - dsGroup1 = toggleTagAssignment(dsGroup1, dsTagA).getAssignedEntity(); + dsGroup1 = assignTag(dsGroup1, dsTagA); dsTagA = getOrThrow(distributionSetTagRepository.findByNameEquals(dsTagA.getName())); - dsGroup1 = toggleTagAssignment(dsGroup1, dsTagB).getAssignedEntity(); + dsGroup1 = assignTag(dsGroup1, dsTagB); dsTagA = getOrThrow(distributionSetTagRepository.findByNameEquals(dsTagA.getName())); - dsGroup2 = toggleTagAssignment(dsGroup2, dsTagA).getAssignedEntity(); + dsGroup2 = assignTag(dsGroup2, dsTagA); dsTagA = getOrThrow(distributionSetTagRepository.findByNameEquals(dsTagA.getName())); final List allDistributionSets = Stream diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTagManagementTest.java index d0056baaa..fa54f7f5e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTagManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTagManagementTest.java @@ -89,22 +89,22 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest final DistributionSetTag tagX = distributionSetTagManagement.create(entityFactory.tag().create().name("X")); final DistributionSetTag tagY = distributionSetTagManagement.create(entityFactory.tag().create().name("Y")); - toggleTagAssignment(dsAs, tagA); - toggleTagAssignment(dsBs, tagB); - toggleTagAssignment(dsCs, tagC); + assignTag(dsAs, tagA); + assignTag(dsBs, tagB); + assignTag(dsCs, tagC); - toggleTagAssignment(dsABs, distributionSetTagManagement.getByName(tagA.getName()).get()); - toggleTagAssignment(dsABs, distributionSetTagManagement.getByName(tagB.getName()).get()); + assignTag(dsABs, distributionSetTagManagement.getByName(tagA.getName()).get()); + assignTag(dsABs, distributionSetTagManagement.getByName(tagB.getName()).get()); - toggleTagAssignment(dsACs, distributionSetTagManagement.getByName(tagA.getName()).get()); - toggleTagAssignment(dsACs, distributionSetTagManagement.getByName(tagC.getName()).get()); + assignTag(dsACs, distributionSetTagManagement.getByName(tagA.getName()).get()); + assignTag(dsACs, distributionSetTagManagement.getByName(tagC.getName()).get()); - toggleTagAssignment(dsBCs, distributionSetTagManagement.getByName(tagB.getName()).get()); - toggleTagAssignment(dsBCs, distributionSetTagManagement.getByName(tagC.getName()).get()); + assignTag(dsBCs, distributionSetTagManagement.getByName(tagB.getName()).get()); + assignTag(dsBCs, distributionSetTagManagement.getByName(tagC.getName()).get()); - toggleTagAssignment(dsABCs, distributionSetTagManagement.getByName(tagA.getName()).get()); - toggleTagAssignment(dsABCs, distributionSetTagManagement.getByName(tagB.getName()).get()); - toggleTagAssignment(dsABCs, distributionSetTagManagement.getByName(tagC.getName()).get()); + assignTag(dsABCs, distributionSetTagManagement.getByName(tagA.getName()).get()); + assignTag(dsABCs, distributionSetTagManagement.getByName(tagB.getName()).get()); + assignTag(dsABCs, distributionSetTagManagement.getByName(tagC.getName()).get()); // search for not deleted final DistributionSetFilter.DistributionSetFilterBuilder distributionSetFilterBuilder = getDistributionSetFilterBuilder() @@ -156,35 +156,22 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest .create(entityFactory.tag().create().name("tag1").description("tagdesc1")); // toggle A only -> A is now assigned - DistributionSetTagAssignmentResult result = toggleTagAssignment(groupA, tag); - assertThat(result.getAlreadyAssigned()).isZero(); - assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement + List result = assignTag(groupA, tag); + assertThat(result).size().isEqualTo(20); + assertThat(result).containsAll(distributionSetManagement .get(groupA.stream().map(DistributionSet::getId).collect(Collectors.toList()))); - assertThat(result.getUnassigned()).isZero(); - assertThat(result.getUnassignedEntity()).isEmpty(); - assertThat(result.getDistributionSetTag()).isEqualTo(tag); // toggle A+B -> A is still assigned and B is assigned as well - result = toggleTagAssignment(concat(groupA, groupB), tag); - assertThat(result.getAlreadyAssigned()).isEqualTo(20); - assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement - .get(groupB.stream().map(DistributionSet::getId).collect(Collectors.toList()))); - assertThat(result.getUnassigned()).isZero(); - assertThat(result.getUnassignedEntity()).isEmpty(); - assertThat(result.getDistributionSetTag()).isEqualTo(tag); + result = assignTag(concat(groupA, groupB), tag); + assertThat(result).size().isEqualTo(40); + assertThat(result).containsAll(distributionSetManagement + .get(concat(groupA, groupB).stream().map(DistributionSet::getId).collect(Collectors.toList()))); // toggle A+B -> both unassigned - result = toggleTagAssignment(concat(groupA, groupB), tag); - assertThat(result.getAlreadyAssigned()).isZero(); - assertThat(result.getAssigned()).isZero(); - assertThat(result.getAssignedEntity()).isEmpty(); - assertThat(result.getUnassigned()).isEqualTo(40); - assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement + result = unassignTag(concat(groupA, groupB), tag); + assertThat(result).size().isEqualTo(40); + assertThat(result).containsAll(distributionSetManagement .get(concat(groupB, groupA).stream().map(DistributionSet::getId).collect(Collectors.toList()))); - assertThat(result.getDistributionSetTag()).isEqualTo(tag); - } @Test @@ -293,7 +280,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest final Collection sets = testdataFactory.createDistributionSets(20); final Iterable tags = testdataFactory.createDistributionSetTags(20); - tags.forEach(tag -> toggleTagAssignment(sets, tag)); + tags.forEach(tag -> assignTag(sets, tag)); return distributionSetTagManagement.findAll(PAGE).getContent(); } diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java index 9388166b8..07f519b45 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java @@ -400,15 +400,10 @@ public class TestdataFactory { * * @return {@link DistributionSet} entity. */ - public DistributionSet createDistributionSet(final String prefix, final String version, - final Collection tags) { - + public DistributionSet createDistributionSet(final String prefix, final String version, final Collection tags) { final DistributionSet set = createDistributionSet(prefix, version, false); - - tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(Arrays.asList(set.getId()), tag.getName())); - + tags.forEach(tag -> distributionSetManagement.assignTag(List.of(set.getId()), tag.getId())); return distributionSetManagement.get(set.getId()).get(); - } /** diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java index d83d27206..237bd3bf9 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java @@ -223,7 +223,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); final DistributionSetTagAssignmentResult assigmentResult = this.distributionSetManagement - .toggleTagAssignment(findDistributionSetIds(assignedDSRequestBodies), tag.getName()); + .assignTag(findDistributionSetIds(assignedDSRequestBodies), tag.getName()); final MgmtDistributionSetTagAssigmentResult tagAssigmentResultRest = new MgmtDistributionSetTagAssigmentResult(); tagAssigmentResultRest.setAssignedDistributionSets( diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java index 9aed80268..88d0263f3 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java @@ -95,8 +95,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt final DistributionSet distributionSet1 = testdataFactory.createDistributionSet(); final DistributionSet distributionSet2 = testdataFactory.createDistributionSet(); - distributionSetManagement.toggleTagAssignment(List.of(distributionSet1.getId(), distributionSet2.getId()), tag1.getName()); - distributionSetManagement.toggleTagAssignment(List.of(distributionSet1.getId()), tag2.getName()); + distributionSetManagement.assignTag(List.of(distributionSet1.getId(), distributionSet2.getId()), tag1.getId()); + distributionSetManagement.assignTag(List.of(distributionSet1.getId()), tag2.getId()); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING) .queryParam(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "distributionset.id==" + distributionSet1.getId()) @@ -132,8 +132,8 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt final DistributionSet distributionSet1 = testdataFactory.createDistributionSet(); final DistributionSet distributionSet2 = testdataFactory.createDistributionSet(); - distributionSetManagement.toggleTagAssignment(List.of(distributionSet1.getId(), distributionSet2.getId()), tag1.getName()); - distributionSetManagement.toggleTagAssignment(List.of(distributionSet1.getId()), tag2.getName()); + distributionSetManagement.assignTag(List.of(distributionSet1.getId(), distributionSet2.getId()), tag1.getId()); + distributionSetManagement.assignTag(List.of(distributionSet1.getId()), tag2.getId()); // 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 @@ -243,8 +243,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); final int setsAssigned = 5; final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); - distributionSetManagement.toggleTagAssignment(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), - tag.getName()); + distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId()); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -263,8 +262,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt final int setsAssigned = 5; final int limitSize = 1; final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); - distributionSetManagement.toggleTagAssignment(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), - tag.getName()); + distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId()); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize))) @@ -286,8 +284,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt final int expectedSize = setsAssigned - offsetParam; final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); - distributionSetManagement.toggleTagAssignment(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), - tag.getName()); + distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId()); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam)) @@ -380,8 +377,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt final DistributionSet assigned = sets.get(0); final DistributionSet unassigned = sets.get(1); - distributionSetManagement.toggleTagAssignment(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), - tag.getName()); + distributionSetManagement.assignTag(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), tag.getId()); mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" + unassigned.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());