use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.
the class OpenSearchQueryTest method testOgcFilterEvaluateTemporalBetween.
@Test
public // @Ignore
void testOgcFilterEvaluateTemporalBetween() throws Exception {
FilterFactory filterFactory = new FilterFactoryImpl();
// get a calendar instance, which defaults to "now"
Calendar calendar = Calendar.getInstance();
// get a date to represent "today"
Date now = calendar.getTime();
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
String dateInRange = dateFormatter.format(now);
// set calendar time in past to create start date for temporal filter's criteria
calendar.add(Calendar.DAY_OF_YEAR, -1);
Date start = calendar.getTime();
String startDate = dateFormatter.format(start);
LOGGER.debug("startDate = {}", startDate);
// set calendar time in future to create end date for temporal filter's criteria
calendar.add(Calendar.DAY_OF_YEAR, +3);
Date end = calendar.getTime();
String endDate = dateFormatter.format(end);
LOGGER.debug("endDate = {}", endDate);
// Test date between start and end dates
Filter filter = filterFactory.between(filterFactory.literal(dateInRange), filterFactory.literal(startDate), filterFactory.literal(endDate));
FilterTransformer transform = new FilterTransformer();
transform.setIndentation(2);
LOGGER.debug(transform.transform(filter));
boolean result = filter.evaluate(null);
LOGGER.debug("result = {}", result);
assertTrue(result);
// Test date that is after end date
calendar.add(Calendar.DAY_OF_YEAR, +3);
Date outOfRange = calendar.getTime();
String outOfRangeDate = dateFormatter.format(outOfRange);
filter = filterFactory.between(filterFactory.literal(outOfRangeDate), filterFactory.literal(startDate), filterFactory.literal(endDate));
LOGGER.debug(transform.transform(filter));
result = filter.evaluate(null);
LOGGER.debug("result = {}", result);
assertFalse(result);
// Test date that is before start date
calendar.add(Calendar.DAY_OF_YEAR, -20);
Date outOfRange2 = calendar.getTime();
String outOfRangeDate2 = dateFormatter.format(outOfRange2);
filter = filterFactory.between(filterFactory.literal(outOfRangeDate2), filterFactory.literal(startDate), filterFactory.literal(endDate));
LOGGER.debug(transform.transform(filter));
result = filter.evaluate(null);
LOGGER.debug("result = {}", result);
assertFalse(result);
// Test date that is equal to start date
filter = filterFactory.between(filterFactory.literal(startDate), filterFactory.literal(startDate), filterFactory.literal(endDate));
LOGGER.debug(transform.transform(filter));
result = filter.evaluate(null);
LOGGER.debug("result = {}", result);
assertTrue(result);
// Test date that is equal to end date
filter = filterFactory.between(filterFactory.literal(endDate), filterFactory.literal(startDate), filterFactory.literal(endDate));
LOGGER.debug(transform.transform(filter));
result = filter.evaluate(null);
LOGGER.debug("result = {}", result);
assertTrue(result);
}
use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.
the class TestPubSubOgcFilter method testContextualEvaluate.
@Test
@Ignore
public void testContextualEvaluate() throws TransformerException {
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.like(filterFactory.literal("abcdef"), "abcdef");
printFilter(filter);
assertTrue(filter.evaluate(null));
Filter filter2 = filterFactory.like(filterFactory.literal("123456"), "123456abc");
assertFalse(filter2.evaluate(null));
}
use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnQuery.
@Test
public void testInjectsAttributesOnQuery() throws Exception {
final Metacard original = new MetacardImpl();
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(original), null)).getCreatedMetacards().get(0).getId();
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl("new attribute", true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final FilterFactory filterFactory = new FilterFactoryImpl();
final Filter filter = filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(id));
final QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
final QueryResponse response = framework.query(request);
final Metacard queryMetacard = response.getResults().get(0).getMetacard();
final MetacardType originalMetacardType = original.getMetacardType();
final MetacardType queryMetacardType = queryMetacard.getMetacardType();
assertThat(originalMetacardType.getName(), is(queryMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(queryMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
}
use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testPostQueryStopExecution.
@Test(expected = FederationException.class)
public void testPostQueryStopExecution() throws UnsupportedQueryException, FederationException, SourceUnavailableException {
SourcePoller poller = mock(SourcePoller.class);
when(poller.getCachedSource(isA(Source.class))).thenReturn(null);
BundleContext context = null;
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "goodyear", "*", "?", "/", false);
QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
SourceResponseImpl sourceResponse = new SourceResponseImpl(request, new ArrayList<Result>());
QueryResponseImpl queryResponse = new QueryResponseImpl(sourceResponse, "anyId");
CatalogProvider provider = mock(CatalogProvider.class);
when(provider.query(isA(QueryRequest.class))).thenReturn(sourceResponse);
FederationStrategy federationStrategy = mock(FederationStrategy.class);
when(federationStrategy.federate(isA(List.class), isA(QueryRequest.class))).thenReturn(queryResponse);
PostQueryPlugin stopQueryPlugin = new PostQueryPlugin() {
@Override
public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
throw new StopProcessingException("Testing that the framework will stop the query.");
}
};
FrameworkProperties props = new FrameworkProperties();
props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
props.setBundleContext(context);
props.setPostQuery(Arrays.asList(stopQueryPlugin));
props.setFederationStrategy(federationStrategy);
props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
props.setSourcePoller(poller);
props.setFilterBuilder(new GeotoolsFilterBuilder());
CatalogFrameworkImpl framework = createFramework(props);
framework.query(request);
}
use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.
the class TestQueryImpl method testSetFilterWithNullFilter.
@Test(expected = IllegalArgumentException.class)
public void testSetFilterWithNullFilter() {
FilterFactory filterFactory = new FilterFactoryImpl();
// Dummy filter copied from another test
Filter filter1 = filterFactory.like(filterFactory.property(Metacard.METADATA), "million", DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, "^", false);
Filter filter2 = null;
QueryImpl qi = new QueryImpl(filter1);
assertEquals(filter1, qi.getFilter());
qi.setFilter(filter2);
}
Aggregations