use of org.apache.cxf.ws.transfer.dialect.fragment.ValueType in project cxf by apache.
the class FragmentGetXPath10Test method getAttrNSTest.
@Test
public void getAttrNSTest() throws XMLStreamException {
String content = "<root xmlns:ns=\"www.example.org\"><a><b ns:attr1=\"value1\">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.XPATH10_LANGUAGE_IRI);
expression.getContent().add("/root/a/b/@ns:attr1");
request.getAny().add(objectFactory.createExpression(expression));
GetResponse response = client.get(request);
ValueType value = getValue(response);
Assert.assertEquals(1, value.getContent().size());
Assert.assertTrue(value.getContent().get(0) instanceof Element);
Element attrEl = (Element) value.getContent().get(0);
Assert.assertEquals(FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME, attrEl.getLocalName());
Assert.assertEquals(FragmentDialectConstants.FRAGMENT_2011_03_IRI, attrEl.getNamespaceURI());
Assert.assertEquals("ns:attr1", attrEl.getAttribute(FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME_ATTR));
Assert.assertEquals("value1", attrEl.getTextContent());
resource.destroy();
}
use of org.apache.cxf.ws.transfer.dialect.fragment.ValueType in project cxf by apache.
the class FragmentGetXPath10Test method getMoreValuesTest.
@Test
public void getMoreValuesTest() 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));
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.XPATH10_LANGUAGE_IRI);
expression.getContent().add("//b");
request.getAny().add(objectFactory.createExpression(expression));
GetResponse response = client.get(request);
ValueType value = getValue(response);
Assert.assertEquals(3, value.getContent().size());
Assert.assertEquals("b", ((Element) value.getContent().get(0)).getLocalName());
Assert.assertEquals("b", ((Element) value.getContent().get(1)).getLocalName());
Assert.assertEquals("b", ((Element) value.getContent().get(2)).getLocalName());
resource.destroy();
}
use of org.apache.cxf.ws.transfer.dialect.fragment.ValueType in project cxf by apache.
the class FragmentGetXPath10Test method getAttrTest.
@Test
public void getAttrTest() throws XMLStreamException {
String content = "<root><a><b attr1=\"value1\">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.XPATH10_LANGUAGE_IRI);
expression.getContent().add("/root/a/b/@attr1");
request.getAny().add(objectFactory.createExpression(expression));
GetResponse response = client.get(request);
ValueType value = getValue(response);
Assert.assertEquals(1, value.getContent().size());
Assert.assertTrue(value.getContent().get(0) instanceof Element);
Element attrEl = (Element) value.getContent().get(0);
Assert.assertEquals(FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME, attrEl.getLocalName());
Assert.assertEquals(FragmentDialectConstants.FRAGMENT_2011_03_IRI, attrEl.getNamespaceURI());
Assert.assertEquals("attr1", attrEl.getAttribute(FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME_ATTR));
Assert.assertEquals("value1", attrEl.getTextContent());
resource.destroy();
}
use of org.apache.cxf.ws.transfer.dialect.fragment.ValueType in project cxf by apache.
the class FragmentPutInsertAfterTest method insertAfterRootTest.
@Test(expected = SOAPFaultException.class)
public void insertAfterRootTest() 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.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_AFTER);
expression.getContent().add("/");
Element addedElement = DOMUtils.getEmptyDocument().createElement("b");
ValueType value = new ValueType();
value.getContent().add(addedElement);
fragment.setExpression(expression);
fragment.setValue(value);
request.getAny().add(fragment);
client.put(request);
resource.destroy();
}
use of org.apache.cxf.ws.transfer.dialect.fragment.ValueType in project cxf by apache.
the class FragmentPutInsertAfterTest method insertAfter1Test.
@Test
public void insertAfter1Test() throws XMLStreamException {
String content = "<a><b/><c/></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.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_AFTER);
expression.getContent().add("/a/b");
Element addedElement = DOMUtils.getEmptyDocument().createElement("d");
ValueType value = new ValueType();
value.getContent().add(addedElement);
fragment.setExpression(expression);
fragment.setValue(value);
request.getAny().add(fragment);
PutResponse response = client.put(request);
Element rootEl = (Element) response.getRepresentation().getAny();
Element child0 = (Element) rootEl.getChildNodes().item(0);
Element child1 = (Element) rootEl.getChildNodes().item(1);
Element child2 = (Element) rootEl.getChildNodes().item(2);
Assert.assertEquals("a", rootEl.getNodeName());
Assert.assertEquals("b", child0.getNodeName());
Assert.assertEquals("d", child1.getNodeName());
Assert.assertEquals("c", child2.getNodeName());
resource.destroy();
}
Aggregations