예제 #1
0
  public void testcreateblog2() {
    System.out.println("Test Case to Create a Blog");
    Resource resource1 = client.resource(url);
    System.out.println("URL: " + url);
    JSONObject sendobject = new JSONObject();
    try {
      sendobject.put("subject", "sjsu_cmpe202");
      sendobject.put("description", "XML");
      sendobject.put("userid", "Shaunak");
      sendobject.put("timestamp", "11:53");

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    String jsonStringObj = sendobject.toString();
    System.out.println("Create : " + jsonStringObj);
    ClientResponse created =
        resource1
            .contentType(MediaType.APPLICATION_JSON)
            .accept(MediaType.APPLICATION_JSON)
            .post(jsonStringObj);
    System.out.println(created.getStatusCode());
    System.out.println(created.getEntity(String.class));
  }
  /**
   * Gets the json.
   *
   * @param AssignedToUser the assigned to user
   * @param subjectId the subject id
   * @param tittle the tittle
   * @param content the content
   * @return the json
   * @throws Exception the exception
   */
  private String getJSON(String AssignedToUser, String subjectId, String tittle, String content)
      throws Exception {

    JSONObject json1 = new JSONObject();

    json1.put("subjectId", subjectId);
    json1.put("assignedUserId", AssignedToUser);
    json1.put("title", tittle);
    JSONArray parameter = new JSONArray();
    parameter.add(json1);
    parameter.add(content);

    JSONObject json = new JSONObject();
    json.put("parameters", parameter);

    return json.toString();
  }
 /**
  * Writes the JSON object to file and calls the parseJSON method in the jsonGroupParser object for
  * testing.
  *
  * @throws IOException
  * @throws AdeException
  */
 public void writeToFileAndParseJSON() throws IOException, AdeException {
   fileWriter.write(jsonGroupObject.toString());
   fileWriter.flush();
   jsonGroupParser.parseJSON(jsonFile);
 }