nexus site path corrected
[portal.git] / ecomp-portal-BE / src / test / java / org / openecomp / portalapp / portal / controller / SharedContextTestProperties.java
1 package org.openecomp.portalapp.portal.controller;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.Properties;
6
7 /**
8  * Trivial extension of Properties that populates itself from a known source.
9  */
10 public class SharedContextTestProperties extends Properties {
11
12         private static final long serialVersionUID = -4064100267979036550L;
13
14         // property names
15         public static final String HOSTNAME = "hostname";
16         public static final String PORT = "port";
17         public static final String SECURE = "secure";
18         public static final String APPNAME = "appname";
19         public static final String RESTPATH = "restpath";
20         public static final String UEBKEY = "uebkey";
21         public static final String USERNAME = "username";
22         public static final String PASSWORD = "password";
23
24         /**
25          * Expected on the classpath
26          */
27         private static final String propertiesFileName = "shared-context-test.properties";
28
29         /**
30          * Constructor populates itself from properties file found in same package.
31          * 
32          * @throws Exception
33          */
34         public SharedContextTestProperties() throws IOException {
35                 InputStream inStream = getClass().getResourceAsStream(propertiesFileName);
36                 if (inStream == null)
37                         throw new IOException("Failed to find file on classpath: " + propertiesFileName);
38                 super.load(inStream);
39                 inStream.close();
40         }
41
42         public int getProperty(final String name, final int defVal) throws NumberFormatException {
43                 String prop = getProperty(name);
44                 if (prop == null)
45                         return defVal;
46                 return Integer.parseInt(prop);
47         }
48         
49         public boolean getProperty(final String name, final boolean defVal) {
50                 String prop = getProperty(name);
51                 if (prop == null)
52                         return false;
53                 return Boolean.parseBoolean(prop);
54         }
55         
56         // Test this class
57         public static void main(String[] args) throws Exception {
58                 SharedContextTestProperties p = new SharedContextTestProperties();
59                 System.out.println("Property " + SharedContextTestProperties.HOSTNAME + " = "
60                                 + p.getProperty(SharedContextTestProperties.HOSTNAME));
61         }
62 }