- Fix conversion for boolean for sql query. If boolean is not wellformed
a rsql syntax error is thrown
- Escape % for sql query#
- Remove operator like ("=li=")
- Extend not equal operator with not like jpa query
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -44,7 +44,7 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
|
||||
final DistributionSet ds2 = TestDataUtil
|
||||
.generateDistributionSets("NewDS", 3, softwareManagement, distributionSetManagement).get(0);
|
||||
|
||||
ds2.setDescription("DS2");
|
||||
ds2.setDescription("DS%");
|
||||
ds2.getMetadata().add(new DistributionSetMetadata("metaKey", ds2, "value"));
|
||||
distributionSetManagement.updateDistributionSet(ds2);
|
||||
|
||||
@@ -77,6 +77,7 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
|
||||
public void testFilterByParameterDescription() {
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "==DS", 1);
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "==DS*", 2);
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "==DS%", 1);
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "=in=(DS,notexist)", 1);
|
||||
assertRSQLQuery(DistributionSetFields.DESCRIPTION.name() + "=out=(DS,notexist)", 3);
|
||||
@@ -99,7 +100,6 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest {
|
||||
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "==noExist*", 0);
|
||||
fail();
|
||||
} catch (final RSQLParameterSyntaxException e) {
|
||||
// excepted
|
||||
}
|
||||
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=in=(true)", 4);
|
||||
assertRSQLQuery(DistributionSetFields.COMPLETE.name() + "=out=(true)", 0);
|
||||
|
||||
@@ -61,6 +61,7 @@ public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest {
|
||||
public void testFilterByParameterName() {
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "==agent-hub", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "==agent-hub*", 2);
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "!=agent-hub*", 2);
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "==noExist*", 0);
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "=in=(agent-hub,notexist)", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.NAME.name() + "=out=(agent-hub,notexist)", 3);
|
||||
@@ -94,12 +95,12 @@ public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("")
|
||||
@Description("Test filter software module by metadata")
|
||||
public void testFilterByMetadata() {
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey==metaValue", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey==*v*", 2);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey==noExist*", 0);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey=in=(metaValue,notexist)", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey=in=(metaValue,value)", 2);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".metaKey=out=(metaValue,notexist)", 1);
|
||||
assertRSQLQuery(SoftwareModuleFields.METADATA.name() + ".notExist==metaValue", 0);
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ public class RSQLUtilityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctRsqlBuildsNotEqualPredicate() {
|
||||
public void correctRsqlBuildsNotLikePredicate() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String correctRsql = "name!=abc";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
@@ -164,13 +164,37 @@ public class RSQLUtilityTest {
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
|
||||
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
verify(criteriaBuilderMock, times(1)).and(any(Predicate.class));
|
||||
verify(criteriaBuilderMock, times(1)).notEqual(eq(baseSoftwareModuleRootMock), eq("abc"));
|
||||
verify(criteriaBuilderMock, times(1)).notLike(eq(pathOfString(baseSoftwareModuleRootMock)),
|
||||
eq("abc".toUpperCase()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctRsqlBuildsLikePredicateWithPercentage() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String correctRsql = "name==a%";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
|
||||
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
verify(criteriaBuilderMock, times(1)).and(any(Predicate.class));
|
||||
verify(criteriaBuilderMock, times(1)).like(eq(pathOfString(baseSoftwareModuleRootMock)),
|
||||
eq("a\\%".toUpperCase()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,27 +215,6 @@ public class RSQLUtilityTest {
|
||||
verify(criteriaBuilderMock, times(1)).lessThan(eq(pathOfString(baseSoftwareModuleRootMock)), eq("abc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctRsqlBuildsLikePredicate() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
final String correctRsql = "name=li=abc";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
|
||||
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verfication
|
||||
verify(criteriaBuilderMock, times(1)).and(any(Predicate.class));
|
||||
verify(criteriaBuilderMock, times(1)).like(eq(pathOfString(baseSoftwareModuleRootMock)),
|
||||
eq("abc".toUpperCase()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctRsqlWithEnumValue() {
|
||||
reset(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
Reference in New Issue
Block a user