use of io.restassured.response.Response in project okapi by folio-org.
the class MainDeployTest method testDevMode.
@Test
public void testDevMode(TestContext context) {
async = context.async();
String[] args = { "dev" };
MainDeploy d = new MainDeploy();
d.init(args, res -> {
vertx = res.succeeded() ? res.result() : null;
Assert.assertTrue("main1 " + res.cause(), res.succeeded());
RestAssuredClient c;
Response r;
c = api.createRestAssured3();
r = c.given().get("/_/version").then().statusCode(200).log().ifValidationFails().extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
async.complete();
});
}
use of io.restassured.response.Response in project okapi by folio-org.
the class ModuleTenantsTest method testDepCheck.
@Test
public void testDepCheck() {
RestAssured.port = port;
RestAssuredClient c;
Response r;
// create basic 1.0.0
final String docBasic_1_0_0 = "{" + LS + " \"id\" : \"basic-module-1.0.0\"," + LS + " \"name\" : \"this module\"," + LS + " \"provides\" : [ {" + LS + " \"id\" : \"_tenant\"," + LS + " \"version\" : \"1.0\"," + LS + " \"interfaceType\" : \"system\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"POST\", \"DELETE\" ]," + LS + " \"pathPattern\" : \"/_/tenant\"" + LS + " } ]" + LS + " }, {" + LS + " \"id\" : \"bint\"," + LS + " \"version\" : \"1.0\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"pathPattern\" : \"/foo\"" + LS + " } ]" + LS + " } ]," + LS + " \"requires\" : [ { \"id\" : \"unknown\", \"version\" : \"1.0\" } ]," + LS + " \"launchDescriptor\" : {" + LS + " \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS + " }" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(docBasic_1_0_0).post("/_/proxy/modules?check=true").then().statusCode(400).log().ifValidationFails();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docBasic_1_0_0).post("/_/proxy/modules?check=false").then().statusCode(201).log().ifValidationFails().extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String location = r.getHeader("Location");
c = api.createRestAssured3();
c.given().delete(location).then().statusCode(204).log().ifValidationFails();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
}
use of io.restassured.response.Response in project okapi by folio-org.
the class ModuleTenantsTest method test4.
@Test
public void test4() {
final String okapiTenant = "roskilde";
RestAssured.port = port;
RestAssuredClient c;
Response r;
// add tenant
final String docTenantRoskilde = "{" + LS + " \"id\" : \"" + okapiTenant + "\"," + LS + " \"name\" : \"" + okapiTenant + "\"," + LS + " \"description\" : \"Roskilde bibliotek\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docTenantRoskilde).post("/_/proxy/tenants").then().statusCode(201).body(equalTo(docTenantRoskilde)).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String locationTenantRoskilde = r.getHeader("Location");
final String doc1 = "{" + LS + " \"id\" : \"sample-module-1.0.0\"," + LS + " \"name\" : \"this module\"," + LS + " \"provides\" : [ {" + LS + " \"id\" : \"sample\"," + LS + " \"version\" : \"1.0\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\", \"DELETE\" ]," + LS + " \"pathPattern\" : \"/testb\"," + LS + " \"type\" : \"request-response\"" + LS + " } ]" + LS + " } ]," + LS + " \"requires\" : [ ]," + LS + " \"launchDescriptor\" : {" + LS + " \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS + " }" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc1).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"sample-module-1.0.0\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?deploy=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + " \"id\" : \"sample-module-1.0.0\"," + LS + " \"action\" : \"enable\"" + LS + "} ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c.given().header("X-Okapi-Tenant", okapiTenant).header("X-delay", "11000").get("/testb").then().statusCode(200).log().ifValidationFails();
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"sample-module-1.0.0\", \"action\" : \"disable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?deploy=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + " \"id\" : \"sample-module-1.0.0\"," + LS + " \"action\" : \"disable\"" + LS + "} ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
}
use of io.restassured.response.Response in project okapi by folio-org.
the class ModuleTenantsTest method test3.
@Test
public void test3() {
final String okapiTenant = "roskilde";
RestAssured.port = port;
RestAssuredClient c;
Response r;
// add tenant
final String docTenantRoskilde = "{" + LS + " \"id\" : \"" + okapiTenant + "\"," + LS + " \"name\" : \"" + okapiTenant + "\"," + LS + " \"description\" : \"Roskilde bibliotek\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docTenantRoskilde).post("/_/proxy/tenants").then().statusCode(201).body(equalTo(docTenantRoskilde)).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String locationTenantRoskilde = r.getHeader("Location");
final String doc1 = "{" + LS + " \"id\" : \"basic-1.0.0\"," + LS + " \"name\" : \"this module\"," + LS + " \"provides\" : [ ]," + LS + " \"requires\" : [ ]," + LS + " \"launchDescriptor\" : {" + LS + " \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS + " }" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc1).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// install with mult first
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body("[ {" + LS + " \"id\" : \"basic\"," + LS + " \"action\" : \"enable\"" + LS + "} ]").post("/_/proxy/tenants/" + okapiTenant + "/install").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + " \"id\" : \"basic-1.0.0\"," + LS + " \"action\" : \"enable\"" + LS + "} ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String doc2 = "{" + LS + " \"id\" : \"basic-1.0.1\"," + LS + " \"name\" : \"this module\"," + LS + " \"provides\" : [ ]," + LS + " \"requires\" : [ ]," + LS + " \"launchDescriptor\" : {" + LS + " \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS + " }" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc2).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").post("/_/proxy/tenants/" + okapiTenant + "/upgrade?simulate=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + " \"id\" : \"basic-1.0.1\"," + LS + " \"from\" : \"basic-1.0.0\"," + LS + " \"action\" : \"enable\"" + LS + "} ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body("[ ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body("[ {" + LS + " \"id\" : \"basic\"," + LS + " \"action\" : \"enable\"" + LS + "} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + " \"id\" : \"basic-1.0.1\"," + LS + " \"from\" : \"basic-1.0.0\"," + LS + " \"action\" : \"enable\"" + LS + "} ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
}
use of io.restassured.response.Response in project okapi by folio-org.
the class MultiTenantTest method test1.
@Test
public void test1() {
Response res;
JsonArray ja;
given().header("Content-Type", "application/json").body(docAuthModule).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails();
given().header("Content-Type", "application/json").body(docTestModule).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails();
given().header("Content-Type", "application/json").body(docTestModule2).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails();
final String supertenant = "supertenant";
given().header("Content-Type", "application/json").body("[ {\"id\" : \"auth-1\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + supertenant + "/install?deploy=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + " \"id\" : \"auth-1\"," + LS + " \"action\" : \"enable\"" + LS + "} ]"));
final String tenant1 = "tenant1";
final String docTenant1 = "{" + LS + " \"id\" : \"" + tenant1 + "\"," + LS + " \"name\" : \"" + tenant1 + "\"," + LS + " \"description\" : \"" + tenant1 + " bibliotek\"" + LS + "}";
// create tenant should fail.. Must login first
given().header("Content-Type", "application/json").body(docTenant1).post("/_/proxy/tenants").then().statusCode(401).log().ifValidationFails();
// supertenant login and get token
final String docLoginSupertenant = "{" + LS + " \"tenant\" : \"" + supertenant + "\"," + LS + " \"username\" : \"peter\"," + LS + " \"password\" : \"peter-password\"" + LS + "}";
final String okapiTokenSupertenant = given().header("Content-Type", "application/json").body(docLoginSupertenant).post("/authn/login").then().statusCode(200).extract().header("X-Okapi-Token");
// create tenant1
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).body(docTenant1).post("/_/proxy/tenants").then().statusCode(201).header("Location", containsString("/_/proxy/tenants")).log().ifValidationFails();
final String tenant2 = "tenant2";
final String docTenant2 = "{" + LS + " \"id\" : \"" + tenant2 + "\"," + LS + " \"name\" : \"" + tenant2 + "\"," + LS + " \"description\" : \"" + tenant2 + " bibliotek\"" + LS + "}";
// create tenant2
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).body(docTenant2).post("/_/proxy/tenants").then().statusCode(201).header("Location", containsString("/_/proxy/tenants")).log().ifValidationFails();
// enable+deploy sample-module-1.2.0 for tenant1
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).body("[ {\"id\" : \"sample-module-1.2.0\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + tenant1 + "/install?deploy=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + " \"id\" : \"sample-module-1.2.0\"," + LS + " \"action\" : \"enable\"" + LS + "} ]"));
// enable+deploy auth-1 for tenant2
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).body("[ {\"id\" : \"auth-1\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + tenant2 + "/install?deploy=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + " \"id\" : \"auth-1\"," + LS + " \"action\" : \"enable\"" + LS + "} ]"));
res = given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).get("/_/discovery/modules").then().statusCode(200).log().ifValidationFails().extract().response();
ja = new JsonArray(res.body().asString());
Assert.assertEquals(2, ja.size());
// tenant2 login and get token
final String docLoginTenant2 = "{" + LS + " \"tenant\" : \"" + tenant2 + "\"," + LS + " \"username\" : \"peter\"," + LS + " \"password\" : \"peter-password\"" + LS + "}";
final String okapiTokenTenant2 = given().header("Content-Type", "application/json").body(docLoginTenant2).header("X-Okapi-Tenant", tenant2).post("/authn/login").then().statusCode(200).extract().header("X-Okapi-Token");
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).body("[ {\"id\" : \"okapi-0.0.0\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + tenant2 + "/install?deploy=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + " \"id\" : \"okapi-0.0.0\"," + LS + " \"action\" : \"enable\"" + LS + "} ]"));
// test failure for enable+deploy sample-module-2.0.0 for tenant2 as tenant2
// because no launch descriptor for sample-module-2.0.0
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenTenant2).body("[ {\"id\" : \"sample-module-2.0.0\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + tenant2 + "/install?deploy=true").then().statusCode(400).log().ifValidationFails();
// remedy the situation by add it to discovery with same URL as other sample
final String docSample2Deployment = "{" + LS + " \"instId\" : \"sample2-inst\"," + LS + " \"srvcId\" : \"sample-module-2.0.0\"," + LS + " \"url\" : \"http://localhost:9232\"" + // same URL as sample-module-1.2.0
LS + "}";
res = given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenTenant2).body(docSample2Deployment).post("/_/discovery/modules").then().statusCode(201).extract().response();
res = given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).get("/_/discovery/modules").then().statusCode(200).log().ifValidationFails().extract().response();
logger.info(res.body().asString());
ja = new JsonArray(res.body().asString());
// two sample modules and auth module
Assert.assertEquals(3, ja.size());
// enable+deploy sample-module-2.0.0 for tenant2 as tenant2
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenTenant2).body("[ {\"id\" : \"sample-module-2.0.0\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + tenant2 + "/install?deploy=true").then().statusCode(200).log().ifValidationFails();
// undeploy sample-module-1.2.0
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).body("[ {\"id\" : \"sample-module-1.2.0\", \"action\" : \"disable\"} ]").post("/_/proxy/tenants/" + tenant1 + "/install?deploy=true").then().statusCode(200).log().ifValidationFails();
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).body("[ {\"id\" : \"sample-module-2.0.0\", \"action\" : \"disable\"} ]").post("/_/proxy/tenants/" + tenant2 + "/install?deploy=true").then().statusCode(200).log().ifValidationFails();
res = given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).get("/_/discovery/modules").then().statusCode(200).log().ifValidationFails().extract().response();
ja = new JsonArray(res.body().asString());
// auth + manual discovery for 2.0.0
Assert.assertEquals(2, ja.size());
// undeploy auth-1 for supertenant
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).body("[ {\"id\" : \"auth-1\", \"action\" : \"disable\"} ]").post("/_/proxy/tenants/" + supertenant + "/install?deploy=true").then().statusCode(200).log().ifValidationFails();
res = given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).get("/_/discovery/modules").then().statusCode(200).log().ifValidationFails().extract().response();
ja = new JsonArray(res.body().asString());
Assert.assertEquals(2, ja.size());
// undeploy auth-1 for tenant2
given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).body("[ {\"id\" : \"auth-1\", \"action\" : \"disable\"} ]").post("/_/proxy/tenants/" + tenant2 + "/install?deploy=true").then().statusCode(200).log().ifValidationFails();
res = given().header("Content-Type", "application/json").header("X-Okapi-Token", okapiTokenSupertenant).get("/_/discovery/modules").then().statusCode(200).log().ifValidationFails().extract().response();
ja = new JsonArray(res.body().asString());
Assert.assertEquals(1, ja.size());
}
Aggregations