use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.
the class JsonToFilterMapperTest method values_filter.
@Test
public void values_filter() throws Exception {
Map<String, Object> value = new HashMap<>();
List<String> values = List.of("fisk", "ost", "løk");
final HashMap<String, Object> valueFilter = new HashMap<>();
valueFilter.put("field", "myField");
valueFilter.put("values", values);
value.put("hasValue", valueFilter);
final Filters filters = com.enonic.xp.lib.common.JsonToFilterMapper.create(value);
assertTrue(filters.get(0) instanceof ValueFilter);
assertEquals("myField", ((ValueFilter) filters.get(0)).getFieldName());
assertEquals(3, ((ValueFilter) filters.get(0)).getValues().size());
}
use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.
the class FilterBuilderFactoryTest method createNumberValueFilter.
@Test
public void createNumberValueFilter() throws Exception {
final ValueFilter queryFilter = ValueFilter.create().fieldName("myField").addValue(ValueFactory.newDouble(1.0)).addValue(ValueFactory.newDouble(2.0)).build();
final String expected = load("filter_values_number.json");
final QueryBuilder filterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(queryFilter));
assertEquals(cleanString(expected), cleanString(filterBuilder.toString()));
}
use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.
the class FilterBuilderFactoryTest method createStringValueFilter.
@Test
public void createStringValueFilter() throws Exception {
final ValueFilter queryFilter = ValueFilter.create().fieldName("myField").addValue(ValueFactory.newString("myValue1")).addValue(ValueFactory.newString("myValue2")).build();
final String expected = load("filter_values_string.json");
final QueryBuilder filterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(queryFilter));
assertEquals(cleanString(expected), cleanString(filterBuilder.toString()));
}
use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.
the class AclFilterBuilderFactoryTest method anonymous.
@Test
public void anonymous() throws Exception {
final Filter filter = AclFilterBuilderFactory.create(PrincipalKeys.empty());
assertTrue(filter instanceof ValueFilter);
ValueFilter valueFilter = (ValueFilter) filter;
assertEquals(1, valueFilter.getValues().size());
}
use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.
the class AclFilterBuilderFactoryTest method testName.
@Test
public void testName() throws Exception {
final Principals principals = Principals.from(User.create().email("rmy@enonic.com").login("rmy").displayName("Runar Myklebust").key(PrincipalKey.from("user:system:rmy")).build(), Group.create().key(PrincipalKey.from("group:system:mygroup")).displayName("My group").build());
final Filter filter = AclFilterBuilderFactory.create(principals.getKeys());
assertTrue(filter instanceof ValueFilter);
ValueFilter valueFilter = (ValueFilter) filter;
assertEquals(2, valueFilter.getValues().size());
}
Aggregations