Example usage for org.apache.commons.httpclient.methods PutMethod setRequestEntity

List of usage examples for org.apache.commons.httpclient.methods PutMethod setRequestEntity

Introduction

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

Prototype

public void setRequestEntity(RequestEntity paramRequestEntity) 

Source Link

Usage

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testPutValueAndConditionallyPutAgainWithSuccess() throws Exception {
    String bucket = UUID.randomUUID().toString();

    TestValue value = new TestValue("value1", 1);
    PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();// w  ww .j a  v  a  2  s .com

    TestValue newValue = new TestValue("value2", 1);
    PutMethod conditionallyPutValue = makePutMethodWithPredicate(NODE1_PORT, bucket + "/value",
            "jxpath:/stringField[.='value1']");
    conditionallyPutValue
            .setRequestEntity(new StringRequestEntity(fromObjectToJson(newValue), "application/json", null));
    HTTP_CLIENT.executeMethod(conditionallyPutValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, conditionallyPutValue.getStatusCode());
    conditionallyPutValue.releaseConnection();

    GetMethod getValue = makeGetMethod(NODE2_PORT, bucket + "/value");
    HTTP_CLIENT.executeMethod(getValue);
    assertEquals(HttpStatus.SC_OK, getValue.getStatusCode());
    TestValue returned = fromJsonToObject(getValue.getResponseBodyAsString());
    assertEquals(newValue, returned);
    getValue.releaseConnection();
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testPutValueAndConditionallyPutAgainWithConflict() throws Exception {
    String bucket = UUID.randomUUID().toString();

    TestValue value = new TestValue("value1", 1);
    PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();/*ww w  . ja va2s  .  c o m*/

    TestValue newValue = new TestValue("value2", 1);
    PutMethod conditionallyPutValue = makePutMethodWithPredicate(NODE1_PORT, bucket + "/value",
            "jxpath:/stringField[.='wrong']");
    conditionallyPutValue
            .setRequestEntity(new StringRequestEntity(fromObjectToJson(newValue), "application/json", null));
    HTTP_CLIENT.executeMethod(conditionallyPutValue);
    assertEquals(HttpStatus.SC_CONFLICT, conditionallyPutValue.getStatusCode());
    conditionallyPutValue.releaseConnection();

    GetMethod getValue = makeGetMethod(NODE2_PORT, bucket + "/value");
    HTTP_CLIENT.executeMethod(getValue);
    assertEquals(HttpStatus.SC_OK, getValue.getStatusCode());
    TestValue returned = fromJsonToObject(getValue.getResponseBodyAsString());
    assertEquals(value, returned);
    getValue.releaseConnection();
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testPutValueAndDeleteValueAndBucketOnOtherNode() throws Exception {
    String bucket = UUID.randomUUID().toString();

    TestValue value = new TestValue("value", 1);
    PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();//from   w ww.  j  a  v  a2  s.co  m

    DeleteMethod deleteValue = makeDeleteMethod(NODE2_PORT, bucket + "/value");
    HTTP_CLIENT.executeMethod(deleteValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, deleteValue.getStatusCode());
    deleteValue.releaseConnection();

    DeleteMethod deleteBucket = makeDeleteMethod(NODE2_PORT, bucket);
    HTTP_CLIENT.executeMethod(deleteBucket);
    assertEquals(HttpStatus.SC_NO_CONTENT, deleteBucket.getStatusCode());
    deleteBucket.releaseConnection();
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testDeleteValueIsIdempotent() throws Exception {
    String bucket = UUID.randomUUID().toString();

    TestValue value = new TestValue("value", 1);
    PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value");
    putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
    HTTP_CLIENT.executeMethod(putValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
    putValue.releaseConnection();/*from   w w w . ja  va2 s  . c  o m*/

    DeleteMethod deleteValue = makeDeleteMethod(NODE2_PORT, bucket + "/value");
    HTTP_CLIENT.executeMethod(deleteValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, deleteValue.getStatusCode());
    deleteValue.releaseConnection();
    HTTP_CLIENT.executeMethod(deleteValue);
    assertEquals(HttpStatus.SC_NO_CONTENT, deleteValue.getStatusCode());
    deleteValue.releaseConnection();
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testGetAllValuesWithNoLimit() throws Exception {
    String bucket = UUID.randomUUID().toString();

    int size = 10;

    for (int i = 1; i <= size; i++) {
        TestValue value = new TestValue("value" + i, i);
        PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i));
        putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
        HTTP_CLIENT.executeMethod(putValue);
        assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
        putValue.releaseConnection();//  w ww . jav a 2 s .  c o m
    }

    // Sleep to wait for terracotta broadcasting keys:
    Thread.sleep(1000);

    GetMethod getAllValues = makeGetMethod(NODE2_PORT, bucket);
    HTTP_CLIENT.executeMethod(getAllValues);
    assertEquals(HttpStatus.SC_OK, getAllValues.getStatusCode());
    Map<String, Object> allValues = fromJsonToMap(getAllValues.getResponseBodyAsString());
    System.err.println(getAllValues.getResponseBodyAsString());
    getAllValues.releaseConnection();
    assertEquals(size, allValues.size());
    for (int i = 1; i <= size; i++) {
        assertTrue(allValues.containsKey("value" + (char) ('a' + i)));
    }
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testGetAllValuesWithLimit() throws Exception {
    String bucket = UUID.randomUUID().toString();

    int size = 10;

    for (int i = 1; i <= size; i++) {
        TestValue value = new TestValue("value" + i, i);
        PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i));
        putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
        HTTP_CLIENT.executeMethod(putValue);
        assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
        putValue.releaseConnection();//from   w  ww.  ja  v a 2  s.  c o m
    }

    // Sleep to wait for terracotta broadcasting keys:
    Thread.sleep(1000);

    int limit = 5;
    GetMethod getAllValues = makeGetMethodWithLimit(NODE2_PORT, bucket, limit);
    HTTP_CLIENT.executeMethod(getAllValues);
    assertEquals(HttpStatus.SC_OK, getAllValues.getStatusCode());
    Map<String, Object> allValues = fromJsonToMap(getAllValues.getResponseBodyAsString());
    System.err.println(getAllValues.getResponseBodyAsString());
    getAllValues.releaseConnection();
    assertEquals(limit, allValues.size());
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testRangeQueryWithDefaultComparator() throws Exception {
    String bucket = UUID.randomUUID().toString();

    int size = 10;

    for (int i = 1; i <= size; i++) {
        TestValue value = new TestValue("value" + i, i);
        PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i));
        putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
        HTTP_CLIENT.executeMethod(putValue);
        assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
        putValue.releaseConnection();/*ww w  .  j a v  a2s.c  o  m*/
    }

    // Sleep to wait for terracotta broadcasting keys:
    Thread.sleep(1000);

    GetMethod doRangeQuery = makeGetMethodWithRange(NODE2_PORT, bucket + "/range", "valueb", "valued");
    HTTP_CLIENT.executeMethod(doRangeQuery);
    assertEquals(HttpStatus.SC_OK, doRangeQuery.getStatusCode());
    Map<String, Object> values = fromJsonToMap(doRangeQuery.getResponseBodyAsString());
    System.err.println(doRangeQuery.getResponseBodyAsString());
    doRangeQuery.releaseConnection();
    assertEquals(3, values.size());
    assertEquals("valueb", values.keySet().toArray()[0]);
    assertEquals("valuec", values.keySet().toArray()[1]);
    assertEquals("valued", values.keySet().toArray()[2]);
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testRangeQueryWithStringKeys() throws Exception {
    String bucket = UUID.randomUUID().toString();

    int size = 10;

    for (int i = 1; i <= size; i++) {
        TestValue value = new TestValue("value" + i, i);
        PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i));
        putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
        HTTP_CLIENT.executeMethod(putValue);
        assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
        putValue.releaseConnection();//from  w w  w  . ja  v a2  s.  c o  m
    }

    // Sleep to wait for terracotta broadcasting keys:
    Thread.sleep(1000);

    GetMethod doRangeQuery = makeGetMethodWithRange(NODE2_PORT, bucket + "/range", "valueb", "valued",
            "lexical-asc");
    HTTP_CLIENT.executeMethod(doRangeQuery);
    assertEquals(HttpStatus.SC_OK, doRangeQuery.getStatusCode());
    Map<String, Object> values = fromJsonToMap(doRangeQuery.getResponseBodyAsString());
    System.err.println(doRangeQuery.getResponseBodyAsString());
    doRangeQuery.releaseConnection();
    assertEquals(3, values.size());
    assertEquals("valueb", values.keySet().toArray()[0]);
    assertEquals("valuec", values.keySet().toArray()[1]);
    assertEquals("valued", values.keySet().toArray()[2]);
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testRangeQueryWithNumberKeys() throws Exception {
    String bucket = UUID.randomUUID().toString();

    int size = 10;

    for (int i = 1; i <= size; i++) {
        TestValue value = new TestValue("" + i, i);
        PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/" + i);
        putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
        HTTP_CLIENT.executeMethod(putValue);
        assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
        putValue.releaseConnection();/*  w  w  w  .  j  a v  a 2  s.  c om*/
    }

    // Sleep to wait for terracotta broadcasting keys:
    Thread.sleep(1000);

    GetMethod doRangeQuery = makeGetMethodWithRange(NODE2_PORT, bucket + "/range", "1", "10", "numeric-asc");
    HTTP_CLIENT.executeMethod(doRangeQuery);
    assertEquals(HttpStatus.SC_OK, doRangeQuery.getStatusCode());
    Map<String, Object> values = fromJsonToMap(doRangeQuery.getResponseBodyAsString());
    System.err.println(doRangeQuery.getResponseBodyAsString());
    doRangeQuery.releaseConnection();
    assertEquals(10, values.size());
    assertEquals("1", values.keySet().toArray()[0]);
    assertEquals("10", values.keySet().toArray()[9]);
}

From source file:terrastore.integration.IntegrationTest.java

@Test
public void testRangeQueryWithLimit() throws Exception {
    String bucket = UUID.randomUUID().toString();

    int size = 10;

    for (int i = 1; i <= size; i++) {
        TestValue value = new TestValue("value" + i, i);
        PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i));
        putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null));
        HTTP_CLIENT.executeMethod(putValue);
        assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode());
        putValue.releaseConnection();//from  w ww  .j  a  v  a2 s .c  om
    }

    // Sleep to wait for terracotta broadcasting keys:
    Thread.sleep(1000);

    GetMethod doRangeQuery = makeGetMethodWithRange(NODE2_PORT, bucket + "/range", "valueb", "valued", 2,
            "lexical-asc");
    HTTP_CLIENT.executeMethod(doRangeQuery);
    assertEquals(HttpStatus.SC_OK, doRangeQuery.getStatusCode());
    Map<String, Object> values = fromJsonToMap(doRangeQuery.getResponseBodyAsString());
    System.err.println(doRangeQuery.getResponseBodyAsString());
    doRangeQuery.releaseConnection();
    assertEquals(2, values.size());
    assertEquals("valueb", values.keySet().toArray()[0]);
    assertEquals("valuec", values.keySet().toArray()[1]);
}