2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.analytics.system.fusion.controller;
40 import static org.junit.Assert.assertNull;
41 import static org.mockito.Mockito.mock;
42 import static org.mockito.Mockito.when;
44 import java.util.ArrayList;
45 import java.util.List;
47 import javax.servlet.ServletOutputStream;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
51 import org.junit.Before;
52 import org.junit.Test;
53 import org.junit.runner.RunWith;
54 import org.mockito.InjectMocks;
55 import org.mockito.Matchers;
56 import org.mockito.Mock;
57 import org.mockito.MockitoAnnotations;
58 import org.onap.portalsdk.analytics.util.XSSFilter;
59 import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite;
60 import org.onap.portalsdk.core.service.DataAccessService;
61 import org.owasp.esapi.ESAPI;
62 import org.owasp.esapi.Encoder;
63 import org.powermock.api.mockito.PowerMockito;
64 import org.powermock.core.classloader.annotations.PrepareForTest;
65 import org.powermock.modules.junit4.PowerMockRunner;
67 @RunWith(PowerMockRunner.class)
68 @PrepareForTest({ ESAPI.class, XSSFilter.class})
69 public class FileServletControllerTest {
72 FileServletController fileServletController = new FileServletController();
76 MockitoAnnotations.initMocks(this);
80 DataAccessService dataAccessService;
82 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
83 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
84 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
87 public void handleRequestInternalTest() throws Exception {
88 List<Object> objs = new ArrayList<>();
89 byte [] byteVal = "test123".getBytes();
91 PowerMockito.mockStatic(ESAPI.class);
92 Encoder encoder = PowerMockito.mock(Encoder.class);
93 when(ESAPI.encoder()).thenReturn(encoder);
94 when(encoder.canonicalize(Matchers.anyString())).thenReturn("test");
95 when(mockedRequest.getParameter(Matchers.anyString())).thenReturn("test");
96 ServletOutputStream sos = mock(ServletOutputStream.class);
97 when(mockedResponse.getOutputStream()).thenReturn(sos);
98 when(fileServletController.getDataAccessService().executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap())).thenReturn(objs);
99 assertNull(fileServletController.handleRequestInternal(mockedRequest, mockedResponse));