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.web;
40 import static org.junit.Assert.*;
42 import java.io.IOException;
44 import javax.servlet.ServletContext;
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpServletResponse;
48 import org.junit.Before;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51 import org.onap.portalsdk.analytics.controller.ActionMapping;
52 import org.onap.portalsdk.analytics.system.Globals;
53 import org.mockito.InjectMocks;
54 import org.mockito.Matchers;
55 import org.mockito.Mockito;
56 import org.mockito.MockitoAnnotations;
57 import org.onap.portalsdk.analytics.util.AppConstants;
58 import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite;
59 import org.powermock.api.mockito.PowerMockito;
60 import org.powermock.core.classloader.annotations.PrepareForTest;
61 import org.powermock.modules.junit4.PowerMockRunner;
62 import org.onap.portalsdk.analytics.controller.Action;
64 @RunWith(PowerMockRunner.class)
65 @PrepareForTest(Globals.class)
66 public class RaptorControllerTest {
69 RaptorController raptorController = new RaptorController();
73 MockitoAnnotations.initMocks(this);
76 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
77 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
78 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
81 public void reportTest() {
82 assertEquals(raptorController.report(mockedRequest).getViewName(), "report");
86 public void reportDS1Test() {
87 assertEquals(raptorController.reportDS1(mockedRequest).getViewName(), "reportDS1");
91 public void reportEmbeddedTest() {
92 assertEquals(raptorController.reportEmbedded(mockedRequest).getViewName(), "report_embedded");
96 public void reportSampleTest() {
97 assertEquals(raptorController.reportSample(mockedRequest).getViewName(), "report_sample");
100 @Test(expected = java.lang.NullPointerException.class)
101 public void reportImportTest() throws Exception {
102 PowerMockito.mockStatic(Globals.class);
103 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
104 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
105 ActionMapping actionMapping = PowerMockito.mock(ActionMapping.class);
106 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
107 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(null);
108 assertEquals(raptorController.reportImport(mockedRequest).getViewName(), "report_sample");
112 public void reportImport1Test() throws Exception {
113 PowerMockito.mockStatic(Globals.class);
114 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
115 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
116 ActionMapping actionMapping = PowerMockito.mock(ActionMapping.class);
117 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
118 Action action = PowerMockito.mock(Action.class);
120 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(action);
121 assertEquals(raptorController.reportImport(mockedRequest).getViewName(), "report_import");
124 @Test(expected = java.lang.NullPointerException.class)
125 public void reportWizardExceptionTest() throws Exception {
126 PowerMockito.mockStatic(Globals.class);
127 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
128 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
129 ActionMapping actionMapping = PowerMockito.mock(ActionMapping.class);
130 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
131 raptorController.reportWizard(mockedRequest, mockedResponse);
134 @Test(expected = java.lang.NullPointerException.class)
135 public void reportWizardTest() throws Exception {
136 PowerMockito.mockStatic(Globals.class);
137 ServletContext servletContext = PowerMockito.mock(ServletContext.class);
138 Mockito.when(mockedRequest.getSession().getServletContext()).thenReturn(servletContext);
139 ActionMapping actionMapping = PowerMockito.mock(ActionMapping.class);
140 Mockito.when(Globals.getRaptorActionMapping()).thenReturn(actionMapping);
141 Action action = PowerMockito.mock(Action.class);
142 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(action);
143 raptorController.reportWizard(mockedRequest, mockedResponse);