summaryrefslogtreecommitdiffstats
path: root/feature-state-management/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'feature-state-management/src/test')
-rw-r--r--feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java42
-rw-r--r--feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java257
-rw-r--r--feature-state-management/src/test/resources/META-INF/persistence.xml50
-rw-r--r--feature-state-management/src/test/resources/feature-state-management.properties87
-rw-r--r--feature-state-management/src/test/resources/logback-test.xml50
5 files changed, 0 insertions, 486 deletions
diff --git a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java b/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java
deleted file mode 100644
index 37d9d7b8..00000000
--- a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Integrity Monitor
- * ================================================================================
- * Copyright (C) 2017-2018 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.onap.policy.drools.statemanagement.test;
-
-import java.io.Serializable;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-@Entity
-@Table(name = "Audit")
-
-public class Audit implements Serializable {
- private static final long serialVersionUID = 1L;
-
- @Id
- @Column(name = "name", length = 64, unique = true)
- private String name;
-
- public Audit() {
- //default constructor
- }
-}
diff --git a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java b/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java
deleted file mode 100644
index 578b6222..00000000
--- a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * policy-persistence
- * ================================================================================
- * Copyright (C) 2017-2021 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.onap.policy.drools.statemanagement.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.Properties;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Persistence;
-import javax.ws.rs.core.Response;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.im.IntegrityMonitorException;
-import org.onap.policy.common.im.StateManagement;
-import org.onap.policy.drools.core.PolicySessionFeatureApi;
-import org.onap.policy.drools.statemanagement.DbAudit;
-import org.onap.policy.drools.statemanagement.IntegrityMonitorRestManager;
-import org.onap.policy.drools.statemanagement.RepositoryAudit;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApi;
-import org.onap.policy.drools.statemanagement.StateManagementFeatureApiConstants;
-import org.onap.policy.drools.statemanagement.StateManagementProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class StateManagementTest {
-
- // get an instance of logger
- private static Logger logger = LoggerFactory.getLogger(StateManagementTest.class);
-
- private static EntityManagerFactory emf;
- private static EntityManager em;
-
- StateManagementFeatureApi stateManagementFeature;
-
- /**
- * Setup the class.
- * All you need to do here is create an instance of StateManagementFeature class. Then,
- * check it initial state and the state after diableFailed() and promote()
- *
- * @throws Exception exception
- */
- @BeforeClass
- public static void setUpClass() throws Exception {
-
- logger.info("setUpClass: Entering");
-
- String userDir = System.getProperty("user.dir");
- logger.debug("setUpClass: userDir=" + userDir);
- System.setProperty("com.sun.management.jmxremote.port", "9980");
- System.setProperty("com.sun.management.jmxremote.authenticate", "false");
-
- initializeDb();
-
- logger.info("setUpClass: Exiting");
- }
-
- @AfterClass
- public static void tearDownClass() throws Exception {
- em.close();
- emf.close();
- }
-
- @Before
- public void setUp() throws Exception {
-
- }
-
- @After
- public void tearDown() throws Exception {
-
- }
-
- /*
- * Verifies that StateManagementFeature starts and runs successfully.
- */
-
- //@Ignore
- @Test
- public void testStateManagementOperation() throws Exception {
-
- logger.debug("\n\ntestStateManagementOperation: Entering\n\n");
-
- logger.debug("testStateManagementOperation: Reading StateManagementProperties");
-
- String configDir = "src/test/resources";
-
- DbAudit.setJunit(true);
-
- Properties fsmProperties = new Properties();
- fsmProperties.load(new FileInputStream(new File(
- configDir + "/feature-state-management.properties")));
- String thisPdpId = fsmProperties
- .getProperty(StateManagementProperties.NODE_NAME);
-
- StateManagementFeatureApi stateManagementFeature = null;
- for (StateManagementFeatureApi feature : StateManagementFeatureApiConstants.getImpl().getList()) {
- ((PolicySessionFeatureApi) feature).globalInit(null, configDir);
- stateManagementFeature = feature;
- logger.debug("testStateManagementOperation stateManagementFeature.getResourceName(): "
- + stateManagementFeature.getResourceName());
- break;
- }
- if (stateManagementFeature == null) {
- String msg = "testStateManagementOperation failed to initialize. "
- + "Unable to get instance of StateManagementFeatureApi "
- + "with resourceID: " + thisPdpId;
- logger.error(msg);
- logger.debug(msg);
- }
-
- String admin = stateManagementFeature.getAdminState();
- String oper = stateManagementFeature.getOpState();
- String avail = stateManagementFeature.getAvailStatus();
- String standby = stateManagementFeature.getStandbyStatus();
-
- logger.debug("admin = {}", admin);
- logger.debug("oper = {}", oper);
- logger.debug("avail = {}", avail);
- logger.debug("standby = {}", standby);
-
- assertEquals("Admin state not unlocked after initialization", StateManagement.UNLOCKED, admin);
- assertEquals("Operational state not enabled after initialization", StateManagement.ENABLED, oper);
-
- try {
- stateManagementFeature.disableFailed();
- } catch (Exception e) {
- logger.error(e.getMessage());
- assertTrue(e.getMessage(), false);
- }
-
- admin = stateManagementFeature.getAdminState();
- oper = stateManagementFeature.getOpState();
- avail = stateManagementFeature.getAvailStatus();
- standby = stateManagementFeature.getStandbyStatus();
-
- logger.debug("after disableFailed()");
- logger.debug("admin = {}", admin);
- logger.debug("oper = {}", oper);
- logger.debug("avail = {}", avail);
- logger.debug("standby = {}", standby);
-
- assertEquals("Operational state not disabled after disableFailed()", StateManagement.DISABLED, oper);
- assertEquals("Availability status not failed after disableFailed()", StateManagement.FAILED, avail);
-
-
- try {
- stateManagementFeature.promote();
- } catch (Exception e) {
- logger.debug(e.getMessage());
- }
-
- admin = stateManagementFeature.getAdminState();
- oper = stateManagementFeature.getOpState();
- avail = stateManagementFeature.getAvailStatus();
- standby = stateManagementFeature.getStandbyStatus();
-
- logger.debug("after promote()");
- logger.debug("admin = {}", admin);
- logger.debug("oper = {}", oper);
- logger.debug("avail = {}", avail);
- logger.debug("standby = {}", standby);
-
- assertEquals("Standby status not coldstandby after promote()", StateManagement.COLD_STANDBY, standby);
-
- /* *************Repository Audit Test. ************* */
- logger.debug("\n\ntestStateManagementOperation: Repository Audit\n\n");
- try {
- StateManagementProperties.initProperties(fsmProperties);
- RepositoryAudit repositoryAudit = (RepositoryAudit) RepositoryAudit.getInstance();
- repositoryAudit.invoke(fsmProperties);
-
- //Should not throw an IOException in Linux Foundation env
-
- } catch (IntegrityMonitorException e) {
- //Note: this catch is here because in a local environment mvn will not run in
- //in the temp directory
- logger.debug("testSubsytemTest RepositoryAudit IOException", e);
- }
-
- /* ****************Db Audit Test. ************** */
- logger.debug("\n\ntestStateManagementOperation: DB Audit\n\n");
-
- DbAudit dbAudit = (DbAudit) DbAudit.getInstance();
- dbAudit.invoke(fsmProperties);
-
- /* ************IntegrityMonitorRestManager Test. ************ */
- logger.debug("\n\ntestStateManagementOperation: IntegrityMonitorRestManager\n\n");
- IntegrityMonitorRestManager integrityMonitorRestManager = new IntegrityMonitorRestManager();
-
- Response response = integrityMonitorRestManager.test();
- logger.debug("\n\nIntegrityMonitorRestManager response: " + response.toString());
-
- assertTrue(response.toString().contains("status=500"));
-
- //All done
- logger.debug("\n\ntestStateManagementOperation: Exiting\n\n");
- }
-
- /**
- * This method initializes and cleans the DB so that PDP-D will be able to
- * store fresh records in the DB.
- */
- public static void initializeDb() {
-
- logger.debug("initializeDb: Entering");
-
- Properties cleanProperties = new Properties();
- cleanProperties.put(StateManagementProperties.DB_DRIVER, "org.h2.Driver");
- cleanProperties.put(StateManagementProperties.DB_URL, "jdbc:h2:mem:statemanagement");
- cleanProperties.put(StateManagementProperties.DB_USER, "sa");
- cleanProperties.put(StateManagementProperties.DB_PWD, "");
-
- emf = Persistence.createEntityManagerFactory("junitPU", cleanProperties);
-
- em = emf.createEntityManager();
- // Start a transaction
- EntityTransaction et = em.getTransaction();
-
- et.begin();
-
- // Clean up the DB
- em.createQuery("Delete from StateManagementEntity").executeUpdate();
- em.createQuery("Delete from ForwardProgressEntity").executeUpdate();
- em.createQuery("Delete from ResourceRegistrationEntity").executeUpdate();
-
- // commit transaction
- et.commit();
-
- logger.debug("initializeDb: Exiting");
- }
-}
diff --git a/feature-state-management/src/test/resources/META-INF/persistence.xml b/feature-state-management/src/test/resources/META-INF/persistence.xml
deleted file mode 100644
index c96d8b64..00000000
--- a/feature-state-management/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- feature-state-management
- ================================================================================
- Copyright (C) 2017-2018, 2020 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=========================================================
- -->
-
-<persistence version="2.1"
- xmlns="http://xmlns.jcp.org/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
-
- <persistence-unit name="junitPU"
- transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <class>org.onap.policy.common.im.jpa.StateManagementEntity</class>
- <class>org.onap.policy.common.im.jpa.ForwardProgressEntity</class>
- <class>org.onap.policy.common.im.jpa.ResourceRegistrationEntity</class>
- <class>org.onap.policy.drools.statemanagement.test.Audit</class>
- <properties>
- <property
- name="javax.persistence.schema-generation.database.action"
- value="drop-and-create" />
- <property
- name="javax.persistence.schema-generation.scripts.action"
- value="drop-and-create" />
- <property
- name="javax.persistence.schema-generation.scripts.create-target"
- value="target/classes/META-INF/generatedCreateStateManagement.ddl" />
- <property
- name="javax.persistence.schema-generation.scripts.drop-target"
- value="target/classes/META-INF/generatedDropStateManagement.ddl" />
- </properties>
- </persistence-unit>
-
-</persistence>
diff --git a/feature-state-management/src/test/resources/feature-state-management.properties b/feature-state-management/src/test/resources/feature-state-management.properties
deleted file mode 100644
index ef7b805a..00000000
--- a/feature-state-management/src/test/resources/feature-state-management.properties
+++ /dev/null
@@ -1,87 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# feature-state-management
-# ================================================================================
-# Copyright (C) 2017, 2020-2021 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=========================================================
-###
-
-# DB properties
-eclipselink.target-database=Auto
-javax.persistence.jdbc.driver = org.h2.Driver
-javax.persistence.jdbc.url = jdbc:h2:mem:statemanagement
-javax.persistence.jdbc.user = sa
-javax.persistence.jdbc.password =
-
-# DroolsPDPIntegrityMonitor Properties
-#Test interface host and port defaults may be overwritten here
-http.server.services.TEST.host=0.0.0.0
-http.server.services.TEST.port=9981
-#These properties will default to the following if no other values are provided:
-# http.server.services.TEST.restClasses=org.onap.policy.drools.statemanagement.IntegrityMonitorRestManager
-# http.server.services.TEST.managed=false
-# http.server.services.TEST.swagger=true
-
-#IntegrityMonitor Properties
-
-# Must be unique across the system
-resource.name=pdp1
-# Name of the site in which this node is hosted
-site_name = pdp_1
-# Forward Progress Monitor update interval seconds
-fp_monitor_interval = 30
-# Failed counter threshold before failover
-failed_counter_threshold = 3
-# Interval between test transactions when no traffic seconds
-test_trans_interval = 10
-# Interval between writes of the FPC to the DB seconds
-write_fpc_interval = 5
-# Node type Note: Make sure you don't leave any trailing spaces, or you'll get an 'invalid node type' error!
-node_type = pdp_drools
-# Dependency groups are groups of resources upon which a node operational state is dependent upon.
-# Each group is a comma-separated list of resource names and groups are separated by a semicolon. For example:
-# dependency_groups=site_1.astra_1,site_1.astra_2;site_1.brms_1,site_1.brms_2;site_1.logparser_1;site_1.pypdp_1
-dependency_groups=
-# When set to true, dependent health checks are performed by using JMX to invoke test() on the dependent.
-# The default false is to use state checks for health.
-test_via_jmx=true
-# This is the max number of seconds beyond which a non incrementing FPC is considered a failure
-max_fpc_update_interval=120
-# Run the state audit every 60 seconds (60000 ms). The state audit finds stale DB entries in the
-# forwardprogressentity table and marks the node as disabled/failed in the statemanagemententity
-# table. NOTE! It will only run on nodes that have a standbystatus = providingservice.
-# A value of <= 0 will turn off the state audit.
-state_audit_interval_ms=-1000
-# The refresh state audit is run every (default) 10 minutes (600000 ms) to clean up any state corruption in the
-# DB statemanagemententity table. It only refreshes the DB state entry for the local node. That is, it does not
-# refresh the state of any other nodes. A value <= 0 will turn the audit off. Any other value will override
-# the default of 600000 ms.
-refresh_state_audit_interval_ms=-1000
-
-
-# Repository audit properties
-# Flag to control the execution of the subsystemTest for the Nexus Maven repository
-repository.audit.is.active=true
-repository.audit.ignore.errors=true
-# Timeout in seconds
-repository.audit.timeout=5
-repository.audit.id=statemanagement
-repository.audit.url=jdbc:h2:mem:statemanagement
-repository.audit.username=sa
-repository.audit.password=
-
-# DB Audit Properties
-# Flag to control the execution of the subsystemTest for the Database
-db.audit.is.active=true
diff --git a/feature-state-management/src/test/resources/logback-test.xml b/feature-state-management/src/test/resources/logback-test.xml
deleted file mode 100644
index 99cdaf9a..00000000
--- a/feature-state-management/src/test/resources/logback-test.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- feature-state-management
- ================================================================================
- Copyright (C) 2017-2018 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=========================================================
- -->
-
-<!-- Controls the output of logs for JUnit tests -->
-
-<configuration>
-
- <appender name="STDOUT"
- class="ch.qos.logback.core.ConsoleAppender">
- <encoder
- class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
- <Pattern>
- %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n
- </Pattern>
- </encoder>
- </appender>
- <appender name="FILE"
- class="ch.qos.logback.core.FileAppender">
- <file>logs/debug.log</file>
- <encoder>
- <Pattern>
- %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n
- </Pattern>
- </encoder>
- </appender>
-
- <root level="debug">
- <appender-ref ref="STDOUT" />
- <appender-ref ref="FILE" />
- </root>
-
-</configuration>
-