Package com.cloudburo.servlet

Examples of com.cloudburo.servlet.GsonWrapper


      Customer customerIn = new Customer();
      customerIn.name = "Felix";
      customerIn.address = "Kuestahler";
      customerIn.date = new Date();
      customerIn.date1 = new LocalDateTime();
      String customerInJSON = (new GsonWrapper()).getGson().toJson(customerIn);
     
      logger.log(Level.INFO, "Going to persist {0}", customerInJSON);
      StringWriter stringWriter = new StringWriter();
     
      // TEST: Check the persistence operations "POST"
      when(request.getReader()).thenReturn(new BufferedReader(new StringReader(customerInJSON)));
      when(response.getWriter()).thenReturn(new PrintWriter(stringWriter));
     
      customerServlet.doPost(request, response);

      Customer customerOut =  (new GsonWrapper()).getGson().fromJson(stringWriter.toString(), Customer.class);
      assertEquals("Checking name", customerOut.name, customerIn.name);
      assertEquals("Checking id", customerOut._id > 0,true);
     
      // TEST: Check the retrieval of the collections "GET"
      stringWriter = new StringWriter();
      when(request.getReader()).thenReturn(new BufferedReader(new StringReader("")));
      when(response.getWriter()).thenReturn(new PrintWriter(stringWriter));
     
      customerServlet.doGet(request, response);
     
      // Expect an array with the last entry must be a meta data record (with a attribute _cursor)
      JsonArray array = (new JsonParser()).parse(stringWriter.toString()).getAsJsonArray();
      assertEquals("Checking received numbers of JSON Elements", 2,array.size());
      JsonObject elem  = array.get(array.size()-1).getAsJsonObject();
      assertEquals("Checking that there is a 'cursor' elemen",elem.get("_cursor").getAsString().equals(""),true);

      // TEST: Check the retrieval of a single entry "GET"
      stringWriter = new StringWriter();
      when(request.getPathInfo()).thenReturn("/"+customerOut._id);
      when(response.getWriter()).thenReturn(new PrintWriter(stringWriter));
     
      customerServlet.doGet(request, response);
     
      // Expect a single entry which can be converted in our domain object and correct attributes
      customerOut =  (new GsonWrapper()).getGson().fromJson(stringWriter.toString(), Customer.class);
      assertEquals("Checking Name", customerOut.name, customerIn.name);
      assertEquals("Checking Surname", customerOut.surname, customerIn.surname);
     
      // TEST: Going to delete the entry "DELETE"
      stringWriter = new StringWriter();
View Full Code Here

TOP

Related Classes of com.cloudburo.servlet.GsonWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.