Search in sources :

Example 6 with RestEntity

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

the class AbstractRestResourceTest method putBinaryValueInCache.

void putBinaryValueInCache(String cacheName, String key, byte[] value, MediaType mediaType) {
    RestEntity restEntity = RestEntity.create(mediaType, value);
    CompletionStage<RestResponse> response = client.cache(cacheName).put(key, restEntity);
    ResponseAssertion.assertThat(response).isOk();
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse)

Example 7 with RestEntity

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

the class BaseCacheResourceTest method shouldConflictWhenTryingToReplaceExistingEntryUsingPost.

@Test
public void shouldConflictWhenTryingToReplaceExistingEntryUsingPost() throws Exception {
    // given
    putStringValueInCache("default", "test", "test");
    // when
    RestEntity restEntity = RestEntity.create(MediaType.fromString("text/plain;charset=UTF-8"), "Hey!");
    CompletionStage<RestResponse> response = client.cache("default").post("test", restEntity);
    // then
    ResponseAssertion.assertThat(response).isConflicted();
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) Test(org.testng.annotations.Test)

Example 8 with RestEntity

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

the class BaseCacheResourceTest method putInCache.

private void putInCache(String cacheName, Object key, String keyContentType, String value, String contentType) {
    RestEntity entity = RestEntity.create(MediaType.fromString(contentType), value);
    CompletionStage<RestResponse> response = client.cache(cacheName).put(key.toString(), keyContentType, entity);
    ResponseAssertion.assertThat(response).isOk();
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse)

Example 9 with RestEntity

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

the class BaseCacheResourceTest method shouldPutTextValueInCache.

@Test
public void shouldPutTextValueInCache() {
    // when
    RestEntity restEntity = RestEntity.create(MediaType.fromString("text/plain;charset=UTF-8"), "Hey!");
    CompletionStage<RestResponse> response = client.cache("default").post("test", restEntity);
    ResponseAssertion.assertThat(response).isOk();
    RestResponse getResponse = join(client.cache("default").get("test"));
    // then
    ResponseAssertion.assertThat(getResponse).isOk();
    ResponseAssertion.assertThat(getResponse).hasEtag();
    Assertions.assertThat(getResponse.getBody()).isEqualTo("Hey!");
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) Test(org.testng.annotations.Test)

Example 10 with RestEntity

use of org.infinispan.client.rest.RestEntity 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)

Aggregations

RestEntity (org.infinispan.client.rest.RestEntity)38 RestResponse (org.infinispan.client.rest.RestResponse)35 RestCacheClient (org.infinispan.client.rest.RestCacheClient)14 Test (org.testng.annotations.Test)14 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)11 Json (org.infinispan.commons.dataconversion.internal.Json)5 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)5 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)4 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)4 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 MediaType (org.infinispan.commons.dataconversion.MediaType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashMap (java.util.HashMap)1 Cache (org.infinispan.Cache)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1 RestClient (org.infinispan.client.rest.RestClient)1