Fix sonar findings: DistributionSetTagManagementTest (#1985)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -193,7 +193,6 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
|
|||||||
sb.delete(sb.length() - 2, sb.length());
|
sb.delete(sb.length() - 2, sb.length());
|
||||||
throw new LockedException(JpaSoftwareModule.class, getId(), "DELETE", sb.toString());
|
throw new LockedException(JpaSoftwareModule.class, getId(), "DELETE", sb.toString());
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
this.deleted = deleted;
|
this.deleted = deleted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import io.qameta.allure.Step;
|
|||||||
import io.qameta.allure.Story;
|
import io.qameta.allure.Story;
|
||||||
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
||||||
import org.eclipse.hawkbit.repository.builder.TagCreate;
|
import org.eclipse.hawkbit.repository.builder.TagCreate;
|
||||||
|
import org.eclipse.hawkbit.repository.builder.TagUpdate;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent;
|
||||||
@@ -48,25 +49,25 @@ import org.springframework.data.domain.Pageable;
|
|||||||
*/
|
*/
|
||||||
@Feature("Component Tests - Repository")
|
@Feature("Component Tests - Repository")
|
||||||
@Story("DistributionSet Tag Management")
|
@Story("DistributionSet Tag Management")
|
||||||
public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||||
|
|
||||||
private static final Random RND = new Random();
|
private static final Random RND = new Random();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means "
|
@Description("Verifies that management get access reacts as specified on calls for non existing entities by means of Optional not present.")
|
||||||
+ "of Optional not present.")
|
|
||||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
|
||||||
public void nonExistingEntityAccessReturnsNotPresent() {
|
void nonExistingEntityAccessReturnsNotPresent() {
|
||||||
assertThat(distributionSetTagManagement.getByName(NOT_EXIST_ID)).isNotPresent();
|
assertThat(distributionSetTagManagement.getByName(NOT_EXIST_ID)).isNotPresent();
|
||||||
assertThat(distributionSetTagManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
assertThat(distributionSetTagManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verifies that management queries react as specfied on calls for non existing entities "
|
@Description("Verifies that management queries react as specified on calls for non existing entities by means of throwing " +
|
||||||
+ " by means of throwing EntityNotFoundException.")
|
"EntityNotFoundException.")
|
||||||
@ExpectEvents({ @Expect(type = DistributionSetTagUpdatedEvent.class, count = 0),
|
@ExpectEvents({
|
||||||
|
@Expect(type = DistributionSetTagUpdatedEvent.class, count = 0),
|
||||||
@Expect(type = TargetTagUpdatedEvent.class, count = 0) })
|
@Expect(type = TargetTagUpdatedEvent.class, count = 0) })
|
||||||
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_ID), "DistributionSetTag");
|
verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_ID), "DistributionSetTag");
|
||||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.findByDistributionSet(PAGE, NOT_EXIST_IDL),
|
verifyThrownExceptionBy(() -> distributionSetTagManagement.findByDistributionSet(PAGE, NOT_EXIST_IDL),
|
||||||
"DistributionSet");
|
"DistributionSet");
|
||||||
@@ -76,7 +77,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Full DS tag lifecycle tested. Create tags, assign them to sets and delete the tags.")
|
@Description("Full DS tag lifecycle tested. Create tags, assign them to sets and delete the tags.")
|
||||||
public void createAndAssignAndDeleteDistributionSetTags() {
|
void createAndAssignAndDeleteDistributionSetTags() {
|
||||||
final Collection<DistributionSet> dsAs = testdataFactory.createDistributionSets("DS-A", 20);
|
final Collection<DistributionSet> dsAs = testdataFactory.createDistributionSets("DS-A", 20);
|
||||||
final Collection<DistributionSet> dsBs = testdataFactory.createDistributionSets("DS-B", 10);
|
final Collection<DistributionSet> dsBs = testdataFactory.createDistributionSets("DS-B", 10);
|
||||||
final Collection<DistributionSet> dsCs = testdataFactory.createDistributionSets("DS-C", 25);
|
final Collection<DistributionSet> dsCs = testdataFactory.createDistributionSets("DS-C", 25);
|
||||||
@@ -138,7 +139,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verifies assign/unassign.")
|
@Description("Verifies assign/unassign.")
|
||||||
public void assignAndUnassignDistributionSetTags() {
|
void assignAndUnassignDistributionSetTags() {
|
||||||
final Collection<DistributionSet> groupA = testdataFactory.createDistributionSets(20);
|
final Collection<DistributionSet> groupA = testdataFactory.createDistributionSets(20);
|
||||||
final Collection<DistributionSet> groupB = testdataFactory.createDistributionSets("unassigned", 20);
|
final Collection<DistributionSet> groupB = testdataFactory.createDistributionSets("unassigned", 20);
|
||||||
|
|
||||||
@@ -148,10 +149,11 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
// toggle A only -> A is now assigned
|
// toggle A only -> A is now assigned
|
||||||
List<DistributionSet> result = assignTag(groupA, tag);
|
List<DistributionSet> result = assignTag(groupA, tag);
|
||||||
assertThat(result).size().isEqualTo(20);
|
assertThat(result).size().isEqualTo(20);
|
||||||
assertThat(result).containsAll(distributionSetManagement
|
assertThat(result).containsAll(distributionSetManagement.get(groupA.stream().map(DistributionSet::getId).toList()));
|
||||||
.get(groupA.stream().map(DistributionSet::getId).collect(Collectors.toList())));
|
|
||||||
assertThat(
|
assertThat(
|
||||||
distributionSetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent().stream().map(DistributionSet::getId).sorted()
|
distributionSetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent().stream()
|
||||||
|
.map(DistributionSet::getId)
|
||||||
|
.sorted()
|
||||||
.toList())
|
.toList())
|
||||||
.isEqualTo(groupA.stream().map(DistributionSet::getId).sorted().toList());
|
.isEqualTo(groupA.stream().map(DistributionSet::getId).sorted().toList());
|
||||||
|
|
||||||
@@ -160,7 +162,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
result = assignTag(groupAB, tag);
|
result = assignTag(groupAB, tag);
|
||||||
assertThat(result).size().isEqualTo(40);
|
assertThat(result).size().isEqualTo(40);
|
||||||
assertThat(result).containsAll(distributionSetManagement
|
assertThat(result).containsAll(distributionSetManagement
|
||||||
.get(groupAB.stream().map(DistributionSet::getId).collect(Collectors.toList())));
|
.get(groupAB.stream().map(DistributionSet::getId).toList()));
|
||||||
assertThat(
|
assertThat(
|
||||||
distributionSetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent().stream().map(DistributionSet::getId).sorted()
|
distributionSetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent().stream().map(DistributionSet::getId).sorted()
|
||||||
.toList())
|
.toList())
|
||||||
@@ -169,19 +171,15 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
// toggle A+B -> both unassigned
|
// toggle A+B -> both unassigned
|
||||||
result = unassignTag(concat(groupA, groupB), tag);
|
result = unassignTag(concat(groupA, groupB), tag);
|
||||||
assertThat(result).size().isEqualTo(40);
|
assertThat(result).size().isEqualTo(40);
|
||||||
assertThat(result).containsAll(distributionSetManagement
|
assertThat(result).containsAll(distributionSetManagement.get(concat(groupB, groupA).stream().map(DistributionSet::getId).toList()));
|
||||||
.get(concat(groupB, groupA).stream().map(DistributionSet::getId).collect(Collectors.toList())));
|
|
||||||
assertThat(distributionSetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent()).isEmpty();
|
assertThat(distributionSetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verifies that tagging of set containing missing DS throws meaningful and correct exception.")
|
@Description("Verifies that tagging of set containing missing DS throws meaningful and correct exception.")
|
||||||
public void failOnMissingDs() {
|
void failOnMissingDs() {
|
||||||
final Collection<Long> group = testdataFactory.createDistributionSets(5).stream()
|
final Collection<Long> group = testdataFactory.createDistributionSets(5).stream().map(DistributionSet::getId).toList();
|
||||||
.map(DistributionSet::getId)
|
final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name("tag1").description("tagdesc1"));
|
||||||
.collect(Collectors.toList());
|
|
||||||
final DistributionSetTag tag = distributionSetTagManagement
|
|
||||||
.create(entityFactory.tag().create().name("tag1").description("tagdesc1"));
|
|
||||||
final List<Long> missing = new ArrayList<>();
|
final List<Long> missing = new ArrayList<>();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -196,12 +194,10 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
final Collection<Long> withMissing = concat(group, missing);
|
final Collection<Long> withMissing = concat(group, missing);
|
||||||
assertThatThrownBy(() -> distributionSetManagement.assignTag(withMissing, tag.getId()))
|
assertThatThrownBy(() -> distributionSetManagement.assignTag(withMissing, tag.getId()))
|
||||||
.matches(e -> {
|
.matches(e -> {
|
||||||
if (e instanceof EntityNotFoundException enfe) {
|
if (e instanceof EntityNotFoundException enfe &&
|
||||||
if (enfe.getInfo().get(EntityNotFoundException.TYPE).equals(DistributionSet.class.getSimpleName())) {
|
enfe.getInfo().get(EntityNotFoundException.TYPE).equals(DistributionSet.class.getSimpleName()) &&
|
||||||
if (enfe.getInfo().get(EntityNotFoundException.ENTITY_ID) instanceof Collection entityId) {
|
enfe.getInfo().get(EntityNotFoundException.ENTITY_ID) instanceof Collection<?> entityId) {
|
||||||
return entityId.stream().sorted().toList().equals(missing);
|
return entityId.stream().sorted().toList().equals(missing);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@@ -209,7 +205,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensures that a created tag is persisted in the repository as defined.")
|
@Description("Ensures that a created tag is persisted in the repository as defined.")
|
||||||
public void createDistributionSetTag() {
|
void createDistributionSetTag() {
|
||||||
final Tag tag = distributionSetTagManagement
|
final Tag tag = distributionSetTagManagement
|
||||||
.create(entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
|
.create(entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
|
||||||
|
|
||||||
@@ -223,7 +219,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensures that a deleted tag is removed from the repository as defined.")
|
@Description("Ensures that a deleted tag is removed from the repository as defined.")
|
||||||
public void deleteDistributionSetTag() {
|
void deleteDistributionSetTag() {
|
||||||
// create test data
|
// create test data
|
||||||
final Iterable<DistributionSetTag> tags = createDsSetsWithTags();
|
final Iterable<DistributionSetTag> tags = createDsSetsWithTags();
|
||||||
final DistributionSetTag toDelete = tags.iterator().next();
|
final DistributionSetTag toDelete = tags.iterator().next();
|
||||||
@@ -250,7 +246,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
|
@Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).")
|
||||||
public void failedDuplicateDsTagNameException() {
|
void failedDuplicateDsTagNameException() {
|
||||||
final TagCreate tag = entityFactory.tag().create().name("A");
|
final TagCreate tag = entityFactory.tag().create().name("A");
|
||||||
distributionSetTagManagement.create(tag);
|
distributionSetTagManagement.create(tag);
|
||||||
|
|
||||||
@@ -260,18 +256,18 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
|
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
|
||||||
public void failedDuplicateDsTagNameExceptionAfterUpdate() {
|
void failedDuplicateDsTagNameExceptionAfterUpdate() {
|
||||||
distributionSetTagManagement.create(entityFactory.tag().create().name("A"));
|
distributionSetTagManagement.create(entityFactory.tag().create().name("A"));
|
||||||
final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name("B"));
|
final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name("B"));
|
||||||
|
|
||||||
|
final TagUpdate tagUpdate = entityFactory.tag().update(tag.getId()).name("A");
|
||||||
assertThatExceptionOfType(EntityAlreadyExistsException.class).as("should not have worked as tag already exists")
|
assertThatExceptionOfType(EntityAlreadyExistsException.class).as("should not have worked as tag already exists")
|
||||||
.isThrownBy(
|
.isThrownBy(() -> distributionSetTagManagement.update(tagUpdate));
|
||||||
() -> distributionSetTagManagement.update(entityFactory.tag().update(tag.getId()).name("A")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Tests the name update of a target tag.")
|
@Description("Tests the name update of a target tag.")
|
||||||
public void updateDistributionSetTag() {
|
void updateDistributionSetTag() {
|
||||||
// create test data
|
// create test data
|
||||||
final List<DistributionSetTag> tags = createDsSetsWithTags();
|
final List<DistributionSetTag> tags = createDsSetsWithTags();
|
||||||
// change data
|
// change data
|
||||||
@@ -287,7 +283,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensures that all tags are retrieved through repository.")
|
@Description("Ensures that all tags are retrieved through repository.")
|
||||||
public void findDistributionSetTagsAll() {
|
void findDistributionSetTagsAll() {
|
||||||
final List<DistributionSetTag> tags = createDsSetsWithTags();
|
final List<DistributionSetTag> tags = createDsSetsWithTags();
|
||||||
|
|
||||||
// test
|
// test
|
||||||
@@ -298,7 +294,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Ensures that a created tags are persisted in the repository as defined.")
|
@Description("Ensures that a created tags are persisted in the repository as defined.")
|
||||||
public void createDistributionSetTags() {
|
void createDistributionSetTags() {
|
||||||
final List<DistributionSetTag> tags = createDsSetsWithTags();
|
final List<DistributionSetTag> tags = createDsSetsWithTags();
|
||||||
assertThat(distributionSetTagRepository.findAll()).as("Wrong size of tags created").hasSize(tags.size());
|
assertThat(distributionSetTagRepository.findAll()).as("Wrong size of tags created").hasSize(tags.size());
|
||||||
}
|
}
|
||||||
@@ -308,9 +304,9 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
final Stream<Collection<DistributionSet>> expectedFilteredDistributionSets) {
|
final Stream<Collection<DistributionSet>> expectedFilteredDistributionSets) {
|
||||||
final Collection<Long> retrievedFilteredDsIds = distributionSetManagement
|
final Collection<Long> retrievedFilteredDsIds = distributionSetManagement
|
||||||
.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).stream()
|
.findByDistributionSetFilter(PAGE, distributionSetFilterBuilder.build()).stream()
|
||||||
.map(DistributionSet::getId).collect(Collectors.toList());
|
.map(DistributionSet::getId).toList();
|
||||||
final Collection<Long> expectedFilteredDsIds = expectedFilteredDistributionSets.flatMap(Collection::stream)
|
final Collection<Long> expectedFilteredDsIds = expectedFilteredDistributionSets.flatMap(Collection::stream)
|
||||||
.map(DistributionSet::getId).collect(Collectors.toList());
|
.map(DistributionSet::getId).toList();
|
||||||
assertThat(retrievedFilteredDsIds).hasSameElementsAs(expectedFilteredDsIds);
|
assertThat(retrievedFilteredDsIds).hasSameElementsAs(expectedFilteredDsIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verifies that tagging of set containing missing DS throws meaningful and correct exception.")
|
@Description("Verifies that tagging of set containing missing DS throws meaningful and correct exception.")
|
||||||
public void failOnMissingDs() {
|
void failOnMissingDs() {
|
||||||
final Collection<String> group = testdataFactory.createTargets(5).stream()
|
final Collection<String> group = testdataFactory.createTargets(5).stream()
|
||||||
.map(Target::getControllerId)
|
.map(Target::getControllerId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
Reference in New Issue
Block a user