Skip to content

Commit 5662137

Browse files
authored
increase coverage of PageConfig#getEtag() (#4863)
1 parent b5620ae commit 5662137

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public final class Configuration {
136136
private boolean authorizationWatchdogEnabled;
137137
private AuthorizationStack pluginStack;
138138
private Map<String, Project> projects; // project name -> Project
139-
private Map<String, Group> groups; // project name -> Group
139+
private Map<String, Group> groups; // group name -> Group
140140
private String sourceRoot;
141141
private String dataRoot;
142142
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.configuration;
@@ -2062,7 +2062,7 @@ public SortedSet<AcceptedMessage> getMessages(final String tag) {
20622062

20632063
/**
20642064
* Add a message to the application.
2065-
* Also schedules a expiration timer to remove this message after its expiration.
2065+
* Also schedules an expiration timer to remove this message after its expiration.
20662066
*
20672067
* @param message the message
20682068
*/

opengrok-web/src/test/java/org/opengrok/web/PageConfigTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@
3030
import java.nio.file.Files;
3131
import java.nio.file.Path;
3232
import java.nio.file.Paths;
33+
import java.time.Duration;
3334
import java.util.ArrayList;
3435
import java.util.Arrays;
36+
import java.util.Collections;
3537
import java.util.List;
3638
import java.util.Map;
3739
import java.util.Objects;
40+
import java.util.TreeMap;
3841
import java.util.stream.Collectors;
3942
import java.util.stream.Stream;
4043

@@ -56,6 +59,7 @@
5659
import org.opengrok.indexer.authorization.AuthorizationPlugin;
5760
import org.opengrok.indexer.authorization.TestPlugin;
5861
import org.opengrok.indexer.condition.EnabledForRepository;
62+
import org.opengrok.indexer.configuration.Group;
5963
import org.opengrok.indexer.configuration.IndexTimestamp;
6064
import org.opengrok.indexer.configuration.Project;
6165
import org.opengrok.indexer.configuration.RuntimeEnvironment;
@@ -69,6 +73,7 @@
6973
import org.opengrok.indexer.web.DummyHttpServletRequest;
7074
import org.opengrok.indexer.web.QueryParameters;
7175
import org.opengrok.indexer.web.SortOrder;
76+
import org.opengrok.indexer.web.messages.Message;
7277

7378
import static org.junit.jupiter.api.Assertions.assertAll;
7479
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -744,8 +749,26 @@ public String getPathInfo() {
744749

745750
@Test
746751
void testIsNotModifiedNotModified() {
752+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
753+
env.setProjectsEnabled(true);
754+
Map<String, Group> groups = new TreeMap<>();
755+
Map<String, Project> projects = new TreeMap<>();
756+
final String groupName = "test-group";
757+
final String projectName = "test-project";
758+
759+
// Add message for a project in a group to increase coverage of getEtag().
760+
groups.put(groupName, new Group(groupName, projectName));
761+
projects.put(projectName, new Project(projectName, "/mercurial"));
762+
env.setGroups(groups);
763+
env.setProjects(projects);
764+
env.addMessage(new Message("test",
765+
Collections.singleton(projectName),
766+
Message.MessageLevel.INFO,
767+
Duration.ofMinutes(100)));
768+
assertEquals(1, env.getMessages(projectName).size());
769+
747770
DummyHttpServletRequest req = mock(DummyHttpServletRequest.class);
748-
when(req.getPathInfo()).thenReturn("/");
771+
when(req.getPathInfo()).thenReturn("/mercurial/main.c");
749772
PageConfig cfg = PageConfig.get(req);
750773
final String etag = cfg.getEtag();
751774
when(req.getHeader(HttpHeaders.IF_NONE_MATCH)).thenReturn(etag);

0 commit comments

Comments
 (0)