Search in sources :

Example 36 with RestResponse

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

the class RestAuthentication method testRestReadWrite.

@Test
public void testRestReadWrite() {
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    if (!mechanism.isEmpty()) {
        builder.protocol(protocol).security().authentication().mechanism(mechanism).realm("default").username("all_user").password("all");
    }
    if (mechanism.isEmpty()) {
        Exceptions.expectException(SecurityException.class, () -> SERVER_TEST.rest().withClientConfiguration(builder).create());
    } else {
        RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
        RestResponse response = sync(client.cache(SERVER_TEST.getMethodName()).post("k1", "v1"));
        assertEquals(204, response.getStatus());
        assertEquals(protocol, response.getProtocol());
        response = sync(client.cache(SERVER_TEST.getMethodName()).get("k1"));
        assertEquals(200, response.getStatus());
        assertEquals(protocol, response.getProtocol());
        assertEquals("v1", response.getBody());
    }
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 37 with RestResponse

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

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

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

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

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