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());
}
}
}
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);
}
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);
}
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);
}
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();
}
Aggregations