Package org.raml.model.parameter

Examples of org.raml.model.parameter.UriParameter


        securityScheme.setDescribedBy(describedBy);
        securityScheme.setSettings(new SecuritySettings());

        Raml raml = new Raml();
        raml.setTitle("hi");
        raml.setBaseUriParameters(buildMap(new UriParameter()));
        raml.setDocumentation(Collections.singletonList(new DocumentationItem()));
        raml.setResources(buildMap(resource));
        raml.setProtocols(Collections.singletonList(Protocol.HTTP));
        raml.setResourceTypes(Collections.singletonList(buildMap(new Template())));
        raml.setTraits(Collections.singletonList(buildMap(new Template())));
View Full Code Here


    {
        Raml target = verifyDump(source, dump);

        //*********** URI PARAMETERS ***********

        UriParameter srcHost = source.getBaseUriParameters().get("host");
        UriParameter tgtHost = target.getBaseUriParameters().get("host");
        assertThat(tgtHost.getDisplayName(), is(srcHost.getDisplayName()));
        assertThat(tgtHost.getDescription(), is(srcHost.getDescription()));
        assertThat(tgtHost.getType(), is(srcHost.getType()));
        assertThat(tgtHost.getMinLength(), is(srcHost.getMinLength()));
        assertThat(tgtHost.getMaxLength(), is(srcHost.getMaxLength()));
        assertThat(tgtHost.getPattern(), is(srcHost.getPattern()));

        UriParameter srcPort = source.getBaseUriParameters().get("port");
        UriParameter tgtPort = target.getBaseUriParameters().get("port");
        assertThat(tgtPort.getType(), is(srcPort.getType()));
        assertThat(tgtPort.getMinimum(), is(srcPort.getMinimum()));
        assertThat(tgtPort.getMaximum(), is(srcPort.getMaximum()));

        UriParameter srcPath = source.getBaseUriParameters().get("path");
        UriParameter tgtPath = target.getBaseUriParameters().get("path");
        assertThat(tgtPath.getType(), is(srcPath.getType()));
        assertThat(tgtPath.getEnumeration().size(), is(srcPath.getEnumeration().size()));
        assertThat(tgtPath.getEnumeration().get(0), is(srcPath.getEnumeration().get(0)));
        assertThat(tgtPath.getEnumeration().get(1), is(srcPath.getEnumeration().get(1)));
        assertThat(tgtPath.getEnumeration().get(2), is(srcPath.getEnumeration().get(2)));

        //*********** DOCUMENTATION ***********

        List<DocumentationItem> srcDoc = source.getDocumentation();
        List<DocumentationItem> tgtDoc = target.getDocumentation();
View Full Code Here

        assertThat(tagUriParameters.size(), is(1));
        assertThat(tagUriParameters.get("tagId").getDisplayName(), is("tagId"));
        assertThat(tagUriParameters.get("tagId").isRequired(), is(true));
        assertThat(tagUriParameters.get("tagId").getType(), is(ParamType.STRING));

        UriParameter hostParam = raml.getBaseUriParameters().get("host");
        assertThat(hostParam.getDisplayName(), is("Host"));
        assertThat(hostParam.getDescription(), is("host name"));
        assertThat(hostParam.getType(), is(STRING));
        assertThat(hostParam.getMinLength(), is(5));
        assertThat(hostParam.getMaxLength(), is(10));
        assertThat(hostParam.getPattern(), is("[a-z]*"));

        UriParameter portParam = raml.getBaseUriParameters().get("port");
        assertThat(portParam.getType(), is(INTEGER));
        assertThat(portParam.getMinimum(), is(new BigDecimal(1025)));
        assertThat(portParam.getMaximum(), is(new BigDecimal(65535)));

        assertThat(hostParam.getType(), is(STRING));
        UriParameter pathParam = raml.getBaseUriParameters().get("path");
        assertThat(pathParam.getType(), is(STRING));
        assertThat(pathParam.getEnumeration().size(), is(3));
        assertThat(pathParam.getEnumeration().get(0), is("one"));
        assertThat(pathParam.getEnumeration().get(1), is("two"));
        assertThat(pathParam.getEnumeration().get(2), is("three"));

        //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

    @Test
    public void whenParameterIsYRequiredShouldBeTrue()
    {
        Raml raml = parseRaml(ramlSource);
        UriParameter uriParameter = raml.getBaseUriParameters().get("param2");
        assertThat(uriParameter.isRequired(), is(true));
    }
View Full Code Here

        while (matcher.find())
        {
            String paramName = matcher.group(1);
            if (!resource.getUriParameters().containsKey(paramName))
            {
                resource.getUriParameters().put(paramName, new UriParameter(paramName));
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.raml.model.parameter.UriParameter

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.