Search in sources :

Example 16 with RestAssuredClient

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

the class DockerTest method dockerTest1.

@Test
public void dockerTest1(TestContext context) {
    Async async = context.async();
    logger.info("dockerTest1");
    RestAssuredClient c;
    Response r;
    RamlDefinition api = RamlLoaders.fromFile("src/main/raml").load("okapi.raml").assumingBaseUri("https://okapi.cloud");
    final String docSampleDockerModule = "{" + LS + "  \"id\" : \"sample-module-1\"," + LS + "  \"name\" : \"sample module\"," + LS + "  \"provides\" : [ {" + LS + "    \"id\" : \"sample\"," + LS + "    \"version\" : \"1.0.0\"," + LS + "    \"handlers\" : [ {" + LS + "      \"methods\" : [ \"GET\", \"POST\" ]," + LS + "      \"pathPattern\" : \"/testb\"" + LS + "    } ]" + LS + "  } ]," + LS + "  \"launchDescriptor\" : {" + LS + "    \"dockerImage\" : \"okapi-test-module\"," + LS + "    \"dockerPull\" : false," + LS + "    \"dockerCMD\" : [\"-Dfoo=bar\"]," + LS + "    \"dockerArgs\" : {" + LS + "      \"StopTimeout\" : 12," + LS + "      \"HostConfig\": { \"PortBindings\": { \"8080/tcp\": [{ \"HostPort\": \"%p\" }] } }" + LS + "    }" + LS + "  }" + LS + "}";
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").body(docSampleDockerModule).post("/_/proxy/modules").then().statusCode(201).log().ifValidationFails().extract().response();
    context.assertTrue(c.getLastReport().isEmpty(), "raml: " + c.getLastReport().toString());
    locations.add(r.getHeader("Location"));
    final String doc1 = "{" + LS + "  \"srvcId\" : \"sample-module-1\"," + LS + "  \"nodeId\" : \"localhost\"" + LS + "}";
    c = api.createRestAssured3();
    if (haveDocker) {
        r = c.given().header("Content-Type", "application/json").body(doc1).post("/_/discovery/modules").then().statusCode(201).extract().response();
        locations.add(r.getHeader("Location"));
    } else {
        c.given().header("Content-Type", "application/json").body(doc1).post("/_/discovery/modules").then().statusCode(400);
    }
    context.assertTrue(c.getLastReport().isEmpty(), "raml: " + c.getLastReport().toString());
    if (!haveDocker) {
        async.complete();
        return;
    }
    final String docUserDockerModule = "{" + LS + "  \"id\" : \"mod-users-1\"," + LS + "  \"name\" : \"users\"," + LS + "  \"provides\" : [ {" + LS + "    \"id\" : \"users\"," + LS + "    \"version\" : \"1.0.0\"," + LS + "    \"handlers\" : [ {" + LS + "      \"methods\" : [ \"GET\", \"POST\" ]," + LS + "      \"pathPattern\" : \"/test\"" + LS + "    } ]" + LS + "  } ]," + LS + "  \"launchDescriptor\" : {" + LS + "    \"dockerImage\" : \"folioci/mod-users:5.0.0-SNAPSHOT\"" + LS + "  }" + LS + "}";
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").body(docUserDockerModule).post("/_/proxy/modules").then().statusCode(201).extract().response();
    context.assertTrue(c.getLastReport().isEmpty(), "raml: " + c.getLastReport().toString());
    locations.add(r.getHeader("Location"));
    final String doc2 = "{" + LS + "  \"srvcId\" : \"mod-users-1\"," + LS + "  \"nodeId\" : \"localhost\"" + LS + "}";
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").body(doc2).post("/_/discovery/modules").then().statusCode(201).extract().response();
    context.assertTrue(c.getLastReport().isEmpty(), "raml: " + c.getLastReport().toString());
    locations.add(r.getHeader("Location"));
    async.complete();
}
Also used : Response(io.restassured.response.Response) Async(io.vertx.ext.unit.Async) RamlDefinition(guru.nidi.ramltester.RamlDefinition) RestAssuredClient(guru.nidi.ramltester.restassured3.RestAssuredClient) Test(org.junit.Test)

Example 17 with RestAssuredClient

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

the class HealthCheckTest method testHealthCheck.

@Test
public void testHealthCheck() {
    RestAssured.port = port;
    RestAssuredClient c;
    c = api.createRestAssured3();
    c.given().get("/_/proxy/health").then().log().ifValidationFails().statusCode(200);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    given().get("/_/proxy/health2").then().log().ifValidationFails().statusCode(404);
}
Also used : RestAssuredClient(guru.nidi.ramltester.restassured3.RestAssuredClient) Test(org.junit.Test)

Example 18 with RestAssuredClient

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

the class MainDeployTest method testProxyMode.

@Test
public void testProxyMode(TestContext context) {
    async = context.async();
    String[] args = { "proxy" };
    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 19 with RestAssuredClient

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

the class MainDeployTest method testDeploymentMode.

@Test
public void testDeploymentMode(TestContext context) {
    async = context.async();
    String[] args = { "deployment" };
    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("/_/deployment/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 20 with RestAssuredClient

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

the class ModuleTenantsTest method test1.

@Test
public void test1() {
    final String okapiTenant = "roskilde";
    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\" : [ ]," + 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(docBasic_1_0_0).post("/_/proxy/modules").then().statusCode(201).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    final String locationBasic_1_0_0 = r.getHeader("Location");
    // deploy basic 1.0.0
    final String docBasicDeployment_1_0_0 = "{" + LS + "  \"srvcId\" : \"basic-module-1.0.0\"," + LS + "  \"nodeId\" :  \"localhost\"" + LS + "}";
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").body(docBasicDeployment_1_0_0).post("/_/discovery/modules").then().statusCode(201).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    locationBasicDeployment_1_0_0 = r.getHeader("Location");
    // create sample 1.0.0
    final String docSample_1_0_0 = "{" + 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 + "  \"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(docSample_1_0_0).post("/_/proxy/modules").then().statusCode(201).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // deploy sample 1.0.0
    final String docSampleDeployment_1_0_0 = "{" + LS + "  \"srvcId\" : \"sample-module-1.0.0\"," + LS + "  \"nodeId\" : \"localhost\"" + LS + "}";
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").body(docSampleDeployment_1_0_0).post("/_/discovery/modules").then().statusCode(201).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    locationSampleDeployment_1_0_0 = r.getHeader("Location");
    // 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 docEnableSampleNoSemVer = "{" + LS + "  \"id\" : \"sample-module\"" + LS + "}";
    final String docEnableSample = "{" + LS + "  \"id\" : \"sample-module-1.0.0\"" + LS + "}";
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").body(docEnableSampleNoSemVer).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableSample)).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    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("Hello Okapi"));
    // create sample 1.2.0
    final String docSampleModule_1_2_0 = "{" + LS + "  \"id\" : \"sample-module-1.2.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\" : [ { \"id\" : \"bint\", \"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();
    r = c.given().header("Content-Type", "application/json").body(docSampleModule_1_2_0).post("/_/proxy/modules").then().statusCode(201).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // deploy sample 1.2.0
    final String docSampleDeployment_1_2_0 = "{" + LS + "  \"srvcId\" : \"sample-module-1.2.0\"," + LS + "  \"nodeId\" : \"localhost\"" + LS + "}";
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").body(docSampleDeployment_1_2_0).post("/_/discovery/modules").then().statusCode(201).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    locationSampleDeployment_1_2_0 = r.getHeader("Location");
    // Upgrade with bad JSON.
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("{").post(locationTenantModule).then().statusCode(400);
    // Upgrade from sample 1.0.0 to 1.2.0
    // supply the new ID in the body and the old ID in the header.
    final String docEnableSample2 = "{" + LS + "  \"id\" : \"sample-module-1.2.0\"" + LS + "}";
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body(docEnableSample2).post(locationTenantModule).then().statusCode(// FAIL because bint is not there
    400);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // remedy the situation by enabling basic 1.0.0 which provides bint
    final String docEnableBasic = "{" + LS + "  \"id\" : \"basic-module-1.0.0\"" + LS + "}";
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").body(docEnableBasic).post("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(201).body(equalTo(docEnableBasic)).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    String locationBasicTenantModule = r.getHeader("Location");
    // Upgrade from sample 1.0.0 to sample 1.2.0
    // supply the new ID in the body and the old ID in the header.
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").body(docEnableSample2).post(locationTenantModule).then().statusCode(201).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    locationTenantModule = r.getHeader("Location");
    // run new module
    c = api.createRestAssured3();
    c.given().header("X-Okapi-Tenant", okapiTenant).body("Okapi").post("/testb").then().statusCode(200).body(equalTo("Hello Okapi"));
    // undeploy basic should not work because it is used by sample 1.2.0
    c = api.createRestAssured3();
    r = c.given().header("Content-Type", "application/json").delete(locationBasicTenantModule).then().statusCode(400).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // undeploy sample 1.2.0 is OK
    c = api.createRestAssured3();
    r = c.given().delete(locationTenantModule).then().statusCode(204).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // undeploy basic is OK now
    c = api.createRestAssured3();
    r = c.given().delete(locationBasicTenantModule).then().statusCode(204).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // it's now gone
    c = api.createRestAssured3();
    c.given().header("X-Okapi-Tenant", okapiTenant).body("Okapi").post("/testb").then().statusCode(404);
    // nothing left
    c = api.createRestAssured3();
    c.given().get("/_/proxy/tenants/" + okapiTenant + "/modules").then().statusCode(200).body(equalTo("[ ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // upgrade service: nothing is installed yet
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").post("/_/proxy/tenants/" + okapiTenant + "/upgrade?simulate=true&preRelease=true").then().statusCode(200).body(equalTo("[ ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // enable modules -- wrong type
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("{ \"foo\" : \"bar\"}").post("/_/proxy/tenants/" + okapiTenant + "/install").then().statusCode(400);
    // enable modules -- bad JSON
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("{").post("/_/proxy/tenants/" + okapiTenant + "/install").then().statusCode(400);
    // enable modules: post unknown module with semver
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"sample-foo-1.2.3\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(404);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // enable modules: post unknown module without semver
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"sample-foo\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(404);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // enable modules: post known module with simulation
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"sample-module-1.0.0\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true&preRelease=false").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"sample-module-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // make sure sample-module-1.0.0 is not deployed anymore
    c = api.createRestAssured3();
    c.given().delete(locationSampleDeployment_1_0_0).then().statusCode(204);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    locationSampleDeployment_1_0_0 = null;
    // we simulated above.. This time for real
    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());
    // enable modules again: post known module
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"sample-module-1.0.0\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"sample-module-1.0.0\"," + LS + "  \"action\" : \"uptodate\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // upgrade from 1.0.0 to 1.2.0 - post known module which require basic
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"sample-module-1.2.0\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"basic-module-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"sample-module-1.2.0\"," + LS + "  \"from\" : \"sample-module-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // simulate upgrade modules: post module without version (product only)
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"sample-module\", \"action\" : \"enable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"basic-module-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"sample-module-1.2.0\"," + LS + "  \"from\" : \"sample-module-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // upgrade service: will return same as previous one
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").post("/_/proxy/tenants/" + okapiTenant + "/upgrade?simulate=false&deploy=true").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"basic-module-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"sample-module-1.2.0\"," + LS + "  \"from\" : \"sample-module-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // upgrade service: nothing to be done
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").post("/_/proxy/tenants/" + okapiTenant + "/upgrade?simulate=false&deploy=true").then().statusCode(200).body(equalTo("[ ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // create basic 2.0.0
    final String docBasic_2_0_0 = "{" + LS + "  \"id\" : \"basic-module-2.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\" : \"2.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(docBasic_2_0_0).post("/_/proxy/modules").then().statusCode(201).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    final String locationBasic_2_0_0 = r.getHeader("Location");
    // upgrade service simulate: will return same as previous one
    // basic 2.0.0 should not be included because bint 2.0 is not used
    // it could be nice to return conflict.. But that is difficult to do.
    // for now 400 ..
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").post("/_/proxy/tenants/" + okapiTenant + "/upgrade?simulate=true").then().statusCode(400);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // create sample 2.0.0
    final String docSampleModule_2_0_0 = "{" + LS + "  \"id\" : \"sample-module-2.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\" : [ { \"id\" : \"bint\", \"version\" : \"2.0\" } ]," + 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_2_0_0).post("/_/proxy/modules").then().statusCode(201).extract().response();
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // upgrade service: now bint 2.0 is in use
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").post("/_/proxy/tenants/" + okapiTenant + "/upgrade?simulate=false&deploy=true").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"basic-module-2.0.0\"," + LS + "  \"from\" : \"basic-module-1.0.0\"," + LS + "  \"action\" : \"enable\"" + LS + "}, {" + LS + "  \"id\" : \"sample-module-2.0.0\"," + LS + "  \"from\" : \"sample-module-1.2.0\"," + LS + "  \"action\" : \"enable\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    locationSampleDeployment_1_2_0 = null;
    locationBasicDeployment_1_0_0 = null;
    // try remove sample 1.0.0 which does not exist (removed earlier)
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"sample-module-1.2.0\", \"action\" : \"disable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(404);
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // simulate removal of sample
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"sample-module-2.0.0\", \"action\" : \"disable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"sample-module-2.0.0\"," + LS + "  \"action\" : \"disable\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // simulate removal of basic
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"basic-module-2.0.0\", \"action\" : \"disable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?simulate=true").then().statusCode(200).body(equalTo("[ {" + LS + "  \"id\" : \"sample-module-2.0.0\"," + LS + "  \"action\" : \"disable\"" + LS + "}, {" + LS + "  \"id\" : \"basic-module-2.0.0\"," + LS + "  \"action\" : \"disable\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    // removal of basic with product only (moduleId without version)
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").body("[ {\"id\" : \"basic-module\", \"action\" : \"disable\"} ]").post("/_/proxy/tenants/" + okapiTenant + "/install?deploy=true").then().statusCode(200).log().ifValidationFails().body(equalTo("[ {" + LS + "  \"id\" : \"sample-module-2.0.0\"," + LS + "  \"action\" : \"disable\"" + LS + "}, {" + LS + "  \"id\" : \"basic-module-2.0.0\"," + LS + "  \"action\" : \"disable\"" + LS + "} ]"));
    Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
    c = api.createRestAssured3();
    c.given().header("Content-Type", "application/json").get("/_/discovery/modules").then().statusCode(200).log().ifValidationFails().body(equalTo("[ ]"));
    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)

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