-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests + request body caching preparations
- Loading branch information
Serhii Vydiuk
committed
Dec 17, 2024
1 parent
4cecca1
commit 8626bc4
Showing
8 changed files
with
194 additions
and
92 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.Collections; | ||
import java.util.Enumeration; | ||
import java.util.List; | ||
|
@@ -31,6 +34,9 @@ void setUp() { | |
adapter = new ServletDataPayloadAdapter(requestMock, responseMock); | ||
} | ||
|
||
|
||
// --------------------------- REQUEST -------------------------------- | ||
|
||
@Test | ||
void getRequestHeaders_HappyPath_ReturnsAllHeaders() { | ||
String usernameHeader = "X-User-Name".toLowerCase(); | ||
|
@@ -51,12 +57,44 @@ void getRequestHeaders_HappyPath_ReturnsAllHeaders() { | |
@Test | ||
void getRequestHeaders_NoHeaders_ReturnsEmptyMap() { | ||
when(requestMock.getHeaderNames()).thenReturn(Collections.emptyEnumeration()); | ||
|
||
Map<String, String> headers = adapter.getRequestHeaders(); | ||
|
||
assertTrue(headers.isEmpty()); | ||
} | ||
|
||
@Test | ||
void getRequestMethod_HappyPath_ReturnsCorrectMethod() { | ||
when(requestMock.getMethod()).thenReturn("POST"); | ||
String method = adapter.getRequestMethod(); | ||
|
||
assertEquals("POST", method); | ||
} | ||
|
||
@Test | ||
void getRequestContentType_HappyPath_ReturnsContentType() { | ||
when(requestMock.getContentType()).thenReturn("application/json"); | ||
String contentType = adapter.getRequestContentType(); | ||
|
||
assertEquals("application/json", contentType); | ||
} | ||
|
||
@Test | ||
void getRequestBody_HappyPath_ReturnsRequestBody() throws IOException { | ||
String requestBody = "{\"bird\": \"Owl\"}"; | ||
BufferedReader bufferedReader = new BufferedReader(new StringReader(requestBody)); | ||
when(requestMock.getReader()).thenReturn(bufferedReader); | ||
String result = adapter.getRequestBody(); | ||
|
||
assertEquals(requestBody, result); | ||
} | ||
|
||
@Test | ||
void getRequestBody_WhenIOExceptionOccurs_ReturnsEmptyString() throws IOException { | ||
when(requestMock.getReader()).thenThrow(new IOException("Failed to read request")); | ||
String result = adapter.getRequestBody(); | ||
|
||
assertEquals("", result); | ||
} | ||
|
||
// --------------------------- RESPONSE -------------------------------- | ||
@Test | ||
|
@@ -75,11 +113,24 @@ void getResponseHeaders_HappyPath_ReturnsAllHeaders() { | |
assertEquals("[email protected]", headers.get(userIdHeader)); | ||
} | ||
|
||
// TODO implement this, once it fails | ||
@Test | ||
void getResponseBody_ThrowsUnsupportedOperationException() { | ||
UnsupportedOperationException exception = assertThrows( | ||
UnsupportedOperationException.class, | ||
adapter::getResponseBody | ||
); | ||
|
||
assertEquals("Not implemented yet", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
void getResponseHeaders_NoHeaders_ReturnsEmptyMap() { | ||
when(responseMock.getHeaderNames()).thenReturn(Collections.emptyList()); | ||
|
||
Map<String, String> headers = adapter.getResponseHeaders(); | ||
|
||
assertTrue(headers.isEmpty()); | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.