use of no.nav.vedtak.felles.xml.soeknad.v2.ObjectFactory in project ddf by codice.
the class CswSubscriptionEndpointTest method testCreateOrUpdateSubscriptionPersitanceFalse.
@Test
public void testCreateOrUpdateSubscriptionPersitanceFalse() throws Exception {
ObjectFactory objectFactory = new ObjectFactory();
GetRecordsType getRecordsType = createDefaultGetRecordsRequest().get202RecordsType();
QueryType queryType = new QueryType();
getRecordsType.setAbstractQuery(objectFactory.createQuery(queryType));
cswSubscriptionEndpoint.createOrUpdateSubscription(getRecordsType, subscriptionId, false);
verify(mockContext).registerService(eq(Subscription.class.getName()), any(Subscription.class), any(Dictionary.class));
}
use of no.nav.vedtak.felles.xml.soeknad.v2.ObjectFactory in project ddf by codice.
the class CswQueryResponseTransformer method writeAcknowledgement.
private ByteArrayOutputStream writeAcknowledgement(GetRecordsType request) throws CatalogTransformerException {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JAXBContext jaxBContext = JAXBContext.newInstance("net.opengis.cat.csw.v_2_0_2:" + "net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1:net.opengis.ows.v_1_0_0");
Marshaller marshaller = jaxBContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
AcknowledgementType ack = new AcknowledgementType();
EchoedRequestType echoedRequest = new EchoedRequestType();
JAXBElement<GetRecordsType> jaxBRequest = new ObjectFactory().createGetRecords(request);
echoedRequest.setAny(jaxBRequest);
ack.setEchoedRequest(echoedRequest);
try {
ack.setTimeStamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));
} catch (DatatypeConfigurationException e) {
LOGGER.debug("Failed to set timestamp on Acknowledgement", e);
}
JAXBElement<AcknowledgementType> jaxBAck = new ObjectFactory().createAcknowledgement(ack);
marshaller.marshal(jaxBAck, byteArrayOutputStream);
return byteArrayOutputStream;
} catch (JAXBException e) {
throw new CatalogTransformerException(e);
}
}
use of no.nav.vedtak.felles.xml.soeknad.v2.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetBrief.
@Ignore
@Test
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 no.nav.vedtak.felles.xml.soeknad.v2.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionHits.
@Ignore
@Test
public void testMarshalRecordCollectionHits() 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);
collection.setResultType(ResultType.HITS);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, never()).marshal(any(Object.class), any(HierarchicalStreamWriter.class), any(MarshallingContext.class));
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(0));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of no.nav.vedtak.felles.xml.soeknad.v2.ObjectFactory in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetElements.
@Ignore
@Test
public void testMarshalRecordCollectionGetElements() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
List<QName> elements = new LinkedList<>();
elements.add(CswConstants.CSW_TITLE_QNAME);
elements.add(CswConstants.CSW_SOURCE_QNAME);
query.setElementName(elements);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementName(elements);
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(notNullValue()));
List<QName> qnames = (List<QName>) context.get(CswConstants.ELEMENT_NAMES);
assertThat(qnames.contains(CswConstants.CSW_TITLE_QNAME), is(true));
assertThat(qnames.contains(CswConstants.CSW_SOURCE_QNAME), is(true));
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(nullValue()));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Aggregations