Support keywords in queries (#1193)
* support targettype as keyword in target-queries Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * support valid as keyword in distributionset-queries Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * remove targettype.id from filter queries Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io> * remove targettype.description from filter queries Signed-off-by: Natalia Kislicyn <natalia.kislicyn@bosch.io>
This commit is contained in:
@@ -63,7 +63,12 @@ public enum DistributionSetFields implements FieldNameProvider {
|
||||
/**
|
||||
* The metadata.
|
||||
*/
|
||||
METADATA("metadata", new SimpleImmutableEntry<>("key", "value"));
|
||||
METADATA("metadata", new SimpleImmutableEntry<>("key", "value")),
|
||||
|
||||
/**
|
||||
* The valid field.
|
||||
*/
|
||||
VALID("valid");
|
||||
|
||||
private final String fieldName;
|
||||
private boolean mapField;
|
||||
|
||||
@@ -85,7 +85,12 @@ public enum TargetFields implements FieldNameProvider {
|
||||
/**
|
||||
* The metadata.
|
||||
*/
|
||||
METADATA("metadata", new SimpleImmutableEntry<>("key", "value"));
|
||||
METADATA("metadata", new SimpleImmutableEntry<>("key", "value")),
|
||||
|
||||
/**
|
||||
* The target type.
|
||||
*/
|
||||
TARGETTYPE("targetType", TargetTypeFields.NAME.getFieldName());
|
||||
|
||||
private final String fieldName;
|
||||
private List<String> subEntityAttribues;
|
||||
|
||||
@@ -57,8 +57,9 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
distributionSetManagement.assignTag(Arrays.asList(ds.getId(), ds2.getId()), distSetTag.getId());
|
||||
|
||||
distributionSetManagement
|
||||
final DistributionSet ds3 = distributionSetManagement
|
||||
.create(entityFactory.distributionSet().create().name("test123").version("noDescription"));
|
||||
distributionSetManagement.invalidate(ds3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,7 +120,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by complete property")
|
||||
public void testFilterByAttribute() {
|
||||
public void testFilterByAttributeComplete() {
|
||||
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==true", 4);
|
||||
try {
|
||||
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==noExist*", 0);
|
||||
@@ -130,6 +131,17 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
|
||||
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=out=(true)", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by valid property")
|
||||
public void testFilterByAttributeValid() {
|
||||
assertRSQLQuery(DistributionSetFields.VALID.name() + "==true", 4);
|
||||
assertRSQLQuery(DistributionSetFields.VALID.name() + "==false", 1);
|
||||
assertThatExceptionOfType(RSQLParameterSyntaxException.class)
|
||||
.isThrownBy(() -> assertRSQLQuery(DistributionSetFields.VALID.name() + "==noExist*", 0));
|
||||
assertRSQLQuery(DistributionSetFields.VALID.name() + "=in=(true)", 4);
|
||||
assertRSQLQuery(DistributionSetFields.VALID.name() + "=out=(true)", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test filter distribution set by tag name")
|
||||
public void testFilterByTag() {
|
||||
@@ -177,11 +189,11 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedEntity) {
|
||||
final Page<DistributionSet> find = distributionSetManagement.findByRsql(PageRequest.of(0, 100), rsqlParam);
|
||||
final long countAll = find.getTotalElements();
|
||||
assertThat(find).as("Founded entity is should not be null").isNotNull();
|
||||
assertThat(countAll).as("Founded entity size is wrong").isEqualTo(excpectedEntity);
|
||||
assertThat(find).as("Found entity is should not be null").isNotNull();
|
||||
assertThat(countAll).as("Found entity size is wrong").isEqualTo(expectedEntity);
|
||||
}
|
||||
|
||||
private <T extends Throwable> void assertRSQLQueryThrowsException(final String rsqlParam,
|
||||
|
||||
@@ -18,11 +18,13 @@ import java.util.Map;
|
||||
|
||||
import org.assertj.core.util.Maps;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeFields;
|
||||
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.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -38,6 +40,8 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Target target;
|
||||
private Target target2;
|
||||
private TargetType targetType1;
|
||||
private TargetType targetType2;
|
||||
|
||||
private static final String OR = ",";
|
||||
private static final String AND = ";";
|
||||
@@ -83,6 +87,12 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
targetTag3.getId());
|
||||
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
|
||||
targetType1 = targetTypeManagement.create(entityFactory.targetType().create().name("Type1").description("Desc. Type1"));
|
||||
targetType2 = targetTypeManagement.create(entityFactory.targetType().create().name("Type2").description("Desc. Type2"));
|
||||
|
||||
targetManagement.assignType(target.getControllerId(), targetType1.getId());
|
||||
targetManagement.assignType(target2.getControllerId(), targetType2.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -296,11 +306,25 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
RSQLUtility.validateRsqlFor(rsql6, TargetFields.class);
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) {
|
||||
@Test
|
||||
@Description("Test filter by target type")
|
||||
public void shouldFilterTargetsByTypeIdNameAndDescription() {
|
||||
assertRSQLQuery("targettype." + TargetTypeFields.NAME.name() + "==" + targetType1.getName(), 1);
|
||||
assertRSQLQuery("targettype." + TargetTypeFields.NAME.name() + "==*1", 1);
|
||||
assertRSQLQuery("targettype." + TargetTypeFields.NAME.name() + "!=" + targetType2.getName(), 4);
|
||||
assertRSQLQuery("targettype." + TargetTypeFields.NAME.name() + "==noExist*", 0);
|
||||
|
||||
assertThatExceptionOfType(RSQLParameterUnsupportedFieldException.class)
|
||||
.isThrownBy(() -> assertRSQLQuery("targettype.ID==1", 0));
|
||||
assertThatExceptionOfType(RSQLParameterUnsupportedFieldException.class)
|
||||
.isThrownBy(() -> assertRSQLQuery("targettype.description==Description", 0));
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedTargets) {
|
||||
final Page<Target> findTargetPage = targetManagement.findByRsql(PAGE, rsqlParam);
|
||||
final long countTargetsAll = findTargetPage.getTotalElements();
|
||||
assertThat(findTargetPage).isNotNull();
|
||||
assertThat(countTargetsAll).isEqualTo(expcetedTargets);
|
||||
assertThat(countTargetsAll).isEqualTo(expectedTargets);
|
||||
}
|
||||
|
||||
private <T extends Throwable> void assertRSQLQueryThrowsException(final String rsqlParam,
|
||||
|
||||
Reference in New Issue
Block a user