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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations