From 5e38903a6e37dcc52b2a42e2bc5bfae8c92ef051 Mon Sep 17 00:00:00 2001 From: bobbymander Date: Tue, 20 Feb 2018 15:20:27 -0500 Subject: [PATCH] JUnit additions for ONAP-PAP-REST Issue-ID: POLICY-600 Change-Id: I2e6d0d656a9be77b038a08568d43d1bb7efefe57 Signed-off-by: bobbymander --- .../pap/xacml/rest/elk/ElkConnectorImplTest.java | 48 +++++- .../onap/policy/pap/xacml/rest/elk/PairTest.java | 44 +++++ .../pap/xacml/rest/elk/PolicyElasticDataTest.java | 188 +++++++++++++++++++++ .../pap/xacml/rest/elk/PolicyLocatorTest.java | 43 +++++ 4 files changed, 322 insertions(+), 1 deletion(-) create mode 100644 ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PairTest.java create mode 100644 ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticDataTest.java create mode 100644 ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyLocatorTest.java 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 c0f59273c..853d75ce6 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -27,11 +27,15 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import io.searchbox.client.JestResult; +import java.io.IOException; import java.lang.reflect.Method; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.onap.policy.pap.xacml.rest.elk.client.ElkConnector.PolicyIndexType; import org.onap.policy.pap.xacml.rest.elk.client.ElkConnectorImpl; +import org.onap.policy.rest.adapter.PolicyRestAdapter; public class ElkConnectorImplTest { @@ -96,5 +100,47 @@ public class ElkConnectorImplTest { 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 new file mode 100644 index 000000000..68f1daa0b --- /dev/null +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PairTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP-PAP-REST + * ================================================================================ + * Copyright (C) 2018 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.junit.Assert.assertEquals; +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 pair = new Pair(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 new file mode 100644 index 000000000..a84e4a0cd --- /dev/null +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyElasticDataTest.java @@ -0,0 +1,188 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP-PAP-REST + * ================================================================================ + * Copyright (C) 2018 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.junit.Assert.assertEquals; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import org.junit.Test; +import org.onap.policy.pap.xacml.rest.elk.client.PolicyElasticData; +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 testMap = new LinkedHashMap(); + testMap.put(testKey, testVal); + ArrayList testArray = new ArrayList(); + testArray.add(testVal); + List testList = new ArrayList(); + testList.add(testVal); + List testObjectList = new ArrayList(); + 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/PolicyLocatorTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyLocatorTest.java new file mode 100644 index 000000000..b648a318a --- /dev/null +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/PolicyLocatorTest.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP-PAP-REST + * ================================================================================ + * Copyright (C) 2018 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.junit.Assert.assertEquals; +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"; + String owner = "owner"; + String scope = "scope"; + String policyId = "id"; + String version = "1.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); + } +} -- 2.16.6