Search in sources :

Example 31 with ContentType

use of ddf.catalog.data.ContentType in project ddf by codice.

the class CatalogFrameworkImplTest method testMetacardTransformWithBadShortname.

@Ignore
@Test(expected = CatalogTransformerException.class)
public void testMetacardTransformWithBadShortname() throws CatalogTransformerException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
    // TODO pass in bundle context
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    framework.transform(newCard, "NONE", new HashMap<String, Serializable>());
}
Also used : Serializable(java.io.Serializable) ContentType(ddf.catalog.data.ContentType) CatalogFramework(ddf.catalog.CatalogFramework) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with ContentType

use of ddf.catalog.data.ContentType in project ddf by codice.

the class CatalogFrameworkImplTest method testProviderRuntimeExceptionOnUpdateByIdentifier.

@Test(expected = IngestException.class)
public void testProviderRuntimeExceptionOnUpdateByIdentifier() throws IngestException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    // use exception provider instead of memory
    MockExceptionProvider provider = new MockExceptionProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, null);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
    List<Entry<Object, Metacard>> metacards = new ArrayList<Entry<Object, Metacard>>();
    HashMap<Object, Metacard> map = new HashMap<Object, Metacard>();
    try {
        MetacardImpl newCard = new MetacardImpl();
        newCard.setId(null);
        newCard.setResourceURI(new URI("uri:///1234"));
        map.put(Metacard.ID, newCard);
        metacards.addAll(map.entrySet());
        UpdateRequest update = new UpdateRequestImpl(null, Metacard.RESOURCE_URI, null);
        framework.update(update);
    } catch (URISyntaxException e) {
        fail();
    } catch (SourceUnavailableException e) {
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ContentType(ddf.catalog.data.ContentType) HashMap(java.util.HashMap) 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) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) CatalogFramework(ddf.catalog.CatalogFramework) Matchers.anyObject(org.mockito.Matchers.anyObject) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 33 with ContentType

use of ddf.catalog.data.ContentType in project ddf by codice.

the class CatalogFrameworkImplTest method testProviderRuntimeExceptionOnDeleteByIdentifier.

@Test(expected = IngestException.class)
public void testProviderRuntimeExceptionOnDeleteByIdentifier() throws IngestException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    // use exception provider instead of memory
    MockExceptionProvider provider = new MockExceptionProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, null);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
    // List<MetacardType> identifiers = new ArrayList<MetacardType>();
    // identifiers.add( new MetacardTypeImpl( "id", "1234" ) );
    ArrayList<URI> uris = new ArrayList<URI>();
    DeleteRequest request = new DeleteRequestImpl((URI[]) uris.toArray(new URI[uris.size()]));
    // expected to throw exception due to catalog provider being unavailable
    try {
        framework.delete(request);
    } catch (SourceUnavailableException e) {
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ContentType(ddf.catalog.data.ContentType) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) CatalogFramework(ddf.catalog.CatalogFramework) ArrayList(java.util.ArrayList) URI(java.net.URI) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 34 with ContentType

use of ddf.catalog.data.ContentType 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 35 with ContentType

use of ddf.catalog.data.ContentType in project ddf by codice.

the class CatalogFrameworkImplTest method testGetAllSiteNames.

@Test
public void testGetAllSiteNames() {
    String frameworkName = "DDF";
    CatalogProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
    List<FederatedSource> federatedSources = createDefaultFederatedSourceList(true);
    // Expected Set of Names
    Set<String> expectedNameSet = new HashSet<String>();
    for (FederatedSource curSite : federatedSources) {
        expectedNameSet.add(curSite.getId());
    }
    // Mock register the provider in the container
    // Mock the source poller
    SourcePoller mockPoller = mock(SourcePoller.class);
    when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setSourcePoller(mockPoller);
    Map<String, FederatedSource> sources = new HashMap<>();
    for (FederatedSource federatedSource : federatedSources) {
        sources.put(federatedSource.getId(), federatedSource);
    }
    frameworkProperties.setFederatedSources(sources);
    frameworkProperties.setCatalogProviders(Collections.singletonList(provider));
    CatalogFrameworkImpl framework = createFramework(frameworkProperties);
    framework.setId(frameworkName);
    // Returned Set of Names
    // Returned Sites
    SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
    SourceInfoResponse response = null;
    try {
        response = framework.getSourceInfo(request);
    } catch (SourceUnavailableException e) {
        LOGGER.debug("SourceUnavilable", e);
        fail();
    }
    assert (response != null);
    Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
    // should contain ONLY the original federated sites
    assertEquals(expectedNameSet.size(), sourceDescriptors.size());
    Set<String> returnedSourceIds = new HashSet<String>();
    for (SourceDescriptor sd : sourceDescriptors) {
        returnedSourceIds.add(sd.getSourceId());
    }
    for (String id : returnedSourceIds) {
        LOGGER.debug("returned sourceId: {}", id);
    }
    assertTrue(expectedNameSet.equals(returnedSourceIds));
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) ContentType(ddf.catalog.data.ContentType) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) Date(java.util.Date) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) CachedSource(ddf.catalog.util.impl.CachedSource) FederatedSource(ddf.catalog.source.FederatedSource) SourcePoller(ddf.catalog.util.impl.SourcePoller) FederatedSource(ddf.catalog.source.FederatedSource) CatalogProvider(ddf.catalog.source.CatalogProvider) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ContentType (ddf.catalog.data.ContentType)45 Test (org.junit.Test)34 CatalogFramework (ddf.catalog.CatalogFramework)17 ArrayList (java.util.ArrayList)17 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 Metacard (ddf.catalog.data.Metacard)12 ContentTypeImpl (ddf.catalog.data.impl.ContentTypeImpl)12 Source (ddf.catalog.source.Source)10 Date (java.util.Date)10 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 HashSet (java.util.HashSet)8 Matchers.anyString (org.mockito.Matchers.anyString)7 IngestException (ddf.catalog.source.IngestException)6 URI (java.net.URI)5 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)4 CatalogProvider (ddf.catalog.source.CatalogProvider)4 SourceDescriptor (ddf.catalog.source.SourceDescriptor)4 SourcePoller (ddf.catalog.util.impl.SourcePoller)4 URISyntaxException (java.net.URISyntaxException)4 QName (javax.xml.namespace.QName)4