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();
});
}
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();
});
}
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);
});
}
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);
}
});
}
}
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();
});
}
Aggregations