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 testCreateWithStores.
@Test
public void testCreateWithStores() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
Map<String, CatalogStore> storeMap = new HashMap<>();
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
storeMap.put(store.getId(), store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, null, eventAdmin);
List<Metacard> metacards = new ArrayList<>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
metacards.add(newCard);
Map<String, Serializable> reqProps = new HashMap<>();
HashSet<String> destinations = new HashSet<>();
//==== test writing to store and not local ====
destinations.add("catalogStoreId-1");
CreateResponse response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(0, provider.size());
assertEquals(response.getCreatedMetacards().size(), store.size());
assertEquals(1, store.size());
assertFalse(eventAdmin.wasEventPosted());
//==== test writing to store and local ====
destinations.add("mockMemoryProvider");
newCard.setId(null);
reqProps = new HashMap<>();
response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(1, provider.size());
assertEquals(response.getCreatedMetacards().size(), provider.size());
assertEquals(2, store.size());
assertTrue(eventAdmin.wasEventPosted());
//==== test writing to local when no destination ====
destinations.clear();
newCard.setId(null);
reqProps = new HashMap<>();
response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(2, provider.size());
assertEquals(response.getCreatedMetacards().size(), 1);
assertEquals(2, store.size());
}
Aggregations