use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class TestGetRecordsResponseConverter method createCswRecordCollection.
private CswRecordCollection createCswRecordCollection(GetRecordsType request, int resultCount) {
CswRecordCollection collection = new CswRecordCollection();
int first = 1;
int last = 2;
if (request != null) {
first = request.getStartPosition().intValue();
int next = request.getMaxRecords().intValue() + first;
last = next - 1;
if (last >= resultCount) {
last = resultCount;
}
}
int returned = last - first + 1;
collection.setCswRecords(createMetacardList(first, last));
collection.setNumberOfRecordsMatched(resultCount);
collection.setNumberOfRecordsReturned(returned);
return collection;
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class TestGetRecordsResponseConverter method testMarshalRecordCollectionGetBrief.
@Ignore
public void testMarshalRecordCollectionGetBrief() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
ElementSetNameType set = new ElementSetNameType();
set.setValue(ElementSetType.BRIEF);
query.setElementSetName(set);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementSetType(ElementSetType.BRIEF);
ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
MarshallingContext context = captor.getValue();
assertThat(context, not(nullValue()));
assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.BRIEF));
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(ElementSetType.BRIEF));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class TestGetRecordsResponseConverter method testMarshalRecordCollectionGetFull.
@Ignore
public void testMarshalRecordCollectionGetFull() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
ElementSetNameType set = new ElementSetNameType();
set.setValue(ElementSetType.FULL);
query.setElementSetName(set);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementSetType(ElementSetType.FULL);
ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
MarshallingContext context = captor.getValue();
assertThat(context, not(nullValue()));
assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.FULL));
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class CswRecordCollectionMessageBodyWriterTest method createCswRecordCollection.
private CswRecordCollection createCswRecordCollection(int resultCount) {
CswRecordCollection collection = new CswRecordCollection();
collection.setCswRecords(createMetacardList(resultCount));
return collection;
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class CswRecordCollectionMessageBodyWriterTest method testWriteValidate.
@Test
public void testWriteValidate() throws WebApplicationException, IOException, JAXBException, CatalogTransformerException {
CswRecordCollectionMessageBodyWriter writer = new CswRecordCollectionMessageBodyWriter(mockManager);
when(mockManager.getTransformerBySchema(anyString())).thenReturn(mockTransformer);
ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
when(mockTransformer.transform(any(SourceResponse.class), any(Map.class))).thenReturn(mockContent);
when(mockContent.getInputStream()).thenReturn(new ByteArrayInputStream("bytes".getBytes()));
CswRecordCollection collection = createCswRecordCollection(6);
collection.setNumberOfRecordsMatched(22);
collection.setNumberOfRecordsReturned(6);
collection.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
collection.setById(true);
QName example = new QName("example");
collection.setElementName(Arrays.asList(example));
collection.setElementSetType(ElementSetType.BRIEF);
collection.setResultType(ResultType.VALIDATE);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
writer.writeTo(collection, null, null, null, null, null, stream);
verify(mockManager, times(1)).getTransformerBySchema(anyString());
verify(mockTransformer).transform(any(SourceResponse.class), captor.capture());
Map arguments = captor.getValue();
assertThat(arguments.get(CswConstants.WRITE_NAMESPACES), is(false));
assertThat(arguments.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
assertThat(arguments.get(CswConstants.RESULT_TYPE_PARAMETER), is(ResultType.VALIDATE));
assertThat(arguments.get(CswConstants.IS_BY_ID_QUERY), is(true));
assertThat(arguments.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.BRIEF));
assertThat(((QName[]) arguments.get(CswConstants.ELEMENT_NAMES))[0], is(example));
}
Aggregations