public static Properties getInstance(String file)
{
String path = System.getProperty("jboss.server.base.dir") + File.separator + "configuration" + File.separator + "nxt" + File.separator + file;
logger.info("path " + path);
InputStream in = null;
Properties prop = new Properties();
try
{
in = new FileInputStream(path);
prop.load(in);
}
catch (Exception e)
{
}
finally
{
if (in != null)
{
try
{
in.close();
in = null;
}
catch (IOException e)
{
}
}
}
return prop;
}
Code used to read from a property file in a specified location in the JBoss server
@Test
public void getEdgeHealthDignosticValidTest() throws Exception{
String propertyVal = UtilProperty.getInstance("errorcodes.properties");
assertTrue(propertyVal.contains("true"));
}
Above is the JUnit test to valid the method. Calling the method to get the property value from the properties file in the mentioned location.
While running the JUnit test, getting NullPointerException. Since it can't get the System.getProperty("jboss.server.base.dir")
value.
How can I get JBoss property in JUnit test.
For JUnit you can directly read the property file