JUnit additions for PDP-REST,ONAP-SDK-APP
[policy/engine.git] / ONAP-SDK-APP / src / test / java / org / onap / portalapp / filter / SecurityXssFilterTest.java
1 /*-
2  * ================================================================================
3  * ONAP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20
21 package org.onap.portalapp.filter;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import java.io.IOException;
26 import javax.servlet.FilterChain;
27 import javax.servlet.ServletException;
28 import javax.servlet.http.HttpServletResponse;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import com.mockrunner.mock.web.MockHttpServletRequest;
32 import com.mockrunner.mock.web.MockHttpServletResponse;
33
34 public class SecurityXssFilterTest {
35         @Test
36         public void testGets() throws ServletException, IOException {
37                 SecurityXssFilter filter = new SecurityXssFilter();
38                 assertNotNull(filter);
39                 
40                 MockHttpServletRequest request = new MockHttpServletRequest();
41                 request.setMethod("POST");
42                 request.setBodyContent("testBody");
43                 request.setupAddParameter("testKey", "testVal");
44                 request.setAttribute("testKey", "testVal");
45                 request.setRequestURI("testVal");
46                 request.setRequestURL("testVal");
47                 MockHttpServletResponse response = new MockHttpServletResponse();
48                 FilterChain filterChain = Mockito.mock(FilterChain.class);
49                 filter.doFilterInternal(request, response, filterChain);
50                 assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
51         }
52 }