use of ddf.catalog.CatalogFramework in project ddf by codice.
the class ContentProducerDataAccessObjectTest method testCreateContentItem.
@Test
public void testCreateContentItem() throws Exception {
File testFile = temporaryFolder.newFile("testCreateContentItem.txt");
//make sample list of metacard and set of keys
List<MetacardImpl> metacardList = ImmutableList.of(new MetacardImpl());
Set<String> keys = ImmutableSet.of(String.valueOf(testFile.getAbsolutePath().hashCode()));
//mock out responses for create, delete, update
CreateResponse mockCreateResponse = mock(CreateResponse.class);
doReturn(metacardList).when(mockCreateResponse).getCreatedMetacards();
DeleteResponse mockDeleteResponse = mock(DeleteResponse.class);
doReturn(metacardList).when(mockDeleteResponse).getDeletedMetacards();
UpdateResponse mockUpdateResponse = mock(UpdateResponse.class);
doReturn(metacardList).when(mockUpdateResponse).getUpdatedMetacards();
//setup mockFileSystemPersistenceProvider
FileSystemPersistenceProvider mockFileSystemPersistenceProvider = mock(FileSystemPersistenceProvider.class);
doReturn(keys).when(mockFileSystemPersistenceProvider).loadAllKeys();
doReturn("sample").when(mockFileSystemPersistenceProvider).loadFromPersistence(any(String.class));
//setup mockCatalogFramework
CatalogFramework mockCatalogFramework = mock(CatalogFramework.class);
doReturn(mockCreateResponse).when(mockCatalogFramework).create(any(CreateStorageRequest.class));
doReturn(mockDeleteResponse).when(mockCatalogFramework).delete(any(DeleteRequest.class));
//setup mockComponent
ContentComponent mockComponent = mock(ContentComponent.class);
doReturn(mockCatalogFramework).when(mockComponent).getCatalogFramework();
//setup mockEndpoint
ContentEndpoint mockEndpoint = mock(ContentEndpoint.class);
doReturn(mockComponent).when(mockEndpoint).getComponent();
WatchEvent.Kind<Path> kind;
String mimeType = "txt";
Map<String, Object> headers = new HashedMap();
Map<String, Serializable> attributeOverrides = new HashMap<>();
attributeOverrides.put("example", ImmutableList.of("something", "something1"));
attributeOverrides.put("example2", ImmutableList.of("something2"));
headers.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeOverrides);
kind = StandardWatchEventKinds.ENTRY_CREATE;
contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers);
kind = StandardWatchEventKinds.ENTRY_DELETE;
contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers);
kind = StandardWatchEventKinds.ENTRY_MODIFY;
contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers);
}
use of ddf.catalog.CatalogFramework in project ddf by codice.
the class DescribeCommandTest method setUp.
@Before
public void setUp() throws Exception {
describeCommand = new DescribeCommand();
CatalogProvider catalogProvider = mock(CatalogProvider.class);
doReturn(TEST_CATALOG_PROVIDER_TITLE).when(catalogProvider).getTitle();
doReturn(TEST_CATALOG_PROVIDER_DESCRIPTION).when(catalogProvider).getDescription();
doReturn(TEST_CATALOG_PROVIDER_ID).when(catalogProvider).getId();
doReturn(TEST_CATALOG_PROVIDER_VERSION).when(catalogProvider).getVersion();
describeCommand.catalogProvider = catalogProvider;
CatalogFramework catalogFramework = mock(CatalogFramework.class);
doReturn(TEST_CATALOG_FRAMEWORK_TITLE).when(catalogFramework).getTitle();
doReturn(TEST_CATALOG_FRAMEWORK_DESCRIPTION).when(catalogFramework).getDescription();
doReturn(TEST_CATALOG_FRAMEWORK_ID).when(catalogFramework).getId();
doReturn(TEST_CATALOG_FRAMEWORK_VERSION).when(catalogFramework).getVersion();
describeCommand.catalogFramework = catalogFramework;
}
use of ddf.catalog.CatalogFramework in project ddf by codice.
the class RemoveAllCommandTest method testExecuteWithSubject.
/**
* Checks the forced (-f) generic case.
*
* @throws Exception
*/
@Test
public void testExecuteWithSubject() throws Exception {
// given
RemoveAllCommand removeAllCommand = new RemoveAllCommand();
final CatalogFramework catalogFramework = mock(CatalogFramework.class);
QueryResponse queryResponse = mock(QueryResponse.class);
when(queryResponse.getResults()).thenReturn(getResultList(10));
when(catalogFramework.query(isA(QueryRequest.class))).thenReturn(queryResponse);
DeleteResponse deleteResponse = mock(DeleteResponse.class);
when(deleteResponse.getDeletedMetacards()).thenReturn(getMetacardList(10));
when(catalogFramework.delete(isA(DeleteRequest.class))).thenReturn(deleteResponse);
removeAllCommand.catalogFramework = catalogFramework;
removeAllCommand.filterBuilder = new GeotoolsFilterBuilder();
removeAllCommand.batchSize = 11;
removeAllCommand.force = true;
// when
removeAllCommand.executeWithSubject();
// then
verify(catalogFramework, times(1)).delete(isA(DeleteRequest.class));
}
use of ddf.catalog.CatalogFramework in project ddf by codice.
the class ReplicateCommandTest method setUp.
@Before
public void setUp() throws UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
catalogFramework = mock(CatalogFramework.class);
replicateCommand = new ReplicateCommand() {
@Override
public String getInput(String message) throws IOException {
return "sourceId1";
}
};
replicateCommand.catalogFramework = catalogFramework;
replicateCommand.filterBuilder = new GeotoolsFilterBuilder();
when(mockSession.getKeyboard()).thenReturn(mockIS);
when(catalogFramework.getSourceIds()).thenReturn(SOURCE_IDS);
when(catalogFramework.query(isA(QueryRequest.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
QueryRequest request = (QueryRequest) args[0];
QueryResponse mockQueryResponse = mock(QueryResponse.class);
when(mockQueryResponse.getHits()).thenReturn(Long.valueOf(HITS));
when(mockQueryResponse.getResults()).thenReturn(getResultList(Math.min(replicateCommand.batchSize, HITS - request.getQuery().getStartIndex() + 1)));
return mockQueryResponse;
});
when(catalogFramework.create(isA(CreateRequest.class))).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
CreateRequest request = (CreateRequest) args[0];
when(mockCreateResponse.getCreatedMetacards()).thenReturn(request.getMetacards());
return mockCreateResponse;
});
}
use of ddf.catalog.CatalogFramework in project ddf by codice.
the class CatalogFrameworkImplTest method testQueryTransform.
@Test
public void testQueryTransform() throws Exception {
BundleContext context = mock(BundleContext.class);
QueryResponseTransformer transformer = mock(QueryResponseTransformer.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(SourceResponse.class), isA(Map.class))).thenReturn(new BinaryContentImpl(null));
CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
SourceResponse response = new SourceResponseImpl(null, null);
BinaryContent content = framework.transform(response, "NONE", new HashMap<String, Serializable>());
assertNotNull(content);
}
Aggregations