Example usage for org.apache.commons.httpclient.methods DeleteMethod getStatusCode

List of usage examples for org.apache.commons.httpclient.methods DeleteMethod getStatusCode

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods DeleteMethod getStatusCode.

Prototype

@Override
public int getStatusCode() 

Source Link

Document

Returns the response status code.

Usage

From source file:terrastore.server.impl.JsonHttpServerTest.java

@Test
public void testRemoveByRangeWithLimit() throws Exception {
    UpdateService updateService = createMock(UpdateService.class);
    QueryService queryService = createMock(QueryService.class);
    BackupService backupService = createMock(BackupService.class);
    StatsService statsService = createMock(StatsService.class);

    Range range = new Range(new Key("aaaa"), new Key("ffff"), 100, "", 0);

    updateService.removeByRange("bucket", range, new Predicate(null));
    expectLastCall().andReturn(new Keys(Collections.EMPTY_SET)).once();

    replay(updateService, queryService, backupService, statsService);

    JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService);

    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(
            "http://localhost:8080/bucket/range?startKey=aaaa&endKey=ffff&limit=100");
    client.executeMethod(method);//w w w  .j a  va  2  s .  com

    assertEquals(HttpStatus.SC_OK, method.getStatusCode());

    method.releaseConnection();

    stopServer(server);

    verify(updateService, queryService, backupService, statsService);
}

From source file:terrastore.server.impl.JsonHttpServerTest.java

@Test
public void testRemoveByRangeWithPredicate() throws Exception {
    UpdateService updateService = createMock(UpdateService.class);
    QueryService queryService = createMock(QueryService.class);
    BackupService backupService = createMock(BackupService.class);
    StatsService statsService = createMock(StatsService.class);

    Range range = new Range(new Key("aaaa"), new Key("ffff"), 100, "", 10000L);

    updateService.removeByRange("bucket", range, new Predicate("condition:some"));
    expectLastCall().andReturn(new Keys(Collections.EMPTY_SET)).once();

    replay(updateService, queryService, backupService, statsService);

    JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService);

    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod(
            "http://localhost:8080/bucket/range?startKey=aaaa&endKey=ffff&limit=100&timeToLive=10000&predicate=condition:some");
    client.executeMethod(method);//w ww.jav a  2s . co  m

    assertEquals(HttpStatus.SC_OK, method.getStatusCode());

    method.releaseConnection();

    stopServer(server);

    verify(updateService, queryService, backupService, statsService);
}

From source file:terrastore.server.impl.JsonHttpServerTest.java

@Test
public void testJsonErrorMessageOnInternalFail() throws Exception {
    UpdateService updateService = createMock(UpdateService.class);
    QueryService queryService = createMock(QueryService.class);
    BackupService backupService = createMock(BackupService.class);
    StatsService statsService = createMock(StatsService.class);

    updateService.removeBucket("bucket");
    expectLastCall().andThrow(new UpdateOperationException(new ErrorMessage(500, "error"))).once();

    replay(updateService, queryService, backupService, statsService);

    JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService);

    HttpClient client = new HttpClient();
    DeleteMethod method = new DeleteMethod("http://localhost:8080/bucket");
    method.setRequestHeader("Content-Type", "application/json");
    client.executeMethod(method);//from  ww w  . jav a2 s  .  c o m

    assertEquals(500, method.getStatusCode());
    assertEquals(toJson(new ErrorMessage(500, "error")), method.getResponseBodyAsString());

    method.releaseConnection();

    stopServer(server);

    verify(updateService, queryService, backupService, statsService);
}