Search in sources :

Example 76 with Project

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

the class ProjectHelperTest method testGetAllGrouped.

/**
 * Test of getAllGrouped method, of class ProjectHelper.
 */
@Test
public void testGetAllGrouped() {
    Set<Project> result = helper.getAllGrouped();
    Assert.assertEquals(8, result.size());
    for (Project p : result) {
        Assert.assertTrue(p.getName().startsWith("allowed_"));
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) Test(org.junit.Test)

Example 77 with Project

use of org.opensolaris.opengrok.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
    Assert.assertEquals("There should be 40 env projects", 40, env.getProjects().size());
    Assert.assertEquals("There should be 20 env repositories", 20, env.getRepositories().size());
    Assert.assertEquals("There should be 4 env groups", 4, env.getGroups().size());
    Assert.assertEquals("There are 8 ungrouped projects", 8, helper.getAllUngrouped().size());
    Assert.assertEquals("There are 40 projects", 40, helper.getAllProjects().size());
    Assert.assertEquals("There are 4 projects", 4, helper.getRepositories().size());
    Assert.assertEquals("There are 4 groups", 4, helper.getGroups().size());
    // 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);
    env.register();
    Assert.assertEquals(42, env.getProjects().size());
    Assert.assertEquals(21, env.getRepositories().size());
    Assert.assertEquals(5, env.getGroups().size());
    // simulate another request
    cfg = PageConfig.get(getRequest());
    helper = cfg.getProjectHelper();
    // check for updates
    Assert.assertEquals("The helper state should refresh", 10, helper.getAllUngrouped().size());
    Assert.assertEquals("The helper state should refresh", 42, helper.getAllProjects().size());
    Assert.assertEquals("The helper state should refresh", 5, helper.getRepositories().size());
    Assert.assertEquals("The helper state should refresh", 5, helper.getGroups().size());
    setRepositoriesMap(oldMap);
    env.setProjects(oldProjects);
    env.setRepositories(oldRepositories);
    env.setGroups(oldGroups);
    env.register();
}
Also used : Group(org.opensolaris.opengrok.configuration.Group) HashMap(java.util.HashMap) RepositoryInfo(org.opensolaris.opengrok.history.RepositoryInfo) ArrayList(java.util.ArrayList) RepoRepository(org.opensolaris.opengrok.history.RepoRepository) TreeMap(java.util.TreeMap) Project(org.opensolaris.opengrok.configuration.Project) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 78 with Project

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

the class ProjectHelperTestBase method createRepository.

protected static Project createRepository(int index, int number, int cnt, boolean grouped, boolean allowed, List<RepositoryInfo> rps, Map<String, Project> prjs, Map<Project, List<RepositoryInfo>> map) {
    Project p = createProject(index, number, grouped, allowed, true, rps, prjs, map);
    for (int i = 0; i < cnt; i++) {
        RepositoryInfo info = new RepoRepository();
        info.setParent(p.getName() + "_" + i);
        info.setDirectoryNameRelative(p.getPath());
        rps.add(info);
        List<RepositoryInfo> infos = map.get(p);
        if (infos == null) {
            infos = new ArrayList<>();
        }
        infos.add(info);
        map.put(p, infos);
    }
    return p;
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RepositoryInfo(org.opensolaris.opengrok.history.RepositoryInfo) RepoRepository(org.opensolaris.opengrok.history.RepoRepository)

Example 79 with Project

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

the class SearchHelperTest method testPrepareExecInvalidInput.

@Test
public void testPrepareExecInvalidInput() {
    SortedSet<String> projectNames = new TreeSet<>();
    SearchHelper searchHelper;
    env.setProjectsEnabled(true);
    // Fake project addition to avoid reindex.
    Project project = new Project("c", "/c");
    env.getProjects().put("c", project);
    project = new Project("java", "/java");
    project.setIndexed(true);
    env.getProjects().put("java", project);
    // Try to prepare search for project that is not yet indexed.
    projectNames.add("c");
    projectNames.add("java");
    searchHelper = this.getSearchHelper("foobar").prepareExec(projectNames);
    Assert.assertNotNull(searchHelper.errorMsg);
    Assert.assertTrue(searchHelper.errorMsg.contains("not indexed"));
    Assert.assertFalse(searchHelper.errorMsg.contains("java"));
    // Try to prepare search for list that contains non-existing project.
    projectNames.add("totally_nonexistent_project");
    searchHelper = this.getSearchHelper("foobar").prepareExec(projectNames);
    Assert.assertNotNull(searchHelper.errorMsg);
    Assert.assertTrue(searchHelper.errorMsg.contains("invalid projects"));
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) TreeSet(java.util.TreeSet) Test(org.junit.Test) IndexerTest(org.opensolaris.opengrok.index.IndexerTest)

Aggregations

Project (org.opensolaris.opengrok.configuration.Project)79 Test (org.junit.Test)40 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)31 File (java.io.File)20 ArrayList (java.util.ArrayList)20 Group (org.opensolaris.opengrok.configuration.Group)17 RepositoryInfo (org.opensolaris.opengrok.history.RepositoryInfo)14 IOException (java.io.IOException)12 TreeSet (java.util.TreeSet)12 HistoryException (org.opensolaris.opengrok.history.HistoryException)8 List (java.util.List)6 ParseException (java.text.ParseException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Repository (org.opensolaris.opengrok.history.Repository)5 TestRepository (org.opensolaris.opengrok.util.TestRepository)5 ConnectException (java.net.ConnectException)4