Search in sources :

Example 11 with OkapiClient

use of org.folio.okapi.common.OkapiClient in project okapi by folio-org.

the class SampleModuleTest method test1.

@Test
public void test1(TestContext context) {
    Async async = context.async();
    HashMap<String, String> headers = new HashMap<>();
    headers.put(XOkapiHeaders.URL, URL);
    headers.put(XOkapiHeaders.TENANT, "my-lib");
    OkapiClient cli = new OkapiClient(URL, vertx, headers);
    cli.get("/testb", res -> {
        context.assertTrue(res.succeeded());
        test2(context, cli, async);
    });
}
Also used : OkapiClient(org.folio.okapi.common.OkapiClient) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 12 with OkapiClient

use of org.folio.okapi.common.OkapiClient in project okapi by folio-org.

the class AuthModuleTest method testBadToken.

@Test
public void testBadToken(TestContext context) {
    Async async = context.async();
    HashMap<String, String> headers = new HashMap<>();
    headers.put(XOkapiHeaders.URL, URL);
    headers.put(XOkapiHeaders.TENANT, "my-lib");
    OkapiClient cli = new OkapiClient(URL, vertx, headers);
    cli.setOkapiToken("a.b");
    cli.get("/badtoken", res -> {
        cli.close();
        context.assertTrue(res.failed());
        context.assertEquals(ErrorType.USER, res.getType());
        async.complete();
    });
}
Also used : OkapiClient(org.folio.okapi.common.OkapiClient) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 13 with OkapiClient

use of org.folio.okapi.common.OkapiClient in project okapi by folio-org.

the class AuthModuleTest method testBadTokenPayload.

@Test
public void testBadTokenPayload(TestContext context) {
    Async async = context.async();
    HashMap<String, String> headers = new HashMap<>();
    headers.put(XOkapiHeaders.URL, URL);
    headers.put(XOkapiHeaders.TENANT, "my-lib");
    OkapiClient cli = new OkapiClient(URL, vertx, headers);
    cli.setOkapiToken("dummyJwt.b.c");
    cli.get("/badpayload", res -> {
        cli.close();
        context.assertTrue(res.failed());
        context.assertEquals(ErrorType.USER, res.getType());
        async.complete();
    });
}
Also used : OkapiClient(org.folio.okapi.common.OkapiClient) HashMap(java.util.HashMap) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 14 with OkapiClient

use of org.folio.okapi.common.OkapiClient in project okapi by folio-org.

the class HeaderModuleTest method test2.

private void test2(TestContext context, Async async) {
    HashMap<String, String> headers = new HashMap<>();
    headers.put("X-my-header", "hello");
    OkapiClient cli = new OkapiClient(URL, vertx, headers);
    cli.get("/testb", res -> {
        cli.close();
        context.assertTrue(res.succeeded());
        context.assertEquals("hello,foo", cli.getRespHeaders().get("X-my-header"));
        test3(context, async);
    });
}
Also used : OkapiClient(org.folio.okapi.common.OkapiClient) HashMap(java.util.HashMap)

Example 15 with OkapiClient

use of org.folio.okapi.common.OkapiClient in project okapi by folio-org.

the class HeaderModuleTest method test3.

public void test3(TestContext context, Async async) {
    HashMap<String, String> headers = new HashMap<>();
    OkapiClient cli = new OkapiClient(URL, vertx, headers);
    cli.post("/_/tenantPermissions", "a, b,\nc", res -> {
        cli.close();
        context.assertTrue(res.succeeded());
        context.assertEquals("a, b, c", cli.getRespHeaders().get("X-Tenant-Perms-Result"));
        async.complete();
    });
}
Also used : OkapiClient(org.folio.okapi.common.OkapiClient) HashMap(java.util.HashMap)

Aggregations

OkapiClient (org.folio.okapi.common.OkapiClient)19 HashMap (java.util.HashMap)17 Async (io.vertx.ext.unit.Async)12 Test (org.junit.Test)12 JsonObject (io.vertx.core.json.JsonObject)3 HttpMethod (io.vertx.core.http.HttpMethod)2 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)2 RoutingEntry (org.folio.okapi.bean.RoutingEntry)2 AbstractVerticle (io.vertx.core.AbstractVerticle)1 Future (io.vertx.core.Future)1 MultiMap (io.vertx.core.MultiMap)1 HttpServerOptions (io.vertx.core.http.HttpServerOptions)1 Logger (io.vertx.core.logging.Logger)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ManagementFactory (java.lang.management.ManagementFactory)1 Map (java.util.Map)1 ModuleInstance (org.folio.okapi.bean.ModuleInstance)1