Search in sources :

Example 21 with RestAssuredClient

use of guru.nidi.ramltester.restassured3.RestAssuredClient in project okapi by folio-org.

the class ModuleTenantsTest method test2.

@Test
public void test2() {
    final String okapiTenant = "roskilde";
    RestAssured.port = port;
    RestAssuredClient c;
    Response r;
    final String docMux = "{" + LS + "  \"id\" : \"basic-mux-1.0.0\"," + LS + "  \"name\" : \"this module\"," + LS + "  \"provides\" : [ {" + LS + "    \"id\" : \"myint\"," + LS + "    \"version\" : \"1.0\"," + LS + "    \"handlers\" : [ {" + LS + "      \"methods\" : [ \"GET\", \"POST\" ]," + LS + "      \"pathPattern\" : \"/foo\"" + 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(docMux).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    final String docMul1 = "{" + LS + "  \"id\" : \"basic-mul1-1.0.0\"," + LS + "  \"name\" : \"this module\"," + LS + "  \"provides\" : [ {" + LS + "    \"id\" : \"myint\"," + LS + "    \"version\" : \"1.0\"," + LS + "    \"interfaceType\" : \"multiple\"," + LS + "    \"handlers\" : [ {" + LS + "      \"methods\" : [ \"GET\", \"POST\" ]," + LS + "      \"pathPattern\" : \"/foo\"" + 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(docMul1).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    final String docMul2 = "{" + LS + "  \"id\" : \"basic-mul2-1.0.0\"," + LS + "  \"name\" : \"this module\"," + LS + "  \"provides\" : [ {" + LS + "    \"id\" : \"myint\"," + LS + "    \"version\" : \"1.0\"," + LS + "    \"interfaceType\" : \"multiple\"," + LS + "    \"handlers\" : [ {" + LS + "      \"methods\" : [ \"GET\", \"POST\" ]," + LS + "      \"pathPattern\" : \"/foo\"" + 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(docMul2).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().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");
    // install with mult first
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {" + LS + "  \"id\" : \"basic-mux-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"basic-mul1-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"basic-mul2-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + "  \"id\" : \"basic-mux-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"basic-mul1-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"basic-mul2-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("[ {" + LS + "  \"id\" : \"basic-mul1-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"basic-mul2-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"basic-mux-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + "  \"id\" : \"basic-mul1-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"basic-mul2-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"basic-mux-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
}
Also used : Response(io.restassured.response.Response) RestAssuredClient(guru.nidi.ramltester.restassured3.RestAssuredClient) Test(org.junit.Test)

Example 22 with RestAssuredClient

use of guru.nidi.ramltester.restassured3.RestAssuredClient in project okapi by folio-org.

the class PullTest method test3.

@Test
public void test3() {
    RestAssuredClient c;
    // pull frome dummy server
    final String pullPort3 = "{" + LS + "\"urls\" : [" + LS + "  \"http://localhost:" + port3 + "\"" + LS + "  ]" + LS + "}";
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").body(pullPort3).post("/_/proxy/pull/modules").then().statusCode(400).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // pull from non-existing server
    final String pullPort4 = "{" + LS + "\"urls\" : [" + LS + "  \"http://localhost:" + port4 + "\"" + LS + "  ]" + LS + "}";
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").body(pullPort4).post("/_/proxy/pull/modules").then().statusCode(404).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // first non-existing, then dummy
    final String pullBoth1 = "{" + LS + "\"urls\" : [" + LS + "  \"http://localhost:" + port3 + "\"," + LS + "  \"http://localhost:" + port4 + "\"" + LS + "  ]" + LS + "}";
    // pull from from both
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").body(pullBoth1).post("/_/proxy/pull/modules").then().statusCode(400).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // first dummy, then non-existing
    final String pullBoth2 = "{" + LS + "\"urls\" : [" + LS + "  \"http://localhost:" + port4 + "\"," + LS + "  \"http://localhost:" + port3 + "\"" + LS + "  ]" + LS + "}";
    // pull from from both
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").body(pullBoth2).post("/_/proxy/pull/modules").then().statusCode(400).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
}
Also used : RestAssuredClient(guru.nidi.ramltester.restassured3.RestAssuredClient) Test(org.junit.Test)

Example 23 with RestAssuredClient

use of guru.nidi.ramltester.restassured3.RestAssuredClient in project okapi by folio-org.

the class PullTest method test2.

@Test
public void test2() {
    RestAssuredClient c;
    final String pullDoc = "{" + LS + "\"urls\" : [" + LS + "  \"http://localhost:" + port1 + "\"" + LS + "  ]" + LS + "}";
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").body(pullDoc).post("/_/proxy/pull/modules").then().statusCode(200).log().ifValidationFails().body(equalTo("[ ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    final String docBriefModuleA = "{" + LS + "  \"id\" : \"module-a-1.0.0\"," + LS + "  \"name\" : \"A\"" + LS + "}";
    final String docModuleA = "{" + LS + "  \"id\" : \"module-a-1.0.0\"," + LS + "  \"name\" : \"A\"," + LS + "  \"provides\" : [ {" + LS + "    \"id\" : \"int-a\"," + LS + "    \"version\" : \"1.0\"" + LS + "  } ]," + LS + "  \"requires\" : [ ]" + LS + "}";
    c = api.createRestAssured3();
    c.given().port(port1).header("Content-Type", "application/json").body(docModuleA).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // list of the one module that's always there.
    final String internalModuleDoc = "[ {" + LS + "  \"id\" : \"okapi-0.0.0\"," + LS + "  \"name\" : \"Okapi\"" + LS + "} ]";
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules").then().statusCode(200).log().ifValidationFails().body(equalTo(internalModuleDoc));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").body(pullDoc).post("/_/proxy/pull/modules").then().statusCode(200).log().ifValidationFails().body(equalTo("[ " + docBriefModuleA + " ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    final String docModuleB = "{" + LS + "  \"id\" : \"module-b-1.0.0\"," + LS + "  \"name\" : \"B\"," + LS + "  \"provides\" : [ {" + LS + "    \"id\" : \"int-b\"," + LS + "    \"version\" : \"1.0\"" + LS + "  } ]," + LS + "  \"requires\" : [ {" + LS + "    \"id\" : \"int-a\"," + LS + "    \"version\" : \"1.0\"" + LS + "  } ]" + LS + "}";
    c = api.createRestAssured3();
    c.given().port(port1).header("Content-Type", "application/json").body(docModuleB).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    final String docModuleC = "{" + LS + "  \"id\" : \"module-c-1.0.0\"," + LS + "  \"name\" : \"C\"," + LS + "  \"provides\" : [ {" + LS + "    \"id\" : \"int-c\"," + LS + "    \"version\" : \"1.0\"" + LS + "  } ]," + LS + "  \"requires\" : [ {" + LS + "    \"id\" : \"int-b\"," + LS + "    \"version\" : \"1.0\"" + LS + "  } ]" + LS + "}";
    c = api.createRestAssured3();
    c.given().port(port1).header("Content-Type", "application/json").body(docModuleC).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // should get b and c
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").body(pullDoc).post("/_/proxy/pull/modules").then().statusCode(200).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").body(pullDoc).post("/_/proxy/pull/modules").then().statusCode(200).log().ifValidationFails().body(equalTo("[ ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules?orderBy=id&order=desc&preRelease=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + "  \"id\" : \"okapi-0.0.0\"," + LS + "  \"name\" : \"Okapi\"" + LS + "}, {" + LS + "  \"id\" : \"module-c-1.0.0\"," + LS + "  \"name\" : \"C\"" + LS + "}, {" + LS + "  \"id\" : \"module-b-1.0.0\"," + LS + "  \"name\" : \"B\"" + LS + "}, {" + LS + "  \"id\" : \"module-a-1.0.0\"," + LS + "  \"name\" : \"A\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules?orderBy=id&order=foo&preRelease=true").then().statusCode(400);
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules?orderBy=id&order=asc").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"module-a-1.0.0\"," + LS + "  \"name\" : \"A\"" + LS + "}, {" + LS + "  \"id\" : \"module-b-1.0.0\"," + LS + "  \"name\" : \"B\"" + LS + "}, {" + LS + "  \"id\" : \"module-c-1.0.0\"," + LS + "  \"name\" : \"C\"" + LS + "}, {" + LS + "  \"id\" : \"okapi-0.0.0\"," + LS + "  \"name\" : \"Okapi\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules?orderBy=bogus").then().statusCode(400);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // no RAML check below because preRelease value is invalid
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules?preRelease=sandt").then().statusCode(400);
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules?filter=module-c&orderBy=id").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"module-c-1.0.0\"," + LS + "  \"name\" : \"C\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules?filter=module-c-1").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"module-c-1.0.0\"," + LS + "  \"name\" : \"C\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules?filter=module-2").then().statusCode(200).body(equalTo("[ ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules?filter=module").then().statusCode(200).body(equalTo("[ ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().port(port2).header("Content-Type", "application/json").get("/_/proxy/modules?filter=foo").then().statusCode(200).body(equalTo("[ ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
}
Also used : RestAssuredClient(guru.nidi.ramltester.restassured3.RestAssuredClient) Test(org.junit.Test)

Example 24 with RestAssuredClient

use of guru.nidi.ramltester.restassured3.RestAssuredClient in project okapi by folio-org.

the class ModuleTest method testDiscoveryNodes.

/**
 * Test the various ways we can interact with /_/discovery/nodes.
 *
 * @param context
 */
@Test
public void testDiscoveryNodes(TestContext context) {
    async = context.async();
    RestAssuredClient c;
    Response r;
    checkDbIsEmpty("testDiscoveryNodes starting", context);
    String nodeListDoc = "[ {" + LS + "  \"nodeId\" : \"localhost\"," + LS + "  \"url\" : \"http://localhost:9230\"," + LS + "  \"nodeName\" : \"node1\"" + LS + "} ]";
    String nodeDoc = "{" + LS + "  \"nodeId\" : \"localhost\"," + LS + "  \"url\" : \"http://localhost:9230\"," + LS + "  \"nodeName\" : \"NewName\"" + LS + "}";
    c = api.createRestAssured3();
    c.given().get("/_/discovery/nodes").then().statusCode(200).body(equalTo(nodeListDoc));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().body(nodeDoc).header("Content-Type", "application/json").put("/_/discovery/nodes/localhost").then().log().ifValidationFails().statusCode(200);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().get("/_/discovery/nodes").then().statusCode(200).body(equalTo(nodeListDoc.replaceFirst("node1", "NewName"))).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // Test some bad PUTs
    c = api.createRestAssured3();
    c.given().body(nodeDoc).header("Content-Type", "application/json").put("/_/discovery/nodes/foobarhost").then().statusCode(404);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().body(nodeDoc.replaceFirst("\"localhost\"", "\"foobar\"")).header("Content-Type", "application/json").put("/_/discovery/nodes/localhost").then().statusCode(400);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().body(nodeDoc.replaceFirst("\"http://localhost:9230\"", "\"MayNotChangeUrl\"")).header("Content-Type", "application/json").put("/_/discovery/nodes/localhost").then().statusCode(400);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // Get it in various ways
    c = api.createRestAssured3();
    c.given().get("/_/discovery/nodes/localhost").then().statusCode(200).body(equalTo(nodeDoc)).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().get("/_/discovery/nodes/NewName").then().statusCode(200).body(equalTo(nodeDoc)).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().get("/_/discovery/nodes/http://localhost:9230").then().statusCode(// when testing with curl, you need use http%3A%2F%2Flocal...
    200).body(equalTo(nodeDoc)).log().ifValidationFails();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    checkDbIsEmpty("testDiscoveryNodes done", context);
    async.complete();
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) Matchers.containsString(org.hamcrest.Matchers.containsString) RestAssuredClient(guru.nidi.ramltester.restassured3.RestAssuredClient) Test(org.junit.Test)

Example 25 with RestAssuredClient

use of guru.nidi.ramltester.restassured3.RestAssuredClient in project okapi by folio-org.

the class ModuleTest method testUiModule.

@Test
public void testUiModule(TestContext context) {
    async = context.async();
    Response r;
    final String docUiModuleInput = "{" + LS + "  \"id\" : \"ui-1\"," + LS + "  \"name\" : \"sample-ui\"," + LS + "  \"uiDescriptor\" : {" + LS + "    \"npm\" : \"name-of-module-in-npm\"" + LS + "  }" + LS + "}";
    final String docUiModuleOutput = "{" + LS + "  \"id\" : \"ui-1\"," + LS + "  \"name\" : \"sample-ui\"," + LS + "  \"uiDescriptor\" : {" + LS + "    \"npm\" : \"name-of-module-in-npm\"" + LS + "  }" + LS + "}";
    RestAssuredClient c;
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").body(docUiModuleInput).post("/_/proxy/modules").then().statusCode(201).body(equalTo(docUiModuleOutput)).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    String location = r.getHeader("Location");
    c = api.createRestAssured3();
    c.given().get(location).then().statusCode(200).body(equalTo(docUiModuleOutput));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    given().delete(location).then().statusCode(204);
    checkDbIsEmpty("testUiModule done", context);
    async.complete();
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) Matchers.containsString(org.hamcrest.Matchers.containsString) RestAssuredClient(guru.nidi.ramltester.restassured3.RestAssuredClient) Test(org.junit.Test)

Aggregations

RestAssuredClient (guru.nidi.ramltester.restassured3.RestAssuredClient)30 Test (org.junit.Test)28 Response (io.restassured.response.Response)25 ValidatableResponse (io.restassured.response.ValidatableResponse)12 Matchers.containsString (org.hamcrest.Matchers.containsString)11 MainDeploy (org.folio.okapi.MainDeploy)4 DeploymentOptions (io.vertx.core.DeploymentOptions)2 JsonObject (io.vertx.core.json.JsonObject)2 MainVerticle (org.folio.okapi.MainVerticle)2 RamlDefinition (guru.nidi.ramltester.RamlDefinition)1 Header (io.restassured.http.Header)1 Headers (io.restassured.http.Headers)1 Async (io.vertx.ext.unit.Async)1