Search in sources :

Example 51 with RestResponse

use of org.infinispan.client.rest.RestResponse 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 52 with RestResponse

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

the class BaseCacheResourceTest method shouldPutImmortalEntryWithZeroTtlAndIdleTime.

@Test
public void shouldPutImmortalEntryWithZeroTtlAndIdleTime() {
    RestCacheClient expirationCache = client.cache("expiration");
    // when
    CompletionStage<RestResponse> response = expirationCache.post("test", "test", 0, 0);
    ResponseAssertion.assertThat(response).isOk();
    RestResponse getResponse = join(expirationCache.get("test"));
    // then
    ResponseAssertion.assertThat(getResponse).isOk();
    Assertions.assertThat(getLifespan(getResponse)).isEqualTo(DEFAULT_LIFESPAN_SECONDS);
    Assertions.assertThat(getMaxIdle(getResponse)).isEqualTo(DEFAULT_MAX_IDLE_SECONDS);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test)

Example 53 with RestResponse

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

the class BaseCacheResourceTest method shouldPutLargeObject.

@Test
public void shouldPutLargeObject() {
    byte[] payload = new byte[1_000_000];
    final RestCacheClient binaryCache = client.cache("binary");
    CompletionStage<RestResponse> response = binaryCache.post("test", RestEntity.create(APPLICATION_OCTET_STREAM, payload));
    ResponseAssertion.assertThat(response).isOk();
    ResponseAssertion.assertThat(response).hasEtag();
    RestResponse getResponse = join(binaryCache.get("test"));
    Assertions.assertThat(getResponse.getBodyAsByteArray().length).isEqualTo(1_000_000);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Test(org.testng.annotations.Test)

Example 54 with RestResponse

use of org.infinispan.client.rest.RestResponse 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 55 with RestResponse

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

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