Search in sources :

Example 6 with RestAssuredClient

use of guru.nidi.ramltester.restassured3.RestAssuredClient 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();
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) Matchers.containsString(org.hamcrest.Matchers.containsString) RestAssuredClient(guru.nidi.ramltester.restassured3.RestAssuredClient)

Example 7 with RestAssuredClient

use of guru.nidi.ramltester.restassured3.RestAssuredClient 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();
}
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 8 with RestAssuredClient

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

the class ModuleTest method testInternalModule2.

private void testInternalModule2() {
    logger.info("testInternalModule 3");
    undeployFirst(x -> {
        conf.put("okapiVersion", "3.0.0");
        DeploymentOptions opt = new DeploymentOptions().setConfig(conf);
        vertx.deployVerticle(MainVerticle.class.getName(), opt, res -> {
            logger.info("testInternalModule 4");
            RestAssuredClient c;
            c = api.createRestAssured3();
            c.given().get("/_/proxy/tenants").then().statusCode(200).log().ifValidationFails().body(equalTo(superTenantDoc));
            Assert.assertTrue(c.getLastReport().isEmpty());
            conf.remove("okapiVersion");
            async.complete();
        });
    });
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) MainVerticle(org.folio.okapi.MainVerticle) RestAssuredClient(guru.nidi.ramltester.restassured3.RestAssuredClient)

Example 9 with RestAssuredClient

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

the class MainDeployTest method testClusterMode.

@Test
public void testClusterMode(TestContext context) {
    async = context.async();
    String[] args = { "cluster" };
    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("/_/proxy/modules").then().statusCode(200).log().ifValidationFails().extract().response();
        Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
        async.complete();
    });
}
Also used : Response(io.restassured.response.Response) MainDeploy(org.folio.okapi.MainDeploy) RestAssuredClient(guru.nidi.ramltester.restassured3.RestAssuredClient) Test(org.junit.Test)

Example 10 with RestAssuredClient

use of guru.nidi.ramltester.restassured3.RestAssuredClient 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();
    });
}
Also used : Response(io.restassured.response.Response) MainDeploy(org.folio.okapi.MainDeploy) 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