Search in sources :

Example 21 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder 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 22 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder 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 23 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder 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 24 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class XSiteResourceTest method startServers.

@BeforeClass
public void startServers() {
    sites.forEach(site -> {
        String siteName = site.getSiteName();
        EmbeddedCacheManager cm = site.cacheManagers().iterator().next();
        RestServerHelper restServerHelper = new RestServerHelper(cm);
        restServerHelper.start(TestResourceTracker.getCurrentTestShortName());
        restServerPerSite.put(siteName, restServerHelper);
        RestClientConfiguration clientConfig = new RestClientConfigurationBuilder().addServer().host("127.0.0.1").port(restServerHelper.getPort()).build();
        RestClient client = RestClient.forConfiguration(clientConfig);
        clientPerSite.put(siteName, client);
    });
}
Also used : RestClientConfiguration(org.infinispan.client.rest.configuration.RestClientConfiguration) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) RestServerHelper(org.infinispan.rest.helper.RestServerHelper) BeforeClass(org.testng.annotations.BeforeClass)

Example 25 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class AuthenticationTest method beforeMethod.

@BeforeMethod(alwaysRun = true)
public void beforeMethod() {
    SecurityDomain securityDomainMock = mock(SecurityDomain.class);
    Subject user = TestingUtil.makeSubject("test");
    doReturn(user).when(securityDomainMock).authenticate(eq("test"), eq("test"));
    BasicAuthenticator basicAuthenticator = new BasicAuthenticator(securityDomainMock, REALM);
    restServer = RestServerHelper.defaultRestServer().withAuthenticator(basicAuthenticator).start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder configurationBuilder = new RestClientConfigurationBuilder();
    configurationBuilder.addServer().host(restServer.getHost()).port(restServer.getPort());
    client = RestClient.forConfiguration(configurationBuilder.build());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) BasicAuthenticator(org.infinispan.rest.authentication.impl.BasicAuthenticator) Subject(javax.security.auth.Subject) SecurityDomain(org.infinispan.rest.authentication.SecurityDomain) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)56 Test (org.junit.Test)26 RestClient (org.infinispan.client.rest.RestClient)25 RestResponse (org.infinispan.client.rest.RestResponse)22 RestClientConfiguration (org.infinispan.client.rest.configuration.RestClientConfiguration)8 RestServerHelper (org.infinispan.rest.helper.RestServerHelper)6 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)5 InetSocketAddress (java.net.InetSocketAddress)4 RestCacheClient (org.infinispan.client.rest.RestCacheClient)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 RestServer (org.infinispan.rest.RestServer)4 RestServerConfigurationBuilder (org.infinispan.rest.configuration.RestServerConfigurationBuilder)4 AbstractRestResourceTest (org.infinispan.rest.resources.AbstractRestResourceTest)4 DummyServerManagement (org.infinispan.server.core.DummyServerManagement)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RestEntity (org.infinispan.client.rest.RestEntity)3 Json (org.infinispan.commons.dataconversion.internal.Json)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 Router (org.infinispan.server.router.Router)3