1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package com.gitblit;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import static org.junit.Assert.*;
public class StoredUserConfigTest
{
private static File file;
@Before
public void setup()
{
file = new File("./suc-test.conf");
file.delete();
}
@After
public void teardown()
{
file.delete();
}
@Test
public void testSection() throws Exception
{
StoredUserConfig config = new StoredUserConfig(file);
config.setString("USER", "norman", "key", "value");
config.setString("USER", "admin", "displayName", "marusha");
config.setString("USER", null, "role", "none");
config.setString("TEAM", "admin", "role", "admin");
config.setString("TEAM", "ci", "email", "ci@example.com");
config.setString("TEAM", null, "displayName", "noone");
config.save();
StoredConfig cfg = new FileBasedConfig(file, FS.detect());
cfg.load();
assertEquals("value", cfg.getString("USER", "norman", "key"));
assertEquals("marusha", cfg.getString("USER", "admin", "displayName"));
assertEquals("none", cfg.getString("USER", null, "role"));
assertEquals("admin", cfg.getString("TEAM", "admin", "role"));
assertEquals("ci@example.com", cfg.getString("TEAM", "ci", "email"));
assertEquals("noone", cfg.getString("TEAM", null, "displayName"));
}
}
|