use of org.infinispan.client.rest.RestCacheClient 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.RestCacheClient 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.RestCacheClient in project infinispan by infinispan.
the class CacheResourceV2Test method createDeleteCache.
private void createDeleteCache(String xml) {
RestEntity xmlEntity = RestEntity.create(APPLICATION_XML, xml);
RestCacheClient cacheClient = client.cache("cacheCRUD");
CompletionStage<RestResponse> response = cacheClient.createWithConfiguration(xmlEntity, VOLATILE);
assertThat(response).isOk();
response = cacheClient.stats();
assertThat(response).isOk().hasJson().hasProperty("current_number_of_entries").is(-1);
response = cacheClient.delete();
assertThat(response).isOk();
response = cacheClient.stats();
assertThat(response).isNotFound().hasReturnedText("ISPN012010: Cache with name 'cacheCRUD' not found amongst the configured caches");
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class CacheResourceV2Test method testIndexDataSyncInvalidSchema.
@Test
public void testIndexDataSyncInvalidSchema() {
String notQuiteIndexed = "package schemas;\n" + " /* @Indexed */\n" + " message Entity {\n" + " optional string name=1;\n" + " }";
// Register schema
RestResponse restResponse = join(client.schemas().put("schemas.proto", notQuiteIndexed));
assertThat(restResponse).isOk();
// Create the indexed cache
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.indexing().enable().storage(LOCAL_HEAP).addIndexedEntities("schemas.Entity");
String cacheConfig = cacheConfigToJson("sync-data-index", builder.build());
RestCacheClient cacheClient = client.cache("sync-data-index");
RestEntity config = RestEntity.create(APPLICATION_JSON, cacheConfig);
CompletionStage<RestResponse> response = cacheClient.createWithConfiguration(config);
assertThat(response).isOk();
// Write an entry, it should error
String value = Json.object().set("_type", "schemas.Entity").set("name", "Jun").toString();
RestEntity restEntity = RestEntity.create(APPLICATION_JSON, value);
restResponse = join(cacheClient.put("key", restEntity));
assertThat(restResponse).containsReturnedText("make sure at least one field has the @Field annotation");
// Cache should not have any data
response = cacheClient.size();
assertThat(response).containsReturnedText("0");
}
use of org.infinispan.client.rest.RestCacheClient in project infinispan by infinispan.
the class CacheResourceV2Test method testSourceConnected.
@Test
public void testSourceConnected() {
RestCacheClient cacheClient = client.cache("default");
RestResponse restResponse = join(cacheClient.sourceConnected());
ResponseAssertion.assertThat(restResponse).isNotFound();
}
Aggregations