Exemplo n.º 1
0
  @Test(timeOut = 5000)
  public void postJson() {
    server.expect(
        Condition.when("POST").respond("{\"id\":\"ABCDEFG\"}", ContentType.APPLICATION_JSON));

    Card in = new Card("Hello", "world", "0989080");

    Member out = Post(baseUrl + "/").bean(in).as(APPLICATION_JSON).map(Member.class);
    Assert.assertEquals(out.id, "ABCDEFG");

    out = Post(baseUrl + "/", APPLICATION_JSON).bean(in).map(Member.class);
    Assert.assertEquals(out.id, "ABCDEFG");
  }
Exemplo n.º 2
0
  @Test(timeOut = 5000)
  public void postUrlEncoded() throws ParseException, IOException {
    server.expect(
        Condition.when("POST").respond("{\"id\":\"ABCDEFG\"}", ContentType.APPLICATION_JSON));

    Card in = new Card("Hello", "world", "0989080");

    HttpPost req = (HttpPost) Post(baseUrl).bean(in).build();
    Assert.assertEquals(
        EntityUtils.toString(req.getEntity()), "name=Hello&desc=world&idList=0989080");

    Member out = Post(baseUrl + "/").bean(in).map(Member.class);
    Assert.assertEquals(out.id, "ABCDEFG");
  }
Exemplo n.º 3
0
  @Test(timeOut = 5000)
  public void postJsonBackXml() {
    server.expect(
        Condition.when("POST").respond("<xml><id>ABCDEFG</id></xml>", ContentType.APPLICATION_XML));

    Card in = new Card("Hello", "world", "0989080");

    Member out =
        Post(baseUrl + "/").bean(in).as(APPLICATION_JSON).map(Member.class, new BasicHttpContext());
    Assert.assertEquals(out.id, "ABCDEFG");

    out = Post(baseUrl + "/", APPLICATION_JSON).bean(in).map(Member.class);
    Assert.assertEquals(out.id, "ABCDEFG");
  }