Search in sources :

Example 66 with RestResponse

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

the class CacheResourceTest method testCorsSameOrigin.

@Test
public void testCorsSameOrigin() {
    Map<String, String> headers = new HashMap<>();
    String scheme = ssl ? "https://" : "http://";
    headers.put(ORIGIN.toString(), scheme + "origin-host.org");
    headers.put(HOST.toString(), "origin-host.org");
    CompletionStage<RestResponse> response = client.raw().get("/rest/v2/caches", headers);
    assertThat(response).isOk();
}
Also used : HashMap(java.util.HashMap) RestResponse(org.infinispan.client.rest.RestResponse) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Test(org.testng.annotations.Test)

Example 67 with RestResponse

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

the class CacheResourceTest method testCORSAllOrigins.

@Test
public void testCORSAllOrigins() throws IOException {
    RestServerHelper restServerHelper = null;
    RestClient client = null;
    try {
        RestServerConfigurationBuilder restBuilder = new RestServerConfigurationBuilder();
        restBuilder.cors().addNewRule().allowOrigins(new String[] { "*" });
        restBuilder.host("localhost").port(0);
        restServerHelper = RestServerHelper.defaultRestServer();
        RestServerConfiguration build = restBuilder.build();
        restServerHelper.withConfiguration(build).start("test");
        client = restServerHelper.createClient();
        RestResponse response = join(client.cache("default").get("test", singletonMap(ORIGIN.toString(), "http://host.example.com:5576")));
        assertThat(response).containsAllHeaders("access-control-allow-origin");
    } finally {
        client.close();
        if (restServerHelper != null)
            restServerHelper.stop();
    }
}
Also used : RestServerConfigurationBuilder(org.infinispan.rest.configuration.RestServerConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) RestServerConfiguration(org.infinispan.rest.configuration.RestServerConfiguration) RestServerHelper(org.infinispan.rest.helper.RestServerHelper) Test(org.testng.annotations.Test)

Example 68 with RestResponse

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

the class CacheResourceTest method testIfModifiedHeaderForCache.

@Test
public void testIfModifiedHeaderForCache() {
    putStringValueInCache("expiration", "test", "test");
    RestCacheClient cacheClient = client.cache("expiration");
    RestResponse resp = join(cacheClient.get("test"));
    String dateLast = resp.headers().get("Last-Modified").get(0);
    CompletionStage<RestResponse> sameLastModAndIfModified = cacheClient.get("test", createHeaders(IF_MODIFIED_SINCE, dateLast));
    assertThat(sameLastModAndIfModified).isNotModified();
    putStringValueInCache("expiration", "test", "test-new");
    RestResponse lastmodAfterIfModified = join(cacheClient.get("test"));
    dateLast = lastmodAfterIfModified.headers().get("Last-Modified").get(0);
    assertThat(lastmodAfterIfModified).isOk();
    Map<String, String> header = createHeaders(IF_MODIFIED_SINCE, plus1Day(dateLast));
    CompletionStage<RestResponse> lastmodBeforeIfModified = cacheClient.get("test", header);
    assertThat(lastmodBeforeIfModified).isNotModified();
}
Also used : 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 69 with RestResponse

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

the class CacheResourceTest method shouldReadTextWithPojoCache.

@Test
public void shouldReadTextWithPojoCache() {
    // given
    RestCacheClient pojoCache = client.cache("pojoCache");
    String key = "k1";
    String value = "v1";
    join(pojoCache.put(key, value));
    // when
    RestResponse response = join(pojoCache.get(key));
    // then
    assertThat(response).isOk();
    assertThat(response).hasContentType(TEXT_PLAIN_TYPE);
    assertThat(response).hasReturnedText(value);
}
Also used : 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 70 with RestResponse

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

the class CacheResourceTest method testCORSPreflight.

@Test
public void testCORSPreflight() {
    String url = String.format("/rest/v2/caches/%s/%s", "default", "key");
    RestRawClient rawClient = client.raw();
    join(client.cache("default").put("key", "value"));
    Map<String, String> headers = new HashMap<>();
    headers.put(HOST.toString(), "localhost");
    headers.put(ORIGIN.toString(), "http://localhost:" + restServer().getPort());
    headers.put(ACCESS_CONTROL_REQUEST_METHOD.toString(), "GET");
    CompletionStage<RestResponse> preFlight = rawClient.options(url, headers);
    assertThat(preFlight).isOk();
    assertThat(preFlight).hasNoContent();
    assertThat(preFlight).containsAllHeaders(ACCESS_CONTROL_ALLOW_ORIGIN.toString(), ACCESS_CONTROL_ALLOW_METHODS.toString(), ACCESS_CONTROL_ALLOW_HEADERS.toString());
    assertThat(preFlight).hasHeaderWithValues(ACCESS_CONTROL_ALLOW_HEADERS.toString(), (String[]) RequestHeader.toArray());
}
Also used : RestRawClient(org.infinispan.client.rest.RestRawClient) HashMap(java.util.HashMap) RestResponse(org.infinispan.client.rest.RestResponse) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) 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