use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestAtomTransformer method testNoResourceActionProvider.
@Test
public void testNoResourceActionProvider() throws CatalogTransformerException, IOException, XpathException, SAXException {
// given
MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
Action viewAction = mock(Action.class);
when(viewAction.getUrl()).thenReturn(new URL("http://host:80/" + SAMPLE_ID));
ActionProvider viewActionProvider = mock(ActionProvider.class);
when(viewActionProvider.getAction(isA(Metacard.class))).thenReturn(viewAction);
AtomTransformer transformer = new AtomTransformer();
transformer.setViewMetacardActionProvider(viewActionProvider);
transformer.setMetacardTransformer(metacardTransformer);
setDefaultSystemConfiguration();
SourceResponse response1 = mock(SourceResponse.class);
when(response1.getHits()).thenReturn(new Long(1));
when(response1.getRequest()).thenReturn(getStubRequest());
ResultImpl result1 = new ResultImpl();
MetacardStub metacard = new MetacardStub("");
metacard.setId(SAMPLE_ID);
metacard.setSourceId(SAMPLE_SOURCE_ID);
metacard.setCreatedDate(SAMPLE_DATE_TIME.toDate());
metacard.setModifiedDate(SAMPLE_DATE_TIME.toDate());
result1.setMetacard(metacard);
when(response1.getResults()).thenReturn(Arrays.asList((Result) result1));
SourceResponse response = response1;
Double relevanceScore = 0.3345;
result1.setRelevanceScore(relevanceScore);
// when
BinaryContent binaryContent = transformer.transform(response, null);
// then
assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
byte[] bytes = binaryContent.getByteArray();
/* used to visualize */
IOUtils.write(bytes, new FileOutputStream(new File(TARGET_FOLDER + getMethodName() + ATOM_EXTENSION)));
String output = new String(bytes);
assertFeedCompliant(output);
assertEntryCompliant(output);
validateAgainstAtomSchema(bytes);
/* feed */
assertBasicFeedInfo(output, "1");
/* entry */
assertXpathEvaluatesTo(SAMPLE_SOURCE_ID, "/atom:feed/atom:entry/fs:resultSource/@fs:sourceId", output);
assertXpathEvaluatesTo("", "/atom:feed/atom:entry/fs:resultSource", output);
assertXpathEvaluatesTo(AtomTransformer.URN_CATALOG_ID + SAMPLE_ID, "/atom:feed/atom:entry/atom:id", output);
assertXpathEvaluatesTo(MetacardStub.DEFAULT_TITLE, "/atom:feed/atom:entry/atom:title", output);
assertXpathEvaluatesTo(Double.toString(relevanceScore), "/atom:feed/atom:entry/relevance:score", output);
assertXpathExists("/atom:feed/atom:entry/atom:content", output);
assertXpathEvaluatesTo(atomDateFormat.format(SAMPLE_DATE_TIME.toDate()), "/atom:feed/atom:entry/atom:published", output);
assertXpathEvaluatesTo(atomDateFormat.format(SAMPLE_DATE_TIME.toDate()), "/atom:feed/atom:entry/atom:updated", output);
assertXpathEvaluatesTo("application/xml", "/atom:feed/atom:entry/atom:content/@type", output);
assertXpathEvaluatesTo(MetacardStub.DEFAULT_TYPE, "/atom:feed/atom:entry/atom:category/@term", output);
assertXpathEvaluatesTo("1", "count(/atom:feed/atom:entry/georss:where)", output);
assertXpathEvaluatesTo("1", "count(/atom:feed/atom:entry/georss:where/gml:Point)", output);
assertXpathEvaluatesTo("56.3 13.3", "/atom:feed/atom:entry/georss:where/gml:Point", output);
assertXpathEvaluatesTo("1", "count(/atom:feed/atom:entry/atom:link)", output);
assertXpathExists("/atom:feed/atom:entry/atom:link[@rel='alternate']", output);
assertXpathNotExists("/atom:feed/atom:entry/atom:link[@rel='related']", output);
assertXpathEvaluatesTo("http://host:80/" + SAMPLE_ID, "/atom:feed/atom:entry/atom:link/@href", output);
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestAtomTransformer method basicSetup.
protected SourceResponse basicSetup(AtomTransformer transformer) throws IOException, CatalogTransformerException {
MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
transformer.setMetacardTransformer(metacardTransformer);
setDefaultSystemConfiguration();
SourceResponse response = mock(SourceResponse.class);
when(response.getRequest()).thenReturn(getStubRequest());
ResultImpl result = new ResultImpl();
MetacardStub metacard = new MetacardStub("");
metacard.setId(SAMPLE_ID);
metacard.setSourceId(SAMPLE_SOURCE_ID);
result.setMetacard(metacard);
when(response.getResults()).thenReturn(Arrays.asList((Result) result));
return response;
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestAtomTransformer method testTotalResultsNegative.
@Test
public void testTotalResultsNegative() throws IOException, CatalogTransformerException, XpathException, SAXException {
// given
AtomTransformer transformer = new AtomTransformer();
MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
transformer.setMetacardTransformer(metacardTransformer);
setDefaultSystemConfiguration();
SourceResponse response = mock(SourceResponse.class);
when(response.getHits()).thenReturn(new Long(-1));
QueryImpl query = new QueryImpl(FILTER_BUILDER.attribute(Metacard.METADATA).text("you"));
query.setPageSize(1);
query.setStartIndex(2);
query.setRequestsTotalResultsCount(true);
QueryRequestImpl queryRequestImpl = new QueryRequestImpl(query);
when(response.getRequest()).thenReturn(queryRequestImpl);
ResultImpl result1 = new ResultImpl();
MetacardStub metacard = new MetacardStub("");
metacard.setId(SAMPLE_ID);
result1.setMetacard(metacard);
when(response.getResults()).thenReturn(Arrays.asList((Result) result1));
// when
BinaryContent binaryContent = transformer.transform(response, null);
// then
assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
byte[] bytes = binaryContent.getByteArray();
String output = new String(bytes);
assertFeedCompliant(output);
assertEntryCompliant(output);
validateAgainstAtomSchema(bytes);
assertXpathNotExists("/atom:feed/os:totalResults", output);
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestRegistryStore method testCreateNoExistingMetacard.
@Test
public void testCreateNoExistingMetacard() throws Exception {
Metacard mcard = getDefaultMetacard();
Csw csw = mock(Csw.class);
TransactionResponseType responseType = mock(TransactionResponseType.class);
InsertResultType insertResultType = mock(InsertResultType.class);
BriefRecordType briefRecord = mock(BriefRecordType.class);
JAXBElement identifier = mock(JAXBElement.class);
SimpleLiteral literal = mock(SimpleLiteral.class);
when(literal.getContent()).thenReturn(Collections.singletonList(mcard.getId()));
when(identifier.getValue()).thenReturn(literal);
when(briefRecord.getIdentifier()).thenReturn(Collections.singletonList(identifier));
when(insertResultType.getBriefRecord()).thenReturn(Collections.singletonList(briefRecord));
when(responseType.getInsertResult()).thenReturn(Collections.singletonList(insertResultType));
when(factory.getClientForSubject(any())).thenReturn(csw);
when(csw.transaction(any())).thenReturn(responseType);
when(transformer.getTransformerIdForSchema(any())).thenReturn("myInsertType");
queryResults.add(new ResultImpl(mcard));
CreateRequest request = new CreateRequestImpl(mcard);
CreateResponse response = registryStore.create(request);
assertThat(response.getCreatedMetacards().get(0), is(mcard));
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class TestRegistryStore method testUpdateConfigurationURISyntaxException.
@Test
public void testUpdateConfigurationURISyntaxException() throws Exception {
assertThat(registryStore.getRegistryId(), is(""));
registryStore.setRegistryUrl("^invalid^^^^uri^^");
queryResults.add(new ResultImpl(getDefaultMetacard()));
registryStore.registryInfoQuery();
String registryId = (String) properties.get(RegistryObjectMetacardType.REGISTRY_ID);
assertThat(registryId, is(nullValue()));
}
Aggregations