Skip to content

Commit 58910f4

Browse files
committed
add message for better coverage of PageConfig#getEtag()
1 parent b5620ae commit 58910f4

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -85,6 +90,7 @@
8590
import static org.mockito.Mockito.when;
8691
import static org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL;
8792
import static org.opengrok.indexer.history.LatestRevisionUtil.getLatestRevision;
93+
import static org.opengrok.indexer.web.messages.MessagesContainer.MESSAGES_MAIN_PAGE_TAG;
8894

8995
/**
9096
* Unit tests for the {@code PageConfig} class.
@@ -744,8 +750,25 @@ public String getPathInfo() {
744750

745751
@Test
746752
void testIsNotModifiedNotModified() {
753+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
754+
env.setProjectsEnabled(true);
755+
Map<String, Group> groups = new TreeMap<>();
756+
Map<String, Project> projects = new TreeMap<>();
757+
final String groupName = "test-group";
758+
final String projectName = "test-project";
759+
760+
// Add message for a project in a group to increase coverage of getEtag().
761+
groups.put(groupName, new Group(groupName, projectName));
762+
projects.put(projectName, new Project(projectName, "/mercurial"));
763+
env.setGroups(groups);
764+
env.setProjects(projects);
765+
env.addMessage(new Message("test",
766+
Collections.singleton(projectName),
767+
Message.MessageLevel.INFO,
768+
Duration.ofMinutes(100)));
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)