use of ddf.catalog.operation.DeleteResponse 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.DeleteResponse in project ddf by codice.
the class SolrProviderTest method testDeleteNothing.
/**
* Tests the provider will allow you to delete nothing.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testDeleteNothing() throws IngestException, UnsupportedQueryException {
// Single Deletion
deleteAllIn(provider);
DeleteResponse deleteResponse = delete("no_such_record");
assertThat(deleteResponse.getDeletedMetacards().size(), equalTo(0));
}
use of ddf.catalog.operation.DeleteResponse in project ddf by codice.
the class SolrProviderTest method testDeleteOperation.
/**
* Testing that if records are properly deleted.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testDeleteOperation() throws IngestException, UnsupportedQueryException {
// Single Deletion
deleteAllIn(provider);
MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
CreateResponse createResponse = create(metacard);
DeleteResponse deleteResponse = delete(createResponse.getCreatedMetacards().get(0).getId());
Metacard deletedMetacard = deleteResponse.getDeletedMetacards().get(0);
verifyDeletedRecord(metacard, createResponse, deleteResponse, deletedMetacard);
}
use of ddf.catalog.operation.DeleteResponse 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.DeleteResponse 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));
}
Aggregations