コード例 #1
0
  /**
   * Tests {@link org.jboss.bqt.core.util.PropertiesUtils}
   *
   * @throws Exception
   */
  @Test
  public void test1() throws Exception {
    // add this step of removing the property because the order of
    // running is not guaranteed, and if this doesn't run first,
    // this property is set by other tests
    Properties props = System.getProperties();
    props.remove(ConfigPropertyNames.CONFIG_FILE);

    System.setProperties(props);

    System.setProperty("test", "value");

    ConfigPropertyLoader _instance = ConfigPropertyLoader.getInstance();
    Properties p = _instance.getProperties();
    assertNotNull(p);
    assertTrue(!p.isEmpty());

    assertEquals("value", p.getProperty("test")); // $NON-NLS-1$ //$NON-NLS-2$

    _instance.setProperty("override", "ovalue");

    assertEquals("ovalue", _instance.getProperty("override")); // $NON-NLS-1$ //$NON-NLS-2$

    // confirm the loader actually loaded the default-config.properties file
    assertEquals(
        "driver", p.getProperty(ConfigPropertyNames.CONNECTION_TYPE)); // $NON-NLS-1$ //$NON-NLS-2$

    System.setProperty("username", "");

    ConfigPropertyLoader.reset();

    _instance = ConfigPropertyLoader.getInstance();
    p = _instance.getProperties();

    assertNull("should be null after reset", _instance.getProperties().getProperty("override"));

    assertEquals(
        "failed to pickup system property",
        "value",
        p.getProperty("test")); // $NON-NLS-1$ //$NON-NLS-2$

    // confirm the loader actually loaded the default-config.properties file
    assertEquals(
        "failed to correctly pickup the User ",
        "",
        _instance.getProperty("conn.user")); // $NON-NLS-1$ //$NON-NLS-2$
  }
コード例 #2
0
  @Before
  public void setUp() throws Exception {

    ConfigPropertyLoader.reset();
  }