Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Oct 27, 2024
1 parent 9a030b2 commit 04bb3ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ public static String extractDate(HttpServletRequest request) {
* @return the resource path
*/
public static String extractResourcePath(HttpServletRequest request) {
if (request == null || request.getServletPath().length() <= 3) {
if (request == null || request.getRequestURI().length() <= 3) {
return "";
}
// get request path, strip first slash '/'
String uri = request.getServletPath().substring(1);
String uri = request.getRequestURI().substring(1);
// skip to the end of API version prefix '/v1/'
int start = uri.indexOf('/');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.AfterAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand Down Expand Up @@ -188,27 +188,27 @@ public void testExtractAccessKey() {
@Test
public void testExtractResourcePath() {
HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
Mockito.when(req.getServletPath()).thenReturn("");
Mockito.when(req.getRequestURI()).thenReturn("");
assertEquals(extractResourcePath(null), "");
assertEquals(extractResourcePath(req), "");

Mockito.when(req.getServletPath()).thenReturn("/v1");
Mockito.when(req.getRequestURI()).thenReturn("/v1");
assertEquals("", extractResourcePath(req));

Mockito.when(req.getServletPath()).thenReturn("/v1/");
Mockito.when(req.getRequestURI()).thenReturn("/v1/");
assertEquals("", extractResourcePath(req));

Mockito.when(req.getServletPath()).thenReturn("/v1/_");
Mockito.when(req.getRequestURI()).thenReturn("/v1/_");
assertEquals("_", extractResourcePath(req));

Mockito.when(req.getServletPath()).thenReturn("/v1/_test");
Mockito.when(req.getRequestURI()).thenReturn("/v1/_test");
assertEquals("_test", extractResourcePath(req));

Mockito.when(req.getServletPath()).thenReturn("/v1/_test/path/id");
Mockito.when(req.getRequestURI()).thenReturn("/v1/_test/path/id");
assertEquals("_test/path/id", extractResourcePath(req));

// new feature - specific resource paths
Mockito.when(req.getServletPath()).thenReturn("/v2.0/posts/123");
Mockito.when(req.getRequestURI()).thenReturn("/v2.0/posts/123");
assertEquals("posts/123", extractResourcePath(req));
}

Expand Down

0 comments on commit 04bb3ed

Please sign in to comment.