12.07.2015 Views

Anyframe CXF Plugin

Anyframe CXF Plugin

Anyframe CXF Plugin

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

RESTful Services*/public void testCreateMovies() throws Exception {// 1. create movieString inputFile =this.getClass().getClassLoader().getResource("webservices/restful/httpbinding/jra/create_movies.txt").getFile();File input = new File(inputFile);PostMethod post =new PostMethod("http://localhost:9002/movieservice/movielist");RequestEntity entity =new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");post.setRequestEntity(entity);HttpClient httpclient = new HttpClient();try {assertEquals(200, httpclient.executeMethod(post));} catch (Exception e) {fail();} finally {post.releaseConnection();}// 2. find moviesGetMethod get =new GetMethod("http://localhost:9002/movieservice/movies");HttpClient httpclientforlist = new HttpClient();String response = "";try {assertEquals(200, httpclientforlist.executeMethod(get));response = get.getResponseBodyAsString();System.out.println("movies reponse:"+response);} catch (Exception e) {fail();} finally {get.releaseConnection();}JAXBContext jaxbContext =JAXBContext.newInstance("anyframe.sample.movie.restful.httpbinding.jra");Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();Movies movies =(Movies) unmarshaller.unmarshal(new InputSource(new StringReader(response)));// 3. check the new movie informationCollection col = movies.getMovie();Iterator itr = col.iterator();while(itr.hasNext()){Movie movie = (Movie)itr.next();if(movie.getMovieId().equals("005")){assertEquals("Life Is Beautiful", movie.getTitle());assertEquals("Roberto Benigni", movie.getDirector());}else if(movie.getMovieId().equals("006")){assertEquals("Life Is sad", movie.getTitle());assertEquals("no director", movie.getDirector());61

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!