Improve DS assign tag test - add check for real tags in management API (#1891)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -97,9 +97,7 @@ import io.qameta.allure.Feature;
|
|||||||
import io.qameta.allure.Story;
|
import io.qameta.allure.Story;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class testing the functionality of triggering a deployment of
|
* Test class testing the functionality of triggering a deployment of {@link DistributionSet}s to {@link Target}s.
|
||||||
* {@link DistributionSet}s to {@link Target}s.
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Feature("Component Tests - Repository")
|
@Feature("Component Tests - Repository")
|
||||||
@Story("Deployment Management")
|
@Story("Deployment Management")
|
||||||
@@ -109,8 +107,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
private static final boolean STATE_INACTIVE = false;
|
private static final boolean STATE_INACTIVE = false;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verifies that management get access react as specified on calls for non existing entities by means "
|
@Description("Verifies that management get access react 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) })
|
||||||
void nonExistingEntityAccessReturnsNotPresent() {
|
void nonExistingEntityAccessReturnsNotPresent() {
|
||||||
assertThat(deploymentManagement.findAction(1234L)).isNotPresent();
|
assertThat(deploymentManagement.findAction(1234L)).isNotPresent();
|
||||||
@@ -118,8 +116,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verifies that management queries react as specified on calls for non existing entities "
|
@Description("Verifies that management queries react as specified on calls for non existing entities " +
|
||||||
+ " by means of throwing EntityNotFoundException.")
|
" by means of throwing EntityNotFoundException.")
|
||||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||||
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||||
final Target target = testdataFactory.createTarget();
|
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.")
|
@Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.")
|
||||||
void findActionWithLazyDetails() {
|
void findActionWithLazyDetails() {
|
||||||
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
|
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
|
||||||
new ArrayList<DistributionSetTag>());
|
new ArrayList<>());
|
||||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||||
// one action with one action status is generated
|
// one action with one action status is generated
|
||||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet(testDs, testTarget));
|
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.")
|
@Description("Test verifies that actions of a target are found by using id-based search.")
|
||||||
void findActionByTargetId() {
|
void findActionByTargetId() {
|
||||||
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
|
final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0",
|
||||||
new ArrayList<DistributionSetTag>());
|
new ArrayList<>());
|
||||||
final List<Target> testTarget = testdataFactory.createTargets(1);
|
final List<Target> testTarget = testdataFactory.createTargets(1);
|
||||||
// one action with one action status is generated
|
// one action with one action status is generated
|
||||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet(testDs, testTarget));
|
final Long actionId = getFirstAssignedActionId(assignDistributionSet(testDs, testTarget));
|
||||||
@@ -247,8 +245,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final String expectedMsg = actionStatusWithMessage.getMessages().get(0);
|
final String expectedMsg = actionStatusWithMessage.getMessages().get(0);
|
||||||
|
|
||||||
// act
|
// act
|
||||||
final Page<String> messages = deploymentManagement.findMessagesByActionStatusId(PAGE,
|
final Page<String> messages = deploymentManagement.findMessagesByActionStatusId(PAGE, actionStatusWithMessage.getId());
|
||||||
actionStatusWithMessage.getId());
|
|
||||||
|
|
||||||
assertThat(actionStates.getTotalElements()).as("Two action-states in total").isEqualTo(2L);
|
assertThat(actionStates.getTotalElements()).as("Two action-states in total").isEqualTo(2L);
|
||||||
assertThat(messages.getContent().get(0)).as("Message of action-status").isEqualTo(expectedMsg);
|
assertThat(messages.getContent().get(0)).as("Message of action-status").isEqualTo(expectedMsg);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetFilter;
|
|||||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult;
|
||||||
import org.eclipse.hawkbit.repository.model.Tag;
|
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.Expect;
|
||||||
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -39,10 +40,10 @@ import io.qameta.allure.Description;
|
|||||||
import io.qameta.allure.Feature;
|
import io.qameta.allure.Feature;
|
||||||
import io.qameta.allure.Step;
|
import io.qameta.allure.Step;
|
||||||
import io.qameta.allure.Story;
|
import io.qameta.allure.Story;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link DistributionSetTagManagement} tests.
|
* {@link DistributionSetTagManagement} tests.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Feature("Component Tests - Repository")
|
@Feature("Component Tests - Repository")
|
||||||
@Story("DistributionSet Tag Management")
|
@Story("DistributionSet Tag Management")
|
||||||
@@ -64,10 +65,8 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
@Expect(type = TargetTagUpdatedEvent.class, count = 0) })
|
@Expect(type = TargetTagUpdatedEvent.class, count = 0) })
|
||||||
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
public 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");
|
||||||
|
|
||||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)),
|
verifyThrownExceptionBy(() -> distributionSetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)),
|
||||||
"DistributionSetTag");
|
"DistributionSetTag");
|
||||||
}
|
}
|
||||||
@@ -160,18 +159,24 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
assertThat(result).size().isEqualTo(20);
|
assertThat(result).size().isEqualTo(20);
|
||||||
assertThat(result).containsAll(distributionSetManagement
|
assertThat(result).containsAll(distributionSetManagement
|
||||||
.get(groupA.stream().map(DistributionSet::getId).collect(Collectors.toList())));
|
.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<DistributionSet> groupAB = concat(groupA, groupB);
|
||||||
// toggle A+B -> A is still assigned and B is assigned as well
|
// 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).size().isEqualTo(40);
|
||||||
assertThat(result).containsAll(distributionSetManagement
|
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
|
// 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).collect(Collectors.toList())));
|
.get(concat(groupB, groupA).stream().map(DistributionSet::getId).collect(Collectors.toList())));
|
||||||
|
assertThat(distributionSetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -239,16 +244,12 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
@Test
|
@Test
|
||||||
@Description("Tests the name update of a target tag.")
|
@Description("Tests the name update of a target tag.")
|
||||||
public void updateDistributionSetTag() {
|
public void updateDistributionSetTag() {
|
||||||
|
|
||||||
// create test data
|
// create test data
|
||||||
final List<DistributionSetTag> tags = createDsSetsWithTags();
|
final List<DistributionSetTag> tags = createDsSetsWithTags();
|
||||||
|
|
||||||
// change data
|
// change data
|
||||||
final DistributionSetTag savedAssigned = tags.iterator().next();
|
final DistributionSetTag savedAssigned = tags.iterator().next();
|
||||||
|
|
||||||
// persist
|
// persist
|
||||||
distributionSetTagManagement.update(entityFactory.tag().update(savedAssigned.getId()).name("test123"));
|
distributionSetTagManagement.update(entityFactory.tag().update(savedAssigned.getId()).name("test123"));
|
||||||
|
|
||||||
// check data
|
// check data
|
||||||
assertThat(distributionSetTagManagement.findAll(PAGE).getContent()).as("Wrong size of ds tags")
|
assertThat(distributionSetTagManagement.findAll(PAGE).getContent()).as("Wrong size of ds tags")
|
||||||
.hasSize(tags.size());
|
.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.")
|
@Description("Ensures that a created tags are persisted in the repository as defined.")
|
||||||
public void createDistributionSetTags() {
|
public 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DistributionSetTag> createDsSetsWithTags() {
|
private List<DistributionSetTag> createDsSetsWithTags() {
|
||||||
|
|
||||||
final Collection<DistributionSet> sets = testdataFactory.createDistributionSets(20);
|
final Collection<DistributionSet> sets = testdataFactory.createDistributionSets(20);
|
||||||
final Iterable<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(20);
|
final Iterable<DistributionSetTag> tags = testdataFactory.createDistributionSetTags(20);
|
||||||
|
|
||||||
@@ -290,10 +289,9 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
private final <T> Collection<T> concat(final Collection<T>... targets) {
|
private <T> Collection<T> concat(final Collection<T>... targets) {
|
||||||
final List<T> result = new ArrayList<>();
|
final List<T> result = new ArrayList<>();
|
||||||
Arrays.asList(targets).forEach(result::addAll);
|
Arrays.asList(targets).forEach(result::addAll);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user