use of org.apache.cxf.ws.addressing.ReferenceParametersType in project cxf by apache.
the class FragmentPutRemoveTest method removeAttrTest.
@Test
public void removeAttrTest() throws XMLStreamException {
String content = "<a foo=\"1\"/>";
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.setMode(FragmentDialectConstants.FRAGMENT_MODE_REMOVE);
expression.getContent().add("/a/@foo");
fragment.setExpression(expression);
request.getAny().add(fragment);
PutResponse response = client.put(request);
Element rootEl = (Element) response.getRepresentation().getAny();
Assert.assertNull(rootEl.getAttributeNode("foo"));
resource.destroy();
}
use of org.apache.cxf.ws.addressing.ReferenceParametersType in project cxf by apache.
the class FragmentPutReplaceTest method replaceNonExistingElementFailTest.
@Test(expected = SOAPFaultException.class)
public void replaceNonExistingElementFailTest() 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("//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.addressing.ReferenceParametersType in project cxf by apache.
the class FragmentPutReplaceTest method replaceAttributeTest.
@Test
public void replaceAttributeTest() throws XMLStreamException {
String content = "<root><a foo=\"1\">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/@foo");
Element replacedAttr = DOMUtils.getEmptyDocument().createElementNS(FragmentDialectConstants.FRAGMENT_2011_03_IRI, FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME);
replacedAttr.setAttributeNS(FragmentDialectConstants.FRAGMENT_2011_03_IRI, FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME_ATTR, "bar");
replacedAttr.setTextContent("2");
ValueType value = new ValueType();
value.getContent().add(replacedAttr);
fragment.setExpression(expression);
fragment.setValue(value);
request.getAny().add(fragment);
PutResponse response = client.put(request);
Element rootEl = (Element) response.getRepresentation().getAny();
Element aEl = (Element) rootEl.getChildNodes().item(0);
Assert.assertNotNull(aEl);
String attribute = aEl.getAttribute("bar");
Assert.assertEquals("2", attribute);
resource.destroy();
}
use of org.apache.cxf.ws.addressing.ReferenceParametersType 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.addressing.ReferenceParametersType 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();
}
Aggregations