Search in sources :

Example 1 with ContextualExpressionBuilder

use of ddf.catalog.filter.ContextualExpressionBuilder in project ddf by codice.

the class TagsFilterQueryPluginTest method addTagsToCatalogProvider.

@Test
public void addTagsToCatalogProvider() throws Exception {
    AttributeBuilder attributeBuilder = mock(AttributeBuilder.class);
    ExpressionBuilder expressionBuilder = mock(ExpressionBuilder.class);
    ContextualExpressionBuilder contextualExpressionBuilder = mock(ContextualExpressionBuilder.class);
    Filter defaultTagFilter = mock(Filter.class);
    when(attributeBuilder.is()).thenReturn(expressionBuilder);
    when(expressionBuilder.like()).thenReturn(contextualExpressionBuilder);
    when(contextualExpressionBuilder.text(Metacard.DEFAULT_TAG)).thenReturn(defaultTagFilter);
    when(filterBuilder.allOf(query, defaultTagFilter)).thenReturn(mock(And.class));
    when(filterAdapter.adapt(any(), any())).thenReturn(false);
    when(filterBuilder.attribute(Metacard.TAGS)).thenReturn(attributeBuilder);
    QueryRequest process = plugin.process(source, queryRequest);
    assertThat(process, not(queryRequest));
}
Also used : AttributeBuilder(ddf.catalog.filter.AttributeBuilder) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) And(org.opengis.filter.And) ContextualExpressionBuilder(ddf.catalog.filter.ContextualExpressionBuilder) ContextualExpressionBuilder(ddf.catalog.filter.ContextualExpressionBuilder) ExpressionBuilder(ddf.catalog.filter.ExpressionBuilder) Test(org.junit.Test)

Example 2 with ContextualExpressionBuilder

use of ddf.catalog.filter.ContextualExpressionBuilder in project ddf by codice.

the class TagsFilterQueryPluginTest method addTagsToCacheSource.

@Test
public void addTagsToCacheSource() throws Exception {
    AttributeBuilder attributeBuilder = mock(AttributeBuilder.class);
    ExpressionBuilder expressionBuilder = mock(ExpressionBuilder.class);
    ContextualExpressionBuilder contextualExpressionBuilder = mock(ContextualExpressionBuilder.class);
    Filter defaultTagFilter = mock(Filter.class);
    when(attributeBuilder.is()).thenReturn(expressionBuilder);
    when(expressionBuilder.like()).thenReturn(contextualExpressionBuilder);
    when(contextualExpressionBuilder.text(Metacard.DEFAULT_TAG)).thenReturn(defaultTagFilter);
    when(filterBuilder.allOf(query, defaultTagFilter)).thenReturn(mock(And.class));
    when(filterAdapter.adapt(any(), any())).thenReturn(false);
    when(filterBuilder.attribute(Metacard.TAGS)).thenReturn(attributeBuilder);
    QueryRequest process = plugin.process(cache, queryRequest);
    assertThat(process, not(queryRequest));
}
Also used : AttributeBuilder(ddf.catalog.filter.AttributeBuilder) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) And(org.opengis.filter.And) ContextualExpressionBuilder(ddf.catalog.filter.ContextualExpressionBuilder) ContextualExpressionBuilder(ddf.catalog.filter.ContextualExpressionBuilder) ExpressionBuilder(ddf.catalog.filter.ExpressionBuilder) Test(org.junit.Test)

Example 3 with ContextualExpressionBuilder

use of ddf.catalog.filter.ContextualExpressionBuilder in project ddf by codice.

the class OpenSearchEndpointTest method testProcessQueryForProperHandlingOfSiteNameLOCAL.

/**
 * Test method for {@link OpenSearchEndpoint#processQuery(String, String, String, String, String,
 * String, String, String, String, String, String, String, String, String, String, String, String,
 * String, UriInfo, String, String, HttpServletRequest)} .
 *
 * <p>This test will verify that the string "local" in the sources passed to
 * OpenSearchEndpoint.processQuery is replaced with the local site name (in this case the mocked
 * name "TestSiteName"). The QueryRequest object is checked when the framework.query is called to
 * retrieve the OpenSearchQuery, which contains the Set of sites. An assertion within the Answer
 * object for the call framework.query checks that the sites Set is contains the TEST_SITE_NAME.
 */
@SuppressWarnings("unchecked")
@Test
public void testProcessQueryForProperHandlingOfSiteNameLOCAL() throws URISyntaxException, UnsupportedQueryException, SourceUnavailableException, FederationException, UnsupportedEncodingException, CatalogTransformerException {
    // ***Test setup***
    final String testSiteName = "TestSiteName";
    CatalogFramework mockFramework = mock(CatalogFramework.class);
    FilterBuilder mockFilterBuilder = mock(FilterBuilder.class);
    AttributeBuilder mockAB = mock(AttributeBuilder.class);
    ExpressionBuilder mockEB = mock(ExpressionBuilder.class);
    ContextualExpressionBuilder mockCEB = mock(ContextualExpressionBuilder.class);
    Filter mockFilter = mock(Filter.class);
    when(mockFilterBuilder.attribute(anyString())).thenReturn(mockAB);
    when(mockAB.is()).thenReturn(mockEB);
    when(mockEB.like()).thenReturn(mockCEB);
    when(mockCEB.text(anyString())).thenReturn(mockFilter);
    String searchTerms = "searchForThis";
    // "local" MUST be included
    String sources = "test, local";
    String count = "200";
    // dummy UriInfo, not really used functionally
    UriInfo mockUriInfo = mock(UriInfo.class);
    URI uri = new URI("test");
    when(mockUriInfo.getRequestUri()).thenReturn(uri);
    MultivaluedMap<String, String> mockMVMap = mock(MultivaluedMap.class);
    when(mockMVMap.get("subscription")).thenReturn(null);
    when(mockMVMap.get("interval")).thenReturn(null);
    when(mockUriInfo.getQueryParameters()).thenReturn(mockMVMap);
    @SuppressWarnings("unused") BinaryContent mockByteContent = mock(BinaryContent.class);
    // Check on the sites passed in to framework.query
    when(mockFramework.query(any(QueryRequest.class))).thenAnswer(invocation -> {
        QueryRequest queryRequest = (QueryRequest) invocation.getArguments()[0];
        // ***Test verification***
        // This assert is the whole point of this unit test
        Assert.assertTrue(((OpenSearchQuery) queryRequest.getQuery()).getSiteIds().contains(testSiteName));
        return new QueryResponseImpl(queryRequest);
    });
    // setup the BinaryContent for the call to Response.ok(...)
    // This is just needed to get the method to complete, the
    BinaryContent mockBinaryContent = mock(BinaryContent.class);
    InputStream is = new ByteArrayInputStream("Test String From InputStream".getBytes("UTF-8"));
    when(mockBinaryContent.getInputStream()).thenReturn(is);
    when(mockBinaryContent.getMimeTypeValue()).thenReturn("text/plain");
    when(mockFramework.transform(any(QueryResponse.class), anyString(), anyMap())).thenReturn(mockBinaryContent);
    OpenSearchEndpoint osEndPoint = new OpenSearchEndpoint(mockFramework, mockFilterBuilder);
    System.setProperty(SystemInfo.SITE_NAME, testSiteName);
    // ***Test Execution***
    osEndPoint.processQuery(searchTerms, null, sources, null, null, count, null, null, null, null, null, null, null, null, null, null, null, null, mockUriInfo, null, null, null);
}
Also used : AttributeBuilder(ddf.catalog.filter.AttributeBuilder) QueryRequest(ddf.catalog.operation.QueryRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ContextualExpressionBuilder(ddf.catalog.filter.ContextualExpressionBuilder) ContextualExpressionBuilder(ddf.catalog.filter.ContextualExpressionBuilder) ExpressionBuilder(ddf.catalog.filter.ExpressionBuilder) BinaryContent(ddf.catalog.data.BinaryContent) URI(java.net.URI) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) OpenSearchQuery(org.codice.ddf.opensearch.endpoint.query.OpenSearchQuery) Filter(org.opengis.filter.Filter) ByteArrayInputStream(java.io.ByteArrayInputStream) FilterBuilder(ddf.catalog.filter.FilterBuilder) QueryResponse(ddf.catalog.operation.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 4 with ContextualExpressionBuilder

use of ddf.catalog.filter.ContextualExpressionBuilder in project ddf by codice.

the class OpenSearchEndpointTest method testProcessQueryForProperHandlingOfSiteNameLOCAL.

/**
     * Test method for
     * {@link org.codice.ddf.endpoints.OpenSearchEndpoint#processQuery(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.ws.rs.core.UriInfo, java.lang.String, java.lang.String)}
     * .
     * <p>
     * This test will verify that the string "local" in the sources passed to
     * OpenSearchEndpoint.processQuery is replaced with the local site name (in this case the mocked
     * name "TestSiteName"). The QueryRequest object is checked when the framework.query is called
     * to retrieve the OpenSearchQuery, which contains the Set of sites. An assertion within the
     * Answer object for the call framework.query checks that the sites Set is contains the
     * TEST_SITE_NAME.
     *
     * @throws URISyntaxException
     * @throws FederationException
     * @throws SourceUnavailableException
     * @throws UnsupportedQueryException
     * @throws UnsupportedEncodingException
     * @throws CatalogTransformerException
     */
@SuppressWarnings("unchecked")
@Test
public void testProcessQueryForProperHandlingOfSiteNameLOCAL() throws URISyntaxException, UnsupportedQueryException, SourceUnavailableException, FederationException, UnsupportedEncodingException, CatalogTransformerException {
    // ***Test setup***
    final String testSiteName = "TestSiteName";
    CatalogFramework mockFramework = mock(CatalogFramework.class);
    FilterBuilder mockFilterBuilder = mock(FilterBuilder.class);
    AttributeBuilder mockAB = mock(AttributeBuilder.class);
    ExpressionBuilder mockEB = mock(ExpressionBuilder.class);
    ContextualExpressionBuilder mockCEB = mock(ContextualExpressionBuilder.class);
    Filter mockFilter = mock(Filter.class);
    when(mockFilterBuilder.attribute(anyString())).thenReturn(mockAB);
    when(mockAB.is()).thenReturn(mockEB);
    when(mockEB.like()).thenReturn(mockCEB);
    when(mockCEB.text(anyString())).thenReturn(mockFilter);
    String searchTerms = "searchForThis";
    // "local" MUST be included
    String sources = "test, local";
    String count = "200";
    // dummy UriInfo, not really used functionally
    UriInfo mockUriInfo = mock(UriInfo.class);
    URI uri = new URI("test");
    when(mockUriInfo.getRequestUri()).thenReturn(uri);
    MultivaluedMap<String, String> mockMVMap = mock(MultivaluedMap.class);
    when(mockMVMap.get("subscription")).thenReturn(null);
    when(mockMVMap.get("interval")).thenReturn(null);
    when(mockUriInfo.getQueryParameters()).thenReturn(mockMVMap);
    @SuppressWarnings("unused") BinaryContent mockByteContent = mock(BinaryContent.class);
    // Check on the sites passed in to framework.query
    when(mockFramework.query(any(QueryRequest.class))).thenAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            QueryRequest queryRequest = (QueryRequest) invocation.getArguments()[0];
            // ***Test verification***
            // This assert is the whole point of this unit test
            Assert.assertTrue(((OpenSearchQuery) queryRequest.getQuery()).getSiteIds().contains(testSiteName));
            return new QueryResponseImpl(queryRequest);
        }
    });
    // setup the BinaryContent for the call to Response.ok(...)
    // This is just needed to get the method to complete, the
    BinaryContent mockBinaryContent = mock(BinaryContent.class);
    InputStream is = new ByteArrayInputStream("Test String From InputStream".getBytes("UTF-8"));
    when(mockBinaryContent.getInputStream()).thenReturn(is);
    when(mockBinaryContent.getMimeTypeValue()).thenReturn("text/plain");
    when(mockFramework.transform(any(QueryResponse.class), anyString(), anyMap())).thenReturn(mockBinaryContent);
    OpenSearchEndpoint osEndPoint = new OpenSearchEndpoint(mockFramework, mockFilterBuilder);
    System.setProperty(SystemInfo.SITE_NAME, testSiteName);
    // ***Test Execution***
    osEndPoint.processQuery(searchTerms, null, sources, null, null, count, null, null, null, null, null, null, null, null, null, null, null, null, mockUriInfo, null, null, null);
}
Also used : AttributeBuilder(ddf.catalog.filter.AttributeBuilder) QueryRequest(ddf.catalog.operation.QueryRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) ContextualExpressionBuilder(ddf.catalog.filter.ContextualExpressionBuilder) ContextualExpressionBuilder(ddf.catalog.filter.ContextualExpressionBuilder) ExpressionBuilder(ddf.catalog.filter.ExpressionBuilder) BinaryContent(ddf.catalog.data.BinaryContent) URI(java.net.URI) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Filter(org.opengis.filter.Filter) ByteArrayInputStream(java.io.ByteArrayInputStream) FilterBuilder(ddf.catalog.filter.FilterBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) QueryResponse(ddf.catalog.operation.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

AttributeBuilder (ddf.catalog.filter.AttributeBuilder)4 ContextualExpressionBuilder (ddf.catalog.filter.ContextualExpressionBuilder)4 ExpressionBuilder (ddf.catalog.filter.ExpressionBuilder)4 QueryRequest (ddf.catalog.operation.QueryRequest)4 Test (org.junit.Test)4 Filter (org.opengis.filter.Filter)4 CatalogFramework (ddf.catalog.CatalogFramework)2 BinaryContent (ddf.catalog.data.BinaryContent)2 FilterBuilder (ddf.catalog.filter.FilterBuilder)2 QueryResponse (ddf.catalog.operation.QueryResponse)2 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2 UriInfo (javax.ws.rs.core.UriInfo)2 And (org.opengis.filter.And)2 OpenSearchQuery (org.codice.ddf.opensearch.endpoint.query.OpenSearchQuery)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Matchers.anyString (org.mockito.Matchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1