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();
}
}
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();
}
}
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);
}
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));
}
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();
}
}
Aggregations