Search in sources :

Example 6 with TransactionSummaryType

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);
}
Also used : Marshaller(javax.xml.bind.Marshaller) WGS84BoundingBoxType(org.geotoolkit.ows.xml.v100.WGS84BoundingBoxType) ArrayList(java.util.ArrayList) TransactionSummaryType(org.geotoolkit.csw.xml.v202.TransactionSummaryType) BriefRecordType(org.geotoolkit.csw.xml.v202.BriefRecordType) TransactionResponseType(org.geotoolkit.csw.xml.v202.TransactionResponseType) BoundingBoxType(org.geotoolkit.ows.xml.v100.BoundingBoxType) WGS84BoundingBoxType(org.geotoolkit.ows.xml.v100.WGS84BoundingBoxType) StringWriter(java.io.StringWriter) SimpleLiteral(org.geotoolkit.dublincore.xml.v2.elements.SimpleLiteral) InsertResultType(org.geotoolkit.csw.xml.v202.InsertResultType) Test(org.junit.Test)

Example 7 with TransactionSummaryType

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);
}
Also used : WGS84BoundingBoxType(org.geotoolkit.ows.xml.v100.WGS84BoundingBoxType) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) TransactionSummaryType(org.geotoolkit.csw.xml.v202.TransactionSummaryType) BriefRecordType(org.geotoolkit.csw.xml.v202.BriefRecordType) TransactionResponseType(org.geotoolkit.csw.xml.v202.TransactionResponseType) BoundingBoxType(org.geotoolkit.ows.xml.v100.BoundingBoxType) WGS84BoundingBoxType(org.geotoolkit.ows.xml.v100.WGS84BoundingBoxType) StringReader(java.io.StringReader) SimpleLiteral(org.geotoolkit.dublincore.xml.v2.elements.SimpleLiteral) Unmarshaller(javax.xml.bind.Unmarshaller) InsertResultType(org.geotoolkit.csw.xml.v202.InsertResultType) Test(org.junit.Test)

Example 8 with TransactionSummaryType

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);
}
Also used : UpdateActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateActionImpl) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) CreateRequest(ddf.catalog.operation.CreateRequest) Matchers.hasItems(org.hamcrest.Matchers.hasItems) MediaType(javax.ws.rs.core.MediaType) ServiceIdentification(net.opengis.ows.v_1_0_0.ServiceIdentification) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) ComparisonOperatorType(net.opengis.filter.v_1_1_0.ComparisonOperatorType) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) Mockito.doReturn(org.mockito.Mockito.doReturn) ServiceReference(org.osgi.framework.ServiceReference) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Serializable(java.io.Serializable) Stream(java.util.stream.Stream) Matchers.contains(org.hamcrest.Matchers.contains) ParseException(org.locationtech.jts.io.ParseException) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) Matchers.is(org.hamcrest.Matchers.is) CswConstants(org.codice.ddf.spatial.ogc.csw.catalog.common.CswConstants) UpdateResponse(ddf.catalog.operation.UpdateResponse) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) CswRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRequest) Mockito.mock(org.mockito.Mockito.mock) ResourceResponse(ddf.catalog.operation.ResourceResponse) SpatialOperatorType(net.opengis.filter.v_1_1_0.SpatialOperatorType) Iterables(com.google.common.collect.Iterables) DescribeRecordRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.DescribeRecordRequest) DefaultCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.common.converter.DefaultCswRecordMap) CatalogFramework(ddf.catalog.CatalogFramework) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) Resource(ddf.catalog.resource.Resource) ArrayList(java.util.ArrayList) UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Answer(org.mockito.stubbing.Answer) Subject(org.apache.shiro.subject.Subject) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) QueryRequest(ddf.catalog.operation.QueryRequest) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CswActionTransformerProvider(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswActionTransformerProvider) Result(ddf.catalog.data.Result) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) CapabilitiesType(net.opengis.cat.csw.v_2_0_2.CapabilitiesType) IngestException(ddf.catalog.source.IngestException) StringWriter(java.io.StringWriter) JAXBElement(javax.xml.bind.JAXBElement) ServiceProvider(net.opengis.ows.v_1_0_0.ServiceProvider) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) FederationException(ddf.catalog.federation.FederationException) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Query(ddf.catalog.operation.Query) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Matchers.hasItem(org.hamcrest.Matchers.hasItem) GetRecordsRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordsRequest) ArrayDeque(java.util.ArrayDeque) Mockito.reset(org.mockito.Mockito.reset) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QueryFilterTransformer(ddf.catalog.transform.QueryFilterTransformer) URL(java.net.URL) DescribeRecordResponseType(net.opengis.cat.csw.v_2_0_2.DescribeRecordResponseType) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) SectionsType(net.opengis.ows.v_1_0_0.SectionsType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetCapabilitiesRequest) InsertActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertActionImpl) Assert.fail(org.junit.Assert.fail) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) URI(java.net.URI) DeleteActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteActionImpl) Bundle(org.osgi.framework.Bundle) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Collection(java.util.Collection) GetRecordByIdType(net.opengis.cat.csw.v_2_0_2.GetRecordByIdType) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) ResultImpl(ddf.catalog.data.impl.ResultImpl) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) BundleContext(org.osgi.framework.BundleContext) DeleteRequest(ddf.catalog.operation.DeleteRequest) Objects(java.util.Objects) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) Operation(net.opengis.ows.v_1_0_0.Operation) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Queue(java.util.Queue) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) DescribeRecordType(net.opengis.cat.csw.v_2_0_2.DescribeRecordType) ResultType(net.opengis.cat.csw.v_2_0_2.ResultType) Update(ddf.catalog.operation.Update) SchemaComponentType(net.opengis.cat.csw.v_2_0_2.SchemaComponentType) HashSet(java.util.HashSet) GetCapabilitiesType(net.opengis.cat.csw.v_2_0_2.GetCapabilitiesType) SortBy(org.opengis.filter.sort.SortBy) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) OperationsMetadata(net.opengis.ows.v_1_0_0.OperationsMetadata) Metacard(ddf.catalog.data.Metacard) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) MimeType(javax.activation.MimeType) UpdateRequest(ddf.catalog.operation.UpdateRequest) GmdConstants(org.codice.ddf.spatial.ogc.csw.catalog.common.GmdConstants) LinkedList(java.util.LinkedList) DomainType(net.opengis.ows.v_1_0_0.DomainType) JAXBContext(javax.xml.bind.JAXBContext) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) SimpleSession(org.apache.shiro.session.mgt.SimpleSession) Matchers.empty(org.hamcrest.Matchers.empty) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) Logger(org.slf4j.Logger) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) FilterCapabilities(net.opengis.filter.v_1_1_0.FilterCapabilities) Collectors.toList(java.util.stream.Collectors.toList) SourceResponse(ddf.catalog.operation.SourceResponse) ThreadContext(org.apache.shiro.util.ThreadContext) AcceptVersionsType(net.opengis.ows.v_1_0_0.AcceptVersionsType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Collections(java.util.Collections) DeleteResponse(ddf.catalog.operation.DeleteResponse) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) DeleteActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteActionImpl) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) DeleteRequest(ddf.catalog.operation.DeleteRequest) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) Test(org.junit.Test)

Example 9 with TransactionSummaryType

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));
}
Also used : InsertActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertActionImpl) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QName(javax.xml.namespace.QName) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) Test(org.junit.Test)

Example 10 with TransactionSummaryType

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"));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Update(ddf.catalog.operation.Update) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Result(ddf.catalog.data.Result) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) UpdateActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateActionImpl) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)13 TransactionSummaryType (net.opengis.cat.csw.v_2_0_2.TransactionSummaryType)13 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)11 CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)11 ArrayList (java.util.ArrayList)8 Metacard (ddf.catalog.data.Metacard)5 ResultImpl (ddf.catalog.data.impl.ResultImpl)5 Update (ddf.catalog.operation.Update)5 UpdateRequest (ddf.catalog.operation.UpdateRequest)5 UpdateResponse (ddf.catalog.operation.UpdateResponse)5 UpdateImpl (ddf.catalog.operation.impl.UpdateImpl)5 UpdateResponseImpl (ddf.catalog.operation.impl.UpdateResponseImpl)5 Result (ddf.catalog.data.Result)4 QueryResponse (ddf.catalog.operation.QueryResponse)4 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)4 QName (javax.xml.namespace.QName)4 UpdateAction (org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction)4 QueryRequest (ddf.catalog.operation.QueryRequest)3 Serializable (java.io.Serializable)3