Search in sources :

Example 6 with RestCacheClient

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

the class AbstractAuthorization method testRestWriterCannotRead.

private void testRestWriterCannotRead(String... explicitRoles) {
    restCreateAuthzCache(explicitRoles);
    RestCacheClient writerCache = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.WRITER)).get().cache(getServerTest().getMethodName());
    sync(writerCache.put("k1", "v1"));
    assertStatus(FORBIDDEN, writerCache.get("k1"));
    for (TestUser user : EnumSet.of(TestUser.OBSERVER, TestUser.DEPLOYER)) {
        RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
        assertEquals("v1", sync(userCache.get("k1")).getBody());
    }
}
Also used : RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser)

Example 7 with RestCacheClient

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

the class AbstractAuthorization method testNonBulkReadUsersCannotQuery.

@Test
public void testNonBulkReadUsersCannotQuery() {
    org.infinispan.configuration.cache.ConfigurationBuilder builder = prepareIndexedCache();
    // Hot Rod
    for (TestUser user : EnumSet.of(TestUser.READER, TestUser.WRITER)) {
        RemoteCache<Integer, User> userCache = getServerTest().hotrod().withClientConfiguration(clientConfigurationWithProtostreamMarshaller(user)).withServerConfiguration(builder).get();
        QueryFactory qf = Search.getQueryFactory(userCache);
        Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'Tom'");
        Exceptions.expectException(HotRodClientException.class, "(?s).*ISPN000287.*", () -> query.execute().list());
    }
    // REST
    for (TestUser user : EnumSet.of(TestUser.READER, TestUser.WRITER, TestUser.MONITOR)) {
        RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
        assertStatus(FORBIDDEN, userCache.query("FROM sample_bank_account.User WHERE name = 'Tom'"));
        assertStatus(OK, userCache.searchStats());
        assertStatus(OK, userCache.indexStats());
        assertStatus(OK, userCache.queryStats());
    }
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) TestUser(org.infinispan.server.test.api.TestUser) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 8 with RestCacheClient

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

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

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

the class XSiteHotRodCacheOperations method getTotalMemoryEntries.

private int getTotalMemoryEntries(String lonXML) {
    RestClient restClient = SERVER_TEST.rest(LON).withServerConfiguration(new StringConfiguration(lonXML)).get();
    RestCacheClient client = restClient.cache(SERVER_TEST.getMethodName());
    Json json = Json.read(sync(client.stats()).getBody());
    return json.asJsonMap().get("current_number_of_entries_in_memory").asInteger();
}
Also used : StringConfiguration(org.infinispan.commons.configuration.StringConfiguration) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) Json(org.infinispan.commons.dataconversion.internal.Json)

Aggregations

RestCacheClient (org.infinispan.client.rest.RestCacheClient)66 RestResponse (org.infinispan.client.rest.RestResponse)41 Test (org.testng.annotations.Test)34 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)16 RestEntity (org.infinispan.client.rest.RestEntity)14 Json (org.infinispan.commons.dataconversion.internal.Json)13 RestClient (org.infinispan.client.rest.RestClient)11 Test (org.junit.Test)8 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)7 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)5 TestClass (org.infinispan.rest.TestClass)5 TestUser (org.infinispan.server.test.api.TestUser)5 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 HashMap (java.util.HashMap)2 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)2 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)2 MediaType (org.infinispan.commons.dataconversion.MediaType)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2