Add JpaTargetFilterQuery converter test (#2049)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-16 12:13:22 +02:00
committed by GitHub
parent 4545849548
commit 1c40584733
4 changed files with 44 additions and 16 deletions

View File

@@ -169,8 +169,7 @@ public interface TargetFilterQueryManagement {
Page<TargetFilterQuery> findByAutoAssignDSAndRsql(@NotNull Pageable pageable, long setId, String rsqlParam); Page<TargetFilterQuery> findByAutoAssignDSAndRsql(@NotNull Pageable pageable, long setId, String rsqlParam);
/** /**
* Retrieves all {@link TargetFilterQuery}s with an auto-assign distribution * Retrieves all {@link TargetFilterQuery}s with an auto-assign distribution set.
* set.
* *
* @param pageable pagination information * @param pageable pagination information
* @return the page with the found {@link TargetFilterQuery}s * @return the page with the found {@link TargetFilterQuery}s

View File

@@ -9,6 +9,7 @@
*/ */
package org.eclipse.hawkbit.repository.jpa.model; package org.eclipse.hawkbit.repository.jpa.model;
import java.io.Serial;
import java.util.Optional; import java.util.Optional;
import jakarta.persistence.Column; import jakarta.persistence.Column;
@@ -37,14 +38,14 @@ import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
* Stored target filter. * Stored target filter.
*/ */
@Entity @Entity
@Table(name = "sp_target_filter_query", uniqueConstraints = @UniqueConstraint(columnNames = { "name", @Table(
"tenant" }, name = "uk_tenant_custom_filter_name")) name = "sp_target_filter_query",
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_tenant_custom_filter_name"))
// sub entities // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities
@SuppressWarnings("squid:S2160") @SuppressWarnings("squid:S2160")
public class JpaTargetFilterQuery extends AbstractJpaTenantAwareBaseEntity public class JpaTargetFilterQuery extends AbstractJpaTenantAwareBaseEntity implements TargetFilterQuery, EventAwareEntity {
implements TargetFilterQuery, EventAwareEntity {
@Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Column(name = "name", length = NamedEntity.NAME_MAX_SIZE, nullable = false) @Column(name = "name", length = NamedEntity.NAME_MAX_SIZE, nullable = false)

View File

@@ -47,13 +47,12 @@ import org.springframework.util.CollectionUtils;
class RolloutGroupManagementTest extends AbstractJpaIntegrationTest { class RolloutGroupManagementTest extends AbstractJpaIntegrationTest {
@Test @Test
@Description("Verifies that management get access reacts as specfied on calls for non existing entities by means " @Description("Verifies that management get access reacts as specified on calls for non existing entities by means " +
+ "of Optional not present.") "of Optional not present.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) })
void nonExistingEntityAccessReturnsNotPresent() { void nonExistingEntityAccessReturnsNotPresent() {
assertThat(rolloutGroupManagement.get(NOT_EXIST_IDL)).isNotPresent(); assertThat(rolloutGroupManagement.get(NOT_EXIST_IDL)).isNotPresent();
assertThat(rolloutGroupManagement.getWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent(); assertThat(rolloutGroupManagement.getWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent();
} }
@Test @Test
@@ -219,7 +218,7 @@ class RolloutGroupManagementTest extends AbstractJpaIntegrationTest {
} }
@Test @Test
@Description("Tests the rollout status mapping.") @Description("Tests the rollout group status mapping.")
void testRolloutGroupStatusConvert() { void testRolloutGroupStatusConvert() {
final long id = rolloutGroupRepository.findByRolloutId( final long id = rolloutGroupRepository.findByRolloutId(
testdataFactory.createAndStartRollout(1, 0, 1, "100", "80").getId(), PAGE).getContent() testdataFactory.createAndStartRollout(1, 0, 1, "100", "80").getId(), PAGE).getContent()
@@ -282,5 +281,4 @@ class RolloutGroupManagementTest extends AbstractJpaIntegrationTest {
private Target reloadTarget(final Target targetCancelled) { private Target reloadTarget(final Target targetCancelled) {
return targetManagement.get(targetCancelled.getId()).orElseThrow(); return targetManagement.get(targetCancelled.getId()).orElseThrow();
} }
}
}

View File

@@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.Supplier;
import jakarta.validation.ConstraintViolationException; import jakarta.validation.ConstraintViolationException;
@@ -27,6 +28,7 @@ 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.assertj.core.api.Assertions; import org.assertj.core.api.Assertions;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.builder.AutoAssignDistributionSetUpdate; import org.eclipse.hawkbit.repository.builder.AutoAssignDistributionSetUpdate;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
@@ -41,6 +43,7 @@ import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignActionTypeExcep
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException; import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery;
import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -236,7 +239,6 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
@Test @Test
@Description("Updates an existing filter query with a query string that addresses too many targets.") @Description("Updates an existing filter query with a query string that addresses too many targets.")
public void updateTargetFilterQueryWithQueryThatExceedsQuota() { public void updateTargetFilterQueryWithQueryThatExceedsQuota() {
// create targets // create targets
final int maxTargets = quotaManagement.getMaxTargetsPerAutoAssignment(); final int maxTargets = quotaManagement.getMaxTargetsPerAutoAssignment();
testdataFactory.createTargets(maxTargets + 1, "target%s"); testdataFactory.createTargets(maxTargets + 1, "target%s");
@@ -389,7 +391,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
final DistributionSet ds = testdataFactory.createDistributionSet(); final DistributionSet ds = testdataFactory.createDistributionSet();
final Long filterId = targetFilterQueryManagement final Long filterId = targetFilterQueryManagement
.create(entityFactory.targetFilterQuery().create().name("a") .create(entityFactory.targetFilterQuery().create().name("a")
.query("name==*").autoAssignDistributionSet(ds).autoAssignWeight(23)).getId(); .query("name==*").autoAssignDistributionSet(ds).autoAssignWeight(23)).getId();
assertThat( assertThat(
targetFilterQueryManagement targetFilterQueryManagement
.updateAutoAssignDS(entityFactory.targetFilterQuery().updateAutoAssign(filterId).ds(null).weight(null))) .updateAutoAssignDS(entityFactory.targetFilterQuery().updateAutoAssign(filterId).ds(null).weight(null)))
@@ -481,6 +483,34 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
.ds(incompleteDistributionSet.getId()))); .ds(incompleteDistributionSet.getId())));
} }
@Test
@Description("Tests the auto assign action type mapping.")
void testAutoAssignActionTypeConvert() {
for (final ActionType actionType : ActionType.values()) {
final Supplier<Long> create = () ->
targetFilterQueryManagement.create(
entityFactory.targetFilterQuery()
.create()
.name("testAutoAssignActionTypeConvert_" + actionType)
.query("name==*")
.autoAssignActionType(actionType))
.getId();
if (actionType == ActionType.TIMEFORCED) {
assertThatExceptionOfType(AbstractServerRtException.class).isThrownBy(create::get);
} else {
assertThat(targetFilterQueryManagement.get(create.get()).orElseThrow().getAutoAssignActionType()).isEqualTo(actionType);
}
}
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() ->
((JpaTargetFilterQuery) targetFilterQueryManagement.create(
entityFactory.targetFilterQuery()
.create()
.name("testAutoAssignActionTypeConvert")
.query("name==*")))
.setAutoAssignActionType(ActionType.TIMEFORCED));
}
@Step @Step
private void verifyAutoAssignmentWithDefaultActionType(final String filterName, private void verifyAutoAssignmentWithDefaultActionType(final String filterName,
final TargetFilterQuery targetFilterQuery, final DistributionSet distributionSet) { final TargetFilterQuery targetFilterQuery, final DistributionSet distributionSet) {