use of org.apache.cxf.ws.transfer.manager.ResourceManager in project cxf by apache.
the class FragmentPutReplaceTest method replaceElementTest.
@Test
public void replaceElementTest() throws XMLStreamException {
String content = "<root><a>Text</a></root>";
ResourceManager resourceManager = new MemoryResourceManager();
ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
Server resource = createLocalResource(resourceManager);
Resource client = createClient(refParams);
Put request = new Put();
request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
Fragment fragment = new Fragment();
ExpressionType expression = new ExpressionType();
expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
expression.getContent().add("/root/a");
Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
replacedElement.setTextContent("Better text");
ValueType value = new ValueType();
value.getContent().add(replacedElement);
fragment.setExpression(expression);
fragment.setValue(value);
request.getAny().add(fragment);
PutResponse response = client.put(request);
Element rootEl = (Element) response.getRepresentation().getAny();
Assert.assertEquals("b", rootEl.getChildNodes().item(0).getNodeName());
Assert.assertEquals("Better text", rootEl.getChildNodes().item(0).getTextContent());
resource.destroy();
}
use of org.apache.cxf.ws.transfer.manager.ResourceManager in project cxf by apache.
the class FragmentPutReplaceTest method replaceNonExistingElementFail2Test.
@Test(expected = SOAPFaultException.class)
public void replaceNonExistingElementFail2Test() throws XMLStreamException {
String content = "<a/>";
ResourceManager resourceManager = new MemoryResourceManager();
ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
Server resource = createLocalResource(resourceManager);
Resource client = createClient(refParams);
Put request = new Put();
request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
Fragment fragment = new Fragment();
ExpressionType expression = new ExpressionType();
expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
expression.getContent().add("/a/[local-name() = 'b'");
Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
ValueType value = new ValueType();
value.getContent().add(replacedElement);
fragment.setExpression(expression);
fragment.setValue(value);
request.getAny().add(fragment);
client.put(request);
resource.destroy();
}
use of org.apache.cxf.ws.transfer.manager.ResourceManager in project cxf by apache.
the class FragmentPutReplaceTest method replaceEmptyDocumentTest.
@Test
public void replaceEmptyDocumentTest() {
ResourceManager resourceManager = new MemoryResourceManager();
ReferenceParametersType refParams = resourceManager.create(new Representation());
Server resource = createLocalResource(resourceManager);
Resource client = createClient(refParams);
Put request = new Put();
request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
Fragment fragment = new Fragment();
ExpressionType expression = new ExpressionType();
expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
expression.getContent().add("/");
Element replacedElement = DOMUtils.getEmptyDocument().createElement("a");
ValueType value = new ValueType();
value.getContent().add(replacedElement);
fragment.setExpression(expression);
fragment.setValue(value);
request.getAny().add(fragment);
PutResponse response = client.put(request);
Element rootEl = (Element) response.getRepresentation().getAny();
Assert.assertEquals("a", rootEl.getNodeName());
resource.destroy();
}
use of org.apache.cxf.ws.transfer.manager.ResourceManager in project cxf by apache.
the class FragmentPutReplaceTest method replaceDocument2Test.
@Test
public void replaceDocument2Test() throws XMLStreamException {
String content = "<a/>";
ResourceManager resourceManager = new MemoryResourceManager();
ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
Server resource = createLocalResource(resourceManager);
Resource client = createClient(refParams);
Put request = new Put();
request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
Fragment fragment = new Fragment();
ExpressionType expression = new ExpressionType();
expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
expression.getContent().add("/*");
Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
ValueType value = new ValueType();
value.getContent().add(replacedElement);
fragment.setExpression(expression);
fragment.setValue(value);
request.getAny().add(fragment);
PutResponse response = client.put(request);
Element rootEl = (Element) response.getRepresentation().getAny();
Assert.assertEquals("b", rootEl.getNodeName());
resource.destroy();
}
use of org.apache.cxf.ws.transfer.manager.ResourceManager in project cxf by apache.
the class ResourceFactoryTest method createLocalResourceTest.
@Test
public void createLocalResourceTest() {
ReferenceParametersType refParams = createReferenceParameters();
ResourceManager manager = EasyMock.createMock(ResourceManager.class);
EasyMock.expect(manager.create(EasyMock.isA(Representation.class))).andReturn(refParams);
EasyMock.expectLastCall().once();
EasyMock.replay(manager);
Server localResourceFactory = createLocalResourceFactory(manager);
ResourceFactory client = createClient();
Create createRequest = new Create();
Representation representation = new Representation();
representation.setAny(createXMLRepresentation());
createRequest.setRepresentation(representation);
CreateResponse response = client.create(createRequest);
EasyMock.verify(manager);
Assert.assertEquals("ResourceAddress is other than expected.", RESOURCE_ADDRESS, response.getResourceCreated().getAddress().getValue());
Element refParamEl = (Element) response.getResourceCreated().getReferenceParameters().getAny().get(0);
Assert.assertEquals(REF_PARAM_NAMESPACE, refParamEl.getNamespaceURI());
Assert.assertEquals(REF_PARAM_LOCAL_NAME, refParamEl.getLocalName());
Assert.assertEquals(RESOURCE_UUID, refParamEl.getTextContent());
Assert.assertEquals("root", ((Element) response.getRepresentation().getAny()).getLocalName());
Assert.assertEquals(2, ((Element) response.getRepresentation().getAny()).getChildNodes().getLength());
localResourceFactory.destroy();
}
Aggregations