Search in sources :

Example 81 with Project

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

the class ProjectHelperTest method testGetAllGroupedAllowedGroup.

/**
 * Test of getAllGrouped method, of class ProjectHelper.
 */
@Test
public void testGetAllGroupedAllowedGroup() {
    for (Group g : RuntimeEnvironment.getInstance().getGroups()) {
        if (g.getName().startsWith("allowed_group_0")) {
            Set<Project> result = helper.getAllGrouped(g);
            assertEquals(4, result.size());
            for (Project p : result) {
                assertTrue(p.getName().startsWith("allowed_"));
            }
        }
    }
}
Also used : Group(org.opengrok.indexer.configuration.Group) Project(org.opengrok.indexer.configuration.Project) Test(org.junit.jupiter.api.Test)

Example 82 with Project

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

the class ProjectHelperTest method testAllowedGetRepositoryInfo.

/**
 * Test of getRepositoryInfo method, of class ProjectHelper.
 */
@Test
public void testAllowedGetRepositoryInfo() {
    Project p = new Project("allowed_grouped_repository_0_1");
    p.setIndexed(true);
    List<RepositoryInfo> result = helper.getRepositoryInfo(p);
    assertEquals(1, result.size());
    assertEquals("allowed_grouped_repository_0_1_" + 0, result.get(0).getParent());
}
Also used : Project(org.opengrok.indexer.configuration.Project) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) Test(org.junit.jupiter.api.Test)

Example 83 with Project

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

the class ProjectHelperTest method testSynchronization.

/**
 * Test if projects and groups are always reloaded fully from the env.
 *
 * This ensures that when the RuntimeEnvironment changes that it also
 * updates the projects in the UI.
 */
@Test
public void testSynchronization() {
    HashMap<String, Project> oldProjects = new HashMap<>(env.getProjects());
    List<RepositoryInfo> oldRepositories = new ArrayList<>(env.getRepositories());
    Set<Group> oldGroups = new TreeSet<>(env.getGroups());
    Map<Project, List<RepositoryInfo>> oldMap = new TreeMap<>(getRepositoriesMap());
    env.getAuthorizationFramework().removeAll();
    // needed for setDirectoryName() below
    env.setSourceRoot("/src");
    cfg = PageConfig.get(getRequest());
    helper = cfg.getProjectHelper();
    // basic setup
    assertEquals(40, env.getProjects().size(), "There should be 40 env projects");
    assertEquals(20, env.getRepositories().size(), "There should be 20 env repositories");
    assertEquals(4, env.getGroups().size(), "There should be 4 env groups");
    assertEquals(8, helper.getAllUngrouped().size(), "There are 8 ungrouped projects");
    assertEquals(40, helper.getAllProjects().size(), "There are 40 projects");
    assertEquals(4, helper.getRepositories().size(), "There are 4 projects");
    assertEquals(4, helper.getGroups().size(), "There are 4 groups");
    // project
    Project p = new Project("some random name not in any group");
    p.setIndexed(true);
    // group
    Group g = new Group("some random name of a group");
    // repository
    Project repo = new Project("some random name not in any other group");
    repo.setIndexed(true);
    RepositoryInfo info = new RepoRepository();
    info.setParent(repo.getName());
    info.setDirectoryName(new File("/foo"));
    List<RepositoryInfo> infos = getRepositoriesMap().get(repo);
    if (infos == null) {
        infos = new ArrayList<>();
    }
    infos.add(info);
    getRepositoriesMap().put(repo, infos);
    env.getRepositories().add(info);
    env.getProjects().put("foo", p);
    env.getProjects().put("bar", repo);
    env.getGroups().add(g);
    assertEquals(42, env.getProjects().size());
    assertEquals(21, env.getRepositories().size());
    assertEquals(5, env.getGroups().size());
    // simulate another request
    cfg = PageConfig.get(getRequest());
    helper = cfg.getProjectHelper();
    // check for updates
    assertEquals(10, helper.getAllUngrouped().size(), "The helper state should refresh");
    assertEquals(42, helper.getAllProjects().size(), "The helper state should refresh");
    assertEquals(5, helper.getRepositories().size(), "The helper state should refresh");
    assertEquals(5, helper.getGroups().size(), "The helper state should refresh");
    setRepositoriesMap(oldMap);
    env.setProjects(oldProjects);
    env.setRepositories(oldRepositories);
    env.setGroups(oldGroups);
}
Also used : Group(org.opengrok.indexer.configuration.Group) HashMap(java.util.HashMap) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) ArrayList(java.util.ArrayList) RepoRepository(org.opengrok.indexer.history.RepoRepository) TreeMap(java.util.TreeMap) Project(org.opengrok.indexer.configuration.Project) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 84 with Project

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

the class ProjectHelperTest method testGetAllowedProjects.

/**
 * Test of getProjects method, of class ProjectHelper.
 */
@Test
public void testGetAllowedProjects() {
    Set<Project> result = helper.getProjects();
    assertEquals(2, result.size());
    for (Project p : result) {
        assertTrue(p.getName().startsWith("allowed_"));
    }
}
Also used : Project(org.opengrok.indexer.configuration.Project) Test(org.junit.jupiter.api.Test)

Example 85 with Project

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

the class ProjectHelperTest method testGetGroupedProjects.

/**
 * Test of getGroupedProjects method, of class ProjectHelper.
 */
@Test
public void testGetGroupedProjects() {
    Set<Project> result = helper.getGroupedProjects();
    assertEquals(4, result.size());
    for (Project p : result) {
        assertTrue(p.getName().startsWith("allowed_"));
    }
}
Also used : Project(org.opengrok.indexer.configuration.Project) Test(org.junit.jupiter.api.Test)

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