summaryrefslogtreecommitdiffstats
path: root/gui-pdp-monitoring/src/test/java
diff options
context:
space:
mode:
authorHengye <yehui.wang@est.tech>2020-02-25 09:15:58 +0800
committerHengye <yehui.wang@est.tech>2020-03-03 09:26:05 +0800
commit7fa12fdd8d4428a8b21ad143943858a1ca2e0e27 (patch)
tree770f902b866e426776a5b450c431ae1799c48a7f /gui-pdp-monitoring/src/test/java
parentfd7eb2d478674ae0922abee899d784441c7f3487 (diff)
Create PDP Monitoring GUI Model
Monitorning GUI to monitor PDPs Statistics, including Web and Rest Server by embeded jetty. Issue-ID: POLICY-2311 Signed-off-by: Hengye <yehui.wang@est.tech> Change-Id: I9bd0d50eaa7ae4dbd07d17389da2cf107e854c61
Diffstat (limited to 'gui-pdp-monitoring/src/test/java')
-rw-r--r--gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringExceptionTest.java39
-rw-r--r--gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringMainTest.java159
-rw-r--r--gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringRestTest.java40
3 files changed, 238 insertions, 0 deletions
diff --git a/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringExceptionTest.java b/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringExceptionTest.java
new file mode 100644
index 0000000..dbd0d80
--- /dev/null
+++ b/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringExceptionTest.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.gui.pdp.monitoring;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import org.onap.policy.common.utils.test.ExceptionsTester;
+
+/**
+ * Test the Pdp monitoring exception.
+ *
+ */
+public class MonitoringExceptionTest {
+
+ @Test
+ public void test() {
+ assertEquals(2, new ExceptionsTester().test(PdpMonitoringServerParameterException.class));
+ }
+}
diff --git a/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringMainTest.java b/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringMainTest.java
new file mode 100644
index 0000000..6421b01
--- /dev/null
+++ b/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringMainTest.java
@@ -0,0 +1,159 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.gui.pdp.monitoring;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+/**
+ * Test the periodic event manager utility.
+ */
+public class MonitoringMainTest {
+ @Test
+ public void testMonitoringServerBad() {
+ try {
+ final String[] eventArgs = {"-z"};
+
+ PdpMonitoringMain.main(eventArgs);
+ } catch (Exception exc) {
+ fail("test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testMonitoringServerOk() {
+ try {
+ final String[] eventArgs = {"-t", "1"};
+
+ PdpMonitoringMain.main(eventArgs);
+ } catch (Exception exc) {
+ fail("test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testMonitoringServerBadOptions() {
+ final String[] eventArgs = {"-zabbu"};
+ Throwable thrown = catchThrowable(() -> new PdpMonitoringMain(eventArgs));
+ assertThat(thrown).isInstanceOf(PdpMonitoringServerParameterException.class)
+ .hasMessageContaining("parameter error, invalid command line arguments specified");
+
+ }
+
+ @Test
+ public void testMonitoringServerHelp() {
+ final String[] eventArgs = {"-h"};
+ Throwable thrown = catchThrowable(() -> new PdpMonitoringMain(eventArgs));
+ assertThat(thrown).isInstanceOf(PdpMonitoringServerParameterException.class).hasMessageContaining(
+ "usage: org.onap.policy.gui.pdp.monitoring.PdpMonitoringMain [options...]");
+ }
+
+ @Test
+ public void testMonitoringServerPortBad() {
+ final String[] eventArgs = {"-p", "hello"};
+ Throwable thrown = catchThrowable(() -> new PdpMonitoringMain(eventArgs));
+ assertThat(thrown).isInstanceOf(PdpMonitoringServerParameterException.class)
+ .hasMessageContaining("error parsing argument \"port\"");
+ }
+
+ @Test
+ public void testMonitoringServerPortNegative() {
+ final String[] eventArgs = {"-p", "-1"};
+ Throwable thrown = catchThrowable(() -> new PdpMonitoringMain(eventArgs));
+ assertThat(thrown).isInstanceOf(PdpMonitoringServerParameterException.class).hasMessageContaining(
+ "item \"port\" value \"-1\" INVALID, is below the minimum value: 1024");
+ }
+
+ @Test
+ public void testMonitoringServerTtlTooSmall() {
+ final String[] eventArgs = {"-t", "-2"};
+
+ Throwable thrown = catchThrowable(() -> new PdpMonitoringMain(eventArgs));
+ assertThat(thrown).isInstanceOf(PdpMonitoringServerParameterException.class)
+ .hasMessageContaining("item \"timeToLive\" value \"-2\" INVALID, is below the minimum value: -1");
+ }
+
+ @Test
+ public void testMonitoringServerTooManyPars() {
+ final String[] eventArgs = {"-t", "10", "-p", "12344", "aaa", "bbb"};
+
+ Throwable thrown = catchThrowable(() -> new PdpMonitoringMain(eventArgs));
+ assertThat(thrown).isInstanceOf(PdpMonitoringServerParameterException.class)
+ .hasMessageContaining("parameter error, too many command line arguments specified : [aaa, bbb]");
+ }
+
+ @Test
+ public void testMonitoringServerTtlNotNumber() {
+ final String[] eventArgs = {"-t", "timetolive"};
+
+ Throwable thrown = catchThrowable(() -> new PdpMonitoringMain(eventArgs));
+ assertThat(thrown).isInstanceOf(PdpMonitoringServerParameterException.class).hasMessageContaining(
+ "parameter error, error parsing argument \"time-to-live\"");
+ }
+
+ @Test
+ public void testMonitoringServerPortTooBig() {
+ final String[] eventArgs = {"-p", "65536"};
+
+ Throwable thrown = catchThrowable(() -> new PdpMonitoringMain(eventArgs));
+ assertThat(thrown).isInstanceOf(PdpMonitoringServerParameterException.class)
+ .hasMessageContaining("item \"port\" value \"65536\" INVALID, exceeds the maximum value: 65534");
+ }
+
+ @Test
+ public void testMonitoringOneSecStart() {
+ final String[] eventArgs = {"-t", "1"};
+
+ try {
+ PdpMonitoringMain monRestMain = new PdpMonitoringMain(eventArgs);
+ monRestMain.init();
+ monRestMain.shutdown();
+
+ } catch (Exception ex) {
+ fail("test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testMonitoringForeverStart() {
+ final String[] eventArgs = {"-t", "-1"};
+
+ PdpMonitoringMain monRestMain = new PdpMonitoringMain(eventArgs);
+
+ Thread monThread = new Thread() {
+ @Override
+ public void run() {
+ monRestMain.init();
+ }
+ };
+
+ try {
+ monThread.start();
+ Thread.sleep(2000);
+ monRestMain.shutdown();
+ } catch (Exception ex) {
+ fail("test should not throw an exception");
+ }
+ }
+}
diff --git a/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringRestTest.java b/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringRestTest.java
new file mode 100644
index 0000000..06fe3b3
--- /dev/null
+++ b/gui-pdp-monitoring/src/test/java/org/onap/policy/gui/pdp/monitoring/MonitoringRestTest.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.gui.pdp.monitoring;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * monitoring rest tests.
+ *
+ */
+public class MonitoringRestTest {
+
+ @Test
+ public void test() {
+ PdpMonitoringServerParameters parameters = new PdpMonitoringServerParameters();
+ parameters.setPort(12345);
+ assertEquals(12345, parameters.getPort());
+ }
+
+}