use of org.geotoolkit.csw.xml.v202.TransactionSummaryType in project geotoolkit by Geomatys.
the class CswXMLBindingTest method transactionResponseMarshalingTest.
@Test
public void transactionResponseMarshalingTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
Marshaller marshaller = pool.acquireMarshaller();
SimpleLiteral id = new SimpleLiteral("{8C71082D-5B3B-5F9D-FC40-F7807C8AB645}");
SimpleLiteral title = new SimpleLiteral("(JASON-1)");
SimpleLiteral type = new SimpleLiteral("clearinghouse");
List<BoundingBoxType> bbox = new ArrayList<>();
bbox.add(new WGS84BoundingBoxType(180, -66.0000000558794, -180, 65.9999999720603));
Object record = new BriefRecordType(id, title, type, bbox);
final List<InsertResultType> inserteds = new ArrayList<>();
inserteds.add(new InsertResultType(Arrays.asList(record), null));
TransactionSummaryType summ = new TransactionSummaryType(2, 0, 1, "rid");
TransactionResponseType request = new TransactionResponseType(summ, inserteds, "2.0.2");
String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<csw:TransactionResponse version=\"2.0.2\" xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:ows=\"http://www.opengis.net/ows\">\n" + " <csw:TransactionSummary requestId=\"rid\">\n" + " <csw:totalInserted>2</csw:totalInserted>\n" + " <csw:totalUpdated>0</csw:totalUpdated>\n" + " <csw:totalDeleted>1</csw:totalDeleted>\n" + " </csw:TransactionSummary>\n" + " <csw:InsertResult>\n" + " <csw:BriefRecord>\n" + " <dc:identifier>{8C71082D-5B3B-5F9D-FC40-F7807C8AB645}</dc:identifier>\n" + " <dc:title>(JASON-1)</dc:title>\n" + " <dc:type>clearinghouse</dc:type>\n" + " <ows:WGS84BoundingBox dimensions=\"2\">\n" + " <ows:LowerCorner>180.0 -66.0000000558794</ows:LowerCorner>\n" + " <ows:UpperCorner>-180.0 65.9999999720603</ows:UpperCorner>\n" + " </ows:WGS84BoundingBox>\n" + " </csw:BriefRecord>\n" + " </csw:InsertResult>\n" + "</csw:TransactionResponse>\n";
StringWriter sw = new StringWriter();
marshaller.marshal(request, sw);
String result = sw.toString();
assertXmlEquals(expResult, result, "xmlns:*");
pool.recycle(marshaller);
}
use of org.geotoolkit.csw.xml.v202.TransactionSummaryType in project geotoolkit by Geomatys.
the class CswXMLBindingTest method transactionResponseUnmarshalingTest.
/**
* Test simple Record Marshalling.
*/
@Test
public void transactionResponseUnmarshalingTest() throws JAXBException {
Unmarshaller unmarshaller = pool.acquireUnmarshaller();
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<csw:TransactionResponse version=\"2.0.2\" xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:ows=\"http://www.opengis.net/ows\">\n" + " <csw:TransactionSummary requestId=\"rid\">\n" + " <csw:totalInserted>2</csw:totalInserted>\n" + " <csw:totalUpdated>0</csw:totalUpdated>\n" + " <csw:totalDeleted>1</csw:totalDeleted>\n" + " </csw:TransactionSummary>\n" + " <csw:InsertResult>\n" + " <csw:BriefRecord>\n" + " <dc:identifier>{8C71082D-5B3B-5F9D-FC40-F7807C8AB645}</dc:identifier>\n" + " <dc:title>(JASON-1)</dc:title>\n" + " <dc:type>clearinghouse</dc:type>\n" + " <ows:WGS84BoundingBox dimensions=\"2\">\n" + " <ows:LowerCorner>180.0 -66.0000000558794</ows:LowerCorner>\n" + " <ows:UpperCorner>-180.0 65.9999999720603</ows:UpperCorner>\n" + " </ows:WGS84BoundingBox>\n" + " </csw:BriefRecord>\n" + " </csw:InsertResult>\n" + "</csw:TransactionResponse>\n";
TransactionResponseType result = ((JAXBElement<TransactionResponseType>) unmarshaller.unmarshal(new StringReader(xml))).getValue();
SimpleLiteral id = new SimpleLiteral("{8C71082D-5B3B-5F9D-FC40-F7807C8AB645}");
SimpleLiteral title = new SimpleLiteral("(JASON-1)");
SimpleLiteral type = new SimpleLiteral("clearinghouse");
List<BoundingBoxType> bbox = new ArrayList<>();
bbox.add(new WGS84BoundingBoxType(180, -66.0000000558794, -180, 65.9999999720603));
Object record = new BriefRecordType(id, title, type, bbox);
final List<InsertResultType> inserteds = new ArrayList<>();
inserteds.add(new InsertResultType(Arrays.asList(record), null));
TransactionSummaryType summ = new TransactionSummaryType(2, 0, 1, "rid");
TransactionResponseType expResult = new TransactionResponseType(summ, inserteds, "2.0.2");
assertEquals(expResult.getTransactionSummary(), result.getTransactionSummary());
assertEquals(expResult.getInsertResult(), result.getInsertResult());
assertEquals(expResult, result);
pool.recycle(unmarshaller);
}
use of org.geotoolkit.csw.xml.v202.TransactionSummaryType in project ddf by codice.
the class CswEndpointTest method testDeleteTransaction.
@Test
public void testDeleteTransaction() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
DeleteType deleteType = mock(DeleteType.class);
doReturn(CswConstants.CSW_RECORD).when(deleteType).getTypeName();
doReturn("").when(deleteType).getHandle();
QueryConstraintType queryConstraintType = new QueryConstraintType();
queryConstraintType.setCqlText("title = \"foo\"");
doReturn(queryConstraintType).when(deleteType).getConstraint();
when(catalogFramework.delete(any(DeleteRequest.class))).thenAnswer((Answer<DeleteResponse>) invocation -> {
DeleteRequest request = (DeleteRequest) invocation.getArguments()[0];
long numResults = request.getAttributeValues().size();
when(deleteResponse.getDeletedMetacards()).thenReturn(populateMetacardList((int) numResults));
return deleteResponse;
});
DeleteAction deleteAction = new DeleteActionImpl(deleteType, DefaultCswRecordMap.getPrefixToUriMapping());
CswTransactionRequest deleteRequest = new CswTransactionRequest();
deleteRequest.getDeleteActions().add(deleteAction);
deleteRequest.setVersion(CswConstants.VERSION_2_0_2);
deleteRequest.setService(CswConstants.CSW);
deleteRequest.setVerbose(false);
TransactionResponseType response = csw.transaction(deleteRequest);
assertThat(response, notNullValue());
TransactionSummaryType summary = response.getTransactionSummary();
assertThat(summary, notNullValue());
assertThat(summary.getTotalDeleted().intValue(), is(BATCH_TOTAL));
assertThat(summary.getTotalInserted().intValue(), is(0));
assertThat(summary.getTotalUpdated().intValue(), is(0));
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);
}
use of org.geotoolkit.csw.xml.v202.TransactionSummaryType in project ddf by codice.
the class CswEndpointTest method testIngestVerboseTransaction.
@Test
public void testIngestVerboseTransaction() throws CswException, SourceUnavailableException, FederationException, IngestException {
CswTransactionRequest request = new CswTransactionRequest();
request.getInsertActions().add(new InsertActionImpl(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 CswEndpointTest 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());
QueryResponse emptyResponse = new QueryResponseImpl(null, Collections.emptyList(), 0);
when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponse).thenReturn(emptyResponse);
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 UpdateActionImpl(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"));
}
Aggregations