Package org.raml.model

Examples of org.raml.model.Resource


    }

    @Test
    public void noBody()
    {
        Resource resource = raml.getResource("/nobody");
        assertThat(resource.getAction(GET).getBody(), nullValue());
        assertThat(resource.getAction(GET).getResponses().get("200").getBody(), nullValue());
    }
View Full Code Here


    @Test
    public void resourceLikeBaseUriPath()
    {
        Raml raml = parseRaml(RAML);
        Resource resource = raml.getResource("/apis");
        assertThat(resource.getRelativeUri(), is("/apis"));
    }
View Full Code Here

    @Test
    public void parentUriTemplate()
    {
        Raml raml = parseRaml(RAML);

        Resource apiId = raml.getResource("/apis/{apiId}");
        assertThat(apiId.getUriParameters().size(), is(1));
        assertThat(apiId.getUriParameters().get("apiId").getType(), is(ParamType.STRING));

        Resource childId = raml.getResource("/apis/{apiId}/{childId}");
        assertThat(childId.getUriParameters().size(), is(1));
        assertThat(childId.getResolvedUriParameters().size(), is(2));
        assertThat(childId.getResolvedUriParameters().get("apiId").getType(), is(ParamType.STRING));
        assertThat(childId.getResolvedUriParameters().get("childId").getType(), is(ParamType.STRING));
    }
View Full Code Here

    @Test
    public void simple()
    {

        Resource simpleResource = raml.getResources().get("/simpleResource");
        assertThat(simpleResource.getActions().size(), is(1));
        assertThat(simpleResource.getAction(ActionType.GET).getDescription(), is("some description"));
    }
View Full Code Here

    }

    @Test
    public void optional()
    {
        Resource optionalResource = raml.getResources().get("/optionalResource");
        assertThat(optionalResource.getActions().size(), is(2));
        assertThat(optionalResource.getAction(ActionType.PUT).getDescription(), is("resource put description"));
        assertThat(optionalResource.getAction(ActionType.PUT).getBody().size(), is(2));
        assertThat(optionalResource.getAction(ActionType.PUT).getBody().containsKey("application/json"), is(true));
        assertThat(optionalResource.getAction(ActionType.PUT).getBody().containsKey("text/xml"), is(true));
        assertThat(optionalResource.getAction(ActionType.POST).getDescription(), is("post description"));
        assertThat(optionalResource.getAction(ActionType.POST).getBody().size(), is(1));
    }
View Full Code Here

    }

    @Test
    public void parameters()
    {
        Resource paramsResource = raml.getResources().get("/paramsResource");
        assertThat(paramsResource.getActions().size(), is(1));
        assertThat(paramsResource.getAction(ActionType.PATCH).getDescription(), is("homemade description"));

        Resource paramsResource2 = raml.getResources().get("/paramsResource2");
        assertThat(paramsResource2.getActions().size(), is(1));
        assertThat(paramsResource2.getAction(ActionType.DELETE).getDescription(), is("fine description"));
    }
View Full Code Here

    }

    @Test
    public void inheritance()
    {
        Resource inheritanceResource = raml.getResources().get("/inheritanceResource");
        assertThat(inheritanceResource.getActions().size(), is(2));
        assertThat(inheritanceResource.getAction(ActionType.GET).getDescription(), is("some description"));
        assertThat(inheritanceResource.getAction(ActionType.POST).getBody().size(), is(1));
        assertThat(inheritanceResource.getAction(ActionType.POST).getBody().containsKey("text/yaml"), is(true));
    }
View Full Code Here

        //resources
        assertThat(raml.getResources().size(), is(3));

        String rootUri = "/";
        Resource rootResource = raml.getResources().get(rootUri);
        assertThat(rootResource.getRelativeUri(), is(rootUri));
        assertThat(rootResource.getUri(), is(rootUri));
        assertThat(rootResource.getDisplayName(), is("Root resource"));
        assertThat(rootResource.getDescription(), is("Root resource description"));
        assertThat(rootResource.getAction(ActionType.HEAD).getProtocols().size(), is(1));
        assertThat(rootResource.getAction(ActionType.HEAD).getProtocols().get(0), is(HTTP));

        String mediaUri = "/media";
        Resource mediaResource = raml.getResources().get(mediaUri);
        assertThat(mediaResource.getRelativeUri(), is(mediaUri));
        assertThat(mediaResource.getUri(), is(mediaUri));
        assertThat(mediaResource.getDisplayName(), is("Media collection"));

        //actions
        assertThat(mediaResource.getActions().size(), is(2));
        Action action = mediaResource.getAction(ActionType.GET);
        assertThat(action.getType(), is(ActionType.GET));
        assertThat(action.getDescription(), is("retrieve media"));

        //action headers
        assertThat(action.getHeaders().size(), is(1));
        Header apiKeyHeader = action.getHeaders().get("api-key");
        assertThat(apiKeyHeader.getDisplayName(), is("Api key"));
        assertThat(apiKeyHeader.getDescription(), is("Api key description"));
        assertThat(apiKeyHeader.getType(), is(STRING));
        assertThat(apiKeyHeader.isRequired(), is(true));
        assertThat(apiKeyHeader.getMinLength(), is(10));
        assertThat(apiKeyHeader.getMaxLength(), is(10));
        assertThat(apiKeyHeader.getExample(), is("0123456789"));

        //action query parameters
        assertThat(action.getQueryParameters().size(), is(1));
        QueryParameter pageQueryParam = action.getQueryParameters().get("page");
        assertThat(pageQueryParam.getType(), is(INTEGER));
        assertThat(pageQueryParam.isRequired(), is(false));
        assertThat(pageQueryParam.getDefaultValue(), is("1"));
        assertThat(pageQueryParam.getMinimum(), is(new BigDecimal(1)));

        //action body types
        assertThat(action.getBody().size(), is(3));
        String jsonMime = "application/json";
        MimeType jsonBody = action.getBody().get(jsonMime);
        assertThat(jsonBody.getType(), is(jsonMime));
        assertThat(jsonBody.getSchema(), containsString("\"input\": {"));
        assertThat(jsonBody.getExample(), is("{ \"input\": \"hola\" }"));

        String formMime = "multipart/form-data";
        MimeType formBody = action.getBody().get(formMime);
        assertThat(formBody.getType(), is(formMime));
        assertThat(formBody.getFormParameters().size(), is(2));
        List<FormParameter> form1Param = formBody.getFormParameters().get("form-1");
        assertThat(form1Param.get(0).getDisplayName(), is("form 1"));
        assertThat(form1Param.get(0).getDescription(), is("form 1 description"));
        assertThat(form1Param.get(0).getType(), is(NUMBER));
        assertThat(form1Param.get(0).isRequired(), is(true));
        assertThat(form1Param.get(0).getMinimum(), is(new BigDecimal("9.5")));
        assertThat(form1Param.get(0).getMaximum(), is(new BigDecimal("10.5")));
        assertThat(form1Param.get(1).getType(), is(STRING));
        assertThat(form1Param.get(1).getEnumeration().size(), is(3));

        //action responses
        assertThat(action.getResponses().size(), is(3));
        Response response200 = action.getResponses().get("200");
        assertThat(response200.getBody().size(), is(1));
        assertThat(response200.getBody().get("application/json").getExample(), is("{ \"key\": \"value\" }"));
        assertThat(response200.getHeaders().size(), is(2));
        Response response400 = action.getResponses().get("400");
        assertThat(response400.getBody().size(), is(2));
        assertThat(response400.getBody().get("text/xml").getExample(), is("<root>none</root>"));
        assertThat(response400.getBody().get("text/plain").getType(), is("text/plain"));
        Response response404 = action.getResponses().get("404");
        assertThat(response404.getDescription(), is("not found"));

        //nested resource
        assertThat(mediaResource.getResources().size(), is(1));
        String mediaItemUri = "/{mediaId}";
        Resource mediaItemResource = mediaResource.getResource(mediaItemUri);
        assertThat(mediaItemResource.getRelativeUri(), is(mediaItemUri));
        assertThat(mediaItemResource.getUri(), is(mediaUri + mediaItemUri));
        assertThat(mediaItemResource.getDisplayName(), is("Media item"));
        assertThat(mediaItemResource.getActions().size(), is(1));
        assertThat(mediaItemResource.getUriParameters().size(), is(1));
        UriParameter mediaIdParam = mediaItemResource.getUriParameters().get("mediaId");
        assertThat(mediaIdParam.getType(), is(STRING));
        assertThat(mediaIdParam.getMaxLength(), is(10));

    }
View Full Code Here

TOP

Related Classes of org.raml.model.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.