Search in sources :

Example 6 with OkapiClient

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

the class AuthModuleTest method testNoTenant.

@Test
public void testNoTenant(TestContext context) {
    Async async = context.async();
    HashMap<String, String> headers = new HashMap<>();
    headers.put(XOkapiHeaders.URL, URL);
    OkapiClient cli = new OkapiClient(URL, vertx, headers);
    cli.setOkapiToken("a.b.c");
    cli.get("/notenant", res -> {
        context.assertTrue(res.failed());
        context.assertEquals(ErrorType.INTERNAL, 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 7 with OkapiClient

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

the class AuthModuleTest method testAAANoLoginToken.

@Test
public void testAAANoLoginToken(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("/nologintoken", res -> {
        if (res.succeeded()) {
            logger.debug("res.succeeded. " + res.result());
        } else {
            logger.debug("res.failed. " + Json.encode(res));
        }
        context.assertTrue(res.succeeded());
        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 8 with OkapiClient

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

the class HeaderModuleTest method test1.

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

Example 9 with OkapiClient

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

the class MainVerticle method recurseHandle.

private void recurseHandle(RoutingContext ctx) {
    String d = ctx.request().getParam("depth");
    if (d == null || d.isEmpty()) {
        d = "1";
    }
    // must be final
    String depthstr = d;
    int depth = Integer.parseInt(depthstr);
    if (depth < 0) {
        responseError(ctx, 400, "Bad recursion, can not be negative " + depthstr);
    } else if (depth == 0) {
        responseText(ctx, 200);
        ctx.response().end("Recursion done");
    } else {
        OkapiClient ok = new OkapiClient(ctx);
        depth--;
        ok.get("/recurse?depth=" + depth, res -> {
            ok.close();
            if (res.succeeded()) {
                MultiMap respH = ok.getRespHeaders();
                for (Map.Entry<String, String> e : respH.entries()) {
                    if (e.getKey().startsWith("X-") || e.getKey().startsWith("x-")) {
                        ctx.response().headers().add(e.getKey(), e.getValue());
                    }
                }
                responseText(ctx, 200);
                ctx.response().end(depthstr + " " + res.result());
            } else {
                String message = res.cause().getMessage();
                responseError(ctx, 500, "Recurse " + depthstr + " failed with " + message);
            }
        });
    }
}
Also used : XOkapiHeaders(org.folio.okapi.common.XOkapiHeaders) MultiMap(io.vertx.core.MultiMap) FileWriter(java.io.FileWriter) Router(io.vertx.ext.web.Router) IOException(java.io.IOException) RoutingContext(io.vertx.ext.web.RoutingContext) Future(io.vertx.core.Future) OkapiClient(org.folio.okapi.common.OkapiClient) OkapiLogger(org.folio.okapi.common.OkapiLogger) HttpResponse(org.folio.okapi.common.HttpResponse) HttpMethod(io.vertx.core.http.HttpMethod) AbstractVerticle(io.vertx.core.AbstractVerticle) Map(java.util.Map) HttpServerOptions(io.vertx.core.http.HttpServerOptions) ModuleVersionReporter(org.folio.okapi.common.ModuleVersionReporter) ManagementFactory(java.lang.management.ManagementFactory) Logger(io.vertx.core.logging.Logger) MultiMap(io.vertx.core.MultiMap) OkapiClient(org.folio.okapi.common.OkapiClient)

Example 10 with OkapiClient

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

the class SampleModuleTest method testAllHeaders.

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

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