Search in sources :

Example 16 with BinaryContentImpl

use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.

the class BinaryContentImplTest method testBinaryContentImplSizeNotSet.

@Test
public void testBinaryContentImplSizeNotSet() {
    InputStream is;
    try {
        is = new FileInputStream(content);
        BinaryContentImpl bci = new BinaryContentImpl(is, mimeType);
        assertEquals(-1, bci.getSize());
    } catch (IOException e) {
        LOGGER.error("IO Failure", e);
        new Failure(null, e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Failure(org.junit.runner.notification.Failure) Test(org.junit.Test)

Example 17 with BinaryContentImpl

use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testMetacardTransform.

@Test
public void testMetacardTransform() throws Exception {
    BundleContext context = mock(BundleContext.class);
    MetacardTransformer transformer = mock(MetacardTransformer.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(Metacard.class), isA(Map.class))).thenReturn(new BinaryContentImpl(null));
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    BinaryContent content = framework.transform(newCard, "NONE", new HashMap<String, Serializable>());
    assertNotNull(content);
}
Also used : Serializable(java.io.Serializable) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ServiceReference(org.osgi.framework.ServiceReference) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 18 with BinaryContentImpl

use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.

the class CswQueryResponseTransformer method transform.

@Override
public BinaryContent transform(SourceResponse sourceResponse, Map<String, Serializable> arguments) throws CatalogTransformerException {
    validateInput(sourceResponse, arguments);
    CswRecordCollection recordCollection = buildCollection(sourceResponse, arguments);
    ByteArrayInputStream bais;
    if (ResultType.VALIDATE.equals(recordCollection.getResultType())) {
        ByteArrayOutputStream baos = writeAcknowledgement(recordCollection.getRequest());
        bais = new ByteArrayInputStream(baos.toByteArray());
    } else {
        // "catches" recordCollection.getResultType() == null
        List<Result> results = sourceResponse.getResults();
        String xmlString = convert(recordCollection, results, arguments);
        bais = new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8));
    }
    BinaryContent transformedContent = new BinaryContentImpl(bais, CswRecordConverter.XML_MIME_TYPE);
    return transformedContent;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) BinaryContent(ddf.catalog.data.BinaryContent) Result(ddf.catalog.data.Result)

Example 19 with BinaryContentImpl

use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.

the class WorkspaceTransformerTest method setup.

@Before
public void setup() throws Exception {
    cf = Mockito.mock(CatalogFramework.class);
    doReturn(new BinaryContentImpl(IOUtils.toInputStream("<xml></xml>"))).when(cf).transform(any(Metacard.class), any(String.class), any(Map.class));
    it = Mockito.mock(InputTransformer.class);
    doReturn(new QueryMetacardImpl("my query")).when(it).transform(any(InputStream.class));
    ut = Mockito.mock(EndpointUtil.class);
    wt = new WorkspaceTransformer(cf, it, ut);
}
Also used : Metacard(ddf.catalog.data.Metacard) InputStream(java.io.InputStream) CatalogFramework(ddf.catalog.CatalogFramework) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) InputTransformer(ddf.catalog.transform.InputTransformer) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) EndpointUtil(org.codice.ddf.catalog.ui.util.EndpointUtil) Before(org.junit.Before)

Example 20 with BinaryContentImpl

use of ddf.catalog.data.impl.BinaryContentImpl in project ddf by codice.

the class MetacardBackupPluginTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    metacardTransformer = mock(MetacardTransformer.class);
    BinaryContent binaryContent = new BinaryContentImpl(new ByteArrayInputStream(XML_METADATA.getBytes(StandardCharsets.UTF_8)));
    when(metacardTransformer.transform(any(Metacard.class), anyMap())).thenReturn(binaryContent);
    doThrow(new MetacardBackupException("Not Implemented")).when(mockProvider).store(any(), any());
    doThrow(new MetacardBackupException("Not Implemented")).when(mockProvider).delete(any());
    doReturn(MOCK_ID).when(mockProvider).getId();
    metacardBackupPlugin = new MetacardBackupPlugin();
    metacardBackupPlugin.setMetacardTransformerId(METACARD_TRANSFORMER_ID);
    metacardBackupPlugin.setMetacardTransformer(metacardTransformer);
    createRequest = generateProcessRequest(ProcessCreateItem.class, true);
    updateRequest = generateProcessRequest(ProcessUpdateItem.class, true);
    deleteRequest = generateDeleteRequest();
    fileStorageProvider.setId(FILE_STORAGE_PROVIDER_ID);
    fileStorageProvider.setOutputDirectory(OUTPUT_DIRECTORY);
    metacardBackupPlugin.setMetacardOutputProviderIds(Collections.singletonList(FILE_STORAGE_PROVIDER_ID));
    metacardBackupPlugin.setStorageBackupPlugins(Arrays.asList(new MetacardBackupStorageProvider[] { fileStorageProvider }));
}
Also used : MetacardBackupException(org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupException) Metacard(ddf.catalog.data.Metacard) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessCreateItem(org.codice.ddf.catalog.async.data.api.internal.ProcessCreateItem) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) MetacardBackupStorageProvider(org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupStorageProvider) BinaryContent(ddf.catalog.data.BinaryContent) ProcessUpdateItem(org.codice.ddf.catalog.async.data.api.internal.ProcessUpdateItem) Before(org.junit.Before)

Aggregations

BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)33 ByteArrayInputStream (java.io.ByteArrayInputStream)19 InputStream (java.io.InputStream)12 Test (org.junit.Test)12 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)11 IOException (java.io.IOException)11 BinaryContent (ddf.catalog.data.BinaryContent)10 HashMap (java.util.HashMap)10 FileInputStream (java.io.FileInputStream)9 Metacard (ddf.catalog.data.Metacard)8 MimeType (javax.activation.MimeType)8 Map (java.util.Map)7 Matchers.anyString (org.mockito.Matchers.anyString)6 Result (ddf.catalog.data.Result)5 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)4 TreeMarshaller (com.thoughtworks.xstream.core.TreeMarshaller)4 StringWriter (java.io.StringWriter)4 MimeTypeParseException (javax.activation.MimeTypeParseException)4 Failure (org.junit.runner.notification.Failure)4 CatalogFramework (ddf.catalog.CatalogFramework)3