Search in sources :

Example 46 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class CatalogFrameworkImplTest method testQueryTransformWithNullResponse.

@Test(expected = IllegalArgumentException.class)
public void testQueryTransformWithNullResponse() throws Exception {
    BundleContext context = mock(BundleContext.class);
    ServiceReference reference = mock(ServiceReference.class);
    ServiceReference[] serviceReferences = new ServiceReference[] { reference };
    when(context.getServiceReferences(anyString(), anyString())).thenReturn(serviceReferences);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
    framework.transform((SourceResponse) null, "NONE", new HashMap<String, Serializable>());
}
Also used : Serializable(java.io.Serializable) CatalogFramework(ddf.catalog.CatalogFramework) Matchers.anyString(org.mockito.Matchers.anyString) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 47 with CatalogFramework

use of ddf.catalog.CatalogFramework 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);
}
Also used : Serializable(java.io.Serializable) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) Matchers.anyString(org.mockito.Matchers.anyString) BinaryContent(ddf.catalog.data.BinaryContent) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ServiceReference(org.osgi.framework.ServiceReference) Metacard(ddf.catalog.data.Metacard) 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)

Example 48 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class CatalogFrameworkImplTest method testProviderUnavailableDeleteByIdentifier.

/**
     * Tests that the framework properly throws a catalog exception when the local provider is not
     * available for delete by identifier.
     *
     * @throws IngestException
     * @throws SourceUnavailableException
     */
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableDeleteByIdentifier() throws SourceUnavailableException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
    List<URI> uris = new ArrayList<URI>();
    try {
        uris.add(new URI("id://1234"));
        DeleteRequest request = new DeleteRequestImpl((URI[]) uris.toArray(new URI[uris.size()]));
        // expected to throw exception due to catalog provider being
        // unavailable
        framework.delete(request);
    } catch (URISyntaxException e) {
        fail();
    } catch (IngestException e) {
        fail();
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) CatalogFramework(ddf.catalog.CatalogFramework) ArrayList(java.util.ArrayList) IngestException(ddf.catalog.source.IngestException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 49 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class FtpRequestHandlerTest method testMimeTypeMapperNull.

@Test(expected = IllegalArgumentException.class)
public void testMimeTypeMapperNull() {
    String mimeType;
    catalogFramework = mock(CatalogFramework.class);
    FtpRequestHandler ftplett = new FtpRequestHandler(catalogFramework, null, uuidGenerator);
    mimeType = ftplett.getMimeType("xml", new TemporaryFileBackedOutputStream());
    assertEquals("", mimeType);
}
Also used : TemporaryFileBackedOutputStream(org.codice.ddf.platform.util.TemporaryFileBackedOutputStream) CatalogFramework(ddf.catalog.CatalogFramework) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 50 with CatalogFramework

use of ddf.catalog.CatalogFramework in project ddf by codice.

the class SeedCommandTest method mockQueryResponse.

private void mockQueryResponse(int stopReturningResultsAtIndex, String[] ids, boolean[] cached) throws Exception {
    List<Result> results = new ArrayList<>();
    for (int i = 0; i < ids.length; ++i) {
        String id = ids[i];
        Result mockResult = mock(Result.class);
        MetacardImpl metacard = new MetacardImpl();
        metacard.setId(id);
        metacard.setSourceId(id);
        metacard.setAttribute("internal.local-resource", cached[i]);
        when(mockResult.getMetacard()).thenReturn(metacard);
        results.add(mockResult);
    }
    QueryResponse response = mock(QueryResponse.class);
    when(response.getResults()).thenReturn(results);
    doReturn(response).when(catalogFramework).query(argThat(is(queryWithStartIndex(request -> request.getQuery().getStartIndex() < stopReturningResultsAtIndex))));
    QueryResponse noResults = mock(QueryResponse.class);
    when(noResults.getResults()).thenReturn(Collections.emptyList());
    doReturn(noResults).when(catalogFramework).query(argThat(is(queryWithStartIndex(request -> request.getQuery().getStartIndex() >= stopReturningResultsAtIndex))));
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) CatalogFramework(ddf.catalog.CatalogFramework) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Resource(ddf.catalog.resource.Resource) Assert.assertThat(org.junit.Assert.assertThat) ArgumentMatcher(org.mockito.ArgumentMatcher) ArgumentCaptor(org.mockito.ArgumentCaptor) CQL(org.geotools.filter.text.cql2.CQL) Metacard(ddf.catalog.data.Metacard) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) QueryRequest(ddf.catalog.operation.QueryRequest) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Matchers.anyInt(org.mockito.Matchers.anyInt) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Mockito.doReturn(org.mockito.Mockito.doReturn) Result(ddf.catalog.data.Result) Before(org.junit.Before) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Predicate(java.util.function.Predicate) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Consumer(java.util.function.Consumer) Query(ddf.catalog.operation.Query) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Matchers.argThat(org.mockito.Matchers.argThat) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) InputStream(java.io.InputStream) QueryResponse(ddf.catalog.operation.QueryResponse) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.containsString(org.hamcrest.Matchers.containsString) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result)

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