From 06f456d8d06840a21f48531b0bd35b1a429b10f9 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Thu, 1 Feb 2018 12:22:30 -0500 Subject: Reduce technical debt and add JUnit * Addressed some very simple cyclic complexity * Added simple JUnit tests and finished others * Removed useless assignments Issue-ID: POLICY-477 Change-Id: Ic919bbf78ad2732a430c32f1feb3c88678be710d Signed-off-by: Pamela Dragosh --- .../onap/policy/std/test/AutoClientEndTest.java | 12 --- .../policy/std/test/ManualClientEndUEBTest.java | 12 --- .../org/onap/policy/std/test/MatchStoreTest.java | 12 --- .../org/onap/policy/test/AttributeTypeTest.java | 9 +++ .../policy/test/DeletePolicyConditionTest.java | 7 ++ .../onap/policy/test/DictionaryParametersTest.java | 51 ++++++++++++ .../org/onap/policy/test/DictionaryTypeTest.java | 45 +++++++++++ .../policy/test/MetricsRequestParametersTest.java | 39 +++++++++ .../java/org/onap/policy/test/PolicyClassTest.java | 10 ++- .../onap/policy/test/PolicyConfigStatusTest.java | 14 +++- .../org/onap/policy/test/PolicyConfigTypeTest.java | 6 ++ .../org/onap/policy/test/PolicyDecisionTest.java | 7 ++ .../org/onap/policy/test/PolicyExceptionTest.java | 92 ++++++++++++++++++++++ .../org/onap/policy/test/PolicyParametersTest.java | 29 ++++++- .../onap/policy/test/PolicyResponseStatusTest.java | 23 ++++-- .../java/org/onap/policy/test/PolicyTypeTest.java | 7 ++ .../org/onap/policy/test/RuleProviderTest.java | 39 +++++++++ .../onap/policy/test/StdDecisionResponseTest.java | 39 +++++++++ .../policy/test/StdDictionaryResponseTest.java | 44 +++++++++++ .../onap/policy/test/StdMetricsResponseTest.java | 44 +++++++++++ 20 files changed, 489 insertions(+), 52 deletions(-) create mode 100644 PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryParametersTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryTypeTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/onap/policy/test/MetricsRequestParametersTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyExceptionTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/onap/policy/test/RuleProviderTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDecisionResponseTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDictionaryResponseTest.java create mode 100644 PolicyEngineAPI/src/test/java/org/onap/policy/test/StdMetricsResponseTest.java (limited to 'PolicyEngineAPI/src/test/java/org/onap') diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java index 203b9f54f..664dcc808 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/AutoClientEndTest.java @@ -37,18 +37,6 @@ import org.onap.policy.std.StdPolicyEngine; * @version $Revision: 1.0 $ */ public class AutoClientEndTest { - /** - * Run the AutoClientEnd() constructor test. - * - * @generatedBy CodePro at 6/1/16 1:40 PM - */ - @Test - public void testAutoClientEnd_1() - throws Exception { - AutoClientEnd result = new AutoClientEnd(); - assertNotNull(result); - // add additional test code here - } /** * Run the boolean getStatus() method test. diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndUEBTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndUEBTest.java index 77b0c6f49..d81ba3f98 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndUEBTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/ManualClientEndUEBTest.java @@ -62,18 +62,6 @@ public class ManualClientEndUEBTest { uebURLList.add(url); } - /** - * Run the ManualClientEndUEB() constructor test. - * - * @generatedBy CodePro at 6/1/16 1:40 PM - */ - @Test - public void testManualClientEndUEB_1() - throws Exception { - ManualClientEndUEB result = new ManualClientEndUEB(); - assertNotNull(result); - // add additional test code here - } /** * Run the PDPNotification result(NotificationScheme) method test. diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java index 856474dd8..e4116db1d 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/std/test/MatchStoreTest.java @@ -41,18 +41,6 @@ import org.onap.policy.std.StdPDPNotification; * @version $Revision: 1.0 $ */ public class MatchStoreTest { - /** - * Run the MatchStore() constructor test. - * - * @generatedBy CodePro at 6/1/16 1:41 PM - */ - @Test - public void testMatchStore_1() - throws Exception { - MatchStore result = new MatchStore(); - assertNotNull(result); - // add additional test code here - } /** * Run the PDPNotification checkMatch(PDPNotification) method test. diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/AttributeTypeTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/AttributeTypeTest.java index 62c447fae..d817deff3 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/AttributeTypeTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/AttributeTypeTest.java @@ -48,6 +48,15 @@ public class AttributeTypeTest { // add additional test code here assertEquals("matching", result); + + AttributeType type = AttributeType.create("dictionary"); + assertEquals(AttributeType.DICTIONARY, type); + + } + + @Test(expected = IllegalArgumentException.class) + public void testException() { + AttributeType.create("foobar"); } /** diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/DeletePolicyConditionTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DeletePolicyConditionTest.java index 2513816bb..d59a14658 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/DeletePolicyConditionTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DeletePolicyConditionTest.java @@ -48,8 +48,15 @@ public class DeletePolicyConditionTest { // add additional test code here assertEquals("All Versions", result); + + assertEquals(DeletePolicyCondition.ALL, DeletePolicyCondition.create(DeletePolicyCondition.ALL.name())); } + @Test(expected = IllegalArgumentException.class) + public void testException() { + DeletePolicyCondition.create("foobar"); + } + /** * Perform pre-test initialization. * diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryParametersTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryParametersTest.java new file mode 100644 index 000000000..63e1d7c5a --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryParametersTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * 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.test; + +import static org.junit.Assert.*; + +import java.util.UUID; + +import org.junit.Test; +import org.onap.policy.api.DictionaryParameters; +import org.onap.policy.api.DictionaryType; + +public class DictionaryParametersTest { + + @Test + public void test() { + DictionaryParameters params = new DictionaryParameters(); + + params.setDictionary("dictionary"); + assertEquals("dictionary", params.getDictionary()); + + UUID uuid = UUID.randomUUID(); + params.setRequestID(uuid); + assertEquals(uuid, params.getRequestID()); + + params.setDictionaryJson("{}"); + assertEquals("{}", params.getDictionaryJson()); + + params.setDictionaryType(DictionaryType.BRMS); + assertEquals(DictionaryType.BRMS, params.getDictionaryType()); + + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryTypeTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryTypeTest.java new file mode 100644 index 000000000..bbab6d318 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/DictionaryTypeTest.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * 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.test; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.api.DictionaryType; + +public class DictionaryTypeTest { + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test(expected = IllegalArgumentException.class) + public void test() { + assertEquals(DictionaryType.Action, DictionaryType.create(DictionaryType.Action.toString())); + DictionaryType.create("foobar"); + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/MetricsRequestParametersTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/MetricsRequestParametersTest.java new file mode 100644 index 000000000..19d7933fc --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/MetricsRequestParametersTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * 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.test; + +import static org.junit.Assert.*; + +import java.util.UUID; + +import org.junit.Test; +import org.onap.policy.api.MetricsRequestParameters; + +public class MetricsRequestParametersTest { + + @Test + public void test() { + MetricsRequestParameters p = new MetricsRequestParameters(); + + p.setRequestID(UUID.randomUUID()); + assertNotNull(p.getRequestID()); + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyClassTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyClassTest.java index 24eafc1ad..b4aaa64d8 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyClassTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyClassTest.java @@ -40,16 +40,22 @@ public class PolicyClassTest { * @generatedBy CodePro at 6/1/16 1:40 PM */ @Test - public void testToString_1() - throws Exception { + public void testToString_1() { PolicyClass fixture = PolicyClass.Action; String result = fixture.toString(); // add additional test code here assertEquals("Action", result); + + assertEquals(PolicyClass.Decision, PolicyClass.create(PolicyClass.Decision.toString())); } + @Test(expected = IllegalArgumentException.class) + public void testException() { + PolicyClass.create("foobar"); + } + /** * Perform pre-test initialization. * diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigStatusTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigStatusTest.java index 7a93f0505..49691724a 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigStatusTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigStatusTest.java @@ -51,6 +51,8 @@ public class PolicyConfigStatusTest { assertEquals("not_found", result.toString()); assertEquals("CONFIG_NOT_FOUND", result.name()); assertEquals(1, result.ordinal()); + + assertEquals(PolicyConfigStatus.CONFIG_RETRIEVED, PolicyConfigStatus.create("retrieved")); } /** @@ -63,15 +65,15 @@ public class PolicyConfigStatusTest { @Test public void testGetStatus_2() throws Exception { - String configStatus = ""; + String configStatus = "retrieved"; PolicyConfigStatus result = PolicyConfigStatus.getStatus(configStatus); // add additional test code here assertNotNull(result); - assertEquals("not_found", result.toString()); - assertEquals("CONFIG_NOT_FOUND", result.name()); - assertEquals(1, result.ordinal()); + assertEquals("retrieved", result.toString()); + assertEquals("CONFIG_RETRIEVED", result.name()); + assertEquals(0, result.ordinal()); } /** @@ -92,6 +94,10 @@ public class PolicyConfigStatusTest { assertEquals("not_found", result); } + @Test(expected = IllegalArgumentException.class) + public void testException () { + PolicyConfigStatus.create("foobar"); + } /** * Perform pre-test initialization. * diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigTypeTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigTypeTest.java index e5e0b5494..2d838aa08 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigTypeTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyConfigTypeTest.java @@ -48,8 +48,14 @@ public class PolicyConfigTypeTest { // add additional test code here assertEquals("BRMS_Param", result); + + assertEquals(PolicyConfigType.MicroService, PolicyConfigType.create(PolicyConfigType.MicroService.name())); } + @Test(expected = IllegalArgumentException.class) + public void testException() { + PolicyConfigType.create("foobar"); + } /** * Perform pre-test initialization. * diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyDecisionTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyDecisionTest.java index 4d9523859..a6391700f 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyDecisionTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyDecisionTest.java @@ -48,6 +48,13 @@ public class PolicyDecisionTest { // add additional test code here assertEquals("deny", result); + + assertEquals(PolicyDecision.PERMIT, PolicyDecision.create(PolicyDecision.PERMIT.name())); + } + + @Test(expected = IllegalArgumentException.class) + public void testException() { + PolicyDecision.create("foobar"); } /** diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyExceptionTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyExceptionTest.java new file mode 100644 index 000000000..f925edbfa --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyExceptionTest.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * 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.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.api.PolicyException; + +public class PolicyExceptionTest { + + @Test + public void test1() { + PolicyException result = new PolicyException(); + // add additional test code here + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.onap.policy.api.PolicyException", result.toString()); + assertEquals(null, result.getLocalizedMessage()); + assertEquals(null, result.getMessage()); + } + + @Test + public void test2() { + String message = "message"; + PolicyException result = new PolicyException(message); + assertNotNull(result); + assertEquals(null, result.getCause()); + assertEquals("org.onap.policy.api.PolicyException: " + message, result.toString()); + assertEquals(message, result.getLocalizedMessage()); + assertEquals(message, result.getMessage()); + + } + + @Test + public void test3() { + Throwable cause = new Throwable(); + PolicyException result = new PolicyException(cause); + assertNotNull(result); + assertEquals("org.onap.policy.api.PolicyException: java.lang.Throwable", result.toString()); + assertEquals("java.lang.Throwable", result.getLocalizedMessage()); + assertEquals("java.lang.Throwable", result.getMessage()); + } + + @Test + public void test4() { + String message = ""; + Throwable cause = new Throwable(); + PolicyException result = new PolicyException(message, cause); + assertNotNull(result); + assertEquals("org.onap.policy.api.PolicyException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + @Test + public void test5() + throws Exception { + String message = ""; + Throwable cause = new Throwable(); + boolean enableSuppression = true; + boolean writableStackTrace = true; + + PolicyException result = new PolicyException(message, cause, enableSuppression, writableStackTrace); + + // add additional test code here + assertNotNull(result); + assertEquals("org.onap.policy.api.PolicyException: ", result.toString()); + assertEquals("", result.getLocalizedMessage()); + assertEquals("", result.getMessage()); + } + + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyParametersTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyParametersTest.java index ff192dcab..c0bc0e84f 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyParametersTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyParametersTest.java @@ -20,9 +20,10 @@ package org.onap.policy.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; +import java.util.Collections; +import java.util.Date; import java.util.Hashtable; import java.util.LinkedList; import java.util.List; @@ -45,6 +46,30 @@ import org.onap.policy.api.PolicyType; * @version $Revision: 1.0 $ */ public class PolicyParametersTest { + + @Test + public void testEverythingElse() { + PolicyParameters params = new PolicyParameters(); + params.setRuleProvider(null); + assertNull(params.getRuleProvider()); + params.setGuard(false); + assertFalse(params.getGuard()); + params.setRiskLevel("level"); + assertEquals("level", params.getRiskLevel()); + params.setRiskType("type"); + assertEquals("type", params.getRiskType()); + params.setTtlDate(new Date()); + assertNotNull(params.getTtlDate()); + params.setControllerName(null); + assertNull(params.getControllerName()); + params.setDependencyNames(Collections.emptyList()); + params.setExtendedOption(null); + assertNull(params.getExtendedOption()); + params.setTreatments(Collections.emptyMap()); + assertTrue(params.getTreatments().size() == 0); + assertNotNull(params.toString()); + } + /** * Run the String getActionAttribute() method test. * diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyResponseStatusTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyResponseStatusTest.java index 294f0929d..4803a8ece 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyResponseStatusTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyResponseStatusTest.java @@ -63,15 +63,15 @@ public class PolicyResponseStatusTest { @Test public void testGetStatus_2() throws Exception { - String responseStatus = ""; + String responseStatus = "action_advised"; PolicyResponseStatus result = PolicyResponseStatus.getStatus(responseStatus); // add additional test code here assertNotNull(result); - assertEquals("no_action", result.toString()); - assertEquals("NO_ACTION_REQUIRED", result.name()); - assertEquals(0, result.ordinal()); + assertEquals("action_advised", result.toString()); + assertEquals("ACTION_ADVISED", result.name()); + assertEquals(1, result.ordinal()); } /** @@ -84,15 +84,15 @@ public class PolicyResponseStatusTest { @Test public void testGetStatus_3() throws Exception { - String responseStatus = ""; + String responseStatus = "action_taken"; PolicyResponseStatus result = PolicyResponseStatus.getStatus(responseStatus); // add additional test code here assertNotNull(result); - assertEquals("no_action", result.toString()); - assertEquals("NO_ACTION_REQUIRED", result.name()); - assertEquals(0, result.ordinal()); + assertEquals("action_taken", result.toString()); + assertEquals("ACTION_TAKEN", result.name()); + assertEquals(2, result.ordinal()); } /** @@ -111,6 +111,13 @@ public class PolicyResponseStatusTest { // add additional test code here assertEquals("action_advised", result); + + assertEquals(PolicyResponseStatus.ACTION_ADVISED, PolicyResponseStatus.create("ACTION_ADVISED")); + } + + @Test(expected = IllegalArgumentException.class) + public void testTheRest() { + PolicyResponseStatus.create("foobar"); } /** diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyTypeTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyTypeTest.java index 9f1a608da..267dd9771 100644 --- a/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyTypeTest.java +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/PolicyTypeTest.java @@ -48,6 +48,13 @@ public class PolicyTypeTest { // add additional test code here assertEquals("json", result); + + assertEquals(PolicyType.JSON, PolicyType.create("json")); + } + + @Test(expected = IllegalArgumentException.class) + public void testException() { + PolicyType.create("foobar"); } /** diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/RuleProviderTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/RuleProviderTest.java new file mode 100644 index 000000000..23353232e --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/RuleProviderTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * 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.test; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.policy.api.RuleProvider; + +public class RuleProviderTest { + + @Test + public void test() { + assertEquals(RuleProvider.RAINY_DAY, RuleProvider.create(RuleProvider.RAINY_DAY.name())); + } + + @Test(expected = IllegalArgumentException.class) + public void testException() { + RuleProvider.create("foobar"); + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDecisionResponseTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDecisionResponseTest.java new file mode 100644 index 000000000..0808c6b3a --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDecisionResponseTest.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * 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.test; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.policy.api.PolicyDecision; +import org.onap.policy.std.StdDecisionResponse; + +public class StdDecisionResponseTest { + + @Test + public void test() { + StdDecisionResponse r = new StdDecisionResponse(); + r.setDecision(PolicyDecision.DENY); + assertEquals(PolicyDecision.DENY, r.getDecision()); + r.setDetails("details"); + assertEquals("details", r.getDetails()); + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDictionaryResponseTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDictionaryResponseTest.java new file mode 100644 index 000000000..fc0b9f97c --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdDictionaryResponseTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * 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.test; + +import static org.junit.Assert.*; + +import java.util.Collections; + +import org.junit.Test; +import org.onap.policy.std.StdDictionaryResponse; + +public class StdDictionaryResponseTest { + + @Test + public void test() { + StdDictionaryResponse r = new StdDictionaryResponse(); + r.setResponseCode(0); + assertEquals(0, r.getResponseCode()); + r.setResponseMessage("msg"); + assertEquals("msg", r.getResponseMessage()); + r.setDictionaryData(Collections.emptyMap()); + assertEquals(0, r.getDictionaryData().size()); + r.setDictionaryJson(null); + assertNull(r.getDictionaryJson()); + } + +} diff --git a/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdMetricsResponseTest.java b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdMetricsResponseTest.java new file mode 100644 index 000000000..a17fb06c2 --- /dev/null +++ b/PolicyEngineAPI/src/test/java/org/onap/policy/test/StdMetricsResponseTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * PolicyEngineAPI + * ================================================================================ + * 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.test; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.policy.std.StdMetricsResponse; + +public class StdMetricsResponseTest { + + @Test + public void test() { + StdMetricsResponse r = new StdMetricsResponse(); + r.setMetricsTotal(0); + assertEquals(0, r.getMetricsTotal()); + r.setPapMetrics(0); + assertEquals(0, r.getPapMetrics()); + r.setPdpMetrics(0); + assertEquals(0, r.getPdpMetrics()); + r.setResponseCode(0); + assertEquals(0, r.getResponseCode()); + r.setResponseMessage("msg"); + assertEquals("msg", r.getResponseMessage()); + } + +} -- cgit 1.2.3-korg