Search in sources :

Example 1 with DummyHttpServletRequest

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

the class RuntimeEnvironmentTest method testSaveStatistics.

@Test
public void testSaveStatistics() throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setStatistics(new Statistics());
    env.getStatistics().addRequest(new DummyHttpServletRequest());
    env.getStatistics().addRequest(new DummyHttpServletRequest(), "root");
    env.getStatistics().addRequestTime(new DummyHttpServletRequest(), "root", 10L);
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        env.saveStatistics(out);
        Assert.assertNotEquals("{}", out.toString());
        Assert.assertEquals(env.getStatistics().toJson().toJSONString(), out.toString());
    }
}
Also used : DummyHttpServletRequest(org.opensolaris.opengrok.web.DummyHttpServletRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Statistics(org.opensolaris.opengrok.web.Statistics) Test(org.junit.Test)

Example 2 with DummyHttpServletRequest

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

the class AuthorizationPluginClassLoaderTest method testTruePlugin.

@Test
public void testTruePlugin() {
    AuthorizationPluginClassLoader instance = new AuthorizationPluginClassLoader(pluginDirectory);
    Class clazz = loadClass(instance, "org.sample.plugin.TruePlugin");
    IAuthorizationPlugin plugin = getNewInstance(clazz);
    Group g = new Group();
    g.setName("group1");
    Project p = new Project();
    p.setName(("project1"));
    Assert.assertTrue(plugin.isAllowed(new DummyHttpServletRequest(), g));
    Assert.assertTrue(plugin.isAllowed(new DummyHttpServletRequest(), p));
}
Also used : Group(org.opensolaris.opengrok.configuration.Group) Project(org.opensolaris.opengrok.configuration.Project) DummyHttpServletRequest(org.opensolaris.opengrok.web.DummyHttpServletRequest) Test(org.junit.Test)

Example 3 with DummyHttpServletRequest

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

the class AuthorizationPluginClassLoaderTest method testFalsePlugin.

@Test
public void testFalsePlugin() {
    AuthorizationPluginClassLoader instance = new AuthorizationPluginClassLoader(pluginDirectory);
    Class clazz = loadClass(instance, "org.sample.plugin.FalsePlugin");
    IAuthorizationPlugin plugin = getNewInstance(clazz);
    Group g = new Group();
    g.setName("group1");
    Project p = new Project();
    p.setName(("project1"));
    Assert.assertFalse(plugin.isAllowed(new DummyHttpServletRequest(), g));
    Assert.assertFalse(plugin.isAllowed(new DummyHttpServletRequest(), p));
}
Also used : Group(org.opensolaris.opengrok.configuration.Group) Project(org.opensolaris.opengrok.configuration.Project) DummyHttpServletRequest(org.opensolaris.opengrok.web.DummyHttpServletRequest) Test(org.junit.Test)

Example 4 with DummyHttpServletRequest

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

the class StatsMessageTest method testGet.

@Test
public void testGet() {
    testClean();
    env.getStatistics().addRequest(new DummyHttpServletRequest());
    Message m = new StatsMessage();
    m.setText("get");
    byte[] out = null;
    try {
        out = m.apply(env);
    } catch (Exception ex) {
        Assert.fail("Should not throw any exception");
    }
    Assert.assertNotNull(out);
    Assert.assertTrue(out.length > 0);
    Assert.assertNotEquals("{}", new String(out));
}
Also used : DummyHttpServletRequest(org.opensolaris.opengrok.web.DummyHttpServletRequest) ParseException(org.json.simple.parser.ParseException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 DummyHttpServletRequest (org.opensolaris.opengrok.web.DummyHttpServletRequest)4 Group (org.opensolaris.opengrok.configuration.Group)2 Project (org.opensolaris.opengrok.configuration.Project)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ParseException (org.json.simple.parser.ParseException)1 Statistics (org.opensolaris.opengrok.web.Statistics)1