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