Search in sources :

Example 56 with CatalogFramework

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

the class CatalogFrameworkImplTest method testMetacardTransformWithTransformException.

@Test(expected = CatalogTransformerException.class)
public void testMetacardTransformWithTransformException() 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))).thenThrow(new CatalogTransformerException("Could not transform"));
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    framework.transform(newCard, "NONE", new HashMap<String, Serializable>());
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) CatalogFramework(ddf.catalog.CatalogFramework) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 57 with CatalogFramework

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

the class CatalogFrameworkImplTest method testProviderUnavailableUpdateByIdentifier.

/**
     * Tests that the framework properly throws a catalog exception when the local provider is not
     * available for update by identifier.
     *
     * @throws IngestException
     * @throws SourceUnavailableException
     */
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableUpdateByIdentifier() 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<Metacard> metacards = new ArrayList<Metacard>();
    List<URI> uris = new ArrayList<URI>();
    // expected to throw exception due to catalog provider being unavailable
    try {
        MetacardImpl newCard = new MetacardImpl();
        newCard.setId(null);
        newCard.setResourceURI(new URI("uri:///1234"));
        metacards.add(newCard);
        uris.add(new URI("uri:////1234"));
        UpdateRequest update = new UpdateRequestImpl((URI[]) uris.toArray(new URI[uris.size()]), metacards);
        framework.update(update);
    } catch (URISyntaxException e) {
        fail();
    } catch (IngestException e) {
        fail();
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) IngestException(ddf.catalog.source.IngestException) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 58 with CatalogFramework

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

the class CatalogFrameworkImplTest method testNullFederatedQuery.

/**
     * Tests that the framework properly throws a catalog exception when the federated query being
     * passed in is null.
     *
     * @throws UnsupportedQueryException
     */
@Test(expected = UnsupportedQueryException.class)
public void testNullFederatedQuery() throws UnsupportedQueryException {
    boolean isAvailable = false;
    CatalogProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), isAvailable, new Date());
    createDefaultFederatedSourceList(isAvailable);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, null, true);
    try {
        framework.query(null, null);
    } catch (FederationException e) {
        fail();
    } catch (SourceUnavailableException e) {
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ContentType(ddf.catalog.data.ContentType) CatalogProvider(ddf.catalog.source.CatalogProvider) CatalogFramework(ddf.catalog.CatalogFramework) FederationException(ddf.catalog.federation.FederationException) Date(java.util.Date) Test(org.junit.Test)

Example 59 with CatalogFramework

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

the class CatalogFrameworkImplTest method testNullEntriesCreate.

@Test(expected = IngestException.class)
public void testNullEntriesCreate() throws IngestException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
    // call framework with null request
    try {
        framework.create((CreateRequest) null);
    } catch (SourceUnavailableException e) {
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ContentType(ddf.catalog.data.ContentType) CatalogFramework(ddf.catalog.CatalogFramework) Date(java.util.Date) Test(org.junit.Test)

Example 60 with CatalogFramework

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

the class CatalogFrameworkImplTest method testQueryTransformWithInvalidSyntaxException.

@Test(expected = IllegalArgumentException.class)
public void testQueryTransformWithInvalidSyntaxException() throws Exception {
    BundleContext context = mock(BundleContext.class);
    when(context.getServiceReferences(anyString(), anyString())).thenThrow(new InvalidSyntaxException("Invalid Syntax", ""));
    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) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Matchers.anyString(org.mockito.Matchers.anyString) 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