Consolidate PolicyRestAdapter setup
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / controller / CreateDcaeMicroServiceControllerTest.java
index e4ededa..1a99fdf 100644 (file)
@@ -22,7 +22,6 @@
 
 package org.onap.policy.controller;
 
-
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
@@ -31,10 +30,12 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.fge.jackson.JsonLoader;
+
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
@@ -46,9 +47,11 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+
 import javax.servlet.ReadListener;
 import javax.servlet.ServletInputStream;
 import javax.servlet.http.HttpServletRequest;
+
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
@@ -56,6 +59,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
@@ -70,10 +74,9 @@ import org.springframework.mock.web.MockHttpServletResponse;
 
 /**
  * The class <code>CreateDcaeMicroServiceControllerTest</code> contains tests for the class
- * {@link <code>CreateDcaeMicroServiceController</code>}*
  *
- * All JUnits are designed to run in the local development environment where they have write privileges and can execute
- * time-sensitive tasks.
+ * <p/>All JUnits are designed to run in the local development environment where they have write privileges
+ * and can execute time-sensitive tasks.
  *
  */
 
@@ -85,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<Object> microServiceModelsData = new ArrayList<Object>();
         MicroServiceModels testData = new MicroServiceModels();
         testData.setVersion("OpenOnap-Junit");
         testData.setModelName("modelName");
@@ -136,6 +143,7 @@ public class CreateDcaeMicroServiceControllerTest {
         testData.setDataOrderInfo("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
                 + "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
                 + "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
+        List<Object> microServiceModelsData = new ArrayList<Object>();
         microServiceModelsData.add(testData);
 
         // mock the getDataById() call
@@ -349,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();
@@ -363,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 ...)
@@ -377,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