491554d8f45da3ef01f57386d3c4fb0f9c636e08
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalsdk.analytics.system.fusion.web;
39
40 import static org.junit.Assert.*;
41
42 import java.io.IOException;
43
44 import javax.servlet.ServletContext;
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpServletResponse;
47
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;
63
64 @RunWith(PowerMockRunner.class)
65 @PrepareForTest(Globals.class)
66 public class RaptorControllerTest {
67
68         @InjectMocks
69         RaptorController raptorController = new RaptorController();
70
71         @Before
72         public void setup() {
73                 MockitoAnnotations.initMocks(this);
74         }
75
76         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
77         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
78         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
79
80         @Test
81         public void reportTest() {
82                 assertEquals(raptorController.report(mockedRequest).getViewName(), "report");
83         }
84
85         @Test
86         public void reportDS1Test() {
87                 assertEquals(raptorController.reportDS1(mockedRequest).getViewName(), "reportDS1");
88         }
89
90         @Test
91         public void reportEmbeddedTest() {
92                 assertEquals(raptorController.reportEmbedded(mockedRequest).getViewName(), "report_embedded");
93         }
94
95         @Test
96         public void reportSampleTest() {
97                 assertEquals(raptorController.reportSample(mockedRequest).getViewName(), "report_sample");
98         }
99
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");
109         }
110
111         @Test
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);
119
120                 Mockito.when(actionMapping.getAction(Matchers.anyString())).thenReturn(action);
121                 assertEquals(raptorController.reportImport(mockedRequest).getViewName(), "report_import");
122         }
123
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);
132         }
133
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);
144         }
145
146 }