use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class SecurityAuditPluginTest method testAddedAttributeInAuditConfigIsAudited.
@Test
public void testAddedAttributeInAuditConfigIsAudited() throws StopProcessingException {
MetacardImpl existingMetacard = new MetacardImpl();
MetacardImpl updateMetacard = new MetacardImpl();
updateMetacard.setAttribute(Metacard.TITLE, "A test string");
existingMetacard.setAttribute(Metacard.ID, "test");
updateMetacard.setAttribute(Metacard.ID, "test");
List<Map.Entry<Serializable, Metacard>> updateMetacards = new ArrayList<>();
updateMetacards.add(new AbstractMap.SimpleEntry<Serializable, Metacard>(metacardKey, updateMetacard));
Map<String, Metacard> existingMetacards = new HashMap<>();
existingMetacards.put(metacardKey, existingMetacard);
UpdateRequestImpl updateRequest = new UpdateRequestImpl(updateMetacards, Metacard.TITLE, null);
securityAuditPlugin.processPreUpdate(updateRequest, existingMetacards);
verify(securityAuditPlugin, times(1)).auditMetacardUpdate(Metacard.TITLE, "test", "[NO VALUE]", "A test string");
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class SecurityAuditPluginTest method testUnchangedAttributeInAuditConfigIsNotAudited.
@Test
public void testUnchangedAttributeInAuditConfigIsNotAudited() throws StopProcessingException {
MetacardImpl existingMetacard = new MetacardImpl();
MetacardImpl updateMetacard = new MetacardImpl();
existingMetacard.setAttribute(Metacard.TITLE, "B");
updateMetacard.setAttribute(Metacard.TITLE, "B");
existingMetacard.setAttribute(Metacard.ID, "test");
updateMetacard.setAttribute(Metacard.ID, "test");
List<Map.Entry<Serializable, Metacard>> updateMetacards = new ArrayList<>();
updateMetacards.add(new AbstractMap.SimpleEntry<Serializable, Metacard>(metacardKey, updateMetacard));
Map<String, Metacard> existingMetacards = new HashMap<>();
existingMetacards.put(metacardKey, existingMetacard);
UpdateRequestImpl updateRequest = new UpdateRequestImpl(updateMetacards, Metacard.TITLE, null);
securityAuditPlugin.processPreUpdate(updateRequest, existingMetacards);
verify(securityAuditPlugin, never()).auditMetacardUpdate(Metacard.TITLE, "test", "B", "B");
}
use of ddf.catalog.operation.impl.UpdateRequestImpl 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(), any())).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.impl.UpdateRequestImpl 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();
}
}
use of ddf.catalog.operation.impl.UpdateRequestImpl 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