Search in sources :

Example 56 with RestClient

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

the class AbstractAuthorization method assertXSiteOps.

private void assertXSiteOps(TestUser user, int status, int noContentStatus, int notModifiedStatus) {
    RestClientConfigurationBuilder userConfig = restBuilders.get(user);
    RestClient client = getServerTest().rest().withClientConfiguration(userConfig).get();
    RestCacheClient xsiteCache = client.cache("xsite");
    assertStatus(status, xsiteCache.takeSiteOffline("NYC"));
    assertStatus(status, xsiteCache.bringSiteOnline("NYC"));
    assertStatus(status, xsiteCache.cancelPushState("NYC"));
    assertStatus(status, xsiteCache.cancelReceiveState("NYC"));
    assertStatus(status, xsiteCache.clearPushStateStatus());
    assertStatus(status, xsiteCache.pushSiteState("NYC"));
    assertStatus(status, xsiteCache.pushStateStatus());
    assertStatus(status, xsiteCache.xsiteBackups());
    assertStatus(status, xsiteCache.backupStatus("NYC"));
    assertStatus(status, xsiteCache.getXSiteTakeOfflineConfig("NYC"));
    assertStatus(noContentStatus, xsiteCache.updateXSiteTakeOfflineConfig("NYC", 10, 1000));
    assertStatus(status, xsiteCache.xSiteStateTransferMode("NYC"));
    assertStatus(notModifiedStatus, xsiteCache.xSiteStateTransferMode("NYC", XSiteStateTransferMode.MANUAL));
    RestCacheManagerClient xsiteCacheManager = client.cacheManager("default");
    assertStatus(status, xsiteCacheManager.bringBackupOnline("NYC"));
    assertStatus(status, xsiteCacheManager.takeOffline("NYC"));
    assertStatus(status, xsiteCacheManager.backupStatuses());
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient)

Example 57 with RestClient

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

the class AbstractAuthorization method testRestNonAdminsMustNotPerformSearchActions.

@Test
public void testRestNonAdminsMustNotPerformSearchActions() {
    String schema = Exceptions.unchecked(() -> Util.getResourceAsString("/sample_bank_account/bank.proto", this.getClass().getClassLoader()));
    assertStatus(OK, getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.ADMIN)).get().schemas().put(BANK_PROTO, schema));
    org.infinispan.configuration.cache.ConfigurationBuilder builder = new org.infinispan.configuration.cache.ConfigurationBuilder();
    builder.clustering().cacheMode(CacheMode.DIST_SYNC);
    builder.indexing().enable().addIndexedEntity("sample_bank_account.User").statistics().enable();
    RestClient restClient = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.ADMIN)).withServerConfiguration(builder).create();
    String indexedCache = getServerTest().getMethodName();
    RestCacheClient cache = restClient.cache(indexedCache);
    for (TestUser user : TestUser.NON_ADMINS) {
        searchActions(user, indexedCache, FORBIDDEN, FORBIDDEN);
    }
    searchActions(TestUser.ADMIN, indexedCache, OK, NO_CONTENT);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) AuthorizationConfigurationBuilder(org.infinispan.configuration.cache.AuthorizationConfigurationBuilder) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 58 with RestClient

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

the class AbstractAuthorization method testAnonymousHealthPredefinedCache.

@Test
public void testAnonymousHealthPredefinedCache() {
    RestClient client = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.ANONYMOUS)).get();
    assertEquals("HEALTHY", sync(client.cacheManager("default").healthStatus()).getBody());
}
Also used : RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Example 59 with RestClient

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

the class StatefulSetRollingUpgradeIT method assertLiveness.

private void assertLiveness(int server) {
    RestClient rest = methodRule.rest().get(server);
    RestResponse rsp = sync(rest.cacheManager(CACHE_MANAGER).healthStatus(), 10, TimeUnit.SECONDS);
    assertEquals(HttpResponseStatus.OK.code(), rsp.getStatus());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient)

Example 60 with RestClient

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

the class AbstractAuthenticationKeyCloak method testRestReadWrite.

@Test
public void testRestReadWrite() {
    String token = getToken();
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.security().authentication().mechanism("BEARER_TOKEN").username(token);
    RestClient client = getServerTest().rest().withClientConfiguration(builder).create();
    RestResponse response = sync(client.cache(getServerTest().getMethodName()).post("k1", "v1"));
    assertEquals(204, response.getStatus());
    response = sync(client.cache(getServerTest().getMethodName()).get("k1"));
    assertEquals(200, response.getStatus());
    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)

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