1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/*-
* ================================================================================
* ECOMP Portal
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ================================================================================
*/
package org.openecomp.portalapp.portal.service;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.portalapp.portal.domain.FunctionalMenuItemWithAppID;
import org.openecomp.portalapp.portal.service.FunctionalMenuService;
import org.openecomp.portalapp.portal.service.FunctionalMenuServiceImpl;
import org.openecomp.portalapp.portal.transport.FavoritesFunctionalMenuItemJson;
import org.openecomp.portalapp.portal.transport.FunctionalMenuItem;
import org.openecomp.portalapp.portal.transport.FunctionalMenuRole;
import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
import org.openecomp.portalsdk.core.service.DataAccessService;
import org.openecomp.portalsdk.core.util.SystemProperties;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest({SystemProperties.class, EPCommonSystemProperties.class})
public class FunctionalMenuMockServiceImplTest {
@Mock
FunctionalMenuService functionalMenuService;
@Mock
DataAccessService dataAccessService;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@InjectMocks
FunctionalMenuServiceImpl functionalMenuServiceImpl= new FunctionalMenuServiceImpl();
@Test
public void assignHelpURLsTest(){
List<FunctionalMenuItem> menuItems = new ArrayList<FunctionalMenuItem>();
FunctionalMenuItem functionalMenuItem1 = new FunctionalMenuItem();
functionalMenuItem1.text = "Contact Us";
FunctionalMenuItem functionalMenuItem2 = new FunctionalMenuItem();
functionalMenuItem2.text = "Get Access";
FunctionalMenuItem functionalMenuItem3 = new FunctionalMenuItem();
functionalMenuItem3.text = "User Guide";
menuItems.add(functionalMenuItem1);
menuItems.add(functionalMenuItem2);
menuItems.add(functionalMenuItem3);
PowerMockito.mockStatic(SystemProperties.class);
Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.USER_GUIDE_URL)).thenReturn("http://todo_enter_user_guide_link");
// Mockito.doNothing().when(functionalMenuServiceImpl).assignHelpURLs(menuItems);
functionalMenuServiceImpl.assignHelpURLs(menuItems);
}
@Test
public void getFunctionalMenuItemsTest(){
String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, "
+ "fn_menu_functional_roles r WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' "
+ "UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id FROM fn_menu_functional m "
+ "WHERE m.url='' AND UPPER(m.active_yn) = 'Y'";
List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>();
List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>();
Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult);
actualResult = functionalMenuServiceImpl.getFunctionalMenuItems(true);
assertEquals(actualResult, expectedResult);
}
@Test
public void getFunctionalMenuItemsNegativeTest(){
String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, "
+ "fn_menu_functional_roles r WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' "
+ "UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id FROM fn_menu_functional m "
+ "WHERE m.url='' AND UPPER(m.active_yn) = 'Y'";
List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>();
List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>();
Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult);
actualResult = functionalMenuServiceImpl.getFunctionalMenuItems(false);
assertEquals(actualResult, expectedResult);
}
@Test
public void getFunctionalMenuItemsForNotificationTreeTest(){
String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, fn_menu_functional_roles r "
+ "WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id,"
+ " m.url, m.active_yn,-1 app_id FROM fn_menu_functional m WHERE m.url='' AND UPPER(m.active_yn) = 'Y'";
List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>();
List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>();
Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult);
actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForNotificationTree(true);
assertEquals(actualResult, expectedResult);
}
@Test
public void getFunctionalMenuItemsForNotificationNegativeTreeTest(){
String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, fn_menu_functional_roles r "
+ "WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id,"
+ " m.url, m.active_yn,-1 app_id FROM fn_menu_functional m WHERE m.url='' AND UPPER(m.active_yn) = 'Y'";
List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>();
List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>();
Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult);
actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForNotificationTree(false);
assertEquals(actualResult, expectedResult);
}
@Test
public void getFunctionalMenuItemsForAppTest(){
String sql = "SELECT DISTINCT m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m.active_yn "
+ "FROM fn_menu_functional m, fn_menu_functional m1, fn_menu_functional_ancestors a, fn_menu_functional_roles mr "
+ "WHERE mr.app_id='1' AND mr.menu_id = m.menu_id AND UPPER(m.active_yn) = 'Y' AND UPPER(m1.active_yn) ='Y' AND a.menu_id = m.menu_id "
+ "AND a.ancestor_menu_id = m1.menu_id";
Integer appId = 1;
List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>();
List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>();
Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult);
actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForApp(appId);
assertEquals(actualResult, expectedResult);
}
@Test
public void getFunctionalMenuItemsForUserTest(){
String orgUserId = "test";
String sql = "SELECT DISTINCT m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m.active_yn "
+ "FROM fn_menu_functional m, fn_menu_functional m1, fn_menu_functional_ancestors a, fn_menu_functional_roles mr, fn_user u , fn_user_role ur "
+ "WHERE u.org_user_id='test' AND u.user_id = ur.user_id AND ur.app_id = mr.app_id AND (ur.role_id = mr.role_id OR ur.role_id = '999') "
+ "AND m.menu_id = mr.menu_id AND UPPER(m.active_yn) = 'Y' AND UPPER(m1.active_yn) ='Y' AND a.menu_id = m.menu_id "
+ "AND a.ancestor_menu_id = m1.menu_id UNION select m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m1.active_yn "
+ "FROM fn_menu_functional m, fn_menu_functional_roles mr, fn_menu_functional m1, fn_menu_functional_ancestors a where a.menu_id = m.menu_id AND a.ancestor_menu_id = m1.menu_id AND m.menu_id != m1.menu_id AND m.menu_id = mr.menu_id AND mr.role_id = '900' AND UPPER(m.active_yn) = 'Y' AND UPPER(m1.active_yn) ='Y' UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn FROM fn_menu_functional m WHERE m.text in ('Favorites','Get Access','Contact Us','Support','User Guide','Help')";
List<FunctionalMenuItem> actualResult = new ArrayList<FunctionalMenuItem>();
List<FunctionalMenuItem> expectedResult = new ArrayList<FunctionalMenuItem>();
Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult);
actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForUser(orgUserId);
assertEquals(actualResult, expectedResult);
}
@Test
public void getFunctionalMenuItemDetailsTest(){
Integer menuid = 1;
String sql = "SELECT * FROM fn_menu_functional_roles WHERE menu_id = '1'";
FunctionalMenuItem actualResult = null;
FunctionalMenuItem expectedResult = null;
List<FunctionalMenuRole> roleItems = new ArrayList<FunctionalMenuRole>();
Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(roleItems);
actualResult = functionalMenuServiceImpl.getFunctionalMenuItemDetails(menuid);
assertEquals(actualResult, expectedResult);
}
@Test
public void getFavoriteItemsTest(){
Long userId = (long)1;
String sql = "SELECT DISTINCT f.user_id,f.menu_id,m.text,m.url "
+ "FROM fn_menu_favorites f, fn_menu_functional m, fn_menu_functional_roles mr "
+ "WHERE f.user_id='1' AND f.menu_id = m.menu_id AND f.menu_id = mr.menu_id AND mr.role_id != '900' ";
List<FavoritesFunctionalMenuItemJson> actualResult = new ArrayList<FavoritesFunctionalMenuItemJson>();
List<FavoritesFunctionalMenuItemJson> expectedResult = new ArrayList<FavoritesFunctionalMenuItemJson>();
Mockito.when(dataAccessService.executeSQLQuery(sql, FavoritesFunctionalMenuItemJson.class, null)).thenReturn(expectedResult);
actualResult = functionalMenuServiceImpl.getFavoriteItems(userId);
assertEquals(actualResult, expectedResult);
}
}
|