10108cde472cda7e94cb9b80f7a6f22491e882c7
[portal.git] / ecomp-portal-BE-common-test / src / main / java / org / openecomp / portalapp / portal / test / core / RestURLsTestSuite.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 package org.openecomp.portalapp.portal.test.core;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.IOException;
26 import java.nio.charset.Charset;
27 import java.util.ArrayList;
28
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.openecomp.portalapp.portal.domain.EPUser;
32 import org.openecomp.portalapp.portal.transport.AppNameIdIsAdmin;
33 import org.openecomp.portalapp.portal.transport.AppsListWithAdminRole;
34 import org.openecomp.portalapp.test.framework.ApplicationCommonContextTestSuite;
35 import org.openecomp.portalsdk.core.util.SystemProperties;
36 import org.springframework.http.MediaType;
37 import org.springframework.test.web.servlet.ResultActions;
38 import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
39 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
40
41 import com.fasterxml.jackson.annotation.JsonInclude;
42 import com.fasterxml.jackson.databind.ObjectMapper;
43
44 /**
45  * 
46  * Use RestURLsTestSuite to test Rest API URL's
47  */
48 public class RestURLsTestSuite extends ApplicationCommonContextTestSuite {
49
50         public static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
51                         MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
52
53         String url = null;
54
55         MockEPUser mockUser = new MockEPUser();
56
57         public byte[] convertObjectToJsonBytes(Object object) throws IOException {
58                 ObjectMapper mapper = new ObjectMapper();
59                 mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
60                 return mapper.writeValueAsBytes(object);
61         }
62
63         public void requestBuilder(String url) throws Exception {
64                 EPUser user = mockUser.mockEPUser();
65
66                 MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get(url);
67                 requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
68                 ResultActions ra = getMockMvc().perform(requestBuilder);
69                 assertData(ra);
70         }
71
72         public void assertData(ResultActions ra) {
73                 Assert.assertEquals("application/json", ra.andReturn().getResponse().getContentType());
74                 Assert.assertEquals(200, ra.andReturn().getResponse().getStatus());
75
76         }
77
78         @Test
79         public void getMenuItemsTest() throws Exception {
80                 url = "/portalApi/functionalMenu";
81                 requestBuilder(url);
82         }
83
84         @Test
85         public void getMenuItemsForNotificationsTest() throws Exception {
86                 url = "/portalApi/functionalMenuForNotificationTree";
87                 requestBuilder(url);
88         }
89
90         @Test
91         public void getUserAppsTestnew() throws Exception {
92                 url = "/portalApi/userApps";
93                 requestBuilder(url);
94         }
95
96         @Test
97         public void getPersUserAppsTest() throws Exception {
98                 url = "/portalApi/persUserApps";
99                 requestBuilder(url);
100         }
101
102         @Test
103         public void getAppCatalogTest() throws Exception {
104                 url = "/portalApi/appCatalog";
105                 requestBuilder(url);
106         }
107
108         @Test
109         public void getAppListNewTest() throws Exception {
110                 ResultActions ra = getMockMvc()
111                                 .perform(MockMvcRequestBuilders.get("/portalApi/userApplicationRoles").param("userId", "guest"));
112                 assertData(ra);
113         }
114
115         @Test
116         public void getAvailableAppListTest() throws Exception {
117                 url = "/portalApi/availableApps";
118                 requestBuilder(url);
119         }
120
121         @Test
122         public void getAllAppsTest() throws Exception {
123                 url = "/portalApi/allAvailableApps";
124                 requestBuilder(url);
125         }
126
127         @Test
128         public void getUserProfileTest() throws Exception {
129                 url = "/portalApi/userProfile";
130                 requestBuilder(url);
131         }
132
133         @Test
134         public void getRolesByAppTest() throws Exception {
135                 EPUser user = mockUser.mockEPUser();
136                 MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/portalApi/adminAppsRoles/550");
137                 requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
138                 ResultActions ra = getMockMvc().perform(requestBuilder);
139                 assertData(ra);
140         }
141
142         @Test
143         public void getAppsWithAdminRoleStateForUserTest() throws Exception {
144                 url = "/portalApi/adminAppsRoles?user=guest";
145                 requestBuilder(url);
146
147         }
148
149         @Test
150         public void getUsersFromAppEndpointTest() throws Exception {
151                 url = "/portalApi/app/550/users";
152                 requestBuilder(url);
153         }
154
155         @Test
156         public void getOnboardingAppsTest() throws Exception {
157                 url = "/portalApi/onboardingApps";
158                 requestBuilder(url);
159         }
160
161         @Test
162         public void getMenuItemsForAuthUserTest() throws Exception {
163                 url = "/portalApi/functionalMenuForAuthUser";
164                 requestBuilder(url);
165         }
166
167         @Test
168         public void getMenuItemsForEditingTest() throws Exception {
169                 url = "/portalApi/functionalMenuForEditing";
170                 requestBuilder(url);
171         }
172
173         @Test
174         public void getAppRolesTest() throws Exception {
175                 url = "/portalApi/appRoles/455";
176                 requestBuilder(url);
177         }
178
179         @Test
180         public void regenerateAncestorTableTest() throws Exception {
181
182                 EPUser user = mockUser.mockEPUser();
183
184                 MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders
185                                 .get("/portalApi/regenerateFunctionalMenuAncestors");
186                 requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
187                 ResultActions ra = getMockMvc().perform(requestBuilder);
188                 assertEquals("application/json;charset=UTF-8", ra.andReturn().getResponse().getContentType());
189                 Assert.assertEquals(200, ra.andReturn().getResponse().getStatus());
190
191         }
192
193         @Test
194         public void getAppListTest() throws Exception {
195                 url = "/portalApi/getAppList";
196                 requestBuilder(url);
197         }
198
199         @Test
200         public void getFavoritesForUserTest() throws Exception {
201                 url = "/portalApi/getFavoriteItems";
202                 requestBuilder(url);
203         }
204
205         @Test
206         public void getManifestTest() throws Exception {
207                 url = "/portalApi/manifest";
208                 requestBuilder(url);
209         }
210
211         @Test
212         public void getActiveUsersTest() throws Exception {
213                 url = "/portalApi/dashboard/activeUsers";
214                 requestBuilder(url);
215         }
216
217         @Test
218         public void searchPortalTest() throws Exception {
219                 EPUser user = mockUser.mockEPUser();
220                 MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/portalApi/dashboard/search")
221                                 .param("searchString", "guest");
222                 requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
223                 ResultActions ra = getMockMvc().perform(requestBuilder);
224                 assertData(ra);
225         }
226
227         @Test
228         public void getWidgetDataTest() throws Exception {
229                 EPUser user = mockUser.mockEPUser();
230                 MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/portalApi/dashboard/widgetData")
231                                 .param("resourceType", "guest");
232                 requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
233                 ResultActions ra = getMockMvc().perform(requestBuilder);
234                 assertData(ra);
235         }
236
237         @Test
238         public void getAppsAndContactsTest() throws Exception {
239                 url = "/portalApi/contactus/allapps";
240                 requestBuilder(url);
241         }
242
243         @Test
244         public void getPortalDetailsTest() throws Exception {
245                 url = "/portalApi/contactus/feedback";
246                 requestBuilder(url);
247         }
248
249         @Test
250         public void getAppCategoryFunctionsTest() throws Exception {
251                 url = "/portalApi/contactus/functions";
252                 requestBuilder(url);
253         }
254
255         @Test
256         public void getOnlineUserUpdateRateTest() throws Exception {
257                 url = "/portalApi/dashboard/onlineUserUpdateRate";
258                 requestBuilder(url);
259         }
260
261         @Test
262         public void getMenuIdRoleIdTest() throws Exception {
263                 url = "/portalApi/getFunctionalMenuRole";
264                 requestBuilder(url);
265         }
266
267         @Test
268         public void getNotificationsTest() throws Exception {
269                 url = "/portalApi/getNotifications";
270                 requestBuilder(url);
271         }
272
273         @Test
274         public void getAdminNotificationsTest() throws Exception {
275                 url = "/portalApi/getAdminNotifications";
276                 requestBuilder(url);
277         }
278
279         @Test
280         public void getNotificationAppRolesTest() throws Exception {
281                 url = "/portalApi/getNotificationAppRoles";
282                 requestBuilder(url);
283         }
284
285         @Test
286         public void getNotificationUpdateRateTest() throws Exception {
287                 url = "/portalApi/notificationUpdateRate";
288                 requestBuilder(url);
289         }
290
291         @Test
292         public void notificationReadTest() throws Exception {
293                 url = "/portalApi/notificationRead?notificationId=262";
294                 requestBuilder(url);
295         }
296
297         @Test
298         public void testGetRolesTest() throws Exception {
299                 url = "/portalApi/notificationRole/248/roles";
300                 requestBuilder(url);
301         }
302
303         @Test
304         public void putAppsWithAdminRoleStateForUserTest() throws Exception {
305
306                 AppsListWithAdminRole appsListWithAdminRole = new AppsListWithAdminRole();
307                 appsListWithAdminRole.setOrgUserId("guest");
308                 ArrayList<AppNameIdIsAdmin> appsRoles = new ArrayList<AppNameIdIsAdmin>();
309                 AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin();
310                 appNameIdIsAdmin.setId((long) 455);
311                 appNameIdIsAdmin.setAppName("CCD");
312                 appNameIdIsAdmin.setIsAdmin(true);
313                 appNameIdIsAdmin.setRestrictedApp(false);
314                 appsRoles.add(appNameIdIsAdmin);
315                 appsListWithAdminRole.setAppsRoles(appsRoles);
316                 EPUser user = mockUser.mockEPUser();
317                 MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/portalApi/adminAppsRoles")
318                                 .contentType(APPLICATION_JSON_UTF8).content(convertObjectToJsonBytes(appsListWithAdminRole));
319
320                 requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
321                 ResultActions ra = getMockMvc().perform(requestBuilder);
322                 assertData(ra);
323         }
324
325         @Test
326         public void ticketEventControllerForExternalSystem() throws Exception {
327                 String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\",  \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\",      \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}";
328                 MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/auxapi/ticketevent")
329                                 .contentType(APPLICATION_JSON_UTF8).content(ticketEventJson);
330                 ResultActions ra = getMockMvc().perform(requestBuilder);
331                 assertTrue(ra.andReturn().getResponse().getContentType().contains("application/json"));
332         }
333 }