Search in sources :

Example 36 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 37 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 38 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 39 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 40 with CatalogFramework

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);
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) ServiceReference(org.osgi.framework.ServiceReference) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) 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)

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