Search in sources :

Example 1 with ExpressionType

use of org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType in project cxf by apache.

the class FragmentGetXPath10Test method getBooleanTrueTest.

@Test
public void getBooleanTrueTest() throws XMLStreamException {
    String content = "<root><a><b>Text</b><b>Text2</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("count(//b) = 2");
    request.getAny().add(objectFactory.createExpression(expression));
    GetResponse response = client.get(request);
    ValueType value = getValue(response);
    Assert.assertEquals(1, value.getContent().size());
    Assert.assertEquals("true", value.getContent().get(0));
    resource.destroy();
}
Also used : Server(org.apache.cxf.endpoint.Server) ObjectFactory(org.apache.cxf.ws.transfer.dialect.fragment.ObjectFactory) ValueType(org.apache.cxf.ws.transfer.dialect.fragment.ValueType) Get(org.apache.cxf.ws.transfer.Get) 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) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) ExpressionType(org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType) GetResponse(org.apache.cxf.ws.transfer.GetResponse) Test(org.junit.Test)

Example 2 with ExpressionType

use of org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType in project cxf by apache.

the class FragmentGetXPath10Test method getImpliedLanguageTest.

@Test
public void getImpliedLanguageTest() 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.getContent().add("/root/a/b");
    request.getAny().add(objectFactory.createExpression(expression));
    GetResponse response = client.get(request);
    ValueType value = getValue(response);
    Assert.assertEquals(1, value.getContent().size());
    Assert.assertEquals("b", ((Element) value.getContent().get(0)).getLocalName());
    resource.destroy();
}
Also used : Server(org.apache.cxf.endpoint.Server) ObjectFactory(org.apache.cxf.ws.transfer.dialect.fragment.ObjectFactory) ValueType(org.apache.cxf.ws.transfer.dialect.fragment.ValueType) Get(org.apache.cxf.ws.transfer.Get) 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) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) ExpressionType(org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType) GetResponse(org.apache.cxf.ws.transfer.GetResponse) Test(org.junit.Test)

Example 3 with ExpressionType

use of org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType in project cxf by apache.

the class FragmentGetXPath10Test method getWithNamespaceTest.

@Test
public void getWithNamespaceTest() throws XMLStreamException {
    String content = "<ns:root xmlns:ns=\"www.example.org\"><ns:a><ns:b>Text</ns:b></ns:a></ns: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("/ns:root/ns:a/ns:b");
    request.getAny().add(objectFactory.createExpression(expression));
    GetResponse response = client.get(request);
    ValueType value = getValue(response);
    Assert.assertEquals(1, value.getContent().size());
    Assert.assertEquals("b", ((Element) value.getContent().get(0)).getLocalName());
    Assert.assertEquals("www.example.org", ((Element) value.getContent().get(0)).getNamespaceURI());
    resource.destroy();
}
Also used : Server(org.apache.cxf.endpoint.Server) ObjectFactory(org.apache.cxf.ws.transfer.dialect.fragment.ObjectFactory) ValueType(org.apache.cxf.ws.transfer.dialect.fragment.ValueType) Get(org.apache.cxf.ws.transfer.Get) 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) MemoryResourceManager(org.apache.cxf.ws.transfer.manager.MemoryResourceManager) ExpressionType(org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType) GetResponse(org.apache.cxf.ws.transfer.GetResponse) Test(org.junit.Test)

Example 4 with ExpressionType

use of org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType 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 5 with ExpressionType

use of org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType 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)

Aggregations

ReferenceParametersType (org.apache.cxf.ws.addressing.ReferenceParametersType)48 ExpressionType (org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType)48 MemoryResourceManager (org.apache.cxf.ws.transfer.manager.MemoryResourceManager)48 ResourceManager (org.apache.cxf.ws.transfer.manager.ResourceManager)48 Resource (org.apache.cxf.ws.transfer.resource.Resource)48 Test (org.junit.Test)48 Server (org.apache.cxf.endpoint.Server)47 ValueType (org.apache.cxf.ws.transfer.dialect.fragment.ValueType)44 Element (org.w3c.dom.Element)34 Put (org.apache.cxf.ws.transfer.Put)32 Fragment (org.apache.cxf.ws.transfer.dialect.fragment.Fragment)32 PutResponse (org.apache.cxf.ws.transfer.PutResponse)24 Get (org.apache.cxf.ws.transfer.Get)16 ObjectFactory (org.apache.cxf.ws.transfer.dialect.fragment.ObjectFactory)16 GetResponse (org.apache.cxf.ws.transfer.GetResponse)15 Representation (org.apache.cxf.ws.transfer.Representation)5 JAXBElement (javax.xml.bind.JAXBElement)2 Document (org.w3c.dom.Document)2