diff options
Diffstat (limited to 'status-control')
9 files changed, 1123 insertions, 0 deletions
diff --git a/status-control/pom.xml b/status-control/pom.xml new file mode 100644 index 0000000000..169c2ba131 --- /dev/null +++ b/status-control/pom.xml @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.openecomp</groupId> + <artifactId>mso</artifactId> + <version>0.0.4-SNAPSHOT</version> + </parent> + + <groupId>org.openecomp.mso</groupId> + <artifactId>status-control</artifactId> + <name>MSO Status Control module</name> + <description>Contains classes to update and query the MSO status per site</description> + + <dependencies> + <dependency> + <groupId>org.openecomp.mso</groupId> + <artifactId>common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.mso</groupId> + <artifactId>mso-catalog-db</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.mso</groupId> + <artifactId>mso-requests-db</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <version>3.1.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>resteasy-jaxrs</artifactId> + <version>3.0.19.Final</version> + <scope>provided</scope> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <version>1.10.19</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpcore</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + </dependency> + + </dependencies> +</project>
\ No newline at end of file diff --git a/status-control/src/main/java/org/openecomp/mso/HealthCheckUtils.java b/status-control/src/main/java/org/openecomp/mso/HealthCheckUtils.java new file mode 100644 index 0000000000..03e807ae5a --- /dev/null +++ b/status-control/src/main/java/org/openecomp/mso/HealthCheckUtils.java @@ -0,0 +1,288 @@ +/*- + * ============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; + + +import org.openecomp.mso.db.catalog.CatalogDatabase; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.properties.MsoJsonProperties; +import org.openecomp.mso.properties.MsoPropertiesFactory; +import org.openecomp.mso.requestsdb.RequestsDatabase; +import org.openecomp.mso.utils.UUIDChecker; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; + +import javax.ws.rs.core.Response; + +public class HealthCheckUtils { + + private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); + private final static String MSO_PROP_TOPOLOGY = "MSO_PROP_TOPOLOGY"; + private static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); + private static final String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application ready</body></html>"; + private static final String NOT_FOUND = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Application Not Started</title></head><body>Application not started. Properties file missing or invalid or database Connection failed</body></html>"; + private static final String NOT_HEALTHY = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Application Not Started</title></head><body>Application not available or at least one of the sub-modules is not available.</body></html>"; + public static final Response HEALTH_CHECK_RESPONSE = Response.status (HttpStatus.SC_OK) + .entity (CHECK_HTML) + .build (); + public static final Response HEALTH_CHECK_NOK_RESPONSE = Response.status (HttpStatus.SC_SERVICE_UNAVAILABLE) + .entity (NOT_HEALTHY) + . build (); + public static final Response NOT_STARTED_RESPONSE = Response.status (HttpStatus.SC_SERVICE_UNAVAILABLE) + .entity (NOT_FOUND) + .build (); + + public enum NodeType {APIH, RA}; + + public boolean catalogDBCheck (MsoLogger subMsoLogger, long startTime) { + try (CatalogDatabase catalogDB = new CatalogDatabase ()) { + catalogDB.healthCheck (); + } catch (Exception e) { + subMsoLogger.error(MessageEnum.GENERAL_EXCEPTION, "", "HealthCheck", MsoLogger.ErrorCode.DataError, "Failed to check catalog database", e); + subMsoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception during healthcheck"); + return false; + } + return true; + } + + public boolean requestDBCheck (MsoLogger subMsoLogger, long startTime) { + try { + RequestsDatabase.healthCheck (); + } catch (Exception e) { + subMsoLogger.error(MessageEnum.GENERAL_EXCEPTION, "", "HealthCheck", MsoLogger.ErrorCode.DataError, "Failed to check request database", e); + subMsoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.ServiceNotAvailable, "Exception during local healthcheck"); + return false; + } + return true; + } + + public boolean siteStatusCheck (MsoLogger subMsoLogger, long startTime) { + // Check the Site Status value in DB first, if set to false, return NOK + String site = getProperty("site-name"); + + MsoStatusUtil statusUtil = new MsoStatusUtil (); + if (!statusUtil.getSiteStatus (site)) { + subMsoLogger.debug("This site is currently disabled for maintenance."); + return false; + } + return true; + } + + public boolean configFileCheck (MsoLogger subMsoLogger, long startTime, String propertiesFile) { + if (null != propertiesFile) { + MsoJavaProperties props = loadMsoProperties (propertiesFile); + if (props == null) { + subMsoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.ServiceNotAvailable, "Configuration file can not be loaded"); + return false; + } + } + return true; + } + + + private MsoJavaProperties loadMsoProperties (String fileName) { + MsoJavaProperties msoProperties; + try { + msoProperties = msoPropertiesFactory.getMsoJavaProperties(fileName); + } catch (Exception e) { + msoLogger.error (MessageEnum.LOAD_PROPERTIES_FAIL, fileName, "", "HealthCheck", MsoLogger.ErrorCode.DataError, "Failed to load topology properties", e); + return null; + } + if (msoProperties !=null && msoProperties.size() > 0) { + return msoProperties; + } else { + msoLogger.error (MessageEnum.NO_PROPERTIES, fileName, "", "HealthCheck", MsoLogger.ErrorCode.DataError, "No topology properties"); + return null; + } + } + + protected boolean verifyLocalHealth(String ip, String apiPort, String url, String sslEnabled, String requestId) { + String finalUrl = getFinalUrl(ip, apiPort, url, sslEnabled); + long startTime = System.currentTimeMillis (); + if (null != requestId) { + finalUrl = finalUrl + "?requestId=" + requestId; + } + try (CloseableHttpClient client = getHttpClient()) { + HttpResponse response; + HttpGet get = new HttpGet(finalUrl); + msoLogger.debug("Get url is: " + finalUrl); + response = client.execute(get); + msoLogger.debug("Get response is: " + response); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + msoLogger.debug("verifyLocalHealth - Successfully communicate with APIH/BPMN/RA"); + return true; + } + msoLogger.debug("verifyLocalHealth - Service not available"); + } catch (Exception e) { + msoLogger.error(MessageEnum.GENERAL_EXCEPTION, "", "HealthCheck", MsoLogger.ErrorCode.UnknownError, "Error in local HealthCheck", e); + msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with APIH/BPMN/RA", url, "HealthCheck", null); + msoLogger.debug("Exception while triggering local health check api:" + finalUrl); + } + return false; + } + + protected CloseableHttpClient getHttpClient () { + // set the connection timeout value to 30 seconds (30000 milliseconds) + RequestConfig.Builder requestBuilder = RequestConfig.custom(); + requestBuilder = requestBuilder.setConnectTimeout(30000); + requestBuilder = requestBuilder.setConnectionRequestTimeout(30000); + HttpClientBuilder builder = HttpClientBuilder.create (); + builder.setDefaultRequestConfig (requestBuilder.build ()); + + return builder.build (); + } + + public MsoJavaProperties loadTopologyProperties() { + MsoJavaProperties msoProperties; + try { + msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_TOPOLOGY); + } catch (Exception e) { + msoLogger.error(MessageEnum.LOAD_PROPERTIES_FAIL, MSO_PROP_TOPOLOGY, "", "HealthCheck", MsoLogger.ErrorCode.DataError, "Not able to load topology properties", e); + return null; + } + + if (msoProperties != null && msoProperties.size() > 0) { + return msoProperties; + } else { + msoLogger.error(MessageEnum.LOAD_PROPERTIES_FAIL, MSO_PROP_TOPOLOGY, "", "HealthCheck", MsoLogger.ErrorCode.DataError, "Not able to load topology properties"); + return null; + } + } + + public boolean verifyNodeHealthCheck (HealthCheckUtils.NodeType type, String requestId) { + // Get info from topology properties file + MsoJavaProperties topologyProp = this.loadTopologyProperties(); + if (null == topologyProp) { + return false; + } + String port = topologyProp.getProperty("server-port", null); + String ip = System.getProperty("jboss.qualified.host.name"); + String sslEnabled = topologyProp.getProperty("ssl-enable", null); + + if (null == port || null == ip || ip.isEmpty() || port.isEmpty()) { + msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Not able to get the IP or the Port value. IP:" + ip + "; Port:" + port, "", "HealthCheck", MsoLogger.ErrorCode.DataError, "Not able to get the IP or the Port value. IP:" + ip + "; Port:" + port); + return false; + } + + String[] apis; + if (NodeType.APIH.equals (type)) { + String apiList = topologyProp.getProperty("apih-healthcheck-urn", null); + if (null == apiList) { + msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Not able to get apih-healthcheck-urn parameter", "", "HealthCheck", MsoLogger.ErrorCode.DataError, "Not able to get apih-healthcheck-urn parameter"); + return false; + } + apis = apiList.split(","); + } else if (NodeType.RA.equals (type)){ + String apiList = topologyProp.getProperty("jra-healthcheck-urn", null); + if (null == apiList) { + msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Not able to get jra-healthcheck-urn parameter", "", "HealthCheck", MsoLogger.ErrorCode.DataError, "Not able to get jra-healthcheck-urn parameter"); + return false; + } + apis = apiList.split(","); + } else { + msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Unknown NodeType:" + type, "", "HealthCheck", MsoLogger.ErrorCode.DataError, "Unknown NodeType:" + type); + return false; + } + + // Verify health check on APIH servers + for (String url : apis) { + // if any of the parameters is null or empty, no need to establish the health check request, just go to the next iteration + if ((url == null) || url.isEmpty()) { + continue; + } + // Exit the loop if local health check returns false from any of the sub component + if (!this.verifyLocalHealth(ip, port, url, sslEnabled, requestId)) { + return false; + } + } + return true; + } + + public boolean verifyGlobalHealthCheck(boolean verifyBpmn, String requestId) { + // Get info from topology properties file + MsoJavaProperties topologyProp = this.loadTopologyProperties(); + if (null == topologyProp) { + msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Not able to find the topology file", "", "HealthCheck", MsoLogger.ErrorCode.PermissionError, "Not able to find the topology file"); + return false; + } + + String apihLB = topologyProp.getProperty("apih-load-balancer", null); + String apihApi = topologyProp.getProperty("apih-nodehealthcheck-urn", null); + String bpmnLB= topologyProp.getProperty("camunda-load-balancer", null); + String bpmnApi = topologyProp.getProperty("camunda-healthcheck-urn", null); + String jraLB = topologyProp.getProperty("jra-load-balancer", null); + String jraApi = topologyProp.getProperty("jra-nodehealthcheck-urn", null); + + if (null == apihLB || null == apihApi || null == bpmnLB || null == bpmnApi || null == jraLB || null == jraApi + || apihLB.isEmpty () || apihApi.isEmpty () || bpmnLB.isEmpty () || bpmnApi.isEmpty () || jraLB.isEmpty () || jraApi.isEmpty () ) { + msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Key parameters are missing from the topology file", "", "HealthCheck", MsoLogger.ErrorCode.DataError, "Key parameters are missing from the topology file"); + return false; + } + + // Verify health check on APIH servers + if (!this.verifyLocalHealth (apihLB, null, apihApi, null, requestId)) { + return false; + } + + // Verify health check on Camunda servers + if (verifyBpmn) { + if (!this.verifyLocalHealth (bpmnLB, null, bpmnApi, null, requestId)) { + return false; + } + } + + // Verify health check on RA servers + if (!verifyLocalHealth (jraLB, null, jraApi, null, requestId)) { + return false; + } + + return true; + } + + public String getProperty (String name) { + MsoJavaProperties prop = this.loadTopologyProperties(); + + return prop.getProperty(name, null); + } + + protected String getFinalUrl (String ip, String port, String url, String sslEnabled) { + if (null == port && null == sslEnabled) { + int length = ip.length(); + if (ip.substring(length - 1).equals ("/")) { + ip = ip.substring (0, length - 1); + } + return ip + url; + } else if (null != sslEnabled && "true".equals (sslEnabled.toLowerCase ())) { + return "https://" + ip + ":" + port + url; + } else { + return "http://" + ip + ":" + port + url; + } + } +} diff --git a/status-control/src/main/java/org/openecomp/mso/MsoStatusHandler.java b/status-control/src/main/java/org/openecomp/mso/MsoStatusHandler.java new file mode 100644 index 0000000000..f125cbbc50 --- /dev/null +++ b/status-control/src/main/java/org/openecomp/mso/MsoStatusHandler.java @@ -0,0 +1,64 @@ +/*- + * ============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; + + +import org.openecomp.mso.utils.UUIDChecker; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.requestsdb.RequestsDatabase; + +import javax.ws.rs.*; +import javax.ws.rs.core.Response; + +@Path("/") +public class MsoStatusHandler { + private MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL); + + @POST + @Path("/setStatus/{siteName}") + @Produces("text/plain") + public Response setSiteStatus (@DefaultValue("true") @QueryParam("enable") Boolean enable, + @PathParam("siteName") String siteName) { + long startTime = System.currentTimeMillis(); + // Set logger parameters + UUIDChecker.generateUUID (logger); + MsoLogger.setServiceName ("SetSiteStatus"); + + + if (null == siteName) { + logger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.BadRequest, "Not able to find the site name attribute in the config file"); + return Response.status (Response.Status.INTERNAL_SERVER_ERROR).entity ("Exception: not able to find the site name attribute in the config file").build (); + } + + // Query DB for the value + try { + RequestsDatabase.updateSiteStatus(siteName, enable); + + } catch (Exception e) { + logger.error (MessageEnum.GENERAL_EXCEPTION, "", "setSiteStatus", MsoLogger.ErrorCode.DataError, "Failed to set site status", e); + logger.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while updating site status"); + return Response.status (Response.Status.INTERNAL_SERVER_ERROR).entity ("Exception while updating site status").build (); + } + logger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful"); + return Response.status (Response.Status.OK).entity ("Site status successfully updated to " + enable).build (); + } +} diff --git a/status-control/src/main/java/org/openecomp/mso/MsoStatusUtil.java b/status-control/src/main/java/org/openecomp/mso/MsoStatusUtil.java new file mode 100644 index 0000000000..2a86a4a260 --- /dev/null +++ b/status-control/src/main/java/org/openecomp/mso/MsoStatusUtil.java @@ -0,0 +1,50 @@ +/*- + * ============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; + + +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.requestsdb.SiteStatus; +import org.openecomp.mso.requestsdb.RequestsDatabase; + +public class MsoStatusUtil { + + private MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL); + + public boolean getSiteStatus (String siteName) { + // Query DB for the value + + try { + SiteStatus siteStatus = RequestsDatabase.getSiteStatus(siteName); + if (null != siteStatus) { + return siteStatus.getStatus(); + } else { + // If status not present in the DB, by default the site is on, thus return true + return true; + } + } catch (Exception e) { + logger.error (MessageEnum.GENERAL_EXCEPTION, "", "getSiteStatus", MsoLogger.ErrorCode.DataError, "Exception in getting the site status", e); + } + + return false; + } +} diff --git a/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsESTest.java b/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsESTest.java new file mode 100644 index 0000000000..3fa901c51a --- /dev/null +++ b/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsESTest.java @@ -0,0 +1,44 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:26:24 GMT 2016 + */ + +package org.openecomp.mso; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.properties.MsoJavaProperties; +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 HealthCheckUtilsESTest extends HealthCheckUtilsESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + HealthCheckUtils healthCheckUtils0 = new HealthCheckUtils(); + MsoJavaProperties msoJavaProperties0 = healthCheckUtils0.loadTopologyProperties(); + assertNull(msoJavaProperties0); + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + HealthCheckUtils healthCheckUtils0 = new HealthCheckUtils(); + MsoLogger.Catalog msoLogger_Catalog0 = MsoLogger.Catalog.BPEL; + MsoLogger msoLogger0 = MsoLogger.getMsoLogger(msoLogger_Catalog0); + boolean boolean0 = healthCheckUtils0.configFileCheck(msoLogger0, 0L, "58zhaz/qbA"); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test2() throws Throwable { + HealthCheckUtils healthCheckUtils0 = new HealthCheckUtils(); + MsoLogger.Catalog msoLogger_Catalog0 = MsoLogger.Catalog.BPEL; + MsoLogger msoLogger0 = MsoLogger.getMsoLogger(msoLogger_Catalog0); + boolean boolean0 = healthCheckUtils0.requestDBCheck(msoLogger0, 0L); + assertFalse(boolean0); + } +} diff --git a/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsESTestscaffolding.java b/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsESTestscaffolding.java new file mode 100644 index 0000000000..fdb925abcf --- /dev/null +++ b/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsESTestscaffolding.java @@ -0,0 +1,155 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:26:24 GMT 2016 + */ + +package org.openecomp.mso; + +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 HealthCheckUtilsESTestscaffolding { + + @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.HealthCheckUtils"; + 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(HealthCheckUtilsESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.properties.AbstractMsoProperties", + "org.openecomp.mso.properties.MsoPropertiesParameters", + "org.apache.http.client.config.RequestConfig", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "org.jboss.resteasy.specimpl.MultivaluedTreeMap", + "org.hibernate.criterion.Order", + "com.att.eelf.configuration.SLF4jWrapper", + "org.apache.http.HttpMessage", + "org.hibernate.Query", + "org.openecomp.mso.properties.MsoPropertiesException", + "org.openecomp.mso.requestsdb.InfraActiveRequests", + "org.openecomp.mso.logger.MsoLogger", + "com.att.eelf.i18n.EELFResolvableErrorEnum", + "org.openecomp.mso.HealthCheckUtils", + "org.hibernate.SessionFactory", + "org.apache.http.HttpRequest", + "com.att.eelf.i18n.EELFMsgs", + "org.openecomp.mso.properties.MsoPropertiesFactory", + "org.openecomp.mso.requestsdb.RequestsDatabase", + "com.att.eelf.configuration.EELFLogger$Level", + "org.openecomp.mso.requestsdb.MockRequestsDatabase", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.apache.http.client.config.RequestConfig$Builder", + "org.openecomp.mso.requestsdb.InfraRequests", + "org.openecomp.mso.requestsdb.SiteStatus", + "org.openecomp.mso.properties.MsoPropertiesParameters$MsoPropertiesType", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "org.apache.http.client.methods.HttpUriRequest", + "org.openecomp.mso.HealthCheckUtils$NodeType", + "com.att.eelf.configuration.EELFLogger", + "org.hibernate.engine.spi.Mapping", + "org.openecomp.mso.properties.MsoJavaProperties", + "org.apache.http.client.HttpClient", + "com.att.eelf.i18n.EELFResourceManager", + "org.jboss.resteasy.util.CaseInsensitiveMap$CaseInsensitiveComparator", + "org.hibernate.criterion.Criterion", + "org.openecomp.mso.logger.MessageEnum", + "org.apache.http.impl.client.CloseableHttpClient", + "org.openecomp.mso.logger.MsoLogger$ResponseCode", + "org.openecomp.mso.entity.MsoRequest", + "org.openecomp.mso.properties.MsoJsonProperties", + "org.openecomp.mso.logger.MsoLogger$StatusCode", + "com.att.eelf.configuration.EELFManager", + "org.jboss.resteasy.util.CaseInsensitiveMap$1", + "org.jboss.resteasy.core.Headers", + "org.hibernate.BasicQueryContract", + "org.jboss.resteasy.util.CaseInsensitiveMap", + "com.att.eelf.i18n.EELFResourceManager$1", + "org.apache.http.HttpResponse", + "org.openecomp.mso.requestsdb.HibernateUtil", + "org.apache.http.HttpHost" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(HealthCheckUtilsESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.HealthCheckUtils$NodeType", + "com.att.eelf.i18n.EELFResourceManager", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.openecomp.mso.logger.MsoLogger$ResponseCode", + "org.openecomp.mso.logger.MsoLogger", + "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.properties.MsoPropertiesFactory", + "org.openecomp.mso.HealthCheckUtils", + "org.openecomp.mso.logger.MsoLogger$StatusCode", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "org.openecomp.mso.requestsdb.HibernateUtil", + "org.apache.http.client.config.RequestConfig", + "org.jboss.resteasy.specimpl.MultivaluedTreeMap", + "org.jboss.resteasy.util.CaseInsensitiveMap$CaseInsensitiveComparator", + "org.jboss.resteasy.util.CaseInsensitiveMap", + "org.jboss.resteasy.core.Headers", + "org.openecomp.mso.requestsdb.RequestsDatabase", + "org.openecomp.mso.properties.MsoPropertiesParameters$MsoPropertiesType", + "org.openecomp.mso.properties.MsoPropertiesException" + ); + } +} diff --git a/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsTest.java b/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsTest.java new file mode 100644 index 0000000000..712cdb2ce6 --- /dev/null +++ b/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsTest.java @@ -0,0 +1,300 @@ +/*- + * ============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; + + +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.requestsdb.RequestsDatabase; +import org.apache.http.HttpStatus; +import org.apache.http.HttpVersion; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.message.BasicStatusLine; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; + +/** + */ +public class HealthCheckUtilsTest { + + private static HealthCheckUtils utils; + private static String port = "8080"; + private static String ip1 = "localhost"; + private static String ip2 = "192.3.2.1"; + private static String iptest = "test/"; + private static String apihUrl1 = "/api/healthcheck"; + private static String apihUrl2 = "/api/healthcheck2"; + private static String bpmnUrl1 = "/bpmn/healthcheck"; + private static String raUrl1 = "/tenants/healthcheck"; + private static String raUrl2 = "/vnf/healthcheck"; + private static String raUrl3 = "/sdnc/healthcheck"; + private static MsoJavaProperties properties; + private static String sslEnable = "false"; + private static CloseableHttpClient client; + private static CloseableHttpResponse nokRes, okRes; + + @BeforeClass + public static final void prepareMockvalues() { + utils = Mockito.mock(HealthCheckUtils.class); + client = Mockito.mock(CloseableHttpClient.class); + nokRes = Mockito.mock(CloseableHttpResponse.class); + okRes = Mockito.mock(CloseableHttpResponse.class); + Mockito.when(nokRes.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_SERVICE_UNAVAILABLE, "FINE!"));; + Mockito.when(okRes.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "FINE!")); + + properties = new MsoJavaProperties(); + properties.setProperty("server-port", port); + properties.setProperty("ssl-enable", sslEnable); + properties.setProperty("apih-load-balancer", ip1); + properties.setProperty("apih-healthcheck-urn",apihUrl1 + "," + apihUrl2); + properties.setProperty("camunda-load-balancer",ip1); + properties.setProperty("camunda-healthcheck-urn",bpmnUrl1); + properties.setProperty("jra-load-balancer",ip1); + properties.setProperty("jra-healthcheck-urn",raUrl1 + "," + raUrl2 + "," + raUrl3); + properties.setProperty("apih-nodehealthcheck-urn", apihUrl1); + properties.setProperty("camunda-nodehealthcheck-urn", bpmnUrl1); + properties.setProperty("jra-nodehealthcheck-urn", raUrl1); + + Mockito.when(utils.loadTopologyProperties()).thenReturn(properties); + Mockito.when(utils.verifyNodeHealthCheck(HealthCheckUtils.NodeType.APIH, null)).thenCallRealMethod(); + Mockito.when(utils.verifyNodeHealthCheck(HealthCheckUtils.NodeType.RA, null)).thenCallRealMethod(); + Mockito.when(utils.verifyGlobalHealthCheck(true, null)).thenCallRealMethod(); + Mockito.when(utils.verifyGlobalHealthCheck(false, null)).thenCallRealMethod(); + + Mockito.when(utils.getFinalUrl (ip1, port, raUrl1, sslEnable)).thenCallRealMethod(); + Mockito.when(utils.getFinalUrl (ip1, port, raUrl1, null)).thenCallRealMethod(); + Mockito.when(utils.getFinalUrl (ip1, port, raUrl1, "true")).thenCallRealMethod(); + Mockito.when(utils.getFinalUrl (ip1, port, raUrl1, "otherValue")).thenCallRealMethod(); + Mockito.when(utils.getFinalUrl (ip1, port, raUrl1, "True")).thenCallRealMethod(); + Mockito.when(utils.getFinalUrl (ip1, port, raUrl1, "TRUE")).thenCallRealMethod(); + Mockito.when(utils.getFinalUrl (ip1, null, raUrl1, null)).thenCallRealMethod(); + Mockito.when(utils.getFinalUrl (iptest, null, raUrl1, null)).thenCallRealMethod(); + + System.setProperty("jboss.qualified.host.name", ip1); + } + + @Test + public final void testVerifyNodeHealthCheck () { + Mockito.when (utils.verifyLocalHealth(ip1, port, apihUrl1, sslEnable, null)).thenReturn(true); + Mockito.when (utils.verifyLocalHealth(ip1, port, apihUrl2, sslEnable, null)).thenReturn(true); + Mockito.when (utils.verifyLocalHealth(ip2, port, apihUrl2, sslEnable, null)).thenReturn(true); + Mockito.when (utils.verifyLocalHealth(ip2, port, apihUrl1, sslEnable, null)).thenReturn(false); + Mockito.when (utils.verifyLocalHealth(ip1, port, raUrl1, sslEnable, null)).thenReturn(true); + Mockito.when (utils.verifyLocalHealth(ip1, port, raUrl2, sslEnable, null)).thenReturn(false); + Mockito.when (utils.verifyLocalHealth(ip1, port, raUrl3, sslEnable, null)).thenReturn(true); + + assertTrue (utils.verifyNodeHealthCheck (HealthCheckUtils.NodeType.APIH, null)); + assertFalse (utils.verifyNodeHealthCheck (HealthCheckUtils.NodeType.RA, null)); + + Mockito.when (utils.verifyLocalHealth(ip1, port, apihUrl1, sslEnable, null)).thenReturn(false); + Mockito.when (utils.verifyLocalHealth(ip1, port, raUrl2, sslEnable, null)).thenReturn(true); + assertFalse (utils.verifyNodeHealthCheck (HealthCheckUtils.NodeType.APIH, null)); + assertTrue (utils.verifyNodeHealthCheck (HealthCheckUtils.NodeType.RA, null)); + + Mockito.when (utils.verifyLocalHealth(ip2, port, apihUrl1, sslEnable, null)).thenReturn(true); + assertFalse (utils.verifyNodeHealthCheck (HealthCheckUtils.NodeType.APIH, null)); + assertTrue (utils.verifyNodeHealthCheck (HealthCheckUtils.NodeType.RA, null)); + + } + + @Test + public final void testVerifyGlobalHealthCheckBPMN () { + + // healthcheck of bpmn returns false + Mockito.when(utils.verifyLocalHealth(ip1, null, bpmnUrl1, null, null)).thenReturn(false); + Mockito.when(utils.verifyLocalHealth(ip1, null, apihUrl1, null, null)).thenReturn(true); + Mockito.when(utils.verifyLocalHealth(ip1, null, raUrl1, null, null)).thenReturn(true); + + // verify BPMN healthcheck + assertFalse(utils.verifyGlobalHealthCheck (true, null)); + + // do not verify BPMN healthcheck + assertTrue(utils.verifyGlobalHealthCheck (false, null)); + + Mockito.when(utils.verifyLocalHealth(ip1, null, bpmnUrl1, null, null)).thenReturn(true); + assertTrue(utils.verifyGlobalHealthCheck (true, null)); + } + + @Test + public final void testVerifyGlobalHealthCheckAPIH () { + + Mockito.when(utils.verifyLocalHealth(ip1, null, apihUrl1, null, null)).thenReturn(true); + Mockito.when(utils.verifyLocalHealth(ip1, null, raUrl1, null, null)).thenReturn(true); + Mockito.when(utils.verifyLocalHealth(ip1, null, bpmnUrl1, null, null)).thenReturn(true); + assertTrue(utils.verifyGlobalHealthCheck (true, null)); + + Mockito.when(utils.verifyLocalHealth(ip1, null, apihUrl1, null, null)).thenReturn(false); + assertFalse(utils.verifyGlobalHealthCheck (true, null)); + } + + @Test + public final void testVerifyGlobalHealthCheckRA () { + // all health check apis returns true + Mockito.when(utils.verifyLocalHealth(ip1, null, apihUrl1, null, null)).thenReturn(true); + Mockito.when(utils.verifyLocalHealth(ip1, null, raUrl1, null, null)).thenReturn(true); + Mockito.when(utils.verifyLocalHealth(ip1, null, bpmnUrl1, null, null)).thenReturn(true); + assertTrue(utils.verifyGlobalHealthCheck (true, null)); + + + // 3rd ra api return false; others return true + Mockito.when(utils.verifyLocalHealth(ip1, null, raUrl1, null, null)).thenReturn(false); + assertFalse(utils.verifyGlobalHealthCheck (true, null)); + } + + @Test + public final void testGetFinalUrl () { + String finalUrl1 = utils.getFinalUrl (ip1, port, raUrl1, sslEnable); + assertTrue (finalUrl1.equals ("http://" + ip1 + ":" + port + raUrl1)); + + String finalUrl2 = utils.getFinalUrl (ip1, port, raUrl1, "true"); + assertTrue (finalUrl2.equals ("https://" + ip1 + ":" + port + raUrl1)); + + String finalUrl3 = utils.getFinalUrl (ip1, port, raUrl1, null); + assertTrue (finalUrl3.equals ("http://" + ip1 + ":" + port + raUrl1)); + + String finalUrl4 = utils.getFinalUrl (ip1, port, raUrl1, "otherValue"); + assertTrue (finalUrl4.equals ("http://" + ip1 + ":" + port + raUrl1)); + + String finalUrl5 = utils.getFinalUrl (ip1, port, raUrl1, "True"); + assertTrue (finalUrl5.equals ("https://" + ip1 + ":" + port + raUrl1)); + + String finalUrl6 = utils.getFinalUrl (ip1, port, raUrl1, "TRUE"); + assertTrue (finalUrl6.equals ("https://" + ip1 + ":" + port + raUrl1)); + + String finalUrl7 = utils.getFinalUrl (ip1, null, raUrl1, null); + assertTrue (finalUrl7.equals (ip1 + raUrl1)); + + String finalUrl8 = utils.getFinalUrl (iptest, null, raUrl1, null); + assertTrue (finalUrl8.equals ("test" + raUrl1)); + } + + @Test + public final void testVerifyLocalHealth() { + HealthCheckUtils tempUtil = Mockito.mock(HealthCheckUtils.class); + + Mockito.when(tempUtil.verifyLocalHealth(ip1, port, apihUrl1, sslEnable, null)).thenCallRealMethod (); + Mockito.when(tempUtil.getFinalUrl (ip1, port, apihUrl1, sslEnable)).thenCallRealMethod (); + Mockito.when(tempUtil.getHttpClient()).thenReturn (client); + + try { + Mockito.when (client.execute (any(HttpUriRequest.class))).thenReturn (okRes); + Boolean res1 = (Boolean)invokeProtectedMethod(tempUtil, "verifyLocalHealth", ip1, port, apihUrl1, sslEnable, null); + assertTrue(res1); + + Mockito.when (client.execute (any(HttpUriRequest.class))).thenReturn (nokRes); + Boolean res2 = (Boolean)invokeProtectedMethod(tempUtil, "verifyLocalHealth", ip1, port, apihUrl1, sslEnable, null); + assertFalse(res2); + + } catch (Exception e) { + e.printStackTrace (); + } + + } + + + @Test + public final void NullityCheck () { + Mockito.when(utils.verifyLocalHealth(ip1, null, bpmnUrl1, null, null)).thenReturn(true); + Mockito.when(utils.verifyLocalHealth(ip1, null, apihUrl1, null, null)).thenReturn(true); + Mockito.when(utils.verifyLocalHealth(ip1, null, raUrl1, null, null)).thenReturn(true); + + assertTrue (utils.verifyGlobalHealthCheck (true, null)); + + // mising server-port parameter + MsoJavaProperties newProperties1 = new MsoJavaProperties(); + Mockito.when(utils.loadTopologyProperties()).thenReturn(newProperties1); + + newProperties1.setProperty("apih-load-balancer", ip1); + newProperties1.setProperty("apih-nodehealthcheck-urn",apihUrl1); + newProperties1.setProperty("camunda-load-balancer",ip1); + newProperties1.setProperty("camunda-nodehealthcheck-urn",bpmnUrl1); + newProperties1.setProperty("jra-load-balancer",ip1); + newProperties1.setProperty("jra-nodehealthcheck-urn",raUrl1); + + assertFalse (utils.verifyGlobalHealthCheck (true, null)); + + // mising apih-server-list parameter + MsoJavaProperties newProperties2 = new MsoJavaProperties(); + Mockito.when(utils.loadTopologyProperties()).thenReturn(newProperties2); + + newProperties2.setProperty("server-port", port); + newProperties1.setProperty("apih-nodehealthcheck-urn",apihUrl1); + newProperties1.setProperty("camunda-load-balancer",ip1); + newProperties1.setProperty("camunda-nodehealthcheck-urn",bpmnUrl1); + newProperties1.setProperty("jra-load-balancer",ip1); + newProperties1.setProperty("jra-nodehealthcheck-urn",raUrl1); + + assertFalse (utils.verifyGlobalHealthCheck (true, null)); + + // mising jra-healthcheck-urn parameter + MsoJavaProperties newProperties3 = new MsoJavaProperties(); + Mockito.when(utils.loadTopologyProperties()).thenReturn(newProperties3); + + newProperties3.setProperty("server-port", port); + newProperties1.setProperty("apih-load-balancer", ip1); + newProperties1.setProperty("apih-nodehealthcheck-urn",apihUrl1); + newProperties1.setProperty("camunda-load-balancer",ip1); + newProperties1.setProperty("camunda-nodehealthcheck-urn",bpmnUrl1); + newProperties1.setProperty("jra-load-balancer",ip1); + newProperties3.setProperty("jra-server-list",ip1); + + assertFalse (utils.verifyGlobalHealthCheck (true, null)); + + Mockito.when(utils.loadTopologyProperties()).thenReturn(properties); + } + + // User reflection to invoke to avoid change the publicity of the method + private static Object invokeProtectedMethod (HealthCheckUtils tempUtil, String methodName, String arg1, String arg2, String arg3, String arg4, String arg5) { + Method method; + try { + method = HealthCheckUtils.class.getDeclaredMethod(methodName, String.class, String.class, String.class, String.class, String.class); + method.setAccessible(true); + return method.invoke(tempUtil, arg1, arg2, arg3, arg4, arg5); + } 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/status-control/src/test/java/org/openecomp/mso/MsoStatusUtilESTest.java b/status-control/src/test/java/org/openecomp/mso/MsoStatusUtilESTest.java new file mode 100644 index 0000000000..3a05a7777b --- /dev/null +++ b/status-control/src/test/java/org/openecomp/mso/MsoStatusUtilESTest.java @@ -0,0 +1,24 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:26:39 GMT 2016 + */ + +package org.openecomp.mso; + +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 MsoStatusUtilESTest extends MsoStatusUtilESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoStatusUtil msoStatusUtil0 = new MsoStatusUtil(); + boolean boolean0 = msoStatusUtil0.getSiteStatus("getSiteStatus"); + assertFalse(boolean0); + } +} diff --git a/status-control/src/test/java/org/openecomp/mso/MsoStatusUtilESTestscaffolding.java b/status-control/src/test/java/org/openecomp/mso/MsoStatusUtilESTestscaffolding.java new file mode 100644 index 0000000000..bd9141aa66 --- /dev/null +++ b/status-control/src/test/java/org/openecomp/mso/MsoStatusUtilESTestscaffolding.java @@ -0,0 +1,121 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:26:39 GMT 2016 + */ + +package org.openecomp.mso; + +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 MsoStatusUtilESTestscaffolding { + + @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.MsoStatusUtil"; + 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(MsoStatusUtilESTestscaffolding.class.getClassLoader() , + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "com.att.eelf.configuration.EELFLogger", + "org.hibernate.engine.spi.Mapping", + "org.hibernate.criterion.Order", + "com.att.eelf.configuration.SLF4jWrapper", + "org.hibernate.Query", + "com.att.eelf.i18n.EELFResourceManager", + "org.openecomp.mso.requestsdb.InfraActiveRequests", + "org.hibernate.criterion.Criterion", + "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.hibernate.SessionFactory", + "org.openecomp.mso.logger.MsoLogger$StatusCode", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.MsoStatusUtil", + "com.att.eelf.i18n.EELFMsgs", + "org.openecomp.mso.requestsdb.RequestsDatabase", + "com.att.eelf.configuration.EELFLogger$Level", + "org.openecomp.mso.requestsdb.MockRequestsDatabase", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.hibernate.BasicQueryContract", + "com.att.eelf.i18n.EELFResourceManager$1", + "org.openecomp.mso.requestsdb.HibernateUtil", + "org.openecomp.mso.requestsdb.InfraRequests", + "org.openecomp.mso.requestsdb.SiteStatus" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoStatusUtilESTestscaffolding.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", + "com.att.eelf.configuration.EELFLogger$Level", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.requestsdb.HibernateUtil", + "org.openecomp.mso.requestsdb.RequestsDatabase" + ); + } +} |