use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class DefaultFactoryTest method createHeadersFilter.
private MapFieldValueFilter<String, WebPage> createHeadersFilter() {
MapFieldValueFilter<String, WebPage> filter = new MapFieldValueFilter<>();
filter.setFieldName(WebPage.Field.HEADERS.toString());
filter.setMapKey(new Utf8("C.T"));
filter.getOperands().add("text/html");
return filter;
}
use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class DefaultFactoryTest method testCreateFilter_handlingUtf8.
/**
* Check that <a href="https://issues.apache.org/jira/browse/GORA-388">GORA-388</a> is fixed.
* @see <a href="https://issues.apache.org/jira/browse/GORA-388">GORA-388</a>
*/
@Test
public void testCreateFilter_handlingUtf8() throws Exception {
SingleFieldValueFilter<String, WebPage> filter = new SingleFieldValueFilter<>();
filter.setFieldName(WebPage.Field.URL.toString());
filter.setFilterOp(FilterOp.EQUALS);
filter.getOperands().add(new Utf8("http://www.example.com"));
filter.setFilterIfMissing(true);
DBObject dbObject = filterFactory.createFilter(filter, store);
assertEquals("{ \"url\" : \"http://www.example.com\"}", dbObject.toString());
}
use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class DefaultFactoryTest method testCreateFilter_list_2.
@Test
public void testCreateFilter_list_2() throws Exception {
FilterList<String, WebPage> filter = new FilterList<>();
MapFieldValueFilter<String, WebPage> hFilter = createHeadersFilter();
hFilter.setFilterIfMissing(true);
hFilter.setFilterOp(FilterOp.EQUALS);
filter.addFilter(hFilter);
SingleFieldValueFilter<String, WebPage> urlFilter = createUrlFilter();
urlFilter.setFilterIfMissing(true);
urlFilter.setFilterOp(FilterOp.EQUALS);
filter.addFilter(urlFilter);
DBObject dbObject = filterFactory.createFilter(filter, store);
assertEquals("{ \"h.C·T\" : \"text/html\" , \"url\" : \"http://www.example.com\"}", dbObject.toString());
}
use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class DefaultFactoryTest method testCreateFilter_mapField_equalsOrNull.
@Test
public void testCreateFilter_mapField_equalsOrNull() throws Exception {
MapFieldValueFilter<String, WebPage> filter = createHeadersFilter();
filter.setFilterOp(FilterOp.EQUALS);
// include doc with missing field
filter.setFilterIfMissing(false);
DBObject dbObject = filterFactory.createFilter(filter, store);
assertEquals("{ \"$or\" : [ { \"h.C·T\" : { \"$exists\" : false}} , { \"h.C·T\" : \"text/html\"}]}", dbObject.toString());
}
use of org.apache.gora.examples.generated.WebPage in project gora by apache.
the class TestSingleFieldValueFilter method testFilterBasics.
@Test
public void testFilterBasics() {
SingleFieldValueFilter<String, WebPage> filter = new SingleFieldValueFilter<>();
//set filter field to url
filter.setFieldName(WebPage.Field.URL.toString());
filter.setFilterOp(FilterOp.EQUALS);
filter.setFilterIfMissing(true);
filter.getOperands().add(new Utf8("example.org"));
WebPage page = WebPage.newBuilder().build();
page.setUrl(new Utf8("example.org"));
assertFalse(filter.filter("irrelevant", page));
page.setUrl(new Utf8("mismatch.whatever"));
assertTrue(filter.filter("irrelevant", page));
page = new WebPage();
assertTrue(filter.filter("irrelevant", page));
filter.setFilterIfMissing(false);
assertFalse(filter.filter("irrelevant", page));
}
Aggregations