Search in sources :

Example 6 with Group

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

the class ProjectHelperExtendedTest method testHasAllowedSubgroupAllowedNoSubgroups.

@Test
public void testHasAllowedSubgroupAllowedNoSubgroups() {
    Group g = getAllowedGroupWithoutSubgroups();
    assertFalse(helper.hasAllowedSubgroup(g));
}
Also used : Group(org.opengrok.indexer.configuration.Group) Test(org.junit.jupiter.api.Test)

Example 7 with Group

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

the class ProjectHelperExtendedTest method testGetAllowedGroupSubgroups.

@Test
public void testGetAllowedGroupSubgroups() {
    Set<Group> result = helper.getSubgroups(getAllowedGroupWithSubgroups());
    assertEquals(1, result.size());
    for (Group p : result) {
        assertTrue(p.getName().startsWith("allowed_"));
    }
}
Also used : Group(org.opengrok.indexer.configuration.Group) Test(org.junit.jupiter.api.Test)

Example 8 with Group

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

the class ProjectHelperExtendedTest method testHasAllowedSubgroupUnAllowedNoSubgroups.

@Test
public void testHasAllowedSubgroupUnAllowedNoSubgroups() {
    Group g = getUnAllowedGroupWithoutSubgroups();
    assertFalse(helper.hasAllowedSubgroup(g));
}
Also used : Group(org.opengrok.indexer.configuration.Group) Test(org.junit.jupiter.api.Test)

Example 9 with Group

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

the class PluginClassLoaderTest method testFalsePlugin.

@Test
public void testFalsePlugin() {
    PluginClassLoader instance = new PluginClassLoader(pluginDirectory);
    Class<?> clazz = loadClass(instance, "opengrok.auth.plugin.FalsePlugin");
    IAuthorizationPlugin plugin = getNewInstance(clazz);
    Group g = new Group("group1");
    Project p = new Project("project1");
    assertFalse(plugin.isAllowed(new DummyHttpServletRequest(), g));
    assertFalse(plugin.isAllowed(new DummyHttpServletRequest(), p));
}
Also used : Group(org.opengrok.indexer.configuration.Group) Project(org.opengrok.indexer.configuration.Project) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) PluginClassLoader(org.opengrok.indexer.framework.PluginClassLoader) Test(org.junit.jupiter.api.Test)

Example 10 with Group

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

the class ProjectsControllerTest method testAdd.

/**
 * Verify that added project correctly inherits a property
 * from configuration. Ideally, this should test all properties of Project.
 */
@Test
void testAdd() throws Exception {
    assertTrue(env.getRepositories().isEmpty());
    assertTrue(env.getProjects().isEmpty());
    // Add a group matching the project to be added.
    String groupName = "mercurialgroup";
    Group group = new Group(groupName, "mercurial.*");
    env.getGroups().add(group);
    assertTrue(env.hasGroups());
    assertEquals(1, env.getGroups().stream().filter(g -> g.getName().equals(groupName)).collect(Collectors.toSet()).size());
    assertEquals(0, group.getRepositories().size());
    assertEquals(0, group.getProjects().size());
    // Add a sub-repository.
    String repoPath = repository.getSourceRoot() + File.separator + "mercurial";
    File mercurialRoot = new File(repoPath);
    File subDir = new File(mercurialRoot, "usr");
    assertTrue(subDir.mkdir());
    String subRepoPath = repoPath + File.separator + "usr" + File.separator + "closed";
    File mercurialSubRoot = new File(subRepoPath);
    MercurialRepositoryTest.runHgCommand(mercurialRoot, "clone", mercurialRoot.getAbsolutePath(), subRepoPath);
    // Add the project.
    env.setScanningDepth(3);
    addProject("mercurial");
    // Check that the project was added properly.
    assertTrue(env.getProjects().containsKey("mercurial"));
    assertEquals(1, env.getProjects().size());
    assertEquals(2, env.getRepositories().size());
    assertEquals(1, group.getRepositories().size());
    assertEquals(0, group.getProjects().size());
    assertEquals(1, group.getRepositories().stream().filter(p -> p.getName().equals("mercurial")).collect(Collectors.toSet()).size());
    // Check that HistoryGuru now includes the project in its list.
    Set<String> directoryNames = HistoryGuru.getInstance().getRepositories().stream().map(RepositoryInfo::getDirectoryName).collect(Collectors.toSet());
    assertTrue(directoryNames.contains(repoPath) || directoryNames.contains(mercurialRoot.getCanonicalPath()), "though it should contain the top root,");
    assertTrue(directoryNames.contains(subRepoPath) || directoryNames.contains(mercurialSubRoot.getCanonicalPath()), "though it should contain the sub-root,");
    // Add more projects and check that they have been added incrementally.
    // At the same time, it checks that multiple projects can be added
    // with single message.
    addProject("git");
    assertEquals(2, env.getProjects().size());
    assertEquals(3, env.getRepositories().size());
    assertTrue(env.getProjects().containsKey("git"));
    assertFalse(HistoryGuru.getInstance().getRepositories().stream().map(RepositoryInfo::getDirectoryName).collect(Collectors.toSet()).contains("git"));
}
Also used : GrizzlyWebTestContainerFactory(org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory) TestContainerFactory(org.glassfish.jersey.test.spi.TestContainerFactory) BeforeEach(org.junit.jupiter.api.BeforeEach) RepositoryFactory(org.opengrok.indexer.history.RepositoryFactory) SuggesterService(org.opengrok.web.api.v1.suggester.provider.service.SuggesterService) Arrays(java.util.Arrays) Group(org.opengrok.indexer.configuration.Group) Project(org.opengrok.indexer.configuration.Project) MercurialRepositoryTest(org.opengrok.indexer.history.MercurialRepositoryTest) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) ApiTaskManager(org.opengrok.web.api.ApiTaskManager) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) ApiUtils.waitForTask(org.opengrok.web.api.v1.controller.ApiUtils.waitForTask) Path(java.nio.file.Path) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) SUBVERSION(org.opengrok.indexer.condition.RepositoryInstalled.Type.SUBVERSION) IndexDatabase(org.opengrok.indexer.index.IndexDatabase) Collectors(java.util.stream.Collectors) Indexer(org.opengrok.indexer.index.Indexer) Entity(jakarta.ws.rs.client.Entity) Test(org.junit.jupiter.api.Test) IndexerException(org.opengrok.indexer.index.IndexerException) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DeploymentContext(org.glassfish.jersey.test.DeploymentContext) Mock(org.mockito.Mock) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Response(jakarta.ws.rs.core.Response) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestRepository(org.opengrok.indexer.util.TestRepository) CommandTimeoutType(org.opengrok.indexer.configuration.CommandTimeoutType) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) Files(java.nio.file.Files) IOUtils.removeRecursive(org.opengrok.indexer.util.IOUtils.removeRecursive) IOException(java.io.IOException) File(java.io.File) GenericType(jakarta.ws.rs.core.GenericType) AfterEach(org.junit.jupiter.api.AfterEach) ServletDeploymentContext(org.glassfish.jersey.test.ServletDeploymentContext) Paths(java.nio.file.Paths) MERCURIAL(org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL) Collections(java.util.Collections) Group(org.opengrok.indexer.configuration.Group) File(java.io.File) MercurialRepositoryTest(org.opengrok.indexer.history.MercurialRepositoryTest) Test(org.junit.jupiter.api.Test)

Aggregations

Group (org.opengrok.indexer.configuration.Group)33 Test (org.junit.jupiter.api.Test)19 Project (org.opengrok.indexer.configuration.Project)19 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)7 User (opengrok.auth.plugin.entity.User)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TreeSet (java.util.TreeSet)3 Entity (jakarta.ws.rs.client.Entity)2 GenericType (jakarta.ws.rs.core.GenericType)2 Response (jakarta.ws.rs.core.Response)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2