summaryrefslogtreecommitdiffstats
path: root/main/src/test/java
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@est.tech>2019-01-31 13:09:00 +0000
committerramverma <ram.krishna.verma@est.tech>2019-01-31 13:09:00 +0000
commit07b7ba00a053a26a5eef39070bff5297c630c5ce (patch)
tree475cc8ce35a140797d5527b924a307936beaaa61 /main/src/test/java
parentb4b7d79c3a90255d2f59fdc05ed4259a94b57fc2 (diff)
Create basic structure of pap component
1) Creating the basic code structure of pap component which includes main sub-module having Main, PapActivator, PapCommandLineArguments, PapParameterGroup & PapParameterHandler. Along with few exception classes. Basicalliy the structure follows the pattern developed in policy/distribution component. 2) Created the related unit test cases and required test resources. Change-Id: I67c82f9d072e6c8a306cb983accb693da70e58a2 Issue-ID: POLICY-1476 Signed-off-by: ramverma <ram.krishna.verma@est.tech>
Diffstat (limited to 'main/src/test/java')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/TestExceptions.java44
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java32
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java73
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java166
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/startstop/TestMain.java72
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java54
6 files changed, 441 insertions, 0 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/TestExceptions.java b/main/src/test/java/org/onap/policy/pap/main/TestExceptions.java
new file mode 100644
index 00000000..b45cdab7
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pap/main/TestExceptions.java
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test of {@link PolicyPapException PolicyPapRuntimeException}}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class TestExceptions {
+
+ @Test
+ public void test() {
+ assertNotNull(new PolicyPapException("Message"));
+ assertNotNull(new PolicyPapException("Message", new IOException()));
+
+ assertNotNull(new PolicyPapRuntimeException("Message"));
+ assertNotNull(new PolicyPapRuntimeException("Message", new IOException()));
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java
new file mode 100644
index 00000000..5e62ba68
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pap/main/parameters/CommonTestData.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.parameters;
+
+/**
+ * Class to hold/create all parameters for test cases.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class CommonTestData {
+
+ public static final String PAP_GROUP_NAME = "PapGroup";
+
+}
diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java
new file mode 100644
index 00000000..086d7c22
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+/**
+ * Class to perform unit test of {@link PapParameterGroup}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class TestPapParameterGroup {
+
+ @Test
+ public void testPapParameterGroup() {
+ final PapParameterGroup papParameters = new PapParameterGroup(CommonTestData.PAP_GROUP_NAME);
+ final GroupValidationResult validationResult = papParameters.validate();
+ assertTrue(validationResult.isValid());
+ assertEquals(CommonTestData.PAP_GROUP_NAME, papParameters.getName());
+ }
+
+ @Test
+ public void testPapParameterGroup_NullName() {
+ final PapParameterGroup papParameters = new PapParameterGroup(null);
+ final GroupValidationResult validationResult = papParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertEquals(null, papParameters.getName());
+ assertTrue(validationResult.getResult().contains(
+ "field \"name\" type \"java.lang.String\" value \"null\" INVALID, " + "must be a non-blank string"));
+ }
+
+ @Test
+ public void testPapParameterGroup_EmptyName() {
+ final PapParameterGroup papParameters = new PapParameterGroup("");
+ final GroupValidationResult validationResult = papParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertEquals("", papParameters.getName());
+ assertTrue(validationResult.getResult().contains(
+ "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
+ }
+
+ @Test
+ public void testPapParameterGroup_SetName() {
+ final PapParameterGroup papParameters = new PapParameterGroup(CommonTestData.PAP_GROUP_NAME);
+ papParameters.setName("PapNewGroup");
+ final GroupValidationResult validationResult = papParameters.validate();
+ assertTrue(validationResult.isValid());
+ assertEquals("PapNewGroup", papParameters.getName());
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java
new file mode 100644
index 00000000..cb14748d
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java
@@ -0,0 +1,166 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.pap.main.PolicyPapException;
+import org.onap.policy.pap.main.startstop.PapCommandLineArguments;
+
+/**
+ * Class to perform unit test of {@link PapParameterHandler}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class TestPapParameterHandler {
+
+ @Test
+ public void testParameterHandlerNoParameterFile() throws PolicyPapException {
+ final String[] noArgumentString = { "-c", "parameters/NoParameterFile.json" };
+
+ final PapCommandLineArguments noArguments = new PapCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new PapParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("FileNotFoundException"));
+ }
+ }
+
+ @Test
+ public void testParameterHandlerEmptyParameters() throws PolicyPapException {
+ final String[] emptyArgumentString = { "-c", "parameters/EmptyParameters.json" };
+
+ final PapCommandLineArguments emptyArguments = new PapCommandLineArguments();
+ emptyArguments.parse(emptyArgumentString);
+
+ try {
+ new PapParameterHandler().getParameters(emptyArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("no parameters found in \"parameters/EmptyParameters.json\"", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerInvalidParameters() throws PolicyPapException {
+ final String[] invalidArgumentString = { "-c", "parameters/InvalidParameters.json" };
+
+ final PapCommandLineArguments invalidArguments = new PapCommandLineArguments();
+ invalidArguments.parse(invalidArgumentString);
+
+ try {
+ new PapParameterHandler().getParameters(invalidArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("error reading parameters from \"parameters/InvalidParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerNoParameters() throws PolicyPapException {
+ final String[] noArgumentString = { "-c", "parameters/NoParameters.json" };
+
+ final PapCommandLineArguments noArguments = new PapCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new PapParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains(
+ "field \"name\" type \"java.lang.String\" value \"null\" INVALID, must be a non-blank string"));
+ }
+ }
+
+ @Test
+ public void testParameterHandlerMinumumParameters() throws PolicyPapException {
+ final String[] minArgumentString = { "-c", "parameters/MinimumParameters.json" };
+
+ final PapCommandLineArguments minArguments = new PapCommandLineArguments();
+ minArguments.parse(minArgumentString);
+
+ final PapParameterGroup parGroup = new PapParameterHandler().getParameters(minArguments);
+ assertEquals(CommonTestData.PAP_GROUP_NAME, parGroup.getName());
+ }
+
+ @Test
+ public void testPapParameterGroup() throws PolicyPapException {
+ final String[] papConfigParameters = { "-c", "parameters/PapConfigParameters.json" };
+
+ final PapCommandLineArguments arguments = new PapCommandLineArguments();
+ arguments.parse(papConfigParameters);
+
+ final PapParameterGroup parGroup = new PapParameterHandler().getParameters(arguments);
+ assertTrue(arguments.checkSetConfigurationFilePath());
+ assertEquals(CommonTestData.PAP_GROUP_NAME, parGroup.getName());
+ }
+
+ @Test
+ public void testPapParameterGroup_InvalidName() throws PolicyPapException {
+ final String[] papConfigParameters = { "-c", "parameters/PapConfigParameters_InvalidName.json" };
+
+ final PapCommandLineArguments arguments = new PapCommandLineArguments();
+ arguments.parse(papConfigParameters);
+
+ try {
+ new PapParameterHandler().getParameters(arguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains(
+ "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"));
+ }
+ }
+
+ @Test
+ public void testPapVersion() throws PolicyPapException {
+ final String[] papConfigParameters = { "-v" };
+ final PapCommandLineArguments arguments = new PapCommandLineArguments();
+ final String version = arguments.parse(papConfigParameters);
+ assertTrue(version.startsWith("ONAP Policy Framework PAP Service"));
+ }
+
+ @Test
+ public void testPapHelp() throws PolicyPapException {
+ final String[] papConfigParameters = { "-h" };
+ final PapCommandLineArguments arguments = new PapCommandLineArguments();
+ final String help = arguments.parse(papConfigParameters);
+ assertTrue(help.startsWith("usage:"));
+ }
+
+ @Test
+ public void testPapInvalidOption() throws PolicyPapException {
+ final String[] papConfigParameters = { "-d" };
+ final PapCommandLineArguments arguments = new PapCommandLineArguments();
+ try {
+ arguments.parse(papConfigParameters);
+ } catch (final Exception exp) {
+ assertTrue(exp.getMessage().startsWith("invalid command line arguments specified"));
+ }
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/pap/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/pap/main/startstop/TestMain.java
new file mode 100644
index 00000000..8bc544b0
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pap/main/startstop/TestMain.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.startstop;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.pap.main.PolicyPapException;
+import org.onap.policy.pap.main.parameters.CommonTestData;
+
+/**
+ * Class to perform unit test of {@link Main}}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class TestMain {
+
+ @Test
+ public void testMain() throws PolicyPapException {
+ final String[] papConfigParameters = { "-c", "parameters/PapConfigParameters.json" };
+ final Main main = new Main(papConfigParameters);
+ assertTrue(main.getParameters().isValid());
+ assertEquals(CommonTestData.PAP_GROUP_NAME, main.getParameters().getName());
+ main.shutdown();
+ }
+
+ @Test
+ public void testMain_NoArguments() {
+ final String[] papConfigParameters = {};
+ final Main main = new Main(papConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+
+ @Test
+ public void testMain_InvalidArguments() {
+ final String[] papConfigParameters = { "parameters/PapConfigParameters.json" };
+ final Main main = new Main(papConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+
+ @Test
+ public void testMain_Help() {
+ final String[] papConfigParameters = { "-h" };
+ Main.main(papConfigParameters);
+ }
+
+ @Test
+ public void testMain_InvalidParameters() {
+ final String[] papConfigParameters = { "-c", "parameters/PapConfigParameters_InvalidName.json" };
+ final Main main = new Main(papConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java b/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java
new file mode 100644
index 00000000..03c3413a
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.startstop;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.pap.main.PolicyPapException;
+import org.onap.policy.pap.main.parameters.CommonTestData;
+import org.onap.policy.pap.main.parameters.PapParameterGroup;
+import org.onap.policy.pap.main.parameters.PapParameterHandler;
+
+
+/**
+ * Class to perform unit test of {@link PapActivator}}.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
+ */
+public class TestPapActivator {
+
+ @Test
+ public void testPapActivator() throws PolicyPapException {
+ final String[] papConfigParameters = { "-c", "parameters/PapConfigParameters.json" };
+
+ final PapCommandLineArguments arguments = new PapCommandLineArguments(papConfigParameters);
+
+ final PapParameterGroup parGroup = new PapParameterHandler().getParameters(arguments);
+
+ final PapActivator activator = new PapActivator(parGroup);
+ activator.initialize();
+ assertTrue(activator.getParameterGroup().isValid());
+ assertEquals(CommonTestData.PAP_GROUP_NAME, activator.getParameterGroup().getName());
+ activator.terminate();
+ }
+}