diff options
author | ChrisC <cc697w@intl.att.com> | 2017-01-31 11:40:03 +0100 |
---|---|---|
committer | ChrisC <cc697w@intl.att.com> | 2017-01-31 12:59:33 +0100 |
commit | 025301d08b061482c1f046d562bf017c8cbcfe8d (patch) | |
tree | 68a2a549736c9bf0f7cd4e71c76e40ef7e2606f2 /common/src/test/java/org/openecomp | |
parent | 2754ad52f833278a5c925bd788a16d1dce16a598 (diff) |
Initial OpenECOMP MSO commit
Change-Id: Ia6a7574859480717402cc2f22534d9973a78fa6d
Signed-off-by: ChrisC <cc697w@intl.att.com>
Diffstat (limited to 'common/src/test/java/org/openecomp')
34 files changed, 4527 insertions, 0 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 new file mode 100644 index 0000000000..302102b839 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/CryptoTest.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.adapter_utils.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.security.GeneralSecurityException; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.openecomp.mso.utils.CryptoUtils; + +/** + * This class implements all test methods of the CryptoUtils features. + * + * + */ +public class CryptoTest { + + 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 () { + + } + + /** + * This method implements a test of tree structure, mainly the storage of the leaves structure. + * @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)); + } + +} 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 new file mode 100644 index 0000000000..52246b00d9 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoAlarmLoggerTest.java @@ -0,0 +1,131 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.adapter_utils.tests; + + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.openecomp.mso.logger.MsoAlarmLogger; +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.properties.MsoPropertiesException; +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(); + + } +} 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 new file mode 100644 index 0000000000..3da16be23a --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoLoggerTest.java @@ -0,0 +1,339 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.adapter_utils.tests; + +import org.openecomp.mso.entity.MsoRequest; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.logger.MsoLogger.ErrorCode; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.MDC; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +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); + + /** + * This method is called before any test occurs. + * It creates a fake tree from scratch + */ + @BeforeClass + 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(); + } + + @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(); + } + + @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(); + } + + + + /** + * This method implements a test of getSeverifyLevel method. + */ + @Test + public final void testGetSeverityLevel () { + + try { + String levelInfo = (String)invokePriveMethod("getSeverityLevel", "INFO"); + Assert.assertEquals (levelInfo, "0"); + + String levelWarn = (String)invokePriveMethod("getSeverityLevel", "WARN"); + Assert.assertEquals (levelWarn, "1"); + + String levelERROR = (String)invokePriveMethod("getSeverityLevel", "ERROR"); + Assert.assertEquals (levelERROR, "2"); + + 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(); + } + } + + /** + * 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 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(); + } + } + /** + * 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(); + } + } + + /** + * 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(); + } + } + + /** + * 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(); + } + } + + + + + // 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; + } + + // 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; + } +} 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 new file mode 100644 index 0000000000..ac27b20ada --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java @@ -0,0 +1,174 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.adapter_utils.tests; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.openecomp.mso.properties.AbstractMsoProperties; +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.properties.MsoPropertiesException; +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<Future<Integer>>(); + 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)); + } + + } + +} 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 new file mode 100644 index 0000000000..b0290b088e --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryTest.java @@ -0,0 +1,611 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.adapter_utils.tests; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.codehaus.jackson.JsonNode; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.properties.MsoJsonProperties; +import org.openecomp.mso.properties.MsoPropertiesException; +import org.openecomp.mso.properties.MsoPropertiesFactory; + +/** + * 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(new 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.equals(new String())); + + // 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 new file mode 100644 index 0000000000..36b6249737 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertyInitializerTest.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.adapter_utils.tests; + + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; + +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.properties.MsoPropertiesException; +import org.openecomp.mso.properties.MsoPropertiesFactory; +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 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); + + + + } + +} diff --git a/common/src/test/java/org/openecomp/mso/entity/MsoRequestESTest.java b/common/src/test/java/org/openecomp/mso/entity/MsoRequestESTest.java new file mode 100644 index 0000000000..a4fe1d361b --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/entity/MsoRequestESTest.java @@ -0,0 +1,65 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 09:09:00 GMT 2016 + */ + +package org.openecomp.mso.entity; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoRequestESTest extends MsoRequestESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoRequest msoRequest0 = new MsoRequest(); + msoRequest0.setServiceInstanceId("B1!G~O TIP1Auoc}pE"); + String string0 = msoRequest0.getServiceInstanceId(); + assertEquals("B1!G~O TIP1Auoc}pE", string0); + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + MsoRequest msoRequest0 = new MsoRequest(); + msoRequest0.setServiceInstanceId(""); + String string0 = msoRequest0.getServiceInstanceId(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test2() throws Throwable { + MsoRequest msoRequest0 = new MsoRequest(); + String string0 = msoRequest0.getRequestId(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test3() throws Throwable { + MsoRequest msoRequest0 = new MsoRequest("'SJ", "XUQ4Vd$ppTT4"); + assertEquals("'SJ", msoRequest0.getRequestId()); + + msoRequest0.setRequestId(""); + msoRequest0.getRequestId(); + assertEquals("XUQ4Vd$ppTT4", msoRequest0.getServiceInstanceId()); + } + + @Test(timeout = 4000) + public void test4() throws Throwable { + MsoRequest msoRequest0 = new MsoRequest("'SJ", "XUQ4Vd$ppTT4"); + String string0 = msoRequest0.getRequestId(); + assertEquals("XUQ4Vd$ppTT4", msoRequest0.getServiceInstanceId()); + assertEquals("'SJ", string0); + } + + @Test(timeout = 4000) + public void test5() throws Throwable { + MsoRequest msoRequest0 = new MsoRequest(); + String string0 = msoRequest0.getServiceInstanceId(); + assertNull(string0); + } +} diff --git a/common/src/test/java/org/openecomp/mso/entity/MsoRequestESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/entity/MsoRequestESTestscaffolding.java new file mode 100644 index 0000000000..9ac7ad816d --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/entity/MsoRequestESTestscaffolding.java @@ -0,0 +1,78 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 09:09:00 GMT 2016 + */ + +package org.openecomp.mso.entity; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoRequestESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.entity.MsoRequest"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoRequestESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.entity.MsoRequest" + ); + } + + private static void resetClasses() { + } +} diff --git a/common/src/test/java/org/openecomp/mso/logger/LogFilterESTest.java b/common/src/test/java/org/openecomp/mso/logger/LogFilterESTest.java new file mode 100644 index 0000000000..22936857c6 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/logger/LogFilterESTest.java @@ -0,0 +1,191 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 09:08:24 GMT 2016 + */ + +package org.openecomp.mso.logger; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.shaded.org.mockito.Mockito.*; +import static org.evosuite.runtime.MockitoExtension.*; +import static org.evosuite.runtime.EvoAssertions.*; + +import java.security.Principal; +import javax.servlet.AsyncContext; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.ServletResponseWrapper; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.ViolatedAssumptionAnswer; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class LogFilterESTest extends LogFilterESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + LogFilter logFilter0 = new LogFilter(); + FilterChain filterChain0 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + // Undeclared exception! + try { + logFilter0.doFilter((ServletRequest) null, (ServletResponse) null, filterChain0); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.logger.LogFilter", e); + } + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + LogFilter logFilter0 = new LogFilter(); + ServletRequest servletRequest0 = mock(ServletRequest.class, new ViolatedAssumptionAnswer()); + ServletResponse servletResponse0 = mock(ServletResponse.class, new ViolatedAssumptionAnswer()); + FilterChain filterChain0 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + // Undeclared exception! + try { + logFilter0.doFilter(servletRequest0, servletResponse0, filterChain0); + fail("Expecting exception: ClassCastException"); + + } catch(ClassCastException e) { + // + // $javax.servlet.ServletRequest$$EnhancerByMockitoWithCGLIB$$d677bdba cannot be cast to javax.servlet.http.HttpServletRequest + // + verifyException("org.openecomp.mso.logger.LogFilter", e); + } + } + + @Test(timeout = 4000) + public void test2() throws Throwable { + LogFilter logFilter0 = new LogFilter(); + FilterConfig filterConfig0 = mock(FilterConfig.class, new ViolatedAssumptionAnswer()); + logFilter0.init(filterConfig0); + ServletRequest servletRequest0 = mock(ServletRequest.class, new ViolatedAssumptionAnswer()); + ServletResponse servletResponse0 = mock(ServletResponse.class, new ViolatedAssumptionAnswer()); + FilterChain filterChain0 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + // Undeclared exception! + try { + logFilter0.doFilter(servletRequest0, servletResponse0, filterChain0); + fail("Expecting exception: ClassCastException"); + + } catch(ClassCastException e) { + // + // $javax.servlet.ServletRequest$$EnhancerByMockitoWithCGLIB$$d677bdba cannot be cast to javax.servlet.http.HttpServletRequest + // + verifyException("org.openecomp.mso.logger.LogFilter", e); + } + } + + @Test(timeout = 4000) + public void test3() throws Throwable { + LogFilter logFilter0 = new LogFilter(); + FilterConfig filterConfig0 = mock(FilterConfig.class, new ViolatedAssumptionAnswer()); + logFilter0.init(filterConfig0); + ServletRequest servletRequest0 = null; + ServletResponse servletResponse0 = mock(ServletResponse.class, new ViolatedAssumptionAnswer()); + ServletResponse servletResponse1 = mock(ServletResponse.class, new ViolatedAssumptionAnswer()); + FilterChain filterChain0 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + // Undeclared exception! + try { + logFilter0.doFilter((ServletRequest) null, servletResponse1, filterChain0); + fail("Expecting exception: ClassCastException"); + + } catch(ClassCastException e) { + // + // $javax.servlet.ServletResponse$$EnhancerByMockitoWithCGLIB$$b9bd7b44 cannot be cast to javax.servlet.http.HttpServletResponse + // + verifyException("org.openecomp.mso.logger.LogFilter", e); + } + } + + @Test(timeout = 4000) + public void test4() throws Throwable { + LogFilter logFilter0 = new LogFilter(); + logFilter0.destroy(); + HttpServletRequest httpServletRequest0 = mock(HttpServletRequest.class, new ViolatedAssumptionAnswer()); + HttpServletRequestWrapper httpServletRequestWrapper0 = new HttpServletRequestWrapper(httpServletRequest0); + ServletResponse servletResponse0 = null; + ServletResponseWrapper servletResponseWrapper0 = null; + try { + servletResponseWrapper0 = new ServletResponseWrapper((ServletResponse) null); + fail("Expecting exception: IllegalArgumentException"); + + } catch(IllegalArgumentException e) { + // + // Response cannot be null + // + verifyException("javax.servlet.ServletResponseWrapper", e); + } + } + + @Test(timeout = 4000) + public void test5() throws Throwable { + LogFilter logFilter0 = new LogFilter(); + HttpServletRequest httpServletRequest0 = mock(HttpServletRequest.class, new ViolatedAssumptionAnswer()); + doReturn((String) null, (String) null, (String) null, (String) null, (String) null).when(httpServletRequest0).getRemoteAddr(); + doReturn((AsyncContext) null).when(httpServletRequest0).startAsync(any(javax.servlet.ServletRequest.class) , any(javax.servlet.ServletResponse.class)); + doReturn((Principal) null, (Principal) null, (Principal) null, (Principal) null, (Principal) null).when(httpServletRequest0).getUserPrincipal(); + HttpServletRequestWrapper httpServletRequestWrapper0 = new HttpServletRequestWrapper(httpServletRequest0); + ServletRequest servletRequest0 = httpServletRequestWrapper0.getRequest(); + HttpServletResponse httpServletResponse0 = mock(HttpServletResponse.class, new ViolatedAssumptionAnswer()); + doReturn((String) null).when(httpServletResponse0).getCharacterEncoding(); + HttpServletResponseWrapper httpServletResponseWrapper0 = new HttpServletResponseWrapper(httpServletResponse0); + FilterChain filterChain0 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + logFilter0.doFilter(servletRequest0, httpServletResponseWrapper0, filterChain0); + logFilter0.destroy(); + LogFilter logFilter1 = new LogFilter(); + HttpServletResponseWrapper httpServletResponseWrapper1 = new HttpServletResponseWrapper((HttpServletResponse) httpServletResponseWrapper0); + FilterChain filterChain1 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + logFilter0.doFilter(servletRequest0, httpServletResponseWrapper0, filterChain1); + FilterChain filterChain2 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + logFilter1.doFilter(servletRequest0, httpServletResponseWrapper1, filterChain2); + HttpServletResponseWrapper httpServletResponseWrapper2 = (HttpServletResponseWrapper)httpServletResponseWrapper1.getResponse(); + httpServletResponseWrapper1.getCharacterEncoding(); + httpServletResponseWrapper1.flushBuffer(); + httpServletRequestWrapper0.startAsync(servletRequest0, (ServletResponse) httpServletResponseWrapper1); + FilterChain filterChain3 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + logFilter1.doFilter(servletRequest0, httpServletResponseWrapper2, filterChain3); + FilterChain filterChain4 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + FilterChain filterChain5 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + logFilter1.doFilter(httpServletRequestWrapper0, httpServletResponseWrapper1, filterChain5); + logFilter1.doFilter(servletRequest0, httpServletResponseWrapper0, filterChain4); + logFilter0.destroy(); + FilterConfig filterConfig0 = mock(FilterConfig.class, new ViolatedAssumptionAnswer()); + logFilter1.init(filterConfig0); + LogFilter logFilter2 = new LogFilter(); + FilterConfig filterConfig1 = mock(FilterConfig.class, new ViolatedAssumptionAnswer()); + logFilter1.init(filterConfig1); + logFilter0.destroy(); + assertFalse(logFilter0.equals((Object)logFilter1)); + } + + @Test(timeout = 4000) + public void test6() throws Throwable { + LogFilter logFilter0 = new LogFilter(); + Principal principal0 = mock(Principal.class, new ViolatedAssumptionAnswer()); + doReturn((String) null).when(principal0).getName(); + HttpServletRequest httpServletRequest0 = mock(HttpServletRequest.class, new ViolatedAssumptionAnswer()); + doReturn("$PJ-hW?").when(httpServletRequest0).getRemoteAddr(); + doReturn(principal0).when(httpServletRequest0).getUserPrincipal(); + HttpServletRequestWrapper httpServletRequestWrapper0 = new HttpServletRequestWrapper(httpServletRequest0); + ServletRequest servletRequest0 = httpServletRequestWrapper0.getRequest(); + HttpServletResponse httpServletResponse0 = mock(HttpServletResponse.class, new ViolatedAssumptionAnswer()); + HttpServletResponseWrapper httpServletResponseWrapper0 = new HttpServletResponseWrapper(httpServletResponse0); + ServletResponse servletResponse0 = httpServletResponseWrapper0.getResponse(); + FilterChain filterChain0 = mock(FilterChain.class, new ViolatedAssumptionAnswer()); + logFilter0.doFilter(servletRequest0, servletResponse0, filterChain0); + FilterConfig filterConfig0 = mock(FilterConfig.class, new ViolatedAssumptionAnswer()); + logFilter0.init(filterConfig0); + } +} diff --git a/common/src/test/java/org/openecomp/mso/logger/LogFilterESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/logger/LogFilterESTestscaffolding.java new file mode 100644 index 0000000000..50487634d4 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/logger/LogFilterESTestscaffolding.java @@ -0,0 +1,78 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 09:08:24 GMT 2016 + */ + +package org.openecomp.mso.logger; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class LogFilterESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.logger.LogFilter"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(LogFilterESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.logger.LogFilter" + ); + } + + private static void resetClasses() { + } +} diff --git a/common/src/test/java/org/openecomp/mso/logger/MsoAlarmLoggerESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/logger/MsoAlarmLoggerESTestscaffolding.java new file mode 100644 index 0000000000..320b7557b7 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/logger/MsoAlarmLoggerESTestscaffolding.java @@ -0,0 +1,90 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 09:05:53 GMT 2016 + */ + +package org.openecomp.mso.logger; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +@EvoSuiteClassExclude +public class MsoAlarmLoggerESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + protected static ExecutorService executor; + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.logger.MsoAlarmLogger"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + executor = Executors.newCachedThreadPool(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + executor.shutdownNow(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoAlarmLoggerESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.logger.MsoAlarmLogger" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoAlarmLoggerESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.logger.MsoAlarmLogger" + ); + } +} diff --git a/common/src/test/java/org/openecomp/mso/logger/MsoLogInitializerESTest.java b/common/src/test/java/org/openecomp/mso/logger/MsoLogInitializerESTest.java new file mode 100644 index 0000000000..97058d5df3 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/logger/MsoLogInitializerESTest.java @@ -0,0 +1,37 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 09:06:06 GMT 2016 + */ + +package org.openecomp.mso.logger; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.shaded.org.mockito.Mockito.*; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.PrivateAccess; +import org.evosuite.runtime.ViolatedAssumptionAnswer; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoLogInitializerESTest extends MsoLogInitializerESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoLogInitializer msoLogInitializer0 = new MsoLogInitializer(); + ServletContextEvent servletContextEvent0 = mock(ServletContextEvent.class, new ViolatedAssumptionAnswer()); + doReturn((ServletContext) null).when(servletContextEvent0).getServletContext(); + msoLogInitializer0.contextInitialized(servletContextEvent0); + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + MsoLogInitializer msoLogInitializer0 = new MsoLogInitializer(); + Boolean boolean0 = (Boolean)PrivateAccess.callMethod((Class<MsoLogInitializer>) MsoLogInitializer.class, msoLogInitializer0, "fileIsReadable", (Object) "", (Class<?>) String.class); + assertTrue(boolean0); + } +} diff --git a/common/src/test/java/org/openecomp/mso/logger/MsoLogInitializerESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/logger/MsoLogInitializerESTestscaffolding.java new file mode 100644 index 0000000000..c0139549fb --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/logger/MsoLogInitializerESTestscaffolding.java @@ -0,0 +1,145 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 09:06:06 GMT 2016 + */ + +package org.openecomp.mso.logger; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoLogInitializerESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.logger.MsoLogInitializer"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoLogInitializerESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.logger.MsoLogger", + "org.openecomp.mso.logger.MessageEnum", + "com.att.eelf.i18n.EELFResolvableErrorEnum", + "org.openecomp.mso.logger.MsoLogger$ResponseCode", + "org.openecomp.mso.entity.MsoRequest", + "org.openecomp.mso.logger.MsoLogger$StatusCode", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "com.att.eelf.configuration.EELFLogger", + "com.att.eelf.i18n.EELFMsgs", + "com.att.eelf.configuration.EELFLogger$Level", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "com.att.eelf.configuration.SLF4jWrapper", + "org.openecomp.mso.logger.MsoLogInitializer", + "com.att.eelf.i18n.EELFResourceManager" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoLogInitializerESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "com.att.eelf.i18n.EELFResourceManager", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.openecomp.mso.logger.MsoLogInitializer", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "org.openecomp.mso.logger.MsoLogger", + "com.att.eelf.i18n.EELFMsgs", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "org.apache.xerces.jaxp.SAXParserFactoryImpl", + "org.apache.xerces.jaxp.SAXParserImpl", + "org.apache.xerces.parsers.XMLParser", + "org.apache.xerces.parsers.AbstractSAXParser", + "org.apache.xerces.parsers.SAXParser", + "org.apache.xerces.parsers.ObjectFactory", + "org.apache.xerces.util.ParserConfigurationSettings", + "org.apache.xerces.parsers.XML11Configuration", + "org.apache.xerces.parsers.XIncludeAwareParserConfiguration", + "org.apache.xerces.util.SymbolTable", + "org.apache.xerces.impl.XMLEntityManager", + "org.apache.xerces.util.AugmentationsImpl$SmallContainer", + "org.apache.xerces.impl.XMLEntityManager$ByteBufferPool", + "org.apache.xerces.impl.XMLEntityManager$CharacterBufferPool", + "org.apache.xerces.impl.XMLEntityScanner$1", + "org.apache.xerces.impl.XMLEntityScanner", + "org.apache.xerces.impl.XMLErrorReporter", + "org.apache.xerces.impl.XMLScanner", + "org.apache.xerces.impl.XMLDocumentFragmentScannerImpl", + "org.apache.xerces.impl.XMLDocumentScannerImpl", + "org.apache.xerces.util.XMLStringBuffer", + "org.apache.xerces.util.XMLAttributesImpl", + "org.apache.xerces.impl.XMLDTDScannerImpl", + "org.apache.xerces.impl.dtd.XMLDTDProcessor", + "org.apache.xerces.impl.dtd.XMLDTDValidator", + "org.apache.xerces.impl.validation.ValidationState", + "org.apache.xerces.impl.dtd.XMLElementDecl", + "org.apache.xerces.impl.dtd.XMLSimpleType", + "org.apache.xerces.impl.dv.DTDDVFactory", + "org.apache.xerces.impl.dv.ObjectFactory", + "org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl", + "org.apache.xerces.impl.XMLVersionDetector", + "org.apache.xerces.impl.msg.XMLMessageFormatter", + "org.apache.xerces.impl.io.UTF8Reader", + "org.apache.xerces.util.XMLSymbols", + "org.apache.xerces.xni.NamespaceContext", + "org.apache.xerces.util.XMLChar", + "org.apache.xerces.impl.Constants", + "com.att.eelf.configuration.EELFLogger$Level", + "com.att.eelf.configuration.EELFManager" + ); + } +} diff --git a/common/src/test/java/org/openecomp/mso/logger/MsoLoggingServletESTest.java b/common/src/test/java/org/openecomp/mso/logger/MsoLoggingServletESTest.java new file mode 100644 index 0000000000..2761f647bc --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/logger/MsoLoggingServletESTest.java @@ -0,0 +1,34 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 09:04:06 GMT 2016 + */ + +package org.openecomp.mso.logger; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.runtime.EvoAssertions.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.PrivateAccess; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoLoggingServletESTest extends MsoLoggingServletESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoLoggingServlet msoLoggingServlet0 = new MsoLoggingServlet(); + try { + PrivateAccess.callMethod((Class<MsoLoggingServlet>) MsoLoggingServlet.class, msoLoggingServlet0, "isMsoLogger", (Object) null, (Class<?>) String.class); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.logger.MsoLoggingServlet", e); + } + } +} diff --git a/common/src/test/java/org/openecomp/mso/logger/MsoLoggingServletESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/logger/MsoLoggingServletESTestscaffolding.java new file mode 100644 index 0000000000..be6c378ccc --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/logger/MsoLoggingServletESTestscaffolding.java @@ -0,0 +1,337 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 09:04:06 GMT 2016 + */ + +package org.openecomp.mso.logger; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoLoggingServletESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.logger.MsoLoggingServlet"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoLoggingServletESTestscaffolding.class.getClassLoader() , + "org.jboss.resteasy.spi.StringConverter", + "org.apache.xerces.impl.XMLEntityManager$CharacterBufferPool", + "org.apache.xerces.xni.XMLResourceIdentifier", + "org.apache.xerces.impl.XMLEntityManager", + "org.apache.xerces.impl.dtd.XMLDTDDescription", + "com.att.eelf.i18n.EELFMsgs", + "org.jboss.resteasy.util.ThreadLocalStack", + "org.apache.xerces.impl.dv.InvalidDatatypeValueException", + "org.apache.xerces.jaxp.UnparsedEntityHandler", + "org.apache.xerces.parsers.AbstractXMLDocumentParser", + "org.apache.xerces.impl.XMLScanner", + "org.apache.xerces.impl.dv.dtd.NOTATIONDatatypeValidator", + "org.apache.xerces.xni.parser.XMLParseException", + "org.apache.xerces.impl.XMLEntityScanner", + "org.apache.xerces.util.URI$MalformedURIException", + "org.apache.xerces.impl.XMLNSDocumentScannerImpl", + "org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry", + "org.apache.xerces.impl.dtd.models.CMAny", + "org.apache.xerces.util.URI", + "org.apache.xerces.xni.parser.XMLDocumentFilter", + "org.apache.xerces.xni.parser.XMLDTDSource", + "org.apache.xerces.impl.dtd.XMLAttributeDecl", + "org.apache.xerces.parsers.XMLParser", + "org.jboss.resteasy.spi.ResteasyProviderFactory", + "org.apache.xerces.util.SymbolTable", + "org.apache.xerces.impl.io.Latin1Reader", + "org.apache.xerces.impl.dv.ValidationContext", + "org.jboss.resteasy.spi.BadRequestException", + "org.apache.xerces.impl.dtd.XMLDTDValidator", + "org.apache.xerces.impl.dtd.XML11NSDTDValidator", + "org.openecomp.mso.logger.MsoLoggingServlet", + "org.apache.xerces.util.AugmentationsImpl", + "org.jboss.resteasy.core.interception.ReaderInterceptorRegistry", + "org.apache.xerces.impl.dv.ObjectFactory", + "org.jboss.resteasy.client.exception.mapper.ClientExceptionMapper", + "org.apache.xerces.impl.dv.DatatypeValidator", + "org.jboss.resteasy.spi.InjectorFactory", + "org.jboss.resteasy.core.interception.LegacyPrecedence", + "org.apache.xerces.jaxp.SAXParserImpl", + "org.apache.xerces.xni.grammars.XMLGrammarDescription", + "org.jboss.resteasy.plugins.delegates.NewCookieHeaderDelegate", + "org.apache.xerces.xni.parser.XMLErrorHandler", + "org.apache.xerces.util.MessageFormatter", + "org.apache.xerces.impl.XMLEntityManager$1", + "org.apache.xerces.xni.parser.XMLDTDScanner", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "org.apache.xerces.xni.XMLAttributes", + "org.apache.xerces.impl.dv.dtd.StringDatatypeValidator", + "org.apache.xerces.impl.io.MalformedByteSequenceException", + "org.apache.xerces.impl.Constants$ArrayEnumeration", + "org.jboss.resteasy.core.interception.WriterInterceptorRegistry", + "org.apache.xerces.impl.dv.DTDDVFactory", + "org.apache.xerces.impl.dv.dtd.IDDatatypeValidator", + "org.apache.xerces.impl.validation.ValidationManager", + "org.apache.xerces.xni.XNIException", + "org.apache.xerces.impl.dtd.models.CMNode", + "org.apache.xerces.xni.parser.XMLDocumentSource", + "org.apache.xerces.xni.XMLDTDContentModelHandler", + "org.jboss.resteasy.spi.StringParameterUnmarshaller", + "org.jboss.resteasy.core.MediaTypeMap", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.apache.xerces.util.AugmentationsImpl$SmallContainer", + "org.apache.xerces.impl.XMLErrorReporter", + "org.jboss.resteasy.specimpl.ResteasyUriBuilder", + "org.apache.xerces.impl.Constants", + "org.apache.xerces.util.XMLStringBuffer", + "org.apache.xerces.jaxp.JAXPConstants", + "org.apache.xerces.xni.parser.XMLParserConfiguration", + "org.apache.xerces.xni.XMLString", + "org.apache.xerces.impl.dv.DVFactoryException", + "org.apache.xerces.impl.dv.DatatypeException", + "org.apache.xerces.parsers.XML11Configurable", + "org.apache.xerces.parsers.XIncludeAwareParserConfiguration", + "org.jboss.resteasy.logging.Logger$LoggerType", + "org.apache.xerces.impl.xs.identity.FieldActivator", + "org.apache.xerces.impl.XMLEntityScanner$1", + "org.apache.xerces.jaxp.SAXParserFactoryImpl", + "org.jboss.resteasy.util.CaseInsensitiveMap$CaseInsensitiveComparator", + "org.apache.xerces.xs.ElementPSVI", + "org.apache.xerces.parsers.AbstractSAXParser", + "org.jboss.resteasy.spi.LoggableFailure", + "org.apache.xerces.xni.parser.XMLDTDFilter", + "org.apache.xerces.xni.parser.XMLDTDContentModelSource", + "org.openecomp.mso.entity.MsoRequest", + "org.apache.xerces.xni.XMLLocator", + "org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser", + "org.apache.xerces.xni.Augmentations", + "org.apache.xerces.impl.XMLEntityHandler", + "org.jboss.resteasy.util.CaseInsensitiveMap$1", + "org.jboss.resteasy.specimpl.BuiltResponse", + "org.jboss.resteasy.core.Headers", + "org.apache.xerces.xni.parser.XMLComponent", + "org.apache.xerces.impl.dv.dtd.ListDatatypeValidator", + "org.jboss.resteasy.spi.Failure", + "org.apache.xerces.impl.XMLEntityManager$ScannedEntity", + "org.apache.xerces.jaxp.JAXPValidatorComponent", + "org.apache.xerces.xni.parser.XMLDTDContentModelFilter", + "org.apache.xerces.xs.PSVIProvider", + "org.apache.xerces.impl.XMLEntityManager$ByteBufferPool", + "org.jboss.resteasy.specimpl.ResponseBuilderImpl", + "org.jboss.resteasy.core.interception.ClientResponseFilterRegistry", + "org.apache.xerces.impl.dtd.XMLEntityDecl", + "org.apache.xerces.xs.ItemPSVI", + "org.jboss.resteasy.specimpl.MultivaluedTreeMap", + "org.apache.xerces.impl.dv.dtd.ENTITYDatatypeValidator", + "org.apache.xerces.xni.parser.XMLEntityResolver", + "org.jboss.resteasy.client.core.ClientErrorInterceptor", + "org.apache.xerces.impl.dtd.XMLNSDTDValidator", + "org.apache.xerces.impl.XMLDTDScannerImpl", + "org.apache.xerces.impl.dv.dtd.NMTOKENDatatypeValidator", + "org.apache.xerces.parsers.ObjectFactory", + "org.jboss.resteasy.spi.ResteasyProviderFactory$SortedKey", + "org.apache.xerces.xni.parser.XMLConfigurationException", + "org.apache.xerces.impl.XML11NSDocumentScannerImpl", + "org.apache.xerces.parsers.SAXParser", + "com.att.eelf.i18n.EELFResolvableErrorEnum", + "org.apache.xerces.impl.XMLEntityManager$RewindableInputStream", + "org.jboss.resteasy.core.interception.ContainerRequestFilterRegistry", + "org.jboss.resteasy.specimpl.VariantListBuilderImpl", + "org.apache.xerces.xni.parser.XMLInputSource", + "org.apache.xerces.xni.parser.XMLComponentManager", + "com.att.eelf.configuration.EELFLogger$Level", + "org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry$InterceptorFactory", + "org.apache.xerces.impl.io.UTF8Reader", + "org.apache.xerces.impl.dtd.XMLSimpleType", + "org.apache.xerces.impl.XML11DocumentScannerImpl", + "org.apache.xerces.util.AugmentationsImpl$AugmentationsItemsContainer", + "org.apache.xerces.util.XMLChar", + "org.apache.xerces.impl.XML11DTDScannerImpl", + "org.apache.xerces.impl.dtd.XMLElementDecl", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "org.apache.xerces.xni.grammars.Grammar", + "org.apache.xerces.impl.dtd.models.ContentModelValidator", + "com.att.eelf.configuration.EELFLogger", + "org.apache.xerces.xni.grammars.XMLGrammarLoader", + "org.apache.xerces.xni.XMLDocumentHandler", + "org.apache.xerces.impl.io.UCSReader", + "org.apache.xerces.impl.XMLEntityManager$CharacterBuffer", + "org.apache.xerces.impl.validation.ValidationState", + "org.apache.xerces.impl.XMLEntityManager$Entity", + "org.jboss.resteasy.spi.HttpRequest", + "org.apache.xerces.util.XMLResourceIdentifierImpl", + "org.jboss.resteasy.logging.Logger", + "org.jboss.resteasy.spi.ConstructorInjector", + "org.apache.xerces.xni.NamespaceContext", + "org.apache.xerces.impl.dtd.XMLDTDLoader", + "org.jboss.resteasy.util.CaseInsensitiveMap", + "org.apache.xerces.util.XMLSymbols", + "org.apache.xerces.parsers.ObjectFactory$ConfigurationError", + "org.jboss.resteasy.core.interception.ContainerResponseFilterRegistry", + "org.apache.xerces.impl.io.ASCIIReader", + "org.jboss.resteasy.core.interception.InterceptorRegistry", + "org.apache.xerces.impl.dtd.XMLDTDProcessor", + "org.apache.xerces.impl.XMLDocumentFragmentScannerImpl", + "org.apache.xerces.impl.XML11EntityScanner", + "org.apache.xerces.impl.dtd.DTDGrammar", + "org.apache.xerces.impl.dv.dtd.IDREFDatatypeValidator", + "com.att.eelf.configuration.SLF4jWrapper", + "org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl", + "org.apache.xerces.impl.dtd.XMLContentSpec", + "org.openecomp.mso.logger.MsoLogger", + "org.apache.xerces.xs.AttributePSVI", + "org.apache.xerces.impl.dtd.DTDGrammarBucket", + "org.apache.xerces.impl.msg.XMLMessageFormatter", + "org.apache.xerces.xni.parser.XMLDocumentScanner", + "org.apache.xerces.impl.XMLVersionDetector", + "org.apache.xerces.impl.XMLDocumentScannerImpl", + "org.apache.xerces.xni.parser.XMLPullParserConfiguration", + "org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$Dispatcher", + "org.apache.xerces.impl.xs.XMLSchemaValidator", + "org.apache.xerces.xni.grammars.XMLDTDDescription", + "org.jboss.resteasy.logging.impl.Slf4jLogger", + "org.apache.xerces.xni.QName", + "org.apache.xerces.jaxp.TeeXMLDocumentFilterImpl", + "org.apache.xerces.util.XMLAttributesImpl", + "org.apache.xerces.impl.XMLEntityManager$InternalEntity", + "org.apache.xerces.impl.RevalidationHandler", + "org.jboss.resteasy.spi.HeaderValueProcessor", + "org.apache.xerces.util.AugmentationsImpl$LargeContainer", + "org.apache.xerces.impl.dtd.BalancedDTDGrammar", + "org.apache.xerces.xni.XMLDTDHandler", + "org.apache.xerces.impl.dtd.XML11DTDProcessor", + "org.apache.xerces.parsers.XML11Configuration", + "org.apache.xerces.impl.dtd.XMLDTDValidatorFilter", + "com.att.eelf.i18n.EELFResourceManager", + "org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate", + "org.jboss.resteasy.core.MediaTypeMap$Typed", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.logger.MsoLogger$ResponseCode", + "org.openecomp.mso.logger.MsoLogger$StatusCode", + "com.att.eelf.configuration.EELFManager", + "org.jboss.resteasy.spi.HttpResponse", + "org.apache.xerces.impl.validation.EntityState", + "org.apache.xerces.impl.XMLEntityManager$ExternalEntity", + "org.apache.xerces.util.ParserConfigurationSettings", + "org.apache.xerces.impl.dv.ObjectFactory$ConfigurationError", + "com.att.eelf.i18n.EELFResourceManager$1", + "org.apache.xerces.impl.dtd.XML11DTDValidator" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoLoggingServletESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "com.att.eelf.i18n.EELFResourceManager", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.openecomp.mso.logger.MsoLogger", + "com.att.eelf.i18n.EELFMsgs", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "org.apache.xerces.jaxp.SAXParserFactoryImpl", + "org.apache.xerces.jaxp.SAXParserImpl", + "org.apache.xerces.parsers.XMLParser", + "org.apache.xerces.parsers.AbstractSAXParser", + "org.apache.xerces.parsers.SAXParser", + "org.apache.xerces.parsers.ObjectFactory", + "org.apache.xerces.util.ParserConfigurationSettings", + "org.apache.xerces.parsers.XML11Configuration", + "org.apache.xerces.parsers.XIncludeAwareParserConfiguration", + "org.apache.xerces.util.SymbolTable", + "org.apache.xerces.impl.XMLEntityManager", + "org.apache.xerces.util.AugmentationsImpl$SmallContainer", + "org.apache.xerces.impl.XMLEntityManager$ByteBufferPool", + "org.apache.xerces.impl.XMLEntityManager$CharacterBufferPool", + "org.apache.xerces.impl.XMLEntityScanner$1", + "org.apache.xerces.impl.XMLEntityScanner", + "org.apache.xerces.impl.XMLErrorReporter", + "org.apache.xerces.impl.XMLScanner", + "org.apache.xerces.impl.XMLDocumentFragmentScannerImpl", + "org.apache.xerces.impl.XMLDocumentScannerImpl", + "org.apache.xerces.util.XMLStringBuffer", + "org.apache.xerces.util.XMLAttributesImpl", + "org.apache.xerces.impl.XMLDTDScannerImpl", + "org.apache.xerces.impl.dtd.XMLDTDProcessor", + "org.apache.xerces.impl.dtd.XMLDTDValidator", + "org.apache.xerces.impl.validation.ValidationState", + "org.apache.xerces.impl.dtd.XMLElementDecl", + "org.apache.xerces.impl.dtd.XMLSimpleType", + "org.apache.xerces.impl.dv.DTDDVFactory", + "org.apache.xerces.impl.dv.ObjectFactory", + "org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl", + "org.apache.xerces.impl.XMLVersionDetector", + "org.apache.xerces.impl.msg.XMLMessageFormatter", + "org.apache.xerces.impl.io.UTF8Reader", + "org.apache.xerces.util.XMLSymbols", + "org.apache.xerces.xni.NamespaceContext", + "org.apache.xerces.util.XMLChar", + "org.apache.xerces.impl.Constants", + "com.att.eelf.configuration.EELFLogger$Level", + "com.att.eelf.configuration.EELFManager", + "org.jboss.resteasy.logging.Logger$LoggerType", + "org.jboss.resteasy.logging.Logger", + "org.jboss.resteasy.spi.ResteasyProviderFactory", + "org.jboss.resteasy.core.MediaTypeMap", + "org.jboss.resteasy.core.interception.LegacyPrecedence", + "org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate", + "org.jboss.resteasy.plugins.delegates.NewCookieHeaderDelegate", + "org.jboss.resteasy.specimpl.MultivaluedTreeMap", + "org.jboss.resteasy.util.CaseInsensitiveMap$CaseInsensitiveComparator", + "org.jboss.resteasy.util.CaseInsensitiveMap", + "org.jboss.resteasy.core.Headers", + "org.openecomp.mso.logger.MsoLoggingServlet" + ); + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/AbstractMsoPropertiesESTest.java b/common/src/test/java/org/openecomp/mso/properties/AbstractMsoPropertiesESTest.java new file mode 100644 index 0000000000..535d929807 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/AbstractMsoPropertiesESTest.java @@ -0,0 +1,151 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 09:09:20 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import static org.evosuite.runtime.EvoAssertions.verifyException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.FileNotFoundException; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class AbstractMsoPropertiesESTest extends AbstractMsoPropertiesESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + String string0 = msoJavaProperties0.toString(); + assertEquals("Config file null(Timer:0mins):\n\n\n", string0); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + MsoJavaProperties msoJavaProperties1 = msoJavaProperties0.clone(); + msoJavaProperties1.propertiesFileName = "+"; + msoJavaProperties1.getPropertiesFileName(); + assertEquals(0, msoJavaProperties1.getAutomaticRefreshInMinutes()); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + MsoJavaProperties msoJavaProperties1 = msoJavaProperties0.clone(); + msoJavaProperties1.propertiesFileName = ""; + msoJavaProperties1.getPropertiesFileName(); + assertEquals(0, msoJavaProperties1.getAutomaticRefreshInMinutes()); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.automaticRefreshInMinutes = (-1447); + int int0 = msoJavaProperties0.getAutomaticRefreshInMinutes(); + assertEquals((-1447), int0); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.equals(msoJavaProperties0); + assertEquals(0, msoJavaProperties0.getAutomaticRefreshInMinutes()); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.equals("X<0P%qxWR fu\""); + assertEquals(0, msoJavaProperties0.getAutomaticRefreshInMinutes()); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + MsoJavaProperties msoJavaProperties1 = (MsoJavaProperties)msoJavaProperties0.clone(); + assertEquals(0, msoJavaProperties1.getAutomaticRefreshInMinutes()); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.automaticRefreshInMinutes = (-1447); + MsoJavaProperties msoJavaProperties1 = (MsoJavaProperties)msoJavaProperties0.clone(); + assertTrue(msoJavaProperties1.equals((Object)msoJavaProperties0)); + } + + /** + * TODO: fails when run using maven, but succeeds when run using eclipse + * @throws Throwable + */ + @Ignore + @Test(timeout = 4000) + public void test08() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + // Undeclared exception! + try { + msoJavaProperties0.reloadPropertiesFile(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.evosuite.runtime.mock.java.io.MockFileInputStream", e); + } + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.propertiesFileName = "ASDC_ARTIFACT_ALREADY_DEPLOYED"; + try { + msoJavaProperties0.reloadPropertiesFile(); + fail("Expecting exception: FileNotFoundException"); + + } catch(FileNotFoundException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.evosuite.runtime.mock.java.io.MockFileInputStream", e); + } + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + try { + msoJavaProperties0.loadPropertiesFile("Trying to reset value handler for type ["); + fail("Expecting exception: FileNotFoundException"); + + } catch(FileNotFoundException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.evosuite.runtime.mock.java.io.MockFileInputStream", e); + } + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.getPropertiesFileName(); + assertEquals(0, msoJavaProperties0.getAutomaticRefreshInMinutes()); + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + int int0 = msoJavaProperties0.getAutomaticRefreshInMinutes(); + assertEquals(0, int0); + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/AbstractMsoPropertiesESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/properties/AbstractMsoPropertiesESTestscaffolding.java new file mode 100644 index 0000000000..4224f01dc0 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/AbstractMsoPropertiesESTestscaffolding.java @@ -0,0 +1,120 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 09:09:20 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class AbstractMsoPropertiesESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.properties.AbstractMsoProperties"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(AbstractMsoPropertiesESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.properties.AbstractMsoProperties", + "org.openecomp.mso.logger.MsoLogger", + "org.openecomp.mso.logger.MessageEnum", + "com.att.eelf.i18n.EELFResolvableErrorEnum", + "org.openecomp.mso.logger.MsoLogger$ResponseCode", + "org.openecomp.mso.entity.MsoRequest", + "org.openecomp.mso.logger.MsoLogger$StatusCode", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "com.att.eelf.configuration.EELFLogger", + "com.att.eelf.i18n.EELFMsgs", + "com.att.eelf.configuration.EELFLogger$Level", + "org.openecomp.mso.properties.MsoJavaProperties", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "com.att.eelf.configuration.SLF4jWrapper", + "com.att.eelf.i18n.EELFResourceManager" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(AbstractMsoPropertiesESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.codehaus.jackson.map.introspect.AnnotatedClass", + "org.codehaus.jackson.map.introspect.BasicClassIntrospector", + "org.codehaus.jackson.annotate.JsonAutoDetect$Visibility", + "org.codehaus.jackson.annotate.JsonMethod", + "org.codehaus.jackson.map.introspect.VisibilityChecker$Std", + "org.codehaus.jackson.map.ObjectMapper", + "org.codehaus.jackson.JsonParser$Feature", + "org.codehaus.jackson.JsonGenerator$Feature", + "org.codehaus.jackson.JsonFactory", + "org.codehaus.jackson.sym.CharsToNameCanonicalizer", + "org.codehaus.jackson.sym.BytesToNameCanonicalizer", + "org.codehaus.jackson.map.type.TypeFactory", + "org.openecomp.mso.utils.CryptoUtils", + "org.openecomp.mso.logger.MsoLogger", + "com.att.eelf.i18n.EELFResourceManager", + "com.att.eelf.i18n.EELFMsgs", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "com.att.eelf.configuration.EELFLogger$Level", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.properties.AbstractMsoProperties" + ); + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/MsoJavaPropertiesESTest.java b/common/src/test/java/org/openecomp/mso/properties/MsoJavaPropertiesESTest.java new file mode 100644 index 0000000000..d64f63fb2c --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/MsoJavaPropertiesESTest.java @@ -0,0 +1,358 @@ +/* + * This file was automatically generated by EvoSuite + * Thu Nov 10 08:35:35 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import static org.evosuite.runtime.EvoAssertions.verifyException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.FileNotFoundException; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.PrivateAccess; +import org.evosuite.runtime.testdata.FileSystemHandling; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.openecomp.mso.logger.MsoLogger; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoJavaPropertiesESTest extends MsoJavaPropertiesESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.setProperty("", "J6"); + msoJavaProperties0.hashCode(); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + String string0 = msoJavaProperties0.getProperty("IK#uRP]", (String) null); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + String string0 = msoJavaProperties0.getProperty("", ""); + assertNotNull(string0); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + int int0 = msoJavaProperties0.getIntProperty("RA_VNF_NOT_EXIST", (-1417)); + assertEquals((-1417), int0); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + String string0 = msoJavaProperties0.getEncryptedProperty("", "", ""); + assertEquals("", string0); + assertNotNull(string0); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.automaticRefreshInMinutes = 1821; + MsoJavaProperties msoJavaProperties1 = msoJavaProperties0.clone(); + assertNotSame(msoJavaProperties1, msoJavaProperties0); + assertEquals(1821, msoJavaProperties1.getAutomaticRefreshInMinutes()); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.automaticRefreshInMinutes = (-78); + MsoJavaProperties msoJavaProperties1 = msoJavaProperties0.clone(); + assertNotSame(msoJavaProperties1, msoJavaProperties0); + assertEquals(-78, msoJavaProperties1.getAutomaticRefreshInMinutes()); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + FileSystemHandling fileSystemHandling0 = new FileSystemHandling(); + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + PrivateAccess.setVariable((Class<MsoJavaProperties>) MsoJavaProperties.class, msoJavaProperties0, "msoProperties", (Object) null); + msoJavaProperties0.hashCode(); + msoJavaProperties0.hashCode(); + // Undeclared exception! + try { + msoJavaProperties0.size(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.properties.MsoJavaProperties", e); + } + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + // Undeclared exception! + try { + msoJavaProperties0.setProperty((String) null, "+UaYo-~&{QxdaN(c"); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + } + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + MsoJavaProperties msoJavaProperties1 = msoJavaProperties0.clone(); + msoJavaProperties1.propertiesFileName = ""; + try { + msoJavaProperties1.reloadPropertiesFile(); + fail("Expecting exception: FileNotFoundException"); + + } catch(FileNotFoundException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.evosuite.runtime.mock.java.io.MockFileInputStream", e); + } + } + + /** + * TODO: fails when run using maven, but succeeds when run using eclipse + */ + @Ignore + @Test(timeout = 4000) + public void test12() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + // Undeclared exception! + try { + msoJavaProperties0.loadPropertiesFile((String) null); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.evosuite.runtime.mock.java.io.MockFileInputStream", e); + } + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + try { + msoJavaProperties0.loadPropertiesFile(""); + fail("Expecting exception: FileNotFoundException"); + + } catch(FileNotFoundException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.evosuite.runtime.mock.java.io.MockFileInputStream", e); + } + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + // Undeclared exception! + try { + msoJavaProperties0.getIntProperty((String) null, 0); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + } + } + + @Test(timeout = 4000) + public void test15() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.setProperty("APIH_READ_VNFOUTPUT_CLOB_EXCEPTION", ""); + // Undeclared exception! + try { + msoJavaProperties0.getEncryptedProperty("APIH_READ_VNFOUTPUT_CLOB_EXCEPTION", "", "k$&Fq}"); + fail("Expecting exception: NumberFormatException"); + + } catch(NumberFormatException e) { + // + // For input string: \"k$\" + // + verifyException("java.lang.NumberFormatException", e); + } + } + + @Test(timeout = 4000) + public void test16() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + MsoJavaProperties msoJavaProperties1 = msoJavaProperties0.clone(); + msoJavaProperties1.clone(); + msoJavaProperties0.hashCode(); + MsoJavaProperties msoJavaProperties2 = msoJavaProperties1.clone(); + PrivateAccess.setVariable((Class<MsoJavaProperties>) MsoJavaProperties.class, msoJavaProperties0, "msoProperties", (Object) null); + msoJavaProperties1.equals(msoJavaProperties2); + MsoLogger msoLogger0 = AbstractMsoProperties.LOGGER; + // Undeclared exception! + try { + msoJavaProperties0.clone(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("java.util.Hashtable", e); + } + } + + @Test(timeout = 4000) + public void test18() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + int int0 = msoJavaProperties0.getIntProperty("", 0); + assertEquals(0, int0); + } + + @Test(timeout = 4000) + public void test19() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.setProperty("-6;qct1", ""); + String string0 = msoJavaProperties0.toString(); + assertEquals("Config file null(Timer:0mins):\n-6;qct1=\n\n\n", string0); + } + + @Test(timeout = 4000) + public void test20() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + boolean boolean0 = msoJavaProperties0.equals("APIH_READ_VNFOUTPUT_CLOB_EXCEPTION"); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test21() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + boolean boolean0 = msoJavaProperties0.equals((Object) null); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test22() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + boolean boolean0 = msoJavaProperties0.equals(msoJavaProperties0); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test24() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.setProperty("APIH_READ_VNFOUTPUT_CLOB_EXCEPTION", ""); + // Undeclared exception! + try { + msoJavaProperties0.getEncryptedProperty("APIH_READ_VNFOUTPUT_CLOB_EXCEPTION", ".", ""); + fail("Expecting exception: IllegalArgumentException"); + + } catch(IllegalArgumentException e) { + // + // Empty key + // + verifyException("javax.crypto.spec.SecretKeySpec", e); + } + } + + @Test(timeout = 4000) + public void test25() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + String string0 = msoJavaProperties0.getEncryptedProperty("YhmJSc|~L0$,?/oh", (String) null, "YhmJSc|~L0$,?/oh"); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test26() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.setProperty("M;WrYY%E,;sa&4F", "M;WrYY%E,;sa&4F"); + boolean boolean0 = msoJavaProperties0.getBooleanProperty("M;WrYY%E,;sa&4F", false); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test27() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + boolean boolean0 = msoJavaProperties0.getBooleanProperty("", true); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test28() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.setProperty("M;WrYY%E,;sa&4F", "M;WrYY%E,;sa&4F"); + int int0 = msoJavaProperties0.getIntProperty("M;WrYY%E,;sa&4F", 0); + assertEquals(0, int0); + } + + @Test(timeout = 4000) + public void test29() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + msoJavaProperties0.setProperty("", "J6"); + String string0 = msoJavaProperties0.getProperty("", "mso.properties.reload.time.minutes"); + assertNotNull(string0); + assertEquals("J6", string0); + } + /** + * TODO: fails when run using maven, but succeeds when run using eclipse + */ + @Ignore + @Test(timeout = 4000) + public void test30() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + // Undeclared exception! + try { + msoJavaProperties0.reloadPropertiesFile(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.evosuite.runtime.mock.java.io.MockFileInputStream", e); + } + } + + @Test(timeout = 4000) + public void test31() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + MsoJavaProperties msoJavaProperties1 = msoJavaProperties0.clone(); + assertTrue(msoJavaProperties1.equals((Object)msoJavaProperties0)); + + msoJavaProperties0.setProperty("", ""); + boolean boolean0 = msoJavaProperties0.equals(msoJavaProperties1); + assertFalse(boolean0); + assertFalse(msoJavaProperties1.equals((Object)msoJavaProperties0)); + } + + @Test(timeout = 4000) + public void test32() throws Throwable { + MsoJavaProperties msoJavaProperties0 = new MsoJavaProperties(); + int int0 = msoJavaProperties0.size(); + assertEquals(0, int0); + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/MsoJavaPropertiesESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/properties/MsoJavaPropertiesESTestscaffolding.java new file mode 100644 index 0000000000..da13dc1d3d --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/MsoJavaPropertiesESTestscaffolding.java @@ -0,0 +1,110 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 07:59:01 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoJavaPropertiesESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.properties.MsoJavaProperties"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoJavaPropertiesESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.properties.AbstractMsoProperties", + "org.openecomp.mso.logger.MsoLogger", + "org.openecomp.mso.logger.MessageEnum", + "com.att.eelf.i18n.EELFResolvableErrorEnum", + "org.openecomp.mso.logger.MsoLogger$ResponseCode", + "org.openecomp.mso.utils.CryptoUtils", + "org.openecomp.mso.entity.MsoRequest", + "org.openecomp.mso.logger.MsoLogger$StatusCode", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "com.att.eelf.configuration.EELFLogger", + "com.att.eelf.i18n.EELFMsgs", + "com.att.eelf.configuration.EELFLogger$Level", + "org.openecomp.mso.properties.MsoJavaProperties", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "com.att.eelf.configuration.SLF4jWrapper", + "com.att.eelf.i18n.EELFResourceManager$1", + "com.att.eelf.i18n.EELFResourceManager" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoJavaPropertiesESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.openecomp.mso.logger.MsoLogger", + "com.att.eelf.i18n.EELFResourceManager", + "com.att.eelf.i18n.EELFMsgs", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "com.att.eelf.configuration.EELFLogger$Level", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.properties.AbstractMsoProperties", + "org.openecomp.mso.utils.CryptoUtils" + ); + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/MsoJsonPropertiesESTest.java b/common/src/test/java/org/openecomp/mso/properties/MsoJsonPropertiesESTest.java new file mode 100644 index 0000000000..0243c13c7f --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/MsoJsonPropertiesESTest.java @@ -0,0 +1,35 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 09:04:39 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import static org.evosuite.runtime.EvoAssertions.verifyException; +import static org.junit.Assert.fail; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoJsonPropertiesESTest { + + @Ignore + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoJsonProperties msoJsonProperties0 = null; + try { + msoJsonProperties0 = new MsoJsonProperties(); + fail("Expecting exception: VerifyError"); + + } catch(VerifyError e) { + // + // (class: org/codehaus/jackson/map/MapperConfig, method: <clinit> signature: ()V) Bad type in putfield/putstatic + // + verifyException("org.codehaus.jackson.map.ObjectMapper", e); + } + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesExceptionESTest.java b/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesExceptionESTest.java new file mode 100644 index 0000000000..c53dd85fb0 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesExceptionESTest.java @@ -0,0 +1,24 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 09:10:06 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoPropertiesExceptionESTest extends MsoPropertiesExceptionESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoPropertiesException msoPropertiesException0 = new MsoPropertiesException(""); + MsoPropertiesException msoPropertiesException1 = new MsoPropertiesException("l6G(", (Throwable) msoPropertiesException0); + assertFalse(msoPropertiesException1.equals((Object)msoPropertiesException0)); + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesExceptionESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesExceptionESTestscaffolding.java new file mode 100644 index 0000000000..379956310b --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesExceptionESTestscaffolding.java @@ -0,0 +1,83 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 09:10:06 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoPropertiesExceptionESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.properties.MsoPropertiesException"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoPropertiesExceptionESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.properties.MsoPropertiesException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoPropertiesExceptionESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.properties.MsoPropertiesException" + ); + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesFactoryESTest.java b/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesFactoryESTest.java new file mode 100644 index 0000000000..7ab574569c --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesFactoryESTest.java @@ -0,0 +1,71 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 09:02:51 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.runtime.EvoAssertions.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.PrivateAccess; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoPropertiesFactoryESTest { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoPropertiesFactory msoPropertiesFactory0 = new MsoPropertiesFactory(); + // Undeclared exception! + try { + msoPropertiesFactory0.changeMsoPropertiesFilePath((String) null, "Unable to load the MSO properties file because format is not recognized (only .json or .properties): "); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + } + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + MsoPropertiesFactory msoPropertiesFactory0 = new MsoPropertiesFactory(); + msoPropertiesFactory0.removeAllMsoProperties(); + } + + @Test(timeout = 4000) + public void test2() throws Throwable { + MsoPropertiesFactory msoPropertiesFactory0 = new MsoPropertiesFactory(); + try { + msoPropertiesFactory0.getMsoJavaProperties("iz/`I"); + fail("Expecting exception: Exception"); + + } catch(Exception e) { + // + // Mso properties not found in cache:iz/`I + // + verifyException("org.openecomp.mso.properties.MsoPropertiesFactory", e); + } + } + + @Test(timeout = 4000) + public void test3() throws Throwable { + MsoPropertiesFactory msoPropertiesFactory0 = new MsoPropertiesFactory(); + MsoPropertiesParameters msoPropertiesParameters0 = new MsoPropertiesParameters(); + try { + PrivateAccess.callMethod((Class<MsoPropertiesFactory>) MsoPropertiesFactory.class, msoPropertiesFactory0, "createObjectType", (Object) msoPropertiesParameters0, (Class<?>) MsoPropertiesParameters.class, (Object) ":8nnlF[sGvCub6J", (Class<?>) String.class); + fail("Expecting exception: Exception"); + + } catch(Exception e) { + // + // Unable to load the MSO properties file because format is not recognized (only .json or .properties): :8nnlF[sGvCub6J + // + verifyException("org.openecomp.mso.properties.MsoPropertiesFactory", e); + } + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesParametersESTest.java b/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesParametersESTest.java new file mode 100644 index 0000000000..9579b3b367 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesParametersESTest.java @@ -0,0 +1,20 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 09:09:37 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import org.junit.Test; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoPropertiesParametersESTest extends MsoPropertiesParametersESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoPropertiesParameters msoPropertiesParameters0 = new MsoPropertiesParameters(); + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesParametersESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesParametersESTestscaffolding.java new file mode 100644 index 0000000000..fec0b9ecf1 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/MsoPropertiesParametersESTestscaffolding.java @@ -0,0 +1,129 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 09:09:37 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoPropertiesParametersESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.properties.MsoPropertiesParameters"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoPropertiesParametersESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.properties.MsoPropertiesParameters" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoPropertiesParametersESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.openecomp.mso.logger.MsoLogger", + "com.att.eelf.i18n.EELFResourceManager", + "com.att.eelf.i18n.EELFMsgs", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "org.apache.xerces.jaxp.SAXParserFactoryImpl", + "org.apache.xerces.jaxp.SAXParserImpl", + "org.apache.xerces.parsers.XMLParser", + "org.apache.xerces.parsers.AbstractSAXParser", + "org.apache.xerces.parsers.SAXParser", + "org.apache.xerces.parsers.ObjectFactory", + "org.apache.xerces.util.ParserConfigurationSettings", + "org.apache.xerces.parsers.XML11Configuration", + "org.apache.xerces.parsers.XIncludeAwareParserConfiguration", + "org.apache.xerces.util.SymbolTable", + "org.apache.xerces.impl.XMLEntityManager", + "org.apache.xerces.util.AugmentationsImpl$SmallContainer", + "org.apache.xerces.impl.XMLEntityManager$ByteBufferPool", + "org.apache.xerces.impl.XMLEntityManager$CharacterBufferPool", + "org.apache.xerces.impl.XMLEntityScanner$1", + "org.apache.xerces.impl.XMLEntityScanner", + "org.apache.xerces.impl.XMLErrorReporter", + "org.apache.xerces.impl.XMLScanner", + "org.apache.xerces.impl.XMLDocumentFragmentScannerImpl", + "org.apache.xerces.impl.XMLDocumentScannerImpl", + "org.apache.xerces.util.XMLStringBuffer", + "org.apache.xerces.util.XMLAttributesImpl", + "org.apache.xerces.impl.XMLDTDScannerImpl", + "org.apache.xerces.impl.dtd.XMLDTDProcessor", + "org.apache.xerces.impl.dtd.XMLDTDValidator", + "org.apache.xerces.impl.validation.ValidationState", + "org.apache.xerces.impl.dtd.XMLElementDecl", + "org.apache.xerces.impl.dtd.XMLSimpleType", + "org.apache.xerces.impl.dv.DTDDVFactory", + "org.apache.xerces.impl.dv.ObjectFactory", + "org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl", + "org.apache.xerces.impl.XMLVersionDetector", + "org.apache.xerces.impl.msg.XMLMessageFormatter", + "org.apache.xerces.impl.io.UTF8Reader", + "org.apache.xerces.util.XMLSymbols", + "org.apache.xerces.xni.NamespaceContext", + "org.apache.xerces.util.XMLChar", + "org.apache.xerces.impl.Constants", + "com.att.eelf.configuration.EELFLogger$Level", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.properties.AbstractMsoProperties" + ); + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/MsoPropertyInitializerESTest.java b/common/src/test/java/org/openecomp/mso/properties/MsoPropertyInitializerESTest.java new file mode 100644 index 0000000000..a7efa76b1b --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/MsoPropertyInitializerESTest.java @@ -0,0 +1,20 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:01:07 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import org.junit.Test; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoPropertyInitializerESTest extends MsoPropertyInitializerESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoPropertyInitializer msoPropertyInitializer0 = new MsoPropertyInitializer(); + } +} diff --git a/common/src/test/java/org/openecomp/mso/properties/MsoPropertyInitializerESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/properties/MsoPropertyInitializerESTestscaffolding.java new file mode 100644 index 0000000000..9a056fb576 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/properties/MsoPropertyInitializerESTestscaffolding.java @@ -0,0 +1,284 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:01:07 GMT 2016 + */ + +package org.openecomp.mso.properties; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoPropertyInitializerESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.properties.MsoPropertyInitializer"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoPropertyInitializerESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.properties.AbstractMsoProperties", + "org.apache.xerces.xni.parser.XMLDTDContentModelFilter", + "org.apache.xerces.xs.PSVIProvider", + "org.apache.xerces.impl.XMLEntityManager$ByteBufferPool", + "org.apache.xerces.impl.dtd.XMLEntityDecl", + "org.apache.xerces.xs.ItemPSVI", + "org.apache.xerces.xni.parser.XMLEntityResolver", + "org.apache.xerces.impl.dtd.XMLNSDTDValidator", + "org.apache.xerces.impl.XMLDTDScannerImpl", + "org.apache.xerces.parsers.ObjectFactory", + "org.apache.xerces.xni.parser.XMLConfigurationException", + "org.apache.xerces.impl.XML11NSDocumentScannerImpl", + "org.apache.xerces.impl.XMLEntityManager$CharacterBufferPool", + "org.apache.xerces.parsers.SAXParser", + "com.att.eelf.i18n.EELFResolvableErrorEnum", + "org.apache.xerces.xni.XMLResourceIdentifier", + "org.apache.xerces.impl.XMLEntityManager$RewindableInputStream", + "org.apache.xerces.impl.XMLEntityManager", + "org.apache.xerces.impl.dtd.XMLDTDDescription", + "org.apache.xerces.xni.parser.XMLInputSource", + "com.att.eelf.i18n.EELFMsgs", + "org.apache.xerces.xni.parser.XMLComponentManager", + "com.att.eelf.configuration.EELFLogger$Level", + "org.apache.xerces.impl.io.UTF8Reader", + "org.apache.xerces.impl.dv.InvalidDatatypeValueException", + "org.apache.xerces.jaxp.UnparsedEntityHandler", + "org.apache.xerces.parsers.AbstractXMLDocumentParser", + "org.apache.xerces.impl.XMLScanner", + "org.apache.xerces.impl.dtd.XMLSimpleType", + "org.apache.xerces.impl.XML11DocumentScannerImpl", + "org.apache.xerces.xni.parser.XMLParseException", + "org.apache.xerces.util.AugmentationsImpl$AugmentationsItemsContainer", + "org.apache.xerces.impl.XMLEntityScanner", + "org.apache.xerces.util.URI$MalformedURIException", + "org.apache.xerces.util.XMLChar", + "org.apache.xerces.impl.XMLNSDocumentScannerImpl", + "org.apache.xerces.impl.XML11DTDScannerImpl", + "org.apache.xerces.util.URI", + "org.apache.xerces.xni.parser.XMLDocumentFilter", + "org.apache.xerces.xni.parser.XMLDTDSource", + "org.apache.xerces.impl.dtd.XMLElementDecl", + "org.apache.xerces.impl.dtd.XMLAttributeDecl", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "org.apache.xerces.xni.grammars.Grammar", + "org.apache.xerces.parsers.XMLParser", + "org.apache.xerces.impl.dtd.models.ContentModelValidator", + "com.att.eelf.configuration.EELFLogger", + "org.apache.xerces.xni.grammars.XMLGrammarLoader", + "org.apache.xerces.xni.XMLDocumentHandler", + "org.openecomp.mso.properties.MsoJavaProperties", + "org.apache.xerces.util.SymbolTable", + "org.apache.xerces.impl.io.UCSReader", + "org.apache.xerces.impl.XMLEntityManager$CharacterBuffer", + "org.apache.xerces.impl.io.Latin1Reader", + "org.apache.xerces.impl.dv.ValidationContext", + "org.apache.xerces.impl.dtd.XMLDTDValidator", + "org.apache.xerces.impl.dtd.XML11NSDTDValidator", + "org.apache.xerces.impl.validation.ValidationState", + "org.apache.xerces.impl.XMLEntityManager$Entity", + "org.apache.xerces.util.XMLResourceIdentifierImpl", + "org.apache.xerces.util.AugmentationsImpl", + "org.apache.xerces.impl.dv.ObjectFactory", + "org.apache.xerces.impl.dv.DatatypeValidator", + "org.apache.xerces.xni.NamespaceContext", + "org.apache.xerces.impl.dtd.XMLDTDLoader", + "org.apache.xerces.jaxp.SAXParserImpl", + "org.apache.xerces.util.XMLSymbols", + "org.apache.xerces.parsers.ObjectFactory$ConfigurationError", + "org.apache.xerces.xni.grammars.XMLGrammarDescription", + "org.apache.xerces.xni.parser.XMLErrorHandler", + "org.apache.xerces.impl.io.ASCIIReader", + "org.apache.xerces.util.MessageFormatter", + "org.openecomp.mso.properties.MsoPropertiesParameters", + "org.apache.xerces.impl.dtd.XMLDTDProcessor", + "org.apache.xerces.impl.XMLDocumentFragmentScannerImpl", + "org.apache.xerces.xni.parser.XMLDTDScanner", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "org.apache.xerces.xni.XMLAttributes", + "org.apache.xerces.impl.io.MalformedByteSequenceException", + "org.apache.xerces.impl.Constants$ArrayEnumeration", + "org.apache.xerces.impl.XML11EntityScanner", + "org.apache.xerces.impl.dtd.DTDGrammar", + "org.apache.xerces.impl.dv.DTDDVFactory", + "com.att.eelf.configuration.SLF4jWrapper", + "org.openecomp.mso.properties.MsoPropertiesException", + "org.apache.xerces.impl.validation.ValidationManager", + "org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl", + "org.apache.xerces.xni.XNIException", + "org.apache.xerces.impl.dtd.XMLContentSpec", + "org.openecomp.mso.logger.MsoLogger", + "org.apache.xerces.xs.AttributePSVI", + "org.apache.xerces.impl.dtd.DTDGrammarBucket", + "org.apache.xerces.impl.msg.XMLMessageFormatter", + "org.apache.xerces.xni.parser.XMLDocumentScanner", + "org.apache.xerces.impl.XMLVersionDetector", + "org.apache.xerces.impl.XMLDocumentScannerImpl", + "org.apache.xerces.xni.parser.XMLPullParserConfiguration", + "org.apache.xerces.xni.parser.XMLDocumentSource", + "org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$Dispatcher", + "org.openecomp.mso.properties.MsoPropertiesFactory", + "org.apache.xerces.xni.XMLDTDContentModelHandler", + "org.apache.xerces.impl.xs.XMLSchemaValidator", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.apache.xerces.xni.grammars.XMLDTDDescription", + "org.apache.xerces.util.AugmentationsImpl$SmallContainer", + "org.apache.xerces.impl.XMLErrorReporter", + "org.apache.xerces.xni.QName", + "org.apache.xerces.jaxp.TeeXMLDocumentFilterImpl", + "org.apache.xerces.util.XMLAttributesImpl", + "org.apache.xerces.impl.Constants", + "org.apache.xerces.util.XMLStringBuffer", + "org.apache.xerces.impl.XMLEntityManager$InternalEntity", + "org.apache.xerces.jaxp.JAXPConstants", + "org.openecomp.mso.properties.MsoPropertiesParameters$MsoPropertiesType", + "org.apache.xerces.impl.RevalidationHandler", + "org.apache.xerces.xni.parser.XMLParserConfiguration", + "org.apache.xerces.xni.XMLString", + "org.apache.xerces.impl.dv.DVFactoryException", + "org.apache.xerces.impl.dv.DatatypeException", + "org.apache.xerces.parsers.XML11Configurable", + "org.apache.xerces.util.AugmentationsImpl$LargeContainer", + "org.apache.xerces.impl.dtd.BalancedDTDGrammar", + "org.apache.xerces.parsers.XIncludeAwareParserConfiguration", + "org.apache.xerces.xni.XMLDTDHandler", + "org.apache.xerces.impl.dtd.XML11DTDProcessor", + "org.apache.xerces.parsers.XML11Configuration", + "org.apache.xerces.impl.dtd.XMLDTDValidatorFilter", + "org.apache.xerces.impl.xs.identity.FieldActivator", + "org.apache.xerces.impl.XMLEntityScanner$1", + "com.att.eelf.i18n.EELFResourceManager", + "org.apache.xerces.jaxp.SAXParserFactoryImpl", + "org.apache.xerces.xs.ElementPSVI", + "org.apache.xerces.parsers.AbstractSAXParser", + "org.apache.xerces.xni.parser.XMLDTDFilter", + "org.apache.xerces.xni.parser.XMLDTDContentModelSource", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.logger.MsoLogger$ResponseCode", + "org.openecomp.mso.properties.MsoJsonProperties", + "org.openecomp.mso.entity.MsoRequest", + "org.openecomp.mso.properties.MsoPropertyInitializer", + "org.openecomp.mso.logger.MsoLogger$StatusCode", + "org.apache.xerces.xni.XMLLocator", + "com.att.eelf.configuration.EELFManager", + "org.apache.xerces.impl.validation.EntityState", + "org.apache.xerces.impl.XMLEntityManager$ExternalEntity", + "org.apache.xerces.util.ParserConfigurationSettings", + "org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser", + "org.apache.xerces.xni.Augmentations", + "org.apache.xerces.impl.XMLEntityHandler", + "org.apache.xerces.impl.dv.ObjectFactory$ConfigurationError", + "org.apache.xerces.xni.parser.XMLComponent", + "com.att.eelf.i18n.EELFResourceManager$1", + "org.apache.xerces.impl.dtd.XML11DTDValidator", + "org.apache.xerces.impl.XMLEntityManager$ScannedEntity", + "org.apache.xerces.jaxp.JAXPValidatorComponent" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoPropertyInitializerESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "com.att.eelf.i18n.EELFResourceManager", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "org.openecomp.mso.logger.MsoLogger", + "com.att.eelf.i18n.EELFMsgs", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "org.apache.xerces.jaxp.SAXParserFactoryImpl", + "org.apache.xerces.jaxp.SAXParserImpl", + "org.apache.xerces.parsers.XMLParser", + "org.apache.xerces.parsers.AbstractSAXParser", + "org.apache.xerces.parsers.SAXParser", + "org.apache.xerces.parsers.ObjectFactory", + "org.apache.xerces.util.ParserConfigurationSettings", + "org.apache.xerces.parsers.XML11Configuration", + "org.apache.xerces.parsers.XIncludeAwareParserConfiguration", + "org.apache.xerces.util.SymbolTable", + "org.apache.xerces.impl.XMLEntityManager", + "org.apache.xerces.util.AugmentationsImpl$SmallContainer", + "org.apache.xerces.impl.XMLEntityManager$ByteBufferPool", + "org.apache.xerces.impl.XMLEntityManager$CharacterBufferPool", + "org.apache.xerces.impl.XMLEntityScanner$1", + "org.apache.xerces.impl.XMLEntityScanner", + "org.apache.xerces.impl.XMLErrorReporter", + "org.apache.xerces.impl.XMLScanner", + "org.apache.xerces.impl.XMLDocumentFragmentScannerImpl", + "org.apache.xerces.impl.XMLDocumentScannerImpl", + "org.apache.xerces.util.XMLStringBuffer", + "org.apache.xerces.util.XMLAttributesImpl", + "org.apache.xerces.impl.XMLDTDScannerImpl", + "org.apache.xerces.impl.dtd.XMLDTDProcessor", + "org.apache.xerces.impl.dtd.XMLDTDValidator", + "org.apache.xerces.impl.validation.ValidationState", + "org.apache.xerces.impl.dtd.XMLElementDecl", + "org.apache.xerces.impl.dtd.XMLSimpleType", + "org.apache.xerces.impl.dv.DTDDVFactory", + "org.apache.xerces.impl.dv.ObjectFactory", + "org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl", + "org.apache.xerces.impl.XMLVersionDetector", + "org.apache.xerces.impl.msg.XMLMessageFormatter", + "org.apache.xerces.impl.io.UTF8Reader", + "org.apache.xerces.util.XMLSymbols", + "org.apache.xerces.xni.NamespaceContext", + "org.apache.xerces.util.XMLChar", + "org.apache.xerces.impl.Constants", + "com.att.eelf.configuration.EELFLogger$Level", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.properties.MsoPropertiesFactory" + ); + } +} diff --git a/common/src/test/java/org/openecomp/mso/utils/CheckResultsESTest.java b/common/src/test/java/org/openecomp/mso/utils/CheckResultsESTest.java new file mode 100644 index 0000000000..212fe95407 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/utils/CheckResultsESTest.java @@ -0,0 +1,124 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:02:57 GMT 2016 + */ + +package org.openecomp.mso.utils; + +import org.junit.Test; +import static org.junit.Assert.*; + +import java.util.List; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.PrivateAccess; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class CheckResultsESTest extends CheckResultsESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + CheckResults checkResults0 = new CheckResults(); + checkResults0.addHostCheckResult("GP<QUZyf\"vf-sD", (-1), ""); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + CheckResults checkResults0 = new CheckResults(); + PrivateAccess.setVariable((Class<CheckResults>) CheckResults.class, checkResults0, "results", (Object) null); + List<CheckResults.CheckResult> list0 = checkResults0.getResults(); + assertNull(list0); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + CheckResults.CheckResult checkResults_CheckResult0 = new CheckResults.CheckResult(); + checkResults_CheckResult0.setOutput("xp"); + assertEquals(0, checkResults_CheckResult0.getState()); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + CheckResults.CheckResult checkResults_CheckResult0 = new CheckResults.CheckResult(); + checkResults_CheckResult0.setType("2"); + assertEquals(0, checkResults_CheckResult0.getState()); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + CheckResults.CheckResult checkResults_CheckResult0 = new CheckResults.CheckResult(); + checkResults_CheckResult0.setState(1); + assertEquals(1, checkResults_CheckResult0.getState()); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + CheckResults.CheckResult checkResults_CheckResult0 = new CheckResults.CheckResult(); + checkResults_CheckResult0.setServicename("9~"); + assertEquals(0, checkResults_CheckResult0.getState()); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + CheckResults.CheckResult checkResults_CheckResult0 = new CheckResults.CheckResult(); + checkResults_CheckResult0.setHostname((String) null); + assertNull(checkResults_CheckResult0.getServicename()); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + CheckResults checkResults0 = new CheckResults(); + checkResults0.addHostCheckResult("GP<QUZyf\"vf-sD", 0, "GP<QUZyf\"vf-sD"); + List<CheckResults.CheckResult> list0 = checkResults0.getResults(); + assertEquals(1, list0.size()); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + CheckResults checkResults0 = new CheckResults(); + List<CheckResults.CheckResult> list0 = checkResults0.getResults(); + assertTrue(list0.isEmpty()); + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + CheckResults.CheckResult checkResults_CheckResult0 = new CheckResults.CheckResult(); + String string0 = checkResults_CheckResult0.getServicename(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + CheckResults.CheckResult checkResults_CheckResult0 = new CheckResults.CheckResult(); + int int0 = checkResults_CheckResult0.getState(); + assertEquals(0, int0); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + CheckResults.CheckResult checkResults_CheckResult0 = new CheckResults.CheckResult(); + String string0 = checkResults_CheckResult0.getHostname(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + CheckResults.CheckResult checkResults_CheckResult0 = new CheckResults.CheckResult(); + String string0 = checkResults_CheckResult0.getType(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + CheckResults checkResults0 = new CheckResults(); + checkResults0.addServiceCheckResult("", "Ifp73+/", 0, " "); + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + CheckResults.CheckResult checkResults_CheckResult0 = new CheckResults.CheckResult(); + String string0 = checkResults_CheckResult0.getOutput(); + assertNull(string0); + } +} diff --git a/common/src/test/java/org/openecomp/mso/utils/CheckResultsESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/utils/CheckResultsESTestscaffolding.java new file mode 100644 index 0000000000..a4fea268c1 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/utils/CheckResultsESTestscaffolding.java @@ -0,0 +1,79 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:02:57 GMT 2016 + */ + +package org.openecomp.mso.utils; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class CheckResultsESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.utils.CheckResults"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(CheckResultsESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.utils.CheckResults$CheckResult", + "org.openecomp.mso.utils.CheckResults" + ); + } + + private static void resetClasses() { + } +} diff --git a/common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java b/common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java new file mode 100644 index 0000000000..e178e4cf9c --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/utils/CheckResultsTest.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.utils; + +import java.util.List; + +import org.junit.Test; + +import org.openecomp.mso.utils.CheckResults.CheckResult; + +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); + } + +} diff --git a/common/src/test/java/org/openecomp/mso/utils/CryptoUtilsESTest.java b/common/src/test/java/org/openecomp/mso/utils/CryptoUtilsESTest.java new file mode 100644 index 0000000000..397db374bb --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/utils/CryptoUtilsESTest.java @@ -0,0 +1,175 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 09:07:10 GMT 2016 + */ + +package org.openecomp.mso.utils; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.runtime.EvoAssertions.*; + +import javax.crypto.BadPaddingException; +import javax.crypto.IllegalBlockSizeException; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class CryptoUtilsESTest extends CryptoUtilsESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + CryptoUtils.decrypt("E08682BE5F2B18A6E8437A15B110D418E08682BE5F2B18A6E8437A15B110D4180143DB63EE66B0CDFF9F69917680151E", "00000000000000000000000000000000"); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + byte[] byteArray0 = new byte[0]; + CryptoUtils.byteArrayToHexString(byteArray0); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + // Undeclared exception! + try { + CryptoUtils.encrypt("AES", "w^p&|^Cvs@K.@@"); + fail("Expecting exception: NumberFormatException"); + + } catch(NumberFormatException e) { + // + // For input string: \"w^\" + // + verifyException("java.lang.NumberFormatException", e); + } + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + // Undeclared exception! + try { + CryptoUtils.encrypt((String) null, "B2000000000000000000000000000000"); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.utils.CryptoUtils", e); + } + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + try { + CryptoUtils.decrypt("B20000000000000000000000000000000000000000000000", "B20000000000000000000000000000000000000000000000"); + fail("Expecting exception: IllegalBlockSizeException"); + + } catch(IllegalBlockSizeException e) { + } + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + try { + CryptoUtils.decrypt("0000C200000000000000000000000000", "0000C200000000000000000000000000"); + fail("Expecting exception: BadPaddingException"); + + } catch(BadPaddingException e) { + } + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + // Undeclared exception! + try { + CryptoUtils.decrypt("s.", "s."); + fail("Expecting exception: NumberFormatException"); + + } catch(NumberFormatException e) { + // + // For input string: \"s.\" + // + verifyException("java.lang.NumberFormatException", e); + } + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + // Undeclared exception! + try { + CryptoUtils.decrypt("", ""); + fail("Expecting exception: IllegalArgumentException"); + + } catch(IllegalArgumentException e) { + // + // Empty key + // + verifyException("javax.crypto.spec.SecretKeySpec", e); + } + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + // Undeclared exception! + try { + CryptoUtils.byteArrayToHexString((byte[]) null); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.utils.CryptoUtils", e); + } + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + byte[] byteArray0 = new byte[16]; + byteArray0[0] = (byte) (-78); + String string0 = CryptoUtils.byteArrayToHexString(byteArray0); + assertEquals("B2000000000000000000000000000000", string0); + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + String string0 = CryptoUtils.encrypt("00000000000000000000000000000000", "00000000000000000000000000000000"); + assertEquals("E08682BE5F2B18A6E8437A15B110D418E08682BE5F2B18A6E8437A15B110D4180143DB63EE66B0CDFF9F69917680151E", string0); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + // Undeclared exception! + try { + CryptoUtils.encrypt("", ""); + fail("Expecting exception: IllegalArgumentException"); + + } catch(IllegalArgumentException e) { + // + // Empty key + // + verifyException("javax.crypto.spec.SecretKeySpec", e); + } + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + CryptoUtils cryptoUtils0 = new CryptoUtils(); + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + // Undeclared exception! + try { + CryptoUtils.decrypt((String) null, "00000000000000000000000000000000"); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.utils.CryptoUtils", e); + } + } +} diff --git a/common/src/test/java/org/openecomp/mso/utils/CryptoUtilsESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/utils/CryptoUtilsESTestscaffolding.java new file mode 100644 index 0000000000..09574153c7 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/utils/CryptoUtilsESTestscaffolding.java @@ -0,0 +1,83 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 09:07:10 GMT 2016 + */ + +package org.openecomp.mso.utils; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class CryptoUtilsESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.utils.CryptoUtils"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(CryptoUtilsESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.utils.CryptoUtils" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(CryptoUtilsESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.utils.CryptoUtils" + ); + } +} diff --git a/common/src/test/java/org/openecomp/mso/utils/UUIDCheckerESTest.java b/common/src/test/java/org/openecomp/mso/utils/UUIDCheckerESTest.java new file mode 100644 index 0000000000..fa8517e3db --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/utils/UUIDCheckerESTest.java @@ -0,0 +1,34 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:02:03 GMT 2016 + */ + +package org.openecomp.mso.utils; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.shaded.org.mockito.Mockito.*; + +import org.openecomp.mso.logger.MsoLogger; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.PrivateAccess; +import org.evosuite.runtime.ViolatedAssumptionAnswer; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class UUIDCheckerESTest extends UUIDCheckerESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoLogger msoLogger0 = mock(MsoLogger.class, new ViolatedAssumptionAnswer()); + String string0 = UUIDChecker.generateServiceInstanceID(msoLogger0); + assertEquals("00000000-0100-4000-8200-000003000000", string0); + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + UUIDChecker uUIDChecker0 = (UUIDChecker)PrivateAccess.callDefaultConstructorOfTheClassUnderTest(); + assertNotNull(uUIDChecker0); + } +} diff --git a/common/src/test/java/org/openecomp/mso/utils/UUIDCheckerESTestscaffolding.java b/common/src/test/java/org/openecomp/mso/utils/UUIDCheckerESTestscaffolding.java new file mode 100644 index 0000000000..15397cb165 --- /dev/null +++ b/common/src/test/java/org/openecomp/mso/utils/UUIDCheckerESTestscaffolding.java @@ -0,0 +1,94 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:02:03 GMT 2016 + */ + +package org.openecomp.mso.utils; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class UUIDCheckerESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.utils.UUIDChecker"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(UUIDCheckerESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.logger.MsoLogger", + "org.openecomp.mso.logger.MessageEnum", + "com.att.eelf.i18n.EELFResolvableErrorEnum", + "org.openecomp.mso.logger.MsoLogger$ResponseCode", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.openecomp.mso.entity.MsoRequest", + "org.openecomp.mso.logger.MsoLogger$StatusCode", + "com.att.eelf.i18n.EELFResourceManager", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "org.openecomp.mso.utils.UUIDChecker" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(UUIDCheckerESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "com.att.eelf.i18n.EELFResourceManager", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.logger.MsoLogger" + ); + } +} |