Search in sources :

Example 21 with MimeType

use of javax.activation.MimeType in project ddf by codice.

the class TestResourceMetacardTransformer method testGetResourceTransportStream.

@Test
public void testGetResourceTransportStream() 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(VIDEO_MIME_TYPE);
    CatalogFramework framework = getFramework(getResourceResponse(getResource(mimeType, 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 22 with MimeType

use of javax.activation.MimeType in project ddf by codice.

the class TestResourceMetacardTransformer method testNullMetacardId.

@Test
public void testNullMetacardId() throws Exception {
    thrown.expect(CatalogTransformerException.class);
    thrown.expectMessage("Could not transform metacard to a resource because the metacard is not valid.");
    String filePath = ABSOLUTE_PATH + TEST_PATH + TS_FILE_NAME_1;
    URI uri = getUri(filePath);
    Metacard metacard = getMockMetacard(uri);
    when(metacard.getId()).thenReturn(null);
    boolean expectSuccess = false;
    MimeType mimeType = getMimeType(VIDEO_MIME_TYPE);
    CatalogFramework framework = getFramework(getResourceResponse(getResource(mimeType, 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 23 with MimeType

use of javax.activation.MimeType 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 24 with MimeType

use of javax.activation.MimeType 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 25 with MimeType

use of javax.activation.MimeType 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

MimeType (javax.activation.MimeType)67 Test (org.junit.Test)38 Metacard (ddf.catalog.data.Metacard)21 URI (java.net.URI)14 HashMap (java.util.HashMap)14 MimeTypeParseException (javax.activation.MimeTypeParseException)14 MimeTypeToTransformerMapper (ddf.mime.MimeTypeToTransformerMapper)13 BundleContext (org.osgi.framework.BundleContext)13 ServiceReference (org.osgi.framework.ServiceReference)13 CatalogFramework (ddf.catalog.CatalogFramework)10 ResourceResponse (ddf.catalog.operation.ResourceResponse)10 Serializable (java.io.Serializable)9 Resource (ddf.catalog.resource.Resource)8 IOException (java.io.IOException)8 File (java.io.File)7 Matchers.anyString (org.mockito.Matchers.anyString)7 MetacardCreationException (ddf.catalog.data.MetacardCreationException)6 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)6 Response (javax.ws.rs.core.Response)6 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)5