use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class SolrProviderTest method testUpdateOperationSimple.
/**
* Testing that if records are properly updated.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testUpdateOperationSimple() throws IngestException, UnsupportedQueryException {
// Single Update
deleteAllIn(provider);
MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
CreateResponse createResponse = create(metacard);
String id = createResponse.getCreatedMetacards().get(0).getId();
metacard.setContentTypeName("newContentType");
UpdateResponse response = update(id, metacard);
Update update = response.getUpdatedMetacards().get(0);
Metacard newMetacard = update.getNewMetacard();
Metacard oldMetacard = update.getOldMetacard();
assertEquals(1, response.getUpdatedMetacards().size());
assertEquals("newContentType", newMetacard.getContentTypeName());
assertEquals(MockMetacard.DEFAULT_TYPE, oldMetacard.getContentTypeName());
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class SolrProviderTest method testUpdateEmptyList.
/**
* Tests empty list in UpdateRequest
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testUpdateEmptyList() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
UpdateResponse response = provider.update(new UpdateRequestImpl(new ArrayList<Entry<Serializable, Metacard>>(), Metacard.ID, null));
assertEquals(0, response.getUpdatedMetacards().size());
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class TestCswEndpoint method testUpdateTransactionWithConstraint.
@Test
public void testUpdateTransactionWithConstraint() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
List<Result> results = new ArrayList<>();
MetacardImpl firstResult = new MetacardImpl();
firstResult.setId("123");
firstResult.setTitle("Title one");
firstResult.setAttribute("subject", "Subject one");
results.add(new ResultImpl(firstResult));
MetacardImpl secondResult = new MetacardImpl();
secondResult.setId("789");
secondResult.setTitle("Title two");
secondResult.setAttribute("subject", "Subject two");
results.add(new ResultImpl(secondResult));
QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
List<Update> updatedMetacards = new ArrayList<>();
updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
Map<String, Serializable> recordProperties = new HashMap<>();
recordProperties.put("title", "foo");
recordProperties.put("subject", "bar");
QueryConstraintType constraint = new QueryConstraintType();
constraint.setCqlText("title = 'fake'");
UpdateAction updateAction = new UpdateAction(recordProperties, CswConstants.CSW_RECORD, "", constraint, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
CswTransactionRequest updateRequest = new CswTransactionRequest();
updateRequest.getUpdateActions().add(updateAction);
updateRequest.setVersion(CswConstants.VERSION_2_0_2);
updateRequest.setService(CswConstants.CSW);
updateRequest.setVerbose(false);
TransactionResponseType response = csw.transaction(updateRequest);
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(2));
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();
List<Map.Entry<Serializable, Metacard>> updates = actualUpdateRequest.getUpdates();
assertThat(updates.size(), is(2));
Metacard firstUpdate = updates.get(0).getValue();
assertThat(firstUpdate.getId(), is("123"));
assertThat(firstUpdate.getTitle(), is("foo"));
assertThat(firstUpdate.getAttribute("subject").getValue(), is("bar"));
Metacard secondUpdate = updates.get(1).getValue();
assertThat(secondUpdate.getId(), is("789"));
assertThat(secondUpdate.getTitle(), is("foo"));
assertThat(secondUpdate.getAttribute("subject").getValue(), is("bar"));
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class CatalogMetricsTest method catalogUpdateMetric.
@Test
public void catalogUpdateMetric() throws Exception {
UpdateRequest request = mock(UpdateRequest.class);
UpdateResponse response = mock(UpdateResponse.class);
List<Update> updatedList = mock(List.class);
when(updatedList.size()).thenReturn(100);
when(response.getRequest()).thenReturn(request);
when(response.getUpdatedMetacards()).thenReturn(updatedList);
underTest.process(response);
assertThat(underTest.updatedMetacards.getCount(), is(100L));
}
use of ddf.catalog.operation.UpdateResponse 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)));
}
Aggregations