use of ddf.catalog.operation.SourceResponse in project ddf by codice.
the class TestWfsSource method testPaging.
// Simulates query by ID (which is analogous to clicking on link in search
// results to
// view associated metacard in XML)
@Test
public void testPaging() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
int pageSize = 4;
int startIndex = 1;
int numFeatures = 1;
setUp(ONE_TEXT_PROPERTY_SCHEMA, null, null, numFeatures, null);
SourceResponse response = executeQuery(startIndex, pageSize);
List<Result> results = response.getResults();
assertThat(results.size(), is(1));
assertThat(response.getHits(), equalTo(new Long(numFeatures)));
}
use of ddf.catalog.operation.SourceResponse in project ddf by codice.
the class CatalogFrameworkImplTest method testQueryTransformWithTransformException.
@Test(expected = CatalogTransformerException.class)
public void testQueryTransformWithTransformException() throws Exception {
BundleContext context = mock(BundleContext.class);
QueryResponseTransformer transformer = mock(QueryResponseTransformer.class);
ServiceReference reference = mock(ServiceReference.class);
ServiceReference[] serviceReferences = new ServiceReference[] { reference };
when(context.getServiceReferences(anyString(), anyString())).thenReturn(serviceReferences);
when(context.getService(isA(ServiceReference.class))).thenReturn(transformer);
when(transformer.transform(isA(SourceResponse.class), isA(Map.class))).thenThrow(new CatalogTransformerException("Could not transform"));
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
SourceResponse response = new SourceResponseImpl(null, null);
framework.transform(response, "NONE", new HashMap<String, Serializable>());
}
use of ddf.catalog.operation.SourceResponse in project ddf by codice.
the class TestOpenSearchSource method testQueryQueryByMetacardIdFollowedByAnyTextQuery.
// DDF-161
@Test
public void testQueryQueryByMetacardIdFollowedByAnyTextQuery() throws Exception {
WebClient client = mock(WebClient.class);
Response clientResponse = mock(Response.class);
when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(client.get()).thenReturn(clientResponse);
when(clientResponse.getEntity()).thenReturn(getSampleXmlStream()).thenReturn(getSampleAtomStream());
SecureCxfClientFactory factory = getMockFactory(client);
OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
source.setLocalQueryOnly(true);
source.setInputTransformer(getMockInputTransformer());
source.setEndpointUrl("http://localhost:8181/services/catalog/query");
source.init();
source.setParameters(DEFAULT_PARAMETERS);
source.factory = factory;
// Metacard ID filter
Filter idFilter = filterBuilder.attribute(Metacard.ID).equalTo().text(SAMPLE_ID);
// Any text filter
Filter anyTextFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text(SAMPLE_SEARCH_PHRASE);
// Perform Test (Query by ID followed by Any Text Query)
SourceResponse response1 = source.query(new QueryRequestImpl(new QueryImpl(idFilter)));
SourceResponse response2 = source.query(new QueryRequestImpl(new QueryImpl(anyTextFilter)));
// Verification - Verify that we don't see any exceptions when
// processing the input stream from the endpoint.
// Verify 1 metacard is in the results
assertThat(response1.getResults().size(), is(1));
// Verify that the atom feed is converted into 1 metacard result
assertThat(response2.getResults().size(), is(1));
}
use of ddf.catalog.operation.SourceResponse in project ddf by codice.
the class TestOpenSearchSource method testQueryQueryByMetacardIdFollowedByAnyTextQueryRss.
// DDF-161
@Test
public void testQueryQueryByMetacardIdFollowedByAnyTextQueryRss() throws Exception {
WebClient client = mock(WebClient.class);
Response clientResponse = mock(Response.class);
when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(clientResponse.getEntity()).thenReturn(getSampleXmlStream()).thenReturn(getSampleRssStream());
when(client.get()).thenReturn(clientResponse);
SecureCxfClientFactory factory = getMockFactory(client);
OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
source.setLocalQueryOnly(true);
source.setInputTransformer(getMockInputTransformer());
source.setEndpointUrl("http://localhost:8181/services/catalog/query");
source.init();
source.setParameters(DEFAULT_PARAMETERS);
source.factory = factory;
// Metacard ID filter
Filter idFilter = filterBuilder.attribute(Metacard.ID).equalTo().text(SAMPLE_ID);
// Any text filter
Filter anyTextFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text(SAMPLE_SEARCH_PHRASE);
// Perform Test (Query by ID followed by Any Text Query)
SourceResponse response1 = source.query(new QueryRequestImpl(new QueryImpl(idFilter)));
SourceResponse response2 = source.query(new QueryRequestImpl(new QueryImpl(anyTextFilter)));
// Verification - Verify that we don't see any exceptions when
// processing the input stream from the endpoint.
// Verify 1 metacard is in the results
assertThat(response1.getResults().size(), is(1));
// Verify that the atom feed is converted into 1 metacard result
assertThat(response2.getResults().size(), is(1));
}
use of ddf.catalog.operation.SourceResponse in project ddf by codice.
the class TestOpenSearchSource method testQueryById.
/**
* Tests the proper query is sent to the remote source for query by id.
*
* @throws UnsupportedQueryException
* @throws IOException
* @throws MalformedURLException
*/
@Test
public void testQueryById() throws UnsupportedQueryException, IOException {
Response clientResponse = mock(Response.class);
WebClient client = mock(WebClient.class);
//ClientResponse
doReturn(clientResponse).when(client).get();
doReturn(Response.Status.OK.getStatusCode()).when(clientResponse).getStatus();
//Client functions
doReturn(getSampleXmlStream()).when(clientResponse).getEntity();
when(clientResponse.getHeaderString(eq(OpenSearchSource.HEADER_ACCEPT_RANGES))).thenReturn(OpenSearchSource.BYTES);
when(client.replaceQueryParam(any(String.class), any(Object.class))).thenReturn(client);
SecureCxfClientFactory factory = getMockFactory(client);
OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
source.setInputTransformer(getMockInputTransformer());
source.setEndpointUrl("http://localhost:8181/services/catalog/query");
source.init();
source.setParameters(DEFAULT_PARAMETERS);
source.factory = factory;
Filter filter = filterBuilder.attribute(Metacard.ID).equalTo().text(SAMPLE_ID);
// when
SourceResponse response = source.query(new QueryRequestImpl(new QueryImpl(filter)));
// then
Assert.assertEquals(1, response.getHits());
}
Aggregations