Remove deprecated toggle ds tag assigment from where possible (#1888)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-10-17 10:21:11 +03:00
committed by GitHub
parent 26fa649f6e
commit 897c49602c
8 changed files with 60 additions and 79 deletions

View File

@@ -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<DistributionSet> sets,
protected List<DistributionSet> assignTag(final Collection<DistributionSet> 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<DistributionSet> unassignTag(final Collection<DistributionSet> sets,
final DistributionSetTag tag) {
return distributionSetManagement.unassignTag(
sets.stream().map(DistributionSet::getId).collect(Collectors.toList()), tag.getId());
}
protected TargetTypeAssignmentResult initiateTypeAssignment(final Collection<Target> targets, final TargetType type) {

View File

@@ -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

View File

@@ -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);

View File

@@ -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<DistributionSet> allDistributionSets = Stream

View File

@@ -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<DistributionSet> 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<DistributionSet> sets = testdataFactory.createDistributionSets(20);
final Iterable<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(20);
tags.forEach(tag -> toggleTagAssignment(sets, tag));
tags.forEach(tag -> assignTag(sets, tag));
return distributionSetTagManagement.findAll(PAGE).getContent();
}

View File

@@ -400,15 +400,10 @@ public class TestdataFactory {
*
* @return {@link DistributionSet} entity.
*/
public DistributionSet createDistributionSet(final String prefix, final String version,
final Collection<DistributionSetTag> tags) {
public DistributionSet createDistributionSet(final String prefix, final String version, final Collection<DistributionSetTag> 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();
}
/**