Search in sources :

Example 36 with Resource

use of org.apache.cxf.ws.transfer.resource.Resource in project cxf by apache.

the class GetTest method getStudentTest.

@Test
public void getStudentTest() {
    Resource client = TestUtils.createResourceClient(studentRef);
    GetResponse response = client.get(new Get());
    Element representation = (Element) response.getRepresentation().getAny();
    NodeList children = representation.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Element child = (Element) children.item(i);
        if ("name".equals(child.getLocalName())) {
            Assert.assertEquals("John", child.getTextContent());
        } else if ("surname".equals(child.getLocalName())) {
            Assert.assertEquals("Smith", child.getTextContent());
        } else if ("address".equals(child.getLocalName())) {
            Assert.assertEquals("Street 21", child.getTextContent());
        }
    }
}
Also used : Get(org.apache.cxf.ws.transfer.Get) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Resource(org.apache.cxf.ws.transfer.resource.Resource) GetResponse(org.apache.cxf.ws.transfer.GetResponse) Test(org.junit.Test)

Example 37 with Resource

use of org.apache.cxf.ws.transfer.resource.Resource in project cxf by apache.

the class PutTest method rightTeacherPutTest.

@Test
public void rightTeacherPutTest() throws XMLStreamException {
    CreateResponse createResponse = createTeacher();
    Document putStudentXML = StaxUtils.read(getClass().getResourceAsStream("/xml/putTeacher.xml"));
    Put request = new Put();
    request.setRepresentation(new Representation());
    request.getRepresentation().setAny(putStudentXML.getDocumentElement());
    Resource client = TestUtils.createResourceClient(createResponse.getResourceCreated());
    client.put(request);
}
Also used : CreateResponse(org.apache.cxf.ws.transfer.CreateResponse) Resource(org.apache.cxf.ws.transfer.resource.Resource) Representation(org.apache.cxf.ws.transfer.Representation) Document(org.w3c.dom.Document) Put(org.apache.cxf.ws.transfer.Put) Test(org.junit.Test)

Example 38 with Resource

use of org.apache.cxf.ws.transfer.resource.Resource in project cxf by apache.

the class PutTest method wrongTeacherPutTest.

@Test(expected = SOAPFaultException.class)
public void wrongTeacherPutTest() throws XMLStreamException {
    createStudent();
    CreateResponse createResponse = createTeacher();
    Document putStudentXML = StaxUtils.read(getClass().getResourceAsStream("/xml/putTeacher.xml"));
    Put request = new Put();
    request.setRepresentation(new Representation());
    request.getRepresentation().setAny(putStudentXML.getDocumentElement());
    Resource client = TestUtils.createResourceClient(createResponse.getResourceCreated());
    client.put(request);
}
Also used : CreateResponse(org.apache.cxf.ws.transfer.CreateResponse) Resource(org.apache.cxf.ws.transfer.resource.Resource) Representation(org.apache.cxf.ws.transfer.Representation) Document(org.w3c.dom.Document) Put(org.apache.cxf.ws.transfer.Put) Test(org.junit.Test)

Example 39 with Resource

use of org.apache.cxf.ws.transfer.resource.Resource in project cxf by apache.

the class PutTest method rightStudentPutTest.

@Test
public void rightStudentPutTest() throws XMLStreamException {
    CreateResponse createResponse = createStudent();
    Document putStudentXML = StaxUtils.read(getClass().getResourceAsStream("/xml/putStudent.xml"));
    Put request = new Put();
    request.setRepresentation(new Representation());
    request.getRepresentation().setAny(putStudentXML.getDocumentElement());
    Resource client = TestUtils.createResourceClient(createResponse.getResourceCreated());
    client.put(request);
}
Also used : CreateResponse(org.apache.cxf.ws.transfer.CreateResponse) Resource(org.apache.cxf.ws.transfer.resource.Resource) Representation(org.apache.cxf.ws.transfer.Representation) Document(org.w3c.dom.Document) Put(org.apache.cxf.ws.transfer.Put) Test(org.junit.Test)

Example 40 with Resource

use of org.apache.cxf.ws.transfer.resource.Resource in project cxf by apache.

the class FragmentPutAddTest method addSiblingTest.

@Test
public void addSiblingTest() throws XMLStreamException {
    String content = "<a><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_ADD);
    expression.getContent().add("/a");
    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);
    Assert.assertEquals("a", rootEl.getNodeName());
    Assert.assertEquals("b", child0.getNodeName());
    Assert.assertEquals("c", child1.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)

Aggregations

Resource (org.apache.cxf.ws.transfer.resource.Resource)66 Test (org.junit.Test)63 ReferenceParametersType (org.apache.cxf.ws.addressing.ReferenceParametersType)51 MemoryResourceManager (org.apache.cxf.ws.transfer.manager.MemoryResourceManager)51 ResourceManager (org.apache.cxf.ws.transfer.manager.ResourceManager)51 Server (org.apache.cxf.endpoint.Server)50 ExpressionType (org.apache.cxf.ws.transfer.dialect.fragment.ExpressionType)48 ValueType (org.apache.cxf.ws.transfer.dialect.fragment.ValueType)44 Element (org.w3c.dom.Element)39 Put (org.apache.cxf.ws.transfer.Put)37 Fragment (org.apache.cxf.ws.transfer.dialect.fragment.Fragment)32 PutResponse (org.apache.cxf.ws.transfer.PutResponse)25 Get (org.apache.cxf.ws.transfer.Get)21 GetResponse (org.apache.cxf.ws.transfer.GetResponse)18 ObjectFactory (org.apache.cxf.ws.transfer.dialect.fragment.ObjectFactory)16 Representation (org.apache.cxf.ws.transfer.Representation)11 CreateResponse (org.apache.cxf.ws.transfer.CreateResponse)10 Delete (org.apache.cxf.ws.transfer.Delete)7 Document (org.w3c.dom.Document)6 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)3