Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-24 20:10:28 +02:00
committed by GitHub
parent ef4c0c6d18
commit bbb2193d74
37 changed files with 227 additions and 239 deletions

View File

@@ -9,8 +9,6 @@
*/
package org.eclipse.hawkbit.repository.builder;
import java.util.Optional;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
@@ -62,8 +60,8 @@ public interface SoftwareModuleCreate {
* @param type for {@link SoftwareModule#getType()}
* @return updated builder instance
*/
default SoftwareModuleCreate type(final SoftwareModuleType type) {
return type(Optional.ofNullable(type).map(SoftwareModuleType::getKey).orElse(null));
default SoftwareModuleCreate type(@NotNull final SoftwareModuleType type) {
return type(type.getKey());
}
/**

View File

@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.event.remote;
import java.io.Serial;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.EqualsAndHashCode;
import lombok.Getter;
@@ -47,8 +46,7 @@ public class TargetAssignDistributionSetEvent extends AbstractAssignmentEvent {
public TargetAssignDistributionSetEvent(final String tenant, final long distributionSetId, final List<Action> a,
final String applicationId, final boolean maintenanceWindowAvailable) {
super(distributionSetId, tenant,
a.stream().filter(action -> action.getDistributionSet().getId().longValue() == distributionSetId)
.collect(Collectors.toList()),
a.stream().filter(action -> action.getDistributionSet().getId().longValue() == distributionSetId).toList(),
applicationId);
this.distributionSetId = distributionSetId;
this.maintenanceWindowAvailable = maintenanceWindowAvailable;

View File

@@ -11,12 +11,14 @@ package org.eclipse.hawkbit.repository.exception;
import static org.eclipse.hawkbit.repository.SizeConversionHelper.byteValueToReadableString;
import lombok.EqualsAndHashCode;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.exception.SpServerError;
/**
* Thrown if storage quota is exceeded
*/
@EqualsAndHashCode(callSuper = true)
public class StorageQuotaExceededException extends AbstractServerRtException {
private static final String MAX_ARTIFACT_SIZE_TOTAL_EXCEEDED = "Storage quota exceeded, %s left.";

View File

@@ -13,9 +13,12 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.EqualsAndHashCode;
/**
* Bean for holding the system usage stats including tenant specific data.
*/
@EqualsAndHashCode(callSuper = true)
public class SystemUsageReportWithTenants extends SystemUsageReport {
private final List<TenantUsage> tenants = new ArrayList<>();

View File

@@ -13,7 +13,6 @@ import io.micrometer.core.instrument.MeterRegistry;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;

View File

@@ -306,8 +306,8 @@ public class RepositoryApplicationConfiguration {
@Bean
@ConditionalOnMissingBean
SystemManagementCacheKeyGenerator systemManagementCacheKeyGenerator() {
return new SystemManagementCacheKeyGenerator();
SystemManagementCacheKeyGenerator systemManagementCacheKeyGenerator(final TenantAware tenantAware) {
return new SystemManagementCacheKeyGenerator(tenantAware);
}
@Bean

View File

@@ -27,8 +27,11 @@ import org.springframework.context.annotation.Bean;
public class SystemManagementCacheKeyGenerator implements CurrentTenantCacheKeyGenerator {
private final ThreadLocal<String> createInitialTenant = new ThreadLocal<>();
@Autowired
private TenantAware tenantAware;
private final TenantAware tenantAware;
public SystemManagementCacheKeyGenerator(final TenantAware tenantAware) {
this.tenantAware = tenantAware;
}
@Override
@Bean

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository.jpa.model;
import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;
import lombok.Data;
import lombok.NoArgsConstructor;

View File

@@ -11,10 +11,11 @@ package org.eclipse.hawkbit.repository.jpa.specifications;
import jakarta.persistence.criteria.ListJoin;
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.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType_;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -38,13 +39,13 @@ public final class SoftwareModuleSpecification {
* @return the {@link SoftwareModule} {@link Specification}
*/
public static Specification<JpaSoftwareModule> byId(final Long swModuleId) {
return (swRoot, query, cb) -> cb.equal(swRoot.get(JpaSoftwareModule_.id), swModuleId);
return (swRoot, query, cb) -> cb.equal(swRoot.get(AbstractJpaBaseEntity_.id), swModuleId);
}
public static Specification<JpaSoftwareModule> byAssignedToDs(final Long dsId) {
return (swRoot, query, cb) -> {
final ListJoin<JpaSoftwareModule, JpaDistributionSet> join = swRoot.join(JpaSoftwareModule_.assignedTo);
return cb.equal(join.get(JpaDistributionSet_.ID), dsId);
return cb.equal(join.get(AbstractJpaBaseEntity_.ID), dsId);
};
}
@@ -68,8 +69,8 @@ public final class SoftwareModuleSpecification {
*/
public static Specification<JpaSoftwareModule> likeNameAndVersion(final String name, final String version) {
return (smRoot, query, cb) -> cb.and(
cb.like(cb.lower(smRoot.get(JpaSoftwareModule_.name)), name.toLowerCase()),
cb.like(cb.lower(smRoot.get(JpaSoftwareModule_.version)), version.toLowerCase()));
cb.like(cb.lower(smRoot.get(AbstractJpaNamedEntity_.name)), name.toLowerCase()),
cb.like(cb.lower(smRoot.get(AbstractJpaNamedVersionedEntity_.version)), version.toLowerCase()));
}
/**
@@ -81,7 +82,7 @@ public final class SoftwareModuleSpecification {
*/
public static Specification<JpaSoftwareModule> equalType(final Long type) {
return (smRoot, query, cb) -> cb.equal(
smRoot.get(JpaSoftwareModule_.type).get(JpaSoftwareModuleType_.id), type);
smRoot.get(JpaSoftwareModule_.type).get(AbstractJpaBaseEntity_.id), type);
}
/**

View File

@@ -13,10 +13,10 @@ import jakarta.persistence.criteria.Join;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
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.JpaDistributionSet_;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.springframework.data.jpa.domain.Specification;
@@ -42,8 +42,7 @@ public final class TagSpecification {
query.distinct(true);
return criteriaBuilder.equal(tagJoin.get(JpaDistributionSet_.id), dsId);
return criteriaBuilder.equal(tagJoin.get(AbstractJpaBaseEntity_.id), dsId);
};
}
}

View File

@@ -26,16 +26,12 @@ import jakarta.validation.constraints.NotNull;
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.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag_;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType_;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
@@ -99,7 +95,7 @@ public final class TargetSpecifications {
* @return the {@link Target} {@link Specification}
*/
public static Specification<JpaTarget> hasId(final Long id) {
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTarget_.id), id);
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(AbstractJpaBaseEntity_.id), id);
}
/**
@@ -109,7 +105,7 @@ public final class TargetSpecifications {
* @return the {@link Target} {@link Specification}
*/
public static Specification<JpaTarget> hasIdIn(final Collection<Long> ids) {
return (targetRoot, query, cb) -> targetRoot.get(JpaTarget_.id).in(ids);
return (targetRoot, query, cb) -> targetRoot.get(AbstractJpaBaseEntity_.id).in(ids);
}
/**
@@ -201,7 +197,7 @@ public final class TargetSpecifications {
return (targetRoot, query, cb) -> {
final String searchTextToLower = searchText.toLowerCase();
return cb.or(cb.like(cb.lower(targetRoot.get(JpaTarget_.controllerId)), searchTextToLower),
cb.like(cb.lower(targetRoot.get(JpaTarget_.name)), searchTextToLower));
cb.like(cb.lower(targetRoot.get(AbstractJpaNamedEntity_.name)), searchTextToLower));
};
}
@@ -227,8 +223,8 @@ public final class TargetSpecifications {
@NotNull final Long distributionId) {
return (targetRoot, query, cb) -> cb.and(targetRoot.get(JpaTarget_.controllerId).in(tIDs),
cb.or(
cb.notEqual(targetRoot.get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id), distributionId),
cb.isNull(targetRoot.<JpaDistributionSet> get(JpaTarget_.assignedDistributionSet))));
cb.notEqual(targetRoot.get(JpaTarget_.assignedDistributionSet).get(AbstractJpaBaseEntity_.id), distributionId),
cb.isNull(targetRoot.get(JpaTarget_.assignedDistributionSet))));
}
/**
@@ -241,7 +237,7 @@ public final class TargetSpecifications {
public static Specification<JpaTarget> hasTagName(final String tagName) {
return (targetRoot, query, cb) -> {
final SetJoin<JpaTarget, JpaTargetTag> join = targetRoot.join(JpaTarget_.tags);
return cb.equal(join.get(JpaTargetTag_.name), tagName);
return cb.equal(join.get(AbstractJpaNamedEntity_.name), tagName);
};
}
@@ -270,7 +266,7 @@ public final class TargetSpecifications {
*/
public static Specification<JpaTarget> hasAssignedDistributionSet(final Long distributionSetId) {
return (targetRoot, query, cb) -> cb.equal(
targetRoot.get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id), distributionSetId);
targetRoot.get(JpaTarget_.assignedDistributionSet).get(AbstractJpaBaseEntity_.id), distributionSetId);
}
/**
@@ -283,8 +279,8 @@ public final class TargetSpecifications {
public static Specification<JpaTarget> hasNotDistributionSetInActions(final Long distributionSetId) {
return (targetRoot, query, cb) -> {
final ListJoin<JpaTarget, JpaAction> actionsJoin = targetRoot.join(JpaTarget_.actions, JoinType.LEFT);
actionsJoin.on(cb.equal(actionsJoin.get(JpaAction_.distributionSet).get(JpaDistributionSet_.id), distributionSetId));
return cb.isNull(actionsJoin.get(JpaAction_.id));
actionsJoin.on(cb.equal(actionsJoin.get(JpaAction_.distributionSet).get(AbstractJpaBaseEntity_.id), distributionSetId));
return cb.isNull(actionsJoin.get(AbstractJpaBaseEntity_.id));
};
}
@@ -323,9 +319,9 @@ public final class TargetSpecifications {
final Subquery<Long> compatibilitySubQuery = query.subquery(Long.class);
final Root<JpaTarget> subQueryTargetRoot = compatibilitySubQuery.from(JpaTarget.class);
compatibilitySubQuery.select(subQueryTargetRoot.get(JpaTarget_.id))
compatibilitySubQuery.select(subQueryTargetRoot.get(AbstractJpaBaseEntity_.id))
.where(cb.and(
cb.equal(targetRoot.get(JpaTarget_.id), subQueryTargetRoot.get(JpaTarget_.id)),
cb.equal(targetRoot.get(AbstractJpaBaseEntity_.id), subQueryTargetRoot.get(AbstractJpaBaseEntity_.id)),
cb.equal(getDsTypeIdPath(subQueryTargetRoot), distributionSetTypeId)));
return cb.and(targetTypeNotNull, cb.not(cb.exists(compatibilitySubQuery)));
@@ -343,7 +339,7 @@ public final class TargetSpecifications {
return (targetRoot, query, cb) -> {
final ListJoin<JpaTarget, RolloutTargetGroup> targetGroupJoin = targetRoot
.join(JpaTarget_.rolloutTargetGroup);
return cb.equal(targetGroupJoin.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), group);
return cb.equal(targetGroupJoin.get(RolloutTargetGroup_.rolloutGroup).get(AbstractJpaBaseEntity_.id), group);
};
}
@@ -357,7 +353,7 @@ public final class TargetSpecifications {
public static Specification<JpaTarget> isInActionRolloutGroup(final Long group) {
return (targetRoot, query, cb) -> {
final ListJoin<JpaTarget, JpaAction> targetActionJoin = targetRoot.join(JpaTarget_.actions);
return cb.equal(targetActionJoin.get(JpaAction_.rolloutGroup).get(JpaRolloutGroup_.id), group);
return cb.equal(targetActionJoin.get(JpaAction_.rolloutGroup).get(AbstractJpaBaseEntity_.id), group);
};
}
@@ -373,7 +369,7 @@ public final class TargetSpecifications {
final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = targetRoot
.join(JpaTarget_.rolloutTargetGroup, JoinType.LEFT);
rolloutTargetJoin.on(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup)
.get(JpaRolloutGroup_.id).in(groups));
.get(AbstractJpaBaseEntity_.id).in(groups));
return cb.isNull(rolloutTargetJoin.get(RolloutTargetGroup_.target));
};
}
@@ -389,7 +385,7 @@ public final class TargetSpecifications {
final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = targetRoot
.join(JpaTarget_.rolloutTargetGroup, JoinType.LEFT);
rolloutTargetJoin.on(cb.ge(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup)
.get(JpaRolloutGroup_.id), groupId));
.get(AbstractJpaBaseEntity_.id), groupId));
return cb.isNull(rolloutTargetJoin.get(RolloutTargetGroup_.target));
};
}
@@ -406,12 +402,12 @@ public final class TargetSpecifications {
final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = targetRoot
.join(JpaTarget_.rolloutTargetGroup, JoinType.INNER);
rolloutTargetJoin.on(
cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), group));
cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(AbstractJpaBaseEntity_.id), group));
final ListJoin<JpaTarget, JpaAction> actionsJoin = targetRoot.join(JpaTarget_.actions, JoinType.LEFT);
actionsJoin.on(cb.equal(actionsJoin.get(JpaAction_.rolloutGroup).get(JpaRolloutGroup_.id), group));
actionsJoin.on(cb.equal(actionsJoin.get(JpaAction_.rolloutGroup).get(AbstractJpaBaseEntity_.id), group));
return cb.isNull(actionsJoin.get(JpaAction_.id));
return cb.isNull(actionsJoin.get(AbstractJpaBaseEntity_.id));
};
}
@@ -424,7 +420,7 @@ public final class TargetSpecifications {
*/
public static Specification<JpaTarget> hasInstalledDistributionSet(final Long distributionSetId) {
return (targetRoot, query, cb) -> cb.equal(
targetRoot.get(JpaTarget_.installedDistributionSet).get(JpaDistributionSet_.id), distributionSetId);
targetRoot.get(JpaTarget_.installedDistributionSet).get(AbstractJpaBaseEntity_.id), distributionSetId);
}
/**
@@ -437,7 +433,7 @@ public final class TargetSpecifications {
return (targetRoot, query, cb) -> {
final SetJoin<JpaTarget, JpaTargetTag> tags = targetRoot.join(JpaTarget_.tags, JoinType.LEFT);
return cb.equal(tags.get(JpaTargetTag_.id), tagId);
return cb.equal(tags.get(AbstractJpaBaseEntity_.id), tagId);
};
}
@@ -448,8 +444,7 @@ public final class TargetSpecifications {
* @return the {@link Target} {@link Specification}
*/
public static Specification<JpaTarget> hasTargetType(final long typeId) {
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTarget_.targetType).get(JpaTargetType_.id),
typeId);
return (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTarget_.targetType).get(AbstractJpaBaseEntity_.id), typeId);
}
/**
@@ -471,7 +466,7 @@ public final class TargetSpecifications {
*/
public static Specification<JpaTarget> hasTargetTypeNot(final Long typeId) {
return (targetRoot, query, cb) -> cb.or(getTargetTypeIsNullPredicate(targetRoot),
cb.notEqual(targetRoot.get(JpaTarget_.targetType).get(JpaTargetType_.id), typeId));
cb.notEqual(targetRoot.get(JpaTarget_.targetType).get(AbstractJpaBaseEntity_.id), typeId));
}
public static Specification<JpaTarget> failedActionsForRollout(final String rolloutId) {
@@ -500,28 +495,28 @@ public final class TargetSpecifications {
cb.gt(actionsJoin.get(JpaAction_.weight), weight),
cb.and(
cb.equal(actionsJoin.get(JpaAction_.weight), weight),
cb.ge(actionsJoin.get(JpaAction_.ROLLOUT).get(JpaRollout_.ID), rolloutId))));
cb.ge(actionsJoin.get(JpaAction_.ROLLOUT).get(AbstractJpaBaseEntity_.ID), rolloutId))));
// another, but probably heavier variant
// actionsJoin.on(
// cb.or(
// // in rollout
// cb.equal(actionsJoin.get(JpaAction_.ROLLOUT).get(JpaRollout_.ID), rolloutId),
// cb.equal(actionsJoin.get(JpaAction_.ROLLOUT).get(AbstractJpaBaseEntity_.ID), rolloutId),
// // or, in newer rollout with greater or equal weight
// cb.and(
// cb.gt(actionsJoin.get(JpaAction_.ROLLOUT).get(JpaRollout_.ID), rolloutId),
// cb.gt(actionsJoin.get(JpaAction_.ROLLOUT).get(AbstractJpaBaseEntity_.ID), rolloutId),
// cb.ge(actionsJoin.get(JpaAction_.weight), weight)),
// // or, in older with greater status
// cb.and(
// cb.lt(actionsJoin.get(JpaAction_.ROLLOUT).get(JpaRollout_.ID), rolloutId),
// cb.lt(actionsJoin.get(JpaAction_.ROLLOUT).get(AbstractJpaBaseEntity_.ID), rolloutId),
// cb.gt(actionsJoin.get(JpaAction_.weight), weight))));
return cb.isNull(actionsJoin.get(JpaAction_.id));
return cb.isNull(actionsJoin.get(AbstractJpaBaseEntity_.id));
};
}
private static Predicate getHasTagsPredicate(final Root<JpaTarget> targetRoot, final CriteriaBuilder cb,
final Boolean selectTargetWithNoTag, final String[] tagNames) {
final SetJoin<JpaTarget, JpaTargetTag> tags = targetRoot.join(JpaTarget_.tags, JoinType.LEFT);
final Path<String> exp = tags.get(JpaTargetTag_.name);
final Path<String> exp = tags.get(AbstractJpaNamedEntity_.name);
final List<Predicate> hasTagsPredicates = new ArrayList<>();
if (isNoTagActive(selectTargetWithNoTag)) {
@@ -549,6 +544,6 @@ public final class TargetSpecifications {
private static Path<Long> getDsTypeIdPath(final Root<JpaTarget> root) {
final Join<JpaTarget, JpaTargetType> targetTypeJoin = root.join(JpaTarget_.targetType, JoinType.LEFT);
return targetTypeJoin.join(JpaTargetType_.distributionSetTypes, JoinType.LEFT).get(JpaDistributionSetType_.id);
return targetTypeJoin.join(JpaTargetType_.distributionSetTypes, JoinType.LEFT).get(AbstractJpaBaseEntity_.id);
}
}

View File

@@ -31,6 +31,7 @@ import org.springframework.util.ObjectUtils;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class StatisticsUtils {
@SuppressWarnings("java:S5164") // intentionally don't call remove. should always keep the last reported
private static final ThreadLocal<Map<String, Double>> LAST_COUNTERS = ThreadLocal.withInitial(MapUFToString::new);
// for test purposes we may want to flush the statistics and to get diff from the last get int THIS thread

View File

@@ -20,17 +20,17 @@ import org.junit.jupiter.api.Test;
*/
@Feature("Component Tests - Repository")
@Story("Test TargetCreatedEvent, TargetUpdatedEvent and CancelTargetAssignmentEvent")
public class TargetEventTest extends AbstractRemoteEntityEventTest<Target> {
class TargetEventTest extends AbstractRemoteEntityEventTest<Target> {
@Test
@Description("Verifies that the target entity reloading by remote created event works")
public void testTargetCreatedEvent() {
void testTargetCreatedEvent() {
assertAndCreateRemoteEvent(TargetCreatedEvent.class);
}
@Test
@Description("Verifies that the target entity reloading by remote updated event works")
public void testTargetUpdatedEvent() {
void testTargetUpdatedEvent() {
assertAndCreateRemoteEvent(TargetUpdatedEvent.class);
}

View File

@@ -20,17 +20,17 @@ import org.junit.jupiter.api.Test;
*/
@Feature("Component Tests - Repository")
@Story("Test TargetTagCreatedEvent and TargetTagUpdateEvent")
public class TargetTagEventTest extends AbstractRemoteEntityEventTest<TargetTag> {
class TargetTagEventTest extends AbstractRemoteEntityEventTest<TargetTag> {
@Test
@Description("Verifies that the target tag entity reloading by remote created event works")
public void testTargetTagCreatedEvent() {
void testTargetTagCreatedEvent() {
assertAndCreateRemoteEvent(TargetTagCreatedEvent.class);
}
@Test
@Description("Verifies that the target tag entity reloading by remote updated event works")
public void testTargetTagUpdateEventt() {
void testTargetTagUpdateEventt() {
assertAndCreateRemoteEvent(TargetTagUpdatedEvent.class);
}

View File

@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
@Feature("SecurityTests - SoftwareManagement")
@Story("SecurityTests SoftwareManagement")
public class SoftwareManagementSecurityTest
class SoftwareManagementSecurityTest
extends AbstractRepositoryManagementSecurityTest<SoftwareModule, SoftwareModuleCreate, SoftwareModuleUpdate> {
@Override

View File

@@ -25,7 +25,6 @@ import java.util.Set;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import org.apache.commons.lang3.RandomUtils;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
@@ -358,7 +357,7 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
// Init artifact binary data, target and DistributionSets
final int artifactSize = 1024;
final byte[] source = RandomUtils.nextBytes(artifactSize);
final byte[] source = randomBytes(artifactSize);
// [STEP1]: Create SoftwareModuleX and add a new ArtifactX
SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0);
@@ -403,7 +402,7 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
void deleteMultipleSoftwareModulesWhichShareAnArtifact() {
// Init artifact binary data, target and DistributionSets
final int artifactSize = 1024;
final byte[] source = RandomUtils.nextBytes(artifactSize);
final byte[] source = randomBytes(artifactSize);
final Target target = testdataFactory.createTarget();
// [STEP1]: Create SoftwareModuleX and add a new ArtifactX
@@ -533,9 +532,10 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
}
// quota exceeded
final SoftwareModuleMetadataCreate metadata = entityFactory.softwareModuleMetadata().create(module.getId())
.key("k" + maxMetaData).value("v" + maxMetaData);
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
.isThrownBy(() -> softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata()
.create(module.getId()).key("k" + maxMetaData).value("v" + maxMetaData)));
.isThrownBy(() -> softwareModuleManagement.updateMetaData(metadata));
// add multiple meta data entries at once
final SoftwareModule module2 = testdataFactory.createSoftwareModuleApp("m2");
@@ -574,12 +574,12 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
final String knownValue1 = "myKnownValue1";
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(ah.getId()).key(knownKey1)
.value(knownValue1).targetVisible(true));
final SoftwareModuleMetadataCreate metadata = entityFactory.softwareModuleMetadata()
.create(ah.getId()).key(knownKey1).value(knownValue1).targetVisible(true);
softwareModuleManagement.updateMetaData(metadata);
assertThatExceptionOfType(EntityAlreadyExistsException.class)
.isThrownBy(() -> softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata()
.create(ah.getId()).key(knownKey1).value(knownValue1).targetVisible(true)))
.isThrownBy(() -> softwareModuleManagement.updateMetaData(metadata))
.withMessageContaining("Metadata").withMessageContaining(knownKey1);
final String knownKey2 = "myKnownKey2";
@@ -587,9 +587,10 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(ah.getId()).key(knownKey2)
.value(knownValue1).targetVisible(false));
final SoftwareModuleMetadataCreate metadata2 = entityFactory.softwareModuleMetadata().create(ah.getId())
.key(knownKey2).value(knownValue1).targetVisible(true);
assertThatExceptionOfType(EntityAlreadyExistsException.class)
.isThrownBy(() -> softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata()
.create(ah.getId()).key(knownKey2).value(knownValue1).targetVisible(true)))
.isThrownBy(() -> softwareModuleManagement.updateMetaData(metadata2))
.withMessageContaining("Metadata").withMessageContaining(knownKey2);
}
@@ -746,36 +747,32 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Artifacts of a locked SM can't be modified. Expected behaviour is to throw an exception and to do not modify them.")
void lockSoftwareModuleApplied() {
final SoftwareModule softwareModule = testdataFactory.createSoftwareModule("sm-1");
final Long softwareModuleId = testdataFactory.createSoftwareModule("sm-1").getId();
artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(new byte[] { 1 }), softwareModule.getId(),
"artifact1", false, 1));
final int artifactCount = softwareModuleManagement.get(softwareModule.getId()).get().getArtifacts().size();
assertThat(artifactCount).isNotEqualTo(0);
softwareModuleManagement.lock(softwareModule.getId());
assertThat(
softwareModuleManagement.get(softwareModule.getId()).map(SoftwareModule::isLocked).orElse(false))
new ArtifactUpload(new ByteArrayInputStream(new byte[] { 1 }), softwareModuleId, "artifact1", false, 1));
final int artifactCount = softwareModuleManagement.get(softwareModuleId).get().getArtifacts().size();
assertThat(artifactCount).isNotZero();
softwareModuleManagement.lock(softwareModuleId);
assertThat(softwareModuleManagement.get(softwareModuleId).map(SoftwareModule::isLocked).orElse(false))
.isTrue();
// try add
final ArtifactUpload artifactUpload = new ArtifactUpload(new ByteArrayInputStream(new byte[] { 2 }), softwareModuleId, "artifact2", false, 1);
assertThatExceptionOfType(LockedException.class)
.as("Attempt to modify a locked SM artifacts should throw an exception")
.isThrownBy(() -> artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(new byte[] { 2 }), softwareModule.getId(),
"artifact2", false, 1)));
assertThat(softwareModuleManagement.get(softwareModule.getId()).get().getArtifacts().size())
.isThrownBy(() -> artifactManagement.create(artifactUpload));
assertThat(softwareModuleManagement.get(softwareModuleId).get().getArtifacts())
.as("Artifacts shall not be added to a locked SM.")
.isEqualTo(artifactCount);
.hasSize(artifactCount);
// try remove
final long artifactId = softwareModuleManagement.get(softwareModule.getId()).get()
.getArtifacts().stream().findFirst().get().getId();
final long artifactId = softwareModuleManagement.get(softwareModuleId).get().getArtifacts().stream().findFirst().get().getId();
assertThatExceptionOfType(LockedException.class)
.as("Attempt to modify a locked SM artifacts should throw an exception")
.isThrownBy(() -> artifactManagement.delete(artifactId));
assertThat(softwareModuleManagement.get(softwareModule.getId()).get().getArtifacts().size())
assertThat(softwareModuleManagement.get(softwareModuleId).get().getArtifacts())
.as("Artifact shall not be removed from a locked SM.")
.isEqualTo(artifactCount);
.hasSize(artifactCount);
assertThat(artifactManagement.get(artifactId))
.as("Artifact shall not be removed if belongs to a locked SM.")
.isPresent();
@@ -786,7 +783,7 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
void lockedContainingDistributionSetApplied() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-1");
final List<SoftwareModule> modules = distributionSet.getModules().stream().toList();
assertThat(modules.size()).isGreaterThan(1);
assertThat(modules).hasSizeGreaterThan(1);
// try delete while DS is not locked
softwareModuleManagement.delete(modules.get(0).getId());
@@ -797,9 +794,10 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
.isTrue();
// try delete SM of a locked DS
final Long moduleId = modules.get(1).getId();
assertThatExceptionOfType(LockedException.class)
.as("Attempt to delete a software module of a locked DS should throw an exception")
.isThrownBy(() -> softwareModuleManagement.delete(modules.get(1).getId()));
.isThrownBy(() -> softwareModuleManagement.delete(moduleId));
}
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
@@ -817,7 +815,6 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
cb.equal(root.get(JpaAction_.target).get(JpaTarget_.id), target.getId()),
cb.equal(root.get(JpaAction_.distributionSet).get(JpaDistributionSet_.id), ds.getId())),
PAGE).getContent().get(0);
;
assertThat(action).isNotNull();
return action;
}

View File

@@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
@Feature("SecurityTests - SoftwareModuleTypeManagement")
@Story("SecurityTests SoftwareModuleTypeManagement")
public class SoftwareModuleTypeManagementSecurityTest
class SoftwareModuleTypeManagementSecurityTest
extends AbstractRepositoryManagementSecurityTest<SoftwareModuleType, SoftwareModuleTypeCreate, SoftwareModuleTypeUpdate> {
@Override

View File

@@ -10,7 +10,7 @@
package org.eclipse.hawkbit.repository.jpa.management;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.util.Arrays;
import java.util.List;
@@ -32,13 +32,13 @@ import org.junit.jupiter.api.Test;
@Feature("Component Tests - Repository")
@Story("Software Module Management")
public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest {
class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() {
void nonExistingEntityAccessReturnsNotPresent() {
assertThat(softwareModuleTypeManagement.get(NOT_EXIST_IDL)).isNotPresent();
assertThat(softwareModuleTypeManagement.findByKey(NOT_EXIST_ID)).isNotPresent();
@@ -49,7 +49,7 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
verifyThrownExceptionBy(() -> softwareModuleTypeManagement.delete(NOT_EXIST_IDL), "SoftwareModuleType");
verifyThrownExceptionBy(
@@ -59,7 +59,7 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.")
public void updateNothingResultsInUnchangedRepositoryForType() {
void updateNothingResultsInUnchangedRepositoryForType() {
final SoftwareModuleType created = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
@@ -73,7 +73,7 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Calling update for changed fields results in change in the repository.")
public void updateSoftwareModuleTypeFieldsToNewValue() {
void updateSoftwareModuleTypeFieldsToNewValue() {
final SoftwareModuleType created = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
@@ -88,23 +88,19 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Create Software Module Types call fails when called for existing entities.")
public void createModuleTypesCallFailsForExistingTypes() {
void _for() {
final List<SoftwareModuleTypeCreate> created = Arrays.asList(
entityFactory.softwareModuleType().create().key("test-key").name("test-name"),
entityFactory.softwareModuleType().create().key("test-key2").name("test-name2"));
softwareModuleTypeManagement.create(created);
try {
softwareModuleTypeManagement.create(created);
fail("Should not have worked as module already exists.");
} catch (final EntityAlreadyExistsException e) {
}
assertThatExceptionOfType(EntityAlreadyExistsException.class)
.as("should not have worked as module type already exists")
.isThrownBy(() -> softwareModuleTypeManagement.create(created));
}
@Test
@Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).")
public void deleteAssignedAndUnassignedSoftwareModuleTypes() {
void deleteAssignedAndUnassignedSoftwareModuleTypes() {
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType);
SoftwareModuleType type = softwareModuleTypeManagement
@@ -140,64 +136,56 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Checks that software module typeis found based on given name.")
public void findSoftwareModuleTypeByName() {
void findSoftwareModuleTypeByName() {
testdataFactory.createSoftwareModuleOs();
final SoftwareModuleType found = softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("thetype2").name("anothername"));
assertThat(softwareModuleTypeManagement.findByName("thename").get()).as("Type with given name").isEqualTo(found);
assertThat(softwareModuleTypeManagement.findByName("thename")).as("Type with given name").contains(found);
}
@Test
@Description("Verifies that it is not possible to create a type that alrady exists.")
public void createSoftwareModuleTypeFailsWithExistingEntity() {
softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
try {
softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
fail("should not have worked as module type already exists");
} catch (final EntityAlreadyExistsException e) {
}
void createSoftwareModuleTypeFailsWithExistingEntity() {
final SoftwareModuleTypeCreate create = entityFactory.softwareModuleType().create().key("thetype").name("thename");
softwareModuleTypeManagement.create(create);
assertThatExceptionOfType(EntityAlreadyExistsException.class)
.as("should not have worked as module type already exists")
.isThrownBy(() -> softwareModuleTypeManagement
.create(create));
}
@Test
@Description("Verifies that it is not possible to create a list of types where one already exists.")
public void createSoftwareModuleTypesFailsWithExistingEntity() {
void createSoftwareModuleTypesFailsWithExistingEntity() {
softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
try {
softwareModuleTypeManagement
.create(Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
entityFactory.softwareModuleType().create().key("anothertype").name("anothername")));
fail("should not have worked as module type already exists");
} catch (final EntityAlreadyExistsException e) {
}
final List<SoftwareModuleTypeCreate> creates = List.of(
entityFactory.softwareModuleType().create().key("thetype").name("thename"),
entityFactory.softwareModuleType().create().key("anothertype").name("anothername"));
assertThatExceptionOfType(EntityAlreadyExistsException.class)
.as("should not have worked as module type already exists")
.isThrownBy(() -> softwareModuleTypeManagement.create(creates));
}
@Test
@Description("Verifies that the creation of a softwareModuleType is failing because of invalid max assignment")
public void createSoftwareModuleTypesFailsWithInvalidMaxAssignment() {
try {
softwareModuleTypeManagement
.create(entityFactory.softwareModuleType().create().key("type").name("name").maxAssignments(0));
fail("should not have worked as max assignment is invalid. Should be greater than 0.");
} catch (final ConstraintViolationException e) {
}
void createSoftwareModuleTypesFailsWithInvalidMaxAssignment() {
final SoftwareModuleTypeCreate create = entityFactory.softwareModuleType().create().key("type").name("name").maxAssignments(0);
assertThatExceptionOfType(ConstraintViolationException.class)
.as("should not have worked as max assignment is invalid. Should be greater than 0")
.isThrownBy(() -> softwareModuleTypeManagement.create(create));
}
@Test
@Description("Verifies that multiple types are created as requested.")
public void createMultipleSoftwareModuleTypes() {
void createMultipleSoftwareModuleTypes() {
final List<SoftwareModuleType> created = softwareModuleTypeManagement
.create(Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
entityFactory.softwareModuleType().create().key("thetype2").name("thename2")));
assertThat(created.size()).as("Number of created types").isEqualTo(2);
assertThat(created).as("Number of created types").hasSize(2);
assertThat(softwareModuleTypeManagement.count()).as("Number of types in repository").isEqualTo(5);
}

View File

@@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test;
@Slf4j
@Feature("SecurityTests - SystemManagement")
@Story("SecurityTests SystemManagement")
public class SystemManagementSecurityTest extends AbstractJpaIntegrationTest {
class SystemManagementSecurityTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")

View File

@@ -87,7 +87,7 @@ class SystemManagementTest extends AbstractJpaIntegrationTest {
// overall data
assertThat(systemManagement.getSystemUsageStatistics().getOverallTargets()).isEqualTo(200);
assertThat(systemManagement.getSystemUsageStatistics().getOverallActions()).isEqualTo(0);
assertThat(systemManagement.getSystemUsageStatistics().getOverallActions()).isZero();
// per tenant data
final List<TenantUsage> tenants = systemManagement.getSystemUsageStatisticsWithTenants().getTenants();
@@ -123,7 +123,7 @@ class SystemManagementTest extends AbstractJpaIntegrationTest {
private byte[] createTestTenantsForSystemStatistics(final int tenants, final int artifactSize, final int targets,
final int updates) throws Exception {
final Random randomgen = new Random();
final byte random[] = new byte[artifactSize];
final byte[] random = new byte[artifactSize];
randomgen.nextBytes(random);
for (int i = 0; i < tenants; i++) {

View File

@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
@Feature("SecurityTests - TargetFilterQueryManagement")
@Story("SecurityTests TargetFilterQueryManagement")
public class TargetFilterQueryManagementSecurityTest extends AbstractJpaIntegrationTest {
class TargetFilterQueryManagementSecurityTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")

View File

@@ -61,13 +61,13 @@ import org.springframework.data.domain.Slice;
*/
@Feature("Component Tests - Repository")
@Story("Target Filter Query Management")
public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest {
class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
public void nonExistingEntityAccessReturnsNotPresent() {
void nonExistingEntityAccessReturnsNotPresent() {
assertThat(targetFilterQueryManagement.get(NOT_EXIST_IDL)).isNotPresent();
assertThat(targetFilterQueryManagement.getByName(NOT_EXIST_ID)).isNotPresent();
}
@@ -79,7 +79,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = TargetFilterQueryCreatedEvent.class, count = 1) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
final DistributionSet set = testdataFactory.createDistributionSet();
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create(
entityFactory.targetFilterQuery().create().name("test filter").query("name==PendingTargets001"));
@@ -110,7 +110,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Test creation of target filter query.")
public void createTargetFilterQuery() {
void createTargetFilterQuery() {
final String filterName = "new target filter";
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
@@ -120,7 +120,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Create a target filter query with an auto-assign distribution set and a query string that addresses too many targets.")
public void createTargetFilterQueryThatExceedsQuota() {
void createTargetFilterQueryThatExceedsQuota() {
// create targets
final int maxTargets = quotaManagement.getMaxTargetsPerAutoAssignment();
@@ -135,7 +135,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Test searching a target filter query.")
public void searchTargetFilterQuery() {
void searchTargetFilterQuery() {
final String filterName = "targetFilterQueryName";
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
@@ -151,7 +151,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Test searching a target filter query with an invalid filter.")
public void searchTargetFilterQueryInvalidField() {
void searchTargetFilterQueryInvalidField() {
Assertions.assertThatExceptionOfType(RSQLParameterUnsupportedFieldException.class)
.isThrownBy(() -> targetFilterQueryManagement
.findByRsql(PageRequest.of(0, 10), "unknownField==testValue").getContent());
@@ -159,7 +159,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Checks if the EntityAlreadyExistsException is thrown if a targetfilterquery with the same name are created more than once.")
public void createDuplicateTargetFilterQuery() {
void createDuplicateTargetFilterQuery() {
final String filterName = "new target filter duplicate";
targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
@@ -172,7 +172,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Test deletion of target filter query.")
public void deleteTargetFilterQuery() {
void deleteTargetFilterQuery() {
final String filterName = "delete_target_filter_query";
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
@@ -183,7 +183,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Test updation of target filter query.")
public void updateTargetFilterQuery() {
void updateTargetFilterQuery() {
final String filterName = "target_filter_01";
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
@@ -197,7 +197,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Test assigning a distribution set for auto assignment with different action types")
public void assignDistributionSet() {
void assignDistributionSet() {
final String filterName = "target_filter_02";
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
@@ -218,7 +218,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Assigns a distribution set to an existing filter query and verifies that the quota 'max targets per auto assignment' is enforced.")
public void assignDistributionSetToTargetFilterQueryThatExceedsQuota() {
void assignDistributionSetToTargetFilterQueryThatExceedsQuota() {
// create targets
final int maxTargets = quotaManagement.getMaxTargetsPerAutoAssignment();
@@ -239,7 +239,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Updates an existing filter query with a query string that addresses too many targets.")
public void updateTargetFilterQueryWithQueryThatExceedsQuota() {
void updateTargetFilterQueryWithQueryThatExceedsQuota() {
// create targets
final int maxTargets = quotaManagement.getMaxTargetsPerAutoAssignment();
testdataFactory.createTargets(maxTargets + 1, "target%s");
@@ -256,7 +256,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Test removing distribution set while it has a relation to a target filter query")
public void removeAssignDistributionSet() {
void removeAssignDistributionSet() {
final String filterName = "target_filter_03";
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name(filterName).query("name==PendingTargets001"));
@@ -283,7 +283,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Test to implicitly remove the auto assign distribution set when the ds is soft deleted")
public void implicitlyRemoveAssignDistributionSet() {
void implicitlyRemoveAssignDistributionSet() {
final String filterName = "target_filter_03";
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dist_set");
final Target target = testdataFactory.createTarget();
@@ -319,7 +319,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Test finding and auto assign distribution set")
public void findFiltersWithDistributionSet() {
void findFiltersWithDistributionSet() {
final String filterName = "d";
assertEquals(0L, targetFilterQueryManagement.count());
targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create().name("a").query("name==*"));
@@ -351,7 +351,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Creating or updating a target filter query with autoassignment and no-value weight when multi assignment in enabled.")
public void weightNotRequiredInMultiAssignmentMode() {
void weightNotRequiredInMultiAssignmentMode() {
enableMultiAssignments();
final DistributionSet ds = testdataFactory.createDistributionSet();
final Long filterId = targetFilterQueryManagement
@@ -369,7 +369,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Creating or updating a target filter query with autoassignment with a weight causes an error when multi assignment in disabled.")
public void weightAllowedWhenMultiAssignmentModeNotEnabled() {
void weightAllowedWhenMultiAssignmentModeNotEnabled() {
final DistributionSet ds = testdataFactory.createDistributionSet();
final Long filterId = targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name("a").query("name==*")).getId();
@@ -387,7 +387,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Auto assignment can be removed from filter when multi assignment in enabled.")
public void removeDsFromFilterWhenMultiAssignmentModeNotEnabled() {
void removeDsFromFilterWhenMultiAssignmentModeNotEnabled() {
enableMultiAssignments();
final DistributionSet ds = testdataFactory.createDistributionSet();
final Long filterId = targetFilterQueryManagement
@@ -401,7 +401,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Weight is validated and saved to the Filter.")
public void weightValidatedAndSaved() {
void weightValidatedAndSaved() {
enableMultiAssignments();
final DistributionSet ds = testdataFactory.createDistributionSet();
@@ -411,8 +411,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
final Long filterId = targetFilterQueryManagement.create(entityFactory.targetFilterQuery().create().name("a")
.query("name==*").autoAssignDistributionSet(ds).autoAssignWeight(Action.WEIGHT_MAX)).getId();
assertThat(targetFilterQueryManagement.get(filterId).get().getAutoAssignWeight().get())
.isEqualTo(Action.WEIGHT_MAX);
assertThat(targetFilterQueryManagement.get(filterId).get().getAutoAssignWeight()).contains(Action.WEIGHT_MAX);
Assertions.assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> targetFilterQueryManagement.updateAutoAssignDS(entityFactory.targetFilterQuery()
@@ -424,13 +423,12 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
entityFactory.targetFilterQuery().updateAutoAssign(filterId).ds(ds.getId()).weight(Action.WEIGHT_MAX));
targetFilterQueryManagement.updateAutoAssignDS(
entityFactory.targetFilterQuery().updateAutoAssign(filterId).ds(ds.getId()).weight(Action.WEIGHT_MIN));
assertThat(targetFilterQueryManagement.get(filterId).get().getAutoAssignWeight().get())
.isEqualTo(Action.WEIGHT_MIN);
assertThat(targetFilterQueryManagement.get(filterId).get().getAutoAssignWeight()).contains(Action.WEIGHT_MIN);
}
@Test
@Description("Verifies that an exception is thrown when trying to create a target filter with an invalidated distribution set.")
public void createTargetFilterWithInvalidDistributionSet() {
void createTargetFilterWithInvalidDistributionSet() {
final DistributionSet distributionSet = testdataFactory.createAndInvalidateDistributionSet();
assertThatExceptionOfType(InvalidDistributionSetException.class)
@@ -442,7 +440,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Verifies that an exception is thrown when trying to create a target filter with an incomplete distribution set.")
public void createTargetFilterWithIncompleteDistributionSet() {
void createTargetFilterWithIncompleteDistributionSet() {
final DistributionSet distributionSet = testdataFactory.createIncompleteDistributionSet();
assertThatExceptionOfType(IncompleteDistributionSetException.class)
@@ -454,7 +452,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Verifies that an exception is thrown when trying to update a target filter with an invalidated distribution set.")
public void updateAutoAssignDsWithInvalidDistributionSet() {
void updateAutoAssignDsWithInvalidDistributionSet() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name("updateAutoAssignDsWithInvalidDistributionSet")
@@ -470,7 +468,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test
@Description("Verifies that an exception is thrown when trying to update a target filter with an incomplete distribution set.")
public void updateAutoAssignDsWithIncompleteDistributionSet() {
void updateAutoAssignDsWithIncompleteDistributionSet() {
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.create(
entityFactory.targetFilterQuery().create().name("updateAutoAssignDsWithIncompleteDistributionSet")

View File

@@ -41,7 +41,7 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that targets with given target type are returned from repository.")
public void findTargetByTargetType() {
void findTargetByTargetType() {
final TargetType testType = testdataFactory.createTargetType("testType",
Collections.singletonList(standardDsType));
final List<Target> unassigned = testdataFactory.createTargets(9, "unassigned");
@@ -451,12 +451,12 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
+ setA.getName() + ")";
assertThat(targetManagement.findByFilters(PAGE, filterParams).getContent())
.as("has number of elements")
.hasSize(0)
.as("that number is also returned by count query")
.hasSize((int) targetManagement.countByFilters(filterParams))
.as("and filter query returns the same result")
.hasSize(targetManagement.findByRsql(PAGE, query).getContent().size());
.hasSize(targetManagement.findByRsql(PAGE, query).getContent().size())
.as("has number of elements")
.isEmpty();
}
@Step
@@ -537,11 +537,13 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
targTagX.getName());
final String query = "(name==*targ-C* or description==*targ-C*) and tag==" + targTagX.getName()
+ " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")";
assertThat(targetManagement.findByFilters(PAGE, filterParams).getContent()).as("has number of elements")
.hasSize(0).as("that number is also returned by count query")
assertThat(targetManagement.findByFilters(PAGE, filterParams).getContent())
.as("that number is also returned by count query")
.hasSize((int) targetManagement.countByFilters(filterParams))
.as("and filter query returns the same result")
.hasSize(targetManagement.findByRsql(PAGE, query).getContent().size());
.hasSize(targetManagement.findByRsql(PAGE, query).getContent().size())
.as("has number of elements")
.isEmpty();
}
@Step
@@ -550,11 +552,12 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
targTagW.getName());
final String query = "(name==*targ-A* or description==*targ-A*) and tag==" + targTagW.getName()
+ " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")";
assertThat(targetManagement.findByFilters(PAGE, filterParams).getContent()).as("has number of elements")
.hasSize(0).as("that number is also returned by count query")
assertThat(targetManagement.findByFilters(PAGE, filterParams).getContent())
.hasSize((int) targetManagement.countByFilters(filterParams))
.as("and filter query returns the same result")
.hasSize(targetManagement.findByRsql(PAGE, query).getContent().size());
.hasSize(targetManagement.findByRsql(PAGE, query).getContent().size())
.as("has number of elements")
.isEmpty();
}
@Step

View File

@@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
@Slf4j
@Feature("SecurityTests - TargetManagement")
@Story("SecurityTests TargetManagement")
public class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")

View File

@@ -260,13 +260,12 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
final TargetTag targetTag = targetTagManagement.create(entityFactory.tag().create().name("Tag1"));
final List<Target> assignedTargets = targetManagement.assignTag(assignTarget, targetTag.getId());
assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4);
assignedTargets.forEach(target -> assertThat(
getTargetTags(target.getControllerId()).size()).isEqualTo(1));
assertThat(assignedTargets).as("Assigned targets are wrong").hasSize(4);
assignedTargets.forEach(target -> assertThat(getTargetTags(target.getControllerId())).hasSize(1));
final TargetTag findTargetTag = targetTagManagement.getByName("Tag1").orElseThrow(IllegalStateException::new);
assertThat(assignedTargets.size()).as("Assigned targets are wrong")
.isEqualTo(targetManagement.findByTag(PAGE, targetTag.getId()).getNumberOfElements());
assertThat(assignedTargets).as("Assigned targets are wrong")
.hasSize(targetManagement.findByTag(PAGE, targetTag.getId()).getNumberOfElements());
final Target unAssignTarget = targetManagement.unassignTag(List.of("targetId123"), findTargetTag.getId()).get(0);
assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123");
@@ -692,7 +691,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
.findByFilters(PAGE, new FilterParams(null, null, null, null, Boolean.TRUE, tagNames)).getContent();
assertThat(targetManagement.count()).as("Total targets").isEqualTo(50L);
assertThat(targetsListWithNoTag.size()).as("Targets with no tag").isEqualTo(25);
assertThat(targetsListWithNoTag).as("Targets with no tag").hasSize(25);
}
@@ -1412,7 +1411,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
private void checkTargetsHaveType(final List<Target> targets, final TargetType type) {
final List<JpaTarget> foundTargets = targetRepository
.findAllById(targets.stream().map(Identifiable::getId).collect(Collectors.toList()));
.findAllById(targets.stream().map(Identifiable::getId).toList());
for (final Target target : foundTargets) {
if (!type.getName().equals(type.getName())) {
fail(String.format("Target %s is not of type %s.", target, type));

View File

@@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test;
@Slf4j
@Feature("SecurityTests - TargetTagManagement")
@Story("SecurityTests TargetTagManagement")
public class TargetTagManagementSecurityTest extends AbstractJpaIntegrationTest {
class TargetTagManagementSecurityTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")

View File

@@ -19,7 +19,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import jakarta.validation.ConstraintViolationException;
@@ -58,7 +57,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
void failOnMissingDs() {
final Collection<String> group = testdataFactory.createTargets(5).stream()
.map(Target::getControllerId)
.collect(Collectors.toList());
.toList();
final TargetTag tag = targetTagManagement.create(entityFactory.tag().create().name("tag1").description("tagdesc1"));
final List<String> missing = new ArrayList<>();
@@ -75,12 +74,10 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
final Collection<String> withMissing = concat(group, missing);
assertThatThrownBy(() -> targetManagement.assignTag(withMissing, tag.getId()))
.matches(e -> {
if (e instanceof EntityNotFoundException enfe) {
if (enfe.getInfo().get(EntityNotFoundException.TYPE).equals(Target.class.getSimpleName())) {
if (enfe.getInfo().get(EntityNotFoundException.ENTITY_ID) instanceof Collection entityId) {
return entityId.stream().sorted().toList().equals(missing);
}
}
if (e instanceof EntityNotFoundException enfe
&& enfe.getInfo().get(EntityNotFoundException.TYPE).equals(Target.class.getSimpleName())
&& enfe.getInfo().get(EntityNotFoundException.ENTITY_ID) instanceof Collection entityId) {
return entityId.stream().sorted().toList().equals(missing);
}
return false;
});
@@ -99,7 +96,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
@Description("Verifies that management queries react as specfied on calls for non existing entities " +
" by means of throwing EntityNotFoundException.")
@ExpectEvents({
@Expect(type = DistributionSetTagUpdatedEvent.class),
@Expect(type = DistributionSetTagUpdatedEvent.class),
@Expect(type = TargetTagUpdatedEvent.class) })
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
verifyThrownExceptionBy(() -> targetTagManagement.delete(NOT_EXIST_ID), "TargetTag");
@@ -126,9 +123,10 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
// toggle A only -> A is now assigned
List<Target> result = assignTag(groupA, tag);
assertThat(result).size().isEqualTo(20);
assertThat(result).containsAll(
targetManagement.getByControllerID(groupA.stream().map(Target::getControllerId).collect(Collectors.toList())));
assertThat(result)
.containsAll(
targetManagement.getByControllerID(groupA.stream().map(Target::getControllerId).toList()))
.size().isEqualTo(20);
assertThat(targetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent().stream().map(Target::getControllerId).sorted()
.toList())
.isEqualTo(groupA.stream().map(Target::getControllerId).sorted().toList());
@@ -136,18 +134,19 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
// toggle A+B -> A is still assigned and B is assigned as well
final Collection<Target> groupAB = concat(groupA, groupB);
result = assignTag(groupAB, tag);
assertThat(result).size().isEqualTo(40);
assertThat(result).containsAll(
targetManagement.getByControllerID(groupAB.stream().map(Target::getControllerId).collect(Collectors.toList())));
assertThat(result)
.containsAll(
targetManagement.getByControllerID(groupAB.stream().map(Target::getControllerId).toList()))
.size().isEqualTo(40);
assertThat(targetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent().stream().map(Target::getControllerId).sorted()
.toList())
.isEqualTo(groupAB.stream().map(Target::getControllerId).sorted().toList());
// toggle A+B -> both unassigned
result = unassignTag(groupAB, tag);
assertThat(result).size().isEqualTo(40);
assertThat(result).containsAll(
targetManagement.getByControllerID(groupAB.stream().map(Target::getControllerId).collect(Collectors.toList())));
assertThat(result)
.containsAll(targetManagement.getByControllerID(groupAB.stream().map(Target::getControllerId).toList()))
.size().isEqualTo(40);
assertThat(targetManagement.findByTag(Pageable.unpaged(), tag.getId()).getContent()).isEmpty();
}

View File

@@ -35,18 +35,18 @@ import org.springframework.data.jpa.domain.Specification;
@Feature("Unit Tests - Repository")
@Story("Specifications builder")
public class SpecificationsBuilderTest {
class SpecificationsBuilderTest {
@Test
@Description("Test the combination of specs on an empty list which returns null")
public void combineWithAndEmptyList() {
void combineWithAndEmptyList() {
final List<Specification<Object>> specList = Collections.emptyList();
assertThat(SpecificationsBuilder.combineWithAnd(specList)).isNull();
}
@Test
@Description("Test the combination of specs on an immutable list with one entry")
public void combineWithAndSingleImmutableList() {
void combineWithAndSingleImmutableList() {
final Specification<Object> spec = (root, query, cb) -> cb.equal(root.get("field1"), "testValue");
final List<Specification<Object>> specList = Collections.singletonList(spec);
final Specification<Object> specifications = SpecificationsBuilder.combineWithAnd(specList);
@@ -70,7 +70,7 @@ public class SpecificationsBuilderTest {
@Test
@Description("Test the combination of specs on a list with multiple entries")
public void combineWithAndList() {
void combineWithAndList() {
final Specification<Object> spec1 = (root, query, cb) -> cb.equal(root.get("field1"), "testValue1");
final Specification<Object> spec2 = (root, query, cb) -> cb.equal(root.get("field2"), "testValue2");
@@ -93,7 +93,7 @@ public class SpecificationsBuilderTest {
when(criteriaBuilder.equal(any(Path.class), eq("testValue1"))).thenReturn(equalPredicate1);
when(criteriaBuilder.equal(any(Path.class), eq("testValue2"))).thenReturn(equalPredicate2);
when(criteriaBuilder.and(eq(equalPredicate1), eq(equalPredicate2))).thenReturn(combinedPredicate);
when(criteriaBuilder.and(equalPredicate1, equalPredicate2)).thenReturn(combinedPredicate);
when(root.get("field1")).thenReturn(field1);
when(root.get("field2")).thenReturn(field2);

View File

@@ -92,6 +92,7 @@ public class SecurityContextSwitch {
}
// should be used only for test purposes and taking in account 'annotation' non-transient field in a Serializable
@SuppressWarnings("java:S1948") // java:S1948 - see comments into the method
static class WithUserSecurityContext implements SecurityContext {
@Serial