summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src
diff options
context:
space:
mode:
authorbobbymander <bobby.mander@att.com>2019-10-29 14:25:50 -0400
committerbobbymander <bobby.mander@att.com>2019-10-30 10:30:47 -0400
commit349714f2b187d55560fd8ed9a461f64cac233743 (patch)
treeb9521f92d7e5419649cc515add12ba8503b49f21 /ONAP-PAP-REST/src
parentc46961c5322b8113dcf859e07e596bd7e473bc5d (diff)
JUnit additions for PAP-REST, checkstyle fixes
Issue-ID: POLICY-2130 Change-Id: Ia9fb294090a27ee86321249bc6b1cbdf20f33d06 Signed-off-by: bobbymander <bobby.mander@att.com>
Diffstat (limited to 'ONAP-PAP-REST/src')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java21
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicy.java21
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/MicroServicePolicyTest.java40
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicyTest.java74
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorTest.java54
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java48
6 files changed, 174 insertions, 84 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
index 5120d25fa..5a7a2088f 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,7 +25,6 @@ import com.att.research.xacml.std.IdentifierImpl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Splitter;
-
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
@@ -38,7 +37,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
@@ -52,7 +50,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
-
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.onap.policy.common.logging.eelf.MessageCodes;
@@ -181,7 +178,7 @@ public class MicroServiceConfigPolicy extends Policy {
matching = getValueFromDictionary(policyAdapter.getServiceType());
} else {
String jsonVersion = StringUtils.replaceEach(rootNode.get("version").toString(),
- new String[] {"\""}, new String[] {""});
+ new String[] {"\""}, new String[] {""});
matching = getValueFromDictionary(policyAdapter.getServiceType() + "-v" + jsonVersion);
}
if (matching != null && !matching.isEmpty()) {
@@ -261,7 +258,7 @@ public class MicroServiceConfigPolicy extends Policy {
accessURI = new URI(ACTION_ID);
} catch (URISyntaxException e) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy",
- "Exception creating ACCESS URI");
+ "Exception creating ACCESS URI");
}
accessAttributeDesignator.setCategory(CATEGORY_ACTION);
accessAttributeDesignator.setDataType(STRING_DATATYPE);
@@ -281,7 +278,7 @@ public class MicroServiceConfigPolicy extends Policy {
configURI = new URI(RESOURCE_ID);
} catch (URISyntaxException e) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy",
- "Exception creating Config URI");
+ "Exception creating Config URI");
}
configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
configAttributeDesignator.setDataType(STRING_DATATYPE);
@@ -321,8 +318,8 @@ public class MicroServiceConfigPolicy extends Policy {
if (value.isContainerNode() && !value.isArray()) {
pullMatchValue(value); // RECURSIVE CALL
} else {
- newValue = StringUtils.replaceEach(value.toString(), new String[] {"[", "]", "\""},
- new String[] {"", "", ""});
+ newValue =
+ StringUtils.replaceEach(value.toString(), new String[] {"[", "]", "\""}, new String[] {"", "", ""});
mapAttribute.put(key, newValue);
}
}
@@ -336,7 +333,7 @@ public class MicroServiceConfigPolicy extends Policy {
CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
List<Object> result =
- dbConnection.getDataById(MicroServiceModels.class, "modelName:version", modelName + ":" + modelVersion);
+ dbConnection.getDataById(MicroServiceModels.class, "modelName:version", modelName + ":" + modelVersion);
if (result != null && !result.isEmpty()) {
MicroServiceModels model = (MicroServiceModels) result.get(0);
ruleTemplate = model.getAnnotation();
@@ -345,7 +342,7 @@ public class MicroServiceConfigPolicy extends Policy {
}
// Data required for Advice part is setting here.
- private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
+ protected AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
AdviceExpressionsType advices = new AdviceExpressionsType();
AdviceExpressionType advice = new AdviceExpressionType();
advice.setAdviceId("MSID");
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicy.java
index 82a6c4b83..097a33f8e 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicy.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,7 +25,6 @@ import com.att.research.xacml.std.IdentifierImpl;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Splitter;
-
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
@@ -38,7 +37,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
@@ -52,7 +50,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
-
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.onap.policy.common.logging.eelf.MessageCodes;
@@ -183,7 +180,7 @@ public class OptimizationConfigPolicy extends Policy {
matching = getValueFromDictionary(policyAdapter.getServiceType());
} else {
String jsonVersion = StringUtils.replaceEach(rootNode.get("version").toString(),
- new String[] {"\""}, new String[] {""});
+ new String[] {"\""}, new String[] {""});
matching = getValueFromDictionary(policyAdapter.getServiceType() + "-v" + jsonVersion);
}
if (matching != null && !matching.isEmpty()) {
@@ -253,7 +250,7 @@ public class OptimizationConfigPolicy extends Policy {
accessURI = new URI(ACTION_ID);
} catch (URISyntaxException e) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "OptimizationConfigPolicy",
- "Exception creating ACCESS URI");
+ "Exception creating ACCESS URI");
}
accessAttributeDesignator.setCategory(CATEGORY_ACTION);
accessAttributeDesignator.setDataType(STRING_DATATYPE);
@@ -273,7 +270,7 @@ public class OptimizationConfigPolicy extends Policy {
configURI = new URI(RESOURCE_ID);
} catch (URISyntaxException e) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "OptimizationConfigPolicy",
- "Exception creating Config URI");
+ "Exception creating Config URI");
}
configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
configAttributeDesignator.setDataType(STRING_DATATYPE);
@@ -313,8 +310,8 @@ public class OptimizationConfigPolicy extends Policy {
if (value.isContainerNode() && !value.isArray()) {
pullMatchValue(value); // RECURSIVE CALL
} else {
- newValue = StringUtils.replaceEach(value.toString(), new String[] {"[", "]", "\""},
- new String[] {"", "", ""});
+ newValue =
+ StringUtils.replaceEach(value.toString(), new String[] {"[", "]", "\""}, new String[] {"", "", ""});
mapAttribute.put(key, newValue);
}
}
@@ -328,7 +325,7 @@ public class OptimizationConfigPolicy extends Policy {
CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
List<Object> result =
- dbConnection.getDataById(OptimizationModels.class, "modelName:version", modelName + ":" + modelVersion);
+ dbConnection.getDataById(OptimizationModels.class, "modelName:version", modelName + ":" + modelVersion);
if (result != null && !result.isEmpty()) {
OptimizationModels model = (OptimizationModels) result.get(0);
ruleTemplate = model.getAnnotation();
@@ -337,7 +334,7 @@ public class OptimizationConfigPolicy extends Policy {
}
// Data required for Advice part is setting here.
- private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
+ protected AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
AdviceExpressionsType advices = new AdviceExpressionsType();
AdviceExpressionType advice = new AdviceExpressionType();
advice.setAdviceId("OptimizationID");
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 780e7d717..35c99f770 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
@@ -20,9 +20,14 @@
package org.onap.policy.pap.xacml.rest.components;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
+import com.att.research.xacml.api.pap.PAPException;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -46,4 +51,39 @@ public class MicroServicePolicyTest {
MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
assertNull(policy.getCorrectPolicyDataObject());
}
+
+ @Test(expected = NullPointerException.class)
+ public void testSave() throws PAPException {
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ PolicyType policyType = new PolicyType();
+ policyAdapter.setPolicyID("id");
+ policyAdapter.setHighestVersion(1);
+ policyAdapter.setPolicyType("Config");
+ policyAdapter.setNewFileName("newfile");
+ policyAdapter.setData(policyType);
+ policyAdapter.setJsonBody("{\"key\":\"value\"}");
+ policyAdapter.setServiceType("svcType");
+ MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
+
+ policy.savePolicies();
+ }
+
+ @Test
+ public void testAdvice() {
+ PolicyType policyType = new PolicyType();
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ policyAdapter.setPolicyID("id");
+ policyAdapter.setHighestVersion(1);
+ policyAdapter.setPolicyType("Config");
+ policyAdapter.setNewFileName("newfile");
+ policyAdapter.setData(policyType);
+ policyAdapter.setJsonBody("{\"key\":\"value\"}");
+ policyAdapter.setServiceType("svcType");
+
+ MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
+ assertThatThrownBy(() -> policy.savePolicies()).isInstanceOf(NullPointerException.class);
+
+ AdviceExpressionsType expType = policy.getAdviceExpressions(1, "filename");
+ assertEquals(1, expType.getAdviceExpression().size());
+ }
}
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 9fc6add39..8437fb0f7 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
@@ -20,28 +20,19 @@
package org.onap.policy.pap.xacml.rest.components;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.when;
-
-import java.io.File;
-import java.util.Collections;
+import com.att.research.xacml.api.pap.PAPException;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-@RunWith(PowerMockRunner.class)
public class OptimizationConfigPolicyTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -61,48 +52,37 @@ public class OptimizationConfigPolicyTest {
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);
-
+ public void testSave() throws PAPException {
+ PolicyType policyType = new PolicyType();
PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
- OptimizationConfigPolicy policy = new OptimizationConfigPolicy(policyAdapter);
+ policyAdapter.setPolicyID("id");
policyAdapter.setHighestVersion(1);
policyAdapter.setPolicyType("Config");
- policyAdapter.setNewFileName("foo.xml");
- policyAdapter.setJsonBody("{ \"version\": \"1.0\"}");
- policyAdapter.setServiceType("foo");
- policy.prepareToSave();
- assertEquals(true, policy.isPreparedToSave());
+ policyAdapter.setNewFileName("newfile");
+ policyAdapter.setData(policyType);
+ policyAdapter.setJsonBody("{\"key\":\"value\"}");
+ policyAdapter.setServiceType("svcType");
+ OptimizationConfigPolicy policy = new OptimizationConfigPolicy(policyAdapter);
+ assertThatThrownBy(() -> policy.savePolicies()).isInstanceOf(Exception.class);
}
- @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);
+ public void testAdvice() {
+ PolicyType policyType = new PolicyType();
+ PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
+ policyAdapter.setPolicyID("id");
+ policyAdapter.setHighestVersion(1);
+ policyAdapter.setPolicyType("Config");
+ policyAdapter.setNewFileName("newfile");
+ policyAdapter.setData(policyType);
+ policyAdapter.setJsonBody("{\"key\":\"value\"}");
+ policyAdapter.setServiceType("svcType");
- // 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());
+ OptimizationConfigPolicy policy = new OptimizationConfigPolicy(policyAdapter);
+ assertThatThrownBy(() -> policy.savePolicies()).isInstanceOf(Exception.class);
- // Test create methods
- String testFileName = "testFile.zip";
- String testVal = "testVal";
- CreateNewOptimizationModel model =
- new CreateNewOptimizationModel(testFileName, testVal, testVal, testVal, testVal);
- model.addValuesToNewModel();
- model.saveImportService();
+ AdviceExpressionsType expType = policy.getAdviceExpressions(1, "filename");
+ assertEquals(1, expType.getAdviceExpression().size());
}
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorTest.java
new file mode 100644
index 000000000..145873981
--- /dev/null
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorTest.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.xacml.rest.elk;
+
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.pap.xacml.rest.elk.client.ElkConnector;
+import org.onap.policy.pap.xacml.rest.elk.client.ElkConnector.PolicyBodyType;
+import org.onap.policy.pap.xacml.rest.elk.client.ElkConnector.PolicyIndexType;
+import org.onap.policy.pap.xacml.rest.elk.client.ElkConnector.PolicyType;
+
+public class ElkConnectorTest {
+ @Test
+ public void testConnector() {
+ PolicyType type = PolicyType.Config;
+ PolicyBodyType body = PolicyBodyType.json;
+ assertNotNull(type);
+ assertNotNull(body);
+
+ assertEquals(PolicyIndexType.closedloop, ElkConnector.toPolicyIndexType("Config_Fault"));
+ assertEquals(PolicyIndexType.closedloop, ElkConnector.toPolicyIndexType("Config_PM"));
+ assertEquals(PolicyIndexType.config, ElkConnector.toPolicyIndexType("Config_FW"));
+ assertEquals(PolicyIndexType.config, ElkConnector.toPolicyIndexType("Config_MS"));
+ assertEquals(PolicyIndexType.config, ElkConnector.toPolicyIndexType("Config_OOF"));
+ assertEquals(PolicyIndexType.action, ElkConnector.toPolicyIndexType("Action"));
+ assertEquals(PolicyIndexType.decision, ElkConnector.toPolicyIndexType("Decision"));
+ assertEquals(PolicyIndexType.config, ElkConnector.toPolicyIndexType("Config"));
+
+ assertThatIllegalArgumentException().isThrownBy(() -> ElkConnector.toPolicyIndexType(null));
+
+ assertThatIllegalArgumentException().isThrownBy(() -> ElkConnector.toPolicyIndexType("Foo"));
+ }
+}
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 17967a4bb..a9da00d5a 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
@@ -23,16 +23,15 @@ package org.onap.policy.pap.xacml.rest.handler;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
import com.mockrunner.mock.web.MockHttpServletRequest;
import com.mockrunner.mock.web.MockHttpServletResponse;
-
+import java.io.IOException;
import java.util.Collections;
import java.util.List;
-
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
@@ -44,6 +43,7 @@ import org.onap.policy.common.logging.OnapLoggingContext;
import org.onap.policy.pap.xacml.rest.XACMLPapServlet;
import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
import org.onap.policy.pap.xacml.rest.elk.client.PolicyElasticSearchController;
+import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
import org.onap.policy.xacml.std.pap.StdEngine;
@@ -98,19 +98,11 @@ public class DeleteHandlerTest {
// Test deletion from PAP
MockHttpServletResponse response = new MockHttpServletResponse();
- try {
- handler.doApiDeleteFromPap(request, response);
- } catch (Exception ex) {
- fail("Not expecting an exception: " + ex);
- }
+ handler.doApiDeleteFromPap(request, response);
// 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);
- }
+ handler.doApiDeleteFromPdp(request, response, loggingContext);
// Test delete entity
PolicyEntity policyEntity = new PolicyEntity();
@@ -122,4 +114,34 @@ public class DeleteHandlerTest {
List<?> peResult = Collections.emptyList();
assertEquals(DeleteHandler.checkPolicyGroupEntity(peResult), false);
}
+
+ @Test
+ public void testDoDeletePap() throws IOException {
+ CommonClassDao dao = Mockito.mock(CommonClassDao.class);
+ DeleteHandler handler = new DeleteHandler(dao);
+
+ // Mock request
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ request.setBodyContent(
+ "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Config_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n");
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ handler.doApiDeleteFromPap(request, response);
+ assertTrue(response.containsHeader("error"));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testDoDeletePdp() throws IOException {
+ CommonClassDao dao = Mockito.mock(CommonClassDao.class);
+ DeleteHandler handler = new DeleteHandler(dao);
+ OnapLoggingContext loggingContext = new OnapLoggingContext();
+
+ // Mock request
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ request.setBodyContent(
+ "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Config_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n");
+ MockHttpServletResponse response = new MockHttpServletResponse();
+
+ handler.doApiDeleteFromPdp(request, response, loggingContext);
+ }
}