예제 #1
0
  @Test
  public void testSplitRequestByLine() {
    String request = "GET / HTTP/1.1\n" + "Host: localhost:5000\n" + "Connection: keep-alive\n";
    BufferedReader bufferedReader = new BufferedReader(new StringReader(request));
    HashMap state = new HashMap();
    RequestHandler requestHandler = new RequestHandler(bufferedReader, state);
    List<String> parsedMessageHead = requestHandler.splitRequestByLine(request);

    assertEquals("GET / HTTP/1.1", parsedMessageHead.get(0));
    assertEquals("Host: localhost:5000", parsedMessageHead.get(1));
    assertEquals("Connection: keep-alive", parsedMessageHead.get(2));
  }
예제 #2
0
  @Test
  public void testMapMultipleFields() {
    String request = "Host: localhost:5000\n" + "Connection: keep-alive\n";
    BufferedReader bufferedReader = new BufferedReader(new StringReader(request));
    HashMap state = new HashMap();
    RequestHandler requestHandler = new RequestHandler(bufferedReader, state);
    ArrayList<String> splitRequest = requestHandler.splitRequestByLine(request);
    Map testMap = new HashMap();
    testMap.put("Host", "localhost:5000");
    testMap.put("Connection", "keep-alive");
    requestHandler.mapFields(splitRequest);

    assertEquals(testMap, requestHandler.getHeaderFields());
  }