Search in sources :

Example 21 with RestCacheClient

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\"}");
}
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 22 with RestCacheClient

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\"}");
}
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 23 with RestCacheClient

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");
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 24 with RestCacheClient

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");
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

Example 25 with RestCacheClient

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();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test)

Aggregations

RestCacheClient (org.infinispan.client.rest.RestCacheClient)66 RestResponse (org.infinispan.client.rest.RestResponse)41 Test (org.testng.annotations.Test)34 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)16 RestEntity (org.infinispan.client.rest.RestEntity)14 Json (org.infinispan.commons.dataconversion.internal.Json)13 RestClient (org.infinispan.client.rest.RestClient)11 Test (org.junit.Test)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)7 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)5 TestClass (org.infinispan.rest.TestClass)5 TestUser (org.infinispan.server.test.api.TestUser)5 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 HashMap (java.util.HashMap)2 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)2 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2