Ejemplo n.º 1
0
  @Test
  public void testCreateUserConfig_ByFile() {
    Path file = Paths.get(FileUtils.getTempDirectoryPath(), "userconfig_test.conf");

    UserConfig cfg = UserConfigUtils.createUserConfig(file);
    assertNotNull(cfg);
    assertEquals(file, cfg.getConfigFile());
  }
Ejemplo n.º 2
0
  @Test
  public void testCreateUserConfig_ByUsername() {
    String sha256 = "96d9632f363564cc3032521409cf22a852f2032eec099ed5967c0d000cec607a"; // John
    String username = "******";
    Path expectedFile = Paths.get(String.format("%s.conf", sha256));

    UserConfig cfg = UserConfigUtils.createUserConfig(username);
    assertNotNull(cfg);
    assertEquals(expectedFile, cfg.getConfigFile().getFileName());

    // lower
    cfg = UserConfigUtils.createUserConfig(username.toLowerCase());
    assertNotNull(cfg);
    assertEquals(expectedFile, cfg.getConfigFile().getFileName());

    // upper
    cfg = UserConfigUtils.createUserConfig(username.toUpperCase());
    assertNotNull(cfg);
    assertEquals(expectedFile, cfg.getConfigFile().getFileName());
  }
Ejemplo n.º 3
0
  @Test
  public void testGetAllConfigFiles() throws IOException {
    // user 1
    UserConfig cfgJohn = UserConfigUtils.createUserConfig("john");
    cfgJohn.load();
    cfgJohn.setUsername("john");

    // user 2
    UserConfig cfgSteven = UserConfigUtils.createUserConfig("steven");
    cfgSteven.load();
    cfgSteven.setUsername("steven");

    // search files
    Map<String, UserConfig> cfgFiles = UserConfigUtils.getAllConfigFiles();
    assertEquals(2, cfgFiles.size());

    assertTrue(cfgFiles.containsKey("john"));
    assertTrue(cfgFiles.containsKey("steven"));

    assertEquals("john", cfgFiles.get("john").getUsername());
    assertEquals("steven", cfgFiles.get("steven").getUsername());
  }