/** * Tests that, when 'mark-generated' option is set, @Generated annotations are inserted in all * generated java classes. */ @Test public void testMarkGeneratedOption() throws Exception { env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl")); env.put(ToolConstants.CFG_MARK_GENERATED, "true"); env.put(ToolConstants.CFG_COMPILE, null); env.put(ToolConstants.CFG_CLASSDIR, null); processor.setContext(env); processor.execute(); File dir = new File(output, "org"); assertTrue("org directory is not found", dir.exists()); dir = new File(dir, "apache"); assertTrue("apache directory is not found", dir.exists()); dir = new File(dir, "cxf"); assertTrue("cxf directory is not found", dir.exists()); dir = new File(dir, "w2j"); assertTrue("w2j directory is not found", dir.exists()); dir = new File(dir, "hello_world_soap_http"); assertTrue("hello_world_soap_http directory is not found", dir.exists()); File types = new File(dir, "types"); assertTrue("types directory is not found", dir.exists()); String str = IOUtils.readStringFromStream(new FileInputStream(new File(dir, "Greeter.java"))); assertEquals(7, countGeneratedAnnotations(str)); str = IOUtils.readStringFromStream(new FileInputStream(new File(types, "SayHi.java"))); assertEquals(1, countGeneratedAnnotations(str)); str = IOUtils.readStringFromStream(new FileInputStream(new File(types, "SayHiResponse.java"))); assertEquals(4, countGeneratedAnnotations(str)); }
private void doInvoke(String actualBookName, String actualHeaderName) throws Exception { Response response = client.post(actualBookName); assertEquals(actualHeaderName, response.getMetadata().getFirst("CustomHeader").toString()); String responseValue = IOUtils.readStringFromStream((InputStream) response.getEntity()); assertEquals(actualBookName, responseValue); }
public String storeTurtleUserProfile(String userProfile, String username, String password) { String rsUri = getBASE_URI() + "createNewUserAccount"; WebClient client = WebClient.create(rsUri); client.type("multipart/mixed").accept(MediaType.TEXT_PLAIN); registerJsonProvider(); List<Attachment> atts = new LinkedList<Attachment>(); atts.add(new Attachment("userProfile", MediaType.TEXT_PLAIN, userProfile)); atts.add(new Attachment("username", MediaType.TEXT_PLAIN, username)); atts.add(new Attachment("password", MediaType.TEXT_PLAIN, password)); Response response = client.post(new MultipartBody(atts)); String userInstanceUriId = null; if (Response.Status.fromStatusCode(response.getStatus()) == Response.Status.CREATED) { try { userInstanceUriId = IOUtils.readStringFromStream((InputStream) response.getEntity()); logger.debug("Response Status CREATED - userInstanceUriId: " + userInstanceUriId); } catch (IOException ex) { logger.error("Error reading the REST response: " + ex.getMessage()); } } return userInstanceUriId; }
public boolean removeUserCredentialsForPaaS(String userInstanceUriId, String paaSInstanceUriId) throws SOAException { String rsUri = getBASE_URI() + "removeUserCredentialsForPaaS"; WebClient client = WebClient.create(rsUri); client.type("multipart/mixed").accept(MediaType.TEXT_PLAIN); registerJsonProvider(); List<Attachment> atts = new LinkedList<Attachment>(); atts.add(new Attachment("userInstanceUriId", MediaType.TEXT_PLAIN, userInstanceUriId)); atts.add(new Attachment("paaSInstanceUriId", MediaType.TEXT_PLAIN, paaSInstanceUriId)); Response response = client.post(new MultipartBody(atts)); if (Response.Status.fromStatusCode(response.getStatus()) == Response.Status.ACCEPTED) { try { String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); logger.debug("Response Status ACCEPTED - " + responseString); } catch (IOException ex) { logger.error("Error reading the REST response: " + ex.getMessage()); } return true; } return false; }
@Test public void testEncoding() throws Exception { try { CodeWriter.class.getDeclaredField("encoding"); } catch (Throwable t) { // version of jaxb that doesn't support this. We'll just not run the test. return; } env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world_encoding.wsdl")); env.put(ToolConstants.CFG_WSDLLOCATION, "/wsdl2java_wsdl/hello_world_encoding.wsdl"); env.put(ToolConstants.CFG_ENCODING, "Cp1251"); processor.setContext(env); processor.execute(); File dir = new File(output, "org"); assertTrue("org directory is not found", dir.exists()); dir = new File(dir, "apache"); assertTrue("apache directory is not found", dir.exists()); dir = new File(dir, "cxf"); assertTrue("cxf directory is not found", dir.exists()); dir = new File(dir, "w2j"); assertTrue("w2j directory is not found", dir.exists()); dir = new File(dir, "hello_world_soap_http"); assertTrue("hello_world_soap_http directory is not found", dir.exists()); String str = IOUtils.readStringFromStream(new FileInputStream(new File(dir, "SOAPService.java"))); assertTrue(str, str.contains("getResource")); Class<?> clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_soap_http.Greeter"); for (Method m : clz.getMethods()) { String s = m.getName(); assertEquals(1039, s.charAt(2)); } }
@POST @Path("/bookform") @Consumes("application/xml") @Produces("application/xml") public String echoBookFormXml(@Context HttpServletRequest req) throws IOException { InputStream is = req.getInputStream(); return IOUtils.readStringFromStream(is); }
@Test @Ignore public void testApiListingIsProperlyReturnedJSON() throws Exception { final WebClient client = createWebClient("/swagger.json"); try { final Response r = client.get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); JSONAssert.assertEquals( getExpectedValue(getExpectedFileJson(), getPort()), IOUtils.readStringFromStream((InputStream) r.getEntity()), false); } finally { client.close(); } }
@Test @Ignore public void testApiListingIsProperlyReturnedYAML() throws Exception { final WebClient client = createWebClient("/swagger.yaml"); try { final Response r = client.get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); // REVISIT find a better way of reliably comparing two yaml instances. // I noticed that yaml.load instantiates a Map and // for an integer valued key, an Integer or a String is arbitrarily instantiated, // which leads to the assertion error. So, we serilialize the yamls and compare the // re-serialized texts. Yaml yaml = new Yaml(); assertEquals( yaml.load(getExpectedValue(getExpectedFileYaml(), getPort())).toString(), yaml.load(IOUtils.readStringFromStream((InputStream) r.getEntity())).toString()); } finally { client.close(); } }
@Test public void testResourceURLForWsdlLocation() throws Exception { env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl")); env.put(ToolConstants.CFG_WSDLLOCATION, "/wsdl2java_wsdl/hello_world.wsdl"); env.put(ToolConstants.CFG_COMPILE, null); env.put(ToolConstants.CFG_CLASSDIR, null); processor.setContext(env); processor.execute(); File dir = new File(output, "org"); assertTrue("org directory is not found", dir.exists()); dir = new File(dir, "apache"); assertTrue("apache directory is not found", dir.exists()); dir = new File(dir, "cxf"); assertTrue("cxf directory is not found", dir.exists()); dir = new File(dir, "w2j"); assertTrue("w2j directory is not found", dir.exists()); dir = new File(dir, "hello_world_soap_http"); assertTrue("hello_world_soap_http directory is not found", dir.exists()); String str = IOUtils.readStringFromStream(new FileInputStream(new File(dir, "SOAPService.java"))); assertTrue(str, str.contains("getResource")); }
private static String getExpectedValue(String name, Object... args) throws IOException { return String.format( IOUtils.readStringFromStream( AbstractSwagger2ServiceDescriptionTest.class.getResourceAsStream(name)), args); }