[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-BE-os / src / test / java / org / openecomp / portalapp / portal / controller / SharedContextTestProperties.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 package org.openecomp.portalapp.portal.controller;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.util.Properties;
25
26 /**
27  * Trivial extension of Properties that populates itself from a known source.
28  */
29 public class SharedContextTestProperties extends Properties {
30
31         private static final long serialVersionUID = -4064100267979036550L;
32
33         // property names
34         public static final String HOSTNAME = "hostname";
35         public static final String PORT = "port";
36         public static final String SECURE = "secure";
37         public static final String APPNAME = "appname";
38         public static final String RESTPATH = "restpath";
39         public static final String UEBKEY = "uebkey";
40         public static final String USERNAME = "username";
41         public static final String PASSWORD = "password";
42
43         /**
44          * Expected on the classpath
45          */
46         private static final String propertiesFileName = "shared-context-test.properties";
47
48         /**
49          * Constructor populates itself from properties file found in same package.
50          * 
51          * @throws Exception
52          */
53         public SharedContextTestProperties() throws IOException {
54                 InputStream inStream = getClass().getResourceAsStream(propertiesFileName);
55                 if (inStream == null)
56                         throw new IOException("Failed to find file on classpath: " + propertiesFileName);
57                 super.load(inStream);
58                 inStream.close();
59         }
60
61         public int getProperty(final String name, final int defVal) throws NumberFormatException {
62                 String prop = getProperty(name);
63                 if (prop == null)
64                         return defVal;
65                 return Integer.parseInt(prop);
66         }
67         
68         public boolean getProperty(final String name, final boolean defVal) {
69                 String prop = getProperty(name);
70                 if (prop == null)
71                         return false;
72                 return Boolean.parseBoolean(prop);
73         }
74         
75         // Test this class
76         public static void main(String[] args) throws Exception {
77                 SharedContextTestProperties p = new SharedContextTestProperties();
78                 System.out.println("Property " + SharedContextTestProperties.HOSTNAME + " = "
79                                 + p.getProperty(SharedContextTestProperties.HOSTNAME));
80         }
81 }