use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class TestCswEndpoint method testUpdateTransactionWithNewRecord.
@Test
public void testUpdateTransactionWithNewRecord() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
List<Update> updatedMetacards = new ArrayList<>();
updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
MetacardImpl updatedMetacard = new MetacardImpl();
updatedMetacard.setId("123");
UpdateAction updateAction = new UpdateAction(updatedMetacard, CswConstants.CSW_RECORD, "");
CswTransactionRequest transactionRequest = new CswTransactionRequest();
transactionRequest.getUpdateActions().add(updateAction);
transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
transactionRequest.setService(CswConstants.CSW);
transactionRequest.setVerbose(false);
TransactionResponseType response = csw.transaction(transactionRequest);
assertThat(response, notNullValue());
TransactionSummaryType summary = response.getTransactionSummary();
assertThat(summary, notNullValue());
assertThat(summary.getTotalDeleted().intValue(), is(0));
assertThat(summary.getTotalInserted().intValue(), is(0));
assertThat(summary.getTotalUpdated().intValue(), is(1));
verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
ArgumentCaptor<UpdateRequest> updateRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class);
verify(catalogFramework, times(1)).update(updateRequestArgumentCaptor.capture());
UpdateRequest actualUpdateRequest = updateRequestArgumentCaptor.getValue();
assertThat(actualUpdateRequest.getUpdates().size(), is(1));
assertThat(actualUpdateRequest.getUpdates().get(0).getValue().getId(), is("123"));
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class CachingFederationStrategyTest method testProcessUpdateResponse.
@Test
public void testProcessUpdateResponse() throws Exception {
Map<String, Serializable> testMap = new HashMap<>();
testMap.put(Constants.SERVICE_TITLE, MOCK_RESPONSE_TITLE);
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);
MetacardImpl newMetacard = mock(MetacardImpl.class);
when(newMetacard.getId()).thenReturn("new metacard");
when(newMetacard.getSourceId()).thenReturn("new source ID");
UpdateImpl updateImpl = mock(UpdateImpl.class);
when(updateImpl.getNewMetacard()).thenReturn(newMetacard);
List<Update> cards = Arrays.asList(updateImpl);
ArgumentCaptor<List<Metacard>> metacardsCaptor = ArgumentCaptor.forClass((Class) List.class);
when(response.getUpdatedMetacards()).thenReturn(cards);
doNothing().when(cache).create(metacardsCaptor.capture());
assertThat(response, is(strategy.process(response)));
assertThat(metacardsCaptor.getValue().contains(newMetacard), is(true));
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class DummyPreIngestPlugin method process.
public UpdateRequest process(UpdateRequest input) throws PluginExecutionException {
String methodName = "process(UpdateRequest)";
LOGGER.debug(ENTERING, methodName);
UpdateRequest newRequest = input;
if (newRequest != null) {
List<Entry<Serializable, Metacard>> updates = newRequest.getUpdates();
List<Metacard> updatedMetacards = new ArrayList<Metacard>();
for (Entry<Serializable, Metacard> updateEntry : updates) {
Metacard metacard = updateEntry.getValue();
updatedMetacards.add(metacard);
}
// Loop to get all ids
List<String> ids = new ArrayList<String>();
int i = 0;
for (Entry<Serializable, Metacard> updateEntry : updates) {
if (i % 2 == 0) {
ids.add((String) updateEntry.getKey());
}
i++;
}
updatedMetacards = this.filterOutMetacards(updatedMetacards);
LOGGER.debug("Returning new update request with id list size: {} and metacard list size: {}", ids.size(), updatedMetacards.size());
newRequest = new UpdateRequestImpl(ids.toArray(new String[ids.size()]), updatedMetacards);
}
LOGGER.debug(EXITING, methodName);
return newRequest;
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class SolrProviderTest method testUpdateAlternativeAttribute.
/**
* Testing update operation of alternative attribute. Should return positive results.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testUpdateAlternativeAttribute() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
final MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
create(metacard);
UpdateResponse response = provider.update(new UpdateRequest() {
@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<Entry<Serializable, Metacard>> getUpdates() {
MetacardImpl newMetacard = new MetacardImpl(metacard);
newMetacard.setContentTypeName("newContentName");
List<Entry<Serializable, Metacard>> updateList = new ArrayList<Entry<Serializable, Metacard>>();
updateList.add(new SimpleEntry<Serializable, Metacard>(MockMetacard.DEFAULT_TITLE, newMetacard));
return updateList;
}
@Override
public String getAttributeName() {
return Metacard.TITLE;
}
});
Update update = response.getUpdatedMetacards().get(0);
assertThat(update.getNewMetacard().getId(), is(equalTo(update.getOldMetacard().getId())));
assertEquals(1, response.getUpdatedMetacards().size());
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class SecurityPluginTest method testNominalCaseUpdate.
@Test
public void testNominalCaseUpdate() throws Exception {
Subject mockSubject = mock(Subject.class);
ThreadContext.bind(mockSubject);
UpdateRequest request = new MockUpdateRequest();
SecurityPlugin plugin = new SecurityPlugin();
request = plugin.processPreUpdate(request, new HashMap<>());
assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
}
Aggregations