Search in sources :

Example 31 with ObjectFactory

use of jaxb1.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));
}
Also used : Dictionary(java.util.Dictionary) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Subscription(ddf.catalog.event.Subscription) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Test(org.junit.Test)

Example 32 with ObjectFactory

use of jaxb1.ObjectFactory in project ddf by codice.

the class SendEventTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("ddf.home", ".");
    callbackURI = new URL("https://localhost:12345/services/csw/subscription/event");
    ObjectFactory objectFactory = new ObjectFactory();
    request = new GetRecordsType();
    request.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    request.setResultType(ResultType.RESULTS);
    request.getResponseHandler().add(callbackURI.toString());
    queryType = new QueryType();
    elementSetNameType = new ElementSetNameType();
    elementSetNameType.setValue(ElementSetType.BRIEF);
    queryType.setElementSetName(elementSetNameType);
    request.setAbstractQuery(objectFactory.createAbstractQuery(queryType));
    transformerManager = mock(TransformerManager.class);
    transformer = mock(QueryResponseTransformer.class);
    binaryContent = mock(BinaryContent.class);
    when(transformerManager.getTransformerBySchema(ArgumentMatchers.contains(CswConstants.CSW_OUTPUT_SCHEMA))).thenReturn(transformer);
    when(transformer.transform(any(SourceResponse.class), anyMap())).thenReturn(binaryContent);
    when(binaryContent.getByteArray()).thenReturn("byte array with message contents".getBytes());
    query = mock(QueryRequest.class);
    metacard = mock(Metacard.class);
    webclient = mock(WebClient.class);
    mockCxfClientFactory = mock(SecureCxfClientFactory.class);
    response = mock(Response.class);
    subject = mock(Subject.class);
    mockSecurity = mock(Security.class);
    headers.put(Subject.class.toString(), Arrays.asList(new Subject[] { subject }));
    AccessPlugin accessPlugin = mock(AccessPlugin.class);
    accessPlugins.add(accessPlugin);
    when(mockCxfClientFactory.getWebClient()).thenReturn(webclient);
    when(webclient.invoke(anyString(), isNull())).thenReturn(response);
    when(response.getHeaders()).thenReturn(headers);
    when(accessPlugin.processPostQuery(any(QueryResponse.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);
    sendEvent = new SendEventExtension(request, query, mockCxfClientFactory);
    sendEvent.setSubject(subject);
}
Also used : TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SecureCxfClientFactory(org.codice.ddf.cxf.client.SecureCxfClientFactory) AccessPlugin(ddf.catalog.plugin.AccessPlugin) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) BinaryContent(ddf.catalog.data.BinaryContent) Security(org.codice.ddf.security.Security) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Subject(ddf.security.Subject) QueryResponse(ddf.catalog.operation.QueryResponse) SourceResponse(ddf.catalog.operation.SourceResponse) Response(javax.ws.rs.core.Response) Metacard(ddf.catalog.data.Metacard) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) QueryResponse(ddf.catalog.operation.QueryResponse) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Before(org.junit.Before)

Example 33 with ObjectFactory

use of jaxb1.ObjectFactory in project ddf by codice.

the class CswQueryFactoryTest method setUp.

@org.junit.Before
public void setUp() throws URISyntaxException, SourceUnavailableException, UnsupportedQueryException, FederationException, ParseException, IngestException {
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    FilterAdapter filterAdapter = new GeotoolsFilterAdapterImpl();
    CswRecordMap cswRecordMap = new MetacardCswRecordMap();
    queryFactory = new CswQueryFactory(cswRecordMap, filterBuilder, filterAdapter, new PermissionsImpl());
    AttributeRegistryImpl attributeRegistry = new AttributeRegistryImpl();
    attributeRegistry.registerMetacardType(getCswMetacardType());
    queryFactory.setAttributeRegistry(attributeRegistry);
    polygon = new WKTReader().read(POLYGON_STR);
    gmlObjectFactory = new net.opengis.gml.v_3_1_1.ObjectFactory();
    filterObjectFactory = new ObjectFactory();
    queryFilterTransformerProvider = mock(QueryFilterTransformerProvider.class);
    QueryFilterTransformer cswQueryFilter = new CswQueryFilterTransformer(new MetacardCswRecordMap(), attributeRegistry);
    when(queryFilterTransformerProvider.getTransformer(new QName(CswConstants.CSW_OUTPUT_SCHEMA, "Record"))).thenReturn(Optional.of(cswQueryFilter));
    when(queryFilterTransformerProvider.getTransformer(anyString())).thenReturn(Optional.of(cswQueryFilter));
    queryFactory.setQueryFilterTransformerProvider(queryFilterTransformerProvider);
}
Also used : AttributeRegistryImpl(ddf.catalog.data.impl.AttributeRegistryImpl) QueryFilterTransformerProvider(ddf.catalog.transform.QueryFilterTransformerProvider) QName(javax.xml.namespace.QName) FilterAdapter(ddf.catalog.filter.FilterAdapter) CswQueryFilterTransformer(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswQueryFilterTransformer) CswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswRecordMap) MetacardCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.MetacardCswRecordMap) WKTReader(org.locationtech.jts.io.WKTReader) ObjectFactory(net.opengis.filter.v_1_1_0.ObjectFactory) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) MetacardCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.MetacardCswRecordMap) QueryFilterTransformer(ddf.catalog.transform.QueryFilterTransformer) CswQueryFilterTransformer(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.transformer.CswQueryFilterTransformer)

Example 34 with ObjectFactory

use of jaxb1.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);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) GregorianCalendar(java.util.GregorianCalendar) EchoedRequestType(net.opengis.cat.csw.v_2_0_2.EchoedRequestType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBContext(javax.xml.bind.JAXBContext) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType)

Example 35 with ObjectFactory

use of jaxb1.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));
}
Also used : HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) QName(javax.xml.namespace.QName) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) LinkedList(java.util.LinkedList) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)23 JAXBElement (javax.xml.bind.JAXBElement)22 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)20 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)18 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 QName (javax.xml.namespace.QName)13 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)13 XStream (com.thoughtworks.xstream.XStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)12 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)12 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)12 ArrayList (java.util.ArrayList)11 Marshaller (javax.xml.bind.Marshaller)11 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)11 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)10 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 StringWriter (java.io.StringWriter)10 BigInteger (java.math.BigInteger)10 JAXBContext (javax.xml.bind.JAXBContext)10 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)8