summaryrefslogtreecommitdiffstats
path: root/integrity-monitor/src/test/java/org/onap/policy/common/im/StateManagementEntityTest.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-02-13 09:19:43 -0500
committerJim Hahn <jrh3@att.com>2018-02-13 19:21:55 -0500
commitbf2cc29bf766feabca8ef633926f5fce00a5fe2e (patch)
tree6094d9294378fe7226a3ed7e287dc0381b067fcf /integrity-monitor/src/test/java/org/onap/policy/common/im/StateManagementEntityTest.java
parent86664073b5a778c56e831d64b3a1883818af0ffe (diff)
Add test coverage to integrity-monitor
Removed "test" from package name. Refactored tests, creating common IntegrityMonitorTestBase. Turned log/print statements into assertEquals in StateTransitionTest. Turned log/print statements into assertEquals in StateManagementTest. Modified AllSeemsWellTest to use IntegrityMonitorTestBase. Modified IntegrityMonitorTest to use IntegrityMonitorTestBase. Added several hooks to IntegrityMonitor to control timers at a finer granularity. Added hooks to IntegrityMonitor to control the FPManager thread. Remove hooks for refresh timer, as property suffices. Added assertException() and assertNoException() methods to IntegrityMonitorTestBase, and then replaced most "try/catch" blocks with calls to those methods. Updated StateManagement to close EntityManagers. Modify pom to remove scope from utils dependency. Fix some comments and remove an unneeded EntityTransaction variable. Change-Id: Ic0789d26f985a40a35f618343fa4e88aa473b2b3 Issue-ID: POLICY-582 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'integrity-monitor/src/test/java/org/onap/policy/common/im/StateManagementEntityTest.java')
-rw-r--r--integrity-monitor/src/test/java/org/onap/policy/common/im/StateManagementEntityTest.java130
1 files changed, 130 insertions, 0 deletions
diff --git a/integrity-monitor/src/test/java/org/onap/policy/common/im/StateManagementEntityTest.java b/integrity-monitor/src/test/java/org/onap/policy/common/im/StateManagementEntityTest.java
new file mode 100644
index 00000000..44faa58f
--- /dev/null
+++ b/integrity-monitor/src/test/java/org/onap/policy/common/im/StateManagementEntityTest.java
@@ -0,0 +1,130 @@
+/*-
+ * ============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.common.im;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import javax.persistence.Query;
+
+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.jpa.StateManagementEntity;
+import org.onap.policy.common.utils.jpa.EntityTransCloser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StateManagementEntityTest extends IntegrityMonitorTestBase {
+ private static Logger logger = LoggerFactory.getLogger(StateManagementEntityTest.class);
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ IntegrityMonitorTestBase.setUpBeforeClass(DEFAULT_DB_URL_PREFIX + StateManagementEntityTest.class.getSimpleName());
+
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ IntegrityMonitorTestBase.tearDownAfterClass();
+ }
+
+ @Before
+ public void setUp() {
+ super.setUpTest();
+ }
+
+ @After
+ public void tearDown() {
+ super.tearDownTest();
+ }
+
+ @Test
+ public void testJPA() throws Exception {
+ logger.debug("\n??? logger.infor StateManagementEntityTest: Entering\n\n");
+
+ //Define the resourceName for the StateManagement constructor
+ String resourceName = "test_resource1";
+
+ //
+ logger.debug("Create StateManagementEntity, resourceName: {}", resourceName);
+ logger.debug("??? instantiate StateManagementEntity object");
+ StateManagementEntity sme = new StateManagementEntity();
+
+ logger.debug("??? setResourceName : {}", resourceName);
+ sme.setResourceName(resourceName);
+ logger.debug("??? getResourceName : {}", sme.getResourceName());
+
+ sme.setAdminState(StateManagement.UNLOCKED);
+ assertEquals(StateManagement.UNLOCKED, sme.getAdminState());
+
+ sme.setOpState(StateManagement.ENABLED);
+ assertEquals(StateManagement.ENABLED, sme.getOpState());
+
+ sme.setAvailStatus(StateManagement.NULL_VALUE);
+ assertEquals(StateManagement.NULL_VALUE, sme.getAvailStatus());
+
+ sme.setStandbyStatus(StateManagement.COLD_STANDBY);
+ assertEquals(StateManagement.COLD_STANDBY, sme.getStandbyStatus());
+
+ try(EntityTransCloser et = new EntityTransCloser(em.getTransaction())) {
+ logger.debug("??? before persist");
+ em.persist(sme);
+ logger.debug("??? after persist");
+
+ em.flush();
+ logger.debug("??? after flush");
+
+ et.commit();
+ logger.debug("??? after commit");
+ }
+
+ try {
+ Query query = em.createQuery("Select p from StateManagementEntity p where p.resourceName=:resource");
+
+ query.setParameter("resource", resourceName);
+
+ //Just test that we are retrieving the right object
+ @SuppressWarnings("rawtypes")
+ List resourceList = query.getResultList();
+ if (!resourceList.isEmpty()) {
+ // exist
+ StateManagementEntity sme2 = (StateManagementEntity) resourceList.get(0);
+
+ assertEquals(sme.getResourceName(), sme2.getResourceName());
+ assertEquals(sme.getAdminState(), sme2.getAdminState());
+ assertEquals(sme.getOpState(), sme2.getOpState());
+ assertEquals(sme.getAvailStatus(), sme2.getAvailStatus());
+ assertEquals(sme.getStandbyStatus(), sme2.getStandbyStatus());
+ logger.debug("--");
+ } else {
+ logger.debug("Record not found, resourceName: {}", resourceName);
+ }
+ } catch(Exception ex) {
+ logger.error("Exception on select query: " + ex.toString());
+ }
+
+ logger.debug("\n\nJpaTest: Exit\n\n");
+ }
+}