예제 #1
0
파일: PropsTest.java 프로젝트: vtudiv/jodd
  @Test
  public void testNestedProfiles() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test-profiles.props"));

    assertEquals("hello", p.getBaseValue("key1"));
    assertEquals("hello", p.getValue("key1"));
    assertEquals("Hi!", p.getValue("key1", "one"));
    assertEquals("Hola!", p.getValue("key1", "one.two"));
    assertEquals("world", p.getValue("key2", "one.two"));
    assertNull(p.getValue("key2", "one"));
    assertEquals("Grazias", p.getValue("key3", "one.two"));
    assertEquals("Grazias", p.getValue("key3", "one"));

    Properties prop = new Properties();
    p.extractProps(prop);
    assertEquals(3, prop.size());
    assertEquals("hello", prop.getProperty("key1"));

    prop.clear();
    p.extractProps(prop, "one");
    assertEquals(3 + 1, prop.size());
    assertEquals("Hi!", prop.getProperty("key1"));
    assertEquals("Grazias", prop.getProperty("key3"));

    prop.clear();
    p.extractProps(prop, "one.two");
    assertEquals(3 + 2, prop.size());
    assertEquals("Hola!", prop.getProperty("key1"));
    assertEquals("world", prop.getProperty("key2"));
    assertEquals("Grazias", prop.getProperty("key3"));
  }
예제 #2
0
파일: PropsTest.java 프로젝트: vtudiv/jodd
  @Test
  public void testProfiles() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test-profiles.props"));

    assertEquals("one", p.getValue("foo"));
    assertEquals("one", p.getValue("foo", "non_existing_profile"));
    assertEquals("one", p.getValue("foo", "qwe"));
    assertEquals("ten", p.getValue("bar"));

    assertEquals("12345", p.getValue("vitamine", "aaa"));

    assertEquals(8, p.countTotalProperties());

    assertNull(p.getValue("db.url"));
    assertEquals("localhost", p.getValue("db.url", "develop"));
    assertEquals("localhost", p.getValue("db.url", "develop", "deploy"));
    assertEquals("192.168.1.102", p.getValue("db.url", "deploy", "develop"));
    assertEquals("192.168.1.102", p.getValue("db.url", "deploy"));

    Properties prop = new Properties();
    p.extractBaseProps(prop);
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "non_existing");
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "aaa");
    assertEquals("12345", prop.getProperty("vitamine"));

    prop.clear();
    p.extractProps(prop, "develop");
    assertEquals("localhost", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "develop", "deploy");
    assertEquals("localhost", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "deploy", "develop");
    assertEquals("192.168.1.102", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.extractProps(prop, "deploy");
    assertEquals("192.168.1.102", prop.getProperty("db.url"));
    assertEquals("one", prop.getProperty("foo"));

    prop.clear();
    p.setActiveProfiles("deploy");
    p.extractSubProps(prop, "db.*");
    assertEquals(2, prop.size());
  }
예제 #3
0
파일: PropsTest.java 프로젝트: vtudiv/jodd
  @Test
  public void testMacros() throws IOException {
    Props p = new Props();
    p.load(readDataFile("test2.props"));

    assertEquals("/app/data", p.getValue("data.path"));
    assertEquals("/app/data2", p.getValue("data.path", "@prof1"));
    assertEquals("/foo/data3", p.getValue("data.path", "@prof2"));

    assertEquals("/roo/re", p.getValue("data.path", "@p1"));
    assertEquals("/app/re", p.getValue("data.path", "@p2"));

    Properties prop = new Properties();
    p.extractProps(prop, "@prof2");
    assertEquals("/foo/data3", prop.getProperty("data.path"));
  }