2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
20 package org.openecomp.portalapp.portal.test.core;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
25 import java.io.IOException;
26 import java.nio.charset.Charset;
27 import java.util.ArrayList;
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;
41 import com.fasterxml.jackson.annotation.JsonInclude;
42 import com.fasterxml.jackson.databind.ObjectMapper;
46 * Use RestURLsTestSuite to test Rest API URL's
48 public class RestURLsTestSuite extends ApplicationCommonContextTestSuite {
50 public static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
51 MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
55 MockEPUser mockUser = new MockEPUser();
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);
63 public void requestBuilder(String url) throws Exception {
64 EPUser user = mockUser.mockEPUser();
66 MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get(url);
67 requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
68 ResultActions ra = getMockMvc().perform(requestBuilder);
72 public void assertData(ResultActions ra) {
73 Assert.assertEquals("application/json", ra.andReturn().getResponse().getContentType());
74 Assert.assertEquals(200, ra.andReturn().getResponse().getStatus());
79 public void getMenuItemsTest() throws Exception {
80 url = "/portalApi/functionalMenu";
85 public void getMenuItemsForNotificationsTest() throws Exception {
86 url = "/portalApi/functionalMenuForNotificationTree";
91 public void getUserAppsTestnew() throws Exception {
92 url = "/portalApi/userApps";
97 public void getPersUserAppsTest() throws Exception {
98 url = "/portalApi/persUserApps";
103 public void getAppCatalogTest() throws Exception {
104 url = "/portalApi/appCatalog";
109 public void getAppListNewTest() throws Exception {
110 ResultActions ra = getMockMvc()
111 .perform(MockMvcRequestBuilders.get("/portalApi/userApplicationRoles").param("userId", "guest"));
116 public void getAvailableAppListTest() throws Exception {
117 url = "/portalApi/availableApps";
122 public void getAllAppsTest() throws Exception {
123 url = "/portalApi/allAvailableApps";
128 public void getUserProfileTest() throws Exception {
129 url = "/portalApi/userProfile";
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);
143 public void getAppsWithAdminRoleStateForUserTest() throws Exception {
144 url = "/portalApi/adminAppsRoles?user=guest";
150 public void getUsersFromAppEndpointTest() throws Exception {
151 url = "/portalApi/app/550/users";
156 public void getOnboardingAppsTest() throws Exception {
157 url = "/portalApi/onboardingApps";
162 public void getMenuItemsForAuthUserTest() throws Exception {
163 url = "/portalApi/functionalMenuForAuthUser";
168 public void getMenuItemsForEditingTest() throws Exception {
169 url = "/portalApi/functionalMenuForEditing";
174 public void getAppRolesTest() throws Exception {
175 url = "/portalApi/appRoles/455";
180 public void regenerateAncestorTableTest() throws Exception {
182 EPUser user = mockUser.mockEPUser();
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());
194 public void getAppListTest() throws Exception {
195 url = "/portalApi/getAppList";
200 public void getFavoritesForUserTest() throws Exception {
201 url = "/portalApi/getFavoriteItems";
206 public void getManifestTest() throws Exception {
207 url = "/portalApi/manifest";
212 public void getActiveUsersTest() throws Exception {
213 url = "/portalApi/dashboard/activeUsers";
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);
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);
238 public void getAppsAndContactsTest() throws Exception {
239 url = "/portalApi/contactus/allapps";
244 public void getPortalDetailsTest() throws Exception {
245 url = "/portalApi/contactus/feedback";
250 public void getAppCategoryFunctionsTest() throws Exception {
251 url = "/portalApi/contactus/functions";
256 public void getOnlineUserUpdateRateTest() throws Exception {
257 url = "/portalApi/dashboard/onlineUserUpdateRate";
262 public void getMenuIdRoleIdTest() throws Exception {
263 url = "/portalApi/getFunctionalMenuRole";
268 public void getNotificationsTest() throws Exception {
269 url = "/portalApi/getNotifications";
274 public void getAdminNotificationsTest() throws Exception {
275 url = "/portalApi/getAdminNotifications";
280 public void getNotificationAppRolesTest() throws Exception {
281 url = "/portalApi/getNotificationAppRoles";
286 public void getNotificationUpdateRateTest() throws Exception {
287 url = "/portalApi/notificationUpdateRate";
292 public void notificationReadTest() throws Exception {
293 url = "/portalApi/notificationRead?notificationId=262";
298 public void testGetRolesTest() throws Exception {
299 url = "/portalApi/notificationRole/248/roles";
304 public void putAppsWithAdminRoleStateForUserTest() throws Exception {
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));
320 requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
321 ResultActions ra = getMockMvc().perform(requestBuilder);
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"));