@SuppressWarnings("unchecked") @Test public void testUnwrappedLiteralResponseParsing() throws Exception { List response = new ArrayList(); String xml = "<getStringReturn xmlns=\"http://testing.org\">a string</getStringReturn>"; DocumentBuilder builder = DocumentBuilderFactory.newInstance() .newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes())); response.add(new SOAPBodyElement(doc.getDocumentElement())); TypeDescriptor descriptor = new BaseTypeDescriptor(); descriptor.setName("getStringReturn"); SOAPResponseLiteralParser parser = new SOAPResponsePrimitiveLiteralParser( Collections.singletonList(descriptor)); Map outputMap = parser.parse(response); assertNotNull("no output map returned", outputMap); assertEquals("map should contain 1 element", 1, outputMap.size()); Object stringReturn = outputMap.get("getStringReturn"); assertEquals("value of data returned is wrong","a string",stringReturn.toString()); }
@SuppressWarnings("unchecked") @Test public void testEmptyResponse() throws Exception { List response = new ArrayList(); TypeDescriptor descriptor = new BaseTypeDescriptor(); descriptor.setName("getStringReturn"); SOAPResponseLiteralParser parser = new SOAPResponseLiteralParser( Collections.singletonList(descriptor)); Map outputMap = parser.parse(response); assertNotNull("no output map returned", outputMap); assertEquals("map should contain 1 element", 0, outputMap.size()); }
@SuppressWarnings("unchecked") @Test public void testLiteralParserResultInTextBlock() throws Exception { List response = new ArrayList(); String xml = "<testResponse><out><data name="a">some data</data><data name="b">some more data</data></out></testResponse>"; DocumentBuilder builder = DocumentBuilderFactory.newInstance() .newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes())); response.add(new SOAPBodyElement(doc.getDocumentElement())); TypeDescriptor descriptor = new ComplexTypeDescriptor(); descriptor.setName("testResponse"); SOAPResponseLiteralParser parser = new SOAPResponseLiteralParser( Collections.singletonList(descriptor)); Map outputMap = parser.parse(response); assertNotNull("no output map returned", outputMap); assertEquals("map should contain 1 element", 1, outputMap.size()); Object testResponse = outputMap.get("testResponse"); assertNotNull("there should be an output named 'testReponse'", testResponse); assertEquals("output data should be a string", String.class, testResponse.getClass()); assertEquals( "xml is wrong", "<testResponse><out><data name="a">some data</data><data name="b">some more data</data></out></testResponse>", testResponse.toString()); }
@SuppressWarnings("unchecked") @Test public void testLiteralParser() throws Exception { List response = new ArrayList(); String xml = "<testResponse><out><data name=\"a\">some data</data><data name=\"b\">some more data</data></out></testResponse>"; DocumentBuilder builder = DocumentBuilderFactory.newInstance() .newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes())); response.add(new SOAPBodyElement(doc.getDocumentElement())); TypeDescriptor descriptor = new ComplexTypeDescriptor(); descriptor.setName("testResponse"); SOAPResponseLiteralParser parser = new SOAPResponseLiteralParser( Collections.singletonList(descriptor)); Map outputMap = parser.parse(response); assertNotNull("no output map returned", outputMap); assertEquals("map should contain 1 element", 1, outputMap.size()); Object testResponse = outputMap.get("testResponse"); assertNotNull("there should be an output named 'testReponse'", testResponse); assertEquals("output data should be a string", String.class, testResponse.getClass()); assertEquals( "xml is wrong", "<testResponse><out><data name=\"a\">some data</data><data name=\"b\">some more data</data></out></testResponse>", testResponse.toString()); }
descriptor.setName("result"); SOAPResponseEncodedMultiRefParser parser = new SOAPResponseEncodedMultiRefParser( Collections.singletonList(descriptor));
public void testBaseTypeKnownSigniture() { TypeDescriptor decimal=new BaseTypeDescriptor(); decimal.setName("adecimal"); decimal.setType("decimal"); List<TypeDescriptor> params=new ArrayList<TypeDescriptor>(); String [] names=new String[1]; Class<?> [] types=new Class[1]; params.add(decimal); TypeDescriptor.retrieveSignature(params, names, types); assertEquals("should only be 1 type",1,types.length); assertEquals("should only be 1 name",1,names.length); assertEquals("name should be adecimal","adecimal",names[0]); assertEquals("type should be double",Double.TYPE,types[0]); }
public void testBaseTypeUnrecognisedSigniture() { TypeDescriptor date=new BaseTypeDescriptor(); date.setName("adate"); date.setType("date"); List<TypeDescriptor> params=new ArrayList<TypeDescriptor>(); String [] names=new String[1]; Class<?> [] types=new Class[1]; params.add(date); TypeDescriptor.retrieveSignature(params, names, types); assertEquals("should only be 1 type",1,types.length); assertEquals("should only be 1 name",1,names.length); assertEquals("name should be adecimal","adate",names[0]); assertEquals("type should be string",String.class,types[0]); }
public void testComplex() { TypeDescriptor complex=new ComplexTypeDescriptor(); complex.setName("acomplex"); complex.setType("complextype"); List<TypeDescriptor> params=new ArrayList<TypeDescriptor>(); String [] names=new String[1]; Class<?> [] types=new Class[1]; params.add(complex); TypeDescriptor.retrieveSignature(params, names, types); assertEquals("should only be 1 type",1,types.length); assertEquals("should only be 1 name",1,names.length); assertEquals("name should be adecimal","acomplex",names[0]); assertEquals("type should be string",org.w3c.dom.Element.class,types[0]); }