use of ddf.catalog.operation.DeleteRequest in project ddf by codice.
the class TestMetacardGroomerPlugin method testDelete.
@Test
public void testDelete() throws PluginExecutionException, StopProcessingException, ParseException {
DeleteRequest inputRequest = new DeleteRequestImpl(SAMPLE_ID);
DeleteRequest returnedRequest = plugin.process(inputRequest);
assertNotNull(returnedRequest);
assertThat(returnedRequest, equalTo(inputRequest));
}
use of ddf.catalog.operation.DeleteRequest in project ddf by codice.
the class SolrProviderTest method testDeleteAlternativeAttribute.
/**
* Testing if another attribute can be used to delete records other than {@link Metacard#ID}
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testDeleteAlternativeAttribute() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
CreateResponse createResponse = create(metacard);
DeleteResponse deleteResponse = provider.delete(new DeleteRequest() {
@Override
public boolean hasProperties() {
return false;
}
@Override
public Serializable getPropertyValue(String name) {
return null;
}
@Override
public Set<String> getPropertyNames() {
return null;
}
@Override
public Map<String, Serializable> getProperties() {
return null;
}
@Override
public boolean containsPropertyName(String name) {
return false;
}
@Override
public List<? extends Serializable> getAttributeValues() {
return Arrays.asList(MockMetacard.DEFAULT_TITLE);
}
@Override
public String getAttributeName() {
return Metacard.TITLE;
}
});
Metacard deletedMetacard = deleteResponse.getDeletedMetacards().get(0);
verifyDeletedRecord(metacard, createResponse, deleteResponse, deletedMetacard);
// verify it is really not in SOLR
Filter filter = filterBuilder.attribute(Metacard.TITLE).like().text(MockMetacard.DEFAULT_TITLE);
QueryImpl query = new QueryImpl(filter);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
List<Result> results = sourceResponse.getResults();
assertEquals(0, results.size());
}
use of ddf.catalog.operation.DeleteRequest in project ddf by codice.
the class SolrProviderTest method testDeleteNoList.
@Test
public void testDeleteNoList() throws IngestException, UnsupportedQueryException {
/* EMPTY */
DeleteRequestImpl deleteRequest = new DeleteRequestImpl(new String[0]);
DeleteResponse results = provider.delete(deleteRequest);
assertNotNull(results.getDeletedMetacards());
assertEquals(0, results.getDeletedMetacards().size());
assertEquals(deleteRequest, results.getRequest());
/* EMPTY */
DeleteRequestImpl emptyDeleteRequest = new DeleteRequestImpl(new ArrayList<Serializable>(), DeleteRequest.DELETE_BY_ID, null);
results = provider.delete(emptyDeleteRequest);
assertNotNull(results.getDeletedMetacards());
assertEquals(0, results.getDeletedMetacards().size());
assertEquals(emptyDeleteRequest, results.getRequest());
/* NULL */
DeleteRequest nullDeleteRequest = new DeleteRequestImpl(null, DeleteRequest.DELETE_BY_ID, null);
results = provider.delete(nullDeleteRequest);
assertNotNull(results.getDeletedMetacards());
assertEquals(0, results.getDeletedMetacards().size());
assertEquals(nullDeleteRequest, results.getRequest());
}
use of ddf.catalog.operation.DeleteRequest 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(), anyObject())).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.DeleteRequest in project ddf by codice.
the class CatalogFrameworkImplTest method testDeleteWithStores.
// TODO (DDF-2436) -
@Ignore
@Test
public void testDeleteWithStores() 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<>();
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
storeMap.put(store.getId(), store);
sourceMap.put(store.getId(), store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, sourceMap, eventAdmin);
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "*", "*", "?", "/", false);
List<Metacard> metacards = new ArrayList<>();
String id = UUID.randomUUID().toString().replaceAll("-", "");
MetacardImpl newCard = new MetacardImpl();
newCard.setId(id);
newCard.setAttribute("myKey", "myValue1");
metacards.add(newCard);
Map<String, Serializable> reqProps = new HashMap<>();
HashSet<String> destinations = new HashSet<>();
destinations.add("mockMemoryProvider");
destinations.add("catalogStoreId-1");
framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
DeleteRequest deleteRequest = new DeleteRequestImpl(Collections.singletonList(id), Metacard.ID, new HashMap<>(), destinations);
DeleteResponse response = framework.delete(deleteRequest);
assertThat(response.getDeletedMetacards().size(), is(1));
QueryResponse queryResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), true));
assertThat(queryResponse.getResults().size(), is(0));
}
Aggregations