summaryrefslogtreecommitdiffstats
path: root/feature-state-management/src/test/java/org
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-09-13 20:37:15 -0400
committerPamela Dragosh <pdragosh@research.att.com>2018-09-13 20:56:08 -0400
commitad83319991bdd6a25416eff9f0adde148e2eee35 (patch)
treebbaa601361802763cebf014160b87fa897d62a58 /feature-state-management/src/test/java/org
parentc733c08b7201ffdee81c7dab2ed50a1ce8fd5bbb (diff)
Fix checkstyle for features submodules.
These are the remaining submodules that have checkstyle. Pretty clean compile after this. There were a couple of sonar fixes in there also. Issue-ID: POLICY-882 Change-Id: I8191ea1aa261f4a7b9d3d21c108572fd31db1b8c Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'feature-state-management/src/test/java/org')
-rw-r--r--feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java20
-rw-r--r--feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java417
2 files changed, 219 insertions, 218 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
index b33171bb..943293c9 100644
--- 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Integrity Monitor
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -28,16 +28,16 @@ import javax.persistence.Id;
import javax.persistence.Table;
@Entity
-@Table(name="Audit")
+@Table(name = "Audit")
public class Audit implements Serializable {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- @Id
- @Column(name="name", length=64, unique=true)
- private String name;
-
- public Audit() {
- //default constructor
- }
+ @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
index b364ef83..5c69284f 100644
--- 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-persistence
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -49,215 +49,216 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StateManagementTest {
-
- // get an instance of logger
- private static Logger logger = LoggerFactory.getLogger(StateManagementTest.class);
-
- StateManagementFeatureAPI stateManagementFeature;
-
- /*
- * 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()
- */
-
- @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 {
-
- }
-
- @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.setIsJunit(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 : StateManagementFeatureAPI.impl.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);
-
- assertTrue("Admin state not unlocked after initialization", admin.equals(StateManagement.UNLOCKED));
- assertTrue("Operational state not enabled after initialization", oper.equals(StateManagement.ENABLED));
-
- 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);
-
- assertTrue("Operational state not disabled after disableFailed()", oper.equals(StateManagement.DISABLED));
- assertTrue("Availability status not failed after disableFailed()", avail.equals(StateManagement.FAILED));
-
-
- 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);
-
- assertTrue("Standby status not coldstandby after promote()", standby.equals(StateManagement.COLD_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
- assertTrue(true);
- }catch(IOException 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);
- }catch(InterruptedException e){
- assertTrue(false);
- logger.debug("testSubsytemTest RepositoryAudit InterruptedException", e);
- }
-
- /*****************Db Audit Test***************/
- logger.debug("\n\ntestStateManagementOperation: DB Audit\n\n");
-
- try{
- DbAudit dbAudit = (DbAudit) DbAudit.getInstance();
- dbAudit.invoke(fsmProperties);
-
- assertTrue(true);
- }catch(Exception e){
- assertTrue(false);
- logger.debug("testSubsytemTest DbAudit exception", e);
- }
-
- /*************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");
- }
-
+
+ // get an instance of logger
+ private static Logger logger = LoggerFactory.getLogger(StateManagementTest.class);
+
+ 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 {
+
+ }
+
+ @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.setIsJunit(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 : StateManagementFeatureAPI.impl.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);
+
+ assertTrue("Admin state not unlocked after initialization", admin.equals(StateManagement.UNLOCKED));
+ assertTrue("Operational state not enabled after initialization", oper.equals(StateManagement.ENABLED));
+
+ 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);
+
+ assertTrue("Operational state not disabled after disableFailed()", oper.equals(StateManagement.DISABLED));
+ assertTrue("Availability status not failed after disableFailed()", avail.equals(StateManagement.FAILED));
+
+
+ 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);
+
+ assertTrue("Standby status not coldstandby after promote()", standby.equals(StateManagement.COLD_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
+ assertTrue(true);
+ } catch (IOException 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);
+ } catch (InterruptedException e) {
+ assertTrue(false);
+ logger.debug("testSubsytemTest RepositoryAudit InterruptedException", e);
+ }
+
+ /*****************Db Audit Test. ***************/
+ logger.debug("\n\ntestStateManagementOperation: DB Audit\n\n");
+
+ try {
+ DbAudit dbAudit = (DbAudit) DbAudit.getInstance();
+ dbAudit.invoke(fsmProperties);
+
+ assertTrue(true);
+ } catch (Exception e) {
+ assertTrue(false);
+ logger.debug("testSubsytemTest DbAudit exception", e);
+ }
+
+ /*************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:file:./sql/statemanagement");
- cleanProperties.put(StateManagementProperties.DB_USER, "sa");
- cleanProperties.put(StateManagementProperties.DB_PWD, "");
-
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("junitPU", cleanProperties);
-
- EntityManager 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();
- em.close();
-
- logger.debug("initializeDb: Exiting");
- }
+ 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:file:./sql/statemanagement");
+ cleanProperties.put(StateManagementProperties.DB_USER, "sa");
+ cleanProperties.put(StateManagementProperties.DB_PWD, "");
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory("junitPU", cleanProperties);
+
+ EntityManager 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();
+ em.close();
+
+ logger.debug("initializeDb: Exiting");
+ }
}