Filter Distribution Sets by assigned Software Modules (#1386)

* Filter Distribution Sets by assigned Software Modules

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

* Fixed tests

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>

---------

Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>
This commit is contained in:
Denislav Prinov
2023-07-10 15:19:08 +03:00
committed by GitHub
parent 5edd9fdf76
commit 2fe73ee40c
2 changed files with 42 additions and 11 deletions

View File

@@ -9,6 +9,9 @@
package org.eclipse.hawkbit.repository;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
@@ -49,22 +52,22 @@ public enum DistributionSetFields implements FieldNameProvider {
* The id field.
*/
ID("id"),
/**
* The module field.
*/
MODULE("modules", SoftwareModuleFields.ID.getFieldName(), SoftwareModuleFields.NAME.getFieldName()),
/**
* The tags field.
*/
TAG("tags.name"),
/**
* The sw type key field.
*/
TYPE("type.key"),
/**
* The metadata.
*/
METADATA("metadata", new SimpleImmutableEntry<>("key", "value")),
/**
* The valid field.
*/
@@ -74,19 +77,31 @@ public enum DistributionSetFields implements FieldNameProvider {
private boolean mapField;
private Entry<String, String> subEntityMapTuple;
private final List<String> subEntityAttributes;
private DistributionSetFields(final String fieldName) {
this(fieldName, false, null);
this(fieldName, false, null, Collections.emptyList());
}
private DistributionSetFields(final String fieldName, final String... subEntityAttributes) {
this(fieldName, false, null, Arrays.asList(subEntityAttributes));
}
private DistributionSetFields(final String fieldName, final Entry<String, String> subEntityMapTuple) {
this(fieldName, true, subEntityMapTuple);
this(fieldName, true, subEntityMapTuple, Collections.emptyList());
}
private DistributionSetFields(final String fieldName, final boolean mapField,
final Entry<String, String> subEntityMapTuple) {
final Entry<String, String> subEntityMapTuple, List<String> subEntityAttributes) {
this.fieldName = fieldName;
this.mapField = mapField;
this.subEntityMapTuple = subEntityMapTuple;
this.subEntityAttributes = subEntityAttributes;
}
@Override
public List<String> getSubEntityAttributes() {
return Collections.unmodifiableList(subEntityAttributes);
}
@Override

View File

@@ -13,13 +13,16 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays;
import java.util.Collections;
import org.eclipse.hawkbit.repository.DistributionSetFields;
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -36,11 +39,14 @@ import io.qameta.allure.Story;
public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
private DistributionSet ds;
private SoftwareModule sm;
@BeforeEach
public void setupBeforeTest() {
ds = testdataFactory.createDistributionSet("DS");
sm = testdataFactory.createSoftwareModuleApp("SM");
ds = testdataFactory.createDistributionSet(Collections.singletonList(sm),"DS");
ds = distributionSetManagement.update(entityFactory.distributionSet().update(ds.getId()).description("DS"));
createDistributionSetMetadata(ds.getId(), entityFactory.generateDsMetadata("metaKey", "metaValue"));
@@ -92,6 +98,16 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
assertRSQLQuery(DistributionSetFields.NAME.name() + "=out=(DS,notexist)", 4);
}
@Test
@Description("Test filter distribution set by assigned software module")
public void testFilterBySoftwareModule() {
assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.NAME.name() + "==" + sm.getName(), 1);
assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "==" + sm.getId(), 1);
assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.NAME.name() + "==noExist", 0);
assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "=in=(" + sm.getId() + ", noExist)", 1);
assertRSQLQuery(DistributionSetFields.MODULE.name() + "." + SoftwareModuleFields.ID.name() + "=out=(" + sm.getId() + ", noExist)", 4);
}
@Test
@Description("Test filter distribution set by description")
public void testFilterByParameterDescription() {
@@ -121,14 +137,14 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
@Test
@Description("Test filter distribution set by complete property")
public void testFilterByAttributeComplete() {
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==true", 4);
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==true", 3);
try {
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==noExist*", 0);
fail("Expected RSQLParameterSyntaxException");
} catch (final RSQLParameterSyntaxException e) {
}
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=in=(true)", 4);
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=out=(true)", 1);
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=in=(true)", 3);
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=out=(true)", 2);
}
@Test