Search in sources :

Example 71 with RestResponse

use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.

the class CacheResourceTest method testReplaceExistingObject.

@Test
public void testReplaceExistingObject() {
    String initialJson = "{\"" + TYPE + "\":\"org.infinispan.rest.TestClass\",\"name\":\"test\"}";
    String changedJson = "{\"" + TYPE + "\":\"org.infinispan.rest.TestClass\",\"name\":\"test2\"}";
    RestResponse response = writeJsonToCache("key", initialJson, "objectCache");
    assertThat(response).isOk();
    response = writeJsonToCache("key", changedJson, "objectCache");
    assertThat(response).isOk();
    response = join(client.cache("objectCache").get("key", APPLICATION_JSON_TYPE));
    Json jsonNode = Json.read(response.getBody());
    assertEquals(jsonNode.at("name").asString(), "test2");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test)

Example 72 with RestResponse

use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.

the class CacheResourceTest method shouldConvertExistingSerializableObjectToJson.

@Test
public void shouldConvertExistingSerializableObjectToJson() {
    // given
    TestClass testClass = new TestClass();
    testClass.setName("test");
    RestCacheClient objectCache = client.cache("objectCache");
    join(objectCache.put("test", RestEntity.create(APPLICATION_JSON, testClass.toJson().toString())));
    // when
    CompletionStage<RestResponse> response = objectCache.get("test", APPLICATION_JSON_TYPE);
    // then
    assertThat(response).isOk();
    assertThat(response).hasContentType("application/json");
    assertThat(response).hasReturnedText("{\"" + TYPE + "\":\"" + TestClass.class.getName() + "\",\"name\":\"test\"}");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestClass(org.infinispan.rest.TestClass) Test(org.testng.annotations.Test)

Example 73 with RestResponse

use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.

the class CacheResourceTest method shouldReadAsJsonWithPojoCache.

@Test
public void shouldReadAsJsonWithPojoCache() {
    // given
    TestClass testClass = new TestClass();
    testClass.setName("test");
    RestCacheClient pojoCache = client.cache("pojoCache");
    join(pojoCache.put("test", RestEntity.create(APPLICATION_JSON, testClass.toJson().toString())));
    // when
    CompletionStage<RestResponse> response = pojoCache.get("test", APPLICATION_JSON_TYPE);
    // then
    assertThat(response).isOk();
    assertThat(response).hasContentType(APPLICATION_JSON_TYPE);
    assertThat(response).hasReturnedText("{\"" + TYPE + "\":\"org.infinispan.rest.TestClass\",\"name\":\"test\"}");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestClass(org.infinispan.rest.TestClass) Test(org.testng.annotations.Test)

Example 74 with RestResponse

use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.

the class CacheResourceTest method testCompression.

@Test
public void testCompression() throws Exception {
    String payload = getResourceAsString("person.proto", getClass().getClassLoader());
    putStringValueInCache("default", "k", payload);
    String path = String.format("/rest/v2/caches/%s/%s", "default", "k");
    RestResponse response = join(client.raw().get(path, singletonMap(ACCEPT_ENCODING.toString(), "none")));
    assertThat(response).hasNoContentEncoding();
    assertThat(response).hasContentLength(payload.getBytes().length);
    response = join(client.raw().get(path, singletonMap(ACCEPT_ENCODING.toString(), "gzip")));
    assertThat(response).hasGzipContentEncoding();
    assertEquals(decompress(response.getBodyAsByteArray()), payload);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

Example 75 with RestResponse

use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.

the class CacheResourceV2Test method testCacheFullDetail.

@Test
public void testCacheFullDetail() {
    RestResponse response = join(client.cache("default").details());
    Json document = Json.read(response.getBody());
    assertThat(response).isOk();
    assertThat(document.at("stats")).isNotNull();
    assertThat(document.at("size")).isNotNull();
    assertThat(document.at("configuration")).isNotNull();
    assertThat(document.at("rehash_in_progress")).isNotNull();
    assertThat(document.at("persistent")).isNotNull();
    assertThat(document.at("bounded")).isNotNull();
    assertThat(document.at("indexed")).isNotNull();
    assertThat(document.at("has_remote_backup")).isNotNull();
    assertThat(document.at("secured")).isNotNull();
    assertThat(document.at("indexing_in_progress")).isNotNull();
    assertThat(document.at("queryable")).isNotNull();
    assertThat(document.at("rebalancing_enabled")).isNotNull();
    assertThat(document.at("key_storage").asString()).isEqualTo("application/unknown");
    assertThat(document.at("value_storage").asString()).isEqualTo("application/unknown");
    response = join(client.cache("proto").details());
    document = Json.read(response.getBody());
    assertThat(document.at("key_storage").asString()).isEqualTo("application/x-protostream");
    assertThat(document.at("value_storage").asString()).isEqualTo("application/x-protostream");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test)

Aggregations

RestResponse (org.infinispan.client.rest.RestResponse)233 Test (org.testng.annotations.Test)108 Json (org.infinispan.commons.dataconversion.internal.Json)52 RestCacheClient (org.infinispan.client.rest.RestCacheClient)42 Test (org.junit.Test)41 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)39 RestClient (org.infinispan.client.rest.RestClient)37 RestEntity (org.infinispan.client.rest.RestEntity)36 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)23 HashMap (java.util.HashMap)8 RestCounterClient (org.infinispan.client.rest.RestCounterClient)8 TestClass (org.infinispan.rest.TestClass)8 RestSchemaClient (org.infinispan.client.rest.RestSchemaClient)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)6 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)6 Cache (org.infinispan.Cache)5 RestRawClient (org.infinispan.client.rest.RestRawClient)5 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)5