use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnDelete.
@Test
public void testInjectsAttributesOnDelete() throws Exception {
final String title = "Delete this";
final String injectAttributeName = "new attribute";
final double injectAttributeValue = 11.1;
final MetacardImpl metacard = new MetacardImpl();
metacard.setTitle(title);
metacard.setAttribute(injectAttributeName, injectAttributeValue);
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(metacard), null)).getCreatedMetacards().get(0).getId();
final DeleteRequest request = new DeleteRequestImpl(id);
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
List<Result> mockFederationResults = Stream.of(metacard).map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), any())).thenReturn(queryResponse);
when(mockRemoteDeleteOperations.performRemoteDelete(any(), any())).then(returnsSecondArg());
deleteOperations.setRemoteDeleteOperations(mockRemoteDeleteOperations);
final DeleteResponse response = framework.delete(request);
final Metacard deletedMetacard = response.getDeletedMetacards().get(0);
final MetacardType originalMetacardType = metacard.getMetacardType();
final MetacardType deletedMetacardType = deletedMetacard.getMetacardType();
assertThat(deletedMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(deletedMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(deletedMetacard.getTitle(), is(title));
assertThat(deletedMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testDelete.
/**
* Tests that the framework properly passes a delete request to the local provider.
*/
@Test
public void testDelete() throws Exception {
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
metacards.add(newCard);
// create the entry manually in the provider
Metacard insertedCard = provider.create(new CreateRequestImpl(metacards, null)).getCreatedMetacards().iterator().next();
String[] ids = new String[1];
ids[0] = insertedCard.getId();
Result mockFederationResult = mock(Result.class);
MetacardImpl metacard = new MetacardImpl();
metacard.setId(ids[0]);
when(mockFederationResult.getMetacard()).thenReturn(metacard);
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), Collections.singletonList(mockFederationResult), 1);
when(mockFederationStrategy.federate(anyList(), any())).thenReturn(queryResponse);
when(mockRemoteDeleteOperations.performRemoteDelete(any(), any())).then(returnsSecondArg());
deleteOperations.setRemoteDeleteOperations(mockRemoteDeleteOperations);
// send delete to framework
List<Metacard> returnedCards = framework.delete(new DeleteRequestImpl(ids)).getDeletedMetacards();
assertEquals(ids.length, returnedCards.size());
// make sure that the event was posted correctly
Metacard[] array = {};
array = returnedCards.toArray(array);
assertTrue(eventAdmin.wasEventPosted());
assertEquals(eventAdmin.getLastEvent(), array[array.length - 1]);
}
use of ddf.catalog.operation.impl.CreateRequestImpl 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.operation.impl.CreateRequestImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testCreateWithStores.
@Test
public void testCreateWithStores() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
List<CatalogStore> stores = new ArrayList<>();
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
stores.add(store);
CatalogFramework framework = createDummyCatalogFramework(provider, stores, null, eventAdmin);
List<Metacard> metacards = new ArrayList<>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
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");
CreateResponse response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(0, provider.size());
assertEquals(response.getCreatedMetacards().size(), store.size());
assertEquals(1, store.size());
assertFalse(eventAdmin.wasEventPosted());
// ==== test writing to store and local ====
destinations.add("mockMemoryProvider");
newCard.setId(null);
reqProps = new HashMap<>();
response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(1, provider.size());
assertEquals(response.getCreatedMetacards().size(), provider.size());
assertEquals(2, store.size());
assertTrue(eventAdmin.wasEventPosted());
// ==== test writing to local when no destination ====
destinations.clear();
newCard.setId(null);
reqProps = new HashMap<>();
response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(2, provider.size());
assertEquals(response.getCreatedMetacards().size(), 1);
assertEquals(2, store.size());
}
use of ddf.catalog.operation.impl.CreateRequestImpl 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();
}
}
Aggregations