use of guru.nidi.ramltester.restassured3.RestAssuredClient 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 guru.nidi.ramltester.restassured3.RestAssuredClient 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 guru.nidi.ramltester.restassured3.RestAssuredClient 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 guru.nidi.ramltester.restassured3.RestAssuredClient in project okapi by folio-org.
the class PullTest method test1.
@Test
public void test1() {
RestAssuredClient c;
c = api.createRestAssured3();
c.given().port(port1).get("/_/version").then().statusCode(200);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().port(port2).get("/_/version").then().statusCode(200);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().port(port2).header("Content-Type", "application/json").body("{ bad json").post("/_/proxy/pull/modules").then().statusCode(400).log().ifValidationFails();
}
use of guru.nidi.ramltester.restassured3.RestAssuredClient in project okapi by folio-org.
the class TenantRATest method test1.
@Test
public void test1() {
RestAssured.port = port;
RestAssuredClient c;
Response r;
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants//modules").then().statusCode(404);
String superTenantDoc = "{" + LS + " \"id\" : \"supertenant\"," + LS + " \"name\" : \"supertenant\"," + LS + " \"description\" : \"Okapi built-in super tenant\"" + LS + "}";
String superTenantList = "[ " + superTenantDoc + " ]";
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants").then().log().ifValidationFails().statusCode(200).body(equalTo(superTenantList));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// Check that we can not delete the superTenant
c = api.createRestAssured3();
c.given().delete("/_/proxy/tenants/supertenant").then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String badId = "{" + LS + " \"id\" : \"Bad Id with Spaces and Specials: ?%!\"," + LS + " \"name\" : \"roskilde\"," + LS + " \"description\" : \"Roskilde bibliotek\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(badId).post("/_/proxy/tenants").then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String doc = "{" + LS + " \"id\" : \"roskilde\"," + LS + " \"name\" : \"roskilde\"," + LS + " \"description\" : \"Roskilde bibliotek\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc).post("/_/proxy/tenants").then().statusCode(201).body(equalTo(doc)).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String location = r.getHeader("Location");
// post again, fail because of duplicate
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc).post("/_/proxy/tenants").then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").get("/_/proxy/tenants/roskilde/modules/foo").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get(location).then().statusCode(200).body(equalTo(doc));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get(location + "none").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String tenantList = "[ " + doc + ", " + superTenantDoc + " ]";
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants").then().log().ifValidationFails().statusCode(200).body(equalTo(tenantList));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().delete(location).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants").then().statusCode(200).body(equalTo(superTenantList));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String doc3BadJson = "{" + LS + " \"id\" : \"roskildedk\"," + LS;
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc3BadJson).post("/_/proxy/tenants").then().statusCode(400);
String doc3 = "{" + LS + " \"id\" : \"roskildedk\"," + LS + " \"name\" : \"roskilde\"," + LS + " \"description\" : \"Roskilde bibliotek\"" + LS + "}";
c = api.createRestAssured3();
Response r3 = c.given().header("Content-Type", "application/json").body(doc3).post("/_/proxy/tenants").then().statusCode(201).body(equalTo(doc3)).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String location3 = r3.getHeader("Location");
logger.debug("location3 = " + location3);
final String tenantList3 = "[ " + doc3 + ", " + superTenantDoc + " ]";
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants").then().statusCode(200).body(equalTo(tenantList3));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String doc4BadJson = "{" + LS + " \"id\" : \"roskildedk\"," + LS;
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc4BadJson).put(location3).then().statusCode(400);
String doc4badId = "{" + LS + " \"id\" : \"roskildedk2\"," + LS + " \"name\" : \"Roskildes Real Name\"," + LS + " \"description\" : \"Roskilde bibliotek with a better description\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc4badId).put(location3).then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String doc4 = "{" + LS + " \"id\" : \"roskildedk\"," + LS + " \"name\" : \"Roskildes Real Name\"," + LS + " \"description\" : \"Roskilde bibliotek with a better description\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc4).put(location3).then().statusCode(200).body(equalTo(doc4));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().delete(location3).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().delete(location3 + "notThere").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String doc5 = "{" + LS + " \"id\" : \"roskildedk\"," + LS + " \"name\" : \"Roskildes Real Name\"," + LS + " \"description\" : \"Roskilde bibliotek with a better description\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc5).put(location3).then().statusCode(200);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().delete(location3).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String superdoc2 = "{" + LS + " \"id\" : \"supertenant\"," + LS + " \"name\" : \"The Real Super Tenant\"," + LS + " \"description\" : \"With a better description\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(superdoc2).put("/_/proxy/tenants/supertenant").then().statusCode(200);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants").then().statusCode(200).body(equalTo("[ " + superdoc2 + " ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// server-side generated Id
String doc6 = "{" + LS + " \"name\" : \"Ringsted\"," + LS + " \"description\" : \"Ringsted description\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc6).post("/_/proxy/tenants").then().statusCode(201).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
location3 = r.getHeader("Location");
c = api.createRestAssured3();
c.given().delete(location3).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// no name
String doc7 = "{" + LS + " \"id\" : \"ringsted\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc7).post("/_/proxy/tenants").then().statusCode(201).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
location3 = r.getHeader("Location");
c = api.createRestAssured3();
r = c.given().get("/_/proxy/tenants/ringsted").then().statusCode(200).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
Assert.assertEquals(doc7, r.body().asString());
String doc8 = "{" + LS + " \"id\" : \"ringsted\"," + LS + " \"name\" : \"Ringsted\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc8).put(location3).then().statusCode(200).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
JsonObject j = new JsonObject(r.body().asString());
Assert.assertEquals("Ringsted", j.getString("name"));
Assert.assertEquals("ringsted", j.getString("id"));
c = api.createRestAssured3();
c.given().delete(location3).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
}
Aggregations