From 1e61676b77dd09659027b8984f050df7e8538526 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Tue, 22 Oct 2019 07:53:44 -0400 Subject: Consolidate PolicyRestAdapter setup Put common code into PolicyEngineUtils that the controllers use to populate the PolicyRestController. Also some more sonar cleanup and formatting of XML files. Shortened 120 line characters. Removed some trailing spaces from comments. Fixed up one JUnit. Licenses. Issue-ID: POLICY-2133 Change-Id: Id7d8ac3ab60331535f048ec0f26aeb17a099414e Signed-off-by: Pamela Dragosh --- .../policy/admin/PolicyManagerServletTest.java | 5 +++++ .../policy/admin/PolicyNotificationMailTest.java | 5 +++++ .../CreateDcaeMicroServiceControllerTest.java | 18 +++++++++++------- .../CreateOptimizationControllerTest.java | 22 +++++++++------------- .../controller/CreatePolicyControllerTest.java | 2 +- .../policy/controller/DashboardControllerTest.java | 5 +++++ .../policy/controller/PolicyControllerTest.java | 7 ++++++- 7 files changed, 42 insertions(+), 22 deletions(-) (limited to 'POLICY-SDK-APP/src/test/java/org/onap') diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java index 0325c8d8f..244901a3f 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java @@ -71,6 +71,11 @@ public class PolicyManagerServletTest extends Mockito { private HttpServletRequest request; private MockHttpServletResponse response; + /** + * setUp. + * + * @throws Exception should not get one + */ @Before public void setUp() throws Exception { logger.info("setUp: Entering"); diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java index 4449676d3..5111ef2a8 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java @@ -45,6 +45,11 @@ public class PolicyNotificationMailTest { private CommonClassDao commonClassDao; private List data = null; + /** + * setUp. + * + * @throws Exception should not throw one + */ @Before public void setUp() throws Exception { PolicyController.setjUnit(true); diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java index 96320e7bc..1a99fdf92 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java @@ -74,10 +74,9 @@ import org.springframework.mock.web.MockHttpServletResponse; /** * The class CreateDcaeMicroServiceControllerTest contains tests for the class - * {@link CreateDcaeMicroServiceController}* * - * All JUnits are designed to run in the local development environment where they have write privileges and can execute - * time-sensitive tasks. + *

All JUnits are designed to run in the local development environment where they have write privileges + * and can execute time-sensitive tasks. * */ @@ -89,11 +88,15 @@ public class CreateDcaeMicroServiceControllerTest { private String configBodyString = null; private HttpServletRequest request = null; + /** + * setUp. + * + * @throws Exception should not throw one + */ @Before public void setUp() throws Exception { logger.info("setUp: Entering"); commonClassDao = mock(CommonClassDao.class); - List microServiceModelsData = new ArrayList(); MicroServiceModels testData = new MicroServiceModels(); testData.setVersion("OpenOnap-Junit"); testData.setModelName("modelName"); @@ -140,6 +143,7 @@ public class CreateDcaeMicroServiceControllerTest { testData.setDataOrderInfo("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, " + "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures." + "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]"); + List microServiceModelsData = new ArrayList(); microServiceModelsData.add(testData); // mock the getDataById() call @@ -353,11 +357,8 @@ public class CreateDcaeMicroServiceControllerTest { try { root = JsonLoader.fromString(jsonString); restAdapter = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class); - TargetType target = new TargetType(); // create guard attribute - AnyOfType anyOfType = new AnyOfType(); - AllOfType alltype = new AllOfType(); MatchType matchType = new MatchType(); // set value AttributeValueType attributeValue1 = new AttributeValueType(); @@ -367,6 +368,7 @@ public class CreateDcaeMicroServiceControllerTest { AttributeDesignatorType designator = new AttributeDesignatorType(); designator.setAttributeId("guard"); matchType.setAttributeDesignator(designator); + AllOfType alltype = new AllOfType(); alltype.getMatch().add(matchType); // add a dummy MatchType object since while (matchList.size()>1 ...) @@ -381,8 +383,10 @@ public class CreateDcaeMicroServiceControllerTest { matchDummy.setAttributeDesignator(designatorDummy); alltype.getMatch().add(matchDummy); + AnyOfType anyOfType = new AnyOfType(); anyOfType.getAllOf().add(alltype); + TargetType target = new TargetType(); target.getAnyOf().add(anyOfType); // create RiskType attribute diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateOptimizationControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateOptimizationControllerTest.java index 6a5e83f4e..8e1b8be87 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateOptimizationControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateOptimizationControllerTest.java @@ -66,14 +66,12 @@ import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ConfigurationDataEntity; import org.onap.policy.rest.jpa.OptimizationModels; import org.onap.policy.rest.jpa.PolicyEntity; -import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; /** * The class CreateOptimizationControllerTest contains tests for the class - * {@link CreateOptimizationController}* * - * All JUnits are designed to run in the local development environment where they have write + *

All JUnits are designed to run in the local development environment where they have write * privileges and can execute time-sensitive tasks. */ public class CreateOptimizationControllerTest { @@ -126,7 +124,7 @@ public class CreateOptimizationControllerTest { } /** - * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, JsonNode) method test + * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, JsonNode) method test. */ @Test @@ -143,7 +141,7 @@ public class CreateOptimizationControllerTest { PolicyRestAdapter policyData = null; try { root = JsonLoader.fromString(jsonString); - policyData = (PolicyRestAdapter) mapper.readValue(root.get("policyData").get("policy").toString(), + policyData = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class); } catch (Exception e) { logger.error("testSetDataToPolicyRestAdapter", e); @@ -158,7 +156,7 @@ public class CreateOptimizationControllerTest { /** * Run the ModelAndView getOptimizationTemplateData(HttpServletRequest, HttpServletResponse) - * method test + * method test. */ @Test @@ -201,7 +199,7 @@ public class CreateOptimizationControllerTest { /** * Run the ModelAndView getModelServiceVersionData(HttpServletRequest, HttpServletResponse) - * method test + * method test. */ @Test @@ -244,7 +242,7 @@ public class CreateOptimizationControllerTest { } /** - * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, PolicyEntity) method test + * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, PolicyEntity) method test. */ @Test @@ -267,7 +265,7 @@ public class CreateOptimizationControllerTest { try { root = JsonLoader.fromString(jsonString); - restAdapter = (PolicyRestAdapter) mapper.readValue(root.get("policyData").get("policy").toString(), + restAdapter = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class); PolicyType policyType = new PolicyType(); TargetType target = new TargetType(); @@ -387,7 +385,7 @@ public class CreateOptimizationControllerTest { } /** - * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) method test + * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) method test. */ @Test @@ -429,9 +427,7 @@ public class CreateOptimizationControllerTest { } /** - * - * @ Get File Stream - * + * @ Get File Stream. */ private class MockServletInputStream extends ServletInputStream { diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreatePolicyControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreatePolicyControllerTest.java index 6a431a0af..79277d81d 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreatePolicyControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreatePolicyControllerTest.java @@ -20,9 +20,9 @@ package org.onap.policy.controller; -import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; + import com.att.research.xacml.api.XACML3; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/DashboardControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/DashboardControllerTest.java index f86f3532c..413849cd3 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/DashboardControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/DashboardControllerTest.java @@ -54,6 +54,11 @@ public class DashboardControllerTest { private Path repo; StdEngine engine = null; + /** + * setUp. + * + * @throws Exception should not get one + */ @Before public void setUp() throws Exception { logger.info("setUp: Entering"); diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java index af3c88257..554c40f90 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java @@ -47,12 +47,16 @@ public class PolicyControllerTest { private static Logger logger = FlexLogger.getLogger(PolicyControllerTest.class); private static CommonClassDao commonClassDao; + /** + * setUp. + * + * @throws Exception Should not throw one + */ @Before public void setUp() throws Exception { logger.info("setUp: Entering"); commonClassDao = mock(CommonClassDao.class); PolicyController.setCommonClassDao(commonClassDao); - List data = new ArrayList<>(); String policyData = ""; try { ClassLoader classLoader = getClass().getClassLoader(); @@ -64,6 +68,7 @@ public class PolicyControllerTest { entity.setPolicyName("Config_SampleTest.1.xml"); entity.setPolicyData(policyData); entity.setScope("com"); + List data = new ArrayList<>(); data.add(entity); when(commonClassDao.getDataByQuery( -- cgit 1.2.3-korg