use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class TestGetRecordsMessageBodyReader method testGetMultipleMetacardsWithForeignText.
// verifies UTF-8 encoding configured properly when XML includes foreign text with special characters
@Test
public void testGetMultipleMetacardsWithForeignText() throws Exception {
List<Metacard> inputMetacards = new ArrayList<>();
MetacardImpl metacard = new MetacardImpl(BasicTypes.BASIC_METACARD);
inputMetacards.add(metacard);
CswRecordCollection collection = new CswRecordCollection();
collection.setCswRecords(inputMetacards);
when(mockProvider.unmarshal(any(), any())).thenReturn(collection);
CswSourceConfiguration config = new CswSourceConfiguration(encryptionService);
config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
InputStream is = TestGetRecordsMessageBodyReader.class.getResourceAsStream("/geomaticsGetRecordsResponse.xml");
MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
CswRecordCollection cswRecords = reader.readFrom(CswRecordCollection.class, null, null, null, httpHeaders, is);
List<Metacard> metacards = cswRecords.getCswRecords();
assertThat(metacards, contains(metacard));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionById.
@Ignore
@Test
public void testMarshalRecordCollectionById() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 2;
XStream xstream = createXStream(CswConstants.GET_RECORD_BY_ID_RESPONSE);
CswRecordCollection collection = createCswRecordCollection(null, totalResults);
collection.setById(true);
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(nullValue()));
assertThat(context.get(CswConstants.ELEMENT_NAMES), is(nullValue()));
JAXBElement<GetRecordByIdResponseType> jaxb = (JAXBElement<GetRecordByIdResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordByIdResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetFull.
@Ignore
@Test
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 GetRecordsResponseConverterTest 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 GetRecordsResponseConverterTest method getRecords.
private void getRecords(final int maxRecords, final int startPosition, final int totalResults, final int expectedNext, final int expectedReturn) throws JAXBException, UnsupportedEncodingException {
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType query = new GetRecordsType();
query.setMaxRecords(BigInteger.valueOf(maxRecords));
query.setStartPosition(BigInteger.valueOf(startPosition));
CswRecordCollection collection = createCswRecordCollection(query, totalResults);
collection.setStartPosition(startPosition);
String xml = xstream.toXML(collection);
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
assertThat(response.getSearchResults().getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(response.getSearchResults().getNumberOfRecordsReturned().intValue(), is(expectedReturn));
assertThat(response.getSearchResults().getAbstractRecord().size(), is(expectedReturn));
assertThat(response.getSearchResults().getNextRecord().intValue(), is(expectedNext));
}
Aggregations