Search in sources :

Example 6 with Project

use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.

the class ProjectsControllerTest method testIndexed.

@Test
void testIndexed() throws IOException {
    String projectName = "mercurial";
    // When a project is added, it should be marked as not indexed.
    addProject(projectName);
    assertFalse(env.getProjects().get(projectName).isIndexed());
    // Get repository info for the project.
    Project project = env.getProjects().get(projectName);
    assertNotNull(project);
    List<RepositoryInfo> riList = env.getProjectRepositoriesMap().get(project);
    assertNotNull(riList);
    assertEquals(1, riList.size(), "there should be just 1 repository");
    RepositoryInfo ri = riList.get(0);
    assertNotNull(ri);
    assertTrue(ri.getCurrentVersion().contains("8b340409b3a8"));
    // Add some changes to the repository.
    File mercurialRoot = new File(repository.getSourceRoot() + File.separator + "mercurial");
    // copy file from jar to a temp file
    Path temp = Files.createTempFile("opengrok", "temp");
    Files.copy(HistoryGuru.getInstance().getClass().getResourceAsStream("/history/hg-export-subdir.txt"), temp, StandardCopyOption.REPLACE_EXISTING);
    // prevent 'uncommitted changes' error
    MercurialRepositoryTest.runHgCommand(mercurialRoot, "revert", "--all");
    MercurialRepositoryTest.runHgCommand(mercurialRoot, "import", temp.toString());
    assertTrue(temp.toFile().delete());
    // Test that the project's indexed flag becomes true only after
    // the message is applied.
    assertEquals(markIndexed(projectName).getStatusInfo().getFamily(), Response.Status.Family.SUCCESSFUL);
    assertTrue(env.getProjects().get(projectName).isIndexed(), "indexed flag should be set to true");
    // Test that the "indexed" message triggers refresh of current version
    // info in related repositories.
    riList = env.getProjectRepositoriesMap().get(project);
    assertNotNull(riList);
    ri = riList.get(0);
    assertNotNull(ri);
    assertTrue(ri.getCurrentVersion().contains("c78fa757c524"), "current version should be refreshed");
}
Also used : Path(java.nio.file.Path) Project(org.opengrok.indexer.configuration.Project) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) File(java.io.File) MercurialRepositoryTest(org.opengrok.indexer.history.MercurialRepositoryTest) Test(org.junit.jupiter.api.Test)

Example 7 with Project

use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.

the class FalsePluginTest method shouldNotAllowRandomUserForAnyProject.

@Test
void shouldNotAllowRandomUserForAnyProject() {
    DummyHttpServletRequest req = new DummyHttpServletRequest();
    req.setAttribute(UserPlugin.REQUEST_ATTR, new User(RandomStringUtils.randomAlphanumeric(8)));
    Project randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
    boolean projectAllowed = plugin.isAllowed(req, randomProject);
    assertFalse(projectAllowed, "should not allow rando for random project 1");
    randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
    projectAllowed = plugin.isAllowed(req, randomProject);
    assertFalse(projectAllowed, "should not allow rando for random project 2");
}
Also used : Project(org.opengrok.indexer.configuration.Project) User(opengrok.auth.plugin.entity.User) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 8 with Project

use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.

the class UserPluginTest method testUser.

@Test
public void testUser() {
    HttpServletRequest req;
    assertTrue(plugin.isAllowed(req = createRequest("007"), new Group()));
    assertEquals("007", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
    assertTrue(plugin.isAllowed(req = createRequest("008"), new Project()));
    assertEquals("008", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
    assertTrue(plugin.isAllowed(req = createRequest("009"), createGroup("some group")));
    assertEquals("009", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
    assertTrue(plugin.isAllowed(req = createRequest("00A"), createProject("some project")));
    assertEquals("00A", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Group(org.opengrok.indexer.configuration.Group) Project(org.opengrok.indexer.configuration.Project) Test(org.junit.jupiter.api.Test)

Example 9 with Project

use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.

the class UserPluginTest method createProject.

protected Project createProject(String name) {
    Project g = new Project();
    g.setName(name);
    return g;
}
Also used : Project(org.opengrok.indexer.configuration.Project)

Example 10 with Project

use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.

the class LdapAttrPluginTest method makeProject.

private Project makeProject(String name) {
    Project p = new Project();
    p.setName(name);
    return p;
}
Also used : Project(org.opengrok.indexer.configuration.Project)

Aggregations

Project (org.opengrok.indexer.configuration.Project)88 Test (org.junit.jupiter.api.Test)42 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)27 File (java.io.File)22 Group (org.opengrok.indexer.configuration.Group)20 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)17 ArrayList (java.util.ArrayList)16 TreeSet (java.util.TreeSet)11 IOException (java.io.IOException)10 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)10 List (java.util.List)8 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)7 Path (jakarta.ws.rs.Path)7 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)7 Path (java.nio.file.Path)6 Map (java.util.Map)6 Paths (java.nio.file.Paths)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 MercurialRepositoryTest (org.opengrok.indexer.history.MercurialRepositoryTest)5