Package com.gatehill.apibms.core.model

Examples of com.gatehill.apibms.core.model.ResourceDefinition


                // add resource headers
                final Map<String, String> parentHeaders = new HashMap<>();
                parentHeaders.putAll(asMap(astResource.getHeaders()));

                // build resource
                final ResourceDefinition resource = new ResourceDefinition(astResource.getName());
                resource.setName(astResource.getName());
                resource.setUrl(astResource.getUriTemplate());

                for (AstAction astAction : astResource.getActions()) {
                    // add action headers
                    parentHeaders.putAll(asMap(astAction.getHeaders()));
View Full Code Here


        // assert
        Assert.assertNotNull(actual);
        Assert.assertEquals("My API", actual.getName());
        Assert.assertEquals(1, actual.getEndpoints().size());

        final ResourceDefinition endpoint1 = actual.getEndpoints().get(0);
        Assert.assertNotNull(endpoint1);
        Assert.assertEquals("/message", endpoint1.getUrl());

        Assert.assertEquals(1, endpoint1.getRequests().size());
        final RequestDefinition request = endpoint1.getRequests().get(0);
        Assert.assertEquals("GET", request.getVerb());

        Assert.assertEquals(1, endpoint1.getResponses().size());
        final ResponseDefinition response = endpoint1.getResponses().get(HTTP_SC_OK);
        Assert.assertEquals(200, response.getCode());
        Assert.assertEquals("Hello World!\n", response.getBody());
    }
View Full Code Here

    public void testExecute() throws Exception {
        // test data
        final File jsonAst = new File(ExecutionServiceTest.class.getResource("/api1.json").getPath());

        final MockDefinition mock = new MockDefinition();
        mock.getEndpoints().add(new ResourceDefinition());

        final MockServer server = new MockServer(ServerService.HOST_LOCALHOST, PORT);

        // mock behaviour
        when(mockFactory.createMock(any(File.class), any(MockFactory.BlueprintFormat.class)))
View Full Code Here

        // assert
        Assert.assertNotNull(actual);
        Assert.assertEquals("My API", actual.getName());
        Assert.assertEquals(1, actual.getEndpoints().size());

        final ResourceDefinition endpoint1 = actual.getEndpoints().get(0);
        Assert.assertNotNull(endpoint1);
        Assert.assertEquals("/message", endpoint1.getUrl());

        Assert.assertEquals(1, endpoint1.getRequests().size());
        final RequestDefinition request = endpoint1.getRequests().get(0);
        Assert.assertEquals("GET", request.getVerb());

        Assert.assertEquals(1, endpoint1.getResponses().size());
        final ResponseDefinition response = endpoint1.getResponses().get(HTTP_SC_OK);

        // FIXME trailing \n is stripped off
        Assert.assertEquals("Hello World!", response.getBody());

        // verify behaviour
View Full Code Here

            final Node body = nodes.item(0);

            // build endpoint definitions
            if (body.hasChildNodes()) {
                ResourceDefinition currentEndpoint = null;

                for (int i = 0; i < body.getChildNodes().getLength(); i++) {
                    final Node child = body.getChildNodes().item(i);
                    LOGGER.debug("Found {}: {}", child.getNodeName(), child.getTextContent());

                    if (child.getNodeType() == Node.ELEMENT_NODE) {

                        // <h1>My API</h1>
                        if (isApiTitle(child.getNodeName())) {
                            definition.setName(child.getTextContent());
                            LOGGER.info("Found API: {}", definition.getName());
                        }

                        // <h2>GET /message</h2>
                        if (isEndpointHTTP(child.getNodeName())) {
                            // start of a new endpoint
                            currentEndpoint = new ResourceDefinition();
                            definition.addEndpoint(currentEndpoint);

                            LOGGER.info("Found endpoint: {}", currentEndpoint.getName());

                            final String[] http = child.getTextContent().split(" ");
                            currentEndpoint.setUrl(http[1]);

                            final RequestDefinition request = new RequestDefinition();
                            currentEndpoint.getRequests().add(request);
                            request.setVerb(http[0]);
                        }

                        // <ul><li><p>Response 200 (text/plain)</p>
                        if (isEndpointResponse(child.getNodeName())) {
                            final ResponseDefinition response = parseResponseDefinition(child);
                            populateResponseBody(response, child);
                            currentEndpoint.getResponses().put(response.getCode(), response);
                        }
                    }
                }
            }
View Full Code Here

TOP

Related Classes of com.gatehill.apibms.core.model.ResourceDefinition

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.