use of org.apache.cxf.ws.transfer.dialect.fragment.ValueType in project cxf by apache.
the class FragmentPutReplaceTest method replaceOneElementTest.
@Test
public void replaceOneElementTest() 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[1]");
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("c", ((Element) rootEl.getChildNodes().item(0)).getLocalName());
Assert.assertEquals("b", ((Element) rootEl.getChildNodes().item(1)).getLocalName());
resource.destroy();
}
use of org.apache.cxf.ws.transfer.dialect.fragment.ValueType in project cxf by apache.
the class FragmentGetQNameTest method getMoreValuesTest.
@Test
public void getMoreValuesTest() throws XMLStreamException {
String content = "<root><b>Text1</b><b>Text2</b><b>Text3</b></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("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 FragmentGetQNameTest method qetEmptyResultTest.
@Test
public void qetEmptyResultTest() 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("c");
request.getAny().add(objectFactory.createExpression(expression));
GetResponse response = client.get(request);
ValueType value = getValue(response);
Assert.assertEquals(0, value.getContent().size());
resource.destroy();
}
use of org.apache.cxf.ws.transfer.dialect.fragment.ValueType in project cxf by apache.
the class FragmentPutAddTest method addAttributeTest.
@Test
public void addAttributeTest() 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_ADD);
expression.getContent().add("/a");
Document doc = DOMUtils.getEmptyDocument();
Element addedAttr = doc.createElementNS(FragmentDialectConstants.FRAGMENT_2011_03_IRI, FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME);
addedAttr.setAttributeNS(FragmentDialectConstants.FRAGMENT_2011_03_IRI, FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME_ATTR, "foo");
addedAttr.setTextContent("1");
ValueType value = new ValueType();
value.getContent().add(addedAttr);
fragment.setExpression(expression);
fragment.setValue(value);
request.getAny().add(fragment);
PutResponse response = client.put(request);
Element aEl = (Element) response.getRepresentation().getAny();
String attribute = aEl.getAttribute("foo");
Assert.assertEquals("1", attribute);
resource.destroy();
}
use of org.apache.cxf.ws.transfer.dialect.fragment.ValueType in project cxf by apache.
the class FragmentPutAddTest method addExistingAttributeTest.
@Test(expected = SOAPFaultException.class)
public void addExistingAttributeTest() 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_ADD);
expression.getContent().add("/a");
Document doc = DOMUtils.getEmptyDocument();
Element addedAttr = doc.createElementNS(FragmentDialectConstants.FRAGMENT_2011_03_IRI, FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME);
addedAttr.setAttributeNS(FragmentDialectConstants.FRAGMENT_2011_03_IRI, FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME_ATTR, "foo");
addedAttr.setTextContent("2");
ValueType value = new ValueType();
value.getContent().add(addedAttr);
fragment.setExpression(expression);
fragment.setValue(value);
request.getAny().add(fragment);
client.put(request);
resource.destroy();
}
Aggregations