-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add /coffee endpoint with 418 I'm a Teapot response - Implement Teapot class for handling /coffee requests. - Update HttpParser for path extraction. - Modify ClientHandler for /coffee response. - Add TeapotTest for endpoint testing. * Add /coffee endpoint with 418 I'm a Teapot response - Implement Teapot class for handling /coffee requests. - Update HttpParser for path extraction. - Modify ClientHandler for /coffee response. - Add TeapotTest for endpoint testing. * Add /coffee endpoint with 418 I'm a Teapot response - Implement Teapot class for handling /coffee requests. - Update HttpParser for path extraction. - Modify ClientHandler for /coffee response. - Add TeapotTest for endpoint testing. * Add /coffee endpoint with 418 I'm a Teapot response - Implement Teapot class for handling /coffee requests. - Update HttpParser for path extraction. - Modify ClientHandler for /coffee response. - Add TeapotTest for endpoint testing. --------- Co-authored-by: Martin Blomberg <martin.blomberg@outlook.com>
- Loading branch information
Showing
4 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/fungover/storm/filehandler/re/Teapot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.fungover.storm.filehandler.re; | ||
|
||
public class Teapot { | ||
|
||
|
||
public static boolean isCoffeeRequest(String requestPath) { | ||
return "/coffee".equals(requestPath); | ||
} | ||
|
||
|
||
public static byte[][] write418Response() { | ||
String response = "HTTP/1.1 418 I'm a Teapot\r\n" + | ||
"Content-Type: text/plain\r\n" + | ||
"Connection: close\r\n\r\n" + | ||
"418 I'm a teapot."; | ||
return new byte[][]{response.getBytes()}; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/org/fungover/storm/filehandler/re/TeapotTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.fungover.storm.filehandler.re; | ||
|
||
import org.fungover.storm.client.HttpParser; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import java.util.Map; | ||
|
||
public class TeapotTest { | ||
|
||
@Test | ||
public void testIsCoffeeRequest() { | ||
assertTrue(Teapot.isCoffeeRequest("/coffee")); | ||
assertFalse(Teapot.isCoffeeRequest("/tea")); | ||
} | ||
|
||
@Test | ||
public void testIsCoffeeRequestCaseSensitivity() { | ||
assertFalse(Teapot.isCoffeeRequest("/Coffee"), "Path matching should be case-sensitive."); | ||
} | ||
|
||
@Test | ||
public void testWrite418Response() { | ||
byte[][] response = Teapot.write418Response(); | ||
String responseString = new String(response[0]); | ||
|
||
assertTrue(responseString.startsWith("HTTP/1.1 418 I'm a Teapot"), "Response should start with 418 status code."); | ||
assertTrue(responseString.contains("418 I'm a teapot."), "Response should contain the teapot message."); | ||
} | ||
|
||
@Test | ||
public void testResponseContentType() { | ||
byte[][] response = Teapot.write418Response(); | ||
String responseHeaders = new String(response[0]); | ||
assertTrue(responseHeaders.contains("Content-Type: text/plain"), "Response should specify the correct content type."); | ||
} | ||
|
||
@Test | ||
public void testHttpRequestParsingForCoffee() { | ||
String httpRequest = "GET /coffee HTTP/1.1\r\nHost: localhost\r\n\r\n"; | ||
Map<String, String> parsedHeaders = HttpParser.getRequestHeaders(httpRequest); | ||
assertTrue(Teapot.isCoffeeRequest(parsedHeaders.get("path")), "The path should be correctly identified from an HTTP request."); | ||
} | ||
|
||
@Test | ||
public void testMalformedHttpRequest() { | ||
String malformedRequest = "GET /coffee"; | ||
Map<String, String> parsedHeaders = HttpParser.getRequestHeaders(malformedRequest); | ||
assertTrue(parsedHeaders.isEmpty(), "Malformed requests should not produce valid headers."); | ||
} | ||
} |