aboutsummaryrefslogtreecommitdiffstats
path: root/common/src
diff options
context:
space:
mode:
authorRob Daugherty <rd472p@att.com>2018-03-09 15:02:18 -0500
committerRob Daugherty <rd472p@att.com>2018-03-09 15:08:14 -0500
commit96b5a685d0c3afddb632e4a68ca7483f933b55dc (patch)
tree246399de05a3d429bf45ef1e5af2b9b0218d99f3 /common/src
parent4475278c81668109b2b37a1d2720d8f2910641c4 (diff)
Revert Reduce log noise/warnings
This reverts commit 327b17ab250b4c17cf3f91f5e4cd9bffd89f3d1e. It is seriously impeding our ability complete the promised merge of AT&T 1802 code. While I'm all for coding standards, if we are serious about using spaces instead of tabs, then I think we need to (1) agree with the community when this will happen, (2) do consistently in all files, and (3) enforce it. Change-Id: Ib9b996f6b6c7d81ac9ac95d58b0c7d8cc39675ff Issue-ID: SO-368 Signed-off-by: Rob Daugherty <rd472p@att.com>
Diffstat (limited to 'common/src')
-rw-r--r--common/src/test/java/org/openecomp/mso/adapter_utils/tests/CryptoTest.java51
-rw-r--r--common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoAlarmLoggerTest.java166
-rw-r--r--common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java516
-rw-r--r--common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java252
-rw-r--r--common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryTest.java1154
-rw-r--r--common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertyInitializerTest.java85
-rw-r--r--common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java38
7 files changed, 1093 insertions, 1169 deletions
diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/CryptoTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/CryptoTest.java
index e38aed8285..3415420c88 100644
--- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/CryptoTest.java
+++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/CryptoTest.java
@@ -34,45 +34,46 @@ import org.openecomp.mso.utils.CryptoUtils;
/**
* This class implements all test methods of the CryptoUtils features.
+ *
+ *
*/
public class CryptoTest {
- private static String testKey = "546573746F736973546573746F736973";
+ private static String testKey = "546573746F736973546573746F736973";
- /**
+ /**
* This method is called before any test occurs.
* It creates a fake tree from scratch
*/
@BeforeClass
- public static final void prepare() {
-
+ public static final void prepare () {
+
}
/**
* This method implements a test of tree structure, mainly the storage of the leaves structure.
- *
- * @throws GeneralSecurityException
+ * @throws GeneralSecurityException
*/
@Test
- public final void testEncryption() throws GeneralSecurityException {
- String hexString = CryptoUtils.byteArrayToHexString("testosistestosi".getBytes());
-
- final String testData = "This is a test string";
- final String nonTestData = "This is not the right String";
-
- String encodeString = CryptoUtils.encrypt(testData, testKey);
-
- assertNotNull(encodeString);
-
- assertTrue(testData.equals(CryptoUtils.decrypt(encodeString, testKey)));
- assertFalse(nonTestData.equals(CryptoUtils.decrypt(encodeString, testKey)));
-
- String encode2String = CryptoUtils.encrypt(testData, testKey);
- assertNotNull(encode2String);
-
- assertEquals(encodeString, encode2String);
-
- assertEquals(CryptoUtils.decrypt(encodeString, testKey), CryptoUtils.decrypt(encode2String, testKey));
+ public final void testEncryption () throws GeneralSecurityException {
+ String hexString = CryptoUtils.byteArrayToHexString("testosistestosi".getBytes());
+
+ final String testData = "This is a test string";
+ final String nonTestData = "This is not the right String";
+
+ String encodeString = CryptoUtils.encrypt(testData, testKey);
+
+ assertNotNull(encodeString);
+
+ assertTrue(testData.equals(CryptoUtils.decrypt(encodeString, testKey)));
+ assertFalse(nonTestData.equals(CryptoUtils.decrypt(encodeString, testKey)));
+
+ String encode2String = CryptoUtils.encrypt(testData, testKey);
+ assertNotNull(encode2String);
+
+ assertEquals(encodeString,encode2String);
+
+ assertEquals(CryptoUtils.decrypt(encodeString, testKey),CryptoUtils.decrypt(encode2String, testKey));
}
}
diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoAlarmLoggerTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoAlarmLoggerTest.java
index 86b0bfb478..f7d27acaf3 100644
--- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoAlarmLoggerTest.java
+++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoAlarmLoggerTest.java
@@ -41,89 +41,91 @@ import org.openecomp.mso.properties.MsoPropertiesFactory;
/**
* This junit test very roughly the alarm logger
+ *
*/
public class MsoAlarmLoggerTest {
- public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
- public static MsoAlarmLogger msoAlarmLogger;
-
- @BeforeClass
- public static final void createObjects() throws MsoPropertiesException {
-
- File outputFile = new File("target/alarm-test.log");
- if (outputFile.exists()) {
- outputFile.delete();
- }
- msoAlarmLogger = new MsoAlarmLogger("target/alarm-test.log");
- }
-
- @Test
- public void testAlarmConfig() throws MsoPropertiesException, IOException {
-
- msoAlarmLogger.sendAlarm("test", 0, "detail message");
-
- FileInputStream inputStream = new FileInputStream("target/alarm-test.log");
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-
- String line = reader.readLine();
- String[] splitLine = line.split("\\|");
- assertTrue(splitLine.length == 4);
- assertTrue("test".equals(splitLine[1]));
- assertTrue("0".equals(splitLine[2]));
- assertTrue("detail message".equals(splitLine[3]));
-
- line = reader.readLine();
- assertNull(line);
- reader.close();
- inputStream.close();
-
- // Reset the file for others tests
- PrintWriter writer = new PrintWriter(new File("target/alarm-test.log"));
- writer.print("");
- writer.close();
-
- }
-
- @Test
- public void testAlarm() throws IOException {
-
- msoAlarmLogger.sendAlarm("test", 0, "detail message");
- msoAlarmLogger.sendAlarm("test2", 1, "detail message2");
- msoAlarmLogger.sendAlarm("test3", 2, "detail message3");
-
- FileInputStream inputStream = new FileInputStream("target/alarm-test.log");
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-
- String line = reader.readLine();
- String[] splitLine = line.split("\\|");
- assertTrue(splitLine.length == 4);
- assertTrue("test".equals(splitLine[1]));
- assertTrue("0".equals(splitLine[2]));
- assertTrue("detail message".equals(splitLine[3]));
-
- line = reader.readLine();
- splitLine = line.split("\\|");
- assertTrue(splitLine.length == 4);
- assertTrue("test2".equals(splitLine[1]));
- assertTrue("1".equals(splitLine[2]));
- assertTrue("detail message2".equals(splitLine[3]));
-
- line = reader.readLine();
- splitLine = line.split("\\|");
- assertTrue(splitLine.length == 4);
- assertTrue("test3".equals(splitLine[1]));
- assertTrue("2".equals(splitLine[2]));
- assertTrue("detail message3".equals(splitLine[3]));
-
- line = reader.readLine();
- assertNull(line);
- reader.close();
- inputStream.close();
-
- // Reset the file for others tests
- PrintWriter writer = new PrintWriter(new File("target/alarm-test.log"));
- writer.print("");
- writer.close();
-
- }
+ public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+ public static MsoAlarmLogger msoAlarmLogger;
+
+ @BeforeClass
+ public static final void createObjects() throws MsoPropertiesException
+ {
+
+ File outputFile = new File ("target/alarm-test.log");
+ if (outputFile.exists()) {
+ outputFile.delete();
+ }
+ msoAlarmLogger = new MsoAlarmLogger("target/alarm-test.log");
+ }
+
+ @Test
+ public void testAlarmConfig() throws MsoPropertiesException, IOException {
+
+ msoAlarmLogger.sendAlarm("test", 0, "detail message");
+
+ FileInputStream inputStream = new FileInputStream("target/alarm-test.log");
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+
+ String line = reader.readLine();
+ String[] splitLine = line.split("\\|");
+ assertTrue(splitLine.length==4);
+ assertTrue("test".equals(splitLine[1]));
+ assertTrue("0".equals(splitLine[2]));
+ assertTrue("detail message".equals(splitLine[3]));
+
+ line = reader.readLine();
+ assertNull(line);
+ reader.close();
+ inputStream.close();
+
+ // Reset the file for others tests
+ PrintWriter writer = new PrintWriter(new File("target/alarm-test.log"));
+ writer.print("");
+ writer.close();
+
+ }
+
+ @Test
+ public void testAlarm() throws IOException {
+
+ msoAlarmLogger.sendAlarm("test", 0, "detail message");
+ msoAlarmLogger.sendAlarm("test2", 1, "detail message2");
+ msoAlarmLogger.sendAlarm("test3", 2, "detail message3");
+
+ FileInputStream inputStream = new FileInputStream("target/alarm-test.log");
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+
+ String line = reader.readLine();
+ String[] splitLine = line.split("\\|");
+ assertTrue(splitLine.length==4);
+ assertTrue("test".equals(splitLine[1]));
+ assertTrue("0".equals(splitLine[2]));
+ assertTrue("detail message".equals(splitLine[3]));
+
+ line = reader.readLine();
+ splitLine = line.split("\\|");
+ assertTrue(splitLine.length==4);
+ assertTrue("test2".equals(splitLine[1]));
+ assertTrue("1".equals(splitLine[2]));
+ assertTrue("detail message2".equals(splitLine[3]));
+
+ line = reader.readLine();
+ splitLine = line.split("\\|");
+ assertTrue(splitLine.length==4);
+ assertTrue("test3".equals(splitLine[1]));
+ assertTrue("2".equals(splitLine[2]));
+ assertTrue("detail message3".equals(splitLine[3]));
+
+ line = reader.readLine();
+ assertNull(line);
+ reader.close();
+ inputStream.close();
+
+ // Reset the file for others tests
+ PrintWriter writer = new PrintWriter(new File("target/alarm-test.log"));
+ writer.print("");
+ writer.close();
+
+ }
}
diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java
index faef522fbf..473f5320df 100644
--- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java
+++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java
@@ -40,340 +40,300 @@ import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
-
/**
* This class implements all test methods of the MsoLogger features.
+ *
+ *
*/
public class MsoLoggerTest {
- static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
+ static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
- /**
+ /**
* This method is called before any test occurs.
* It creates a fake tree from scratch
*/
@BeforeClass
- public static final void prepare() {
+ public static final void prepare () {
}
@Before
public final void cleanErrorLogFile() throws FileNotFoundException {
- URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
- String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) +
- "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log";
- PrintWriter asdcConfigFileWriter = new PrintWriter(logFile);
- asdcConfigFileWriter.print("");
- asdcConfigFileWriter.flush();
- asdcConfigFileWriter.close();
- }
-
+ URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
+ String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log";
+ PrintWriter asdcConfigFileWriter = new PrintWriter(logFile);
+ asdcConfigFileWriter.print("");
+ asdcConfigFileWriter.flush();
+ asdcConfigFileWriter.close();
+ }
+
@Before
public final void cleanMetricLogFile() throws FileNotFoundException {
- URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
- String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) +
- "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log";
- PrintWriter asdcConfigFileWriter = new PrintWriter(logFile);
- asdcConfigFileWriter.print("");
- asdcConfigFileWriter.flush();
- asdcConfigFileWriter.close();
- }
-
+ URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
+ String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log";
+ PrintWriter asdcConfigFileWriter = new PrintWriter(logFile);
+ asdcConfigFileWriter.print("");
+ asdcConfigFileWriter.flush();
+ asdcConfigFileWriter.close();
+ }
+
@Before
public final void cleanAuditLogFile() throws FileNotFoundException {
- URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
- String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/auditjbo ss.server.name_IS_UNDEFINED.log";
- PrintWriter asdcConfigFileWriter = new PrintWriter(logFile);
- asdcConfigFileWriter.print("");
- asdcConfigFileWriter.flush();
- asdcConfigFileWriter.close();
- }
+ URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
+ String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/auditjbo ss.server.name_IS_UNDEFINED.log";
+ PrintWriter asdcConfigFileWriter = new PrintWriter(logFile);
+ asdcConfigFileWriter.print("");
+ asdcConfigFileWriter.flush();
+ asdcConfigFileWriter.close();
+ }
+
/**
* This method implements a test of getSeverifyLevel method.
*/
- @Test
- public final void testGetSeverityLevel() {
+ @Test
+ public final void testGetSeverityLevel () {
- try {
- String levelInfo = (String) invokePriveMethod("getSeverityLevel", "INFO");
- Assert.assertEquals(levelInfo, "0");
+ try {
+ String levelInfo = (String)invokePriveMethod("getSeverityLevel", "INFO");
+ Assert.assertEquals (levelInfo, "0");
- String levelWarn = (String) invokePriveMethod("getSeverityLevel", "WARN");
- Assert.assertEquals(levelWarn, "1");
+ String levelWarn = (String)invokePriveMethod("getSeverityLevel", "WARN");
+ Assert.assertEquals (levelWarn, "1");
- String levelERROR = (String) invokePriveMethod("getSeverityLevel", "ERROR");
- Assert.assertEquals(levelERROR, "2");
+ String levelERROR = (String)invokePriveMethod("getSeverityLevel", "ERROR");
+ Assert.assertEquals (levelERROR, "2");
- String levelDEBUG = (String) invokePriveMethod("getSeverityLevel", "DEBUG");
- Assert.assertEquals(levelDEBUG, "0");
+ String levelDEBUG = (String)invokePriveMethod("getSeverityLevel", "DEBUG");
+ Assert.assertEquals (levelDEBUG, "0");
- String levelFATAL = (String) invokePriveMethod("getSeverityLevel", "FATAL");
- Assert.assertEquals(levelFATAL, "3");
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ String levelFATAL = (String)invokePriveMethod("getSeverityLevel", "FATAL");
+ Assert.assertEquals (levelFATAL, "3");
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
/**
* This method implements a test of getFinalServiceName method.
*/
- @Test
- public final void testGetFinalServiceName() {
- try {
- String serviceName1 = (String) invokePriveMethod("getFinalServiceName",
- "testServiceName1");
- Assert.assertEquals(serviceName1, "testServiceName1");
-
- MsoLogger.setServiceName("testServiceName2");
- String serviceName2 = (String) invokePriveMethod("getFinalServiceName",
- "testServiceName1");
- Assert.assertEquals(serviceName2, "testServiceName1");
-
- String msgNull = null;
- String serviceName3 = (String) invokePriveMethod("getFinalServiceName", msgNull);
- Assert.assertEquals(serviceName3, "testServiceName2");
-
- MsoLogger.resetServiceName();
- String serviceName4 = (String) invokePriveMethod("getFinalServiceName", msgNull);
- Assert.assertEquals(serviceName4, "invoke0");
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ @Test
+ public final void testGetFinalServiceName () {
+ try {
+ String serviceName1 = (String)invokePriveMethod("getFinalServiceName", "testServiceName1");
+ Assert.assertEquals(serviceName1, "testServiceName1");
+
+ MsoLogger.setServiceName("testServiceName2");
+ String serviceName2 = (String)invokePriveMethod("getFinalServiceName", "testServiceName1");
+ Assert.assertEquals(serviceName2, "testServiceName1");
+
+ String msgNull = null;
+ String serviceName3 = (String)invokePriveMethod("getFinalServiceName", msgNull);
+ Assert.assertEquals(serviceName3, "testServiceName2");
+
+ MsoLogger.resetServiceName();
+ String serviceName4 = (String)invokePriveMethod("getFinalServiceName", msgNull);
+ Assert.assertEquals(serviceName4, "invoke0");
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
- @Test
- public final void testPrepareMsg() {
- try {
- String msgNull = null;
- MDC.clear();
- invokePrepareMsg("INFO", null, null);
-
- Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("trace-#") &&
- MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("trace-#") &&
- MDC.get(MsoLogger.SERVICE_NAME).equals("invoke0")
- && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("0"));
-
- MsoLogger.setLoggerParameters("testRemoteIp", "testUser");
- MsoLogger.setLogContext("testReqId", "testSvcId");
- invokePrepareMsg("ERROR", "testServiceName3", null);
- Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") &&
- MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") &&
- MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName3")
- && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("2"));
-
- MsoLogger.setServiceName("testServiceName2");
- invokePrepareMsg("WARN", msgNull, msgNull);
- Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") &&
- MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") &&
- MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName2")
- && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("1"));
-
- MDC.clear();
- MsoRequest msoRequest = new MsoRequest();
- msoRequest.setRequestId("reqId2");
- msoRequest.setServiceInstanceId("servId2");
- MsoLogger.setLogContext(msoRequest);
+ @Test
+ public final void testPrepareMsg () {
+ try {
+ String msgNull = null;
+ MDC.clear();
+ invokePrepareMsg("INFO", null, null);
+
+ Assert.assertTrue (MDC.get(MsoLogger.REQUEST_ID).equals("trace-#") && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("trace-#") && MDC.get(MsoLogger.SERVICE_NAME).equals("invoke0")
+ && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("0"));
+
+ MsoLogger.setLoggerParameters("testRemoteIp", "testUser");
+ MsoLogger.setLogContext("testReqId", "testSvcId");
+ invokePrepareMsg("ERROR", "testServiceName3", null);
+ Assert.assertTrue (MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") && MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName3")
+ && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("2") );
+
+ MsoLogger.setServiceName("testServiceName2");
+ invokePrepareMsg("WARN", msgNull, msgNull);
+ Assert.assertTrue (MDC.get(MsoLogger.REQUEST_ID).equals("testReqId") && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("testSvcId") && MDC.get(MsoLogger.SERVICE_NAME).equals("testServiceName2")
+ && MDC.get(MsoLogger.TIMER) == null && MDC.get(MsoLogger.ALERT_SEVERITY).equals("1"));
+
+ MDC.clear ();
+ MsoRequest msoRequest = new MsoRequest ();
+ msoRequest.setRequestId ("reqId2");
+ msoRequest.setServiceInstanceId ("servId2");
+ MsoLogger.setLogContext (msoRequest);
invokePrepareMsg("FATAL", null, "123");
- Assert.assertTrue(MDC.get(MsoLogger.REQUEST_ID).equals("reqId2") &&
- MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("servId2") &&
- MDC.get(MsoLogger.TIMER).equals("123") && MDC.get(MsoLogger.ALERT_SEVERITY).equals("3"));
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ Assert.assertTrue (MDC.get(MsoLogger.REQUEST_ID).equals("reqId2") && MDC.get(MsoLogger.SERVICE_INSTANCE_ID).equals("servId2") && MDC.get(MsoLogger.TIMER).equals("123") && MDC.get(MsoLogger.ALERT_SEVERITY).equals("3"));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
/**
* This method implements a test of log methods
*/
- @Test
- public final void testLogMethods() {
- try {
- MDC.clear();
- MsoLogger.setLogContext("reqId2", "servId2");
- MsoLogger.setServiceName("MSO.testServiceName");
- msoLogger.info(MessageEnum.LOGGER_UPDATE_SUC, "testLogger", "INFO",
- "DEBUG", "target entity", "target service");
- msoLogger.warn(MessageEnum.GENERAL_WARNING, "warning test", "",
- "", MsoLogger.ErrorCode.UnknownError, "warning test");
- msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "target entity",
- "target service", MsoLogger.ErrorCode.UnknownError, "error test");
-
- //Fetch from the error log
- URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
- String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) +
- "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log";
-
- Path filePath = new File(logFile).toPath();
- Charset charset = Charset.defaultCharset();
- List<String> stringList = Files.readAllLines(filePath, charset);
- String[] stringArray = stringList.toArray(new String[]{});
- int size = stringArray.length;
-
- Assert.assertTrue(stringArray[size - 3].
- contains("|reqId2|main|MSO.testServiceName||target entity|target service|INFO|null||") &&
- stringArray[size - 3].contains("||MSO-GENERAL-5408I Successfully update Logger: " +
- "testLogger from level INFO to level DEBUG"));
- Assert.assertTrue(stringArray[size - 2].
- contains("|reqId2|main|MSO.testServiceName||||WARN|UnknownError|warning test|") &&
- stringArray[size - 2].contains("|MSO-GENERAL-5401W WARNING: warning test"));
- Assert.assertTrue(stringArray[size - 1].
- contains("|reqId2|main|MSO.testServiceName||target entity|target " +
- "service|ERROR|UnknownError|error test|") && stringArray[size - 1].
- contains("|MSO-GENERAL-9401E Exception encountered"));
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ @Test
+ public final void testLogMethods () {
+ try {
+ MDC.clear();
+ MsoLogger.setLogContext("reqId2", "servId2");
+ MsoLogger.setServiceName("MSO.testServiceName");
+ msoLogger.info (MessageEnum.LOGGER_UPDATE_SUC, "testLogger", "INFO", "DEBUG", "target entity", "target service");
+ msoLogger.warn (MessageEnum.GENERAL_WARNING, "warning test", "", "", MsoLogger.ErrorCode.UnknownError, "warning test");
+ msoLogger.error (MessageEnum.GENERAL_EXCEPTION, "target entity", "target service", MsoLogger.ErrorCode.UnknownError, "error test");
+
+ //Fetch from the error log
+ URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
+ String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/errorjboss.server.name_IS_UNDEFINED.log";
+
+ Path filePath = new File(logFile).toPath();
+ Charset charset = Charset.defaultCharset();
+ List<String> stringList = Files.readAllLines(filePath, charset);
+ String[] stringArray = stringList.toArray(new String[]{});
+ int size = stringArray.length;
+
+ Assert.assertTrue(stringArray[size-3].contains("|reqId2|main|MSO.testServiceName||target entity|target service|INFO|null||") && stringArray[size-3].contains("||MSO-GENERAL-5408I Successfully update Logger: testLogger from level INFO to level DEBUG"));
+ Assert.assertTrue(stringArray[size-2].contains("|reqId2|main|MSO.testServiceName||||WARN|UnknownError|warning test|") && stringArray[size-2].contains("|MSO-GENERAL-5401W WARNING: warning test"));
+ Assert.assertTrue(stringArray[size-1].contains("|reqId2|main|MSO.testServiceName||target entity|target service|ERROR|UnknownError|error test|") && stringArray[size-1].contains("|MSO-GENERAL-9401E Exception encountered"));
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
- /**
+ /**
* This method implements a test of recordMetricEvent method.
*/
- @Test
- public final void testRecordMetricEvent() {
- try {
- MDC.clear();
- MsoLogger.setLogContext("reqId", "servId");
- msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- "Successful", "VNF", "createVNF", null);
- MDC.put(MsoLogger.REMOTE_HOST, "127.0.0.1");
- MDC.put(MsoLogger.PARTNERNAME, "testUser");
- msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.ServiceNotAvailable, "Exception", "SDNC",
- "removeSDNC", "testVNF");
-
- //Fetch from the metric log
- URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
- String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) +
- "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log";
-
- Path filePath = new File(logFile).toPath();
- Charset charset = Charset.defaultCharset();
- List<String> stringList = Files.readAllLines(filePath, charset);
- String[] stringArray = stringList.toArray(new String[]{});
- msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "", "",
- MsoLogger.ErrorCode.UnknownError, "test error msg");
-
- Assert.assertTrue(stringArray[0].contains("|reqId|servId|main||testRecordMetricEvent||" +
- "VNF|createVNF|COMPLETE|0|Successful|Test UUID as JBoss not found|INFO|0|"));
- // count the occurance of symbol "|"
- Assert.assertTrue((stringArray[0].length() - stringArray[0].replace("|",
- "").length()) == 28);
- Assert.assertTrue(stringArray[1].contains("|reqId|servId|main||testRecordMetricEvent|" +
- "testUser|SDNC|removeSDNC|ERROR|501|Exception|Test UUID as JBoss not found|INFO|0|") &&
- stringArray[1].contains("|127.0.0.1||||testVNF|||||"));
- Assert.assertTrue((stringArray[1].length() - stringArray[1].replace("|",
- "").length()) == 28);
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ @Test
+ public final void testRecordMetricEvent () {
+ try {
+ MDC.clear();
+ MsoLogger.setLogContext("reqId", "servId");
+ msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful", "VNF" , "createVNF", null);
+ MDC.put (MsoLogger.REMOTE_HOST, "127.0.0.1");
+ MDC.put (MsoLogger.PARTNERNAME, "testUser");
+ msoLogger.recordMetricEvent(123456789L, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.ServiceNotAvailable, "Exception", "SDNC", "removeSDNC", "testVNF");
+
+ //Fetch from the metric log
+ URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
+ String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/metricsjboss.server.name_IS_UNDEFINED.log";
+
+ Path filePath = new File(logFile).toPath();
+ Charset charset = Charset.defaultCharset();
+ List<String> stringList = Files.readAllLines(filePath, charset);
+ String[] stringArray = stringList.toArray(new String[]{});
+ msoLogger.error (MessageEnum.GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.UnknownError, "test error msg");
+
+ Assert.assertTrue(stringArray[0].contains("|reqId|servId|main||testRecordMetricEvent||VNF|createVNF|COMPLETE|0|Successful|Test UUID as JBoss not found|INFO|0|"));
+ // count the occurance of symbol "|"
+ Assert.assertTrue ((stringArray[0].length() - stringArray[0].replace("|", "").length()) == 28);
+ Assert.assertTrue(stringArray[1].contains("|reqId|servId|main||testRecordMetricEvent|testUser|SDNC|removeSDNC|ERROR|501|Exception|Test UUID as JBoss not found|INFO|0|") && stringArray[1].contains("|127.0.0.1||||testVNF|||||"));
+ Assert.assertTrue ((stringArray[1].length() - stringArray[1].replace("|", "").length()) == 28);
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
/**
* This method implements a test of testRecordAuditEvent method.
*/
- @Test
- public final void testRecordAuditEvent() {
-
- try {
-
- MDC.clear();
- MsoLogger.setLogContext("reqId", "servId");
- msoLogger.recordAuditEvent(123456789L, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- "Successful");
- MDC.put(MsoLogger.REMOTE_HOST, "127.0.0.1");
- MDC.put(MsoLogger.PARTNERNAME, "testUser");
- msoLogger.recordAuditEvent(123456789L, MsoLogger.StatusCode.ERROR,
- MsoLogger.ResponseCode.ServiceNotAvailable, "Exception");
-
- //Fetch from the metric log
- URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
- String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) +
- "/MSO/Test/auditjboss.server.name_IS_UNDEFINED.log";
-
- Path filePath = new File(logFile).toPath();
- Charset charset = Charset.defaultCharset();
- List<String> stringList = Files.readAllLines(filePath, charset);
- String[] stringArray = stringList.toArray(new String[]{});
- msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "", "",
- ErrorCode.UnknownError, "log error");
-
- Assert.assertTrue(stringArray[0].contains("|reqId|servId|main||testRecordAuditEvent||" +
- "COMPLETE|0|Successful|Test UUID as JBoss not found|INFO|0|"));
- // count the occurance of symbol "|"
- Assert.assertTrue((stringArray[0].length() - stringArray[0].replace("|",
- "").length()) == 25);
- Assert.assertTrue(stringArray[1].contains("|reqId|servId|main||testRecordAuditEvent" +
- "|testUser|ERROR|501|Exception|Test UUID as JBoss not found|INFO|0|") &&
- stringArray[1].contains("|127.0.0.1||||||||"));
- Assert.assertTrue((stringArray[1].length() - stringArray[1].replace("|",
- "").length()) == 25);
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ @Test
+ public final void testRecordAuditEvent () {
+
+ try {
+
+ MDC.clear();
+ MsoLogger.setLogContext("reqId", "servId");
+ msoLogger.recordAuditEvent(123456789L, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful");
+ MDC.put (MsoLogger.REMOTE_HOST, "127.0.0.1");
+ MDC.put (MsoLogger.PARTNERNAME, "testUser");
+ msoLogger.recordAuditEvent(123456789L, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.ServiceNotAvailable, "Exception");
+
+ //Fetch from the metric log
+ URL url = this.getClass().getClassLoader().getResource("logback-test.xml");
+ String logFile = url.getFile().substring(0, url.getFile().indexOf("test-classes")) + "/MSO/Test/auditjboss.server.name_IS_UNDEFINED.log";
+
+ Path filePath = new File(logFile).toPath();
+ Charset charset = Charset.defaultCharset();
+ List<String> stringList = Files.readAllLines(filePath, charset);
+ String[] stringArray = stringList.toArray(new String[]{});
+ msoLogger.error (MessageEnum.GENERAL_EXCEPTION, "", "", ErrorCode.UnknownError, "log error");
+
+ Assert.assertTrue (stringArray[0].contains("|reqId|servId|main||testRecordAuditEvent||COMPLETE|0|Successful|Test UUID as JBoss not found|INFO|0|"));
+ // count the occurance of symbol "|"
+ Assert.assertTrue ((stringArray[0].length() - stringArray[0].replace("|", "").length()) == 25);
+ Assert.assertTrue (stringArray[1].contains("|reqId|servId|main||testRecordAuditEvent|testUser|ERROR|501|Exception|Test UUID as JBoss not found|INFO|0|") && stringArray[1].contains("|127.0.0.1||||||||"));
+ Assert.assertTrue ((stringArray[1].length() - stringArray[1].replace("|", "").length()) == 25);
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
+
+
// User reflection to invoke to avoid change the publicity of the method
- private static String invokePrepareMsg(String arg1, String arg2, String arg3) {
- Method method;
- try {
- method = MsoLogger.class.getDeclaredMethod("prepareMsg", String.class, String.class, String.class);
- method.setAccessible(true);
- return (String) method.invoke(msoLogger, arg1, arg2, arg3);
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
+ private static String invokePrepareMsg (String arg1, String arg2, String arg3) {
+ Method method;
+ try {
+ method = MsoLogger.class.getDeclaredMethod("prepareMsg", String.class, String.class, String.class);
+ method.setAccessible(true);
+ return (String)method.invoke(msoLogger, arg1, arg2, arg3);
+ } catch (NoSuchMethodException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
}
// User reflection to invoke to avoid change the publicity of the method
- private static Object invokePriveMethod(String methodName, String arg) {
- Method method;
- try {
- method = MsoLogger.class.getDeclaredMethod(methodName, String.class);
- method.setAccessible(true);
- return method.invoke(msoLogger, arg);
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
+ private static Object invokePriveMethod (String methodName, String arg) {
+ Method method;
+ try {
+ method = MsoLogger.class.getDeclaredMethod(methodName, String.class);
+ method.setAccessible(true);
+ return method.invoke(msoLogger, arg);
+ } catch (NoSuchMethodException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
}
}
diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java
index 5caa137d33..a814c4ea9c 100644
--- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java
+++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java
@@ -44,145 +44,131 @@ import org.openecomp.mso.properties.MsoPropertiesFactory;
/**
* This class implements test methods of the MsoPropertiesFactory features.
+ *
+ *
*/
public class MsoPropertiesFactoryConcurrencyTest {
- public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
-
- public static final String MSO_PROP_ID = "TEST_PROP";
- public static final String PATH_MSO_PROP1 = MsoJavaProperties.class.getClassLoader().
- getResource("mso.properties")
- .toString().substring(5);
- public static final String PATH_MSO_PROP2 = MsoJavaProperties.class.getClassLoader().
- getResource("mso2.properties")
- .toString().substring(5);
-
- /**
- * This method is called before any test occurs. It creates a fake tree from
- * scratch
- *
- * @throws MsoPropertiesException
- */
- @BeforeClass
- public static final void prepare() throws MsoPropertiesException {
- // it's possible to have it already initialized, as tests are executed in the same JVM
- msoPropertiesFactory.removeAllMsoProperties();
- msoPropertiesFactory.initializeMsoProperties(MSO_PROP_ID, PATH_MSO_PROP1);
- }
-
- private Callable<Integer> taskReload = new Callable<Integer>() {
- @Override
- public Integer call() {
- try {
- if (!msoPropertiesFactory.reloadMsoProperties()) {
- return 1;
- }
- } catch (Exception e) {
- e.printStackTrace();
- return 1;
- }
- return 0;
- }
- };
-
- private Callable<Integer> taskRead = new Callable<Integer>() {
- @Override
- public Integer call() {
- try {
- MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_ID);
- String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId",
- "defaultValue");
- String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl",
- "defaultValue");
- String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId",
- "defaultValue");
- String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId",
- "defaultValue");
- String property5 = msoProperties.getProperty("does.not.exist",
- "defaultValue");
- String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test",
- "defaultValue");
- String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean",
- "defaultValue");
-
- assertEquals(property1, "MT");
- assertEquals(property2, "http://localhost:5000/v2.0");
- assertEquals(property3, "John");
- assertEquals(property4, "FD205490A48D48475607C36B9AD902BF");
- assertEquals(property5, "defaultValue");
- assertEquals(property6, "1234");
- assertEquals(property7, "true");
-
- } catch (MsoPropertiesException e) {
- e.printStackTrace();
- return 1;
- }
- return 0;
- }
- };
-
- private Callable<Integer> taskReadAll = new Callable<Integer>() {
- @Override
- public Integer call() {
- try {
- List<AbstractMsoProperties> msoPropertiesList = msoPropertiesFactory.getAllMsoProperties();
- String property1 = ((MsoJavaProperties) msoPropertiesList.get(0)).
- getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
- String property2 = ((MsoJavaProperties) msoPropertiesList.get(0)).
- getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
- String property3 = ((MsoJavaProperties) msoPropertiesList.get(0)).
- getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
- String property4 = ((MsoJavaProperties) msoPropertiesList.get(0)).
- getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
- String property5 = ((MsoJavaProperties) msoPropertiesList.get(0)).
- getProperty("does.not.exist", "defaultValue");
- String property6 = ((MsoJavaProperties) msoPropertiesList.get(0)).
- getProperty("ecomp.mso.cloud.1.test", "defaultValue");
- String property7 = ((MsoJavaProperties) msoPropertiesList.get(0)).
- getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
-
- assertEquals(property1, "MT");
- assertEquals(property2, "http://localhost:5000/v2.0");
- assertEquals(property3, "John");
- assertEquals(property4, "FD205490A48D48475607C36B9AD902BF");
- assertEquals(property5, "defaultValue");
- assertEquals(property6, "1234");
- assertEquals(property7, "true");
- } catch (Exception e) {
- e.printStackTrace();
- return 1;
- }
- return 0;
- }
- };
-
- @Test
- public final void testGetMsoProperties()
- throws MsoPropertiesException, InterruptedException, ExecutionException, FileNotFoundException {
-
- List<Future<Integer>> list = new ArrayList<>();
- ExecutorService executor = Executors.newFixedThreadPool(20);
-
- for (int i = 0; i <= 100000; i++) {
-
- Future<Integer> futureResult = executor.submit(taskRead);
- list.add(futureResult);
-
- futureResult = executor.submit(taskReload);
- list.add(futureResult);
-
- futureResult = executor.submit(taskReadAll);
- list.add(futureResult);
- }
- executor.shutdown();
- while (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
+ public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+
+ public static final String MSO_PROP_ID = "TEST_PROP";
+ public static final String PATH_MSO_PROP1 = MsoJavaProperties.class.getClassLoader().getResource("mso.properties")
+ .toString().substring(5);
+ public static final String PATH_MSO_PROP2 = MsoJavaProperties.class.getClassLoader().getResource("mso2.properties")
+ .toString().substring(5);
+
+ /**
+ * This method is called before any test occurs. It creates a fake tree from
+ * scratch
+ *
+ * @throws MsoPropertiesException
+ */
+ @BeforeClass
+ public static final void prepare() throws MsoPropertiesException {
+ // it's possible to have it already initialized, as tests are executed in the same JVM
+ msoPropertiesFactory.removeAllMsoProperties ();
+ msoPropertiesFactory.initializeMsoProperties(MSO_PROP_ID, PATH_MSO_PROP1);
+ }
+
+ private Callable<Integer> taskReload = new Callable<Integer>() {
+ @Override
+ public Integer call() {
+ try {
+ if (!msoPropertiesFactory.reloadMsoProperties()) {
+ return 1;
+ }
+ } catch (Exception e) {
+ e.printStackTrace ();
+ return 1;
+ }
+ return 0;
+ }
+ };
+
+ private Callable<Integer> taskRead = new Callable<Integer>() {
+ @Override
+ public Integer call() {
+ try {
+ MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_ID);
+ String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
+ String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
+ String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
+ String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
+ String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
+ String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
+ String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
+
+ assertEquals(property1, "MT");
+ assertEquals(property2, "http://localhost:5000/v2.0");
+ assertEquals(property3, "John");
+ assertEquals(property4, "FD205490A48D48475607C36B9AD902BF");
+ assertEquals(property5, "defaultValue");
+ assertEquals(property6, "1234");
+ assertEquals(property7, "true");
+
+ } catch (MsoPropertiesException e) {
+ e.printStackTrace ();
+ return 1;
+ }
+ return 0;
+ }
+ };
+
+ private Callable<Integer> taskReadAll = new Callable<Integer>() {
+ @Override
+ public Integer call() {
+ try {
+ List<AbstractMsoProperties> msoPropertiesList = msoPropertiesFactory.getAllMsoProperties();
+ String property1 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
+ String property2 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
+ String property3 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
+ String property4 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
+ String property5 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("does.not.exist", "defaultValue");
+ String property6 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.test", "defaultValue");
+ String property7 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
+
+ assertEquals(property1, "MT");
+ assertEquals(property2, "http://localhost:5000/v2.0");
+ assertEquals(property3, "John");
+ assertEquals(property4, "FD205490A48D48475607C36B9AD902BF");
+ assertEquals(property5, "defaultValue");
+ assertEquals(property6, "1234");
+ assertEquals(property7, "true");
+ } catch (Exception e) {
+ e.printStackTrace ();
+ return 1;
+ }
+ return 0;
+ }
+ };
+
+ @Test
+ public final void testGetMsoProperties()
+ throws MsoPropertiesException, InterruptedException, ExecutionException, FileNotFoundException {
+
+ List<Future<Integer>> list = new ArrayList<>();
+ ExecutorService executor = Executors.newFixedThreadPool(20);
+
+ for (int i = 0; i <= 100000; i++) {
+
+ Future<Integer> futureResult = executor.submit(taskRead);
+ list.add(futureResult);
+
+ futureResult = executor.submit(taskReload);
+ list.add(futureResult);
+
+ futureResult = executor.submit(taskReadAll);
+ list.add(futureResult);
+ }
+ executor.shutdown();
+ while (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
;
}
- for (Future<Integer> result : list) {
- assertTrue(result.get().equals(0));
- }
+ for (Future<Integer> result : list) {
+ assertTrue(result.get().equals(0));
+ }
- }
+ }
}
diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryTest.java
index 9f5e71785e..db58c5a49e 100644
--- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryTest.java
+++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryTest.java
@@ -41,597 +41,571 @@ import com.fasterxml.jackson.databind.JsonNode;
/**
* This class implements test methods of the MsoPropertiesFactory features.
+ *
+ *
*/
public class MsoPropertiesFactoryTest {
- public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
-
- public static final String MSO_JAVA_PROP_ID = "TEST_JAVA_PROP";
- public static final String MSO_JSON_PROP_ID = "TEST_JSON_PROP";
- public static final String PATH_MSO_JAVA_PROP1 = MsoJavaProperties.class.getClassLoader().
- getResource("mso.properties")
- .toString().substring(5);
- public static final String PATH_MSO_JAVA_PROP2 = MsoJavaProperties.class.getClassLoader().
- getResource("mso2.properties")
- .toString().substring(5);
- public static final String PATH_MSO_JSON_PROP = MsoJavaProperties.class.getClassLoader().
- getResource("mso.json")
- .toString().substring(5);
- public static final String PATH_MSO_JSON_PROP2 = MsoJavaProperties.class.getClassLoader().
- getResource("mso2.json")
- .toString().substring(5);
- public static final String PATH_MSO_JSON_PROP_BAD = MsoJavaProperties.class.getClassLoader().
- getResource("mso-bad.json")
- .toString().substring(5);
-
- @BeforeClass
- public static final void prepareBeforeAllTests() {
- msoPropertiesFactory.removeAllMsoProperties();
- }
-
- /**
- * This method is called before any test occurs. It creates a fake tree from
- * scratch
- *
- * @throws MsoPropertiesException
- */
- @Before
- public final void prepareBeforeEachTest() throws MsoPropertiesException {
-
- msoPropertiesFactory.initializeMsoProperties(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP1);
- msoPropertiesFactory.initializeMsoProperties(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP);
- }
-
- @After
- public final void cleanAfterEachTest() throws MsoPropertiesException {
- msoPropertiesFactory.removeAllMsoProperties();
- }
-
- @Test
- public final void testNotRecognizedFile() {
- try {
- msoPropertiesFactory.initializeMsoProperties("BAD_FILE", "new_file.toto");
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Unable to load the MSO properties file because format is not recognized (only .json or" +
- " .properties): new_file.toto").equals(ep.getMessage()));
- }
- }
-
- @Test
- public final void testDoubleInit() {
-
- try {
- msoPropertiesFactory.initializeMsoProperties(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP1);
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("The factory contains already an instance of this mso properties: " +
- PATH_MSO_JAVA_PROP1).equals(ep.getMessage()));
- }
-
-
- }
-
- /**
- * This method implements a test for the getMsoJavaProperties method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testGetMsoJavaProperties() throws MsoPropertiesException {
- assertNotNull(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID));
- assertTrue(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).size() == 8);
-
- try {
- msoPropertiesFactory.getMsoJavaProperties(MSO_JSON_PROP_ID);
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Mso properties is not JAVA_PROP properties type:" + MSO_JSON_PROP_ID).
- equals(ep.getMessage()));
- }
-
- try {
- msoPropertiesFactory.getMsoJavaProperties("DUMB_PROP");
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Mso properties not found in cache:" + "DUMB_PROP").equals(ep.getMessage()));
- }
-
- }
-
- /**
- * This method test the MsoJavaProperties Set, equals and hascode
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testSetMsoJavaProperties() throws MsoPropertiesException {
- MsoJavaProperties msoPropChanged = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
- msoPropChanged.setProperty("testos", "testos");
- assertNotNull(msoPropChanged.getProperty("testos", null));
-
- // Check no modification occurred on cache one
- MsoJavaProperties msoPropCache = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
- assertNull(msoPropCache.getProperty("testos", null));
- assertFalse(msoPropChanged.hashCode() != msoPropCache.hashCode());
-
- assertFalse(msoPropChanged.equals(null));
- assertFalse(msoPropChanged.equals(msoPropCache));
- assertFalse(msoPropChanged.equals(Boolean.TRUE));
-
- assertTrue(msoPropChanged.equals(msoPropChanged));
- }
-
-
- /**
- * This method implements a test for the testGetMsoJsonProperties method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testGetMsoJsonProperties() throws MsoPropertiesException {
- assertNotNull(msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID));
-
- try {
- msoPropertiesFactory.getMsoJsonProperties(MSO_JAVA_PROP_ID);
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Mso properties is not JSON_PROP properties type:" + MSO_JAVA_PROP_ID).equals(ep.getMessage()));
- }
-
- try {
- msoPropertiesFactory.getMsoJsonProperties("DUMB_PROP");
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Mso properties not found in cache:" + "DUMB_PROP").equals(ep.getMessage()));
- }
-
- }
-
- /**
- * This method implements a test for the testGetAllMsoProperties method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testGetAllMsoProperties() throws MsoPropertiesException {
- assertNotNull(msoPropertiesFactory.getAllMsoProperties().size() == 2);
-
- }
-
- /**
- * This method implements a test for the testGetAllMsoProperties method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testToString() throws MsoPropertiesException {
- String dump = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID).toString();
- assertTrue(dump != null && !dump.isEmpty());
-
- dump = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).toString();
- assertTrue(dump != null && !dump.isEmpty());
-
- }
-
- /**
- * This method implements a test for the getProperty of JAVA_PROP type method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testGetProperties() throws MsoPropertiesException {
- MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
-
- String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
- String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
- String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
- String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
- String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
- String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
- String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
-
- assertEquals(property1, "MT");
- assertEquals(property2, "http://localhost:5000/v2.0");
- assertEquals(property3, "John");
- assertEquals(property4, "FD205490A48D48475607C36B9AD902BF");
- assertEquals(property5, "defaultValue");
- assertEquals(property6, "1234");
- assertEquals(property7, "true");
- }
-
- /**
- * This method implements a test for the getIntProperty JAVA_RPOP type method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testGetIntProperties() throws MsoPropertiesException {
- MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
- int property1 = msoProperties.getIntProperty("ecomp.mso.cloud.1.test", 345);
- int property2 = msoProperties.getIntProperty("ecomp.mso.cloud.1.publicNetId", 345);
- int property3 = msoProperties.getIntProperty("does.not.exist", 345);
- assertEquals(property1, 1234);
- assertEquals(property2, 345);
- assertEquals(property3, 345);
- }
-
- /**
- * This method implements a test for the getBooleanProperty JAVA_RPOP type method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testGetBooleanProperty() throws MsoPropertiesException {
- MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
- boolean property1 = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.boolean", false);
- boolean property2 = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.publicNetId", false);
- boolean property3NotThere = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.publicNetIdBad",
- true);
-
- assertEquals(property1, true);
- assertEquals(property2, false);
- assertEquals(property3NotThere, true);
- }
-
- /**
- * This method implements a test for the getEncryptedProperty JAVA_RPOP type method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testGetEncryptedProperty() throws MsoPropertiesException {
- MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
- String property1 = msoProperties.getEncryptedProperty("ecomp.mso.cloud.1.publicNetId",
- "defaultValue",
- "aa3871669d893c7fb8abbcda31b88b4f");
- String property2 = msoProperties.getEncryptedProperty("test", "defaultValue",
- "aa3871669d893c7fb8abbcda31b88b4f");
-
-
- String property3Wrong = msoProperties.getEncryptedProperty("ecomp.mso.cloud.1.publicNetId",
- "defaultValue",
- "aa3871669d893c7fb8abbcda31b88b4");
-
-
- assertEquals(property1, "changeme");
- assertEquals(property2, "defaultValue");
- assertEquals(property3Wrong, "defaultValue");
- }
-
- /**
- * This method implements a test for the getEncryptedProperty JAVA_RPOP type method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testencryptProperty() {
-
- assertTrue("FD205490A48D48475607C36B9AD902BF"
- .contains(msoPropertiesFactory.encryptProperty("changeme",
- "aa3871669d893c7fb8abbcda31b88b4f").getEntity().toString()));
-
-
- assertTrue("Invalid AES key length: 15 bytes".contains(msoPropertiesFactory.encryptProperty("changeme",
- "aa3871669d893c7fb8abbcda31b88b4").getEntity().toString()));
-
- }
-
- /**
- * This method implements a test for the getJSON JSON_RPOP type method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testGetJsonNode() throws MsoPropertiesException {
- MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
-
- JsonNode propNode = msoProperties.getJsonRootNode();
- assertNotNull(propNode);
- assertFalse(propNode.toString().isEmpty());
- assertTrue(propNode.isContainerNode());
- assertNotNull(propNode.path("asdc-connections").path("asdc-controller1"));
- assertNotNull(propNode.path("asdc-connections").path("asdc-controller2"));
-
- }
-
- /**
- * This method implements a test for the reloadMsoProperties method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testReloadJavaMsoProperties() throws MsoPropertiesException {
- MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
-
- // Do some additional test on propertiesHaveChanged method
- assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, null));
-
- // Change path with bad one
- try {
- msoPropertiesFactory.changeMsoPropertiesFilePath("DO_NOT_EXIST", PATH_MSO_JAVA_PROP2);
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Mso properties not found in cache:DO_NOT_EXIST").equals(ep.getMessage()));
- }
-
-
- // Change path with right one
- msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP2);
- assertTrue(PATH_MSO_JAVA_PROP2.equals(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).
- getPropertiesFileName()));
-
- assertTrue(msoPropertiesFactory.reloadMsoProperties());
- assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
- // Do a second time as timer value is set to 2
- assertTrue(msoPropertiesFactory.reloadMsoProperties());
- assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
-
- // Get the new one
- msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
- String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
- String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
- String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
- String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
- String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
- String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
- String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
-
- assertEquals(property1, "MT2");
- assertEquals(property2, "defaultValue");
- assertEquals(property3, "defaultValue");
- assertEquals(property4, "defaultValue");
- assertEquals(property5, "defaultValue");
- assertEquals(property6, "defaultValue");
- assertEquals(property7, "defaultValue");
-
- // Additional test on propertiesHaveChanged
- msoPropertiesFactory.removeAllMsoProperties();
-
- // Do some additional test on propertiesHaveChanged method
- try {
- msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, null);
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Mso properties not found in cache:" + MSO_JAVA_PROP_ID).equals(ep.getMessage()));
- }
-
- try {
- msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties);
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Mso properties not found in cache:" + MSO_JAVA_PROP_ID).equals(ep.getMessage()));
- }
-
- }
-
- /**
- * This method implements a test for the reloadMsoProperties method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testReloadMoreThanAMinuteMsoProperties() throws MsoPropertiesException {
- MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
-
- msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP2);
-
- // Simulate 2 minutes
- msoPropertiesFactory.reloadMsoProperties();
- assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
- msoPropertiesFactory.reloadMsoProperties();
-
- assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
-
- // Get the new one
- msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
- String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
- String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
- String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
- String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
- String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
- String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
- String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
-
- assertEquals(property1, "MT2");
- assertEquals(property2, "defaultValue");
- assertEquals(property3, "defaultValue");
- assertEquals(property4, "defaultValue");
- assertEquals(property5, "defaultValue");
- assertEquals(property6, "defaultValue");
- assertEquals(property7, "defaultValue");
-
-
- }
-
- /**
- * This method implements a test for the reloadMsoProperties method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testReloadBadMsoProperties() throws MsoPropertiesException {
- MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
-
- msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID,
- "file-does-not-exist.properties");
- msoPropertiesFactory.reloadMsoProperties();
- assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
- // Reload it a second time as initial timer parameter was set to 2
- msoPropertiesFactory.reloadMsoProperties();
-
- assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
-
- // Get the new one
- msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
- String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
- String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
- String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
- String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
- String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
- String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
- String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
-
- assertEquals(property1, "defaultValue");
- assertEquals(property2, "defaultValue");
- assertEquals(property3, "defaultValue");
- assertEquals(property4, "defaultValue");
- assertEquals(property5, "defaultValue");
- assertEquals(property6, "defaultValue");
- assertEquals(property7, "defaultValue");
-
- }
-
- /**
- * This method implements a test for the reloadMsoProperties method.
- *
- * @throws MsoPropertiesException
- */
- @Test
- public final void testReloadBadMsoJsonProperties() throws MsoPropertiesException {
- // Load a bad JSON file
- MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
-
- msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP_BAD);
-
- msoPropertiesFactory.reloadMsoProperties();
- assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
- // Reload it a second time as initial timer parameter was set to 2
- msoPropertiesFactory.reloadMsoProperties();
-
- assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
-
- // Get the new one
- msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
- assertNotNull(msoProperties);
- assertNotNull(msoProperties.getJsonRootNode());
- assertTrue(msoProperties.getJsonRootNode().size() == 0);
-
- }
-
- @Test
- public final void testRemoveMsoProperties() throws MsoPropertiesException {
- try {
- msoPropertiesFactory.removeMsoProperties("DUMB_PROP");
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Mso properties not found in cache:" + "DUMB_PROP").equals(ep.getMessage()));
- }
-
- msoPropertiesFactory.removeMsoProperties(MSO_JAVA_PROP_ID);
-
- try {
- msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
-
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Mso properties not found in cache:" + MSO_JAVA_PROP_ID).equals(ep.getMessage()));
- }
-
- }
-
- @Test
- public final void testInitializeWithNonExistingPropertiesFile() throws MsoPropertiesException {
- try {
- msoPropertiesFactory.initializeMsoProperties("NEW_BAD_FILE",
- "no_file.properties");
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Unable to load the MSO properties file because it has not been found:no_file.properties").
- equals(ep.getMessage()));
- }
-
- // empty object should be returned as no config has been loaded, anyway no exception should be raised
- // because the config ID must be loaded in cache
- // This is there for automatic reload attempt
- assertTrue(msoPropertiesFactory.getMsoJavaProperties("NEW_BAD_FILE").size() == 0);
- }
-
-
- @Test
- public final void testInitializeWithNonExistingJsonFile() throws MsoPropertiesException {
- try {
- msoPropertiesFactory.initializeMsoProperties("NEW_BAD_FILE", "no_file.json");
- fail("MsoPropertiesException should have been raised");
- } catch (MsoPropertiesException ep) {
- assertTrue(("Unable to load the MSO properties file because it has not been found:no_file.json").
- equals(ep.getMessage()));
- }
-
- // empty object should be returned as no config has been loaded, anyway no exception should be raised
- // because the config ID must be loaded in cache
- // This is there for automatic reload attempt
- assertTrue(msoPropertiesFactory.getMsoJsonProperties("NEW_BAD_FILE").
- getJsonRootNode() != null);
- assertTrue("{}".equals(msoPropertiesFactory.getMsoJsonProperties("NEW_BAD_FILE").
- getJsonRootNode().toString()));
- }
-
- @Test
- public final void testShowProperties() {
- assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().
- contains("/target/test-classes/mso.json(Timer:2mins)"));
- assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().
- contains("asdc-controller1"));
- assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().
- contains("/target/test-classes/mso.properties(Timer:2mins):"));
- assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().
- contains("ecomp.mso.cloud.1.keystoneUrl"));
-
- }
-
- @Test
- public final void testGetEncryptedPropertyJson() throws MsoPropertiesException {
- MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
- assertTrue("ThePassword".equals(msoProperties.getEncryptedProperty(msoProperties.getJsonRootNode().
- get("asdc-connections").get("asdc-controller1").get("asdcPassword"),
- "defautlvalue", "566B754875657232314F5548556D3665")));
-
- assertTrue("defautlvalue".equals(msoProperties.getEncryptedProperty(msoProperties.getJsonRootNode().
- get("asdc-connections").get("asdc-controller1").get("asdcPassword"),
- "defautlvalue", "566B754875657232314F5548556D366")));
-
-
- }
-
- @Test
- public final void testHashcodeAndEqualsMsoJsonProperties() throws MsoPropertiesException {
-
- MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
-
- msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP2);
-
- msoPropertiesFactory.reloadMsoProperties();
- assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
- // Reload it a second time as initial timer parameter was set to 2
- msoPropertiesFactory.reloadMsoProperties();
- assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
-
- // Get the new one
- MsoJsonProperties msoProperties2 = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
- assertFalse(msoProperties.hashCode() == msoProperties2.hashCode());
-
- assertFalse(msoProperties.equals(msoProperties2));
- assertTrue(msoProperties.equals(msoProperties));
- assertFalse(msoProperties.equals(null));
- assertFalse(msoProperties.toString().isEmpty());
-
- // Test a reload with timer set to 1 in PATH_MSO_JSON_PROP2
- msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP);
-
- msoPropertiesFactory.reloadMsoProperties();
- assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties2));
-
- }
-
+ public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+
+ public static final String MSO_JAVA_PROP_ID = "TEST_JAVA_PROP";
+ public static final String MSO_JSON_PROP_ID = "TEST_JSON_PROP";
+ public static final String PATH_MSO_JAVA_PROP1 = MsoJavaProperties.class.getClassLoader().getResource("mso.properties")
+ .toString().substring(5);
+ public static final String PATH_MSO_JAVA_PROP2 = MsoJavaProperties.class.getClassLoader().getResource("mso2.properties")
+ .toString().substring(5);
+ public static final String PATH_MSO_JSON_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.json")
+ .toString().substring(5);
+ public static final String PATH_MSO_JSON_PROP2 = MsoJavaProperties.class.getClassLoader().getResource("mso2.json")
+ .toString().substring(5);
+ public static final String PATH_MSO_JSON_PROP_BAD = MsoJavaProperties.class.getClassLoader().getResource("mso-bad.json")
+ .toString().substring(5);
+
+ @BeforeClass
+ public static final void prepareBeforeAllTests() {
+ msoPropertiesFactory.removeAllMsoProperties();
+ }
+ /**
+ * This method is called before any test occurs. It creates a fake tree from
+ * scratch
+ *
+ * @throws MsoPropertiesException
+ */
+ @Before
+ public final void prepareBeforeEachTest() throws MsoPropertiesException {
+
+ msoPropertiesFactory.initializeMsoProperties(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP1);
+ msoPropertiesFactory.initializeMsoProperties(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP);
+ }
+
+ @After
+ public final void cleanAfterEachTest() throws MsoPropertiesException {
+ msoPropertiesFactory.removeAllMsoProperties ();
+ }
+
+ @Test
+ public final void testNotRecognizedFile() {
+ try {
+ msoPropertiesFactory.initializeMsoProperties("BAD_FILE", "new_file.toto");
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Unable to load the MSO properties file because format is not recognized (only .json or .properties): new_file.toto").equals(ep.getMessage()));
+ }
+ }
+
+ @Test
+ public final void testDoubleInit() {
+
+ try {
+ msoPropertiesFactory.initializeMsoProperties(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP1);
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("The factory contains already an instance of this mso properties: "+PATH_MSO_JAVA_PROP1).equals(ep.getMessage()));
+ }
+
+
+ }
+
+ /**
+ * This method implements a test for the getMsoJavaProperties method.
+ *
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testGetMsoJavaProperties() throws MsoPropertiesException {
+ assertNotNull(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID));
+ assertTrue(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).size()==8);
+
+ try {
+ msoPropertiesFactory.getMsoJavaProperties(MSO_JSON_PROP_ID);
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Mso properties is not JAVA_PROP properties type:" + MSO_JSON_PROP_ID).equals(ep.getMessage()));
+ }
+
+ try {
+ msoPropertiesFactory.getMsoJavaProperties("DUMB_PROP");
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Mso properties not found in cache:"+"DUMB_PROP").equals(ep.getMessage()));
+ }
+
+ }
+
+ /**
+ * This method test the MsoJavaProperties Set, equals and hascode
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testSetMsoJavaProperties() throws MsoPropertiesException {
+ MsoJavaProperties msoPropChanged = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+ msoPropChanged.setProperty("testos", "testos");
+ assertNotNull(msoPropChanged.getProperty("testos", null));
+
+ // Check no modification occurred on cache one
+ MsoJavaProperties msoPropCache = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+ assertNull(msoPropCache.getProperty("testos", null));
+ assertFalse(msoPropChanged.hashCode() != msoPropCache.hashCode());
+
+ assertFalse(msoPropChanged.equals(null));
+ assertFalse(msoPropChanged.equals(msoPropCache));
+ assertFalse(msoPropChanged.equals(Boolean.TRUE));
+
+ assertTrue(msoPropChanged.equals(msoPropChanged));
+ }
+
+
+ /**
+ * This method implements a test for the testGetMsoJsonProperties method.
+ *
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testGetMsoJsonProperties() throws MsoPropertiesException {
+ assertNotNull(msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID));
+
+ try {
+ msoPropertiesFactory.getMsoJsonProperties(MSO_JAVA_PROP_ID);
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Mso properties is not JSON_PROP properties type:" + MSO_JAVA_PROP_ID).equals(ep.getMessage()));
+ }
+
+ try {
+ msoPropertiesFactory.getMsoJsonProperties("DUMB_PROP");
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Mso properties not found in cache:"+"DUMB_PROP").equals(ep.getMessage()));
+ }
+
+ }
+
+ /**
+ * This method implements a test for the testGetAllMsoProperties method.
+ *
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testGetAllMsoProperties() throws MsoPropertiesException {
+ assertNotNull(msoPropertiesFactory.getAllMsoProperties().size()==2);
+
+ }
+
+ /**
+ * This method implements a test for the testGetAllMsoProperties method.
+ *
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testToString() throws MsoPropertiesException {
+ String dump = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID).toString();
+ assertTrue(dump != null && !dump.isEmpty());
+
+ dump = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).toString();
+ assertTrue(dump != null && !dump.isEmpty());
+
+ }
+
+ /**
+ * This method implements a test for the getProperty of JAVA_PROP type method.
+ *
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testGetProperties() throws MsoPropertiesException {
+ MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+
+ String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
+ String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
+ String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
+ String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
+ String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
+ String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
+ String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
+
+ assertEquals(property1, "MT");
+ assertEquals(property2, "http://localhost:5000/v2.0");
+ assertEquals(property3, "John");
+ assertEquals(property4, "FD205490A48D48475607C36B9AD902BF");
+ assertEquals(property5, "defaultValue");
+ assertEquals(property6, "1234");
+ assertEquals(property7, "true");
+ }
+
+ /**
+ * This method implements a test for the getIntProperty JAVA_RPOP type method.
+ *
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testGetIntProperties() throws MsoPropertiesException {
+ MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+ int property1 = msoProperties.getIntProperty("ecomp.mso.cloud.1.test", 345);
+ int property2 = msoProperties.getIntProperty("ecomp.mso.cloud.1.publicNetId", 345);
+ int property3 = msoProperties.getIntProperty("does.not.exist", 345);
+ assertEquals(property1, 1234);
+ assertEquals(property2, 345);
+ assertEquals(property3, 345);
+ }
+
+ /**
+ * This method implements a test for the getBooleanProperty JAVA_RPOP type method.
+ *
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testGetBooleanProperty() throws MsoPropertiesException {
+ MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+ boolean property1 = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.boolean", false);
+ boolean property2 = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.publicNetId", false);
+ boolean property3NotThere = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.publicNetIdBad", true);
+
+ assertEquals(property1, true);
+ assertEquals(property2, false);
+ assertEquals(property3NotThere, true);
+ }
+
+ /**
+ * This method implements a test for the getEncryptedProperty JAVA_RPOP type method.
+ *
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testGetEncryptedProperty() throws MsoPropertiesException {
+ MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+ String property1 = msoProperties.getEncryptedProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue",
+ "aa3871669d893c7fb8abbcda31b88b4f");
+ String property2 = msoProperties.getEncryptedProperty("test", "defaultValue",
+ "aa3871669d893c7fb8abbcda31b88b4f");
+
+
+ String property3Wrong = msoProperties.getEncryptedProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue",
+ "aa3871669d893c7fb8abbcda31b88b4");
+
+
+ assertEquals(property1, "changeme");
+ assertEquals(property2, "defaultValue");
+ assertEquals(property3Wrong, "defaultValue");
+ }
+
+ /**
+ * This method implements a test for the getEncryptedProperty JAVA_RPOP type method.
+ *
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testencryptProperty() {
+
+ assertTrue("FD205490A48D48475607C36B9AD902BF"
+ .contains(msoPropertiesFactory.encryptProperty("changeme", "aa3871669d893c7fb8abbcda31b88b4f").getEntity().toString()));
+
+
+ assertTrue("Invalid AES key length: 15 bytes".contains(msoPropertiesFactory.encryptProperty("changeme", "aa3871669d893c7fb8abbcda31b88b4").getEntity().toString()));
+
+ }
+
+ /**
+ * This method implements a test for the getJSON JSON_RPOP type method.
+ *
+ * @throws MsoPropertiesException
+ */
+ @Test
+ public final void testGetJsonNode() throws MsoPropertiesException {
+ MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
+
+ JsonNode propNode = msoProperties.getJsonRootNode();
+ assertNotNull(propNode);
+ assertFalse(propNode.toString().isEmpty());
+ assertTrue(propNode.isContainerNode());
+ assertNotNull(propNode.path("asdc-connections").path("asdc-controller1"));
+ assertNotNull(propNode.path("asdc-connections").path("asdc-controller2"));
+
+ }
+
+ /**
+ * This method implements a test for the reloadMsoProperties method.
+ *
+ * @throws MsoPropertiesException
+ *
+ */
+ @Test
+ public final void testReloadJavaMsoProperties() throws MsoPropertiesException {
+ MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+
+ // Do some additional test on propertiesHaveChanged method
+ assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, null));
+
+ // Change path with bad one
+ try {
+ msoPropertiesFactory.changeMsoPropertiesFilePath("DO_NOT_EXIST", PATH_MSO_JAVA_PROP2);
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Mso properties not found in cache:DO_NOT_EXIST").equals(ep.getMessage()));
+ }
+
+
+ // Change path with right one
+ msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP2);
+ assertTrue(PATH_MSO_JAVA_PROP2.equals(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).getPropertiesFileName()));
+
+ assertTrue(msoPropertiesFactory.reloadMsoProperties());
+ assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
+ // Do a second time as timer value is set to 2
+ assertTrue(msoPropertiesFactory.reloadMsoProperties());
+ assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
+
+ // Get the new one
+ msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+ String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
+ String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
+ String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
+ String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
+ String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
+ String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
+ String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
+
+ assertEquals(property1, "MT2");
+ assertEquals(property2, "defaultValue");
+ assertEquals(property3, "defaultValue");
+ assertEquals(property4, "defaultValue");
+ assertEquals(property5, "defaultValue");
+ assertEquals(property6, "defaultValue");
+ assertEquals(property7, "defaultValue");
+
+ // Additional test on propertiesHaveChanged
+ msoPropertiesFactory.removeAllMsoProperties();
+
+ // Do some additional test on propertiesHaveChanged method
+ try {
+ msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, null);
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Mso properties not found in cache:"+MSO_JAVA_PROP_ID).equals(ep.getMessage()));
+ }
+
+ try {
+ msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties);
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Mso properties not found in cache:"+MSO_JAVA_PROP_ID).equals(ep.getMessage()));
+ }
+
+ }
+
+ /**
+ * This method implements a test for the reloadMsoProperties method.
+ *
+ * @throws MsoPropertiesException
+ *
+ */
+ @Test
+ public final void testReloadMoreThanAMinuteMsoProperties() throws MsoPropertiesException {
+ MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+
+ msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP2);
+
+ // Simulate 2 minutes
+ msoPropertiesFactory.reloadMsoProperties();
+ assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
+ msoPropertiesFactory.reloadMsoProperties();
+
+ assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
+
+ // Get the new one
+ msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+ String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
+ String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
+ String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
+ String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
+ String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
+ String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
+ String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
+
+ assertEquals(property1, "MT2");
+ assertEquals(property2, "defaultValue");
+ assertEquals(property3, "defaultValue");
+ assertEquals(property4, "defaultValue");
+ assertEquals(property5, "defaultValue");
+ assertEquals(property6, "defaultValue");
+ assertEquals(property7, "defaultValue");
+
+
+ }
+
+ /**
+ * This method implements a test for the reloadMsoProperties method.
+ *
+ * @throws MsoPropertiesException
+ *
+ */
+ @Test
+ public final void testReloadBadMsoProperties() throws MsoPropertiesException {
+ MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+
+ msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, "file-does-not-exist.properties");
+ msoPropertiesFactory.reloadMsoProperties();
+ assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
+ // Reload it a second time as initial timer parameter was set to 2
+ msoPropertiesFactory.reloadMsoProperties();
+
+ assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
+
+ // Get the new one
+ msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+ String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
+ String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
+ String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
+ String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
+ String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
+ String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
+ String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
+
+ assertEquals(property1, "defaultValue");
+ assertEquals(property2, "defaultValue");
+ assertEquals(property3, "defaultValue");
+ assertEquals(property4, "defaultValue");
+ assertEquals(property5, "defaultValue");
+ assertEquals(property6, "defaultValue");
+ assertEquals(property7, "defaultValue");
+
+ }
+
+ /**
+ * This method implements a test for the reloadMsoProperties method.
+ *
+ * @throws MsoPropertiesException
+ *
+ */
+ @Test
+ public final void testReloadBadMsoJsonProperties() throws MsoPropertiesException {
+ // Load a bad JSON file
+ MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
+
+ msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP_BAD);
+
+ msoPropertiesFactory.reloadMsoProperties();
+ assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
+ // Reload it a second time as initial timer parameter was set to 2
+ msoPropertiesFactory.reloadMsoProperties();
+
+ assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
+
+ // Get the new one
+ msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
+ assertNotNull(msoProperties);
+ assertNotNull(msoProperties.getJsonRootNode());
+ assertTrue(msoProperties.getJsonRootNode().size() == 0);
+
+ }
+
+ @Test
+ public final void testRemoveMsoProperties() throws MsoPropertiesException {
+ try {
+ msoPropertiesFactory.removeMsoProperties("DUMB_PROP");
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Mso properties not found in cache:"+"DUMB_PROP").equals(ep.getMessage()));
+ }
+
+ msoPropertiesFactory.removeMsoProperties(MSO_JAVA_PROP_ID);
+
+ try {
+ msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
+
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Mso properties not found in cache:"+MSO_JAVA_PROP_ID).equals(ep.getMessage()));
+ }
+
+ }
+
+ @Test
+ public final void testInitializeWithNonExistingPropertiesFile () throws MsoPropertiesException {
+ try {
+ msoPropertiesFactory.initializeMsoProperties("NEW_BAD_FILE", "no_file.properties");
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Unable to load the MSO properties file because it has not been found:no_file.properties").equals(ep.getMessage()));
+ }
+
+ // empty object should be returned as no config has been loaded, anyway no exception should be raised because the config ID must be loaded in cache
+ // This is there for automatic reload attempt
+ assertTrue(msoPropertiesFactory.getMsoJavaProperties("NEW_BAD_FILE").size()==0);
+ }
+
+
+ @Test
+ public final void testInitializeWithNonExistingJsonFile () throws MsoPropertiesException {
+ try {
+ msoPropertiesFactory.initializeMsoProperties("NEW_BAD_FILE", "no_file.json");
+ fail ("MsoPropertiesException should have been raised");
+ } catch (MsoPropertiesException ep) {
+ assertTrue(("Unable to load the MSO properties file because it has not been found:no_file.json").equals(ep.getMessage()));
+ }
+
+ // empty object should be returned as no config has been loaded, anyway no exception should be raised because the config ID must be loaded in cache
+ // This is there for automatic reload attempt
+ assertTrue(msoPropertiesFactory.getMsoJsonProperties("NEW_BAD_FILE").getJsonRootNode()!=null);
+ assertTrue("{}".equals(msoPropertiesFactory.getMsoJsonProperties("NEW_BAD_FILE").getJsonRootNode().toString()));
+ }
+
+ @Test
+ public final void testShowProperties() {
+ assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("/target/test-classes/mso.json(Timer:2mins)"));
+ assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("asdc-controller1"));
+ assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("/target/test-classes/mso.properties(Timer:2mins):"));
+ assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("ecomp.mso.cloud.1.keystoneUrl"));
+
+ }
+
+ @Test
+ public final void testGetEncryptedPropertyJson() throws MsoPropertiesException {
+ MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
+ assertTrue("ThePassword".equals(msoProperties.getEncryptedProperty(msoProperties.getJsonRootNode().get("asdc-connections").get("asdc-controller1").get("asdcPassword"),"defautlvalue","566B754875657232314F5548556D3665")));
+
+ assertTrue("defautlvalue".equals(msoProperties.getEncryptedProperty(msoProperties.getJsonRootNode().get("asdc-connections").get("asdc-controller1").get("asdcPassword"),"defautlvalue","566B754875657232314F5548556D366")));
+
+
+ }
+
+ @Test
+ public final void testHashcodeAndEqualsMsoJsonProperties() throws MsoPropertiesException {
+
+ MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
+
+ msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP2);
+
+ msoPropertiesFactory.reloadMsoProperties();
+ assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
+ // Reload it a second time as initial timer parameter was set to 2
+ msoPropertiesFactory.reloadMsoProperties();
+ assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
+
+ // Get the new one
+ MsoJsonProperties msoProperties2 = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
+ assertFalse(msoProperties.hashCode()==msoProperties2.hashCode());
+
+ assertFalse(msoProperties.equals(msoProperties2));
+ assertTrue(msoProperties.equals(msoProperties));
+ assertFalse(msoProperties.equals(null));
+ assertFalse(msoProperties.toString().isEmpty());
+
+ // Test a reload with timer set to 1 in PATH_MSO_JSON_PROP2
+ msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP);
+
+ msoPropertiesFactory.reloadMsoProperties();
+ assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties2));
+
+ }
+
}
diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertyInitializerTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertyInitializerTest.java
index 3d9ed77983..419a82b8a4 100644
--- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertyInitializerTest.java
+++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertyInitializerTest.java
@@ -41,47 +41,48 @@ import org.openecomp.mso.properties.MsoPropertyInitializer;
public class MsoPropertyInitializerTest {
- public static final String ASDC_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.json").toString().substring(5);
- public static ServletContextEvent servletContextEvent = Mockito.mock(ServletContextEvent.class);
- public static ServletContext servletContext = Mockito.mock(ServletContext.class);
+ public static final String ASDC_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.json").toString().substring(5);
+ public static ServletContextEvent servletContextEvent = Mockito.mock(ServletContextEvent.class);
+ public static ServletContext servletContext = Mockito.mock(ServletContext.class);
public MsoPropertyInitializer msoPropInitializer = new MsoPropertyInitializer();
-
- @BeforeClass
- public static final void prepareBeforeClass() throws MsoPropertiesException {
-
- Mockito.when(servletContextEvent.getServletContext()).thenReturn(servletContext);
- }
-
- @Before
- public final void preparebeforeEachTest() throws MsoPropertiesException {
- MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
- msoPropertiesFactory.removeAllMsoProperties();
-
- }
-
- @Test
- public void testContextInitialized() throws MsoPropertiesException {
- Mockito.when(servletContext.getInitParameter("mso.configuration")).thenReturn("MSO_PROP_ASDC=" + ASDC_PROP);
- msoPropInitializer.contextInitialized(servletContextEvent);
-
- MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
- assertNotNull(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC"));
- assertFalse("{}".equals(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().toString()));
- assertTrue(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().get("asdc-connections") != null);
- }
-
- @Test
- public void testContextInitializedFailure() throws MsoPropertiesException {
- Mockito.when(servletContext.getInitParameter("mso.configuration")).thenReturn("MSO_PROP_ASDC=" + "Does_not_exist.json");
- msoPropInitializer.contextInitialized(servletContextEvent);
-
- // No exception should be raised, log instead
- MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
-
- assertTrue("{}".equals(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().toString()));
- assertTrue(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().get("asdc-connections") == null);
-
-
- }
-
+
+ @BeforeClass
+ public static final void prepareBeforeClass() throws MsoPropertiesException {
+
+ Mockito.when(servletContextEvent.getServletContext()).thenReturn(servletContext);
+ }
+
+ @Before
+ public final void preparebeforeEachTest() throws MsoPropertiesException {
+ MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+ msoPropertiesFactory.removeAllMsoProperties();
+
+ }
+
+ @Test
+ public void testContextInitialized() throws MsoPropertiesException {
+ Mockito.when(servletContext.getInitParameter("mso.configuration")).thenReturn("MSO_PROP_ASDC="+ASDC_PROP);
+ msoPropInitializer.contextInitialized(servletContextEvent);
+
+ MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+ assertNotNull(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC"));
+ assertFalse("{}".equals(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().toString()));
+ assertTrue(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().get("asdc-connections")!= null);
+ }
+
+ @Test
+ public void testContextInitializedFailure() throws MsoPropertiesException {
+ Mockito.when(servletContext.getInitParameter("mso.configuration")).thenReturn("MSO_PROP_ASDC="+"Does_not_exist.json");
+ msoPropInitializer.contextInitialized(servletContextEvent);
+
+ // No exception should be raised, log instead
+ MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+
+ assertTrue("{}".equals(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().toString()));
+ assertTrue(msoPropertiesFactory.getMsoJsonProperties("MSO_PROP_ASDC").getJsonRootNode().get("asdc-connections")== null);
+
+
+
+ }
+
}
diff --git a/common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java b/common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java
index d81a885f4b..eeb7342d50 100644
--- a/common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java
+++ b/common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java
@@ -32,25 +32,25 @@ public class CheckResultsTest {
* Test method for {@link org.openecomp.mso.utils.CheckResults#getResults()}.
*/
@Test
- public final void testGetResults() {
- CheckResults cr = new CheckResults();
- cr.addHostCheckResult("host1", 0, "output");
- cr.addHostCheckResult("host2", 2, "output2");
- cr.addServiceCheckResult("host1", "service1", 0, "outputServ");
- cr.addServiceCheckResult("host1", "service2", 2, "outputServ2");
- cr.addServiceCheckResult("host2", "service1", 0, "output2Serv");
- cr.addServiceCheckResult("host2", "service2", 2, "output2Serv2");
- List<CheckResult> res = cr.getResults();
- assert(res.size() == 6);
- assert(res.get(0).getHostname().equals("host1"));
- assert(res.get(1).getHostname().equals("host2"));
- assert(res.get(2).getHostname().equals("host1"));
- assert(res.get(3).getHostname().equals("host1"));
- assert(res.get(4).getHostname().equals("host2"));
- assert(res.get(5).getHostname().equals("host2"));
- assert(res.get(0).getServicename() == null);
- assert(res.get(3).getServicename().equals("service2"));
- assert(res.get(5).getState() == 2);
+ public final void testGetResults () {
+ CheckResults cr = new CheckResults ();
+ cr.addHostCheckResult ("host1", 0, "output");
+ cr.addHostCheckResult ("host2", 2, "output2");
+ cr.addServiceCheckResult ("host1", "service1", 0, "outputServ");
+ cr.addServiceCheckResult ("host1", "service2", 2, "outputServ2");
+ cr.addServiceCheckResult ("host2", "service1", 0, "output2Serv");
+ cr.addServiceCheckResult ("host2", "service2", 2, "output2Serv2");
+ List <CheckResult> res = cr.getResults ();
+ assert(res.size () == 6);
+ assert(res.get (0).getHostname ().equals ("host1"));
+ assert(res.get (1).getHostname ().equals ("host2"));
+ assert(res.get (2).getHostname ().equals ("host1"));
+ assert(res.get (3).getHostname ().equals ("host1"));
+ assert(res.get (4).getHostname ().equals ("host2"));
+ assert(res.get (5).getHostname ().equals ("host2"));
+ assert(res.get (0).getServicename () == null);
+ assert(res.get (3).getServicename ().equals ("service2"));
+ assert(res.get (5).getState () == 2);
}
}