Search in sources :

Example 41 with CatalogFramework

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

the class CatalogFrameworkImplTest method testProviderUnavailableCreate.

// End testing CatalogFramework
// Test negative use-cases (expected errors)
/**
     * Tests that the framework properly throws a catalog exception when the local provider is not
     * available for create.
     *
     * @throws SourceUnavailableException
     */
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableCreate() throws SourceUnavailableException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
    CatalogFramework framework = createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    metacards.add(newCard);
    CreateRequest create = new CreateRequestImpl(metacards);
    // expected to throw exception due to catalog provider being unavailable
    try {
        framework.create(create);
    } catch (IngestException e) {
        fail();
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) ContentType(ddf.catalog.data.ContentType) CreateRequest(ddf.catalog.operation.CreateRequest) CatalogFramework(ddf.catalog.CatalogFramework) ArrayList(java.util.ArrayList) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 42 with CatalogFramework

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

the class CatalogFrameworkImplTest method testProviderRuntimeExceptionOnCreate.

@Test(expected = IngestException.class)
public void testProviderRuntimeExceptionOnCreate() 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<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    metacards.add(newCard);
    CreateRequest create = new CreateRequestImpl((Metacard) null);
    try {
        framework.create(create);
    } catch (SourceUnavailableException e) {
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Metacard(ddf.catalog.data.Metacard) ContentType(ddf.catalog.data.ContentType) CreateRequest(ddf.catalog.operation.CreateRequest) CatalogFramework(ddf.catalog.CatalogFramework) ArrayList(java.util.ArrayList) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 43 with CatalogFramework

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

the class TestZipCompression method setUp.

@Before
public void setUp() throws Exception {
    JarSigner jarSigner = mock(JarSigner.class);
    doNothing().when(jarSigner).signJar(any(File.class), anyString(), anyString(), anyString(), anyString());
    zipCompression = new ZipCompression(jarSigner);
    sourceResponse = createSourceResponseWithURISchemes(null, null);
    filePathArgument = new HashMap<>();
    filePathArgument.put("filePath", temporaryFolder.getRoot().getAbsolutePath() + File.separator + "signed.zip");
    catalogFramework = mock(CatalogFramework.class);
    Resource resource = mock(Resource.class);
    InputStream resourceFileStream = new FileInputStream(new File(LOCAL_RESOURCE_PATH));
    when(resource.getName()).thenReturn(LOCAL_RESOURCE_FILENAME);
    when(resource.getInputStream()).thenReturn(resourceFileStream);
    ResourceResponse resourceResponse = new ResourceResponseImpl(resource);
    when(catalogFramework.getLocalResource(any(ResourceRequestById.class))).thenReturn(resourceResponse);
    zipCompression.setCatalogFramework(catalogFramework);
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CatalogFramework(ddf.catalog.CatalogFramework) Resource(ddf.catalog.resource.Resource) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 44 with CatalogFramework

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

the class CatalogFrameworkImplTest method testFederatedQueryPermissions.

@Test
public void testFederatedQueryPermissions() 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<>();
    Map<String, FederatedSource> sourceMap = new HashMap<>();
    Map<String, Set<String>> securityAttributes = new HashMap<>();
    securityAttributes.put("role", Collections.singleton("myRole"));
    MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true, securityAttributes);
    storeMap.put(store.getId(), store);
    sourceMap.put(store.getId(), store);
    CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, sourceMap, eventAdmin);
    List<Metacard> metacards = new ArrayList<>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    newCard.setContentTypeName("someType");
    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");
    framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Subject subject = mock(Subject.class);
    when(subject.isPermitted(any(KeyValueCollectionPermission.class))).thenReturn(true);
    HashMap<String, Serializable> properties = new HashMap<>();
    properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().like().text("someType"));
    QueryRequestImpl request = new QueryRequestImpl(query, false, Collections.singletonList("catalogStoreId-1"), properties);
    QueryResponse response = framework.query(request);
    assertThat(response.getResults().size(), is(1));
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) CatalogStore(ddf.catalog.source.CatalogStore) QueryImpl(ddf.catalog.operation.impl.QueryImpl) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) CatalogFramework(ddf.catalog.CatalogFramework) HashSet(java.util.HashSet) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Subject(ddf.security.Subject) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Test(org.junit.Test)

Example 45 with CatalogFramework

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

the class CatalogFrameworkImplTest method testProviderUnavailableUpdateByID.

/**
     * Tests that the framework properly throws a catalog exception when the local provider is not
     * available for update by id.
     *
     * @throws IngestException
     * @throws SourceUnavailableException
     */
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableUpdateByID() 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)

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