18
18
*/
19
19
20
20
/*
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.
22
22
* Portions Copyright (c) 2020, Chris Fraire <[email protected] >.
23
23
*/
24
24
package org .opengrok .web ;
50
50
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
51
51
import org .opengrok .indexer .history .Annotation ;
52
52
import org .opengrok .indexer .history .HistoryGuru ;
53
+ import org .opengrok .indexer .history .RepositoryFactory ;
54
+ import org .opengrok .indexer .index .Indexer ;
53
55
import org .opengrok .indexer .util .TestRepository ;
54
56
import org .opengrok .indexer .web .DummyHttpServletRequest ;
55
57
@@ -82,7 +84,7 @@ public static void tearDownClass() throws Exception {
82
84
}
83
85
84
86
@ Test
85
- public void testRequestAttributes () {
87
+ void testRequestAttributes () {
86
88
HttpServletRequest req = new DummyHttpServletRequest ();
87
89
PageConfig cfg = PageConfig .get (req );
88
90
@@ -112,7 +114,7 @@ public void testRequestAttributes() {
112
114
113
115
@ Test
114
116
@ EnabledForRepository (MERCURIAL )
115
- public void canProcessHistory () {
117
+ void canProcessHistory () {
116
118
// Expect no redirection (that is, empty string is returned) for a
117
119
// file that exists.
118
120
assertCanProcess ("" , "/source" , "/history" , "/mercurial/main.c" );
@@ -131,7 +133,7 @@ public void canProcessHistory() {
131
133
}
132
134
133
135
@ Test
134
- public void canProcessXref () {
136
+ void canProcessXref () {
135
137
// Expect no redirection (that is, empty string is returned) for a
136
138
// file that exists.
137
139
assertCanProcess ("" , "/source" , "/xref" , "/mercurial/main.c" );
@@ -154,7 +156,7 @@ public void canProcessXref() {
154
156
* Testing the root of /xref for authorization filtering.
155
157
*/
156
158
@ Test
157
- public void testGetResourceFileList () {
159
+ void testGetResourceFileList () {
158
160
RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
159
161
160
162
// backup original values
@@ -177,7 +179,7 @@ public void testGetResourceFileList() {
177
179
PageConfig cfg = PageConfig .get (req );
178
180
List <String > allFiles = new ArrayList <>(cfg .getResourceFileList ());
179
181
180
- /**
182
+ /*
181
183
* Check if there are some files (the "5" here is just a sufficient
182
184
* value for now which won't break any future repository tests) without
183
185
* any authorization.
@@ -186,7 +188,7 @@ public void testGetResourceFileList() {
186
188
assertTrue (allFiles .contains ("git" ));
187
189
assertTrue (allFiles .contains ("mercurial" ));
188
190
189
- /**
191
+ /*
190
192
* Now set up the same projects with authorization plugin enabling only
191
193
* some of them.
192
194
* <pre>
@@ -266,7 +268,7 @@ void testGetSortedFilesDirsFirst() throws IOException {
266
268
}
267
269
268
270
@ Test
269
- public void testGetIntParam () {
271
+ void testGetIntParam () {
270
272
String [] attrs = {"a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" };
271
273
int [] values = {1 , 100 , -1 , 2 , 200 , 3000 , -200 , 3000 };
272
274
DummyHttpServletRequest req = new DummyHttpServletRequest () {
@@ -302,7 +304,7 @@ public String getParameter(String name) {
302
304
}
303
305
304
306
@ Test
305
- public void testGetLatestRevisionValid () {
307
+ void testGetLatestRevisionValid () {
306
308
DummyHttpServletRequest req1 = new DummyHttpServletRequest () {
307
309
@ Override
308
310
public String getPathInfo () {
@@ -317,7 +319,40 @@ public String getPathInfo() {
317
319
}
318
320
319
321
@ 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 () {
321
356
DummyHttpServletRequest req1 = new DummyHttpServletRequest () {
322
357
@ Override
323
358
public String getPathInfo () {
@@ -343,7 +378,7 @@ public String getQueryString() {
343
378
}
344
379
345
380
@ Test
346
- public void testGetRevisionLocationNullQuery () {
381
+ void testGetRevisionLocationNullQuery () {
347
382
DummyHttpServletRequest req1 = new DummyHttpServletRequest () {
348
383
@ Override
349
384
public String getPathInfo () {
@@ -369,7 +404,7 @@ public String getQueryString() {
369
404
}
370
405
371
406
@ Test
372
- public void testGetLatestRevisionNotValid () {
407
+ void testGetLatestRevisionNotValid () {
373
408
DummyHttpServletRequest req2 = new DummyHttpServletRequest () {
374
409
@ Override
375
410
public String getPathInfo () {
@@ -383,7 +418,7 @@ public String getPathInfo() {
383
418
}
384
419
385
420
@ Test
386
- public void testGetRequestedRevision () {
421
+ void testGetRequestedRevision () {
387
422
final String [] revisions = {"6c5588de" , "" , "6c5588de" , "6c5588de" , "6c5588de" };
388
423
for (int i = 0 ; i < revisions .length ; i ++) {
389
424
final int index = i ;
@@ -409,7 +444,7 @@ public String getParameter(String name) {
409
444
}
410
445
411
446
@ Test
412
- public void testGetAnnotation () {
447
+ void testGetAnnotation () {
413
448
final String [] revisions = {"aa35c258" , "bb74b7e8" };
414
449
415
450
for (int i = 0 ; i < revisions .length ; i ++) {
@@ -464,7 +499,7 @@ public String getParameter(String name) {
464
499
* Test the case when the source root is null.
465
500
*/
466
501
@ Test
467
- public void testCheckSourceRootExistence1 () {
502
+ void testCheckSourceRootExistence1 () {
468
503
assertThrows (FileNotFoundException .class , () -> {
469
504
HttpServletRequest req = new DummyHttpServletRequest ();
470
505
PageConfig cfg = PageConfig .get (req );
@@ -484,7 +519,7 @@ public void testCheckSourceRootExistence1() {
484
519
* Test the case when source root is empty.
485
520
*/
486
521
@ Test
487
- public void testCheckSourceRootExistence2 () {
522
+ void testCheckSourceRootExistence2 () {
488
523
assertThrows (FileNotFoundException .class , () -> {
489
524
HttpServletRequest req = new DummyHttpServletRequest ();
490
525
PageConfig cfg = PageConfig .get (req );
@@ -504,7 +539,7 @@ public void testCheckSourceRootExistence2() {
504
539
* @throws IOException I/O exception
505
540
*/
506
541
@ Test
507
- public void testCheckSourceRootExistence3 () throws IOException {
542
+ void testCheckSourceRootExistence3 () throws IOException {
508
543
HttpServletRequest req = new DummyHttpServletRequest ();
509
544
PageConfig cfg = PageConfig .get (req );
510
545
String path = RuntimeEnvironment .getInstance ().getSourceRootPath ();
@@ -523,7 +558,7 @@ public void testCheckSourceRootExistence3() throws IOException {
523
558
*/
524
559
@ Test
525
560
@ EnabledOnOs ({OS .LINUX , OS .MAC , OS .SOLARIS , OS .AIX , OS .OTHER })
526
- public void testCheckSourceRootExistence4 () throws IOException {
561
+ void testCheckSourceRootExistence4 () throws IOException {
527
562
HttpServletRequest req = new DummyHttpServletRequest ();
528
563
PageConfig cfg = PageConfig .get (req );
529
564
String path = RuntimeEnvironment .getInstance ().getSourceRootPath ();
@@ -546,7 +581,7 @@ public void testCheckSourceRootExistence4() throws IOException {
546
581
* @throws IOException I/O exception
547
582
*/
548
583
@ Test
549
- public void testCheckSourceRootExistence5 () throws IOException {
584
+ void testCheckSourceRootExistence5 () throws IOException {
550
585
HttpServletRequest req = new DummyHttpServletRequest ();
551
586
PageConfig cfg = PageConfig .get (req );
552
587
String path = RuntimeEnvironment .getInstance ().getSourceRootPath ();
0 commit comments