Sonar Fixes (#2229)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-24 10:08:31 +02:00
committed by GitHub
parent 99e545b75f
commit e6c8215d05
10 changed files with 133 additions and 110 deletions

View File

@@ -22,10 +22,11 @@ import jakarta.persistence.criteria.SetJoin;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaNamedEntity_;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaNamedVersionedEntity_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.springframework.data.jpa.domain.Specification;
@@ -84,7 +85,7 @@ public final class DistributionSetSpecification {
*/
public static Specification<JpaDistributionSet> byIdFetch(final Long distid) {
return (dsRoot, query, cb) -> {
final Predicate predicate = cb.equal(dsRoot.get(JpaDistributionSet_.id), distid);
final Predicate predicate = cb.equal(dsRoot.get(AbstractJpaBaseEntity_.id), distid);
dsRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT);
dsRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT);
query.distinct(true);
@@ -101,7 +102,7 @@ public final class DistributionSetSpecification {
*/
public static Specification<JpaDistributionSet> byIdsFetch(final Collection<Long> distids) {
return (dsRoot, query, cb) -> {
final Predicate predicate = dsRoot.get(JpaDistributionSet_.id).in(distids);
final Predicate predicate = dsRoot.get(AbstractJpaBaseEntity_.id).in(distids);
dsRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT);
dsRoot.fetch(JpaDistributionSet_.tags, JoinType.LEFT);
dsRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT);
@@ -119,8 +120,8 @@ public final class DistributionSetSpecification {
*/
public static Specification<JpaDistributionSet> likeNameAndVersion(final String name, final String version) {
return (dsRoot, query, cb) -> cb.and(
cb.like(cb.lower(dsRoot.get(JpaDistributionSet_.name)), name.toLowerCase()),
cb.like(cb.lower(dsRoot.get(JpaDistributionSet_.version)), version.toLowerCase()));
cb.like(cb.lower(dsRoot.get(AbstractJpaNamedEntity_.name)), name.toLowerCase()),
cb.like(cb.lower(dsRoot.get(AbstractJpaNamedVersionedEntity_.version)), version.toLowerCase()));
}
/**
@@ -147,8 +148,8 @@ public final class DistributionSetSpecification {
*/
public static Specification<JpaDistributionSet> equalsNameAndVersionIgnoreCase(final String name, final String version) {
return (dsRoot, query, cb) -> cb.and(
cb.equal(cb.lower(dsRoot.get(JpaDistributionSet_.name)), name.toLowerCase()),
cb.equal(cb.lower(dsRoot.get(JpaDistributionSet_.version)), version.toLowerCase()));
cb.equal(cb.lower(dsRoot.get(AbstractJpaNamedEntity_.name)), name.toLowerCase()),
cb.equal(cb.lower(dsRoot.get(AbstractJpaNamedVersionedEntity_.version)), version.toLowerCase()));
}
/**
@@ -158,7 +159,7 @@ public final class DistributionSetSpecification {
* @return the {@link DistributionSet} {@link Specification}
*/
public static Specification<JpaDistributionSet> byType(final Long typeId) {
return (dsRoot, query, cb) -> cb.equal(dsRoot.get(JpaDistributionSet_.type).get(JpaDistributionSetType_.id), typeId);
return (dsRoot, query, cb) -> cb.equal(dsRoot.get(JpaDistributionSet_.type).get(AbstractJpaBaseEntity_.id), typeId);
}
/**
@@ -168,7 +169,7 @@ public final class DistributionSetSpecification {
* @return the {@link DistributionSet} {@link Specification}
*/
public static Specification<JpaDistributionSet> hasType(final Collection<Long> typeIds) {
return (dsRoot, query, cb) -> dsRoot.get(JpaDistributionSet_.type).get(JpaDistributionSetType_.id).in(typeIds);
return (dsRoot, query, cb) -> dsRoot.get(JpaDistributionSet_.type).get(AbstractJpaBaseEntity_.id).in(typeIds);
}
/**
@@ -180,7 +181,7 @@ public final class DistributionSetSpecification {
public static Specification<JpaDistributionSet> hasTag(final Long tagId) {
return (dsRoot, query, cb) -> {
final SetJoin<JpaDistributionSet, JpaDistributionSetTag> tags = dsRoot.join(JpaDistributionSet_.tags, JoinType.LEFT);
return cb.equal(tags.get(JpaDistributionSetTag_.id), tagId);
return cb.equal(tags.get(AbstractJpaBaseEntity_.id), tagId);
};
}
@@ -188,7 +189,7 @@ public final class DistributionSetSpecification {
final Root<JpaDistributionSet> dsRoot, final CriteriaBuilder cb,
final Boolean selectDSWithNoTag, final Collection<String> tagNames) {
final SetJoin<JpaDistributionSet, JpaDistributionSetTag> tags = dsRoot.join(JpaDistributionSet_.tags, JoinType.LEFT);
final Path<String> exp = tags.get(JpaDistributionSetTag_.name);
final Path<String> exp = tags.get(AbstractJpaNamedEntity_.name);
final List<Predicate> hasTagsPredicates = new ArrayList<>();
if (isNoTagActive(selectDSWithNoTag)) {

View File

@@ -11,21 +11,19 @@ package org.eclipse.hawkbit.repository.jpa.specifications;
import jakarta.validation.constraints.NotEmpty;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaNamedEntity_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag_;
import org.springframework.data.jpa.domain.Specification;
/**
* Utility class for {@link JpaDistributionSetTag}s {@link Specification}s. The class provides
* Spring Data JPQL Specifications.
* Utility class for {@link JpaDistributionSetTag}s {@link Specification}s. The class provides Spring Data JPQL Specifications.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DistributionSetTagSpecifications {
private DistributionSetTagSpecifications() {
// utility class
}
public static Specification<JpaDistributionSetTag> byName(@NotEmpty final String name) {
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaDistributionSetTag_.name), name);
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(AbstractJpaNamedEntity_.name), name);
}
}
}

View File

@@ -147,8 +147,9 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
// toggle A only -> A is now assigned
List<DistributionSet> result = assignTag(groupA, tag);
assertThat(result).size().isEqualTo(20);
assertThat(result).containsAll(distributionSetManagement.get(groupA.stream().map(DistributionSet::getId).toList()));
assertThat(result)
.hasSize(20)
.containsAll(distributionSetManagement.get(groupA.stream().map(DistributionSet::getId).toList()));
assertThat(
distributionSetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent().stream()
.map(DistributionSet::getId)
@@ -159,18 +160,19 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
final Collection<DistributionSet> groupAB = concat(groupA, groupB);
// toggle A+B -> A is still assigned and B is assigned as well
result = assignTag(groupAB, tag);
assertThat(result).size().isEqualTo(40);
assertThat(result).containsAll(distributionSetManagement
.get(groupAB.stream().map(DistributionSet::getId).toList()));
assertThat(result)
.hasSize(40)
.containsAll(distributionSetManagement.get(groupAB.stream().map(DistributionSet::getId).toList()));
assertThat(
distributionSetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent().stream().map(DistributionSet::getId).sorted()
.toList())
distributionSetManagement.findByTag(
tag.getId(), Pageable.unpaged()).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).toList()));
assertThat(result)
.hasSize(40)
.containsAll(distributionSetManagement.get(concat(groupB, groupA).stream().map(DistributionSet::getId).toList()));
assertThat(distributionSetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent()).isEmpty();
}

View File

@@ -26,6 +26,8 @@ import io.qameta.allure.Feature;
import io.qameta.allure.Step;
import io.qameta.allure.Story;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
import org.eclipse.hawkbit.repository.builder.DistributionSetUpdate;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTypeCreatedEvent;
@@ -145,33 +147,35 @@ class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
// assign all types at once
final DistributionSetType dsType1 = distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("dst1").name("dst1"));
final Long dsType1Id = dsType1.getId();
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
.isThrownBy(() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType1Id, moduleTypeIds));
assertThatExceptionOfType(AssignmentQuotaExceededException.class).isThrownBy(
() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType1.getId(), moduleTypeIds));
assertThatExceptionOfType(AssignmentQuotaExceededException.class).isThrownBy(
() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType1.getId(), moduleTypeIds));
() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType1Id, moduleTypeIds));
// assign as many mandatory modules as possible
final DistributionSetType dsType2 = distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("dst2").name("dst2"));
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2.getId(),
final Long dsType2Id = dsType2.getId();
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2Id,
moduleTypeIds.subList(0, quota));
assertThat(distributionSetTypeManagement.get(dsType2.getId())).isNotEmpty();
assertThat(distributionSetTypeManagement.get(dsType2.getId()).get().getMandatoryModuleTypes()).hasSize(quota);
assertThat(distributionSetTypeManagement.get(dsType2Id)).isNotEmpty();
assertThat(distributionSetTypeManagement.get(dsType2Id).get().getMandatoryModuleTypes()).hasSize(quota);
// assign one more to trigger the quota exceeded error
final List<Long> softwareModuleTypeIds = Collections.singletonList(moduleTypeIds.get(quota));
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
.isThrownBy(() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2.getId(),
Collections.singletonList(moduleTypeIds.get(quota))));
.isThrownBy(() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2Id, softwareModuleTypeIds));
// assign as many optional modules as possible
final DistributionSetType dsType3 = distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("dst3").name("dst3"));
distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3.getId(), moduleTypeIds.subList(0, quota));
assertThat(distributionSetTypeManagement.get(dsType3.getId())).isNotEmpty();
assertThat(distributionSetTypeManagement.get(dsType3.getId()).get().getOptionalModuleTypes()).hasSize(quota);
final Long dsType3Id = dsType3.getId();
distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3Id, moduleTypeIds.subList(0, quota));
assertThat(distributionSetTypeManagement.get(dsType3Id)).isNotEmpty();
assertThat(distributionSetTypeManagement.get(dsType3Id).get().getOptionalModuleTypes()).hasSize(quota);
// assign one more to trigger the quota exceeded error
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
.isThrownBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3.getId(),
Collections.singletonList(moduleTypeIds.get(quota))));
.isThrownBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3Id, softwareModuleTypeIds));
}
@@ -189,29 +193,29 @@ class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
}
@Test
@Description("Tests the unsuccessfull update of used distribution set type (module addition).")
@Description("Tests the unsuccessful update of used distribution set type (module addition).")
void addModuleToAssignedDistributionSetTypeFails() {
final DistributionSetType nonUpdatableType = createDistributionSetTypeUsedByDs();
final Long nonUpdatableTypeId = createDistributionSetTypeUsedByDs().getId();
final Set<Long> osTypeId = Set.of(osType.getId());
assertThatThrownBy(() -> distributionSetTypeManagement
.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(), Set.of(osType.getId())))
.assignMandatorySoftwareModuleTypes(nonUpdatableTypeId, osTypeId))
.isInstanceOf(EntityReadOnlyException.class);
}
@Test
@Description("Tests the unsuccessfull update of used distribution set type (module removal).")
@Description("Tests the unsuccessful update of used distribution set type (module removal).")
void removeModuleToAssignedDistributionSetTypeFails() {
DistributionSetType nonUpdatableType = distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
assertThat(distributionSetTypeManagement.findByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty();
nonUpdatableType = distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
Set.of(osType.getId()));
distributionSetManagement.create(entityFactory.distributionSet().create().name("newtypesoft").version("1")
.type(nonUpdatableType.getKey()));
final Long osTypeId = osType.getId();
nonUpdatableType = distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(), Set.of(osTypeId));
distributionSetManagement.create(
entityFactory.distributionSet().create().name("newtypesoft").version("1").type(nonUpdatableType.getKey()));
final Long typeId = nonUpdatableType.getId();
assertThatThrownBy(() -> distributionSetTypeManagement.unassignSoftwareModuleType(typeId, osType.getId()))
assertThatThrownBy(() -> distributionSetTypeManagement.unassignSoftwareModuleType(typeId, osTypeId))
.isInstanceOf(EntityReadOnlyException.class);
}
@@ -264,100 +268,116 @@ class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
@Step
private void createAndUpdateDistributionSetWithInvalidDescription(final DistributionSet set) {
final DistributionSetCreate distributionSetCreate = entityFactory.distributionSet().create()
.name("a").version("a").description(randomString(513));
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too long description should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
.version("a").description(randomString(513))));
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate));
final DistributionSetCreate distributionSetCreate2 = entityFactory.distributionSet().create()
.name("a").version("a").description(INVALID_TEXT_HTML);
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set invalid description text should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
.version("a").description(INVALID_TEXT_HTML)));
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate2));
final DistributionSetUpdate distributionSetUpdate = entityFactory.distributionSet().update(set.getId())
.description(randomString(513));
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too long description should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.description(randomString(513))));
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate));
final DistributionSetUpdate distributionSetUpdate2 = entityFactory.distributionSet().update(set.getId()).description(INVALID_TEXT_HTML);
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with invalid description should not be updated").isThrownBy(() -> distributionSetManagement
.update(entityFactory.distributionSet().update(set.getId()).description(INVALID_TEXT_HTML)));
.as("set with invalid description should not be updated")
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate2));
}
@Step
private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet set) {
assertThatExceptionOfType(ConstraintViolationException.class).as("set with too long name should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().version("a")
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class).as("set with invalid name should not be created")
.isThrownBy(() -> distributionSetManagement
.create(entityFactory.distributionSet().create().version("a").name(INVALID_TEXT_HTML)));
final DistributionSetCreate distributionSetCreate = entityFactory.distributionSet().create()
.version("a").name(randomString(NamedEntity.NAME_MAX_SIZE + 1));
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too short name should not be created").isThrownBy(() -> distributionSetManagement
.create(entityFactory.distributionSet().create().version("a").name("")));
assertThatExceptionOfType(ConstraintViolationException.class).as("set with null name should not be created")
.isThrownBy(() -> distributionSetManagement
.create(entityFactory.distributionSet().create().version("a").name(null)));
assertThatExceptionOfType(ConstraintViolationException.class).as("set with too long name should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1))));
assertThatExceptionOfType(ConstraintViolationException.class).as("set with invalid name should not be updated")
.isThrownBy(() -> distributionSetManagement
.update(entityFactory.distributionSet().update(set.getId()).name(INVALID_TEXT_HTML)));
.as("set with too long name should not be created")
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate));
final DistributionSetCreate distributionSetCreate2 = entityFactory.distributionSet().create().version("a").name(INVALID_TEXT_HTML);
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too short name should not be updated").isThrownBy(() -> distributionSetManagement
.update(entityFactory.distributionSet().update(set.getId()).name("")));
.as("set with invalid name should not be created")
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate2));
final DistributionSetCreate distributionSetCreate3 = entityFactory.distributionSet().create().version("a").name("");
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too short name should not be created")
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate3));
final DistributionSetCreate distributionSetCreate4 = entityFactory.distributionSet().create().version("a").name(null);
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with null name should not be created")
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate4));
final DistributionSetUpdate distributionSetUpdate = entityFactory.distributionSet().update(set.getId())
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1));
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too long name should not be updated")
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate));
final DistributionSetUpdate distributionSetUpdate2 = entityFactory.distributionSet().update(set.getId()).name(INVALID_TEXT_HTML);
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with invalid name should not be updated")
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate2));
final DistributionSetUpdate distributionSetUpdate3 = entityFactory.distributionSet().update(set.getId()).name("");
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too short name should not be updated")
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate3));
}
@Step
private void createAndUpdateDistributionSetWithInvalidVersion(final DistributionSet set) {
final DistributionSetCreate distributionSetCreate = entityFactory.distributionSet().create()
.name("a").version(randomString(NamedVersionedEntity.VERSION_MAX_SIZE + 1));
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too long version should not be created")
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
.version(randomString(NamedVersionedEntity.VERSION_MAX_SIZE + 1))));
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate));
final DistributionSetCreate distributionSetCreate2 = entityFactory.distributionSet().create().name("a").version(INVALID_TEXT_HTML);
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with invalid version should not be created").isThrownBy(() -> distributionSetManagement
.create(entityFactory.distributionSet().create().name("a").version(INVALID_TEXT_HTML)));
.as("set with invalid version should not be created")
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate2));
final DistributionSetCreate distributionSetCreate3 = entityFactory.distributionSet().create().name("a").version("");
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too short version should not be created").isThrownBy(() -> distributionSetManagement
.create(entityFactory.distributionSet().create().name("a").version("")));
.as("set with too short version should not be created")
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate3));
assertThatExceptionOfType(ConstraintViolationException.class).as("set with null version should not be created")
.isThrownBy(() -> distributionSetManagement
.create(entityFactory.distributionSet().create().name("a").version(null)));
final DistributionSetCreate distributionSetCreate4 = entityFactory.distributionSet().create().name("a").version(null);
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with null version should not be created")
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate4));
final DistributionSetUpdate distributionSetUpdate = entityFactory.distributionSet().update(set.getId())
.version(randomString(NamedVersionedEntity.VERSION_MAX_SIZE + 1));
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too long version should not be updated")
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.version(randomString(NamedVersionedEntity.VERSION_MAX_SIZE + 1))));
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate));
final DistributionSetUpdate distributionSetUpdate2 = entityFactory.distributionSet().update(set.getId()).version(INVALID_TEXT_HTML);
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with invalid version should not be updated").isThrownBy(() -> distributionSetManagement
.update(entityFactory.distributionSet().update(set.getId()).version(INVALID_TEXT_HTML)));
.as("set with invalid version should not be updated")
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate2));
final DistributionSetUpdate distributionSetUpdate3 = entityFactory.distributionSet().update(set.getId()).version("");
assertThatExceptionOfType(ConstraintViolationException.class)
.as("set with too short version should not be updated").isThrownBy(() -> distributionSetManagement
.update(entityFactory.distributionSet().update(set.getId()).version("")));
.as("set with too short version should not be updated")
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate3));
}
private DistributionSetType createDistributionSetTypeUsedByDs() {
final DistributionSetType nonUpdatableType = distributionSetTypeManagement.create(entityFactory
.distributionSetType().create().key("updatableType").name("to be deleted").colour("test123"));
final DistributionSetType nonUpdatableType = distributionSetTypeManagement.create(
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted").colour("test123"));
assertThat(distributionSetTypeManagement.findByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty();
distributionSetManagement.create(entityFactory.distributionSet().create().name("newtypesoft").version("1")
.type(nonUpdatableType.getKey()));
distributionSetManagement.create(entityFactory.distributionSet().create()
.name("newtypesoft").version("1").type(nonUpdatableType.getKey()));
return nonUpdatableType;
}
}