2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
41 package org.onap.portal.controller;
43 import static junit.framework.TestCase.assertEquals;
44 import static junit.framework.TestCase.assertNull;
45 import static org.mockito.Mockito.when;
47 import java.time.LocalDateTime;
48 import java.util.ArrayList;
49 import java.util.List;
50 import javax.servlet.http.HttpServletRequest;
51 import javax.servlet.http.HttpServletResponse;
52 import org.junit.Test;
53 import org.junit.runner.RunWith;
54 import org.onap.portal.dao.fn.FnLanguageDao;
55 import org.onap.portal.dao.fn.FnUserDao;
56 import org.onap.portal.domain.db.fn.FnLanguage;
57 import org.onap.portal.domain.db.fn.FnUser;
58 import org.onap.portal.domain.dto.transport.OnboardingWidget;
59 import org.onap.portal.framework.MockitoTestSuite;
60 import org.springframework.beans.factory.annotation.Autowired;
61 import org.springframework.boot.test.context.SpringBootTest;
62 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
63 import org.springframework.security.core.userdetails.UsernameNotFoundException;
64 import org.springframework.test.context.TestPropertySource;
65 import org.springframework.test.context.junit4.SpringRunner;
67 @RunWith(SpringRunner.class)
69 @TestPropertySource(locations = "classpath:test.properties")
70 public class WidgetsControllerTest {
72 private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo",
75 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
77 HttpServletRequest request = mockitoTestSuite.getMockedRequest();
78 HttpServletResponse response = mockitoTestSuite.getMockedResponse();
81 private WidgetsController widgetsController;
87 FnLanguageDao fnLanguageDao;
89 private FnLanguage language = getFnLanguage();
90 private FnUser questUser = getQuestUser();
91 private FnUser notQuestUser = getNotQuestUser();
93 @Test(expected = UsernameNotFoundException.class)
94 public void getOnboardingWidgetsNullUserTest() {
95 UsernamePasswordAuthenticationToken nullPrincipal = new UsernamePasswordAuthenticationToken("nulluser",
97 widgetsController.getOnboardingWidgets(nullPrincipal, request, response);
101 public void getOnboardingWidgetsQuestUserTest() {
102 UsernamePasswordAuthenticationToken questPrincipal = new UsernamePasswordAuthenticationToken("questUser",
104 fnUserDao.save(questUser);
105 List<OnboardingWidget> onboardingWidgets = widgetsController
106 .getOnboardingWidgets(questPrincipal, request, response);
107 assertNull(onboardingWidgets);
110 fnUserDao.delete(questUser);
111 fnLanguageDao.delete(language);
115 public void getOnboardingWidgetsUserTest() {
116 UsernamePasswordAuthenticationToken notQuestprincipal = new UsernamePasswordAuthenticationToken("notQuestUser",
118 fnUserDao.save(notQuestUser);
119 List<OnboardingWidget> expected = new ArrayList<>();
120 when(request.getHeader("X-Widgets-Type")).thenReturn("managed");
122 List<OnboardingWidget> actual = widgetsController
123 .getOnboardingWidgets(notQuestprincipal, request, response);
125 assertEquals(expected, actual);
126 fnUserDao.delete(notQuestUser);
130 public void getOnboardingWidgetsWrongHeaderTest() {
131 UsernamePasswordAuthenticationToken notQuestprincipal = new UsernamePasswordAuthenticationToken("notQuestUser",
133 fnUserDao.save(notQuestUser);
134 when(request.getHeader("X-Widgets-Type")).thenReturn("test");
135 List<OnboardingWidget> actual = widgetsController
136 .getOnboardingWidgets(notQuestprincipal, request, response);
139 fnUserDao.delete(notQuestUser);
143 public void putOnboardingWidget() {
147 public void postOnboardingWidget() {
151 public void deleteOnboardingWidget() {
155 public void putWidgetCatalogSelection() {
158 private FnUser getQuestUser(){
159 return FnUser.builder()
160 .loginId("questUser")
162 .lastLoginDate(LocalDateTime.now())
164 .createdDate(LocalDateTime.now())
165 .modifiedDate(LocalDateTime.now())
167 .languageId(language)
172 private FnUser getNotQuestUser(){
173 return FnUser.builder()
174 .loginId("notQuestUser")
176 .lastLoginDate(LocalDateTime.now())
178 .createdDate(LocalDateTime.now())
179 .modifiedDate(LocalDateTime.now())
181 .languageId(language)
186 private FnLanguage getFnLanguage(){
187 return FnLanguage.builder().languageName("Polish").languageAlias("Pl").build();