use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class TestMetacardGroomerPlugin method testUpdateWithNullRecords.
@Test
public void testUpdateWithNullRecords() throws PluginExecutionException, StopProcessingException {
UpdateRequest request = mock(UpdateRequest.class);
when(request.getUpdates()).thenReturn(null);
UpdateRequest returnedRequest = plugin.process(request);
assertThat(returnedRequest, not(nullValue()));
assertThat(returnedRequest.getUpdates(), nullValue());
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class TestMetacardGroomerPlugin method testUpdateWithNoRecords.
@Test
public void testUpdateWithNoRecords() throws PluginExecutionException, StopProcessingException {
UpdateRequest request = mock(UpdateRequest.class);
when(request.getUpdates()).thenReturn(new ArrayList<>());
UpdateRequest returnedRequest = plugin.process(request);
assertThat(returnedRequest, not(nullValue()));
assertThat(returnedRequest.getUpdates(), not(nullValue()));
assertThat(returnedRequest.getUpdates().size(), is(0));
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class CachingFederationStrategyTest method testProcessUpdateResponseRequestNotLocal.
@Test
public void testProcessUpdateResponseRequestNotLocal() throws Exception {
Map<String, Serializable> testMap = new HashMap<>();
testMap.put(Constants.SERVICE_TITLE, MOCK_RESPONSE_TITLE);
testMap.put(Constants.LOCAL_DESTINATION_KEY, false);
UpdateResponse response = mock(UpdateResponseImpl.class);
UpdateRequest request = mock(UpdateRequestImpl.class);
when(request.hasProperties()).thenReturn(true);
when(request.getProperties()).thenReturn(testMap);
when(response.getRequest()).thenReturn(request);
assertThat(response, is(strategy.process(response)));
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnUpdate.
@Test
public void testInjectsAttributesOnUpdate() throws Exception {
final String injectAttributeName = "new attribute";
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(new MetacardImpl()), null)).getCreatedMetacards().get(0).getId();
final String title = "Update";
final double injectAttributeValue = -1;
final MetacardImpl metacard = new MetacardImpl();
metacard.setId(id);
metacard.setTitle(title);
metacard.setAttribute(injectAttributeName, injectAttributeValue);
final UpdateRequest request = new UpdateRequestImpl(id, metacard);
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);
final UpdateResponse response = framework.update(request);
final Metacard updatedMetacard = response.getUpdatedMetacards().get(0).getNewMetacard();
final MetacardType originalMetacardType = metacard.getMetacardType();
final MetacardType updatedMetacardType = updatedMetacard.getMetacardType();
assertThat(updatedMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(updatedMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(updatedMetacard.getTitle(), is(title));
assertThat(updatedMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class CatalogFrameworkImplTest method testProviderRuntimeExceptionOnUpdateByIdentifier.
@Test(expected = IngestException.class)
public void testProviderRuntimeExceptionOnUpdateByIdentifier() 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<Entry<Object, Metacard>> metacards = new ArrayList<Entry<Object, Metacard>>();
HashMap<Object, Metacard> map = new HashMap<Object, Metacard>();
try {
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
newCard.setResourceURI(new URI("uri:///1234"));
map.put(Metacard.ID, newCard);
metacards.addAll(map.entrySet());
UpdateRequest update = new UpdateRequestImpl(null, Metacard.RESOURCE_URI, null);
framework.update(update);
} catch (URISyntaxException e) {
fail();
} catch (SourceUnavailableException e) {
fail();
}
}
Aggregations