Package com.gatehill.apibms.core.model

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


     * @param parentHeaders
     * @return
     */
    private void buildResponses(Map<String, String> parentHeaders, ResourceDefinition resource, AstTransactionExample example) {
        for (AstResponse astResponse : example.getResponses()) {
            final ResponseDefinition response = new ResponseDefinition();
            response.setCode(Integer.valueOf(astResponse.getName()));
            response.setBody(astResponse.getBody());

            // add headers from parent and response definition
            final Map<String, String> headers = new HashMap<>();
            headers.putAll(parentHeaders);
            headers.putAll(asMap(astResponse.getHeaders()));
            response.setHeaders(headers);

            resource.getResponses().put(response.getCode(), response);
        }

        LOGGER.debug("Built {} response(s) from example", resource.getResponses().size());
        LOGGER.trace("Got all responses: {}", resource.getResponses());
    }
View Full Code Here


        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

        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
        verify(parsingService, times(1)).parseMarkdownFile(any(File.class));
        verify(parsingService, times(1)).toXhtmlDocument(anyString());
        verifyNoMoreInteractions(parsingService);
View Full Code Here

                            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

        }

        final Node p = nodes.item(0);

        // build definition
        final ResponseDefinition response = new ResponseDefinition();

        final String textContent = p.getTextContent().trim();
        final String[] responseCode = textContent.split(" ");
        if (!"Response".equals(responseCode[0])) {
            throw new ServiceException("Response definition should start with 'Response'");
        }

        // HTTP response code
        response.setCode(Integer.parseInt(responseCode[1]));

        // check for MIME type
        String restOfLine = textContent.substring(
                textContent.indexOf(response.getCode()) + responseCode[1].length());

        if (restOfLine.length() > 0) {
            restOfLine = restOfLine.trim();
            if (restOfLine.startsWith("(")) {
                restOfLine = restOfLine.substring(1);
            }
            if (restOfLine.endsWith(")")) {
                restOfLine = restOfLine.substring(0, restOfLine.length() - 1);
            }

            response.getHeaders().put(CONTENT_TYPE_STRING, restOfLine);
        }

        return response;
    }
View Full Code Here

TOP

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

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.