use of ddf.action.ActionProvider in project ddf by codice.
the class TestAtomTransformer method testSimple.
@Test
public void testSimple() 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);
ActionProvider resourceActionProvider = mock(ActionProvider.class);
when(resourceActionProvider.getAction(isA(Metacard.class))).thenReturn(viewAction);
ActionProvider thumbnailActionProvider = mock(ActionProvider.class);
when(thumbnailActionProvider.getAction(isA(Metacard.class))).thenReturn(viewAction);
AtomTransformer transformer = new AtomTransformer();
transformer.setViewMetacardActionProvider(viewActionProvider);
transformer.setResourceActionProvider(resourceActionProvider);
transformer.setMetacardTransformer(metacardTransformer);
transformer.setThumbnailActionProvider(thumbnailActionProvider);
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("3", "count(/atom:feed/atom:entry/atom:link)", output);
assertXpathExists("/atom:feed/atom:entry/atom:link[@rel='alternate']", output);
assertXpathExists("/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.action.ActionProvider in project ddf by codice.
the class TestKMLTransformerImpl method setUp.
@BeforeClass
public static void setUp() throws IOException {
when(mockContext.getBundle()).thenReturn(mockBundle);
URL url = TestKMLTransformerImpl.class.getResource(DEFAULT_STYLE_LOCATION);
when(mockBundle.getResource(any(String.class))).thenReturn(url);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
ActionProvider mockActionProvider = mock(ActionProvider.class);
Action mockAction = mock(Action.class);
when(mockActionProvider.getAction(any(Metacard.class))).thenReturn(mockAction);
when(mockAction.getUrl()).thenReturn(new URL(ACTION_URL));
kmlTransformer = new KMLTransformerImpl(mockContext, DEFAULT_STYLE_LOCATION, new KmlStyleMap(), mockActionProvider);
}
use of ddf.action.ActionProvider in project ddf by codice.
the class TestActionProviderRegistryProxy method testAttributeTransformer.
@Test
public void testAttributeTransformer() throws MimeTypeParseException {
// given
ActionProviderRegistryProxy proxy = new ActionProviderRegistryProxyTest(mtapf);
when(mockBundleContext.getService(mockServiceReference)).thenReturn(new AttributeMetacardTransformer("metadata", "metadata", new MimeType("text", "xml")));
// when
proxy.bind(mockServiceReference);
// then
verify(mockBundleContext, times(1)).registerService(anyString(), captor.capture(), any(Dictionary.class));
Object value = captor.getValue();
assertThat(value, notNullValue());
assertThat(value instanceof ActionProvider, is(true));
}
Aggregations