Search in sources :

Example 16 with Put

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

the class FragmentPutReplaceTest method replaceTextContentTest.

@Test
public void replaceTextContentTest() throws XMLStreamException {
    String content = "<root><a>Text</a></root>";
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);
    // ObjectFactory objectFactory = new ObjectFactory();
    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("/root/a/text()");
    ValueType value = new ValueType();
    value.getContent().add("Better text");
    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.getChildNodes().item(0).getNodeName());
    Assert.assertEquals("Better text", rootEl.getChildNodes().item(0).getTextContent());
    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 17 with Put

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

the class ResourceTest method putRequestTest.

@Test
public void putRequestTest() {
    ResourceManager manager = EasyMock.createMock(ResourceManager.class);
    EasyMock.expect(manager.get(EasyMock.isA(ReferenceParametersType.class))).andReturn(new Representation());
    EasyMock.expectLastCall().once();
    manager.put(EasyMock.isA(ReferenceParametersType.class), EasyMock.isA(Representation.class));
    EasyMock.expectLastCall().once();
    EasyMock.replay(manager);
    ReferenceParametersType refParams = new ReferenceParametersType();
    Element uuid = document.createElementNS(MemoryResourceManager.REF_NAMESPACE, MemoryResourceManager.REF_LOCAL_NAME);
    uuid.setTextContent(UUID_VALUE);
    refParams.getAny().add(uuid);
    Element representationEl = document.createElementNS(REPRESENTATION_NAMESPACE, REPRESENTATION_NAME);
    representationEl.setTextContent(REPRESENTATION_VALUE);
    Representation representation = new Representation();
    representation.setAny(representationEl);
    Server server = createLocalResource(manager);
    Resource client = createClient(refParams);
    Put putRequest = new Put();
    putRequest.setRepresentation(representation);
    PutResponse response = client.put(putRequest);
    EasyMock.verify(manager);
    representationEl = (Element) response.getRepresentation().getAny();
    Assert.assertEquals("Namespace is other than expected.", REPRESENTATION_NAMESPACE, representationEl.getNamespaceURI());
    Assert.assertEquals("Element name is other than expected", REPRESENTATION_NAME, representationEl.getLocalName());
    Assert.assertEquals("Value is other than expected.", REPRESENTATION_VALUE, representationEl.getTextContent());
    server.destroy();
}
Also used : Server(org.apache.cxf.endpoint.Server) 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) Put(org.apache.cxf.ws.transfer.Put) Test(org.junit.Test)

Example 18 with Put

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

the class PutTest method wrongStudentPutTest.

@Test(expected = SOAPFaultException.class)
public void wrongStudentPutTest() throws XMLStreamException {
    createStudent();
    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 19 with Put

use of org.apache.cxf.ws.transfer.Put 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 20 with Put

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

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