Beispiel #1
0
 @Test
 public void shouldBeAbleToConvertToHTTPProtocolString() throws Exception {
   Response response = new Response(200, "OK");
   response.setBody("This is the body");
   String HTTPString = response.toString();
   String expected = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nThis is the body";
   assertEquals(expected, HTTPString);
 }
  public Response[] createTwoDocumentsInRemoteDb(CouchClientWrapper db) {
    Bar bar1 = new Bar();
    Response res1 = db.create(bar1);
    Assert.assertNotNull(res1);

    Bar bar2 = new Bar();
    Response res2 = db.create(bar2);
    bar2 = db.get(Bar.class, res2.getId());

    Response res3 = db.update(bar2.getId(), bar2);
    Assert.assertNotNull(res3);
    return new Response[] {res1, res2};
  }
 @Test
 public void accessAndUpdateRemoteDbWithSlashInName() throws Exception {
   // do a little set up for this specific test
   CouchConfig config = super.getCouchConfig("myslash%2Fencoded_db");
   remoteDb =
       new CouchClientWrapper(
           config.getRootUri(), config.getRequestInterceptors(), config.getResponseInterceptors());
   CouchClientWrapperDbUtils.deleteDbQuietly(remoteDb);
   remoteDb.createDatabase();
   Bar bar1 = new Bar();
   Response res1 = remoteDb.create(bar1);
   Assert.assertNotNull(res1);
   Assert.assertTrue(res1.getOk());
 }
  public Response[] createDocAndUpdateTwoTimes(CouchClientWrapper db) {
    Response res1 = db.create(new Bar());
    Bar bar1 = db.get(Bar.class, res1.getId());

    Response res2 = db.update(bar1.getId(), bar1);
    Assert.assertNotNull(res2);
    Assert.assertEquals(res1.getId(), res2.getId());
    Bar bar2 = db.get(Bar.class, res1.getId());

    Response res3 = db.update(bar2.getId(), bar2);
    Assert.assertEquals(res1.getId(), res3.getId());
    Bar bar3 = db.get(Bar.class, res1.getId());
    Assert.assertNotNull(bar3);
    return new Response[] {res1, res2, res3};
  }
Beispiel #5
0
 @Test
 public void shouldBeAbleToChangeTheHeaderForResponse() throws Exception {
   Response response = new Response(200, "OK");
   response.setHeader("Connection", "keep-alive");
   response.setHeader("foo", "bar");
   assertEquals("keep-alive", response.getHeader("Connection"));
   assertEquals("bar", response.getHeader("foo"));
   assertEquals("foo: bar\nConnection: keep-alive", response.toHTTPHeaderString());
 }
Beispiel #6
0
 @Test
 public void redirectShouldHaveFullLocationHeader() {
   Response res = Response.redirectTo("/somepath");
   assertThat(res.getHeader("Location"), equalTo("http://test.host:8080/somepath"));
 }
  public Response[] createDocUpdateTwoTimesThenDelete(CouchClientWrapper remoteDb) {
    Response res1 = remoteDb.create(new Bar());
    Bar bar1 = remoteDb.get(Bar.class, res1.getId());

    Response res2 = remoteDb.update(bar1.getId(), bar1);
    Assert.assertNotNull(res2);
    Assert.assertEquals(res1.getId(), res2.getId());
    Bar bar2 = remoteDb.get(Bar.class, res1.getId());

    Response res3 = remoteDb.update(bar2.getId(), bar2);
    Assert.assertEquals(res1.getId(), res3.getId());
    Bar bar3 = remoteDb.get(Bar.class, res1.getId());
    Assert.assertNotNull(bar3);

    Response res4 = remoteDb.delete(bar3.getId(), bar3.getRevision());
    Assert.assertEquals(res1.getId(), res4.getId());
    try {
      Bar bar4 = remoteDb.get(Bar.class, res1.getId());
      Assert.fail();
    } catch (NoResourceException e) {
    }
    return new Response[] {res1, res2, res3, res4};
  }