Search in sources :

Example 81 with RestResponse

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

the class CacheResourceV2Test method createAndWriteToCache.

private void createAndWriteToCache(String name, Configuration configuration) {
    String jsonConfig = cacheConfigToJson(name, configuration);
    RestEntity configEntity = RestEntity.create(APPLICATION_JSON, jsonConfig);
    CompletionStage<RestResponse> response = client.cache(name).createWithConfiguration(configEntity);
    assertThat(response).isOk();
    RestEntity valueEntity = RestEntity.create(APPLICATION_JSON, "{\"_type\":\"Simple\",\"value\":1}");
    response = client.cache(name).post("1", valueEntity);
    assertThat(response).isOk();
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString)

Example 82 with RestResponse

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

the class CacheResourceV2Test method createCache.

private RestCacheClient createCache(RestClient c, String json, String name) {
    RestEntity jsonEntity = RestEntity.create(APPLICATION_JSON, json);
    RestCacheClient cache = c.cache(name);
    CompletionStage<RestResponse> response = cache.createWithConfiguration(jsonEntity);
    assertThat(response).isOk();
    return cache;
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 83 with RestResponse

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

the class CacheResourceV2Test method createCache.

private void createCache(String cacheName, MediaType mediaType) {
    RestCacheClient cacheClient = client.cache(cacheName);
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.clustering().cacheMode(CacheMode.DIST_SYNC);
    if (mediaType != null)
        builder.encoding().mediaType(mediaType.toString());
    String jsonConfig = cacheConfigToJson(cacheName, builder.build());
    RestEntity cacheConfig = RestEntity.create(APPLICATION_JSON, jsonConfig);
    RestResponse response = join(cacheClient.createWithConfiguration(cacheConfig));
    assertThat(response).isOk();
}
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)

Example 84 with RestResponse

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

the class CacheResourceV2Test method testCacheV2KeyOps.

@Test
public void testCacheV2KeyOps() {
    RestCacheClient cacheClient = client.cache("default");
    RestResponse response = join(cacheClient.post("key", "value"));
    assertThat(response).isOk();
    response = join(cacheClient.post("key", "value"));
    assertThat(response).isConflicted().hasReturnedText("An entry already exists");
    response = join(cacheClient.put("key", "value-new"));
    assertThat(response).isOk();
    response = join(cacheClient.get("key"));
    assertThat(response).hasReturnedText("value-new");
    response = join(cacheClient.head("key"));
    assertThat(response).isOk();
    assertThat(response).hasNoContent();
    response = join(cacheClient.remove("key"));
    assertThat(response).isOk();
    response = join(cacheClient.get("key"));
    assertThat(response).isNotFound();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test)

Example 85 with RestResponse

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

the class CacheResourceV2Test method assertIndex.

private void assertIndex(int value, boolean present) {
    String query = "FROM Entity WHERE value = " + value;
    RestResponse response = join(client.cache("indexedCache").query(query));
    assertThat(response).isOk();
    assertEquals(present, response.getBody().contains(String.valueOf(value)));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString)

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