Search in sources :

Example 41 with CswTransactionRequest

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest in project ddf by codice.

the class TransactionMessageBodyReaderTest method testReadDeleteWithFilterFrom.

@Test
public void testReadDeleteWithFilterFrom() throws IOException {
    TransactionMessageBodyReader reader = new TransactionMessageBodyReader(mock(Converter.class), CswQueryFactoryTest.getCswMetacardType(), registry);
    CswTransactionRequest request = reader.readFrom(CswTransactionRequest.class, null, null, null, null, IOUtils.toInputStream(DELETE_REQUEST_FILTER_XML, StandardCharsets.UTF_8));
    assertThat(request, notNullValue());
    assertThat(request.getDeleteActions().size(), is(1));
    assertThat(request.getInsertActions().size(), is(0));
    assertThat(request.getUpdateActions().size(), is(0));
    DeleteAction deleteAction = request.getDeleteActions().get(0);
    assertThat(deleteAction, notNullValue());
    assertThat(deleteAction.getTypeName(), is(CswConstants.CSW_RECORD));
    assertThat(deleteAction.getHandle(), is("something"));
    assertThat(deleteAction.getConstraint(), notNullValue());
    assertThat(deleteAction.getConstraint().getFilter(), notNullValue());
    assertThat(request.getService(), is(CswConstants.CSW));
    assertThat(request.getVersion(), is(CswConstants.VERSION_2_0_2));
    assertThat(request.isVerbose(), is(false));
}
Also used : CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Converter(com.thoughtworks.xstream.converters.Converter) CswRecordConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 42 with CswTransactionRequest

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest in project ddf by codice.

the class TransactionRequestConverterTest method testValidInsertMarshal.

@Test
public void testValidInsertMarshal() throws SAXException, IOException, XpathException {
    CswTransactionRequest transactionRequest = new CswTransactionRequest();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId(METACARD_ID);
    InsertAction insertAction = new InsertActionImpl(CswConstants.CSW_METACARD_TYPE_NAME, null, Arrays.asList(metacard));
    transactionRequest.getInsertActions().add(insertAction);
    transactionRequest.setService(CswConstants.CSW);
    transactionRequest.setVerbose(true);
    transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
    String xml = xStream.toXML(transactionRequest);
    System.out.println("xml = " + xml);
    System.out.println("EXPECTED_INSERT_XML = " + EXPECTED_INSERT_XML);
    Diff diff = XMLUnit.compareXML(xml, EXPECTED_INSERT_XML);
    assertThat(diff.similar(), is(true));
}
Also used : InsertActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertActionImpl) Diff(org.custommonkey.xmlunit.Diff) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.InsertAction) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 43 with CswTransactionRequest

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest in project ddf by codice.

the class TransactionRequestConverterTest method testUnmarshalInsert.

@Test
public void testUnmarshalInsert() throws Exception {
    String insertRequest = IOUtils.toString(TransactionRequestConverterTest.class.getResourceAsStream("/insertRequest.xml"));
    CswTransactionRequest request = (CswTransactionRequest) xStream.fromXML(insertRequest);
    assertThat(request.getDeleteActions(), emptyCollectionOf(DeleteAction.class));
    assertThat(request.getUpdateActions(), emptyCollectionOf(UpdateAction.class));
    assertThat(request.getInsertActions(), hasSize(1));
    InsertAction action = request.getInsertActions().get(0);
    assertThat(action.getTypeName(), is(CswConstants.CSW_RECORD));
}
Also used : UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.InsertAction) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) Test(org.junit.Test)

Example 44 with CswTransactionRequest

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest in project ddf by codice.

the class TransactionRequestConverterTest method testValidDeleteMarshal.

@Test
public void testValidDeleteMarshal() throws SAXException, IOException, XpathException {
    CswTransactionRequest transactionRequest = new CswTransactionRequest();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId(METACARD_ID);
    DeleteType deleteType = new DeleteType();
    QueryConstraintType queryConstraintType = new QueryConstraintType();
    queryConstraintType.setCqlText("identifier = " + METACARD_ID);
    deleteType.setConstraint(queryConstraintType);
    DeleteAction deleteAction = new DeleteActionImpl(deleteType, null);
    transactionRequest.getDeleteActions().add(deleteAction);
    transactionRequest.setService(CswConstants.CSW);
    transactionRequest.setVerbose(true);
    transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
    String xml = xStream.toXML(transactionRequest);
    Diff diff = XMLUnit.compareXML(xml, EXPECTED_DELETE_XML);
    assertThat(diff.similar(), is(true));
}
Also used : Diff(org.custommonkey.xmlunit.Diff) 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) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Test(org.junit.Test)

Example 45 with CswTransactionRequest

use of org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest in project ddf by codice.

the class TransactionRequestConverterTest method testUnmarshalByProperty.

@Test
public void testUnmarshalByProperty() throws Exception {
    String updateRequest = IOUtils.toString(TransactionRequestConverterTest.class.getResourceAsStream("/updateByPropertyRequest.xml"));
    CswTransactionRequest request = (CswTransactionRequest) xStream.fromXML(updateRequest);
    assertThat(request.getDeleteActions(), emptyCollectionOf(DeleteAction.class));
    assertThat(request.getUpdateActions(), hasSize(1));
    assertThat(request.getInsertActions(), emptyCollectionOf(InsertAction.class));
    UpdateAction action = request.getUpdateActions().get(0);
    assertThat(action.getTypeName(), is(CswConstants.CSW_RECORD));
    assertThat(action.getConstraint(), notNullValue());
    assertThat(action.getRecordProperties().size(), is(5));
    assertThat(action.getRecordProperties().get("title"), is("Updated Title"));
    assertThat(action.getRecordProperties().get("created"), is(CswUnmarshallHelper.convertToDate("2015-08-25")));
    assertThat(action.getRecordProperties().get("datatype"), is(Arrays.asList("ABC", "DEF", "GHI")));
    assertThat(action.getRecordProperties().get("language"), is(""));
    assertThat(action.getRecordProperties().get("language"), is(""));
}
Also used : UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.InsertAction) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction) Test(org.junit.Test)

Aggregations

CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)48 Test (org.junit.Test)41 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 Metacard (ddf.catalog.data.Metacard)17 UpdateAction (org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction)15 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)14 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)14 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)14 DeleteAction (org.codice.ddf.spatial.ogc.csw.catalog.actions.DeleteAction)13 Serializable (java.io.Serializable)11 ArrayList (java.util.ArrayList)11 TransactionSummaryType (net.opengis.cat.csw.v_2_0_2.TransactionSummaryType)11 UpdateAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction)11 CswRecordConverter (org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter)11 Converter (com.thoughtworks.xstream.converters.Converter)10 DeleteAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction)10 InsertAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertAction)10 DeleteType (net.opengis.cat.csw.v_2_0_2.DeleteType)9 InsertAction (org.codice.ddf.spatial.ogc.csw.catalog.actions.InsertAction)9 InsertActionImpl (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertActionImpl)8