Search in sources :

Example 1 with RamlDefinition

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

the class RamlTest method testOkapiRaml.

@Test
public void testOkapiRaml() {
    RamlDefinition api = RamlLoaders.fromFile("src/main/raml").load("okapi.raml");
    // Don't check Validation.DESCRIPTION
    RamlValidator v = api.validator().withChecks(Validation.URI_PARAMETER, Validation.PARAMETER, Validation.EMPTY);
    Assert.assertThat(v.validate(), validates());
}
Also used : RamlDefinition(guru.nidi.ramltester.RamlDefinition) RamlValidator(guru.nidi.ramltester.core.RamlValidator) Test(org.junit.Test)

Example 2 with RamlDefinition

use of guru.nidi.ramltester.RamlDefinition 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 3 with RamlDefinition

use of guru.nidi.ramltester.RamlDefinition in project openlmis-stockmanagement by OpenLMIS.

the class BaseWebIntegrationTest method init.

/**
 * Method called to initialize basic resources after the object is created.
 */
@PostConstruct
public void init() {
    mockExternalAuthorization();
    RestAssured.baseURI = BASE_URL;
    RestAssured.port = serverPort;
    RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory((clazz, charset) -> objectMapper));
    RamlDefinition ramlDefinition = RamlLoaders.fromClasspath().load("api-definition-raml.yaml").ignoringXheaders();
    restAssured = ramlDefinition.createRestAssured();
}
Also used : ObjectMapperConfig(com.jayway.restassured.config.ObjectMapperConfig) RamlDefinition(guru.nidi.ramltester.RamlDefinition) PostConstruct(javax.annotation.PostConstruct)

Aggregations

RamlDefinition (guru.nidi.ramltester.RamlDefinition)3 Test (org.junit.Test)2 ObjectMapperConfig (com.jayway.restassured.config.ObjectMapperConfig)1 RamlValidator (guru.nidi.ramltester.core.RamlValidator)1 RestAssuredClient (guru.nidi.ramltester.restassured3.RestAssuredClient)1 Response (io.restassured.response.Response)1 Async (io.vertx.ext.unit.Async)1 PostConstruct (javax.annotation.PostConstruct)1