Search in sources :

Example 16 with RestClient

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

the class AuthenticationMultiEndpointIT method testRest.

private void testRest() {
    Protocol proto = Protocol.valueOf(protocol);
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder().followRedirects(false);
    if (useAuth) {
        builder.protocol(proto).security().authentication().mechanism(mechanism).realm(realm).username(userPrefix + "all_user").password("all");
    }
    try {
        RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).withPort(port).create();
        validateSuccess();
        RestResponse response = sync(client.cache(SERVER_TEST.getMethodName()).post("k1", "v1"));
        assertEquals(204, response.getStatus());
        assertEquals(proto, response.getProtocol());
        response = sync(client.cache(SERVER_TEST.getMethodName()).get("k1"));
        assertEquals(200, response.getStatus());
        assertEquals(proto, response.getProtocol());
        assertEquals("v1", response.getBody());
        response = sync(client.raw().get("/"));
        assertEquals(isAdmin ? 307 : 404, response.getStatus());
        response = sync(client.server().info());
        assertEquals(isAdmin ? 200 : 404, response.getStatus());
    } catch (SecurityException e) {
        validateException(e);
    }
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Protocol(org.infinispan.client.rest.configuration.Protocol)

Example 17 with RestClient

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

the class RestOperations method taskFilter.

@Test
public void taskFilter() {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.protocol(protocol);
    RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
    RestResponse tasks = sync(client.tasks().list(ResultType.USER));
    List<Json> taskListNode = Json.read(tasks.getBody()).asJsonList();
    taskListNode.forEach(n -> assertFalse(n.at("name").asString().startsWith("@@")));
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Json(org.infinispan.commons.dataconversion.internal.Json) AbstractRestResourceTest(org.infinispan.rest.resources.AbstractRestResourceTest) Test(org.junit.Test)

Example 18 with RestClient

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

the class RestOperations method testRestOperations.

@Test
public void testRestOperations() {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.protocol(protocol);
    RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
    RestCacheClient cache = client.cache(SERVER_TEST.getMethodName());
    RestResponse response = sync(cache.put("k1", "v1"));
    assertEquals(204, response.getStatus());
    assertEquals(protocol, response.getProtocol());
    response = sync(cache.get("k1"));
    assertEquals(200, response.getStatus());
    assertEquals(protocol, response.getProtocol());
    assertEquals("v1", response.getBody());
    response = sync(cache.remove("k1"));
    assertEquals(204, response.getStatus());
    assertEquals(protocol, response.getProtocol());
    response = sync(cache.get("k1"));
    assertEquals(404, response.getStatus());
    assertEquals(protocol, response.getProtocol());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) AbstractRestResourceTest(org.infinispan.rest.resources.AbstractRestResourceTest) Test(org.junit.Test)

Example 19 with RestClient

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

the class RestOperations method testPutWithTimeToLive.

@Test
public void testPutWithTimeToLive() throws InterruptedException {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.protocol(protocol);
    RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
    RestCacheClient cache = client.cache(SERVER_TEST.getMethodName());
    sync(cache.post("k1", "v1", 1, 1));
    assertEquals(HttpResponseStatus.OK.code(), sync(cache.get("k1")).getStatus());
    Thread.sleep(2000);
    assertEquals(HttpResponseStatus.NOT_FOUND.code(), sync(cache.get("k1")).getStatus());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) AbstractRestResourceTest(org.infinispan.rest.resources.AbstractRestResourceTest) Test(org.junit.Test)

Example 20 with RestClient

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

the class RestServerResource method testCacheManagerNames.

@Test
public void testCacheManagerNames() {
    RestClient client = SERVER_TEST.rest().create();
    RestResponse restResponse = sync(client.cacheManagers());
    assertEquals(200, restResponse.getStatus());
    Json cacheManagers = Json.read(restResponse.getBody());
    Set<String> cmNames = cacheManagers.asJsonList().stream().map(Json::asString).collect(Collectors.toSet());
    assertEquals(cmNames, Sets.newHashSet("default"));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.junit.Test)

Aggregations

RestClient (org.infinispan.client.rest.RestClient)65 Test (org.junit.Test)41 RestResponse (org.infinispan.client.rest.RestResponse)37 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)26 Json (org.infinispan.commons.dataconversion.internal.Json)15 RestCacheClient (org.infinispan.client.rest.RestCacheClient)11 Test (org.testng.annotations.Test)10 IOException (java.io.IOException)6 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)6 ArrayList (java.util.ArrayList)4 RestServerHelper (org.infinispan.rest.helper.RestServerHelper)4 AbstractRestResourceTest (org.infinispan.rest.resources.AbstractRestResourceTest)4 InetSocketAddress (java.net.InetSocketAddress)3 List (java.util.List)3 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)3 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 TestUser (org.infinispan.server.test.api.TestUser)3 File (java.io.File)2 UncheckedIOException (java.io.UncheckedIOException)2