Ejemplo n.º 1
0
  @Test
  public void testArticlePublish() {
    String result;
    JSONObject respJson;

    // for no token and no comment no image
    response.resetBuffer();
    request.setParam("data", buildInvalidData("article-publish"));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.REQUEST_PARAMETER_NOT_STISFIED, respJson.getInt("ret"));

    // register
    response.resetBuffer();
    request.setParam("data", buildNormalRegister("12346", "12346"));
    userService.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertTrue(respJson.has("user"));
    assertTrue(respJson.has("token"));

    String token = respJson.getString("token");

    // for with comment and no image
    response.resetBuffer();
    request.setParam("data", buildNormalDataWithoutPic("article-publish", "eeeee", token));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));

    // for with comment and no image
    response.resetBuffer();
    request.setParam("data", buildNormalDataWithoutPic("article-publish", "eeeee", token));
    request.addPart(new LocalPart("/home/jiangzhen/Pictures/b.png"));
    request.addPart(new LocalPart("/home/jiangzhen/Pictures/b1.png"));
    request.addPart(new LocalPart("/home/jiangzhen/Pictures/c.png"));

    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    System.out.println(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
  }
Ejemplo n.º 2
0
  @Test
  public void testArticleComment() {
    String result;
    JSONObject respJson;

    // register
    response.resetBuffer();
    request.setParam("data", buildNormalRegister("12345", "12345"));
    userService.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertTrue(respJson.has("user"));
    assertTrue(respJson.has("token"));

    String token = respJson.getString("token");

    // register
    response.resetBuffer();
    request.setParam("data", buildNormalRegister("17", "27"));
    userService.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertTrue(respJson.has("user"));
    assertTrue(respJson.has("token"));

    String token1 = respJson.getString("token");

    // register
    response.resetBuffer();
    request.setParam("data", buildNormalRegister("178", "278"));
    userService.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertTrue(respJson.has("user"));
    assertTrue(respJson.has("token"));

    String token2 = respJson.getString("token");

    // for with comment and no image
    response.resetBuffer();
    System.out.println(buildNormalDataWithoutPic("article-publish", "eeeee", token));
    request.setParam("data", buildNormalDataWithoutPic("article-publish", "eeeee", token));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    long arid = respJson.getJSONObject("article").getLong("id");

    response.resetBuffer();
    System.out.println(buildNormalDataForComment(token1, arid, "eee"));
    request.setParam("data", buildNormalDataForComment(token1, arid, "eee"));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    System.out.println(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertEquals(1, respJson.getJSONObject("article").getJSONArray("comments").length());

    response.resetBuffer();
    request.setParam("data", buildNormalDataForComment(token2, arid, "eee"));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    System.out.println(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertEquals(2, respJson.getJSONObject("article").getJSONArray("comments").length());
  }
Ejemplo n.º 3
0
  @Test
  public void testArticleQuery() {
    String result;
    JSONObject respJson;

    // for no token and no comment no image
    response.resetBuffer();
    request.setParam("data", buildInvalidData("article-publish"));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.REQUEST_PARAMETER_NOT_STISFIED, respJson.getInt("ret"));

    // register
    response.resetBuffer();
    request.setParam("data", buildNormalRegister("aaaaa", "aa"));
    userService.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertTrue(respJson.has("user"));
    assertTrue(respJson.has("token"));

    String token = respJson.getString("token");

    // for with comment and no image
    response.resetBuffer();
    request.setParam("data", buildNormalDataWithoutPic("article-publish", "eeeee", token));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));

    // for with comment and no image
    response.resetBuffer();
    request.setParam("data", buildNormalDataWithoutPic("article-publish", "eeeee", token));
    request.addPart(new LocalPart("/home/jiangzhen/Pictures/b.png"));
    request.addPart(new LocalPart("/home/jiangzhen/Pictures/b1.png"));
    request.addPart(new LocalPart("/home/jiangzhen/Pictures/c.png"));

    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    System.out.println(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    long arid = respJson.getJSONObject("article").getLong("id");

    response.resetBuffer();
    request.setParam("data", buildNormalDataForComment(token, arid, "eee"));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    System.out.println(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertEquals(1, respJson.getJSONObject("article").getJSONArray("comments").length());

    response.resetBuffer();
    request.setParam("data", buildNormalDataForComment(token, arid, "eee"));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    System.out.println(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertEquals(2, respJson.getJSONObject("article").getJSONArray("comments").length());

    response.resetBuffer();
    request.setParam("data", buildNormalDataForRecommend(token, arid, true));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    System.out.println(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertEquals(1, respJson.getJSONObject("article").getJSONArray("recommends").length());

    // for  query
    response.resetBuffer();
    request.setParam("data", buildNormalArticleQuery(token));

    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    System.out.println(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertTrue(respJson.getInt("articles_count") >= 2);
    assertTrue(respJson.getJSONArray("articles").length() >= 2);
  }
Ejemplo n.º 4
0
  @Test
  public void testArticleRecomment() {
    String result;
    JSONObject respJson;

    // register
    response.resetBuffer();
    request.setParam("data", buildNormalRegister("1234", "1234"));
    userService.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertTrue(respJson.has("user"));
    assertTrue(respJson.has("token"));

    String token = respJson.getString("token");

    // register
    response.resetBuffer();
    request.setParam("data", buildNormalRegister("1", "2"));
    userService.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertTrue(respJson.has("user"));
    assertTrue(respJson.has("token"));

    String token1 = respJson.getString("token");

    // for with comment and no image
    response.resetBuffer();
    request.setParam("data", buildNormalDataWithoutPic("article-publish", "eeeee", token));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    long arid = respJson.getJSONObject("article").getLong("id");

    response.resetBuffer();
    request.setParam("data", buildDataForRecommendWithInvalidToken());
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    assertEquals(APICode.TOKEN_INVALID, respJson.getInt("ret"));

    response.resetBuffer();
    System.out.println(buildNormalDataForRecommend(token1, arid, true));
    request.setParam("data", buildNormalDataForRecommend(token1, arid, true));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    System.out.println(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertEquals(1, respJson.getJSONObject("article").getJSONArray("recommends").length());

    response.resetBuffer();
    request.setParam("data", buildNormalDataForRecommend(token1, arid, false));
    service.service(request, response);
    result = response.getFlusedBuffer();
    respJson = parse(result);
    System.out.println(result);
    assertEquals(APICode.SUCCESS, respJson.getInt("ret"));
    assertEquals(0, respJson.getJSONObject("article").getJSONArray("recommends").length());
  }