1818 */
1919
2020/*
21- * Copyright (c) 2011, 2021 , Oracle and/or its affiliates. All rights reserved.
21+ * Copyright (c) 2011, 2022 , Oracle and/or its affiliates. All rights reserved.
2222 * Portions Copyright (c) 2020, Chris Fraire <cfraire@me.com>.
2323 */
2424package org .opengrok .web ;
5050import org .opengrok .indexer .configuration .RuntimeEnvironment ;
5151import org .opengrok .indexer .history .Annotation ;
5252import org .opengrok .indexer .history .HistoryGuru ;
53+ import org .opengrok .indexer .history .RepositoryFactory ;
54+ import org .opengrok .indexer .index .Indexer ;
5355import org .opengrok .indexer .util .TestRepository ;
5456import org .opengrok .indexer .web .DummyHttpServletRequest ;
5557
@@ -82,7 +84,7 @@ public static void tearDownClass() throws Exception {
8284 }
8385
8486 @ Test
85- public void testRequestAttributes () {
87+ void testRequestAttributes () {
8688 HttpServletRequest req = new DummyHttpServletRequest ();
8789 PageConfig cfg = PageConfig .get (req );
8890
@@ -112,7 +114,7 @@ public void testRequestAttributes() {
112114
113115 @ Test
114116 @ EnabledForRepository (MERCURIAL )
115- public void canProcessHistory () {
117+ void canProcessHistory () {
116118 // Expect no redirection (that is, empty string is returned) for a
117119 // file that exists.
118120 assertCanProcess ("" , "/source" , "/history" , "/mercurial/main.c" );
@@ -131,7 +133,7 @@ public void canProcessHistory() {
131133 }
132134
133135 @ Test
134- public void canProcessXref () {
136+ void canProcessXref () {
135137 // Expect no redirection (that is, empty string is returned) for a
136138 // file that exists.
137139 assertCanProcess ("" , "/source" , "/xref" , "/mercurial/main.c" );
@@ -154,7 +156,7 @@ public void canProcessXref() {
154156 * Testing the root of /xref for authorization filtering.
155157 */
156158 @ Test
157- public void testGetResourceFileList () {
159+ void testGetResourceFileList () {
158160 RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
159161
160162 // backup original values
@@ -177,7 +179,7 @@ public void testGetResourceFileList() {
177179 PageConfig cfg = PageConfig .get (req );
178180 List <String > allFiles = new ArrayList <>(cfg .getResourceFileList ());
179181
180- /**
182+ /*
181183 * Check if there are some files (the "5" here is just a sufficient
182184 * value for now which won't break any future repository tests) without
183185 * any authorization.
@@ -186,7 +188,7 @@ public void testGetResourceFileList() {
186188 assertTrue (allFiles .contains ("git" ));
187189 assertTrue (allFiles .contains ("mercurial" ));
188190
189- /**
191+ /*
190192 * Now set up the same projects with authorization plugin enabling only
191193 * some of them.
192194 * <pre>
@@ -266,7 +268,7 @@ void testGetSortedFilesDirsFirst() throws IOException {
266268 }
267269
268270 @ Test
269- public void testGetIntParam () {
271+ void testGetIntParam () {
270272 String [] attrs = {"a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" };
271273 int [] values = {1 , 100 , -1 , 2 , 200 , 3000 , -200 , 3000 };
272274 DummyHttpServletRequest req = new DummyHttpServletRequest () {
@@ -302,7 +304,7 @@ public String getParameter(String name) {
302304 }
303305
304306 @ Test
305- public void testGetLatestRevisionValid () {
307+ void testGetLatestRevisionValid () {
306308 DummyHttpServletRequest req1 = new DummyHttpServletRequest () {
307309 @ Override
308310 public String getPathInfo () {
@@ -317,7 +319,40 @@ public String getPathInfo() {
317319 }
318320
319321 @ Test
320- public void testGetRevisionLocation () {
322+ void testGetLatestRevisionViaIndex () throws Exception {
323+ // Run the indexer.
324+ RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
325+ env .setSourceRoot (repository .getSourceRoot ());
326+ env .setDataRoot (repository .getDataRoot ());
327+ env .setProjectsEnabled (true );
328+ env .setHistoryEnabled (true );
329+ RepositoryFactory .initializeIgnoredNames (env );
330+
331+ Indexer indexer = Indexer .getInstance ();
332+ indexer .prepareIndexer (
333+ env ,
334+ true , // search for repositories
335+ true , // scan and add projects
336+ false , // don't create dictionary
337+ null , // subFiles - needed when refreshing history partially
338+ null ); // repositories - needed when refreshing history partially
339+ indexer .doIndexerExecution (true , null , null );
340+
341+ DummyHttpServletRequest req1 = new DummyHttpServletRequest () {
342+ @ Override
343+ public String getPathInfo () {
344+ return "/git/main.c" ;
345+ }
346+ };
347+
348+ PageConfig cfg = PageConfig .get (req1 );
349+ String rev = cfg .getLastRevFromIndex ();
350+ assertNotNull (rev );
351+ assertEquals ("aa35c258" , rev );
352+ }
353+
354+ @ Test
355+ void testGetRevisionLocation () {
321356 DummyHttpServletRequest req1 = new DummyHttpServletRequest () {
322357 @ Override
323358 public String getPathInfo () {
@@ -343,7 +378,7 @@ public String getQueryString() {
343378 }
344379
345380 @ Test
346- public void testGetRevisionLocationNullQuery () {
381+ void testGetRevisionLocationNullQuery () {
347382 DummyHttpServletRequest req1 = new DummyHttpServletRequest () {
348383 @ Override
349384 public String getPathInfo () {
@@ -369,7 +404,7 @@ public String getQueryString() {
369404 }
370405
371406 @ Test
372- public void testGetLatestRevisionNotValid () {
407+ void testGetLatestRevisionNotValid () {
373408 DummyHttpServletRequest req2 = new DummyHttpServletRequest () {
374409 @ Override
375410 public String getPathInfo () {
@@ -383,7 +418,7 @@ public String getPathInfo() {
383418 }
384419
385420 @ Test
386- public void testGetRequestedRevision () {
421+ void testGetRequestedRevision () {
387422 final String [] revisions = {"6c5588de" , "" , "6c5588de" , "6c5588de" , "6c5588de" };
388423 for (int i = 0 ; i < revisions .length ; i ++) {
389424 final int index = i ;
@@ -409,7 +444,7 @@ public String getParameter(String name) {
409444 }
410445
411446 @ Test
412- public void testGetAnnotation () {
447+ void testGetAnnotation () {
413448 final String [] revisions = {"aa35c258" , "bb74b7e8" };
414449
415450 for (int i = 0 ; i < revisions .length ; i ++) {
@@ -464,7 +499,7 @@ public String getParameter(String name) {
464499 * Test the case when the source root is null.
465500 */
466501 @ Test
467- public void testCheckSourceRootExistence1 () {
502+ void testCheckSourceRootExistence1 () {
468503 assertThrows (FileNotFoundException .class , () -> {
469504 HttpServletRequest req = new DummyHttpServletRequest ();
470505 PageConfig cfg = PageConfig .get (req );
@@ -484,7 +519,7 @@ public void testCheckSourceRootExistence1() {
484519 * Test the case when source root is empty.
485520 */
486521 @ Test
487- public void testCheckSourceRootExistence2 () {
522+ void testCheckSourceRootExistence2 () {
488523 assertThrows (FileNotFoundException .class , () -> {
489524 HttpServletRequest req = new DummyHttpServletRequest ();
490525 PageConfig cfg = PageConfig .get (req );
@@ -504,7 +539,7 @@ public void testCheckSourceRootExistence2() {
504539 * @throws IOException I/O exception
505540 */
506541 @ Test
507- public void testCheckSourceRootExistence3 () throws IOException {
542+ void testCheckSourceRootExistence3 () throws IOException {
508543 HttpServletRequest req = new DummyHttpServletRequest ();
509544 PageConfig cfg = PageConfig .get (req );
510545 String path = RuntimeEnvironment .getInstance ().getSourceRootPath ();
@@ -523,7 +558,7 @@ public void testCheckSourceRootExistence3() throws IOException {
523558 */
524559 @ Test
525560 @ EnabledOnOs ({OS .LINUX , OS .MAC , OS .SOLARIS , OS .AIX , OS .OTHER })
526- public void testCheckSourceRootExistence4 () throws IOException {
561+ void testCheckSourceRootExistence4 () throws IOException {
527562 HttpServletRequest req = new DummyHttpServletRequest ();
528563 PageConfig cfg = PageConfig .get (req );
529564 String path = RuntimeEnvironment .getInstance ().getSourceRootPath ();
@@ -546,7 +581,7 @@ public void testCheckSourceRootExistence4() throws IOException {
546581 * @throws IOException I/O exception
547582 */
548583 @ Test
549- public void testCheckSourceRootExistence5 () throws IOException {
584+ void testCheckSourceRootExistence5 () throws IOException {
550585 HttpServletRequest req = new DummyHttpServletRequest ();
551586 PageConfig cfg = PageConfig .get (req );
552587 String path = RuntimeEnvironment .getInstance ().getSourceRootPath ();
0 commit comments