diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2019-08-23 12:55:45 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-08-23 12:55:45 +0000 |
commit | b2341e2ee94605af08728a38f835e9545ab60cac (patch) | |
tree | 8606acc976901748f310d1c8c2c8b98ab2cdc9a2 /POLICY-SDK-APP/src/test | |
parent | ca8e0c7e1182faf67a1049d521e3d5ac2c899cff (diff) | |
parent | 962dd9714c6d35cacdec0ee8e601431aa349001a (diff) |
Merge "Remove powermock to increase coverage"
Diffstat (limited to 'POLICY-SDK-APP/src/test')
-rw-r--r-- | POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java | 11 | ||||
-rw-r--r-- | POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java | 37 |
2 files changed, 33 insertions, 15 deletions
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java index 95296f4b0..e270583bb 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java @@ -29,6 +29,7 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import static org.mockito.Mockito.when; +import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.controller.PolicyController; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.PolicyVersion; @@ -46,11 +47,17 @@ public class PolicyNotificationMailTest { PolicyController.setjUnit(true); PolicyController.setSmtpApplicationName("Test"); PolicyController.setSmtpEmailExtension("test.com"); - PolicyController.setSmtpHost("test"); - PolicyController.setSmtpPort("23"); + PolicyController.setSmtpHost("localhost"); PolicyController.setSmtpPassword("test"); PolicyController.setSmtpUsername("test"); + /* + * Allocate a port to which the mail sender should connect, but don't actually + * start a listener on the port so that connection attempts will be immediately + * rejected. + */ + PolicyController.setSmtpPort(String.valueOf(NetworkUtil.allocPort())); + version = new PolicyVersion(); version.setPolicyName("com/Config_Test"); version.setModifiedBy("xyz"); diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java index 4b307f594..e8434d46d 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java @@ -23,28 +23,27 @@ package org.onap.policy.admin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; -import java.net.URL; -import javax.servlet.http.HttpServletResponse; import java.net.HttpURLConnection; +import java.net.URLConnection; +import javax.servlet.http.HttpServletResponse; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.mockito.Mockito; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.xacml.api.pap.OnapPDP; import org.onap.policy.xacml.api.pap.OnapPDPGroup; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import com.att.research.xacml.api.pap.PAPException; import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.util.XACMLProperties; -@RunWith(PowerMockRunner.class) -@PrepareForTest({URL.class, RESTfulPAPEngine.class}) public class RESTfulPAPEngineTest { @Rule public ExpectedException thrown = ExpectedException.none(); @@ -61,13 +60,20 @@ public class RESTfulPAPEngineTest { OnapPDP pdp = Mockito.mock(OnapPDP.class); InputStream policy; + @BeforeClass + public static void setUpBeforeClass() { + XACMLProperties.reloadProperties(); + } + + @AfterClass + public static void tearDownAfterClass() { + XACMLProperties.reloadProperties(); + } + @Before public void runConstructor() throws Exception { - // Mock url and connection - URL url = PowerMockito.mock(URL.class); - PowerMockito.whenNew(URL.class).withArguments(Mockito.any()).thenReturn(url); + // Mock connection HttpURLConnection connection = Mockito.mock(HttpURLConnection.class); - Mockito.when(url.openConnection()).thenReturn(connection); Mockito.when(connection.getResponseCode()).thenReturn(HttpServletResponse.SC_NO_CONTENT); // Set the system property temporarily @@ -77,7 +83,12 @@ public class RESTfulPAPEngineTest { // Test constructor String urlName = "localhost:1234"; - engine = new RESTfulPAPEngine(urlName); + engine = new RESTfulPAPEngine(urlName) { + @Override + protected URLConnection makeConnection(String fullURL) throws IOException { + return connection; + } + }; // Initialize policy policy = new ByteArrayInputStream(policyContent.getBytes("UTF-8")); |