use of org.apache.cxf.ws.addressing.ReferenceParametersType in project cxf by apache.
the class FragmentPutReplaceTest method replaceNonExistingRootTest.
@Test
public void replaceNonExistingRootTest() {
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("/a");
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.getLocalName());
resource.destroy();
}
use of org.apache.cxf.ws.addressing.ReferenceParametersType in project cxf by apache.
the class FragmentPutReplaceTest method replaceElement2Test.
@Test
public void replaceElement2Test() 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");
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.addressing.ReferenceParametersType in project cxf by apache.
the class FragmentPutReplaceTest method replaceAllElementsTest.
@Test
public void replaceAllElementsTest() throws XMLStreamException {
String content = "<a><b/><b/></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/b");
Element replacedElement = DOMUtils.getEmptyDocument().createElement("c");
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(1, rootEl.getChildNodes().getLength());
Assert.assertEquals("c", ((Element) rootEl.getChildNodes().item(0)).getLocalName());
resource.destroy();
}
use of org.apache.cxf.ws.addressing.ReferenceParametersType in project cxf by apache.
the class FragmentPutReplaceTest method replaceNonExistingElementTest.
@Test
public void replaceNonExistingElementTest() 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/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);
PutResponse response = client.put(request);
Element rootEl = (Element) response.getRepresentation().getAny();
Assert.assertEquals(1, rootEl.getChildNodes().getLength());
Assert.assertEquals("b", ((Element) rootEl.getChildNodes().item(0)).getLocalName());
resource.destroy();
}
use of org.apache.cxf.ws.addressing.ReferenceParametersType in project cxf by apache.
the class FragmentPutReplaceTest method replaceTextContentTest.
@Test
public void replaceTextContentTest() 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);
// ObjectFactory objectFactory = new ObjectFactory();
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/text()");
ValueType value = new ValueType();
value.getContent().add("Better text");
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.getChildNodes().item(0).getNodeName());
Assert.assertEquals("Better text", rootEl.getChildNodes().item(0).getTextContent());
resource.destroy();
}
Aggregations