Search in sources :

Example 1 with CswTransactionRequest

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

the class TestTransactionRequestConverter method testUnmarshalDelete.

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

Example 2 with CswTransactionRequest

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

the class TestTransactionRequestConverter method testUnmarshalInsert.

@Test
public void testUnmarshalInsert() throws Exception {
    String insertRequest = IOUtils.toString(TestTransactionRequestConverter.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.common.transaction.UpdateAction) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertAction) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction) Test(org.junit.Test)

Example 3 with CswTransactionRequest

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

the class TestTransactionRequestConverter method testMultipleOperations.

@Test
public void testMultipleOperations() throws Exception {
    CswTransactionRequest transactionRequest = new CswTransactionRequest();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId(METACARD_ID);
    transactionRequest.setService(CswConstants.CSW);
    transactionRequest.setVerbose(true);
    transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
    InsertAction insertAction = new InsertAction(CswConstants.CSW_METACARD_TYPE_NAME, null, Arrays.asList(metacard));
    transactionRequest.getInsertActions().add(insertAction);
    UpdateAction updateAction = new UpdateAction(metacard, CswConstants.CSW_METACARD_TYPE_NAME, null);
    transactionRequest.getUpdateActions().add(updateAction);
    DeleteType deleteType = new DeleteType();
    QueryConstraintType queryConstraintType = new QueryConstraintType();
    queryConstraintType.setCqlText("identifier = " + METACARD_ID);
    deleteType.setConstraint(queryConstraintType);
    DeleteAction deleteAction = new DeleteAction(deleteType, null);
    transactionRequest.getDeleteActions().add(deleteAction);
    String xml = xStream.toXML(transactionRequest);
    Diff diff = XMLUnit.compareXML(xml, EXPECTED_MULTI_OP_XML);
    assertThat(diff.similar(), is(true));
}
Also used : UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) Diff(org.custommonkey.xmlunit.Diff) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertAction) DeleteAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction) DeleteType(net.opengis.cat.csw.v_2_0_2.DeleteType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Test(org.junit.Test)

Example 4 with CswTransactionRequest

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

the class TestTransactionMessageBodyReader method testReadMultipleUpdatesFrom.

@Test
public void testReadMultipleUpdatesFrom() throws IOException, ParseException {
    TransactionMessageBodyReader reader = new TransactionMessageBodyReader(cswRecordConverter, CswQueryFactoryTest.getCswMetacardType(), registry);
    CswTransactionRequest request = reader.readFrom(CswTransactionRequest.class, null, null, null, null, IOUtils.toInputStream(MULTIPLE_UPDATES_REQUEST_XML));
    assertThat(request, notNullValue());
    assertThat(request.getInsertActions().size(), is(0));
    assertThat(request.getDeleteActions().size(), is(0));
    assertThat(request.getUpdateActions().size(), is(2));
    UpdateAction firstUpdateAction = request.getUpdateActions().get(0);
    assertThat(firstUpdateAction, notNullValue());
    assertThat(firstUpdateAction.getMetacard(), notNullValue());
    Metacard metacard = firstUpdateAction.getMetacard();
    assertThat(metacard.getId(), is("123"));
    assertThat(metacard.getTitle(), is("Aliquam fermentum purus quis arcu"));
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = simpleDateFormat.parse("2008-08-10");
    assertThat(metacard.getModifiedDate(), is(date));
    assertThat(metacard.getLocation(), is("POLYGON ((1.0 2.0, 3.0 2.0, 3.0 4.0, 1.0 4.0, 1.0 2.0))"));
    assertThat(firstUpdateAction.getHandle(), is("handle1"));
    assertThat(firstUpdateAction.getTypeName(), is(CswConstants.CSW_RECORD));
    UpdateAction secondUpdateAction = request.getUpdateActions().get(1);
    assertThat(secondUpdateAction, notNullValue());
    assertThat(secondUpdateAction.getMetacard(), nullValue());
    Map<String, Serializable> recordProperties = secondUpdateAction.getRecordProperties();
    assertThat(recordProperties, notNullValue());
    assertThat(recordProperties.size(), is(1));
    Serializable newSubject = recordProperties.get("topic.category");
    assertThat(newSubject, is("foo"));
    QueryConstraintType constraint = secondUpdateAction.getConstraint();
    assertThat(constraint, notNullValue());
    assertThat(constraint.getCqlText().trim(), is("title = 'bar'"));
    assertThat(secondUpdateAction.getHandle(), is("handle2"));
    assertThat(secondUpdateAction.getTypeName(), is(CswConstants.CSW_RECORD));
    assertThat(request.getService(), is(CswConstants.CSW));
    assertThat(request.getVersion(), is(CswConstants.VERSION_2_0_2));
    assertThat(request.isVerbose(), is(false));
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 5 with CswTransactionRequest

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

the class TestTransactionMessageBodyReader method testReadInsertFrom.

@Test
public void testReadInsertFrom() throws Exception {
    Converter mockConverter = mock(Converter.class);
    when(mockConverter.canConvert(any(Metacard.class.getClass()))).thenReturn(true);
    when(mockConverter.unmarshal(any(HierarchicalStreamReader.class), any(UnmarshallingContext.class))).thenReturn(mock(Metacard.class));
    TransactionMessageBodyReader reader = new TransactionMessageBodyReader(mockConverter, CswQueryFactoryTest.getCswMetacardType(), registry);
    CswTransactionRequest request = reader.readFrom(CswTransactionRequest.class, null, null, null, null, IOUtils.toInputStream(getInsertRequest(COUNT)));
    assertThat(request, notNullValue());
    assertThat(request.getInsertActions().size(), is(1));
    assertThat(request.getDeleteActions().size(), is(0));
    assertThat(request.getUpdateActions().size(), is(0));
    InsertAction insertAction = request.getInsertActions().get(0);
    assertThat(insertAction, notNullValue());
    assertThat(insertAction.getRecords().size(), is(COUNT));
    assertThat(request.getService(), is(CswConstants.CSW));
    assertThat(request.getVersion(), is(CswConstants.VERSION_2_0_2));
    assertThat(request.isVerbose(), is(true));
}
Also used : Metacard(ddf.catalog.data.Metacard) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) InsertAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.InsertAction) Converter(com.thoughtworks.xstream.converters.Converter) CswRecordConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) UnmarshallingContext(com.thoughtworks.xstream.converters.UnmarshallingContext) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) 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