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.rnotebookintegration.controller;
40 import static org.junit.Assert.assertEquals;
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
45 import org.hibernate.SessionFactory;
46 import org.junit.Assert;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.junit.runner.RunWith;
50 import org.mockito.InjectMocks;
51 import org.mockito.Mock;
52 import org.mockito.Mockito;
53 import org.mockito.MockitoAnnotations;
54 import org.onap.portalapp.framework.MockitoTestSuite;
55 import org.onap.portalsdk.core.domain.User;
56 import org.onap.portalsdk.core.restful.domain.EcompUser;
57 import org.onap.portalsdk.core.service.DataAccessService;
58 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
59 import org.onap.portalsdk.core.util.SystemProperties;
60 import org.onap.portalsdk.core.web.support.UserUtils;
61 import org.onap.portalsdk.rnotebookintegration.exception.RNotebookIntegrationException;
62 import org.onap.portalsdk.rnotebookintegration.service.RNoteBookIntegrationService;
63 import org.powermock.api.mockito.PowerMockito;
64 import org.powermock.core.classloader.annotations.PrepareForTest;
65 import org.powermock.modules.junit4.PowerMockRunner;
66 import org.springframework.mock.web.MockHttpServletResponse;
68 @RunWith(PowerMockRunner.class)
69 @PrepareForTest({UserUtils.class, SystemProperties.class})
70 public class RNoteBookFEControllerTest {
73 RNoteBookFEController rNoteBookFEController = new RNoteBookFEController();
76 private RNoteBookIntegrationService rNoteBookIntegrationService;
79 private SessionFactory sessionFactory;
81 private DataAccessServiceImpl dataAccessServiceImpl;
84 private DataAccessService dataAccessService;
88 MockitoAnnotations.initMocks(this);
91 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
93 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
94 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
96 NullPointerException nullPointerException = new NullPointerException();
98 User user = new User();
101 UserUtils userUtils = new UserUtils();
104 public void getrNoteBookIntegrationServiceTest() {
105 RNoteBookIntegrationService actualRNoteBookIntegrationService = rNoteBookIntegrationService;
106 RNoteBookIntegrationService expectedRNoteBookIntegrationService = rNoteBookFEController
107 .getrNoteBookIntegrationService();
108 rNoteBookFEController.setrNoteBookIntegrationService(null);
109 assertEquals(actualRNoteBookIntegrationService, expectedRNoteBookIntegrationService);
113 public void saveRNotebookCredentialsExceptionTest() {
115 String notebookId = "123";
116 HttpServletRequest request = PowerMockito.mock(HttpServletRequest.class);
117 String value = " { \"key\" : \"value\" }" ;
119 Mockito.when(request.getParameter("qparams")).thenReturn(value);
121 HttpServletResponse response = new MockHttpServletResponse();
123 PowerMockito.mockStatic(UserUtils.class);
124 User user = new User();
125 Mockito.when(UserUtils.getUserSession(request)).thenReturn(user);
126 Mockito.when(dataAccessService.getDomainObject(User.class, user.getId(), null)).thenReturn(user);
127 EcompUser ecUser = new EcompUser();
128 Mockito.when(UserUtils.convertToEcompUser(user)).thenReturn(ecUser);
130 PowerMockito.mockStatic(SystemProperties.class);
131 Mockito.when(SystemProperties.containsProperty(Mockito.anyString())).thenReturn(false);
133 rNoteBookFEController.saveRNotebookCredentials(notebookId, request, response);
134 Assert.assertTrue(true);
138 public void saveRNotebookCredentialsTest() {
140 String notebookId = "123";
141 HttpServletRequest request = PowerMockito.mock(HttpServletRequest.class);
142 String value = " { \"key\" : \"value\" }" ;
144 Mockito.when(request.getParameter("qparams")).thenReturn(value);
146 HttpServletResponse response = new MockHttpServletResponse();
148 PowerMockito.mockStatic(UserUtils.class);
149 User user = new User();
150 Mockito.when(UserUtils.getUserSession(request)).thenReturn(user);
151 Mockito.when(dataAccessService.getDomainObject(User.class, user.getId(), null)).thenReturn(user);
152 EcompUser ecUser = new EcompUser();
153 Mockito.when(UserUtils.convertToEcompUser(user)).thenReturn(ecUser);
155 PowerMockito.mockStatic(SystemProperties.class);
156 Mockito.when(SystemProperties.containsProperty(Mockito.anyString())).thenReturn(true);
158 rNoteBookFEController.saveRNotebookCredentials(notebookId, request, response);
159 Assert.assertTrue(true);
163 public void saveRNotebookCredentialsCustExceptionTest() {
165 String notebookId = "123";
166 HttpServletRequest request = PowerMockito.mock(HttpServletRequest.class);
167 String value = " { \"key\" : \"value\" }" ;
169 Mockito.when(request.getParameter("qparams")).thenReturn(value);
171 HttpServletResponse response = new MockHttpServletResponse();
173 PowerMockito.mockStatic(UserUtils.class);
174 User user = new User();
175 Mockito.when(UserUtils.getUserSession(request)).thenThrow(RNotebookIntegrationException.class);
176 Mockito.when(dataAccessService.getDomainObject(User.class, user.getId(), null)).thenReturn(user);
177 EcompUser ecUser = new EcompUser();
178 Mockito.when(UserUtils.convertToEcompUser(user)).thenReturn(ecUser);
180 PowerMockito.mockStatic(SystemProperties.class);
181 Mockito.when(SystemProperties.containsProperty(Mockito.anyString())).thenReturn(true);
183 rNoteBookFEController.saveRNotebookCredentials(notebookId, request, response);
184 Assert.assertTrue(true);