catalog.add(ft2 = newFeatureType("ft2", ds));
catalog.add(ft3 = newFeatureType("ft3", ds));
ft1 = catalog.getFeatureType(ft1.getId());
ft2 = catalog.getFeatureType(ft2.getId());
ft3 = catalog.getFeatureType(ft3.getId());
ft1.getKeywords().add(new Keyword("keyword1"));
ft1.getKeywords().add(new Keyword("keyword2"));
ft1.getKeywords().add(new Keyword("ft1"));
ft1.setDescription("ft1 description");
catalog.save(ft1);
ft2.getKeywords().add(new Keyword("keyword1"));
ft2.getKeywords().add(new Keyword("keyword1"));
ft2.setDescription("ft2");
catalog.save(ft2);
ft3.getKeywords().add(new Keyword("ft3"));
ft3.getKeywords().add(new Keyword("ft3"));
ft3.setDescription("FT3");
catalog.save(ft3);
Filter filter = acceptAll();
Set<? extends CatalogInfo> expected;
Set<? extends CatalogInfo> actual;
// opposite equality
filter = factory.equal(factory.literal(ft1.getId()), factory.property("id"), true);
expected = Sets.newHashSet(ft1);
actual = Sets.newHashSet(catalog.list(ResourceInfo.class, filter));
assertEquals(expected, actual);
// match case
filter = factory.equal(factory.literal("FT1"), factory.property("name"), false);
expected = Sets.newHashSet(ft1);
actual = Sets.newHashSet(catalog.list(ResourceInfo.class, filter));
assertEquals(expected, actual);
// equality of fields
filter = factory.equal(factory.property("name"), factory.property("description"), true);
expected = Sets.newHashSet(ft2);
actual = Sets.newHashSet(catalog.list(ResourceInfo.class, filter));
assertEquals(expected, actual);
// match case
filter = factory.equal(factory.property("name"), factory.property("description"), false);
expected = Sets.newHashSet(ft2, ft3);
actual = Sets.newHashSet(catalog.list(ResourceInfo.class, filter));
assertEquals(expected, actual);
//match action
filter = factory.equal(factory.literal(new Keyword("keyword1")), factory.property("keywords"), true, MatchAction.ANY);
expected = Sets.newHashSet(ft1, ft2);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
filter = factory.equal(factory.literal(new Keyword("keyword1")), factory.property("keywords"), true, MatchAction.ALL);
expected = Sets.newHashSet(ft2);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
filter = factory.equal(factory.literal(new Keyword("keyword1")), factory.property("keywords"), true, MatchAction.ONE);
expected = Sets.newHashSet(ft1);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
//match action - like
filter = factory.like(factory.property("keywords"), "key*d1", "*","?","\\", true, MatchAction.ANY);
expected = Sets.newHashSet(ft1, ft2);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
filter = factory.like(factory.property("keywords"), "key*d1", "*","?","\\", true, MatchAction.ALL);
expected = Sets.newHashSet(ft2);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
filter = factory.like(factory.property("keywords"), "key*d1", "*","?","\\", true, MatchAction.ONE);
expected = Sets.newHashSet(ft1);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
//multivalued literals
List values = new ArrayList<String>();
values.add("ft1");
values.add("ft2");
filter = factory.equal(factory.literal(values), factory.property("name"), true, MatchAction.ANY);
expected = Sets.newHashSet(ft1, ft2);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
values = new ArrayList<String>();
values.add("ft1");
values.add("ft1");
filter = factory.equal(factory.literal(values), factory.property("name"), true, MatchAction.ALL);
expected = Sets.newHashSet(ft1);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
values = new ArrayList<String>();
values.add("ft1");
values.add("ft2");
filter = factory.equal(factory.literal(values), factory.property("name"), true, MatchAction.ALL);
expected = Sets.newHashSet();
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
values = new ArrayList<String>();
values.add("ft1");
values.add("ft1");
values.add("ft2");
filter = factory.equal(factory.literal(values), factory.property("name"), true, MatchAction.ONE);
expected = Sets.newHashSet(ft2);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
//multivalued literals with multivalued fields
values = new ArrayList<Keyword>();
values.add(new Keyword("keyword1"));
values.add(new Keyword("keyword2"));
filter = factory.equal(factory.literal(values), factory.property("keywords"), true, MatchAction.ANY);
expected = Sets.newHashSet(ft1, ft2);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
values = new ArrayList<Keyword>();
values.add(new Keyword("keyword1"));
values.add(new Keyword("keyword1"));
filter = factory.equal(factory.literal(values), factory.property("keywords"), true, MatchAction.ALL);
expected = Sets.newHashSet(ft2);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);
values = new ArrayList<Keyword>();
values.add(new Keyword("keyword1"));
values.add(new Keyword("blah"));
filter = factory.equal(factory.literal(values), factory.property("keywords"), true, MatchAction.ONE);
expected = Sets.newHashSet(ft1);
actual = Sets.newHashSet(catalog.list(FeatureTypeInfo.class, filter));
assertEquals(expected, actual);