aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PAP-REST/src/test/java/org/onap')
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/ia/DbAuditCompareEntriesTest.java800
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/UpdateOthersPAPSTest.java118
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java398
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/PAPRestConfigTest.java84
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java14
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/XACMLPapServletTest.java78
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/SearchDataTest.java58
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/UpdateObjectDataTest.java24
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ActionPolicyTest.java174
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicyTest.java64
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicyTest.java186
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java180
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/MicroServicePolicyTest.java126
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicyTest.java114
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java1054
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java220
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryControllerTest.java388
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java786
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java434
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java236
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java342
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java184
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java1226
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryControllerTest.java1342
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java198
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryControllerTest.java664
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyControllerTest.java138
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java308
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElasticSearchPolicyUpdateTest.java62
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java208
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PairTest.java32
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticDataTest.java310
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticSearchControllerTest.java84
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyLocatorTest.java20
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java128
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/PushPolicyHandlerTest.java78
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/jpa/PolicyEntityTest.java608
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/model/RemoveGroupPolicyTest.java28
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java16
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/MetricServiceTest.java22
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/AuthenticationServiceTest.java44
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/PAPAuthenticationFilterTest.java160
42 files changed, 5869 insertions, 5869 deletions
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/ia/DbAuditCompareEntriesTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/ia/DbAuditCompareEntriesTest.java
index 049f721ea..5b4165fdb 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/ia/DbAuditCompareEntriesTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/ia/DbAuditCompareEntriesTest.java
@@ -50,404 +50,404 @@ import org.onap.policy.jpa.BackUpMonitorEntity;
public class DbAuditCompareEntriesTest {
- private static Log logger = LogFactory.getLog(DbAuditCompareEntriesTest.class);
- private DbDAO dbDAO;
- private String persistenceUnit;
- private Properties properties;
- private String resourceName;
- private String dbDriver;
- private String dbUrl;
- private String dbUser;
- private String dbPwd;
- private String siteName;
- private String nodeType;
- private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
- private static final String DEFAULT_DB_USER = "sa";
- private static final String DEFAULT_DB_PWD = "";
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
-
- properties = new Properties();
- properties.put(IntegrityAuditProperties.DB_DRIVER, DbAuditCompareEntriesTest.DEFAULT_DB_DRIVER);
- properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest");
- properties.put(IntegrityAuditProperties.DB_USER, DbAuditCompareEntriesTest.DEFAULT_DB_USER);
- properties.put(IntegrityAuditProperties.DB_PWD, DbAuditCompareEntriesTest.DEFAULT_DB_PWD);
- properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA");
- properties.put(IntegrityAuditProperties.NODE_TYPE, "pap");
-
- dbDriver = DbAuditCompareEntriesTest.DEFAULT_DB_DRIVER;
- dbUrl = "jdbc:h2:file:./sql/xacmlTest";
- dbUser = DbAuditCompareEntriesTest.DEFAULT_DB_USER;
- dbPwd = DbAuditCompareEntriesTest.DEFAULT_DB_PWD;
- siteName = "SiteA";
- nodeType = "pap";
- persistenceUnit = "testPapPU";
- resourceName = "siteA.pap1";
-
- //Clean the iaTest DB table for IntegrityAuditEntity entries
- cleanDb(persistenceUnit, properties);
-
- logger.info("setUp: Exiting");
- }
-
- @After
- public void tearDown() throws Exception {
- logger.info("tearDown: Entering");
- //nothing to do
- logger.info("tearDown: Exiting");
- }
-
- public void cleanDb(String persistenceUnit, Properties properties){
- logger.debug("cleanDb: enter");
-
- EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
-
- EntityManager em = emf.createEntityManager();
- // Start a transaction
- EntityTransaction et = em.getTransaction();
-
- et.begin();
-
- // Clean up the DB
- em.createQuery("Delete from IntegrityAuditEntity").executeUpdate();
-
- // commit transaction
- et.commit();
- em.close();
- logger.debug("cleanDb: exit");
- }
-
-
- /*
- * Tests that a comparison between hashsets is successful if
- * the entries match
- */
- @Test
- public void runAllTests() throws Exception {
- logger.info("runAllTests: Entering");
-
-
- testIntegrityAuditEntity();
- testBackupMonitorEntity();
- testStateManagementEntity();
- testForwardProgressEntity();
- testResourceRegistrationEntity();
-
- //clean up the IntegrityAuditEntity table
- cleanDb(persistenceUnit, properties);
-
- logger.info("runAllTests: Exit");
- }
-
-
- public void testIntegrityAuditEntity() throws Exception {
- logger.info("testIntegrityAuditEntity: Entering");
-
- dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
- DbAudit dbAudit = new DbAudit(dbDAO);
-
- String className = null;
- //There is only one entry IntegrityAuditEntity, but we will check anyway
- Set<String> classNameSet = dbDAO.getPersistenceClassNames();
- for(String c : classNameSet){
- if (c.equals("org.onap.policy.common.ia.jpa.IntegrityAuditEntity")){
- className = c;
- }
- }
- String resourceName1 = resourceName;
- String resourceName2 = resourceName;
-
- IntegrityAuditEntity entry1 = new IntegrityAuditEntity();
- IntegrityAuditEntity entry2 = new IntegrityAuditEntity();
- Date date = new Date();
-
- /*
- * Two entries with the same field values
- */
- entry1.setDesignated(false);
- entry1.setJdbcDriver(dbDriver);
- entry1.setJdbcPassword(dbPwd);
- entry1.setJdbcUrl(dbUrl);
- entry1.setJdbcUser(dbUser);
- entry1.setLastUpdated(date);
- entry1.setNodeType(nodeType);
- entry1.setPersistenceUnit(persistenceUnit);
- entry1.setResourceName(resourceName1);
- entry1.setSite(siteName);
-
- entry2 = SerializationUtils.clone(entry1);
-
- dbAudit.writeAuditDebugLog(className, resourceName1, resourceName2, entry1, entry2);
-
- HashMap<Object, Object> myEntries = new HashMap<>();
- HashMap<Object, Object> theirEntries = new HashMap<>();
-
- myEntries.put("pdp1", entry1);
- theirEntries.put("pdp1", entry2);
-
- Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
-
- /*
- * Assert that there are no mismatches returned
- */
- assertTrue(result.isEmpty());
-
- /*
- * ************************************
- * Now test with a mis-matched entry
- * ************************************
- */
-
- /*
- * Change the entry2 to different designated value
- */
- entry2.setDesignated(true);
-
- myEntries = new HashMap<>();
- theirEntries = new HashMap<>();
-
- myEntries.put("pdp1", entry1);
- theirEntries.put("pdp1", entry2);
-
- result = dbAudit.compareEntries(myEntries, theirEntries);
-
- /*
- * Assert that there was one mismatch
- */
- assertEquals(1, result.size());
- logger.info("testIntegrityAuditEntity: Exit");
- }
-
- void testBackupMonitorEntity() throws Exception {
- logger.info("testBackupMonitorEntity: Entering");
-
- dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
- DbAudit dbAudit = new DbAudit(dbDAO);
-
- BackUpMonitorEntity entry1 = new BackUpMonitorEntity();
- BackUpMonitorEntity entry2 = new BackUpMonitorEntity();
-
- // Two entries with the same field values
-
-
- entry1.setFlag("flag1");
- entry1.setResourceNodeName("node1");
- entry1.setResourceName("resourceName");
- entry1.setTimeStamp(new Date());
-
- // Clone the first entry
- entry2 = SerializationUtils.clone(entry1);
-
- HashMap<Object, Object> myEntries = new HashMap<>();
- HashMap<Object, Object> theirEntries = new HashMap<>();
-
- myEntries.put("pdp1", entry1);
- theirEntries.put("pdp1", entry2);
-
- Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
-
-
- // Assert that there are no mismatches returned
-
- assertTrue(result.isEmpty());
-
-
- /* ************************************
- * Now test with a mis-matched entry
- * ************************************/
-
-
-
- // Change a field on entry2
-
- entry2.setFlag("flag2");
-
- myEntries = new HashMap<>();
- theirEntries = new HashMap<>();
-
- myEntries.put("pdp1", entry1);
- theirEntries.put("pdp1", entry2);
-
- result = dbAudit.compareEntries(myEntries, theirEntries);
-
-
- //Assert that there was one mismatch
-
- assertEquals(1, result.size());
- logger.info("testBackupMonitorEntity: Exit");
- }
-
- void testStateManagementEntity() throws Exception {
- logger.info("testStateManagementEntity: Entering");
-
- dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
- DbAudit dbAudit = new DbAudit(dbDAO);
-
- StateManagementEntity entry1 = new StateManagementEntity();
- StateManagementEntity entry2 = new StateManagementEntity();
-
- // Two entries with the same field values
-
- entry1.setAdminState("locked");
- entry1.setAvailStatus("null");
- entry1.setModifiedDate(new Date());
- entry1.setOpState("enabled");
- entry1.setResourceName("myResource");
- entry1.setStandbyStatus("coldstandby");
-
- // Clone the first entry
- entry2 = SerializationUtils.clone(entry1);
-
- HashMap<Object, Object> myEntries = new HashMap<>();
- HashMap<Object, Object> theirEntries = new HashMap<>();
-
- myEntries.put("pdp1", entry1);
- theirEntries.put("pdp1", entry2);
-
- Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
-
-
- // Assert that there are no mismatches returned
-
- assertTrue(result.isEmpty());
-
-
- /* ************************************
- * Now test with a mis-matched entry
- * ************************************/
-
-
-
- // Change a field on entry2
-
- entry2.setAdminState("unlocked");
-
- myEntries = new HashMap<>();
- theirEntries = new HashMap<>();
-
- myEntries.put("pdp1", entry1);
- theirEntries.put("pdp1", entry2);
-
- result = dbAudit.compareEntries(myEntries, theirEntries);
-
-
- //Assert that there was one mismatch
-
- assertEquals(1, result.size());
- logger.info("testStateManagementEntity: Exit");
- }
-
- void testForwardProgressEntity() throws Exception {
- logger.info("testForwardProgressEntity: Entering");
-
- dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
- DbAudit dbAudit = new DbAudit(dbDAO);
-
- ForwardProgressEntity entry1 = new ForwardProgressEntity();
- ForwardProgressEntity entry2 = new ForwardProgressEntity();
-
- // Two entries with the same field values
-
- entry1.setFpcCount(123L);
- entry1.setLastUpdated(new Date());
- entry1.setResourceName("myResource");
-
- // Clone the first entry
- entry2 = SerializationUtils.clone(entry1);
-
- HashMap<Object, Object> myEntries = new HashMap<Object, Object>();
- HashMap<Object, Object> theirEntries = new HashMap<Object, Object>();
-
- myEntries.put("pdp1", entry1);
- theirEntries.put("pdp1", entry2);
-
- Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
-
-
- // Assert that there are no mismatches returned
-
- assertTrue(result.isEmpty());
-
-
- /* ************************************
- * Now test with a mis-matched entry
- * ************************************/
-
- // Change a field on entry2
-
- entry2.setFpcCount(321L);
-
- myEntries = new HashMap<>();
- theirEntries = new HashMap<>();
-
- myEntries.put("pdp1", entry1);
- theirEntries.put("pdp1", entry2);
-
- result = dbAudit.compareEntries(myEntries, theirEntries);
-
-
- //Assert that there was one mismatch
-
- assertEquals(1, result.size());
- logger.info("testForwardProgressEntity: Exit");
- }
-
- void testResourceRegistrationEntity() throws Exception {
- logger.info("testResourceRegistrationEntity: Entering");
-
- dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
- DbAudit dbAudit = new DbAudit(dbDAO);
-
- ResourceRegistrationEntity entry1 = new ResourceRegistrationEntity();
- ResourceRegistrationEntity entry2 = new ResourceRegistrationEntity();
-
- // Two entries with the same field values
-
- entry1.setNodeType("pap");
- entry1.setLastUpdated(new Date());
- entry1.setResourceName("myResource");
- entry1.setResourceUrl("http://nowhere.com");
- entry1.setSite("site_1");
-
- // Clone the first entry
- entry2 = SerializationUtils.clone(entry1);
-
- HashMap<Object, Object> myEntries = new HashMap<>();
- HashMap<Object, Object> theirEntries = new HashMap<>();
-
- myEntries.put("pdp1", entry1);
- theirEntries.put("pdp1", entry2);
-
- Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
-
-
- // Assert that there are no mismatches returned
-
- assertTrue(result.isEmpty());
-
-
- /* ************************************
- * Now test with a mis-matched entry
- * ************************************/
-
- // Change a field on entry2
-
- entry2.setSite("site_1a");
-
- myEntries = new HashMap<>();
- theirEntries = new HashMap<>();
-
- myEntries.put("pdp1", entry1);
- theirEntries.put("pdp1", entry2);
-
- result = dbAudit.compareEntries(myEntries, theirEntries);
-
-
- //Assert that there was one mismatch
-
- assertEquals(1, result.size());
- logger.info("testResourceRegistrationEntity: Exit");
- }
+ private static Log logger = LogFactory.getLog(DbAuditCompareEntriesTest.class);
+ private DbDAO dbDAO;
+ private String persistenceUnit;
+ private Properties properties;
+ private String resourceName;
+ private String dbDriver;
+ private String dbUrl;
+ private String dbUser;
+ private String dbPwd;
+ private String siteName;
+ private String nodeType;
+ private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
+ private static final String DEFAULT_DB_USER = "sa";
+ private static final String DEFAULT_DB_PWD = "";
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+
+ properties = new Properties();
+ properties.put(IntegrityAuditProperties.DB_DRIVER, DbAuditCompareEntriesTest.DEFAULT_DB_DRIVER);
+ properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest");
+ properties.put(IntegrityAuditProperties.DB_USER, DbAuditCompareEntriesTest.DEFAULT_DB_USER);
+ properties.put(IntegrityAuditProperties.DB_PWD, DbAuditCompareEntriesTest.DEFAULT_DB_PWD);
+ properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA");
+ properties.put(IntegrityAuditProperties.NODE_TYPE, "pap");
+
+ dbDriver = DbAuditCompareEntriesTest.DEFAULT_DB_DRIVER;
+ dbUrl = "jdbc:h2:file:./sql/xacmlTest";
+ dbUser = DbAuditCompareEntriesTest.DEFAULT_DB_USER;
+ dbPwd = DbAuditCompareEntriesTest.DEFAULT_DB_PWD;
+ siteName = "SiteA";
+ nodeType = "pap";
+ persistenceUnit = "testPapPU";
+ resourceName = "siteA.pap1";
+
+ //Clean the iaTest DB table for IntegrityAuditEntity entries
+ cleanDb(persistenceUnit, properties);
+
+ logger.info("setUp: Exiting");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ logger.info("tearDown: Entering");
+ //nothing to do
+ logger.info("tearDown: Exiting");
+ }
+
+ public void cleanDb(String persistenceUnit, Properties properties){
+ logger.debug("cleanDb: enter");
+
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
+
+ EntityManager em = emf.createEntityManager();
+ // Start a transaction
+ EntityTransaction et = em.getTransaction();
+
+ et.begin();
+
+ // Clean up the DB
+ em.createQuery("Delete from IntegrityAuditEntity").executeUpdate();
+
+ // commit transaction
+ et.commit();
+ em.close();
+ logger.debug("cleanDb: exit");
+ }
+
+
+ /*
+ * Tests that a comparison between hashsets is successful if
+ * the entries match
+ */
+ @Test
+ public void runAllTests() throws Exception {
+ logger.info("runAllTests: Entering");
+
+
+ testIntegrityAuditEntity();
+ testBackupMonitorEntity();
+ testStateManagementEntity();
+ testForwardProgressEntity();
+ testResourceRegistrationEntity();
+
+ //clean up the IntegrityAuditEntity table
+ cleanDb(persistenceUnit, properties);
+
+ logger.info("runAllTests: Exit");
+ }
+
+
+ public void testIntegrityAuditEntity() throws Exception {
+ logger.info("testIntegrityAuditEntity: Entering");
+
+ dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
+ DbAudit dbAudit = new DbAudit(dbDAO);
+
+ String className = null;
+ //There is only one entry IntegrityAuditEntity, but we will check anyway
+ Set<String> classNameSet = dbDAO.getPersistenceClassNames();
+ for(String c : classNameSet){
+ if (c.equals("org.onap.policy.common.ia.jpa.IntegrityAuditEntity")){
+ className = c;
+ }
+ }
+ String resourceName1 = resourceName;
+ String resourceName2 = resourceName;
+
+ IntegrityAuditEntity entry1 = new IntegrityAuditEntity();
+ IntegrityAuditEntity entry2 = new IntegrityAuditEntity();
+ Date date = new Date();
+
+ /*
+ * Two entries with the same field values
+ */
+ entry1.setDesignated(false);
+ entry1.setJdbcDriver(dbDriver);
+ entry1.setJdbcPassword(dbPwd);
+ entry1.setJdbcUrl(dbUrl);
+ entry1.setJdbcUser(dbUser);
+ entry1.setLastUpdated(date);
+ entry1.setNodeType(nodeType);
+ entry1.setPersistenceUnit(persistenceUnit);
+ entry1.setResourceName(resourceName1);
+ entry1.setSite(siteName);
+
+ entry2 = SerializationUtils.clone(entry1);
+
+ dbAudit.writeAuditDebugLog(className, resourceName1, resourceName2, entry1, entry2);
+
+ HashMap<Object, Object> myEntries = new HashMap<>();
+ HashMap<Object, Object> theirEntries = new HashMap<>();
+
+ myEntries.put("pdp1", entry1);
+ theirEntries.put("pdp1", entry2);
+
+ Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
+
+ /*
+ * Assert that there are no mismatches returned
+ */
+ assertTrue(result.isEmpty());
+
+ /*
+ * ************************************
+ * Now test with a mis-matched entry
+ * ************************************
+ */
+
+ /*
+ * Change the entry2 to different designated value
+ */
+ entry2.setDesignated(true);
+
+ myEntries = new HashMap<>();
+ theirEntries = new HashMap<>();
+
+ myEntries.put("pdp1", entry1);
+ theirEntries.put("pdp1", entry2);
+
+ result = dbAudit.compareEntries(myEntries, theirEntries);
+
+ /*
+ * Assert that there was one mismatch
+ */
+ assertEquals(1, result.size());
+ logger.info("testIntegrityAuditEntity: Exit");
+ }
+
+ void testBackupMonitorEntity() throws Exception {
+ logger.info("testBackupMonitorEntity: Entering");
+
+ dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
+ DbAudit dbAudit = new DbAudit(dbDAO);
+
+ BackUpMonitorEntity entry1 = new BackUpMonitorEntity();
+ BackUpMonitorEntity entry2 = new BackUpMonitorEntity();
+
+ // Two entries with the same field values
+
+
+ entry1.setFlag("flag1");
+ entry1.setResourceNodeName("node1");
+ entry1.setResourceName("resourceName");
+ entry1.setTimeStamp(new Date());
+
+ // Clone the first entry
+ entry2 = SerializationUtils.clone(entry1);
+
+ HashMap<Object, Object> myEntries = new HashMap<>();
+ HashMap<Object, Object> theirEntries = new HashMap<>();
+
+ myEntries.put("pdp1", entry1);
+ theirEntries.put("pdp1", entry2);
+
+ Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
+
+
+ // Assert that there are no mismatches returned
+
+ assertTrue(result.isEmpty());
+
+
+ /* ************************************
+ * Now test with a mis-matched entry
+ * ************************************/
+
+
+
+ // Change a field on entry2
+
+ entry2.setFlag("flag2");
+
+ myEntries = new HashMap<>();
+ theirEntries = new HashMap<>();
+
+ myEntries.put("pdp1", entry1);
+ theirEntries.put("pdp1", entry2);
+
+ result = dbAudit.compareEntries(myEntries, theirEntries);
+
+
+ //Assert that there was one mismatch
+
+ assertEquals(1, result.size());
+ logger.info("testBackupMonitorEntity: Exit");
+ }
+
+ void testStateManagementEntity() throws Exception {
+ logger.info("testStateManagementEntity: Entering");
+
+ dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
+ DbAudit dbAudit = new DbAudit(dbDAO);
+
+ StateManagementEntity entry1 = new StateManagementEntity();
+ StateManagementEntity entry2 = new StateManagementEntity();
+
+ // Two entries with the same field values
+
+ entry1.setAdminState("locked");
+ entry1.setAvailStatus("null");
+ entry1.setModifiedDate(new Date());
+ entry1.setOpState("enabled");
+ entry1.setResourceName("myResource");
+ entry1.setStandbyStatus("coldstandby");
+
+ // Clone the first entry
+ entry2 = SerializationUtils.clone(entry1);
+
+ HashMap<Object, Object> myEntries = new HashMap<>();
+ HashMap<Object, Object> theirEntries = new HashMap<>();
+
+ myEntries.put("pdp1", entry1);
+ theirEntries.put("pdp1", entry2);
+
+ Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
+
+
+ // Assert that there are no mismatches returned
+
+ assertTrue(result.isEmpty());
+
+
+ /* ************************************
+ * Now test with a mis-matched entry
+ * ************************************/
+
+
+
+ // Change a field on entry2
+
+ entry2.setAdminState("unlocked");
+
+ myEntries = new HashMap<>();
+ theirEntries = new HashMap<>();
+
+ myEntries.put("pdp1", entry1);
+ theirEntries.put("pdp1", entry2);
+
+ result = dbAudit.compareEntries(myEntries, theirEntries);
+
+
+ //Assert that there was one mismatch
+
+ assertEquals(1, result.size());
+ logger.info("testStateManagementEntity: Exit");
+ }
+
+ void testForwardProgressEntity() throws Exception {
+ logger.info("testForwardProgressEntity: Entering");
+
+ dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
+ DbAudit dbAudit = new DbAudit(dbDAO);
+
+ ForwardProgressEntity entry1 = new ForwardProgressEntity();
+ ForwardProgressEntity entry2 = new ForwardProgressEntity();
+
+ // Two entries with the same field values
+
+ entry1.setFpcCount(123L);
+ entry1.setLastUpdated(new Date());
+ entry1.setResourceName("myResource");
+
+ // Clone the first entry
+ entry2 = SerializationUtils.clone(entry1);
+
+ HashMap<Object, Object> myEntries = new HashMap<Object, Object>();
+ HashMap<Object, Object> theirEntries = new HashMap<Object, Object>();
+
+ myEntries.put("pdp1", entry1);
+ theirEntries.put("pdp1", entry2);
+
+ Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
+
+
+ // Assert that there are no mismatches returned
+
+ assertTrue(result.isEmpty());
+
+
+ /* ************************************
+ * Now test with a mis-matched entry
+ * ************************************/
+
+ // Change a field on entry2
+
+ entry2.setFpcCount(321L);
+
+ myEntries = new HashMap<>();
+ theirEntries = new HashMap<>();
+
+ myEntries.put("pdp1", entry1);
+ theirEntries.put("pdp1", entry2);
+
+ result = dbAudit.compareEntries(myEntries, theirEntries);
+
+
+ //Assert that there was one mismatch
+
+ assertEquals(1, result.size());
+ logger.info("testForwardProgressEntity: Exit");
+ }
+
+ void testResourceRegistrationEntity() throws Exception {
+ logger.info("testResourceRegistrationEntity: Entering");
+
+ dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
+ DbAudit dbAudit = new DbAudit(dbDAO);
+
+ ResourceRegistrationEntity entry1 = new ResourceRegistrationEntity();
+ ResourceRegistrationEntity entry2 = new ResourceRegistrationEntity();
+
+ // Two entries with the same field values
+
+ entry1.setNodeType("pap");
+ entry1.setLastUpdated(new Date());
+ entry1.setResourceName("myResource");
+ entry1.setResourceUrl("http://nowhere.com");
+ entry1.setSite("site_1");
+
+ // Clone the first entry
+ entry2 = SerializationUtils.clone(entry1);
+
+ HashMap<Object, Object> myEntries = new HashMap<>();
+ HashMap<Object, Object> theirEntries = new HashMap<>();
+
+ myEntries.put("pdp1", entry1);
+ theirEntries.put("pdp1", entry2);
+
+ Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
+
+
+ // Assert that there are no mismatches returned
+
+ assertTrue(result.isEmpty());
+
+
+ /* ************************************
+ * Now test with a mis-matched entry
+ * ************************************/
+
+ // Change a field on entry2
+
+ entry2.setSite("site_1a");
+
+ myEntries = new HashMap<>();
+ theirEntries = new HashMap<>();
+
+ myEntries.put("pdp1", entry1);
+ theirEntries.put("pdp1", entry2);
+
+ result = dbAudit.compareEntries(myEntries, theirEntries);
+
+
+ //Assert that there was one mismatch
+
+ assertEquals(1, result.size());
+ logger.info("testResourceRegistrationEntity: Exit");
+ }
} \ No newline at end of file
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/UpdateOthersPAPSTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/UpdateOthersPAPSTest.java
index f9ed0ac70..5a8e20b26 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/UpdateOthersPAPSTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/UpdateOthersPAPSTest.java
@@ -51,66 +51,66 @@ import org.springframework.mock.web.MockHttpServletResponse;
@RunWith(PowerMockRunner.class)
public class UpdateOthersPAPSTest {
- private static Logger logger = FlexLogger.getLogger(UpdateOthersPAPSTest.class);
- private static CommonClassDao commonClassDao;
- private HttpServletRequest request;
- private MockHttpServletResponse response;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
+ private static Logger logger = FlexLogger.getLogger(UpdateOthersPAPSTest.class);
+ private static CommonClassDao commonClassDao;
+ private HttpServletRequest request;
+ private MockHttpServletResponse response;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
commonClassDao = mock(CommonClassDao.class);
request = mock(HttpServletRequest.class);
- response = new MockHttpServletResponse();
- List<Object> data = new ArrayList<>();
- PolicyDBDaoEntity entity = new PolicyDBDaoEntity();
- entity.setPolicyDBDaoUrl("http://localhost:8070/pap");
- entity.setUsername("test");
- entity.setPassword("test");
-
- PolicyDBDaoEntity entity1 = new PolicyDBDaoEntity();
- entity1.setPolicyDBDaoUrl("http://localhost:8071/pap");
- entity1.setUsername("test");
- entity1.setPassword("test");
-
- data.add(entity);
- data.add(entity1);
- System.setProperty("xacml.rest.pap.url","http://localhost:8070/pap");
- when(commonClassDao.getData(PolicyDBDaoEntity.class)).thenReturn(data);
- }
-
- @Test
- public void testNotifyOthersPAPsToUpdateConfigurations(){
- UpdateOthersPAPS updateOtherPaps = new UpdateOthersPAPS();
- UpdateOthersPAPS.setCommonClassDao(commonClassDao);
- when(request.getParameter("action")).thenReturn("rename");
- when(request.getParameter("newPolicyName")).thenReturn("com.Config_newTest.1.json");
- when(request.getParameter("oldPolicyName")).thenReturn("com.Config_Test.1.json");
- updateOtherPaps.notifyOthersPAPsToUpdateConfigurations(request, response);
- try {
- JSONObject responseString = new JSONObject(response.getContentAsString());
- assertTrue(responseString.get("data").toString().contains("http://localhost:8071/pap"));
- } catch (Exception e) {
- fail();
- }
- }
-
- @PrepareForTest({Policy.class})
- @Test
- public void testUpdateConfiguration() throws Exception{
- UpdateOthersPAPS updateOtherPaps = new UpdateOthersPAPS();
- UpdateObjectData data = new UpdateObjectData();
- PowerMockito.mockStatic(Policy.class);
- data.setNewPolicyName("com.Config_newTest.1.json");
- data.setOldPolicyName("com.Config_Test.1.json");
- data.setAction("rename");
- when(Policy.getConfigHome()).thenReturn("test");
- when(Policy.getActionHome()).thenReturn("test");
- File mockedFile = Mockito.mock(File.class);
- Mockito.when(mockedFile.exists()).thenReturn(true);
- PowerMockito.whenNew(File.class).withParameterTypes(String.class).withArguments(Matchers.anyString()).thenReturn(mockedFile);
- updateOtherPaps.updateConfiguration(data, response);
- assertTrue(response.getStatus() == 200);
- }
+ response = new MockHttpServletResponse();
+ List<Object> data = new ArrayList<>();
+ PolicyDBDaoEntity entity = new PolicyDBDaoEntity();
+ entity.setPolicyDBDaoUrl("http://localhost:8070/pap");
+ entity.setUsername("test");
+ entity.setPassword("test");
+
+ PolicyDBDaoEntity entity1 = new PolicyDBDaoEntity();
+ entity1.setPolicyDBDaoUrl("http://localhost:8071/pap");
+ entity1.setUsername("test");
+ entity1.setPassword("test");
+
+ data.add(entity);
+ data.add(entity1);
+ System.setProperty("xacml.rest.pap.url","http://localhost:8070/pap");
+ when(commonClassDao.getData(PolicyDBDaoEntity.class)).thenReturn(data);
+ }
+
+ @Test
+ public void testNotifyOthersPAPsToUpdateConfigurations(){
+ UpdateOthersPAPS updateOtherPaps = new UpdateOthersPAPS();
+ UpdateOthersPAPS.setCommonClassDao(commonClassDao);
+ when(request.getParameter("action")).thenReturn("rename");
+ when(request.getParameter("newPolicyName")).thenReturn("com.Config_newTest.1.json");
+ when(request.getParameter("oldPolicyName")).thenReturn("com.Config_Test.1.json");
+ updateOtherPaps.notifyOthersPAPsToUpdateConfigurations(request, response);
+ try {
+ JSONObject responseString = new JSONObject(response.getContentAsString());
+ assertTrue(responseString.get("data").toString().contains("http://localhost:8071/pap"));
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ @PrepareForTest({Policy.class})
+ @Test
+ public void testUpdateConfiguration() throws Exception{
+ UpdateOthersPAPS updateOtherPaps = new UpdateOthersPAPS();
+ UpdateObjectData data = new UpdateObjectData();
+ PowerMockito.mockStatic(Policy.class);
+ data.setNewPolicyName("com.Config_newTest.1.json");
+ data.setOldPolicyName("com.Config_Test.1.json");
+ data.setAction("rename");
+ when(Policy.getConfigHome()).thenReturn("test");
+ when(Policy.getActionHome()).thenReturn("test");
+ File mockedFile = Mockito.mock(File.class);
+ Mockito.when(mockedFile.exists()).thenReturn(true);
+ PowerMockito.whenNew(File.class).withParameterTypes(String.class).withArguments(Matchers.anyString()).thenReturn(mockedFile);
+ updateOtherPaps.updateConfiguration(data, response);
+ assertTrue(response.getStatus() == 200);
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
index 5208ad7a7..717266264 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java
@@ -81,7 +81,7 @@ import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import com.mockrunner.mock.web.MockServletInputStream;
public class XACMLPAPTest {
- private static final Log logger = LogFactory.getLog(XACMLPAPTest.class);
+ private static final Log logger = LogFactory.getLog(XACMLPAPTest.class);
private static final String ENVIRONMENT_HEADER = "Environment";
private List<String> headers = new ArrayList<>();
@@ -93,47 +93,47 @@ public class XACMLPAPTest {
private SessionFactory sessionFactory;
private CommonClassDao commonClassDao;
- private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
- private static final String DEFAULT_DB_USER = "sa";
- private static final String DEFAULT_DB_PWD = "";
+ private static final String DEFAULT_DB_DRIVER = "org.h2.Driver";
+ private static final String DEFAULT_DB_USER = "sa";
+ private static final String DEFAULT_DB_PWD = "";
- @Before
- public void setUpDB() throws Exception {
- logger.info("setUpDB: Entering");
+ @Before
+ public void setUpDB() throws Exception {
+ logger.info("setUpDB: Entering");
- Properties properties = new Properties();
- properties.put(IntegrityAuditProperties.DB_DRIVER, XACMLPAPTest.DEFAULT_DB_DRIVER);
- properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest");
- properties.put(IntegrityAuditProperties.DB_USER, XACMLPAPTest.DEFAULT_DB_USER);
- properties.put(IntegrityAuditProperties.DB_PWD, XACMLPAPTest.DEFAULT_DB_PWD);
- properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA");
- properties.put(IntegrityAuditProperties.NODE_TYPE, "pap");
+ Properties properties = new Properties();
+ properties.put(IntegrityAuditProperties.DB_DRIVER, XACMLPAPTest.DEFAULT_DB_DRIVER);
+ properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest");
+ properties.put(IntegrityAuditProperties.DB_USER, XACMLPAPTest.DEFAULT_DB_USER);
+ properties.put(IntegrityAuditProperties.DB_PWD, XACMLPAPTest.DEFAULT_DB_PWD);
+ properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA");
+ properties.put(IntegrityAuditProperties.NODE_TYPE, "pap");
- //Clean the iaTest DB table for IntegrityAuditEntity entries
- cleanDb("testPapPU", properties);
+ //Clean the iaTest DB table for IntegrityAuditEntity entries
+ cleanDb("testPapPU", properties);
- logger.info("setUpDB: Exiting");
- }
+ logger.info("setUpDB: Exiting");
+ }
- public void cleanDb(String persistenceUnit, Properties properties){
- logger.debug("cleanDb: enter");
+ public void cleanDb(String persistenceUnit, Properties properties){
+ logger.debug("cleanDb: enter");
- EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties);
- EntityManager em = emf.createEntityManager();
- // Start a transaction
- EntityTransaction et = em.getTransaction();
+ EntityManager em = emf.createEntityManager();
+ // Start a transaction
+ EntityTransaction et = em.getTransaction();
- et.begin();
+ et.begin();
- // Clean up the DB
- em.createQuery("Delete from IntegrityAuditEntity").executeUpdate();
+ // Clean up the DB
+ em.createQuery("Delete from IntegrityAuditEntity").executeUpdate();
- // commit transaction
- et.commit();
- em.close();
- logger.debug("cleanDb: exit");
- }
+ // commit transaction
+ et.commit();
+ em.close();
+ logger.debug("cleanDb: exit");
+ }
@Before
public void setUp() throws ServletException {
@@ -584,166 +584,166 @@ public class XACMLPAPTest {
@Test
public void testCommonCreateDictionary() throws IOException, SQLException, ServletException {
- new DictionaryController(commonClassDao);
- new ActionPolicyDictionaryController(commonClassDao);
- new SafePolicyController(commonClassDao);
- new DescriptiveDictionaryController(commonClassDao);
- List<Object> object = new ArrayList<>();
+ new DictionaryController(commonClassDao);
+ new ActionPolicyDictionaryController(commonClassDao);
+ new SafePolicyController(commonClassDao);
+ new DescriptiveDictionaryController(commonClassDao);
+ List<Object> object = new ArrayList<>();
object.add(new Category());
when(commonClassDao.getDataById(Category.class, "shortName", "resource")).thenReturn(object);
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- String json = "{\"dictionaryFields\": {\"onapName\": \"testMMRestAPI1\",\"description\": \"testing update response message\"}}";
- dictionaryTestSetup(false, "OnapName", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\": {\"xacmlId\": \"testMMRestAPI1\",\"datatypeBean\": {\"shortName\": \"string\"}, \"description\": \"testing update\",\"priority\": \"High\",\"userDataTypeValues\": [{\"attributeValues\": \"testAttr\"}, {\"attributeValues\": \"testAttr2\"}, {\"attributeValues\": \"testAttr3\"}]}}";
- dictionaryTestSetup(false, "Attribute", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"attributeName\":\"TestMMrestAPI1\",\"type\":\"REST\",\"url\":\"testsomeurl.com\",\"method\":\"GET\",\"description\":\"test create\",\"body\":\"Testing Create\",\"headers\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\",\"number\":\"test\"}]}}";
- dictionaryTestSetup(false, "Action", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"scopeName\":\"testMMRestAPI1\",\"description\":\"test\",\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\",\"number\":\"test\"}]}}";
- dictionaryTestSetup(false, "DescriptiveScope", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"riskName\":\"testMMrestAPI1\",\"description\":\"test\"}}";
- dictionaryTestSetup(false, "RiskType", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"message\":\"test\",\"riskType\":\"testMMrestAPI1\"}}";
- dictionaryTestSetup(false, "SafePolicyWarning", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ String json = "{\"dictionaryFields\": {\"onapName\": \"testMMRestAPI1\",\"description\": \"testing update response message\"}}";
+ dictionaryTestSetup(false, "OnapName", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\": {\"xacmlId\": \"testMMRestAPI1\",\"datatypeBean\": {\"shortName\": \"string\"}, \"description\": \"testing update\",\"priority\": \"High\",\"userDataTypeValues\": [{\"attributeValues\": \"testAttr\"}, {\"attributeValues\": \"testAttr2\"}, {\"attributeValues\": \"testAttr3\"}]}}";
+ dictionaryTestSetup(false, "Attribute", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"attributeName\":\"TestMMrestAPI1\",\"type\":\"REST\",\"url\":\"testsomeurl.com\",\"method\":\"GET\",\"description\":\"test create\",\"body\":\"Testing Create\",\"headers\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\",\"number\":\"test\"}]}}";
+ dictionaryTestSetup(false, "Action", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"scopeName\":\"testMMRestAPI1\",\"description\":\"test\",\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\",\"number\":\"test\"}]}}";
+ dictionaryTestSetup(false, "DescriptiveScope", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"riskName\":\"testMMrestAPI1\",\"description\":\"test\"}}";
+ dictionaryTestSetup(false, "RiskType", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"message\":\"test\",\"riskType\":\"testMMrestAPI1\"}}";
+ dictionaryTestSetup(false, "SafePolicyWarning", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
}
@Test
public void testDecisionCreateDictionary() throws IOException, SQLException, ServletException {
- new DecisionPolicyDictionaryController(commonClassDao);
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- String json = "{\"dictionaryFields\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"test\",\"priority\":\"High\"}}";
- dictionaryTestSetup(false, "Settings", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"bbid\":\"BB1\",\"workstep\":\"1\",\"treatments\":\"Manual Handling,Abort,Retry\"}}";
- dictionaryTestSetup(false, "RainyDayTreatments", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ new DecisionPolicyDictionaryController(commonClassDao);
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ String json = "{\"dictionaryFields\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"test\",\"priority\":\"High\"}}";
+ dictionaryTestSetup(false, "Settings", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"bbid\":\"BB1\",\"workstep\":\"1\",\"treatments\":\"Manual Handling,Abort,Retry\"}}";
+ dictionaryTestSetup(false, "RainyDayTreatments", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
}
@Test
public void testMSCreateDictionary() throws IOException, SQLException, ServletException {
- new MicroServiceDictionaryController(commonClassDao);
- new PolicyScopeDictionaryController(commonClassDao);
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- String json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"descriptionValue\":\"test\"}}";
- dictionaryTestSetup(false, "MicroServiceLocation", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"descriptionValue\":\"test\"}}";
- dictionaryTestSetup(false, "MicroServiceConfigName", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"description\":\"test\"}}";
- dictionaryTestSetup(false, "DCAEUUID", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
- dictionaryTestSetup(false, "PolicyScopeService", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
- dictionaryTestSetup(false, "PolicyScopeResource", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
- dictionaryTestSetup(false, "PolicyScopeType", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
- dictionaryTestSetup(false, "PolicyScopeClosedLoop", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
-
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
- json = "{\"dictionaryFields\":{\"groupName\":\"testMMrestAPI1\",\"description\":\"testing\"},\"groupPolicyScopeListData1\":{\"resource\":\"ANY\",\"type\":\"ANY\",\"service\":\"ANY\",\"closedloop\":\"ANY\"}}";
- dictionaryTestSetup(false, "GroupPolicyScopeList", json);
- // send Request to PAP
- pap.service(httpServletRequest, httpServletResponse);
- // Verify
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+ new MicroServiceDictionaryController(commonClassDao);
+ new PolicyScopeDictionaryController(commonClassDao);
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ String json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"descriptionValue\":\"test\"}}";
+ dictionaryTestSetup(false, "MicroServiceLocation", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"descriptionValue\":\"test\"}}";
+ dictionaryTestSetup(false, "MicroServiceConfigName", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"description\":\"test\"}}";
+ dictionaryTestSetup(false, "DCAEUUID", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
+ dictionaryTestSetup(false, "PolicyScopeService", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
+ dictionaryTestSetup(false, "PolicyScopeResource", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
+ dictionaryTestSetup(false, "PolicyScopeType", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"name\":\"testApiANY\",\"descriptionValue\":\"default test\"}}";
+ dictionaryTestSetup(false, "PolicyScopeClosedLoop", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
+
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = Mockito.mock(MockHttpServletResponse.class);
+ json = "{\"dictionaryFields\":{\"groupName\":\"testMMrestAPI1\",\"description\":\"testing\"},\"groupPolicyScopeListData1\":{\"resource\":\"ANY\",\"type\":\"ANY\",\"service\":\"ANY\",\"closedloop\":\"ANY\"}}";
+ dictionaryTestSetup(false, "GroupPolicyScopeList", json);
+ // send Request to PAP
+ pap.service(httpServletRequest, httpServletResponse);
+ // Verify
+ Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
}
private void dictionaryTestSetup(Boolean updateFlag, String dictionaryType, String json) throws IOException, SQLException {
@@ -790,23 +790,23 @@ public class XACMLPAPTest {
@Test
public void getDictionary() throws ServletException, IOException{
- String[] dictionarys = new String[]{"Attribute", "OnapName", "Action", "BRMSParamTemplate","VSCLAction"
- ,"VNFType","PEPOptions","Varbind","Service","Site", "Settings", "RainyDayTreatments",
- "DescriptiveScope", "ActionList", "ProtocolList", "Zone", "SecurityZone",
- "PrefixList", "AddressGroup", "ServiceGroup", "ServiceList", "TermList",
- "MicroServiceLocation", "MicroServiceConfigName", "DCAEUUID", "MicroServiceModels",
- "PolicyScopeService", "PolicyScopeResource", "PolicyScopeType", "PolicyScopeClosedLoop",
- "GroupPolicyScopeList", "RiskType", "SafePolicyWarning", "MicroServiceDictionary"};
- for(String dictionary : dictionarys){
- httpServletRequest = Mockito.mock(HttpServletRequest.class);
- httpServletResponse = new MockHttpServletResponse();
- Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
- Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");
- Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
- Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionary);
- pap.service(httpServletRequest, httpServletResponse);
- assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
- }
+ String[] dictionarys = new String[]{"Attribute", "OnapName", "Action", "BRMSParamTemplate","VSCLAction"
+ ,"VNFType","PEPOptions","Varbind","Service","Site", "Settings", "RainyDayTreatments",
+ "DescriptiveScope", "ActionList", "ProtocolList", "Zone", "SecurityZone",
+ "PrefixList", "AddressGroup", "ServiceGroup", "ServiceList", "TermList",
+ "MicroServiceLocation", "MicroServiceConfigName", "DCAEUUID", "MicroServiceModels",
+ "PolicyScopeService", "PolicyScopeResource", "PolicyScopeType", "PolicyScopeClosedLoop",
+ "GroupPolicyScopeList", "RiskType", "SafePolicyWarning", "MicroServiceDictionary"};
+ for(String dictionary : dictionarys){
+ httpServletRequest = Mockito.mock(HttpServletRequest.class);
+ httpServletResponse = new MockHttpServletResponse();
+ Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL");
+ Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");
+ Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api");
+ Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionary);
+ pap.service(httpServletRequest, httpServletResponse);
+ assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
+ }
}
@Test
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/PAPRestConfigTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/PAPRestConfigTest.java
index b57c187c7..dfadf8e81 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/PAPRestConfigTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/PAPRestConfigTest.java
@@ -28,46 +28,46 @@ import org.onap.policy.pap.xacml.rest.PAPRestConfig;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
public class PAPRestConfigTest {
- @Test
- public void testSetAndGet() {
- String testVal = "testVal";
-
- PAPRestConfig.setDbDriver(testVal);
- assertEquals(PAPRestConfig.getDbDriver(), testVal);
- PAPRestConfig.setDbUrl(testVal);
- assertEquals(PAPRestConfig.getDbUrl(), testVal);
- PAPRestConfig.setDbUserName(testVal);
- assertEquals(PAPRestConfig.getDbUserName(), testVal);
- PAPRestConfig.setDbPassword(testVal);
- assertEquals(PAPRestConfig.getDbPassword(), testVal);
- }
-
- @Test
- public void testInit() {
- String driver = "org.mariadb.jdbc.Driver";
- String url = "jdbc:mariadb://localhost:3306/onap_sdk?connectTimeout=30000&socketTimeout=60000&log=true&sessionVariables=max_statement_time=30";
- String user = "policy_user";
- String password = "policy_user";
-
- PAPRestConfig config = new PAPRestConfig();
- config.init();
-
- assertEquals(PAPRestConfig.getDbDriver(), driver);
- assertEquals(PAPRestConfig.getDbUrl(), url);
- assertEquals(PAPRestConfig.getDbUserName(), user);
- assertEquals(PAPRestConfig.getDbPassword(), password);
-
- // Test hibernate
- BasicDataSource source = (BasicDataSource)config.getDataSource();
- assertEquals(source.getDriverClassName(), driver);
- assertEquals(source.getUrl(), url);
- assertEquals(source.getUsername(), user);
- assertEquals(source.getPassword(), password);
-
- SessionFactory factory = config.getSessionFactory(source);
- assertEquals(factory.isClosed(), false);
-
- HibernateTransactionManager manager = config.getTransactionManager(factory);
- assertEquals(manager.getSessionFactory(), factory);
- }
+ @Test
+ public void testSetAndGet() {
+ String testVal = "testVal";
+
+ PAPRestConfig.setDbDriver(testVal);
+ assertEquals(PAPRestConfig.getDbDriver(), testVal);
+ PAPRestConfig.setDbUrl(testVal);
+ assertEquals(PAPRestConfig.getDbUrl(), testVal);
+ PAPRestConfig.setDbUserName(testVal);
+ assertEquals(PAPRestConfig.getDbUserName(), testVal);
+ PAPRestConfig.setDbPassword(testVal);
+ assertEquals(PAPRestConfig.getDbPassword(), testVal);
+ }
+
+ @Test
+ public void testInit() {
+ String driver = "org.mariadb.jdbc.Driver";
+ String url = "jdbc:mariadb://localhost:3306/onap_sdk?connectTimeout=30000&socketTimeout=60000&log=true&sessionVariables=max_statement_time=30";
+ String user = "policy_user";
+ String password = "policy_user";
+
+ PAPRestConfig config = new PAPRestConfig();
+ config.init();
+
+ assertEquals(PAPRestConfig.getDbDriver(), driver);
+ assertEquals(PAPRestConfig.getDbUrl(), url);
+ assertEquals(PAPRestConfig.getDbUserName(), user);
+ assertEquals(PAPRestConfig.getDbPassword(), password);
+
+ // Test hibernate
+ BasicDataSource source = (BasicDataSource)config.getDataSource();
+ assertEquals(source.getDriverClassName(), driver);
+ assertEquals(source.getUrl(), url);
+ assertEquals(source.getUsername(), user);
+ assertEquals(source.getPassword(), password);
+
+ SessionFactory factory = config.getSessionFactory(source);
+ assertEquals(factory.isClosed(), false);
+
+ HibernateTransactionManager manager = config.getTransactionManager(factory);
+ assertEquals(manager.getSessionFactory(), factory);
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java
index 15bdf8962..32d7dedd3 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/WebConfigTest.java
@@ -27,11 +27,11 @@ import org.junit.Test;
import org.mockito.Mockito;
public class WebConfigTest {
- @Test(expected=NullPointerException.class)
- public void testNegativeStartup() throws ServletException {
- WebConfig init = new WebConfig();
- ServletContext container = Mockito.mock(ServletContext.class);
- init.onStartup(container);
- fail("Expecting an exception.");
- }
+ @Test(expected=NullPointerException.class)
+ public void testNegativeStartup() throws ServletException {
+ WebConfig init = new WebConfig();
+ ServletContext container = Mockito.mock(ServletContext.class);
+ init.onStartup(container);
+ fail("Expecting an exception.");
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/XACMLPapServletTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/XACMLPapServletTest.java
index 3630889b0..36d40278b 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/XACMLPapServletTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/XACMLPapServletTest.java
@@ -26,44 +26,44 @@ import org.junit.Test;
import org.onap.policy.pap.xacml.rest.XACMLPapServlet;
public class XACMLPapServletTest {
- @Test
- public void testSetAndGet() {
- String systemKey = "xacml.properties";
- String testVal = "testVal";
- XACMLPapServlet servlet = new XACMLPapServlet();
-
- // Set the system property temporarily
- String oldProperty = System.getProperty(systemKey);
- System.setProperty(systemKey, "xacml.pap.properties");
-
- assertNotNull(XACMLPapServlet.getConfigHome());
- assertNotNull(XACMLPapServlet.getActionHome());
- assertEquals(XACMLPapServlet.getPersistenceUnit(), "XACML-PAP-REST");
+ @Test
+ public void testSetAndGet() {
+ String systemKey = "xacml.properties";
+ String testVal = "testVal";
+ XACMLPapServlet servlet = new XACMLPapServlet();
- //assertNull(XACMLPapServlet.getEmf());
- //assertNull(XACMLPapServlet.getPDPFile());
- //assertNull(XACMLPapServlet.getPAPEngine());
- //assertNull(servlet.getIa());
-
- XACMLPapServlet.setPapDbDriver(testVal);
- assertEquals(XACMLPapServlet.getPapDbDriver(), testVal);
- XACMLPapServlet.setPapDbUrl(testVal);
- assertEquals(XACMLPapServlet.getPapDbUrl(), testVal);
- XACMLPapServlet.setPapDbUser(testVal);
- assertEquals(XACMLPapServlet.getPapDbUser(), testVal);
- XACMLPapServlet.setPapDbPassword(testVal);
- assertEquals(XACMLPapServlet.getPapDbPassword(), testVal);
- XACMLPapServlet.setMsOnapName(testVal);
- assertEquals(XACMLPapServlet.getMsOnapName(), testVal);
- XACMLPapServlet.setMsPolicyName(testVal);
- assertEquals(XACMLPapServlet.getMsPolicyName(), testVal);
-
- // Restore the original system property
- if (oldProperty != null) {
- System.setProperty(systemKey, oldProperty);
- }
- else {
- System.clearProperty(systemKey);
- }
- }
+ // Set the system property temporarily
+ String oldProperty = System.getProperty(systemKey);
+ System.setProperty(systemKey, "xacml.pap.properties");
+
+ assertNotNull(XACMLPapServlet.getConfigHome());
+ assertNotNull(XACMLPapServlet.getActionHome());
+ assertEquals(XACMLPapServlet.getPersistenceUnit(), "XACML-PAP-REST");
+
+ //assertNull(XACMLPapServlet.getEmf());
+ //assertNull(XACMLPapServlet.getPDPFile());
+ //assertNull(XACMLPapServlet.getPAPEngine());
+ //assertNull(servlet.getIa());
+
+ XACMLPapServlet.setPapDbDriver(testVal);
+ assertEquals(XACMLPapServlet.getPapDbDriver(), testVal);
+ XACMLPapServlet.setPapDbUrl(testVal);
+ assertEquals(XACMLPapServlet.getPapDbUrl(), testVal);
+ XACMLPapServlet.setPapDbUser(testVal);
+ assertEquals(XACMLPapServlet.getPapDbUser(), testVal);
+ XACMLPapServlet.setPapDbPassword(testVal);
+ assertEquals(XACMLPapServlet.getPapDbPassword(), testVal);
+ XACMLPapServlet.setMsOnapName(testVal);
+ assertEquals(XACMLPapServlet.getMsOnapName(), testVal);
+ XACMLPapServlet.setMsPolicyName(testVal);
+ assertEquals(XACMLPapServlet.getMsPolicyName(), testVal);
+
+ // Restore the original system property
+ if (oldProperty != null) {
+ System.setProperty(systemKey, oldProperty);
+ }
+ else {
+ System.clearProperty(systemKey);
+ }
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/SearchDataTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/SearchDataTest.java
index 839af2fdc..841ba28fc 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/SearchDataTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/SearchDataTest.java
@@ -24,33 +24,33 @@ import static org.junit.Assert.*;
import org.junit.Test;
public class SearchDataTest {
-
-
- @Test
- public void testSearchData(){
- String data = "Test";
- SearchData searchData = new SearchData();
- searchData.setQuery(data);
- searchData.setPolicyType(data);
- searchData.setOnapName(data);
- searchData.setDescriptiveScope(data);
- searchData.setClosedLooppolicyType(data);
- searchData.setD2Service(data);
- searchData.setVnfType(data);
- searchData.setPolicyStatus(data);
- searchData.setVproAction(data);
- searchData.setServiceType(data);
- searchData.setBindTextSearch(data);
- assertEquals(data, searchData.getQuery());
- assertEquals(data, searchData.getPolicyType());
- assertEquals(data, searchData.getDescriptiveScope());
- assertEquals(data, searchData.getClosedLooppolicyType());
- assertEquals(data, searchData.getOnapName());
- assertEquals(data, searchData.getD2Service());
- assertEquals(data, searchData.getVnfType());
- assertEquals(data, searchData.getPolicyStatus());
- assertEquals(data, searchData.getVproAction());
- assertEquals(data, searchData.getServiceType());
- assertEquals(data, searchData.getBindTextSearch());
- }
+
+
+ @Test
+ public void testSearchData(){
+ String data = "Test";
+ SearchData searchData = new SearchData();
+ searchData.setQuery(data);
+ searchData.setPolicyType(data);
+ searchData.setOnapName(data);
+ searchData.setDescriptiveScope(data);
+ searchData.setClosedLooppolicyType(data);
+ searchData.setD2Service(data);
+ searchData.setVnfType(data);
+ searchData.setPolicyStatus(data);
+ searchData.setVproAction(data);
+ searchData.setServiceType(data);
+ searchData.setBindTextSearch(data);
+ assertEquals(data, searchData.getQuery());
+ assertEquals(data, searchData.getPolicyType());
+ assertEquals(data, searchData.getDescriptiveScope());
+ assertEquals(data, searchData.getClosedLooppolicyType());
+ assertEquals(data, searchData.getOnapName());
+ assertEquals(data, searchData.getD2Service());
+ assertEquals(data, searchData.getVnfType());
+ assertEquals(data, searchData.getPolicyStatus());
+ assertEquals(data, searchData.getVproAction());
+ assertEquals(data, searchData.getServiceType());
+ assertEquals(data, searchData.getBindTextSearch());
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/UpdateObjectDataTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/UpdateObjectDataTest.java
index 2c1bc1c53..094994e41 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/UpdateObjectDataTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/adapters/UpdateObjectDataTest.java
@@ -24,16 +24,16 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class UpdateObjectDataTest {
-
- @Test
- public void testClosedLoopFaultTrapDatas(){
- UpdateObjectData updateObject = new UpdateObjectData();
- updateObject.setAction("Rename");
- assertTrue("Rename".equals(updateObject.getAction()));
- updateObject.setNewPolicyName("com.Config_test1.1.json");
- assertTrue("com.Config_test1.1.json".equals(updateObject.getNewPolicyName()));
- updateObject.setOldPolicyName("com.Config_test.1.json");
- assertTrue("com.Config_test.1.json".equals(updateObject.getOldPolicyName()));
- }
-
+
+ @Test
+ public void testClosedLoopFaultTrapDatas(){
+ UpdateObjectData updateObject = new UpdateObjectData();
+ updateObject.setAction("Rename");
+ assertTrue("Rename".equals(updateObject.getAction()));
+ updateObject.setNewPolicyName("com.Config_test1.1.json");
+ assertTrue("com.Config_test1.1.json".equals(updateObject.getNewPolicyName()));
+ updateObject.setOldPolicyName("com.Config_test.1.json");
+ assertTrue("com.Config_test.1.json".equals(updateObject.getOldPolicyName()));
+ }
+
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ActionPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ActionPolicyTest.java
index cb09becf3..a04859b27 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ActionPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ActionPolicyTest.java
@@ -40,102 +40,102 @@ import com.att.research.xacml.util.XACMLProperties;
public class ActionPolicyTest {
-
- private static Logger logger = FlexLogger.getLogger(ActionPolicyTest.class);
- PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
- List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
- List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
- List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
- List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
- Map<String, String> attributeMap = new HashMap<>();
- ActionPolicy component = null;
-
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
-
- dynamicRuleAlgorithmLabels.add("test");
- dynamicRuleAlgorithmField1.add("testField1");
- dynamicRuleAlgorithmCombo.add("testCombo");
- dynamicRuleAlgorithmField2.add("testField2");
-
- policyAdapter.setPolicyName("Test.Action_junitTest");
- policyAdapter.setPolicyDescription("test");
- policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
- policyAdapter.setPolicyType("Action");
- policyAdapter.setEditPolicy(false);
- policyAdapter.setDomainDir("Test");
- policyAdapter.setNewFileName("Test.Action_junitTest.1.xml");
- policyAdapter.setHighestVersion(1);
- policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
-
- policyAdapter.setActionDictHeader("");
- policyAdapter.setActionDictType("REST");
- policyAdapter.setActionDictUrl("onap.org");
- policyAdapter.setActionDictMethod("GET");
- policyAdapter.setActionAttribute("test");
- policyAdapter.setActionBody("test");
-
- policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
- policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
- policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
- policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
-
- attributeMap.put("java", "test");
- policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
-
- component = new ActionPolicy(policyAdapter, null);
+
+ private static Logger logger = FlexLogger.getLogger(ActionPolicyTest.class);
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
+ Map<String, String> attributeMap = new HashMap<>();
+ ActionPolicy component = null;
+
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
+
+ dynamicRuleAlgorithmLabels.add("test");
+ dynamicRuleAlgorithmField1.add("testField1");
+ dynamicRuleAlgorithmCombo.add("testCombo");
+ dynamicRuleAlgorithmField2.add("testField2");
+
+ policyAdapter.setPolicyName("Test.Action_junitTest");
+ policyAdapter.setPolicyDescription("test");
+ policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
+ policyAdapter.setPolicyType("Action");
+ policyAdapter.setEditPolicy(false);
+ policyAdapter.setDomainDir("Test");
+ policyAdapter.setNewFileName("Test.Action_junitTest.1.xml");
+ policyAdapter.setHighestVersion(1);
+ policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
+
+ policyAdapter.setActionDictHeader("");
+ policyAdapter.setActionDictType("REST");
+ policyAdapter.setActionDictUrl("onap.org");
+ policyAdapter.setActionDictMethod("GET");
+ policyAdapter.setActionAttribute("test");
+ policyAdapter.setActionBody("test");
+
+ policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
+ policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
+ policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
+ policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
+
+ attributeMap.put("java", "test");
+ policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
+
+ component = new ActionPolicy(policyAdapter, null);
logger.info("setUp: exit");
- }
+ }
- /**
- * @throws java.lang.Exception
- */
- @After
- public void tearDown() throws Exception {
- }
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
/* *//**
- * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.ActionPolicy#savePolicies()}.
- */
- @Test
- public void testSavePolicies() {
+ * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.ActionPolicy#savePolicies()}.
+ */
+ @Test
+ public void testSavePolicies() {
ActionPolicy mockAction = Mockito.mock(component.getClass());
-
+
Map<String, String> successMap = new HashMap<>();
- successMap.put("success", "success");
+ successMap.put("success", "success");
try {
- when(mockAction.savePolicies()).thenReturn(successMap);
- successMap = mockAction.savePolicies();
- } catch (Exception e) {
- logger.error("Exception Occured"+e);
- }
- assertEquals(successMap.get("success"),"success");
- }
-
- /**
- * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.ActionPolicy#prepareToSave()}.
- */
- @Test
- public void testPrepareToSave() {
- logger.debug("test PrepareToSave Policy: enter");
- boolean response = true;
-
- try {
- response = component.prepareToSave();
- } catch (Exception e) {
- logger.error("Exception Occured"+e);
- }
- assertTrue(response);
-
- }
+ when(mockAction.savePolicies()).thenReturn(successMap);
+ successMap = mockAction.savePolicies();
+ } catch (Exception e) {
+ logger.error("Exception Occured"+e);
+ }
+ assertEquals(successMap.get("success"),"success");
+ }
+
+ /**
+ * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.ActionPolicy#prepareToSave()}.
+ */
+ @Test
+ public void testPrepareToSave() {
+ logger.debug("test PrepareToSave Policy: enter");
+ boolean response = true;
+
+ try {
+ response = component.prepareToSave();
+ } catch (Exception e) {
+ logger.error("Exception Occured"+e);
+ }
+ assertTrue(response);
+
+ }
} \ No newline at end of file
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicyTest.java
index 9c5f71f55..542d45e3e 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicyTest.java
@@ -31,38 +31,38 @@ import com.att.research.xacml.api.pap.PAPException;
import java.nio.charset.StandardCharsets;
public class ClosedLoopPolicyTest {
- @Rule
+ @Rule
public ExpectedException thrown = ExpectedException.none();
- @Test
- public void testConstructor1() {
- thrown.expect(NullPointerException.class);
- ClosedLoopPolicy policy = new ClosedLoopPolicy();
- policy.getCorrectPolicyDataObject();
- }
-
- @Test
- public void testConstructor2() {
- PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
- ClosedLoopPolicy policy = new ClosedLoopPolicy(policyAdapter);
- assertNull(policy.getCorrectPolicyDataObject());
- }
-
- @Test
- public void testReadFile() throws IOException {
- thrown.expect(IOException.class);
- String read = ClosedLoopPolicy.readFile("/foo", StandardCharsets.UTF_8);
- fail("Expecting an exception.");
- }
-
- @Test
- public void testPrepareToSave() throws PAPException {
- PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
- ClosedLoopPolicy policy = new ClosedLoopPolicy(policyAdapter);
- policyAdapter.setHighestVersion(1);
- policyAdapter.setPolicyType("Config");
- policyAdapter.setNewFileName("foo.xml");
- policy.prepareToSave();
- assertEquals(policy.isPreparedToSave(), true);
- }
+ @Test
+ public void testConstructor1() {
+ thrown.expect(NullPointerException.class);
+ ClosedLoopPolicy policy = new ClosedLoopPolicy();
+ policy.getCorrectPolicyDataObject();
+ }
+
+ @Test
+ public void testConstructor2() {
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ ClosedLoopPolicy policy = new ClosedLoopPolicy(policyAdapter);
+ assertNull(policy.getCorrectPolicyDataObject());
+ }
+
+ @Test
+ public void testReadFile() throws IOException {
+ thrown.expect(IOException.class);
+ String read = ClosedLoopPolicy.readFile("/foo", StandardCharsets.UTF_8);
+ fail("Expecting an exception.");
+ }
+
+ @Test
+ public void testPrepareToSave() throws PAPException {
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ ClosedLoopPolicy policy = new ClosedLoopPolicy(policyAdapter);
+ policyAdapter.setHighestVersion(1);
+ policyAdapter.setPolicyType("Config");
+ policyAdapter.setNewFileName("foo.xml");
+ policy.prepareToSave();
+ assertEquals(policy.isPreparedToSave(), true);
+ }
} \ No newline at end of file
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicyTest.java
index e16dd9889..3cf3128dd 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicyTest.java
@@ -41,104 +41,104 @@ import com.att.research.xacml.util.XACMLProperties;
public class DecisionPolicyTest {
- private static Logger logger = FlexLogger.getLogger(DecisionPolicyTest.class);
- PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
- RainyDayParams rainyday = new RainyDayParams();
- Map<String, String> attributeMap = new HashMap<>();
- Map<String, String> treatmentMap = new HashMap<>();
- Map<String, String> settingsMap = new HashMap<>();
- List<String> errorCodeList = new LinkedList<>();
- List<String> treatmentList = new LinkedList<>();
- List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
- List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
- List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
- List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
- List<Object> dynamicVariableList = new LinkedList<>();
- List<String> dataTypeList = new LinkedList<>();
- DecisionPolicy component = null;
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
-
- policyAdapter.setPolicyName("Test.Decision_junitTest.1.xml");
- policyAdapter.setPolicyDescription("testing");
- policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
- policyAdapter.setPolicyType("Decision");
- policyAdapter.setEditPolicy(false);
- policyAdapter.setDomainDir("Test");
- policyAdapter.setNewFileName("/src/test/resources/Test/client.properties");
- policyAdapter.setHighestVersion(1);
- policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
- policyAdapter.setOnapName("MSO");
-
- //rainy day attributes
- attributeMap.put("ServiceType", "S");
- attributeMap.put("VNFType", "V");
- attributeMap.put("BB_ID", "testBB");
- attributeMap.put("WorkStep", "1");
-
- dynamicRuleAlgorithmLabels.add("test1");
- dynamicRuleAlgorithmField1.add("testField1");
- dynamicRuleAlgorithmCombo.add("testruleCombo");
- dynamicRuleAlgorithmField2.add("testField2");
-
- policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
- policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
- policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
- policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
- policyAdapter.setDynamicVariableList(dynamicVariableList);
- policyAdapter.setDynamicSettingsMap(settingsMap);
- policyAdapter.setDataTypeList(dataTypeList);
-
- policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
- policyAdapter.setRainydayMap(treatmentMap);
- policyAdapter.setRainyday(rainyday);
-
- component = new DecisionPolicy(policyAdapter, null);
+ private static Logger logger = FlexLogger.getLogger(DecisionPolicyTest.class);
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ RainyDayParams rainyday = new RainyDayParams();
+ Map<String, String> attributeMap = new HashMap<>();
+ Map<String, String> treatmentMap = new HashMap<>();
+ Map<String, String> settingsMap = new HashMap<>();
+ List<String> errorCodeList = new LinkedList<>();
+ List<String> treatmentList = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
+ List<Object> dynamicVariableList = new LinkedList<>();
+ List<String> dataTypeList = new LinkedList<>();
+ DecisionPolicy component = null;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
+
+ policyAdapter.setPolicyName("Test.Decision_junitTest.1.xml");
+ policyAdapter.setPolicyDescription("testing");
+ policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
+ policyAdapter.setPolicyType("Decision");
+ policyAdapter.setEditPolicy(false);
+ policyAdapter.setDomainDir("Test");
+ policyAdapter.setNewFileName("/src/test/resources/Test/client.properties");
+ policyAdapter.setHighestVersion(1);
+ policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
+ policyAdapter.setOnapName("MSO");
+
+ //rainy day attributes
+ attributeMap.put("ServiceType", "S");
+ attributeMap.put("VNFType", "V");
+ attributeMap.put("BB_ID", "testBB");
+ attributeMap.put("WorkStep", "1");
+
+ dynamicRuleAlgorithmLabels.add("test1");
+ dynamicRuleAlgorithmField1.add("testField1");
+ dynamicRuleAlgorithmCombo.add("testruleCombo");
+ dynamicRuleAlgorithmField2.add("testField2");
+
+ policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
+ policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
+ policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
+ policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
+ policyAdapter.setDynamicVariableList(dynamicVariableList);
+ policyAdapter.setDynamicSettingsMap(settingsMap);
+ policyAdapter.setDataTypeList(dataTypeList);
+
+ policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
+ policyAdapter.setRainydayMap(treatmentMap);
+ policyAdapter.setRainyday(rainyday);
+
+ component = new DecisionPolicy(policyAdapter, null);
logger.info("setUp: exit");
- }
+ }
- /**
- * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#savePolicies()}.
- */
- @Test
- public void testSavePolicies() {
+ /**
+ * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#savePolicies()}.
+ */
+ @Test
+ public void testSavePolicies() {
DecisionPolicy mockDecision = Mockito.mock(component.getClass());
Map<String, String> successMap = new HashMap<>();
- successMap.put("success", "success");
-
+ successMap.put("success", "success");
+
+ try {
+ when(mockDecision.savePolicies()).thenReturn(successMap);
+ successMap = mockDecision.savePolicies();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ assertEquals(successMap.get("success"),"success");
+ }
+
+ /**
+ * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#prepareToSave()}.
+ */
+ @Test
+ public void testPrepareToSaveRainyDay() {
+ logger.debug("test PrepareToSave Policy: enter");
+ policyAdapter.setRuleProvider("Rainy_Day");
+ component = new DecisionPolicy(policyAdapter, null);
+ boolean response = false;
+
try {
- when(mockDecision.savePolicies()).thenReturn(successMap);
- successMap = mockDecision.savePolicies();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- assertEquals(successMap.get("success"),"success");
- }
-
- /**
- * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#prepareToSave()}.
- */
- @Test
- public void testPrepareToSaveRainyDay() {
- logger.debug("test PrepareToSave Policy: enter");
- policyAdapter.setRuleProvider("Rainy_Day");
- component = new DecisionPolicy(policyAdapter, null);
- boolean response = false;
-
- try {
- response = component.prepareToSave();
- } catch (Exception e) {
- logger.error("Exception Occured"+e);
- }
- assertTrue(response);
- }
+ response = component.prepareToSave();
+ } catch (Exception e) {
+ logger.error("Exception Occured"+e);
+ }
+ assertTrue(response);
+ }
} \ No newline at end of file
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
index 0dd919a35..7f3ebb3b4 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
@@ -42,103 +42,103 @@ import com.att.research.xacml.util.XACMLProperties;
public class FirewallConfigPolicyTest {
-
- private static Logger logger = FlexLogger.getLogger(FirewallConfigPolicyTest.class);
- PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
- Map<String, String> attributeMap = new HashMap<>();
- FirewallConfigPolicy component = null;
+
+ private static Logger logger = FlexLogger.getLogger(FirewallConfigPolicyTest.class);
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ Map<String, String> attributeMap = new HashMap<>();
+ FirewallConfigPolicy component = null;
FirewallConfigPolicy mockFWConfig = null;
private XACMLPAPTest papTest;
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- logger.info("setup: enter");
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
-
- policyAdapter.setPolicyName("FWjunitTest");
- policyAdapter.setPolicyDescription("test");
- policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
- policyAdapter.setPolicyType("Config");
- policyAdapter.setConfigPolicyType("Firewall Config");
- policyAdapter.setEditPolicy(false);
- policyAdapter.setDomainDir("Test");
- policyAdapter.setNewFileName("Test.Config_FW_junitTest.1.xml");
- policyAdapter.setHighestVersion(1);
- policyAdapter.setVersion(String.valueOf(1));
- policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
- policyAdapter.setRuleID("");
- policyAdapter.setConfigName("testname");
- policyAdapter.setGuard("True");
- policyAdapter.setRiskLevel("3");
- policyAdapter.setRiskType("RiskTest");
- policyAdapter.setSecurityZone("CraigSecurityZone");
- policyAdapter.setUserId("API");
-
- attributeMap.put("testJunits", "test");
- policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
-
- component = new FirewallConfigPolicy(policyAdapter);
- mockFWConfig = Mockito.mock(FirewallConfigPolicy.class);
- papTest = new XACMLPAPTest();
- papTest.setDBDao();
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setup: enter");
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
+
+ policyAdapter.setPolicyName("FWjunitTest");
+ policyAdapter.setPolicyDescription("test");
+ policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
+ policyAdapter.setPolicyType("Config");
+ policyAdapter.setConfigPolicyType("Firewall Config");
+ policyAdapter.setEditPolicy(false);
+ policyAdapter.setDomainDir("Test");
+ policyAdapter.setNewFileName("Test.Config_FW_junitTest.1.xml");
+ policyAdapter.setHighestVersion(1);
+ policyAdapter.setVersion(String.valueOf(1));
+ policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
+ policyAdapter.setRuleID("");
+ policyAdapter.setConfigName("testname");
+ policyAdapter.setGuard("True");
+ policyAdapter.setRiskLevel("3");
+ policyAdapter.setRiskType("RiskTest");
+ policyAdapter.setSecurityZone("CraigSecurityZone");
+ policyAdapter.setUserId("API");
+
+ attributeMap.put("testJunits", "test");
+ policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
+
+ component = new FirewallConfigPolicy(policyAdapter);
+ mockFWConfig = Mockito.mock(FirewallConfigPolicy.class);
+ papTest = new XACMLPAPTest();
+ papTest.setDBDao();
logger.info("setUp: exit");
-
- }
-
- /**
- * @throws java.lang.Exception
- */
- @After
- public void tearDown() throws Exception {
- }
-
- /**
- * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.FirewallConfigPolicy#savePolicies()}.
- */
- @Test
- public void testSavePolicies() {
+
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ /**
+ * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.FirewallConfigPolicy#savePolicies()}.
+ */
+ @Test
+ public void testSavePolicies() {
Map<String, String> successMap = new HashMap<>();
successMap.put("success", "success");
- try {
- when(mockFWConfig.savePolicies()).thenReturn(successMap);
- successMap = mockFWConfig.savePolicies();
- } catch (Exception e) {
- logger.error("Exception Occured"+e);
- }
- }
-
- /**
- * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.FirewallConfigPolicy#prepareToSave()}.
- */
- @Test
- public void testPrepareToSave() {
- logger.debug("test prepareToSave Policy: enter");
-
- boolean response = false;
- try {
- when(mockFWConfig.prepareToSave()).thenReturn(true);
- response = mockFWConfig.prepareToSave();
- } catch (Exception e) {
- logger.error("Exception Occured"+e);
- }
- assertTrue(response);
-
- }
-
- @Test
- public void testUpdateJson() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
- FirewallConfigPolicy firewallConfigPolicy = new FirewallConfigPolicy();
- Method method = firewallConfigPolicy.getClass().getDeclaredMethod("updateFirewallDictionaryData", String.class , String.class);
- method.setAccessible(true);
- String jsonBody= "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicyConfig\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev1a\",\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Sshservice entry in servicelist\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"test\",\"description\":\"Destination\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"SourceTestServers for firsttesting\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerToTest\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTestName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TestServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FWrule for Test source to Test destination\",\"enabled\":true,\"log\":true}]}";
- String prevJsonBody = "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicy1Config\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev\",\"vendorServiceId\":\"test\",\"vendorSpecificData\":{\"idMap\":[{\"Id\":\"cloudsite:dev1a\",\"vendorId\":\"deviceGroup:dev\"}]},\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Ssh service entry in service list\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"Test\",\"description\":\"Destination Test\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"Source TestServers for first testing\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerTot\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FW rule for HOHO source to CiscoVCE destination\",\"enabled\":true,\"log\":true}]}";
+ try {
+ when(mockFWConfig.savePolicies()).thenReturn(successMap);
+ successMap = mockFWConfig.savePolicies();
+ } catch (Exception e) {
+ logger.error("Exception Occured"+e);
+ }
+ }
+
+ /**
+ * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.FirewallConfigPolicy#prepareToSave()}.
+ */
+ @Test
+ public void testPrepareToSave() {
+ logger.debug("test prepareToSave Policy: enter");
+
+ boolean response = false;
+ try {
+ when(mockFWConfig.prepareToSave()).thenReturn(true);
+ response = mockFWConfig.prepareToSave();
+ } catch (Exception e) {
+ logger.error("Exception Occured"+e);
+ }
+ assertTrue(response);
+
+ }
+
+ @Test
+ public void testUpdateJson() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
+ FirewallConfigPolicy firewallConfigPolicy = new FirewallConfigPolicy();
+ Method method = firewallConfigPolicy.getClass().getDeclaredMethod("updateFirewallDictionaryData", String.class , String.class);
+ method.setAccessible(true);
+ String jsonBody= "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicyConfig\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev1a\",\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Sshservice entry in servicelist\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"test\",\"description\":\"Destination\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"SourceTestServers for firsttesting\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerToTest\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTestName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TestServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FWrule for Test source to Test destination\",\"enabled\":true,\"log\":true}]}";
+ String prevJsonBody = "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicy1Config\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev\",\"vendorServiceId\":\"test\",\"vendorSpecificData\":{\"idMap\":[{\"Id\":\"cloudsite:dev1a\",\"vendorId\":\"deviceGroup:dev\"}]},\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Ssh service entry in service list\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"Test\",\"description\":\"Destination Test\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"Source TestServers for first testing\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerTot\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FW rule for HOHO source to CiscoVCE destination\",\"enabled\":true,\"log\":true}]}";
assertTrue((Boolean) method.invoke(firewallConfigPolicy, jsonBody, prevJsonBody));
- }
-
- @Test
+ }
+
+ @Test
public void testInsertJson() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
FirewallConfigPolicy firewallConfigPolicy = new FirewallConfigPolicy();
Method method = firewallConfigPolicy.getClass().getDeclaredMethod("insertFirewallDicionaryData", String.class);
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/MicroServicePolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/MicroServicePolicyTest.java
index a47c2be58..f698bc0c0 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/MicroServicePolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/MicroServicePolicyTest.java
@@ -41,71 +41,71 @@ import java.util.Collections;
@RunWith(PowerMockRunner.class)
public class MicroServicePolicyTest {
- @Rule
+ @Rule
public ExpectedException thrown = ExpectedException.none();
- @Test
- public void testConstructor1() {
- thrown.expect(NullPointerException.class);
- MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy();
- policy.getCorrectPolicyDataObject();
- fail("Expected an exception");
- }
-
- @Test
- public void testConstructor2() {
- PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
- MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
- assertNull(policy.getCorrectPolicyDataObject());
- }
-
- @PrepareForTest({MicroServiceConfigPolicy.class})
- @Test
- public void testPrepareToSave() throws Exception {
- // Need to mock internal dictionary retrieval
- CommonClassDaoImpl impl = Mockito.mock(CommonClassDaoImpl.class);
- PowerMockito.whenNew(CommonClassDaoImpl.class).withNoArguments().thenReturn(impl);
- when(impl.getDataById(any(), anyString(), anyString())).thenReturn(null);
-
- PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
- MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
- policyAdapter.setHighestVersion(1);
- policyAdapter.setPolicyType("Config");
- policyAdapter.setNewFileName("foo.xml");
- policyAdapter.setJsonBody("{ \"version\": \"1.0\"}");
- policyAdapter.setServiceType("foo");
- policy.prepareToSave();
- assertEquals(policy.isPreparedToSave(), true);
- }
-
- @Test
- public void testCreateConstructor1() {
- CreateNewMicroServiceModel model = new CreateNewMicroServiceModel(null, null, null, null);
- assertNotNull(model);
- }
-
- @PrepareForTest({CreateNewMicroServiceModel.class})
- @Test
- public void testCreateModel() throws Exception {
- // Mock file retrieval
- File testFile = new File("testFile");
- File[] testList = new File[1];
- testList[0] = testFile;
- File impl = Mockito.mock(File.class);
- PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(impl);
- when(impl.listFiles()).thenReturn(testList);
- when(impl.isFile()).thenReturn(true);
+ @Test
+ public void testConstructor1() {
+ thrown.expect(NullPointerException.class);
+ MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy();
+ policy.getCorrectPolicyDataObject();
+ fail("Expected an exception");
+ }
- // Mock internal dictionary retrieval
- CommonClassDaoImpl daoImpl = Mockito.mock(CommonClassDaoImpl.class);
- PowerMockito.whenNew(CommonClassDaoImpl.class).withNoArguments().thenReturn(daoImpl);
- when(daoImpl.getDataById(any(), anyString(), anyString())).thenReturn(Collections.emptyList());
+ @Test
+ public void testConstructor2() {
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
+ assertNull(policy.getCorrectPolicyDataObject());
+ }
- // Test create methods
- String testFileName = "testFile.zip";
- String testVal = "testVal";
- CreateNewMicroServiceModel model = new CreateNewMicroServiceModel(testFileName, testVal, testVal, testVal, testVal);
- model.addValuesToNewModel(".xmi");
- model.saveImportService();
- }
+ @PrepareForTest({MicroServiceConfigPolicy.class})
+ @Test
+ public void testPrepareToSave() throws Exception {
+ // Need to mock internal dictionary retrieval
+ CommonClassDaoImpl impl = Mockito.mock(CommonClassDaoImpl.class);
+ PowerMockito.whenNew(CommonClassDaoImpl.class).withNoArguments().thenReturn(impl);
+ when(impl.getDataById(any(), anyString(), anyString())).thenReturn(null);
+
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
+ policyAdapter.setHighestVersion(1);
+ policyAdapter.setPolicyType("Config");
+ policyAdapter.setNewFileName("foo.xml");
+ policyAdapter.setJsonBody("{ \"version\": \"1.0\"}");
+ policyAdapter.setServiceType("foo");
+ policy.prepareToSave();
+ assertEquals(policy.isPreparedToSave(), true);
+ }
+
+ @Test
+ public void testCreateConstructor1() {
+ CreateNewMicroServiceModel model = new CreateNewMicroServiceModel(null, null, null, null);
+ assertNotNull(model);
+ }
+
+ @PrepareForTest({CreateNewMicroServiceModel.class})
+ @Test
+ public void testCreateModel() throws Exception {
+ // Mock file retrieval
+ File testFile = new File("testFile");
+ File[] testList = new File[1];
+ testList[0] = testFile;
+ File impl = Mockito.mock(File.class);
+ PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(impl);
+ when(impl.listFiles()).thenReturn(testList);
+ when(impl.isFile()).thenReturn(true);
+
+ // Mock internal dictionary retrieval
+ CommonClassDaoImpl daoImpl = Mockito.mock(CommonClassDaoImpl.class);
+ PowerMockito.whenNew(CommonClassDaoImpl.class).withNoArguments().thenReturn(daoImpl);
+ when(daoImpl.getDataById(any(), anyString(), anyString())).thenReturn(Collections.emptyList());
+
+ // Test create methods
+ String testFileName = "testFile.zip";
+ String testVal = "testVal";
+ CreateNewMicroServiceModel model = new CreateNewMicroServiceModel(testFileName, testVal, testVal, testVal, testVal);
+ model.addValuesToNewModel(".xmi");
+ model.saveImportService();
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicyTest.java
index 7b9be6891..25e94c1a2 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicyTest.java
@@ -41,65 +41,65 @@ import java.util.Collections;
@RunWith(PowerMockRunner.class)
public class OptimizationConfigPolicyTest {
- @Rule
+ @Rule
public ExpectedException thrown = ExpectedException.none();
- @Test
- public void testConstructor1() {
- thrown.expect(NullPointerException.class);
- OptimizationConfigPolicy policy = new OptimizationConfigPolicy();
- policy.getCorrectPolicyDataObject();
- fail("Expected an exception");
- }
-
- @Test
- public void testConstructor2() {
- PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
- OptimizationConfigPolicy policy = new OptimizationConfigPolicy(policyAdapter);
- assertNull(policy.getCorrectPolicyDataObject());
- }
-
- @PrepareForTest({OptimizationConfigPolicy.class})
- @Test
- public void testPrepareToSave() throws Exception {
- // Need to mock internal dictionary retrieval
- CommonClassDaoImpl impl = Mockito.mock(CommonClassDaoImpl.class);
- PowerMockito.whenNew(CommonClassDaoImpl.class).withNoArguments().thenReturn(impl);
- when(impl.getDataById(any(), anyString(), anyString())).thenReturn(null);
-
- PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
- OptimizationConfigPolicy policy = new OptimizationConfigPolicy(policyAdapter);
- policyAdapter.setHighestVersion(1);
- policyAdapter.setPolicyType("Config");
- policyAdapter.setNewFileName("foo.xml");
- policyAdapter.setJsonBody("{ \"version\": \"1.0\"}");
- policyAdapter.setServiceType("foo");
- policy.prepareToSave();
- assertEquals(true, policy.isPreparedToSave());
- }
-
- @PrepareForTest({CreateNewOptimizationModel.class})
- @Test
- public void testCreateModel() throws Exception {
- // Mock file retrieval
- File testFile = new File("testFile");
- File[] testList = new File[1];
- testList[0] = testFile;
- File impl = Mockito.mock(File.class);
- PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(impl);
- when(impl.listFiles()).thenReturn(testList);
- when(impl.isFile()).thenReturn(true);
+ @Test
+ public void testConstructor1() {
+ thrown.expect(NullPointerException.class);
+ OptimizationConfigPolicy policy = new OptimizationConfigPolicy();
+ policy.getCorrectPolicyDataObject();
+ fail("Expected an exception");
+ }
- // Mock internal dictionary retrieval
- CommonClassDaoImpl daoImpl = Mockito.mock(CommonClassDaoImpl.class);
- PowerMockito.whenNew(CommonClassDaoImpl.class).withNoArguments().thenReturn(daoImpl);
- when(daoImpl.getDataById(any(), anyString(), anyString())).thenReturn(Collections.emptyList());
+ @Test
+ public void testConstructor2() {
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ OptimizationConfigPolicy policy = new OptimizationConfigPolicy(policyAdapter);
+ assertNull(policy.getCorrectPolicyDataObject());
+ }
- // Test create methods
- String testFileName = "testFile.zip";
- String testVal = "testVal";
- CreateNewOptimizationModel model = new CreateNewOptimizationModel(testFileName, testVal, testVal, testVal, testVal);
- model.addValuesToNewModel();
- model.saveImportService();
- }
+ @PrepareForTest({OptimizationConfigPolicy.class})
+ @Test
+ public void testPrepareToSave() throws Exception {
+ // Need to mock internal dictionary retrieval
+ CommonClassDaoImpl impl = Mockito.mock(CommonClassDaoImpl.class);
+ PowerMockito.whenNew(CommonClassDaoImpl.class).withNoArguments().thenReturn(impl);
+ when(impl.getDataById(any(), anyString(), anyString())).thenReturn(null);
+
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ OptimizationConfigPolicy policy = new OptimizationConfigPolicy(policyAdapter);
+ policyAdapter.setHighestVersion(1);
+ policyAdapter.setPolicyType("Config");
+ policyAdapter.setNewFileName("foo.xml");
+ policyAdapter.setJsonBody("{ \"version\": \"1.0\"}");
+ policyAdapter.setServiceType("foo");
+ policy.prepareToSave();
+ assertEquals(true, policy.isPreparedToSave());
+ }
+
+ @PrepareForTest({CreateNewOptimizationModel.class})
+ @Test
+ public void testCreateModel() throws Exception {
+ // Mock file retrieval
+ File testFile = new File("testFile");
+ File[] testList = new File[1];
+ testList[0] = testFile;
+ File impl = Mockito.mock(File.class);
+ PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(impl);
+ when(impl.listFiles()).thenReturn(testList);
+ when(impl.isFile()).thenReturn(true);
+
+ // Mock internal dictionary retrieval
+ CommonClassDaoImpl daoImpl = Mockito.mock(CommonClassDaoImpl.class);
+ PowerMockito.whenNew(CommonClassDaoImpl.class).withNoArguments().thenReturn(daoImpl);
+ when(daoImpl.getDataById(any(), anyString(), anyString())).thenReturn(Collections.emptyList());
+
+ // Test create methods
+ String testFileName = "testFile.zip";
+ String testVal = "testVal";
+ CreateNewOptimizationModel model = new CreateNewOptimizationModel(testFileName, testVal, testVal, testVal, testVal);
+ model.addValuesToNewModel();
+ model.saveImportService();
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java
index c098bf4fa..bdfd8db33 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTest.java
@@ -65,538 +65,538 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
public class PolicyDBDaoTest extends Mockito{
- private static Logger logger = FlexLogger.getLogger(PolicyDBDaoTest.class);
-
- PolicyDBDaoTestClass d;
- PolicyDBDao dbd;
- PolicyDBDao dbd2;
- EntityManagerFactory emf;
- private Path repository;
- StdEngine stdEngine = null;
-
- @Before
- public void init() throws PAPException, IOException{
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
- emf = Persistence.createEntityManagerFactory("testPapPU");
- EntityManager em = emf.createEntityManager();
- em.getTransaction().begin();
- try{
- em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate();
- em.createQuery("DELETE FROM PolicyEntity").executeUpdate();
- em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate();
- em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate();
- em.createQuery("DELETE FROM PdpEntity").executeUpdate();
- em.createQuery("DELETE FROM GroupEntity").executeUpdate();
-
- em.getTransaction().commit();
- } catch(Exception e){
- logger.error("Exception Occured"+e);
- em.getTransaction().rollback();
- }
- em.close();
- try {
- dbd = PolicyDBDao.getPolicyDBDaoInstance(emf);
- dbd2 = PolicyDBDao.getPolicyDBDaoInstance(emf);
- } catch (Exception e) {
- Assert.fail();
- }
-
- d = PolicyDBDao.getPolicyDBDaoTestClass();
- PolicyDBDao.setJunit(true);
- repository = Paths.get("src/test/resources/pdps");
+ private static Logger logger = FlexLogger.getLogger(PolicyDBDaoTest.class);
+
+ PolicyDBDaoTestClass d;
+ PolicyDBDao dbd;
+ PolicyDBDao dbd2;
+ EntityManagerFactory emf;
+ private Path repository;
+ StdEngine stdEngine = null;
+
+ @Before
+ public void init() throws PAPException, IOException{
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
+ emf = Persistence.createEntityManagerFactory("testPapPU");
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ try{
+ em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate();
+ em.createQuery("DELETE FROM PolicyEntity").executeUpdate();
+ em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate();
+ em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate();
+ em.createQuery("DELETE FROM PdpEntity").executeUpdate();
+ em.createQuery("DELETE FROM GroupEntity").executeUpdate();
+
+ em.getTransaction().commit();
+ } catch(Exception e){
+ logger.error("Exception Occured"+e);
+ em.getTransaction().rollback();
+ }
+ em.close();
+ try {
+ dbd = PolicyDBDao.getPolicyDBDaoInstance(emf);
+ dbd2 = PolicyDBDao.getPolicyDBDaoInstance(emf);
+ } catch (Exception e) {
+ Assert.fail();
+ }
+
+ d = PolicyDBDao.getPolicyDBDaoTestClass();
+ PolicyDBDao.setJunit(true);
+ repository = Paths.get("src/test/resources/pdps");
stdEngine = new StdEngine(repository);
dbd.setPapEngine(stdEngine);
- }
-
- @After
- public void cleanUp(){
- PolicyDBDao.setJunit(false);
- EntityManager em = emf.createEntityManager();
- em.getTransaction().begin();
- try{
- em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate();
- em.createQuery("DELETE FROM PolicyEntity").executeUpdate();
- em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate();
- em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate();
- em.createQuery("DELETE FROM PdpEntity").executeUpdate();
- em.createQuery("DELETE FROM GroupEntity").executeUpdate();
-
- em.getTransaction().commit();
- } catch(Exception e){
- em.getTransaction().rollback();
- }
- em.close();
- try {
- FileUtils.forceDelete(new File("src/test/resources/junitTestCreatedDirectory"));
- } catch (IOException e) {
- //could not delete
- }
- }
-
- @Test
- public void getConfigFileTest(){
- PolicyRestAdapter pra = new PolicyRestAdapter();
- pra.setConfigType(ConfigPolicy.JSON_CONFIG);
- String configFile = d.getConfigFile("Config_mypolicy.xml", "org.onap", pra);
- Assert.assertEquals("org.onap.Config_mypolicy.json", configFile);
- //yes, we can do action files too even though they don't have configs
- configFile = d.getConfigFile("Action_mypolicy.xml", "org.onap", pra);
- Assert.assertEquals("org.onap.Action_mypolicy.json", configFile);
- }
-
- @Test
- public void createFromPolicyObject(){
- Policy policyObject = new ConfigPolicy();
- policyObject.policyAdapter = new PolicyRestAdapter();
- policyObject.policyAdapter.setConfigName("testpolicy1");
- policyObject.policyAdapter.setPolicyDescription("my description");
- policyObject.policyAdapter.setConfigBodyData("this is my test config file");
- policyObject.policyAdapter.setPolicyName("SampleTest1206");
- policyObject.policyAdapter.setConfigType(ConfigPolicy.OTHER_CONFIG);
- policyObject.policyAdapter.setPolicyType("Config");
- policyObject.policyAdapter.setDomainDir("com");
- policyObject.policyAdapter.setVersion("1");
- PolicyType policyTypeObject = new PolicyType();
- policyObject.policyAdapter.setPolicyData(policyTypeObject);
- ClassLoader classLoader = getClass().getClassLoader();
- PolicyType policyConfig = new PolicyType();
+ }
+
+ @After
+ public void cleanUp(){
+ PolicyDBDao.setJunit(false);
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ try{
+ em.createQuery("DELETE FROM PolicyDBDaoEntity").executeUpdate();
+ em.createQuery("DELETE FROM PolicyEntity").executeUpdate();
+ em.createQuery("DELETE FROM ConfigurationDataEntity").executeUpdate();
+ em.createQuery("DELETE FROM ActionBodyEntity").executeUpdate();
+ em.createQuery("DELETE FROM PdpEntity").executeUpdate();
+ em.createQuery("DELETE FROM GroupEntity").executeUpdate();
+
+ em.getTransaction().commit();
+ } catch(Exception e){
+ em.getTransaction().rollback();
+ }
+ em.close();
+ try {
+ FileUtils.forceDelete(new File("src/test/resources/junitTestCreatedDirectory"));
+ } catch (IOException e) {
+ //could not delete
+ }
+ }
+
+ @Test
+ public void getConfigFileTest(){
+ PolicyRestAdapter pra = new PolicyRestAdapter();
+ pra.setConfigType(ConfigPolicy.JSON_CONFIG);
+ String configFile = d.getConfigFile("Config_mypolicy.xml", "org.onap", pra);
+ Assert.assertEquals("org.onap.Config_mypolicy.json", configFile);
+ //yes, we can do action files too even though they don't have configs
+ configFile = d.getConfigFile("Action_mypolicy.xml", "org.onap", pra);
+ Assert.assertEquals("org.onap.Action_mypolicy.json", configFile);
+ }
+
+ @Test
+ public void createFromPolicyObject(){
+ Policy policyObject = new ConfigPolicy();
+ policyObject.policyAdapter = new PolicyRestAdapter();
+ policyObject.policyAdapter.setConfigName("testpolicy1");
+ policyObject.policyAdapter.setPolicyDescription("my description");
+ policyObject.policyAdapter.setConfigBodyData("this is my test config file");
+ policyObject.policyAdapter.setPolicyName("SampleTest1206");
+ policyObject.policyAdapter.setConfigType(ConfigPolicy.OTHER_CONFIG);
+ policyObject.policyAdapter.setPolicyType("Config");
+ policyObject.policyAdapter.setDomainDir("com");
+ policyObject.policyAdapter.setVersion("1");
+ PolicyType policyTypeObject = new PolicyType();
+ policyObject.policyAdapter.setPolicyData(policyTypeObject);
+ ClassLoader classLoader = getClass().getClassLoader();
+ PolicyType policyConfig = new PolicyType();
policyConfig.setVersion(Integer.toString(1));
policyConfig.setPolicyId("");
policyConfig.setTarget(new TargetType());
policyObject.policyAdapter.setData(policyConfig);
- mock(XACMLPolicyWriter.class);
- try {
- policyObject.policyAdapter.setParentPath(IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml")));
- } catch (Exception e2) {
- fail();
- }
-
- PolicyDBDaoTransaction transaction = dbd.getNewTransaction();
- try{
- transaction.createPolicy(policyObject, "testuser1");
- transaction.commitTransaction();
- } catch(Exception e){
- transaction.rollbackTransaction();
- Assert.fail();
- }
-
- EntityManager getData = emf.createEntityManager();
- Query getDataQuery = getData.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:name");
- getDataQuery.setParameter("scope", "com");
- getDataQuery.setParameter("name","Config_SampleTest1206.1.xml");
- PolicyEntity result = null;
- try{
- result = (PolicyEntity)getDataQuery.getSingleResult();
- } catch(Exception e){
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- String expectedData;
- try {
- expectedData = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
- } catch (IOException e1) {
- expectedData = "";
- }
- Assert.assertEquals(expectedData, result.getPolicyData());
- getData.close();
- result = null;
-
- transaction.commitTransaction();
- Assert.assertFalse(transaction.isTransactionOpen());
- }
-
- @Test
- public void groupTransactions(){
- PolicyDBDaoTransaction group = dbd.getNewTransaction();
- String groupName = "test group 1";
- try{
- group.createGroup(PolicyDBDao.createNewPDPGroupId(groupName), groupName, "this is a test group","testuser");
- group.commitTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- EntityManager em = emf.createEntityManager();
- Query getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted");
- getGroup.setParameter("groupId", PolicyDBDao.createNewPDPGroupId(groupName));
- getGroup.setParameter("deleted", false);
- List<?> groups = getGroup.getResultList();
- if(groups.size() != 1){
- Assert.fail();
- }
- GroupEntity groupEntity = (GroupEntity)groups.get(0);
- em.close();
- Assert.assertEquals(groupName, groupEntity.getgroupName());
- Assert.assertEquals("this is a test group", groupEntity.getDescription());
- group = dbd.getNewTransaction();
- try{
- OnapPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId(groupName),Paths.get("/"));
- group.deleteGroup(groupToDelete, null,"testuser");
- group.commitTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- em = emf.createEntityManager();
- getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted");
- getGroup.setParameter("groupId", PolicyDBDao.createNewPDPGroupId(groupName));
- getGroup.setParameter("deleted", false);
- groups = getGroup.getResultList();
- if(groups.size() != 0){
- System.out.println("Group size: "+groups.size());
- Assert.fail();
- }
- em.close();
- //add a pdp to a group
- group = dbd.getNewTransaction();
- try{
- group.createGroup(PolicyDBDao.createNewPDPGroupId(groupName), groupName, "test group", "testuser");
- group.commitTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- group = dbd.getNewTransaction();
- try{
- group.addPdpToGroup("http://localhost:4344/pdp/", PolicyDBDao.createNewPDPGroupId(groupName), "primary", "the main pdp", 3232, "testuser");
- group.commitTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- em = emf.createEntityManager();
- Query getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpId=:pdpId AND p.deleted=:deleted");
- getPdp.setParameter("pdpId", "http://localhost:4344/pdp/");
- getPdp.setParameter("deleted", false);
- List<?> pdps = getPdp.getResultList();
- if(pdps.size() != 1){
- System.out.println("Group size: "+pdps.size());
- Assert.fail();
- }
- PdpEntity pdp = (PdpEntity)pdps.get(0);
- Assert.assertEquals(groupName, pdp.getGroup().getgroupName());
- Assert.assertEquals(pdp.getPdpName(), "primary");
- em.close();
- group = dbd.getNewTransaction();
- try{
- group.removePdpFromGroup("http://localhost:4344/pdp/","testuser");
- group.commitTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- em = emf.createEntityManager();
- getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpId=:pdpId AND p.deleted=:deleted");
- getPdp.setParameter("pdpId", "http://localhost:4344/pdp/");
- getPdp.setParameter("deleted", false);
- pdps = getPdp.getResultList();
- if(pdps.size() != 0){
- System.out.println("Group size: "+pdps.size());
- Assert.fail();
- }
- em.close();
-
- //add some pdps to groups
- group = dbd.getNewTransaction();
- try{
- group.createGroup(PolicyDBDao.createNewPDPGroupId("testgroup1"), "testgroup1", "test group", "testuser");
- group.commitTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- group = dbd.getNewTransaction();
- try{
- group.createGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"), "testgroup2", "test group", "testuser");
- group.commitTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
-
- group = dbd.getNewTransaction();
- try{
- group.addPdpToGroup("http://localhost:4344/pdp/", PolicyDBDao.createNewPDPGroupId("testgroup1"), "primary", "the main pdp", 3232, "testuser");
- group.commitTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- group = dbd.getNewTransaction();
- try{
- group.addPdpToGroup("http://localhost:4345/pdp/", PolicyDBDao.createNewPDPGroupId("testgroup1"), "secondary", "the second pdp", 3233, "testuser");
- group.commitTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- em = emf.createEntityManager();
- getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.deleted=:deleted");
- getPdp.setParameter("deleted", false);
- pdps = getPdp.getResultList();
- for(Object o : pdps){
- Assert.assertEquals("testgroup1",((PdpEntity)o).getGroup().getgroupName());
- }
- em.close();
-
- group = dbd.getNewTransaction();
- try{
- OnapPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup1"),Paths.get("/"));
- OnapPDPGroup groupToMoveTo = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"),Paths.get("/"));
- group.deleteGroup(groupToDelete, groupToMoveTo,"testuser");
- group.commitTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
- em = emf.createEntityManager();
- getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted");
- getGroup.setParameter("groupId", "testgroup1");
- getGroup.setParameter("deleted", false);
- groups = getGroup.getResultList();
- if(groups.size() != 0){
- System.out.println("Group size: "+groups.size());
- Assert.fail();
- }
- em.close();
-
- em = emf.createEntityManager();
- getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.deleted=:deleted");
- getPdp.setParameter("deleted", false);
- pdps = getPdp.getResultList();
- for(Object o : pdps){
- Assert.assertEquals("testgroup2",((PdpEntity)o).getGroup().getgroupName());
- }
- em.close();
-
- group = dbd.getNewTransaction();
- try{
- OnapPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"),Paths.get("/"));
- OnapPDPGroup groupToMoveTo = null;
- group.deleteGroup(groupToDelete, groupToMoveTo,"testuser");
- group.commitTransaction();
- Assert.fail();
- } catch(PolicyDBException pe){
- //good, can't delete group with pdps
- group.rollbackTransaction();
- } catch(Exception e){
- group.rollbackTransaction();
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
-
- //update group
- OnapPDPGroup pdpGroup = new StdPDPGroup("testgroup2", false, "newtestgroup2", "this is my new description", Paths.get("/"));
- group = dbd.getNewTransaction();
- try{
- group.updateGroup(pdpGroup, "testuser");
- group.commitTransaction();
- }catch (Exception e){
- logger.error("Exception Occured"+e);
- group.rollbackTransaction();
- Assert.fail();
- }
- em = emf.createEntityManager();
- getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted");
- getGroup.setParameter("groupId", "newtestgroup2");
- getGroup.setParameter("deleted", false);
- groups = getGroup.getResultList();
- if(groups.size() != 1){
- System.out.println("Group size: "+groups.size());
- Assert.fail();
- }
- em.close();
- em = emf.createEntityManager();
- getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted");
- getGroup.setParameter("groupId", "testgroup2");
- getGroup.setParameter("deleted", false);
- groups = getGroup.getResultList();
- if(groups.size() != 0){
- System.out.println("Group size: "+groups.size());
- Assert.fail();
- }
- em.close();
- }
-
- @Ignore
- @Test
- public void threadingStabilityTest(){
- if(logger.isDebugEnabled()){
- logger.debug("\n\n****************************"
- + "threadingStabilityTest() entry"
- + "******************************\n\n");
- }
-
- PolicyDBDaoTransaction t = dbd.getNewTransaction();
- Assert.assertTrue(t.isTransactionOpen());
- try {
- //Add 1000 ms to the timeout just to be sure it actually times out
- int sleepTime = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)) + 1000;
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n sleepTime = " + sleepTime
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- Thread.sleep(sleepTime);
- } catch (InterruptedException e) {
- logger.error("Exception Occured"+e);
- }
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n Assert.assertFalse(t.isTransactionOpen() = " + t.isTransactionOpen() + ")"
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- Assert.assertFalse(t.isTransactionOpen());
-
-
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n a = dbd.getNewTransaction() "
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- PolicyDBDaoTransaction a = dbd.getNewTransaction();
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n Assert.assertTrue(a.isTransactionOpen() = " + a.isTransactionOpen() + ")"
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- Assert.assertTrue(a.isTransactionOpen());
-
- try {
- //Add 1000 ms to the timeout just to be sure it actually times out
- int sleepTime = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)) + 1000;
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n sleepTime = " + sleepTime
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- Thread.sleep(sleepTime);
- } catch (InterruptedException e) {
- logger.error("Exception Occured"+e);
- }
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n b = dbd.getNewTransaction() "
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- PolicyDBDaoTransaction b = dbd.getNewTransaction();
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n Assert.assertFalse(a.isTransactionOpen() = " + a.isTransactionOpen() + ")"
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- Assert.assertFalse(a.isTransactionOpen());
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n Assert.assertTrue(b.isTransactionOpen() = " + b.isTransactionOpen() + ")"
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- Assert.assertTrue(b.isTransactionOpen());
- b.close();
-
-
-
- //Now let's test the transaction wait time timeout. Shorten the wait time to 1000 ms
- System.setProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT,"1000");
- //And let's lengthen the transaction timeout to 5000 ms
- System.setProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT,"5000");
- //get a transacton
- PolicyDBDaoTransaction t1 = dbd.getNewTransaction();
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n Assert.assertTrue(t1.isTransactionOpen() = " + t1.isTransactionOpen() + ")"
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- Assert.assertTrue(t1.isTransactionOpen());
- //while it is open, get another from a different DB Dao so it will not collide on the synchronized code segment
- //but will collide at the DB. Remember that the wait time is only 1000 ms
- try {
- //Now the 2nd transaction has a wait timeout in 1000 ms
- PolicyDBDaoTransaction t2 = dbd2.getNewTransaction();
- /*
- * Give it plenty of time to time out the second transaction
- * It will actually hang right here until it either gets the lock from the DB or the
- * request for the DB lock times out. The timers are very sloppy so, I have given
- * this plenty of leeway.
- */
-
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n Thread.sleep(3000)"
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- Thread.sleep(3000);
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n Assert.assertTrue(t1.isTransactionOpen() = " + t1.isTransactionOpen() + ")"
- + "\n Assert.assertFalse(t2.isTransactionOpen() = " + t2.isTransactionOpen() + ")"
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- //Assert.assertTrue(t1.isTransactionOpen());
- //Assert.assertFalse(t2.isTransactionOpen());
-
- Assert.fail("\n\nTransaction timeout of 1000 ms exceeded without a PersistenceException\n\n");
- } catch (PersistenceException e) {
- //success
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
- + "\n SUCCESS! Transaction Wait Timeout worked!"
- + "\n Caught PersistenceException = " + e
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- } catch (Exception e) {
- // failure due to some other reason
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() FAILURE"
- + "\n Caught Exception = " + e
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- logger.error("Exception Occured"+e);
- Assert.fail();
- }
-
- if(logger.isDebugEnabled()){
- Date date= new java.util.Date();
- logger.debug("\n\nthreadingStabilityTest() exit"
- + "\n TimeStamp = " + date.getTime()
- + "\n\n");
- }
- }
+ mock(XACMLPolicyWriter.class);
+ try {
+ policyObject.policyAdapter.setParentPath(IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml")));
+ } catch (Exception e2) {
+ fail();
+ }
+
+ PolicyDBDaoTransaction transaction = dbd.getNewTransaction();
+ try{
+ transaction.createPolicy(policyObject, "testuser1");
+ transaction.commitTransaction();
+ } catch(Exception e){
+ transaction.rollbackTransaction();
+ Assert.fail();
+ }
+
+ EntityManager getData = emf.createEntityManager();
+ Query getDataQuery = getData.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:name");
+ getDataQuery.setParameter("scope", "com");
+ getDataQuery.setParameter("name","Config_SampleTest1206.1.xml");
+ PolicyEntity result = null;
+ try{
+ result = (PolicyEntity)getDataQuery.getSingleResult();
+ } catch(Exception e){
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+ String expectedData;
+ try {
+ expectedData = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
+ } catch (IOException e1) {
+ expectedData = "";
+ }
+ Assert.assertEquals(expectedData, result.getPolicyData());
+ getData.close();
+ result = null;
+
+ transaction.commitTransaction();
+ Assert.assertFalse(transaction.isTransactionOpen());
+ }
+
+ @Test
+ public void groupTransactions(){
+ PolicyDBDaoTransaction group = dbd.getNewTransaction();
+ String groupName = "test group 1";
+ try{
+ group.createGroup(PolicyDBDao.createNewPDPGroupId(groupName), groupName, "this is a test group","testuser");
+ group.commitTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+ EntityManager em = emf.createEntityManager();
+ Query getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted");
+ getGroup.setParameter("groupId", PolicyDBDao.createNewPDPGroupId(groupName));
+ getGroup.setParameter("deleted", false);
+ List<?> groups = getGroup.getResultList();
+ if(groups.size() != 1){
+ Assert.fail();
+ }
+ GroupEntity groupEntity = (GroupEntity)groups.get(0);
+ em.close();
+ Assert.assertEquals(groupName, groupEntity.getgroupName());
+ Assert.assertEquals("this is a test group", groupEntity.getDescription());
+ group = dbd.getNewTransaction();
+ try{
+ OnapPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId(groupName),Paths.get("/"));
+ group.deleteGroup(groupToDelete, null,"testuser");
+ group.commitTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+ em = emf.createEntityManager();
+ getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted");
+ getGroup.setParameter("groupId", PolicyDBDao.createNewPDPGroupId(groupName));
+ getGroup.setParameter("deleted", false);
+ groups = getGroup.getResultList();
+ if(groups.size() != 0){
+ System.out.println("Group size: "+groups.size());
+ Assert.fail();
+ }
+ em.close();
+ //add a pdp to a group
+ group = dbd.getNewTransaction();
+ try{
+ group.createGroup(PolicyDBDao.createNewPDPGroupId(groupName), groupName, "test group", "testuser");
+ group.commitTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+ group = dbd.getNewTransaction();
+ try{
+ group.addPdpToGroup("http://localhost:4344/pdp/", PolicyDBDao.createNewPDPGroupId(groupName), "primary", "the main pdp", 3232, "testuser");
+ group.commitTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+ em = emf.createEntityManager();
+ Query getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpId=:pdpId AND p.deleted=:deleted");
+ getPdp.setParameter("pdpId", "http://localhost:4344/pdp/");
+ getPdp.setParameter("deleted", false);
+ List<?> pdps = getPdp.getResultList();
+ if(pdps.size() != 1){
+ System.out.println("Group size: "+pdps.size());
+ Assert.fail();
+ }
+ PdpEntity pdp = (PdpEntity)pdps.get(0);
+ Assert.assertEquals(groupName, pdp.getGroup().getgroupName());
+ Assert.assertEquals(pdp.getPdpName(), "primary");
+ em.close();
+ group = dbd.getNewTransaction();
+ try{
+ group.removePdpFromGroup("http://localhost:4344/pdp/","testuser");
+ group.commitTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+ em = emf.createEntityManager();
+ getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.pdpId=:pdpId AND p.deleted=:deleted");
+ getPdp.setParameter("pdpId", "http://localhost:4344/pdp/");
+ getPdp.setParameter("deleted", false);
+ pdps = getPdp.getResultList();
+ if(pdps.size() != 0){
+ System.out.println("Group size: "+pdps.size());
+ Assert.fail();
+ }
+ em.close();
+
+ //add some pdps to groups
+ group = dbd.getNewTransaction();
+ try{
+ group.createGroup(PolicyDBDao.createNewPDPGroupId("testgroup1"), "testgroup1", "test group", "testuser");
+ group.commitTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+ group = dbd.getNewTransaction();
+ try{
+ group.createGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"), "testgroup2", "test group", "testuser");
+ group.commitTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+
+ group = dbd.getNewTransaction();
+ try{
+ group.addPdpToGroup("http://localhost:4344/pdp/", PolicyDBDao.createNewPDPGroupId("testgroup1"), "primary", "the main pdp", 3232, "testuser");
+ group.commitTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+ group = dbd.getNewTransaction();
+ try{
+ group.addPdpToGroup("http://localhost:4345/pdp/", PolicyDBDao.createNewPDPGroupId("testgroup1"), "secondary", "the second pdp", 3233, "testuser");
+ group.commitTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+ em = emf.createEntityManager();
+ getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.deleted=:deleted");
+ getPdp.setParameter("deleted", false);
+ pdps = getPdp.getResultList();
+ for(Object o : pdps){
+ Assert.assertEquals("testgroup1",((PdpEntity)o).getGroup().getgroupName());
+ }
+ em.close();
+
+ group = dbd.getNewTransaction();
+ try{
+ OnapPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup1"),Paths.get("/"));
+ OnapPDPGroup groupToMoveTo = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"),Paths.get("/"));
+ group.deleteGroup(groupToDelete, groupToMoveTo,"testuser");
+ group.commitTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+ em = emf.createEntityManager();
+ getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted");
+ getGroup.setParameter("groupId", "testgroup1");
+ getGroup.setParameter("deleted", false);
+ groups = getGroup.getResultList();
+ if(groups.size() != 0){
+ System.out.println("Group size: "+groups.size());
+ Assert.fail();
+ }
+ em.close();
+
+ em = emf.createEntityManager();
+ getPdp = em.createQuery("SELECT p FROM PdpEntity p WHERE p.deleted=:deleted");
+ getPdp.setParameter("deleted", false);
+ pdps = getPdp.getResultList();
+ for(Object o : pdps){
+ Assert.assertEquals("testgroup2",((PdpEntity)o).getGroup().getgroupName());
+ }
+ em.close();
+
+ group = dbd.getNewTransaction();
+ try{
+ OnapPDPGroup groupToDelete = new StdPDPGroup(PolicyDBDao.createNewPDPGroupId("testgroup2"),Paths.get("/"));
+ OnapPDPGroup groupToMoveTo = null;
+ group.deleteGroup(groupToDelete, groupToMoveTo,"testuser");
+ group.commitTransaction();
+ Assert.fail();
+ } catch(PolicyDBException pe){
+ //good, can't delete group with pdps
+ group.rollbackTransaction();
+ } catch(Exception e){
+ group.rollbackTransaction();
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+
+ //update group
+ OnapPDPGroup pdpGroup = new StdPDPGroup("testgroup2", false, "newtestgroup2", "this is my new description", Paths.get("/"));
+ group = dbd.getNewTransaction();
+ try{
+ group.updateGroup(pdpGroup, "testuser");
+ group.commitTransaction();
+ }catch (Exception e){
+ logger.error("Exception Occured"+e);
+ group.rollbackTransaction();
+ Assert.fail();
+ }
+ em = emf.createEntityManager();
+ getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted");
+ getGroup.setParameter("groupId", "newtestgroup2");
+ getGroup.setParameter("deleted", false);
+ groups = getGroup.getResultList();
+ if(groups.size() != 1){
+ System.out.println("Group size: "+groups.size());
+ Assert.fail();
+ }
+ em.close();
+ em = emf.createEntityManager();
+ getGroup = em.createQuery("SELECT g FROM GroupEntity g WHERE g.groupId=:groupId AND g.deleted=:deleted");
+ getGroup.setParameter("groupId", "testgroup2");
+ getGroup.setParameter("deleted", false);
+ groups = getGroup.getResultList();
+ if(groups.size() != 0){
+ System.out.println("Group size: "+groups.size());
+ Assert.fail();
+ }
+ em.close();
+ }
+
+ @Ignore
+ @Test
+ public void threadingStabilityTest(){
+ if(logger.isDebugEnabled()){
+ logger.debug("\n\n****************************"
+ + "threadingStabilityTest() entry"
+ + "******************************\n\n");
+ }
+
+ PolicyDBDaoTransaction t = dbd.getNewTransaction();
+ Assert.assertTrue(t.isTransactionOpen());
+ try {
+ //Add 1000 ms to the timeout just to be sure it actually times out
+ int sleepTime = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)) + 1000;
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n sleepTime = " + sleepTime
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ Thread.sleep(sleepTime);
+ } catch (InterruptedException e) {
+ logger.error("Exception Occured"+e);
+ }
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n Assert.assertFalse(t.isTransactionOpen() = " + t.isTransactionOpen() + ")"
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ Assert.assertFalse(t.isTransactionOpen());
+
+
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n a = dbd.getNewTransaction() "
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ PolicyDBDaoTransaction a = dbd.getNewTransaction();
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n Assert.assertTrue(a.isTransactionOpen() = " + a.isTransactionOpen() + ")"
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ Assert.assertTrue(a.isTransactionOpen());
+
+ try {
+ //Add 1000 ms to the timeout just to be sure it actually times out
+ int sleepTime = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT)) + 1000;
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n sleepTime = " + sleepTime
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ Thread.sleep(sleepTime);
+ } catch (InterruptedException e) {
+ logger.error("Exception Occured"+e);
+ }
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n b = dbd.getNewTransaction() "
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ PolicyDBDaoTransaction b = dbd.getNewTransaction();
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n Assert.assertFalse(a.isTransactionOpen() = " + a.isTransactionOpen() + ")"
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ Assert.assertFalse(a.isTransactionOpen());
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n Assert.assertTrue(b.isTransactionOpen() = " + b.isTransactionOpen() + ")"
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ Assert.assertTrue(b.isTransactionOpen());
+ b.close();
+
+
+
+ //Now let's test the transaction wait time timeout. Shorten the wait time to 1000 ms
+ System.setProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT,"1000");
+ //And let's lengthen the transaction timeout to 5000 ms
+ System.setProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT,"5000");
+ //get a transacton
+ PolicyDBDaoTransaction t1 = dbd.getNewTransaction();
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n Assert.assertTrue(t1.isTransactionOpen() = " + t1.isTransactionOpen() + ")"
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ Assert.assertTrue(t1.isTransactionOpen());
+ //while it is open, get another from a different DB Dao so it will not collide on the synchronized code segment
+ //but will collide at the DB. Remember that the wait time is only 1000 ms
+ try {
+ //Now the 2nd transaction has a wait timeout in 1000 ms
+ PolicyDBDaoTransaction t2 = dbd2.getNewTransaction();
+ /*
+ * Give it plenty of time to time out the second transaction
+ * It will actually hang right here until it either gets the lock from the DB or the
+ * request for the DB lock times out. The timers are very sloppy so, I have given
+ * this plenty of leeway.
+ */
+
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n Thread.sleep(3000)"
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ Thread.sleep(3000);
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n Assert.assertTrue(t1.isTransactionOpen() = " + t1.isTransactionOpen() + ")"
+ + "\n Assert.assertFalse(t2.isTransactionOpen() = " + t2.isTransactionOpen() + ")"
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ //Assert.assertTrue(t1.isTransactionOpen());
+ //Assert.assertFalse(t2.isTransactionOpen());
+
+ Assert.fail("\n\nTransaction timeout of 1000 ms exceeded without a PersistenceException\n\n");
+ } catch (PersistenceException e) {
+ //success
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() "
+ + "\n SUCCESS! Transaction Wait Timeout worked!"
+ + "\n Caught PersistenceException = " + e
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ } catch (Exception e) {
+ // failure due to some other reason
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nPolicyDBDaoTest.threadingStabilityTest() FAILURE"
+ + "\n Caught Exception = " + e
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ logger.error("Exception Occured"+e);
+ Assert.fail();
+ }
+
+ if(logger.isDebugEnabled()){
+ Date date= new java.util.Date();
+ logger.debug("\n\nthreadingStabilityTest() exit"
+ + "\n TimeStamp = " + date.getTime()
+ + "\n\n");
+ }
+ }
} \ No newline at end of file
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java
index 6fa480c72..efb13b5a0 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java
@@ -46,117 +46,117 @@ import org.springframework.mock.web.MockHttpServletResponse;
public class ActionPolicyDictionaryControllerTest {
- private static Logger logger = FlexLogger.getLogger(ActionPolicyDictionaryControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private ActionPolicyDictionaryController controller = null;
- private MockHttpServletResponse response = null;
+ private static Logger logger = FlexLogger.getLogger(ActionPolicyDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private ActionPolicyDictionaryController controller = null;
+ private MockHttpServletResponse response = null;
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- commonClassDao = Mockito.mock(CommonClassDao.class);
- List<String> data = new ArrayList<>();
- List<Object> objectData = new ArrayList<>();
- data.add("Test");
-
- UserInfo userInfo = new UserInfo();
- userInfo.setUserLoginId("Test");
- userInfo.setUserName("Test");
-
- ActionPolicyDict actionData = new ActionPolicyDict();
- actionData.setAttributeName("Test");
- assertTrue("Test".equals(actionData.getAttributeName()));
- actionData.setBody("Test");
- assertTrue("Test".equals(actionData.getBody()));
- actionData.setCreatedDate(new Date());
- assertTrue(actionData.getCreatedDate()!= null);
- actionData.setModifiedDate(new Date());
- assertTrue(actionData.getModifiedDate()!= null);
- actionData.setHeader("Test");
- assertTrue("Test".equals(actionData.getHeader()));
- actionData.setMethod("POST");
- assertTrue("POST".equals(actionData.getMethod()));
- actionData.setType("Test");
- assertTrue("Test".equals(actionData.getType()));
- actionData.setUrl("http://test.com");
- assertTrue("http://test.com".equals(actionData.getUrl()));
- actionData.setUserCreatedBy(userInfo);
- assertTrue(actionData.getUserCreatedBy()!= null);
- actionData.setUserModifiedBy(userInfo);
- assertTrue(actionData.getUserModifiedBy()!= null);
-
- objectData.add(actionData);
- when(commonClassDao.getDataByColumn(ActionPolicyDict.class, "attributeName")).thenReturn(data);
- when(commonClassDao.getData(ActionPolicyDict.class)).thenReturn(objectData);
- doNothing().when(commonClassDao).delete(new ActionPolicyDict());
- doNothing().when(commonClassDao).save(new ActionPolicyDict());
- controller = new ActionPolicyDictionaryController();
- controller.setCommonClassDao(commonClassDao);
- request = Mockito.mock(HttpServletRequest.class);
- response = new MockHttpServletResponse();
- new DictionaryUtils(commonClassDao);
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+ List<String> data = new ArrayList<>();
+ List<Object> objectData = new ArrayList<>();
+ data.add("Test");
+
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+
+ ActionPolicyDict actionData = new ActionPolicyDict();
+ actionData.setAttributeName("Test");
+ assertTrue("Test".equals(actionData.getAttributeName()));
+ actionData.setBody("Test");
+ assertTrue("Test".equals(actionData.getBody()));
+ actionData.setCreatedDate(new Date());
+ assertTrue(actionData.getCreatedDate()!= null);
+ actionData.setModifiedDate(new Date());
+ assertTrue(actionData.getModifiedDate()!= null);
+ actionData.setHeader("Test");
+ assertTrue("Test".equals(actionData.getHeader()));
+ actionData.setMethod("POST");
+ assertTrue("POST".equals(actionData.getMethod()));
+ actionData.setType("Test");
+ assertTrue("Test".equals(actionData.getType()));
+ actionData.setUrl("http://test.com");
+ assertTrue("http://test.com".equals(actionData.getUrl()));
+ actionData.setUserCreatedBy(userInfo);
+ assertTrue(actionData.getUserCreatedBy()!= null);
+ actionData.setUserModifiedBy(userInfo);
+ assertTrue(actionData.getUserModifiedBy()!= null);
+
+ objectData.add(actionData);
+ when(commonClassDao.getDataByColumn(ActionPolicyDict.class, "attributeName")).thenReturn(data);
+ when(commonClassDao.getData(ActionPolicyDict.class)).thenReturn(objectData);
+ doNothing().when(commonClassDao).delete(new ActionPolicyDict());
+ doNothing().when(commonClassDao).save(new ActionPolicyDict());
+ controller = new ActionPolicyDictionaryController();
+ controller.setCommonClassDao(commonClassDao);
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ new DictionaryUtils(commonClassDao);
DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
mock(DictionaryUtils.class);
- logger.info("setUp: exit");
- }
-
- @Test
- public void testGetActionEntitybyName(){
- controller.getActionEntitybyName(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetActionPolicyDictionaryEntityData(){
- controller.getActionPolicyDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testSaveActionPolicyDictionary(){
- jsonString = "{\"actionPolicyDictionaryData\":{\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http://test.com\"},\"userid\":\"demo\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveActionPolicyDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryData"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdateActionPolicyDictionary(){
- jsonString = "{\"actionPolicyDictionaryData\":{\"id\":1,\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http://test.com\"},\"userid\":\"demo\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveActionPolicyDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryData"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemoveActionPolicyDictionary(){
- jsonString = "{\"data\":{\"$$hashKey\":\"uiGrid-003S\",\"attributeName\":\"Test\",\"body\":\"{}\",\"createdDate\":1518195117000,\"description\":\"test\",\"header\":\"test=12\",\"id\":1,\"method\":\"GET\",\"modifiedDate\":1518195489000,\"type\":\"REST\",\"url\":\"http://test.com\",\"userCreatedBy\":{\"userLoginId\":\"demo\",\"userName\":\"Demo\"},\"userModifiedBy\":{\"userLoginId\":\"demo\",\"userName\":\"Demo\"}}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeActionPolicyDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
+ logger.info("setUp: exit");
+ }
+
+ @Test
+ public void testGetActionEntitybyName(){
+ controller.getActionEntitybyName(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetActionPolicyDictionaryEntityData(){
+ controller.getActionPolicyDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testSaveActionPolicyDictionary(){
+ jsonString = "{\"actionPolicyDictionaryData\":{\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http://test.com\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveActionPolicyDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateActionPolicyDictionary(){
+ jsonString = "{\"actionPolicyDictionaryData\":{\"id\":1,\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http://test.com\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveActionPolicyDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveActionPolicyDictionary(){
+ jsonString = "{\"data\":{\"$$hashKey\":\"uiGrid-003S\",\"attributeName\":\"Test\",\"body\":\"{}\",\"createdDate\":1518195117000,\"description\":\"test\",\"header\":\"test=12\",\"id\":1,\"method\":\"GET\",\"modifiedDate\":1518195489000,\"type\":\"REST\",\"url\":\"http://test.com\",\"userCreatedBy\":{\"userLoginId\":\"demo\",\"userName\":\"Demo\"},\"userModifiedBy\":{\"userLoginId\":\"demo\",\"userName\":\"Demo\"}}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeActionPolicyDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryControllerTest.java
index 0a60e1831..d34e505ba 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryControllerTest.java
@@ -46,217 +46,217 @@ import org.springframework.mock.web.MockHttpServletResponse;
public class BRMSDictionaryControllerTest {
- private static Logger logger = FlexLogger.getLogger(BRMSDictionaryControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private BRMSDictionaryController controller = null;
- private MockHttpServletResponse response = null;
+ private static Logger logger = FlexLogger.getLogger(BRMSDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private BRMSDictionaryController controller = null;
+ private MockHttpServletResponse response = null;
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- commonClassDao = Mockito.mock(CommonClassDao.class);
- UserInfo userInfo = new UserInfo();
- userInfo.setUserLoginId("testUserId");
- userInfo.setUserName("John");
- when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing")).thenReturn(userInfo);
- List<String> brms = new ArrayList<String>();
- brms.add("BRMS-Model");
- when(commonClassDao.getDataByColumn(BRMSParamTemplate.class, "name")).thenReturn(brms);
- doNothing().when(commonClassDao).delete(new BRMSParamTemplate());
- doNothing().when(commonClassDao).save(new BRMSParamTemplate());
- controller = new BRMSDictionaryController();
- request = Mockito.mock(HttpServletRequest.class);
- response = new MockHttpServletResponse();
- new DictionaryUtils(commonClassDao);
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("testUserId");
+ userInfo.setUserName("John");
+ when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing")).thenReturn(userInfo);
+ List<String> brms = new ArrayList<String>();
+ brms.add("BRMS-Model");
+ when(commonClassDao.getDataByColumn(BRMSParamTemplate.class, "name")).thenReturn(brms);
+ doNothing().when(commonClassDao).delete(new BRMSParamTemplate());
+ doNothing().when(commonClassDao).save(new BRMSParamTemplate());
+ controller = new BRMSDictionaryController();
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ new DictionaryUtils(commonClassDao);
DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
mock(DictionaryUtils.class);
- logger.info("setUp: exit");
- }
+ logger.info("setUp: exit");
+ }
- @Test
- public void testGetBRMSParamDictionaryByNameEntityData(){
- logger.info("testGetBRMSParamDictionaryByNameEntityData: Entering");
- BRMSDictionaryController.setCommonClassDao(commonClassDao);
- controller.getBRMSParamDictionaryByNameEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
- logger.info("testGetBRMSParamDictionaryByNameEntityData: exit");
- }
+ @Test
+ public void testGetBRMSParamDictionaryByNameEntityData(){
+ logger.info("testGetBRMSParamDictionaryByNameEntityData: Entering");
+ BRMSDictionaryController.setCommonClassDao(commonClassDao);
+ controller.getBRMSParamDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+ logger.info("testGetBRMSParamDictionaryByNameEntityData: exit");
+ }
- @Test
- public void testGetBRMSParamDictionaryEntityData() {
- logger.info("testGetBRMSParamDictionaryEntityData: Entering");
- controller.getBRMSParamDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
- logger.info("testGetBRMSParamDictionaryEntityData: exit");
- }
+ @Test
+ public void testGetBRMSParamDictionaryEntityData() {
+ logger.info("testGetBRMSParamDictionaryEntityData: Entering");
+ controller.getBRMSParamDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+ logger.info("testGetBRMSParamDictionaryEntityData: exit");
+ }
- @Test
- public void testSaveBRMSParamDictionary() {
- logger.info("testSaveBRMSParamDictionary: Entering");
- jsonString = "{\"brmsParamDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveBRMSParamDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryData"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- logger.info("testSaveBRMSParamDictionary: exit");
- }
+ @Test
+ public void testSaveBRMSParamDictionary() {
+ logger.info("testSaveBRMSParamDictionary: Entering");
+ jsonString = "{\"brmsParamDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveBRMSParamDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryData"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ logger.info("testSaveBRMSParamDictionary: exit");
+ }
- @Test
- public void testRemoveBRMSParamDictionary() {
- logger.info("testRemoveBRMSParamDictionary: Entering");
- jsonString = "{\"data\": {\"ruleName\": \"test\",\"rule\": \"test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeBRMSParamDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryDatas"));
- } catch (Exception e) {
- fail("Exception: " + e);
- }
- logger.info("testRemoveBRMSParamDictionary: exit");
- }
+ @Test
+ public void testRemoveBRMSParamDictionary() {
+ logger.info("testRemoveBRMSParamDictionary: Entering");
+ jsonString = "{\"data\": {\"ruleName\": \"test\",\"rule\": \"test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeBRMSParamDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryDatas"));
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+ logger.info("testRemoveBRMSParamDictionary: exit");
+ }
- @Test
- public void testGetBRMSDependencyDictionaryByNameEntityData(){
- logger.info("testGetBRMSDependencyDictionaryByNameEntityData: Entering");
- BRMSDictionaryController.setCommonClassDao(commonClassDao);
- controller.getBRMSDependencyDictionaryByNameEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
- logger.info("testGetBRMSDependencyDictionaryByNameEntityData: exit");
- }
+ @Test
+ public void testGetBRMSDependencyDictionaryByNameEntityData(){
+ logger.info("testGetBRMSDependencyDictionaryByNameEntityData: Entering");
+ BRMSDictionaryController.setCommonClassDao(commonClassDao);
+ controller.getBRMSDependencyDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+ logger.info("testGetBRMSDependencyDictionaryByNameEntityData: exit");
+ }
- @Test
- public void testGetBRMSDependencyDictionaryEntityData(){
- logger.info("testGetBRMSDependencyDictionaryEntityData: Entering");
- BRMSDictionaryController.setCommonClassDao(commonClassDao);
- controller.getBRMSDependencyDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
+ @Test
+ public void testGetBRMSDependencyDictionaryEntityData(){
+ logger.info("testGetBRMSDependencyDictionaryEntityData: Entering");
+ BRMSDictionaryController.setCommonClassDao(commonClassDao);
+ controller.getBRMSDependencyDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
- logger.info("testGetBRMSDependencyDictionaryEntityData: exit");
- }
+ logger.info("testGetBRMSDependencyDictionaryEntityData: exit");
+ }
- @Test
- public void testSaveBRMSDependencyDictionary() {
- logger.info("testSaveBRMSDependencyDictionary: Entering");
- jsonString = "{\"brmsDependencyDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveBRMSDependencyDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryData"));
- } catch (Exception e) {
- fail("Exception: " + e);
- }
- logger.info("testSaveBRMSDependencyDictionary: exit");
- }
+ @Test
+ public void testSaveBRMSDependencyDictionary() {
+ logger.info("testSaveBRMSDependencyDictionary: Entering");
+ jsonString = "{\"brmsDependencyDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveBRMSDependencyDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryData"));
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+ logger.info("testSaveBRMSDependencyDictionary: exit");
+ }
- @Test
- public void testRemoveBRMSDependencyDictionary() {
- logger.info("testRemoveBRMSDependencyDictionary: Entering");
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
- jsonString = "{\"data\": {\"ruleName\": \"test\",\"rule\": \"test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeBRMSDependencyDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryDatas"));
- } catch (Exception e) {
- fail("Exception: " + e);
- }
- logger.info("testRemoveBRMSDependencyDictionary: exit");
- }
+ @Test
+ public void testRemoveBRMSDependencyDictionary() {
+ logger.info("testRemoveBRMSDependencyDictionary: Entering");
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+ jsonString = "{\"data\": {\"ruleName\": \"test\",\"rule\": \"test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeBRMSDependencyDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryDatas"));
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+ logger.info("testRemoveBRMSDependencyDictionary: exit");
+ }
- @Test
- public void testGetBRMSControllerDictionaryByNameEntityData(){
- logger.info("testGetBRMSControllerDictionaryByNameEntityData: Entering");
- MockHttpServletResponse response = new MockHttpServletResponse();
- BRMSDictionaryController.setCommonClassDao(commonClassDao);
- controller.getBRMSControllerDictionaryByNameEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
- logger.info("testGetBRMSControllerDictionaryByNameEntityData: exit");
- }
+ @Test
+ public void testGetBRMSControllerDictionaryByNameEntityData(){
+ logger.info("testGetBRMSControllerDictionaryByNameEntityData: Entering");
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ BRMSDictionaryController.setCommonClassDao(commonClassDao);
+ controller.getBRMSControllerDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+ logger.info("testGetBRMSControllerDictionaryByNameEntityData: exit");
+ }
- @Test
- public void testGetBRMSControllerDictionaryEntityData(){
- logger.info("testGetBRMSControllerDictionaryEntityData: Entering");
- MockHttpServletResponse response = new MockHttpServletResponse();
- BRMSDictionaryController.setCommonClassDao(commonClassDao);
- controller.getBRMSControllerDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
- logger.info("testGetBRMSControllerDictionaryEntityData: exit");
- }
+ @Test
+ public void testGetBRMSControllerDictionaryEntityData(){
+ logger.info("testGetBRMSControllerDictionaryEntityData: Entering");
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ BRMSDictionaryController.setCommonClassDao(commonClassDao);
+ controller.getBRMSControllerDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+ logger.info("testGetBRMSControllerDictionaryEntityData: exit");
+ }
- @Test
- public void testSaveBRMSControllerDictionary() {
- logger.info("testSaveBRMSControllerDictionary: Entering");
+ @Test
+ public void testSaveBRMSControllerDictionary() {
+ logger.info("testSaveBRMSControllerDictionary: Entering");
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
- jsonString = "{\"brmsControllerDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveBRMSControllerDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryData"));
- } catch (Exception e) {
- fail("Exception: " + e);
- }
- logger.info("testSaveBRMSControllerDictionary: exit");
- }
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+ jsonString = "{\"brmsControllerDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveBRMSControllerDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryData"));
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+ logger.info("testSaveBRMSControllerDictionary: exit");
+ }
- @Test
- public void testRemoveBRMSControllerDictionary() {
- logger.info("testRemoveBRMSControllerDictionary: Entering");
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
- jsonString = "{\"data\": {\"ruleName\": \"test\",\"rule\": \"test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeBRMSControllerDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryDatas"));
+ @Test
+ public void testRemoveBRMSControllerDictionary() {
+ logger.info("testRemoveBRMSControllerDictionary: Entering");
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+ jsonString = "{\"data\": {\"ruleName\": \"test\",\"rule\": \"test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeBRMSControllerDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryDatas"));
- } catch (Exception e) {
- fail("Exception: " + e);
- }
- logger.info("testRemoveBRMSControllerDictionary: exit");
- }
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+ logger.info("testRemoveBRMSControllerDictionary: exit");
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java
index ea1ea3b88..f530b4c62 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java
@@ -49,399 +49,399 @@ import org.onap.policy.rest.jpa.VarbindDictionary;
import org.springframework.mock.web.MockHttpServletResponse;
public class ClosedLoopDictionaryControllerTest {
-
- private static Logger logger = FlexLogger.getLogger(ClosedLoopDictionaryControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private ClosedLoopDictionaryController controller = null;
- private MockHttpServletResponse response = null;
- private UserInfo userInfo;
- private List<String> data;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- commonClassDao = Mockito.mock(CommonClassDao.class);
-
- data = new ArrayList<>();
- data.add("Test");
-
- userInfo = new UserInfo();
- userInfo.setUserLoginId("Test");
- userInfo.setUserName("Test");
-
- doNothing().when(commonClassDao).delete(new VSCLAction());
- doNothing().when(commonClassDao).save(new VSCLAction());
-
- controller = new ClosedLoopDictionaryController();
- controller.setCommonClassDao(commonClassDao);
-
- request = Mockito.mock(HttpServletRequest.class);
- response = new MockHttpServletResponse();
- new DictionaryUtils(commonClassDao);
+
+ private static Logger logger = FlexLogger.getLogger(ClosedLoopDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private ClosedLoopDictionaryController controller = null;
+ private MockHttpServletResponse response = null;
+ private UserInfo userInfo;
+ private List<String> data;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+
+ data = new ArrayList<>();
+ data.add("Test");
+
+ userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+
+ doNothing().when(commonClassDao).delete(new VSCLAction());
+ doNothing().when(commonClassDao).save(new VSCLAction());
+
+ controller = new ClosedLoopDictionaryController();
+ controller.setCommonClassDao(commonClassDao);
+
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ new DictionaryUtils(commonClassDao);
DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
mock(DictionaryUtils.class);
- logger.info("setUp: exit");
- }
-
- @Test
- public void testGetVSCLActionDictionaryByNameEntityData(){
- when(commonClassDao.getDataByColumn(VSCLAction.class, "vsclaction")).thenReturn(data);
- controller.getVSCLActionDictionaryByNameEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetVSCLActionDictionaryEntityData(){
- when(commonClassDao.getData(VSCLAction.class)).thenReturn(new ArrayList<>());
- controller.getVSCLActionDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetVNFTypeDictionaryByNameEntityData(){
- when(commonClassDao.getDataByColumn(VNFType.class, "vnftype")).thenReturn(data);
- controller.getVNFTypeDictionaryByNameEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetVNFTypeDictionaryEntityData(){
- when(commonClassDao.getData(VNFType.class)).thenReturn(new ArrayList<>());
- controller.getVNFTypeDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetPEPOptionsDictionaryByNameEntityData(){
- when(commonClassDao.getDataByColumn(PEPOptions.class, "pepName")).thenReturn(data);
- controller.getPEPOptionsDictionaryByNameEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetPEPOptionsDictionaryEntityData(){
- when(commonClassDao.getData(PEPOptions.class)).thenReturn(new ArrayList<>());
- controller.getPEPOptionsDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetVarbindDictionaryByNameEntityData(){
- when(commonClassDao.getDataByColumn(VarbindDictionary.class, "varbindName")).thenReturn(data);
- controller.getVarbindDictionaryByNameEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetVarbindDictionaryEntityData(){
- when(commonClassDao.getData(VarbindDictionary.class)).thenReturn(new ArrayList<>());
- controller.getVarbindDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetClosedLoopServiceDictionaryByNameEntityData(){
- when(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, "serviceName")).thenReturn(data);
- controller.getClosedLoopServiceDictionaryByNameEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetClosedLoopServiceDictionaryEntityData(){
- when(commonClassDao.getData(ClosedLoopD2Services.class)).thenReturn(new ArrayList<>());
- controller.getClosedLoopServiceDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetClosedLoopSiteDictionaryByNameEntityData(){
- when(commonClassDao.getDataByColumn(ClosedLoopSite.class, "siteName")).thenReturn(data);
- controller.getClosedLoopSiteDictionaryByNameEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetClosedLoopSiteDictionaryEntityData(){
- when(commonClassDao.getData(ClosedLoopSite.class)).thenReturn(new ArrayList<>());
- controller.getClosedLoopSiteDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testSaveVSCLAction(){
- jsonString = "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"description\":\"test\",\"vsclaction\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveVSCLAction(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdateVSCLAction(){
- jsonString = "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveVSCLAction(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemoveVSCLAction(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeVSCLAction(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testSaveVnfType(){
- jsonString = "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"description\":\"test\",\"vnftype\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveVnfType(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdateVnfType(){
- jsonString = "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveVnfType(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemoveVnfType(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeVnfType(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testSavePEPOptions(){
- jsonString = "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePEPOptions(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdatePEPOptions(){
- jsonString = "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\",\"id\":1},\"userid\":\"demo\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePEPOptions(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemovePEPOptions(){
- jsonString = "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removePEPOptions(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testSaveServiceType(){
- jsonString = "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"description\":\"test\",\"serviceName\":\"Test\",\"id\":1}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveServiceType(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdateServiceType(){
- jsonString = "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveServiceType(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemoveServiceType(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeServiceType(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testSaveSiteType(){
- jsonString = "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"description\":\"test\",\"siteName\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveSiteType(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdateSiteType(){
- jsonString = "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveSiteType(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemoveSiteType(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeSiteType(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testSaveVarbind(){
- jsonString = "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"description\":\"test\",\"varbindName\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveVarbind(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdateVarbind(){
- jsonString = "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveVarbind(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemoveVarbind(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeVarbind(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
+ logger.info("setUp: exit");
+ }
+
+ @Test
+ public void testGetVSCLActionDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(VSCLAction.class, "vsclaction")).thenReturn(data);
+ controller.getVSCLActionDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetVSCLActionDictionaryEntityData(){
+ when(commonClassDao.getData(VSCLAction.class)).thenReturn(new ArrayList<>());
+ controller.getVSCLActionDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetVNFTypeDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(VNFType.class, "vnftype")).thenReturn(data);
+ controller.getVNFTypeDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetVNFTypeDictionaryEntityData(){
+ when(commonClassDao.getData(VNFType.class)).thenReturn(new ArrayList<>());
+ controller.getVNFTypeDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPEPOptionsDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(PEPOptions.class, "pepName")).thenReturn(data);
+ controller.getPEPOptionsDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPEPOptionsDictionaryEntityData(){
+ when(commonClassDao.getData(PEPOptions.class)).thenReturn(new ArrayList<>());
+ controller.getPEPOptionsDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetVarbindDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(VarbindDictionary.class, "varbindName")).thenReturn(data);
+ controller.getVarbindDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetVarbindDictionaryEntityData(){
+ when(commonClassDao.getData(VarbindDictionary.class)).thenReturn(new ArrayList<>());
+ controller.getVarbindDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetClosedLoopServiceDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, "serviceName")).thenReturn(data);
+ controller.getClosedLoopServiceDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetClosedLoopServiceDictionaryEntityData(){
+ when(commonClassDao.getData(ClosedLoopD2Services.class)).thenReturn(new ArrayList<>());
+ controller.getClosedLoopServiceDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetClosedLoopSiteDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(ClosedLoopSite.class, "siteName")).thenReturn(data);
+ controller.getClosedLoopSiteDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetClosedLoopSiteDictionaryEntityData(){
+ when(commonClassDao.getData(ClosedLoopSite.class)).thenReturn(new ArrayList<>());
+ controller.getClosedLoopSiteDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testSaveVSCLAction(){
+ jsonString = "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"description\":\"test\",\"vsclaction\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVSCLAction(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateVSCLAction(){
+ jsonString = "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVSCLAction(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveVSCLAction(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeVSCLAction(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSaveVnfType(){
+ jsonString = "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"description\":\"test\",\"vnftype\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVnfType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateVnfType(){
+ jsonString = "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVnfType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveVnfType(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeVnfType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSavePEPOptions(){
+ jsonString = "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePEPOptions(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdatePEPOptions(){
+ jsonString = "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\",\"id\":1},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePEPOptions(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemovePEPOptions(){
+ jsonString = "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removePEPOptions(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSaveServiceType(){
+ jsonString = "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"description\":\"test\",\"serviceName\":\"Test\",\"id\":1}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveServiceType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateServiceType(){
+ jsonString = "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveServiceType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveServiceType(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeServiceType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSaveSiteType(){
+ jsonString = "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"description\":\"test\",\"siteName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveSiteType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateSiteType(){
+ jsonString = "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveSiteType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveSiteType(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeSiteType(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSaveVarbind(){
+ jsonString = "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"description\":\"test\",\"varbindName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVarbind(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateVarbind(){
+ jsonString = "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveVarbind(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveVarbind(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeVarbind(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java
index 2e8c63cf8..7910aed11 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java
@@ -40,26 +40,26 @@ import org.onap.policy.rest.dao.CommonClassDao;
import org.springframework.mock.web.MockHttpServletResponse;
public class DecisionPolicyDictionaryControllerTest {
- private static Logger logger = FlexLogger.getLogger(DecisionPolicyDictionaryControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private DecisionPolicyDictionaryController controller = null;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
+ private static Logger logger = FlexLogger.getLogger(DecisionPolicyDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private DecisionPolicyDictionaryController controller = null;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
commonClassDao = Mockito.mock(CommonClassDao.class);
- HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+ HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- jsonString = "{\"attributeDictionaryDatas\": {\"error\": \"\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"ecompName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ jsonString = "{\"attributeDictionaryDatas\": {\"error\": \"\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"ecompName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
BufferedReader br = new BufferedReader(new StringReader(jsonString));
@@ -71,206 +71,206 @@ public class DecisionPolicyDictionaryControllerTest {
DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
mock(DictionaryUtils.class);
logger.info("setUp: exit");
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testGetSettingsDictionaryByNameEntityData() {
- logger.info("testGetSettingsDictionaryByNameEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getSettingsDictionaryByNameEntityData(request, response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- logger.error("Exception Occured"+e);
- fail("Exception: " + e);
- }
-
- logger.info("testGetSettingsDictionaryByNameEntityData: exit");
-
- }
-
- @Test
- public void testGetSettingsDictionaryEntityData() {
- logger.info("testGetSettingsDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getSettingsDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- logger.error("Exception Occured"+e);
- fail("Exception: " + e);
- }
-
- logger.info("testGetSettingsDictionaryEntityData: exit");
-
- }
-
- @Test
- public void testSaveSettingsDictionary() {
- logger.info("testSaveSettingsDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testGetSettingsDictionaryByNameEntityData() {
+ logger.info("testGetSettingsDictionaryByNameEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getSettingsDictionaryByNameEntityData(request, response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ logger.error("Exception Occured"+e);
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetSettingsDictionaryByNameEntityData: exit");
+
+ }
+
+ @Test
+ public void testGetSettingsDictionaryEntityData() {
+ logger.info("testGetSettingsDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getSettingsDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ logger.error("Exception Occured"+e);
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetSettingsDictionaryEntityData: exit");
+
+ }
+
+ @Test
+ public void testSaveSettingsDictionary() {
+ logger.info("testSaveSettingsDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
- try {
- // mock the getReader() call
- jsonString = "{\"settingsDictionaryData\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"test\",\"priority\":\"High\"}, \"userid\":\"test\"}";
-
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.saveSettingsDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas"));
-
- } catch (Exception e) {
- logger.error("Exception Occured"+e);
- fail("Exception: " + e);
- }
-
- logger.info("testSaveSettingsDictionary: exit");
-
- }
-
- @Test
- public void testRemoveSettingsDictionary() {
- logger.info("testRemoveSettingsDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"ecompName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.removeSettingsDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas"));
-
- } catch (Exception e) {
- logger.error("Exception Occured"+e);
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveSettingsDictionary: exit");
-
- }
-
- @Test
- public void testGetRainyDayDictionaryByNameEntityData() {
- logger.info("testGetRainyDayDictionaryByNameEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getRainyDayDictionaryByNameEntityData(request, response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- logger.error("Exception Occured"+e);
- fail("Exception: " + e);
- }
-
- logger.info("testGetRainyDayDictionaryByNameEntityData: exit");
-
- }
-
- @Test
- public void testGetRainyDayDictionaryEntityData() {
- logger.info("testGetRainyDayDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getRainyDayDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- logger.error("Exception Occured"+e);
- fail("Exception: " + e);
- }
-
- logger.info("testGetRainyDayDictionaryEntityData: exit");
-
- }
-
- @Test
- public void testSaveRainyDayDictionary() {
- logger.info("testSaveRainyDayDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
+ try {
+ // mock the getReader() call
+ jsonString = "{\"settingsDictionaryData\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"test\",\"priority\":\"High\"}, \"userid\":\"test\"}";
+
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.saveSettingsDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas"));
+
+ } catch (Exception e) {
+ logger.error("Exception Occured"+e);
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveSettingsDictionary: exit");
+
+ }
+
+ @Test
+ public void testRemoveSettingsDictionary() {
+ logger.info("testRemoveSettingsDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"ecompName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.removeSettingsDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas"));
+
+ } catch (Exception e) {
+ logger.error("Exception Occured"+e);
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveSettingsDictionary: exit");
+
+ }
+
+ @Test
+ public void testGetRainyDayDictionaryByNameEntityData() {
+ logger.info("testGetRainyDayDictionaryByNameEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getRainyDayDictionaryByNameEntityData(request, response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ logger.error("Exception Occured"+e);
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetRainyDayDictionaryByNameEntityData: exit");
+
+ }
+
+ @Test
+ public void testGetRainyDayDictionaryEntityData() {
+ logger.info("testGetRainyDayDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getRainyDayDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ logger.error("Exception Occured"+e);
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetRainyDayDictionaryEntityData: exit");
+
+ }
+
+ @Test
+ public void testSaveRainyDayDictionary() {
+ logger.info("testSaveRainyDayDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
- try {
- // mock the getReader() call
- jsonString = "{\"rainyDayDictionaryData\":{\"bbid\":\"BB2\",\"workstep\":\"1\",\"userDataTypeValues\":[{\"$$hashKey\":\"object:233\",\"treatment\":\"test1\"},{\"$$hashKey\":\"object:239\",\"treatment\":\"test2\"}]},\"userid\":\"mm117s\"}";
-
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.saveRainyDayDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas"));
-
- } catch (Exception e) {
- logger.error("Exception Occured"+e);
- fail("Exception: " + e);
- }
-
- logger.info("testSaveRainyDayDictionary: exit");
-
- }
-
- @Test
- public void testRemoveRainyDayDictionary() {
- logger.info("testRemoveRainyDayDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"ecompName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.removeRainyDayDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas"));
-
- } catch (Exception e) {
- logger.error("Exception Occured"+e);
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveRainyDayDictionary: exit");
-
- }
+ try {
+ // mock the getReader() call
+ jsonString = "{\"rainyDayDictionaryData\":{\"bbid\":\"BB2\",\"workstep\":\"1\",\"userDataTypeValues\":[{\"$$hashKey\":\"object:233\",\"treatment\":\"test1\"},{\"$$hashKey\":\"object:239\",\"treatment\":\"test2\"}]},\"userid\":\"mm117s\"}";
+
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.saveRainyDayDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas"));
+
+ } catch (Exception e) {
+ logger.error("Exception Occured"+e);
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveRainyDayDictionary: exit");
+
+ }
+
+ @Test
+ public void testRemoveRainyDayDictionary() {
+ logger.info("testRemoveRainyDayDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"ecompName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.removeRainyDayDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas"));
+
+ } catch (Exception e) {
+ logger.error("Exception Occured"+e);
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveRainyDayDictionary: exit");
+
+ }
} \ No newline at end of file
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java
index 5310ddc93..0950b1cfd 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java
@@ -45,124 +45,124 @@ import org.onap.policy.rest.jpa.UserInfo;
import org.springframework.mock.web.MockHttpServletResponse;
public class DescriptiveDictionaryControllerTest {
-
- private static Logger logger = FlexLogger.getLogger(DescriptiveDictionaryControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private DescriptiveDictionaryController controller = null;
- private MockHttpServletResponse response = null;
- private UserInfo userInfo;
- private List<String> data;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- commonClassDao = Mockito.mock(CommonClassDao.class);
-
- data = new ArrayList<>();
- data.add("Test");
-
- userInfo = new UserInfo();
- userInfo.setUserLoginId("Test");
- userInfo.setUserName("Test");
-
- doNothing().when(commonClassDao).delete(new DescriptiveScope());
- doNothing().when(commonClassDao).save(new DescriptiveScope());
-
- controller = new DescriptiveDictionaryController();
- controller.setCommonClassDao(commonClassDao);
-
- request = Mockito.mock(HttpServletRequest.class);
- response = new MockHttpServletResponse();
- new DictionaryUtils(commonClassDao);
+
+ private static Logger logger = FlexLogger.getLogger(DescriptiveDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private DescriptiveDictionaryController controller = null;
+ private MockHttpServletResponse response = null;
+ private UserInfo userInfo;
+ private List<String> data;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+
+ data = new ArrayList<>();
+ data.add("Test");
+
+ userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+
+ doNothing().when(commonClassDao).delete(new DescriptiveScope());
+ doNothing().when(commonClassDao).save(new DescriptiveScope());
+
+ controller = new DescriptiveDictionaryController();
+ controller.setCommonClassDao(commonClassDao);
+
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ new DictionaryUtils(commonClassDao);
DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
mock(DictionaryUtils.class);
- logger.info("setUp: exit");
- }
-
- public List<Object> testDescriptiveScope(){
- List<Object> objectData = new ArrayList<>();
-
- DescriptiveScope data = new DescriptiveScope();
- data.setId(1);
- assertTrue(1 == data.getId());
- data.setScopeName("Test");
- assertTrue("Test".equals(data.getScopeName()));
- data.setDescription("Test");
- assertTrue("Test".equals(data.getDescription()));
- data.setSearch("Test");
- assertTrue("Test".equals(data.getSearch()));
- data.setCreatedDate(new Date());
- assertTrue(data.getCreatedDate()!= null);
- data.setModifiedDate(new Date());
- assertTrue(data.getModifiedDate()!= null);
- data.setUserCreatedBy(userInfo);
- assertTrue(data.getUserCreatedBy()!= null);
- data.setUserModifiedBy(userInfo);
- assertTrue(data.getUserModifiedBy()!= null);
- objectData.add(data);
-
- return objectData;
- }
-
- @Test
- public void testGetDescriptiveDictionaryByNameEntityData(){
- when(commonClassDao.getDataByColumn(DescriptiveScope.class, "descriptiveScopeName")).thenReturn(data);
- controller.getDescriptiveDictionaryByNameEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetDescriptiveDictionaryEntityData(){
- when(commonClassDao.getData(DescriptiveScope.class)).thenReturn(testDescriptiveScope());
- controller.getDescriptiveDictionaryEntityData(response);
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testSaveDescriptiveDictionary(){
- jsonString = "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"search\":\"Test\"},\"userid\":\"demo\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveDescriptiveDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdateDescriptiveDictionary(){
- jsonString = "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"id\":1,\"search\":\"Test\"},\"userid\":\"demo\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveDescriptiveDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemoveDescriptiveDictionary(){
- jsonString = "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"id\":1,\"search\":\"Test\"},\"userid\":\"demo\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeDescriptiveDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
+ logger.info("setUp: exit");
+ }
+
+ public List<Object> testDescriptiveScope(){
+ List<Object> objectData = new ArrayList<>();
+
+ DescriptiveScope data = new DescriptiveScope();
+ data.setId(1);
+ assertTrue(1 == data.getId());
+ data.setScopeName("Test");
+ assertTrue("Test".equals(data.getScopeName()));
+ data.setDescription("Test");
+ assertTrue("Test".equals(data.getDescription()));
+ data.setSearch("Test");
+ assertTrue("Test".equals(data.getSearch()));
+ data.setCreatedDate(new Date());
+ assertTrue(data.getCreatedDate()!= null);
+ data.setModifiedDate(new Date());
+ assertTrue(data.getModifiedDate()!= null);
+ data.setUserCreatedBy(userInfo);
+ assertTrue(data.getUserCreatedBy()!= null);
+ data.setUserModifiedBy(userInfo);
+ assertTrue(data.getUserModifiedBy()!= null);
+ objectData.add(data);
+
+ return objectData;
+ }
+
+ @Test
+ public void testGetDescriptiveDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(DescriptiveScope.class, "descriptiveScopeName")).thenReturn(data);
+ controller.getDescriptiveDictionaryByNameEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetDescriptiveDictionaryEntityData(){
+ when(commonClassDao.getData(DescriptiveScope.class)).thenReturn(testDescriptiveScope());
+ controller.getDescriptiveDictionaryEntityData(response);
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testSaveDescriptiveDictionary(){
+ jsonString = "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"search\":\"Test\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveDescriptiveDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateDescriptiveDictionary(){
+ jsonString = "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"id\":1,\"search\":\"Test\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveDescriptiveDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveDescriptiveDictionary(){
+ jsonString = "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"id\":1,\"search\":\"Test\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeDescriptiveDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
} \ No newline at end of file
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java
index e76ebdf12..89be75f52 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java
@@ -57,16 +57,16 @@ import org.springframework.mock.web.MockHttpServletResponse;
* tasks.
*/
public class DictionaryControllerTest {
-
- private static Logger logger = FlexLogger.getLogger(DictionaryControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private DictionaryController controller = null;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
+
+ private static Logger logger = FlexLogger.getLogger(DictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private DictionaryController controller = null;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
commonClassDao = Mockito.mock(CommonClassDao.class);
MicroServiceModels testData = new MicroServiceModels();
@@ -86,173 +86,173 @@ public class DictionaryControllerTest {
when(commonClassDao.getData(Attribute.class)).thenReturn(listId);
- request = mock(HttpServletRequest.class);
+ request = mock(HttpServletRequest.class);
controller = new DictionaryController(commonClassDao);
new DictionaryUtils(commonClassDao);
DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
mock(DictionaryUtils.class);
logger.info("setUp: exit");
- }
-
- @Test
- public void testGetAttributeDictionaryEntityDatabyAttributeName() {
- logger.info("testGetAttributeDictionaryEntityDatabyAttributeName: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getAttributeDictionaryEntityDatabyAttributeName(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetAttributeDictionaryEntityDatabyAttributeName: exit");
- }
-
- @Test
- public void testGetAttributeDictionaryEntityData() {
- logger.info("testGetAttributeDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getAttributeDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetAttributeDictionaryEntityData: exit");
- }
-
- @Test
- public void testSaveAttributeDictionary() {
- logger.info("testSaveAttributeDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
+ }
+
+ @Test
+ public void testGetAttributeDictionaryEntityDatabyAttributeName() {
+ logger.info("testGetAttributeDictionaryEntityDatabyAttributeName: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getAttributeDictionaryEntityDatabyAttributeName(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetAttributeDictionaryEntityDatabyAttributeName: exit");
+ }
+
+ @Test
+ public void testGetAttributeDictionaryEntityData() {
+ logger.info("testGetAttributeDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getAttributeDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetAttributeDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testSaveAttributeDictionary() {
+ logger.info("testSaveAttributeDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
- try {
- jsonString = "{\"attributeDictionaryData\":{\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"Qwerty\",\"priority\":\"High\",\"userDataTypeValues\":[{\"$$hashKey\":\"object:641\",\"attributeValues\":\"test\",\"id\":\"choice1\"},{\"$$hashKey\":\"object:646\",\"attributeValues\":\"test\",\"id\":\"choice2\"}],\"xacmlId\":\"Qwerty\"},\"userid\":\"demo\"}";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.saveAttributeDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testSaveAttributeDictionary: exit");
- }
-
- @Test
- public void testRemoveAttributeDictionary() {
- logger.info("testRemoveAttributeDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"xacmlId\":\"Test\"}}";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.removeAttributeDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveAttributeDictionary: exit");
- }
-
- @Test
- public void testGetOnapNameDictionaryByNameEntityData() {
- logger.info("testGetOnapNameDictionaryByNameEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getOnapNameDictionaryByNameEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetOnapNameDictionaryByNameEntityData: exit");
- }
-
- @Test
- public void testGetOnapNameDictionaryEntityData() {
- logger.info("testGetOnapNameDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getOnapNameDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetOnapNameDictionaryEntityData: exit");
- }
-
- @Test
- public void testSaveOnapDictionary() {
-
- logger.info("testSaveOnapDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
+ try {
+ jsonString = "{\"attributeDictionaryData\":{\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"Qwerty\",\"priority\":\"High\",\"userDataTypeValues\":[{\"$$hashKey\":\"object:641\",\"attributeValues\":\"test\",\"id\":\"choice1\"},{\"$$hashKey\":\"object:646\",\"attributeValues\":\"test\",\"id\":\"choice2\"}],\"xacmlId\":\"Qwerty\"},\"userid\":\"demo\"}";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.saveAttributeDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveAttributeDictionary: exit");
+ }
+
+ @Test
+ public void testRemoveAttributeDictionary() {
+ logger.info("testRemoveAttributeDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"xacmlId\":\"Test\"}}";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.removeAttributeDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveAttributeDictionary: exit");
+ }
+
+ @Test
+ public void testGetOnapNameDictionaryByNameEntityData() {
+ logger.info("testGetOnapNameDictionaryByNameEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getOnapNameDictionaryByNameEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetOnapNameDictionaryByNameEntityData: exit");
+ }
+
+ @Test
+ public void testGetOnapNameDictionaryEntityData() {
+ logger.info("testGetOnapNameDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getOnapNameDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetOnapNameDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testSaveOnapDictionary() {
+
+ logger.info("testSaveOnapDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
- try {
- jsonString = "{\"userid\":\"demo\",\"onapNameDictionaryData\":{\"description\":\"test\",\"onapName\":\"Test\"}}";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.saveOnapDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testSaveOnapDictionary: exit");
- }
-
- @Test
- public void testRemoveOnapDictionary() {
- logger.info("testRemoveOnapDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"onapName\":\"Test\"}}";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.removeOnapDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveOnapDictionary: exit");
- }
+ try {
+ jsonString = "{\"userid\":\"demo\",\"onapNameDictionaryData\":{\"description\":\"test\",\"onapName\":\"Test\"}}";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.saveOnapDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveOnapDictionary: exit");
+ }
+
+ @Test
+ public void testRemoveOnapDictionary() {
+ logger.info("testRemoveOnapDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"onapName\":\"Test\"}}";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.removeOnapDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveOnapDictionary: exit");
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java
index 6a28c271a..7ab1b170e 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java
@@ -43,98 +43,98 @@ import org.onap.policy.rest.dao.CommonClassDao;
import org.springframework.mock.web.MockHttpServletResponse;
public class DictionaryImportControllerTest extends Mockito{
-
- private static Logger logger = FlexLogger.getLogger(DictionaryImportController.class);
-
- private static CommonClassDao commonClassDao;
- private HttpServletRequest request = null;
- private HttpServletResponse response = null;
- private DictionaryImportController controller = null;
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- commonClassDao = Mockito.mock(CommonClassDao.class);
- doNothing().when(commonClassDao).save(new Object());
- controller = new DictionaryImportController();
- new DictionaryImportController(commonClassDao);
- request = Mockito.mock(HttpServletRequest.class);
- response = new MockHttpServletResponse();
- }
-
- @Test
- public void testIsValidDictionaryName(){
- DictionaryImportController cotroller = new DictionaryImportController();
- //test invalid name
- assertTrue(!cotroller.isValidDictionaryName("wrong-name"));
- //test valid name
- assertTrue(cotroller.isValidDictionaryName("ActionList"));
- }
+ private static Logger logger = FlexLogger.getLogger(DictionaryImportController.class);
- @Test
- public void testImportDictionaryData() throws ServletException, IOException{
- List<String> fileNames = new ArrayList<>();
- fileNames.add("Attribute.csv");
- fileNames.add("ActionPolicyDictionary.csv");
- fileNames.add("OnapName.csv");
- fileNames.add("MSPolicyDictionary.csv");
- fileNames.add("OptimizationPolicyDictionary.csv");
- fileNames.add("ClosedLoopService.csv");
- fileNames.add("ClosedLoopSite.csv");
- fileNames.add("VarbindDictionary.csv");
- fileNames.add("BRMSParamDictionary.csv");
- fileNames.add("BRMSControllerDictionary.csv");
- fileNames.add("BRMSDependencyDictionary.csv");
- fileNames.add("PrefixList.csv");
- fileNames.add("SecurityZone.csv");
- fileNames.add("ServiceList.csv");
- fileNames.add("ServiceGroup.csv");
- fileNames.add("AddressGroup.csv");
- fileNames.add("ProtocolList.csv");
- fileNames.add("TermList.csv");
- fileNames.add("SearchCriteria.csv");
- fileNames.add("VNFType.csv");
- fileNames.add("VSCLAction.csv");
- fileNames.add("PEPOptions.csv");
- fileNames.add("Settings.csv");
- fileNames.add("Zone.csv");
- fileNames.add("ActionList.csv");
- for(int i =0; i < fileNames.size(); i++){
- File file = new File("src/test/resources/dictionaryImport/"+fileNames.get(i));
- try(FileInputStream targetStream = new FileInputStream(file)){
- PushPolicyControllerTest pushController = new PushPolicyControllerTest();
- when(request.getInputStream()).thenReturn(pushController.getInputStream(getBytes(targetStream)));
- when(request.getParameter("userId")).thenReturn("demo");
- when(request.getParameter("dictionaryName")).thenReturn(fileNames.get(i));
- controller.importDictionaryData(request, response);
- assertTrue(HttpServletResponse.SC_OK == response.getStatus());
- } catch (IOException e) {
- fail();
- }
- }
- when(request.getParameter("dictionaryName")).thenReturn("WrongName");
- controller.importDictionaryData(request, response);
- assertTrue(HttpServletResponse.SC_BAD_REQUEST == response.getStatus());
-
- when(request.getParameter("dictionaryName")).thenReturn("");
- controller.importDictionaryData(request, response);
- assertTrue(HttpServletResponse.SC_BAD_REQUEST == response.getStatus());
-
- when(request.getInputStream()).thenReturn(null);
- when(request.getParameter("dictionaryName")).thenReturn("Attribute.csv");
- controller.importDictionaryData(request, response);
- assertTrue(HttpServletResponse.SC_INTERNAL_SERVER_ERROR == response.getStatus());
- }
-
- public static byte[] getBytes(InputStream is) throws IOException {
- int len;
- int size = 1024;
- byte[] buf;
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- buf = new byte[size];
- while ((len = is.read(buf, 0, size)) != -1)
- bos.write(buf, 0, len);
- buf = bos.toByteArray();
- return buf;
- }
+ private static CommonClassDao commonClassDao;
+ private HttpServletRequest request = null;
+ private HttpServletResponse response = null;
+ private DictionaryImportController controller = null;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+ doNothing().when(commonClassDao).save(new Object());
+ controller = new DictionaryImportController();
+ new DictionaryImportController(commonClassDao);
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ }
+
+ @Test
+ public void testIsValidDictionaryName(){
+ DictionaryImportController cotroller = new DictionaryImportController();
+ //test invalid name
+ assertTrue(!cotroller.isValidDictionaryName("wrong-name"));
+ //test valid name
+ assertTrue(cotroller.isValidDictionaryName("ActionList"));
+ }
+
+ @Test
+ public void testImportDictionaryData() throws ServletException, IOException{
+ List<String> fileNames = new ArrayList<>();
+ fileNames.add("Attribute.csv");
+ fileNames.add("ActionPolicyDictionary.csv");
+ fileNames.add("OnapName.csv");
+ fileNames.add("MSPolicyDictionary.csv");
+ fileNames.add("OptimizationPolicyDictionary.csv");
+ fileNames.add("ClosedLoopService.csv");
+ fileNames.add("ClosedLoopSite.csv");
+ fileNames.add("VarbindDictionary.csv");
+ fileNames.add("BRMSParamDictionary.csv");
+ fileNames.add("BRMSControllerDictionary.csv");
+ fileNames.add("BRMSDependencyDictionary.csv");
+ fileNames.add("PrefixList.csv");
+ fileNames.add("SecurityZone.csv");
+ fileNames.add("ServiceList.csv");
+ fileNames.add("ServiceGroup.csv");
+ fileNames.add("AddressGroup.csv");
+ fileNames.add("ProtocolList.csv");
+ fileNames.add("TermList.csv");
+ fileNames.add("SearchCriteria.csv");
+ fileNames.add("VNFType.csv");
+ fileNames.add("VSCLAction.csv");
+ fileNames.add("PEPOptions.csv");
+ fileNames.add("Settings.csv");
+ fileNames.add("Zone.csv");
+ fileNames.add("ActionList.csv");
+ for(int i =0; i < fileNames.size(); i++){
+ File file = new File("src/test/resources/dictionaryImport/"+fileNames.get(i));
+ try(FileInputStream targetStream = new FileInputStream(file)){
+ PushPolicyControllerTest pushController = new PushPolicyControllerTest();
+ when(request.getInputStream()).thenReturn(pushController.getInputStream(getBytes(targetStream)));
+ when(request.getParameter("userId")).thenReturn("demo");
+ when(request.getParameter("dictionaryName")).thenReturn(fileNames.get(i));
+ controller.importDictionaryData(request, response);
+ assertTrue(HttpServletResponse.SC_OK == response.getStatus());
+ } catch (IOException e) {
+ fail();
+ }
+ }
+ when(request.getParameter("dictionaryName")).thenReturn("WrongName");
+ controller.importDictionaryData(request, response);
+ assertTrue(HttpServletResponse.SC_BAD_REQUEST == response.getStatus());
+
+ when(request.getParameter("dictionaryName")).thenReturn("");
+ controller.importDictionaryData(request, response);
+ assertTrue(HttpServletResponse.SC_BAD_REQUEST == response.getStatus());
+
+ when(request.getInputStream()).thenReturn(null);
+ when(request.getParameter("dictionaryName")).thenReturn("Attribute.csv");
+ controller.importDictionaryData(request, response);
+ assertTrue(HttpServletResponse.SC_INTERNAL_SERVER_ERROR == response.getStatus());
+ }
+
+ public static byte[] getBytes(InputStream is) throws IOException {
+ int len;
+ int size = 1024;
+ byte[] buf;
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ buf = new byte[size];
+ while ((len = is.read(buf, 0, size)) != -1)
+ bos.write(buf, 0, len);
+ buf = bos.toByteArray();
+ return buf;
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java
index e305b1221..45d8466b6 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java
@@ -62,617 +62,617 @@ import org.springframework.mock.web.MockHttpServletResponse;
public class FirewallDictionaryControllerTest {
- private static Logger logger = FlexLogger.getLogger(FirewallDictionaryControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private FirewallDictionaryController controller = null;
- private MockHttpServletResponse response = null;
- private UserInfo userInfo;
- private List<String> data;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- commonClassDao = Mockito.mock(CommonClassDao.class);
-
- data = new ArrayList<>();
- data.add("Test");
-
- userInfo = new UserInfo();
- userInfo.setUserLoginId("Test");
- userInfo.setUserName("Test");
-
- doNothing().when(commonClassDao).delete(any(Term.class));
- doNothing().when(commonClassDao).save(any(Term.class));
-
- controller = new FirewallDictionaryController();
- FirewallDictionaryController.setCommonClassDao(commonClassDao);
-
- request = Mockito.mock(HttpServletRequest.class);
- response = new MockHttpServletResponse();
- new DictionaryUtils(commonClassDao);
- DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
- mock(DictionaryUtils.class);
- logger.info("setUp: exit");
- }
-
- @Test
- public void testGetPrefixListDictionaryEntityDataByName() {
- test_WithGetDataByColumn(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
- () -> controller.getPrefixListDictionaryEntityDataByName(response));
- }
-
- @Test
- public void testGetPrefixListDictionaryEntityData() {
- test_WithGetData(PrefixList.class, "prefixListDictionaryDatas",
- () -> controller.getPrefixListDictionaryEntityData(response));
- }
-
- @Test
- public void testGetPortListDictionaryEntityData() {
- test_WithGetData(PortList.class, "portListDictionaryDatas",
- () -> controller.getPortListDictionaryEntityData(response));
- }
-
- @Test
- public void testGetProtocolListDictionaryEntityDataByName() {
- test_WithGetDataByColumn(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
- () -> controller.getProtocolListDictionaryEntityDataByName(response));
- }
-
- @Test
- public void testGetProtocolListDictionaryEntityData() {
- test_WithGetData(ProtocolList.class, "protocolListDictionaryDatas",
- () -> controller.getProtocolListDictionaryEntityData(response));
- }
-
- @Test
- public void testGetAddressGroupDictionaryEntityDataByName() {
- test_WithGetDataByColumn(AddressGroup.class, "addressGroupDictionaryDatas", "name",
- () -> controller.getAddressGroupDictionaryEntityDataByName(response));
- }
-
- @Test
- public void testGetAddressGroupDictionaryEntityData() {
- test_WithGetData(AddressGroup.class, "addressGroupDictionaryDatas",
- () -> controller.getAddressGroupDictionaryEntityData(response));
- }
-
- @Test
- public void testGetActionListDictionaryEntityDataByName() {
- test_WithGetDataByColumn(ActionList.class, "actionListDictionaryDatas", "actionName",
- () -> controller.getActionListDictionaryEntityDataByName(response));
- }
-
- @Test
- public void testGetActionListDictionaryEntityData() {
- test_WithGetData(ActionList.class, "actionListDictionaryDatas",
- () -> controller.getActionListDictionaryEntityData(response));
- }
-
- @Test
- public void testGetServiceGroupDictionaryEntityDataByName() {
- test_WithGetDataByColumn(GroupServiceList.class, "serviceGroupDictionaryDatas", "name",
- () -> controller.getServiceGroupDictionaryEntityDataByName(response));
- }
-
- @Test
- public void testGetServiceGroupDictionaryEntityData() {
- test_WithGetData(GroupServiceList.class, "serviceGroupDictionaryDatas",
- () -> controller.getServiceGroupDictionaryEntityData(response));
- }
-
- @Test
- public void testGetSecurityZoneDictionaryEntityDataByName() {
- test_WithGetDataByColumn(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
- () -> controller.getSecurityZoneDictionaryEntityDataByName(response));
- }
-
- @Test
- public void testGetSecurityZoneDictionaryEntityData() {
- test_WithGetData(SecurityZone.class, "securityZoneDictionaryDatas",
- () -> controller.getSecurityZoneDictionaryEntityData(response));
- }
-
- @Test
- public void testGetServiceListDictionaryEntityDataByName() {
- test_WithGetDataByColumn(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
- () -> controller.getServiceListDictionaryEntityDataByName(response));
- }
-
- @Test
- public void testGetServiceListDictionaryEntityData() {
- test_WithGetData(ServiceList.class, "serviceListDictionaryDatas",
- () -> controller.getServiceListDictionaryEntityData(response));
- }
-
- @Test
- public void testGetZoneDictionaryEntityDataByName() {
- test_WithGetDataByColumn(Zone.class, "zoneDictionaryDatas", "zoneName",
- () -> controller.getZoneDictionaryEntityDataByName(response));
- }
-
- @Test
- public void testGetZoneDictionaryEntityData() {
- test_WithGetData(Zone.class, "zoneDictionaryDatas", () -> controller.getZoneDictionaryEntityData(response));
- }
-
- @Test
- public void testGetTermListDictionaryEntityDataByName() {
- test_WithGetDataByColumn(TermList.class, "termListDictionaryDatas", "termName",
- () -> controller.getTermListDictionaryEntityDataByName(response));
- }
-
- @Test
- public void testGetTermListDictionaryEntityData() {
- test_WithGetData(TermList.class, "termListDictionaryDatas",
- () -> controller.getTermListDictionaryEntityData(response));
- }
-
- @Test
- public void testGetFWDictListDictionaryEntityDataByName() {
- test_WithGetDataByColumn(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
- () -> controller.getFWDictListDictionaryEntityDataByName(response));
- }
-
- @Test
- public void testGetFWDictionaryListEntityData() {
- test_WithGetData(FirewallDictionaryList.class, "fwDictListDictionaryDatas",
- () -> controller.getFWDictionaryListEntityData(response));
- }
-
- @Test
- public void testGetTagPickerNameEntityDataByName() {
- test_WithGetDataByColumn(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
- () -> controller.getTagPickerNameEntityDataByName(response));
- }
-
- @Test
- public void testGetTagPickerDictionaryEntityData() {
- test_WithGetData(FWTagPicker.class, "fwTagPickerDictionaryDatas",
- () -> controller.getTagPickerDictionaryEntityData(response));
- }
-
- @Test
- public void testGetTagNameEntityDataByName() {
- test_WithGetDataByColumn(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
- () -> controller.getTagNameEntityDataByName(response));
- }
-
- @Test
- public void testGetTagDictionaryEntityData() {
- test_WithGetData(FWTag.class, "fwTagDictionaryDatas", () -> controller.getTagDictionaryEntityData(response));
- }
-
- @Test
- public void testSavePrefixListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"description\":\"test\",\"prefixListName\":\"Test\"}}";
- testSave(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
- () -> controller.savePrefixListDictionary(request, response));
- }
-
- @Test
- public void testUpdatePrefixListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\"}}";
- testUpdate(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
- () -> controller.savePrefixListDictionary(request, response));
- }
-
- @Test
- public void testRemovePrefixListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\"}}";
- testRemove(PrefixList.class, "prefixListDictionaryDatas",
- () -> controller.removePrefixListDictionary(request, response));
- }
-
- @Test
- public void testValidatePrefixListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\",\"prefixListValue\":\"10.10.10\"}}";
- testValidate(PrefixList.class, "result", () -> controller.validatePrefixListDictionary(request, response));
- }
-
- @Test
- public void testSavePortListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"portListDictionaryData\":{\"description\":\"test\",\"portName\":\"Test\"}}";
- testSave(PortList.class, "portListDictionaryDatas", "portName",
- () -> controller.savePortListDictionary(request, response));
- }
-
- @Test
- public void testUpdatePortListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"portListDictionaryData\":{\"id\":1,\"description\":\"test\",\"portName\":\"Test\"}}";
- testUpdate(PortList.class, "portListDictionaryDatas", "portName",
- () -> controller.savePortListDictionary(request, response));
- }
-
- @Test
- public void testRemovePortListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"portName\":\"Test\"}}";
- testRemove(PortList.class, "portListDictionaryDatas",
- () -> controller.removePortListDictionary(request, response));
- }
-
- @Test
- public void testSaveProtocolListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"description\":\"test\",\"protocolName\":\"Test\"}}";
- testSave(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
- () -> controller.saveProtocolListDictionary(request, response));
- }
-
- @Test
- public void testUpdateProtocolListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"id\":1,\"description\":\"test\",\"protocolName\":\"Test\"}}";
- testUpdate(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
- () -> controller.saveProtocolListDictionary(request, response));
- }
-
- @Test
- public void testRemoveProtocolListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"protocolName\":\"Test\"}}";
- testRemove(ProtocolList.class, "protocolListDictionaryDatas",
- () -> controller.removeProtocolListDictionary(request, response));
- }
-
- @Test
- public void testSaveAddressGroupDictionary() {
- jsonString = "{\"addressGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":\"Test\"},\"userid\":\"demo\"}";
- testSave(AddressGroup.class, "addressGroupDictionaryDatas", "name", "Group_Test",
- () -> controller.saveAddressGroupDictionary(request, response));
- }
-
- @Test
- public void testUpdateAddressGroupDictionary() {
- jsonString = "{\"addressGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":\"Test\"},\"userid\":\"demo\"}";
- testUpdate(AddressGroup.class, "addressGroupDictionaryDatas", "name", "Group_Test",
- () -> controller.saveAddressGroupDictionary(request, response));
- }
-
- @Test
- public void testRemoveAddressGroupDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- testRemove(AddressGroup.class, "addressGroupDictionaryDatas",
- () -> controller.removeAddressGroupDictionary(request, response));
- }
-
- @Test
- public void testSaveActionListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"description\":\"test\",\"actionName\":\"Test\"}}";
- testSave(ActionList.class, "actionListDictionaryDatas", "actionName",
- () -> controller.saveActionListDictionary(request, response));
- }
-
- @Test
- public void testUpdateActionListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"id\":1,\"description\":\"test\",\"actionName\":\"Test\"}}";
- testUpdate(ActionList.class, "actionListDictionaryDatas", "actionName",
- () -> controller.saveActionListDictionary(request, response));
- }
-
- @Test
- public void testRemoveActionListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"actionName\":\"Test\"}}";
- testRemove(ActionList.class, "actionListDictionaryDatas",
- () -> controller.removeActionListDictionary(request, response));
- }
-
- @Test
- public void testSaveServiceGroupDictionary() {
- jsonString = "{\"serviceGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}";
- testSave(GroupServiceList.class, "serviceGroupDictionaryDatas", "name", "Group_Test",
- () -> controller.saveServiceGroupDictionary(request, response));
- }
-
- @Test
- public void testUpdateServiceGroupDictionary() {
- jsonString = "{\"serviceGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}";
- testUpdate(GroupServiceList.class, "serviceGroupDictionaryDatas", "name", "Group_Test",
- () -> controller.saveServiceGroupDictionary(request, response));
- }
-
- @Test
- public void testRemoveServiceGroupDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- testRemove(GroupServiceList.class, "serviceGroupDictionaryDatas",
- () -> controller.removeServiceGroupDictionary(request, response));
- }
-
- @Test
- public void testSaveSecurityZoneDictionary() {
- jsonString = "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"description\":\"test\",\"zoneName\":\"Test\"}}";
- testSave(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
- () -> controller.saveSecurityZoneDictionary(request, response));
- }
-
- @Test
- public void testUpdateSecurityZoneDictionary() {
- jsonString = "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"id\":1,\"description\":\"test\",\"zoneName\":\"Test\"}}";
- testUpdate(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
- () -> controller.saveSecurityZoneDictionary(request, response));
- }
-
- @Test
- public void testRemoveSecurityZoneDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"zoneName\":\"Test\"}}";
- testRemove(SecurityZone.class, "securityZoneDictionaryDatas",
- () -> controller.removeSecurityZoneDictionary(request, response));
- }
-
- @Test
- public void testSaveServiceListDictionary() {
- jsonString = "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
- testSave(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
- () -> controller.saveServiceListDictionary(request, response));
- }
-
- @Test
- public void testUpdateServiceListDictionary() {
- jsonString = "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
- testUpdate(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
- () -> controller.saveServiceListDictionary(request, response));
- }
-
- @Test
- public void testRemoveServiceListDictionary() {
- jsonString = "{\"data\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
- testRemove(ServiceList.class, "serviceListDictionaryDatas",
- () -> controller.removeServiceListDictionary(request, response));
- }
-
- @Test
- public void testSaveZoneDictionary() {
- jsonString = "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
- testSave(Zone.class, "zoneDictionaryDatas", "zoneName", () -> controller.saveZoneDictionary(request, response));
- }
-
- @Test
- public void testUpdateZoneDictionary() {
- jsonString = "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"id\":1,\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
- testUpdate(Zone.class, "zoneDictionaryDatas", "zoneName",
- () -> controller.saveZoneDictionary(request, response));
- }
-
- @Test
- public void testRemoveZoneDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
- testRemove(Zone.class, "zoneDictionaryDatas", () -> controller.removeZoneDictionary(request, response));
- }
-
- @Test
- public void testSaveTermListDictionary() {
- jsonString = "{\"termListDictionaryData\":{\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
- testSave(TermList.class, "termListDictionaryDatas", "termName",
- () -> controller.saveTermListDictionary(request, response));
- }
-
- @Test
- public void testUpdateTermListDictionary() {
- jsonString = "{\"termListDictionaryData\":{\"id\":1,\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
- testUpdate(TermList.class, "termListDictionaryDatas", "termName",
- () -> controller.saveTermListDictionary(request, response));
- }
-
- @Test
- public void testRemoveTermListDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"termDescription\":\"test\",\"termName\":\"Test\"}}";
- testRemove(TermList.class, "termListDictionaryDatas",
- () -> controller.removeTermListDictionary(request, response));
- }
-
- @Test
- public void testSaveFWDictionaryList() {
- jsonString = "{\"fwDictListDictionaryData\":{\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":\"demo\"}";
- testSave(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
- () -> controller.saveFWDictionaryList(request, response));
- }
-
- @Test
- public void testUpdateFWDictionaryList() {
- jsonString = "{\"fwDictListDictionaryData\":{\"id\":1,\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":\"demo\"}";
- testUpdate(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
- () -> controller.saveFWDictionaryList(request, response));
- }
-
- @Test
- public void testRemoveFWDictionaryList() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"parentItemName\":\"Test\"}}";
- testRemove(FirewallDictionaryList.class, "fwDictListDictionaryDatas",
- () -> controller.removeFWDictionaryList(request, response));
- }
-
- @Test
- public void testSaveFirewallTagPickerDictionary() {
- jsonString = "{\"fwTagPickerDictionaryData\":{\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
- testSave(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
- () -> controller.saveFirewallTagPickerDictionary(request, response));
- }
-
- @Test
- public void testUpdateFirewallTagPickerDictionary() {
- jsonString = "{\"fwTagPickerDictionaryData\":{\"id\":1,\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
- testUpdate(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
- () -> controller.saveFirewallTagPickerDictionary(request, response));
- }
-
- @Test
- public void testRemoveFirewallTagPickerDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"tagPickerName\":\"Test\"}}";
- testRemove(FWTagPicker.class, "fwTagPickerDictionaryDatas",
- () -> controller.removeFirewallTagPickerDictionary(request, response));
- }
-
- @Test
- public void testSaveFirewallTagDictionary() {
- jsonString = "{\"fwTagDictionaryData\":{\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}";
- testSave(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
- () -> controller.saveFirewallTagDictionary(request, response));
- }
-
- @Test
- public void testUpdateFirewallTagDictionary() {
- jsonString = "{\"fwTagDictionaryData\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}";
- testUpdate(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
- () -> controller.saveFirewallTagDictionary(request, response));
- }
-
- @Test
- public void testRemoveFirewallTagDictionary() {
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\"}}";
- testRemove(FWTag.class, "fwTagDictionaryDatas",
- () -> controller.removeFirewallTagDictionary(request, response));
- }
-
- /**
- * Tests a "get" function that uses commonClassDao.getDataByColumn().
- *
- * @param clazz
- * @param contentData
- * @param contentName
- * @param func
- */
- private void test_WithGetDataByColumn(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
- when(commonClassDao.getDataByColumn(clazz, contentName)).thenReturn(data);
- try {
- func.apply();
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
- verify(commonClassDao).getDataByColumn(clazz, contentName);
- } catch (Exception e) {
- fail("get " + clazz.getName() + e);
- }
- }
-
- /**
- * Tests a "get" function that uses commonClassDao.getData().
- *
- * @param clazz
- * @param contentData
- * @param contentName
- * @param func
- */
- private void test_WithGetData(Class<?> clazz, String contentData, VoidFunc func) {
- when(commonClassDao.getData(clazz)).thenReturn(new ArrayList<>());
- try {
- func.apply();
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
- verify(commonClassDao).getData(clazz);
- } catch (Exception e) {
- fail("get " + clazz.getName() + e);
- }
- }
-
- /**
- * Tests a function that uses commonClassDao.save().
- *
- * @param clazz
- * @param contentData
- * @param contentName
- * @param func
- */
- private void testSave(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
- testSave(clazz, contentData, contentName, "Test", func);
- }
-
- /**
- * Tests a function that uses commonClassDao.save().
- *
- * @param clazz
- * @param contentData
- * @param contentName
- * @param testName
- * @param func
- */
- private void testSave(Class<?> clazz, String contentData, String contentName, String testName, VoidFunc func) {
- try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
- when(request.getReader()).thenReturn(br);
- func.apply();
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
- verify(commonClassDao).checkDuplicateEntry(testName, contentName, clazz);
- verify(commonClassDao).save(any());
- verify(commonClassDao, never()).update(any());
- verify(commonClassDao).getData(clazz);
-
- } catch (IOException e) {
- fail("save " + clazz.getName() + e);
- }
- }
-
- /**
- * Tests a function that uses commonClassDao.update().
- *
- * @param clazz
- * @param contentData
- * @param contentName
- * @param func
- */
- private void testUpdate(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
- testUpdate(clazz, contentData, contentName, "Test", func);
- }
-
- /**
- * Tests a function that uses commonClassDao.update().
- *
- * @param clazz
- * @param contentData
- * @param contentName
- * @param testName
- * @param func
- */
- private void testUpdate(Class<?> clazz, String contentData, String contentName, String testName, VoidFunc func) {
- try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
- when(request.getReader()).thenReturn(br);
- func.apply();
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
- verify(commonClassDao).checkDuplicateEntry(testName, contentName, clazz);
- verify(commonClassDao, never()).save(any());
- verify(commonClassDao).update(any());
- verify(commonClassDao).getData(clazz);
-
- } catch (IOException e) {
- fail("update " + clazz.getName() + e);
- }
- }
-
- /**
- * Tests a function that uses commonClassDao.delete() and
- * commonClassDao.getData().
- *
- * @param clazz
- * @param contentData
- * @param func
- */
- private void testRemove(Class<?> clazz, String contentData, VoidFunc func) {
- try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
- when(request.getReader()).thenReturn(br);
- func.apply();
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
- verify(commonClassDao).delete(any());
- verify(commonClassDao).getData(clazz);
-
- } catch (IOException e) {
- fail("remove " + clazz.getName() + e);
- }
- }
-
- /**
- * Tests a "validate" function.
- *
- * @param clazz
- * @param contentData
- * @param func
- */
- private void testValidate(Class<?> clazz, String contentData, VoidFunc func) {
- try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
- when(request.getReader()).thenReturn(br);
- func.apply();
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
-
- } catch (IOException e) {
- fail("save " + clazz.getName() + e);
- }
- }
-
- @FunctionalInterface
- private static interface VoidFunc {
- public void apply() throws IOException;
- }
+ private static Logger logger = FlexLogger.getLogger(FirewallDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private FirewallDictionaryController controller = null;
+ private MockHttpServletResponse response = null;
+ private UserInfo userInfo;
+ private List<String> data;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+
+ data = new ArrayList<>();
+ data.add("Test");
+
+ userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+
+ doNothing().when(commonClassDao).delete(any(Term.class));
+ doNothing().when(commonClassDao).save(any(Term.class));
+
+ controller = new FirewallDictionaryController();
+ FirewallDictionaryController.setCommonClassDao(commonClassDao);
+
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ new DictionaryUtils(commonClassDao);
+ DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
+ mock(DictionaryUtils.class);
+ logger.info("setUp: exit");
+ }
+
+ @Test
+ public void testGetPrefixListDictionaryEntityDataByName() {
+ test_WithGetDataByColumn(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
+ () -> controller.getPrefixListDictionaryEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetPrefixListDictionaryEntityData() {
+ test_WithGetData(PrefixList.class, "prefixListDictionaryDatas",
+ () -> controller.getPrefixListDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetPortListDictionaryEntityData() {
+ test_WithGetData(PortList.class, "portListDictionaryDatas",
+ () -> controller.getPortListDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetProtocolListDictionaryEntityDataByName() {
+ test_WithGetDataByColumn(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
+ () -> controller.getProtocolListDictionaryEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetProtocolListDictionaryEntityData() {
+ test_WithGetData(ProtocolList.class, "protocolListDictionaryDatas",
+ () -> controller.getProtocolListDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetAddressGroupDictionaryEntityDataByName() {
+ test_WithGetDataByColumn(AddressGroup.class, "addressGroupDictionaryDatas", "name",
+ () -> controller.getAddressGroupDictionaryEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetAddressGroupDictionaryEntityData() {
+ test_WithGetData(AddressGroup.class, "addressGroupDictionaryDatas",
+ () -> controller.getAddressGroupDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetActionListDictionaryEntityDataByName() {
+ test_WithGetDataByColumn(ActionList.class, "actionListDictionaryDatas", "actionName",
+ () -> controller.getActionListDictionaryEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetActionListDictionaryEntityData() {
+ test_WithGetData(ActionList.class, "actionListDictionaryDatas",
+ () -> controller.getActionListDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetServiceGroupDictionaryEntityDataByName() {
+ test_WithGetDataByColumn(GroupServiceList.class, "serviceGroupDictionaryDatas", "name",
+ () -> controller.getServiceGroupDictionaryEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetServiceGroupDictionaryEntityData() {
+ test_WithGetData(GroupServiceList.class, "serviceGroupDictionaryDatas",
+ () -> controller.getServiceGroupDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetSecurityZoneDictionaryEntityDataByName() {
+ test_WithGetDataByColumn(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
+ () -> controller.getSecurityZoneDictionaryEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetSecurityZoneDictionaryEntityData() {
+ test_WithGetData(SecurityZone.class, "securityZoneDictionaryDatas",
+ () -> controller.getSecurityZoneDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetServiceListDictionaryEntityDataByName() {
+ test_WithGetDataByColumn(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
+ () -> controller.getServiceListDictionaryEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetServiceListDictionaryEntityData() {
+ test_WithGetData(ServiceList.class, "serviceListDictionaryDatas",
+ () -> controller.getServiceListDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetZoneDictionaryEntityDataByName() {
+ test_WithGetDataByColumn(Zone.class, "zoneDictionaryDatas", "zoneName",
+ () -> controller.getZoneDictionaryEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetZoneDictionaryEntityData() {
+ test_WithGetData(Zone.class, "zoneDictionaryDatas", () -> controller.getZoneDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetTermListDictionaryEntityDataByName() {
+ test_WithGetDataByColumn(TermList.class, "termListDictionaryDatas", "termName",
+ () -> controller.getTermListDictionaryEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetTermListDictionaryEntityData() {
+ test_WithGetData(TermList.class, "termListDictionaryDatas",
+ () -> controller.getTermListDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetFWDictListDictionaryEntityDataByName() {
+ test_WithGetDataByColumn(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
+ () -> controller.getFWDictListDictionaryEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetFWDictionaryListEntityData() {
+ test_WithGetData(FirewallDictionaryList.class, "fwDictListDictionaryDatas",
+ () -> controller.getFWDictionaryListEntityData(response));
+ }
+
+ @Test
+ public void testGetTagPickerNameEntityDataByName() {
+ test_WithGetDataByColumn(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
+ () -> controller.getTagPickerNameEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetTagPickerDictionaryEntityData() {
+ test_WithGetData(FWTagPicker.class, "fwTagPickerDictionaryDatas",
+ () -> controller.getTagPickerDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testGetTagNameEntityDataByName() {
+ test_WithGetDataByColumn(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
+ () -> controller.getTagNameEntityDataByName(response));
+ }
+
+ @Test
+ public void testGetTagDictionaryEntityData() {
+ test_WithGetData(FWTag.class, "fwTagDictionaryDatas", () -> controller.getTagDictionaryEntityData(response));
+ }
+
+ @Test
+ public void testSavePrefixListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"description\":\"test\",\"prefixListName\":\"Test\"}}";
+ testSave(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
+ () -> controller.savePrefixListDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdatePrefixListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\"}}";
+ testUpdate(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
+ () -> controller.savePrefixListDictionary(request, response));
+ }
+
+ @Test
+ public void testRemovePrefixListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\"}}";
+ testRemove(PrefixList.class, "prefixListDictionaryDatas",
+ () -> controller.removePrefixListDictionary(request, response));
+ }
+
+ @Test
+ public void testValidatePrefixListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\",\"prefixListValue\":\"10.10.10\"}}";
+ testValidate(PrefixList.class, "result", () -> controller.validatePrefixListDictionary(request, response));
+ }
+
+ @Test
+ public void testSavePortListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"portListDictionaryData\":{\"description\":\"test\",\"portName\":\"Test\"}}";
+ testSave(PortList.class, "portListDictionaryDatas", "portName",
+ () -> controller.savePortListDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdatePortListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"portListDictionaryData\":{\"id\":1,\"description\":\"test\",\"portName\":\"Test\"}}";
+ testUpdate(PortList.class, "portListDictionaryDatas", "portName",
+ () -> controller.savePortListDictionary(request, response));
+ }
+
+ @Test
+ public void testRemovePortListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"portName\":\"Test\"}}";
+ testRemove(PortList.class, "portListDictionaryDatas",
+ () -> controller.removePortListDictionary(request, response));
+ }
+
+ @Test
+ public void testSaveProtocolListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"description\":\"test\",\"protocolName\":\"Test\"}}";
+ testSave(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
+ () -> controller.saveProtocolListDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdateProtocolListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"id\":1,\"description\":\"test\",\"protocolName\":\"Test\"}}";
+ testUpdate(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
+ () -> controller.saveProtocolListDictionary(request, response));
+ }
+
+ @Test
+ public void testRemoveProtocolListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"protocolName\":\"Test\"}}";
+ testRemove(ProtocolList.class, "protocolListDictionaryDatas",
+ () -> controller.removeProtocolListDictionary(request, response));
+ }
+
+ @Test
+ public void testSaveAddressGroupDictionary() {
+ jsonString = "{\"addressGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":\"Test\"},\"userid\":\"demo\"}";
+ testSave(AddressGroup.class, "addressGroupDictionaryDatas", "name", "Group_Test",
+ () -> controller.saveAddressGroupDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdateAddressGroupDictionary() {
+ jsonString = "{\"addressGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":\"Test\"},\"userid\":\"demo\"}";
+ testUpdate(AddressGroup.class, "addressGroupDictionaryDatas", "name", "Group_Test",
+ () -> controller.saveAddressGroupDictionary(request, response));
+ }
+
+ @Test
+ public void testRemoveAddressGroupDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ testRemove(AddressGroup.class, "addressGroupDictionaryDatas",
+ () -> controller.removeAddressGroupDictionary(request, response));
+ }
+
+ @Test
+ public void testSaveActionListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"description\":\"test\",\"actionName\":\"Test\"}}";
+ testSave(ActionList.class, "actionListDictionaryDatas", "actionName",
+ () -> controller.saveActionListDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdateActionListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"id\":1,\"description\":\"test\",\"actionName\":\"Test\"}}";
+ testUpdate(ActionList.class, "actionListDictionaryDatas", "actionName",
+ () -> controller.saveActionListDictionary(request, response));
+ }
+
+ @Test
+ public void testRemoveActionListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"actionName\":\"Test\"}}";
+ testRemove(ActionList.class, "actionListDictionaryDatas",
+ () -> controller.removeActionListDictionary(request, response));
+ }
+
+ @Test
+ public void testSaveServiceGroupDictionary() {
+ jsonString = "{\"serviceGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}";
+ testSave(GroupServiceList.class, "serviceGroupDictionaryDatas", "name", "Group_Test",
+ () -> controller.saveServiceGroupDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdateServiceGroupDictionary() {
+ jsonString = "{\"serviceGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}";
+ testUpdate(GroupServiceList.class, "serviceGroupDictionaryDatas", "name", "Group_Test",
+ () -> controller.saveServiceGroupDictionary(request, response));
+ }
+
+ @Test
+ public void testRemoveServiceGroupDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ testRemove(GroupServiceList.class, "serviceGroupDictionaryDatas",
+ () -> controller.removeServiceGroupDictionary(request, response));
+ }
+
+ @Test
+ public void testSaveSecurityZoneDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"description\":\"test\",\"zoneName\":\"Test\"}}";
+ testSave(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
+ () -> controller.saveSecurityZoneDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdateSecurityZoneDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"id\":1,\"description\":\"test\",\"zoneName\":\"Test\"}}";
+ testUpdate(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
+ () -> controller.saveSecurityZoneDictionary(request, response));
+ }
+
+ @Test
+ public void testRemoveSecurityZoneDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"zoneName\":\"Test\"}}";
+ testRemove(SecurityZone.class, "securityZoneDictionaryDatas",
+ () -> controller.removeSecurityZoneDictionary(request, response));
+ }
+
+ @Test
+ public void testSaveServiceListDictionary() {
+ jsonString = "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
+ testSave(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
+ () -> controller.saveServiceListDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdateServiceListDictionary() {
+ jsonString = "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
+ testUpdate(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
+ () -> controller.saveServiceListDictionary(request, response));
+ }
+
+ @Test
+ public void testRemoveServiceListDictionary() {
+ jsonString = "{\"data\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
+ testRemove(ServiceList.class, "serviceListDictionaryDatas",
+ () -> controller.removeServiceListDictionary(request, response));
+ }
+
+ @Test
+ public void testSaveZoneDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
+ testSave(Zone.class, "zoneDictionaryDatas", "zoneName", () -> controller.saveZoneDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdateZoneDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"id\":1,\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
+ testUpdate(Zone.class, "zoneDictionaryDatas", "zoneName",
+ () -> controller.saveZoneDictionary(request, response));
+ }
+
+ @Test
+ public void testRemoveZoneDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
+ testRemove(Zone.class, "zoneDictionaryDatas", () -> controller.removeZoneDictionary(request, response));
+ }
+
+ @Test
+ public void testSaveTermListDictionary() {
+ jsonString = "{\"termListDictionaryData\":{\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
+ testSave(TermList.class, "termListDictionaryDatas", "termName",
+ () -> controller.saveTermListDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdateTermListDictionary() {
+ jsonString = "{\"termListDictionaryData\":{\"id\":1,\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
+ testUpdate(TermList.class, "termListDictionaryDatas", "termName",
+ () -> controller.saveTermListDictionary(request, response));
+ }
+
+ @Test
+ public void testRemoveTermListDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"termDescription\":\"test\",\"termName\":\"Test\"}}";
+ testRemove(TermList.class, "termListDictionaryDatas",
+ () -> controller.removeTermListDictionary(request, response));
+ }
+
+ @Test
+ public void testSaveFWDictionaryList() {
+ jsonString = "{\"fwDictListDictionaryData\":{\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":\"demo\"}";
+ testSave(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
+ () -> controller.saveFWDictionaryList(request, response));
+ }
+
+ @Test
+ public void testUpdateFWDictionaryList() {
+ jsonString = "{\"fwDictListDictionaryData\":{\"id\":1,\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":\"demo\"}";
+ testUpdate(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
+ () -> controller.saveFWDictionaryList(request, response));
+ }
+
+ @Test
+ public void testRemoveFWDictionaryList() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"parentItemName\":\"Test\"}}";
+ testRemove(FirewallDictionaryList.class, "fwDictListDictionaryDatas",
+ () -> controller.removeFWDictionaryList(request, response));
+ }
+
+ @Test
+ public void testSaveFirewallTagPickerDictionary() {
+ jsonString = "{\"fwTagPickerDictionaryData\":{\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
+ testSave(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
+ () -> controller.saveFirewallTagPickerDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdateFirewallTagPickerDictionary() {
+ jsonString = "{\"fwTagPickerDictionaryData\":{\"id\":1,\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
+ testUpdate(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
+ () -> controller.saveFirewallTagPickerDictionary(request, response));
+ }
+
+ @Test
+ public void testRemoveFirewallTagPickerDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"tagPickerName\":\"Test\"}}";
+ testRemove(FWTagPicker.class, "fwTagPickerDictionaryDatas",
+ () -> controller.removeFirewallTagPickerDictionary(request, response));
+ }
+
+ @Test
+ public void testSaveFirewallTagDictionary() {
+ jsonString = "{\"fwTagDictionaryData\":{\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}";
+ testSave(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
+ () -> controller.saveFirewallTagDictionary(request, response));
+ }
+
+ @Test
+ public void testUpdateFirewallTagDictionary() {
+ jsonString = "{\"fwTagDictionaryData\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}";
+ testUpdate(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
+ () -> controller.saveFirewallTagDictionary(request, response));
+ }
+
+ @Test
+ public void testRemoveFirewallTagDictionary() {
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\"}}";
+ testRemove(FWTag.class, "fwTagDictionaryDatas",
+ () -> controller.removeFirewallTagDictionary(request, response));
+ }
+
+ /**
+ * Tests a "get" function that uses commonClassDao.getDataByColumn().
+ *
+ * @param clazz
+ * @param contentData
+ * @param contentName
+ * @param func
+ */
+ private void test_WithGetDataByColumn(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
+ when(commonClassDao.getDataByColumn(clazz, contentName)).thenReturn(data);
+ try {
+ func.apply();
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
+ verify(commonClassDao).getDataByColumn(clazz, contentName);
+ } catch (Exception e) {
+ fail("get " + clazz.getName() + e);
+ }
+ }
+
+ /**
+ * Tests a "get" function that uses commonClassDao.getData().
+ *
+ * @param clazz
+ * @param contentData
+ * @param contentName
+ * @param func
+ */
+ private void test_WithGetData(Class<?> clazz, String contentData, VoidFunc func) {
+ when(commonClassDao.getData(clazz)).thenReturn(new ArrayList<>());
+ try {
+ func.apply();
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
+ verify(commonClassDao).getData(clazz);
+ } catch (Exception e) {
+ fail("get " + clazz.getName() + e);
+ }
+ }
+
+ /**
+ * Tests a function that uses commonClassDao.save().
+ *
+ * @param clazz
+ * @param contentData
+ * @param contentName
+ * @param func
+ */
+ private void testSave(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
+ testSave(clazz, contentData, contentName, "Test", func);
+ }
+
+ /**
+ * Tests a function that uses commonClassDao.save().
+ *
+ * @param clazz
+ * @param contentData
+ * @param contentName
+ * @param testName
+ * @param func
+ */
+ private void testSave(Class<?> clazz, String contentData, String contentName, String testName, VoidFunc func) {
+ try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
+ when(request.getReader()).thenReturn(br);
+ func.apply();
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
+ verify(commonClassDao).checkDuplicateEntry(testName, contentName, clazz);
+ verify(commonClassDao).save(any());
+ verify(commonClassDao, never()).update(any());
+ verify(commonClassDao).getData(clazz);
+
+ } catch (IOException e) {
+ fail("save " + clazz.getName() + e);
+ }
+ }
+
+ /**
+ * Tests a function that uses commonClassDao.update().
+ *
+ * @param clazz
+ * @param contentData
+ * @param contentName
+ * @param func
+ */
+ private void testUpdate(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
+ testUpdate(clazz, contentData, contentName, "Test", func);
+ }
+
+ /**
+ * Tests a function that uses commonClassDao.update().
+ *
+ * @param clazz
+ * @param contentData
+ * @param contentName
+ * @param testName
+ * @param func
+ */
+ private void testUpdate(Class<?> clazz, String contentData, String contentName, String testName, VoidFunc func) {
+ try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
+ when(request.getReader()).thenReturn(br);
+ func.apply();
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
+ verify(commonClassDao).checkDuplicateEntry(testName, contentName, clazz);
+ verify(commonClassDao, never()).save(any());
+ verify(commonClassDao).update(any());
+ verify(commonClassDao).getData(clazz);
+
+ } catch (IOException e) {
+ fail("update " + clazz.getName() + e);
+ }
+ }
+
+ /**
+ * Tests a function that uses commonClassDao.delete() and
+ * commonClassDao.getData().
+ *
+ * @param clazz
+ * @param contentData
+ * @param func
+ */
+ private void testRemove(Class<?> clazz, String contentData, VoidFunc func) {
+ try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
+ when(request.getReader()).thenReturn(br);
+ func.apply();
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
+ verify(commonClassDao).delete(any());
+ verify(commonClassDao).getData(clazz);
+
+ } catch (IOException e) {
+ fail("remove " + clazz.getName() + e);
+ }
+ }
+
+ /**
+ * Tests a "validate" function.
+ *
+ * @param clazz
+ * @param contentData
+ * @param func
+ */
+ private void testValidate(Class<?> clazz, String contentData, VoidFunc func) {
+ try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
+ when(request.getReader()).thenReturn(br);
+ func.apply();
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
+
+ } catch (IOException e) {
+ fail("save " + clazz.getName() + e);
+ }
+ }
+
+ @FunctionalInterface
+ private static interface VoidFunc {
+ public void apply() throws IOException;
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryControllerTest.java
index ae71692c1..2e9df2592 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryControllerTest.java
@@ -58,17 +58,17 @@ import org.springframework.mock.web.MockHttpServletResponse;
*/
public class MicroServiceDictionaryControllerTest {
-
- private static Logger logger = FlexLogger.getLogger(MicroServiceDictionaryControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private MicroServiceDictionaryController controller = null;
- BufferedReader br = null;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
+
+ private static Logger logger = FlexLogger.getLogger(MicroServiceDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private MicroServiceDictionaryController controller = null;
+ BufferedReader br = null;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
commonClassDao = Mockito.mock(CommonClassDao.class);
UserInfo userInfo = new UserInfo();
userInfo.setUserLoginId("testUserId");
@@ -89,21 +89,21 @@ public class MicroServiceDictionaryControllerTest {
MicroServiceModels microServiceModels = new MicroServiceModels();
doNothing().when(commonClassDao).delete(microServiceModels);
-
- MicroServiceDictionaryController.setCommonClassDao(commonClassDao);
-
- controller = new MicroServiceDictionaryController();
+
+ MicroServiceDictionaryController.setCommonClassDao(commonClassDao);
+
+ controller = new MicroServiceDictionaryController();
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- jsonString = "{\"microServiceModelsDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ jsonString = "{\"microServiceModelsDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
br = new BufferedReader(new StringReader(jsonString));
//--- mock the getReader() call
@@ -112,653 +112,653 @@ public class MicroServiceDictionaryControllerTest {
DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
mock(DictionaryUtils.class);
logger.info("setUp: exit");
- }
-
-
- @Test
- public void testSaveMicroServiceHeaderDefaultValues() {
- logger.info("testSaveMicroServiceHeaderDefaultValues: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"modelAttributeDictionaryData\": {\"onapName\": \"test\", \"guard\": false,\"priority\": \"3\","
- + " \"riskType\": \"test\", \"riskLevel\": \"7\", \"modelName\": \"testname\"}}";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.saveMicroServiceHeaderDefaultValues(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testSaveMicroServiceHeaderDefaultValues: exit");
- }
-
-
- @Test
- public void testGetMicroServiceHeaderDefaultsEntityDataByName() {
- logger.info("testGetMicroServiceHeaderDefaultsEntityDataByName: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getMicroServiceHeaderDefaultsEntityDataByName(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceHeaderDefaultsEntityDataByName: exit");
- }
-
- @Test
- public void testGetMicroServiceHeaderDefaultsEntityData() {
- logger.info("testGetMicroServiceHeaderDefaultsEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getMicroServiceHeaderDefaultsEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceHeaderDefaultsEntityData: exit");
- }
-
- @Test
- public void testRemoveMicroServiceHeaderDefaults() {
- logger.info("testRemoveMicroServiceHeaderDefaults: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.removeMicroServiceHeaderDefaults(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveMicroServiceHeaderDefaults: exit");
- }
-
-
- @Test
- public void testGetDCAEUUIDDictionaryByNameEntityData() {
-
- logger.info("testGetDCAEUUIDDictionaryByNameEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getDCAEUUIDDictionaryByNameEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetDCAEUUIDDictionaryByNameEntityData: exit");
- }
-
- @Test
- public void testGetDCAEUUIDDictionaryEntityData() {
-
- logger.info("testGetDCAEUUIDDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getDCAEUUIDDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetDCAEUUIDDictionaryEntityData: exit");
- }
-
- @Test
- public void testSaveDCAEUUIDDictionary() {
- logger.info("testSaveDCAEUUIDDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"dcaeUUIDDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.saveDCAEUUIDDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testSaveDCAEUUIDDictionary: exit");
- }
-
- @Test
- public void testRemoveDCAEUUIDDictionary() {
- logger.info("testRemoveDCAEUUIDDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.removeMicroServiceConfigNameDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveDCAEUUIDDictionary: exit");
- }
-
- @Test
- public void testGetMicroServiceConfigNameByNameDictionaryEntityData() {
- logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getMicroServiceConfigNameByNameDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: exit");
- }
-
- @Test
- public void testGetMicroServiceConfigNameDictionaryEntityData() {
- logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getMicroServiceConfigNameDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceConfigNameDictionaryEntityData: exit");
- }
-
- @Test
- public void testSaveMicroServiceConfigNameDictionary() {
- logger.info("testSaveMicroServiceConfigNameDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"microServiceConfigNameDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.saveMicroServiceConfigNameDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testSaveMicroServiceConfigNameDictionary: exit");
- }
-
- @Test
- public void testRemoveMicroServiceConfigNameDictionary() {
- logger.info("testRemoveMicroServiceConfigNameDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.removeMicroServiceConfigNameDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveMicroServiceConfigNameDictionary: exit");
- }
-
- @Test
- public void testGetMicroServiceLocationByNameDictionaryEntityData() {
-
- logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getMicroServiceLocationByNameDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: exit");
- }
-
- @Test
- public void testGetMicroServiceLocationDictionaryEntityData() {
- logger.info("testGetMicroServiceLocationDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getMicroServiceLocationDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceLocationDictionaryEntityData: exit");
- }
-
- @Test
- public void testSaveMicroServiceLocationDictionary() {
- logger.info("testSaveMicroServiceLocationDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"microServiceLocationDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.saveMicroServiceLocationDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testSaveMicroServiceLocationDictionary: exit");
- }
-
- @Test
- public void testRemoveMicroServiceLocationDictionary() {
- logger.info("testRemoveMicroServiceLocationDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
-
- when(request.getReader()).thenReturn(br);
- controller.removeMicroServiceLocationDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveMicroServiceLocationDictionary: exit");
- }
-
- @Test
- public void testGetMicroServiceAttributeByNameDictionaryEntityData() {
- logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getMicroServiceAttributeByNameDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: exit");
- }
-
- @Test
- public void testGetMicroServiceAttributeDictionaryEntityData() {
- logger.info("testGetMicroServiceAttributeDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getMicroServiceAttributeDictionaryEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceAttributeDictionaryEntityData: exit");
- }
-
- @Test
- public void testSaveMicroServiceAttributeDictionary() {
- logger.info("testSaveMicroServiceAttributeDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"modelAttributeDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.saveMicroServiceAttributeDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testSaveMicroServiceAttributeDictionary: exit");
- }
-
- @Test
- public void testRemoveMicroServiceAttributeDictionary() {
- logger.info("testRemoveMicroServiceAttributeDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.removeMicroServiceAttributeDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveMicroServiceAttributeDictionary: exit");
- }
-
- @Test
- public void testGetMicroServiceModelsDictionaryByNameEntityData() {
- logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
-
- controller.getMicroServiceModelsDictionaryByNameEntityData(response);
-
- try {
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- } catch (UnsupportedEncodingException e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: exit");
- }
-
- @Test
- public void testGetMicroServiceModelsDictionaryByVersionEntityData() {
- logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
-
- BufferedReader br = new BufferedReader(new StringReader(msModelJson));
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- when(request.getReader()).thenReturn(br);
- controller.getMicroServiceModelsDictionaryByVersionEntityData(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("No model name given"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: exit");
- }
-
- @Test
- public void testGetMicroServiceModelsDictionaryEntityData() {
- logger.info("testGetMicroServiceModelsDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
-
- BufferedReader br = new BufferedReader(new StringReader(msModelJson));
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- when(request.getReader()).thenReturn(br);
- controller.getMicroServiceModelsDictionaryEntityData(response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceModelsDictionaryEntityData: exit");
- }
-
- @Test
- public void testGetMicroServiceModelsDictionaryEntityDataServiceVersion() {
- logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
-
- BufferedReader br = new BufferedReader(new StringReader(msModelJson));
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- when(request.getReader()).thenReturn(br);
- controller.getMicroServiceModelsDictionaryEntityDataServiceVersion(response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: exit");
- }
-
- @Test
- public void testGetMicroServiceModelsDictionaryClassEntityData() {
- logger.info("testGetMicroServiceModelsDictionaryClassEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
-
- BufferedReader br = new BufferedReader(new StringReader(msModelJson));
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- when(request.getReader()).thenReturn(br);
- controller.getMicroServiceModelsDictionaryClassEntityData(response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryClassDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetMicroServiceModelsDictionaryClassEntityData: exit");
- }
-
- @Test
- public void testSaveMicroServiceModelsDictionary() {
- logger.info("testSaveMicroServiceModelsDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- when(request.getReader()).thenReturn(br);
- controller.saveMicroServiceModelsDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testSaveMicroServiceModelsDictionary: exit");
- }
-
- @Test
- public void testRemoveMicroServiceModelsDictionary() {
- logger.info("testRemoveMicroServiceModelsDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
-
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.removeMicroServiceModelsDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveMicroServiceModelsDictionary: exit");
- }
+ }
+
+
+ @Test
+ public void testSaveMicroServiceHeaderDefaultValues() {
+ logger.info("testSaveMicroServiceHeaderDefaultValues: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"modelAttributeDictionaryData\": {\"onapName\": \"test\", \"guard\": false,\"priority\": \"3\","
+ + " \"riskType\": \"test\", \"riskLevel\": \"7\", \"modelName\": \"testname\"}}";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.saveMicroServiceHeaderDefaultValues(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveMicroServiceHeaderDefaultValues: exit");
+ }
+
+
+ @Test
+ public void testGetMicroServiceHeaderDefaultsEntityDataByName() {
+ logger.info("testGetMicroServiceHeaderDefaultsEntityDataByName: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getMicroServiceHeaderDefaultsEntityDataByName(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceHeaderDefaultsEntityDataByName: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceHeaderDefaultsEntityData() {
+ logger.info("testGetMicroServiceHeaderDefaultsEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getMicroServiceHeaderDefaultsEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceHeaderDefaultsEntityData: exit");
+ }
+
+ @Test
+ public void testRemoveMicroServiceHeaderDefaults() {
+ logger.info("testRemoveMicroServiceHeaderDefaults: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.removeMicroServiceHeaderDefaults(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceHeaderDefaultDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveMicroServiceHeaderDefaults: exit");
+ }
+
+
+ @Test
+ public void testGetDCAEUUIDDictionaryByNameEntityData() {
+
+ logger.info("testGetDCAEUUIDDictionaryByNameEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getDCAEUUIDDictionaryByNameEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetDCAEUUIDDictionaryByNameEntityData: exit");
+ }
+
+ @Test
+ public void testGetDCAEUUIDDictionaryEntityData() {
+
+ logger.info("testGetDCAEUUIDDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getDCAEUUIDDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetDCAEUUIDDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testSaveDCAEUUIDDictionary() {
+ logger.info("testSaveDCAEUUIDDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"dcaeUUIDDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.saveDCAEUUIDDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeUUIDDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveDCAEUUIDDictionary: exit");
+ }
+
+ @Test
+ public void testRemoveDCAEUUIDDictionary() {
+ logger.info("testRemoveDCAEUUIDDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.removeMicroServiceConfigNameDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveDCAEUUIDDictionary: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceConfigNameByNameDictionaryEntityData() {
+ logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getMicroServiceConfigNameByNameDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceConfigNameDictionaryEntityData() {
+ logger.info("testGetMicroServiceConfigNameByNameDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getMicroServiceConfigNameDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceConfigNameDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testSaveMicroServiceConfigNameDictionary() {
+ logger.info("testSaveMicroServiceConfigNameDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"microServiceConfigNameDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.saveMicroServiceConfigNameDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveMicroServiceConfigNameDictionary: exit");
+ }
+
+ @Test
+ public void testRemoveMicroServiceConfigNameDictionary() {
+ logger.info("testRemoveMicroServiceConfigNameDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.removeMicroServiceConfigNameDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceConfigNameDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveMicroServiceConfigNameDictionary: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceLocationByNameDictionaryEntityData() {
+
+ logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getMicroServiceLocationByNameDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceLocationByNameDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceLocationDictionaryEntityData() {
+ logger.info("testGetMicroServiceLocationDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getMicroServiceLocationDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceLocationDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testSaveMicroServiceLocationDictionary() {
+ logger.info("testSaveMicroServiceLocationDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"microServiceLocationDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.saveMicroServiceLocationDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveMicroServiceLocationDictionary: exit");
+ }
+
+ @Test
+ public void testRemoveMicroServiceLocationDictionary() {
+ logger.info("testRemoveMicroServiceLocationDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+
+ when(request.getReader()).thenReturn(br);
+ controller.removeMicroServiceLocationDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceLocationDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveMicroServiceLocationDictionary: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceAttributeByNameDictionaryEntityData() {
+ logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getMicroServiceAttributeByNameDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceAttributeByNameDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceAttributeDictionaryEntityData() {
+ logger.info("testGetMicroServiceAttributeDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getMicroServiceAttributeDictionaryEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceAttributeDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testSaveMicroServiceAttributeDictionary() {
+ logger.info("testSaveMicroServiceAttributeDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"modelAttributeDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.saveMicroServiceAttributeDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveMicroServiceAttributeDictionary: exit");
+ }
+
+ @Test
+ public void testRemoveMicroServiceAttributeDictionary() {
+ logger.info("testRemoveMicroServiceAttributeDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.removeMicroServiceAttributeDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveMicroServiceAttributeDictionary: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceModelsDictionaryByNameEntityData() {
+ logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ controller.getMicroServiceModelsDictionaryByNameEntityData(response);
+
+ try {
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ } catch (UnsupportedEncodingException e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceModelsDictionaryByNameEntityData: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceModelsDictionaryByVersionEntityData() {
+ logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
+
+ BufferedReader br = new BufferedReader(new StringReader(msModelJson));
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ when(request.getReader()).thenReturn(br);
+ controller.getMicroServiceModelsDictionaryByVersionEntityData(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("No model name given"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceModelsDictionaryByVersionEntityData: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceModelsDictionaryEntityData() {
+ logger.info("testGetMicroServiceModelsDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
+
+ BufferedReader br = new BufferedReader(new StringReader(msModelJson));
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ when(request.getReader()).thenReturn(br);
+ controller.getMicroServiceModelsDictionaryEntityData(response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceModelsDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceModelsDictionaryEntityDataServiceVersion() {
+ logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
+
+ BufferedReader br = new BufferedReader(new StringReader(msModelJson));
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ when(request.getReader()).thenReturn(br);
+ controller.getMicroServiceModelsDictionaryEntityDataServiceVersion(response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceModelsDictionaryEntityDataServiceVersion: exit");
+ }
+
+ @Test
+ public void testGetMicroServiceModelsDictionaryClassEntityData() {
+ logger.info("testGetMicroServiceModelsDictionaryClassEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ String msModelJson = "{\"microServiceModelsDictionaryData\":[\"modelName\"]}";
+
+ BufferedReader br = new BufferedReader(new StringReader(msModelJson));
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ when(request.getReader()).thenReturn(br);
+ controller.getMicroServiceModelsDictionaryClassEntityData(response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryClassDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetMicroServiceModelsDictionaryClassEntityData: exit");
+ }
+
+ @Test
+ public void testSaveMicroServiceModelsDictionary() {
+ logger.info("testSaveMicroServiceModelsDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ when(request.getReader()).thenReturn(br);
+ controller.saveMicroServiceModelsDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveMicroServiceModelsDictionary: exit");
+ }
+
+ @Test
+ public void testRemoveMicroServiceModelsDictionary() {
+ logger.info("testRemoveMicroServiceModelsDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.removeMicroServiceModelsDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("microServiceModelsDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveMicroServiceModelsDictionary: exit");
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java
index edc08f31b..dd355d948 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java
@@ -49,17 +49,17 @@ import org.springframework.mock.web.MockHttpServletResponse;
public class OptimizationDictionaryControllerTest {
-
- private static Logger logger = FlexLogger.getLogger(OptimizationDictionaryControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private OptimizationDictionaryController controller = null;
- BufferedReader br = null;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
+
+ private static Logger logger = FlexLogger.getLogger(OptimizationDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private OptimizationDictionaryController controller = null;
+ BufferedReader br = null;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
commonClassDao = Mockito.mock(CommonClassDao.class);
UserInfo userInfo = new UserInfo();
userInfo.setUserLoginId("testUserId");
@@ -69,21 +69,21 @@ public class OptimizationDictionaryControllerTest {
OptimizationModels optimziationModels = new OptimizationModels();
doNothing().when(commonClassDao).delete(optimziationModels);
-
+
OptimizationDictionaryController.setCommonClassDao(commonClassDao);
-
- controller = new OptimizationDictionaryController();
+
+ controller = new OptimizationDictionaryController();
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- jsonString = "{\"optimizationModelsDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+ jsonString = "{\"optimizationModelsDictionaryData\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
br = new BufferedReader(new StringReader(jsonString));
//--- mock the getReader() call
@@ -92,82 +92,82 @@ public class OptimizationDictionaryControllerTest {
DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
mock(DictionaryUtils.class);
logger.info("setUp: exit");
- }
-
- @Test
- public void testGetOptimizationModelsDictionaryEntityData() {
- logger.info("testGetOptimizationModelsDictionaryEntityData: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- String modelJson = "{\"optimizationModelsDictionaryData\":[\"modelName\"]}";
-
- BufferedReader br = new BufferedReader(new StringReader(modelJson));
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- when(request.getReader()).thenReturn(br);
- controller.getOptimizationModelsDictionaryEntityData(response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testGetOptimizationModelsDictionaryEntityData: exit");
- }
-
- @Test
- public void testSaveOptimizationModelsDictionary() {
- logger.info("testSaveOptimizationModelsDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- when(request.getReader()).thenReturn(br);
- controller.saveOptimizationModelsDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testSaveOptimizationModelsDictionary: exit");
- }
-
- @Test
- public void testRemoveOptimizationModelsDictionary() {
- logger.info("testRemoveOptimizationModelsDictionary: Entering");
-
- MockHttpServletResponse response = new MockHttpServletResponse();
- request = mock(HttpServletRequest.class);
-
- try {
- // mock the getReader() call
- jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
- + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
- + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
- + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
- + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
- + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
- + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
- + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
-
- BufferedReader br = new BufferedReader(new StringReader(jsonString));
- when(request.getReader()).thenReturn(br);
- controller.removeOptimizationModelsDictionary(request, response);
- logger.info("response.getContentAsString(): " + response.getContentAsString());
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
-
- } catch (Exception e) {
- fail("Exception: " + e);
- }
-
- logger.info("testRemoveOptimizationModelsDictionary: exit");
- }
+ }
+
+ @Test
+ public void testGetOptimizationModelsDictionaryEntityData() {
+ logger.info("testGetOptimizationModelsDictionaryEntityData: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ String modelJson = "{\"optimizationModelsDictionaryData\":[\"modelName\"]}";
+
+ BufferedReader br = new BufferedReader(new StringReader(modelJson));
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ when(request.getReader()).thenReturn(br);
+ controller.getOptimizationModelsDictionaryEntityData(response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testGetOptimizationModelsDictionaryEntityData: exit");
+ }
+
+ @Test
+ public void testSaveOptimizationModelsDictionary() {
+ logger.info("testSaveOptimizationModelsDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ when(request.getReader()).thenReturn(br);
+ controller.saveOptimizationModelsDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testSaveOptimizationModelsDictionary: exit");
+ }
+
+ @Test
+ public void testRemoveOptimizationModelsDictionary() {
+ logger.info("testRemoveOptimizationModelsDictionary: Entering");
+
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ request = mock(HttpServletRequest.class);
+
+ try {
+ // mock the getReader() call
+ jsonString = "{\"data\": {\"modelName\": \"test\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", "
+ + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", "
+ + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false},"
+ + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" },"
+ + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", "
+ + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\","
+ + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, "
+ + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }";
+
+ BufferedReader br = new BufferedReader(new StringReader(jsonString));
+ when(request.getReader()).thenReturn(br);
+ controller.removeOptimizationModelsDictionary(request, response);
+ logger.info("response.getContentAsString(): " + response.getContentAsString());
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("optimizationModelsDictionaryDatas"));
+
+ } catch (Exception e) {
+ fail("Exception: " + e);
+ }
+
+ logger.info("testRemoveOptimizationModelsDictionary: exit");
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryControllerTest.java
index 40ec34831..9bf2ae590 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryControllerTest.java
@@ -48,338 +48,338 @@ import org.onap.policy.rest.jpa.UserInfo;
import org.springframework.mock.web.MockHttpServletResponse;
public class PolicyScopeDictionaryControllerTest {
- private static Logger logger = FlexLogger.getLogger(PolicyScopeDictionaryControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private PolicyScopeDictionaryController controller = null;
- private MockHttpServletResponse response = null;
- private UserInfo userInfo;
- private List<String> data;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- commonClassDao = Mockito.mock(CommonClassDao.class);
-
- data = new ArrayList<>();
- data.add("Test");
-
- userInfo = new UserInfo();
- userInfo.setUserLoginId("Test");
- userInfo.setUserName("Test");
-
- doNothing().when(commonClassDao).delete(new GroupPolicyScopeList());
- doNothing().when(commonClassDao).save(new GroupPolicyScopeList());
-
- controller = new PolicyScopeDictionaryController();
- controller.setCommonClassDao(commonClassDao);
-
- request = Mockito.mock(HttpServletRequest.class);
- response = new MockHttpServletResponse();
- new DictionaryUtils(commonClassDao);
+ private static Logger logger = FlexLogger.getLogger(PolicyScopeDictionaryControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private PolicyScopeDictionaryController controller = null;
+ private MockHttpServletResponse response = null;
+ private UserInfo userInfo;
+ private List<String> data;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+
+ data = new ArrayList<>();
+ data.add("Test");
+
+ userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+
+ doNothing().when(commonClassDao).delete(new GroupPolicyScopeList());
+ doNothing().when(commonClassDao).save(new GroupPolicyScopeList());
+
+ controller = new PolicyScopeDictionaryController();
+ controller.setCommonClassDao(commonClassDao);
+
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ new DictionaryUtils(commonClassDao);
DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
mock(DictionaryUtils.class);
- logger.info("setUp: exit");
- }
-
- @Test
- public void testGetGroupPolicyScopeEntityDataByName(){
- when(commonClassDao.getDataByColumn(GroupPolicyScopeList.class, "name")).thenReturn(data);
- controller.getGroupPolicyScopeEntityDataByName(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetGroupPolicyScopeEntityData(){
- when(commonClassDao.getData(GroupPolicyScopeList.class)).thenReturn(new ArrayList<>());
- controller.getGroupPolicyScopeEntityData(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetPSClosedLoopEntityDataByName(){
- when(commonClassDao.getDataByColumn(PolicyScopeClosedLoop.class, "name")).thenReturn(data);
- controller.getPSClosedLoopEntityDataByName(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetPSClosedLoopEntityData(){
- when(commonClassDao.getData(PolicyScopeClosedLoop.class)).thenReturn(new ArrayList<>());
- controller.getPSClosedLoopEntityData(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetPSServiceEntityDataByName(){
- when(commonClassDao.getDataByColumn(PolicyScopeService.class, "name")).thenReturn(data);
- controller.getPSServiceEntityDataByName(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetPSServiceEntityData(){
- when(commonClassDao.getData(PolicyScopeService.class)).thenReturn(new ArrayList<>());
- controller.getPSServiceEntityData(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetPSTypeEntityDataByName(){
- when(commonClassDao.getDataByColumn(PolicyScopeType.class, "name")).thenReturn(data);
- controller.getPSTypeEntityDataByName(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetPSTypeEntityData(){
- when(commonClassDao.getData(PolicyScopeType.class)).thenReturn(new ArrayList<>());
- controller.getPSTypeEntityData(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetPSResourceEntityDataByName(){
- when(commonClassDao.getDataByColumn(PolicyScopeResource.class, "name")).thenReturn(data);
- controller.getPSResourceEntityDataByName(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetPSResourceEntityData(){
- when(commonClassDao.getData(PolicyScopeResource.class)).thenReturn(new ArrayList<>());
- controller.getPSResourceEntityData(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testSavePSGroupScopeDictionary(){
- jsonString = "{\"groupPolicyScopeListData\":{\"description\":\"test\",\"groupName\":\"Test\"},\"groupPolicyScopeListData1\":{\"closedloop\":\"SampleClosedLoop\",\"resource\":\"SampleResource\",\"service\":\"SampleService\",\"type\":\"SampleType\"},\"userid\":\"demo\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePSGroupScopeDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdatePSGroupScopeDictionary(){
- jsonString = "{\"groupPolicyScopeListData\":{\"id\":1,\"description\":\"test\",\"groupName\":\"Test\"},\"groupPolicyScopeListData1\":{\"closedloop\":\"SampleClosedLoop\",\"resource\":\"SampleResource\",\"service\":\"SampleService\",\"type\":\"SampleType\"},\"userid\":\"demo\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePSGroupScopeDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemovePSGroupScopeDictionary(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removePSGroupScopeDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testSavePSClosedLoopDictionary(){
- jsonString = "{\"userid\":\"demo\",\"psClosedLoopDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePSClosedLoopDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdatePSClosedLoopDictionary(){
- jsonString = "{\"userid\":\"demo\",\"psClosedLoopDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePSClosedLoopDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemovePSClosedLoopDictionary(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removePSClosedLoopDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testSavePSServiceDictionary(){
- jsonString = "{\"userid\":\"demo\",\"psServiceDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePSServiceDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdatePSServiceDictionary(){
- jsonString = "{\"userid\":\"demo\",\"psServiceDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePSServiceDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemovePSServiceDictionary(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removePSServiceDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testSavePSTypeDictionary(){
- jsonString = "{\"userid\":\"demo\",\"psTypeDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePSTypeDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdatePSTypeDictionary(){
- jsonString = "{\"userid\":\"demo\",\"psTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePSTypeDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemovePSTypeDictionary(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removePSTypeDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testSavePSResourceDictionary(){
- jsonString = "{\"userid\":\"demo\",\"psResourceDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePSResourceDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdatePSResourceDictionary(){
- jsonString = "{\"userid\":\"demo\",\"psResourceDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.savePSResourceDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemovePSResourceDictionary(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removePSResourceDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
+ logger.info("setUp: exit");
+ }
+
+ @Test
+ public void testGetGroupPolicyScopeEntityDataByName(){
+ when(commonClassDao.getDataByColumn(GroupPolicyScopeList.class, "name")).thenReturn(data);
+ controller.getGroupPolicyScopeEntityDataByName(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetGroupPolicyScopeEntityData(){
+ when(commonClassDao.getData(GroupPolicyScopeList.class)).thenReturn(new ArrayList<>());
+ controller.getGroupPolicyScopeEntityData(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPSClosedLoopEntityDataByName(){
+ when(commonClassDao.getDataByColumn(PolicyScopeClosedLoop.class, "name")).thenReturn(data);
+ controller.getPSClosedLoopEntityDataByName(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPSClosedLoopEntityData(){
+ when(commonClassDao.getData(PolicyScopeClosedLoop.class)).thenReturn(new ArrayList<>());
+ controller.getPSClosedLoopEntityData(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPSServiceEntityDataByName(){
+ when(commonClassDao.getDataByColumn(PolicyScopeService.class, "name")).thenReturn(data);
+ controller.getPSServiceEntityDataByName(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPSServiceEntityData(){
+ when(commonClassDao.getData(PolicyScopeService.class)).thenReturn(new ArrayList<>());
+ controller.getPSServiceEntityData(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPSTypeEntityDataByName(){
+ when(commonClassDao.getDataByColumn(PolicyScopeType.class, "name")).thenReturn(data);
+ controller.getPSTypeEntityDataByName(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPSTypeEntityData(){
+ when(commonClassDao.getData(PolicyScopeType.class)).thenReturn(new ArrayList<>());
+ controller.getPSTypeEntityData(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPSResourceEntityDataByName(){
+ when(commonClassDao.getDataByColumn(PolicyScopeResource.class, "name")).thenReturn(data);
+ controller.getPSResourceEntityDataByName(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetPSResourceEntityData(){
+ when(commonClassDao.getData(PolicyScopeResource.class)).thenReturn(new ArrayList<>());
+ controller.getPSResourceEntityData(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testSavePSGroupScopeDictionary(){
+ jsonString = "{\"groupPolicyScopeListData\":{\"description\":\"test\",\"groupName\":\"Test\"},\"groupPolicyScopeListData1\":{\"closedloop\":\"SampleClosedLoop\",\"resource\":\"SampleResource\",\"service\":\"SampleService\",\"type\":\"SampleType\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePSGroupScopeDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdatePSGroupScopeDictionary(){
+ jsonString = "{\"groupPolicyScopeListData\":{\"id\":1,\"description\":\"test\",\"groupName\":\"Test\"},\"groupPolicyScopeListData1\":{\"closedloop\":\"SampleClosedLoop\",\"resource\":\"SampleResource\",\"service\":\"SampleService\",\"type\":\"SampleType\"},\"userid\":\"demo\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePSGroupScopeDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemovePSGroupScopeDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removePSGroupScopeDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSavePSClosedLoopDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"psClosedLoopDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePSClosedLoopDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdatePSClosedLoopDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"psClosedLoopDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePSClosedLoopDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemovePSClosedLoopDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removePSClosedLoopDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSavePSServiceDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"psServiceDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePSServiceDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdatePSServiceDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"psServiceDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePSServiceDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemovePSServiceDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removePSServiceDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSavePSTypeDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"psTypeDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePSTypeDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdatePSTypeDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"psTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePSTypeDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemovePSTypeDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removePSTypeDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSavePSResourceDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"psResourceDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePSResourceDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdatePSResourceDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"psResourceDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.savePSResourceDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemovePSResourceDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removePSResourceDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyControllerTest.java
index 1f8cb6f90..dbddecc51 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyControllerTest.java
@@ -54,22 +54,22 @@ import com.att.research.xacml.api.pap.PAPException;
public class PushPolicyControllerTest {
-
- private static Logger logger = FlexLogger.getLogger(PushPolicyControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private PushPolicyController controller = null;
- private HttpServletResponse response = null;
+
+ private static Logger logger = FlexLogger.getLogger(PushPolicyControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private PushPolicyController controller = null;
+ private HttpServletResponse response = null;
private List<String> headers = new ArrayList<>();
private ServletConfig servletConfig;
private XACMLPapServlet pap;
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- request = Mockito.mock(HttpServletRequest.class);
- response = Mockito.mock(HttpServletResponse.class);
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ request = Mockito.mock(HttpServletRequest.class);
+ response = Mockito.mock(HttpServletResponse.class);
Mockito.when(request.getHeaderNames()).thenReturn(Collections.enumeration(headers));
Mockito.when(request.getAttributeNames()).thenReturn(Collections.enumeration(headers));
@@ -78,72 +78,72 @@ public class PushPolicyControllerTest {
Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("src/test/resources/xacml.pap.properties");
- commonClassDao = Mockito.mock(CommonClassDao.class);
- controller = new PushPolicyController();
- controller.setCommonClassDao(commonClassDao);
- logger.info("setUp: exit");
- }
-
- @Test
- public void testPushPolicy() throws ServletException, PAPException{
- PolicyVersion versionData = new PolicyVersion();
- versionData.setPolicyName("com"+File.separator+"Config_Test");
- versionData.setActiveVersion(1);
- versionData.setHigherVersion(1);
- List<Object> data = new ArrayList<>();
- data.add(versionData);
- when(commonClassDao.getDataById(PolicyVersion.class, "policyName", "com"+File.separator+"Config_Test")).thenReturn(data);
- pap = new XACMLPapServlet();
- pap.init(servletConfig);
- callPushPolicy();
- when(commonClassDao.getDataById(PolicyVersion.class, "policyName", "com"+File.separator+"Config_Test")).thenReturn(null);
- callPushPolicy();
- }
-
- public void callPushPolicy(){
- jsonString = "{\"policyScope\":\"com\",\"filePrefix\":\"Config_\",\"policyName\":\"Test\",\"pdpGroup\":\"default\"}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- char[] charBuffer = new char[8 * 1024];
- StringBuilder builder = new StringBuilder();
- int numCharsRead;
- while ((numCharsRead = br.read(charBuffer, 0, charBuffer.length)) != -1) {
- builder.append(charBuffer, 0, numCharsRead);
- }
- when(request.getInputStream()).thenReturn(getInputStream(builder.toString().getBytes(StandardCharsets.UTF_8)));
- controller.pushPolicy(request, response);
- assertTrue(response != null);
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- public ServletInputStream getInputStream(byte[] body) throws IOException {
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+ controller = new PushPolicyController();
+ controller.setCommonClassDao(commonClassDao);
+ logger.info("setUp: exit");
+ }
+
+ @Test
+ public void testPushPolicy() throws ServletException, PAPException{
+ PolicyVersion versionData = new PolicyVersion();
+ versionData.setPolicyName("com"+File.separator+"Config_Test");
+ versionData.setActiveVersion(1);
+ versionData.setHigherVersion(1);
+ List<Object> data = new ArrayList<>();
+ data.add(versionData);
+ when(commonClassDao.getDataById(PolicyVersion.class, "policyName", "com"+File.separator+"Config_Test")).thenReturn(data);
+ pap = new XACMLPapServlet();
+ pap.init(servletConfig);
+ callPushPolicy();
+ when(commonClassDao.getDataById(PolicyVersion.class, "policyName", "com"+File.separator+"Config_Test")).thenReturn(null);
+ callPushPolicy();
+ }
+
+ public void callPushPolicy(){
+ jsonString = "{\"policyScope\":\"com\",\"filePrefix\":\"Config_\",\"policyName\":\"Test\",\"pdpGroup\":\"default\"}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ char[] charBuffer = new char[8 * 1024];
+ StringBuilder builder = new StringBuilder();
+ int numCharsRead;
+ while ((numCharsRead = br.read(charBuffer, 0, charBuffer.length)) != -1) {
+ builder.append(charBuffer, 0, numCharsRead);
+ }
+ when(request.getInputStream()).thenReturn(getInputStream(builder.toString().getBytes(StandardCharsets.UTF_8)));
+ controller.pushPolicy(request, response);
+ assertTrue(response != null);
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ public ServletInputStream getInputStream(byte[] body) throws IOException {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body);
ServletInputStream servletInputStream = new ServletInputStream() {
public int read() throws IOException {
return byteArrayInputStream.read();
}
- @Override
- public boolean isFinished() {
- return false;
- }
+ @Override
+ public boolean isFinished() {
+ return false;
+ }
- @Override
- public boolean isReady() {
- return false;
- }
+ @Override
+ public boolean isReady() {
+ return false;
+ }
- @Override
- public void setReadListener(ReadListener readListener) {
- }
+ @Override
+ public void setReadListener(ReadListener readListener) {
+ }
};
return servletInputStream;
}
-
- @After
- public void destroy(){
- if(pap!=null)
- pap.destroy();
- }
+
+ @After
+ public void destroy(){
+ if(pap!=null)
+ pap.destroy();
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java
index 7d23475a1..ae1840ebb 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java
@@ -45,158 +45,158 @@ import org.onap.policy.rest.jpa.UserInfo;
import org.springframework.mock.web.MockHttpServletResponse;
public class SafePolicyControllerTest {
-
- private static Logger logger = FlexLogger.getLogger(SafePolicyControllerTest.class);
- private static CommonClassDao commonClassDao;
- private String jsonString = null;
- private HttpServletRequest request = null;
- private SafePolicyController controller = null;
- private MockHttpServletResponse response = null;
- private UserInfo userInfo;
- private List<String> data;
-
- @Before
- public void setUp() throws Exception {
- logger.info("setUp: Entering");
- commonClassDao = Mockito.mock(CommonClassDao.class);
-
- data = new ArrayList<>();
- data.add("Test");
-
- userInfo = new UserInfo();
- userInfo.setUserLoginId("Test");
- userInfo.setUserName("Test");
-
- doNothing().when(commonClassDao).delete(new RiskType());
- doNothing().when(commonClassDao).save(new RiskType());
-
- controller = new SafePolicyController();
- controller.setCommonClassDao(commonClassDao);
- new DictionaryUtils(commonClassDao);
- DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
- mock(DictionaryUtils.class);
- request = Mockito.mock(HttpServletRequest.class);
- response = new MockHttpServletResponse();
- logger.info("setUp: exit");
- }
-
- @Test
- public void testGetRiskTypeDictionaryByNameEntityData(){
- when(commonClassDao.getDataByColumn(RiskType.class, "name")).thenReturn(data);
- controller.getRiskTypeDictionaryByNameEntityData(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetRiskTypeDictionaryEntityData(){
- when(commonClassDao.getData(RiskType.class)).thenReturn(new ArrayList<>());
- controller.getRiskTypeDictionaryEntityData(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetSafePolicyWarningEntityDataByName(){
- when(commonClassDao.getDataByColumn(SafePolicyWarning.class, "name")).thenReturn(data);
- controller.getSafePolicyWarningEntityDataByName(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testGetSafePolicyWarningeEntityData(){
- when(commonClassDao.getData(SafePolicyWarning.class)).thenReturn(new ArrayList<>());
- controller.getSafePolicyWarningeEntityData(response);
- try {
- assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas"));
- } catch (Exception e) {
- fail();
- logger.error(e.getMessage(),e);
- }
- }
-
- @Test
- public void testSaveRiskTypeDictionary(){
- jsonString = "{\"userid\":\"demo\",\"riskTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveRiskTypeDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdateRiskTypeDictionary(){
- jsonString = "{\"userid\":\"demo\",\"riskTypeDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveRiskTypeDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemoveRiskTypeDictionary(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeRiskTypeDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testSaveSafePolicyWarningDictionary(){
- jsonString = "{\"userid\":\"demo\",\"safePolicyWarningData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveSafePolicyWarningDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testUpdateSafePolicyWarningDictionary(){
- jsonString = "{\"userid\":\"demo\",\"safePolicyWarningData\":{\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.saveSafePolicyWarningDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
-
- @Test
- public void testRemoveSafePolicyWarningDictionary(){
- jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
- when(request.getReader()).thenReturn(br);
- controller.removeSafePolicyWarningDictionary(request, response);
- assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas"));
- }catch(Exception e){
- logger.error("Exception"+ e);
- }
- }
+
+ private static Logger logger = FlexLogger.getLogger(SafePolicyControllerTest.class);
+ private static CommonClassDao commonClassDao;
+ private String jsonString = null;
+ private HttpServletRequest request = null;
+ private SafePolicyController controller = null;
+ private MockHttpServletResponse response = null;
+ private UserInfo userInfo;
+ private List<String> data;
+
+ @Before
+ public void setUp() throws Exception {
+ logger.info("setUp: Entering");
+ commonClassDao = Mockito.mock(CommonClassDao.class);
+
+ data = new ArrayList<>();
+ data.add("Test");
+
+ userInfo = new UserInfo();
+ userInfo.setUserLoginId("Test");
+ userInfo.setUserName("Test");
+
+ doNothing().when(commonClassDao).delete(new RiskType());
+ doNothing().when(commonClassDao).save(new RiskType());
+
+ controller = new SafePolicyController();
+ controller.setCommonClassDao(commonClassDao);
+ new DictionaryUtils(commonClassDao);
+ DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
+ mock(DictionaryUtils.class);
+ request = Mockito.mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+ logger.info("setUp: exit");
+ }
+
+ @Test
+ public void testGetRiskTypeDictionaryByNameEntityData(){
+ when(commonClassDao.getDataByColumn(RiskType.class, "name")).thenReturn(data);
+ controller.getRiskTypeDictionaryByNameEntityData(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetRiskTypeDictionaryEntityData(){
+ when(commonClassDao.getData(RiskType.class)).thenReturn(new ArrayList<>());
+ controller.getRiskTypeDictionaryEntityData(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetSafePolicyWarningEntityDataByName(){
+ when(commonClassDao.getDataByColumn(SafePolicyWarning.class, "name")).thenReturn(data);
+ controller.getSafePolicyWarningEntityDataByName(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testGetSafePolicyWarningeEntityData(){
+ when(commonClassDao.getData(SafePolicyWarning.class)).thenReturn(new ArrayList<>());
+ controller.getSafePolicyWarningeEntityData(response);
+ try {
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas"));
+ } catch (Exception e) {
+ fail();
+ logger.error(e.getMessage(),e);
+ }
+ }
+
+ @Test
+ public void testSaveRiskTypeDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"riskTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveRiskTypeDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateRiskTypeDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"riskTypeDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveRiskTypeDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveRiskTypeDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeRiskTypeDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testSaveSafePolicyWarningDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"safePolicyWarningData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveSafePolicyWarningDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testUpdateSafePolicyWarningDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"safePolicyWarningData\":{\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.saveSafePolicyWarningDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
+
+ @Test
+ public void testRemoveSafePolicyWarningDictionary(){
+ jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){
+ when(request.getReader()).thenReturn(br);
+ controller.removeSafePolicyWarningDictionary(request, response);
+ assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas"));
+ }catch(Exception e){
+ logger.error("Exception"+ e);
+ }
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElasticSearchPolicyUpdateTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElasticSearchPolicyUpdateTest.java
index 2b1300cc4..da9c4e8f5 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElasticSearchPolicyUpdateTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElasticSearchPolicyUpdateTest.java
@@ -40,28 +40,28 @@ import org.onap.policy.rest.jpa.ConfigurationDataEntity;
import org.onap.policy.rest.jpa.PolicyEntity;
public class ElasticSearchPolicyUpdateTest {
-
- private static Logger logger = FlexLogger.getLogger(ElasticSearchPolicyUpdateTest.class);
- private Object policyContent = "";
- private XACMLPAPTest papTest;
-
- @Before
- public void setUp() throws IOException, ServletException, SQLException{
- // Set the system property temporarily
- System.setProperty("PROPERTY_FILE", "src/test/resources/policyelk.properties");
+
+ private static Logger logger = FlexLogger.getLogger(ElasticSearchPolicyUpdateTest.class);
+ private Object policyContent = "";
+ private XACMLPAPTest papTest;
+
+ @Before
+ public void setUp() throws IOException, ServletException, SQLException{
+ // Set the system property temporarily
+ System.setProperty("PROPERTY_FILE", "src/test/resources/policyelk.properties");
try {
- ClassLoader classLoader = getClass().getClassLoader();
- policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
- } catch (Exception e1) {
- logger.error("Exception Occured"+e1);
- }
+ ClassLoader classLoader = getClass().getClassLoader();
+ policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
papTest = new XACMLPAPTest();
- papTest.setDBDao();
- }
-
- @Test
- public void testElasticSearchMainFunction() throws SQLException{
- ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
+ papTest.setDBDao();
+ }
+
+ @Test
+ public void testElasticSearchMainFunction() throws SQLException{
+ ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
configurationEntity.setConfigBody("Sample Test");
configurationEntity.setConfigType("OTHER");
configurationEntity.setConfigurationName("com.Config_SampleTest1206.1.txt");
@@ -70,7 +70,7 @@ public class ElasticSearchPolicyUpdateTest {
configurationEntity.setModifiedDate(new Date());
- PolicyEntity entity = new PolicyEntity();
+ PolicyEntity entity = new PolicyEntity();
entity.setPolicyName("Config_SampleTest.1.xml");
entity.setPolicyData(policyContent.toString());
entity.setScope("com");
@@ -84,14 +84,14 @@ public class ElasticSearchPolicyUpdateTest {
dao.save(configurationEntity);
dao.save(entity);
dao.delete(dao.getEntityItem(PolicyEntity.class, "policyName", "Config_SampleTest.1.xml"));
- ElasticSearchPolicyUpdate.main(null);
- StringBuilder policyDataString = new StringBuilder();
- ElasticSearchPolicyUpdate.constructPolicyData(policyContent, policyDataString);
- assertTrue(policyDataString.toString().contains("onapName"));
- }
-
- @After
- public void reset(){
- System.clearProperty("PROPERTY_FILE");
- }
+ ElasticSearchPolicyUpdate.main(null);
+ StringBuilder policyDataString = new StringBuilder();
+ ElasticSearchPolicyUpdate.constructPolicyData(policyContent, policyDataString);
+ assertTrue(policyDataString.toString().contains("onapName"));
+ }
+
+ @After
+ public void reset(){
+ System.clearProperty("PROPERTY_FILE");
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java
index 853d75ce6..2f3d580f7 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java
@@ -39,108 +39,108 @@ import org.onap.policy.rest.adapter.PolicyRestAdapter;
public class ElkConnectorImplTest {
- @Test
- public void isAlphaNumericTest() {
- try {
- Method method = ElkConnectorImpl.class.getDeclaredMethod("isAlphaNumeric", String.class);
- method.setAccessible(true);
- assertTrue((boolean) method.invoke(new ElkConnectorImpl(), "abc123"));
- assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123*"));
- assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123{}"));
- assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123\n"));
- assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123<"));
- assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123:"));
- } catch (Exception e) {
- fail();
- }
- }
-
- @Test
- public void searchTest(){
- JestResult r1=null, r2=null, r3=null, r4=null;
-
- // Should always work if the above test passes and ELK server is up
- try{
- r1 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123");
- } catch (Exception e) {
- // ELK server is down. Don't continue the test
- if(e instanceof IllegalStateException){
- return;
- }
- fail();
- }
-
- // Should always work
- try{
- r2 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The_quick_brown_fox_jumps_over_the_lazy_dog");
- } catch (Exception e) {
- fail();
- }
-
- // Should throw exception
- try{
- r3 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123{}");
- } catch (Exception e) {
- if(! (e instanceof IllegalArgumentException)){
- fail();
- }
- }
-
- // Should throw exception
- try{
- r4 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The quick brown fox jumps over the lazy dog");
- } catch (Exception e) {
- if(! (e instanceof IllegalArgumentException)){
- fail();
- }
- }
-
- assertNotNull(r1);
- assertNotNull(r2);
- assertNull(r3);
- assertNull(r4);
- }
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void testDelete() {
- thrown.expect(NullPointerException.class);
-
- ElkConnectorImpl impl = new ElkConnectorImpl();
- PolicyRestAdapter adapter = new PolicyRestAdapter();
- impl.delete(adapter);
- fail("Expected exception to be thrown");
- }
-
-
- @Test
- public void testPut() throws IOException {
- thrown.expect(NullPointerException.class);
-
- ElkConnectorImpl impl = new ElkConnectorImpl();
- PolicyRestAdapter adapter = new PolicyRestAdapter();
- impl.put(adapter);
- fail("Expected exception to be thrown");
- }
-
- @Test
- public void testUpdate() {
- thrown.expect(IllegalStateException.class);
-
- ElkConnectorImpl impl = new ElkConnectorImpl();
- PolicyRestAdapter adapter = new PolicyRestAdapter();
- impl.update(adapter);
- fail("Expected exception to be thrown");
- }
-
- @Test
- public void testSearchWithFilter() {
- thrown.expect(IllegalStateException.class);
-
- ElkConnectorImpl impl = new ElkConnectorImpl();
- impl.search(PolicyIndexType.config, "search", null);
- fail("Expected exception to be thrown");
- }
+ @Test
+ public void isAlphaNumericTest() {
+ try {
+ Method method = ElkConnectorImpl.class.getDeclaredMethod("isAlphaNumeric", String.class);
+ method.setAccessible(true);
+ assertTrue((boolean) method.invoke(new ElkConnectorImpl(), "abc123"));
+ assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123*"));
+ assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123{}"));
+ assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123\n"));
+ assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123<"));
+ assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123:"));
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void searchTest(){
+ JestResult r1=null, r2=null, r3=null, r4=null;
+
+ // Should always work if the above test passes and ELK server is up
+ try{
+ r1 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123");
+ } catch (Exception e) {
+ // ELK server is down. Don't continue the test
+ if(e instanceof IllegalStateException){
+ return;
+ }
+ fail();
+ }
+
+ // Should always work
+ try{
+ r2 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The_quick_brown_fox_jumps_over_the_lazy_dog");
+ } catch (Exception e) {
+ fail();
+ }
+
+ // Should throw exception
+ try{
+ r3 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123{}");
+ } catch (Exception e) {
+ if(! (e instanceof IllegalArgumentException)){
+ fail();
+ }
+ }
+
+ // Should throw exception
+ try{
+ r4 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The quick brown fox jumps over the lazy dog");
+ } catch (Exception e) {
+ if(! (e instanceof IllegalArgumentException)){
+ fail();
+ }
+ }
+
+ assertNotNull(r1);
+ assertNotNull(r2);
+ assertNull(r3);
+ assertNull(r4);
+ }
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void testDelete() {
+ thrown.expect(NullPointerException.class);
+
+ ElkConnectorImpl impl = new ElkConnectorImpl();
+ PolicyRestAdapter adapter = new PolicyRestAdapter();
+ impl.delete(adapter);
+ fail("Expected exception to be thrown");
+ }
+
+
+ @Test
+ public void testPut() throws IOException {
+ thrown.expect(NullPointerException.class);
+
+ ElkConnectorImpl impl = new ElkConnectorImpl();
+ PolicyRestAdapter adapter = new PolicyRestAdapter();
+ impl.put(adapter);
+ fail("Expected exception to be thrown");
+ }
+
+ @Test
+ public void testUpdate() {
+ thrown.expect(IllegalStateException.class);
+
+ ElkConnectorImpl impl = new ElkConnectorImpl();
+ PolicyRestAdapter adapter = new PolicyRestAdapter();
+ impl.update(adapter);
+ fail("Expected exception to be thrown");
+ }
+
+ @Test
+ public void testSearchWithFilter() {
+ thrown.expect(IllegalStateException.class);
+
+ ElkConnectorImpl impl = new ElkConnectorImpl();
+ impl.search(PolicyIndexType.config, "search", null);
+ fail("Expected exception to be thrown");
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PairTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PairTest.java
index 68f1daa0b..0b8c86c1e 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PairTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PairTest.java
@@ -25,20 +25,20 @@ import org.junit.Test;
import org.onap.policy.pap.xacml.rest.elk.client.Pair;
public class PairTest {
- @Test
- public void testPair() {
- String testLeft = "left";
- String testRight = "right";
-
- // Test constructor
- Pair<String, String> pair = new Pair<String, String>(testLeft, testRight);
- assertEquals(pair.left(), testLeft);
- assertEquals(pair.right(), testRight);
-
- // Test setters
- pair.left(testRight);
- pair.right(testLeft);
- assertEquals(pair.left(), testRight);
- assertEquals(pair.right(), testLeft);
- }
+ @Test
+ public void testPair() {
+ String testLeft = "left";
+ String testRight = "right";
+
+ // Test constructor
+ Pair<String, String> pair = new Pair<String, String>(testLeft, testRight);
+ assertEquals(pair.left(), testLeft);
+ assertEquals(pair.right(), testRight);
+
+ // Test setters
+ pair.left(testRight);
+ pair.right(testLeft);
+ assertEquals(pair.left(), testRight);
+ assertEquals(pair.right(), testLeft);
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticDataTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticDataTest.java
index a84e4a0cd..76c0ce788 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticDataTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticDataTest.java
@@ -30,159 +30,159 @@ import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.rest.adapter.YAMLParams;
public class PolicyElasticDataTest {
- @Test
- public void testSetAndGet() {
- String testKey = "testKey";
- String testVal = "testVal";
- LinkedHashMap<String, String> testMap = new LinkedHashMap<String, String>();
- testMap.put(testKey, testVal);
- ArrayList<Object> testArray = new ArrayList<Object>();
- testArray.add(testVal);
- List<String> testList = new ArrayList<String>();
- testList.add(testVal);
- List<Object> testObjectList = new ArrayList<Object>();
- testObjectList.add(testVal);
- YAMLParams testYaml = new YAMLParams();
-
- PolicyRestAdapter adapter = new PolicyRestAdapter();
- adapter.setConfigPolicyType(testVal);
-
- PolicyElasticData data = new PolicyElasticData(adapter);
- data.setScope(testVal);
- assertEquals(data.getScope(), testVal);
- data.setPolicyType(testVal);
- assertEquals(data.getPolicyType(), testVal);
- data.setConfigPolicyType(testVal);
- assertEquals(data.getConfigPolicyType(), testVal);
- data.setConfigBodyData(testVal);
- assertEquals(data.getConfigBodyData(), testVal);
- data.setPolicyName(testVal);
- assertEquals(data.getPolicyName(), testVal);
- data.setPolicyDescription(testVal);
- assertEquals(data.getPolicyDescription(), testVal);
- data.setOnapName(testVal);
- assertEquals(data.getOnapName(), testVal);
- data.setConfigName(testVal);
- assertEquals(data.getConfigName(), testVal);
- data.setConfigType(testVal);
- assertEquals(data.getConfigType(), testVal);
- data.setJsonBody(testVal);
- assertEquals(data.getJsonBody(), testVal);
- data.setServiceTypePolicyName(testMap);
- assertEquals(data.getServiceTypePolicyName(), testMap);
- data.setVerticaMetrics(testMap);
- assertEquals(data.getVerticaMetrics(), testMap);
- data.setDescription(testMap);
- assertEquals(data.getDescription(), testMap);
- data.setAttributeFields(testMap);
- assertEquals(data.getAttributeFields(), testMap);
- data.setPolicyScope(testVal);
- assertEquals(data.getPolicyScope(), testVal);
- data.setProviderComboBox(testVal);
- assertEquals(data.getProviderComboBox(), testVal);
- data.setRiskType(testVal);
- assertEquals(data.getRiskType(), testVal);
- data.setRiskLevel(testVal);
- assertEquals(data.getRiskLevel(), testVal);
- data.setGuard(testVal);
- assertEquals(data.getGuard(), testVal);
- data.setTtlDate(testVal);
- assertEquals(data.getTtlDate(), testVal);
- data.setMatching(testMap);
- assertEquals(data.getMatching(), testMap);
- data.setTriggerSignatures(testArray);
- assertEquals(data.getTriggerSignatures(), testArray);
- data.setSymptomSignatures(testArray);
- assertEquals(data.getSymptomSignatures(), testArray);
- data.setLogicalConnector(testVal);
- assertEquals(data.getLogicalConnector(), testVal);
- data.setPolicyStatus(testVal);
- assertEquals(data.getPolicyStatus(), testVal);
- data.setGocServerScope(testVal);
- assertEquals(data.getGocServerScope(), testVal);
- data.setSupressionType(testVal);
- assertEquals(data.getSupressionType(), testVal);
- data.setServiceType(testVal);
- assertEquals(data.getServiceType(),testVal);
- data.setUuid(testVal);
- assertEquals(data.getUuid(), testVal);
- data.setLocation(testVal);
- assertEquals(data.getLocation(), testVal);
- data.setPriority(testVal);
- assertEquals(data.getPriority(), testVal);
- data.setMsLocation(testVal);
- assertEquals(data.getMsLocation(),testVal);
- data.setRuleName(testVal);
- assertEquals(data.getRuleName(), testVal);
- data.setBrmsParamBody(testMap);
- assertEquals(data.getBrmsParamBody(), testMap);
- data.setBrmsController(testVal);
- assertEquals(data.getBrmsController(), testVal);
- data.setBrmsDependency(testList);
- assertEquals(data.getBrmsDependency(), testList);
- data.setRuleData(testMap);
- assertEquals(data.getRuleData(), testMap);
- data.setRuleListData(testMap);
- assertEquals(data.getRuleListData(), testMap);
- data.setDrlRuleAndUIParams(testMap);
- assertEquals(data.getDrlRuleAndUIParams(), testMap);
- data.setClearTimeOut(testVal);
- assertEquals(data.getClearTimeOut(), testVal);
- data.setTrapMaxAge(testVal);
- assertEquals(data.getTrapMaxAge(), testVal);
- data.setVerificationclearTimeOut(testVal);
- assertEquals(data.getVerificationclearTimeOut(), testVal);
- data.setDynamicLayoutMap(testMap);
- assertEquals(data.getDynamicLayoutMap(), testMap);
- data.setFwPolicyType(testVal);
- assertEquals(data.getFwPolicyType(), testVal);
- data.setFwattributes(testArray);
- assertEquals(data.getFwattributes(), testArray);
- data.setParentForChild(testVal);
- assertEquals(data.getParentForChild(), testVal);
- data.setSecurityZone(testVal);
- assertEquals(data.getSecurityZone(), testVal);
- data.setRuleCombiningAlgId(testVal);
- assertEquals(data.getRuleCombiningAlgId(), testVal);
- data.setDynamicFieldConfigAttributes(testMap);
- assertEquals(data.getDynamicFieldConfigAttributes(), testMap);
- data.setDynamicSettingsMap(testMap);
- assertEquals(data.getDynamicSettingsMap(), testMap);
- data.setDropDownMap(testMap);
- assertEquals(data.getDropDownMap(), testMap);
- data.setActionPerformer(testVal);
- assertEquals(data.getActionPerformer(), testVal);
- data.setActionAttribute(testVal);
- assertEquals(data.getActionAttribute(), testVal);
- data.setDynamicRuleAlgorithmLabels(testList);
- assertEquals(data.getDynamicRuleAlgorithmLabels(), testList);
- data.setDynamicRuleAlgorithmCombo(testList);
- assertEquals(data.getDynamicRuleAlgorithmCombo(), testList);
- data.setDynamicRuleAlgorithmField1(testList);
- assertEquals(data.getDynamicRuleAlgorithmField1(), testList);
- data.setDynamicRuleAlgorithmField2(testList);
- assertEquals(data.getDynamicRuleAlgorithmField2(), testList);
- data.setDynamicVariableList(testObjectList);
- assertEquals(data.getDynamicVariableList(), testObjectList);
- data.setDataTypeList(testList);
- assertEquals(data.getDataTypeList(), testList);
- data.setActionAttributeValue(testVal);
- assertEquals(data.getActionAttributeValue(), testVal);
- data.setRuleProvider(testVal);
- assertEquals(data.getRuleProvider(), testVal);
- data.setActionBody(testVal);
- assertEquals(data.getActionBody(), testVal);
- data.setActionDictHeader(testVal);
- assertEquals(data.getActionDictHeader(), testVal);
- data.setActionDictType(testVal);
- assertEquals(data.getActionDictType(), testVal);
- data.setActionDictUrl(testVal);
- assertEquals(data.getActionDictUrl(), testVal);
- data.setActionDictMethod(testVal);
- assertEquals(data.getActionDictMethod(), testVal);
- data.setYamlparams(testYaml);
- assertEquals(data.getYamlparams(), testYaml);
- data.setJsonBodyData(testVal);
- assertEquals(data.getJsonBodyData(), testVal);
- }
+ @Test
+ public void testSetAndGet() {
+ String testKey = "testKey";
+ String testVal = "testVal";
+ LinkedHashMap<String, String> testMap = new LinkedHashMap<String, String>();
+ testMap.put(testKey, testVal);
+ ArrayList<Object> testArray = new ArrayList<Object>();
+ testArray.add(testVal);
+ List<String> testList = new ArrayList<String>();
+ testList.add(testVal);
+ List<Object> testObjectList = new ArrayList<Object>();
+ testObjectList.add(testVal);
+ YAMLParams testYaml = new YAMLParams();
+
+ PolicyRestAdapter adapter = new PolicyRestAdapter();
+ adapter.setConfigPolicyType(testVal);
+
+ PolicyElasticData data = new PolicyElasticData(adapter);
+ data.setScope(testVal);
+ assertEquals(data.getScope(), testVal);
+ data.setPolicyType(testVal);
+ assertEquals(data.getPolicyType(), testVal);
+ data.setConfigPolicyType(testVal);
+ assertEquals(data.getConfigPolicyType(), testVal);
+ data.setConfigBodyData(testVal);
+ assertEquals(data.getConfigBodyData(), testVal);
+ data.setPolicyName(testVal);
+ assertEquals(data.getPolicyName(), testVal);
+ data.setPolicyDescription(testVal);
+ assertEquals(data.getPolicyDescription(), testVal);
+ data.setOnapName(testVal);
+ assertEquals(data.getOnapName(), testVal);
+ data.setConfigName(testVal);
+ assertEquals(data.getConfigName(), testVal);
+ data.setConfigType(testVal);
+ assertEquals(data.getConfigType(), testVal);
+ data.setJsonBody(testVal);
+ assertEquals(data.getJsonBody(), testVal);
+ data.setServiceTypePolicyName(testMap);
+ assertEquals(data.getServiceTypePolicyName(), testMap);
+ data.setVerticaMetrics(testMap);
+ assertEquals(data.getVerticaMetrics(), testMap);
+ data.setDescription(testMap);
+ assertEquals(data.getDescription(), testMap);
+ data.setAttributeFields(testMap);
+ assertEquals(data.getAttributeFields(), testMap);
+ data.setPolicyScope(testVal);
+ assertEquals(data.getPolicyScope(), testVal);
+ data.setProviderComboBox(testVal);
+ assertEquals(data.getProviderComboBox(), testVal);
+ data.setRiskType(testVal);
+ assertEquals(data.getRiskType(), testVal);
+ data.setRiskLevel(testVal);
+ assertEquals(data.getRiskLevel(), testVal);
+ data.setGuard(testVal);
+ assertEquals(data.getGuard(), testVal);
+ data.setTtlDate(testVal);
+ assertEquals(data.getTtlDate(), testVal);
+ data.setMatching(testMap);
+ assertEquals(data.getMatching(), testMap);
+ data.setTriggerSignatures(testArray);
+ assertEquals(data.getTriggerSignatures(), testArray);
+ data.setSymptomSignatures(testArray);
+ assertEquals(data.getSymptomSignatures(), testArray);
+ data.setLogicalConnector(testVal);
+ assertEquals(data.getLogicalConnector(), testVal);
+ data.setPolicyStatus(testVal);
+ assertEquals(data.getPolicyStatus(), testVal);
+ data.setGocServerScope(testVal);
+ assertEquals(data.getGocServerScope(), testVal);
+ data.setSupressionType(testVal);
+ assertEquals(data.getSupressionType(), testVal);
+ data.setServiceType(testVal);
+ assertEquals(data.getServiceType(),testVal);
+ data.setUuid(testVal);
+ assertEquals(data.getUuid(), testVal);
+ data.setLocation(testVal);
+ assertEquals(data.getLocation(), testVal);
+ data.setPriority(testVal);
+ assertEquals(data.getPriority(), testVal);
+ data.setMsLocation(testVal);
+ assertEquals(data.getMsLocation(),testVal);
+ data.setRuleName(testVal);
+ assertEquals(data.getRuleName(), testVal);
+ data.setBrmsParamBody(testMap);
+ assertEquals(data.getBrmsParamBody(), testMap);
+ data.setBrmsController(testVal);
+ assertEquals(data.getBrmsController(), testVal);
+ data.setBrmsDependency(testList);
+ assertEquals(data.getBrmsDependency(), testList);
+ data.setRuleData(testMap);
+ assertEquals(data.getRuleData(), testMap);
+ data.setRuleListData(testMap);
+ assertEquals(data.getRuleListData(), testMap);
+ data.setDrlRuleAndUIParams(testMap);
+ assertEquals(data.getDrlRuleAndUIParams(), testMap);
+ data.setClearTimeOut(testVal);
+ assertEquals(data.getClearTimeOut(), testVal);
+ data.setTrapMaxAge(testVal);
+ assertEquals(data.getTrapMaxAge(), testVal);
+ data.setVerificationclearTimeOut(testVal);
+ assertEquals(data.getVerificationclearTimeOut(), testVal);
+ data.setDynamicLayoutMap(testMap);
+ assertEquals(data.getDynamicLayoutMap(), testMap);
+ data.setFwPolicyType(testVal);
+ assertEquals(data.getFwPolicyType(), testVal);
+ data.setFwattributes(testArray);
+ assertEquals(data.getFwattributes(), testArray);
+ data.setParentForChild(testVal);
+ assertEquals(data.getParentForChild(), testVal);
+ data.setSecurityZone(testVal);
+ assertEquals(data.getSecurityZone(), testVal);
+ data.setRuleCombiningAlgId(testVal);
+ assertEquals(data.getRuleCombiningAlgId(), testVal);
+ data.setDynamicFieldConfigAttributes(testMap);
+ assertEquals(data.getDynamicFieldConfigAttributes(), testMap);
+ data.setDynamicSettingsMap(testMap);
+ assertEquals(data.getDynamicSettingsMap(), testMap);
+ data.setDropDownMap(testMap);
+ assertEquals(data.getDropDownMap(), testMap);
+ data.setActionPerformer(testVal);
+ assertEquals(data.getActionPerformer(), testVal);
+ data.setActionAttribute(testVal);
+ assertEquals(data.getActionAttribute(), testVal);
+ data.setDynamicRuleAlgorithmLabels(testList);
+ assertEquals(data.getDynamicRuleAlgorithmLabels(), testList);
+ data.setDynamicRuleAlgorithmCombo(testList);
+ assertEquals(data.getDynamicRuleAlgorithmCombo(), testList);
+ data.setDynamicRuleAlgorithmField1(testList);
+ assertEquals(data.getDynamicRuleAlgorithmField1(), testList);
+ data.setDynamicRuleAlgorithmField2(testList);
+ assertEquals(data.getDynamicRuleAlgorithmField2(), testList);
+ data.setDynamicVariableList(testObjectList);
+ assertEquals(data.getDynamicVariableList(), testObjectList);
+ data.setDataTypeList(testList);
+ assertEquals(data.getDataTypeList(), testList);
+ data.setActionAttributeValue(testVal);
+ assertEquals(data.getActionAttributeValue(), testVal);
+ data.setRuleProvider(testVal);
+ assertEquals(data.getRuleProvider(), testVal);
+ data.setActionBody(testVal);
+ assertEquals(data.getActionBody(), testVal);
+ data.setActionDictHeader(testVal);
+ assertEquals(data.getActionDictHeader(), testVal);
+ data.setActionDictType(testVal);
+ assertEquals(data.getActionDictType(), testVal);
+ data.setActionDictUrl(testVal);
+ assertEquals(data.getActionDictUrl(), testVal);
+ data.setActionDictMethod(testVal);
+ assertEquals(data.getActionDictMethod(), testVal);
+ data.setYamlparams(testYaml);
+ assertEquals(data.getYamlparams(), testYaml);
+ data.setJsonBodyData(testVal);
+ assertEquals(data.getJsonBodyData(), testVal);
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticSearchControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticSearchControllerTest.java
index ec86996c1..bdbe1441d 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticSearchControllerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticSearchControllerTest.java
@@ -36,46 +36,46 @@ import org.mockito.Mockito;
import org.onap.policy.pap.xacml.rest.elk.client.PolicyElasticSearchController;
public class PolicyElasticSearchControllerTest {
-
- private PolicyElasticSearchController conroller;
- private HttpServletRequest request = null;
- private HttpServletResponse response = null;
-
- @Before
- public void setup(){
- conroller = new PolicyElasticSearchController();
- request = Mockito.mock(HttpServletRequest.class);
- response = Mockito.mock(HttpServletResponse.class);
- }
-
- @Test
- public void testSearchDictionary(){
- List<String> jsonString = new ArrayList<>();
- jsonString.add("{\"type\":\"attribute\",\"data\":{\"xacmlId\":\"Test\"}}");
- jsonString.add("{\"type\":\"onapName\",\"data\":{\"onapName\":\"Test\"}}");
- jsonString.add("{\"type\":\"actionPolicy\",\"data\":{\"attributeName\":\"Test\"}}");
- jsonString.add("{\"type\":\"brmsParam\",\"data\":{\"ruleName\":\"Test\"}}");
- jsonString.add("{\"type\":\"pepOptions\",\"data\":{\"pepName\":\"Test\"}}");
- jsonString.add("{\"type\":\"clSite\",\"data\":{\"siteName\":\"Test\"}}");
- jsonString.add("{\"type\":\"clService\",\"data\":{\"serviceName\":\"Test\"}}");
- jsonString.add("{\"type\":\"clVarbind\",\"data\":{\"varbindName\":\"Test\"}}");
- jsonString.add("{\"type\":\"clVnf\",\"data\":{\"vnftype\":\"Test\"}}");
- jsonString.add("{\"type\":\"clVSCL\",\"data\":{\"vsclaction\":\"Test\"}}");
- jsonString.add("{\"type\":\"decision\",\"data\":{\"xacmlId\":\"Test\"}}");
- jsonString.add("{\"type\":\"fwTerm\",\"data\":{\"termName\":\"Test\"}}");
- jsonString.add("{\"type\":\"msDCAEUUID\",\"data\":{\"name\":\"Test\"}}");
- jsonString.add("{\"type\":\"msLocation\",\"data\":{\"name\":\"Test\"}}");
- jsonString.add("{\"type\":\"msModels\",\"data\":{\"modelName\":\"Test\"}}");
- jsonString.add("{\"type\":\"psGroupPolicy\",\"data\":{\"name\":\"Test\"}}");
- jsonString.add("{\"type\":\"safeRisk\",\"data\":{\"name\":\"Test\"}}");
- jsonString.add("{\"type\":\"safePolicyWarning\",\"data\":{\"name\":\"Test\"}}");
- for(int i = 0; i < jsonString.size(); i++){
- try(BufferedReader br = new BufferedReader(new StringReader(jsonString.get(i)))) {
- when(request.getReader()).thenReturn(br);
- conroller.searchDictionary(request, response);
- } catch (Exception e) {
- assertEquals(NullPointerException.class, e.getClass());
- }
- }
- }
+
+ private PolicyElasticSearchController conroller;
+ private HttpServletRequest request = null;
+ private HttpServletResponse response = null;
+
+ @Before
+ public void setup(){
+ conroller = new PolicyElasticSearchController();
+ request = Mockito.mock(HttpServletRequest.class);
+ response = Mockito.mock(HttpServletResponse.class);
+ }
+
+ @Test
+ public void testSearchDictionary(){
+ List<String> jsonString = new ArrayList<>();
+ jsonString.add("{\"type\":\"attribute\",\"data\":{\"xacmlId\":\"Test\"}}");
+ jsonString.add("{\"type\":\"onapName\",\"data\":{\"onapName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"actionPolicy\",\"data\":{\"attributeName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"brmsParam\",\"data\":{\"ruleName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"pepOptions\",\"data\":{\"pepName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"clSite\",\"data\":{\"siteName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"clService\",\"data\":{\"serviceName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"clVarbind\",\"data\":{\"varbindName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"clVnf\",\"data\":{\"vnftype\":\"Test\"}}");
+ jsonString.add("{\"type\":\"clVSCL\",\"data\":{\"vsclaction\":\"Test\"}}");
+ jsonString.add("{\"type\":\"decision\",\"data\":{\"xacmlId\":\"Test\"}}");
+ jsonString.add("{\"type\":\"fwTerm\",\"data\":{\"termName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"msDCAEUUID\",\"data\":{\"name\":\"Test\"}}");
+ jsonString.add("{\"type\":\"msLocation\",\"data\":{\"name\":\"Test\"}}");
+ jsonString.add("{\"type\":\"msModels\",\"data\":{\"modelName\":\"Test\"}}");
+ jsonString.add("{\"type\":\"psGroupPolicy\",\"data\":{\"name\":\"Test\"}}");
+ jsonString.add("{\"type\":\"safeRisk\",\"data\":{\"name\":\"Test\"}}");
+ jsonString.add("{\"type\":\"safePolicyWarning\",\"data\":{\"name\":\"Test\"}}");
+ for(int i = 0; i < jsonString.size(); i++){
+ try(BufferedReader br = new BufferedReader(new StringReader(jsonString.get(i)))) {
+ when(request.getReader()).thenReturn(br);
+ conroller.searchDictionary(request, response);
+ } catch (Exception e) {
+ assertEquals(NullPointerException.class, e.getClass());
+ }
+ }
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyLocatorTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyLocatorTest.java
index b648a318a..7df295382 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyLocatorTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyLocatorTest.java
@@ -25,19 +25,19 @@ import org.junit.Test;
import org.onap.policy.pap.xacml.rest.elk.client.PolicyLocator;
public class PolicyLocatorTest {
- @Test
- public void testLocator() {
- String policyType = "type";
- String policyName = "name";
+ @Test
+ public void testLocator() {
+ String policyType = "type";
+ String policyName = "name";
String owner = "owner";
String scope = "scope";
String policyId = "id";
String version = "1.0";
- String testString = "[owner|scope|type|name|id|v1.0|]";
+ String testString = "[owner|scope|type|name|id|v1.0|]";
- PolicyLocator locator = new PolicyLocator(policyType, policyName, owner,
- scope, policyId, version);
- String locatorString = locator.toString();
- assertEquals(locatorString, testString);
- }
+ PolicyLocator locator = new PolicyLocator(policyType, policyName, owner,
+ scope, policyId, version);
+ String locatorString = locator.toString();
+ assertEquals(locatorString, testString);
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java
index 3941593e9..84f36aa63 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java
@@ -47,68 +47,68 @@ import javax.persistence.EntityManager;
@RunWith(PowerMockRunner.class)
public class DeleteHandlerTest {
- @Test
- public void testGets() {
- DeleteHandler handler = new DeleteHandler();
- assertNotNull(handler);
- assertEquals(handler.preSafetyCheck(null), true);
- assertNull(handler.getDeletedGroup());
- }
-
- @Test
- public void testGetInstance() {
- DeleteHandler handler = DeleteHandler.getInstance();
- assertNotNull(handler);
- }
-
- @PrepareForTest({DeleteHandler.class, XACMLPapServlet.class})
- @Test
- public void testDeletes() throws Exception {
- // Mock request
- DeleteHandler handler = new DeleteHandler();
- MockHttpServletRequest request = new MockHttpServletRequest();
- request.setBodyContent("{\n\"PAPPolicyType\": \"StdPAPPolicy\"\n}\n");
-
- // Mock servlet
- PAPPolicyEngine engine = Mockito.mock(StdEngine.class);
- PowerMockito.mockStatic(XACMLPapServlet.class);
- when(XACMLPapServlet.getPAPEngine()).thenReturn(engine);
- when(engine.getGroup(any())).thenReturn(null);
-
- // Mock elastic search
- PolicyElasticSearchController controller = Mockito.mock(PolicyElasticSearchController.class);
- PowerMockito.whenNew(PolicyElasticSearchController.class).withNoArguments().thenReturn(controller);
-
- // Mock entity manager
- EntityManager em = Mockito.mock(EntityManager.class);
-
- // Test deletion from PAP
- MockHttpServletResponse response = new MockHttpServletResponse();
- try {
- handler.doAPIDeleteFromPAP(request, response);
- }
- catch (Exception ex) {
- fail("Not expecting an exception: " + ex);
- }
-
- // Test deletion from PDP
- ONAPLoggingContext loggingContext = Mockito.mock(ONAPLoggingContext.class);
- try {
- handler.doAPIDeleteFromPDP(request, response, loggingContext);
- }
- catch (Exception ex) {
- fail("Not expecting an exception: " + ex);
- }
-
- // Test delete entity
- PolicyEntity policyEntity = new PolicyEntity();
- policyEntity.setPolicyName("testVal");
- String result = DeleteHandler.deletePolicyEntityData(em, policyEntity);
- assertEquals(result, "success");
-
- // Test check entity
- Connection con = null;
- List<?> peResult = Collections.emptyList();
- assertEquals(DeleteHandler.checkPolicyGroupEntity(con, peResult), false);
- }
+ @Test
+ public void testGets() {
+ DeleteHandler handler = new DeleteHandler();
+ assertNotNull(handler);
+ assertEquals(handler.preSafetyCheck(null), true);
+ assertNull(handler.getDeletedGroup());
+ }
+
+ @Test
+ public void testGetInstance() {
+ DeleteHandler handler = DeleteHandler.getInstance();
+ assertNotNull(handler);
+ }
+
+ @PrepareForTest({DeleteHandler.class, XACMLPapServlet.class})
+ @Test
+ public void testDeletes() throws Exception {
+ // Mock request
+ DeleteHandler handler = new DeleteHandler();
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ request.setBodyContent("{\n\"PAPPolicyType\": \"StdPAPPolicy\"\n}\n");
+
+ // Mock servlet
+ PAPPolicyEngine engine = Mockito.mock(StdEngine.class);
+ PowerMockito.mockStatic(XACMLPapServlet.class);
+ when(XACMLPapServlet.getPAPEngine()).thenReturn(engine);
+ when(engine.getGroup(any())).thenReturn(null);
+
+ // Mock elastic search
+ PolicyElasticSearchController controller = Mockito.mock(PolicyElasticSearchController.class);
+ PowerMockito.whenNew(PolicyElasticSearchController.class).withNoArguments().thenReturn(controller);
+
+ // Mock entity manager
+ EntityManager em = Mockito.mock(EntityManager.class);
+
+ // Test deletion from PAP
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ try {
+ handler.doAPIDeleteFromPAP(request, response);
+ }
+ catch (Exception ex) {
+ fail("Not expecting an exception: " + ex);
+ }
+
+ // Test deletion from PDP
+ ONAPLoggingContext loggingContext = Mockito.mock(ONAPLoggingContext.class);
+ try {
+ handler.doAPIDeleteFromPDP(request, response, loggingContext);
+ }
+ catch (Exception ex) {
+ fail("Not expecting an exception: " + ex);
+ }
+
+ // Test delete entity
+ PolicyEntity policyEntity = new PolicyEntity();
+ policyEntity.setPolicyName("testVal");
+ String result = DeleteHandler.deletePolicyEntityData(em, policyEntity);
+ assertEquals(result, "success");
+
+ // Test check entity
+ Connection con = null;
+ List<?> peResult = Collections.emptyList();
+ assertEquals(DeleteHandler.checkPolicyGroupEntity(con, peResult), false);
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/PushPolicyHandlerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/PushPolicyHandlerTest.java
index 81fe8a7ab..6971ed706 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/PushPolicyHandlerTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/PushPolicyHandlerTest.java
@@ -42,44 +42,44 @@ import javax.persistence.Query;
@RunWith(PowerMockRunner.class)
public class PushPolicyHandlerTest {
- @PrepareForTest({XACMLPapServlet.class})
- @Test
- public void testGetsAndChecks() {
- // Mock servlet, entity mgr, transaction, and query
- EntityManager em = Mockito.mock(EntityManager.class);
- EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class);
- PowerMockito.mockStatic(XACMLPapServlet.class);
- PowerMockito.when(XACMLPapServlet.getEmf()).thenReturn(emf);
- Mockito.when(emf.createEntityManager()).thenReturn(em);
- EntityTransaction transaction = Mockito.mock(EntityTransaction.class);
- Mockito.when(em.getTransaction()).thenReturn(transaction);
- Query query = Mockito.mock(Query.class);
- Mockito.when(em.createQuery(Mockito.anyString())).thenReturn(query);
-
- // Test constructor
- PushPolicyHandler handler = new PushPolicyHandler();
- assertNotNull(handler);
+ @PrepareForTest({XACMLPapServlet.class})
+ @Test
+ public void testGetsAndChecks() {
+ // Mock servlet, entity mgr, transaction, and query
+ EntityManager em = Mockito.mock(EntityManager.class);
+ EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class);
+ PowerMockito.mockStatic(XACMLPapServlet.class);
+ PowerMockito.when(XACMLPapServlet.getEmf()).thenReturn(emf);
+ Mockito.when(emf.createEntityManager()).thenReturn(em);
+ EntityTransaction transaction = Mockito.mock(EntityTransaction.class);
+ Mockito.when(em.getTransaction()).thenReturn(transaction);
+ Query query = Mockito.mock(Query.class);
+ Mockito.when(em.createQuery(Mockito.anyString())).thenReturn(query);
- // Test gets
- MockHttpServletRequest request = new MockHttpServletRequest();
- MockHttpServletResponse response = new MockHttpServletResponse();
- handler.getActiveVersion(request, response);
- assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
- request.setupAddParameter("gitPath", "testPath");
- handler.getSelectedURI(request, response);
- assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
-
- // Test check
- StdPDPPolicy policy = new StdPDPPolicy();
- OnapPDPGroup onapPolicy = new StdPDPGroup();
- String configHome = "testVal";
- assertEquals(handler.preSafetyCheck(policy, configHome), true);
- assertEquals(handler.preSafetyCheck(onapPolicy, configHome), true);
- }
-
- @Test
- public void testGetInstance() {
- PushPolicyHandler handler = PushPolicyHandler.getInstance();
- assertNotNull(handler);
- }
+ // Test constructor
+ PushPolicyHandler handler = new PushPolicyHandler();
+ assertNotNull(handler);
+
+ // Test gets
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ handler.getActiveVersion(request, response);
+ assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
+ request.setupAddParameter("gitPath", "testPath");
+ handler.getSelectedURI(request, response);
+ assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
+
+ // Test check
+ StdPDPPolicy policy = new StdPDPPolicy();
+ OnapPDPGroup onapPolicy = new StdPDPGroup();
+ String configHome = "testVal";
+ assertEquals(handler.preSafetyCheck(policy, configHome), true);
+ assertEquals(handler.preSafetyCheck(onapPolicy, configHome), true);
+ }
+
+ @Test
+ public void testGetInstance() {
+ PushPolicyHandler handler = PushPolicyHandler.getInstance();
+ assertNotNull(handler);
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/jpa/PolicyEntityTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/jpa/PolicyEntityTest.java
index 8b4c73abd..e7de8d0c4 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/jpa/PolicyEntityTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/jpa/PolicyEntityTest.java
@@ -45,18 +45,18 @@ import org.onap.policy.common.logging.flexlogger.Logger;
import java.util.Properties;
public class PolicyEntityTest {
-
- private static Logger logger = FlexLogger.getLogger(PolicyEntityTest.class);
-
+
+ private static Logger logger = FlexLogger.getLogger(PolicyEntityTest.class);
+
@Test
public void testAllOps(){
- Properties properties = new Properties();
- properties.put(XACMLRestProperties.PROP_PAP_DB_DRIVER,"org.h2.Driver");
- properties.put(XACMLRestProperties.PROP_PAP_DB_URL, "jdbc:h2:file:./sql/xacmlTest");
- properties.put(XACMLRestProperties.PROP_PAP_DB_USER, "sa");
- properties.put(XACMLRestProperties.PROP_PAP_DB_PASSWORD, "");
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("testPapPU", properties);
- EntityManager em = emf.createEntityManager();
+ Properties properties = new Properties();
+ properties.put(XACMLRestProperties.PROP_PAP_DB_DRIVER,"org.h2.Driver");
+ properties.put(XACMLRestProperties.PROP_PAP_DB_URL, "jdbc:h2:file:./sql/xacmlTest");
+ properties.put(XACMLRestProperties.PROP_PAP_DB_USER, "sa");
+ properties.put(XACMLRestProperties.PROP_PAP_DB_PASSWORD, "");
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory("testPapPU", properties);
+ EntityManager em = emf.createEntityManager();
// Start a transaction
EntityTransaction et = em.getTransaction();
@@ -101,19 +101,19 @@ public class PolicyEntityTest {
logger.debug("\n\n********PolicyEntityTest: Local PolicyEntity and Configuration objects before persist*********"
- + "\npolicyId1 = " + policyId1
- + "\npolicyName1 = " + policyName1
- + "\nversion1 = " + version1
- + "\npolicyData1 = " + policyData1
- + "\nconfigDataStr1 = " + configDataStr1
- + "\nactionBodyStr1 = " + actionBodyStr1
- + "\nscope = " + p1.getScope()
- + "\ncreatedBy1 = " + createdBy1
- + "\ncreatedDateStr1 = " + createdDateStr1
- + "\ndescription = " + description
- + "\nmodifiedBy1 = " + modifiedBy1
- + "\nmodifiedDateStr1 = " + modifiedDateStr1
- + "\ndeleted = " + p1.isDeleted());
+ + "\npolicyId1 = " + policyId1
+ + "\npolicyName1 = " + policyName1
+ + "\nversion1 = " + version1
+ + "\npolicyData1 = " + policyData1
+ + "\nconfigDataStr1 = " + configDataStr1
+ + "\nactionBodyStr1 = " + actionBodyStr1
+ + "\nscope = " + p1.getScope()
+ + "\ncreatedBy1 = " + createdBy1
+ + "\ncreatedDateStr1 = " + createdDateStr1
+ + "\ndescription = " + description
+ + "\nmodifiedBy1 = " + modifiedBy1
+ + "\nmodifiedDateStr1 = " + modifiedDateStr1
+ + "\ndeleted = " + p1.isDeleted());
//Set policyID
p1.setPolicyName("testPID2");
@@ -171,19 +171,19 @@ public class PolicyEntityTest {
modifiedDateStr1 = (modifiedDate1 != null ? modifiedDate1.toString() : "modifiedDate is null");
logger.debug("\n\n********PolicyEntityTest: Local PolicyEntity and Configuration objects after persist*********"
- + "\npolicyId1 = " + policyId1
- + "\npolicyName1 = " + policyName1
- + "\nversion1 = " + version1
- + "\npolicyData1 = " + policyData1
- + "\nconfigDataStr1 = " + configDataStr1
- + "\nactionBodyStr1 = " + actionBodyStr1
- + "\nscopeId = " + p1.getScope()
- + "\ncreatedBy1 = " + createdBy1
- + "\ncreatedDateStr1 = " + createdDateStr1
- + "\ndescription = " + description
- + "\nmodifiedBy1 = " + modifiedBy1
- + "\nmodifiedDateStr1 = " + modifiedDateStr1
- + "\ndeleted = " + p1.isDeleted());
+ + "\npolicyId1 = " + policyId1
+ + "\npolicyName1 = " + policyName1
+ + "\nversion1 = " + version1
+ + "\npolicyData1 = " + policyData1
+ + "\nconfigDataStr1 = " + configDataStr1
+ + "\nactionBodyStr1 = " + actionBodyStr1
+ + "\nscopeId = " + p1.getScope()
+ + "\ncreatedBy1 = " + createdBy1
+ + "\ncreatedDateStr1 = " + createdDateStr1
+ + "\ndescription = " + description
+ + "\nmodifiedBy1 = " + modifiedBy1
+ + "\nmodifiedDateStr1 = " + modifiedDateStr1
+ + "\ndeleted = " + p1.isDeleted());
//Now lets fully configure the configurationData and actionBody
@@ -193,7 +193,7 @@ public class PolicyEntityTest {
ActionBodyEntity a1 = new ActionBodyEntity();
//persist the configuration Data
- em.persist(c1);
+ em.persist(c1);
c1.setConfigType("OTHER");
@@ -241,28 +241,28 @@ public class PolicyEntityTest {
Date cdModifiedDate = c1.getModifiedDate();
logger.debug("\n\n********PolicyEntityTest: Local Configuration object after setting values *********"
- + "\nconfigurationDataId = " + configurationDataId
- + "\ncdVersion = " + cdVersion
- + "\ncdConfigType = " + cdConfigType
- + "\ncdConfigBody = " + cdConfigBody
- + "\ncdCreatedBy = " + cdCreatedBy
- + "\ncdCreatedDate = " + cdCreatedDate
- + "\ncdDescription = " + cdDescription
- + "\ncdModifiedBy = " + cdModifiedBy
- + "\ncdModifiedDate = " + cdModifiedDate
- + "\ndeleted = " + c1.isDeleted());
+ + "\nconfigurationDataId = " + configurationDataId
+ + "\ncdVersion = " + cdVersion
+ + "\ncdConfigType = " + cdConfigType
+ + "\ncdConfigBody = " + cdConfigBody
+ + "\ncdCreatedBy = " + cdCreatedBy
+ + "\ncdCreatedDate = " + cdCreatedDate
+ + "\ncdDescription = " + cdDescription
+ + "\ncdModifiedBy = " + cdModifiedBy
+ + "\ncdModifiedDate = " + cdModifiedDate
+ + "\ndeleted = " + c1.isDeleted());
logger.debug("\n\n********PolicyEntityTest: Local Action Body object after setting values *********"
- + "\nactionBodyId = " + a1.getActionBodyId()
- + "\nactionBodyVersion = " + a1.getVersion()
- + "\nactionBody = " + a1.getActionBody()
- + "\nactionBodyCeatedBy = " + a1.getCreatedBy()
- + "\nactionBodyCreatedDate = " + a1.getCreatedDate()
- + "\nactionBodyModifiedBy = " + a1.getModifiedBy()
- + "\nactionBodyModifiedDate = " + a1.getModifiedDate()
- + "\nactionBodyDeleted = " + a1.isDeleted());
+ + "\nactionBodyId = " + a1.getActionBodyId()
+ + "\nactionBodyVersion = " + a1.getVersion()
+ + "\nactionBody = " + a1.getActionBody()
+ + "\nactionBodyCeatedBy = " + a1.getCreatedBy()
+ + "\nactionBodyCreatedDate = " + a1.getCreatedDate()
+ + "\nactionBodyModifiedBy = " + a1.getModifiedBy()
+ + "\nactionBodyModifiedDate = " + a1.getModifiedDate()
+ + "\nactionBodyDeleted = " + a1.isDeleted());
p1.setScope("mckiou.kevin.kim");
@@ -282,10 +282,10 @@ public class PolicyEntityTest {
List psList = queryscope.getResultList();
PolicyEntity px = null;
if(!psList.isEmpty()){
- //ignores multiple results
- px = (PolicyEntity) psList.get(0);
+ //ignores multiple results
+ px = (PolicyEntity) psList.get(0);
}else{
- fail("\nPolicyEntityTest: No PolicyEntity using scope DB entry found");
+ fail("\nPolicyEntityTest: No PolicyEntity using scope DB entry found");
}
//The scope object on the retrieved policy object should be same as the one we used to find it
@@ -295,29 +295,29 @@ public class PolicyEntityTest {
//Because getSingleResult() throws an unchecked exception which is an indication of a
//programming error, we are not going to use it.
@SuppressWarnings("rawtypes")
- List resultList = query.getResultList();
+ List resultList = query.getResultList();
PolicyEntity p2 = null;
if(!resultList.isEmpty()){
// ignores multiple results
p2 = (PolicyEntity) resultList.get(0);
}else{
- fail("\nPolicyEntityTest: No PolicyEntity DB entry found");
+ fail("\nPolicyEntityTest: No PolicyEntity DB entry found");
}
logger.debug("\n\n********PolicyEntityTest: PolicyEntity object after retrieving from DB BEFORE assigning configurationData*********"
- + "\npolicyId2 = " + p2.getPolicyId()
- + "\npolicyName2 = " + p2.getPolicyName()
- + "\nversion2 = " + p2.getVersion()
- + "\npolicyData2 = " + p2.getPolicyData()
- + "\nconfigurationData2 = " + (p2.getConfigurationData()!=null ? "configurationDataId = " + p2.getConfigurationData().getConfigurationDataId() : "configurationData is null")
- + "\nactionBody2 = " + (p2.getActionBodyEntity()!=null ? "actionBodyId = " + p2.getActionBodyEntity().getActionBodyId() : "actionBody is null")
- + "\nscope2 = " + p2.getScope()
- + "\ncreatedBy2 = " + p2.getCreatedBy()
- + "\ncreatedDate2 = " + p2.getCreatedDate()
- + "\ndescription2 = " + p2.getDescription()
- + "\nmodifiedBy2 = " + p2.getModifiedBy()
- + "\nmodifiedDate2 = " + p2.getModifiedDate()
- + "\ndeleted2 = " + p2.isDeleted());
+ + "\npolicyId2 = " + p2.getPolicyId()
+ + "\npolicyName2 = " + p2.getPolicyName()
+ + "\nversion2 = " + p2.getVersion()
+ + "\npolicyData2 = " + p2.getPolicyData()
+ + "\nconfigurationData2 = " + (p2.getConfigurationData()!=null ? "configurationDataId = " + p2.getConfigurationData().getConfigurationDataId() : "configurationData is null")
+ + "\nactionBody2 = " + (p2.getActionBodyEntity()!=null ? "actionBodyId = " + p2.getActionBodyEntity().getActionBodyId() : "actionBody is null")
+ + "\nscope2 = " + p2.getScope()
+ + "\ncreatedBy2 = " + p2.getCreatedBy()
+ + "\ncreatedDate2 = " + p2.getCreatedDate()
+ + "\ndescription2 = " + p2.getDescription()
+ + "\nmodifiedBy2 = " + p2.getModifiedBy()
+ + "\nmodifiedDate2 = " + p2.getModifiedDate()
+ + "\ndeleted2 = " + p2.isDeleted());
//Confirm that the retrieved policy object is the same as the persisted object
assertSame(p1,p2);
@@ -328,26 +328,26 @@ public class PolicyEntityTest {
query2.setParameter("cid", c1.getConfigurationDataId());
//Get the database version of the Configuration Data
- resultList = query2.getResultList();
+ resultList = query2.getResultList();
ConfigurationDataEntity c2 = null;
if(!resultList.isEmpty()){
// ignores multiple results
c2 = (ConfigurationDataEntity) resultList.get(0);
}else{
- fail("\nPolicyEntityTest: No ConfigurationDataEntity DB entry found");
+ fail("\nPolicyEntityTest: No ConfigurationDataEntity DB entry found");
}
logger.debug("\n\n********PolicyEntityTest: Configuration object after retrieving from DB BEFORE assigning to policy*********"
- + "\nconfigurationDataId2 = " + c2.getConfigurationDataId()
- + "\nversion2 = " + c2.getVersion()
- + "\nconfigType2 = " + c2.getConfigType()
- + "\nconfigBody2 = " + c2.getConfigBody()
- + "\ncreatedBy2 = " + c2.getCreatedBy()
- + "\ncreatedDate2 = " + c2.getCreatedDate()
- + "\ndescription2 = " + c2.getDescription()
- + "\nmodifiedBy2 = " + c2.getModifiedBy()
- + "\nmodifiedDate2 = " + c2.getModifiedDate()
- + "\ndeleted2 = " + c2.isDeleted());
+ + "\nconfigurationDataId2 = " + c2.getConfigurationDataId()
+ + "\nversion2 = " + c2.getVersion()
+ + "\nconfigType2 = " + c2.getConfigType()
+ + "\nconfigBody2 = " + c2.getConfigBody()
+ + "\ncreatedBy2 = " + c2.getCreatedBy()
+ + "\ncreatedDate2 = " + c2.getCreatedDate()
+ + "\ndescription2 = " + c2.getDescription()
+ + "\nmodifiedBy2 = " + c2.getModifiedBy()
+ + "\nmodifiedDate2 = " + c2.getModifiedDate()
+ + "\ndeleted2 = " + c2.isDeleted());
//Confirm the retrieved ConfigurationDataEntity object is the same as the persisted
assertSame(c1,c2);
@@ -361,25 +361,25 @@ public class PolicyEntityTest {
querya2.setParameter("aid", a1.getActionBodyId());
//Get the database version of the Action Body
- resultList = querya2.getResultList();
+ resultList = querya2.getResultList();
ActionBodyEntity a2 = null;
if(!resultList.isEmpty()){
// ignores multiple results
a2 = (ActionBodyEntity) resultList.get(0);
}else{
- fail("\nPolicyEntityTest: No ActionBodyEntity DB entry found");
+ fail("\nPolicyEntityTest: No ActionBodyEntity DB entry found");
}
logger.debug("\n\n********PolicyEntityTest: Local Action Body object after retrieving from DB BEFORE assigning to policy *********"
- + "\nactionBodyId2 = " + a2.getActionBodyId()
- + "\nactionBodyVersion2 = " + a2.getVersion()
- + "\nactionBody2 = " + a2.getActionBody()
- + "\nactionBodyCeatedBy2 = " + a2.getCreatedBy()
- + "\nactionBodyCreatedDate2 = " + a2.getCreatedDate()
- + "\nactionBodyModifiedBy2 = " + a2.getModifiedBy()
- + "\nactionBodyModifiedDate2 = " + a2.getModifiedDate()
- + "\nactionBodyDeleted2 = " + a2.isDeleted());
+ + "\nactionBodyId2 = " + a2.getActionBodyId()
+ + "\nactionBodyVersion2 = " + a2.getVersion()
+ + "\nactionBody2 = " + a2.getActionBody()
+ + "\nactionBodyCeatedBy2 = " + a2.getCreatedBy()
+ + "\nactionBodyCreatedDate2 = " + a2.getCreatedDate()
+ + "\nactionBodyModifiedBy2 = " + a2.getModifiedBy()
+ + "\nactionBodyModifiedDate2 = " + a2.getModifiedDate()
+ + "\nactionBodyDeleted2 = " + a2.isDeleted());
//Confirm the retrieved ActionBodyEntity object is the same as the persisted
@@ -398,67 +398,67 @@ public class PolicyEntityTest {
// ignores multiple results
p2 = (PolicyEntity) resultList.get(0);
}else{
- fail("PolicyEntityTest: No PolicyEntity DB entry found");
+ fail("PolicyEntityTest: No PolicyEntity DB entry found");
}
logger.debug("\n\n********PolicyEntityTest: PolicyEntity object after retrieving from DB AFTER assigning configurationData*********"
- + "\npolicyId2 = " + p2.getPolicyId()
- + "\npolicyName2 = " + p2.getPolicyName()
- + "\nversion2 = " + p2.getVersion()
- + "\npolicyData2 = " + p2.getPolicyData()
- + "\nconfigurationData2 = " + (p2.getConfigurationData()!=null ? "configurationDataId = " + p2.getConfigurationData().getConfigurationDataId() : "configurationData is null")
- + "\nactionBody2 = " + (p2.getActionBodyEntity()!=null ? "actionBodyId = " + p2.getActionBodyEntity().getActionBodyId() : "actionBody is null")
- + "\nscope2 = " + p2.getScope()
- + "\ncreatedBy2 = " + p2.getCreatedBy()
- + "\ncreatedDate2 = " + p2.getCreatedDate()
- + "\ndescription2 = " + p2.getDescription()
- + "\nmodifiedBy2 = " + p2.getModifiedBy()
- + "\nmodifiedDate2 = " + p2.getModifiedDate()
- + "\ndeleted2 = " + p2.isDeleted());
+ + "\npolicyId2 = " + p2.getPolicyId()
+ + "\npolicyName2 = " + p2.getPolicyName()
+ + "\nversion2 = " + p2.getVersion()
+ + "\npolicyData2 = " + p2.getPolicyData()
+ + "\nconfigurationData2 = " + (p2.getConfigurationData()!=null ? "configurationDataId = " + p2.getConfigurationData().getConfigurationDataId() : "configurationData is null")
+ + "\nactionBody2 = " + (p2.getActionBodyEntity()!=null ? "actionBodyId = " + p2.getActionBodyEntity().getActionBodyId() : "actionBody is null")
+ + "\nscope2 = " + p2.getScope()
+ + "\ncreatedBy2 = " + p2.getCreatedBy()
+ + "\ncreatedDate2 = " + p2.getCreatedDate()
+ + "\ndescription2 = " + p2.getDescription()
+ + "\nmodifiedBy2 = " + p2.getModifiedBy()
+ + "\nmodifiedDate2 = " + p2.getModifiedDate()
+ + "\ndeleted2 = " + p2.isDeleted());
//And now the ConfigurationDataEntity object
- resultList = query2.getResultList();
+ resultList = query2.getResultList();
c2 = null;
if(!resultList.isEmpty()){
// ignores multiple results
c2 = (ConfigurationDataEntity) resultList.get(0);
}else{
- fail("\nPolicyEntityTest: No ConfigurationDataEntity DB entry found");
+ fail("\nPolicyEntityTest: No ConfigurationDataEntity DB entry found");
}
logger.debug("\n\n********PolicyEntityTest: Configuration object after retrieving from DB AFTER assigning to policy*********"
- + "\nconfigurationDataId2 = " + c2.getConfigurationDataId()
- + "\nversion2 = " + c2.getVersion()
- + "\nconfigType2 = " + c2.getConfigType()
- + "\nconfigBody2 = " + c2.getConfigBody()
- + "\ncreatedBy2 = " + c2.getCreatedBy()
- + "\ncreatedDate2 = " + c2.getCreatedDate()
- + "\ndescription2 = " + c2.getDescription()
- + "\nmodifiedBy = " + c2.getModifiedBy()
- + "\nmodifiedDate = " + c2.getModifiedDate()
- + "\ndeleted2 = " + c2.isDeleted());
+ + "\nconfigurationDataId2 = " + c2.getConfigurationDataId()
+ + "\nversion2 = " + c2.getVersion()
+ + "\nconfigType2 = " + c2.getConfigType()
+ + "\nconfigBody2 = " + c2.getConfigBody()
+ + "\ncreatedBy2 = " + c2.getCreatedBy()
+ + "\ncreatedDate2 = " + c2.getCreatedDate()
+ + "\ndescription2 = " + c2.getDescription()
+ + "\nmodifiedBy = " + c2.getModifiedBy()
+ + "\nmodifiedDate = " + c2.getModifiedDate()
+ + "\ndeleted2 = " + c2.isDeleted());
//Get the database version of the Action Body
- resultList = querya2.getResultList();
+ resultList = querya2.getResultList();
a2 = null;
if(!resultList.isEmpty()){
// ignores multiple results
a2 = (ActionBodyEntity) resultList.get(0);
}else{
- fail("\nPolicyEntityTest: No ActionBodyEntity DB entry found");
+ fail("\nPolicyEntityTest: No ActionBodyEntity DB entry found");
}
logger.debug("\n\n********PolicyEntityTest: Local Action Body object after retrieving from DB AFTER assigning to policy *********"
- + "\nactionBodyId2 = " + a2.getActionBodyId()
- + "\nactionBodyVersion2 = " + a2.getVersion()
- + "\nactionBody2 = " + a2.getActionBody()
- + "\nactionBodyCeatedBy2 = " + a2.getCreatedBy()
- + "\nactionBodyCreatedDate2 = " + a2.getCreatedDate()
- + "\nactionBodyModifiedBy2 = " + a2.getModifiedBy()
- + "\nactionBodyModifiedDate2 = " + a2.getModifiedDate()
- + "\nactionBodyDeleted2 = " + a2.isDeleted());
+ + "\nactionBodyId2 = " + a2.getActionBodyId()
+ + "\nactionBodyVersion2 = " + a2.getVersion()
+ + "\nactionBody2 = " + a2.getActionBody()
+ + "\nactionBodyCeatedBy2 = " + a2.getCreatedBy()
+ + "\nactionBodyCreatedDate2 = " + a2.getCreatedDate()
+ + "\nactionBodyModifiedBy2 = " + a2.getModifiedBy()
+ + "\nactionBodyModifiedDate2 = " + a2.getModifiedDate()
+ + "\nactionBodyDeleted2 = " + a2.isDeleted());
//****Now lets see if the orphanRemoval=true does anything useful***
@@ -473,30 +473,30 @@ public class PolicyEntityTest {
//Attempt to retrieve the configuration data object from the db. It should not be there
//Reusing the previous query
- resultList = query2.getResultList();
+ resultList = query2.getResultList();
c2 = null;
if(resultList.isEmpty()){
- logger.debug("\n\n********PolicyEntityTest: orphanRemoval=true******"
- + "\n Success!! No ConfigurationDataEntity DB entry found");
+ logger.debug("\n\n********PolicyEntityTest: orphanRemoval=true******"
+ + "\n Success!! No ConfigurationDataEntity DB entry found");
}else{
- c2 = (ConfigurationDataEntity) resultList.get(0);
- fail("\nPolicyEntityTest: ConfigurationDataEntity DB entry found - and none should exist"
- + "\nconfigurationDataId = " + c2.getConfigurationDataId());
+ c2 = (ConfigurationDataEntity) resultList.get(0);
+ fail("\nPolicyEntityTest: ConfigurationDataEntity DB entry found - and none should exist"
+ + "\nconfigurationDataId = " + c2.getConfigurationDataId());
}
//Attempt to retrieve the actionBody data object from the db. It should not be there
//Reusing the previous query
- resultList = querya2.getResultList();
+ resultList = querya2.getResultList();
a2 = null;
if(resultList.isEmpty()){
- logger.debug("\n\n********PolicyEntityTest: orphanRemoval=true******"
- + "\n Success!! No ActionBodyEntity DB entry found");
+ logger.debug("\n\n********PolicyEntityTest: orphanRemoval=true******"
+ + "\n Success!! No ActionBodyEntity DB entry found");
}else{
- a2 = (ActionBodyEntity) resultList.get(0);
- fail("\nPolicyEntityTest: ActionBodyEntity DB entry found - and none should exist"
- + "\nactionBodyId = " + a2.getActionBodyId());
+ a2 = (ActionBodyEntity) resultList.get(0);
+ fail("\nPolicyEntityTest: ActionBodyEntity DB entry found - and none should exist"
+ + "\nactionBodyId = " + a2.getActionBodyId());
}
//Now lets put the configurationData and actionBody back into the policy object and see what appears
@@ -512,86 +512,86 @@ public class PolicyEntityTest {
em.flush();
//retrieve the policy object
- resultList = query.getResultList();
+ resultList = query.getResultList();
p2 = null;
if(!resultList.isEmpty()){
// ignores multiple results
p2 = (PolicyEntity) resultList.get(0);
}else{
- fail("\nPolicyEntityTest: No PolicyEntity DB entry found");
+ fail("\nPolicyEntityTest: No PolicyEntity DB entry found");
}
//output what we policy object found
logger.debug("\n\n********PolicyEntityTest: PolicyEntity object after again adding ConfigurationDataEntity and retrieving from DB*********"
- + "\npolicyId2 = " + p2.getPolicyId()
- + "\npolicyName2 = " + p2.getPolicyName()
- + "\nversion2 = " + p2.getVersion()
- + "\npolicyData2 = " + p2.getPolicyData()
- + "\nconfigurationData2 = " + (p2.getConfigurationData()!=null ? "configurationDataId = " + p2.getConfigurationData().getConfigurationDataId() : "configurationData is null")
- + "\nactionBody2 = " + (p2.getActionBodyEntity()!=null ? "actionBodyId = " + p2.getActionBodyEntity().getActionBodyId() : "actionBody is null")
- + "\nscope2 = " + p2.getScope()
- + "\ncreatedBy2 = " + p2.getCreatedBy()
- + "\ncreatedDate2 = " + p2.getCreatedDate()
- + "\ndescription2 = " + p2.getDescription()
- + "\nmodifiedBy2 = " + p2.getModifiedBy()
- + "\nmodifiedDate2 = " + p2.getModifiedDate()
- + "\ndeleted2 = " + p2.isDeleted());
+ + "\npolicyId2 = " + p2.getPolicyId()
+ + "\npolicyName2 = " + p2.getPolicyName()
+ + "\nversion2 = " + p2.getVersion()
+ + "\npolicyData2 = " + p2.getPolicyData()
+ + "\nconfigurationData2 = " + (p2.getConfigurationData()!=null ? "configurationDataId = " + p2.getConfigurationData().getConfigurationDataId() : "configurationData is null")
+ + "\nactionBody2 = " + (p2.getActionBodyEntity()!=null ? "actionBodyId = " + p2.getActionBodyEntity().getActionBodyId() : "actionBody is null")
+ + "\nscope2 = " + p2.getScope()
+ + "\ncreatedBy2 = " + p2.getCreatedBy()
+ + "\ncreatedDate2 = " + p2.getCreatedDate()
+ + "\ndescription2 = " + p2.getDescription()
+ + "\nmodifiedBy2 = " + p2.getModifiedBy()
+ + "\nmodifiedDate2 = " + p2.getModifiedDate()
+ + "\ndeleted2 = " + p2.isDeleted());
//now lets see if it put the configurationData c1 back into the table
- resultList = query2.getResultList();
+ resultList = query2.getResultList();
c2 = null;
if(!resultList.isEmpty()){
// ignores multiple results
c2 = (ConfigurationDataEntity) resultList.get(0);
}else{
- fail("\nPolicyEntityTest - Check re-entry of configurationData into DB"
- + "No ConfigurationDataEntity DB entry found");
+ fail("\nPolicyEntityTest - Check re-entry of configurationData into DB"
+ + "No ConfigurationDataEntity DB entry found");
}
//output what configurationData object we found
logger.debug("\n\n********PolicyEntityTest: Configuration object after re-enter into policy object and retrieving from DB *********"
- + "\nconfigurationDataId2 = " + c2.getConfigurationDataId()
- + "\nversion2 = " + c2.getVersion()
- + "\nconfigType2 = " + c2.getConfigType()
- + "\nconfigBody2 = " + c2.getConfigBody()
- + "\ncreatedBy2 = " + c2.getCreatedBy()
- + "\ncreatedDate2 = " + c2.getCreatedDate()
- + "\ndescription2 = " + c2.getDescription()
- + "\nmodifiedBy = " + c2.getModifiedBy()
- + "\nmodifiedDate = " + c2.getModifiedDate()
- + "\ndeleted2 = " + c2.isDeleted());
+ + "\nconfigurationDataId2 = " + c2.getConfigurationDataId()
+ + "\nversion2 = " + c2.getVersion()
+ + "\nconfigType2 = " + c2.getConfigType()
+ + "\nconfigBody2 = " + c2.getConfigBody()
+ + "\ncreatedBy2 = " + c2.getCreatedBy()
+ + "\ncreatedDate2 = " + c2.getCreatedDate()
+ + "\ndescription2 = " + c2.getDescription()
+ + "\nmodifiedBy = " + c2.getModifiedBy()
+ + "\nmodifiedDate = " + c2.getModifiedDate()
+ + "\ndeleted2 = " + c2.isDeleted());
//now lets see if it put the actionBody a1 back into the table
//Get the database version of the Action Body
- resultList = querya2.getResultList();
+ resultList = querya2.getResultList();
a2 = null;
if(!resultList.isEmpty()){
// ignores multiple results
a2 = (ActionBodyEntity) resultList.get(0);
}else{
- fail("\nPolicyEntityTest - Check re-entry of actionBody into DB"
- + "No ActionBodyEntity DB entry found");
+ fail("\nPolicyEntityTest - Check re-entry of actionBody into DB"
+ + "No ActionBodyEntity DB entry found");
}
logger.debug("\n\n********PolicyEntityTest: Local Action Body object after re-enter into policy object and retrieving from DB *********"
- + "\nactionBodyId2 = " + a2.getActionBodyId()
- + "\nactionBodyVersion2 = " + a2.getVersion()
- + "\nactionBody2 = " + a2.getActionBody()
- + "\nactionBodyCeatedBy2 = " + a2.getCreatedBy()
- + "\nactionBodyCreatedDate2 = " + a2.getCreatedDate()
- + "\nactionBodyModifiedBy2 = " + a2.getModifiedBy()
- + "\nactionBodyModifiedDate2 = " + a2.getModifiedDate()
- + "\nactionBodyDeleted2 = " + a2.isDeleted());
+ + "\nactionBodyId2 = " + a2.getActionBodyId()
+ + "\nactionBodyVersion2 = " + a2.getVersion()
+ + "\nactionBody2 = " + a2.getActionBody()
+ + "\nactionBodyCeatedBy2 = " + a2.getCreatedBy()
+ + "\nactionBodyCreatedDate2 = " + a2.getCreatedDate()
+ + "\nactionBodyModifiedBy2 = " + a2.getModifiedBy()
+ + "\nactionBodyModifiedDate2 = " + a2.getModifiedDate()
+ + "\nactionBodyDeleted2 = " + a2.isDeleted());
//I want to save all the above in the DB
try{
- et.commit();
- logger.debug("\n\n***********PolicyEntityTest: et.commit Succeeded********");
+ et.commit();
+ logger.debug("\n\n***********PolicyEntityTest: et.commit Succeeded********");
}catch(Exception e){
- logger.debug("\n\n***********PolicyEntityTest: et.commit Failed********"
- + "\nTRANSACTION ROLLBACK "
- + "\n with exception: " + e);
+ logger.debug("\n\n***********PolicyEntityTest: et.commit Failed********"
+ + "\nTRANSACTION ROLLBACK "
+ + "\n with exception: " + e);
}
// Start a new transaction
@@ -603,58 +603,58 @@ public class PolicyEntityTest {
PolicyEntity p3 = new PolicyEntity();
em.persist(p3);
-
- //first let's assure that you can save with the same name but a different scope
- p3.setPolicyName(p1.getPolicyName());
- p3.setScope("mckiou.kevin.kory");
- em.flush();
- logger.debug("\n\n***********PolicyEntityTest: PolicyEntity Unique test for policyName and scope********"
- + "\nSuccess! PolicyEntity uniqueness constraint allowed "
- + "\n policyId1 " + p1.getPolicyId()
- + "\n policyName1 " + p1.getPolicyName()
- + "\n scope1 = " + p1.getScope()
- + "\n policyId3 " + p3.getPolicyId()
- + "\n policyName3 " + p3.getPolicyName()
- + "\n scope3 = " + p3.getScope());
-
- //Assert that the policyIds are NOT the same to show that the automatic sequencing is working
- assert(p1.getPolicyId() != p3.getPolicyId());
-
- try{
- //Now set the scope the same to verify the uniqueness constraint will be enforced
- p3.setScope(p1.getScope());
-
- em.flush();
- logger.debug("\n\n***********PolicyEntityTest: PolicyEntity Unique test for policyName and scope********"
- + "\nFailed! PolicyEntity Uniqueness constraint FAILED and DID allow "
- + "\n policyId1 " + p1.getPolicyId()
- + "\n policyName1 " + p1.getPolicyName()
- + "\n scope1 = " + p1.getScope()
- + "\n policyId3 " + p3.getPolicyId()
- + "\n policyName3 " + p3.getPolicyName()
- + "\n scope3 = " + p3.getScope());;
+
+ //first let's assure that you can save with the same name but a different scope
+ p3.setPolicyName(p1.getPolicyName());
+ p3.setScope("mckiou.kevin.kory");
+ em.flush();
+ logger.debug("\n\n***********PolicyEntityTest: PolicyEntity Unique test for policyName and scope********"
+ + "\nSuccess! PolicyEntity uniqueness constraint allowed "
+ + "\n policyId1 " + p1.getPolicyId()
+ + "\n policyName1 " + p1.getPolicyName()
+ + "\n scope1 = " + p1.getScope()
+ + "\n policyId3 " + p3.getPolicyId()
+ + "\n policyName3 " + p3.getPolicyName()
+ + "\n scope3 = " + p3.getScope());
+
+ //Assert that the policyIds are NOT the same to show that the automatic sequencing is working
+ assert(p1.getPolicyId() != p3.getPolicyId());
+
+ try{
+ //Now set the scope the same to verify the uniqueness constraint will be enforced
+ p3.setScope(p1.getScope());
+
+ em.flush();
+ logger.debug("\n\n***********PolicyEntityTest: PolicyEntity Unique test for policyName and scope********"
+ + "\nFailed! PolicyEntity Uniqueness constraint FAILED and DID allow "
+ + "\n policyId1 " + p1.getPolicyId()
+ + "\n policyName1 " + p1.getPolicyName()
+ + "\n scope1 = " + p1.getScope()
+ + "\n policyId3 " + p3.getPolicyId()
+ + "\n policyName3 " + p3.getPolicyName()
+ + "\n scope3 = " + p3.getScope());;
}
catch(Exception e){
- //Success
- logger.debug("\n\n***********PolicyEntityTest: PolicyEntity Unique test for policyName and scope********"
- + "\nSuccess! PolicyEntity Uniqueness constraint SUCCEEDED and did NOT allow "
- + "\n policyId1 " + p1.getPolicyId()
- + "\n policyName1 " + p1.getPolicyName()
- + "\n scope1 = " + p1.getScope()
- + "\n policyId3 " + p3.getPolicyId()
- + "\n policyName3 " + p3.getPolicyName()
- + "\n scope3 = " + p3.getScope()
- + "\n with excpetion: " + e);
+ //Success
+ logger.debug("\n\n***********PolicyEntityTest: PolicyEntity Unique test for policyName and scope********"
+ + "\nSuccess! PolicyEntity Uniqueness constraint SUCCEEDED and did NOT allow "
+ + "\n policyId1 " + p1.getPolicyId()
+ + "\n policyName1 " + p1.getPolicyName()
+ + "\n scope1 = " + p1.getScope()
+ + "\n policyId3 " + p3.getPolicyId()
+ + "\n policyName3 " + p3.getPolicyName()
+ + "\n scope3 = " + p3.getScope()
+ + "\n with excpetion: " + e);
}
-
+
try{
- et2.commit();
- logger.debug("\n\n***********PolicyEntityTest: et2.commit Succeeded********");
+ et2.commit();
+ logger.debug("\n\n***********PolicyEntityTest: et2.commit Succeeded********");
}catch(Exception e){
- logger.debug("\n\n***********PolicyEntityTest: et2.commit Failed********"
- + "\nTRANSACTION ROLLBACK "
- + "\n with exception: " + e);
+ logger.debug("\n\n***********PolicyEntityTest: et2.commit Failed********"
+ + "\nTRANSACTION ROLLBACK "
+ + "\n with exception: " + e);
}
//****************Test the PolicyDBDaoEntity************************
@@ -685,63 +685,63 @@ public class PolicyEntityTest {
//Print them to the log before flushing
logger.debug("\n\n***********PolicyEntityTest: PolicyDBDaoEntity objects before flush********"
- + "\n policyDBDaoUrl-1 = " + pe1.getPolicyDBDaoUrl()
- + "\n description-1 = " + pe1.getDescription()
- + "\n createdDate-1 = " + pe1.getCreatedDate()
- + "\n modifiedDate-1 " + pe1.getModifiedDate()
- + "\n*****************************************"
- + "\n policyDBDaoUrl-2 = " + pe2.getPolicyDBDaoUrl()
- + "\n description-2 = " + pe2.getDescription()
- + "\n createdDate-2 = " + pe2.getCreatedDate()
- + "\n modifiedDate-2 " + pe2.getModifiedDate()
- );
+ + "\n policyDBDaoUrl-1 = " + pe1.getPolicyDBDaoUrl()
+ + "\n description-1 = " + pe1.getDescription()
+ + "\n createdDate-1 = " + pe1.getCreatedDate()
+ + "\n modifiedDate-1 " + pe1.getModifiedDate()
+ + "\n*****************************************"
+ + "\n policyDBDaoUrl-2 = " + pe2.getPolicyDBDaoUrl()
+ + "\n description-2 = " + pe2.getDescription()
+ + "\n createdDate-2 = " + pe2.getCreatedDate()
+ + "\n modifiedDate-2 " + pe2.getModifiedDate()
+ );
//push it to the DB
em.flush();
//Now let's retrieve them from the DB using the named query
- resultList = em.createNamedQuery("PolicyDBDaoEntity.findAll").getResultList();
+ resultList = em.createNamedQuery("PolicyDBDaoEntity.findAll").getResultList();
+
+ PolicyDBDaoEntity pex = null;
+ PolicyDBDaoEntity pey = null;
- PolicyDBDaoEntity pex = null;
- PolicyDBDaoEntity pey = null;
-
if(!resultList.isEmpty()){
- if (resultList.size() != 2){
- fail("\nPolicyEntityTest: Number of PolicyDBDaoEntity entries = " + resultList.size() + " instead of 2");
- }
- for(Object policyDBDaoEntity: resultList){
- PolicyDBDaoEntity pdbdao = (PolicyDBDaoEntity)policyDBDaoEntity;
- if(pdbdao.getPolicyDBDaoUrl().equals("http://123.45.2.456:2345")){
- pex = pdbdao;
- }else if(pdbdao.getPolicyDBDaoUrl().equals("http://789.01.2.345:2345")){
- pey = pdbdao;
- }
- }
-
+ if (resultList.size() != 2){
+ fail("\nPolicyEntityTest: Number of PolicyDBDaoEntity entries = " + resultList.size() + " instead of 2");
+ }
+ for(Object policyDBDaoEntity: resultList){
+ PolicyDBDaoEntity pdbdao = (PolicyDBDaoEntity)policyDBDaoEntity;
+ if(pdbdao.getPolicyDBDaoUrl().equals("http://123.45.2.456:2345")){
+ pex = pdbdao;
+ }else if(pdbdao.getPolicyDBDaoUrl().equals("http://789.01.2.345:2345")){
+ pey = pdbdao;
+ }
+ }
+
//Print them to the log before flushing
logger.debug("\n\n***********PolicyEntityTest: PolicyDBDaoEntity objects retrieved from DB********"
- + "\n policyDBDaoUrl-x = " + pex.getPolicyDBDaoUrl()
- + "\n description-x = " + pex.getDescription()
- + "\n createdDate-x = " + pex.getCreatedDate()
- + "\n modifiedDate-x " + pex.getModifiedDate()
- + "\n*****************************************"
- + "\n policyDBDaoUrl-y = " + pey.getPolicyDBDaoUrl()
- + "\n description-y = " + pey.getDescription()
- + "\n createdDate-y = " + pey.getCreatedDate()
- + "\n modifiedDate-y " + pey.getModifiedDate()
- );
- //Verify the retrieved objects are the same as the ones we stored in the DB
- if(pex.getPolicyDBDaoUrl().equals("http://123.45.2.456:2345")){
- assertSame(pe1,pex);
- assertSame(pe2,pey);
- }else{
- assertSame(pe2,pex);
- assertSame(pe1,pey);
- }
+ + "\n policyDBDaoUrl-x = " + pex.getPolicyDBDaoUrl()
+ + "\n description-x = " + pex.getDescription()
+ + "\n createdDate-x = " + pex.getCreatedDate()
+ + "\n modifiedDate-x " + pex.getModifiedDate()
+ + "\n*****************************************"
+ + "\n policyDBDaoUrl-y = " + pey.getPolicyDBDaoUrl()
+ + "\n description-y = " + pey.getDescription()
+ + "\n createdDate-y = " + pey.getCreatedDate()
+ + "\n modifiedDate-y " + pey.getModifiedDate()
+ );
+ //Verify the retrieved objects are the same as the ones we stored in the DB
+ if(pex.getPolicyDBDaoUrl().equals("http://123.45.2.456:2345")){
+ assertSame(pe1,pex);
+ assertSame(pe2,pey);
+ }else{
+ assertSame(pe2,pex);
+ assertSame(pe1,pey);
+ }
}else{
- fail("\nPolicyEntityTest: No PolicyDBDaoEntity DB entry found");
+ fail("\nPolicyEntityTest: No PolicyDBDaoEntity DB entry found");
}
//Now let's see if we can do an update on the PolicyDBDaoEntity which we retrieved.
@@ -751,32 +751,32 @@ public class PolicyEntityTest {
//retrieve it
Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyDBDaoEntity p WHERE p.description=:desc");
- resultList = createPolicyQuery.setParameter("desc", "This is pex").getResultList();
-
- PolicyDBDaoEntity pez = null;
+ resultList = createPolicyQuery.setParameter("desc", "This is pex").getResultList();
+
+ PolicyDBDaoEntity pez = null;
if(!resultList.isEmpty()){
- if (resultList.size() != 1){
- fail("\nPolicyEntityTest: Update Test - Number of PolicyDBDaoEntity entries = " + resultList.size() + " instead of 1");
- }
- pez = (PolicyDBDaoEntity) resultList.get(0);
-
+ if (resultList.size() != 1){
+ fail("\nPolicyEntityTest: Update Test - Number of PolicyDBDaoEntity entries = " + resultList.size() + " instead of 1");
+ }
+ pez = (PolicyDBDaoEntity) resultList.get(0);
+
//Print them to the log before flushing
logger.debug("\n\n***********PolicyEntityTest: Update Test - PolicyDBDaoEntity objects retrieved from DB********"
- + "\n policyDBDaoUrl-x = " + pex.getPolicyDBDaoUrl()
- + "\n description-x = " + pex.getDescription()
- + "\n createdDate-x = " + pex.getCreatedDate()
- + "\n modifiedDate-x " + pex.getModifiedDate()
- + "\n*****************************************"
- + "\n policyDBDaoUrl-z = " + pez.getPolicyDBDaoUrl()
- + "\n description-z = " + pez.getDescription()
- + "\n createdDate-z = " + pez.getCreatedDate()
- + "\n modifiedDate-z " + pez.getModifiedDate()
- );
- //Verify the retrieved objects are the same as the ones we stored in the DB
- assertSame(pex,pez);
+ + "\n policyDBDaoUrl-x = " + pex.getPolicyDBDaoUrl()
+ + "\n description-x = " + pex.getDescription()
+ + "\n createdDate-x = " + pex.getCreatedDate()
+ + "\n modifiedDate-x " + pex.getModifiedDate()
+ + "\n*****************************************"
+ + "\n policyDBDaoUrl-z = " + pez.getPolicyDBDaoUrl()
+ + "\n description-z = " + pez.getDescription()
+ + "\n createdDate-z = " + pez.getCreatedDate()
+ + "\n modifiedDate-z " + pez.getModifiedDate()
+ );
+ //Verify the retrieved objects are the same as the ones we stored in the DB
+ assertSame(pex,pez);
}else{
- fail("\nPolicyEntityTest: Update Test - No PolicyDBDaoEntity DB updated entry found");
+ fail("\nPolicyEntityTest: Update Test - No PolicyDBDaoEntity DB updated entry found");
}
//Clean up the DB
@@ -787,12 +787,12 @@ public class PolicyEntityTest {
//Wrap up the transaction
try{
- et3.commit();
- logger.debug("\n\n***********PolicyEntityTest: et3.commit Succeeded********");
+ et3.commit();
+ logger.debug("\n\n***********PolicyEntityTest: et3.commit Succeeded********");
}catch(Exception e){
- logger.debug("\n\n***********PolicyEntityTest: et3.commit Failed********"
- + "\nTRANSACTION ROLLBACK "
- + "\n with exception: " + e);
+ logger.debug("\n\n***********PolicyEntityTest: et3.commit Failed********"
+ + "\nTRANSACTION ROLLBACK "
+ + "\n with exception: " + e);
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/model/RemoveGroupPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/model/RemoveGroupPolicyTest.java
index 34a26631f..162f4a928 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/model/RemoveGroupPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/model/RemoveGroupPolicyTest.java
@@ -27,18 +27,18 @@ import org.onap.policy.xacml.std.pap.StdPDPPolicy;
import com.att.research.xacml.api.pap.PDPPolicy;
public class RemoveGroupPolicyTest {
- @Test
- public void testRemove() {
- // Test constructor
- StdPDPGroup group = new StdPDPGroup();
- RemoveGroupPolicy remove = new RemoveGroupPolicy(group);
- assertEquals(remove.isRemoved(), false);
- assertEquals(remove.getUpdatedObject(), null);
-
- // Test remove
- PDPPolicy policy = new StdPDPPolicy();
- remove.prepareToRemove(policy);
- remove.doSave();
- assertEquals(remove.isRemoved(), true);
- }
+ @Test
+ public void testRemove() {
+ // Test constructor
+ StdPDPGroup group = new StdPDPGroup();
+ RemoveGroupPolicy remove = new RemoveGroupPolicy(group);
+ assertEquals(remove.isRemoved(), false);
+ assertEquals(remove.getUpdatedObject(), null);
+
+ // Test remove
+ PDPPolicy policy = new StdPDPPolicy();
+ remove.prepareToRemove(policy);
+ remove.doSave();
+ assertEquals(remove.isRemoved(), true);
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java
index fed2ac973..ba400dfc0 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java
@@ -28,12 +28,12 @@ import com.mockrunner.mock.web.MockHttpServletRequest;
import com.mockrunner.mock.web.MockHttpServletResponse;
public class ImportServiceTest {
- @Test
- public void testNegativeCases() {
- ImportService service = new ImportService();
- HttpServletRequest request = new MockHttpServletRequest();
- HttpServletResponse response = new MockHttpServletResponse();
- service.doImportMicroServicePut(request, response);
- assertEquals(response.getHeader("error"), "missing");
- }
+ @Test
+ public void testNegativeCases() {
+ ImportService service = new ImportService();
+ HttpServletRequest request = new MockHttpServletRequest();
+ HttpServletResponse response = new MockHttpServletResponse();
+ service.doImportMicroServicePut(request, response);
+ assertEquals(response.getHeader("error"), "missing");
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/MetricServiceTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/MetricServiceTest.java
index 0c85fe163..8c976d9aa 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/MetricServiceTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/MetricServiceTest.java
@@ -34,16 +34,16 @@ import com.mockrunner.mock.web.MockHttpServletResponse;
@RunWith(PowerMockRunner.class)
public class MetricServiceTest {
- @PrepareForTest({XACMLPapServlet.class})
- @Test
- public void testNegativeGet() {
- // Mock pap servlet
- PowerMockito.mockStatic(XACMLPapServlet.class);
- when(XACMLPapServlet.getPAPEngine()).thenReturn(null);
- when(XACMLPapServlet.getEmf()).thenReturn(null);
+ @PrepareForTest({XACMLPapServlet.class})
+ @Test
+ public void testNegativeGet() {
+ // Mock pap servlet
+ PowerMockito.mockStatic(XACMLPapServlet.class);
+ when(XACMLPapServlet.getPAPEngine()).thenReturn(null);
+ when(XACMLPapServlet.getEmf()).thenReturn(null);
- MockHttpServletResponse response = new MockHttpServletResponse();
- MetricService.doGetPolicyMetrics(response);
- assertEquals(response.getStatusCode(), HttpServletResponse.SC_BAD_REQUEST);
- }
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ MetricService.doGetPolicyMetrics(response);
+ assertEquals(response.getStatusCode(), HttpServletResponse.SC_BAD_REQUEST);
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/AuthenticationServiceTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/AuthenticationServiceTest.java
index 180c13f69..cbe9ff250 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/AuthenticationServiceTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/AuthenticationServiceTest.java
@@ -26,27 +26,27 @@ import org.junit.Test;
import org.onap.policy.pap.xacml.restAuth.AuthenticationService;
public class AuthenticationServiceTest {
- private final String testCred = "testpap:alpha123";
- private final String testCredEncoded = new String(Base64.getEncoder().encode(testCred.getBytes()));
- private final String basicCred = "Basic " + testCredEncoded;
-
- @Test
- public void testAuth() throws UnsupportedEncodingException {
- String systemKey = "xacml.properties";
+ private final String testCred = "testpap:alpha123";
+ private final String testCredEncoded = new String(Base64.getEncoder().encode(testCred.getBytes()));
+ private final String basicCred = "Basic " + testCredEncoded;
- // Set the system property temporarily
- String oldProperty = System.getProperty(systemKey);
- System.setProperty(systemKey, "xacml.pap.properties");
-
- AuthenticationService service = new AuthenticationService();
- assertEquals(service.authenticate(basicCred), true);
-
- // Restore the original system property
- if (oldProperty != null) {
- System.setProperty(systemKey, oldProperty);
- }
- else {
- System.clearProperty(systemKey);
- }
- }
+ @Test
+ public void testAuth() throws UnsupportedEncodingException {
+ String systemKey = "xacml.properties";
+
+ // Set the system property temporarily
+ String oldProperty = System.getProperty(systemKey);
+ System.setProperty(systemKey, "xacml.pap.properties");
+
+ AuthenticationService service = new AuthenticationService();
+ assertEquals(service.authenticate(basicCred), true);
+
+ // Restore the original system property
+ if (oldProperty != null) {
+ System.setProperty(systemKey, oldProperty);
+ }
+ else {
+ System.clearProperty(systemKey);
+ }
+ }
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/PAPAuthenticationFilterTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/PAPAuthenticationFilterTest.java
index 2d72c8a4d..f1554e84c 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/PAPAuthenticationFilterTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/restAuth/PAPAuthenticationFilterTest.java
@@ -38,84 +38,84 @@ import com.mockrunner.mock.web.MockHttpServletRequest;
import com.mockrunner.mock.web.MockHttpServletResponse;
public class PAPAuthenticationFilterTest {
-
- private HttpServletRequest request = null;
- private HttpServletResponse response = null;
- private String oldProperty;
- private String systemKey = "xacml.properties";
- private FilterChain filter;
- private PAPAuthenticationFilter papFilter;
-
- @Before
- public void setUp(){
- // Set the system property temporarily
- oldProperty = System.getProperty(systemKey);
- System.setProperty(systemKey, "xacml.pap.properties");
-
- request = Mockito.mock(HttpServletRequest.class);
- response = Mockito.mock(HttpServletResponse.class);
- filter = Mockito.mock(FilterChain.class);
- papFilter = new PAPAuthenticationFilter();
- }
-
- @Test
- public void testAuth() throws IOException, ServletException {
- PAPAuthenticationFilter filter = new PAPAuthenticationFilter();
- MockHttpServletRequest request = new MockHttpServletRequest();
- request.setRequestURI("/foo");
- MockHttpServletResponse response = new MockHttpServletResponse();
- FilterChain filterChain = null;
-
- // Negative test the filter
- filter.doFilter(request, response, filterChain);
- assertEquals(response.getStatusCode(), 401);
-
- // Test base methods
- try {
- filter.destroy();
- filter.init(null);
- }
- catch (Exception ex) {
- fail("Not expecting any exceptions.");
- }
- }
-
- @Test
- public void testDoFilter() {
- Mockito.when(request.getRequestURI()).thenReturn("/pap/");
- Mockito.when(request.getHeader("Authorization")).thenReturn("Basic dGVzdHBhcDphbHBoYTEyMw==");
- callDoFilter();
- Mockito.when(request.getRequestURI()).thenReturn("/pap/onap/");
- callDoFilter();
- }
-
- public void callDoFilter(){
- try {
- papFilter.doFilter(request, response, filter);
- } catch (Exception e) {
- assertEquals(NullPointerException.class, e.getClass());
- }
- }
-
- @Test
- public void testOnPassingInvalidParamters(){
- Mockito.when(request.getRequestURI()).thenReturn("/pap/");
- Mockito.when(request.getHeader("Authorization")).thenReturn("Basic dGVzdHBhcDphbHBoYTE789==");
- try {
- papFilter.doFilter(request, response, filter);
- assertEquals(0, response.getStatus());
- } catch (Exception e) {
- fail();
- }
- }
-
- @After
- public void reset(){
- // Restore the original system property
- if (oldProperty != null) {
- System.setProperty(systemKey, oldProperty);
- } else {
- System.clearProperty(systemKey);
- }
- }
+
+ private HttpServletRequest request = null;
+ private HttpServletResponse response = null;
+ private String oldProperty;
+ private String systemKey = "xacml.properties";
+ private FilterChain filter;
+ private PAPAuthenticationFilter papFilter;
+
+ @Before
+ public void setUp(){
+ // Set the system property temporarily
+ oldProperty = System.getProperty(systemKey);
+ System.setProperty(systemKey, "xacml.pap.properties");
+
+ request = Mockito.mock(HttpServletRequest.class);
+ response = Mockito.mock(HttpServletResponse.class);
+ filter = Mockito.mock(FilterChain.class);
+ papFilter = new PAPAuthenticationFilter();
+ }
+
+ @Test
+ public void testAuth() throws IOException, ServletException {
+ PAPAuthenticationFilter filter = new PAPAuthenticationFilter();
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ request.setRequestURI("/foo");
+ MockHttpServletResponse response = new MockHttpServletResponse();
+ FilterChain filterChain = null;
+
+ // Negative test the filter
+ filter.doFilter(request, response, filterChain);
+ assertEquals(response.getStatusCode(), 401);
+
+ // Test base methods
+ try {
+ filter.destroy();
+ filter.init(null);
+ }
+ catch (Exception ex) {
+ fail("Not expecting any exceptions.");
+ }
+ }
+
+ @Test
+ public void testDoFilter() {
+ Mockito.when(request.getRequestURI()).thenReturn("/pap/");
+ Mockito.when(request.getHeader("Authorization")).thenReturn("Basic dGVzdHBhcDphbHBoYTEyMw==");
+ callDoFilter();
+ Mockito.when(request.getRequestURI()).thenReturn("/pap/onap/");
+ callDoFilter();
+ }
+
+ public void callDoFilter(){
+ try {
+ papFilter.doFilter(request, response, filter);
+ } catch (Exception e) {
+ assertEquals(NullPointerException.class, e.getClass());
+ }
+ }
+
+ @Test
+ public void testOnPassingInvalidParamters(){
+ Mockito.when(request.getRequestURI()).thenReturn("/pap/");
+ Mockito.when(request.getHeader("Authorization")).thenReturn("Basic dGVzdHBhcDphbHBoYTE789==");
+ try {
+ papFilter.doFilter(request, response, filter);
+ assertEquals(0, response.getStatus());
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ @After
+ public void reset(){
+ // Restore the original system property
+ if (oldProperty != null) {
+ System.setProperty(systemKey, oldProperty);
+ } else {
+ System.clearProperty(systemKey);
+ }
+ }
}