Improve Target assign tag test - add check for real tags in management API (#1892)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -41,18 +41,18 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for {@link TargetTagManagement}.
|
* Test class for {@link TargetTagManagement}.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Feature("Component Tests - Repository")
|
@Feature("Component Tests - Repository")
|
||||||
@Story("Target Tag Management")
|
@Story("Target Tag Management")
|
||||||
class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||||
|
|
||||||
@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 specfied on calls for non existing entities by means " +
|
||||||
+ "of Optional not present.")
|
"of Optional not present.")
|
||||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class) })
|
||||||
void nonExistingEntityAccessReturnsNotPresent() {
|
void nonExistingEntityAccessReturnsNotPresent() {
|
||||||
assertThat(targetTagManagement.getByName(NOT_EXIST_ID)).isNotPresent();
|
assertThat(targetTagManagement.getByName(NOT_EXIST_ID)).isNotPresent();
|
||||||
@@ -60,24 +60,19 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verifies that management queries react as specfied on calls for non existing entities "
|
@Description("Verifies that management queries react as specfied on calls for non existing entities " +
|
||||||
+ " by means of throwing EntityNotFoundException.")
|
" by means of throwing EntityNotFoundException.")
|
||||||
@ExpectEvents({ @Expect(type = DistributionSetTagUpdatedEvent.class), @Expect(type = TargetTagUpdatedEvent.class) })
|
@ExpectEvents({ @Expect(type = DistributionSetTagUpdatedEvent.class), @Expect(type = TargetTagUpdatedEvent.class) })
|
||||||
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||||
verifyThrownExceptionBy(() -> targetTagManagement.delete(NOT_EXIST_ID), "TargetTag");
|
verifyThrownExceptionBy(() -> targetTagManagement.delete(NOT_EXIST_ID), "TargetTag");
|
||||||
|
verifyThrownExceptionBy(() -> targetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)), "TargetTag");
|
||||||
verifyThrownExceptionBy(() -> targetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)),
|
|
||||||
"TargetTag");
|
|
||||||
|
|
||||||
verifyThrownExceptionBy(() -> getTargetTags(NOT_EXIST_ID), "Target");
|
verifyThrownExceptionBy(() -> getTargetTags(NOT_EXIST_ID), "Target");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verify that a tag with with invalid properties cannot be created or updated")
|
@Description("Verify that a tag with with invalid properties cannot be created or updated")
|
||||||
void createAndUpdateTagWithInvalidFields() {
|
void createAndUpdateTagWithInvalidFields() {
|
||||||
final TargetTag tag = targetTagManagement
|
final TargetTag tag = targetTagManagement.create(entityFactory.tag().create().name("tag1").description("tagdesc1"));
|
||||||
.create(entityFactory.tag().create().name("tag1").description("tagdesc1"));
|
|
||||||
|
|
||||||
createAndUpdateTagWithInvalidDescription(tag);
|
createAndUpdateTagWithInvalidDescription(tag);
|
||||||
createAndUpdateTagWithInvalidColour(tag);
|
createAndUpdateTagWithInvalidColour(tag);
|
||||||
createAndUpdateTagWithInvalidName(tag);
|
createAndUpdateTagWithInvalidName(tag);
|
||||||
@@ -85,22 +80,18 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Step
|
@Step
|
||||||
private void createAndUpdateTagWithInvalidDescription(final Tag tag) {
|
private void createAndUpdateTagWithInvalidDescription(final Tag tag) {
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with too long description should not be created")
|
.as("tag with too long description should not be created")
|
||||||
.isThrownBy(() -> targetTagManagement.create(
|
.isThrownBy(() -> targetTagManagement.create(
|
||||||
entityFactory.tag().create().name("a").description(RandomStringUtils.randomAlphanumeric(513))));
|
entityFactory.tag().create().name("a").description(RandomStringUtils.randomAlphanumeric(513))));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with invalid description should not be created").isThrownBy(() -> targetTagManagement
|
.as("tag with invalid description should not be created").isThrownBy(() -> targetTagManagement
|
||||||
.create(entityFactory.tag().create().name("a").description(INVALID_TEXT_HTML)));
|
.create(entityFactory.tag().create().name("a").description(INVALID_TEXT_HTML)));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with too long description should not be updated")
|
.as("tag with too long description should not be updated")
|
||||||
.isThrownBy(() -> targetTagManagement.update(
|
.isThrownBy(() -> targetTagManagement.update(
|
||||||
entityFactory.tag().update(tag.getId())
|
entityFactory.tag().update(tag.getId())
|
||||||
.description(RandomStringUtils.randomAlphanumeric(513))));
|
.description(RandomStringUtils.randomAlphanumeric(513))));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with invalid description should not be updated")
|
.as("tag with invalid description should not be updated")
|
||||||
.isThrownBy(() -> targetTagManagement
|
.isThrownBy(() -> targetTagManagement
|
||||||
@@ -109,21 +100,17 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Step
|
@Step
|
||||||
private void createAndUpdateTagWithInvalidColour(final Tag tag) {
|
private void createAndUpdateTagWithInvalidColour(final Tag tag) {
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with too long colour should not be created")
|
.as("tag with too long colour should not be created")
|
||||||
.isThrownBy(() -> targetTagManagement.create(
|
.isThrownBy(() -> targetTagManagement.create(
|
||||||
entityFactory.tag().create().name("a").colour(RandomStringUtils.randomAlphanumeric(17))));
|
entityFactory.tag().create().name("a").colour(RandomStringUtils.randomAlphanumeric(17))));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with invalid colour should not be created").isThrownBy(() -> targetTagManagement
|
.as("tag with invalid colour should not be created").isThrownBy(() -> targetTagManagement
|
||||||
.create(entityFactory.tag().create().name("a").colour(INVALID_TEXT_HTML)));
|
.create(entityFactory.tag().create().name("a").colour(INVALID_TEXT_HTML)));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with too long colour should not be updated")
|
.as("tag with too long colour should not be updated")
|
||||||
.isThrownBy(() -> targetTagManagement.update(
|
.isThrownBy(() -> targetTagManagement.update(
|
||||||
entityFactory.tag().update(tag.getId()).colour(RandomStringUtils.randomAlphanumeric(17))));
|
entityFactory.tag().update(tag.getId()).colour(RandomStringUtils.randomAlphanumeric(17))));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with invalid colour should not be updated").isThrownBy(() -> targetTagManagement
|
.as("tag with invalid colour should not be updated").isThrownBy(() -> targetTagManagement
|
||||||
.update(entityFactory.tag().update(tag.getId()).colour(INVALID_TEXT_HTML)));
|
.update(entityFactory.tag().update(tag.getId()).colour(INVALID_TEXT_HTML)));
|
||||||
@@ -131,31 +118,25 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Step
|
@Step
|
||||||
private void createAndUpdateTagWithInvalidName(final Tag tag) {
|
private void createAndUpdateTagWithInvalidName(final Tag tag) {
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with too long name should not be created")
|
.as("tag with too long name should not be created")
|
||||||
.isThrownBy(() -> targetTagManagement
|
.isThrownBy(() -> targetTagManagement
|
||||||
.create(entityFactory.tag().create().name(RandomStringUtils.randomAlphanumeric(
|
.create(entityFactory.tag().create().name(RandomStringUtils.randomAlphanumeric(
|
||||||
NamedEntity.NAME_MAX_SIZE + 1))));
|
NamedEntity.NAME_MAX_SIZE + 1))));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with invalidname should not be created")
|
.as("tag with invalidname should not be created")
|
||||||
.isThrownBy(() -> targetTagManagement.create(entityFactory.tag().create().name(INVALID_TEXT_HTML)));
|
.isThrownBy(() -> targetTagManagement.create(entityFactory.tag().create().name(INVALID_TEXT_HTML)));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with too long name should not be updated")
|
.as("tag with too long name should not be updated")
|
||||||
.isThrownBy(() -> targetTagManagement
|
.isThrownBy(() -> targetTagManagement
|
||||||
.update(entityFactory.tag().update(tag.getId()).name(RandomStringUtils.randomAlphanumeric(
|
.update(entityFactory.tag().update(tag.getId()).name(RandomStringUtils.randomAlphanumeric(
|
||||||
NamedEntity.NAME_MAX_SIZE + 1))));
|
NamedEntity.NAME_MAX_SIZE + 1))));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class).as("tag with invalid name should not be updated")
|
assertThatExceptionOfType(ConstraintViolationException.class).as("tag with invalid name should not be updated")
|
||||||
.isThrownBy(() -> targetTagManagement
|
.isThrownBy(() -> targetTagManagement
|
||||||
.update(entityFactory.tag().update(tag.getId()).name(INVALID_TEXT_HTML)));
|
.update(entityFactory.tag().update(tag.getId()).name(INVALID_TEXT_HTML)));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("tag with too short name should not be updated")
|
.as("tag with too short name should not be updated")
|
||||||
.isThrownBy(() -> targetTagManagement.update(entityFactory.tag().update(tag.getId()).name("")));
|
.isThrownBy(() -> targetTagManagement.update(entityFactory.tag().update(tag.getId()).name("")));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -165,27 +146,31 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final List<Target> groupA = testdataFactory.createTargets(20);
|
final List<Target> groupA = testdataFactory.createTargets(20);
|
||||||
final List<Target> groupB = testdataFactory.createTargets(20, "groupb", "groupb");
|
final List<Target> groupB = testdataFactory.createTargets(20, "groupb", "groupb");
|
||||||
|
|
||||||
final TargetTag tag = targetTagManagement
|
final TargetTag tag = targetTagManagement.create(entityFactory.tag().create().name("tag1").description("tagdesc1"));
|
||||||
.create(entityFactory.tag().create().name("tag1").description("tagdesc1"));
|
|
||||||
|
|
||||||
// toggle A only -> A is now assigned
|
// toggle A only -> A is now assigned
|
||||||
List<Target> result = assignTag(groupA, tag);
|
List<Target> result = assignTag(groupA, tag);
|
||||||
assertThat(result).size().isEqualTo(20);
|
assertThat(result).size().isEqualTo(20);
|
||||||
assertThat(result).containsAll(targetManagement
|
assertThat(result).containsAll(
|
||||||
.getByControllerID(groupA.stream().map(Target::getControllerId).collect(Collectors.toList())));
|
targetManagement.getByControllerID(groupA.stream().map(Target::getControllerId).collect(Collectors.toList())));
|
||||||
|
assertThat(targetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent().stream().map(Target::getControllerId).sorted().toList())
|
||||||
|
.isEqualTo(groupA.stream().map(Target::getControllerId).sorted().toList());
|
||||||
|
|
||||||
// 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);
|
final Collection<Target> groupAB = concat(groupA, groupB);
|
||||||
|
result = assignTag(groupAB, tag);
|
||||||
assertThat(result).size().isEqualTo(40);
|
assertThat(result).size().isEqualTo(40);
|
||||||
assertThat(result).containsAll(targetManagement.getByControllerID(
|
assertThat(result).containsAll(
|
||||||
concat(groupB, groupA).stream().map(Target::getControllerId).collect(Collectors.toList())));
|
targetManagement.getByControllerID(groupAB.stream().map(Target::getControllerId).collect(Collectors.toList())));
|
||||||
|
assertThat(targetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent().stream().map(Target::getControllerId).sorted().toList())
|
||||||
|
.isEqualTo(groupAB.stream().map(Target::getControllerId).sorted().toList());
|
||||||
|
|
||||||
// toggle A+B -> both unassigned
|
// toggle A+B -> both unassigned
|
||||||
result = unassignTag(concat(groupA, groupB), tag);
|
result = unassignTag(groupAB, tag);
|
||||||
assertThat(result).size().isEqualTo(40);
|
assertThat(result).size().isEqualTo(40);
|
||||||
assertThat(result).containsAll(targetManagement.getByControllerID(
|
assertThat(result).containsAll(
|
||||||
concat(groupB, groupA).stream().map(Target::getControllerId).collect(Collectors.toList())));
|
targetManagement.getByControllerID(groupAB.stream().map(Target::getControllerId).collect(Collectors.toList())));
|
||||||
|
assertThat(targetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
|
|||||||
Reference in New Issue
Block a user