- @Test
- public void testInit(){
- LOGGER.info("XACMLPdpServletTest - testInit");
- try {
- pdpServlet.init(servletConfig);
-
- assertTrue(true);
- } catch (Exception e) {
- LOGGER.error("Exception Occured"+e);
- fail();
-
- }
-
- }
-
- @Test
- public void testUebNotification() {
- System.out.println("drewtest1");
- LOGGER.info("XACMLPdpServletTest - drewTest1");
- try {
-
- XACMLProperties.reloadProperties();
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pdp.ueb.properties");
- XACMLProperties.getProperties();
- XACMLProperties.setProperty(XACMLRestProperties.PROP_NOTIFICATION_TYPE, "ueb");
-
- pdpServlet.init(servletConfig);
-
- status.setStatus(com.att.research.xacml.api.pap.PDPStatus.Status.UPDATING_CONFIGURATION);
-
- XACMLPdpLoader.validatePolicies(properties, status);
- XACMLPdpLoader.sendNotification();
- assertTrue(true);
- } catch (Exception e) {
- LOGGER.error("Exception Occured"+e);
- fail();
-
- }
-
- }
-
- @Test
- public void testDmaapNotification() {
- System.out.println("drewtest2");
- LOGGER.info("XACMLPdpServletTest - drewTest2");
- try {
-
- XACMLProperties.reloadProperties();
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pdp.dmaap.properties");
- XACMLProperties.getProperties();
- XACMLProperties.setProperty(XACMLRestProperties.PROP_NOTIFICATION_TYPE, "dmaap");
-
- pdpServlet.init(servletConfig);
-
- status.setStatus(com.att.research.xacml.api.pap.PDPStatus.Status.UPDATING_CONFIGURATION);
-
- XACMLPdpLoader.validatePolicies(properties, status);
- XACMLPdpLoader.sendNotification();
- assertTrue(true);
- } catch (Exception e) {
- LOGGER.error("Exception Occured"+e);
- fail();
-
- }
-
- }
-
-
- @Test
- public void testDoGetNoTypeError(){
- LOGGER.info("XACMLPdpServletTest - testDoGetNoTypeError");
- try{
-
- pdpServlet.init(servletConfig);
- pdpServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- assertTrue(true);
- }catch(Exception e){
- System.out.println("Unexpected exception in testDoGetNoTypeError");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void 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);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoGetConfigType");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
-
- }
-
- @Test
- public void testDoGetTypeHb(){
- LOGGER.info("XACMLPdpServletTest - testDoGetTypeHb");
- try{
- Mockito.when(httpServletRequest.getParameter("type")).thenReturn("hb");
- pdpServlet.init(servletConfig);
- pdpServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- assertTrue(true);
- }catch(Exception e){
- System.out.println("Unexpected exception in testDoGetTypeHb");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoGetTypeStatus(){
- LOGGER.info("XACMLPdpServletTest - testDoGetTypeStatus");
- try{
- Mockito.when(httpServletRequest.getParameter("type")).thenReturn("Status");
- pdpServlet.init(servletConfig);
- pdpServlet.doGet(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK);
- assertTrue(true);
- }catch(Exception e){
- System.out.println("Unexpected exception in testDoGetTypeStatus");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPost(){
- LOGGER.info("XACMLPdpServletTest - testDoPost");
- try{
- pdpServlet.init(servletConfig);
- pdpServlet.doPost(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPost");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void 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);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPostToLong");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPostContentLengthNegative(){
- LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
- try{
- Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(-1);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPost(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPostContentLengthNegative");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPostContentTypeNonValid(){
- LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
- try{
- Mockito.when(httpServletRequest.getContentType()).thenReturn(";");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPost(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPostContentTypeNonValid");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPostContentTypeConfigurationError(){
- LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
- try{
- Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPost(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPostContentTypeConfigurationError");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPutCacheEmpty(){
- LOGGER.info("XACMLPdpServletTest - testDoPutCacheEmpty");
- mockInput = Mockito.mock(ServletInputStream.class);
-
- try{
- Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("cache");
- Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
- Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
- pdpServlet.init(servletConfig);
- pdpServlet.doPut(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT must contain at least one property");
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPutCacheEmpty");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPutConfigPolicies(){
- LOGGER.info("XACMLPdpServletTest - testDoPutConfigPolicies");
- byte[] b = new byte[20];
- new Random().nextBytes(b);
-
- mockInput = new MockServletInputStream(b);
-
- try{
- Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
- Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
- Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
- pdpServlet.init(servletConfig);
- pdpServlet.doPut(httpServletRequest, httpServletResponse);
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPutConfigPolicies");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- public void testDoPutToLong(){
- LOGGER.info("XACMLPdpServletTest - testDoPutToLong");
- try{
- Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
-
- Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(1000000000);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPut(httpServletRequest, httpServletResponse);
- 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 testDoPutToLong");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDoPutInvalidContentType(){
- LOGGER.info("XACMLPdpServletTest - testDoPutToLong");
- try{
- Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
-
- Mockito.when(httpServletRequest.getContentType()).thenReturn("text/json");
- Mockito.when(httpServletRequest.getContentLength()).thenReturn(32768);
-
- pdpServlet.init(servletConfig);
- pdpServlet.doPut(httpServletRequest, httpServletResponse);
- Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid cache: 'policies' or content-type: 'text/json'");
- assertTrue(true);
- }catch (Exception e){
- System.out.println("Unexpected exception in testDoPutInvalidContentType");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
-
- @Test
- public void testDestroy(){
- LOGGER.info("XACMLPdpServletTest - testDestroy");
-
- try{
- pdpServlet.init(servletConfig);
- pdpServlet.destroy();
- }catch(Exception e){
- System.out.println("Unexpected exception in testDestroy");
- LOGGER.error("Exception Occured"+e);
- fail();
- }
- }
+ @Test
+ public void testDoPostContentTypeConfigurationError() {
+ LOGGER.info("XACMLPdpServletTest - testDoPostToLong");
+ try {
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("stuff");
+ Mockito.when(httpServletRequest.getContentLength()).thenReturn(30768);
+
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPost(httpServletRequest, httpServletResponse);
+ assertTrue(true);
+ } catch (Exception e) {
+ LOGGER.error(ERROR_TEXT + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPutCacheEmpty() {
+ LOGGER.info("XACMLPdpServletTest - testDoPutCacheEmpty");
+ mockInput = Mockito.mock(ServletInputStream.class);
+
+ try {
+ Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("cache");
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPut(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST,
+ "PUT must contain at least one property");
+ assertTrue(true);
+ } catch (Exception e) {
+ LOGGER.error(ERROR_TEXT + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPutConfigPolicies() {
+ LOGGER.info("XACMLPdpServletTest - testDoPutConfigPolicies");
+ byte[] b = new byte[20];
+ new Random().nextBytes(b);
+
+ mockInput = new MockServletInputStream(b);
+
+ try {
+ Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
+ Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput);
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPut(httpServletRequest, httpServletResponse);
+ assertTrue(true);
+ } catch (Exception e) {
+ LOGGER.error(ERROR_TEXT + e);
+ fail();
+ }
+ }
+
+ public void testDoPutToLong() {
+ LOGGER.info("XACMLPdpServletTest - testDoPutToLong");
+ try {
+ Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
+
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("text/x-java-properties");
+ Mockito.when(httpServletRequest.getContentLength()).thenReturn(1000000000);
+
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPut(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST,
+ "Content-Length larger than server will accept.");
+ assertTrue(true);
+ } catch (Exception e) {
+ LOGGER.error(ERROR_TEXT + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDoPutInvalidContentType() {
+ LOGGER.info("XACMLPdpServletTest - testDoPutToLong");
+ try {
+ Mockito.when(httpServletRequest.getParameter("cache")).thenReturn("policies");
+
+ Mockito.when(httpServletRequest.getContentType()).thenReturn("text/json");
+ Mockito.when(httpServletRequest.getContentLength()).thenReturn(32768);
+
+ pdpServlet.init(servletConfig);
+ pdpServlet.doPut(httpServletRequest, httpServletResponse);
+ Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST,
+ "Invalid cache: 'policies' or content-type: 'text/json'");
+ assertTrue(true);
+ } catch (Exception e) {
+ LOGGER.error(ERROR_TEXT + e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testDestroy() {
+ LOGGER.info("XACMLPdpServletTest - testDestroy");
+
+ try {
+ pdpServlet.init(servletConfig);
+ pdpServlet.destroy();
+ } catch (Exception e) {
+ LOGGER.error(ERROR_TEXT + e);
+ fail();
+ }
+ }