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);
}
}
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);
}
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;
}
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);
}
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 }));
}
Aggregations