diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/DelegatingAmqpErrorHandlerTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/DelegatingAmqpErrorHandlerTest.java index 6659718566..fada7a40a5 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/DelegatingAmqpErrorHandlerTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/DelegatingAmqpErrorHandlerTest.java @@ -11,7 +11,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import java.util.ArrayList; import java.util.List; import io.qameta.allure.Description; diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtResource.java index 3b70f75b03..119b4f8c00 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtResource.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtResource.java @@ -59,6 +59,7 @@ */ @Slf4j @RestController +@SuppressWarnings("java:S5738") // will be removed at some point public class DeprecatedMgmtResource implements DeprecatedMgmtRestApi { // logger that logs usage of deprecated API diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtRestApi.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtRestApi.java index 053877cded..1860c6ed16 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtRestApi.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DeprecatedMgmtRestApi.java @@ -44,6 +44,7 @@ @Deprecated(forRemoval = true, since = "0.6.0") @Tag(name = "Deprecated operations", description = "Deprecated REST operations.", extensions = @Extension(name = OpenApiConfiguration.X_HAWKBIT, properties = @ExtensionProperty(name = "order", value = "2147483647"))) +@SuppressWarnings("java:S1133") // will be removed at some point public interface DeprecatedMgmtRestApi { /** diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DistributionSetTagAssignmentResult.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DistributionSetTagAssignmentResult.java index 085fc16186..aefaac2fba 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DistributionSetTagAssignmentResult.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/DistributionSetTagAssignmentResult.java @@ -27,6 +27,7 @@ @Getter @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) +@SuppressWarnings("java:S1133") // will be removed at some point public class DistributionSetTagAssignmentResult extends AbstractAssignmentResult { private final DistributionSetTag distributionSetTag; diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/TargetTagAssignmentResult.java b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/TargetTagAssignmentResult.java index 2bf307a4db..834dad6703 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/TargetTagAssignmentResult.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource-deprecated/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/deprecated/TargetTagAssignmentResult.java @@ -27,6 +27,7 @@ @Getter @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) +@SuppressWarnings("java:S1133") // will be removed at some point public class TargetTagAssignmentResult extends AbstractAssignmentResult { private final TargetTag targetTag; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/builder/DistributionSetCreate.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/builder/DistributionSetCreate.java index b4da2fe364..64eb5a9122 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/builder/DistributionSetCreate.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/builder/DistributionSetCreate.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository.builder; import java.util.Collection; -import java.util.Optional; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java index 77585a77d1..82acb99d06 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java @@ -22,10 +22,11 @@ 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 static Specification isValid(final Boolean isValid) { */ public static Specification 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 static Specification byIdFetch(final Long distid) { */ public static Specification byIdsFetch(final Collection 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 static Specification byIdsFetch(final Collection 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 static Specification hasTags(final Collection */ public static Specification 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 static Specification equalsNameAndVersionIgnoreCase(f * @return the {@link DistributionSet} {@link Specification} */ public static Specification 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 static Specification byType(final Long typeId) { * @return the {@link DistributionSet} {@link Specification} */ public static Specification hasType(final Collection 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 static Specification hasType(final Collection t public static Specification hasTag(final Long tagId) { return (dsRoot, query, cb) -> { final SetJoin 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 @@ private static Predicate getHasTagsPredicate( final Root dsRoot, final CriteriaBuilder cb, final Boolean selectDSWithNoTag, final Collection tagNames) { final SetJoin tags = dsRoot.join(JpaDistributionSet_.tags, JoinType.LEFT); - final Path exp = tags.get(JpaDistributionSetTag_.name); + final Path exp = tags.get(AbstractJpaNamedEntity_.name); final List hasTagsPredicates = new ArrayList<>(); if (isNoTagActive(selectDSWithNoTag)) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetTagSpecifications.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetTagSpecifications.java index 1592adaf6d..99b4318129 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetTagSpecifications.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetTagSpecifications.java @@ -11,21 +11,19 @@ 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 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); } -} +} \ No newline at end of file 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 507925e76d..4b5b573566 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 @@ -147,8 +147,9 @@ void assignAndUnassignDistributionSetTags() { // toggle A only -> A is now assigned List 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 @@ void assignAndUnassignDistributionSetTags() { final Collection 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(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTypeManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTypeManagementTest.java index cadc0b91c8..882f76d94b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTypeManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/DistributionSetTypeManagementTest.java @@ -26,6 +26,8 @@ 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 @@ void quotaMaxSoftwareModuleTypes() { // 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 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 @@ void updateAssignedDistributionSetTypeMetaData() { } @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 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 @@ void shouldFailWhenDistributionSetHasNoSoftwareModulesAssigned() { @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) { + final DistributionSetCreate distributionSetCreate = entityFactory.distributionSet().create() + .version("a").name(randomString(NamedEntity.NAME_MAX_SIZE + 1)); + assertThatExceptionOfType(ConstraintViolationException.class) + .as("set with too long name should not be created") + .isThrownBy(() -> distributionSetManagement.create(distributionSetCreate)); - 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 distributionSetCreate2 = entityFactory.distributionSet().create().version("a").name(INVALID_TEXT_HTML); + assertThatExceptionOfType(ConstraintViolationException.class) + .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(entityFactory.distributionSet().create().version("a").name(""))); + .as("set with too short name should not be created") + .isThrownBy(() -> distributionSetManagement.create(distributionSetCreate3)); - assertThatExceptionOfType(ConstraintViolationException.class).as("set with null name should not be created") - .isThrownBy(() -> distributionSetManagement - .create(entityFactory.distributionSet().create().version("a").name(null))); + 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)); - 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)))); + 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)); - assertThatExceptionOfType(ConstraintViolationException.class).as("set with invalid name should not be updated") - .isThrownBy(() -> distributionSetManagement - .update(entityFactory.distributionSet().update(set.getId()).name(INVALID_TEXT_HTML))); + 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(entityFactory.distributionSet().update(set.getId()).name(""))); + .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; } }