diff options
author | bobbymander <bobby.mander@att.com> | 2019-10-31 15:08:36 -0400 |
---|---|---|
committer | bobbymander <bobby.mander@att.com> | 2019-11-05 09:21:05 -0500 |
commit | f0d99cbc1c5969a6c51af5fe6dcfe546d3a6df66 (patch) | |
tree | 148cd98a72baec013c8c62c95dbf48afb75d9e23 /ONAP-PAP-REST/src/test | |
parent | 46b5b531eada52e963f9ca196473a6c1bd8cbf37 (diff) |
More JUnit additions for PAP-REST
Issue-ID: POLICY-2130
Change-Id: Ia64bdbb377d26ba209b2d3fc51bc95f5769a7729
Signed-off-by: bobbymander <bobby.mander@att.com>
Diffstat (limited to 'ONAP-PAP-REST/src/test')
4 files changed, 202 insertions, 2 deletions
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> properties = new ArrayList<Properties>(); + 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<PolicyDBDaoEntity> otherServers = new ArrayList<PolicyDBDaoEntity>(); + 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); + } } |