Package com.github.kristofa.test.http

Examples of com.github.kristofa.test.http.HttpRequest


    }

    @Test
    public void testReadValidRequestNoEntity() {

        final HttpRequest request =
            reader.read(new File(TEST_FILE_DIRECTORY, "HttpRequestFileReaderTest_valid_file.txt"), new File(
                "unexisting_file.txt"));
        assertEquals(Method.POST, request.getMethod());
        assertEquals("/a/b", request.getPath());
        final Set<HttpMessageHeader> httpMessageHeaders = request.getHttpMessageHeaders();
        assertEquals(2, httpMessageHeaders.size());
        assertTrue(httpMessageHeaders.contains(new HttpMessageHeader("Content-Type", "application/json; charset=UTF-8")));
        assertTrue(httpMessageHeaders.contains(new HttpMessageHeader("Agent", "Eclipse")));
        final Set<QueryParameter> queryParameters = request.getQueryParameters();
        assertEquals(3, queryParameters.size());
        assertTrue(queryParameters.contains(new QueryParameter("a", "b")));
        assertTrue(queryParameters.contains(new QueryParameter("a", "c")));
        assertTrue(queryParameters.contains(new QueryParameter("c", "d")));
        assertNull(request.getContent());
    }
View Full Code Here


    }

    @Test
    public void testReadValidRequestWithEntity() {

        final HttpRequest request =
            reader.read(new File(TEST_FILE_DIRECTORY, "HttpRequestFileReaderTest_valid_file.txt"), new File(
                TEST_FILE_DIRECTORY, "HttpRequestFileReaderTest_entity_valid_file.txt"));
        assertEquals(Method.POST, request.getMethod());
        assertEquals("/a/b", request.getPath());
        final Set<HttpMessageHeader> httpMessageHeaders = request.getHttpMessageHeaders();
        assertEquals(2, httpMessageHeaders.size());
        assertTrue(httpMessageHeaders.contains(new HttpMessageHeader("Content-Type", "application/json; charset=UTF-8")));
        assertTrue(httpMessageHeaders.contains(new HttpMessageHeader("Agent", "Eclipse")));
        final Set<QueryParameter> queryParameters = request.getQueryParameters();
        assertEquals(3, queryParameters.size());
        assertTrue(queryParameters.contains(new QueryParameter("a", "b")));
        assertTrue(queryParameters.contains(new QueryParameter("a", "c")));
        assertTrue(queryParameters.contains(new QueryParameter("c", "d")));
        assertNotNull(request.getContent());
    }
View Full Code Here

        assertNotNull(request.getContent());
    }

    @Test
    public void testReadValidRequestWithQueryParamWithEmptyValue() {
        final HttpRequest request =
            reader.read(new File(TEST_FILE_DIRECTORY, "HttpRequestFileReaderTest_empty_query_param_value.txt"), new File(
                TEST_FILE_DIRECTORY, "HttpRequestFileReaderTest_entity_valid_file.txt"));
        assertEquals(Method.POST, request.getMethod());
        assertEquals("/a/b", request.getPath());
        final Set<HttpMessageHeader> httpMessageHeaders = request.getHttpMessageHeaders();
        assertEquals(2, httpMessageHeaders.size());
        assertTrue(httpMessageHeaders.contains(new HttpMessageHeader("Content-Type", "application/json")));
        assertTrue(httpMessageHeaders.contains(new HttpMessageHeader("Agent", "Eclipse")));
        final Set<QueryParameter> queryParameters = request.getQueryParameters();
        assertEquals(3, queryParameters.size());
        assertTrue(queryParameters.contains(new QueryParameter("a", "b")));
        assertTrue(queryParameters.contains(new QueryParameter("a", "c")));
        assertTrue(queryParameters.contains(new QueryParameter("c", "")));
        assertNotNull(request.getContent());

    }
View Full Code Here

    private void submitRequest(final String fileName, final int seqNr) {

        final File requestFile = new File(directory, FileNameBuilder.REQUEST_FILE_NAME.getFileName(fileName, seqNr));
        final File requestEntityFile =
            new File(directory, FileNameBuilder.REQUEST_ENTITY_FILE_NAME.getFileName(fileName, seqNr));
        final HttpRequest request = httpRequestFileReader.read(requestFile, requestEntityFile);
        final FileHttpResponseProxy responseProxy =
            new FileHttpResponseProxy(directory, fileName, seqNr, httpResponseFileReader);
        addExpected(request, responseProxy);
    }
View Full Code Here

    @Test
    public void testFileHttpResponseProvider_NoSingleFileFound() {
        try {
            final FileHttpResponseProvider fileHttpResponseProvider =
                new FileHttpResponseProvider(TEST_FILE_DIRECTORY, "unexisting");
            final HttpRequest mockRequest = mock(HttpRequest.class);
            fileHttpResponseProvider.getResponse(mockRequest);
            fail("Expected exception.");
        } catch (final IllegalStateException e) {
            assertEquals(
                "No saved http request/responses found. File target/test-classes/unexisting_request_00001.txt not found.",
View Full Code Here

    @Test
    public void testFileHttpResponseProvider_NoResponseFileFound() {
        try {
            final FileHttpResponseProvider fileHttpResponseProvider =
                new FileHttpResponseProvider(TEST_FILE_DIRECTORY, "ExpectedHttpResponseFileProviderTest_No_Response");
            final HttpRequest mockRequest = mock(HttpRequest.class);
            fileHttpResponseProvider.getResponse(mockRequest);
            fail("Expected exception.");
        } catch (final IllegalStateException e) {
            assertEquals(
                "Found request file (target/test-classes/ExpectedHttpResponseFileProviderTest_No_Response_request_00001.txt) but no matching response file: target/test-classes/ExpectedHttpResponseFileProviderTest_No_Response_response_00001.txt",
View Full Code Here

        final HttpRequestMatchingFilter filter = new HttpRequestMatchingFilter() {

            @Override
            public HttpRequestMatchingContext filter(final HttpRequestMatchingContext context) {
                final HttpRequest originalRequest = context.originalRequest();
                final HttpRequest otherRequest = context.otherRequest();

                if (originalRequest.getPath().equals("/a/b")) {
                    final HttpRequestImpl copyOriginal = new HttpRequestImpl(originalRequest);
                    removeAllHeaderParams(copyOriginal);
                    final HttpRequestImpl copyOther = new HttpRequestImpl(otherRequest);
View Full Code Here

TOP

Related Classes of com.github.kristofa.test.http.HttpRequest

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.