diff options
author | ITSERVICES\rb7147 <rb7147@att.com> | 2017-04-25 11:46:00 -0400 |
---|---|---|
committer | ITSERVICES\rb7147 <rb7147@att.com> | 2017-05-03 09:58:17 -0400 |
commit | e0addf5b588a1244f9679becd90999dfcb4c3a94 (patch) | |
tree | 1212772d6366730266ff0e093c874b07aa716c29 /ECOMP-PDP-REST/src/test | |
parent | 39fb0f30472777e4b60d6a7ac8aa4eb9773961ff (diff) |
Policy 1707 commit to LF
Change-Id: Ibe6f01d92f9a434c040abb05d5386e89d675ae65
Signed-off-by: ITSERVICES\rb7147 <rb7147@att.com>
Diffstat (limited to 'ECOMP-PDP-REST/src/test')
-rw-r--r-- | ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/PapUrlResolverTest.java | 137 | ||||
-rw-r--r-- | ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/XACMLPdpServletTest.java | 76 |
2 files changed, 26 insertions, 187 deletions
diff --git a/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/PapUrlResolverTest.java b/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/PapUrlResolverTest.java index 7a8060114..1811d8912 100644 --- a/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/PapUrlResolverTest.java +++ b/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/PapUrlResolverTest.java @@ -19,24 +19,20 @@ */ package org.openecomp.policy.pdp.rest; -import org.junit.Before; -import org.junit.Test; -import org.openecomp.policy.pdp.rest.PapUrlResolver; -import org.openecomp.policy.rest.XACMLRestProperties; - import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Properties; import org.junit.Assert; +import org.junit.Test; +import org.openecomp.policy.rest.XACMLRestProperties; public class PapUrlResolverTest { @Test public void testPropertyModifications(){ - long currentTime = new Date().getTime(); DateFormat df = new SimpleDateFormat(); //first sort order String urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; @@ -104,20 +100,8 @@ public class PapUrlResolverTest { prop = rs.getProperties(); succeeded = prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); - System.out.println(succeeded); - //can't test this in a timely manner since it will need to wait a minute, since they all succeeded at the same time - /* - prop = rs.getProperties(); - failed = prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS); - succeeded = prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); - rs = PapUrlResolver.getInstance(urls, failed, succeeded); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://two.localhost.com", rs.getUrl()); - rs.succeeded(); - rs.getNext(); - Assert.assertFalse(rs.hasMoreUrls()); - */ } + @SuppressWarnings("unused") @Test public void testModifyUrl(){ String newUrl = PapUrlResolver.modifyUrl("http://mypap1.com/pap?id=987654", "http://mypap2.com:45/pap/"); @@ -236,120 +220,5 @@ public class PapUrlResolverTest { Assert.assertEquals("http://four.localhost.com", rs.getUrl()); rs.getNext(); Assert.assertFalse(rs.hasMoreUrls()); - - - - - //not used because we are no longer sorting based on success time, only failed time. Modified above. - /* - //first sort order - String urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; - String failed = df.format(new Date(currentTime-3600000))+",-1,-1,"+df.format(new Date(currentTime-3200000)); - String succeeded = "-1,8/13/15 5:41 PM,8/13/15 4:41 PM,-1"; - PapUrlResolver rs = PapUrlResolver.getInstance(urls, failed, succeeded); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://three.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://two.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://one.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://four.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertFalse(rs.hasMoreUrls()); - - urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; - failed = "-1,-1,-1,-1"; - succeeded = "-1,"+df.format(new Date(currentTime-3600000))+","+df.format(new Date(currentTime-6600000))+",-1"; - rs = PapUrlResolver.getInstance(urls, failed, succeeded); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://one.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://four.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://three.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://two.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertFalse(rs.hasMoreUrls()); - - urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; - failed = "-1,-1,-1,-1"; - succeeded = "-1,-1,-1,-1"; - rs = PapUrlResolver.getInstance(urls, failed, succeeded); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://one.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://two.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://three.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://four.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertFalse(rs.hasMoreUrls()); - - urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; - failed = df.format(new Date(currentTime-3900000))+","+df.format(new Date(currentTime-5600000))+","+df.format(new Date(currentTime-4600000))+","+df.format(new Date(currentTime-3600000)); - succeeded = "-1,-1,-1,-1"; - rs = PapUrlResolver.getInstance(urls, failed, succeeded); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://two.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://three.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://one.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://four.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertFalse(rs.hasMoreUrls()); - - urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; - failed = df.format(new Date(currentTime-(3600000*4)))+",-1,-1,-1"; - succeeded = "-1,-1,-1,-1"; - rs = PapUrlResolver.getInstance(urls, failed, succeeded); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://two.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://three.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://four.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://one.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertFalse(rs.hasMoreUrls()); - - urls = "http://one.localhost.com,http://two.localhost.com,http://three.localhost.com,http://four.localhost.com"; - failed = df.format(new Date(currentTime-(3600000*6)))+",-1,-1,-1"; - succeeded = "-1,-1,-1,-1"; - rs = PapUrlResolver.getInstance(urls, failed, succeeded); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://one.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://two.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://three.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertTrue(rs.hasMoreUrls()); - Assert.assertEquals("http://four.localhost.com", rs.getUrl()); - rs.getNext(); - Assert.assertFalse(rs.hasMoreUrls()); - */ } } diff --git a/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/XACMLPdpServletTest.java b/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/XACMLPdpServletTest.java index 95cb0293c..808f421ff 100644 --- a/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/XACMLPdpServletTest.java +++ b/ECOMP-PDP-REST/src/test/java/org/openecomp/policy/pdp/rest/XACMLPdpServletTest.java @@ -21,7 +21,6 @@ package org.openecomp.policy.pdp.rest; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -36,31 +35,26 @@ import javax.servlet.http.HttpServletResponse; import junit.framework.TestCase; -import org.apache.commons.lang.math.RandomUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.junit.Before; import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.openecomp.policy.pdp.rest.XACMLPdpServlet; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.mock.web.MockServletConfig; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - import org.openecomp.policy.common.im.AdministrativeStateException; import org.openecomp.policy.common.im.IntegrityMonitor; import org.openecomp.policy.common.im.StandbyStatusException; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockServletConfig; -import com.att.research.xacml.util.XACMLProperties; import com.mockrunner.mock.web.MockServletInputStream; -import org.openecomp.policy.common.logging.flexlogger.*; @RunWith(PowerMockRunner.class) @PrepareForTest(IntegrityMonitor.class) // so PowerMock can mock static method of IntegrityMonitor public class XACMLPdpServletTest extends TestCase{ - private static Logger logger = FlexLogger.getLogger(XACMLPdpServletTest.class); + private static Logger LOGGER = FlexLogger.getLogger(XACMLPdpServletTest.class); private List<String> headers = new ArrayList<String>(); @@ -89,14 +83,10 @@ public class XACMLPdpServletTest extends TestCase{ try { Mockito.when(httpServletResponse.getOutputStream()).thenReturn(mockOutput); } catch (IOException e) { - // TODO Auto-generated catch block fail(); } - - //when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); servletConfig = Mockito.mock(MockServletConfig.class); - //Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); //servletConfig Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); pdpServlet = new XACMLPdpServlet(); @@ -120,7 +110,6 @@ public class XACMLPdpServletTest extends TestCase{ // when IntegrityMonitor.getInstance is called, return the mock object PowerMockito.when(IntegrityMonitor.getInstance(Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(im); } catch (Exception e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } @@ -133,13 +122,11 @@ public class XACMLPdpServletTest extends TestCase{ } public void testInit(){ - logger.info("XACMLPdpServletTest - testInit"); + LOGGER.info("XACMLPdpServletTest - testInit"); try { pdpServlet.init(servletConfig); assertTrue(true); } catch (Exception e) { - // TODO Auto-generated catch block - System.out.println("Unexpected exception in testInit"); e.printStackTrace(); fail(); @@ -148,7 +135,7 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoGetNoTypeError(){ - logger.info("XACMLPdpServletTest - testDoGetNoTypeError"); + LOGGER.info("XACMLPdpServletTest - testDoGetNoTypeError"); try{ pdpServlet.init(servletConfig); pdpServlet.doGet(httpServletRequest, httpServletResponse); @@ -162,14 +149,13 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoGetConfigType(){ - logger.info("XACMLPdpServletTest - testDoGetConfigType"); + LOGGER.info("XACMLPdpServletTest - testDoGetConfigType"); Mockito.when(httpServletRequest.getParameter("type")).thenReturn("config"); try{ pdpServlet.init(servletConfig); pdpServlet.doGet(httpServletRequest, httpServletResponse); Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); - //Mockito.verify(httpServletResponse).sendError(400, "Failed to copy Property file"); assertTrue(true); }catch (Exception e){ System.out.println("Unexpected exception in testDoGetConfigType"); @@ -181,7 +167,7 @@ public class XACMLPdpServletTest extends TestCase{ public void testDoGetTypeHb(){ - logger.info("XACMLPdpServletTest - testDoGetTypeHb"); + LOGGER.info("XACMLPdpServletTest - testDoGetTypeHb"); try{ Mockito.when(httpServletRequest.getParameter("type")).thenReturn("hb"); pdpServlet.init(servletConfig); @@ -195,7 +181,7 @@ public class XACMLPdpServletTest extends TestCase{ } } public void testDoGetTypeStatus(){ - logger.info("XACMLPdpServletTest - testDoGetTypeStatus"); + LOGGER.info("XACMLPdpServletTest - testDoGetTypeStatus"); try{ Mockito.when(httpServletRequest.getParameter("type")).thenReturn("Status"); pdpServlet.init(servletConfig); @@ -210,12 +196,10 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoPost(){ - logger.info("XACMLPdpServletTest - testDoPost"); + LOGGER.info("XACMLPdpServletTest - testDoPost"); try{ pdpServlet.init(servletConfig); pdpServlet.doPost(httpServletRequest, httpServletResponse); - //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); - //Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); assertTrue(true); }catch (Exception e){ System.out.println("Unexpected exception in testDoPost"); @@ -225,15 +209,13 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoPostToLong(){ - logger.info("XACMLPdpServletTest - testDoPostToLong"); + LOGGER.info("XACMLPdpServletTest - testDoPostToLong"); try{ Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff"); Mockito.when(httpServletRequest.getContentLength()).thenReturn(32768); pdpServlet.init(servletConfig); pdpServlet.doPost(httpServletRequest, httpServletResponse); - //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); - //Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Content-Length larger than server will accept."); assertTrue(true); }catch (Exception e){ System.out.println("Unexpected exception in testDoPostToLong"); @@ -243,15 +225,13 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoPostContentLengthNegative(){ - logger.info("XACMLPdpServletTest - testDoPostToLong"); + LOGGER.info("XACMLPdpServletTest - testDoPostToLong"); try{ Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff"); Mockito.when(httpServletRequest.getContentLength()).thenReturn(-1); pdpServlet.init(servletConfig); pdpServlet.doPost(httpServletRequest, httpServletResponse); - //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); - //Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Content-Length is negative"); assertTrue(true); }catch (Exception e){ System.out.println("Unexpected exception in testDoPostContentLengthNegative"); @@ -261,15 +241,13 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoPostContentTypeNonValid(){ - logger.info("XACMLPdpServletTest - testDoPostToLong"); + LOGGER.info("XACMLPdpServletTest - testDoPostToLong"); try{ Mockito.when(httpServletRequest.getContentType()).thenReturn(";"); Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768); pdpServlet.init(servletConfig); pdpServlet.doPost(httpServletRequest, httpServletResponse); - //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); - //Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Parsing Content-Type: ;, error=Invalid content type: ;"); assertTrue(true); }catch (Exception e){ System.out.println("Unexpected exception in testDoPostContentTypeNonValid"); @@ -279,15 +257,13 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoPostContentTypeConfigurationError(){ - logger.info("XACMLPdpServletTest - testDoPostToLong"); + LOGGER.info("XACMLPdpServletTest - testDoPostToLong"); try{ Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff"); Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768); pdpServlet.init(servletConfig); pdpServlet.doPost(httpServletRequest, httpServletResponse); - //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); - //Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "unsupported content typestuff"); assertTrue(true); }catch (Exception e){ System.out.println("Unexpected exception in testDoPostContentTypeConfigurationError"); @@ -297,7 +273,7 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoPutCacheEmpty(){ - logger.info("XACMLPdpServletTest - testDoPutCacheEmpty"); + LOGGER.info("XACMLPdpServletTest - testDoPutCacheEmpty"); mockInput = Mockito.mock(ServletInputStream.class); try{ @@ -316,7 +292,7 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoPutConfigPolicies(){ - logger.info("XACMLPdpServletTest - testDoPutConfigPolicies"); + LOGGER.info("XACMLPdpServletTest - testDoPutConfigPolicies"); byte[] b = new byte[20]; new Random().nextBytes(b); @@ -328,10 +304,6 @@ public class XACMLPdpServletTest extends TestCase{ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); pdpServlet.init(servletConfig); pdpServlet.doPut(httpServletRequest, httpServletResponse); - /* - * Started failing 8/17/16 - * Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Missing property: xacml.rootPolicies"); - */ assertTrue(true); }catch (Exception e){ System.out.println("Unexpected exception in testDoPutConfigPolicies"); @@ -341,7 +313,7 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoPutToLong(){ - logger.info("XACMLPdpServletTest - testDoPutToLong"); + LOGGER.info("XACMLPdpServletTest - testDoPutToLong"); try{ Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies"); @@ -350,7 +322,6 @@ public class XACMLPdpServletTest extends TestCase{ pdpServlet.init(servletConfig); pdpServlet.doPut(httpServletRequest, httpServletResponse); - //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Content-Length larger than server will accept."); assertTrue(true); }catch (Exception e){ @@ -361,7 +332,7 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDoPutInvalidContentType(){ - logger.info("XACMLPdpServletTest - testDoPutToLong"); + LOGGER.info("XACMLPdpServletTest - testDoPutToLong"); try{ Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies"); @@ -370,7 +341,6 @@ public class XACMLPdpServletTest extends TestCase{ pdpServlet.init(servletConfig); pdpServlet.doPut(httpServletRequest, httpServletResponse); - //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "no content-type given"); Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid cache: 'policies' or content-type: 'text/json'"); assertTrue(true); }catch (Exception e){ @@ -381,7 +351,7 @@ public class XACMLPdpServletTest extends TestCase{ } public void testDestroy(){ - logger.info("XACMLPdpServletTest - testDestroy"); + LOGGER.info("XACMLPdpServletTest - testDestroy"); try{ pdpServlet.init(servletConfig); |