|
39 | 39 | import java.util.stream.Stream;
|
40 | 40 |
|
41 | 41 | import jakarta.servlet.http.HttpServletRequest;
|
| 42 | +import jakarta.servlet.http.HttpServletResponse; |
| 43 | +import jakarta.ws.rs.core.HttpHeaders; |
42 | 44 | import org.apache.commons.lang3.tuple.Pair;
|
43 | 45 | import org.junit.jupiter.api.AfterAll;
|
44 | 46 | import org.junit.jupiter.api.BeforeAll;
|
|
47 | 49 | import org.junit.jupiter.api.condition.OS;
|
48 | 50 | import org.junit.jupiter.params.ParameterizedTest;
|
49 | 51 | import org.junit.jupiter.params.provider.MethodSource;
|
| 52 | +import org.mockito.Mockito; |
50 | 53 | import org.opengrok.indexer.authorization.AuthControlFlag;
|
51 | 54 | import org.opengrok.indexer.authorization.AuthorizationFramework;
|
52 | 55 | import org.opengrok.indexer.authorization.AuthorizationPlugin;
|
|
68 | 71 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
69 | 72 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
70 | 73 | import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
| 74 | +import static org.mockito.ArgumentMatchers.eq; |
| 75 | +import static org.mockito.ArgumentMatchers.startsWith; |
71 | 76 | import static org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL;
|
72 | 77 | import static org.opengrok.indexer.history.LatestRevisionUtil.getLatestRevision;
|
73 | 78 |
|
@@ -647,4 +652,27 @@ public String getPathInfo() {
|
647 | 652 | }
|
648 | 653 | };
|
649 | 654 | }
|
| 655 | + |
| 656 | + @Test |
| 657 | + void testIsNotModified() { |
| 658 | + HttpServletRequest req = new DummyHttpServletRequest() { |
| 659 | + @Override |
| 660 | + public String getHeader(String name) { |
| 661 | + if (name.equals(HttpHeaders.IF_NONE_MATCH)) { |
| 662 | + return "foo"; // will not match the hash computed in |
| 663 | + } |
| 664 | + return null; |
| 665 | + } |
| 666 | + |
| 667 | + @Override |
| 668 | + public String getPathInfo() { |
| 669 | + return "path"; |
| 670 | + } |
| 671 | + }; |
| 672 | + |
| 673 | + PageConfig cfg = PageConfig.get(req); |
| 674 | + HttpServletResponse resp = Mockito.mock(HttpServletResponse.class); |
| 675 | + assertFalse(cfg.isNotModified(req, resp)); |
| 676 | + Mockito.verify(resp).setHeader(eq(HttpHeaders.ETAG), startsWith("W/")); |
| 677 | + } |
650 | 678 | }
|
0 commit comments