use of io.restassured.response.Response in project okapi by folio-org.
the class ModuleTest method testNotFound.
@Test
public void testNotFound(TestContext context) {
async = context.async();
Response r;
ValidatableResponse then;
final String docTenantRoskilde = "{" + LS + " \"id\" : \"" + okapiTenant + "\"," + LS + " \"name\" : \"" + okapiTenant + "\"," + LS + " \"description\" : \"Roskilde bibliotek\"" + LS + "}";
r = given().header("Content-Type", "application/json").body(docTenantRoskilde).post("/_/proxy/tenants").then().statusCode(201).body(equalTo(docTenantRoskilde)).extract().response();
final String locationTenantRoskilde = r.getHeader("Location");
final String docLaunch1 = "{" + LS + " \"srvcId\" : \"sample-module-1\"," + LS + " \"nodeId\" : \"localhost\"," + LS + " \"descriptor\" : {" + LS + " \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS + " }" + LS + "}";
r = given().header("Content-Type", "application/json").body(docLaunch1).post("/_/discovery/modules").then().statusCode(201).extract().response();
locationSampleDeployment = r.getHeader("Location");
for (String type : Arrays.asList("request-response", "request-only", "headers")) {
final String docSampleModule = "{" + LS + " \"id\" : \"sample-module-1\"," + LS + " \"filters\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"path\" : \"/test2\"," + LS + " \"level\" : \"20\"," + LS + " \"type\" : \"" + type + "\"" + LS + " } ]" + LS + "}";
r = given().header("Content-Type", "application/json").body(docSampleModule).post("/_/proxy/modules").then().statusCode(201).extract().response();
final String locationSampleModule = r.getHeader("Location");
final String docEnableSample = "{" + LS + " \"id\" : \"sample-module-1\"" + LS + "}";
r = given().header("Content-Type", "application/json").body(docEnableSample).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableSample)).extract().response();
final String enableLoc = r.getHeader("Location");
given().header("X-Okapi-Tenant", okapiTenant).body("bar").post("/test2").then().statusCode(404);
given().delete(enableLoc).then().statusCode(204);
given().delete(locationSampleModule).then().statusCode(204);
}
given().delete(locationSampleDeployment).then().statusCode(204);
locationSampleDeployment = null;
given().delete(locationTenantRoskilde).then().statusCode(204);
async.complete();
}
use of io.restassured.response.Response in project okapi by folio-org.
the class ModuleTest method testHeader.
@Test
public void testHeader(TestContext context) {
async = context.async();
Response r;
ValidatableResponse then;
final String docLaunch1 = "{" + LS + " \"srvcId\" : \"sample-module-5\"," + LS + " \"nodeId\" : \"localhost\"," + LS + " \"descriptor\" : {" + LS + " \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS + " }" + LS + "}";
r = given().header("Content-Type", "application/json").body(docLaunch1).post("/_/discovery/modules").then().statusCode(201).extract().response();
locationSampleDeployment = r.getHeader("Location");
final String docLaunch2 = "{" + LS + " \"srvcId\" : \"header-module-1\"," + LS + " \"nodeId\" : \"localhost\"," + LS + " \"descriptor\" : {" + LS + " \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-header-module/target/okapi-test-header-module-fat.jar\"" + LS + " }" + LS + "}";
r = given().header("Content-Type", "application/json").body(docLaunch2).post("/_/discovery/modules").then().statusCode(201).extract().response();
locationHeaderDeployment = r.getHeader("Location");
final String docSampleModule = "{" + LS + " \"id\" : \"sample-module-5\"," + LS + " \"filters\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"path\" : \"/testb\"," + LS + " \"level\" : \"20\"," + LS + " \"type\" : \"request-response\"" + LS + " } ]" + LS + "}";
r = given().header("Content-Type", "application/json").body(docSampleModule).post("/_/proxy/modules").then().statusCode(201).extract().response();
final String locationSampleModule = r.getHeader("Location");
final String docHeaderModule = "{" + LS + " \"id\" : \"header-module-1\"," + LS + " \"filters\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"path\" : \"/testb\"," + LS + " \"level\" : \"10\"," + LS + " \"type\" : \"headers\"" + LS + " } ]" + LS + "}";
r = given().header("Content-Type", "application/json").body(docHeaderModule).post("/_/proxy/modules").then().statusCode(201).extract().response();
final String locationHeaderModule = r.getHeader("Location");
final String docTenantRoskilde = "{" + LS + " \"id\" : \"" + okapiTenant + "\"," + LS + " \"name\" : \"" + okapiTenant + "\"," + LS + " \"description\" : \"Roskilde bibliotek\"" + LS + "}";
r = given().header("Content-Type", "application/json").body(docTenantRoskilde).post("/_/proxy/tenants").then().statusCode(201).body(equalTo(docTenantRoskilde)).extract().response();
final String locationTenantRoskilde = r.getHeader("Location");
final String docEnableSample = "{" + LS + " \"id\" : \"sample-module-5\"" + LS + "}";
given().header("Content-Type", "application/json").body(docEnableSample).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableSample));
final String docEnableHeader = "{" + LS + " \"id\" : \"header-module-1\"" + LS + "}";
given().header("Content-Type", "application/json").body(docEnableHeader).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableHeader));
given().header("X-Okapi-Tenant", okapiTenant).body("bar").post("/testb").then().statusCode(200).body(equalTo("Hello foobar")).extract().response();
given().delete("/_/proxy/tenants/" + okapiTenant + "/modules/sample-module-5").then().statusCode(204);
given().delete(locationSampleModule).then().statusCode(204);
final String docSampleModule2 = "{" + LS + " \"id\" : \"sample-module-5\"," + LS + " \"filters\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"path\" : \"/testb\"," + LS + " \"level\" : \"5\"," + LS + " \"type\" : \"request-response\"" + LS + " } ]" + LS + "}";
given().header("Content-Type", "application/json").body(docSampleModule2).post("/_/proxy/modules").then().statusCode(201).extract().response();
final String locationSampleModule2 = r.getHeader("Location");
given().header("Content-Type", "application/json").body(docEnableSample).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableSample));
given().header("X-Okapi-Tenant", okapiTenant).body("bar").post("/testb").then().statusCode(200).body(equalTo("Hello foobar")).extract().response();
logger.debug("testHeader cleaning up");
given().delete(locationTenantRoskilde).then().statusCode(204);
given().delete(locationSampleModule).then().statusCode(204);
given().delete(locationSampleDeployment).then().statusCode(204);
locationSampleDeployment = null;
given().delete(locationHeaderDeployment).then().statusCode(204);
locationHeaderDeployment = null;
given().delete(locationHeaderModule).then().statusCode(204);
checkDbIsEmpty("testHeader done", context);
async.complete();
}
use of io.restassured.response.Response in project okapi by folio-org.
the class ModuleTest method testDeployment.
@Test
public void testDeployment(TestContext context) {
async = context.async();
Response r;
RestAssuredClient c;
c = api.createRestAssured3();
c.given().get("/_/deployment/modules").then().statusCode(200).body(equalTo("[ ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/deployment/modules/not_found").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/discovery/modules").then().statusCode(200).body(equalTo("[ ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/discovery/modules/not_found").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String doc1 = "{" + LS + " \"instId\" : \"localhost-9231\"," + // set so we can compare with result
LS + " \"srvcId\" : \"sample-module5\"," + LS + " \"nodeId\" : \"localhost\"," + LS + " \"descriptor\" : {" + LS + " \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS + " }" + LS + "}";
given().header("Content-Type", "application/json").body(doc1).post(// extra slash !
"/_/discovery/modules/").then().statusCode(404);
// with descriptor, but missing nodeId
final String doc1a = "{" + LS + " \"instId\" : \"localhost-9231\"," + LS + " \"srvcId\" : \"sample-module5\"," + LS + " \"descriptor\" : {" + 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(doc1a).post("/_/discovery/modules").then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// unknown nodeId
final String doc1b = "{" + LS + " \"instId\" : \"localhost-9231\"," + LS + " \"srvcId\" : \"sample-module5\"," + LS + " \"nodeId\" : \"foobarhost\"," + LS + " \"descriptor\" : {" + 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(doc1b).post("/_/discovery/modules").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String doc2 = "{" + LS + " \"instId\" : \"localhost-9231\"," + LS + " \"srvcId\" : \"sample-module5\"," + LS + " \"nodeId\" : \"localhost\"," + LS + " \"url\" : \"http://localhost:9231\"," + LS + " \"descriptor\" : {" + 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("/_/discovery/modules").then().statusCode(201).body(equalTo(doc2)).extract().response();
locationSampleDeployment = r.getHeader("Location");
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get(locationSampleDeployment).then().statusCode(200).body(equalTo(doc2));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/deployment/modules").then().statusCode(200).body(equalTo("[ " + doc2 + " ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc2).post("/_/discovery/modules").then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/discovery/modules/sample-module5").then().statusCode(200).body(equalTo("[ " + doc2 + " ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/discovery/modules").then().statusCode(200).log().ifValidationFails().body(equalTo("[ " + doc2 + " ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
if ("inmemory".equals(conf.getString("storage"))) {
testDeployment2(async, context);
} else {
// just undeploy but keep it registered in discovery
logger.info("doc2 " + doc2);
JsonObject o2 = new JsonObject(doc2);
String instId = o2.getString("instId");
String loc = "http://localhost:9230/_/deployment/modules/" + instId;
c = api.createRestAssured3();
c.given().delete(loc).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
undeployFirst(x -> {
conf.remove("mongo_db_init");
conf.remove("postgres_db_init");
DeploymentOptions opt = new DeploymentOptions().setConfig(conf);
vertx.deployVerticle(MainVerticle.class.getName(), opt, res -> {
waitDeployment2();
});
});
waitDeployment2(async, context);
}
}
use of io.restassured.response.Response in project okapi by folio-org.
the class ModuleTest method testDeployment2.
private void testDeployment2(Async async, TestContext context) {
logger.info("testDeployment2");
Response r;
RestAssuredClient c;
c = api.createRestAssured3();
c.given().delete(locationSampleDeployment).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().delete(locationSampleDeployment).then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
locationSampleDeployment = null;
// Verify that the list works also after delete
c = api.createRestAssured3();
c.given().get("/_/deployment/modules").then().statusCode(200).body(equalTo("[ ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// verify that module5 is no longer there
c = api.createRestAssured3();
c.given().get("/_/discovery/modules/sample-module5").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// verify that a never-seen module returns the same
c = api.createRestAssured3();
c.given().get("/_/discovery/modules/UNKNOWN-MODULE").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// Deploy a module via its own LaunchDescriptor
final String docSampleModule = "{" + LS + " \"id\" : \"sample-module-depl-1\"," + LS + " \"name\" : \"sample module for deployment test\"," + LS + " \"provides\" : [ {" + LS + " \"id\" : \"sample\"," + LS + " \"version\" : \"1.0\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"path\" : \"/testb\"," + LS + " \"level\" : \"30\"," + LS + " \"type\" : \"request-response\"" + LS + " } ]" + LS + " }, {" + LS + " \"id\" : \"_tenant\"," + LS + " \"version\" : \"1.0\"" + LS + " } ]," + 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(docSampleModule).post("/_/proxy/modules").then().statusCode(201).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String locationSampleModule = r.getHeader("Location");
// Specify the node via url, to test that too
final String docDeploy = "{" + LS + " \"instId\" : \"localhost-9231\"," + LS + " \"srvcId\" : \"sample-module-depl-1\"," + LS + " \"nodeId\" : \"http://localhost:9230\"" + LS + "}";
final String DeployResp = "{" + LS + " \"instId\" : \"localhost-9231\"," + LS + " \"srvcId\" : \"sample-module-depl-1\"," + LS + " \"nodeId\" : \"http://localhost:9230\"," + LS + " \"url\" : \"http://localhost:9231\"," + LS + " \"descriptor\" : {" + 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(docDeploy).post("/_/discovery/modules").then().statusCode(201).body(equalTo(DeployResp)).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
locationSampleDeployment = r.getHeader("Location");
// Would be nice to verify that the module works, but too much hassle with
// tenants etc.
// Undeploy.
c = api.createRestAssured3();
c.given().delete(locationSampleDeployment).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// Undeploy again, to see it is gone
c = api.createRestAssured3();
c.given().delete(locationSampleDeployment).then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
locationSampleDeployment = null;
// and delete from the proxy
c = api.createRestAssured3();
c.given().delete(locationSampleModule).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
checkDbIsEmpty("testDeployment done", context);
async.complete();
}
use of io.restassured.response.Response in project okapi by folio-org.
the class ModuleTest method testManyModules.
@Test
public void testManyModules(TestContext context) {
async = context.async();
RestAssuredClient c;
Response r;
int i;
for (i = 0; i < 10; i++) {
String docSampleModule = "{" + LS + " \"id\" : \"sample-1.2." + Integer.toString(i) + "\"," + LS + " \"name\" : \"sample module " + Integer.toString(i) + "\"," + LS + " \"requires\" : [ ]" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(docSampleModule).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
}
c = api.createRestAssured3();
r = c.given().get("/_/proxy/modules").then().statusCode(200).log().ifValidationFails().extract().response();
Assert.assertTrue(c.getLastReport().isEmpty());
async.complete();
}
Aggregations