aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java7
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java2
-rw-r--r--feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java43
-rw-r--r--feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java70
-rw-r--r--feature-state-management/src/test/resources/META-INF/persistence.xml1
-rw-r--r--feature-state-management/src/test/resources/feature-state-management.properties14
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java92
7 files changed, 200 insertions, 29 deletions
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java
index efecf887..cde6e4e4 100644
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java
+++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java
@@ -43,6 +43,8 @@ public class DbAudit extends DroolsPDPIntegrityMonitor.AuditBase
// This indicates if 'CREATE TABLE IF NOT EXISTS Audit ...' should be
// invoked -- doing this avoids the need to create the table in advance.
static private boolean createTableNeeded = true;
+
+ static public boolean isJunit = false;
synchronized private static void setCreateTableNeeded(boolean b) {
DbAudit.createTableNeeded = b;
@@ -50,7 +52,7 @@ public class DbAudit extends DroolsPDPIntegrityMonitor.AuditBase
/**
* @return the single 'DbAudit' instance
*/
- static DroolsPDPIntegrityMonitor.AuditBase getInstance()
+ public static DroolsPDPIntegrityMonitor.AuditBase getInstance()
{
return(instance);
}
@@ -74,6 +76,9 @@ public class DbAudit extends DroolsPDPIntegrityMonitor.AuditBase
if(logger.isDebugEnabled()){
logger.debug("Running 'DbAudit.invoke'");
}
+ if(isJunit){
+ createTableNeeded = false;
+ }
boolean isActive = true;
String dbAuditIsActive = StateManagementProperties.getProperty("db.audit.is.active");
if(logger.isDebugEnabled()){
diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java
index 7eed736e..b36c1657 100644
--- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java
+++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java
@@ -51,7 +51,7 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase
/**
* @return the single 'RepositoryAudit' instance
*/
- static DroolsPDPIntegrityMonitor.AuditBase getInstance()
+ public static DroolsPDPIntegrityMonitor.AuditBase getInstance()
{
return instance;
}
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
new file mode 100644
index 00000000..b33171bb
--- /dev/null
+++ b/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/Audit.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Integrity Monitor
+ * ================================================================================
+ * 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.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
index 1cd61788..ba7ce3ea 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
@@ -24,12 +24,14 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
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;
@@ -38,6 +40,9 @@ import org.junit.BeforeClass;
import org.junit.Test;
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.StateManagementProperties;
import org.slf4j.Logger;
@@ -49,10 +54,10 @@ public class StateManagementTest {
private static Logger logger = LoggerFactory.getLogger(StateManagementTest.class);
/*
- * Sleep 5 seconds after each test to allow interrupt (shutdown) recovery.
+ * Sleep after each test to allow interrupt (shutdown) recovery.
*/
- private long interruptRecoveryTime = 1000;
+ private long interruptRecoveryTime = 1500L;
StateManagementFeatureAPI stateManagementFeature;
@@ -90,7 +95,6 @@ public class StateManagementTest {
public void tearDown() throws Exception {
}
-
/*
* Verifies that StateManagementFeature starts and runs successfully.
@@ -106,6 +110,8 @@ public class StateManagementTest {
String configDir = "src/test/resources";
+ DbAudit.isJunit = true;
+
Properties fsmProperties = new Properties();
fsmProperties.load(new FileInputStream(new File(
configDir + "/feature-state-management.properties")));
@@ -136,13 +142,9 @@ public class StateManagementTest {
String standby = stateManagementFeature.getStandbyStatus();
logger.debug("admin = {}", admin);
- System.out.println("admin = " + admin);
logger.debug("oper = {}", oper);
- System.out.println("oper = " + oper);
logger.debug("avail = {}", avail);
- System.out.println("avail = " + avail);
logger.debug("standby = {}", standby);
- System.out.println("standby = " + standby);
assertTrue("Admin state not unlocked after initialization", admin.equals(StateManagement.UNLOCKED));
assertTrue("Operational state not enabled after initialization", oper.equals(StateManagement.ENABLED));
@@ -151,7 +153,6 @@ public class StateManagementTest {
stateManagementFeature.disableFailed();
}catch(Exception e){
logger.error(e.getMessage());
- System.out.println(e.getMessage());
assertTrue(e.getMessage(), false);
}
@@ -163,15 +164,10 @@ public class StateManagementTest {
standby = stateManagementFeature.getStandbyStatus();
logger.debug("after disableFailed()");
- System.out.println("after disableFailed()");
logger.debug("admin = {}", admin);
- System.out.println("admin = " + admin);
logger.debug("oper = {}", oper);
- System.out.println("oper = " + oper);
logger.debug("avail = {}", avail);
- System.out.println("avail = " + avail);
logger.debug("standby = {}", standby);
- System.out.println("standby = " + standby);
assertTrue("Operational state not disabled after disableFailed()", oper.equals(StateManagement.DISABLED));
assertTrue("Availability status not failed after disableFailed()", avail.equals(StateManagement.FAILED));
@@ -181,7 +177,6 @@ public class StateManagementTest {
stateManagementFeature.promote();
}catch(Exception e){
logger.debug(e.getMessage());
- System.out.println(e.getMessage());
}
Thread.sleep(interruptRecoveryTime);
@@ -192,18 +187,53 @@ public class StateManagementTest {
standby = stateManagementFeature.getStandbyStatus();
logger.debug("after promote()");
- System.out.println("after promote()");
logger.debug("admin = {}", admin);
- System.out.println("admin = " + admin);
logger.debug("oper = {}", oper);
- System.out.println("oper = " + oper);
logger.debug("avail = {}", avail);
- System.out.println("avail = " + avail);
logger.debug("standby = {}", standby);
- System.out.println("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{
+ 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");
}
diff --git a/feature-state-management/src/test/resources/META-INF/persistence.xml b/feature-state-management/src/test/resources/META-INF/persistence.xml
index d26ab443..0214b7f5 100644
--- a/feature-state-management/src/test/resources/META-INF/persistence.xml
+++ b/feature-state-management/src/test/resources/META-INF/persistence.xml
@@ -28,6 +28,7 @@
<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"/>
diff --git a/feature-state-management/src/test/resources/feature-state-management.properties b/feature-state-management/src/test/resources/feature-state-management.properties
index 7b4a697e..64c7c660 100644
--- a/feature-state-management/src/test/resources/feature-state-management.properties
+++ b/feature-state-management/src/test/resources/feature-state-management.properties
@@ -56,19 +56,25 @@ max_fpc_update_interval=120
# 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=60000
+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=600000
+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=false
+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:file:./sql/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=false
+db.audit.is.active=true
diff --git a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
index 981d5748..3a9f8a4b 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
@@ -28,7 +28,9 @@ import java.util.Properties;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
import org.junit.Test;
+import org.junit.runners.MethodSorters;
import org.onap.policy.drools.properties.PolicyProperties;
import org.onap.policy.drools.system.PolicyEngine;
import org.slf4j.Logger;
@@ -36,11 +38,15 @@ import org.slf4j.LoggerFactory;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RestManagerTest {
@@ -117,11 +123,85 @@ public class RestManagerTest {
}
-
+
@Test
- public void GETTest() throws ClientProtocolException, IOException, InterruptedException {
- assertTrue(PolicyEngine.manager.isAlive());
+ public void putDeleteTest() throws ClientProtocolException, IOException, InterruptedException {
+ HttpPut httpPut;
+ HttpDelete httpDelete;
+ CloseableHttpResponse response;
+
+ httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/events");
+ httpPut.addHeader("Content-Type", "text/plain");
+ httpPut.addHeader("Accept", "application/json");
+ httpPut.setEntity(new StringEntity("FOOOO"));
+ response = client.execute(httpPut);
+ logger.info("/engine/topics/sources/ueb/{}/events response code: {}", UEB_TOPIC, response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpPut.releaseConnection();
+
+ httpPut = new HttpPut(HOST_URL + "/engine/topics/switches/lock");
+ response = client.execute(httpPut);
+ logger.info("/engine/topics/switches/lock response code: {}", response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpPut.releaseConnection();
+
+ httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/events");
+ httpPut.addHeader("Content-Type", "text/plain");
+ httpPut.addHeader("Accept", "application/json");
+ httpPut.setEntity(new StringEntity("FOOOO"));
+ response = client.execute(httpPut);
+ logger.info("/engine/topics/sources/ueb/{}/events response code: {}", UEB_TOPIC, response.getStatusLine().getStatusCode());
+ assertEquals(406, response.getStatusLine().getStatusCode());
+ httpPut.releaseConnection();
+
+ httpDelete = new HttpDelete(HOST_URL + "/engine/topics/switches/lock");
+ response = client.execute(httpDelete);
+ logger.info("/engine/topics/switches/lock response code: {}", response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpDelete.releaseConnection();
+
+ httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/switches/lock");
+ response = client.execute(httpPut);
+ logger.info("/engine/topics/sources/ueb/{}/switches/lock: {}", UEB_TOPIC, response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpPut.releaseConnection();
+
+ httpDelete = new HttpDelete(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/switches/lock");
+ response = client.execute(httpDelete);
+ logger.info("/engine/topics/sources/ueb/{}/switches/lock: {}", UEB_TOPIC, response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpDelete.releaseConnection();
+
+ httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC + "/switches/lock");
+ response = client.execute(httpPut);
+ logger.info("/engine/topics/sources/dmaap/{}/switches/lock: {}", DMAAP_TOPIC, response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpPut.releaseConnection();
+
+ httpDelete = new HttpDelete(HOST_URL + "/engine/topics/sources/dmaap/" + DMAAP_TOPIC + "/switches/lock");
+ response = client.execute(httpDelete);
+ logger.info("/engine/topics/sources/dmaap/{}/switches/lock: {}", DMAAP_TOPIC, response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpDelete.releaseConnection();
+
+ httpPut = new HttpPut(HOST_URL + "/engine/switches/activation");
+ response = client.execute(httpPut);
+ logger.info("/engine/switches/activation response code: {}", response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpPut.releaseConnection();
+
+ httpDelete = new HttpDelete(HOST_URL + "/engine/switches/activation");
+ response = client.execute(httpDelete);
+ logger.info("/engine/switches/activation response code: {}", response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpDelete.releaseConnection();
+ }
+
+
+ @Test
+ public void getTest() throws ClientProtocolException, IOException, InterruptedException {
+
HttpGet httpGet;
CloseableHttpResponse response;
String responseBody;
@@ -561,6 +641,12 @@ public class RestManagerTest {
assertEquals(200, response.getStatusLine().getStatusCode());
httpGet.releaseConnection();
+ httpGet = new HttpGet(HOST_URL + "/engine/tools/loggers/ROOT");
+ response = client.execute(httpGet);
+ logger.info("engine/tools/loggers/ROOT response code: {}", response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
}