Search in sources :

Example 6 with RepositoryInfo

use of org.opensolaris.opengrok.history.RepositoryInfo 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, List<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.setDirectoryName(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 7 with RepositoryInfo

use of org.opensolaris.opengrok.history.RepositoryInfo in project OpenGrok by OpenGrok.

the class ProjectHelperTestBase method getRepositoriesMap.

@SuppressWarnings("unchecked")
protected static Map<Project, List<RepositoryInfo>> getRepositoriesMap() {
    try {
        Field field = RuntimeEnvironment.class.getDeclaredField("repository_map");
        field.setAccessible(true);
        return (Map<Project, List<RepositoryInfo>>) field.get(RuntimeEnvironment.getInstance());
    } catch (Throwable ex) {
        Assert.fail("invoking getRepositoriesMap should not throw an exception");
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) RepositoryInfo(org.opensolaris.opengrok.history.RepositoryInfo) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 8 with RepositoryInfo

use of org.opensolaris.opengrok.history.RepositoryInfo 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() {
    List<Project> oldProjects = new ArrayList<>(env.getProjects());
    List<RepositoryInfo> oldRepositories = new ArrayList<>(env.getRepositories());
    Set<Group> oldGroups = new TreeSet<>(env.getGroups());
    Map<Project, List<RepositoryInfo>> oldMap = new TreeMap<>(getRepositoriesMap());
    invokeRemoveAll();
    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();
    p.setName("some random name not in any group");
    // group
    Group g = new Group();
    g.setName("some random name of a group");
    // repository
    Project repo = new Project();
    repo.setName("some random name not in any other group");
    RepositoryInfo info = new RepoRepository();
    info.setParent(repo.getName());
    info.setDirectoryName(null);
    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().add(p);
    env.getProjects().add(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) 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) Test(org.junit.Test)

Aggregations

RepositoryInfo (org.opensolaris.opengrok.history.RepositoryInfo)8 Project (org.opensolaris.opengrok.configuration.Project)6 Test (org.junit.Test)4 File (java.io.File)2 TreeMap (java.util.TreeMap)2 RepoRepository (org.opensolaris.opengrok.history.RepoRepository)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Group (org.opensolaris.opengrok.configuration.Group)1 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)1 HistoryException (org.opensolaris.opengrok.history.HistoryException)1 Repository (org.opensolaris.opengrok.history.Repository)1 TestRepository (org.opensolaris.opengrok.util.TestRepository)1