Search in sources :

Example 1 with Put

use of org.apache.cxf.ws.transfer.Put 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();
}
Also used : Server(org.apache.cxf.endpoint.Server) ValueType(org.apache.cxf.ws.transfer.dialect.fragment.ValueType) Element(org.w3c.dom.Element) Resource(org.apache.cxf.ws.transfer.resource.Resource) ReferenceParametersType(org.apache.cxf.ws.addressing.ReferenceParametersType) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) ResourceManager(org.apache.cxf.ws.transfer.manager.ResourceManager) Document(org.w3c.dom.Document) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) Fragment(org.apache.cxf.ws.transfer.dialect.fragment.Fragment) ExpressionType(org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType) Put(org.apache.cxf.ws.transfer.Put) Test(org.junit.Test)

Example 2 with Put

use of org.apache.cxf.ws.transfer.Put 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();
}
Also used : Server(org.apache.cxf.endpoint.Server) ValueType(org.apache.cxf.ws.transfer.dialect.fragment.ValueType) Element(org.w3c.dom.Element) Resource(org.apache.cxf.ws.transfer.resource.Resource) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) ResourceManager(org.apache.cxf.ws.transfer.manager.ResourceManager) Document(org.w3c.dom.Document) PutResponse(org.apache.cxf.ws.transfer.PutResponse) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) Fragment(org.apache.cxf.ws.transfer.dialect.fragment.Fragment) Put(org.apache.cxf.ws.transfer.Put) ReferenceParametersType(org.apache.cxf.ws.addressing.ReferenceParametersType) ExpressionType(org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType) Test(org.junit.Test)

Example 3 with Put

use of org.apache.cxf.ws.transfer.Put in project cxf by apache.

the class FragmentPutInsertAfterTest method insertAfterEmptyDocTest.

@Test
public void insertAfterEmptyDocTest() {
    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.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_AFTER);
    expression.getContent().add("/");
    Element addedElement = DOMUtils.getEmptyDocument().createElement("a");
    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();
    Assert.assertEquals("a", rootEl.getNodeName());
    resource.destroy();
}
Also used : Server(org.apache.cxf.endpoint.Server) ValueType(org.apache.cxf.ws.transfer.dialect.fragment.ValueType) Element(org.w3c.dom.Element) Resource(org.apache.cxf.ws.transfer.resource.Resource) ReferenceParametersType(org.apache.cxf.ws.addressing.ReferenceParametersType) Representation(org.apache.cxf.ws.transfer.Representation) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) ResourceManager(org.apache.cxf.ws.transfer.manager.ResourceManager) PutResponse(org.apache.cxf.ws.transfer.PutResponse) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) Fragment(org.apache.cxf.ws.transfer.dialect.fragment.Fragment) ExpressionType(org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType) Put(org.apache.cxf.ws.transfer.Put) Test(org.junit.Test)

Example 4 with Put

use of org.apache.cxf.ws.transfer.Put in project cxf by apache.

the class FragmentPutInsertBeforeTest method insertBefore2Test.

@Test
public void insertBefore2Test() 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.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_BEFORE);
    expression.getContent().add("/a/b[1]");
    Element addedElement = DOMUtils.getEmptyDocument().createElement("c");
    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("c", child0.getNodeName());
    Assert.assertEquals("b", child1.getNodeName());
    Assert.assertEquals("b", child2.getNodeName());
    resource.destroy();
}
Also used : Server(org.apache.cxf.endpoint.Server) ValueType(org.apache.cxf.ws.transfer.dialect.fragment.ValueType) Element(org.w3c.dom.Element) Resource(org.apache.cxf.ws.transfer.resource.Resource) ReferenceParametersType(org.apache.cxf.ws.addressing.ReferenceParametersType) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) ResourceManager(org.apache.cxf.ws.transfer.manager.ResourceManager) PutResponse(org.apache.cxf.ws.transfer.PutResponse) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) Fragment(org.apache.cxf.ws.transfer.dialect.fragment.Fragment) ExpressionType(org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType) Put(org.apache.cxf.ws.transfer.Put) Test(org.junit.Test)

Example 5 with Put

use of org.apache.cxf.ws.transfer.Put in project cxf by apache.

the class FragmentPutInsertBeforeTest method insertBeforeEmptyDocTest.

@Test
public void insertBeforeEmptyDocTest() {
    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.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_BEFORE);
    expression.getContent().add("/");
    Element addedElement = DOMUtils.getEmptyDocument().createElement("a");
    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();
    Assert.assertEquals("a", rootEl.getNodeName());
    resource.destroy();
}
Also used : Server(org.apache.cxf.endpoint.Server) ValueType(org.apache.cxf.ws.transfer.dialect.fragment.ValueType) Element(org.w3c.dom.Element) Resource(org.apache.cxf.ws.transfer.resource.Resource) ReferenceParametersType(org.apache.cxf.ws.addressing.ReferenceParametersType) Representation(org.apache.cxf.ws.transfer.Representation) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) ResourceManager(org.apache.cxf.ws.transfer.manager.ResourceManager) PutResponse(org.apache.cxf.ws.transfer.PutResponse) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) Fragment(org.apache.cxf.ws.transfer.dialect.fragment.Fragment) ExpressionType(org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType) Put(org.apache.cxf.ws.transfer.Put) Test(org.junit.Test)

Aggregations

Put (org.apache.cxf.ws.transfer.Put)37 Resource (org.apache.cxf.ws.transfer.resource.Resource)37 Test (org.junit.Test)37 Server (org.apache.cxf.endpoint.Server)33 ReferenceParametersType (org.apache.cxf.ws.addressing.ReferenceParametersType)33 MemoryResourceManager (org.apache.cxf.ws.transfer.manager.MemoryResourceManager)33 ResourceManager (org.apache.cxf.ws.transfer.manager.ResourceManager)33 Element (org.w3c.dom.Element)33 ExpressionType (org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType)32 Fragment (org.apache.cxf.ws.transfer.dialect.fragment.Fragment)32 ValueType (org.apache.cxf.ws.transfer.dialect.fragment.ValueType)29 PutResponse (org.apache.cxf.ws.transfer.PutResponse)25 Representation (org.apache.cxf.ws.transfer.Representation)10 Document (org.w3c.dom.Document)6 CreateResponse (org.apache.cxf.ws.transfer.CreateResponse)4