Beispiel #1
0
  @Test
  @TestDir
  public void constructorsGetters() throws Exception {
    Server server =
        new Server(
            "server",
            getAbsolutePath("/a"),
            getAbsolutePath("/b"),
            getAbsolutePath("/c"),
            getAbsolutePath("/d"),
            new Configuration(false));
    assertEquals(server.getHomeDir(), getAbsolutePath("/a"));
    assertEquals(server.getConfigDir(), getAbsolutePath("/b"));
    assertEquals(server.getLogDir(), getAbsolutePath("/c"));
    assertEquals(server.getTempDir(), getAbsolutePath("/d"));
    assertEquals(server.getName(), "server");
    assertEquals(server.getPrefix(), "server");
    assertEquals(server.getPrefixedName("name"), "server.name");
    assertNotNull(server.getConfig());

    server =
        new Server(
            "server",
            getAbsolutePath("/a"),
            getAbsolutePath("/b"),
            getAbsolutePath("/c"),
            getAbsolutePath("/d"));
    assertEquals(server.getHomeDir(), getAbsolutePath("/a"));
    assertEquals(server.getConfigDir(), getAbsolutePath("/b"));
    assertEquals(server.getLogDir(), getAbsolutePath("/c"));
    assertEquals(server.getTempDir(), getAbsolutePath("/d"));
    assertEquals(server.getName(), "server");
    assertEquals(server.getPrefix(), "server");
    assertEquals(server.getPrefixedName("name"), "server.name");
    assertNull(server.getConfig());

    server =
        new Server(
            "server", TestDirHelper.getTestDir().getAbsolutePath(), new Configuration(false));
    assertEquals(server.getHomeDir(), TestDirHelper.getTestDir().getAbsolutePath());
    assertEquals(server.getConfigDir(), TestDirHelper.getTestDir() + "/conf");
    assertEquals(server.getLogDir(), TestDirHelper.getTestDir() + "/log");
    assertEquals(server.getTempDir(), TestDirHelper.getTestDir() + "/temp");
    assertEquals(server.getName(), "server");
    assertEquals(server.getPrefix(), "server");
    assertEquals(server.getPrefixedName("name"), "server.name");
    assertNotNull(server.getConfig());

    server = new Server("server", TestDirHelper.getTestDir().getAbsolutePath());
    assertEquals(server.getHomeDir(), TestDirHelper.getTestDir().getAbsolutePath());
    assertEquals(server.getConfigDir(), TestDirHelper.getTestDir() + "/conf");
    assertEquals(server.getLogDir(), TestDirHelper.getTestDir() + "/log");
    assertEquals(server.getTempDir(), TestDirHelper.getTestDir() + "/temp");
    assertEquals(server.getName(), "server");
    assertEquals(server.getPrefix(), "server");
    assertEquals(server.getPrefixedName("name"), "server.name");
    assertNull(server.getConfig());
  }
Beispiel #2
0
 @Test
 @TestDir
 public void loadingDefaultConfig() throws Exception {
   String dir = TestDirHelper.getTestDir().getAbsolutePath();
   Server server = new Server("testserver", dir, dir, dir, dir);
   server.init();
   assertEquals(server.getConfig().get("testserver.a"), "default");
 }
Beispiel #3
0
 @Test
 @TestDir
 public void loadingSiteConfig() throws Exception {
   String dir = TestDirHelper.getTestDir().getAbsolutePath();
   File configFile = new File(dir, "testserver-site.xml");
   Writer w = new FileWriter(configFile);
   w.write(
       "<configuration><property><name>testserver.a</name><value>site</value></property></configuration>");
   w.close();
   Server server = new Server("testserver", dir, dir, dir, dir);
   server.init();
   assertEquals(server.getConfig().get("testserver.a"), "site");
 }
  @Test
  public void baseService() throws Exception {
    BaseService service = new MyService();
    assertNull(service.getInterface());
    assertEquals(service.getPrefix(), "myservice");
    assertEquals(service.getServiceDependencies().length, 0);

    Server server = Mockito.mock(Server.class);
    Configuration conf = new Configuration(false);
    conf.set("server.myservice.foo", "FOO");
    conf.set("server.myservice1.bar", "BAR");
    Mockito.when(server.getConfig()).thenReturn(conf);
    Mockito.when(server.getPrefixedName("myservice.foo")).thenReturn("server.myservice.foo");
    Mockito.when(server.getPrefixedName("myservice.")).thenReturn("server.myservice.");

    service.init(server);
    assertEquals(service.getPrefixedName("foo"), "server.myservice.foo");
    assertEquals(service.getServiceConfig().size(), 1);
    assertEquals(service.getServiceConfig().get("foo"), "FOO");
    assertTrue(MyService.INIT);
  }