From f0d99cbc1c5969a6c51af5fe6dcfe546d3a6df66 Mon Sep 17 00:00:00 2001 From: bobbymander Date: Thu, 31 Oct 2019 15:08:36 -0400 Subject: More JUnit additions for PAP-REST Issue-ID: POLICY-2130 Change-Id: Ia64bdbb377d26ba209b2d3fc51bc95f5769a7729 Signed-off-by: bobbymander --- .../onap/policy/pap/xacml/rest/HeartbeatTest.java | 41 ++++++++++++++ .../policy/pap/xacml/rest/UpdatePdpThreadTest.java | 58 +++++++++++++++++++ .../xacml/rest/components/NotifyOtherPapsTest.java | 66 ++++++++++++++++++++++ .../pap/xacml/rest/service/ImportServiceTest.java | 39 ++++++++++++- 4 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/HeartbeatTest.java create mode 100644 ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/UpdatePdpThreadTest.java create mode 100644 ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPapsTest.java (limited to 'ONAP-PAP-REST/src/test') diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/HeartbeatTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/HeartbeatTest.java new file mode 100644 index 000000000..13fb81d17 --- /dev/null +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/HeartbeatTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP-PAP-REST + * ================================================================================ + * Copyright (C) 2019 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; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import com.att.research.xacml.api.pap.PAPException; +import java.io.IOException; +import org.junit.Test; + +public class HeartbeatTest { + @Test + public void testHeartbeat() throws IOException, PAPException { + Heartbeat hb = new Heartbeat(null); + + assertThatThrownBy(hb::run).isInstanceOf(NullPointerException.class); + assertTrue(hb.isHeartBeatRunning()); + hb.terminate(); + assertFalse(hb.isHeartBeatRunning()); + } +} diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/UpdatePdpThreadTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/UpdatePdpThreadTest.java new file mode 100644 index 000000000..9034f393b --- /dev/null +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/UpdatePdpThreadTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP-PAP-REST + * ================================================================================ + * Copyright (C) 2019 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; + +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import org.junit.Test; +import org.onap.policy.common.logging.OnapLoggingContext; +import org.onap.policy.xacml.api.pap.OnapPDP; +import org.onap.policy.xacml.std.pap.StdPDP; + +public class UpdatePdpThreadTest { + @Test + public void testConstructor1() { + UpdatePdpThread thread = new UpdatePdpThread(null, null); + assertNotNull(thread); + } + + @Test + public void testConstructor2() { + OnapLoggingContext loggingContext = new OnapLoggingContext(); + loggingContext.setRequestId("id"); + UpdatePdpThread thread = new UpdatePdpThread(null, loggingContext, null); + assertNotNull(thread); + } + + @Test + public void testRun() { + OnapPDP pdp = new StdPDP("http://id", 0); + OnapLoggingContext loggingContext = new OnapLoggingContext(); + loggingContext.setRequestId("id"); + List properties = new ArrayList(); + UpdatePdpThread thread = new UpdatePdpThread(pdp, loggingContext, properties); + assertThatCode(thread::run).doesNotThrowAnyException(); + } +} diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPapsTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPapsTest.java new file mode 100644 index 000000000..50c166aed --- /dev/null +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/NotifyOtherPapsTest.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP-PAP-REST + * ================================================================================ + * Copyright (C) 2018-2019 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.components; + +import static org.assertj.core.api.Assertions.assertThatCode; + +import com.att.research.xacml.util.XACMLProperties; +import java.util.ArrayList; +import java.util.List; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.rest.jpa.PolicyDBDaoEntity; + +public class NotifyOtherPapsTest { + private static final String systemKey = XACMLProperties.XACML_PROPERTIES_NAME; + private static final String oldProperty = System.getProperty(systemKey); + + @Before + public void setup() { + // Set the system property temporarily + System.setProperty(systemKey, "xacml.pap.properties"); + } + + @Test + public void negTestNotify() { + NotifyOtherPaps notify = new NotifyOtherPaps(); + List otherServers = new ArrayList(); + PolicyDBDaoEntity dbdaoEntity = new PolicyDBDaoEntity(); + dbdaoEntity.setPolicyDBDaoUrl("http://test"); + otherServers.add(dbdaoEntity); + long entityId = 0; + String entityType = "entityType"; + String newGroupId = "newGroupId"; + assertThatCode(() -> notify.startNotifyThreads(otherServers, entityId, entityType, newGroupId)) + .doesNotThrowAnyException(); + } + + @After + public void cleanup() { + // Restore the original system property + if (oldProperty != null) { + System.setProperty(systemKey, oldProperty); + } else { + System.clearProperty(systemKey); + } + } +} diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java index 72d492620..3b826f694 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/service/ImportServiceTest.java @@ -20,14 +20,14 @@ package org.onap.policy.pap.xacml.rest.service; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.MockHttpServletResponse; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.junit.Test; public class ImportServiceTest { @@ -39,4 +39,39 @@ public class ImportServiceTest { service.doImportMicroServicePut(request, response); assertEquals(response.getHeader("error"), "missing"); } + + @Test + public void testImportBRMS() { + ImportService service = new ImportService(); + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setupAddParameter("serviceName", "serviceName"); + request.setupAddParameter("importService", "BRMSPARAM"); + request.setBodyContent("foo"); + HttpServletResponse response = new MockHttpServletResponse(); + assertThatCode(() -> service.doImportMicroServicePut(request, response)).doesNotThrowAnyException(); + } + + @Test + public void testImportMS() { + ImportService service = new ImportService(); + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setupAddParameter("serviceName", "serviceName"); + request.setupAddParameter("importService", "MICROSERVICE"); + request.setupAddParameter("fileName", "fileName"); + request.setBodyContent("foo"); + HttpServletResponse response = new MockHttpServletResponse(); + assertThatThrownBy(() -> service.doImportMicroServicePut(request, response)).isInstanceOf(Exception.class); + } + + @Test + public void testImportOpt() { + ImportService service = new ImportService(); + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setupAddParameter("serviceName", "serviceName"); + request.setupAddParameter("importService", "OPTIMIZATION"); + request.setupAddParameter("fileName", "fileName"); + request.setBodyContent("foo"); + HttpServletResponse response = new MockHttpServletResponse(); + assertThatThrownBy(() -> service.doImportMicroServicePut(request, response)).isInstanceOf(Exception.class); + } } -- cgit 1.2.3-korg