Search in sources :

Example 21 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class TestResourceMetacardTransformer method testFrameworkThrowsIoException.

@Test
public void testFrameworkThrowsIoException() throws Exception {
    String filePath = ABSOLUTE_PATH + TEST_PATH + JPEG_FILE_NAME_1;
    URI uri = getUri(filePath);
    Metacard metacard = getMockMetacard(uri);
    thrown.expect(CatalogTransformerException.class);
    thrown.expectMessage("Unable to retrieve resource.");
    thrown.expectMessage("Metacard id: " + TEST_ID);
    thrown.expectMessage("Uri: " + uri);
    thrown.expectMessage("Source: " + TEST_SITE);
    boolean expectSuccess = false;
    MimeType mimeType = getMimeType(JPEG_MIME_TYPE);
    CatalogFramework framework = getFrameworkException(new IOException("Test IO Exception"));
    testGetResource(metacard, filePath, mimeType, framework, expectSuccess);
}
Also used : Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) IOException(java.io.IOException) URI(java.net.URI) MimeType(javax.activation.MimeType) Test(org.junit.Test)

Example 22 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class TestResourceMetacardTransformer method givenFramework.

private CatalogFramework givenFramework(ArgumentCapture answer) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
    CatalogFramework framework = mock(CatalogFramework.class);
    when(framework.getId()).thenReturn(TEST_SITE);
    when(framework.getResource(any(ResourceRequest.class), isA(String.class))).thenAnswer(answer);
    return framework;
}
Also used : CatalogFramework(ddf.catalog.CatalogFramework) ResourceRequest(ddf.catalog.operation.ResourceRequest)

Example 23 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class TestResourceMetacardTransformer method testResourceHasNullMimeType.

@Test
public void testResourceHasNullMimeType() throws Exception {
    String filePath = ABSOLUTE_PATH + TEST_PATH + TS_FILE_NAME_1;
    URI uri = getUri(filePath);
    Metacard metacard = getMockMetacard(uri);
    boolean expectSuccess = true;
    MimeType mimeType = getMimeType(DEFAULT_MIME_TYPE);
    CatalogFramework framework = getFramework(getResourceResponse(getResource(null, uri)));
    testGetResource(metacard, filePath, mimeType, framework, expectSuccess);
}
Also used : Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) URI(java.net.URI) MimeType(javax.activation.MimeType) Test(org.junit.Test)

Example 24 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class TestResourceMetacardTransformer method getFramework.

private CatalogFramework getFramework(ResourceResponse resourceResponse) throws Exception {
    CatalogFramework framework = mock(CatalogFramework.class);
    when(framework.getId()).thenReturn(TEST_SITE);
    when(framework.getResource(any(ResourceRequest.class), eq(TEST_SITE))).thenReturn(resourceResponse);
    return framework;
}
Also used : CatalogFramework(ddf.catalog.CatalogFramework) ResourceRequest(ddf.catalog.operation.ResourceRequest)

Example 25 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class TestResourceMetacardTransformer method testGetResourceJpegFromFedSource.

/**
     * Tests that the metacard source name is passed to the {@link CatalogFramework}
     *
     * @throws Exception
     */
@Test
public void testGetResourceJpegFromFedSource() throws Exception {
    // given
    String filePath = ABSOLUTE_PATH + TEST_PATH + JPEG_FILE_NAME_1;
    String federatedSourceId = "fedSourceId";
    URI uri = getUri(filePath);
    Metacard metacard = getMockMetacard(uri, federatedSourceId);
    MimeType mimeType = getMimeType(JPEG_MIME_TYPE);
    ArgumentCapture capture = new ArgumentCapture(getResourceResponse(getResource(mimeType, uri)));
    CatalogFramework framework = givenFramework(capture);
    ResourceMetacardTransformer resourceTransformer = new ResourceMetacardTransformer(framework);
    // when
    resourceTransformer.transform(metacard, new HashMap<String, Serializable>());
    // then
    assertEquals(federatedSourceId, capture.inputArgs[1]);
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) CatalogFramework(ddf.catalog.CatalogFramework) URI(java.net.URI) MimeType(javax.activation.MimeType) Test(org.junit.Test)

Aggregations

CatalogFramework (ddf.catalog.CatalogFramework)80 Test (org.junit.Test)63 Matchers.anyString (org.mockito.Matchers.anyString)30 Metacard (ddf.catalog.data.Metacard)27 QueryResponse (ddf.catalog.operation.QueryResponse)20 ArrayList (java.util.ArrayList)20 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)19 Serializable (java.io.Serializable)18 ContentType (ddf.catalog.data.ContentType)17 URI (java.net.URI)17 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 HashMap (java.util.HashMap)14 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)12 Date (java.util.Date)12 BundleContext (org.osgi.framework.BundleContext)11 MimeType (javax.activation.MimeType)10 Response (javax.ws.rs.core.Response)10 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)9 ServiceReference (org.osgi.framework.ServiceReference)9 FilterBuilder (ddf.catalog.filter.FilterBuilder)8