Search in sources :

Example 6 with RestResponse

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

the class EmbeddedRestHotRodTest method testHotRodEmbeddedPutRestGetExpiry.

public void testHotRodEmbeddedPutRestGetExpiry() throws Exception {
    final String key = "10";
    final String key2 = "11";
    // 1. Put with HotRod
    assertNull(cacheFactory.getHotRodCache().put(key, "v1", 5, TimeUnit.SECONDS));
    // 2. Put with Embedded
    assertNull(cacheFactory.getEmbeddedCache().put(key2, "v2", 5, TimeUnit.SECONDS));
    // 3. Get with REST key
    RestResponse response = join(cacheFactory.getRestCacheClient().get(key));
    assertEquals(200, response.getStatus());
    assertDate(response, "Expires");
    // 4. Get with REST key2
    response = join(cacheFactory.getRestCacheClient().get(key2));
    assertEquals(200, response.getStatus());
    assertDate(response, "Expires");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse)

Example 7 with RestResponse

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

the class EmbeddedRestHotRodTest method testHotRodPutEmbeddedRestGet.

public void testHotRodPutEmbeddedRestGet() {
    final String key = "3";
    // 1. Put with Hot Rod
    RemoteCache<String, Object> remote = cacheFactory.getHotRodCache();
    assertNull(remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, "v1"));
    // 2. Get with Embedded
    assertEquals("v1", cacheFactory.getEmbeddedCache().get(key));
    // 3. Get with REST
    RestResponse response = join(cacheFactory.getRestCacheClient().get(key, TEXT_PLAIN_TYPE));
    assertEquals(200, response.getStatus());
    assertEquals("v1", response.getBody());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse)

Example 8 with RestResponse

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

the class EmbeddedRestHotRodTest method testHotRodEmbeddedPutRestGetWrongAccept.

public void testHotRodEmbeddedPutRestGetWrongAccept() {
    final String key1 = "16";
    final String key2 = "17";
    // 1. Put with HotRod
    assertNull(cacheFactory.getHotRodCache().put(key1, "v1"));
    // 2. Put with Embedded
    assertNull(cacheFactory.getEmbeddedCache().put(key2, "v2"));
    // 3. GET with REST key1
    RestResponse response = join(cacheFactory.getRestCacheClient().get(key1, "unknown-media-type"));
    assertEquals(406, response.getStatus());
    // 4. GET with REST key2
    response = join(cacheFactory.getRestCacheClient().get(key2, "unknown-media-type"));
    assertEquals(406, response.getStatus());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse)

Example 9 with RestResponse

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

the class EmbeddedRestHotRodTest method testRestPutEmbeddedHotRodGet.

public void testRestPutEmbeddedHotRodGet() {
    final String key = "1";
    // 1. Put with REST
    RestCacheClient restCacheClient = cacheFactory.getRestCacheClient();
    CompletionStage<RestResponse> response = restCacheClient.put(key, RestEntity.create(TEXT_PLAIN, "<hey>ho</hey>"));
    assertEquals(204, join(response).getStatus());
    // 2. Get with Embedded
    assertEquals("<hey>ho</hey>", cacheFactory.getEmbeddedCache().get(key));
    // 3. Get with Hot Rod
    assertEquals("<hey>ho</hey>", cacheFactory.getHotRodCache().get(key));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 10 with RestResponse

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

the class EmbeddedRestHotRodTest method testCustomObjectHotRodPutRestGetAcceptJSONAndXML.

public void testCustomObjectHotRodPutRestGetAcceptJSONAndXML() {
    final String key = "7";
    final Person p = new Person("Jakub");
    // 1. Put with HotRod
    RemoteCache<String, Object> remote = cacheFactory.getHotRodCache();
    assertNull(remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, p));
    // 2. Get with REST (accept application/json)
    RestResponse response = join(cacheFactory.getRestCacheClient().get(key, APPLICATION_JSON_TYPE));
    assertEquals(200, response.getStatus());
    assertEquals(asJson(p), response.getBody());
    // 3. Get with REST (accept application/xml)
    response = join(cacheFactory.getRestCacheClient().get(key, APPLICATION_XML_TYPE));
    assertEquals(200, response.getStatus());
    assertTrue(response.getBody().contains("<name>Jakub</name>"));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse)

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