Sonar Fixes (#2229)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.amqp;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.qameta.allure.Description;
|
import io.qameta.allure.Description;
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
|
@SuppressWarnings("java:S5738") // will be removed at some point
|
||||||
public class DeprecatedMgmtResource implements DeprecatedMgmtRestApi {
|
public class DeprecatedMgmtResource implements DeprecatedMgmtRestApi {
|
||||||
|
|
||||||
// logger that logs usage of deprecated API
|
// logger that logs usage of deprecated API
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
@Deprecated(forRemoval = true, since = "0.6.0")
|
@Deprecated(forRemoval = true, since = "0.6.0")
|
||||||
@Tag(name = "Deprecated operations", description = "Deprecated REST operations.",
|
@Tag(name = "Deprecated operations", description = "Deprecated REST operations.",
|
||||||
extensions = @Extension(name = OpenApiConfiguration.X_HAWKBIT, properties = @ExtensionProperty(name = "order", value = "2147483647")))
|
extensions = @Extension(name = OpenApiConfiguration.X_HAWKBIT, properties = @ExtensionProperty(name = "order", value = "2147483647")))
|
||||||
|
@SuppressWarnings("java:S1133") // will be removed at some point
|
||||||
public interface DeprecatedMgmtRestApi {
|
public interface DeprecatedMgmtRestApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
|||||||
@Getter
|
@Getter
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
|
@SuppressWarnings("java:S1133") // will be removed at some point
|
||||||
public class DistributionSetTagAssignmentResult extends AbstractAssignmentResult<DistributionSet> {
|
public class DistributionSetTagAssignmentResult extends AbstractAssignmentResult<DistributionSet> {
|
||||||
|
|
||||||
private final DistributionSetTag distributionSetTag;
|
private final DistributionSetTag distributionSetTag;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.eclipse.hawkbit.repository.model.TargetTag;
|
|||||||
@Getter
|
@Getter
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
|
@SuppressWarnings("java:S1133") // will be removed at some point
|
||||||
public class TargetTagAssignmentResult extends AbstractAssignmentResult<Target> {
|
public class TargetTagAssignmentResult extends AbstractAssignmentResult<Target> {
|
||||||
|
|
||||||
private final TargetTag targetTag;
|
private final TargetTag targetTag;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
package org.eclipse.hawkbit.repository.builder;
|
package org.eclipse.hawkbit.repository.builder;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ import jakarta.persistence.criteria.SetJoin;
|
|||||||
|
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
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.JpaDistributionSet;
|
||||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
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.jpa.model.JpaDistributionSet_;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
@@ -84,7 +85,7 @@ public final class DistributionSetSpecification {
|
|||||||
*/
|
*/
|
||||||
public static Specification<JpaDistributionSet> byIdFetch(final Long distid) {
|
public static Specification<JpaDistributionSet> byIdFetch(final Long distid) {
|
||||||
return (dsRoot, query, cb) -> {
|
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_.modules, JoinType.LEFT);
|
||||||
dsRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT);
|
dsRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT);
|
||||||
query.distinct(true);
|
query.distinct(true);
|
||||||
@@ -101,7 +102,7 @@ public final class DistributionSetSpecification {
|
|||||||
*/
|
*/
|
||||||
public static Specification<JpaDistributionSet> byIdsFetch(final Collection<Long> distids) {
|
public static Specification<JpaDistributionSet> byIdsFetch(final Collection<Long> distids) {
|
||||||
return (dsRoot, query, cb) -> {
|
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_.modules, JoinType.LEFT);
|
||||||
dsRoot.fetch(JpaDistributionSet_.tags, JoinType.LEFT);
|
dsRoot.fetch(JpaDistributionSet_.tags, JoinType.LEFT);
|
||||||
dsRoot.fetch(JpaDistributionSet_.type, 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) {
|
public static Specification<JpaDistributionSet> likeNameAndVersion(final String name, final String version) {
|
||||||
return (dsRoot, query, cb) -> cb.and(
|
return (dsRoot, query, cb) -> cb.and(
|
||||||
cb.like(cb.lower(dsRoot.get(JpaDistributionSet_.name)), name.toLowerCase()),
|
cb.like(cb.lower(dsRoot.get(AbstractJpaNamedEntity_.name)), name.toLowerCase()),
|
||||||
cb.like(cb.lower(dsRoot.get(JpaDistributionSet_.version)), version.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) {
|
public static Specification<JpaDistributionSet> equalsNameAndVersionIgnoreCase(final String name, final String version) {
|
||||||
return (dsRoot, query, cb) -> cb.and(
|
return (dsRoot, query, cb) -> cb.and(
|
||||||
cb.equal(cb.lower(dsRoot.get(JpaDistributionSet_.name)), name.toLowerCase()),
|
cb.equal(cb.lower(dsRoot.get(AbstractJpaNamedEntity_.name)), name.toLowerCase()),
|
||||||
cb.equal(cb.lower(dsRoot.get(JpaDistributionSet_.version)), version.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}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<JpaDistributionSet> byType(final Long typeId) {
|
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}
|
* @return the {@link DistributionSet} {@link Specification}
|
||||||
*/
|
*/
|
||||||
public static Specification<JpaDistributionSet> hasType(final Collection<Long> typeIds) {
|
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) {
|
public static Specification<JpaDistributionSet> hasTag(final Long tagId) {
|
||||||
return (dsRoot, query, cb) -> {
|
return (dsRoot, query, cb) -> {
|
||||||
final SetJoin<JpaDistributionSet, JpaDistributionSetTag> tags = dsRoot.join(JpaDistributionSet_.tags, JoinType.LEFT);
|
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 Root<JpaDistributionSet> dsRoot, final CriteriaBuilder cb,
|
||||||
final Boolean selectDSWithNoTag, final Collection<String> tagNames) {
|
final Boolean selectDSWithNoTag, final Collection<String> tagNames) {
|
||||||
final SetJoin<JpaDistributionSet, JpaDistributionSetTag> tags = dsRoot.join(JpaDistributionSet_.tags, JoinType.LEFT);
|
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<>();
|
final List<Predicate> hasTagsPredicates = new ArrayList<>();
|
||||||
if (isNoTagActive(selectDSWithNoTag)) {
|
if (isNoTagActive(selectDSWithNoTag)) {
|
||||||
|
|||||||
@@ -11,21 +11,19 @@ package org.eclipse.hawkbit.repository.jpa.specifications;
|
|||||||
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
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.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag_;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for {@link JpaDistributionSetTag}s {@link Specification}s. The class provides
|
* Utility class for {@link JpaDistributionSetTag}s {@link Specification}s. The class provides Spring Data JPQL Specifications.
|
||||||
* Spring Data JPQL Specifications.
|
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public final class DistributionSetTagSpecifications {
|
public final class DistributionSetTagSpecifications {
|
||||||
|
|
||||||
private DistributionSetTagSpecifications() {
|
|
||||||
// utility class
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Specification<JpaDistributionSetTag> byName(@NotEmpty final String name) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,8 +147,9 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
// toggle A only -> A is now assigned
|
// toggle A only -> A is now assigned
|
||||||
List<DistributionSet> result = assignTag(groupA, tag);
|
List<DistributionSet> result = assignTag(groupA, tag);
|
||||||
assertThat(result).size().isEqualTo(20);
|
assertThat(result)
|
||||||
assertThat(result).containsAll(distributionSetManagement.get(groupA.stream().map(DistributionSet::getId).toList()));
|
.hasSize(20)
|
||||||
|
.containsAll(distributionSetManagement.get(groupA.stream().map(DistributionSet::getId).toList()));
|
||||||
assertThat(
|
assertThat(
|
||||||
distributionSetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent().stream()
|
distributionSetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent().stream()
|
||||||
.map(DistributionSet::getId)
|
.map(DistributionSet::getId)
|
||||||
@@ -159,18 +160,19 @@ class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final Collection<DistributionSet> groupAB = concat(groupA, groupB);
|
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(groupAB, tag);
|
result = assignTag(groupAB, tag);
|
||||||
assertThat(result).size().isEqualTo(40);
|
assertThat(result)
|
||||||
assertThat(result).containsAll(distributionSetManagement
|
.hasSize(40)
|
||||||
.get(groupAB.stream().map(DistributionSet::getId).toList()));
|
.containsAll(distributionSetManagement.get(groupAB.stream().map(DistributionSet::getId).toList()));
|
||||||
assertThat(
|
assertThat(
|
||||||
distributionSetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent().stream().map(DistributionSet::getId).sorted()
|
distributionSetManagement.findByTag(
|
||||||
.toList())
|
tag.getId(), Pageable.unpaged()).getContent().stream().map(DistributionSet::getId).sorted().toList())
|
||||||
.isEqualTo(groupAB.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)
|
||||||
assertThat(result).containsAll(distributionSetManagement.get(concat(groupB, groupA).stream().map(DistributionSet::getId).toList()));
|
.hasSize(40)
|
||||||
|
.containsAll(distributionSetManagement.get(concat(groupB, groupA).stream().map(DistributionSet::getId).toList()));
|
||||||
assertThat(distributionSetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent()).isEmpty();
|
assertThat(distributionSetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ 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.eclipse.hawkbit.repository.DistributionSetManagement;
|
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.builder.SoftwareModuleTypeCreate;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTypeCreatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTypeCreatedEvent;
|
||||||
@@ -145,33 +147,35 @@ class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
// assign all types at once
|
// assign all types at once
|
||||||
final DistributionSetType dsType1 = distributionSetTypeManagement
|
final DistributionSetType dsType1 = distributionSetTypeManagement
|
||||||
.create(entityFactory.distributionSetType().create().key("dst1").name("dst1"));
|
.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(
|
assertThatExceptionOfType(AssignmentQuotaExceededException.class).isThrownBy(
|
||||||
() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType1.getId(), moduleTypeIds));
|
() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType1Id, moduleTypeIds));
|
||||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class).isThrownBy(
|
|
||||||
() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType1.getId(), moduleTypeIds));
|
|
||||||
|
|
||||||
// assign as many mandatory modules as possible
|
// assign as many mandatory modules as possible
|
||||||
final DistributionSetType dsType2 = distributionSetTypeManagement
|
final DistributionSetType dsType2 = distributionSetTypeManagement
|
||||||
.create(entityFactory.distributionSetType().create().key("dst2").name("dst2"));
|
.create(entityFactory.distributionSetType().create().key("dst2").name("dst2"));
|
||||||
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2.getId(),
|
final Long dsType2Id = dsType2.getId();
|
||||||
|
distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2Id,
|
||||||
moduleTypeIds.subList(0, quota));
|
moduleTypeIds.subList(0, quota));
|
||||||
assertThat(distributionSetTypeManagement.get(dsType2.getId())).isNotEmpty();
|
assertThat(distributionSetTypeManagement.get(dsType2Id)).isNotEmpty();
|
||||||
assertThat(distributionSetTypeManagement.get(dsType2.getId()).get().getMandatoryModuleTypes()).hasSize(quota);
|
assertThat(distributionSetTypeManagement.get(dsType2Id).get().getMandatoryModuleTypes()).hasSize(quota);
|
||||||
// assign one more to trigger the quota exceeded error
|
// assign one more to trigger the quota exceeded error
|
||||||
|
final List<Long> softwareModuleTypeIds = Collections.singletonList(moduleTypeIds.get(quota));
|
||||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
|
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
|
||||||
.isThrownBy(() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2.getId(),
|
.isThrownBy(() -> distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(dsType2Id, softwareModuleTypeIds));
|
||||||
Collections.singletonList(moduleTypeIds.get(quota))));
|
|
||||||
|
|
||||||
// assign as many optional modules as possible
|
// assign as many optional modules as possible
|
||||||
final DistributionSetType dsType3 = distributionSetTypeManagement
|
final DistributionSetType dsType3 = distributionSetTypeManagement
|
||||||
.create(entityFactory.distributionSetType().create().key("dst3").name("dst3"));
|
.create(entityFactory.distributionSetType().create().key("dst3").name("dst3"));
|
||||||
distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3.getId(), moduleTypeIds.subList(0, quota));
|
final Long dsType3Id = dsType3.getId();
|
||||||
assertThat(distributionSetTypeManagement.get(dsType3.getId())).isNotEmpty();
|
distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3Id, moduleTypeIds.subList(0, quota));
|
||||||
assertThat(distributionSetTypeManagement.get(dsType3.getId()).get().getOptionalModuleTypes()).hasSize(quota);
|
assertThat(distributionSetTypeManagement.get(dsType3Id)).isNotEmpty();
|
||||||
|
assertThat(distributionSetTypeManagement.get(dsType3Id).get().getOptionalModuleTypes()).hasSize(quota);
|
||||||
// assign one more to trigger the quota exceeded error
|
// assign one more to trigger the quota exceeded error
|
||||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
|
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
|
||||||
.isThrownBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3.getId(),
|
.isThrownBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(dsType3Id, softwareModuleTypeIds));
|
||||||
Collections.singletonList(moduleTypeIds.get(quota))));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,29 +193,29 @@ class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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() {
|
void addModuleToAssignedDistributionSetTypeFails() {
|
||||||
final DistributionSetType nonUpdatableType = createDistributionSetTypeUsedByDs();
|
final Long nonUpdatableTypeId = createDistributionSetTypeUsedByDs().getId();
|
||||||
|
final Set<Long> osTypeId = Set.of(osType.getId());
|
||||||
assertThatThrownBy(() -> distributionSetTypeManagement
|
assertThatThrownBy(() -> distributionSetTypeManagement
|
||||||
.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(), Set.of(osType.getId())))
|
.assignMandatorySoftwareModuleTypes(nonUpdatableTypeId, osTypeId))
|
||||||
.isInstanceOf(EntityReadOnlyException.class);
|
.isInstanceOf(EntityReadOnlyException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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() {
|
void removeModuleToAssignedDistributionSetTypeFails() {
|
||||||
DistributionSetType nonUpdatableType = distributionSetTypeManagement
|
DistributionSetType nonUpdatableType = distributionSetTypeManagement
|
||||||
.create(entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
|
.create(entityFactory.distributionSetType().create().key("updatableType").name("to be deleted"));
|
||||||
assertThat(distributionSetTypeManagement.findByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty();
|
assertThat(distributionSetTypeManagement.findByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty();
|
||||||
|
|
||||||
nonUpdatableType = distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(),
|
final Long osTypeId = osType.getId();
|
||||||
Set.of(osType.getId()));
|
nonUpdatableType = distributionSetTypeManagement.assignMandatorySoftwareModuleTypes(nonUpdatableType.getId(), Set.of(osTypeId));
|
||||||
distributionSetManagement.create(entityFactory.distributionSet().create().name("newtypesoft").version("1")
|
distributionSetManagement.create(
|
||||||
.type(nonUpdatableType.getKey()));
|
entityFactory.distributionSet().create().name("newtypesoft").version("1").type(nonUpdatableType.getKey()));
|
||||||
|
|
||||||
final Long typeId = nonUpdatableType.getId();
|
final Long typeId = nonUpdatableType.getId();
|
||||||
assertThatThrownBy(() -> distributionSetTypeManagement.unassignSoftwareModuleType(typeId, osType.getId()))
|
assertThatThrownBy(() -> distributionSetTypeManagement.unassignSoftwareModuleType(typeId, osTypeId))
|
||||||
.isInstanceOf(EntityReadOnlyException.class);
|
.isInstanceOf(EntityReadOnlyException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,100 +268,116 @@ class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
|
|
||||||
@Step
|
@Step
|
||||||
private void createAndUpdateDistributionSetWithInvalidDescription(final DistributionSet set) {
|
private void createAndUpdateDistributionSetWithInvalidDescription(final DistributionSet set) {
|
||||||
|
final DistributionSetCreate distributionSetCreate = entityFactory.distributionSet().create()
|
||||||
|
.name("a").version("a").description(randomString(513));
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with too long description should not be created")
|
.as("set with too long description should not be created")
|
||||||
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
|
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate));
|
||||||
.version("a").description(randomString(513))));
|
|
||||||
|
|
||||||
|
final DistributionSetCreate distributionSetCreate2 = entityFactory.distributionSet().create()
|
||||||
|
.name("a").version("a").description(INVALID_TEXT_HTML);
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set invalid description text should not be created")
|
.as("set invalid description text should not be created")
|
||||||
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
|
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate2));
|
||||||
.version("a").description(INVALID_TEXT_HTML)));
|
|
||||||
|
|
||||||
|
final DistributionSetUpdate distributionSetUpdate = entityFactory.distributionSet().update(set.getId())
|
||||||
|
.description(randomString(513));
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with too long description should not be updated")
|
.as("set with too long description should not be updated")
|
||||||
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
|
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate));
|
||||||
.description(randomString(513))));
|
|
||||||
|
|
||||||
|
final DistributionSetUpdate distributionSetUpdate2 = entityFactory.distributionSet().update(set.getId()).description(INVALID_TEXT_HTML);
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with invalid description should not be updated").isThrownBy(() -> distributionSetManagement
|
.as("set with invalid description should not be updated")
|
||||||
.update(entityFactory.distributionSet().update(set.getId()).description(INVALID_TEXT_HTML)));
|
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate2));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Step
|
@Step
|
||||||
private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet set) {
|
private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet set) {
|
||||||
|
final DistributionSetCreate distributionSetCreate = entityFactory.distributionSet().create()
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class).as("set with too long name should not be created")
|
.version("a").name(randomString(NamedEntity.NAME_MAX_SIZE + 1));
|
||||||
.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)));
|
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with too short name should not be created").isThrownBy(() -> distributionSetManagement
|
.as("set with too long name should not be created")
|
||||||
.create(entityFactory.distributionSet().create().version("a").name("")));
|
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate));
|
||||||
|
|
||||||
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)));
|
|
||||||
|
|
||||||
|
final DistributionSetCreate distributionSetCreate2 = entityFactory.distributionSet().create().version("a").name(INVALID_TEXT_HTML);
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with too short name should not be updated").isThrownBy(() -> distributionSetManagement
|
.as("set with invalid name should not be created")
|
||||||
.update(entityFactory.distributionSet().update(set.getId()).name("")));
|
.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
|
@Step
|
||||||
private void createAndUpdateDistributionSetWithInvalidVersion(final DistributionSet set) {
|
private void createAndUpdateDistributionSetWithInvalidVersion(final DistributionSet set) {
|
||||||
|
final DistributionSetCreate distributionSetCreate = entityFactory.distributionSet().create()
|
||||||
|
.name("a").version(randomString(NamedVersionedEntity.VERSION_MAX_SIZE + 1));
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with too long version should not be created")
|
.as("set with too long version should not be created")
|
||||||
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
|
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate));
|
||||||
.version(randomString(NamedVersionedEntity.VERSION_MAX_SIZE + 1))));
|
|
||||||
|
|
||||||
|
final DistributionSetCreate distributionSetCreate2 = entityFactory.distributionSet().create().name("a").version(INVALID_TEXT_HTML);
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with invalid version should not be created").isThrownBy(() -> distributionSetManagement
|
.as("set with invalid version should not be created")
|
||||||
.create(entityFactory.distributionSet().create().name("a").version(INVALID_TEXT_HTML)));
|
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate2));
|
||||||
|
|
||||||
|
final DistributionSetCreate distributionSetCreate3 = entityFactory.distributionSet().create().name("a").version("");
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with too short version should not be created").isThrownBy(() -> distributionSetManagement
|
.as("set with too short version should not be created")
|
||||||
.create(entityFactory.distributionSet().create().name("a").version("")));
|
.isThrownBy(() -> distributionSetManagement.create(distributionSetCreate3));
|
||||||
|
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class).as("set with null version should not be created")
|
final DistributionSetCreate distributionSetCreate4 = entityFactory.distributionSet().create().name("a").version(null);
|
||||||
.isThrownBy(() -> distributionSetManagement
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.create(entityFactory.distributionSet().create().name("a").version(null)));
|
.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)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with too long version should not be updated")
|
.as("set with too long version should not be updated")
|
||||||
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
|
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate));
|
||||||
.version(randomString(NamedVersionedEntity.VERSION_MAX_SIZE + 1))));
|
|
||||||
|
|
||||||
|
final DistributionSetUpdate distributionSetUpdate2 = entityFactory.distributionSet().update(set.getId()).version(INVALID_TEXT_HTML);
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with invalid version should not be updated").isThrownBy(() -> distributionSetManagement
|
.as("set with invalid version should not be updated")
|
||||||
.update(entityFactory.distributionSet().update(set.getId()).version(INVALID_TEXT_HTML)));
|
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate2));
|
||||||
|
|
||||||
|
final DistributionSetUpdate distributionSetUpdate3 = entityFactory.distributionSet().update(set.getId()).version("");
|
||||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
.as("set with too short version should not be updated").isThrownBy(() -> distributionSetManagement
|
.as("set with too short version should not be updated")
|
||||||
.update(entityFactory.distributionSet().update(set.getId()).version("")));
|
.isThrownBy(() -> distributionSetManagement.update(distributionSetUpdate3));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DistributionSetType createDistributionSetTypeUsedByDs() {
|
private DistributionSetType createDistributionSetTypeUsedByDs() {
|
||||||
final DistributionSetType nonUpdatableType = distributionSetTypeManagement.create(entityFactory
|
final DistributionSetType nonUpdatableType = distributionSetTypeManagement.create(
|
||||||
.distributionSetType().create().key("updatableType").name("to be deleted").colour("test123"));
|
entityFactory.distributionSetType().create().key("updatableType").name("to be deleted").colour("test123"));
|
||||||
assertThat(distributionSetTypeManagement.findByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty();
|
assertThat(distributionSetTypeManagement.findByKey("updatableType").get().getMandatoryModuleTypes()).isEmpty();
|
||||||
distributionSetManagement.create(entityFactory.distributionSet().create().name("newtypesoft").version("1")
|
distributionSetManagement.create(entityFactory.distributionSet().create()
|
||||||
.type(nonUpdatableType.getKey()));
|
.name("newtypesoft").version("1").type(nonUpdatableType.getKey()));
|
||||||
return nonUpdatableType;
|
return nonUpdatableType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user