|
| 1 | +package org.casbin.jcasbin.main; |
| 2 | + |
| 3 | +import org.casbin.jcasbin.config.Config; |
| 4 | + |
| 5 | +import org.junit.Test; |
| 6 | +import static org.junit.Assert.*; |
| 7 | + |
| 8 | +public class ConfigTest { |
| 9 | + |
| 10 | + @Test |
| 11 | + public void testGet() { |
| 12 | + Config config = Config.newConfig("examples/config/testini.ini"); |
| 13 | + |
| 14 | + // default::key test |
| 15 | + assertTrue(config.getBool("debug")); |
| 16 | + assertEquals("act.wiki", config.getString("url")); |
| 17 | + |
| 18 | + // redis::key test |
| 19 | + String[] redisKeys = config.getStrings("redis::redis.key"); |
| 20 | + assertArrayEquals(new String[]{"push1", "push2"}, redisKeys); |
| 21 | + assertEquals("127.0.0.1", config.getString("mysql::mysql.dev.host")); |
| 22 | + assertEquals("10.0.0.1", config.getString("mysql::mysql.master.host")); |
| 23 | + assertEquals("root", config.getString("mysql::mysql.master.user")); |
| 24 | + assertEquals("89dds)2$", config.getString("mysql::mysql.master.pass")); |
| 25 | + |
| 26 | + // math::key test |
| 27 | + assertEquals(64, config.getInt("math::math.i64")); |
| 28 | + assertEquals(64.1, config.getFloat("math::math.f64"), 0.0001); |
| 29 | + |
| 30 | + config.set("other::key1", "new test key"); |
| 31 | + assertEquals("new test key", config.getString("other::key1")); |
| 32 | + |
| 33 | + config.set("other::key1", "test key"); |
| 34 | + |
| 35 | + assertEquals("r.sub==p.sub && r.obj==p.obj", config.getString("multi1::name")); |
| 36 | + assertEquals("r.sub==p.sub && r.obj==p.obj", config.getString("multi2::name")); |
| 37 | + assertEquals("r.sub==p.sub && r.obj==p.obj", config.getString("multi3::name")); |
| 38 | + assertEquals("", config.getString("multi4::name")); |
| 39 | + assertEquals("r.sub==p.sub && r.obj==p.obj", config.getString("multi5::name")); |
| 40 | + } |
| 41 | +} |
0 commit comments