From c13bd052cfcea1194fe0a98b71e02570aa8eb2e1 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Thu, 17 Oct 2024 10:59:10 +0300 Subject: [PATCH] Improve DS assign tag test - add check for real tags in management API (#1891) Signed-off-by: Marinov Avgustin --- .../management/DeploymentManagementTest.java | 19 ++++++-------- .../DistributionSetTagManagementTest.java | 26 +++++++++---------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java index 473b1954a..366d436fa 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DeploymentManagementTest.java @@ -97,9 +97,7 @@ import io.qameta.allure.Feature; import io.qameta.allure.Story; /** - * Test class testing the functionality of triggering a deployment of - * {@link DistributionSet}s to {@link Target}s. - * + * Test class testing the functionality of triggering a deployment of {@link DistributionSet}s to {@link Target}s. */ @Feature("Component Tests - Repository") @Story("Deployment Management") @@ -109,8 +107,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { private static final boolean STATE_INACTIVE = false; @Test - @Description("Verifies that management get access react as specified on calls for non existing entities by means " - + "of Optional not present.") + @Description("Verifies that management get access react as specified on calls for non existing entities by means " + + "of Optional not present.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) void nonExistingEntityAccessReturnsNotPresent() { assertThat(deploymentManagement.findAction(1234L)).isNotPresent(); @@ -118,8 +116,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { } @Test - @Description("Verifies that management queries react as specified on calls for non existing entities " - + " by means of throwing EntityNotFoundException.") + @Description("Verifies that management queries react as specified on calls for non existing entities " + + " by means of throwing EntityNotFoundException.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) }) void entityQueriesReferringToNotExistingEntitiesThrowsException() { final Target target = testdataFactory.createTarget(); @@ -146,7 +144,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.") void findActionWithLazyDetails() { final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0", - new ArrayList()); + new ArrayList<>()); final List testTarget = testdataFactory.createTargets(1); // one action with one action status is generated final Long actionId = getFirstAssignedActionId(assignDistributionSet(testDs, testTarget)); @@ -163,7 +161,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Description("Test verifies that actions of a target are found by using id-based search.") void findActionByTargetId() { final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0", - new ArrayList()); + new ArrayList<>()); final List testTarget = testdataFactory.createTargets(1); // one action with one action status is generated final Long actionId = getFirstAssignedActionId(assignDistributionSet(testDs, testTarget)); @@ -247,8 +245,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest { final String expectedMsg = actionStatusWithMessage.getMessages().get(0); // act - final Page messages = deploymentManagement.findMessagesByActionStatusId(PAGE, - actionStatusWithMessage.getId()); + final Page messages = deploymentManagement.findMessagesByActionStatusId(PAGE, actionStatusWithMessage.getId()); assertThat(actionStates.getTotalElements()).as("Two action-states in total").isEqualTo(2L); assertThat(messages.getContent().get(0)).as("Message of action-status").isEqualTo(expectedMsg); 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 fa54f7f5e..bd4e6d189 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 @@ -31,6 +31,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetFilter; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Tag; +import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.test.matcher.Expect; import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents; import org.junit.jupiter.api.Test; @@ -39,10 +40,10 @@ import io.qameta.allure.Description; import io.qameta.allure.Feature; import io.qameta.allure.Step; import io.qameta.allure.Story; +import org.springframework.data.domain.Pageable; /** * {@link DistributionSetTagManagement} tests. - * */ @Feature("Component Tests - Repository") @Story("DistributionSet Tag Management") @@ -64,10 +65,8 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest @Expect(type = TargetTagUpdatedEvent.class, count = 0) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() { verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_ID), "DistributionSetTag"); - verifyThrownExceptionBy(() -> distributionSetTagManagement.findByDistributionSet(PAGE, NOT_EXIST_IDL), "DistributionSet"); - verifyThrownExceptionBy(() -> distributionSetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)), "DistributionSetTag"); } @@ -160,18 +159,24 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest assertThat(result).size().isEqualTo(20); assertThat(result).containsAll(distributionSetManagement .get(groupA.stream().map(DistributionSet::getId).collect(Collectors.toList()))); + assertThat(distributionSetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent().stream().map(DistributionSet::getId).sorted().toList()) + .isEqualTo(groupA.stream().map(DistributionSet::getId).sorted().toList()); + final Collection groupAB = concat(groupA, groupB); // toggle A+B -> A is still assigned and B is assigned as well - result = assignTag(concat(groupA, groupB), tag); + result = assignTag(groupAB, tag); assertThat(result).size().isEqualTo(40); assertThat(result).containsAll(distributionSetManagement - .get(concat(groupA, groupB).stream().map(DistributionSet::getId).collect(Collectors.toList()))); + .get(groupAB.stream().map(DistributionSet::getId).collect(Collectors.toList()))); + assertThat(distributionSetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent().stream().map(DistributionSet::getId).sorted().toList()) + .isEqualTo(groupAB.stream().map(DistributionSet::getId).sorted().toList()); // toggle A+B -> both unassigned 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(distributionSetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent()).isEmpty(); } @Test @@ -239,16 +244,12 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest @Test @Description("Tests the name update of a target tag.") public void updateDistributionSetTag() { - // create test data final List tags = createDsSetsWithTags(); - // change data final DistributionSetTag savedAssigned = tags.iterator().next(); - // persist distributionSetTagManagement.update(entityFactory.tag().update(savedAssigned.getId()).name("test123")); - // check data assertThat(distributionSetTagManagement.findAll(PAGE).getContent()).as("Wrong size of ds tags") .hasSize(tags.size()); @@ -271,12 +272,10 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest @Description("Ensures that a created tags are persisted in the repository as defined.") public void createDistributionSetTags() { final List tags = createDsSetsWithTags(); - assertThat(distributionSetTagRepository.findAll()).as("Wrong size of tags created").hasSize(tags.size()); } private List createDsSetsWithTags() { - final Collection sets = testdataFactory.createDistributionSets(20); final Iterable tags = testdataFactory.createDistributionSetTags(20); @@ -290,10 +289,9 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest } @SafeVarargs - private final Collection concat(final Collection... targets) { + private Collection concat(final Collection... targets) { final List result = new ArrayList<>(); Arrays.asList(targets).forEach(result::addAll); return result; } - -} +} \ No newline at end of file