aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-07-30 16:58:54 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-07-31 15:35:49 +0100
commit37d8ade146096bf343f494163a528f75b2161095 (patch)
tree695aa4b86a35bf02c824c56357dd31f0686c21b5 /main/src/test/java
parentce63c402be2f4c5e437eefa1cbe327c3a9d0caad (diff)
Add start and parameter handling
Add startup code, command line parsing, service start, and parameter handling for the policy distribution service. Issue-ID: POLICY-922 Change-Id: Ie664aba6541304cf9b635541e9688c681b24952d Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'main/src/test/java')
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/TestExceptions.java39
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java46
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java127
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java31
4 files changed, 243 insertions, 0 deletions
diff --git a/main/src/test/java/org/onap/policy/distribution/main/TestExceptions.java b/main/src/test/java/org/onap/policy/distribution/main/TestExceptions.java
new file mode 100644
index 00000000..b3140978
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/TestExceptions.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class TestExceptions {
+
+ @Test
+ public void test() {
+ assertNotNull(new PolicyDistributionException("Message"));
+ assertNotNull(new PolicyDistributionException("Message", new IOException()));
+
+ assertNotNull(new PolicyDistributionRuntimeException("Message"));
+ assertNotNull(new PolicyDistributionRuntimeException("Message", new IOException()));
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java
new file mode 100644
index 00000000..bf553918
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterGroup.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class TestParameterGroup {
+
+ @Test
+ public void testParameterGroup() {
+ DistributionParameterGroup parameterGroup = new DistributionParameterGroup("groupName");
+ assertEquals("groupName", parameterGroup.getName());
+ assertTrue(parameterGroup.isValid());
+
+ parameterGroup = new DistributionParameterGroup(null);
+ assertNull(parameterGroup.getName());
+ assertFalse(parameterGroup.isValid());
+
+ parameterGroup = new DistributionParameterGroup("");
+ assertEquals("", parameterGroup.getName());
+ assertFalse(parameterGroup.isValid());
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java
new file mode 100644
index 00000000..5b938988
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestParameterHandler.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.parameters;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments;
+
+public class TestParameterHandler {
+ @Test
+ public void testParameterHandlerNoParameterFile() throws PolicyDistributionException {
+ String[] noArgumentString = { "-c", "parameters/NoParameterFile.json" };
+
+ DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("error reading parameters from \"parameters/NoParameterFile.json\"\n"
+ + "(FileNotFoundException):parameters/NoParameterFile.json (No such file or directory)",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerEmptyParameters() throws PolicyDistributionException {
+ String[] emptyArgumentString = { "-c", "parameters/EmptyParameters.json" };
+
+ DistributionCommandLineArguments emptyArguments = new DistributionCommandLineArguments();
+ emptyArguments.parse(emptyArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(emptyArguments);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("no parameters found in \"parameters/EmptyParameters.json\"", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerBadParameters() throws PolicyDistributionException {
+ String[] badArgumentString = { "-c", "parameters/BadParameters.json" };
+
+ DistributionCommandLineArguments badArguments = new DistributionCommandLineArguments();
+ badArguments.parse(badArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(badArguments);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("error reading parameters from \"parameters/BadParameters.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 testParameterHandlerInvalidParameters() throws PolicyDistributionException {
+ String[] invalidArgumentString = { "-c", "parameters/InvalidParameters.json" };
+
+ DistributionCommandLineArguments invalidArguments = new DistributionCommandLineArguments();
+ invalidArguments.parse(invalidArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(invalidArguments);
+ fail("test should throw an exception here");
+ } catch (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 PolicyDistributionException {
+ String[] noArgumentString = { "-c", "parameters/NoParameters.json" };
+
+ DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("validation error(s) on parameters from \"parameters/NoParameters.json\"\n"
+ + "parameter group \"null\" type "
+ + "\"org.onap.policy.distribution.main.parameters.DistributionParameterGroup\""
+ + " INVALID, parameter group has status INVALID\n"
+ + " field \"name\" type \"java.lang.String\" value \"null\" INVALID, must be a non-blank string\n",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerMinumumParameters() throws PolicyDistributionException {
+ String[] minArgumentString = { "-c", "parameters/MinimumParameters.json" };
+
+ DistributionCommandLineArguments minArguments = new DistributionCommandLineArguments();
+ minArguments.parse(minArgumentString);
+
+ DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(minArguments);
+ assertEquals("nameFromFile", parGroup.getName());
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
new file mode 100644
index 00000000..781a2ab8
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.main.startstop;
+
+import org.junit.Test;
+
+public class TestMain {
+
+ @Test
+ public void testMain() {
+ Main.main(null);
+ }
+}