use of org.apache.cxf.ws.transfer.resource.Resource in project cxf by apache.
the class IntegrationBaseTest method createClient.
protected Resource createClient(ReferenceParametersType refParams) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
Map<String, Object> props = factory.getProperties();
if (props == null) {
props = new HashMap<>();
}
props.put("jaxb.additionalContextClasses", ExpressionType.class);
factory.setProperties(props);
factory.setBus(bus);
factory.setServiceClass(Resource.class);
factory.setAddress(RESOURCE_ADDRESS);
Resource proxy = (Resource) factory.create();
// Add reference parameters
AddressingProperties addrProps = new AddressingProperties();
EndpointReferenceType endpoint = new EndpointReferenceType();
endpoint.setReferenceParameters(refParams);
endpoint.setAddress(ContextUtils.getAttributedURI(RESOURCE_ADDRESS));
addrProps.setTo(endpoint);
((BindingProvider) proxy).getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProps);
return proxy;
}
use of org.apache.cxf.ws.transfer.resource.Resource in project cxf by apache.
the class ResourceTest method getRequestTest.
@Test
public void getRequestTest() {
Element representationEl = document.createElementNS(REPRESENTATION_NAMESPACE, REPRESENTATION_NAME);
representationEl.setTextContent(REPRESENTATION_VALUE);
Representation representation = new Representation();
representation.setAny(representationEl);
ResourceManager manager = EasyMock.createMock(ResourceManager.class);
EasyMock.expect(manager.get(EasyMock.isA(ReferenceParametersType.class))).andReturn(representation);
EasyMock.expectLastCall().once();
EasyMock.replay(manager);
ReferenceParametersType refParams = new ReferenceParametersType();
Element uuid = document.createElementNS(MemoryResourceManager.REF_NAMESPACE, MemoryResourceManager.REF_LOCAL_NAME);
uuid.setTextContent(UUID_VALUE);
refParams.getAny().add(uuid);
Server server = createLocalResource(manager);
Resource client = createClient(refParams);
GetResponse response = client.get(new Get());
EasyMock.verify(manager);
representationEl = (Element) response.getRepresentation().getAny();
Assert.assertEquals("Namespace is other than expected.", REPRESENTATION_NAMESPACE, representationEl.getNamespaceURI());
Assert.assertEquals("Element name is other than expected", REPRESENTATION_NAME, representationEl.getLocalName());
Assert.assertEquals("Value is other than expected.", REPRESENTATION_VALUE, representationEl.getTextContent());
server.destroy();
}
use of org.apache.cxf.ws.transfer.resource.Resource in project cxf by apache.
the class FragmentGetQNameTest method getTest.
@Test
public void getTest() throws XMLStreamException {
String content = "<root><a><b>Text</b></a></root>";
ResourceManager resourceManager = new MemoryResourceManager();
ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
Server resource = createLocalResource(resourceManager);
Resource client = createClient(refParams);
ObjectFactory objectFactory = new ObjectFactory();
Get request = new Get();
request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
ExpressionType expression = new ExpressionType();
expression.setLanguage(FragmentDialectConstants.QNAME_LANGUAGE_IRI);
expression.getContent().add("a");
request.getAny().add(objectFactory.createExpression(expression));
GetResponse response = client.get(request);
ValueType value = getValue(response);
Assert.assertEquals(1, value.getContent().size());
Assert.assertEquals("a", ((Element) value.getContent().get(0)).getLocalName());
resource.destroy();
}
use of org.apache.cxf.ws.transfer.resource.Resource in project cxf by apache.
the class FragmentGetQNameTest method getWrongQNameTest.
@Test(expected = SOAPFaultException.class)
public void getWrongQNameTest() throws XMLStreamException {
String content = "<root><a><b>Text1</b><b>Text2</b><b>Text3</b></a></root>";
ResourceManager resourceManager = new MemoryResourceManager();
ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
createLocalResource(resourceManager);
Resource client = createClient(refParams);
ObjectFactory objectFactory = new ObjectFactory();
Get request = new Get();
request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
ExpressionType expression = new ExpressionType();
expression.setLanguage(FragmentDialectConstants.QNAME_LANGUAGE_IRI);
expression.getContent().add("//b");
request.getAny().add(objectFactory.createExpression(expression));
client.get(request);
}
use of org.apache.cxf.ws.transfer.resource.Resource in project cxf by apache.
the class FragmentGetQNameTest method getWithNamespaceTest.
@Test
public void getWithNamespaceTest() throws XMLStreamException {
String content = "<ns:root xmlns:ns=\"www.example.org\"><ns:a><ns:b>Text</ns:b></ns:a></ns:root>";
ResourceManager resourceManager = new MemoryResourceManager();
ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
Server resource = createLocalResource(resourceManager);
Resource client = createClient(refParams);
ObjectFactory objectFactory = new ObjectFactory();
Get request = new Get();
request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
ExpressionType expression = new ExpressionType();
expression.setLanguage(FragmentDialectConstants.QNAME_LANGUAGE_IRI);
expression.getContent().add("ns:a");
request.getAny().add(objectFactory.createExpression(expression));
GetResponse response = client.get(request);
ValueType value = getValue(response);
Assert.assertEquals(1, value.getContent().size());
Assert.assertEquals("a", ((Element) value.getContent().get(0)).getLocalName());
Assert.assertEquals("www.example.org", ((Element) value.getContent().get(0)).getNamespaceURI());
resource.destroy();
}
Aggregations