use of org.geotoolkit.csw.xml.v202.TransactionSummaryType 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 org.geotoolkit.csw.xml.v202.TransactionSummaryType in project ddf by codice.
the class TestCswEndpoint method testIngestVerboseTransaction.
@Test
public void testIngestVerboseTransaction() throws CswException, SourceUnavailableException, FederationException, IngestException {
CswTransactionRequest request = new CswTransactionRequest();
request.getInsertActions().add(new InsertAction(CswConstants.CSW_TYPE, null, Arrays.asList(new MetacardImpl())));
request.setVerbose(true);
TransactionResponseType response = csw.transaction(request);
assertThat(response, notNullValue());
assertThat(response.getInsertResult().size(), is(1));
assertThat(response.getTransactionSummary(), notNullValue());
TransactionSummaryType summary = response.getTransactionSummary();
assertThat(summary.getTotalDeleted().intValue(), is(0));
assertThat(summary.getTotalUpdated().intValue(), is(0));
assertThat(summary.getTotalInserted().intValue(), is(1));
String contextPath = StringUtils.join(new String[] { CswConstants.OGC_CSW_PACKAGE, CswConstants.OGC_FILTER_PACKAGE, CswConstants.OGC_GML_PACKAGE, CswConstants.OGC_OWS_PACKAGE }, ":");
verifyMarshalResponse(response, contextPath, new QName(CswConstants.CSW_OUTPUT_SCHEMA, CswConstants.TRANSACTION));
}
use of org.geotoolkit.csw.xml.v202.TransactionSummaryType in project ddf by codice.
the class TestRegistryStore method testDelete.
@Test
public void testDelete() throws Exception {
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
Csw csw = mock(Csw.class);
TransactionResponseType transResponse = mock(TransactionResponseType.class);
TransactionSummaryType transSummary = mock(TransactionSummaryType.class);
when(transResponse.getTransactionSummary()).thenReturn(transSummary);
when(transSummary.getTotalDeleted()).thenReturn(new BigInteger("1"));
when(csw.transaction(any(CswTransactionRequest.class))).thenReturn(transResponse);
when(factory.getClientForSubject(any())).thenReturn(csw);
when(transformer.getTransformerIdForSchema(any())).thenReturn(null);
FilterAdapter mockAdaptor = mock(FilterAdapter.class);
CswFilterFactory filterFactory = new CswFilterFactory(CswAxisOrder.LAT_LON, false);
FilterType filterType = filterFactory.buildPropertyIsLikeFilter(Metacard.ID, "testId", false);
when(mockAdaptor.adapt(any(Filter.class), any(FilterDelegate.class))).thenReturn(filterType);
registryStore.setFilterAdapter(mockAdaptor);
DeleteRequestImpl request = new DeleteRequestImpl(Collections.singletonList(RegistryObjectMetacardType.REGISTRY_ID), "registryId", new HashMap<>());
OperationTransactionImpl opTrans = new OperationTransactionImpl(OperationTransaction.OperationType.DELETE, Collections.singletonList(getDefaultMetacard()));
request.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, opTrans);
registryStore.delete(request);
verify(filterBuilder).attribute(captor.capture());
assertThat(captor.getValue(), is("id"));
}
use of org.geotoolkit.csw.xml.v202.TransactionSummaryType in project ddf by codice.
the class TestRegistryStore method testUpdate.
@Test
public void testUpdate() throws Exception {
Csw csw = mock(Csw.class);
TransactionResponseType responseType = mock(TransactionResponseType.class);
TransactionSummaryType tst = new TransactionSummaryType();
tst.setTotalUpdated(new BigInteger("1"));
when(responseType.getTransactionSummary()).thenReturn(tst);
when(factory.getClientForSubject(any())).thenReturn(csw);
when(csw.transaction(any())).thenReturn(responseType);
when(transformer.getTransformerIdForSchema(any())).thenReturn(null);
UpdateRequestImpl request = new UpdateRequestImpl("testId", getDefaultMetacard());
MetacardImpl updatedMcard = getDefaultMetacard();
updatedMcard.setId("newTestId");
OperationTransactionImpl opTrans = new OperationTransactionImpl(OperationTransaction.OperationType.UPDATE, Collections.singletonList(updatedMcard));
request.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, opTrans);
queryResults.add(new ResultImpl(getDefaultMetacard()));
registryStore.update(request);
assertThat(request.getUpdates().get(0).getValue().getMetadata().contains("value=\"newTestId\""), is(true));
}
use of org.geotoolkit.csw.xml.v202.TransactionSummaryType in project ddf by codice.
the class TestCswEndpoint method testIngestTransaction.
@Test
public void testIngestTransaction() throws CswException, SourceUnavailableException, FederationException, IngestException {
CswTransactionRequest request = new CswTransactionRequest();
request.getInsertActions().add(new InsertAction(CswConstants.CSW_TYPE, null, Arrays.asList(new MetacardImpl())));
TransactionResponseType response = csw.transaction(request);
assertThat(response, notNullValue());
assertThat(response.getInsertResult().isEmpty(), is(true));
assertThat(response.getTransactionSummary(), notNullValue());
TransactionSummaryType summary = response.getTransactionSummary();
assertThat(summary.getTotalDeleted().intValue(), is(0));
assertThat(summary.getTotalUpdated().intValue(), is(0));
assertThat(summary.getTotalInserted().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);
}
Aggregations