use of io.restassured.response.Response in project page-factory-2 by sbtqa.
the class EndpointEntry method send.
public void send() {
reflection.applyAnnotations(FromResponse.class);
reflection.applyAnnotations(Query.class);
reflection.applyAnnotations(Stashed.class);
reflection.applyAnnotations(Mutator.class);
String url = PathUtils.unite(host.isEmpty() ? PROPERTIES.getBaseURI() : PlaceholderUtils.replaceTemplatePlaceholders(host), path);
RequestSpecification request = buildRequest();
Response response;
switch(method) {
case GET:
response = request.get(url);
break;
case POST:
response = request.post(url);
break;
case PUT:
response = request.put(url);
break;
case PATCH:
response = request.patch(url);
break;
case DELETE:
response = request.delete(url);
break;
case OPTIONS:
response = request.options(url);
break;
case HEAD:
response = request.head(url);
break;
default:
throw new UnsupportedOperationException("Request method " + method + " is not supported");
}
ApiEnvironment.getRepository().add(this.getClass(), new ApiPair(request, response.then().log().all(true)));
}
use of io.restassured.response.Response in project okapi by folio-org.
the class EnvTest method test2.
@Test
public void test2() {
final String okapiTenant = "roskilde";
RestAssured.port = port;
RestAssuredClient c;
Response r;
// add Env entry
final String doc = "{" + LS + " \"name\" : \"helloGreeting\"," + LS + " \"value\" : \"hejsa\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc).post("/_/env").then().statusCode(201).body(equalTo(doc)).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String locationName1 = r.getHeader("Location");
// deploy module
final String docSampleDeployment = "{" + LS + " \"srvcId\" : \"sample-module-1.0.0\"," + 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(docSampleDeployment).post("/_/deployment/modules").then().statusCode(201).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
locationSampleDeployment1 = r.getHeader("Location");
// proxy module
final String docSampleModule1 = "{" + LS + " \"id\" : \"sample-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\" : \"myint\"," + LS + " \"version\" : \"1.0\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"pathPattern\" : \"/testb\"" + LS + " } ]" + LS + " } ]," + LS + " \"requires\" : [ ]" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docSampleModule1).post("/_/proxy/modules").then().statusCode(201).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// 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");
// associate tenant for module
final String docEnableSample = "{" + LS + " \"id\" : \"sample-module-1.0.0\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docEnableSample).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableSample)).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String locationTenantModule = r.getHeader("Location");
// run module
c = api.createRestAssured3();
c.given().header("X-Okapi-Tenant", okapiTenant).body("Okapi").post("/testb").then().statusCode(200).body(equalTo("hejsa Okapi"));
}
use of io.restassured.response.Response in project okapi by folio-org.
the class EnvTest method test1.
@Test
public void test1() {
RestAssured.port = port;
RestAssuredClient c;
Response r;
c = api.createRestAssured3();
c.given().get("/_/env").then().statusCode(200).body(equalTo("[ ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/env/name1").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String missingNameDoc = "{" + LS + " \"value\" : \"value1\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(missingNameDoc).post("/_/env").then().statusCode(400);
final String missingValueDoc = "{" + LS + " \"name\" : \"name1\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(missingValueDoc).post("/_/env").then().statusCode(400);
final String badDoc = "{" + LS + " \"name\" : \"BADJSON\"," + // the comma here makes it bad json!
LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(badDoc).post("/_/env").then().statusCode(400);
final String doc = "{" + LS + " \"name\" : \"name1\"," + LS + " \"value\" : \"value1\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc).post("/_/env").then().statusCode(201).body(equalTo(doc)).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String locationName1 = r.getHeader("Location");
c = api.createRestAssured3();
c.given().get(locationName1).then().statusCode(200).body(equalTo(doc));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/env").then().statusCode(200);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().delete(locationName1).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get(locationName1).then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/env").then().statusCode(200).body(equalTo("[ ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
}
use of io.restassured.response.Response in project okapi by folio-org.
the class ModuleTest method testMultipleInterface.
@Test
public void testMultipleInterface(TestContext context) {
logger.info("Redirect test starting");
async = context.async();
RestAssuredClient c;
Response r;
Assert.assertNull("locationSampleDeployment", locationSampleDeployment);
Assert.assertNull("locationHeaderDeployment", locationHeaderDeployment);
final String testModJar = "../okapi-test-module/target/okapi-test-module-fat.jar";
final String docSampleModule1 = "{" + LS + " \"id\" : \"sample-module-1\"," + LS + " \"name\" : \"sample module 1\"," + LS + " \"provides\" : [ {" + LS + " \"id\" : \"sample\"," + LS + " \"interfaceType\" : \"proxy\"," + LS + " \"version\" : \"1.0\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"path\" : \"/testb\"" + LS + " } ]" + LS + " } ]," + LS + " \"launchDescriptor\" : {" + LS + " \"exec\" : \"java -Dport=%p -jar " + testModJar + "\"" + LS + " }" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docSampleModule1).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String locationSampleModule1 = r.getHeader("Location");
final String docSampleModule2 = "{" + LS + " \"id\" : \"sample-module-2\"," + LS + " \"name\" : \"sample module 2\"," + LS + " \"provides\" : [ {" + LS + " \"id\" : \"sample\"," + LS + " \"interfaceType\" : \"proxy\"," + LS + " \"version\" : \"1.0\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"path\" : \"/testb\"" + LS + " } ]" + LS + " } ]," + LS + " \"launchDescriptor\" : {" + LS + " \"exec\" : \"java -Dport=%p -jar " + testModJar + "\"" + LS + " }" + LS + "}";
// Create and deploy the sample module
r = c.given().header("Content-Type", "application/json").body(docSampleModule2).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String locationSampleModule2 = r.getHeader("Location");
final String locTenant = createTenant();
final String locEnable1 = enableModule("sample-module-1");
// Same interface defined twice.
final String docEnable2 = "{" + LS + " \"id\" : \"" + "sample-module-2" + "\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docEnable2).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(400).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants/" + okapiTenant + "/interfaces?full=true").then().statusCode(200).body(equalTo("[ {" + LS + " \"id\" : \"sample\"," + LS + " \"version\" : \"1.0\"," + LS + " \"interfaceType\" : \"proxy\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"path\" : \"/testb\"" + LS + " } ]" + LS + "} ]")).log().ifValidationFails();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants/" + okapiTenant + "/interfaces?full=false").then().statusCode(200).body(equalTo("[ {" + LS + " \"id\" : \"sample\"," + LS + " \"version\" : \"1.0\"" + LS + "} ]")).log().ifValidationFails();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants/" + okapiTenant + "/interfaces?full=false&type=proxy").then().statusCode(200).body(equalTo("[ {" + LS + " \"id\" : \"sample\"," + LS + " \"version\" : \"1.0\"" + LS + "} ]")).log().ifValidationFails();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants/" + okapiTenant + "/interfaces?full=false&type=system").then().statusCode(200).body(equalTo("[ ]")).log().ifValidationFails();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants/" + okapiTenant + "/interfaces/sample").then().statusCode(200).body(equalTo("[ {" + LS + " \"id\" : \"sample-module-1\"" + LS + "} ]")).log().ifValidationFails();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants/" + okapiTenant + "/interfaces/sample?type=proxy").then().statusCode(200).body(equalTo("[ {" + LS + " \"id\" : \"sample-module-1\"" + LS + "} ]")).log().ifValidationFails();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants/" + "foo" + "/interfaces/sample").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants/" + okapiTenant + "/interfaces/bar").then().statusCode(200).body(equalTo("[ ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
r = c.given().delete(locEnable1).then().statusCode(204).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
r = c.given().delete(locationSampleModule1).then().statusCode(204).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
r = c.given().delete(locationSampleModule2).then().statusCode(204).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String docSampleModule3 = "{" + LS + " \"id\" : \"sample-module-3\"," + LS + " \"name\" : \"sample module 3\"," + LS + " \"provides\" : [ {" + LS + " \"id\" : \"sample\"," + LS + " \"interfaceType\" : \"multiple\"," + LS + " \"version\" : \"1.0\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"path\" : \"/testb\"" + LS + " } ]" + LS + " } ]," + LS + " \"launchDescriptor\" : {" + LS + " \"exec\" : \"java -Dport=%p -jar " + testModJar + "\"" + LS + " }" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docSampleModule3).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String locationSampleModule3 = r.getHeader("Location");
final String docSampleModule4 = "{" + LS + " \"id\" : \"sample-module-4\"," + LS + " \"name\" : \"sample module 4\"," + LS + " \"provides\" : [ {" + LS + " \"id\" : \"sample\"," + LS + " \"interfaceType\" : \"multiple\"," + LS + " \"version\" : \"1.0\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\", \"POST\" ]," + LS + " \"path\" : \"/testb\"" + LS + " } ]" + LS + " } ]," + LS + " \"launchDescriptor\" : {" + LS + " \"exec\" : \"java -Dport=%p -jar " + testModJar + "\"," + LS + " \"env\" : [ {" + LS + " \"name\" : \"helloGreeting\"," + LS + " \"value\" : \"hej\"" + LS + " } ]" + LS + " }" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docSampleModule4).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String locationSampleModule4 = r.getHeader("Location");
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants/" + okapiTenant + "/interfaces/sample").then().statusCode(200).body(equalTo("[ ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String locEnable3 = enableModule("sample-module-3");
this.locationSampleDeployment = deployModule("sample-module-3");
final String locEnable4 = enableModule("sample-module-4");
this.locationHeaderDeployment = deployModule("sample-module-4");
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants/" + okapiTenant + "/interfaces/sample").then().statusCode(200).body(equalTo("[ {" + LS + " \"id\" : \"sample-module-3\"" + LS + "}, {" + LS + " \"id\" : \"sample-module-4\"" + LS + "} ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
given().header("X-Okapi-Tenant", okapiTenant).get("/testb").then().statusCode(404);
given().header("X-Okapi-Module-Id", "sample-module-u").header("X-Okapi-Tenant", okapiTenant).get("/testb").then().statusCode(404);
r = given().header("X-Okapi-Module-Id", "sample-module-3").header("X-all-headers", // makes module echo headers
"H").header("X-Okapi-Tenant", okapiTenant).get("/testb").then().statusCode(200).extract().response();
// check that X-Okapi-Module-Id was not passed to it
Assert.assertNull(r.headers().get("X-Okapi-Module-Id"));
given().header("X-Okapi-Module-Id", "sample-module-4").header("X-Okapi-Tenant", okapiTenant).get("/testb").then().statusCode(200);
given().header("X-Okapi-Module-Id", "sample-module-3").header("X-Okapi-Tenant", okapiTenant).body("OkapiX").post("/testb").then().log().ifValidationFails().statusCode(200).body(equalTo("Hello OkapiX"));
given().header("X-Okapi-Module-Id", "sample-module-4").header("X-Okapi-Tenant", okapiTenant).body("OkapiX").post("/testb").then().log().ifValidationFails().statusCode(200).body(equalTo("hej OkapiX"));
// cleanup
c = api.createRestAssured3();
r = c.given().delete(locEnable3).then().statusCode(204).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
r = c.given().delete(locEnable4).then().statusCode(204).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
r = c.given().delete(locationSampleModule3).then().statusCode(204).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
r = c.given().delete(locationSampleModule4).then().statusCode(204).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
r = c.given().delete(locationSampleDeployment).then().statusCode(204).extract().response();
locationSampleDeployment = null;
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
r = c.given().delete(locationHeaderDeployment).then().statusCode(204).extract().response();
locationHeaderDeployment = null;
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 ModuleTest method testOneModule.
/**
* Tests that declare one module. Declares a single module in many ways, often
* with errors. In the end the module gets deployed and enabled for a newly
* created tenant, and a request is made to it. Uses the test module, but not
* any auth module, that should be a separate test.
*
* @param context
*/
@Test
public void testOneModule(TestContext context) {
async = context.async();
RestAssuredClient c;
Response r;
checkDbIsEmpty("testOneModule starting", context);
// Get a list of the one built-in module, and nothing else.
c = api.createRestAssured3();
c.given().get("/_/proxy/modules").then().statusCode(200).body(equalTo("[ " + internalModuleDoc + " ]"));
Assert.assertTrue(c.getLastReport().isEmpty());
// Check that we refuse the request with a trailing slash
given().get("/_/proxy/modules/").then().statusCode(404);
given().get("/_/proxy/modules/no-module").then().statusCode(404);
// Check that we refuse the request to unknown okapi service
// (also check (manually!) that the parameters do not end in the log)
given().get("/_/foo?q=bar").then().statusCode(404);
// This is a good ModuleDescriptor. For error tests, some things get
// replaced out. Still some old-style fields here and there...
// Note the '+' in the id, it is valid semver, but may give problems
// in url-encoding things.
final String testModJar = "../okapi-test-module/target/okapi-test-module-fat.jar";
final String docSampleModule = "{" + LS + " \"id\" : \"sample-module-1+1\"," + LS + " \"name\" : \"sample 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 + " \"permissionsRequired\" : [ \"sample.needed\" ]," + LS + " \"permissionsDesired\" : [ \"sample.extra\" ]," + LS + " \"modulePermissions\" : [ \"sample.modperm\" ]" + LS + " } ]" + LS + " }, {" + LS + " \"id\" : \"recurse\"," + LS + " \"version\" : \"1.0\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"GET\" ]," + LS + " \"pathPattern\" : \"/recurse\"," + LS + " \"type\" : \"request-response-1.0\"" + LS + " } ]" + LS + " }, {" + LS + " \"id\" : \"_tenant\"," + LS + " \"version\" : \"1.0\"," + LS + " \"interfaceType\" : \"system\"," + LS + " \"handlers\" : [ {" + LS + " \"methods\" : [ \"POST\", \"DELETE\" ]," + LS + " \"path\" : \"/_/tenant\"," + LS + " \"level\" : \"10\"," + LS + " \"type\" : \"system\"" + // DEPRECATED, gives a warning
LS + " } ]" + LS + " } ]," + LS + " \"permissionSets\" : [ {" + LS + " \"permissionName\" : \"everything\"," + LS + " \"displayName\" : \"every possible permission\"," + LS + " \"description\" : \"All permissions combined\"," + LS + " \"subPermissions\" : [ \"sample.needed\", \"sample.extra\" ]" + LS + " } ]," + LS + " \"launchDescriptor\" : {" + LS + " \"exec\" : \"java -Dport=%p -jar " + testModJar + "\"" + LS + " }" + LS + "}";
// First some error checks
// Invalid Json, a hanging comma
String docHangingComma = docSampleModule.replace("system\"", "system\",");
given().header("Content-Type", "application/json").body(docHangingComma).post("/_/proxy/modules").then().statusCode(400);
// Bad module id
String docBadId = docSampleModule.replace("sample-module-1", "bad module id?!");
given().header("Content-Type", "application/json").body(docBadId).post("/_/proxy/modules").then().statusCode(400);
// Missing module id
given().header("Content-Type", "application/json").body("{\"name\" : \"sample-module\"}").post("/_/proxy/modules").then().statusCode(400);
// Empty module id
given().header("Content-Type", "application/json").body(docSampleModule.replace("\"sample-module-1+1\"", "\"\"")).post("/_/proxy/modules").then().statusCode(400);
// Bad interface type
String docBadIntType = docSampleModule.replace("system", "strange interface type");
given().header("Content-Type", "application/json").body(docBadIntType).post("/_/proxy/modules").then().statusCode(400);
// Bad RoutingEntry type
String docBadReType = docSampleModule.replace("request-response", "strange-re-type");
given().header("Content-Type", "application/json").body(docBadReType).post("/_/proxy/modules").then().statusCode(400);
String docMissingPath = docSampleModule.replace("/testb", "");
given().header("Content-Type", "application/json").body(docMissingPath).post("/_/proxy/modules").then().statusCode(400);
String docBadPathPat = docSampleModule.replace("/testb", // invalid characters in pattern
"/test.*b(/?)");
given().header("Content-Type", "application/json").body(docBadPathPat).post("/_/proxy/modules").then().statusCode(400);
String docbadRedir = docSampleModule.replace("request-response\"", "redirect\"");
given().header("Content-Type", "application/json").body(docbadRedir).post("/_/proxy/modules?check=false").then().statusCode(400);
// Actually create the module
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docSampleModule).post("/_/proxy/modules?check=true").then().statusCode(201).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String locSampleModule = r.getHeader("Location");
Assert.assertTrue(locSampleModule.equals("/_/proxy/modules/sample-module-1%2B1"));
locSampleModule = Utils.urlDecode(locSampleModule, false);
// Damn restAssured encodes the urls in get(), so we need to decode this here.
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// post it again.. Allowed because it is the same MD
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docSampleModule).post("/_/proxy/modules").then().statusCode(201).extract().response();
Assert.assertEquals(Utils.urlDecode(r.getHeader("Location"), false), locSampleModule);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// post it again with slight modification
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(docSampleModule.replace("sample.extra\"", "sample.foo\"")).post("/_/proxy/modules").then().statusCode(400).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
given().header("Content-Type", "application/json").body("{}").post("/_/discovery/modules").then().statusCode(400);
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body("{\"srvcId\" : \"\"}").post("/_/discovery/modules").then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body("{\"srvcId\" : \"1\"}").post("/_/discovery/modules").then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body("{\"srvcId\" : \"1\", \"nodeId\" : \"foo\"}").post("/_/discovery/modules").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// Get the module
c = api.createRestAssured3();
c.given().get(locSampleModule).then().statusCode(200).body(equalTo(docSampleModule));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// List the one module, and the built-in.
final String expOneModList = "[ {" + LS + " \"id\" : \"sample-module-1+1\"," + LS + " \"name\" : \"sample module\"" + LS + "}, " + internalModuleDoc + " ]";
c = api.createRestAssured3();
c.given().get("/_/proxy/modules").then().statusCode(200).body(equalTo(expOneModList));
Assert.assertTrue(c.getLastReport().isEmpty());
// Deploy the module - use the node name, not node id
final String docDeploy = "{" + LS + " \"instId\" : \"sample-inst\"," + LS + " \"srvcId\" : \"sample-module-1+1\"," + LS + // + " \"nodeId\" : \"localhost\"" + LS
" \"nodeId\" : \"node1\"" + LS + "}";
r = c.given().header("Content-Type", "application/json").body(docDeploy).post("/_/discovery/modules").then().statusCode(201).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
locationSampleDeployment = Utils.urlDecode(r.header("Location"), false);
// Create a tenant and enable the module
final String locTenant = createTenant();
final String locEnable = enableModule("sample-module-1+1");
// Try to enable a non-existing module
final String docEnableNonExisting = "{" + LS + " \"id\" : \"UnknownModule\"" + LS + "}";
given().header("Content-Type", "application/json").body(docEnableNonExisting).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(404).log().ifValidationFails();
// Make a simple request to the module
given().header("X-Okapi-Tenant", okapiTenant).get("/testb").then().statusCode(200).body(containsString("It works"));
given().header("X-Okapi-Tenant", okapiTenant).delete("/testb").then().statusCode(204).log().ifValidationFails();
// Make a more complex request that returns all headers and parameters
// So the headers we check are those that the module sees and reports to
// us, not necessarily those that Okapi would return to us.
given().header("X-Okapi-Tenant", okapiTenant).header("X-all-headers", // ask sample to report all headers
"H").get("/testb?query=foo&limit=10").then().statusCode(200).header("X-Okapi-Url", // no trailing slash!
"http://localhost:9230").header("X-Url-Params", "query=foo&limit=10").body(containsString("It works"));
// Check that the module can call itself recursively, 5 time
given().header("X-Okapi-Tenant", okapiTenant).get("/recurse?depth=5").then().statusCode(200).log().ifValidationFails().body(containsString("5 4 3 2 1 Recursion done"));
// Call the module via the redirect-url. No tenant header!
// The RAML can not express this way of calling things, so there can not be
// any tests for that...
given().get("/_/invoke/tenant/" + okapiTenant + "/testb").then().statusCode(200).body(containsString("It works"));
given().get("/_/invoke/tenant/" + okapiTenant + "/testb/foo/bar").then().statusCode(404);
given().header("X-all-headers", // ask sample to report all headers
"HB").get("/_/invoke/tenant/" + okapiTenant + "/testb?query=foo").then().log().ifValidationFails().header("X-Url-Params", "query=foo").statusCode(200);
given().header("Content-Type", "application/json").body("Testing testb").post("/_/invoke/tenant/" + okapiTenant + "/testb?query=foo").then().statusCode(200);
// double slash does not match invoke
given().header("Content-Type", "application/json").body("Testing testb").post("//_/invoke/tenant/" + okapiTenant + "/testb").then().statusCode(403);
// Check that the tenant API got called (exactly once)
given().header("X-Okapi-Tenant", okapiTenant).header("X-tenant-reqs", "yes").get("/testb").then().statusCode(200).body(equalTo("It works Tenant requests: POST-roskilde ")).log().ifValidationFails();
// Test a moduleDescriptor with empty arrays
// We have seen errors with such before.
final String docEmptyModule = "{" + LS + " \"id\" : \"empty-module-1.0\"," + LS + " \"name\" : \"empty module-1.0\"," + LS + " \"tags\" : [ ]," + LS + " \"requires\" : [ ]," + LS + " \"provides\" : [ ]," + LS + " \"filters\" : [ ]," + LS + " \"permissionSets\" : [ ]," + LS + " \"launchDescriptor\" : { }" + LS + "}";
// create the module - no need to deploy and use, it won't work.
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(docEmptyModule).post("/_/proxy/modules").then().statusCode(201).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String locEmptyModule = r.getHeader("Location");
final String locEnableEmpty = enableModule("empty-module-1.0");
// Create another empty module
final String docEmptyModule2 = docEmptyModule.replaceAll("empty-module-1.0", "empty-module-1.1");
final String locEmptyModule2 = createModule(docEmptyModule2);
// upgrade our tenant to use the new version
final String docEnableUpg = "{" + LS + " \"id\" : \"empty-module-1.1\"" + LS + "}";
final String locUpgEmpty = given().header("Content-Type", "application/json").body(docEnableUpg).post("/_/proxy/tenants/" + okapiTenant + "/modules/empty-module-1.0").then().statusCode(201).header("Location", "/_/proxy/tenants/roskilde/modules/empty-module-1.1").extract().header("Location");
// Clean up, so the next test starts with a clean slate (in reverse order)
logger.debug("testOneModule cleaning up");
given().delete(locUpgEmpty).then().log().ifValidationFails().statusCode(204);
given().delete(locEmptyModule2).then().log().ifValidationFails().statusCode(204);
given().delete(locEmptyModule).then().log().ifValidationFails().statusCode(204);
given().delete(locEnable).then().log().ifValidationFails().statusCode(204);
given().delete(locTenant).then().log().ifValidationFails().statusCode(204);
given().delete(locSampleModule).then().log().ifValidationFails().statusCode(204);
given().delete(locationSampleDeployment).then().log().ifValidationFails().statusCode(204);
locationSampleDeployment = null;
checkDbIsEmpty("testOneModule done", context);
async.complete();
}
Aggregations