Search in sources :

Example 1 with CatalogFramework

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);
}
Also used : Path(java.nio.file.Path) Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) UpdateResponse(ddf.catalog.operation.UpdateResponse) DeleteResponse(ddf.catalog.operation.DeleteResponse) CatalogFramework(ddf.catalog.CatalogFramework) WatchEvent(java.nio.file.WatchEvent) HashedMap(org.apache.commons.collections.map.HashedMap) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File) DeleteRequest(ddf.catalog.operation.DeleteRequest) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Example 2 with CatalogFramework

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;
}
Also used : CatalogProvider(ddf.catalog.source.CatalogProvider) CatalogFramework(ddf.catalog.CatalogFramework) Before(org.junit.Before)

Example 3 with 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));
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) QueryRequest(ddf.catalog.operation.QueryRequest) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) CatalogFramework(ddf.catalog.CatalogFramework) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 4 with CatalogFramework

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;
    });
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) CreateRequest(ddf.catalog.operation.CreateRequest) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) QueryResponse(ddf.catalog.operation.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) Before(org.junit.Before)

Example 5 with CatalogFramework

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());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) CatalogStore(ddf.catalog.source.CatalogStore) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

CatalogFramework (ddf.catalog.CatalogFramework)80 Test (org.junit.Test)63 Matchers.anyString (org.mockito.Matchers.anyString)30 Metacard (ddf.catalog.data.Metacard)27 QueryResponse (ddf.catalog.operation.QueryResponse)20 ArrayList (java.util.ArrayList)20 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)19 Serializable (java.io.Serializable)18 ContentType (ddf.catalog.data.ContentType)17 URI (java.net.URI)17 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 HashMap (java.util.HashMap)14 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)12 Date (java.util.Date)12 BundleContext (org.osgi.framework.BundleContext)11 MimeType (javax.activation.MimeType)10 Response (javax.ws.rs.core.Response)10 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)9 ServiceReference (org.osgi.framework.ServiceReference)9 FilterBuilder (ddf.catalog.filter.FilterBuilder)8