aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/java/fi/iki/elonen/HttpPutRequestTest.java
blob: 912113ea0108230f57c628cf712734a5ecabf817 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package fi.iki.elonen;

import org.junit.Test;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileReader;
import java.util.List;

import static junit.framework.Assert.*;

public class HttpPutRequestTest extends HttpServerTest {

    @Test
    public void testPutRequestSendsContent() throws Exception {
        ByteArrayOutputStream outputStream = invokeServer("PUT " + URI + " HTTP/1.1\r\n\r\nBodyData 1\nLine 2");

        String[] expectedOutput = {
                "HTTP/1.1 200 OK",
                "Content-Type: text/html",
                "Date: .*",
                "Connection: keep-alive",
                "Content-Length: 0",
                ""
        };

        assertResponse(outputStream, expectedOutput);

        assertTrue(testServer.files.containsKey("content"));
        BufferedReader reader = null;
        try {
            String[] expectedInputToServeMethodViaFile = {
                    "BodyData 1",
                    "Line 2"
            };
            reader = new BufferedReader(new FileReader(testServer.files.get("content")));
            List<String> lines = readLinesFromFile(reader);
            assertLinesOfText(expectedInputToServeMethodViaFile, lines);
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    }
}