Search in sources :

Example 21 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.

the class PageConfigTest method testCheckSourceRootExistence1.

/**
 * Test the case when the source root is null.
 */
@Test
public void testCheckSourceRootExistence1() {
    assertThrows(FileNotFoundException.class, () -> {
        HttpServletRequest req = new DummyHttpServletRequest();
        PageConfig cfg = PageConfig.get(req);
        String path = RuntimeEnvironment.getInstance().getSourceRootPath();
        System.out.println(path);
        RuntimeEnvironment.getInstance().setSourceRoot(null);
        try {
            cfg.checkSourceRootExistence();
        } finally {
            RuntimeEnvironment.getInstance().setSourceRoot(path);
            PageConfig.cleanup(req);
        }
    });
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 22 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.

the class PageConfigTest method testCheckSourceRootExistence4.

/**
 * Test the case when source root can not be read.
 * @throws IOException I/O exception
 */
@Test
@EnabledOnOs({ OS.LINUX, OS.MAC, OS.SOLARIS, OS.AIX, OS.OTHER })
public void testCheckSourceRootExistence4() throws IOException {
    HttpServletRequest req = new DummyHttpServletRequest();
    PageConfig cfg = PageConfig.get(req);
    String path = RuntimeEnvironment.getInstance().getSourceRootPath();
    File temp = File.createTempFile("opengrok", "-test-file.tmp");
    Files.delete(temp.toPath());
    Files.createDirectories(temp.toPath());
    // skip the test if the implementation does not permit setting permissions
    assumeTrue(temp.setReadable(false));
    RuntimeEnvironment.getInstance().setSourceRoot(temp.getAbsolutePath());
    assertThrows(IOException.class, () -> cfg.checkSourceRootExistence(), "This should throw an exception when the file is not readable");
    RuntimeEnvironment.getInstance().setSourceRoot(path);
    PageConfig.cleanup(req);
    temp.deleteOnExit();
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) File(java.io.File) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test)

Example 23 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.

the class PageConfigTest method testGetLatestRevisionNotValid.

@Test
public void testGetLatestRevisionNotValid() {
    DummyHttpServletRequest req2 = new DummyHttpServletRequest() {

        @Override
        public String getPathInfo() {
            return "/git/nonexistent_file";
        }
    };
    PageConfig cfg = PageConfig.get(req2);
    String rev = cfg.getLatestRevision();
    assertNull(rev);
}
Also used : DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 24 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.

the class PageConfigTest method testCheckSourceRootExistence3.

/**
 * Test the case when source root does not exist.
 * @throws IOException I/O exception
 */
@Test
public void testCheckSourceRootExistence3() throws IOException {
    HttpServletRequest req = new DummyHttpServletRequest();
    PageConfig cfg = PageConfig.get(req);
    String path = RuntimeEnvironment.getInstance().getSourceRootPath();
    File temp = File.createTempFile("opengrok", "-test-file.tmp");
    Files.delete(temp.toPath());
    RuntimeEnvironment.getInstance().setSourceRoot(temp.getAbsolutePath());
    assertThrows(IOException.class, () -> cfg.checkSourceRootExistence(), "This should throw an exception when the file does not exist");
    RuntimeEnvironment.getInstance().setSourceRoot(path);
    PageConfig.cleanup(req);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 25 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.

the class PageConfigTest method testGetRevisionLocation.

@Test
public void testGetRevisionLocation() {
    DummyHttpServletRequest req1 = new DummyHttpServletRequest() {

        @Override
        public String getPathInfo() {
            return "/git/main.c";
        }

        @Override
        public String getContextPath() {
            return "source";
        }

        @Override
        public String getQueryString() {
            return "a=true";
        }
    };
    PageConfig cfg = PageConfig.get(req1);
    String location = cfg.getRevisionLocation(cfg.getLatestRevision());
    assertNotNull(location);
    assertEquals("source/xref/git/main.c?r=aa35c258&a=true", location);
}
Also used : DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Aggregations

DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)27 Test (org.junit.jupiter.api.Test)22 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)8 User (opengrok.auth.plugin.entity.User)8 Project (org.opengrok.indexer.configuration.Project)8 Group (org.opengrok.indexer.configuration.Group)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 File (java.io.File)3 PluginClassLoader (org.opengrok.indexer.framework.PluginClassLoader)2 Cookie (jakarta.servlet.http.Cookie)1 HttpSession (jakarta.servlet.http.HttpSession)1 Response (jakarta.ws.rs.core.Response)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 EnabledOnOs (org.junit.jupiter.api.condition.EnabledOnOs)1 Configuration (org.opengrok.indexer.configuration.Configuration)1 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)1 Annotation (org.opengrok.indexer.history.Annotation)1 PageConfig (org.opengrok.web.PageConfig)1