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");
}
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\"}");
}
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\"}");
}
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);
}
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");
}
Aggregations