From 21a8761f684745bb300e075c7e98ad897ace9eed Mon Sep 17 00:00:00 2001 From: st782s Date: Tue, 30 Jan 2018 17:29:36 -0500 Subject: Security/ Package Name changes Issue-ID: PORTAL-174, PORTAL-157, PORTAL-156, PORTAL-148, PORTAL-145, PORTAL-140, PORTAL-133, PORTAL-121, PORTAL-111, PORTAL-88 Includes security fixes, Role Centralization, replace certain ECOMP occurrences etc Change-Id: I3c8b706709c6b92e646e3cbe50c2d660e8a46ef4 Signed-off-by: st782s --- .../portalapp/authentication/LoginStrategy.java | 45 +++ .../authentication/OpenIdConnectLoginStrategy.java | 123 ++++++ .../authentication/SimpleLoginStrategy.java | 131 +++++++ .../org/onap/portalapp/conf/ExternalAppConfig.java | 412 ++++++++++++++++++++ .../portalapp/conf/ExternalAppInitializer.java | 78 ++++ .../portalapp/conf/HibernateMappingLocations.java | 61 +++ .../controller/ECOMPLogoutController.java | 133 +++++++ .../onap/portalapp/controller/LoginController.java | 413 +++++++++++++++++++++ .../onap/portalapp/controller/LoginService.java | 54 +++ .../portalapp/controller/ONAPLoginController.java | 99 +++++ .../controller/ONAPWelcomeController.java | 102 +++++ .../controller/OpenCollaborationController.java | 41 ++ .../portalapp/controller/PeerBroadcastSocket.java | 124 +++++++ .../onap/portalapp/filter/SecurityXssFilter.java | 158 ++++++++ .../portalapp/filter/SecurityXssValidator.java | 207 +++++++++++ .../portal/controller/AppsOSController.java | 135 +++++++ .../DashboardSearchResultController.java | 262 +++++++++++++ .../controller/ExternalAppsRestfulController.java | 148 ++++++++ .../portal/controller/PortalAdminController.java | 156 ++++++++ .../interceptor/SessionTimeoutInterceptor.java | 118 ++++++ .../portal/logging/aop/EPEELFLoggerAspect.java | 225 +++++++++++ .../portalapp/portal/service/AppsCacheService.java | 58 +++ .../portal/service/AppsCacheServiceImple.java | 124 +++++++ .../portalapp/portal/service/EPAppServiceImpl.java | 178 +++++++++ .../portalapp/portal/service/SearchService.java | 58 +++ .../portal/service/SearchServiceImpl.java | 214 +++++++++++ .../portal/service/TicketEventServiceImpl.java | 56 +++ .../portal/service/UserRolesServiceImpl.java | 123 ++++++ .../onap/portalapp/portal/service/UserService.java | 52 +++ .../portalapp/portal/service/UserServiceImpl.java | 275 ++++++++++++++ .../portalapp/portal/transport/OnboardingApp.java | 107 ++++++ .../org/onap/portalapp/portal/ueb/EPUebHelper.java | 220 +++++++++++ .../onap/portalapp/portal/ueb/EPUebMsgTypes.java | 45 +++ .../portalapp/portal/utils/EPSystemProperties.java | 61 +++ .../java/org/onap/portalapp/scheduler/LogJob.java | 63 ++++ .../org/onap/portalapp/scheduler/LogRegistry.java | 75 ++++ .../org/onap/portalapp/scheduler/Register.java | 103 +++++ .../onap/portalapp/scheduler/RegistryAdapter.java | 118 ++++++ .../portalapp/scheduler/SessionMgtRegistry.java | 105 ++++++ .../service/RemoteWebServiceCallServiceImpl.java | 114 ++++++ .../uebhandler/FunctionalMenuHandler.java | 136 +++++++ .../onap/portalapp/uebhandler/InitUebHandler.java | 86 +++++ .../onap/portalapp/uebhandler/MainUebHandler.java | 125 +++++++ .../uebhandler/WidgetNotificationHandler.java | 110 ++++++ .../org/onap/portalapp/util/SessionCookieUtil.java | 146 ++++++++ .../portalapp/authentication/LoginStrategy.java | 45 --- .../authentication/OpenIdConnectLoginStrategy.java | 123 ------ .../authentication/SimpleLoginStrategy.java | 131 ------- .../portalapp/conf/ExternalAppConfig.java | 335 ----------------- .../portalapp/conf/ExternalAppInitializer.java | 78 ---- .../portalapp/conf/HibernateMappingLocations.java | 61 --- .../controller/ECOMPLogoutController.java | 132 ------- .../portalapp/controller/LoginController.java | 392 ------------------- .../portalapp/controller/LoginService.java | 54 --- .../portalapp/controller/ONAPLoginController.java | 99 ----- .../controller/ONAPWelcomeController.java | 102 ----- .../controller/OpenCollaborationController.java | 41 -- .../portalapp/controller/PeerBroadcastSocket.java | 124 ------- .../portal/controller/AppsOSController.java | 134 ------- .../DashboardSearchResultController.java | 261 ------------- .../controller/ExternalAppsRestfulController.java | 147 -------- .../portal/controller/PortalAdminController.java | 155 -------- .../interceptor/SessionTimeoutInterceptor.java | 118 ------ .../portal/logging/aop/EPEELFLoggerAspect.java | 222 ----------- .../portalapp/portal/service/AppsCacheService.java | 58 --- .../portal/service/AppsCacheServiceImple.java | 122 ------ .../portalapp/portal/service/EPAppServiceImpl.java | 176 --------- .../portalapp/portal/service/SearchService.java | 58 --- .../portal/service/SearchServiceImpl.java | 211 ----------- .../portal/service/TicketEventServiceImpl.java | 55 --- .../portal/service/UserRolesServiceImpl.java | 121 ------ .../portalapp/portal/service/UserService.java | 52 --- .../portalapp/portal/service/UserServiceImpl.java | 273 -------------- .../portalapp/portal/transport/OnboardingApp.java | 107 ------ .../portalapp/portal/ueb/EPUebHelper.java | 221 ----------- .../portalapp/portal/ueb/EPUebMsgTypes.java | 45 --- .../portalapp/portal/utils/EPSystemProperties.java | 60 --- .../org/openecomp/portalapp/scheduler/LogJob.java | 63 ---- .../openecomp/portalapp/scheduler/LogRegistry.java | 75 ---- .../openecomp/portalapp/scheduler/Register.java | 103 ----- .../portalapp/scheduler/RegistryAdapter.java | 118 ------ .../portalapp/scheduler/SessionMgtRegistry.java | 105 ------ .../service/RemoteWebServiceCallServiceImpl.java | 118 ------ .../uebhandler/FunctionalMenuHandler.java | 136 ------- .../portalapp/uebhandler/InitUebHandler.java | 86 ----- .../portalapp/uebhandler/MainUebHandler.java | 125 ------- .../uebhandler/WidgetNotificationHandler.java | 110 ------ .../portalapp/util/SessionCookieUtil.java | 146 -------- .../src/main/resources/key.properties | 3 + ecomp-portal-BE-os/src/main/resources/logback.xml | 6 +- .../src/main/resources/openid-connect.properties | 6 +- .../src/main/resources/portal.properties | 10 +- .../src/main/webapp/WEB-INF/conf/quartz.properties | 6 +- .../src/main/webapp/WEB-INF/conf/raptor.properties | 6 +- .../WEB-INF/conf/raptor_app_fusion.properties | 6 +- .../WEB-INF/conf/raptor_db_fusion.properties | 6 +- .../main/webapp/WEB-INF/conf/raptor_pdf.properties | 6 +- .../main/webapp/WEB-INF/conf/scheduler.properties | 61 +++ .../src/main/webapp/WEB-INF/conf/sql.properties | 6 +- .../src/main/webapp/WEB-INF/conf/system.properties | 44 +-- .../src/main/webapp/WEB-INF/defs/definitions.xml | 6 +- .../webapp/WEB-INF/fusion/conf/fusion.properties | 6 +- .../src/main/webapp/WEB-INF/jsp/error.jsp | 6 +- .../src/main/webapp/WEB-INF/jsp/index.jsp | 6 +- .../src/main/webapp/WEB-INF/jsp/login.jsp | 26 +- .../src/main/webapp/WEB-INF/jsp/oid-admin.jsp | 6 +- .../src/main/webapp/WEB-INF/jsp/oid-home.jsp | 6 +- .../src/main/webapp/WEB-INF/jsp/oid-login.jsp | 6 +- .../src/main/webapp/WEB-INF/jsp/oid-user.jsp | 6 +- .../src/main/webapp/WEB-INF/oid-context.xml | 20 +- ecomp-portal-BE-os/src/main/webapp/WEB-INF/web.xml | 27 +- .../ds2/css/digital-ng-library/ecomp-ionicons.css | 3 + ecomp-portal-BE-os/src/main/webapp/index.jsp | 6 +- .../OpenIdConnectLoginStrategyTest.java | 155 ++++++++ .../SessionTimeoutInterceptorTest.java | 92 +++++ .../authentication/SimpleLoginStrategyTest.java | 171 +++++++++ .../portal/controller/AppsOSControllerTest.java | 189 ++++++++++ .../DashboardSearchResultControllerTest.java | 360 ++++++++++++++++++ .../controller/ECOMPLogoutControllerTest.java | 114 ++++++ .../ExternalAppsRestfulControllerOSTest.java | 199 ++++++++++ .../portal/controller/LoginControllerTest.java | 121 ++++++ .../portal/controller/ONAPLoginControllerTest.java | 128 +++++++ .../controller/ONAPWelcomeControllerTest.java | 101 +++++ .../controller/PortalAdminControllerOSTest.java | 242 ++++++++++++ .../portalapp/portal/framework/MockEPUser.java | 102 +++++ .../portal/framework/MockitoTestSuite.java | 93 +++++ .../portal/listener/HealthMonitorTest.java | 55 +++ .../RemoteWebServiceCallServiceImplTest.java | 186 ++++++++++ .../portal/service/SearchServiceImplTest.java | 228 ++++++++++++ .../portal/service/UserServiceImplTest.java | 101 +++++ .../portal/utils/EcompPortalUtilsTest.java | 52 +++ .../OpenIdConnectLoginStrategyTest.java | 155 -------- .../SessionTimeoutInterceptorTest.java | 92 ----- .../authentication/SimpleLoginStrategyTest.java | 171 --------- .../portal/controller/AppsOSControllerTest.java | 186 ---------- .../DashboardSearchResultControllerTest.java | 359 ------------------ .../controller/ECOMPLogoutControllerTest.java | 112 ------ .../ExternalAppsRestfulControllerOSTest.java | 198 ---------- .../portal/controller/LoginControllerTest.java | 121 ------ .../portal/controller/ONAPLoginControllerTest.java | 128 ------- .../controller/ONAPWelcomeControllerTest.java | 99 ----- .../controller/PortalAdminControllerOSTest.java | 241 ------------ .../portal/controller/SharedContextRestClient.java | 298 --------------- .../SharedContextRestControllerTest.java | 143 ------- .../controller/SharedContextTestProperties.java | 99 ----- .../controller/shared-context-test.properties | 46 --- .../portalapp/portal/framework/MockEPUser.java | 102 ----- .../portal/framework/MockitoTestSuite.java | 93 ----- .../portal/listener/HealthMonitorTest.java | 54 --- .../RemoteWebServiceCallServiceImplTest.java | 185 --------- .../portal/service/SearchServiceImplTest.java | 226 ----------- .../portal/utils/EcompPortalUtilsTest.java | 51 --- 152 files changed, 8834 insertions(+), 8785 deletions(-) create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/LoginStrategy.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/OpenIdConnectLoginStrategy.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/SimpleLoginStrategy.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppInitializer.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/HibernateMappingLocations.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ECOMPLogoutController.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginController.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginService.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ONAPLoginController.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ONAPWelcomeController.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/OpenCollaborationController.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/PeerBroadcastSocket.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/filter/SecurityXssFilter.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/filter/SecurityXssValidator.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/controller/AppsOSController.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/controller/DashboardSearchResultController.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulController.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/controller/PortalAdminController.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/interceptor/SessionTimeoutInterceptor.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/logging/aop/EPEELFLoggerAspect.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/AppsCacheService.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/AppsCacheServiceImple.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/EPAppServiceImpl.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/SearchService.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/SearchServiceImpl.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/TicketEventServiceImpl.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/UserRolesServiceImpl.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/UserService.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/service/UserServiceImpl.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/transport/OnboardingApp.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/ueb/EPUebHelper.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/ueb/EPUebMsgTypes.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/portal/utils/EPSystemProperties.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/scheduler/LogJob.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/scheduler/LogRegistry.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/scheduler/Register.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/scheduler/RegistryAdapter.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/scheduler/SessionMgtRegistry.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/service/RemoteWebServiceCallServiceImpl.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/uebhandler/FunctionalMenuHandler.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/uebhandler/InitUebHandler.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/uebhandler/MainUebHandler.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/uebhandler/WidgetNotificationHandler.java create mode 100644 ecomp-portal-BE-os/src/main/java/org/onap/portalapp/util/SessionCookieUtil.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/authentication/LoginStrategy.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/authentication/OpenIdConnectLoginStrategy.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/authentication/SimpleLoginStrategy.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/conf/ExternalAppConfig.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/conf/ExternalAppInitializer.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/conf/HibernateMappingLocations.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/controller/ECOMPLogoutController.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/controller/LoginController.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/controller/LoginService.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/controller/ONAPLoginController.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/controller/ONAPWelcomeController.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/controller/OpenCollaborationController.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/controller/PeerBroadcastSocket.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/controller/AppsOSController.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/controller/DashboardSearchResultController.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/controller/ExternalAppsRestfulController.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/controller/PortalAdminController.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/interceptor/SessionTimeoutInterceptor.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/logging/aop/EPEELFLoggerAspect.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/AppsCacheService.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/AppsCacheServiceImple.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/EPAppServiceImpl.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/SearchService.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/SearchServiceImpl.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/TicketEventServiceImpl.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/UserRolesServiceImpl.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/UserService.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/service/UserServiceImpl.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/transport/OnboardingApp.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/ueb/EPUebHelper.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/ueb/EPUebMsgTypes.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/portal/utils/EPSystemProperties.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/scheduler/LogJob.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/scheduler/LogRegistry.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/scheduler/Register.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/scheduler/RegistryAdapter.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/scheduler/SessionMgtRegistry.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/service/RemoteWebServiceCallServiceImpl.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/FunctionalMenuHandler.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java delete mode 100644 ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/util/SessionCookieUtil.java create mode 100644 ecomp-portal-BE-os/src/main/resources/key.properties create mode 100644 ecomp-portal-BE-os/src/main/webapp/WEB-INF/conf/scheduler.properties create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/SimpleLoginStrategyTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/AppsOSControllerTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ECOMPLogoutControllerTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerOSTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/LoginControllerTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ONAPLoginControllerTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ONAPWelcomeControllerTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerOSTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/framework/MockEPUser.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/framework/MockitoTestSuite.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/listener/HealthMonitorTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/SearchServiceImplTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/UserServiceImplTest.java create mode 100644 ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SimpleLoginStrategyTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsOSControllerTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/DashboardSearchResultControllerTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ECOMPLogoutControllerTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ExternalAppsRestfulControllerOSTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/LoginControllerTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPLoginControllerTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPWelcomeControllerTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/PortalAdminControllerOSTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextRestClient.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextRestControllerTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextTestProperties.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/shared-context-test.properties delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockEPUser.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockitoTestSuite.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/listener/HealthMonitorTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/SearchServiceImplTest.java delete mode 100644 ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/utils/EcompPortalUtilsTest.java (limited to 'ecomp-portal-BE-os/src') diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/LoginStrategy.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/LoginStrategy.java new file mode 100644 index 00000000..767bd520 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/LoginStrategy.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.authentication; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public interface LoginStrategy { + public boolean login(HttpServletRequest request, HttpServletResponse response) throws Exception; +} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/OpenIdConnectLoginStrategy.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/OpenIdConnectLoginStrategy.java new file mode 100644 index 00000000..cbe4b352 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/OpenIdConnectLoginStrategy.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.authentication; + +import java.util.HashSet; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.mitre.openid.connect.model.UserInfo; +import org.onap.portalapp.command.EPLoginBean; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.utils.EPSystemProperties; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalapp.util.SessionCookieUtil; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.onboarding.exception.PortalAPIException; +import org.onap.portalsdk.core.util.SystemProperties; +import org.springframework.util.StringUtils; +import org.springframework.web.servlet.ModelAndView; + +public class OpenIdConnectLoginStrategy extends org.onap.portalsdk.core.auth.LoginStrategy implements org.onap.portalapp.authentication.LoginStrategy { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(OpenIdConnectLoginStrategy.class); + + private static final String GLOBAL_LOCATION_KEY = "Location"; + + @SuppressWarnings("rawtypes") + public boolean login(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + logger.info("Attempting Login"); + + //check both authentication cookie and authentication header + UserInfo userInfo = (UserInfo) request.getAttribute("userInfo"); + + if (userInfo != null && !StringUtils.isEmpty(userInfo.getPreferredUsername())) { + //package the userid in the login form for processing + EPLoginBean commandBean = new EPLoginBean(); + commandBean.setOrgUserId(userInfo.getPreferredUsername()); + + EPUser user = new EPUser(); + + user.setOrgUserId(userInfo.getPreferredUsername()); + user.setEmail(userInfo.getEmail()); + user.setFirstName(userInfo.getName()); + user.setLastName(userInfo.getFamilyName()); + + //store the currently logged in user's information in the session + EPUserUtils.setUserSession(request, user, new HashSet(), new HashSet(), SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM),null); + + logger.info(EELFLoggerDelegate.errorLogger, request.getContextPath()); + SessionCookieUtil.preSetUp(request, response); + return true; + } else { + // in case authentication cookie is missing, send 401 UNAUTHORIZED to client and it will redirect to Logon + try { + String authentication = SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM); + String loginUrl = SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL); + logger.info(EELFLoggerDelegate.errorLogger, "Authentication Mechanism: '" + authentication + "'."); + + if (authentication == null || authentication.equals("") || authentication.trim().equals("OIDC")) { + response.sendRedirect("oid-login"); + } else { + logger.info(EELFLoggerDelegate.errorLogger, "No cookies are found, redirecting the request to '" + loginUrl + "'."); + response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); + response.setHeader(GLOBAL_LOCATION_KEY, loginUrl); + } + } catch(Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "login failed", e); + } + } + return false; + } + + @Override + public ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response) throws Exception { + String message = "Method not implmented; Cannot be called"; + logger.error(EELFLoggerDelegate.errorLogger, message); + throw new Exception(message); + } + + @Override + public String getUserId(HttpServletRequest request) throws PortalAPIException { + String message = "Method not implmented; Cannot be called"; + logger.error(EELFLoggerDelegate.errorLogger, message); + throw new PortalAPIException(message); + } +} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/SimpleLoginStrategy.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/SimpleLoginStrategy.java new file mode 100644 index 00000000..55a0f10a --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/authentication/SimpleLoginStrategy.java @@ -0,0 +1,131 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.authentication; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.command.EPLoginBean; +import org.onap.portalapp.portal.service.EPLoginService; +import org.onap.portalapp.portal.service.EPRoleFunctionService; +import org.onap.portalapp.portal.utils.EPSystemProperties; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalapp.util.SessionCookieUtil; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.menu.MenuProperties; +import org.onap.portalsdk.core.onboarding.exception.PortalAPIException; +import org.onap.portalsdk.core.util.SystemProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; +import org.springframework.web.servlet.ModelAndView; + +public class SimpleLoginStrategy extends org.onap.portalsdk.core.auth.LoginStrategy implements LoginStrategy{ + + @Autowired + private EPLoginService loginService; + + @Autowired + private EPRoleFunctionService ePRoleFunctionService; + + private static final String GLOBAL_LOCATION_KEY = "Location"; + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SimpleLoginStrategy.class); + + public boolean login(HttpServletRequest request, HttpServletResponse response) throws Exception{ + logger.info("Attempting 'Simple' Login"); + + //check both authentication cookie and authentication header + String orgUserId = SessionCookieUtil.getUserIdFromCookie(request, response); + + if (!StringUtils.isEmpty(orgUserId)) { + // package the userid in the login form for processing + EPLoginBean commandBean = new EPLoginBean(); + commandBean.setOrgUserId(orgUserId); + commandBean = loginService.findUser(commandBean, (String)request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), null); + + // in case authentication has passed but user is not in the ECOMP data base, return a Guest User to the home page. + if (commandBean.getUser() == null) { + } + else { + // store the currently logged in user's information in the session + EPUserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(), commandBean.getBusinessDirectMenu(), "", ePRoleFunctionService); + logger.info(EELFLoggerDelegate.debugLogger, commandBean.getUser().getOrgUserId() + " exists in the the system."); + } + + logger.info(EELFLoggerDelegate.errorLogger, request.getContextPath()); + SessionCookieUtil.preSetUp(request, response); + return true; + } else { + // in case authentication cookie is missing, send 401 UNAUTHORIZED to client and it will redirect to Logon + try { + String authentication = SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM); + String loginUrl = SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL); + logger.info(EELFLoggerDelegate.errorLogger, "Authentication Mechanism: '" + authentication + "'."); + if (authentication == null || authentication.equals("") || authentication.trim().equals("BOTH")) { + + logger.info(EELFLoggerDelegate.errorLogger, "No cookies are found, redirecting the request to '" + loginUrl + "'."); + response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); + response.setHeader(GLOBAL_LOCATION_KEY, loginUrl); //returnUrl + "/index.htm"); + }else { + logger.info(EELFLoggerDelegate.errorLogger, "No cookies are found, redirecting the request to '" + loginUrl + "'."); + response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); + response.setHeader(GLOBAL_LOCATION_KEY, loginUrl); //returnUrl + "/index.htm"); + } + } catch(Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "login failed", e); + } + } + + return false; + + } + + @Override + public ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response) throws Exception { + String message = "Method not implmented; Cannot be called"; + logger.error(EELFLoggerDelegate.errorLogger, message); + throw new Exception(message); + } + + @Override + public String getUserId(HttpServletRequest request) throws PortalAPIException { + String message = "Method not implmented; Cannot be called"; + logger.error(EELFLoggerDelegate.errorLogger, message); + throw new PortalAPIException(message); + } +} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java new file mode 100644 index 00000000..b6d384d5 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppConfig.java @@ -0,0 +1,412 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.conf; + +import static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY; +import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID; +import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN; +import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS; +import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID; +import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME; + +import java.net.InetAddress; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.PostConstruct; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.onap.portalapp.authentication.LoginStrategy; +import org.onap.portalapp.authentication.OpenIdConnectLoginStrategy; +import org.onap.portalapp.authentication.SimpleLoginStrategy; +import org.onap.portalapp.controller.core.LogoutController; +import org.onap.portalapp.controller.core.SDKLoginController; +import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.domain.EPUserApp; +import org.onap.portalapp.portal.interceptor.PortalResourceInterceptor; +import org.onap.portalapp.portal.interceptor.SessionTimeoutInterceptor; +import org.onap.portalapp.portal.listener.HealthMonitor; +import org.onap.portalapp.portal.service.EPLoginService; +import org.onap.portalapp.portal.service.EPLoginServiceImpl; +import org.onap.portalapp.portal.service.ExternalAccessRolesService; +import org.onap.portalapp.portal.service.UserRolesService; +import org.onap.portalapp.portal.transport.ExternalAuthUserRole; +import org.onap.portalapp.portal.transport.ExternalRoleDescription; +import org.onap.portalapp.portal.ueb.EPUebHelper; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalapp.portal.utils.EPSystemProperties; +import org.onap.portalapp.scheduler.RegistryAdapter; +import org.onap.portalapp.uebhandler.FunctionalMenuHandler; +import org.onap.portalapp.uebhandler.InitUebHandler; +import org.onap.portalapp.uebhandler.MainUebHandler; +import org.onap.portalapp.uebhandler.WidgetNotificationHandler; +import org.onap.portalsdk.core.conf.AppConfig; +import org.onap.portalsdk.core.conf.Configurable; +import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.objectcache.AbstractCacheManager; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.FnMenuService; +import org.onap.portalsdk.core.service.FnMenuServiceImpl; +import org.onap.portalsdk.core.util.CacheManager; +import org.onap.portalsdk.core.util.SystemProperties; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.Profile; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; + +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = {"org.onap", "org.openecomp" }, excludeFilters = { + @Filter(value = { LogoutController.class, SDKLoginController.class}, type = FilterType.ASSIGNABLE_TYPE) }) +@Profile("src") +@EnableAsync +@EnableScheduling + +public class ExternalAppConfig extends AppConfig implements Configurable { + + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class); + + @Autowired + private DataAccessService dataAccessService; + + @Autowired + private UserRolesService userRolesService; + + @Autowired + private ExternalAccessRolesService externalAccessRolesService; + + private RegistryAdapter schedulerRegistryAdapter; + + String UEB_APP_KEY = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY); + + public ViewResolver viewResolver() { + return super.viewResolver(); + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/app/fusion/**").addResourceLocations("/app/fusion/"); + registry.addResourceHandler("/static/**").addResourceLocations("/static/"); + registry.addResourceHandler("/images/**").addResourceLocations("/images/"); + registry.addResourceHandler("/**").addResourceLocations("/public/"); + } + + @PostConstruct + private void init() { + String remotecentralizedsystemaccess = SystemProperties.getProperty(EPCommonSystemProperties.REMOTE_CENTRALIZED_SYSTEM_ACCESS); + try { + // Loading defaults + MDC.put(MDC_SERVICE_NAME, EPSystemProperties.ECOMP_PORTAL_BE); + MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName()); + MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress()); + MDC.put(MDC_SERVICE_INSTANCE_ID, ""); + MDC.put(MDC_ALERT_SEVERITY, AlarmSeverityEnum.INFORMATIONAL.severity()); + MDC.put(MDC_INSTANCE_UUID, SystemProperties.getProperty(SystemProperties.INSTANCE_UUID)); + if(remotecentralizedsystemaccess.equalsIgnoreCase("true")){ + importFromExternalAuth(); + } + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "init failed", e); + } + } + + /** + * Does a sync on functions, roles and role functions based on namespace + * for all the centralized applications between AAF and ONAP, updates + * fn_user and fn_user_role with user information from AAF. + * + */ + private void importFromExternalAuth() throws Exception { + JSONArray aafAppRoles = new JSONArray(); + JSONArray aafUserList = new JSONArray(); + List appList; + //to get all centralized apps + List centralizedAppList = dataAccessService.executeNamedQuery("getCentralizedApps", null, null); + if(centralizedAppList != null && centralizedAppList.size() > 0){ + for(int i = 0; i < centralizedAppList.size(); i++){ + //syncRoles(does a sync on functions, roles and role functions) + externalAccessRolesService.syncApplicationRolesWithEcompDB(centralizedAppList.get(i)); + //retrieve roles based on NS + aafAppRoles = externalAccessRolesService.getAppRolesJSONFromExtAuthSystem(centralizedAppList.get(i)); + if(aafAppRoles != null && aafAppRoles.length() > 0){ + for(int j = 0; j < aafAppRoles.length(); j++){ + ObjectMapper mapper = new ObjectMapper(); + String name = aafAppRoles.getJSONObject(j).getString("name"); + String desc = aafAppRoles.getJSONObject(j).getString("description"); + ExternalRoleDescription externalRoleDescription = mapper.readValue(desc, ExternalRoleDescription.class); + aafUserList = externalAccessRolesService.getAllUsersByRole(name); + if(aafUserList != null && aafUserList.length() > 0){ + for(int k = 0; k < aafUserList.length(); k++){ + EPUser user = null; + List usersList = null; + List userRolesList = new ArrayList(); + JSONObject userRole = (JSONObject) aafUserList.get(k); + Gson gson = new Gson(); + ExternalAuthUserRole userRoleObj = gson.fromJson(userRole.toString(), ExternalAuthUserRole.class); + if(userRoleObj.getUser() != null){ + userRoleObj.setUser(userRoleObj.getUser().substring(0, userRoleObj.getUser().indexOf("@"))); + } + //for each role and user in that role, check if user exists in fn_user. If not, add + Map orgUserId = new HashMap<>(); + orgUserId.put("orgUserIdValue", userRoleObj.getUser()); + usersList = dataAccessService.executeNamedQuery("epUserAppId", orgUserId, null); + if(usersList != null && usersList.size() > 0){ + user = usersList.get(0); + } + if(user == null){ + // add user to fn_user(needs to be revisited after getting user info from AAF PORTAL-172) + } + //for each role and user in that role, check if user exists in fn_user_role. If not, add + /*userRolesList = userRolesService.getUserRolesList(centralizedAppList.get(0).getId(), user.getId(), Long.valueOf(externalRoleDescription.getId())); + if(userRolesList == null || userRolesList.isEmpty()){ + // add userRole to fn_user_role(needs to be revisited after getting user info from AAF PORTAL-172) + }*/ + } + } + + } + } + } + } + } + + public DataAccessService dataAccessService() { + return super.dataAccessService(); + } + + public String[] tileDefinitions() { + return super.tileDefinitions(); + } + + public List addTileDefinitions() { + List definitions = new ArrayList(); + definitions.add("/WEB-INF/defs/definitions.xml"); + return definitions; + } + + @Bean + public AbstractCacheManager cacheManager() { + return new CacheManager(); + } + + @Bean + public SessionTimeoutInterceptor sessionTimeoutInterceptor() { + return new SessionTimeoutInterceptor(); + } + + @Bean + public PortalResourceInterceptor portalResourceInterceptor() { + return new PortalResourceInterceptor(); + } + + @Bean + public EPLoginService eploginService() { + return new EPLoginServiceImpl(); + } + + @Bean + public org.onap.portalsdk.core.auth.LoginStrategy coreLoginStrategy() { + if (SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC")) + return new OpenIdConnectLoginStrategy(); + else + return new SimpleLoginStrategy(); + } + + @Bean + public LoginStrategy loginStrategy() { + + if (SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM).trim().equalsIgnoreCase("OIDC")) + return new OpenIdConnectLoginStrategy(); + else + return new SimpleLoginStrategy(); + } + + public FnMenuService fnMenuService() { + return new FnMenuServiceImpl(); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + // registry.addInterceptor(new + // StaticResourcesInterceptor()).addPathPatterns("/index.htm", + // "/applicationsHome", "/widgetsHome", "/admins", "/users", + // "/applications", "/widgets"); + // Excludes login/logout pages and REST endpoints used by other + // application servers. + + registry.addInterceptor(sessionTimeoutInterceptor()).excludePathPatterns("/oid-login", "/portalApi/healthCheck", + "/portalApi/healthCheck/", "/portalApi/healthCheckSuspend", "/portalApi/healthCheckSuspend/", + "/portalApi/healthCheckResume", "/portalApi/healthCheckResume/", "/login_external", + "/login_external.htm*", "login", "/login.htm*", "/auxapi/*", "/context/*", "/api*", + "/single_signon.htm", "/single_signon", "/dashboard", "/OpenSourceLogin.htm"); + + registry.addInterceptor(portalResourceInterceptor()); + + } + + /** + * Creates and returns a new instance of a {@link SchedulerFactoryBean} and + * populates it with triggers. + * + * @return New instance of {@link SchedulerFactoryBean} + */ + + @Bean + public EPUebHelper epUebHelper() { + return new EPUebHelper(); + } + + @Bean + public HealthMonitor healthMonitor() { + return new HealthMonitor(); + } + + /** + * Creates and returns a new instance of a {@link MainUebHandler}. + * + * @return New instance of {@link MainUebHandler}. + */ + @Bean + public MainUebHandler mainUebHandler() { + return new MainUebHandler(); + } + + /** + * Creates and returns a new instance of a {@link InitUebHandler}. + * + * @return New instance of {@link InitUebHandler}. + */ + @Bean + public InitUebHandler initUebHandler() { + return new InitUebHandler(); + } + + /** + * Creates and returns a new instance of a {@link WidgetNotificationHandler} + * . + * + * @return New instance of {@link WidgetNotificationHandler}. + */ + @Bean + public WidgetNotificationHandler widgetNotificationHandler() { + return new WidgetNotificationHandler(); + } + + /** + * Creates and returns a new instance of a {@link FunctionalMenuHandler} . + * + * @return New instance of {@link FunctionalMenuHandler}. + */ + @Bean + public FunctionalMenuHandler functionalMenuHandler() { + return new FunctionalMenuHandler(); + } + + /** + * Creates and returns a new instance of a {@link SchedulerFactoryBean} and + * populates it with triggers. + * + * @return New instance of {@link SchedulerFactoryBean} + * @throws Exception if dataSource fails + */ + // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION + @Bean // ANNOTATION COMMENTED OUT + public SchedulerFactoryBean schedulerFactoryBean() throws Exception { + SchedulerFactoryBean scheduler = new SchedulerFactoryBean(); + scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties")); + scheduler.setDataSource(dataSource()); + scheduler.setTriggers(schedulerRegistryAdapter.getTriggers()); + scheduler.setSchedulerName(getScheduleName()); + return scheduler; + } + + protected String getScheduleName() { + final String CRON_SITE_NAME = "cron_site_name"; + String cronSiteVal = "Default"; + try { + cronSiteVal = SystemProperties.getProperty(CRON_SITE_NAME); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "getScheduleName failed", e); + logger.warn(EELFLoggerDelegate.errorLogger, + "Cron site name not added in property file, using Default value"); + } + + String cronSiteName = cronSiteVal != null ? cronSiteVal : ""; + + SimpleDateFormat dateFormat = new SimpleDateFormat(); + dateFormat.applyPattern("YYYYMMdd"); + String currentDateStr = dateFormat.format(Calendar.getInstance().getTime()); + + return "Scheduler" + "_" + currentDateStr + "_" + cronSiteName; + } + + /** + * Sets the scheduler registry adapter. + * + * @param schedulerRegistryAdapter + * Scheduler registry adapter + */ + @Autowired + public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) { + this.schedulerRegistryAdapter = schedulerRegistryAdapter; + } + +} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppInitializer.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppInitializer.java new file mode 100644 index 00000000..62051b1d --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/ExternalAppInitializer.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.conf; + +import java.util.Arrays; + +import org.onap.portalsdk.core.conf.AppInitializer; + +public class ExternalAppInitializer extends AppInitializer{ + + + @Override + protected Class[] getRootConfigClasses() { + return super.getRootConfigClasses(); + } + + @Override + protected Class[] getServletConfigClasses() { +// Class[] configClasses = super.getServletConfigClasses(); +// Class[] additionalConfigClasses = Arrays.copyOf(configClasses, configClasses.length); +// addConfigClass(additionalConfigClasses, ExternalAppConfig.class); +// return additionalConfigClasses; +// + return new Class[] {ExternalAppConfig.class}; + } + + static Class[] addConfigClass(Class[] a, Class e) { + a = Arrays.copyOf(a, a.length + 1); + a[a.length - 1] = e; + return a; + } + + /* + * URL request will direct to the Spring dispatcher for processing + */ + @Override + protected String[] getServletMappings() { + return super.getServletMappings(); + } + +} + + diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/HibernateMappingLocations.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/HibernateMappingLocations.java new file mode 100644 index 00000000..f340ec35 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/conf/HibernateMappingLocations.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.conf; + +import org.onap.portalsdk.core.conf.HibernateMappingLocatable; +import org.springframework.context.annotation.Profile; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.stereotype.Component; + +@Component +@Profile("src") +public class HibernateMappingLocations implements HibernateMappingLocatable { + + public Resource[] getMappingLocations() { + return new Resource[] { new ClassPathResource("../fusion/orm/Fusion.hbm.xml"), + new ClassPathResource("../fusion/orm/EP.hbm.xml"), + new ClassPathResource("../fusion/orm/Workflow.hbm.xml") }; + } + + @Override + public String[] getPackagesToScan() { + return new String[] { "org.onap","org.openecomp" }; + } + +} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ECOMPLogoutController.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ECOMPLogoutController.java new file mode 100644 index 00000000..0f0cf270 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ECOMPLogoutController.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.controller; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.controller.EPUnRestrictedBaseController; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.logging.aop.EPAuditLog; +import org.onap.portalapp.portal.logging.aop.EPMetricsLog; +import org.onap.portalapp.portal.utils.EPSystemProperties; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.servlet.ModelAndView; + +@Controller +@RequestMapping("/") +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@Profile("src") +public class ECOMPLogoutController extends EPUnRestrictedBaseController{ + + private EPUser user; + private static final String EP_SERVICE = "EPService"; + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ECOMPLogoutController.class); + + @EPAuditLog + @RequestMapping(value = {"/logout.htm" }, method = RequestMethod.GET) + public ModelAndView logOut(HttpServletRequest request, + HttpServletResponse response) throws Exception { + + ModelAndView modelView = null; + + chatRoomLogout(request); + logger.debug(EELFLoggerDelegate.debugLogger, "ECOMPLogoutController.handleRequestInternal - Logout request received."); + + modelView = new ModelAndView("redirect:login.htm"); + + /** + if (UserUtils.isClientMobileDevice(request)){ + modelView.setViewName(modelView.getViewName().concat("?viewType=mobile")); + } + */ + String cookieDoamin = EPSystemProperties.getProperty(EPSystemProperties.COOKIE_DOMAIN); + Cookie epCookie = new Cookie(EP_SERVICE, ""); + epCookie.setMaxAge(0); + epCookie.setDomain(cookieDoamin); + epCookie.setPath("/"); + + Cookie appHeaderCookie = new Cookie("show_app_header", ""); + appHeaderCookie.setMaxAge(0); + appHeaderCookie.setDomain(cookieDoamin); + appHeaderCookie.setPath("/"); + + Cookie appTabCookie = new Cookie("cookieTabs", ""); + appTabCookie.setMaxAge(0); + appTabCookie.setDomain(cookieDoamin); + appTabCookie.setPath("/"); + + Cookie appVisInvisTabCookie = new Cookie("visInVisCookieTabs", ""); + appVisInvisTabCookie.setMaxAge(0); + appVisInvisTabCookie.setDomain(cookieDoamin); + appVisInvisTabCookie.setPath("/"); + + response.addCookie(epCookie); + response.addCookie(appHeaderCookie); + response.addCookie(appTabCookie); + response.addCookie(appVisInvisTabCookie); + request.getSession().invalidate(); + + logger.debug(EELFLoggerDelegate.debugLogger, "ECOMPLogoutController.handleRequestInternal - Successfully processed the logout request."); + + return modelView; + } + + @EPMetricsLog + public void chatRoomLogout(HttpServletRequest request){ + request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); + setUser(EPUserUtils.getUserSession(request)); + } + + public EPUser getUser() { + return user; + } + + public void setUser(EPUser user) { + this.user = user; + } +} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginController.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginController.java new file mode 100644 index 00000000..273a0b1e --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginController.java @@ -0,0 +1,413 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.controller; + +import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; + +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLDecoder; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.json.JSONObject; +import org.onap.portalapp.command.EPLoginBean; +import org.onap.portalapp.controller.EPUnRestrictedBaseController; +import org.onap.portalapp.portal.domain.SharedContext; +import org.onap.portalapp.portal.service.EPLoginService; +import org.onap.portalapp.portal.service.EPRoleFunctionService; +import org.onap.portalapp.portal.service.SharedContextService; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalapp.portal.utils.EPSystemProperties; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalapp.util.SessionCookieUtil; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.menu.MenuProperties; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.util.SystemProperties; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.util.StopWatch; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.util.WebUtils; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Controller +@RequestMapping("/") +public class LoginController extends EPUnRestrictedBaseController implements LoginService { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LoginController.class); + + public static final String DEFAULT_SUCCESS_VIEW = "applicationsHome"; + public static final String DEFAULT_FAILURE_VIEW = "login"; + public static final String ERROR_MESSAGE_KEY = "error"; + public static final String REDIRECT_URL = "redirectUrl"; + public static final String REDIRECT_COLON = "redirect:"; + + @Autowired + private EPLoginService loginService; + @Autowired + private SharedContextService sharedContextService; + @Autowired + private EPRoleFunctionService ePRoleFunctionService; + + private String viewName = "login"; + + private String welcomeView; + + @RequestMapping(value = { "/login.htm" }, method = RequestMethod.GET) + public ModelAndView login(HttpServletRequest request) { + Map model = new HashMap(); + String authentication = SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM); + String loginPage; + if (authentication == null || "".equals(authentication) || "OICD".equals(authentication.trim())) + loginPage = "openIdLogin"; + else + loginPage = getViewName(); + return new ModelAndView(loginPage, "model", model); + } + + @SuppressWarnings("rawtypes") + @RequestMapping(value = { "/open_source/login" }, method = RequestMethod.POST) + @ResponseBody + public String loginValidate(HttpServletRequest request, HttpServletResponse response) throws Exception { + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode root = mapper.readTree(request.getReader()); + + EPLoginBean commandBean = new EPLoginBean(); + String loginId = root.get("loginId").textValue(); + String password = root.get("password").textValue(); + commandBean.setLoginId(loginId); + commandBean.setLoginPwd(CipherUtil.encrypt(password)); + HashMap additionalParamsMap = new HashMap(); + StringBuilder sbAdditionalInfo = new StringBuilder(); + + commandBean = getLoginService().findUser(commandBean, + (String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), additionalParamsMap); + String fullURL = getFullURL(request); + if (commandBean.getUser() == null) { + String loginErrorMessage = (commandBean.getLoginErrorMessage() != null) ? commandBean.getLoginErrorMessage() + : "login.error.external.invalid"; + logger.info(EELFLoggerDelegate.debugLogger, "loginId {} does not exist in the the DB.", loginId); + sbAdditionalInfo.append(String.format("But the Login-Id: %s doesn't exist in the Database. Request-URL: %s", + loginId, fullURL)); + return loginErrorMessage; + } else { + // store the currently logged in user's information in the session + EPUserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(), + commandBean.getBusinessDirectMenu(), + SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM), ePRoleFunctionService); + + try { + logger.info(EELFLoggerDelegate.debugLogger, "loginValidate: store user info into share context begins"); + String sessionId = request.getSession().getId(); + List existingSC = getSharedContextService().getSharedContexts(sessionId); + if (existingSC == null || existingSC.isEmpty()) { + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_FIRST_NAME, + commandBean.getUser().getFirstName()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_LAST_NAME, + commandBean.getUser().getLastName()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_EMAIL, + commandBean.getUser().getEmail()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_ORG_USERID, + commandBean.getLoginId()); + } + + } catch (Exception e) { + logger.info(EELFLoggerDelegate.errorLogger, "loginValidate: failed the shared context adding process ", + e); + } + logger.info(EELFLoggerDelegate.debugLogger, + "loginValidate: PresetUp the EP service cookie and intial sessionManagement"); + + SessionCookieUtil.preSetUp(request, response); + SessionCookieUtil.setUpUserIdCookie(request, response, loginId); + + JSONObject j = new JSONObject("{success: success}"); + + return j.toString(); + } + } + + /* + * Work around a bug in ecompsdkos version 1.1.0 which hard-codes this endpoint. + */ + @RequestMapping(value = { "/process_csp" }, method = RequestMethod.GET) + public ModelAndView processCsp(HttpServletRequest request, HttpServletResponse response) throws Exception { + return processSingleSignOn(request, response); + } + /* + * Remove this method after epsdk-app-common/.../SingleSignOnController.java is + * repaired. + */ + + @RequestMapping(value = { "/processSingleSignOn" }, method = RequestMethod.GET) + public ModelAndView processSingleSignOn(HttpServletRequest request, HttpServletResponse response) throws Exception { + + Map model = new HashMap(); + HashMap additionalParamsMap = new HashMap(); + EPLoginBean commandBean = new EPLoginBean(); + MDC.put(MDC_KEY_REQUEST_ID, getRequestId(request)); + // get userId from cookie + String orgUserId = SessionCookieUtil.getUserIdFromCookie(request, response); + logger.info(EELFLoggerDelegate.debugLogger, "processSingleSignOn: begins with orgUserId {}", orgUserId); + + StringBuilder sbAdditionalInfo = new StringBuilder(); + validateDomain(request); + if (orgUserId == null || orgUserId.length() == 0) { + model.put(ERROR_MESSAGE_KEY, SystemProperties.MESSAGE_KEY_LOGIN_ERROR_COOKIE_EMPTY); + if (request.getParameter(REDIRECT_URL) != null && request.getParameter(REDIRECT_URL).length() != 0) { + return new ModelAndView(REDIRECT_COLON + DEFAULT_FAILURE_VIEW + ".htm" + "?redirectUrl=" + + request.getParameter(REDIRECT_URL)); + } else { + return new ModelAndView(REDIRECT_COLON + DEFAULT_FAILURE_VIEW + ".htm"); + } + } else { + + StopWatch stopWatch = new StopWatch("LoginController.Login"); + stopWatch.start(); + + try { + logger.info(EELFLoggerDelegate.debugLogger, + "Operation findUser is started to locate user {} in the database.", orgUserId); + commandBean.setLoginId(orgUserId); + commandBean.setOrgUserId(orgUserId); + commandBean = getLoginService().findUser(commandBean, + (String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), + additionalParamsMap); + + stopWatch.stop(); + MDC.put(EPSystemProperties.MDC_TIMER, stopWatch.getTotalTimeMillis() + "ms"); + logger.info(EELFLoggerDelegate.debugLogger, "Operation findUser is completed."); + } catch (Exception e) { + stopWatch.stop(); + MDC.put(EPSystemProperties.MDC_TIMER, stopWatch.getTotalTimeMillis() + "ms"); + logger.info(EELFLoggerDelegate.errorLogger, "processSingleSignOn failed on user " + orgUserId, e); + } finally { + MDC.remove(EPSystemProperties.MDC_TIMER); + } + + sbAdditionalInfo.append("Login attempt is succeeded. "); + String fullURL = getFullURL(request); + if (commandBean.getUser() == null) { + logger.info(EELFLoggerDelegate.debugLogger, + "processSingleSignOn: loginId {} does not exist in the the DB.", orgUserId); + + sbAdditionalInfo.append(String.format( + "But the Login-Id: %s doesn't exist in the Database. Created a Guest Session. Request-URL: %s", + orgUserId, fullURL)); + validateDomain(request); + if (request.getParameter(REDIRECT_URL) != null && request.getParameter(REDIRECT_URL).length() != 0) { + return new ModelAndView(REDIRECT_COLON + DEFAULT_FAILURE_VIEW + ".htm" + "?redirectUrl=" + + request.getParameter(REDIRECT_URL)); + } else { + return new ModelAndView(REDIRECT_COLON + DEFAULT_FAILURE_VIEW + ".htm"); + } + } else { + + sbAdditionalInfo.append( + String.format("Login-Id: %s, Login-Method: %s, Request-URL: %s", orgUserId, "", fullURL)); + logger.info(EELFLoggerDelegate.debugLogger, "processSingleSignOn: now set up user session for {}", + orgUserId); + + EPUserUtils.setUserSession(request, commandBean.getUser(), commandBean.getMenu(), + commandBean.getBusinessDirectMenu(), + SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM), ePRoleFunctionService); + logger.info(EELFLoggerDelegate.debugLogger, + "processSingleSignOn: now set up user session for {} finished", orgUserId); + + // Store user's information into share context + try { + logger.info(EELFLoggerDelegate.debugLogger, + "processSingleSignOn: store user info into share context begins"); + String sessionId = request.getSession().getId(); + List existingSC = getSharedContextService().getSharedContexts(sessionId); + if (existingSC == null || existingSC.isEmpty()) { + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_FIRST_NAME, + commandBean.getUser().getFirstName()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_LAST_NAME, + commandBean.getUser().getLastName()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_EMAIL, + commandBean.getUser().getEmail()); + getSharedContextService().addSharedContext(sessionId, EPSystemProperties.USER_ORG_USERID, + commandBean.getLoginId()); + } + } catch (Exception e) { + logger.info(EELFLoggerDelegate.errorLogger, + "processSingleSignOn: failed the shared context adding process", e); + } + + logger.info(EELFLoggerDelegate.debugLogger, + "processSingleSignOn: PresetUp the EP service cookie and intial sessionManagement"); + SessionCookieUtil.preSetUp(request, response); + SessionCookieUtil.setUpUserIdCookie(request, response, orgUserId); + logger.info(EELFLoggerDelegate.debugLogger, + "processSingleSignOn: PresetUp the EP service cookie and intial sessionManagement completed"); + logger.info(EELFLoggerDelegate.debugLogger, + commandBean.getUser().getOrgUserId() + " exists in the the system."); + + // get redirectUrl from URL parameter + validateDomain(request); + if (request.getParameter(REDIRECT_URL) != null && request.getParameter(REDIRECT_URL).length() != 0) { + String forwardUrl = URLDecoder.decode(request.getParameter(REDIRECT_URL), "UTF-8"); + // clean cookie + Cookie cookie2 = new Cookie(REDIRECT_URL, ""); + // ONAP does not use https + cookie2.setSecure(false); + cookie2.setMaxAge(0); + cookie2.setDomain(EPSystemProperties.getProperty(EPSystemProperties.COOKIE_DOMAIN)); + cookie2.setPath("/"); + response.addCookie(cookie2); + return new ModelAndView(REDIRECT_COLON + forwardUrl); + } + + // first check if redirectUrl exists or not + if (WebUtils.getCookie(request, REDIRECT_URL) != null) { + String forwardUrl = WebUtils.getCookie(request, REDIRECT_URL).getValue(); + // clean cookie + Cookie cookie2 = new Cookie(REDIRECT_URL, ""); + // ONAP does not use https + cookie2.setSecure(false); + cookie2.setMaxAge(0); + cookie2.setDomain(EPSystemProperties.getProperty(EPSystemProperties.COOKIE_DOMAIN)); + cookie2.setPath("/"); + response.addCookie(cookie2); + + return new ModelAndView(REDIRECT_COLON + forwardUrl); + } + } + } + + // if user has been authenticated, now take them to the welcome page. + logger.info(EELFLoggerDelegate.debugLogger, "processSingleSignOn: Now return to application home page"); + return new ModelAndView(REDIRECT_COLON + SystemProperties.getProperty(EPSystemProperties.FE_URL)); + } + + private void validateDomain(HttpServletRequest request) throws MalformedURLException { + final String returnToAppUrl = request.getParameter(REDIRECT_URL); + if (StringUtils.isNotBlank(returnToAppUrl)) { + String hostName = new URL(returnToAppUrl).getHost(); + if (StringUtils.isNotBlank(hostName) + && !hostName.endsWith(EPSystemProperties.getProperty(EPCommonSystemProperties.COOKIE_DOMAIN))) { + logger.debug(EELFLoggerDelegate.debugLogger, + "processSingleSignOn () accessing Unauthorized url :" + hostName); + throw new SecurityException("accessing Unauthorized url : " + hostName); + } + } + } + + private String getFullURL(HttpServletRequest request) { + if (request != null) { + String requestURL = request.getRequestURL().toString(); + String queryString = request.getQueryString(); + if (queryString == null) { + return requestURL; + } else { + return requestURL + "?" + queryString; + } + } + return ""; + } + + private String getRequestId(HttpServletRequest request) { + Enumeration headerNames = request.getHeaderNames(); + String requestId = ""; + while (headerNames.hasMoreElements()) { + String headerName = headerNames.nextElement(); + logger.debug(EELFLoggerDelegate.debugLogger, "getRequestId: header {} has value {}", headerName, + request.getHeader(headerName)); + if (headerName.equalsIgnoreCase(SystemProperties.ECOMP_REQUEST_ID)) { + requestId = request.getHeader(headerName); + break; + } + } + return requestId.isEmpty() ? UUID.randomUUID().toString() : requestId; + } + + public String getWelcomeView() { + return welcomeView; + } + + public void setWelcomeView(String welcomeView) { + this.welcomeView = welcomeView; + } + + @Override + public String getViewName() { + return viewName; + } + + @Override + public void setViewName(String viewName) { + this.viewName = viewName; + } + + public EPLoginService getLoginService() { + return loginService; + } + + public void setLoginService(EPLoginService loginService) { + this.loginService = loginService; + } + + public SharedContextService getSharedContextService() { + return sharedContextService; + } + + public void setSharedContextService(SharedContextService sharedContextService) { + this.sharedContextService = sharedContextService; + } + +} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginService.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginService.java new file mode 100644 index 00000000..41e07a8e --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/LoginService.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +public interface LoginService { + + public ModelAndView login(HttpServletRequest request); + + public @ResponseBody String loginValidate(HttpServletRequest request, HttpServletResponse response) throws Exception; + + public ModelAndView processSingleSignOn(HttpServletRequest request, HttpServletResponse response) throws Exception; + +} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ONAPLoginController.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ONAPLoginController.java new file mode 100644 index 00000000..d20a4608 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ONAPLoginController.java @@ -0,0 +1,99 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.controller; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalsdk.core.auth.LoginStrategy; +import org.onap.portalsdk.core.controller.UnRestrictedBaseController; +import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler; +import org.onap.portalsdk.core.service.LoginService; +import org.onap.portalsdk.core.service.ProfileService; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +@Controller +@RequestMapping("/") +public class ONAPLoginController extends UnRestrictedBaseController { + @Autowired + ProfileService service; + @Autowired + private LoginService loginService; + @Autowired + private LoginStrategy loginStrategy; + String viewName; + + @RequestMapping(value = { "/doLogin" }, method = RequestMethod.GET) + public ModelAndView doLogin(HttpServletRequest request, HttpServletResponse response) throws Exception { + return loginStrategy.doLogin(request, response); + } + + public String getJessionId(HttpServletRequest request) { + return request.getSession().getId(); + } + + protected void initateSessionMgtHandler(HttpServletRequest request) { + String jSessionId = getJessionId(request); + PortalTimeoutHandler.sessionCreated(jSessionId, jSessionId, AppUtils.getSession(request)); + } + + public String getViewName() { + return viewName; + } + + public void setViewName(String viewName) { + this.viewName = viewName; + } + + public LoginService getLoginService() { + return loginService; + } + + public void setLoginService(LoginService loginService) { + this.loginService = loginService; + } + +} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ONAPWelcomeController.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ONAPWelcomeController.java new file mode 100644 index 00000000..0435dbaf --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/ONAPWelcomeController.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.controller; + +import java.security.Principal; +import java.util.Set; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.mitre.openid.connect.client.SubjectIssuerGrantedAuthority; +import org.onap.portalapp.controller.EPRestrictedBaseController; +import org.onap.portalapp.portal.logging.aop.EPAuditLog; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +@Controller +@RequestMapping("/") +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +public class ONAPWelcomeController extends EPRestrictedBaseController{ + String viewName; + + @RequestMapping(value = "/index.htm", method = RequestMethod.GET) + public String getIndexPage(HttpServletRequest request) { + return "/index"; + } + + @RequestMapping(value = {"/applicationsHome", "/dashboard", "/widgetsHome", "/kpidash*", "/admins", "/users", "/portalAdmins", "/applications", "/widgets", "/functionalMenu", "/contactUs", "/getAccess","/appCatalog", "/widgetOnboarding", "/accountOnboarding"}, method = RequestMethod.GET) + public String getEcompSinglePage(HttpServletRequest request, HttpServletResponse response) { + return "forward:/index.html"; + } + + protected String getViewName() { + return viewName; + } + + protected void setViewName(String viewName) { + this.viewName = viewName; + } + + //@Resource(name = "namedAdmins") + private Set admins; + + @RequestMapping("/user") + public String user(Principal p) { + return "oid-user"; + } + + @RequestMapping("/admin") + public String admin(Model model, Principal p) { + + model.addAttribute("admins", admins); + + return "oid-admin"; + } + @RequestMapping("/oid-login") + public ModelAndView login(Principal p) { + return new ModelAndView("openIdLogin"); + } +} diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/OpenCollaborationController.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/OpenCollaborationController.java new file mode 100644 index 00000000..5348f237 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/OpenCollaborationController.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.controller; + +import java.util.HashMap; +import java.util.Map; diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/PeerBroadcastSocket.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/PeerBroadcastSocket.java new file mode 100644 index 00000000..170c3ce1 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/controller/PeerBroadcastSocket.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.controller; + +import java.io.IOException; +import java.util.Hashtable; +import java.util.Map; + +import javax.websocket.OnClose; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import com.fasterxml.jackson.databind.ObjectMapper; + +@ServerEndpoint("/opencontact") +public class PeerBroadcastSocket { + + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PeerBroadcastSocket.class); + + public static Map channelMap = new Hashtable(); + public Map sessionMap = new Hashtable(); + ObjectMapper mapper = new ObjectMapper(); + + @OnMessage + public void message(String message, Session session) { + try { + // JSONObject jsonObject = new JSONObject(message); + @SuppressWarnings("unchecked") + Map jsonObject = mapper.readValue(message, Map.class); + try { + Object from = jsonObject.get("from"); + if (from != null) { + if(channelMap.get(from.toString()) == null) { + channelMap.put(from.toString(), session); + sessionMap.put(session.getId(), from.toString()); + } + } + } catch (Exception je) { + logger.error(EELFLoggerDelegate.errorLogger, "Failed to read value" + je.getMessage()); + } + + try { + Object to = jsonObject.get("to"); + if (to == null) + return; + Object toSessionObj = channelMap.get(to); + if (toSessionObj != null) { + Session toSession = null; + toSession = (Session) toSessionObj; + toSession.getBasicRemote().sendText(message); + } + + } catch (Exception ex) { + logger.error(EELFLoggerDelegate.errorLogger, "Failed to send text" + ex.getMessage()); + } + + } catch (Exception ex) { + logger.error(EELFLoggerDelegate.errorLogger, "Failed" + ex.getMessage()); + } + + } + + @OnOpen + public void open(Session session) { + logger.info(EELFLoggerDelegate.debugLogger, "Channel opened"); + } + + @OnClose + public void close(Session session) { + String channel = sessionMap.get(session.getId()); + if (channel != null) { + Object sessObj = channelMap.get(channel); + if (sessObj != null) { + try { + ((Session) sessObj).close(); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, "Failed to close" + e.getMessage()); + } + } + channelMap.remove(channel); + } + logger.info(EELFLoggerDelegate.debugLogger, "Channel closed"); + } + +} + diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/filter/SecurityXssFilter.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/filter/SecurityXssFilter.java new file mode 100644 index 00000000..11d1a449 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/filter/SecurityXssFilter.java @@ -0,0 +1,158 @@ + +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.filter; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + +import javax.servlet.FilterChain; +import javax.servlet.ReadListener; +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpStatus; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.web.filter.OncePerRequestFilter; + +public class SecurityXssFilter extends OncePerRequestFilter { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SecurityXssFilter.class); + + private static final String APPLICATION_JSON = "application/json"; + + private static final String ERROR_BAD_REQUEST = "{\"error\":\"BAD_REQUEST\"}"; + + private SecurityXssValidator validator = SecurityXssValidator.getInstance(); + + public class RequestWrapper extends HttpServletRequestWrapper { + + private ByteArrayOutputStream cachedBytes; + + public RequestWrapper(HttpServletRequest request) { + super(request); + } + + @Override + public ServletInputStream getInputStream() throws IOException { + if (cachedBytes == null) + cacheInputStream(); + + return new CachedServletInputStream(); + } + + @Override + public BufferedReader getReader() throws IOException { + return new BufferedReader(new InputStreamReader(getInputStream())); + } + + private void cacheInputStream() throws IOException { + cachedBytes = new ByteArrayOutputStream(); + IOUtils.copy(super.getInputStream(), cachedBytes); + } + + public class CachedServletInputStream extends ServletInputStream { + private ByteArrayInputStream input; + + public CachedServletInputStream() { + input = new ByteArrayInputStream(cachedBytes.toByteArray()); + } + + @Override + public int read() throws IOException { + return input.read(); + } + + @Override + public boolean isFinished() { + return false; + } + + @Override + public boolean isReady() { + return false; + } + + @Override + public void setReadListener(ReadListener readListener) { + + } + + } + } + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) + throws ServletException, IOException { + if (validateRequestType(request)) { + request = new RequestWrapper(request); + String requestData = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8.toString()); + try { + if (StringUtils.isNotBlank(requestData) && validator.denyXSS(requestData)) { + response.setContentType(APPLICATION_JSON); + response.setStatus(HttpStatus.SC_BAD_REQUEST); + response.getWriter().write(ERROR_BAD_REQUEST); + throw new SecurityException(ERROR_BAD_REQUEST); + } + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "doFilterInternal() failed due to BAD_REQUEST", e); + response.getWriter().close(); + return; + } + filterChain.doFilter(request, response); + + } else { + filterChain.doFilter(request, response); + } + + } + + private boolean validateRequestType(HttpServletRequest request) { + return (request.getMethod().equalsIgnoreCase("POST") || request.getMethod().equalsIgnoreCase("PUT") + || request.getMethod().equalsIgnoreCase("DELETE")); + } +} \ No newline at end of file diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/filter/SecurityXssValidator.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/filter/SecurityXssValidator.java new file mode 100644 index 00000000..4d6a9fe2 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/filter/SecurityXssValidator.java @@ -0,0 +1,207 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.filter; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.regex.Pattern; + +import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringEscapeUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.owasp.esapi.ESAPI; +import org.owasp.esapi.codecs.Codec; +import org.owasp.esapi.codecs.MySQLCodec; +import org.owasp.esapi.codecs.MySQLCodec.Mode; +import org.owasp.esapi.codecs.OracleCodec; + +public class SecurityXssValidator { + + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SecurityXssValidator.class); + + private static final String MYSQL_DB = "mysql"; + private static final String ORACLE_DB = "oracle"; + private static final String MARIA_DB = "mariadb"; + private static final int FLAGS = Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL; + static SecurityXssValidator validator = null; + private static Codec instance; + private static final Lock lock = new ReentrantLock(); + + public static SecurityXssValidator getInstance() { + + if (validator == null) { + lock.lock(); + try { + if (validator == null) + validator = new SecurityXssValidator(); + } finally { + lock.unlock(); + } + } + + return validator; + } + + private SecurityXssValidator() { + // Avoid anything between script tags + XSS_INPUT_PATTERNS.add(Pattern.compile("", FLAGS)); + + // avoid iframes + XSS_INPUT_PATTERNS.add(Pattern.compile("(.*?)", FLAGS)); + + // Avoid anything in a src='...' type of expression + XSS_INPUT_PATTERNS.add(Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'", FLAGS)); + + XSS_INPUT_PATTERNS.add(Pattern.compile("src[\r\n]*=[\r\n]*\\\"(.*?)\\\"", FLAGS)); + + XSS_INPUT_PATTERNS.add(Pattern.compile("src[\r\n]*=[\r\n]*([^>]+)", FLAGS)); + + // Remove any lonesome tag + XSS_INPUT_PATTERNS.add(Pattern.compile("", FLAGS)); + + XSS_INPUT_PATTERNS.add(Pattern.compile(".*().*", FLAGS)); + + XSS_INPUT_PATTERNS.add(Pattern.compile(".*().*", FLAGS)); + + // Remove any lonesome diff --git a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-admin.jsp b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-admin.jsp index 03d04b81..2bd21813 100644 --- a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-admin.jsp +++ b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-admin.jsp @@ -2,11 +2,11 @@ ============LICENSE_START========================================== ONAP Portal =================================================================== - Copyright © 2017 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. =================================================================== Unless otherwise specified, all software contained herein is licensed - under the Apache License, Version 2.0 (the “License”); + under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at @@ -19,7 +19,7 @@ limitations under the License. Unless otherwise specified, all documentation contained herein is licensed - under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + under the Creative Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except in compliance with the License. You may obtain a copy of the License at diff --git a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-home.jsp b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-home.jsp index 9d143592..92c88b15 100644 --- a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-home.jsp +++ b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-home.jsp @@ -2,11 +2,11 @@ ============LICENSE_START========================================== ONAP Portal =================================================================== - Copyright © 2017 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. =================================================================== Unless otherwise specified, all software contained herein is licensed - under the Apache License, Version 2.0 (the “License”); + under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at @@ -19,7 +19,7 @@ limitations under the License. Unless otherwise specified, all documentation contained herein is licensed - under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + under the Creative Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except in compliance with the License. You may obtain a copy of the License at diff --git a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-login.jsp b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-login.jsp index 47ef2491..9989f33e 100644 --- a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-login.jsp +++ b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-login.jsp @@ -2,11 +2,11 @@ ============LICENSE_START========================================== ONAP Portal =================================================================== - Copyright © 2017 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. =================================================================== Unless otherwise specified, all software contained herein is licensed - under the Apache License, Version 2.0 (the “License”); + under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at @@ -19,7 +19,7 @@ limitations under the License. Unless otherwise specified, all documentation contained herein is licensed - under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + under the Creative Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except in compliance with the License. You may obtain a copy of the License at diff --git a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-user.jsp b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-user.jsp index e2440327..38262ae3 100644 --- a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-user.jsp +++ b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/jsp/oid-user.jsp @@ -2,11 +2,11 @@ ============LICENSE_START========================================== ONAP Portal =================================================================== - Copyright © 2017 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. =================================================================== Unless otherwise specified, all software contained herein is licensed - under the Apache License, Version 2.0 (the “License”); + under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at @@ -19,7 +19,7 @@ limitations under the License. Unless otherwise specified, all documentation contained herein is licensed - under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + under the Creative Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except in compliance with the License. You may obtain a copy of the License at diff --git a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/oid-context.xml b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/oid-context.xml index 3eed49a0..119f9e54 100644 --- a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/oid-context.xml +++ b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/oid-context.xml @@ -3,11 +3,11 @@ ============LICENSE_START========================================== ONAP Portal =================================================================== - Copyright © 2017 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. =================================================================== Unless otherwise specified, all software contained herein is licensed - under the Apache License, Version 2.0 (the “License”); + under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at @@ -20,7 +20,7 @@ limitations under the License. Unless otherwise specified, all documentation contained herein is licensed - under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + under the Creative Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except in compliance with the License. You may obtain a copy of the License at @@ -46,12 +46,12 @@ xmlns:oauth="http://www.springframework.org/schema/security/oauth2" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd - http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd - http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd - http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> + http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"> @@ -95,7 +95,7 @@ - + diff --git a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/web.xml b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/web.xml index 1480a517..ee60d326 100644 --- a/ecomp-portal-BE-os/src/main/webapp/WEB-INF/web.xml +++ b/ecomp-portal-BE-os/src/main/webapp/WEB-INF/web.xml @@ -3,11 +3,11 @@ ============LICENSE_START========================================== ONAP Portal =================================================================== - Copyright © 2017 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. =================================================================== Unless otherwise specified, all software contained herein is licensed - under the Apache License, Version 2.0 (the “License”); + under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at @@ -20,7 +20,7 @@ limitations under the License. Unless otherwise specified, all documentation contained herein is licensed - under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + under the Creative Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except in compliance with the License. You may obtain a copy of the License at @@ -54,7 +54,7 @@ - + - org.openecomp.portalapp.portal.listener.UserSessionListener + org.onap.portalapp.portal.listener.UserSessionListener @@ -88,18 +88,13 @@ /* - - springSecurityFilterChain - org.springframework.web.filter.DelegatingFilterProxy - + + SecurityXssFilter + org.onap.portalapp.filter.SecurityXssFilter - + - springSecurityFilterChain + SecurityXssFilter /* - diff --git a/ecomp-portal-BE-os/src/main/webapp/app/fusion/external/ds2/css/digital-ng-library/ecomp-ionicons.css b/ecomp-portal-BE-os/src/main/webapp/app/fusion/external/ds2/css/digital-ng-library/ecomp-ionicons.css index 0bbd8a3f..150124b2 100644 --- a/ecomp-portal-BE-os/src/main/webapp/app/fusion/external/ds2/css/digital-ng-library/ecomp-ionicons.css +++ b/ecomp-portal-BE-os/src/main/webapp/app/fusion/external/ds2/css/digital-ng-library/ecomp-ionicons.css @@ -37,6 +37,7 @@ .icon-people-oneperson-stalker:before, .icon-controls-pointer:before, .icon-arrows-replay-restart:before, .icon-content-star:before, .icon-misc-trash:before, .icon-arrows-upload:before, +.icon-controls-moreapplications:before, .icon-controls-upPRIMARY, .ion-navicon { display: inline-block; @@ -154,3 +155,5 @@ .icon-controls-upPRIMARY:before { content: "\f3d8"; } .ion-navicon:before { content: "\f20e"; } + +.icon-controls-moreapplications:before { content: "\f20b"; } diff --git a/ecomp-portal-BE-os/src/main/webapp/index.jsp b/ecomp-portal-BE-os/src/main/webapp/index.jsp index f63bfa11..8b543da4 100644 --- a/ecomp-portal-BE-os/src/main/webapp/index.jsp +++ b/ecomp-portal-BE-os/src/main/webapp/index.jsp @@ -2,11 +2,11 @@ ============LICENSE_START========================================== ONAP Portal =================================================================== - Copyright © 2017 AT&T Intellectual Property. All rights reserved. + Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. =================================================================== Unless otherwise specified, all software contained herein is licensed - under the Apache License, Version 2.0 (the “License”); + under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at @@ -19,7 +19,7 @@ limitations under the License. Unless otherwise specified, all documentation contained herein is licensed - under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + under the Creative Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except in compliance with the License. You may obtain a copy of the License at diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java new file mode 100644 index 00000000..58e596ae --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java @@ -0,0 +1,155 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.authentication; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalapp.authentication.OpenIdConnectLoginStrategy; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.utils.EPSystemProperties; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalapp.util.SessionCookieUtil; +import org.onap.portalsdk.core.onboarding.exception.PortalAPIException; +import org.onap.portalsdk.core.util.SystemProperties; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mitre.openid.connect.model.DefaultUserInfo; +import org.mitre.openid.connect.model.UserInfo; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.util.StringUtils; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({StringUtils.class, EPUserUtils.class , SessionCookieUtil.class,SystemProperties.class}) +public class OpenIdConnectLoginStrategyTest { + + @InjectMocks + OpenIdConnectLoginStrategy OpenIdConnectLoginStrategy = new OpenIdConnectLoginStrategy(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void loginTest() throws Exception + { + PowerMockito.mockStatic(StringUtils.class); + PowerMockito.mockStatic(EPUserUtils.class); + PowerMockito.mockStatic(SessionCookieUtil.class); + + UserInfo userInfo = new DefaultUserInfo(); + userInfo.setPreferredUsername("Test"); + userInfo.setEmail("test@gmail.com"); + userInfo.setName("first_name"); + userInfo.setFamilyName("last_name"); + Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); + assertTrue(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfUserNullTest() throws Exception + { + PowerMockito.mockStatic(SystemProperties.class); + UserInfo userInfo = null; + Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); +// Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("auth"); + assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfUserIfAuthIsOIDCTest() throws Exception + { + PowerMockito.mockStatic(SystemProperties.class); + UserInfo userInfo = null; + Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); + Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("OIDC"); + Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url"); + assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfUserIfAuthNotNullTest() throws Exception + { + PowerMockito.mockStatic(SystemProperties.class); + UserInfo userInfo = null; + Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); + Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("test"); + Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url"); + assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfUserExceptionest() throws Exception + { + PowerMockito.mockStatic(SystemProperties.class); + UserInfo userInfo = null; + Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); + Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenThrow(nullPointerException); + Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url"); + assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); + } + @Test(expected = Exception.class) + public void doLoginTest() throws Exception + { + OpenIdConnectLoginStrategy.doLogin(mockedRequest, mockedResponse); + } + + @Test(expected = PortalAPIException.class) + public void getUserIdTest() throws Exception + { + OpenIdConnectLoginStrategy.getUserId(mockedRequest); + } + +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java new file mode 100644 index 00000000..11b54bf7 --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.authentication; + +import static org.junit.Assert.assertFalse; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.authentication.LoginStrategy; +import org.onap.portalapp.authentication.SimpleLoginStrategy; +import org.onap.portalapp.controller.EPFusionBaseController; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.interceptor.SessionTimeoutInterceptor; +import org.springframework.web.method.HandlerMethod; + +public class SessionTimeoutInterceptorTest { + + + @Mock + LoginStrategy loginStrategy = new SimpleLoginStrategy(); + + @Mock + EPFusionBaseController ePFusionBaseController = new EPFusionBaseController() { + }; + + @Mock + HandlerMethod handlerMethod; + + @InjectMocks + SessionTimeoutInterceptor sessionTimeoutInterceptor = new SessionTimeoutInterceptor(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Test + public void preHandleTest() throws Exception{ + assertFalse(sessionTimeoutInterceptor.preHandle(mockedRequest, mockedResponse, ePFusionBaseController)); + } + + @Test + public void preHandleTestIfMethodIsinstanceOfHandlerMethod() throws Exception{ + assertFalse(sessionTimeoutInterceptor.preHandle(mockedRequest, mockedResponse, handlerMethod)); + } +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/SimpleLoginStrategyTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/SimpleLoginStrategyTest.java new file mode 100644 index 00000000..1a3972f6 --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/authentication/SimpleLoginStrategyTest.java @@ -0,0 +1,171 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.authentication; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +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.onap.portalapp.authentication.SimpleLoginStrategy; +import org.onap.portalapp.command.EPLoginBean; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.EPLoginService; +import org.onap.portalapp.portal.service.EPRoleFunctionService; +import org.onap.portalapp.portal.service.EPRoleService; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalapp.util.SessionCookieUtil; +import org.onap.portalsdk.core.menu.MenuProperties; +import org.onap.portalsdk.core.onboarding.exception.PortalAPIException; +import org.onap.portalsdk.core.util.SystemProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.util.StringUtils; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ StringUtils.class, EPUserUtils.class, SessionCookieUtil.class, SystemProperties.class, + SessionCookieUtil.class, MenuProperties.class }) +public class SimpleLoginStrategyTest { + + @InjectMocks + SimpleLoginStrategy simpleLoginStrategy = new SimpleLoginStrategy(); + + @Mock + EPLoginService loginService; + @Mock + EPRoleService roleService; + @Mock + EPRoleFunctionService ePRoleFunctionService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + @Test(expected = Exception.class) + public void loginTest() throws Exception { + PowerMockito.mockStatic(MenuProperties.class); + PowerMockito.mockStatic(SessionCookieUtil.class); + PowerMockito.mockStatic(StringUtils.class); + Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT"); + Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(false); + EPLoginBean commandBean = new EPLoginBean(); + EPUser user = new EPUser(); + commandBean.setUser(user); + commandBean.setOrgUserId("guestT"); + Mockito.when(mockedRequest.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY)) + .thenReturn("menu_properties_filename"); + Mockito.when(loginService.findUser(commandBean, "menu_properties_filename", null)).thenReturn(commandBean); + assertTrue(simpleLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfUserEmptyTest() throws Exception { + PowerMockito.mockStatic(MenuProperties.class); + PowerMockito.mockStatic(SessionCookieUtil.class); + PowerMockito.mockStatic(StringUtils.class); + Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT"); + Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true); + EPLoginBean commandBean = new EPLoginBean(); + EPUser user = new EPUser(); + commandBean.setUser(user); + commandBean.setOrgUserId("guestT"); + assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfAuthIsBothTest() throws Exception { + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(SessionCookieUtil.class); + PowerMockito.mockStatic(StringUtils.class); + Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT"); + Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true); + Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("BOTH"); + assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginIfAuthIsNotNullTest() throws Exception { + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(SessionCookieUtil.class); + PowerMockito.mockStatic(StringUtils.class); + Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT"); + Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true); + Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("Test"); + assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test + public void loginExceptionTest() throws Exception { + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(SessionCookieUtil.class); + PowerMockito.mockStatic(StringUtils.class); + Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT"); + Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true); + Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)) + .thenThrow(nullPointerException); + assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse)); + } + + @Test(expected = Exception.class) + public void doLoginTest() throws Exception { + simpleLoginStrategy.doLogin(mockedRequest, mockedResponse); + } + + @Test(expected = PortalAPIException.class) + public void getUserIdTest() throws Exception { + simpleLoginStrategy.getUserId(mockedRequest); + } +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/AppsOSControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/AppsOSControllerTest.java new file mode 100644 index 00000000..565bfdbf --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/AppsOSControllerTest.java @@ -0,0 +1,189 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.controller; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.controller.AppsOSController; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.framework.MockEPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.AdminRolesService; +import org.onap.portalapp.portal.service.EPAppService; +import org.onap.portalapp.portal.service.PersUserAppService; +import org.onap.portalapp.portal.service.UserService; +import org.onap.portalapp.util.EPUserUtils; + +public class AppsOSControllerTest { + + @Mock + AdminRolesService adminRolesService; + + @Mock + EPAppService appService; + + @Mock + PersUserAppService persUserAppService; + + @Mock + UserService userService; + + @Mock + EPUserUtils ePUserUtils; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + AppsOSController appsOSController = new AppsOSController(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + + @Test + public void saveNewUserIfUserISNullTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("failure"); + expectedportalRestResponse.setResponse("New User cannot be null or empty"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + PortalRestResponse actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, null); + assertEquals(expectedportalRestResponse, actualPortalRestResponse); + } + + @Test + @Ignore + public void saveNewUserIfUserNOtNullTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("failure"); + expectedportalRestResponse.setResponse("UnAuthorized"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + EPUser user = mockUser.mockEPUser(); + EPUser user1 = mockUser.mockEPUser(); + user1.setLoginId("guest"); + user.setLoginId("guestT"); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user1); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + PortalRestResponse actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, user); + assertEquals(expectedportalRestResponse, actualPortalRestResponse); + } + + @Test + public void saveNewUserAndLoggedInUserIdSameTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Success"); + expectedportalRestResponse.setResponse(""); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + EPUser user = mockUser.mockEPUser(); + user.setLoginId("guestT"); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(mockedRequest.getParameter("isCheck")).thenReturn("test"); + Mockito.when(userService.saveNewUser(user, "test")).thenReturn("Success"); + PortalRestResponse actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, user); + assertEquals(expectedportalRestResponse, actualPortalRestResponse); + } + + @Test + public void saveNewUserexceptionest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("failure"); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + EPUser user = mockUser.mockEPUser(); + user.setLoginId("guestT"); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(mockedRequest.getParameter("isCheck")).thenReturn("test"); + Mockito.when(userService.saveNewUser(user, "test")).thenThrow(nullPointerException); + PortalRestResponse actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, user); + assertEquals(expectedportalRestResponse, actualPortalRestResponse); + } + + @Test + public void getCurrentUserProfileTest() { + String loginId = "guestT"; + EPUser user = mockUser.mockEPUser(); + List expectedList = new ArrayList(); + expectedList.add(user); + Mockito.when(userService.getUserByUserId(loginId)).thenReturn(expectedList); + String expectedString = appsOSController.getCurrentUserProfile(mockedRequest, loginId); + assertEquals("{\"firstName\":\"test\",\"lastName\":\"test\"}", expectedString); + } + + @Test + public void getCurrentUserProfileExceptionTest() { + String loginId = "guestT"; + EPUser user = mockUser.mockEPUser(); + List expectedList = new ArrayList(); + expectedList.add(user); + Mockito.when(userService.getUserByUserId(loginId)).thenThrow(nullPointerException); + String expectedString = appsOSController.getCurrentUserProfile(mockedRequest, loginId); + assertEquals("{}", expectedString); + } + +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java new file mode 100644 index 00000000..d2a0c4ea --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java @@ -0,0 +1,360 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.controller; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.controller.DashboardSearchResultController; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.ecomp.model.SearchResultItem; +import org.onap.portalapp.portal.framework.MockEPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.DashboardSearchService; +import org.onap.portalapp.portal.transport.CommonWidget; +import org.onap.portalapp.portal.transport.CommonWidgetMeta; +import org.onap.portalapp.util.EPUserUtils; + +public class DashboardSearchResultControllerTest { + + @Mock + DashboardSearchService searchService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + DashboardSearchResultController dashboardSearchResultController = new DashboardSearchResultController(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + + @Test + public void getWidgetDataTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("success"); + ecpectedPortalRestResponse.setResponse(new CommonWidgetMeta()); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta(); + Mockito.when(searchService.getWidgetData("test")).thenReturn(commonWidgetMeta); + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .getWidgetData(mockedRequest, "test"); + assertEquals(ecpectedPortalRestResponse.getStatus(), actualPortalRestResponse.getStatus()); + } + + @Test + public void saveWidgetDataBulkIfCatrgoryNullTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("ERROR"); + ecpectedPortalRestResponse.setResponse("Category cannot be null or empty"); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta(); + commonWidgetMeta.setCategory(null); + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetDataBulk(commonWidgetMeta); + assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); + } + + @Test + public void saveWidgetDataBulkTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("success"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta(); + commonWidgetMeta.setCategory("test"); + List items = new ArrayList<>(); + + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setEventDate("2017-06-06"); + items.add(commonWidget); + commonWidgetMeta.setItems(items); + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetDataBulk(commonWidgetMeta); + assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); + } + + @Test + public void saveWidgetDataBulkExceptionTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"date\""); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta(); + commonWidgetMeta.setCategory("test"); + List items = new ArrayList<>(); + + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setEventDate("date"); + items.add(commonWidget); + commonWidgetMeta.setItems(items); + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetDataBulk(commonWidgetMeta); + assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); + } + + @Test + public void saveWidgetDataIfCatagoryNullTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("ERROR"); + ecpectedPortalRestResponse.setResponse("Cateogry cannot be null or empty"); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setCategory(null); + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetData(commonWidget); + assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); + } + + @Test + public void saveWidgetDataTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("success"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setCategory("test"); + commonWidget.setId((long) 1); + commonWidget.setEventDate("2017-06-06"); + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetData(commonWidget); + assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); + } + + @Test + public void saveWidgetDataExceptionTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"date\""); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setCategory("test"); + commonWidget.setId((long) 1); + commonWidget.setEventDate("date"); + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetData(commonWidget); + assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); + } + + @Test + public void deleteWidgetDataTest() + { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("success"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + CommonWidget commonWidget = new CommonWidget(); + Mockito.when(searchService.deleteWidgetData(commonWidget)).thenReturn("test"); + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .deleteWidgetData(commonWidget); + assertEquals(ecpectedPortalRestResponse.getStatus(), actualPortalRestResponse.getStatus()); + } + + @Test + public void searchPortalIfUserIsTest() + { + EPUser user = null; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String searchString = "test"; + PortalRestResponse>> expectedResult = new PortalRestResponse>>(); + expectedResult.setMessage("searchPortal: User object is null? - check logs"); + expectedResult.setResponse(new HashMap>()); + expectedResult.setStatus(PortalRestStatusEnum.ERROR); + PortalRestResponse>> actualResult = dashboardSearchResultController + .searchPortal(mockedRequest, searchString); + System.out.println(actualResult); + + assertEquals(expectedResult, actualResult); + } + + + @Test + public void getActiveUsersTest() { + List expectedActiveUsers = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + ; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String userId = user.getOrgUserId(); + Mockito.when(searchService.getRelatedUsers(userId)).thenReturn(expectedActiveUsers); + List actualOnlineUsers = dashboardSearchResultController.getActiveUsers(mockedRequest); + assertEquals(expectedActiveUsers, actualOnlineUsers); + + } + + @Test + public void getActiveUsersExceptionTest() { + List expectedActiveUsers = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String userId = user.getOrgUserId(); + Mockito.when(searchService.getRelatedUsers(userId)).thenThrow(nullPointerException); + List actualOnlineUsers = dashboardSearchResultController.getActiveUsers(mockedRequest); + assertEquals(expectedActiveUsers, actualOnlineUsers); + + } + + @Test + public void activeUsersTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + PortalRestResponse> expectedResult = new PortalRestResponse>(); + expectedResult.setMessage("success"); + expectedResult.setResponse(new ArrayList<>()); + expectedResult.setStatus(PortalRestStatusEnum.OK); + PortalRestResponse> actualResult = dashboardSearchResultController.activeUsers(mockedRequest); + + assertEquals(actualResult, expectedResult); + + } + + @Test + public void activeUsersIfUserNullTest() { + EPUser user = null; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + PortalRestResponse> expectedResult = new PortalRestResponse>(); + expectedResult.setMessage("User object is null? - check logs"); + expectedResult.setResponse(new ArrayList<>()); + expectedResult.setStatus(PortalRestStatusEnum.ERROR); + PortalRestResponse> actualResult = dashboardSearchResultController.activeUsers(mockedRequest); + assertEquals(actualResult, expectedResult); + + } + + @Test + public void activeUsersExceptionTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + PortalRestResponse> expectedResult = new PortalRestResponse>(); + expectedResult.setMessage("null - check logs."); + expectedResult.setResponse(new ArrayList<>()); + expectedResult.setStatus(PortalRestStatusEnum.ERROR); + Mockito.when(searchService.getRelatedUsers(user.getLoginId())).thenThrow(nullPointerException); + PortalRestResponse> actualResult = dashboardSearchResultController.activeUsers(mockedRequest); + assertEquals(actualResult, expectedResult); + + } + + @Test + public void searchPortalIfSearchStringNullTest() { + EPUser user = mockUser.mockEPUser(); + ; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String searchString = null; + + PortalRestResponse>> expectedResult = new PortalRestResponse>>(); + expectedResult.setMessage("searchPortal: String string is null"); + expectedResult.setResponse(new HashMap>()); + expectedResult.setStatus(PortalRestStatusEnum.ERROR); + + PortalRestResponse>> actualResult = dashboardSearchResultController + .searchPortal(mockedRequest, searchString); + assertEquals(expectedResult, actualResult); + } + + @Test + public void searchPortalIfSearchTest() { + EPUser user = mockUser.mockEPUser(); + ; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String searchString = "test"; + List searchResultItemList = new ArrayList(); + SearchResultItem searchResultItem = new SearchResultItem(); + + searchResultItem.setId((long) 1); + searchResultItem.setCategory("test"); + searchResultItem.setName("test_name"); + searchResultItem.setTarget("test_target"); + searchResultItem.setUuid("test_UUId"); + searchResultItemList.add(searchResultItem); + Map> expectedResultMap = new HashMap>(); + expectedResultMap.put(searchString, searchResultItemList); + + PortalRestResponse>> expectedResult = new PortalRestResponse>>(); + expectedResult.setMessage("success"); + expectedResult.setResponse(expectedResultMap); + expectedResult.setStatus(PortalRestStatusEnum.OK); + + Mockito.when(searchService.searchResults(user.getLoginId(), searchString)).thenReturn(expectedResultMap); + PortalRestResponse>> actualResult = dashboardSearchResultController + .searchPortal(mockedRequest, searchString); + assertEquals(expectedResult, actualResult); + + } + + @Test + public void searchPortalIfSearchExcptionTest() { + EPUser user = mockUser.mockEPUser(); + ; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String searchString = "test"; + + PortalRestResponse>> expectedResult = new PortalRestResponse>>(); + expectedResult.setMessage("null - check logs."); + expectedResult.setResponse(new HashMap>()); + expectedResult.setStatus(PortalRestStatusEnum.ERROR); + + Mockito.when(searchService.searchResults(user.getLoginId(), searchString)).thenThrow(nullPointerException); + PortalRestResponse>> actualResult = dashboardSearchResultController + .searchPortal(mockedRequest, searchString); + assertEquals(expectedResult, actualResult); + } + +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ECOMPLogoutControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ECOMPLogoutControllerTest.java new file mode 100644 index 00000000..20f3fe7e --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ECOMPLogoutControllerTest.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.controller; + +import static org.junit.Assert.*; + +import javax.servlet.ServletRequestWrapper; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +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.mockito.stubbing.OngoingStubbing; +import org.onap.portalapp.controller.ECOMPLogoutController; +import org.onap.portalapp.portal.framework.MockEPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.DashboardSearchService; +import org.onap.portalapp.portal.service.DashboardSearchServiceImpl; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalapp.util.EPUserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.core.NamedThreadLocal; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.servlet.ModelAndView; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({EPUserUtils.class, EPCommonSystemProperties.class,RequestContextHolder.class,RequestAttributes.class}) +public class ECOMPLogoutControllerTest { + + @Mock + DashboardSearchService searchService = new DashboardSearchServiceImpl(); + + @InjectMocks + ECOMPLogoutController ecompLogoutController = new ECOMPLogoutController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + MockEPUser mockUser = new MockEPUser(); + + @Mock + RequestContextHolder requestContextHolder; + + @Mock + RequestAttributes requestAttributes; + + @Test + public void logOutTest() throws Exception{ + ModelAndView actualData = new ModelAndView("redirect:login.htm"); + ModelAndView expedtedData = null; + ThreadLocal requestAttributesHolder = + new NamedThreadLocal("Request attributes"); + RequestAttributes requestAttributes = new ServletRequestAttributes(mockedRequest); + PowerMockito.mockStatic(RequestContextHolder.class); + PowerMockito.mockStatic(RequestAttributes.class); + Mockito.when((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).thenReturn((ServletRequestAttributes) requestAttributes); + expedtedData = ecompLogoutController.logOut(mockedRequest, mockedResponse); + assertEquals(actualData.getViewName(),expedtedData.getViewName()); + } + +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerOSTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerOSTest.java new file mode 100644 index 00000000..e8811121 --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerOSTest.java @@ -0,0 +1,199 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.controller; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +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.onap.portalapp.portal.controller.ExternalAppsRestfulController; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.framework.MockEPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.AdminRolesService; +import org.onap.portalapp.portal.service.EPLoginService; +import org.onap.portalapp.portal.service.FunctionalMenuService; +import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson; +import org.onap.portalapp.portal.transport.FunctionalMenuItem; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalapp.portal.utils.EPSystemProperties; +import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.slf4j.MDC; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ MDC.class, EPSystemProperties.class , EcompPortalUtils.class}) +public class ExternalAppsRestfulControllerOSTest { + + + @InjectMocks + ExternalAppsRestfulController externalAppsRestfulController = new ExternalAppsRestfulController(); + @Mock + FunctionalMenuService functionalMenuService; + + @Mock + EPLoginService epLoginService; + + @Mock + AdminRolesService adminRolesService; + + + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + MockEPUser mockUser = new MockEPUser(); + + @Test + public void getFavoritesForUserTest() throws Exception + { + PowerMockito.mockStatic(EPSystemProperties.class); + PowerMockito.mockStatic(MDC.class); + PowerMockito.mockStatic(EcompPortalUtils.class); + EPUser epUser = mockUser.mockEPUser(); + epUser.setId((long) 1); + epUser.setLoginId("guestT"); + String loginId = "guestT"; + Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); + List favorites = new ArrayList(); + FavoritesFunctionalMenuItemJson favoritesFunctionalMenuItemJson = new FavoritesFunctionalMenuItemJson(); + favorites.add(favoritesFunctionalMenuItemJson); + Mockito.when(mockedRequest.getHeader(EPCommonSystemProperties.MDC_LOGIN_ID)).thenReturn("Login_URL"); + Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); + Mockito.when(epLoginService.findUserWithoutPwd("Login_URL")).thenReturn(epUser); + Mockito.when(functionalMenuService.getFavoriteItems(epUser.getId())).thenReturn(favorites); + List actaulFavorites = externalAppsRestfulController + .getFavoritesForUser(mockedRequest, mockedResponse); + assertEquals(actaulFavorites.size(), 1); + } + + @Test + public void getFunctionalMenuItemsForUserIfSuperAdminTest() throws Exception { + PowerMockito.mockStatic(EPSystemProperties.class); + PowerMockito.mockStatic(MDC.class); + PowerMockito.mockStatic(EcompPortalUtils.class); + EPUser epUser = mockUser.mockEPUser(); + epUser.setId((long) 1); + epUser.setLoginId("guestT"); + String loginId = "guestT"; + Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); + Mockito.when(epLoginService.findUserWithoutPwd(loginId)).thenReturn(epUser); + List expectedList = new ArrayList(); + FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem(); + expectedList.add(functionalMenuItem); + Mockito.when(mockedRequest.getHeader("LoginId")).thenReturn("guestT"); + Mockito.when(adminRolesService.isSuperAdmin(epUser)).thenReturn(true); + Mockito.when(functionalMenuService.getFunctionalMenuItems()).thenReturn(expectedList); + List actualList = externalAppsRestfulController.getFunctionalMenuItemsForUser(mockedRequest, + mockedResponse); + assertNull(actualList.get(0).menuId); + } + + @Test(expected = Exception.class) + public void getFunctionalMenuItemsForUserIfUSerNullTest() throws + Exception + { + PowerMockito.mockStatic(EPSystemProperties.class); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(MDC.class); + EPUser epUser = null; + String loginId = "guestT"; + Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); + Mockito.when(epLoginService.findUserWithoutPwd(loginId)).thenReturn(epUser); + externalAppsRestfulController.getFunctionalMenuItemsForUser(mockedRequest, + mockedResponse); + } + + @Test + public void getFunctionalMenuItemsForUserTest() throws Exception { + PowerMockito.mockStatic(EPSystemProperties.class); + PowerMockito.mockStatic(MDC.class); + EPUser epUser = mockUser.mockEPUser(); + epUser.setId((long) 1); + epUser.setLoginId("guestT"); + String loginId = "guestT"; + Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); + Mockito.when(epLoginService.findUserWithoutPwd(loginId)).thenReturn(epUser); + List expectedList = new ArrayList(); + FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem(); + expectedList.add(functionalMenuItem); + Mockito.when(mockedRequest.getHeader("LoginId")).thenReturn("guestT"); + Mockito.when(adminRolesService.isSuperAdmin(epUser)).thenReturn(false); + Mockito.when(functionalMenuService.getFunctionalMenuItemsForUser(epUser.getOrgUserId())) + .thenReturn(expectedList); + List actualList = externalAppsRestfulController.getFunctionalMenuItemsForUser(mockedRequest, + mockedResponse); + assertNull(actualList.get(0).menuId); + } + + @Test(expected = Exception.class) + public void getFavoritesForUserIfUserNullTest() throws Exception { + List favorites = new ArrayList(); + FavoritesFunctionalMenuItemJson favoritesFunctionalMenuItemJson = new FavoritesFunctionalMenuItemJson(); + favorites.add(favoritesFunctionalMenuItemJson); + PowerMockito.mockStatic(EPSystemProperties.class); + PowerMockito.mockStatic(MDC.class); + Mockito.when(mockedRequest.getHeader(EPSystemProperties.MDC_LOGIN_ID)).thenReturn("Login_URL"); + Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); + EPUser epUser = null; + externalAppsRestfulController.getFavoritesForUser(mockedRequest, mockedResponse); + } + + +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/LoginControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/LoginControllerTest.java new file mode 100644 index 00000000..983584e9 --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/LoginControllerTest.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.controller; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +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.onap.portalapp.controller.LoginController; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.EPLoginService; +import org.onap.portalapp.portal.service.EPRoleFunctionService; +import org.onap.portalapp.portal.service.EPRoleService; +import org.onap.portalapp.portal.service.SharedContextService; +import org.onap.portalapp.service.EPProfileService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.web.servlet.ModelAndView; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(SystemProperties.class) +public class LoginControllerTest { + + @Mock + EPProfileService service; + @Mock + EPLoginService loginService; + @Mock + SharedContextService sharedContextService; + @Mock + EPRoleService roleService; + @Mock + EPRoleFunctionService ePRoleFunctionService; + + @InjectMocks + LoginController loginController = new LoginController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void loginIfAuthNullTest() + { + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn(null); + ModelAndView result = loginController.login(mockedRequest); + assertEquals(result.getViewName(),"openIdLogin") ; + } + + @Test + public void loginIfAuthOIDCTest() + { + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("OIDC"); + ModelAndView result = loginController.login(mockedRequest); + assertEquals(result.getViewName(),"login") ; + } + + @Test + public void loginTest() + { + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("Test"); + ModelAndView result = loginController.login(mockedRequest); + assertEquals(result.getViewName(),"login") ; + } +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ONAPLoginControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ONAPLoginControllerTest.java new file mode 100644 index 00000000..ab01a0ce --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ONAPLoginControllerTest.java @@ -0,0 +1,128 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.ONAPLoginController; +import org.onap.portalapp.portal.framework.MockEPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalsdk.core.auth.LoginStrategy; +import org.onap.portalsdk.core.service.LoginService; +import org.onap.portalsdk.core.service.ProfileService; +import org.onap.portalsdk.core.service.ProfileServiceImpl; +import org.springframework.web.servlet.ModelAndView; + +public class ONAPLoginControllerTest { + + @Mock + ProfileService ProfileService = new ProfileServiceImpl(); + + @Mock + LoginService mockLoginService; + + @Mock + LoginStrategy loginStrategy ; + + @InjectMocks + ONAPLoginController oNAPLoginController = new ONAPLoginController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + MockEPUser mockUser = new MockEPUser(); + + + @Test + public void doLogin() throws Exception + { + ModelAndView expectedModelandView = null; + ModelAndView actualModelandView = null; + Mockito.when(loginStrategy.doLogin(mockedRequest, mockedResponse)).thenReturn(expectedModelandView); + actualModelandView= oNAPLoginController.doLogin(mockedRequest, mockedResponse); + oNAPLoginController.setViewName("test"); + assertEquals("test", oNAPLoginController.getViewName()); + assertEquals(actualModelandView,expectedModelandView); + } + + + @Test + public void ViewTest() throws Exception + { + ModelAndView expectedModelandView = new ModelAndView(); + expectedModelandView.setViewName("testView"); + ModelAndView actualModelandView = null; + Mockito.when(loginStrategy.doLogin(mockedRequest, mockedResponse)).thenReturn(expectedModelandView); + actualModelandView= oNAPLoginController.doLogin(mockedRequest, mockedResponse); + assertEquals(actualModelandView.getViewName(),expectedModelandView.getViewName()); + } + @Test + public void getJessionIdTest() throws Exception + { + assertNull(oNAPLoginController.getJessionId(mockedRequest)); + } + + @Test + public void getLoginServiceTest() throws Exception + { + LoginService expectedLoginService = oNAPLoginController.getLoginService(); + assertEquals(mockLoginService,expectedLoginService); + } + + + +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ONAPWelcomeControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ONAPWelcomeControllerTest.java new file mode 100644 index 00000000..c9c18b7a --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/ONAPWelcomeControllerTest.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.controller; + +import static org.junit.Assert.*; + +import java.security.Principal; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.ONAPWelcomeController; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.springframework.ui.Model; +import org.springframework.web.servlet.ModelAndView; + +public class ONAPWelcomeControllerTest { + + @InjectMocks + ONAPWelcomeController oNAPWelcomeController = new ONAPWelcomeController(); + + @Mock + Principal p; + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void getIndexPageTest() + { + assertEquals(oNAPWelcomeController.getIndexPage(mockedRequest), "/index"); + } + + @Test + public void getEcompSinglePageTest() + { + assertEquals(oNAPWelcomeController.getEcompSinglePage(mockedRequest, mockedResponse), "forward:/index.html"); + } + + @Test + public void userTest() + { + assertEquals(oNAPWelcomeController.user(null), "oid-user"); + } + + @Test + public void loginTest() + { + ModelAndView expectedView = new ModelAndView(); + expectedView.setViewName("openIdLogin"); + ModelAndView md = oNAPWelcomeController.login(p); + System.out.println(md.getViewName()); + assertEquals(md.getViewName(), expectedView.getViewName()); + } +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerOSTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerOSTest.java new file mode 100644 index 00000000..a8d8e498 --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerOSTest.java @@ -0,0 +1,242 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.controller.PortalAdminController; +import org.onap.portalapp.portal.domain.EPRole; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.framework.MockEPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.AdminRolesService; +import org.onap.portalapp.portal.service.AdminRolesServiceImpl; +import org.onap.portalapp.portal.service.PortalAdminService; +import org.onap.portalapp.portal.service.PortalAdminServiceImpl; +import org.onap.portalapp.portal.transport.FieldsValidator; +import org.onap.portalapp.portal.transport.PortalAdmin; +import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.service.AuditService; +import org.onap.portalsdk.core.service.AuditServiceImpl; + +public class PortalAdminControllerOSTest { + + @InjectMocks + PortalAdminController portalAdminController = new PortalAdminController(); + + @Mock + AdminRolesService adminRolesService = new AdminRolesServiceImpl(); + + @Mock + PortalAdminService portalAdminService = new PortalAdminServiceImpl(); + + @Mock + AuditService auditService = new AuditServiceImpl(); + + + @Mock + EcompPortalUtils ecompPortalUtils = new EcompPortalUtils(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Mock + EPUserUtils ePUserUtils = new EPUserUtils(); + + MockEPUser mockUser = new MockEPUser(); + + @Test + public void deletePortalAdminIfUserIsSuperAdminTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Long userInfo = (long) 12; + assertNull(portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse)); + + } + + @Test + public void deletePortalAdminTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + FieldsValidator actualFieldValidator = new FieldsValidator(); + Long userInfo = (long) 12; + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(portalAdminService.deletePortalAdmin((long) 12)).thenReturn(expectedFieldValidator); + actualFieldValidator = portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse); + assertEquals(actualFieldValidator,expectedFieldValidator); + + } + + @Test + public void deletePortalAdminWithNoUserInfoTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Long userInfo = null; + assertNull(portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse)); + } + + @Test + public void getRolesByAppExceptionTest() + { + EPUser user = mockUser.mockEPUser();; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedRoleList = new ArrayList(); + EPRole ePRole = new EPRole(); + expectedRoleList.add(ePRole); + Long appId = (long) 1; + Mockito.when(adminRolesService.getRolesByApp(user, appId)).thenThrow(nullPointerException); + assertNull(portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse)); + } + + @Test + public void getRolesByAppIfUserNullTest() + { + EPUser user = null; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Long appId = (long) 1; + assertNull(portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse)); + } + + @Test + public void getRolesByAppTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedRoleList = new ArrayList(); + EPRole ePRole = new EPRole(); + expectedRoleList.add(ePRole); + Long appId = (long) 1; + Mockito.when(adminRolesService.getRolesByApp(user, appId)).thenReturn(expectedRoleList); + List actualRoleList = portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse); + assertEquals(actualRoleList,expectedRoleList); + } + + @Test + public void createPortalAdminIfUserNullTest() + { + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null); + assertNull(portalAdminController.createPortalAdmin(mockedRequest, "guestT", mockedResponse)); + } + + + @Test + public void createPortalAdminIfUserIsSuperAdminTest() + { + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + FieldsValidator actualFieldValidator = new FieldsValidator(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(portalAdminService.createPortalAdmin("guestT")).thenReturn(expectedFieldValidator); + actualFieldValidator = portalAdminController.createPortalAdmin(mockedRequest, "guestT", mockedResponse); + assertEquals(actualFieldValidator,expectedFieldValidator); + } + + @Test + public void createPortalAdminIfUserIsNotSuperAdminTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + assertNull(portalAdminController.createPortalAdmin(mockedRequest, "guestT", mockedResponse)); + } + + @Test + public void getPortalAdminsIfUserNullTest() + { + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null); + assertNull(portalAdminController.getPortalAdmins(mockedRequest, mockedResponse)); + } + + @Test + public void getPortalAdminsIfUserAdminTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List portalAdmins = new ArrayList<>(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(portalAdminService.getPortalAdmins()).thenReturn(portalAdmins); + List actualortalAdmins = portalAdminController.getPortalAdmins(mockedRequest, mockedResponse); + assertEquals(actualortalAdmins,portalAdmins); + } + + @Test + public void getPortalAdminIfUserIsNotSuperAdminTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + assertNull(portalAdminController.getPortalAdmins(mockedRequest, mockedResponse)); + } +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/framework/MockEPUser.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/framework/MockEPUser.java new file mode 100644 index 00000000..99c96547 --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/framework/MockEPUser.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.framework; + +import java.util.Date; + +import org.onap.portalapp.portal.domain.EPUser; + +public class MockEPUser { + + public EPUser mockEPUser() { + + EPUser ePUser = new EPUser(); + ePUser.setOrgId(null); + ePUser.setManagerId(null); + ePUser.setFirstName("test"); + ePUser.setLastName("test"); + ePUser.setMiddleInitial(null); + ePUser.setPhone(null); + ePUser.setFax(null); + ePUser.setCellular(null); + ePUser.setEmail(null); + ePUser.setAddressId(null); + ePUser.setAlertMethodCd(null); + ePUser.setHrid(null); + ePUser.setOrgUserId("guestT"); + ePUser.setOrgCode(null); + ePUser.setAddress1(null); + ePUser.setAddress2(null); + ePUser.setCity(null); + ePUser.setState(null); + ePUser.setZipCode(null); + ePUser.setCountry(null); + ePUser.setOrgManagerUserId(null); + ePUser.setLocationClli(null); + ePUser.setBusinessCountryCode(null); + ePUser.setBusinessCountryName(null); + ePUser.setBusinessUnit(null); + ePUser.setBusinessUnitName(null); + ePUser.setDepartment(null); + ePUser.setDepartmentName(null); + ePUser.setCompanyCode(null); + ePUser.setCompany(null); + ePUser.setZipCodeSuffix(null); + ePUser.setJobTitle(null); + ePUser.setCommandChain(null); + ePUser.setSiloStatus(null); + ePUser.setCostCenter(null); + ePUser.setFinancialLocCode(null); + + ePUser.setLoginId(null); + ePUser.setLoginPwd(null); + Date date = new Date(); + ePUser.setLastLoginDate(date); + ePUser.setActive(true); + ePUser.setInternal(false); + ePUser.setSelectedProfileId(null); + ePUser.setTimeZoneId(null); + ePUser.setOnline(true); + ePUser.setChatId(null); + ePUser.setUserApps(null); + ePUser.setPseudoRoles(null); + + ePUser.setId((long) -1); + return ePUser; + } +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/framework/MockitoTestSuite.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/framework/MockitoTestSuite.java new file mode 100644 index 00000000..219bc860 --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/framework/MockitoTestSuite.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.framework; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class MockitoTestSuite { + + + public MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper( + Mockito.mock(HttpServletRequest.class)); + public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class); + + public MockHttpServletRequestWrapper getMockedRequest() { + return mockedRequest; + } + + public HttpServletResponse getMockedResponse() { + return mockedResponse; + } + + public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper { + + HttpSession session = Mockito.mock(HttpSession.class); + + public MockHttpServletRequestWrapper(HttpServletRequest request) { + super(request); + + } + + @Override + public HttpSession getSession() { + + return session; + } + + @Override + public HttpSession getSession(boolean create) { + + return session; + } + + } + @Test + public void test() + { + assert(true); + } +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/listener/HealthMonitorTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/listener/HealthMonitorTest.java new file mode 100644 index 00000000..929c8e36 --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/listener/HealthMonitorTest.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.listener; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.listener.HealthMonitor; + +public class HealthMonitorTest { + + @Test + public void initialFlagsTest() { + assertEquals(false, HealthMonitor.isBackEndUp()); + assertEquals(false, HealthMonitor.isFrontEndUp()); + assertEquals(false, HealthMonitor.isDatabaseUp()); + assertEquals(false, HealthMonitor.isUebUp()); + } + +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java new file mode 100644 index 00000000..ad208f39 --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java @@ -0,0 +1,186 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.service; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.portalsdk.core.util.SystemProperties; +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.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.AppsCacheService; +import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.onap.portalapp.service.RemoteWebServiceCallServiceImpl; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.service.DataAccessService; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ CipherUtil.class , SystemProperties.class}) +public class RemoteWebServiceCallServiceImplTest { + + + @InjectMocks + RemoteWebServiceCallServiceImpl remoteWebServiceCallServiceImpl = new RemoteWebServiceCallServiceImpl(); + + @Mock + AppsCacheService appCacheService; + + @Mock + DataAccessService dataAccessService; + + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void verifyRESTCredentialTest() throws Exception + { + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(SystemProperties.class); + String criteria= " where ueb_key = 'requestUebKey'"; + List appList = new ArrayList<>(); + EPApp app = new EPApp(); + app.setAppPassword("password"); + appList.add(app); + Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList); + String secretKey = null; + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); + Mockito.when(CipherUtil.decryptPKC("password", + secretKey == null ? null : secretKey)).thenReturn("pwd"); + assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","requestPassword")); + } + + @Test + public void verifyRESTCredentialExceptionTest() throws Exception + { + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(SystemProperties.class); + String criteria= " where ueb_key = 'requestUebKey'"; + List appList = new ArrayList<>(); + EPApp app = new EPApp(); + app.setAppPassword("password"); + app.setUsername("requestAppName"); + appList.add(app); + Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList); + String secretKey = null; + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); + Mockito.when(CipherUtil.decryptPKC("password", + secretKey == null ? null : secretKey)).thenReturn("pwd"); + assertTrue(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd")); + } + + @Test + public void verifyRESTCredentialIfAppNullTest() throws Exception + { + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(SystemProperties.class); + String criteria= " where ueb_key = 'requestUebKey'"; + List appList = new ArrayList<>(); + EPApp app = new EPApp(); + app.setAppPassword("password"); + app.setUsername("requestAppName"); + appList.add(app); + Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null); + String secretKey = null; + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); + Mockito.when(CipherUtil.decryptPKC("password", + secretKey == null ? null : secretKey)).thenReturn("pwd"); + assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd")); + } + + @Test + public void verifyAppKeyCredentialIfKeyIsNullTest() throws Exception + { + assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential(null)); + } + + @Test + public void verifyAppKeyCredentialTest() throws Exception + { + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(SystemProperties.class); + StringBuffer criteria = new StringBuffer("where ueb_key = 'requestUebKey'"); +// String criteria= " where ueb_key = 'requestUebKey'"; + List appList = new ArrayList<>(); + EPApp app = new EPApp(); + app.setAppPassword("password"); + app.setUsername("requestAppName"); + appList.add(app); + Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null); + assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test")); + } + + @Test + public void verifyAppKeyCredentialSuccessTest() throws Exception + { + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(SystemProperties.class); + String criteria= " where ueb_key = 'test'"; + List appList = new ArrayList<>(); + EPApp app = new EPApp(); + app.setAppPassword("password"); + app.setUsername("requestAppName"); + appList.add(app); + Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList); + assertTrue(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test")); + } +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/SearchServiceImplTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/SearchServiceImplTest.java new file mode 100644 index 00000000..339f4ebb --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/SearchServiceImplTest.java @@ -0,0 +1,228 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.service; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +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.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.framework.MockEPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.SearchServiceImpl; +import org.onap.portalapp.portal.service.UserService; +import org.onap.portalapp.portal.transport.UserWithNameSurnameTitle; +import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ EcompPortalUtils.class}) +public class SearchServiceImplTest { + + @InjectMocks + SearchServiceImpl searchServiceImpl = new SearchServiceImpl(); + + @Mock + UserService userService; + + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + + @Test + public void searchUsersInPhoneBookTest() + { + PowerMockito.mockStatic(EcompPortalUtils.class); + List list = new ArrayList<>(); + String str = "Test"; + list.add(str); + Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test", " ")).thenReturn(list); + assertEquals(searchServiceImpl.searchUsersInPhoneBook("Test"), "[]"); + } + + @Test + public void searchUsersInFnTableToFindUserIdTest() + { + PowerMockito.mockStatic(EcompPortalUtils.class); + List list = new ArrayList<>(); + String str = "Test"; + String str2 = "Test new"; + String str1 = "Test new1"; + list.add(str); + list.add(str1); + list.add(str2); + Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test", " ")).thenReturn(list); + List userList = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + user.setLastName("Test new"); + userList.add(user); + Mockito.when( this.userService.getUserByFirstLastName("Test","Test new")).thenReturn(userList); + String result = searchServiceImpl.searchUsersInPhoneBook("Test"); + assertEquals("[{\"orgUserId\":\"guestT\",\"firstName\":\"test\",\"lastName\":\"Test new\",\"jobTitle\":null}]" , result); + } + + + + @Test + public void searchUsersInFnTableFirstNameTest() + { + PowerMockito.mockStatic(EcompPortalUtils.class); + List list = new ArrayList<>(); + String str = "TestTT"; + String str2 = "Test new1"; + String str1 = "Test new"; + String str3 = "Test new2"; + list.add(str); + list.add(str1); + list.add(str2); + list.add(str3); + Mockito.when(EcompPortalUtils.parsingByRegularExpression("TestTT", " ")).thenReturn(list); + List userList = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + user.setLastName("Test new"); + user.setFirstName(null); + userList.add(user); + Mockito.when( this.userService.getUserByFirstLastName("TestTT","Test new")).thenReturn(userList); + assertEquals(searchServiceImpl.searchUsersInPhoneBook("TestTT"), "[]"); } + + + @Test + public void searchUsersInFnTableLastNameTest() + { + PowerMockito.mockStatic(EcompPortalUtils.class); + List list = new ArrayList<>(); + String str = "Test"; + String str2 = "Test new"; + String str1 = "Test new1"; + list.add(str); + list.add(str1); + list.add(str2); + Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test", " ")).thenReturn(list); + List userList = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + user.setLastName(null); + userList.add(user); + Mockito.when( this.userService.getUserByFirstLastName("Test","Test new")).thenReturn(userList); + assertEquals(searchServiceImpl.searchUsersInPhoneBook("Test"), "[]"); } + + + + @Test + public void searchUserByUserIdTest() + { + List userList = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + user.setLastName("Test new"); + userList.add(user); + List foundUsers = new ArrayList(); + Mockito.when(this.userService.getUserByUserId("guestT")).thenReturn(userList); + + EPUser expectedUser = searchServiceImpl.searchUserByUserId("guestT"); + assertEquals(user, expectedUser); + } + + @Test + public void searchUserByUserIdExceptionTest() + { + Mockito.when(this.userService.getUserByUserId("guestT")).thenThrow(nullPointerException); + assertNull(searchServiceImpl.searchUserByUserId("guestT")); + + } + + @Test + public void searchUsersByUserIdTest() + { + + List userList = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + user.setLastName("Test new"); + userList.add(user); + Mockito.when(this.userService.getUserByUserId("guestT")).thenReturn(userList); + List foundUsers = searchServiceImpl.searchUsersByUserId(user); + assertEquals(foundUsers.size(), 1); + + } + + @Test + public void searchUsersByUserIdExceptionTest() + { + EPUser user = mockUser.mockEPUser(); + user.setLastName("Test new"); + Mockito.when(this.userService.getUserByUserId("guestT")).thenThrow(nullPointerException); + List foundUsers = searchServiceImpl.searchUsersByUserId(user); + assertEquals(foundUsers.size(), 0); + + } + + @Test + public void searchUsersByNameExceptionTest() + { + EPUser user = mockUser.mockEPUser(); + user.setLastName("test"); + user.setFirstName("test"); + + Mockito.when(this.userService.getUserByFirstLastName("test","test")).thenThrow(nullPointerException); + List foundUsers = searchServiceImpl.searchUsersByName(user); + assertEquals(foundUsers.size(), 0); + + } +} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/UserServiceImplTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/UserServiceImplTest.java new file mode 100644 index 00000000..f4afb0fe --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/UserServiceImplTest.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.service; +//package org.openecomp.portalapp.portal.service; +// +//import javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpServletResponse; +// +//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.framework.MockitoTestSuite; +//import org.openecomp.portalapp.portal.utils.EPSystemProperties; +//import org.openecomp.portalsdk.core.service.DataAccessService; +//import org.openecomp.portalsdk.core.util.SystemProperties; +//import org.powermock.api.mockito.PowerMockito; +// +//import java.io.BufferedReader; +//import java.io.IOException; +//import java.io.InputStreamReader; +//import java.io.UnsupportedEncodingException; +//import java.net.HttpURLConnection; +//import org.powermock.core.classloader.annotations.PrepareForTest; +//import org.powermock.modules.junit4.PowerMockRunner; +// +// +//@RunWith(PowerMockRunner.class) +//@PrepareForTest({ SystemProperties.class , EPSystemProperties.class , SystemProperties.class}) +//public class UserServiceImplTest { +// +// +// @InjectMocks +// UserServiceImpl userServiceImpl = new UserServiceImpl(); +// +// @Mock +// DataAccessService dataAccessService; +// +// @Mock +// HttpURLConnection con; +// +// @Before +// public void setup() { +// MockitoAnnotations.initMocks(this); +// } +// +// MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); +// +// HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); +// HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); +// +// @Test +// public void getUserByUserIdTest() throws UnsupportedEncodingException, IOException +// { +// BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8")); +// PowerMockito.mockStatic(SystemProperties.class); +// PowerMockito.mockStatic(EPSystemProperties.class); +// Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("OIDC"); +// Mockito.when(EPSystemProperties.getProperty(EPSystemProperties.AUTH_USER_SERVER)).thenReturn("http://www.google.com"); +// Mockito.when(new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"))).thenReturn(reader).thenReturn(reader); +// userServiceImpl.getUserByUserId("guestT"); +// } +//} diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java new file mode 100644 index 00000000..532c7204 --- /dev/null +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software 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. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * 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. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalapp.portal.utils; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.utils.EcompPortalUtils; + +public class EcompPortalUtilsTest { + + + @Test + public void legitimateUserIdFailureTest() { + assertEquals(false, EcompPortalUtils.legitimateUserId("1#@23456")); + } +} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java deleted file mode 100644 index 2d0f795a..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/OpenIdConnectLoginStrategyTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.authentication; - -import static org.junit.Assert.*; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException; -import org.openecomp.portalsdk.core.util.SystemProperties; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mitre.openid.connect.model.DefaultUserInfo; -import org.mitre.openid.connect.model.UserInfo; -import org.mockito.InjectMocks; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.openecomp.portalapp.authentication.OpenIdConnectLoginStrategy; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.portal.utils.EPSystemProperties; -import org.openecomp.portalapp.util.EPUserUtils; -import org.openecomp.portalapp.util.SessionCookieUtil; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.springframework.util.StringUtils; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({StringUtils.class, EPUserUtils.class , SessionCookieUtil.class,SystemProperties.class}) -public class OpenIdConnectLoginStrategyTest { - - @InjectMocks - OpenIdConnectLoginStrategy OpenIdConnectLoginStrategy = new OpenIdConnectLoginStrategy(); - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - NullPointerException nullPointerException = new NullPointerException(); - - @Test - public void loginTest() - { - PowerMockito.mockStatic(StringUtils.class); - PowerMockito.mockStatic(EPUserUtils.class); - PowerMockito.mockStatic(SessionCookieUtil.class); - - UserInfo userInfo = new DefaultUserInfo(); - userInfo.setPreferredUsername("Test"); - userInfo.setEmail("test@gmail.com"); - userInfo.setName("first_name"); - userInfo.setFamilyName("last_name"); - Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); - assertTrue(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); - } - - @Test - public void loginIfUserNullTest() - { - PowerMockito.mockStatic(SystemProperties.class); - UserInfo userInfo = null; - Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); -// Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("auth"); - assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); - } - - @Test - public void loginIfUserIfAuthIsOIDCTest() - { - PowerMockito.mockStatic(SystemProperties.class); - UserInfo userInfo = null; - Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); - Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("OIDC"); - Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url"); - assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); - } - - @Test - public void loginIfUserIfAuthNotNullTest() - { - PowerMockito.mockStatic(SystemProperties.class); - UserInfo userInfo = null; - Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); - Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenReturn("test"); - Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url"); - assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); - } - - @Test - public void loginIfUserExceptionest() - { - PowerMockito.mockStatic(SystemProperties.class); - UserInfo userInfo = null; - Mockito.when(mockedRequest.getAttribute("userInfo")).thenReturn(userInfo); - Mockito.when(SystemProperties.getProperty("authentication_mechanism")).thenThrow(nullPointerException); - Mockito.when(SystemProperties.getProperty(EPSystemProperties.LOGIN_URL_NO_RET_VAL)).thenReturn("login_url"); - assertFalse(OpenIdConnectLoginStrategy.login(mockedRequest, mockedResponse)); - } - @Test(expected = Exception.class) - public void doLoginTest() throws Exception - { - OpenIdConnectLoginStrategy.doLogin(mockedRequest, mockedResponse); - } - - @Test(expected = PortalAPIException.class) - public void getUserIdTest() throws Exception - { - OpenIdConnectLoginStrategy.getUserId(mockedRequest); - } - -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java deleted file mode 100644 index c4946c68..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SessionTimeoutInterceptorTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.authentication; - -import static org.junit.Assert.assertFalse; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.openecomp.portalapp.authentication.LoginStrategy; -import org.openecomp.portalapp.authentication.SimpleLoginStrategy; -import org.openecomp.portalapp.controller.EPFusionBaseController; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.portal.interceptor.SessionTimeoutInterceptor; -import org.springframework.web.method.HandlerMethod; - -public class SessionTimeoutInterceptorTest { - - - @Mock - LoginStrategy loginStrategy = new SimpleLoginStrategy(); - - @Mock - EPFusionBaseController ePFusionBaseController = new EPFusionBaseController() { - }; - - @Mock - HandlerMethod handlerMethod; - - @InjectMocks - SessionTimeoutInterceptor sessionTimeoutInterceptor = new SessionTimeoutInterceptor(); - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - @Test - public void preHandleTest() throws Exception{ - assertFalse(sessionTimeoutInterceptor.preHandle(mockedRequest, mockedResponse, ePFusionBaseController)); - } - - @Test - public void preHandleTestIfMethodIsinstanceOfHandlerMethod() throws Exception{ - assertFalse(sessionTimeoutInterceptor.preHandle(mockedRequest, mockedResponse, handlerMethod)); - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SimpleLoginStrategyTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SimpleLoginStrategyTest.java deleted file mode 100644 index 588bd89c..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/authentication/SimpleLoginStrategyTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.authentication; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -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.authentication.SimpleLoginStrategy; -import org.openecomp.portalapp.command.EPLoginBean; -import org.openecomp.portalapp.portal.domain.EPUser; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.portal.service.EPLoginService; -import org.openecomp.portalapp.portal.service.EPRoleFunctionService; -import org.openecomp.portalapp.portal.service.EPRoleService; -import org.openecomp.portalapp.util.EPUserUtils; -import org.openecomp.portalapp.util.SessionCookieUtil; -import org.openecomp.portalsdk.core.menu.MenuProperties; -import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException; -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; -import org.springframework.util.StringUtils; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ StringUtils.class, EPUserUtils.class, SessionCookieUtil.class, SystemProperties.class, - SessionCookieUtil.class, MenuProperties.class }) -public class SimpleLoginStrategyTest { - - @InjectMocks - SimpleLoginStrategy simpleLoginStrategy = new SimpleLoginStrategy(); - - @Mock - EPLoginService loginService; - @Mock - EPRoleService roleService; - @Mock - EPRoleFunctionService ePRoleFunctionService; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - NullPointerException nullPointerException = new NullPointerException(); - - @Test(expected = Exception.class) - public void loginTest() throws Exception { - PowerMockito.mockStatic(MenuProperties.class); - PowerMockito.mockStatic(SessionCookieUtil.class); - PowerMockito.mockStatic(StringUtils.class); - Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT"); - Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(false); - EPLoginBean commandBean = new EPLoginBean(); - EPUser user = new EPUser(); - commandBean.setUser(user); - commandBean.setOrgUserId("guestT"); - Mockito.when(mockedRequest.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY)) - .thenReturn("menu_properties_filename"); - Mockito.when(loginService.findUser(commandBean, "menu_properties_filename", null)).thenReturn(commandBean); - assertTrue(simpleLoginStrategy.login(mockedRequest, mockedResponse)); - } - - @Test - public void loginIfUserEmptyTest() throws Exception { - PowerMockito.mockStatic(MenuProperties.class); - PowerMockito.mockStatic(SessionCookieUtil.class); - PowerMockito.mockStatic(StringUtils.class); - Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT"); - Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true); - EPLoginBean commandBean = new EPLoginBean(); - EPUser user = new EPUser(); - commandBean.setUser(user); - commandBean.setOrgUserId("guestT"); - assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse)); - } - - @Test - public void loginIfAuthIsBothTest() throws Exception { - PowerMockito.mockStatic(SystemProperties.class); - PowerMockito.mockStatic(SessionCookieUtil.class); - PowerMockito.mockStatic(StringUtils.class); - Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT"); - Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true); - Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("BOTH"); - assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse)); - } - - @Test - public void loginIfAuthIsNotNullTest() throws Exception { - PowerMockito.mockStatic(SystemProperties.class); - PowerMockito.mockStatic(SessionCookieUtil.class); - PowerMockito.mockStatic(StringUtils.class); - Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT"); - Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true); - Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("Test"); - assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse)); - } - - @Test - public void loginExceptionTest() throws Exception { - PowerMockito.mockStatic(SystemProperties.class); - PowerMockito.mockStatic(SessionCookieUtil.class); - PowerMockito.mockStatic(StringUtils.class); - Mockito.when(SessionCookieUtil.getUserIdFromCookie(mockedRequest, mockedResponse)).thenReturn("guestT"); - Mockito.when(StringUtils.isEmpty("guestT")).thenReturn(true); - Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)) - .thenThrow(nullPointerException); - assertFalse(simpleLoginStrategy.login(mockedRequest, mockedResponse)); - } - - @Test(expected = Exception.class) - public void doLoginTest() throws Exception { - simpleLoginStrategy.doLogin(mockedRequest, mockedResponse); - } - - @Test(expected = PortalAPIException.class) - public void getUserIdTest() throws Exception { - simpleLoginStrategy.getUserId(mockedRequest); - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsOSControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsOSControllerTest.java deleted file mode 100644 index eb2ea32e..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/AppsOSControllerTest.java +++ /dev/null @@ -1,186 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.openecomp.portalapp.portal.domain.EPUser; -import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse; -import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum; -import org.openecomp.portalapp.portal.framework.MockEPUser; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.portal.service.AdminRolesService; -import org.openecomp.portalapp.portal.service.EPAppService; -import org.openecomp.portalapp.portal.service.PersUserAppService; -import org.openecomp.portalapp.portal.service.UserService; -import org.openecomp.portalapp.util.EPUserUtils; - -public class AppsOSControllerTest { - - @Mock - AdminRolesService adminRolesService; - - @Mock - EPAppService appService; - - @Mock - PersUserAppService persUserAppService; - - @Mock - UserService userService; - - @Mock - EPUserUtils ePUserUtils; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - @InjectMocks - AppsOSController appsOSController = new AppsOSController(); - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - NullPointerException nullPointerException = new NullPointerException(); - MockEPUser mockUser = new MockEPUser(); - - @Test - public void saveNewUserIfUserISNullTest() { - PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); - expectedportalRestResponse.setMessage("failure"); - expectedportalRestResponse.setResponse("New User cannot be null or empty"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - PortalRestResponse actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, null); - assertEquals(expectedportalRestResponse, actualPortalRestResponse); - } - - @Test - public void saveNewUserIfUserNOtNullTest() { - PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); - expectedportalRestResponse.setMessage("failure"); - expectedportalRestResponse.setResponse("UnAuthorized"); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); - EPUser user = mockUser.mockEPUser(); - EPUser user1 = mockUser.mockEPUser(); - user1.setLoginId("guest"); - user.setLoginId("guestT"); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user1); - Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); - Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); - PortalRestResponse actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, user); - assertEquals(expectedportalRestResponse, actualPortalRestResponse); - } - - @Test - public void saveNewUserAndLoggedInUserIdSameTest() throws Exception { - PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); - expectedportalRestResponse.setMessage("Success"); - expectedportalRestResponse.setResponse(""); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); - EPUser user = mockUser.mockEPUser(); - user.setLoginId("guestT"); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); - Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); - Mockito.when(mockedRequest.getParameter("isCheck")).thenReturn("test"); - Mockito.when(userService.saveNewUser(user, "test")).thenReturn("Success"); - PortalRestResponse actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, user); - assertEquals(expectedportalRestResponse, actualPortalRestResponse); - } - - @Test - public void saveNewUserexceptionest() throws Exception { - PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); - expectedportalRestResponse.setMessage("failure"); - expectedportalRestResponse.setResponse(null); - PortalRestStatusEnum portalRestStatusEnum = null; - expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); - EPUser user = mockUser.mockEPUser(); - user.setLoginId("guestT"); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); - Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); - Mockito.when(mockedRequest.getParameter("isCheck")).thenReturn("test"); - Mockito.when(userService.saveNewUser(user, "test")).thenThrow(nullPointerException); - PortalRestResponse actualPortalRestResponse = appsOSController.saveNewUser(mockedRequest, user); - assertEquals(expectedportalRestResponse, actualPortalRestResponse); - } - - @Test - public void getCurrentUserProfileTest() { - String loginId = "guestT"; - EPUser user = mockUser.mockEPUser(); - List expectedList = new ArrayList(); - expectedList.add(user); - Mockito.when(userService.getUserByUserId(loginId)).thenReturn(expectedList); - String expectedString = appsOSController.getCurrentUserProfile(mockedRequest, loginId); - assertEquals("{\"firstName\":\"test\",\"lastName\":\"test\"}", expectedString); - } - - @Test - public void getCurrentUserProfileExceptionTest() { - String loginId = "guestT"; - EPUser user = mockUser.mockEPUser(); - List expectedList = new ArrayList(); - expectedList.add(user); - Mockito.when(userService.getUserByUserId(loginId)).thenThrow(nullPointerException); - String expectedString = appsOSController.getCurrentUserProfile(mockedRequest, loginId); - assertEquals("{}", expectedString); - } - -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/DashboardSearchResultControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/DashboardSearchResultControllerTest.java deleted file mode 100644 index b2a6c431..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/DashboardSearchResultControllerTest.java +++ /dev/null @@ -1,359 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.openecomp.portalapp.portal.domain.EPUser; -import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse; -import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum; -import org.openecomp.portalapp.portal.ecomp.model.SearchResultItem; -import org.openecomp.portalapp.portal.framework.MockEPUser; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.portal.service.DashboardSearchService; -import org.openecomp.portalapp.portal.transport.CommonWidget; -import org.openecomp.portalapp.portal.transport.CommonWidgetMeta; -import org.openecomp.portalapp.util.EPUserUtils; - -public class DashboardSearchResultControllerTest { - - @Mock - DashboardSearchService searchService; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - @InjectMocks - DashboardSearchResultController dashboardSearchResultController = new DashboardSearchResultController(); - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - NullPointerException nullPointerException = new NullPointerException(); - MockEPUser mockUser = new MockEPUser(); - - @Test - public void getWidgetDataTest() { - PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); - ecpectedPortalRestResponse.setMessage("success"); - ecpectedPortalRestResponse.setResponse(new CommonWidgetMeta()); - ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); - CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta(); - Mockito.when(searchService.getWidgetData("test")).thenReturn(commonWidgetMeta); - PortalRestResponse actualPortalRestResponse = dashboardSearchResultController - .getWidgetData(mockedRequest, "test"); - assertEquals(ecpectedPortalRestResponse.getStatus(), actualPortalRestResponse.getStatus()); - } - - @Test - public void saveWidgetDataBulkIfCatrgoryNullTest() { - PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); - ecpectedPortalRestResponse.setMessage("ERROR"); - ecpectedPortalRestResponse.setResponse("Category cannot be null or empty"); - ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); - CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta(); - commonWidgetMeta.setCategory(null); - PortalRestResponse actualPortalRestResponse = dashboardSearchResultController - .saveWidgetDataBulk(commonWidgetMeta); - assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); - } - - @Test - public void saveWidgetDataBulkTest() { - PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); - ecpectedPortalRestResponse.setMessage("success"); - ecpectedPortalRestResponse.setResponse(null); - ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); - CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta(); - commonWidgetMeta.setCategory("test"); - List items = new ArrayList<>(); - - CommonWidget commonWidget = new CommonWidget(); - commonWidget.setId((long) 1); - commonWidget.setEventDate("2017-06-06"); - items.add(commonWidget); - commonWidgetMeta.setItems(items); - PortalRestResponse actualPortalRestResponse = dashboardSearchResultController - .saveWidgetDataBulk(commonWidgetMeta); - assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); - } - - @Test - public void saveWidgetDataBulkExceptionTest() { - PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); - ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"date\""); - ecpectedPortalRestResponse.setResponse(null); - ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); - CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta(); - commonWidgetMeta.setCategory("test"); - List items = new ArrayList<>(); - - CommonWidget commonWidget = new CommonWidget(); - commonWidget.setId((long) 1); - commonWidget.setEventDate("date"); - items.add(commonWidget); - commonWidgetMeta.setItems(items); - PortalRestResponse actualPortalRestResponse = dashboardSearchResultController - .saveWidgetDataBulk(commonWidgetMeta); - assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); - } - - @Test - public void saveWidgetDataIfCatagoryNullTest() { - PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); - ecpectedPortalRestResponse.setMessage("ERROR"); - ecpectedPortalRestResponse.setResponse("Cateogry cannot be null or empty"); - ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); - CommonWidget commonWidget = new CommonWidget(); - commonWidget.setCategory(null); - PortalRestResponse actualPortalRestResponse = dashboardSearchResultController - .saveWidgetData(commonWidget); - assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); - } - - @Test - public void saveWidgetDataTest() { - PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); - ecpectedPortalRestResponse.setMessage("success"); - ecpectedPortalRestResponse.setResponse(null); - ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); - CommonWidget commonWidget = new CommonWidget(); - commonWidget.setCategory("test"); - commonWidget.setId((long) 1); - commonWidget.setEventDate("2017-06-06"); - PortalRestResponse actualPortalRestResponse = dashboardSearchResultController - .saveWidgetData(commonWidget); - assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); - } - - @Test - public void saveWidgetDataExceptionTest() { - PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); - ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"date\""); - ecpectedPortalRestResponse.setResponse(null); - ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); - CommonWidget commonWidget = new CommonWidget(); - commonWidget.setCategory("test"); - commonWidget.setId((long) 1); - commonWidget.setEventDate("date"); - PortalRestResponse actualPortalRestResponse = dashboardSearchResultController - .saveWidgetData(commonWidget); - assertEquals(ecpectedPortalRestResponse, actualPortalRestResponse); - } - - @Test - public void deleteWidgetDataTest() - { - PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); - ecpectedPortalRestResponse.setMessage("success"); - ecpectedPortalRestResponse.setResponse(null); - ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); - CommonWidget commonWidget = new CommonWidget(); - Mockito.when(searchService.deleteWidgetData(commonWidget)).thenReturn("test"); - PortalRestResponse actualPortalRestResponse = dashboardSearchResultController - .deleteWidgetData(commonWidget); - assertEquals(ecpectedPortalRestResponse.getStatus(), actualPortalRestResponse.getStatus()); - } - - @Test - public void searchPortalIfUserIsTest() - { - EPUser user = null; - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - String searchString = "test"; - PortalRestResponse>> expectedResult = new PortalRestResponse>>(); - expectedResult.setMessage("searchPortal: User object is null? - check logs"); - expectedResult.setResponse(new HashMap>()); - expectedResult.setStatus(PortalRestStatusEnum.ERROR); - PortalRestResponse>> actualResult = dashboardSearchResultController - .searchPortal(mockedRequest, searchString); - System.out.println(actualResult); - - assertEquals(expectedResult, actualResult); - } - - - @Test - public void getActiveUsersTest() { - List expectedActiveUsers = new ArrayList(); - EPUser user = mockUser.mockEPUser(); - ; - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - String userId = user.getOrgUserId(); - Mockito.when(searchService.getRelatedUsers(userId)).thenReturn(expectedActiveUsers); - List actualOnlineUsers = dashboardSearchResultController.getActiveUsers(mockedRequest); - assertEquals(expectedActiveUsers, actualOnlineUsers); - - } - - @Test - public void getActiveUsersExceptionTest() { - List expectedActiveUsers = new ArrayList(); - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - String userId = user.getOrgUserId(); - Mockito.when(searchService.getRelatedUsers(userId)).thenThrow(nullPointerException); - List actualOnlineUsers = dashboardSearchResultController.getActiveUsers(mockedRequest); - assertEquals(expectedActiveUsers, actualOnlineUsers); - - } - - @Test - public void activeUsersTest() { - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - PortalRestResponse> expectedResult = new PortalRestResponse>(); - expectedResult.setMessage("success"); - expectedResult.setResponse(new ArrayList<>()); - expectedResult.setStatus(PortalRestStatusEnum.OK); - PortalRestResponse> actualResult = dashboardSearchResultController.activeUsers(mockedRequest); - - assertEquals(actualResult, expectedResult); - - } - - @Test - public void activeUsersIfUserNullTest() { - EPUser user = null; - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - PortalRestResponse> expectedResult = new PortalRestResponse>(); - expectedResult.setMessage("User object is null? - check logs"); - expectedResult.setResponse(new ArrayList<>()); - expectedResult.setStatus(PortalRestStatusEnum.ERROR); - PortalRestResponse> actualResult = dashboardSearchResultController.activeUsers(mockedRequest); - assertEquals(actualResult, expectedResult); - - } - - @Test - public void activeUsersExceptionTest() { - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - PortalRestResponse> expectedResult = new PortalRestResponse>(); - expectedResult.setMessage("null - check logs."); - expectedResult.setResponse(new ArrayList<>()); - expectedResult.setStatus(PortalRestStatusEnum.ERROR); - Mockito.when(searchService.getRelatedUsers(user.getLoginId())).thenThrow(nullPointerException); - PortalRestResponse> actualResult = dashboardSearchResultController.activeUsers(mockedRequest); - assertEquals(actualResult, expectedResult); - - } - - @Test - public void searchPortalIfSearchStringNullTest() { - EPUser user = mockUser.mockEPUser(); - ; - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - String searchString = null; - - PortalRestResponse>> expectedResult = new PortalRestResponse>>(); - expectedResult.setMessage("searchPortal: String string is null"); - expectedResult.setResponse(new HashMap>()); - expectedResult.setStatus(PortalRestStatusEnum.ERROR); - - PortalRestResponse>> actualResult = dashboardSearchResultController - .searchPortal(mockedRequest, searchString); - assertEquals(expectedResult, actualResult); - } - - @Test - public void searchPortalIfSearchTest() { - EPUser user = mockUser.mockEPUser(); - ; - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - String searchString = "test"; - List searchResultItemList = new ArrayList(); - SearchResultItem searchResultItem = new SearchResultItem(); - - searchResultItem.setId((long) 1); - searchResultItem.setCategory("test"); - searchResultItem.setName("test_name"); - searchResultItem.setTarget("test_target"); - searchResultItem.setUuid("test_UUId"); - searchResultItemList.add(searchResultItem); - Map> expectedResultMap = new HashMap>(); - expectedResultMap.put(searchString, searchResultItemList); - - PortalRestResponse>> expectedResult = new PortalRestResponse>>(); - expectedResult.setMessage("success"); - expectedResult.setResponse(expectedResultMap); - expectedResult.setStatus(PortalRestStatusEnum.OK); - - Mockito.when(searchService.searchResults(user.getLoginId(), searchString)).thenReturn(expectedResultMap); - PortalRestResponse>> actualResult = dashboardSearchResultController - .searchPortal(mockedRequest, searchString); - assertEquals(expectedResult, actualResult); - - } - - @Test - public void searchPortalIfSearchExcptionTest() { - EPUser user = mockUser.mockEPUser(); - ; - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - String searchString = "test"; - - PortalRestResponse>> expectedResult = new PortalRestResponse>>(); - expectedResult.setMessage("null - check logs."); - expectedResult.setResponse(new HashMap>()); - expectedResult.setStatus(PortalRestStatusEnum.ERROR); - - Mockito.when(searchService.searchResults(user.getLoginId(), searchString)).thenThrow(nullPointerException); - PortalRestResponse>> actualResult = dashboardSearchResultController - .searchPortal(mockedRequest, searchString); - assertEquals(expectedResult, actualResult); - } - -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ECOMPLogoutControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ECOMPLogoutControllerTest.java deleted file mode 100644 index 954ff0c4..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ECOMPLogoutControllerTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import static org.junit.Assert.assertEquals; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -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.controller.ECOMPLogoutController; -import org.openecomp.portalapp.portal.framework.MockEPUser; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.portal.service.DashboardSearchService; -import org.openecomp.portalapp.portal.service.DashboardSearchServiceImpl; -import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties; -import org.openecomp.portalapp.util.EPUserUtils; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.springframework.core.NamedThreadLocal; -import org.springframework.web.context.request.RequestAttributes; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; -import org.springframework.web.servlet.ModelAndView; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({EPUserUtils.class, EPCommonSystemProperties.class,RequestContextHolder.class,RequestAttributes.class}) -public class ECOMPLogoutControllerTest { - - @Mock - DashboardSearchService searchService = new DashboardSearchServiceImpl(); - - @InjectMocks - ECOMPLogoutController ecompLogoutController = new ECOMPLogoutController(); - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - NullPointerException nullPointerException = new NullPointerException(); - - MockEPUser mockUser = new MockEPUser(); - - @Mock - RequestContextHolder requestContextHolder; - - @Mock - RequestAttributes requestAttributes; - - @Test - public void logOutTest() throws Exception{ - ModelAndView actualData = new ModelAndView("redirect:login.htm"); - ModelAndView expedtedData = null; - ThreadLocal requestAttributesHolder = - new NamedThreadLocal("Request attributes"); - RequestAttributes requestAttributes = new ServletRequestAttributes(mockedRequest); - PowerMockito.mockStatic(RequestContextHolder.class); - PowerMockito.mockStatic(RequestAttributes.class); - Mockito.when((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).thenReturn((ServletRequestAttributes) requestAttributes); - expedtedData = ecompLogoutController.logOut(mockedRequest, mockedResponse); - assertEquals(actualData.getViewName(),expedtedData.getViewName()); - } - -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ExternalAppsRestfulControllerOSTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ExternalAppsRestfulControllerOSTest.java deleted file mode 100644 index 0f92bb3e..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ExternalAppsRestfulControllerOSTest.java +++ /dev/null @@ -1,198 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -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.EPUser; -import org.openecomp.portalapp.portal.framework.MockEPUser; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.portal.service.AdminRolesService; -import org.openecomp.portalapp.portal.service.EPLoginService; -import org.openecomp.portalapp.portal.service.FunctionalMenuService; -import org.openecomp.portalapp.portal.transport.FavoritesFunctionalMenuItemJson; -import org.openecomp.portalapp.portal.transport.FunctionalMenuItem; -import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties; -import org.openecomp.portalapp.portal.utils.EPSystemProperties; -import org.openecomp.portalapp.portal.utils.EcompPortalUtils; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.slf4j.MDC; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ MDC.class, EPSystemProperties.class , EcompPortalUtils.class}) -public class ExternalAppsRestfulControllerOSTest { - - - @InjectMocks - ExternalAppsRestfulController externalAppsRestfulController = new ExternalAppsRestfulController(); - @Mock - FunctionalMenuService functionalMenuService; - - @Mock - EPLoginService epLoginService; - - @Mock - AdminRolesService adminRolesService; - - - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - NullPointerException nullPointerException = new NullPointerException(); - - MockEPUser mockUser = new MockEPUser(); - - @Test - public void getFavoritesForUserTest() throws Exception - { - PowerMockito.mockStatic(EPSystemProperties.class); - PowerMockito.mockStatic(MDC.class); - PowerMockito.mockStatic(EcompPortalUtils.class); - EPUser epUser = mockUser.mockEPUser(); - epUser.setId((long) 1); - epUser.setLoginId("guestT"); - String loginId = "guestT"; - Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); - List favorites = new ArrayList(); - FavoritesFunctionalMenuItemJson favoritesFunctionalMenuItemJson = new FavoritesFunctionalMenuItemJson(); - favorites.add(favoritesFunctionalMenuItemJson); - Mockito.when(mockedRequest.getHeader(EPCommonSystemProperties.MDC_LOGIN_ID)).thenReturn("Login_URL"); - Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); - Mockito.when(epLoginService.findUserWithoutPwd("Login_URL")).thenReturn(epUser); - Mockito.when(functionalMenuService.getFavoriteItems(epUser.getId())).thenReturn(favorites); - List actaulFavorites = externalAppsRestfulController - .getFavoritesForUser(mockedRequest, mockedResponse); - assertEquals(actaulFavorites.size(), 1); - } - - @Test - public void getFunctionalMenuItemsForUserIfSuperAdminTest() throws Exception { - PowerMockito.mockStatic(EPSystemProperties.class); - PowerMockito.mockStatic(MDC.class); - PowerMockito.mockStatic(EcompPortalUtils.class); - EPUser epUser = mockUser.mockEPUser(); - epUser.setId((long) 1); - epUser.setLoginId("guestT"); - String loginId = "guestT"; - Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); - Mockito.when(epLoginService.findUserWithoutPwd(loginId)).thenReturn(epUser); - List expectedList = new ArrayList(); - FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem(); - expectedList.add(functionalMenuItem); - Mockito.when(mockedRequest.getHeader("LoginId")).thenReturn("guestT"); - Mockito.when(adminRolesService.isSuperAdmin(epUser)).thenReturn(true); - Mockito.when(functionalMenuService.getFunctionalMenuItems()).thenReturn(expectedList); - List actualList = externalAppsRestfulController.getFunctionalMenuItemsForUser(mockedRequest, - mockedResponse); - assertNull(actualList.get(0).menuId); - } - - @Test(expected = Exception.class) - public void getFunctionalMenuItemsForUserIfUSerNullTest() throws - Exception - { - PowerMockito.mockStatic(EPSystemProperties.class); - PowerMockito.mockStatic(EcompPortalUtils.class); - PowerMockito.mockStatic(MDC.class); - EPUser epUser = null; - String loginId = "guestT"; - Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); - Mockito.when(epLoginService.findUserWithoutPwd(loginId)).thenReturn(epUser); - externalAppsRestfulController.getFunctionalMenuItemsForUser(mockedRequest, - mockedResponse); - } - - @Test - public void getFunctionalMenuItemsForUserTest() throws Exception { - PowerMockito.mockStatic(EPSystemProperties.class); - PowerMockito.mockStatic(MDC.class); - EPUser epUser = mockUser.mockEPUser(); - epUser.setId((long) 1); - epUser.setLoginId("guestT"); - String loginId = "guestT"; - Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); - Mockito.when(epLoginService.findUserWithoutPwd(loginId)).thenReturn(epUser); - List expectedList = new ArrayList(); - FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem(); - expectedList.add(functionalMenuItem); - Mockito.when(mockedRequest.getHeader("LoginId")).thenReturn("guestT"); - Mockito.when(adminRolesService.isSuperAdmin(epUser)).thenReturn(false); - Mockito.when(functionalMenuService.getFunctionalMenuItemsForUser(epUser.getOrgUserId())) - .thenReturn(expectedList); - List actualList = externalAppsRestfulController.getFunctionalMenuItemsForUser(mockedRequest, - mockedResponse); - assertNull(actualList.get(0).menuId); - } - - @Test(expected = Exception.class) - public void getFavoritesForUserIfUserNullTest() throws Exception { - List favorites = new ArrayList(); - FavoritesFunctionalMenuItemJson favoritesFunctionalMenuItemJson = new FavoritesFunctionalMenuItemJson(); - favorites.add(favoritesFunctionalMenuItemJson); - PowerMockito.mockStatic(EPSystemProperties.class); - PowerMockito.mockStatic(MDC.class); - Mockito.when(mockedRequest.getHeader(EPSystemProperties.MDC_LOGIN_ID)).thenReturn("Login_URL"); - Mockito.when(MDC.get(EPSystemProperties.PARTNER_NAME)).thenReturn("Test"); - EPUser epUser = null; - externalAppsRestfulController.getFavoritesForUser(mockedRequest, mockedResponse); - } - - -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/LoginControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/LoginControllerTest.java deleted file mode 100644 index a02e1b2f..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/LoginControllerTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import static org.junit.Assert.*; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -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.controller.LoginController; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.portal.service.EPLoginService; -import org.openecomp.portalapp.portal.service.EPRoleFunctionService; -import org.openecomp.portalapp.portal.service.EPRoleService; -import org.openecomp.portalapp.portal.service.SharedContextService; -import org.openecomp.portalapp.service.EPProfileService; -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; -import org.springframework.web.servlet.ModelAndView; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(SystemProperties.class) -public class LoginControllerTest { - - @Mock - EPProfileService service; - @Mock - EPLoginService loginService; - @Mock - SharedContextService sharedContextService; - @Mock - EPRoleService roleService; - @Mock - EPRoleFunctionService ePRoleFunctionService; - - @InjectMocks - LoginController loginController = new LoginController(); - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - NullPointerException nullPointerException = new NullPointerException(); - - @Test - public void loginIfAuthNullTest() - { - PowerMockito.mockStatic(SystemProperties.class); - Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn(null); - ModelAndView result = loginController.login(mockedRequest); - assertEquals(result.getViewName(),"openIdLogin") ; - } - - @Test - public void loginIfAuthOIDCTest() - { - PowerMockito.mockStatic(SystemProperties.class); - Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("OIDC"); - ModelAndView result = loginController.login(mockedRequest); - assertEquals(result.getViewName(),"login") ; - } - - @Test - public void loginTest() - { - PowerMockito.mockStatic(SystemProperties.class); - Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("Test"); - ModelAndView result = loginController.login(mockedRequest); - assertEquals(result.getViewName(),"login") ; - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPLoginControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPLoginControllerTest.java deleted file mode 100644 index 46218302..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPLoginControllerTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.openecomp.portalapp.controller.ONAPLoginController; -import org.openecomp.portalapp.portal.framework.MockEPUser; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalsdk.core.auth.LoginStrategy; -import org.openecomp.portalsdk.core.service.LoginService; -import org.openecomp.portalsdk.core.service.ProfileService; -import org.openecomp.portalsdk.core.service.ProfileServiceImpl; -import org.springframework.web.servlet.ModelAndView; - -public class ONAPLoginControllerTest { - - @Mock - ProfileService ProfileService = new ProfileServiceImpl(); - - @Mock - LoginService mockLoginService; - - @Mock - LoginStrategy loginStrategy ; - - @InjectMocks - ONAPLoginController oNAPLoginController = new ONAPLoginController(); - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - NullPointerException nullPointerException = new NullPointerException(); - - MockEPUser mockUser = new MockEPUser(); - - - @Test - public void doLogin() throws Exception - { - ModelAndView expectedModelandView = null; - ModelAndView actualModelandView = null; - Mockito.when(loginStrategy.doLogin(mockedRequest, mockedResponse)).thenReturn(expectedModelandView); - actualModelandView= oNAPLoginController.doLogin(mockedRequest, mockedResponse); - oNAPLoginController.setViewName("test"); - assertEquals("test", oNAPLoginController.getViewName()); - assertEquals(actualModelandView,expectedModelandView); - } - - - @Test - public void ViewTest() throws Exception - { - ModelAndView expectedModelandView = new ModelAndView(); - expectedModelandView.setViewName("testView"); - ModelAndView actualModelandView = null; - Mockito.when(loginStrategy.doLogin(mockedRequest, mockedResponse)).thenReturn(expectedModelandView); - actualModelandView= oNAPLoginController.doLogin(mockedRequest, mockedResponse); - assertEquals(actualModelandView.getViewName(),expectedModelandView.getViewName()); - } - @Test - public void getJessionIdTest() throws Exception - { - assertNull(oNAPLoginController.getJessionId(mockedRequest)); - } - - @Test - public void getLoginServiceTest() throws Exception - { - LoginService expectedLoginService = oNAPLoginController.getLoginService(); - assertEquals(mockLoginService,expectedLoginService); - } - - - -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPWelcomeControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPWelcomeControllerTest.java deleted file mode 100644 index b7399fbe..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/ONAPWelcomeControllerTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import static org.junit.Assert.assertEquals; - -import java.security.Principal; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.openecomp.portalapp.controller.ONAPWelcomeController; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.springframework.web.servlet.ModelAndView; - -public class ONAPWelcomeControllerTest { - - @InjectMocks - ONAPWelcomeController oNAPWelcomeController = new ONAPWelcomeController(); - - @Mock - Principal p; - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - NullPointerException nullPointerException = new NullPointerException(); - - @Test - public void getIndexPageTest() - { - assertEquals(oNAPWelcomeController.getIndexPage(mockedRequest), "/index"); - } - - @Test - public void getEcompSinglePageTest() - { - assertEquals(oNAPWelcomeController.getEcompSinglePage(mockedRequest, mockedResponse), "forward:/index.html"); - } - - @Test - public void userTest() - { - assertEquals(oNAPWelcomeController.user(null), "oid-user"); - } - - @Test - public void loginTest() - { - ModelAndView expectedView = new ModelAndView(); - expectedView.setViewName("openIdLogin"); - ModelAndView md = oNAPWelcomeController.login(p); - System.out.println(md.getViewName()); - assertEquals(md.getViewName(), expectedView.getViewName()); - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/PortalAdminControllerOSTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/PortalAdminControllerOSTest.java deleted file mode 100644 index aa7cb46a..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/PortalAdminControllerOSTest.java +++ /dev/null @@ -1,241 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.openecomp.portalapp.portal.domain.EPRole; -import org.openecomp.portalapp.portal.domain.EPUser; -import org.openecomp.portalapp.portal.framework.MockEPUser; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.portal.service.AdminRolesService; -import org.openecomp.portalapp.portal.service.AdminRolesServiceImpl; -import org.openecomp.portalapp.portal.service.PortalAdminService; -import org.openecomp.portalapp.portal.service.PortalAdminServiceImpl; -import org.openecomp.portalapp.portal.transport.FieldsValidator; -import org.openecomp.portalapp.portal.transport.PortalAdmin; -import org.openecomp.portalapp.portal.utils.EcompPortalUtils; -import org.openecomp.portalapp.util.EPUserUtils; -import org.openecomp.portalsdk.core.service.AuditService; -import org.openecomp.portalsdk.core.service.AuditServiceImpl; - -public class PortalAdminControllerOSTest { - - @InjectMocks - PortalAdminController portalAdminController = new PortalAdminController(); - - @Mock - AdminRolesService adminRolesService = new AdminRolesServiceImpl(); - - @Mock - PortalAdminService portalAdminService = new PortalAdminServiceImpl(); - - @Mock - AuditService auditService = new AuditServiceImpl(); - - - @Mock - EcompPortalUtils ecompPortalUtils = new EcompPortalUtils(); - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - NullPointerException nullPointerException = new NullPointerException(); - - @Mock - EPUserUtils ePUserUtils = new EPUserUtils(); - - MockEPUser mockUser = new MockEPUser(); - - @Test - public void deletePortalAdminIfUserIsSuperAdminTest() - { - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); - Long userInfo = (long) 12; - assertNull(portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse)); - - } - - @Test - public void deletePortalAdminTest() - { - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - - FieldsValidator expectedFieldValidator = new FieldsValidator(); - expectedFieldValidator.setHttpStatusCode((long) 200); - expectedFieldValidator.setFields(null); - expectedFieldValidator.setErrorCode(null); - FieldsValidator actualFieldValidator = new FieldsValidator(); - Long userInfo = (long) 12; - Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); - Mockito.when(portalAdminService.deletePortalAdmin((long) 12)).thenReturn(expectedFieldValidator); - actualFieldValidator = portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse); - assertEquals(actualFieldValidator,expectedFieldValidator); - - } - - @Test - public void deletePortalAdminWithNoUserInfoTest() - { - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); - Long userInfo = null; - assertNull(portalAdminController.deletePortalAdmin(mockedRequest, userInfo, mockedResponse)); - } - - @Test - public void getRolesByAppExceptionTest() - { - EPUser user = mockUser.mockEPUser();; - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - List expectedRoleList = new ArrayList(); - EPRole ePRole = new EPRole(); - expectedRoleList.add(ePRole); - Long appId = (long) 1; - Mockito.when(adminRolesService.getRolesByApp(user, appId)).thenThrow(nullPointerException); - assertNull(portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse)); - } - - @Test - public void getRolesByAppIfUserNullTest() - { - EPUser user = null; - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - Long appId = (long) 1; - assertNull(portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse)); - } - - @Test - public void getRolesByAppTest() - { - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - List expectedRoleList = new ArrayList(); - EPRole ePRole = new EPRole(); - expectedRoleList.add(ePRole); - Long appId = (long) 1; - Mockito.when(adminRolesService.getRolesByApp(user, appId)).thenReturn(expectedRoleList); - List actualRoleList = portalAdminController.getRolesByApp(mockedRequest, appId, mockedResponse); - assertEquals(actualRoleList,expectedRoleList); - } - - @Test - public void createPortalAdminIfUserNullTest() - { - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null); - assertNull(portalAdminController.createPortalAdmin(mockedRequest, "guestT", mockedResponse)); - } - - - @Test - public void createPortalAdminIfUserIsSuperAdminTest() - { - - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - FieldsValidator expectedFieldValidator = new FieldsValidator(); - expectedFieldValidator.setHttpStatusCode((long) 200); - expectedFieldValidator.setFields(null); - expectedFieldValidator.setErrorCode(null); - FieldsValidator actualFieldValidator = new FieldsValidator(); - Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); - Mockito.when(portalAdminService.createPortalAdmin("guestT")).thenReturn(expectedFieldValidator); - actualFieldValidator = portalAdminController.createPortalAdmin(mockedRequest, "guestT", mockedResponse); - assertEquals(actualFieldValidator,expectedFieldValidator); - } - - @Test - public void createPortalAdminIfUserIsNotSuperAdminTest() - { - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); - assertNull(portalAdminController.createPortalAdmin(mockedRequest, "guestT", mockedResponse)); - } - - @Test - public void getPortalAdminsIfUserNullTest() - { - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null); - assertNull(portalAdminController.getPortalAdmins(mockedRequest, mockedResponse)); - } - - @Test - public void getPortalAdminsIfUserAdminTest() - { - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - List portalAdmins = new ArrayList<>(); - Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); - Mockito.when(portalAdminService.getPortalAdmins()).thenReturn(portalAdmins); - List actualortalAdmins = portalAdminController.getPortalAdmins(mockedRequest, mockedResponse); - assertEquals(actualortalAdmins,portalAdmins); - } - - @Test - public void getPortalAdminIfUserIsNotSuperAdminTest() - { - EPUser user = mockUser.mockEPUser(); - Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); - Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); - assertNull(portalAdminController.getPortalAdmins(mockedRequest, mockedResponse)); - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextRestClient.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextRestClient.java deleted file mode 100644 index f4196db8..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextRestClient.java +++ /dev/null @@ -1,298 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import java.net.URI; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; - -import javax.net.ssl.SSLContext; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.http.Consts; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContexts; -import org.apache.http.ssl.TrustStrategy; -import org.apache.http.util.EntityUtils; -/** - * Provides reusable features for test cases to get or post from an REST - * endpoint, allowing use of HTTPS connections to servers that use self-signed - * certificates. - */ -public class SharedContextRestClient { - - private static final Log logger = LogFactory.getLog(SharedContextRestClient.class); - - /** - * Convenience method that builds and sends a GET request using properties - * to build the URI and populate header with credentials. - * - * @param task - * last component(s) of REST endpoint name; e.g., "get". - * @param contextId - * @param contextKey - * @return JSON string fetched - * @throws Exception - * if the HTTP response code is anything other than OK. - */ - public static String getJson(final SharedContextTestProperties properties, final String task, - final String contextId, final String contextKey) throws Exception { - String requestPath = '/' + properties.getProperty(SharedContextTestProperties.APPNAME) // - + '/' + properties.getProperty(SharedContextTestProperties.RESTPATH) // - + '/' + task; - return getJson(properties.getProperty(SharedContextTestProperties.HOSTNAME), // - properties.getProperty(SharedContextTestProperties.PORT, -1), // - properties.getProperty(SharedContextTestProperties.SECURE, true), // - properties.getProperty(SharedContextTestProperties.UEBKEY), // - properties.getProperty(SharedContextTestProperties.USERNAME), // - properties.getProperty(SharedContextTestProperties.PASSWORD), requestPath, // - contextId, // - contextKey); - } - - /** - * Constructs and sends a GET request using the specified values. - * - * @param hostname - * @param port - * ignored if negative - * @param secure - * If true, uses https; else http. - * @param headerUebkey - * @param headerUsername - * @param headerPassword - * @param requestPath - * full path of the REST endpoint - * @param contextId - * @param contextKey - * Ignored if null - * @return JSON result - */ - public static String getJson(final String hostname, final int port, boolean secure, final String headerUebkey, - final String headerUsername, final String headerPassword, final String requestPath, final String contextId, - final String contextKey) throws Exception { - - URIBuilder uriBuilder = new URIBuilder(); - if (secure) - uriBuilder.setScheme("https"); - else - uriBuilder.setScheme("http"); - uriBuilder.setHost(hostname); - if (port > 0) - uriBuilder.setPort(port); - uriBuilder.setPath(requestPath); - uriBuilder.addParameter("context_id", contextId); - if (contextKey != null) - uriBuilder.addParameter("ckey", contextKey); - final URI uri = uriBuilder.build(); - - CloseableHttpClient httpClient; - if (secure) { - // Tell HttpClient to accept any server certificate for HTTPS. - // http://stackoverflow.com/questions/24720013/apache-http-client-ssl-certificate-error - SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { - @Override - public boolean isTrusted(final X509Certificate[] chain, final String authType) - throws CertificateException { - return true; - } - }).build(); - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, - NoopHostnameVerifier.INSTANCE); - httpClient = HttpClientBuilder.create().setSSLSocketFactory(sslsf).build(); - } else { - httpClient = HttpClients.createDefault(); - } - - HttpGet httpGet = new HttpGet(uri); - httpGet.setHeader("uebkey", headerUebkey); - httpGet.setHeader("username", headerUsername); - httpGet.setHeader("password", headerPassword); - - String json = null; - CloseableHttpResponse response = null; - try { - logger.debug("GET from " + uri); - response = httpClient.execute(httpGet); - logger.info("Status is " + response.getStatusLine()); - if (response.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) - throw new Exception("Status is " + response.getStatusLine().toString()); - HttpEntity entity = response.getEntity(); - if (entity == null) { - logger.warn("Entity is null!"); - } else { - // entity content length is never set. - // this naively tries to read everything. - json = EntityUtils.toString(entity); - EntityUtils.consume(entity); - } - } finally { - if (response != null) - response.close(); - } - return json; - } - - /** - * Convenience method that builds and sends a POST request using properties - * to build the URI and populate header with credentials. - * - * @param path - * last component(s) of REST endpoint name; e.g., "users" or - * "user/{userid}/roles". - * @return JSON string fetched - * @throws Exception - * if the HTTP response code is anything other than OK. - */ - public static String postJson(final SharedContextTestProperties properties, final String path, final String json) - throws Exception { - String requestPath = '/' + properties.getProperty(SharedContextTestProperties.APPNAME) // - + '/' + properties.getProperty(SharedContextTestProperties.RESTPATH) // - + '/' + path; - return postJson(properties.getProperty(SharedContextTestProperties.HOSTNAME), // - properties.getProperty(SharedContextTestProperties.PORT, -1), // - properties.getProperty(SharedContextTestProperties.SECURE, true), // - properties.getProperty(SharedContextTestProperties.UEBKEY), // - properties.getProperty(SharedContextTestProperties.USERNAME), // - properties.getProperty(SharedContextTestProperties.PASSWORD), // - requestPath, // - json); - } - - /** - * Constructs and sends a POST request using the specified values. - * - * @param hostname - * @param port - * @param secure - * If true, uses https; else http. - * @param requestPath - * full path of the REST endpoint - * @param headerUebkey - * @param headerUsername - * @param headerPassword - * @param json - * Content to post - * @return JSON result - * @throws Exception - */ - public static String postJson(final String hostname, final int port, boolean secure, final String headerUebkey, - final String headerUsername, final String headerPassword, final String requestPath, final String json) - throws Exception { - - URIBuilder builder = new URIBuilder(); - if (secure) - builder.setScheme("https"); - else - builder.setScheme("http"); - builder.setHost(hostname); - if (port > 0) - builder.setPort(port); - builder.setPath(requestPath); - final URI uri = builder.build(); - - CloseableHttpClient httpClient; - if (secure) { - // Tell HttpClient to accept any server certificate for HTTPS. - // http://stackoverflow.com/questions/24720013/apache-http-client-ssl-certificate-error - SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { - @Override - public boolean isTrusted(final X509Certificate[] chain, final String authType) - throws CertificateException { - return true; - } - }).build(); - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, - NoopHostnameVerifier.INSTANCE); - httpClient = HttpClientBuilder.create().setSSLSocketFactory(sslsf).build(); - } else { - httpClient = HttpClients.createDefault(); - } - HttpPost httpPost = new HttpPost(uri); - httpPost.setHeader("uebkey", headerUebkey); - httpPost.setHeader("username", headerUsername); - httpPost.setHeader("password", headerPassword); - - StringEntity postEntity = new StringEntity(json, ContentType.create("application/json", Consts.UTF_8)); - httpPost.setEntity(postEntity); - - String responseJson = null; - CloseableHttpResponse response = null; - try { - logger.debug("POST to " + uri); - response = httpClient.execute(httpPost); - logger.info("Status is " + response.getStatusLine()); - if (response.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) - throw new Exception("Status is " + response.getStatusLine().toString()); - - HttpEntity entity = response.getEntity(); - if (entity == null) { - logger.warn("Entity is null!"); - } else { - long len = entity.getContentLength(); - if (len < 0) - logger.warn("Content length is -1"); - if (len < 2048) { - responseJson = EntityUtils.toString(entity); - logger.debug(responseJson); - } else { - logger.warn("Not implemented - stream content"); - } - EntityUtils.consume(entity); - } - } finally { - if (response != null) - response.close(); - } - return responseJson; - } - -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextRestControllerTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextRestControllerTest.java deleted file mode 100644 index e4061785..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextRestControllerTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * Tests the endpoints exposed by the Shared Context REST controller in Portal - * Core. - * - * @author clott - */ -public class SharedContextRestControllerTest { - - private final Log logger = LogFactory.getLog(getClass()); - - private final SharedContextTestProperties properties; - - private final String ckey = "ckey"; - private final String cvalue = "cvalue"; - - // Supposed to be a Portal session ID - private final String cxid = UUID.randomUUID().toString(); - - private final String key = "key123"; - private final String value1 = "first value"; - private final String value2 = "second value"; - - public SharedContextRestControllerTest() throws IOException { - properties = new SharedContextTestProperties(); - } - - @SuppressWarnings("unchecked") - //@Test - public void test() throws Exception { - String response = null, val = null; - ObjectMapper mapper = new ObjectMapper(); - Map responseMap, jsonMap; - - logger.info("Get on empty context"); - response = SharedContextRestClient.getJson(properties, "get", cxid, key); - // Should not exist - just generated the UUID - Map responseMap1 = mapper.readValue(response, Map.class); - response = (String) responseMap1.get("response"); - Assert.assertNull(response); - - logger.info("Set a new context"); - response = setContext(cxid, key, value1); - Assert.assertNotNull(response); - responseMap = mapper.readValue(response, Map.class); - String responseValue = (String) responseMap.get("response"); - Assert.assertNotNull(responseValue); - Assert.assertEquals("added", responseValue); - - logger.info("Get existing context"); - response = SharedContextRestClient.getJson(properties, "get", cxid, key); - responseMap = mapper.readValue(response, Map.class); - jsonMap = (Map) responseMap.get("response"); - Assert.assertNotNull(jsonMap); - val = (String) jsonMap.get(cvalue); - Assert.assertEquals(val, value1); - - logger.info("Overwrite exiting context"); - response = setContext(cxid, key, value2); - Assert.assertNotNull(response); - responseMap = mapper.readValue(response, Map.class); - response = (String) responseMap.get("response"); - Assert.assertNotNull(responseValue); - // Assert.assertEquals("replaced", responseValue); - - logger.info("Get existing context to verify overwrite"); - response = SharedContextRestClient.getJson(properties, "get", cxid, key); - responseMap = mapper.readValue(response, Map.class); - jsonMap = (Map) responseMap.get("response"); - Assert.assertNotNull(jsonMap); - val = (String) jsonMap.get(cvalue); - Assert.assertEquals(val, value2); - - logger.info("Delete one context"); - response = SharedContextRestClient.getJson(properties, "remove", cxid, key); - responseMap = mapper.readValue(response, Map.class); - response = (String) responseMap.get("response"); - Assert.assertEquals(response, "removed"); - - logger.info("Clear the context"); - response = SharedContextRestClient.getJson(properties, "clear", cxid, null); - Assert.assertEquals("", response); - } - - private String setContext(String context, String id, String value) throws Exception { - ObjectMapper mapper = new ObjectMapper(); - HashMap stringMap = new HashMap(); - stringMap.put("context_id", cxid); - stringMap.put(ckey, key); - stringMap.put(cvalue, value2); - String json = mapper.writeValueAsString(stringMap); - String response = SharedContextRestClient.postJson(properties, "set", json); - return response; - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextTestProperties.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextTestProperties.java deleted file mode 100644 index 1c849420..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/SharedContextTestProperties.java +++ /dev/null @@ -1,99 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.controller; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -/** - * Trivial extension of Properties that populates itself from a known source. - */ -public class SharedContextTestProperties extends Properties { - - private static final long serialVersionUID = -4064100267979036550L; - - // property names - public static final String HOSTNAME = "hostname"; - public static final String PORT = "port"; - public static final String SECURE = "secure"; - public static final String APPNAME = "appname"; - public static final String RESTPATH = "restpath"; - public static final String UEBKEY = "uebkey"; - public static final String USERNAME = "username"; - public static final String PASSWORD = "password"; - - /** - * Expected on the classpath - */ - private static final String propertiesFileName = "shared-context-test.properties"; - - /** - * Constructor populates itself from properties file found in same package. - * - * @throws Exception - */ - public SharedContextTestProperties() throws IOException { - InputStream inStream = getClass().getResourceAsStream(propertiesFileName); - if (inStream == null) - throw new IOException("Failed to find file on classpath: " + propertiesFileName); - super.load(inStream); - inStream.close(); - } - - public int getProperty(final String name, final int defVal) throws NumberFormatException { - String prop = getProperty(name); - if (prop == null) - return defVal; - return Integer.parseInt(prop); - } - - public boolean getProperty(final String name, final boolean defVal) { - String prop = getProperty(name); - if (prop == null) - return false; - return Boolean.parseBoolean(prop); - } - - // Test this class - public static void main(String[] args) throws Exception { - SharedContextTestProperties p = new SharedContextTestProperties(); - System.out.println("Property " + SharedContextTestProperties.HOSTNAME + " = " - + p.getProperty(SharedContextTestProperties.HOSTNAME)); - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/shared-context-test.properties b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/shared-context-test.properties deleted file mode 100644 index 75e6f836..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/controller/shared-context-test.properties +++ /dev/null @@ -1,46 +0,0 @@ -### -# ============LICENSE_START========================================== -# ONAP Portal -# =================================================================== -# Copyright © 2017 AT&T Intellectual Property. All rights reserved. -# =================================================================== -# -# Unless otherwise specified, all software contained herein is licensed -# under the Apache License, Version 2.0 (the “License”); -# you may not use this software 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. -# -# Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); -# you may not use this documentation except in compliance with the License. -# You may obtain a copy of the License at -# -# https://creativecommons.org/licenses/by/4.0/ -# -# Unless required by applicable law or agreed to in writing, documentation -# 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. -# -# ============LICENSE_END============================================ -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -### - -hostname= localhost -# port = 80 -secure = true -appname = ecompportal -restpath = context -uebkey = xgnLrmNmkfCRnIwa -username = Default -password = AppPassword!1 diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockEPUser.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockEPUser.java deleted file mode 100644 index d38b21a0..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockEPUser.java +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.framework; - -import java.util.Date; - -import org.openecomp.portalapp.portal.domain.EPUser; - -public class MockEPUser { - - public EPUser mockEPUser() { - - EPUser ePUser = new EPUser(); - ePUser.setOrgId(null); - ePUser.setManagerId(null); - ePUser.setFirstName("test"); - ePUser.setLastName("test"); - ePUser.setMiddleInitial(null); - ePUser.setPhone(null); - ePUser.setFax(null); - ePUser.setCellular(null); - ePUser.setEmail(null); - ePUser.setAddressId(null); - ePUser.setAlertMethodCd(null); - ePUser.setHrid(null); - ePUser.setOrgUserId("guestT"); - ePUser.setOrgCode(null); - ePUser.setAddress1(null); - ePUser.setAddress2(null); - ePUser.setCity(null); - ePUser.setState(null); - ePUser.setZipCode(null); - ePUser.setCountry(null); - ePUser.setOrgManagerUserId(null); - ePUser.setLocationClli(null); - ePUser.setBusinessCountryCode(null); - ePUser.setBusinessCountryName(null); - ePUser.setBusinessUnit(null); - ePUser.setBusinessUnitName(null); - ePUser.setDepartment(null); - ePUser.setDepartmentName(null); - ePUser.setCompanyCode(null); - ePUser.setCompany(null); - ePUser.setZipCodeSuffix(null); - ePUser.setJobTitle(null); - ePUser.setCommandChain(null); - ePUser.setSiloStatus(null); - ePUser.setCostCenter(null); - ePUser.setFinancialLocCode(null); - - ePUser.setLoginId(null); - ePUser.setLoginPwd(null); - Date date = new Date(); - ePUser.setLastLoginDate(date); - ePUser.setActive(true); - ePUser.setInternal(false); - ePUser.setSelectedProfileId(null); - ePUser.setTimeZoneId(null); - ePUser.setOnline(true); - ePUser.setChatId(null); - ePUser.setUserApps(null); - ePUser.setPseudoRoles(null); - - ePUser.setId((long) -1); - return ePUser; - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockitoTestSuite.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockitoTestSuite.java deleted file mode 100644 index 529dd5ae..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/framework/MockitoTestSuite.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.framework; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) -public class MockitoTestSuite { - - - public MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper( - Mockito.mock(HttpServletRequest.class)); - public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class); - - public MockHttpServletRequestWrapper getMockedRequest() { - return mockedRequest; - } - - public HttpServletResponse getMockedResponse() { - return mockedResponse; - } - - public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper { - - HttpSession session = Mockito.mock(HttpSession.class); - - public MockHttpServletRequestWrapper(HttpServletRequest request) { - super(request); - - } - - @Override - public HttpSession getSession() { - - return session; - } - - @Override - public HttpSession getSession(boolean create) { - - return session; - } - - } - @Test - public void test() - { - assert(true); - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/listener/HealthMonitorTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/listener/HealthMonitorTest.java deleted file mode 100644 index 651f7f61..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/listener/HealthMonitorTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.listener; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class HealthMonitorTest { - - @Test - public void initialFlagsTest() { - assertEquals(false, HealthMonitor.isBackEndUp()); - assertEquals(false, HealthMonitor.isFrontEndUp()); - assertEquals(false, HealthMonitor.isDatabaseUp()); - assertEquals(false, HealthMonitor.isUebUp()); - } - -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java deleted file mode 100644 index f3218a70..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.service; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -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.EPApp; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.service.RemoteWebServiceCallServiceImpl; -import org.openecomp.portalsdk.core.onboarding.util.CipherUtil; -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({ CipherUtil.class , SystemProperties.class}) -public class RemoteWebServiceCallServiceImplTest { - - - @InjectMocks - RemoteWebServiceCallServiceImpl remoteWebServiceCallServiceImpl = new RemoteWebServiceCallServiceImpl(); - - @Mock - AppsCacheService appCacheService; - - @Mock - DataAccessService dataAccessService; - - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - NullPointerException nullPointerException = new NullPointerException(); - - @Test - public void verifyRESTCredentialTest() throws Exception - { - PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); - String criteria= " where ueb_key = 'requestUebKey'"; - List appList = new ArrayList<>(); - EPApp app = new EPApp(); - app.setAppPassword("password"); - appList.add(app); - Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList); - String secretKey = null; - Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); - Mockito.when(CipherUtil.decrypt("password", - secretKey == null ? null : secretKey)).thenReturn("pwd"); - assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","requestPassword")); - } - - @Test - public void verifyRESTCredentialExceptionTest() throws Exception - { - PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); - String criteria= " where ueb_key = 'requestUebKey'"; - List appList = new ArrayList<>(); - EPApp app = new EPApp(); - app.setAppPassword("password"); - app.setUsername("requestAppName"); - appList.add(app); - Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList); - String secretKey = null; - Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); - Mockito.when(CipherUtil.decrypt("password", - secretKey == null ? null : secretKey)).thenReturn("pwd"); - assertTrue(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd")); - } - - @Test - public void verifyRESTCredentialIfAppNullTest() throws Exception - { - PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); - String criteria= " where ueb_key = 'requestUebKey'"; - List appList = new ArrayList<>(); - EPApp app = new EPApp(); - app.setAppPassword("password"); - app.setUsername("requestAppName"); - appList.add(app); - Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null); - String secretKey = null; - Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); - Mockito.when(CipherUtil.decrypt("password", - secretKey == null ? null : secretKey)).thenReturn("pwd"); - assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd")); - } - - @Test - public void verifyAppKeyCredentialIfKeyIsNullTest() throws Exception - { - assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential(null)); - } - - @Test - public void verifyAppKeyCredentialTest() throws Exception - { - PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); - StringBuffer criteria = new StringBuffer("where ueb_key = 'requestUebKey'"); -// String criteria= " where ueb_key = 'requestUebKey'"; - List appList = new ArrayList<>(); - EPApp app = new EPApp(); - app.setAppPassword("password"); - app.setUsername("requestAppName"); - appList.add(app); - Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null); - assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test")); - } - - @Test - public void verifyAppKeyCredentialSuccessTest() throws Exception - { - PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); - String criteria= " where ueb_key = 'test'"; - List appList = new ArrayList<>(); - EPApp app = new EPApp(); - app.setAppPassword("password"); - app.setUsername("requestAppName"); - appList.add(app); - Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList); - assertTrue(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test")); - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/SearchServiceImplTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/SearchServiceImplTest.java deleted file mode 100644 index 71671da3..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/service/SearchServiceImplTest.java +++ /dev/null @@ -1,226 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.service; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -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.EPUser; -import org.openecomp.portalapp.portal.framework.MockEPUser; -import org.openecomp.portalapp.portal.framework.MockitoTestSuite; -import org.openecomp.portalapp.portal.transport.UserWithNameSurnameTitle; -import org.openecomp.portalapp.portal.utils.EcompPortalUtils; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ EcompPortalUtils.class}) -public class SearchServiceImplTest { - - @InjectMocks - SearchServiceImpl searchServiceImpl = new SearchServiceImpl(); - - @Mock - UserService userService; - - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - NullPointerException nullPointerException = new NullPointerException(); - MockEPUser mockUser = new MockEPUser(); - - @Test - public void searchUsersInPhoneBookTest() - { - PowerMockito.mockStatic(EcompPortalUtils.class); - List list = new ArrayList<>(); - String str = "Test"; - list.add(str); - Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test", " ")).thenReturn(list); - assertEquals(searchServiceImpl.searchUsersInPhoneBook("Test"), "[]"); - } - - @Test - public void searchUsersInFnTableToFindUserIdTest() - { - PowerMockito.mockStatic(EcompPortalUtils.class); - List list = new ArrayList<>(); - String str = "Test"; - String str2 = "Test new"; - String str1 = "Test new1"; - list.add(str); - list.add(str1); - list.add(str2); - Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test", " ")).thenReturn(list); - List userList = new ArrayList(); - EPUser user = mockUser.mockEPUser(); - user.setLastName("Test new"); - userList.add(user); - Mockito.when( this.userService.getUserByFirstLastName("Test","Test new")).thenReturn(userList); - String result = searchServiceImpl.searchUsersInPhoneBook("Test"); - assertEquals("[{\"orgUserId\":\"guestT\",\"firstName\":\"test\",\"lastName\":\"Test new\",\"jobTitle\":null}]" , result); - } - - - - @Test - public void searchUsersInFnTableFirstNameTest() - { - PowerMockito.mockStatic(EcompPortalUtils.class); - List list = new ArrayList<>(); - String str = "TestTT"; - String str2 = "Test new1"; - String str1 = "Test new"; - String str3 = "Test new2"; - list.add(str); - list.add(str1); - list.add(str2); - list.add(str3); - Mockito.when(EcompPortalUtils.parsingByRegularExpression("TestTT", " ")).thenReturn(list); - List userList = new ArrayList(); - EPUser user = mockUser.mockEPUser(); - user.setLastName("Test new"); - user.setFirstName(null); - userList.add(user); - Mockito.when( this.userService.getUserByFirstLastName("TestTT","Test new")).thenReturn(userList); - assertEquals(searchServiceImpl.searchUsersInPhoneBook("TestTT"), "[]"); } - - - @Test - public void searchUsersInFnTableLastNameTest() - { - PowerMockito.mockStatic(EcompPortalUtils.class); - List list = new ArrayList<>(); - String str = "Test"; - String str2 = "Test new"; - String str1 = "Test new1"; - list.add(str); - list.add(str1); - list.add(str2); - Mockito.when(EcompPortalUtils.parsingByRegularExpression("Test", " ")).thenReturn(list); - List userList = new ArrayList(); - EPUser user = mockUser.mockEPUser(); - user.setLastName(null); - userList.add(user); - Mockito.when( this.userService.getUserByFirstLastName("Test","Test new")).thenReturn(userList); - assertEquals(searchServiceImpl.searchUsersInPhoneBook("Test"), "[]"); } - - - - @Test - public void searchUserByUserIdTest() - { - List userList = new ArrayList(); - EPUser user = mockUser.mockEPUser(); - user.setLastName("Test new"); - userList.add(user); - List foundUsers = new ArrayList(); - Mockito.when(this.userService.getUserByUserId("guestT")).thenReturn(userList); - - EPUser expectedUser = searchServiceImpl.searchUserByUserId("guestT"); - assertEquals(user, expectedUser); - } - - @Test - public void searchUserByUserIdExceptionTest() - { - Mockito.when(this.userService.getUserByUserId("guestT")).thenThrow(nullPointerException); - assertNull(searchServiceImpl.searchUserByUserId("guestT")); - - } - - @Test - public void searchUsersByUserIdTest() - { - - List userList = new ArrayList(); - EPUser user = mockUser.mockEPUser(); - user.setLastName("Test new"); - userList.add(user); - Mockito.when(this.userService.getUserByUserId("guestT")).thenReturn(userList); - List foundUsers = searchServiceImpl.searchUsersByUserId(user); - assertEquals(foundUsers.size(), 1); - - } - - @Test - public void searchUsersByUserIdExceptionTest() - { - EPUser user = mockUser.mockEPUser(); - user.setLastName("Test new"); - Mockito.when(this.userService.getUserByUserId("guestT")).thenThrow(nullPointerException); - List foundUsers = searchServiceImpl.searchUsersByUserId(user); - assertEquals(foundUsers.size(), 0); - - } - - @Test - public void searchUsersByNameExceptionTest() - { - EPUser user = mockUser.mockEPUser(); - user.setLastName("test"); - user.setFirstName("test"); - - Mockito.when(this.userService.getUserByFirstLastName("test","test")).thenThrow(nullPointerException); - List foundUsers = searchServiceImpl.searchUsersByName(user); - assertEquals(foundUsers.size(), 0); - - } -} diff --git a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/utils/EcompPortalUtilsTest.java b/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/utils/EcompPortalUtilsTest.java deleted file mode 100644 index d9a54360..00000000 --- a/ecomp-portal-BE-os/src/test/java/org/openecomp/portalapp/portal/utils/EcompPortalUtilsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START========================================== - * ONAP Portal - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); - * you may not use this software 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. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * 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. - * - * ============LICENSE_END============================================ - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.openecomp.portalapp.portal.utils; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class EcompPortalUtilsTest { - - - @Test - public void legitimateUserIdFailureTest() { - assertEquals(false, EcompPortalUtils.legitimateUserId("1#@23456")); - } -} -- cgit 1.2.3-korg