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 --- .../onap/portalapp/command/EPLoginBeanTest.java | 80 ++ .../onap/portalapp/command/PostSearchBeanTest.java | 150 ++++ .../portalapp/config/NotificationCleanupTest.java | 86 ++ .../PortalCentralAccessConfigurationTest.java | 82 ++ .../controller/AppCatalogControllerTest.java | 281 ++++++ .../controller/AppContactUsControllerTest.java | 338 ++++++++ .../AppsControllerExternalRequestTest.java | 310 +++++++ .../portal/controller/AppsControllerTest.java | 955 +++++++++++++++++++++ .../portal/controller/AuditLogControllerTest.java | 139 +++ .../controller/BEPropertyReaderControllerTest.java | 109 +++ .../controller/BasicAuthAccountControllerTest.java | 301 +++++++ .../controller/CommonWidgetControllerTest.java | 121 +++ .../controller/ConsulClientControllerTest.java | 179 ++++ .../portal/controller/DashboardControllerTest.java | 467 ++++++++++ .../DashboardSearchResultControllerTest.java | 403 +++++++++ .../controller/EPFusionBaseControllerTest.java | 151 ++++ .../controller/EPRestrictedBaseControllerTest.java | 70 ++ .../ExternalAccessRolesControllerTest.java | 711 +++++++++++++++ .../ExternalAppsRestfulControllerTest.java | 211 +++++ .../controller/FunctionalMenuControllerTest.java | 607 +++++++++++++ .../portal/controller/GetAccessControllerTest.java | 108 +++ .../portal/controller/ManifestControllerTest.java | 93 ++ .../controller/MicroserviceControllerTest.java | 272 ++++++ .../MicroserviceProxyControllerTest.java | 143 +++ .../portal/controller/PolicyControllerTest.java | 148 ++++ .../controller/PortalAdminControllerTest.java | 192 +++++ .../controller/RoleManageControllerTest.java | 525 +++++++++++ .../RolesApprovalSystemControllerTest.java | 373 ++++++++ .../portal/controller/SchedulerControllerTest.java | 110 +++ .../SessionCommunicationControllerTest.java | 96 +++ .../portal/controller/SharedContextRestClient.java | 299 +++++++ .../SharedContextRestControllerTest.java | 144 ++++ .../controller/SharedContextTestProperties.java | 99 +++ .../controller/TicketEventControllerTest.java | 207 +++++ .../portal/controller/UserControllerTest.java | 176 ++++ .../controller/UserNotificationControllerTest.java | 281 ++++++ .../portal/controller/UserRolesControllerTest.java | 326 +++++++ .../WebAnalyticsExtAppControllerTest.java | 147 ++++ .../controller/WidgetsCatalogControllerTest.java | 139 +++ .../WidgetsCatalogMarkupControllerTest.java | 110 +++ .../controller/shared-context-test.properties | 28 + .../org/onap/portalapp/portal/core/MockEPUser.java | 102 +++ .../portal/core/PopulateSampleTestData.java | 85 ++ .../portal/core/RemoveSampleTestData.java | 84 ++ .../portalapp/portal/core/RestURLsTestSuite.java | 353 ++++++++ .../portalapp/portal/domain/AdminUserAppTest.java | 73 ++ .../portal/domain/AdminUserApplicationsTest.java | 94 ++ .../portalapp/portal/domain/AppContactUsTest.java | 69 ++ .../portal/domain/CentralRoleFunctionTest.java | 67 ++ .../portal/domain/CentralV2RoleFunctionTest.java | 71 ++ .../portal/domain/EPAppRoleFunctionTest.java | 64 ++ .../onap/portalapp/portal/domain/EPAppTest.java | 98 +++ .../portal/domain/EPEndpointAccountTest.java | 66 ++ .../portalapp/portal/domain/EPEndpointTest.java | 64 ++ .../onap/portalapp/portal/domain/EPRoleTest.java | 73 ++ .../portal/domain/EPUserAppCatalogRolesTest.java | 69 ++ .../domain/EPUserAppRolesRequestDetailTest.java | 88 ++ .../portal/domain/EPUserAppRolesTest.java | 65 ++ .../portalapp/portal/domain/EPUserAppTest.java | 122 +++ .../domain/EPUserAppsManualSortPreferenceTest.java | 66 ++ .../domain/EPUserAppsSortPreferenceTest.java | 80 ++ .../portal/domain/EPUserNotificationTest.java | 71 ++ .../onap/portalapp/portal/domain/EPUserTest.java | 151 ++++ .../domain/EPWidgetsManualSortPreferenceTest.java | 73 ++ .../portal/domain/EcompAppRoleIdTest.java | 70 ++ .../portalapp/portal/domain/EcompAppRoleTest.java | 68 ++ .../portal/domain/ExternalRoleDetailsTest.java | 96 +++ .../portal/domain/ExternalSystemAccessTest.java | 64 ++ .../domain/ExternalSystemRoleApprovalTest.java | 60 ++ .../domain/FunctionalMenuItemWithAppIDTest.java | 65 ++ .../portal/domain/GetAccessResultIdTest.java | 66 ++ .../portal/domain/MicroserviceDataTest.java | 94 ++ .../portal/domain/MicroserviceParameterTest.java | 68 ++ .../portal/domain/PersUserAppSelectionTest.java | 72 ++ .../portal/domain/PersUserWidgetSelectionTest.java | 73 ++ .../onap/portalapp/portal/domain/ResultTest.java | 66 ++ .../portalapp/portal/domain/SharedContextTest.java | 73 ++ .../portalapp/portal/domain/UserIdRoleIdTest.java | 66 ++ .../portal/domain/WidgetCatalogParameterTest.java | 70 ++ .../portalapp/portal/domain/WidgetCatalogTest.java | 121 +++ .../portal/domain/WidgetParameterResultTest.java | 70 ++ .../onap/portalapp/portal/domain/WidgetTest.java | 71 ++ .../exceptions/NoHealthyServiceExceptionTest.java | 60 ++ .../ApplicationCommonContextTestSuite.java | 191 +++++ .../portal/framework/MockitoTestSuite.java | 94 ++ .../portal/listener/HealthMonitorTest.java | 55 ++ .../portalapp/portal/model/AppCatalogItemTest.java | 72 ++ .../portal/model/AppCategoryFunctionsItemTest.java | 79 ++ .../portal/model/AppContactUsItemTest.java | 86 ++ .../portal/model/SearchResultItemTest.java | 78 ++ .../service/AppContactUsServiceImplTest.java | 184 ++++ .../service/DashboardSearchServiceImplTest.java | 151 ++++ .../EPRoleFunctionServiceCentralizedImplTest.java | 130 +++ .../service/EPRoleFunctionServiceImplTest.java | 135 +++ .../portal/service/EPRoleServiceImplTest.java | 245 ++++++ .../ExternalAccessRolesServiceImplTest.java | 456 ++++++++++ .../service/FunctionalMenuMockServiceImplTest.java | 222 +++++ .../service/FunctionalMenuServiceImplTest.java | 92 ++ .../portal/service/GetAccessServiceImplTest.java | 87 ++ .../portal/service/ManifestServiceImplTest.java | 92 ++ .../portal/service/PersUserAppServiceImplTest.java | 218 +++++ .../portalapp/portal/transport/AnalyticsTest.java | 70 ++ .../transport/AppCatalogPersonalizationTest.java | 63 ++ .../portal/transport/AppNameIdIsAdminTest.java | 75 ++ .../portal/transport/AppWithRolesForUserTest.java | 70 ++ .../transport/AppsListWithAdminRoleTest.java | 83 ++ .../transport/BulkUploadRoleFunctionTest.java | 72 ++ .../portal/transport/BulkUploadUserRolesTest.java | 74 ++ .../transport/BusinessCardApplicationRoleTest.java | 64 ++ .../BusinessCardApplicationRolesListTest.java | 64 ++ .../portalapp/portal/transport/CentralAppTest.java | 86 ++ .../portal/transport/CentralRoleTest.java | 96 +++ .../portal/transport/CentralUserAppTest.java | 78 ++ .../portal/transport/CentralUserTest.java | 89 ++ .../transport/EPAppsManualPreferenceTest.java | 84 ++ .../portal/transport/EPAppsSortPreferenceTest.java | 66 ++ .../transport/EPDeleteAppsManualSortPrefTest.java | 66 ++ .../transport/EPUserAppCurrentRolesTest.java | 78 ++ .../transport/EPWidgetsSortPreferenceTest.java | 78 ++ .../portal/transport/EcompUserAppRolesTest.java | 70 ++ .../transport/EpNotificationItemExtVOTest.java | 70 ++ .../portal/transport/EpNotificationItemTest.java | 100 +++ .../portal/transport/EpNotificationItemVOTest.java | 83 ++ .../transport/EpRoleNotificationItemTest.java | 68 ++ .../transport/ExternalAccessPermsDetailTest.java | 76 ++ .../portal/transport/ExternalAccessPermsTest.java | 79 ++ .../transport/ExternalAccessRolePermsTest.java | 72 ++ .../portal/transport/ExternalAccessRoleTest.java | 63 ++ .../ExternalAccessUserRoleDetailTest.java | 84 ++ .../portal/transport/ExternalAccessUserTest.java | 61 ++ .../transport/ExternalRoleDescriptionTest.java | 72 ++ .../portal/transport/FunctionalMenuItemTest.java | 79 ++ .../portal/transport/FunctionalMenuRoleTest.java | 77 ++ .../portal/transport/RemoteUserWithRolesTest.java | 102 +++ .../portal/transport/RoleInAppForUserTest.java | 74 ++ .../portal/transport/UserApplicationRolesTest.java | 95 ++ .../transport/UserWithNameSurnameTitleTest.java | 56 ++ .../WidgetCatalogPersonalizationTest.java | 62 ++ .../portal/utils/EcompPortalUtilsTest.java | 56 ++ 139 files changed, 18830 insertions(+) create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/EPLoginBeanTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/PostSearchBeanTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/config/NotificationCleanupTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/config/PortalCentralAccessConfigurationTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppCatalogControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppContactUsControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequestTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AuditLogControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/BEPropertyReaderControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/BasicAuthAccountControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/CommonWidgetControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ConsulClientControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EPFusionBaseControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EPRestrictedBaseControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/GetAccessControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ManifestControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RolesApprovalSystemControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SessionCommunicationControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestClient.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextTestProperties.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/TicketEventControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserNotificationControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserRolesControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupControllerTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/shared-context-test.properties create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/MockEPUser.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/PopulateSampleTestData.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RemoveSampleTestData.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RestURLsTestSuite.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AdminUserAppTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AdminUserApplicationsTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AppContactUsTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/CentralRoleFunctionTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/CentralV2RoleFunctionTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPAppRoleFunctionTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPAppTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPEndpointAccountTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPEndpointTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppCatalogRolesTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesRequestDetailTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreferenceTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsSortPreferenceTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserNotificationTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreferenceTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EcompAppRoleIdTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EcompAppRoleTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalRoleDetailsTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalSystemAccessTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalSystemRoleApprovalTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/FunctionalMenuItemWithAppIDTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/GetAccessResultIdTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/MicroserviceDataTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/MicroserviceParameterTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/PersUserAppSelectionTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/PersUserWidgetSelectionTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ResultTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/SharedContextTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/UserIdRoleIdTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetCatalogParameterTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetCatalogTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetParameterResultTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/exceptions/NoHealthyServiceExceptionTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/ApplicationCommonContextTestSuite.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/MockitoTestSuite.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/listener/HealthMonitorTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCatalogItemTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCategoryFunctionsItemTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppContactUsItemTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/SearchResultItemTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AppContactUsServiceImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/DashboardSearchServiceImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuMockServiceImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/GetAccessServiceImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ManifestServiceImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PersUserAppServiceImplTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AnalyticsTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppCatalogPersonalizationTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppNameIdIsAdminTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppsListWithAdminRoleTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadRoleFunctionTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadUserRolesTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BusinessCardApplicationRoleTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BusinessCardApplicationRolesListTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralAppTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralRoleTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserAppTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPAppsManualPreferenceTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPAppsSortPreferenceTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPDeleteAppsManualSortPrefTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPUserAppCurrentRolesTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPWidgetsSortPreferenceTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EcompUserAppRolesTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemExtVOTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemVOTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpRoleNotificationItemTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessPermsDetailTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessPermsTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessRolePermsTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessRoleTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRoleDescriptionTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/FunctionalMenuItemTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/FunctionalMenuRoleTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteUserWithRolesTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RoleInAppForUserTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/UserApplicationRolesTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/UserWithNameSurnameTitleTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/WidgetCatalogPersonalizationTest.java create mode 100644 ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java (limited to 'ecomp-portal-BE-common/src/test/java/org/onap/portalapp') diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/EPLoginBeanTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/EPLoginBeanTest.java new file mode 100644 index 00000000..88ba024b --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/EPLoginBeanTest.java @@ -0,0 +1,80 @@ +/*- + * ============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.command; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; +import org.onap.portalapp.command.EPLoginBean; + +public class EPLoginBeanTest { + + +public EPLoginBean ePLoginBean(){ + + EPLoginBean ePLoginBean = new EPLoginBean(); + ePLoginBean.setLoginId("guestT"); + ePLoginBean.setLoginPwd("password"); + ePLoginBean.setHrid("hrId"); + ePLoginBean.setOrgUserId("guestT"); + ePLoginBean.setBusinessDirectMenu(null); + ePLoginBean.setSiteAccess("site_test"); + ePLoginBean.setLoginErrorMessage("error"); + ePLoginBean.setUser(null); + ePLoginBean.setMenu(null); + return ePLoginBean; + } + + @Test + public void ePLoginBeanTest(){ + EPLoginBean ePLoginBean = ePLoginBean(); + + assertEquals(ePLoginBean.getLoginId(), "guestT"); + assertEquals(ePLoginBean.getLoginPwd(), "password"); + assertEquals(ePLoginBean.getHrid(), "hrId"); + assertEquals(ePLoginBean.getOrgUserId(), "guestT"); + assertNull(ePLoginBean.getBusinessDirectMenu()); + assertEquals(ePLoginBean.getSiteAccess(), "site_test"); + assertEquals(ePLoginBean.getLoginErrorMessage(), "error"); + assertNull(ePLoginBean.getUser()); + assertNull(ePLoginBean.getMenu()); + + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/PostSearchBeanTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/PostSearchBeanTest.java new file mode 100644 index 00000000..2b095731 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/command/PostSearchBeanTest.java @@ -0,0 +1,150 @@ +/*- + * ============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.command; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.mockito.InjectMocks; +import org.onap.portalapp.command.PostSearchBean; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPUser; + +public class PostSearchBeanTest { + + @InjectMocks + PostSearchBean mockPostSearchBean = new PostSearchBean(); + + MockEPUser mockUser = new MockEPUser(); + public PostSearchBean mockPostSearchBean(){ + + PostSearchBean postSearchBean = new PostSearchBean(); + EPUser user = mockUser.mockEPUser(); + postSearchBean.setUser(user); + postSearchBean.setUserOrig(null); + postSearchBean.setSelected(null); + postSearchBean.setHrid(null); + postSearchBean.setPostUserId(null); + postSearchBean.setPostFirstName(null); + postSearchBean.setPostLastName(null); + postSearchBean.setPostOrgCode(null); + postSearchBean.setPostPhone(null); + postSearchBean.setPostEmail(null); + postSearchBean.setPostAddress1(null); + postSearchBean.setPostAddress2(null); + postSearchBean.setPostCity(null); + postSearchBean.setPostState(null); + postSearchBean.setPostZipCode(null); + postSearchBean.setPostLocationClli(null); + postSearchBean.setPostBusinessCountryCode(null); + postSearchBean.setPostBusinessCountryName(null); + postSearchBean.setPostDepartment(null); + postSearchBean.setPostDepartmentName(null); + postSearchBean.setPostBusinessUnit(null); + postSearchBean.setPostBusinessUnitName(null); + postSearchBean.setPostJobTitle(null); + postSearchBean.setOrgManagerUserId(null); + postSearchBean.setPostCommandChain(null); + postSearchBean.setPostCompanyCode(null); + postSearchBean.setPostCostCenter(null); + postSearchBean.setPostSiloStatus(null); + postSearchBean.setPostFinancialLocCode(null); + postSearchBean.setPostManagerUserId(null); + return postSearchBean; + } + + @Test + public void postSearchBeanTest() + { + PostSearchBean postSearchBean = mockPostSearchBean(); + EPUser user = mockUser.mockEPUser(); + assertEquals(postSearchBean.getUser().getActive(), user.getActive()); + assertNull(postSearchBean.getUserOrig()); + assertNull(postSearchBean.getSelected()); + assertNull(postSearchBean.getHrid()); + assertNull(postSearchBean.getPostOrgUserId()); + assertNull(postSearchBean.getPostFirstName()); + assertNull(postSearchBean.getPostLastName()); + assertNull(postSearchBean.getPostOrgCode()); + assertNull(postSearchBean.getPostPhone()); + assertNull(postSearchBean.getPostEmail()); + assertNull(postSearchBean.getPostAddress1()); + assertNull(postSearchBean.getPostAddress2()); + assertNull(postSearchBean.getPostCity()); + assertNull(postSearchBean.getPostState()); + assertNull(postSearchBean.getPostZipCode()); + assertNull(postSearchBean.getPostLocationClli()); + assertNull(postSearchBean.getPostBusinessCountryCode()); + assertNull(postSearchBean.getPostBusinessCountryName()); + assertNull(postSearchBean.getPostDepartment()); + assertNull(postSearchBean.getPostDepartmentName()); + assertNull(postSearchBean.getPostBusinessUnit()); + assertNull(postSearchBean.getPostBusinessUnitName()); + assertNull(postSearchBean.getPostJobTitle()); + assertNull(postSearchBean.getOrgManagerUserId()); + assertNull(postSearchBean.getPostCommandChain()); + assertNull(postSearchBean.getPostCompanyCode()); + assertNull(postSearchBean.getPostCostCenter()); + assertNull(postSearchBean.getPostSiloStatus()); + assertNull(postSearchBean.getPostFinancialLocCode()); + assertNull(postSearchBean.getPostManagerUserId()); + } + + @Test + public void isCriteriaUpdatedIfUserNotNullTest() + { + assertFalse(mockPostSearchBean.isCriteriaUpdated()); + } + + @Test + public void isCriteriaUpdatedIfUserNullTest() + { + mockPostSearchBean.setUser(null); + assertTrue(mockPostSearchBean.isCriteriaUpdated()); + } + + + @Test + public void isCriteriaUpdatedIfUserTest() + { + mockPostSearchBean.setUser(null); + mockPostSearchBean.setUserOrig(null); + assertFalse(mockPostSearchBean.isCriteriaUpdated()); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/config/NotificationCleanupTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/config/NotificationCleanupTest.java new file mode 100644 index 00000000..8d374526 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/config/NotificationCleanupTest.java @@ -0,0 +1,86 @@ +/*- + * ============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.config; + +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.service.UserNotificationService; +import org.onap.portalapp.portal.service.UserNotificationServiceImpl; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.context.ApplicationContext; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(NotificationCleanupConfig.class) +public class NotificationCleanupTest { + + + @InjectMocks + NotificationCleanup notificationCleanup = new NotificationCleanup(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Mock + UserNotificationService userNotificationService = new UserNotificationServiceImpl(); + @Mock + ApplicationContext applicationContext ; + + + @Test + public void runTest() + { + PowerMockito.mockStatic(NotificationCleanupConfig.class); + Mockito.when(NotificationCleanupConfig.getApplicationContext()).thenReturn(applicationContext); + Mockito.when((applicationContext).getBean(UserNotificationService.class)).thenReturn(userNotificationService); + Mockito.doNothing().when(userNotificationService).deleteNotificationsFromEpUserNotificationTable(); + Mockito.doNothing().when(userNotificationService).deleteNotificationsFromEpRoleNotificationTable(); + + Mockito.doNothing().when(userNotificationService).deleteNotificationsFromEpNotificationTable(); + notificationCleanup.run(); + + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/config/PortalCentralAccessConfigurationTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/config/PortalCentralAccessConfigurationTest.java new file mode 100644 index 00000000..a472f05f --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/config/PortalCentralAccessConfigurationTest.java @@ -0,0 +1,82 @@ +/*- + * ============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.config; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.config.PortalCentralAccessConfiguration; +import org.onap.portalapp.portal.service.EPRoleFunctionService; +import org.onap.portalapp.portal.service.EPRoleFunctionServiceCentralizedImpl; +import org.onap.portalapp.portal.service.EPRoleFunctionServiceImpl; + +public class PortalCentralAccessConfigurationTest { + + @InjectMocks + PortalCentralAccessConfiguration portalCentralAccessConfiguration = new PortalCentralAccessConfiguration(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Mock + EPRoleFunctionService ePRoleFunctionServiceImpl = new EPRoleFunctionServiceImpl(); + + @Mock + EPRoleFunctionService ePRoleFunctionServiceCentralizedImpl = new EPRoleFunctionServiceCentralizedImpl(); + + @Test + public void ePRoleFunctionServiceImplTest() + { + EPRoleFunctionService expectedPRoleFunctionServiceImpl = portalCentralAccessConfiguration.ePRoleFunctionServiceImpl(); + assertEquals(expectedPRoleFunctionServiceImpl.getClass(), EPRoleFunctionServiceImpl.class); + } + + @Test + public void ePRoleFunctionServiceCentralImplTest() + { + EPRoleFunctionService expectedPRoleFunctionServiceImpl = portalCentralAccessConfiguration.ePRoleFunctionServiceCentralizedImpl(); + assertEquals(expectedPRoleFunctionServiceImpl.getClass(), EPRoleFunctionServiceCentralizedImpl.class); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppCatalogControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppCatalogControllerTest.java new file mode 100644 index 00000000..7b099824 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppCatalogControllerTest.java @@ -0,0 +1,281 @@ +/*- + * ============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 static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +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.AppCatalogController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.ecomp.model.AppCatalogItem; +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.EPAppCommonServiceImpl; +import org.onap.portalapp.portal.service.EPAppService; +import org.onap.portalapp.portal.service.PersUserAppService; +import org.onap.portalapp.portal.service.PersUserAppServiceImpl; +import org.onap.portalapp.portal.transport.AppCatalogPersonalization; +import org.onap.portalapp.portal.transport.FieldsValidator; +import org.onap.portalapp.portal.transport.FieldsValidator.FieldName; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.util.SystemProperties; + +public class AppCatalogControllerTest extends MockitoTestSuite { + + @Mock + AdminRolesService adminRolesService = new AdminRolesServiceImpl(); + + @Mock + EPAppService appService = new EPAppCommonServiceImpl(); + + @InjectMocks + AppCatalogController appCatalogController = new AppCatalogController(); + + PersUserAppService persUserAppService = Mockito.spy(new PersUserAppServiceImpl()); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Mock + EPUserUtils ePUserUtils = new EPUserUtils(); + + @Mock + EPUser epuser; + + NullPointerException nullPointerException = new NullPointerException(); + + MockEPUser mockUser = new MockEPUser(); + + public AppCatalogItem mockAppCatalogItem() { + AppCatalogItem appCatalogItem = new AppCatalogItem(); + appCatalogItem.setId((long) 1); + appCatalogItem.setName("Ecomp Portal"); + appCatalogItem.setImageUrl("Test_URL"); + appCatalogItem.setDescription("Testing"); + appCatalogItem.setNotes("Test"); + appCatalogItem.setUrl("test"); + appCatalogItem.setAlternateUrl("test"); + appCatalogItem.setRestricted(false); + appCatalogItem.setOpen(false); + appCatalogItem.setAccess(true); + appCatalogItem.setSelect(true); + appCatalogItem.setPending(false); + + return appCatalogItem; + } + + @Test + public void getAppCatalogTestIfUserNotAdmin() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List actualAppCatalogList = null; + + List expectedAppCatalog = new ArrayList<>(); + + AppCatalogItem appCatalogItem = mockAppCatalogItem(); + expectedAppCatalog.add(appCatalogItem); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(appService.getUserAppCatalog(user)).thenReturn(expectedAppCatalog); + actualAppCatalogList = appCatalogController.getAppCatalog(mockedRequest, mockedResponse); + + assertTrue(actualAppCatalogList.contains(appCatalogItem)); + + } + + @Test + public void getAppCatalogTestIfUserIsAdmin() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List actualAppCatalogList = null; + + List expectedAppCatalog = new ArrayList<>(); + + AppCatalogItem appCatalogItem = mockAppCatalogItem(); + + expectedAppCatalog.add(appCatalogItem); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getAdminAppCatalog(user)).thenReturn(expectedAppCatalog); + actualAppCatalogList = appCatalogController.getAppCatalog(mockedRequest, mockedResponse); + + assertTrue(actualAppCatalogList.contains(appCatalogItem)); + + } + + @Test + public void getAppCatalogTestIfUserisNull() throws IOException { + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null); + List actualAppCatalogList = new ArrayList<>(); + ; + actualAppCatalogList = appCatalogController.getAppCatalog(mockedRequest, mockedResponse); + assertNull(actualAppCatalogList); + + } + + @Test + public void getAppCatalogTestIfUserThrowsExceptionTest() throws IOException { + EPUser user = new EPUser(); + user.setFirstName("test"); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List actualAppCatalogList = new ArrayList<>(); + ; + + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + + Mockito.when(appCatalogController.getAppCatalog(mockedRequest, mockedResponse)).thenThrow(nullPointerException); + + actualAppCatalogList = appCatalogController.getAppCatalog(mockedRequest, mockedResponse); + assertNull(actualAppCatalogList); + + } + + @Test + public void putAppCatalogSelectionTestWhenAppIsNull() throws IOException { + + AppCatalogPersonalization persRequest = new AppCatalogPersonalization(); + persRequest.setAppId((long) 1); + persRequest.setPending(false); + persRequest.setSelect(false); + + EPUser user = mockUser.mockEPUser(); + + FieldsValidator expectedFieldValidator = new FieldsValidator(); + + FieldsValidator actualFieldValidator = new FieldsValidator(); + List fields = new ArrayList<>(); + ; + + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(fields); + expectedFieldValidator.setErrorCode(null); + + EPApp app = null; + + Mockito.when(appService.getApp(persRequest.getAppId())).thenReturn(app); + + HttpSession session = mockedRequest.getSession(); + session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); + + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + actualFieldValidator = appCatalogController.putAppCatalogSelection(mockedRequest, persRequest, mockedResponse); + assertEquals(expectedFieldValidator, actualFieldValidator); + + } + + @Test + public void putAppCatalogSelectionTest() throws IOException { + + AppCatalogPersonalization persRequest = new AppCatalogPersonalization(); + persRequest.setAppId((long) 1); + persRequest.setPending(false); + persRequest.setSelect(false); + + EPUser user = mockUser.mockEPUser(); + + FieldsValidator expectedFieldValidator = new FieldsValidator(); + + FieldsValidator actualFieldValidator = new FieldsValidator(); + List fields = new ArrayList<>(); + ; + + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(fields); + expectedFieldValidator.setErrorCode(null); + + EPApp app = new EPApp(); + + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(false); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + + Mockito.when(appService.getApp(persRequest.getAppId())).thenReturn(app); + + HttpSession session = mockedRequest.getSession(); + session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); + + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.doNothing().when(persUserAppService).setPersUserAppValue(user, app, persRequest.getSelect(), + persRequest.getPending()); + + actualFieldValidator = appCatalogController.putAppCatalogSelection(mockedRequest, persRequest, mockedResponse); + + assertEquals(expectedFieldValidator, actualFieldValidator); + + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppContactUsControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppContactUsControllerTest.java new file mode 100644 index 00000000..522ef7ca --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppContactUsControllerTest.java @@ -0,0 +1,338 @@ +/*- + * ============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.assertTrue; + +import java.util.ArrayList; +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.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.AppContactUsController; +import org.onap.portalapp.portal.ecomp.model.AppCategoryFunctionsItem; +import org.onap.portalapp.portal.ecomp.model.AppContactUsItem; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.AppContactUsService; +import org.onap.portalapp.portal.service.AppContactUsServiceImpl; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.domain.support.CollaborateList; +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; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({SystemProperties.class, EPCommonSystemProperties.class}) +public class AppContactUsControllerTest extends MockitoTestSuite{ + + @Mock + AppContactUsService contactUsService = new AppContactUsServiceImpl(); + + @InjectMocks + AppContactUsController appContactUsController = new AppContactUsController(); + + @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(); + + public List mockResponse() { + List appContactUsItemList = new ArrayList(); + AppContactUsItem appContactUsItem = new AppContactUsItem(); + appContactUsItem.setAppId((long) 1); + appContactUsItem.setAppName("ECOMP Portal"); + appContactUsItem.setDescription("Test"); + appContactUsItem.setContactName("Test"); + appContactUsItem.setContactEmail("person@onap.org"); + appContactUsItem.setUrl("Test_URL"); + appContactUsItem.setActiveYN("Y"); + appContactUsItemList.add(appContactUsItem); + + return appContactUsItemList; + + } + + public PortalRestResponse> successPortalRestResponse() { + PortalRestResponse> expectedportalRestResponse = new PortalRestResponse>(); + List appContactUsItemList = mockResponse(); + expectedportalRestResponse.setMessage("success"); + expectedportalRestResponse.setResponse(appContactUsItemList); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); + return expectedportalRestResponse; + + } + + public PortalRestResponse> exceptionPortalRestResponse() { + PortalRestResponse> expectedportalRestResponse = new PortalRestResponse>(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse(null); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + return expectedportalRestResponse; + + } + + @Test + public void getAppContactUsList() throws Exception { + PortalRestResponse> expectedportalRestResponse = successPortalRestResponse(); + List appContactUsItemList = mockResponse(); + PortalRestResponse> actualPortalRestResponse = new PortalRestResponse>(); + Mockito.when(contactUsService.getAppContactUs()).thenReturn(appContactUsItemList); + actualPortalRestResponse = appContactUsController.getAppContactUsList(mockedRequest); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } + + @Test + public void getAppContactUsListCatchesExeptionTest() throws Exception { + + PortalRestResponse> expectedportalRestResponse = exceptionPortalRestResponse(); + PortalRestResponse> actualPortalRestResponse = new PortalRestResponse>(); + Mockito.when(contactUsService.getAppContactUs()).thenThrow(nullPointerException); + actualPortalRestResponse = appContactUsController.getAppContactUsList(mockedRequest); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } + + @Test + public void getAppsAndContactsTest() throws Exception { + PortalRestResponse> expectedportalRestResponse = successPortalRestResponse(); + List appContactUsItemList = mockResponse(); + PortalRestResponse> actualPortalRestResponse = new PortalRestResponse>(); + Mockito.when(contactUsService.getAppsAndContacts()).thenReturn(appContactUsItemList); + actualPortalRestResponse = appContactUsController.getAppsAndContacts(mockedRequest); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + + } + + @Test + public void getAppsAndContactsCatchesExceptionTest() throws Exception { + PortalRestResponse> expectedportalRestResponse = exceptionPortalRestResponse(); + PortalRestResponse> actualPortalRestResponse = new PortalRestResponse>(); + Mockito.when(contactUsService.getAppsAndContacts()).thenThrow(nullPointerException); + actualPortalRestResponse = appContactUsController.getAppsAndContacts(mockedRequest); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + + } + + @Test + public void getAppCategoryFunctionsTest() throws Exception { + PortalRestResponse> actualportalRestResponse = null; + + List contents = new ArrayList(); + + AppCategoryFunctionsItem appCategoryFunctionsItem = new AppCategoryFunctionsItem(); + AppCategoryFunctionsItem appCategoryFunctionsItem1 = new AppCategoryFunctionsItem(); + + appCategoryFunctionsItem.setRowId("1"); + appCategoryFunctionsItem.setAppId("1"); + appCategoryFunctionsItem.setApplication("Ecomp-portal"); + appCategoryFunctionsItem.setCategory("test"); + appCategoryFunctionsItem.setFunctions("test"); + + appCategoryFunctionsItem1.setRowId("2"); + appCategoryFunctionsItem1.setAppId("2"); + appCategoryFunctionsItem1.setApplication("Ecomp-portal-test"); + appCategoryFunctionsItem1.setCategory("test"); + appCategoryFunctionsItem1.setFunctions("test"); + contents.add(appCategoryFunctionsItem); + contents.add(appCategoryFunctionsItem1); + + PortalRestResponse> expectedportalRestResponse = new PortalRestResponse>(); + expectedportalRestResponse.setMessage("success"); + expectedportalRestResponse.setResponse(contents); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); + + Mockito.when(contactUsService.getAppCategoryFunctions()).thenReturn(contents); + actualportalRestResponse = appContactUsController.getAppCategoryFunctions(mockedRequest); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + + } + + @Test + public void getAppCategoryFunctionsCatchesExceptionTest() throws Exception { + PortalRestResponse> actualportalRestResponse = null; + PortalRestResponse> expectedportalRestResponse = exceptionPortalRestResponse(); + Mockito.when(contactUsService.getAppCategoryFunctions()).thenThrow(nullPointerException); + actualportalRestResponse = appContactUsController.getAppCategoryFunctions(mockedRequest); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + + } + + @Test + public void saveTest() throws Exception { + PortalRestResponse actualSaveAppContactUS = null; + + AppContactUsItem contactUs = new AppContactUsItem(); + contactUs.setAppId((long) 1); + contactUs.setAppName("Ecomp Portal"); + contactUs.setDescription("Test"); + contactUs.setContactName("Test"); + contactUs.setContactEmail("person@onap.org"); + contactUs.setUrl("Test_URL"); + contactUs.setActiveYN("Y"); + + Mockito.when(contactUsService.saveAppContactUs(contactUs)).thenReturn("SUCCESS"); + actualSaveAppContactUS = appContactUsController.save(contactUs); + assertEquals(actualSaveAppContactUS.getMessage(), "SUCCESS"); + } + + @Test + public void saveExceptionTest() throws Exception { + PortalRestResponse actualSaveAppContactUS = null; + + AppContactUsItem contactUs = new AppContactUsItem(); + contactUs.setAppId((long) 1); + contactUs.setAppName("Ecomp Portal"); + contactUs.setDescription("Test"); + contactUs.setContactName("Test"); + contactUs.setContactEmail("person@onap.org"); + contactUs.setUrl("Test_URL"); + contactUs.setActiveYN("Y"); + + Mockito.when(contactUsService.saveAppContactUs(contactUs)).thenThrow(new Exception()); + actualSaveAppContactUS = appContactUsController.save(contactUs); + assertEquals(actualSaveAppContactUS.getMessage(), "failure"); + } + + @Test + public void saveWhenAppContactUsItemNullTest() throws Exception { + PortalRestResponse actualSaveAppContactUS = null; + AppContactUsItem contactUs = null; + actualSaveAppContactUS = appContactUsController.save(contactUs); + assertEquals(actualSaveAppContactUS.getMessage(), "failure"); + + } + + @Test + public void saveAllTest() throws Exception { + + List contactUs = mockResponse(); + PortalRestResponse actualSaveAppContactUS = null; + Mockito.when(contactUsService.saveAppContactUs(contactUs)).thenReturn("SUCCESS"); + actualSaveAppContactUS = appContactUsController.save(contactUs); + assertEquals(actualSaveAppContactUS.getMessage(), "SUCCESS"); + } + + @Test + public void saveAllExceptionTest() throws Exception { + + List contactUs = mockResponse(); + PortalRestResponse actualSaveAppContactUS = null; + Mockito.when(contactUsService.saveAppContactUs(contactUs)).thenThrow(new Exception()); + actualSaveAppContactUS = appContactUsController.save(contactUs); + assertEquals(actualSaveAppContactUS.getMessage(), "failure"); + } + + @Test + public void deleteTest() throws Exception { + + PortalRestResponse actualSaveAppContactUS = null; + Long id = (long) 1; + String saveAppContactUs = "SUCCESS"; + Mockito.when(contactUsService.deleteContactUs(id)).thenReturn(saveAppContactUs); + actualSaveAppContactUS = appContactUsController.delete(id); + assertEquals(actualSaveAppContactUS.getMessage(), "SUCCESS"); + } + + @Test + public void deleteExceptionTest() throws Exception { + + PortalRestResponse actualSaveAppContactUS = null; + Long id = (long) 1; + Mockito.when(contactUsService.deleteContactUs(id)).thenThrow(new Exception()); + actualSaveAppContactUS = appContactUsController.delete(id); + assertEquals(actualSaveAppContactUS.getMessage(), "failure"); + } + + @Test + public void getPortalDetailsTest(){ + PortalRestResponse actualResponse = new PortalRestResponse(); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setStatus(PortalRestStatusEnum.OK); + expectedResponse.setMessage("success"); + expectedResponse.setResponse("\"ush_ticket_url\":\"http://todo_enter_ush_ticket_url\",\"portal_info_url\":\"https://todo_enter_portal_info_url\",\"feedback_email_address\":\"portal@lists.openecomp.org\""); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.USH_TICKET_URL)).thenReturn("http://todo_enter_ush_ticket_url"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.PORTAL_INFO_URL)).thenReturn("https://todo_enter_portal_info_url"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.FEEDBACK_EMAIL_ADDRESS)).thenReturn("portal@lists.openecomp.org"); + + actualResponse = appContactUsController.getPortalDetails(mockedRequest); + assertTrue(actualResponse.getStatus().compareTo(PortalRestStatusEnum.OK) == 0); + } + + @Test + public void getPortalDetailsExceptionTest(){ + PortalRestResponse actualResponse = new PortalRestResponse(); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setStatus(PortalRestStatusEnum.ERROR); + expectedResponse.setMessage("failure"); + expectedResponse.setResponse(null); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.USH_TICKET_URL)).thenThrow(nullPointerException); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.PORTAL_INFO_URL)).thenReturn("https://todo_enter_portal_info_url"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.FEEDBACK_EMAIL_ADDRESS)).thenReturn("portal@lists.openecomp.org"); + + actualResponse = appContactUsController.getPortalDetails(mockedRequest); + assertEquals(actualResponse, expectedResponse); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequestTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequestTest.java new file mode 100644 index 00000000..3a81a6f8 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerExternalRequestTest.java @@ -0,0 +1,310 @@ +/*- + * ============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.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.controller.AppsControllerExternalRequest; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPApp; +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.MockitoTestSuite; +import org.onap.portalapp.portal.service.AdminRolesService; +import org.onap.portalapp.portal.service.EPAppService; +import org.onap.portalapp.portal.service.PortalAdminService; +import org.onap.portalapp.portal.service.UserService; +import org.onap.portalapp.portal.service.UserServiceImpl; +import org.onap.portalapp.portal.transport.FieldsValidator; +import org.onap.portalapp.portal.transport.OnboardingApp; +import org.onap.portalapp.util.EPUserUtils; + +public class AppsControllerExternalRequestTest extends MockitoTestSuite { + + @Mock + AdminRolesService adminRolesService; + + @Mock + EPAppService appService; + + @Mock + PortalAdminService portalAdminService; + + @Mock + UserService userService = new UserServiceImpl(); + + @InjectMocks + AppsControllerExternalRequest appsControllerExternalRequest = new AppsControllerExternalRequest(); + + @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 + EPUserUtils ePUserUtils = new EPUserUtils(); + + @Test + public void postPortalAdminIfUSerNullTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Missing required field: email, loginId, or loginPwd"); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + EPUser user = mockUser.mockEPUser(); + user.setEmail("guestT@test.portal.onap.org"); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + PortalRestResponse actualPortalRestResponse = appsControllerExternalRequest + .postPortalAdmin(mockedRequest, mockedResponse, user); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } + + @Test + public void postPortalAdminTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("java.lang.NullPointerException"); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + EPUser user = mockUser.mockEPUser(); + user.setEmail("guestT@test.portal.onap.org"); + user.setLoginPwd("pwd"); + user.setLoginId("Test"); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenThrow(nullPointerException); + PortalRestResponse actualPortalRestResponse = appsControllerExternalRequest + .postPortalAdmin(mockedRequest, mockedResponse, user); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } + + @Test + public void postPortalAdminCreateUserIfNotFoundTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + EPUser user = mockUser.mockEPUser(); + user.setEmail("guestT@test.portal.onap.org"); + user.setLoginPwd("pwd"); + user.setLoginId("Test"); + List expectedList = null; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenReturn(expectedList); + Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null); + PortalRestResponse actualPortalRestResponse = appsControllerExternalRequest + .postPortalAdmin(mockedRequest, mockedResponse, user); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } + + @Test + public void postPortalAdminCreateUserIfFoundTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + EPUser user = mockUser.mockEPUser(); + user.setEmail("guestT@test.portal.onap.org"); + user.setLoginPwd("pwd"); + user.setLoginId("Test"); + List expectedList = new ArrayList(); + expectedList.add(user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenReturn(expectedList); + Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + PortalRestResponse actualPortalRestResponse = appsControllerExternalRequest + .postPortalAdmin(mockedRequest, mockedResponse, user); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } + + @Test + public void postPortalAdminCreateUserIfNotSuperAdminTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + EPUser user = mockUser.mockEPUser(); + user.setEmail("guestT@test.portal.onap.org"); + user.setLoginPwd("pwd"); + user.setLoginId("Test"); + List expectedList = new ArrayList(); + expectedList.add(user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenReturn(expectedList); + Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + Mockito.when(portalAdminService.createPortalAdmin(user.getOrgUserId())).thenReturn(expectedFieldValidator); + + PortalRestResponse actualPortalRestResponse = appsControllerExternalRequest + .postPortalAdmin(mockedRequest, mockedResponse, user); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } + + @Test + public void postPortalAdminCreateUserIfFieldValidatorErrorTest() throws Exception { + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 500); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("FieldsValidator [httpStatusCode=500, errorCode=null, fields=null]"); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + EPUser user = mockUser.mockEPUser(); + user.setEmail("guestT@test.portal.onap.org"); + user.setLoginPwd("pwd"); + user.setLoginId("Test"); + List expectedList = new ArrayList(); + expectedList.add(user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(userService.getUserByUserId(user.getOrgUserId())).thenReturn(expectedList); + Mockito.when(userService.saveNewUser(user, "Yes")).thenReturn(null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(portalAdminService.createPortalAdmin(user.getOrgUserId())).thenReturn(expectedFieldValidator); + PortalRestResponse actualPortalRestResponse = appsControllerExternalRequest + .postPortalAdmin(mockedRequest, mockedResponse, user); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } + + @Test + public void getOnboardAppExternalTest() { + EPApp epApp = new EPApp(); + Long appId = (long) 1; + Mockito.when(appService.getApp(appId)).thenReturn(epApp); + OnboardingApp expectedApp = new OnboardingApp(); + Mockito.doNothing().when(appService).createOnboardingFromApp(epApp, expectedApp); + OnboardingApp actualApp = appsControllerExternalRequest.getOnboardAppExternal(mockedRequest, mockedResponse, + appId); + assertEquals(expectedApp.getClass(), actualApp.getClass()); + } + + @Test + public void postOnboardAppExternalExceptionTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Unexpected field: id"); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + + OnboardingApp expectedOnboardingApp = new OnboardingApp(); + expectedOnboardingApp.id = (long) 1; + + PortalRestResponse actualPortalRestResponse = appsControllerExternalRequest + .postOnboardAppExternal(mockedRequest, mockedResponse, expectedOnboardingApp); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } + + @Test + public void postOnboardAppExternalTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage( + "Missing required field: name, url, restUrl, restrictedApp, isOpen, isEnabled, myLoginsAppOwner"); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + + OnboardingApp expectedOnboardingApp = new OnboardingApp(); + expectedOnboardingApp.id = null; + + PortalRestResponse actualPortalRestResponse = appsControllerExternalRequest + .postOnboardAppExternal(mockedRequest, mockedResponse, expectedOnboardingApp); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + + } + + @Test + public void putOnboardAppExternalifAppNullTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Unexpected value for field: id"); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + Long appId = null; + OnboardingApp expectedOnboardingApp = new OnboardingApp(); + expectedOnboardingApp.id = null; + + PortalRestResponse actualPortalRestResponse = appsControllerExternalRequest + .putOnboardAppExternal(mockedRequest, mockedResponse, appId, expectedOnboardingApp); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } + + @Test + public void putOnboardAppExternalIfOnboardingAppDetailsNullTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage( + "Missing required field: name, url, restUrl, restrictedApp, isOpen, isEnabled, myLoginsAppOwner"); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + Long appId = (long) 1; + OnboardingApp expectedOnboardingApp = new OnboardingApp(); + expectedOnboardingApp.id = (long) 1; + PortalRestResponse actualPortalRestResponse = appsControllerExternalRequest + .putOnboardAppExternal(mockedRequest, mockedResponse, appId, expectedOnboardingApp); + assertEquals(actualPortalRestResponse, expectedportalRestResponse); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java new file mode 100644 index 00000000..95f1d224 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppsControllerTest.java @@ -0,0 +1,955 @@ +/*- + * ============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.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +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.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.controller.AppsController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.AdminUserApplications; +import org.onap.portalapp.portal.domain.AppIdAndNameTransportModel; +import org.onap.portalapp.portal.domain.AppsResponse; +import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.domain.EcompApp; +import org.onap.portalapp.portal.domain.UserRole; +import org.onap.portalapp.portal.domain.UserRoles; +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.EPAppCommonServiceImpl; +import org.onap.portalapp.portal.service.EPAppService; +import org.onap.portalapp.portal.service.EPLeftMenuService; +import org.onap.portalapp.portal.service.EPLeftMenuServiceImpl; +import org.onap.portalapp.portal.transport.EPAppsManualPreference; +import org.onap.portalapp.portal.transport.EPAppsSortPreference; +import org.onap.portalapp.portal.transport.EPDeleteAppsManualSortPref; +import org.onap.portalapp.portal.transport.EPWidgetsSortPreference; +import org.onap.portalapp.portal.transport.FieldsValidator; +import org.onap.portalapp.portal.transport.LocalRole; +import org.onap.portalapp.portal.transport.OnboardingApp; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.http.HttpEntity; +import org.springframework.http.MediaType; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({SystemProperties.class,AppUtils.class, EPUserUtils.class, MediaType.class}) +public class AppsControllerTest extends MockitoTestSuite{ + + @InjectMocks + AppsController appsController = new AppsController(); + + @Mock + AdminRolesService adminRolesService = new AdminRolesServiceImpl(); + + @Mock + EPAppService appService = new EPAppCommonServiceImpl(); + + @Mock + EPLeftMenuService leftMenuService = new EPLeftMenuServiceImpl(); + + @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(); + + @Mock + AppUtils appUtils = new AppUtils(); + + MockEPUser mockUser = new MockEPUser(); + + @Test + public void getUserAppsTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedEcompApps = new ArrayList(); + + EcompApp ecompApp = new EcompApp(); + ecompApp.setId((long) 1); + ecompApp.setName("Test_app"); + ecompApp.setUrl("Test_URL"); + ecompApp.setUebKey("Test_key"); + ecompApp.setAlternateUrl("Test_alt_URL"); + expectedEcompApps.add(ecompApp); + List actualEcompApps = new ArrayList(); + Mockito.when(appService.transformAppsToEcompApps(appService.getUserApps(user))).thenReturn(expectedEcompApps); + actualEcompApps = appsController.getUserApps(mockedRequest, mockedResponse); + assertEquals(expectedEcompApps, actualEcompApps); + } + + @Test + public void getUserAppsNoUserTest() { + EPUser user = null; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(appService.transformAppsToEcompApps(appService.getUserApps(user))).thenReturn(null); + assertNull(appsController.getUserApps(mockedRequest, mockedResponse)); + + } + + @Test + public void getUserAppsExceptionTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(appService.transformAppsToEcompApps(appService.getUserApps(user))).thenThrow(nullPointerException); + assertNull(appsController.getUserApps(mockedRequest, mockedResponse)); + + } + + @Test + public void getPersUserAppsIfUserIsAdminTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedEcompApps = new ArrayList(); + + EcompApp ecompApp = new EcompApp(); + ecompApp.setId((long) 1); + ecompApp.setName("Test_app"); + ecompApp.setUrl("Test_URL"); + ecompApp.setUebKey("Test_key"); + ecompApp.setAlternateUrl("Test_alt_URL"); + expectedEcompApps.add(ecompApp); + List actualEcompApps = new ArrayList(); + + List expectedApps = new ArrayList(); + + EPApp app = new EPApp(); + + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(false); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + + expectedApps.add(app); + + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getPersAdminApps(user)).thenReturn(expectedApps); + + Mockito.when(appService.transformAppsToEcompApps(expectedApps)).thenReturn(expectedEcompApps); + actualEcompApps = appsController.getPersUserApps(mockedRequest, mockedResponse); + assertEquals(expectedEcompApps, actualEcompApps); + } + + @Test + public void getPersUserAppsIfUserNotAdminTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedEcompApps = new ArrayList(); + + EcompApp ecompApp = new EcompApp(); + ecompApp.setId((long) 1); + ecompApp.setName("Test_app"); + ecompApp.setUrl("Test_URL"); + ecompApp.setUebKey("Test_key"); + ecompApp.setAlternateUrl("Test_alt_URL"); + expectedEcompApps.add(ecompApp); + List actualEcompApps = new ArrayList(); + + List expectedApps = new ArrayList(); + + EPApp app = new EPApp(); + + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(false); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + + expectedApps.add(app); + + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(appService.getPersUserApps(user)).thenReturn(expectedApps); + Mockito.when(appService.transformAppsToEcompApps(expectedApps)).thenReturn(expectedEcompApps); + actualEcompApps = appsController.getPersUserApps(mockedRequest, mockedResponse); + assertEquals(expectedEcompApps, actualEcompApps); + } + + @Test + public void getPersUserAppsIfUserNullTest() throws IOException { + EPUser user = null; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + assertNull(appsController.getPersUserApps(mockedRequest, mockedResponse)); + } + + @Test + public void getPersUserAppsExceptionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getPersAdminApps(user)).thenThrow(nullPointerException); + assertNull(appsController.getPersUserApps(mockedRequest, mockedResponse)); + } + + @Test + public void getAdminAppsIfNotAdminTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + assertNull(appsController.getAdminApps(mockedRequest, mockedResponse)); + } + + @Test + public void getAdminAppsTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedAdminApps = new ArrayList(); + AppIdAndNameTransportModel appIdAndNameTransportModel = new AppIdAndNameTransportModel(); + appIdAndNameTransportModel.setId((long) 1); + appIdAndNameTransportModel.setName("Test_app"); + expectedAdminApps.add(appIdAndNameTransportModel); + List actualAdminApps = new ArrayList(); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(true); + Mockito.when(appService.getAdminApps(user)).thenReturn(expectedAdminApps); + actualAdminApps = appsController.getAdminApps(mockedRequest, mockedResponse); + assertEquals(actualAdminApps, expectedAdminApps); + + } + + @Test + public void getAdminAppsExceptionTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(true); + Mockito.when(appService.getAdminApps(user)).thenThrow(nullPointerException); + assertNull(appsController.getAdminApps(mockedRequest, mockedResponse)); + } + + @Test + public void getAppsForSuperAdminAndAccountAdminifOnlyAccountAdminTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + assertNull(appsController.getAppsForSuperAdminAndAccountAdmin(mockedRequest, mockedResponse)); + } + + @Test + public void getAppsForSuperAdminAndAccountAdminTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedAdminApps = new ArrayList(); + AppIdAndNameTransportModel appIdAndNameTransportModel = new AppIdAndNameTransportModel(); + appIdAndNameTransportModel.setId((long) 1); + appIdAndNameTransportModel.setName("Test_app"); + expectedAdminApps.add(appIdAndNameTransportModel); + List actualAdminApps = new ArrayList(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(true); + Mockito.when(appService.getAppsForSuperAdminAndAccountAdmin(user)).thenReturn(expectedAdminApps); + actualAdminApps = appsController.getAppsForSuperAdminAndAccountAdmin(mockedRequest, mockedResponse); + assertEquals(actualAdminApps, expectedAdminApps); + + } + + @Test + public void getAppsForSuperAdminExceptionTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(appService.getAppsForSuperAdminAndAccountAdmin(user)).thenThrow(nullPointerException); + assertNull(appsController.getAppsForSuperAdminAndAccountAdmin(mockedRequest, mockedResponse)); + } + + @Test + public void putUserAppsSortingManualTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List ePAppsManualPreference = new ArrayList(); + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + FieldsValidator actualFieldValidator = new FieldsValidator(); + Mockito.when(appService.saveAppsSortManual(ePAppsManualPreference, user)).thenReturn(expectedFieldValidator); + actualFieldValidator = appsController.putUserAppsSortingManual(mockedRequest, ePAppsManualPreference, + mockedResponse); + assertEquals(actualFieldValidator, expectedFieldValidator); + } + + @Test + public void putUserAppsSortingManualExceptionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List ePAppsManualPreference = new ArrayList(); + Mockito.when(appService.saveAppsSortManual(ePAppsManualPreference, user)).thenThrow(nullPointerException); + assertNull(appsController.putUserAppsSortingManual(mockedRequest, ePAppsManualPreference, mockedResponse)); + } + + @Test + public void putUserWidgetsSortManualTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List ePWidgetsSortPreference = new ArrayList(); + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + FieldsValidator actualFieldValidator = new FieldsValidator(); + Mockito.when(appService.saveWidgetsSortManual(ePWidgetsSortPreference, user)) + .thenReturn(expectedFieldValidator); + actualFieldValidator = appsController.putUserWidgetsSortManual(mockedRequest, ePWidgetsSortPreference, + mockedResponse); + assertEquals(actualFieldValidator, expectedFieldValidator); + } + + @Test + public void putUserWidgetsSortManualExceptionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List ePAppsManualPreference = new ArrayList(); + Mockito.when(appService.saveAppsSortManual(ePAppsManualPreference, user)).thenThrow(nullPointerException); + assertNull(appsController.putUserAppsSortingManual(mockedRequest, ePAppsManualPreference, mockedResponse)); + } + + @Test + public void putUserWidgetsSortPrefTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List ePWidgetsSortPreference = new ArrayList(); + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + FieldsValidator actualFieldValidator = new FieldsValidator(); + Mockito.when(appService.deleteUserWidgetSortPref(ePWidgetsSortPreference, user)) + .thenReturn(expectedFieldValidator); + actualFieldValidator = appsController.putUserWidgetsSortPref(mockedRequest, ePWidgetsSortPreference, + mockedResponse); + assertEquals(actualFieldValidator, expectedFieldValidator); + } + + @Test + public void putUserWidgetsSortPrefExceptionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List ePWidgetsSortPreference = new ArrayList(); + Mockito.when(appService.deleteUserWidgetSortPref(ePWidgetsSortPreference, user)) + .thenThrow(nullPointerException); + assertNull(appsController.putUserWidgetsSortPref(mockedRequest, ePWidgetsSortPreference, mockedResponse)); + } + + @Test + public void deleteUserAppSortManualTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + EPDeleteAppsManualSortPref epDeleteAppsManualSortPref = new EPDeleteAppsManualSortPref(); + + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + FieldsValidator actualFieldValidator = new FieldsValidator(); + Mockito.when(appService.deleteUserAppSortManual(epDeleteAppsManualSortPref, user)) + .thenReturn(expectedFieldValidator); + actualFieldValidator = appsController.deleteUserAppSortManual(mockedRequest, epDeleteAppsManualSortPref, + mockedResponse); + assertEquals(actualFieldValidator, expectedFieldValidator); + } + + @Test + public void deleteUserAppSortManualExceptionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + EPDeleteAppsManualSortPref epDeleteAppsManualSortPref = new EPDeleteAppsManualSortPref(); + Mockito.when(appService.deleteUserAppSortManual(epDeleteAppsManualSortPref, user)) + .thenThrow(nullPointerException); + assertNull(appsController.deleteUserAppSortManual(mockedRequest, epDeleteAppsManualSortPref, mockedResponse)); + } + + @Test + public void putUserAppsSortingPreferenceTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + EPAppsSortPreference userAppsValue = new EPAppsSortPreference(); + + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + FieldsValidator actualFieldValidator = new FieldsValidator(); + Mockito.when(appService.saveAppsSortPreference(userAppsValue, user)).thenReturn(expectedFieldValidator); + actualFieldValidator = appsController.putUserAppsSortingPreference(mockedRequest, userAppsValue, + mockedResponse); + assertEquals(actualFieldValidator, expectedFieldValidator); + } + + @Test + public void putUserAppsSortingPreferenceExceptionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + EPAppsSortPreference userAppsValue = new EPAppsSortPreference(); + Mockito.when(appService.saveAppsSortPreference(userAppsValue, user)).thenThrow(nullPointerException); + assertNull(appsController.putUserAppsSortingPreference(mockedRequest, userAppsValue, mockedResponse)); + } + + @Test + public void getUserAppsSortTypePreferenceTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String expectedUserSortPreference = "TEST_DECE"; + String actualUserSortPreference = new String(); + Mockito.when(appService.getUserAppsSortTypePreference(user)).thenReturn(expectedUserSortPreference); + actualUserSortPreference = appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse); + assertEquals(actualUserSortPreference, expectedUserSortPreference); + } + + @Test + public void getUserAppsSortTypePreferenceExceptionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(appService.getUserAppsSortTypePreference(user)).thenThrow(nullPointerException); + assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse)); + } + + @Test + public void getUserAppsSortTypePreferenceIfUserNullTest() throws IOException { + EPUser user = null; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(appService.getUserAppsSortTypePreference(user)).thenThrow(nullPointerException); + assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse)); + } + + @Test + public void getAppsAdministratorsTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expecteAdminUserApplications = new ArrayList(); + List actualAdminUserApplications = new ArrayList(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getAppsAdmins()).thenReturn(expecteAdminUserApplications); + actualAdminUserApplications = appsController.getAppsAdministrators(mockedRequest, mockedResponse); + assertEquals(expecteAdminUserApplications, actualAdminUserApplications); + } + + @Test + public void getAppsAdministratorsIfUserNotSuperAdminTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse)); + } + + @Test + public void getAppsAdministratorsExceptionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getAppsAdmins()).thenThrow(nullPointerException); + assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse)); + } + + @Test + public void getAppsTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedApps = new ArrayList(); + AppsResponse apps = new AppsResponse((long) 1, "test", true, true); + expectedApps.add(apps); + + List atualApps = new ArrayList(); + + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getAllApps(false)).thenReturn(expectedApps); + atualApps = appsController.getApps(mockedRequest, mockedResponse); + assertEquals(expectedApps, atualApps); + } + + @Test + public void getAppsExceptionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + assertNull(appsController.getApps(mockedRequest, mockedResponse)); + } + + @Test + public void getAppsIfUserNotSuperAdminTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getAllApps(false)).thenThrow(nullPointerException); + assertNull(appsController.getApps(mockedRequest, mockedResponse)); + } + + @Test + public void getAllAppsTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedApps = new ArrayList(); + AppsResponse apps = new AppsResponse((long) 1, "test", true, true); + expectedApps.add(apps); + List atualApps = new ArrayList(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getAllApps(true)).thenReturn(expectedApps); + atualApps = appsController.getAllApps(mockedRequest, mockedResponse); + assertEquals(expectedApps, atualApps); + } + + @Test + public void getAllAppsExceptionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + assertNull(appsController.getAllApps(mockedRequest, mockedResponse)); + } + + @Test + public void getAllAppsIfUserNotSuperAdminTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getAllApps(true)).thenThrow(nullPointerException); + assertNull(appsController.getAllApps(mockedRequest, mockedResponse)); + } + + @Test + public void getAppsFullListTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedEcompApps = new ArrayList(); + + EcompApp ecompApp = new EcompApp(); + ecompApp.setId((long) 1); + ecompApp.setName("Test_app"); + ecompApp.setUrl("Test_URL"); + ecompApp.setUebKey("Test_key"); + ecompApp.setAlternateUrl("Test_alt_URL"); + expectedEcompApps.add(ecompApp); + List actualEcompApps = new ArrayList(); + Mockito.when(appService.getEcompAppAppsFullList()).thenReturn(expectedEcompApps); + actualEcompApps = appsController.getAppsFullList(mockedRequest, mockedResponse); + assertEquals(expectedEcompApps, actualEcompApps); + } + +// @Test +// public void getAppsFullListNoUserTest() { +// EPUser user = null; +// Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); +// Mockito.when(appService.getEcompAppAppsFullList()).thenReturn(null); +// assertNull(appsController.getAppsFullList(mockedRequest, mockedResponse)); +// +// } + + @Test + public void getUserProfileTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + UserRole userRole = new UserRole(); + userRole.setUser_Id((long) 1); + userRole.setOrgUserId("guest"); + userRole.setFirstName("Test_User_FirstName"); + userRole.setLastName("Test_User_LastName"); + userRole.setRoleId((long) 1); + userRole.setRoleName("test"); + + UserRoles unexpectedserAndRoles = new UserRoles(userRole); + unexpectedserAndRoles.setFirstName("Test_User_FirstName"); + unexpectedserAndRoles.setLastName("Test_User_LastName"); + unexpectedserAndRoles.setGuestSession(false); + unexpectedserAndRoles.setOrgUserId("guest"); + List roles = new ArrayList(); + roles.add("Test"); + unexpectedserAndRoles.setRoles(roles); + Mockito.when(appService.getUserProfileNormalized(user)).thenReturn(unexpectedserAndRoles); + UserRoles actualUserAndRoles = appsController.getUserProfile(mockedRequest, mockedResponse); + assertEquals(unexpectedserAndRoles, actualUserAndRoles); + } + + @Test + public void getUserProfileIfUserNullTest() throws IOException { + EPUser user = null; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(appService.getUserProfileNormalized(user)).thenReturn(null); + assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse)); + } + + @Test + public void getUserProfileExcpetionTest() throws IOException { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(appService.getUserProfileNormalized(user)).thenThrow(nullPointerException); + assertNull(appsController.getUserAppsSortTypePreference(mockedRequest, mockedResponse)); + } + + @Test + public void getAppRolesTest() { + List expectedRoleList = new ArrayList(); + LocalRole localRole = new LocalRole(); + localRole.setRoleId(1); + localRole.setRolename("test"); + expectedRoleList.add(localRole); + long appId = 1; + Mockito.when(appService.getAppRoles(appId)).thenReturn(expectedRoleList); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isAccountAdminOfApplication(Matchers.anyObject(), Matchers.anyObject())).thenReturn(true); + List actualRoleList = appsController.getAppRoles(mockedRequest, appId, mockedResponse); + assertEquals(actualRoleList, expectedRoleList); + } + + @Test + public void getAppRolesExceptionTest() { + long appId = 1; + Mockito.when(appService.getAppRoles(appId)).thenThrow(nullPointerException); + assertNull(appsController.getAppRoles(mockedRequest, appId, mockedResponse)); + } + + @Test + public void getOnboardingAppsTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedOnboardingApps = new ArrayList(); + OnboardingApp onboardingApp = new OnboardingApp(); + onboardingApp.setUebKey("test"); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getOnboardingApps()).thenReturn(expectedOnboardingApps); + List actualOnboardingApps = appsController.getOnboardingApps(mockedRequest, mockedResponse); + assertEquals(expectedOnboardingApps, actualOnboardingApps); + } + + @Test + public void getOnboardingAppsifSuperAdiminTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + assertNull(appsController.getOnboardingApps(mockedRequest, mockedResponse)); + } + + @Test + public void getOnboardingAppsExceptionTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(!adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.getOnboardingApps()).thenThrow(nullPointerException); + assertNull(appsController.getOnboardingApps(mockedRequest, mockedResponse)); + } + + @Test + public void putOnboardingAppTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + OnboardingApp OnboardingApp = new OnboardingApp(); + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.modifyOnboardingApp(OnboardingApp, user)).thenReturn(expectedFieldValidator); + FieldsValidator actualFieldValidator = appsController.putOnboardingApp(mockedRequest, OnboardingApp, + mockedResponse); + assertEquals(expectedFieldValidator, actualFieldValidator); + } + + @Test + public void putOnboardingAppIfSuperAdminTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + FieldsValidator expectedFieldValidator = null; + OnboardingApp OnboardingApp = new OnboardingApp(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(appService.modifyOnboardingApp(OnboardingApp, user)).thenReturn(expectedFieldValidator); + assertNull(appsController.putOnboardingApp(mockedRequest, OnboardingApp, mockedResponse)); + } + + @Test + public void putOnboardingAppExceptionTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + OnboardingApp OnboardingApp = new OnboardingApp(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.modifyOnboardingApp(OnboardingApp, user)).thenThrow(nullPointerException); + assertNull(appsController.putOnboardingApp(mockedRequest, OnboardingApp, mockedResponse)); + } + + @Test + public void postOnboardingAppTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + OnboardingApp OnboardingApp = new OnboardingApp(); + FieldsValidator expectedFieldValidator = new FieldsValidator(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(null); + expectedFieldValidator.setErrorCode(null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.addOnboardingApp(OnboardingApp, user)).thenReturn(expectedFieldValidator); + FieldsValidator actualFieldValidator = appsController.postOnboardingApp(mockedRequest, OnboardingApp, + mockedResponse); + assertEquals(expectedFieldValidator, actualFieldValidator); + } + + @Test + public void postOnboardingAppIfSuperAdminTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + FieldsValidator expectedFieldValidator = null; + OnboardingApp OnboardingApp = new OnboardingApp(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(appService.addOnboardingApp(OnboardingApp, user)).thenReturn(expectedFieldValidator); + assertNull(appsController.postOnboardingApp(mockedRequest, OnboardingApp, mockedResponse)); + } + + @Test + public void postOnboardingAppExceptionTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + OnboardingApp OnboardingApp = new OnboardingApp(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(appService.addOnboardingApp(OnboardingApp, user)).thenThrow(nullPointerException); + assertNull(appsController.postOnboardingApp(mockedRequest, OnboardingApp, mockedResponse)); + } + + @Test + public void deleteOnboardingAppTest() { + 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); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + long appId = 1; + Mockito.when(appService.deleteOnboardingApp(user,appId )).thenReturn(expectedFieldValidator); + FieldsValidator actualFieldValidator = appsController.deleteOnboardingApp(mockedRequest,appId, + mockedResponse); + assertEquals(expectedFieldValidator, actualFieldValidator); + } + + @Test + public void deleteOnboardingAppIfSuperAdminTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + FieldsValidator expectedFieldValidator = null; + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + long appId = 1; + Mockito.when(appService.deleteOnboardingApp(user,appId)).thenReturn(expectedFieldValidator); + assertNull(appsController.deleteOnboardingApp(mockedRequest,appId,mockedResponse)); + } + + @Test + public void deleteOnboardingAppExceptionTest() { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + long appId = 1; + Mockito.when(appService.deleteOnboardingApp(user,appId)).thenThrow(nullPointerException); + assertNull(appsController.deleteOnboardingApp(mockedRequest,appId,mockedResponse)); + } + + @Test + public void getLeftMenuItemsTest() + { + EPUser user = mockUser.mockEPUser(); + String menuList = "Test"; + PowerMockito.mockStatic(EPUserUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Set menuSet = new HashSet<>(); + menuSet.add(1); + Mockito.when(AppUtils.getSession(mockedRequest) + .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME))).thenReturn(menuSet); + Mockito.when(AppUtils.getSession(mockedRequest) + .getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME))).thenReturn(menuSet); + Mockito.when(leftMenuService.getLeftMenuItems(user, menuSet, menuSet)).thenReturn(menuList); + String response = appsController.getLeftMenuItems(mockedRequest, mockedResponse); + assertTrue(response.equals("Test")); + } + + @Test + public void getLeftMenuItemsExceptionTest() + { + EPUser user = mockUser.mockEPUser(); + String menuList = "Test"; + PowerMockito.mockStatic(EPUserUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Set menuSet = new HashSet<>(); + menuSet.add(1); + Mockito.when(AppUtils.getSession(mockedRequest) + .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME))).thenReturn(menuSet); + Mockito.when(AppUtils.getSession(mockedRequest) + .getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME))).thenReturn(menuSet); + Mockito.when(leftMenuService.getLeftMenuItems(user, menuSet, menuSet)).thenThrow(nullPointerException); + assertNull(appsController.getLeftMenuItems(mockedRequest, mockedResponse)); + } + + @Test + public void getAppThumbnailExceptionTest() + { + EPApp app = null; + assertNull(appsController.getAppThumbnail(mockedRequest, (long) 1, mockedResponse)); + } + + @Test + public void getAppThumbnailTest() + { + EPApp app = new EPApp(); + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppType(1); + app.setImageUrl("www.ecomp.com"); + app.setThumbnail(new byte[] {1, 6, 3}); + Mockito.when(appService.getApp((long) 1)).thenReturn(app); + HttpEntity response = appsController.getAppThumbnail(mockedRequest, (long) 1, mockedResponse); + assertEquals(response.getHeaders().getContentLength(), 3); + } + + @Test + public void getAppThumbnailForMediaTypePngTest() + { + + EPApp app = new EPApp(); + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppType(1); + app.setImageUrl("www.ecomp.png"); + app.setThumbnail(new byte[] {1, 6, 3}); + Mockito.when(appService.getApp((long) 1)).thenReturn(app); + PowerMockito.mockStatic(MediaType.class); + HttpEntity response = appsController.getAppThumbnail(mockedRequest, (long) 1, mockedResponse); + assertEquals(response.getHeaders().getContentLength(), 3); + } + + @Test + public void getUserAppsOrderBySortPrefIfUSerNullTest(){ + List listOfApps = new ArrayList(); + + EcompApp app = new EcompApp(); + listOfApps.add(app); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null); + assertNull(appsController.getUserAppsOrderBySortPref(mockedRequest, mockedResponse)); + } + + @Test + public void getUserAppsOrderBySortPrefTest(){ + List listOfApps = new ArrayList(); + + EcompApp app = new EcompApp(); + listOfApps.add(app); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(mockedRequest.getParameter("mparams")).thenReturn(""); + Mockito.when(appService.transformAppsToEcompApps(appService.getAppsOrderByName(user))).thenReturn(listOfApps); + List listOfActualApps = appsController.getUserAppsOrderBySortPref(mockedRequest, mockedResponse); + assertEquals(listOfActualApps.size(), 1); + } + + @Test + public void getUserAppsOrderBySortPrefIfusrSortPrefIsMTest(){ + List listOfApps = new ArrayList(); + + EcompApp app = new EcompApp(); + listOfApps.add(app); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(mockedRequest.getParameter("mparams")).thenReturn("M"); + Mockito.when(appService.transformAppsToEcompApps(appService.getAppsOrderByName(user))).thenReturn(listOfApps); + List listOfActualApps = appsController.getUserAppsOrderBySortPref(mockedRequest, mockedResponse); + assertEquals(listOfActualApps.size(), 1); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AuditLogControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AuditLogControllerTest.java new file mode 100644 index 00000000..27e72b64 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AuditLogControllerTest.java @@ -0,0 +1,139 @@ +/*- + * ============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 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.AuditLogController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.service.AuditService; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(EPUserUtils.class) +public class AuditLogControllerTest { + + + @Mock + AuditService auditService; + + @InjectMocks + AuditLogController auditLogController = new AuditLogController(); + + @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 auditLogTest() + { + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserId(mockedRequest)).thenReturn((int)1); + auditLogController.auditLog(mockedRequest, "1", "app", "test"); + } + + @Test + public void auditLogTabTest() + { + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserId(mockedRequest)).thenReturn((int)1); + auditLogController.auditLog(mockedRequest, "1", "tab", "test"); + } + + @Test + public void auditLogfunctionalTest() + { + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserId(mockedRequest)).thenReturn((int)1); + auditLogController.auditLog(mockedRequest, "1", "functional", "test"); + } + + @Test + public void auditLogleftMenuTest() + { + PowerMockito.mockStatic(EPUserUtils.class); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserId(mockedRequest)).thenReturn((int)1); + auditLogController.auditLog(mockedRequest, "1", "leftMenu", "test"); + } + + @Test(expected = NumberFormatException.class) + public void auditLogExceptionTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(EPUserUtils.getUserId(mockedRequest)).thenReturn((int)1); + auditLogController.auditLog(mockedRequest, "1", "app", "test"); + } + + @Test + public void auditLogerrorTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenThrow(nullPointerException); + auditLogController.auditLog(mockedRequest, "1", "app", "test"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/BEPropertyReaderControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/BEPropertyReaderControllerTest.java new file mode 100644 index 00000000..3ece25ff --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/BEPropertyReaderControllerTest.java @@ -0,0 +1,109 @@ +/*- + * ============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.assertTrue; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.controller.BEPropertyReaderController; +import org.onap.portalapp.portal.domain.BEProperty; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +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; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(SystemProperties.class) +public class BEPropertyReaderControllerTest extends MockitoTestSuite { + + @InjectMocks + BEPropertyReaderController bEPropertyReaderController = new BEPropertyReaderController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void readPropertyTest() { + String key = "DOMAIN_CLASS_LOCATION"; + BEProperty beProperty = new BEProperty("DOMAIN_CLASS_LOCATION", "domain_class_location"); + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("success"); + ecpectedPortalRestResponse.setResponse(beProperty); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + PortalRestResponse actualPortalRestResponse = null; + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty("DOMAIN_CLASS_LOCATION")).thenReturn("domain_class_location"); + actualPortalRestResponse = bEPropertyReaderController.readProperty(mockedRequest, key); + assertTrue(actualPortalRestResponse.equals(ecpectedPortalRestResponse)); + + } + + @Test + public void readPropertyExceptionTest() { + String key =null; + //BEProperty beProperty = new BEProperty("DOMAIN_CLASS_LOCATION", "domain_class_location"); + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("java.lang.NullPointerException"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + PortalRestResponse actualPortalRestResponse = null; + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(new BEProperty(key, SystemProperties.getProperty(key))).thenThrow(nullPointerException); + actualPortalRestResponse = bEPropertyReaderController.readProperty(mockedRequest, key); + assertTrue(actualPortalRestResponse.equals(ecpectedPortalRestResponse)); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/BasicAuthAccountControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/BasicAuthAccountControllerTest.java new file mode 100644 index 00000000..bec28d59 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/BasicAuthAccountControllerTest.java @@ -0,0 +1,301 @@ +/*- + * ============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.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.controller.BasicAuthAccountController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.BasicAuthCredentials; +import org.onap.portalapp.portal.domain.EPEndpoint; +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.MockitoTestSuite; +import org.onap.portalapp.portal.service.AdminRolesService; +import org.onap.portalapp.portal.service.AdminRolesServiceImpl; +import org.onap.portalapp.portal.service.BasicAuthAccountService; +import org.onap.portalapp.portal.service.BasicAuthAccountServiceImpl; +import org.onap.portalapp.util.EPUserUtils; + +public class BasicAuthAccountControllerTest extends MockitoTestSuite { + + @Mock + BasicAuthAccountService basicAuthAccountService = new BasicAuthAccountServiceImpl(); + + @Mock + AdminRolesService adminRolesService = new AdminRolesServiceImpl(); + + @InjectMocks + BasicAuthAccountController basicAuthAccountController = new BasicAuthAccountController(); + + @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(); + + public BasicAuthCredentials basicAuthCredentials() { + BasicAuthCredentials basicAuthCredentials = new BasicAuthCredentials(); + + basicAuthCredentials.setId((long) 1); + basicAuthCredentials.setApplicationName("test"); + basicAuthCredentials.setUsername("Test"); + basicAuthCredentials.setPassword("Password"); + basicAuthCredentials.setIsActive("YES"); + + List endpoints = new ArrayList(); + + EPEndpoint ePEndpoint = new EPEndpoint(); + ePEndpoint.setId((long) 1); + ePEndpoint.setName("Test"); + endpoints.add(ePEndpoint); + basicAuthCredentials.setEndpoints(endpoints); + + return basicAuthCredentials; + + } + + @Test + public void createBasicAuthAccountTest() throws Exception { + BasicAuthCredentials basicAuthCredentials = basicAuthCredentials(); + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("SUCCESS"); + expectedResponse.setResponse(""); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedResponse.setStatus(portalRestStatusEnum.OK); + long accountd = 1; + + Mockito.when(basicAuthAccountService.saveBasicAuthAccount(basicAuthCredentials)).thenReturn(accountd); + + PortalRestResponse actualResponse = basicAuthAccountController.createBasicAuthAccount(mockedRequest, + mockedResponse, basicAuthCredentials); + assertEquals(actualResponse, expectedResponse); + } + + @Test + public void createBasicAuthAccountAdminTest() throws Exception { + BasicAuthCredentials basicAuthCredentials = basicAuthCredentials(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("Authorization Required"); + expectedResponse.setResponse("Admin Only Operation! "); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedResponse.setStatus(portalRestStatusEnum.ERROR); + + PortalRestResponse actualResponse = basicAuthAccountController.createBasicAuthAccount(mockedRequest, + mockedResponse, basicAuthCredentials); + assertEquals(actualResponse, expectedResponse); + } + + @Test + public void createBasicAuthAccountIfInputNullTest() throws Exception { + BasicAuthCredentials basicAuthCredentials = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("FAILURE"); + expectedResponse.setResponse("newBasicAuthAccount cannot be null or empty"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedResponse.setStatus(portalRestStatusEnum.ERROR); + PortalRestResponse actualResponse = basicAuthAccountController.createBasicAuthAccount(mockedRequest, + mockedResponse, basicAuthCredentials); + assertEquals(actualResponse, expectedResponse); + } + + @Test + public void getBasicAuthAccountTest() throws Exception { + PortalRestResponse> expectedPortalResponse = new PortalRestResponse>(); + List basicAuthCredentialsList = new ArrayList(); + BasicAuthCredentials basicAuthCredentials = basicAuthCredentials(); + basicAuthCredentialsList.add(basicAuthCredentials); + + expectedPortalResponse.setMessage("Success"); + expectedPortalResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedPortalResponse.setStatus(portalRestStatusEnum.OK); + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(basicAuthAccountService.getAccountData()).thenReturn(null); + PortalRestResponse> actualResponse = basicAuthAccountController + .getBasicAuthAccount(mockedRequest, mockedResponse); + assertEquals(expectedPortalResponse, actualResponse); + } + + @Test + public void getBasicAuthAccountIfSuperAdminTest() throws Exception { + PortalRestResponse> expectedPortalResponse = new PortalRestResponse>(); + List basicAuthCredentialsList = new ArrayList(); + BasicAuthCredentials basicAuthCredentials = basicAuthCredentials(); + basicAuthCredentialsList.add(basicAuthCredentials); + + expectedPortalResponse.setMessage("UnAuthorized! Admin Only Operation"); + expectedPortalResponse.setResponse(new ArrayList<>()); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedPortalResponse.setStatus(portalRestStatusEnum.ERROR); + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(basicAuthAccountService.getAccountData()).thenReturn(null); + PortalRestResponse> actualResponse = basicAuthAccountController + .getBasicAuthAccount(mockedRequest, mockedResponse); + assertEquals(expectedPortalResponse, actualResponse); + } + + @Test + public void updateAccountTest() throws Exception { + BasicAuthCredentials basicAuthCredentials = basicAuthCredentials(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("SUCCESS"); + expectedResponse.setResponse(""); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedResponse.setStatus(portalRestStatusEnum.OK); + long accountd = 1; + PortalRestResponse actualResponse = basicAuthAccountController.updateAccount(mockedRequest, + mockedResponse, accountd, basicAuthCredentials); + assertEquals(actualResponse, expectedResponse); + } + + @Test + public void updateAccountIfSuperAdminTest() throws Exception { + BasicAuthCredentials basicAuthCredentials = basicAuthCredentials(); + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("Authorization Required"); + expectedResponse.setResponse("Admin Only Operation! "); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedResponse.setStatus(portalRestStatusEnum.ERROR); + long accountd = 1; + PortalRestResponse actualResponse = basicAuthAccountController.updateAccount(mockedRequest, + mockedResponse, accountd, basicAuthCredentials); + assertEquals(actualResponse, expectedResponse); + } + + @Test + public void updateAccountIfInputNullTest() throws Exception { + BasicAuthCredentials basicAuthCredentials = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("FAILURE"); + expectedResponse.setResponse("BasicAuthCredentials cannot be null or empty"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedResponse.setStatus(portalRestStatusEnum.ERROR); + long accountd = 1; + PortalRestResponse actualResponse = basicAuthAccountController.updateAccount(mockedRequest, + mockedResponse, accountd, basicAuthCredentials); + assertEquals(actualResponse, expectedResponse); + } + + @Test + public void deleteAccountTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("SUCCESS"); + expectedResponse.setResponse(""); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedResponse.setStatus(portalRestStatusEnum.OK); + long accountd = 1; + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + PortalRestResponse actualResponse = basicAuthAccountController.deleteAccount(mockedRequest, + mockedResponse, accountd); + assertEquals(actualResponse, expectedResponse); + } + + @Test + public void deleteAccountIfNotSuperAdminTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("Authorization Required"); + expectedResponse.setResponse("Admin Only Operation! "); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedResponse.setStatus(portalRestStatusEnum.ERROR); + long accountd = 1; + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + PortalRestResponse actualResponse = basicAuthAccountController.deleteAccount(mockedRequest, + mockedResponse, accountd); + System.out.println(actualResponse); + assertEquals(actualResponse, expectedResponse); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/CommonWidgetControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/CommonWidgetControllerTest.java new file mode 100644 index 00000000..76961f89 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/CommonWidgetControllerTest.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.assertTrue; + +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.portal.controller.CommonWidgetController; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +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.transport.CommonWidgetMeta; + +public class CommonWidgetControllerTest { + + @Mock + DashboardSearchService dashboardSearchService = new DashboardSearchServiceImpl(); + + @InjectMocks + CommonWidgetController commonWidgetController = new CommonWidgetController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @SuppressWarnings("unchecked") + @Test + public void getWidgetDataTest() { + String resourceType = "Test"; + PortalRestResponse acutualPoratlRestResponse = null; + @SuppressWarnings("rawtypes") + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("Unexpected resource type Test"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + acutualPoratlRestResponse = commonWidgetController.getWidgetData(mockedRequest, resourceType); + assertTrue(acutualPoratlRestResponse.equals(ecpectedPortalRestResponse)); + + } + + @SuppressWarnings("unchecked") + @Test + public void getWidgetDataTestNew() { + String resourceType = "EVENTS"; + PortalRestResponse acutualPoratlRestResponse = null; + @SuppressWarnings("rawtypes") + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("success"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + acutualPoratlRestResponse = commonWidgetController.getWidgetData(mockedRequest, resourceType); + assertTrue(acutualPoratlRestResponse.equals(ecpectedPortalRestResponse)); + + } + + @SuppressWarnings("unchecked") + @Test + public void getWidgetDataExceptionTest() { + String resourceType = "null"; + PortalRestResponse acutualPoratlRestResponse = null; + @SuppressWarnings("rawtypes") + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("Unexpected resource type null"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + acutualPoratlRestResponse = commonWidgetController.getWidgetData(mockedRequest, resourceType); + assertTrue(acutualPoratlRestResponse.equals(ecpectedPortalRestResponse)); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ConsulClientControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ConsulClientControllerTest.java new file mode 100644 index 00000000..8481413e --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ConsulClientControllerTest.java @@ -0,0 +1,179 @@ +/*- + * ============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.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.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.controller.ConsulClientController; +import org.onap.portalapp.portal.domain.BEProperty; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.ConsulHealthService; +import org.onap.portalapp.portal.service.ConsulHealthServiceImpl; + +import com.orbitz.consul.ConsulException; +import com.orbitz.consul.model.health.ServiceHealth; + +import io.searchbox.client.config.exception.NoServerConfiguredException; + +public class ConsulClientControllerTest { + + @Mock + ConsulHealthService consulHealthService = new ConsulHealthServiceImpl(); + + @InjectMocks + ConsulClientController consulClientController = new ConsulClientController(); + + NoServerConfiguredException noServerConfiguredException = new NoServerConfiguredException(null); + + String service = "Test"; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + ConsulException consulException = new ConsulException(nullPointerException); + + @Test + public void getServiceLocationTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("Success!"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + PortalRestResponse actualPortalRestRespone = new PortalRestResponse(); + actualPortalRestRespone = consulClientController.getServiceLocation(mockedRequest, mockedResponse, service); + assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse)); + } + + @Test + public void getServiceLocationExceptionTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("Warning!"); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.WARN); + PortalRestResponse actualPortalRestRespone = new PortalRestResponse(); + Mockito.when(consulHealthService.getServiceLocation(service, null)).thenThrow(noServerConfiguredException); + actualPortalRestRespone = consulClientController.getServiceLocation(mockedRequest, mockedResponse, service); + assertTrue(actualPortalRestRespone.getMessage().equals(ecpectedPortalRestResponse.getMessage())); + assertTrue(actualPortalRestRespone.getStatus().equals(ecpectedPortalRestResponse.getStatus())); + + } + + @Test + public void getServiceLocationExceptionConsulExceptionTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("Error!"); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + PortalRestResponse actualPortalRestRespone = new PortalRestResponse(); + Mockito.when(consulHealthService.getServiceLocation(service, null)).thenThrow(consulException); + actualPortalRestRespone = consulClientController.getServiceLocation(mockedRequest, mockedResponse, service); + assertTrue(actualPortalRestRespone.getMessage().equals(ecpectedPortalRestResponse.getMessage())); + assertTrue(actualPortalRestRespone.getStatus().equals(ecpectedPortalRestResponse.getStatus())); + } + + public PortalRestResponse> successResponse() { + PortalRestResponse> ecpectedPortalRestResponse = new PortalRestResponse>(); + List healths = new ArrayList(); + ecpectedPortalRestResponse.setMessage("Success!"); + ecpectedPortalRestResponse.setResponse(healths); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + return ecpectedPortalRestResponse; + } + + public PortalRestResponse> errorResponse() { + PortalRestResponse> ecpectedPortalRestResponse = new PortalRestResponse>(); + List healths = new ArrayList(); + ecpectedPortalRestResponse.setMessage("Error!"); + ecpectedPortalRestResponse.setResponse(healths); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + return ecpectedPortalRestResponse; + } + + @Test + public void getAllHealthyNodesTest() { + PortalRestResponse> ecpectedPortalRestResponse = successResponse(); + PortalRestResponse> actualPortalRestRespone = new PortalRestResponse>(); + actualPortalRestRespone = consulClientController.getAllHealthyNodes(mockedRequest, mockedResponse, service); + assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse)); + + } + + @Test + public void getAllHealthyNodesExceptionTest() { + PortalRestResponse> ecpectedPortalRestResponse = errorResponse(); + PortalRestResponse> actualPortalRestRespone = new PortalRestResponse>(); + Mockito.when(consulHealthService.getAllHealthyNodes(service)).thenThrow(consulException); + actualPortalRestRespone = consulClientController.getAllHealthyNodes(mockedRequest, mockedResponse, service); + assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse)); + } + + @Test + public void getAllNodesTest() { + PortalRestResponse> ecpectedPortalRestResponse = successResponse(); + PortalRestResponse> actualPortalRestRespone = new PortalRestResponse>(); + actualPortalRestRespone = consulClientController.getAllNodes(mockedRequest, mockedResponse, service); + assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse)); + } + + @Test + public void getAllNodesExceptionTest() { + PortalRestResponse> ecpectedPortalRestResponse = errorResponse(); + PortalRestResponse> actualPortalRestRespone = new PortalRestResponse>(); + Mockito.when(consulHealthService.getAllNodes(service)).thenThrow(consulException); + actualPortalRestRespone = consulClientController.getAllNodes(mockedRequest, mockedResponse, service); + assertTrue(actualPortalRestRespone.equals(ecpectedPortalRestResponse)); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java new file mode 100644 index 00000000..37f7f687 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java @@ -0,0 +1,467 @@ +/*- + * ============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.io.IOException; +import java.util.ArrayList; +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.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.controller.DashboardController; +import org.onap.portalapp.portal.core.MockEPUser; +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.MockitoTestSuite; +import org.onap.portalapp.portal.service.AdminRolesService; +import org.onap.portalapp.portal.service.AdminRolesServiceImpl; +import org.onap.portalapp.portal.service.DashboardSearchService; +import org.onap.portalapp.portal.service.DashboardSearchServiceImpl; +import org.onap.portalapp.portal.transport.CommonWidget; +import org.onap.portalapp.portal.transport.CommonWidgetMeta; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.domain.support.CollaborateList; +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; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({EPUserUtils.class, CollaborateList.class, SystemProperties.class, EPCommonSystemProperties.class}) +public class DashboardControllerTest { + + @Mock + DashboardSearchService searchService = new DashboardSearchServiceImpl(); + + @InjectMocks + DashboardController dashboardController = new DashboardController(); + + @Mock + AdminRolesService adminRolesService = new AdminRolesServiceImpl(); + @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(); + + public CommonWidgetMeta mockCommonWidgetMeta() { + CommonWidgetMeta commonWidgetMeta= new CommonWidgetMeta(); + List widgetList = new ArrayList<>(); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory("test"); + commonWidget.setHref("testhref"); + commonWidget.setTitle("testTitle"); + commonWidget.setContent("testcontent"); + commonWidget.setEventDate("testDate"); + commonWidget.setSortOrder(1); + widgetList.add(commonWidget); + commonWidgetMeta.setItems(widgetList); + + return commonWidgetMeta; + } + + public CommonWidget mockCommonWidget() { + + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory("test"); + commonWidget.setHref("testhref"); + commonWidget.setTitle("testTitle"); + commonWidget.setContent("testcontent"); + commonWidget.setEventDate("testDate"); + commonWidget.setSortOrder(1); + + return commonWidget; + } + + + @Test + public void getWidgetDataTest() throws IOException { + + String resourceType = null; + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("Unexpected resource type null"); + expectedData.setResponse(null); + + PortalRestResponse actualResponse = dashboardController.getWidgetData(mockedRequest, resourceType); + assertEquals(expectedData,actualResponse); + } + + @Test + public void getWidgetDataWithValidResourceTest() throws IOException { + String resourceType = "EVENTS"; + CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta(); + commonWidgetMeta.setCategory(null); + + Mockito.when(searchService.getWidgetData(resourceType)).thenReturn(commonWidgetMeta); + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse(commonWidgetMeta); + + PortalRestResponse actualResponse = dashboardController.getWidgetData(mockedRequest, resourceType); + assertEquals(expectedData,actualResponse); + } + + @Test + public void saveWidgetDataBulkNullTest() throws IOException { + CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta(); + commonWidgetMeta.setCategory(null); + + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("ERROR"); + expectedData.setResponse("Category cannot be null or empty"); + + PortalRestResponse actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta); + assertEquals(expectedData,actualResponse); + } + + @Test + public void saveWidgetUnexpectedDataBulkTest() throws IOException { + CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta(); + commonWidgetMeta.setCategory("Unexpected Data"); + + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("Unexpected resource type Unexpected Data"); + expectedData.setResponse(null); + + PortalRestResponse actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta); + assertEquals(expectedData,actualResponse); + + } + + @Test + public void saveWidgetInvalidDataBulkTest() throws IOException { + CommonWidgetMeta commonWidgetMeta= mockCommonWidgetMeta(); + commonWidgetMeta.setCategory("EVENTS"); + + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("Invalid category: test"); + expectedData.setResponse(null); + + PortalRestResponse actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta); + assertEquals(expectedData,actualResponse); + } + + @Test + public void saveWidgetDataBulkTest() throws IOException { + + List widgetList = new ArrayList<>(); + CommonWidget commonWidget = new CommonWidget("EVENTS", "http://test.com", "testTitle", "testcontent", "2017-07-01", 1); + widgetList.add(commonWidget); + CommonWidgetMeta commonWidgetMeta= new CommonWidgetMeta("EVENTS", widgetList); + + + + /* commonWidgetMeta.setItems(widgetList); + + commonWidgetMeta.setCategory("EVENTS");*/ + + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse("success"); + + Mockito.when(searchService.saveWidgetDataBulk(commonWidgetMeta)).thenReturn("success"); + + PortalRestResponse actualResponse = dashboardController.saveWidgetDataBulk(commonWidgetMeta); + assertEquals(expectedData,actualResponse); + } + + @Test + public void saveWidgetDataNullTest() throws IOException { + + CommonWidget commonWidget = mockCommonWidget(); + commonWidget.setId((long)1); + commonWidget.setContent("test"); + commonWidget.setCategory(null); + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("ERROR"); + expectedData.setResponse("Category cannot be null or empty"); + + Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true); + PortalRestResponse actualResponse = dashboardController.saveWidgetData(commonWidget, mockedRequest, mockedResponse); + assertEquals(expectedData,actualResponse); + + } + + @Test + public void saveWidgetDataErrorTest() throws IOException { + + CommonWidget commonWidget = mockCommonWidget(); + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("Invalid category: test"); + expectedData.setResponse(null); + Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true); + PortalRestResponse actualResponse = dashboardController.saveWidgetData(commonWidget, mockedRequest, mockedResponse); + assertEquals(expectedData,actualResponse); + } + + @Test + public void saveWidgetDataTest() throws IOException { + + CommonWidgetMeta commonWidgetMeta= new CommonWidgetMeta(); + List widgetList = new ArrayList<>(); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory("EVENTS"); + commonWidget.setHref("http://test.com"); + commonWidget.setTitle("testTitle"); + commonWidget.setContent("testcontent"); + commonWidget.setEventDate("2017-07-01"); + commonWidget.setSortOrder(1); + widgetList.add(commonWidget); + commonWidgetMeta.setItems(widgetList); + + commonWidgetMeta.setCategory("EVENTS"); + + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse("success"); + Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true); + Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn("success"); + PortalRestResponse actualResponse = dashboardController.saveWidgetData(commonWidget, mockedRequest, mockedResponse); + assertEquals(expectedData,actualResponse); + + } + + @Test + public void deleteWidgetDataTest() throws IOException { + + CommonWidget commonWidget = mockCommonWidget(); + + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse(null); + + Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn("success"); + + PortalRestResponse actualResponse = dashboardController.deleteWidgetData(commonWidget); + assertEquals(expectedData,actualResponse); + + } + + @Test + public void getActiveUsersTest(){ + List activeUsers = new ArrayList<>(); + List expectedUsersList = new ArrayList<>(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String userId = user.getOrgUserId(); + Mockito.when(searchService.getRelatedUsers(userId)).thenReturn(activeUsers); + expectedUsersList= dashboardController.getActiveUsers(mockedRequest); + assertEquals(expectedUsersList, activeUsers); + } + + + @Test + public void getActiveUsersExceptionTest(){ + List activeUsers = new ArrayList<>(); + List expectedUsersList = new ArrayList<>(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + String userId = user.getOrgUserId(); + Mockito.when(searchService.getRelatedUsers(userId)).thenThrow(nullPointerException); + expectedUsersList = dashboardController.getActiveUsers(mockedRequest); + assertEquals(expectedUsersList, activeUsers); + } + + @Test + public void getOnlineUserUpdateRateTest(){ + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse("{onlineUserUpdateRate=1400000, onlineUserUpdateDuration=1400000}"); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_RATE)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_DURATION)).thenReturn("1400"); + + PortalRestResponse> actualResponse = dashboardController.getOnlineUserUpdateRate(mockedRequest); + assertEquals(expectedData.getStatus(),actualResponse.getStatus()); + } + + @Test + public void getOnlineUserUpdateRateExceptionTest(){ + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("java.lang.NullPointerException"); + expectedData.setResponse(null); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_RATE)).thenThrow(nullPointerException); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_DURATION)).thenThrow(nullPointerException); + + PortalRestResponse> actualResponse = dashboardController.getOnlineUserUpdateRate(mockedRequest); + assertEquals(expectedData,actualResponse); + } + + @Test + public void getWindowWidthThresholdForRightMenuTest(){ + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse("{windowWidth=1400}"); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_RIGHT_MENU)).thenReturn("1400"); + + PortalRestResponse> actualResponse = dashboardController.getWindowWidthThresholdForRightMenu(mockedRequest); + assertEquals(expectedData.getStatus(),actualResponse.getStatus()); + } + + @Test + public void getWindowWidthThresholdForRightMenuExceptionTest(){ + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("java.lang.NullPointerException"); + expectedData.setResponse(null); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_RIGHT_MENU)).thenThrow(nullPointerException); + + PortalRestResponse> actualResponse = dashboardController.getWindowWidthThresholdForRightMenu(mockedRequest); + assertEquals(expectedData,actualResponse); + } + + @Test + public void getWindowWidthThresholdForLeftMenuTest(){ + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse("{windowWidth=1400}"); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_LEFT_MENU)).thenReturn("1400"); + + PortalRestResponse> actualResponse = dashboardController.getWindowWidthThresholdForLeftMenu(mockedRequest); + assertEquals(expectedData.getStatus(),actualResponse.getStatus()); + } + + @Test + public void getWindowWidthThresholdForLeftMenuExceptionTest(){ + PortalRestResponse expectedData = new PortalRestResponse(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("java.lang.NullPointerException"); + expectedData.setResponse(null); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_LEFT_MENU)).thenThrow(nullPointerException); + + PortalRestResponse> actualResponse = dashboardController.getWindowWidthThresholdForLeftMenu(mockedRequest); + assertEquals(expectedData,actualResponse); + } + + @Test + public void getActiveUsersNullTest(){ + PortalRestResponse> expectedData = new PortalRestResponse>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("User object is null? - check logs"); + expectedData.setResponse(new ArrayList<>()); + + PortalRestResponse> actualResponse = dashboardController.activeUsers(mockedRequest); + assertEquals(expectedData,actualResponse); + } + + @Test + public void activeUsersTest(){ + EPUser user = mockUser.mockEPUser(); + PortalRestResponse> expectedData = new PortalRestResponse>(); + expectedData.setStatus(PortalRestStatusEnum.OK); + expectedData.setMessage("success"); + expectedData.setResponse(new ArrayList<>()); + PowerMockito.mockStatic(EPUserUtils.class); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + PortalRestResponse> actualResponse = dashboardController.activeUsers(mockedRequest); + assertEquals(expectedData,actualResponse); + } + + @Test + public void activeUsersExceptionTest(){ + EPUser user = mockUser.mockEPUser(); + user.setLoginId("test"); + PortalRestResponse> expectedData = new PortalRestResponse>(); + expectedData.setStatus(PortalRestStatusEnum.ERROR); + expectedData.setMessage("null - check logs."); + expectedData.setResponse(null); + + PowerMockito.mockStatic(EPUserUtils.class); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(searchService.getRelatedUsers(user.getLoginId())).thenThrow(nullPointerException); + PortalRestResponse> actualResponse = dashboardController.activeUsers(mockedRequest); + assertTrue(actualResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java new file mode 100644 index 00000000..229f1ba9 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardSearchResultControllerTest.java @@ -0,0 +1,403 @@ +/*- + * ============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.core.MockEPUser; +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.MockitoTestSuite; +import org.onap.portalapp.portal.service.DashboardSearchService; +import org.onap.portalapp.portal.service.DashboardSearchServiceImpl; +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 = new DashboardSearchServiceImpl(); + + @InjectMocks + DashboardSearchResultController dashboardSearchResultController = new DashboardSearchResultController(); + + @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 getWidgetDataTest() { + String resourceType = "test"; + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("success"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + Mockito.when(searchService.getWidgetData(resourceType)).thenReturn(null); + PortalRestResponse acutualPoratlRestResponse = dashboardSearchResultController + .getWidgetData(mockedRequest, resourceType); + assertEquals(acutualPoratlRestResponse, ecpectedPortalRestResponse); + + } + + @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 commonWidgetList = new ArrayList(); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory("test"); + commonWidget.setHref("test_href"); + commonWidget.setTitle("test_title"); + commonWidget.setContent("test_content"); + commonWidget.setEventDate(null); + commonWidget.setSortOrder(1); + + commonWidgetList.add(commonWidget); + + commonWidgetMeta.setItems(commonWidgetList); + + Mockito.when(searchService.saveWidgetDataBulk(commonWidgetMeta)).thenReturn(null); + + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetDataBulk(commonWidgetMeta); + assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse); + } + + @Test + public void saveWidgetDataBulkIfCategoryNullTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"1\""); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + + CommonWidgetMeta commonWidgetMeta = new CommonWidgetMeta(); + commonWidgetMeta.setCategory("test"); + + List commonWidgetList = new ArrayList(); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId(null); + commonWidget.setCategory(null); + commonWidget.setHref(null); + commonWidget.setTitle(null); + commonWidget.setContent("test_content"); + commonWidget.setEventDate("1"); + commonWidget.setSortOrder(1); + commonWidgetList.add(commonWidget); + commonWidgetMeta.setItems(commonWidgetList); + + Mockito.when(searchService.saveWidgetDataBulk(commonWidgetMeta)).thenReturn(null); + + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetDataBulk(commonWidgetMeta); + assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse); + } + + @Test + public void saveWidgetDataTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("success"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory("test"); + commonWidget.setHref("test_href"); + commonWidget.setTitle("test_title"); + commonWidget.setContent("test_content"); + commonWidget.setEventDate(null); + commonWidget.setSortOrder(1); + + Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn(null); + + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetData(commonWidget); + assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse); + + } + + @Test + public void saveWidgetDataExceptionTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("ERROR"); + ecpectedPortalRestResponse.setResponse("Cateogry cannot be null or empty"); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory(""); + commonWidget.setHref("test_href"); + commonWidget.setTitle("test_title"); + commonWidget.setContent("test_content"); + commonWidget.setEventDate(null); + commonWidget.setSortOrder(1); + + Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn(null); + + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetData(commonWidget); + assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse); + + } + + @Test + public void saveWidgetDataDateErrorTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("java.text.ParseException: Unparseable date: \"1\""); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory("test"); + commonWidget.setHref("test_href"); + commonWidget.setTitle("test_title"); + commonWidget.setContent("test_content"); + commonWidget.setEventDate("1"); + commonWidget.setSortOrder(1); + + Mockito.when(searchService.saveWidgetData(commonWidget)).thenReturn(null); + + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .saveWidgetData(commonWidget); + assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse); + + } + + public void deleteWidgetDataTest() { + PortalRestResponse ecpectedPortalRestResponse = new PortalRestResponse(); + ecpectedPortalRestResponse.setMessage("success"); + ecpectedPortalRestResponse.setResponse(null); + ecpectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + CommonWidget commonWidget = new CommonWidget(); + commonWidget.setId((long) 1); + commonWidget.setCategory("test"); + commonWidget.setHref("test_href"); + commonWidget.setTitle("test_title"); + commonWidget.setContent("test_content"); + commonWidget.setEventDate(null); + commonWidget.setSortOrder(1); + Mockito.when(searchService.deleteWidgetData(commonWidget)).thenReturn(null); + + PortalRestResponse actualPortalRestResponse = dashboardSearchResultController + .deleteWidgetData(commonWidget); + System.out.println(actualPortalRestResponse); + assertEquals(actualPortalRestResponse, ecpectedPortalRestResponse); + } + + @Test + public void searchPortalIfUserIsNull() { + 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); + assertEquals(expectedResult, actualResult); + } + + @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); + } + + @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); + + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EPFusionBaseControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EPFusionBaseControllerTest.java new file mode 100644 index 00000000..d7950e37 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EPFusionBaseControllerTest.java @@ -0,0 +1,151 @@ +/*- + * ============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.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +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.EPFusionBaseController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPUser; +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.portal.utils.EcompPortalUtils; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.domain.MenuData; +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; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({EPUserUtils.class, SystemProperties.class, EPCommonSystemProperties.class, EcompPortalUtils.class}) +public class EPFusionBaseControllerTest { + + @Mock + DashboardSearchService searchService = new DashboardSearchServiceImpl(); + + @InjectMocks + EPFusionBaseController epFusionBaseController = new EPFusionBaseController() { + }; + + + @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 messagesExceptionTest(){ + Map expectedData = new HashMap(); + Map actualData = null; + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EcompPortalUtils.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME)).thenReturn("test"); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Set menuResult = null; + HttpSession session = mockedRequest.getSession(); + Mockito.when(session + .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME))).thenReturn(menuResult); + actualData = epFusionBaseController.messages(mockedRequest); + assertEquals(expectedData,actualData ); + System.out.println(); + + } + + @Test + public void messagesTest(){ + Map expectedData = new HashMap(); + Map actualData = null; + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EcompPortalUtils.class); + + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME)).thenReturn("test"); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Set menuResult = new HashSet<>(); + MenuData menuData= new MenuData(); + menuResult.add(menuData); + menuData.setChildMenus(menuResult); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session + .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME))).thenReturn(menuResult); + actualData = epFusionBaseController.messages(mockedRequest); + assertEquals(actualData.size(), 2); + } + + @Test + public void isAccessibleTest() + { + assertTrue(epFusionBaseController.isAccessible()); + } + @Test + public void isRESTfulCallTest() + { + assertTrue(epFusionBaseController.isRESTfulCall()); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EPRestrictedBaseControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EPRestrictedBaseControllerTest.java new file mode 100644 index 00000000..ca415121 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/EPRestrictedBaseControllerTest.java @@ -0,0 +1,70 @@ + +/*- + * ============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 org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.EPRestrictedBaseController; + +public class EPRestrictedBaseControllerTest { + + @InjectMocks + EPRestrictedBaseController ePRestrictedBaseController = new EPRestrictedBaseController() ; + + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Test + public void isAccessibleTest() + { + assertFalse(ePRestrictedBaseController.isAccessible()); + } + + @Test + public void isRESTfulCallTest() + { + assertFalse(ePRestrictedBaseController.isRESTfulCall()); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java new file mode 100644 index 00000000..859cc4c2 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java @@ -0,0 +1,711 @@ +/*- + * ============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.io.PrintWriter; +import java.io.StringWriter; +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.Ignore; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.CentralV2RoleFunction; +import org.onap.portalapp.portal.domain.EPApp; +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.MockitoTestSuite; +import org.onap.portalapp.portal.service.ExternalAccessRolesService; +import org.onap.portalapp.portal.service.ExternalAccessRolesServiceImpl; +import org.onap.portalapp.portal.transport.CentralRoleFunction; +import org.onap.portalapp.portal.transport.CentralV2Role; +import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator; +import org.onap.portalsdk.core.domain.AuditLog; +import org.onap.portalsdk.core.domain.Role; +import org.onap.portalsdk.core.restful.domain.EcompUser; +import org.springframework.beans.BeanUtils; +import org.springframework.http.HttpStatus; +import org.springframework.web.client.HttpClientErrorException; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ExternalAccessRolesControllerTest { + + @Mock + ExternalAccessRolesService externalAccessRolesService = new ExternalAccessRolesServiceImpl(); + + @InjectMocks + ExternalAccessRolesController externalAccessRolesController = new ExternalAccessRolesController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Mock + AuditLog auditLog = new AuditLog(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Failed"); + + MockEPUser mockUser = new MockEPUser(); + String loginId = "guestT"; + String uebKey = "testUebKey"; + + @Test + public void getUserTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + List userList = new ArrayList<>(); + Mockito.when(externalAccessRolesService.getUser(loginId)).thenReturn(userList); + externalAccessRolesController.getUser(mockedRequest, mockedResponse, loginId); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + @Test + public void getUserExceptionTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + externalAccessRolesController.getUser(mockedRequest, mockedResponse, loginId); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + public EPApp mockApp() + { + EPApp app = new EPApp(); + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(false); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + return app; + } + + @Test(expected = NullPointerException.class) + public void getRolesForAppTest() throws Exception { + List applicationList = new ArrayList(); + List answer = new ArrayList<>(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app); + Mockito.when(externalAccessRolesService.getRolesForApp(mockedRequest.getHeader(uebKey))).thenReturn(answer); + assertEquals(externalAccessRolesController.getRolesForApp(mockedRequest, mockedResponse), null); + } + + @Test(expected = NullPointerException.class) + public void getRolesForAppExceptionTest() throws Exception { + List applicationList = new ArrayList(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app); + externalAccessRolesController.getRolesForApp(mockedRequest,mockedResponse); + List role = externalAccessRolesService.getRolesForApp(mockedRequest.getHeader(uebKey)); + assertEquals(null,role); + } + + @Test + public void getRoleFunctionsListTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + List answer = null; + Mockito.when(externalAccessRolesService.getRoleFuncList(mockedRequest.getHeader(uebKey))).thenReturn(null); + assertEquals(externalAccessRolesController.getRoleFunctionsList(mockedRequest, mockedResponse), answer); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + @Test + public void getRoleFunctionsListExceptionTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + externalAccessRolesController.getRoleFunctionsList(mockedRequest, mockedResponse); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + @Test + public void getRoleInfoTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + CentralV2Role answer = new CentralV2Role(); + long roleId = 1; + Mockito.when(externalAccessRolesService.getRoleInfo(roleId, mockedRequest.getHeader(uebKey))) + .thenReturn(answer); + externalAccessRolesController.getRoleInfo(mockedRequest, mockedResponse, roleId); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + @Test + public void getRoleInfoExceptionTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + long roleId = 1; + assertNull(externalAccessRolesController.getRoleInfo(mockedRequest, mockedResponse, roleId)); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + @Test + public void getRoleFunctionTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(); + CentralRoleFunction centralRoleFunction = new CentralRoleFunction(); + String code = "test_menu"; + Mockito.when(externalAccessRolesService.getRoleFunction(code, mockedRequest.getHeader(uebKey))) + .thenReturn(centralV2RoleFunction); + CentralRoleFunction returnedValue = externalAccessRolesController.getRoleFunction(mockedRequest, mockedResponse, code); + BeanUtils.copyProperties(centralV2RoleFunction, centralRoleFunction, "type","action"); + assertEquals(returnedValue,centralRoleFunction); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + @Test + public void getRoleFunctionExceptionTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + String code = "test_menu"; + Mockito.when(externalAccessRolesService.getRoleFunction(code, mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + assertEquals(new CentralRoleFunction(),externalAccessRolesController.getRoleFunction(mockedRequest, mockedResponse, code)); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + @Test(expected = NullPointerException.class) + public void saveRoleFunctionIfIsIsNotDeletedTest() throws Exception { + List applicationList = new ArrayList(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Invalid uebkey!"); + expectedportalRestResponse.setResponse("Failed"); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + String data = null; + CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(); + Mockito.when(externalAccessRolesService.saveCentralRoleFunction(centralV2RoleFunction, app)).thenReturn(false); + portalRestResponse = externalAccessRolesController.saveRoleFunction(mockedRequest, mockedResponse, data); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test(expected = NullPointerException.class) + public void saveRoleFunctionExceptionTest() throws Exception { + List applicationList = new ArrayList(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Invalid uebkey!"); + expectedportalRestResponse.setResponse("Failed"); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.saveRoleFunction(mockedRequest, mockedResponse, null); + System.out.println(portalRestResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test(expected = NullPointerException.class) + public void saveRoleFunctionTest() throws Exception { + List applicationList = new ArrayList(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + String data = null; + CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(); + Mockito.when(externalAccessRolesService.saveCentralRoleFunction(centralV2RoleFunction, app)).thenReturn(true); + portalRestResponse = externalAccessRolesController.saveRoleFunction(mockedRequest, mockedResponse, data); + System.out.println(portalRestResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + @Ignore + public void deleteRoleFunctionTest() throws Exception { + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Successfully Deleted"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + EPUser user = mockUser.mockEPUser(); + EPApp app = mockApp(); + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + String code ="testNew"; + Mockito.when(externalAccessRolesService.getUser(mockedRequest.getHeader("LOGIN_ID"))).thenReturn((List) user); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader("UEBKEY")).get(0)).thenReturn(app); + Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(code, app)).thenReturn(true); + portalRestResponse = externalAccessRolesController.deleteRoleFunction(mockedRequest, mockedResponse, code); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void getActiveRolesTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + Mockito.when(externalAccessRolesService.getActiveRoles(mockedRequest.getHeader(uebKey))).thenReturn(null); + List expectedCenRole = externalAccessRolesController.getActiveRoles(mockedRequest, mockedResponse); + assertNull(expectedCenRole); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + @Test + public void getActiveRolesExceptionTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + externalAccessRolesController.getActiveRoles(mockedRequest, mockedResponse); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + /** + * It return JSON string which has error information + * + * @return JSON String + * @throws JsonProcessingException + */ + private String getInvalidKeyJson() throws JsonProcessingException { + final Map uebkeyResponse = new HashMap<>(); + String reason = ""; + ObjectMapper mapper = new ObjectMapper(); + uebkeyResponse.put("error","Invalid uebkey!"); + reason = mapper.writeValueAsString(uebkeyResponse); + return reason; + } + + @Test + public void deleteDependcyRoleRecordExceptionTest() throws Exception { + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Invalid uebkey!"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + long roleId = 123; + portalRestResponse = externalAccessRolesController.deleteDependencyRoleRecord(mockedRequest, mockedResponse, roleId); + assertEquals(expectedportalRestResponse, portalRestResponse); + } + + @Test + public void bulkUploadFunctionsTest() throws Exception { + Integer result = 0; + Mockito.when(externalAccessRolesService.bulkUploadFunctions(mockedRequest.getHeader(uebKey))) + .thenReturn(result); + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Successfully added: 0"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + portalRestResponse = externalAccessRolesController.bulkUploadFunctions(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadFunctionsExceptionTest() throws Exception { + Mockito.when(externalAccessRolesService.bulkUploadFunctions(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Failed to bulkUploadFunctions"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.bulkUploadFunctions(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadRolesTest() throws Exception { + Integer result = 0; + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Successfully added: 0"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + Mockito.when(externalAccessRolesService.bulkUploadRoles(mockedRequest.getHeader(uebKey))).thenReturn(result); + portalRestResponse = externalAccessRolesController.bulkUploadRoles(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadRolesTestException() throws Exception { + Mockito.when(externalAccessRolesService.bulkUploadRoles(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Failed to bulkUploadRoles"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.bulkUploadRoles(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadRoleFunctionsTest() throws Exception { + Integer result = 0; + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Successfully added: 0"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + Mockito.when(externalAccessRolesService.bulkUploadRolesFunctions(mockedRequest.getHeader(uebKey))) + .thenReturn(result); + portalRestResponse = externalAccessRolesController.bulkUploadRoleFunctions(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadRoleFunctionsException() throws Exception { + Mockito.when(externalAccessRolesService.bulkUploadRolesFunctions(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Failed to bulkUploadRoleFunctions"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.bulkUploadRoleFunctions(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadUserRolesTest() throws Exception { + Integer result = 0; + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Successfully added: 0"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + Mockito.when(externalAccessRolesService.bulkUploadUserRoles(mockedRequest.getHeader(uebKey))) + .thenReturn(result); + portalRestResponse = externalAccessRolesController.bulkUploadUserRoles(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadUserRolesExceptionTest() throws Exception { + Mockito.when(externalAccessRolesService.bulkUploadUserRoles(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Failed to bulkUploadUserRoles"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.bulkUploadUserRoles(mockedRequest, mockedResponse); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadPartnerFunctionsTest() throws Exception { + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Successfully added"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + portalRestResponse = externalAccessRolesController.bulkUploadPartnerFunctions(mockedRequest, mockedResponse, null); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + + @Test + public void bulkUploadPartnerRolesTest() throws Exception { + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Successfully added"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + List upload = new ArrayList<>(); + portalRestResponse = externalAccessRolesController.bulkUploadPartnerRoles(mockedRequest, mockedResponse, + upload); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void bulkUploadPartnerRolesExceptionTest() throws Exception + { + ExternalAccessRolesService externalAccessRolesService = null; + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Successfully added"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + List upload = new ArrayList<>(); + portalRestResponse = externalAccessRolesController.bulkUploadPartnerRoles(mockedRequest, mockedResponse, + upload); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void getMenuFunctionsTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + Mockito.when(externalAccessRolesService.getMenuFunctionsList(mockedRequest.getHeader(uebKey))) + .thenReturn(null); + List expectedFunctionsList = externalAccessRolesController.getMenuFunctions(mockedRequest, + mockedResponse); + assertNull(expectedFunctionsList); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + @Test + public void getMenuFunctionsExceptionTest() throws Exception { + String reason = getInvalidKeyJson(); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + Mockito.when(externalAccessRolesService.getMenuFunctionsList(mockedRequest.getHeader(uebKey))) + .thenThrow(httpClientErrorException); + assertNull(externalAccessRolesController.getMenuFunctions(mockedRequest, mockedResponse)); + String result = sw.getBuffer().toString().trim(); + assertEquals(reason, result); + } + + + @Test + public void saveRoleExceptionTest() throws Exception { + Role role = new Role(); + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Invalid uebkey!"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + List upload = new ArrayList<>(); + portalRestResponse = externalAccessRolesController.saveRole(mockedRequest, mockedResponse,role); + + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void deleteRoleExceptionTest() throws Exception { + String role = "TestNew"; + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Invalid uebkey!"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + portalRestResponse = externalAccessRolesController.deleteRole(mockedRequest, mockedResponse,role); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + + @Test + public void bulkUploadPartnerRoleFunctionsTest() throws Exception { + PortalRestResponse portalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Successfully added"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + List upload = new ArrayList<>(); + portalRestResponse = externalAccessRolesController.bulkUploadPartnerRoleFunctions(mockedRequest, mockedResponse,upload); + assertEquals(portalRestResponse, expectedportalRestResponse); + } + + @Test + public void getUsersOfApplicationTest() throws Exception + { + List users = new ArrayList<>(); + EcompUser user = new EcompUser(); + user.setOrgUserId("guestT"); + users.add(user); + Mockito.when(externalAccessRolesService.getAllAppUsers(mockedRequest.getHeader(uebKey))).thenReturn(users); + List expectedUsers = externalAccessRolesController.getUsersOfApplication(mockedRequest, mockedResponse); + assertEquals(expectedUsers, users); + } + + @Test(expected = Exception.class) + public void getUsersOfApplicationExceptionTest() throws Exception + { + List users = new ArrayList<>(); + EcompUser user = new EcompUser(); + user.setOrgUserId("guestT"); + users.add(user); + Mockito.when(externalAccessRolesService.getAllAppUsers(mockedRequest.getHeader(uebKey))).thenThrow(nullPointerException); + assertNull(externalAccessRolesController.getUsersOfApplication(mockedRequest, mockedResponse)); + } + + @Test(expected = NullPointerException.class) + public void deleteRoleV2Test() throws Exception + { + List applicationList = new ArrayList(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true, "Success"); + Mockito.when(externalAccessRolesService.deleteDependencyRoleRecord(Matchers.anyLong(),Matchers.anyString(),Matchers.anyString())).thenReturn(externalRequestFieldsValidator); + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Successfully Deleted"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + PortalRestResponse actualResponse = externalAccessRolesController.deleteRole(mockedRequest, mockedResponse, (long)1); + assertNull(actualResponse); + } + + @Test + public void deleteRoleV2InvalidUebKeyTest() throws Exception + { + List applicationList = new ArrayList(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenThrow(new Exception("Invalid uebkey!")); + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Invalid uebkey!"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + PortalRestResponse actualResponse = externalAccessRolesController.deleteRole(mockedRequest, mockedResponse, (long)1); + assertEquals(actualResponse, expectedportalRestResponse); + } + + @Test + public void deleteRoleV2InvalidUebKeyWithDiffErrorTest() throws Exception + { + List applicationList = new ArrayList(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenThrow(new Exception("test")); + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("test"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + PortalRestResponse actualResponse = externalAccessRolesController.deleteRole(mockedRequest, mockedResponse, (long)1); + assertEquals(actualResponse, expectedportalRestResponse); + } + + + @Test(expected = NullPointerException.class) + public void deleteRoleV2ExceptionTest() throws Exception + { + List applicationList = new ArrayList(); + EPApp app = mockApp(); + applicationList.add(app); + Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList); + ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false, "failed"); + Mockito.when(externalAccessRolesService.deleteDependencyRoleRecord(Matchers.anyLong(),Matchers.anyString(),Matchers.anyString())).thenReturn(externalRequestFieldsValidator); + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Failed to deleteRole"); + expectedportalRestResponse.setResponse("Failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + PortalRestResponse actualResponse = externalAccessRolesController.deleteRole(mockedRequest, mockedResponse, (long)1); + assertEquals(actualResponse, null); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerTest.java new file mode 100644 index 00000000..ae2497e4 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAppsRestfulControllerTest.java @@ -0,0 +1,211 @@ +/*- + * ============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.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.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPUser; +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.EPLoginService; +import org.onap.portalapp.portal.service.EPLoginServiceImpl; +import org.onap.portalapp.portal.service.EPRoleService; +import org.onap.portalapp.portal.service.EPRoleServiceImpl; +import org.onap.portalapp.portal.service.FunctionalMenuService; +import org.onap.portalapp.portal.service.FunctionalMenuServiceImpl; +import org.onap.portalapp.portal.service.UserNotificationService; +import org.onap.portalapp.portal.service.UserNotificationServiceImpl; +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.EcompPortalUtils; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.DataAccessServiceImpl; +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, EPCommonSystemProperties.class }) +public class ExternalAppsRestfulControllerTest { + + @InjectMocks + ExternalAppsRestfulController externalAppsRestfulController = new ExternalAppsRestfulController(); + @Mock + FunctionalMenuService functionalMenuService = new FunctionalMenuServiceImpl(); + + @Mock + EPLoginService epLoginService = new EPLoginServiceImpl(); + + @Mock + AdminRolesService adminRolesService = new AdminRolesServiceImpl(); + + @Mock + UserNotificationService userNotificationService = new UserNotificationServiceImpl(); + + @Mock + EPRoleService epRoleService = new EPRoleServiceImpl(); + + @Mock + EcompPortalUtils EcompPortalUtils = new EcompPortalUtils(); + + @Mock + DataAccessService DataAccessService = new DataAccessServiceImpl(); + + @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(expected = Exception.class) + public void getFunctionalMenuItemsForUserIfUSerNullTest() throws + Exception + { + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(MDC.class); + EPUser epUser = null; + String loginId = "guestT"; + Mockito.when(MDC.get(EPCommonSystemProperties.PARTNER_NAME)).thenReturn("Test"); + Mockito.when(epLoginService.findUserWithoutPwd(loginId)).thenReturn(epUser); + externalAppsRestfulController.getFunctionalMenuItemsForUser(mockedRequest, + mockedResponse); + } + + @Test + public void getFunctionalMenuItemsForUserIfSuperAdminTest() throws Exception { + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(MDC.class); + EPUser epUser = mockUser.mockEPUser(); + epUser.setId((long) 1); + epUser.setLoginId("guestT"); + String loginId = "guestT"; + Mockito.when(MDC.get(EPCommonSystemProperties.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 + public void getFunctionalMenuItemsForUserTest() throws Exception { + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(MDC.class); + EPUser epUser = mockUser.mockEPUser(); + epUser.setId((long) 1); + epUser.setLoginId("guestT"); + String loginId = "guestT"; + Mockito.when(MDC.get(EPCommonSystemProperties.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(EPCommonSystemProperties.class); + PowerMockito.mockStatic(MDC.class); + Mockito.when(mockedRequest.getHeader(EPCommonSystemProperties.MDC_LOGIN_ID)).thenReturn("Login_URL"); + Mockito.when(MDC.get(EPCommonSystemProperties.PARTNER_NAME)).thenReturn("Test"); + EPUser epUser = null; + externalAppsRestfulController.getFavoritesForUser(mockedRequest, mockedResponse); + } + + @Test + public void getFavoritesForUserTest() throws Exception { + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(MDC.class); + EPUser epUser = mockUser.mockEPUser(); + epUser.setId((long) 1); + epUser.setLoginId("guestT"); + String loginId = "guestT"; + Mockito.when(MDC.get(EPCommonSystemProperties.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(EPCommonSystemProperties.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); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java new file mode 100644 index 00000000..488717ca --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/FunctionalMenuControllerTest.java @@ -0,0 +1,607 @@ +/*- + * ============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.assertTrue; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +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.runners.MockitoJUnitRunner; +import org.onap.portalapp.portal.controller.FunctionalMenuController; +import org.onap.portalapp.portal.core.MockEPUser; +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.MockitoTestSuite; +import org.onap.portalapp.portal.service.AdminRolesService; +import org.onap.portalapp.portal.service.AdminRolesServiceImpl; +import org.onap.portalapp.portal.service.FunctionalMenuService; +import org.onap.portalapp.portal.service.FunctionalMenuServiceImpl; +import org.onap.portalapp.portal.service.SearchService; +import org.onap.portalapp.portal.transport.BusinessCardApplicationRole; +import org.onap.portalapp.portal.transport.BusinessCardApplicationRolesList; +import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItem; +import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson; +import org.onap.portalapp.portal.transport.FieldsValidator; +import org.onap.portalapp.portal.transport.FunctionalMenuItem; +import org.onap.portalapp.portal.transport.FunctionalMenuItemWithRoles; +import org.onap.portalapp.portal.transport.FieldsValidator.FieldName; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.service.DataAccessService; +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; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(SystemProperties.class) +public class FunctionalMenuControllerTest extends MockitoTestSuite { + + String userid = "ab1234"; + + @Mock + FunctionalMenuService functionalMenuService = new FunctionalMenuServiceImpl(); + + @InjectMocks + FunctionalMenuController functionalMenuController = new FunctionalMenuController(); + + @Mock + private DataAccessService dataAccessService; + + @Mock + SearchService searchService; + + @Mock + AdminRolesService adminRolesService = new AdminRolesServiceImpl(); + + NullPointerException nullPointerException = new NullPointerException(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @InjectMocks + EPUserUtils ePUserUtils = new EPUserUtils(); + + @Mock + EPUser epuser; + + MockEPUser mockUser = new MockEPUser(); + + List appRoles = new ArrayList(); + List appRolesActual = new ArrayList(); + + List userAppRoleList = new ArrayList(); + + public List mockBusinessCardApplicationRole() { + List userAppRoleList = new ArrayList(); + + BusinessCardApplicationRole businessCardApplicationRole = new BusinessCardApplicationRole(); + businessCardApplicationRole.setRoleName("ADMIN"); + businessCardApplicationRole.setAppName("ASDC"); + + BusinessCardApplicationRole businessCardApplicationRole1 = new BusinessCardApplicationRole(); + businessCardApplicationRole1.setAppName("ASDC"); + businessCardApplicationRole1.setRoleName("Tester"); + + userAppRoleList.add(businessCardApplicationRole); + userAppRoleList.add(businessCardApplicationRole1); + return userAppRoleList; + } + + public List mockBusinessCardApplicationRolesList() { + List appRolesActual = new ArrayList(); + + BusinessCardApplicationRolesList businessCardApplicationRolesList = new BusinessCardApplicationRolesList(); + businessCardApplicationRolesList.setAppName("ASDC"); + + List roleNames = new ArrayList(); + roleNames.add("ADMIN"); + roleNames.add("Tester"); + businessCardApplicationRolesList.setRoleNames(roleNames); + + appRolesActual.add(businessCardApplicationRolesList); + return appRolesActual; + } + + @Test + public void getAppListTestIfAppAlredyExistsBusinessCardApplicationRolesList() throws IOException { + + userAppRoleList = mockBusinessCardApplicationRole(); + appRolesActual = mockBusinessCardApplicationRolesList(); + + Mockito.when(functionalMenuService.getUserAppRolesList(userid)).thenReturn(userAppRoleList); + + appRoles = functionalMenuController.getAppList(mockedRequest, userid); + + assertEquals(appRolesActual.size(), appRoles.size()); + assertEquals(appRolesActual.get(0).getAppName(), appRoles.get(0).getAppName()); + assertEquals(appRolesActual.get(0).getRoleNames(), appRoles.get(0).getRoleNames()); + + } + + @Test + public void getAppListTestIfAppDoesnotExistsInBusinessCardApplicationRolesList() throws IOException { + + userAppRoleList = mockBusinessCardApplicationRole(); + BusinessCardApplicationRole businessCardApplicationRole = new BusinessCardApplicationRole(); + businessCardApplicationRole.setAppName("CCD"); + businessCardApplicationRole.setRoleName("ADMIN"); + userAppRoleList.add(businessCardApplicationRole); + appRolesActual = mockBusinessCardApplicationRolesList(); + BusinessCardApplicationRolesList businessCardApplicationRolesList = new BusinessCardApplicationRolesList(); + businessCardApplicationRolesList.setAppName("CCD"); + List roleNames1 = new ArrayList(); + roleNames1.add("ADMIN"); + businessCardApplicationRolesList.setRoleNames(roleNames1); + appRolesActual.add(businessCardApplicationRolesList); + Mockito.when(functionalMenuService.getUserAppRolesList(userid)).thenReturn(userAppRoleList); + appRoles = functionalMenuController.getAppList(mockedRequest, userid); + assertEquals(appRolesActual.size(), appRoles.size()); + assertEquals(appRolesActual.get(0).getAppName(), appRoles.get(0).getAppName()); + assertEquals(appRolesActual.get(0).getRoleNames(), appRoles.get(0).getRoleNames()); + assertEquals(appRolesActual.get(1).getAppName(), appRoles.get(1).getAppName()); + assertEquals(appRolesActual.get(1).getRoleNames(), appRoles.get(1).getRoleNames()); + + } + + @Test + public void regenerateAncestorTableTest() { + EPUser user = mockUser.mockEPUser(); + + HttpSession session = mockedRequest.getSession(); + session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + FieldsValidator acutualFieldValidator = null; + FieldsValidator expectedFieldValidator = new FieldsValidator(); + List fields = new ArrayList<>(); + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(fields); + expectedFieldValidator.setErrorCode(null); + Mockito.when(!adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(functionalMenuService.regenerateAncestorTable()).thenReturn(expectedFieldValidator); + acutualFieldValidator = functionalMenuController.regenerateAncestorTable(mockedRequest, mockedResponse); + assertTrue(acutualFieldValidator.equals(expectedFieldValidator)); + } + + @Test + public void getMenuItemsExceptionTest(){ + List actualmenuItems = null; + List expectedmenuItems = null; + + Mockito.when(functionalMenuController.getMenuItemsForAuthUser(mockedRequest, mockedResponse)).thenThrow(nullPointerException); + actualmenuItems = functionalMenuController.getMenuItemsForAuthUser(mockedRequest, mockedResponse); + assertEquals(actualmenuItems, expectedmenuItems); + } + + @Test + public void getFunctionalMenuStaticInfoExceptionTest(){ + String fnMenuStaticactualResponse = null; + String fnMenuStaticexpectedResponse = null; + String orgUserIdStr = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(searchService.searchUserByUserId(orgUserIdStr)).thenReturn(user); + fnMenuStaticactualResponse = functionalMenuController.getFunctionalMenuStaticInfo(mockedRequest, mockedResponse); + + assertEquals(fnMenuStaticactualResponse, fnMenuStaticexpectedResponse); + + } + + @Test + public void getFunctionalMenuStaticInfoTest(){ + String fnMenuStaticactualResponse = null; + String fnMenuStaticexpectedResponse = "{\"firstName\":\"test\",\"lastName\":\"test\",\"last_login\":\"09/08/2017 03:48:13-0400\",\"userId\":\"guestT\",\"email\":\"test\"}"; + String orgUserIdStr = null; + + EPUser user = mockUser.mockEPUser(); + user.setEmail("test"); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(searchService.searchUserByUserId(orgUserIdStr)).thenReturn(user); + fnMenuStaticactualResponse = functionalMenuController.getFunctionalMenuStaticInfo(mockedRequest, mockedResponse); + assertEquals(fnMenuStaticactualResponse.length(), fnMenuStaticexpectedResponse.length()); + } + + @Test + public void getMenuItemsForAuthUserNullTest(){ + List actualmenuItems = null; + List expectedmenuItems = null; + + actualmenuItems = functionalMenuController.getMenuItemsForAuthUser(mockedRequest, mockedResponse); + assertEquals(actualmenuItems, expectedmenuItems); + } + + @Test + public void getMenuItemsForAuthUserIsSuperAdminTest(){ + List actualmenuItems = null; + List expectedmenuItems = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + actualmenuItems = functionalMenuController.getMenuItemsForAuthUser(mockedRequest, mockedResponse); + assertEquals(actualmenuItems, expectedmenuItems); + } + + @Test + public void getMenuItemsForAuthUserTest(){ + List actualmenuItems = null; + List expectedmenuItems = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + actualmenuItems = functionalMenuController.getMenuItemsForAuthUser(mockedRequest, mockedResponse); + assertEquals(actualmenuItems, expectedmenuItems); + } + + @Test + public void getFunctionalMenuItemDetailsBadPermissionTest(){ + Long menuId = 1234L; + FunctionalMenuItem actualmenuItem = null; + FunctionalMenuItem expectedmenuItem = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + + actualmenuItem = functionalMenuController.getFunctionalMenuItemDetails(mockedRequest, menuId, mockedResponse); + assertEquals(actualmenuItem, expectedmenuItem); + } + + @Test + public void getFunctionalMenuItemDetailsExceptionTest(){ + Long menuId = 1234L; + FunctionalMenuItem actualmenuItem = null; + FunctionalMenuItem expectedmenuItem = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.getFunctionalMenuItemDetails(menuId)).thenThrow(nullPointerException); + + actualmenuItem = functionalMenuController.getFunctionalMenuItemDetails(mockedRequest, menuId, mockedResponse); + assertEquals(actualmenuItem, expectedmenuItem); + } + + @Test + public void getFunctionalMenuItemDetailsTest(){ + Long menuId = 1234L; + FunctionalMenuItem actualmenuItem = null; + FunctionalMenuItem expectedmenuItem = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.getFunctionalMenuItemDetails(menuId)).thenReturn(actualmenuItem); + + actualmenuItem = functionalMenuController.getFunctionalMenuItemDetails(mockedRequest, menuId, mockedResponse); + assertEquals(actualmenuItem, expectedmenuItem); + } + + @Test + public void getMenuItemsForEditingTest(){ + List actualMenuItems = null; + List expectedMenuItems = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.getFunctionalMenuItems(true)).thenReturn(actualMenuItems); + + actualMenuItems = functionalMenuController.getMenuItemsForEditing(mockedRequest, mockedResponse); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForEditingBadPermissionsTest(){ + List actualMenuItems = null; + List expectedMenuItems = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.getFunctionalMenuItems(true)).thenReturn(actualMenuItems); + + actualMenuItems = functionalMenuController.getMenuItemsForEditing(mockedRequest, mockedResponse); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForEditingExceptionTest(){ + List actualMenuItems = null; + List expectedMenuItems = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.getFunctionalMenuItems(true)).thenThrow(nullPointerException); + actualMenuItems = functionalMenuController.getMenuItemsForEditing(mockedRequest, mockedResponse); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForNotificationsExceptionTest(){ + List actualMenuItems = null; + List expectedMenuItems = null; + Mockito.when(functionalMenuService.getFunctionalMenuItemsForNotificationTree(true)).thenThrow(nullPointerException); + + actualMenuItems = functionalMenuController.getMenuItemsForNotifications(mockedRequest, mockedResponse); + assertEquals(actualMenuItems, expectedMenuItems); + } + @Test + public void getMenuItemsForNotificationsTest(){ + List actualMenuItems = null; + List expectedMenuItems = new ArrayList(); + Mockito.when(functionalMenuService.getFunctionalMenuItemsForNotificationTree(false)).thenReturn(actualMenuItems); + + actualMenuItems = functionalMenuController.getMenuItemsForNotifications(mockedRequest, mockedResponse); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForAppTest(){ + Integer appId = 1234; + List actualMenuItems = null; + List expectedMenuItems = null; + Mockito.when(functionalMenuService.getFunctionalMenuItemsForApp(appId)).thenReturn(actualMenuItems); + + actualMenuItems = functionalMenuController.getMenuItemsForApp(mockedRequest, appId); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForAppExceptionTest(){ + Integer appId = 1234; + List actualMenuItems = null; + List expectedMenuItems = null; + Mockito.when(functionalMenuService.getFunctionalMenuItemsForApp(appId)).thenThrow(nullPointerException); + + actualMenuItems = functionalMenuController.getMenuItemsForApp(mockedRequest, appId); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForUserTest(){ + String orgUserId ="test"; + List actualMenuItems = null; + List expectedMenuItems = null; + Mockito.when(functionalMenuService.getFunctionalMenuItemsForUser(orgUserId)).thenReturn(actualMenuItems); + + actualMenuItems = functionalMenuController.getMenuItemsForUser(mockedRequest, orgUserId); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void getMenuItemsForUserExceptionTest(){ + String orgUserId ="test"; + List actualMenuItems = null; + List expectedMenuItems = null; + Mockito.when(functionalMenuService.getFunctionalMenuItemsForUser(orgUserId)).thenThrow(nullPointerException); + + actualMenuItems = functionalMenuController.getMenuItemsForUser(mockedRequest, orgUserId); + assertEquals(actualMenuItems, expectedMenuItems); + } + + @Test + public void createFunctionalMenuItemTest(){ + FieldsValidator actualFieldsValidator = new FieldsValidator(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List fields = new ArrayList<>(); + expectedFieldsValidator.setHttpStatusCode((long) 200); + expectedFieldsValidator.setFields(fields); + expectedFieldsValidator.setErrorCode(null); + FunctionalMenuItemWithRoles menuItemJson = new FunctionalMenuItemWithRoles(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(functionalMenuService.createFunctionalMenuItem(menuItemJson)).thenReturn(expectedFieldsValidator); + actualFieldsValidator = functionalMenuController.createFunctionalMenuItem(mockedRequest, menuItemJson, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void createFunctionalMenuItemBadPermisssionsTest(){ + FieldsValidator actualFieldsValidator = null; + FieldsValidator expectedFieldsValidator = null; + FunctionalMenuItemWithRoles menuItemJson = new FunctionalMenuItemWithRoles(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(functionalMenuService.createFunctionalMenuItem(menuItemJson)).thenReturn(expectedFieldsValidator); + actualFieldsValidator = functionalMenuController.createFunctionalMenuItem(mockedRequest, menuItemJson, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void getFavoritesForUserTest(){ + List actualFavoritesFunctionalMenuItemsJson = null; + List expectedFunctionalMenuItemsJson = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(functionalMenuService.getFavoriteItems(user.getId())).thenReturn(expectedFunctionalMenuItemsJson); + actualFavoritesFunctionalMenuItemsJson = functionalMenuController.getFavoritesForUser(mockedRequest, mockedResponse); + assertEquals(actualFavoritesFunctionalMenuItemsJson, expectedFunctionalMenuItemsJson); + } + + @Test + public void deleteFavoriteItemTest(){ + Long userId = (long)1; + Long menuId = (long)1; + FieldsValidator actualFieldsValidator = new FieldsValidator(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List fields = new ArrayList<>(); + expectedFieldsValidator.setHttpStatusCode((long) 200); + expectedFieldsValidator.setFields(fields); + expectedFieldsValidator.setErrorCode(null); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.removeFavoriteItem(user.getId(), menuId)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.deleteFavoriteItem(mockedRequest, menuId, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void addFavoriteItemTest(){ + FavoritesFunctionalMenuItem menuItemJson = new FavoritesFunctionalMenuItem(); + FieldsValidator actualFieldsValidator = new FieldsValidator(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List fields = new ArrayList<>(); + expectedFieldsValidator.setHttpStatusCode((long) 200); + expectedFieldsValidator.setFields(fields); + expectedFieldsValidator.setErrorCode(null); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(functionalMenuService.setFavoriteItem(menuItemJson)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.addFavoriteItem(mockedRequest, menuItemJson, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void getMenuItemsTest(){ + List actualFunctionalMenuItems = new ArrayList(); + List expectedFunctionalMenuItems = new ArrayList(); + List menuItems = new ArrayList(); + Mockito.when(functionalMenuService.getFunctionalMenuItems()).thenReturn(menuItems); + actualFunctionalMenuItems = functionalMenuController.getMenuItems(mockedRequest, mockedResponse); + assertEquals(actualFunctionalMenuItems, expectedFunctionalMenuItems); + } + + @Test + public void deleteFunctionalMenuItemTest(){ + Long menuId = (long)1; + FieldsValidator actualFieldsValidator = new FieldsValidator(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List fields = new ArrayList<>(); + expectedFieldsValidator.setHttpStatusCode((long) 200); + expectedFieldsValidator.setFields(fields); + expectedFieldsValidator.setErrorCode(null); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(functionalMenuService.deleteFunctionalMenuItem(menuId)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.deleteFunctionalMenuItem(mockedRequest, menuId, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void deleteFunctionalMenuItemBadPermissionsTest(){ + Long menuId = (long)1; + FieldsValidator actualFieldsValidator = null; + FieldsValidator expectedFieldsValidator = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(functionalMenuService.deleteFunctionalMenuItem(menuId)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.deleteFunctionalMenuItem(mockedRequest, menuId, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void editFunctionalMenuItemTest(){ + FunctionalMenuItemWithRoles menuItemJson = new FunctionalMenuItemWithRoles(); + FieldsValidator actualFieldsValidator = new FieldsValidator(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List fields = new ArrayList<>(); + expectedFieldsValidator.setHttpStatusCode((long) 200); + expectedFieldsValidator.setFields(fields); + expectedFieldsValidator.setErrorCode(null); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(functionalMenuService.editFunctionalMenuItem(menuItemJson)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.editFunctionalMenuItem(mockedRequest, menuItemJson, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void editFunctionalMenuItemBadPermissionsTest(){ + FunctionalMenuItemWithRoles menuItemJson = new FunctionalMenuItemWithRoles(); + FieldsValidator actualFieldsValidator = null; + FieldsValidator expectedFieldsValidator = null; + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(functionalMenuService.editFunctionalMenuItem(menuItemJson)).thenReturn(actualFieldsValidator); + actualFieldsValidator = functionalMenuController.editFunctionalMenuItem(mockedRequest, menuItemJson, mockedResponse); + assertEquals(actualFieldsValidator, expectedFieldsValidator); + } + + @Test + public void getECOMPTitleTest(){ + PortalRestResponse actualportalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); + expectedportalRestResponse.setMessage("success"); + expectedportalRestResponse.setResponse("Portal"); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME)).thenReturn("Portal"); + actualportalRestResponse = functionalMenuController.getECOMPTitle(mockedRequest, mockedResponse); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + } + + @Test + public void getECOMPTitleExceptionTest(){ + PortalRestResponse actualportalRestResponse = null; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse(null); + PowerMockito.mockStatic(SystemProperties.class); + + Mockito.when(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME)).thenThrow(nullPointerException); + actualportalRestResponse = functionalMenuController.getECOMPTitle(mockedRequest, mockedResponse); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/GetAccessControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/GetAccessControllerTest.java new file mode 100644 index 00000000..dbe4b7b7 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/GetAccessControllerTest.java @@ -0,0 +1,108 @@ +/*- + * ============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.assertTrue; + +import java.io.IOException; +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.GetAccessController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.domain.GetAccessResult; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.GetAccessService; +import org.onap.portalapp.portal.service.GetAccessServiceImpl; +import org.onap.portalapp.util.EPUserUtils; + +public class GetAccessControllerTest { + + @Mock + GetAccessService getAccessService = new GetAccessServiceImpl(); + + @InjectMocks + GetAccessController getAccessController = new GetAccessController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + MockEPUser mockUser = new MockEPUser(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + + @Test + public void getAppList() throws IOException + { + List expectedAppsList = new ArrayList(); + EPUser user = mockUser.mockEPUser(); + GetAccessResult getAccessResult = new GetAccessResult(); + getAccessResult.setRowId("1"); + getAccessResult.setRoleId((long) 1); + getAccessResult.setEcompFunction("test"); + getAccessResult.setAppName("Test_App"); + getAccessResult.setAppMotsId(1); + getAccessResult.setRoleName("Test_role"); + getAccessResult.setRoleActive("N"); + getAccessResult.setReqType("test"); + + expectedAppsList.add(getAccessResult); + + List actualAppsList = null; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(getAccessService.getAppAccessList(user)).thenReturn(expectedAppsList); + actualAppsList = getAccessController.getAppList(mockedRequest); + assertTrue(actualAppsList.contains(getAccessResult)); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ManifestControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ManifestControllerTest.java new file mode 100644 index 00000000..fdab8151 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ManifestControllerTest.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.controller; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.jar.Attributes; + +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.ManifestController; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.ManifestService; +import org.onap.portalapp.portal.service.ManifestServiceImpl; + +public class ManifestControllerTest extends MockitoTestSuite{ + + + @Mock + ManifestService manifestService = new ManifestServiceImpl(); + + @InjectMocks + ManifestController manifestController = new ManifestController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void getManifestTest() throws IOException + { + Map expectedResponse = new HashMap(); + Attributes attributes = new Attributes(); + expectedResponse.put("test", attributes); + Mockito.when(manifestService.getWebappManifest()).thenReturn(attributes); + Map actualResponse = manifestController.getManifest(mockedRequest); + assertTrue((actualResponse.keySet().toArray().length) == 1); + + } + + @Test + public void getManifestExceptionTest() throws IOException + { + Mockito.when(manifestService.getWebappManifest()).thenThrow(nullPointerException); + Map actualResponse = manifestController.getManifest(mockedRequest); + assertTrue((actualResponse.keySet().toArray().length) == 1); + assertTrue(actualResponse.get("error").equals("failed to get manifest: java.lang.NullPointerException")); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceControllerTest.java new file mode 100644 index 00000000..e6e9f759 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceControllerTest.java @@ -0,0 +1,272 @@ +/*- + * ============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.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.MicroserviceController; +import org.onap.portalapp.portal.domain.MicroserviceData; +import org.onap.portalapp.portal.domain.WidgetCatalog; +import org.onap.portalapp.portal.domain.WidgetServiceHeaders; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.ConsulHealthService; +import org.onap.portalapp.portal.service.ConsulHealthServiceImpl; +import org.onap.portalapp.portal.service.MicroserviceService; +import org.onap.portalapp.portal.service.MicroserviceServiceImpl; +import org.onap.portalapp.portal.utils.EcompPortalUtils; +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.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({WidgetServiceHeaders.class, EcompPortalUtils.class}) +public class MicroserviceControllerTest extends MockitoTestSuite{ + + @InjectMocks + MicroserviceController microserviceController = new MicroserviceController(); + + @Mock + ConsulHealthService consulHealthService = new ConsulHealthServiceImpl(); + + @Mock + MicroserviceService microserviceService = new MicroserviceServiceImpl(); + + @Mock + RestTemplate template = new RestTemplate(); + + @Mock + MicroserviceData microserviceData = new MicroserviceData(); + + @SuppressWarnings("rawtypes") + @Mock + ResponseEntity> ans = new ResponseEntity>(HttpStatus.OK); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Mock + EcompPortalUtils EcompPortalUtils = new EcompPortalUtils(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void createMicroserviceIfServiceDataNullTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("FAILURE"); + expectedportalRestResponse.setResponse("MicroserviceData cannot be null or empty"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + MicroserviceData microserviceData = null; + PortalRestResponse actualportalRestResponse = microserviceController.createMicroservice(mockedRequest, + mockedResponse, microserviceData); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + } + + @Test + public void createMicroserviceTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("SUCCESS"); + expectedportalRestResponse.setResponse(""); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + PortalRestResponse actualportalRestResponse = microserviceController.createMicroservice(mockedRequest, + mockedResponse, microserviceData); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + } + + @Test + public void createMicroserviceExceptionTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("FAILURE"); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + Mockito.when(microserviceService.saveMicroservice(microserviceData)).thenReturn((long) 1); + Mockito.when(microserviceData.getParameterList()).thenThrow(nullPointerException); + PortalRestResponse actualportalRestResponse = microserviceController.createMicroservice(mockedRequest, + mockedResponse, microserviceData); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + } + + @Test + public void getMicroserviceTest() throws Exception { + Mockito.when(microserviceService.getMicroserviceData()).thenReturn(null); + List list = microserviceController.getMicroservice(mockedRequest, mockedResponse); + assertEquals(list, null); + } + + @Test + public void updateMicroserviceIfServiceISNullTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("FAILURE"); + expectedportalRestResponse.setResponse("MicroserviceData cannot be null or empty"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + MicroserviceData microserviceData = null; + PortalRestResponse actualportalRestResponse = microserviceController.updateMicroservice(mockedRequest, + mockedResponse, 1, microserviceData); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + } + + @Test + public void updateMicroserviceTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("SUCCESS"); + expectedportalRestResponse.setResponse(""); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + PortalRestResponse actualportalRestResponse = microserviceController.updateMicroservice(mockedRequest, + mockedResponse, 1, microserviceData); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + } + + @Test + public void updateMicroserviceExceptionTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("FAILURE"); + expectedportalRestResponse.setResponse(null); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + Mockito.when(microserviceController.updateMicroservice(mockedRequest, mockedResponse, 1, microserviceData)) + .thenThrow(nullPointerException); + PortalRestResponse actualportalRestResponse = microserviceController.updateMicroservice(mockedRequest, + mockedResponse, 1, microserviceData); + assertEquals(actualportalRestResponse, expectedportalRestResponse); + } + + @Test + public void deleteMicroserviceExceptionTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("FAILURE"); + PowerMockito.mockStatic(EcompPortalUtils.class); + expectedportalRestResponse.setResponse( + "I/O error on GET request for \"" + EcompPortalUtils.widgetMsProtocol() + "://null/widget/microservices/widgetCatalog/service/1\":null; nested exception is java.net.UnknownHostException: null"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + PowerMockito.mockStatic(WidgetServiceHeaders.class); + PortalRestResponse actuaPportalRestResponse = microserviceController.deleteMicroservice(mockedRequest, + mockedResponse, 1); + assertEquals(actuaPportalRestResponse.getStatus(), expectedportalRestResponse.getStatus()); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteMicroserviceTest() throws Exception { + String HTTPS = "https://"; + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("SOME WIDGETS ASSOICATE WITH THIS SERVICE"); + expectedportalRestResponse.setResponse("'null' ,'null' "); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.WARN); + List List = new ArrayList(); + WidgetCatalog widgetCatalog = new WidgetCatalog(); + widgetCatalog.setId(1); + WidgetCatalog widgetCatalog1 = new WidgetCatalog(); + widgetCatalog.setId(2); + List.add(widgetCatalog); + List.add(widgetCatalog1); + PowerMockito.mockStatic(WidgetServiceHeaders.class); + PowerMockito.mockStatic(EcompPortalUtils.class); + String whatService = "widgets-service"; + Mockito.when(consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port"))).thenReturn("Test"); + Mockito.when(ans.getBody()).thenReturn(List); + ParameterizedTypeReference> typeRef = new ParameterizedTypeReference>() { + }; + Mockito.when(template.exchange( + EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port")) + + "/widget/microservices/widgetCatalog/service/" + 1, + HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), typeRef)).thenReturn(ans); + + PortalRestResponse actuaPportalRestResponse = microserviceController.deleteMicroservice(mockedRequest, + mockedResponse, 1); + assertEquals(actuaPportalRestResponse, expectedportalRestResponse); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteMicroserviceWhenNoWidgetsAssociatedTest() throws Exception { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("SUCCESS"); + expectedportalRestResponse.setResponse(""); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + List List = new ArrayList(); + PowerMockito.mockStatic(WidgetServiceHeaders.class); + PowerMockito.mockStatic(EcompPortalUtils.class); + String whatService = "widgets-service"; + Mockito.when(consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port"))).thenReturn("Test"); + Mockito.when(ans.getBody()).thenReturn(List); + ParameterizedTypeReference> typeRef = new ParameterizedTypeReference>() { + }; + Mockito.when(template.exchange( + EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, SystemProperties.getProperty("microservices.widget.local.port")) + + "/widget/microservices/widgetCatalog/service/" + 1, + HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), typeRef)).thenReturn(ans); + PortalRestResponse actuaPportalRestResponse = microserviceController.deleteMicroservice(mockedRequest, + mockedResponse, 1); + assertEquals(actuaPportalRestResponse, expectedportalRestResponse); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java new file mode 100644 index 00000000..446c11c4 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/MicroserviceProxyControllerTest.java @@ -0,0 +1,143 @@ +/*- + * ============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.assertTrue; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.portalapp.portal.controller.MicroserviceProxyController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.MicroserviceProxyService; +import org.onap.portalapp.portal.service.MicroserviceProxyServiceImpl; +import org.onap.portalapp.util.EPUserUtils; +import org.springframework.http.HttpStatus; +import org.springframework.web.client.HttpClientErrorException; + +import com.fasterxml.jackson.databind.ObjectMapper; + + + +public class MicroserviceProxyControllerTest extends MockitoTestSuite { + + @Mock + MicroserviceProxyService microserviceProxyService = new MicroserviceProxyServiceImpl(); + + @InjectMocks + MicroserviceProxyController microserviceProxyController = new MicroserviceProxyController(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Mock + EPUserUtils ePUserUtils = new EPUserUtils(); + @Mock + ObjectMapper objectMapper = new ObjectMapper(); + MockEPUser mockUser = new MockEPUser(); + + @Test + public void getMicroserviceProxyTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(microserviceProxyService.proxyToDestination(1, user, mockedRequest)).thenReturn("Success"); + String acutualString = microserviceProxyController.getMicroserviceProxy(mockedRequest, getMockedResponse(), 1); + assertTrue(acutualString.equals("{\"error\":\"Success\"}")); + } + + @Test(expected = NullPointerException.class) + public void getMicroserviceProxyNullPoniterExceptionTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(microserviceProxyService.proxyToDestination(1, user, mockedRequest)) + .thenThrow(nullPointerException); + microserviceProxyController.getMicroserviceProxy(mockedRequest, getMockedResponse(), 1); + } + + @Test + public void getMicroserviceProxyExceptionTest() throws Exception { + HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.OK, "Success"); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(microserviceProxyService.proxyToDestination(1, user, mockedRequest)) + .thenThrow(httpClientErrorException); + String acutualString = microserviceProxyController.getMicroserviceProxy(mockedRequest, getMockedResponse(), 1); + assertTrue(acutualString.equals("{\"error\":\"\"}")); + } + + @Test + public void getMicroserviceProxyByWidgetIdTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(microserviceProxyService.proxyToDestinationByWidgetId(1, user, mockedRequest)) + .thenReturn("Success"); + String acutualString = microserviceProxyController.getMicroserviceProxyByWidgetId(mockedRequest, + getMockedResponse(), 1); + assertTrue(acutualString.equals("{\"error\":\"Success\"}")); + } + + @Test(expected = NullPointerException.class) + public void getMicroserviceProxyByWidgetIdNullPointerExceptionTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(microserviceProxyService.proxyToDestinationByWidgetId(1, user, mockedRequest)) + .thenThrow(nullPointerException); + microserviceProxyController.getMicroserviceProxyByWidgetId(mockedRequest, getMockedResponse(), 1); + } + + @Test + public void getMicroserviceProxyByWidgetIdExceptionTest() throws Exception { + HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.OK, "Success"); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(microserviceProxyService.proxyToDestinationByWidgetId(1, user, mockedRequest)) + .thenThrow(httpClientErrorException); + String acutualString = microserviceProxyController.getMicroserviceProxyByWidgetId(mockedRequest, + getMockedResponse(), 1); + assertTrue(acutualString.equals("{\"error\":\"\"}")); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java new file mode 100644 index 00000000..9c1cbeeb --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java @@ -0,0 +1,148 @@ +/*- + * ============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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.BadRequestException; + +import org.json.simple.JSONObject; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.scheduler.SchedulerProperties; +import org.onap.portalapp.portal.scheduler.SchedulerRestInterface; +import org.onap.portalapp.portal.scheduleraux.RestObject; +import org.onap.portalapp.portal.scheduleraux.SchedulerAuxResponseWrapper; +import org.onap.portalapp.portal.scheduleraux.SchedulerAuxRestInterfaceFactory; +import org.onap.portalapp.portal.scheduleraux.SchedulerAuxRestInterfaceIfc; +import org.onap.portalapp.portal.scheduleraux.SchedulerAuxUtil; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ UserUtils.class, SchedulerProperties.class, SchedulerAuxRestInterfaceFactory.class,SchedulerAuxUtil.class }) +public class PolicyControllerTest { + @Mock + SchedulerRestInterface schedulerRestInterface; + + @InjectMocks + SchedulerAuxController policyController = new SchedulerAuxController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockEPUser mockUser = new MockEPUser(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Before + public void setUp() { + + PowerMockito.mockStatic(SchedulerProperties.class); + + Mockito.when(SchedulerProperties.getProperty(SchedulerProperties.SCHEDULERAUX_GET_CONFIG_VAL)).thenReturn("/api/getConfig"); + Mockito.when(SchedulerProperties.getProperty(SchedulerProperties.SCHEDULERAUX_CLIENT_MECHID_VAL)) + .thenReturn("m06814@controller.dcae.ecomp.att.com"); + Mockito.when(SchedulerProperties.getProperty(SchedulerProperties.SCHEDULERAUX_CLIENT_PASSWORD_VAL)) + .thenReturn("OBF:1ffu1qvu1t2z1l161fuk1i801nz91ro41xf71xfv1rqi1nx51i7y1fuq1kxw1t371qxw1fh0"); + Mockito.when(SchedulerProperties.getProperty(SchedulerProperties.SCHEDULERAUX_USERNAME_VAL)).thenReturn("testpdp"); + Mockito.when(SchedulerProperties.getProperty(SchedulerProperties.SCHEDULERAUX_PASSWORD_VAL)) + .thenReturn("OBF:1igd1kft1l1a1sw61svs1kxs1kcl1idt"); + Mockito.when(SchedulerProperties.getProperty(SchedulerProperties.SCHEDULERAUX_ENVIRONMENT_VAL)).thenReturn("TEST"); + Mockito.when(SchedulerProperties.getProperty(SchedulerProperties.SCHEDULERAUX_SERVER_URL_VAL)) + .thenReturn("https://policypdp-conexus-e2e.ecomp.cci.att.com:8081/pdp"); + + } + + @SuppressWarnings({ "unchecked" }) + @Test + public void getPolicyInfoTest1() throws Exception { + + JSONObject jsonObject = Mockito.mock(JSONObject.class); + PowerMockito.mockStatic(SchedulerAuxRestInterfaceFactory.class); + PowerMockito.mockStatic(SchedulerProperties.class); + SchedulerAuxRestInterfaceIfc policyRestInterface = Mockito.mock(SchedulerAuxRestInterfaceIfc.class); + PowerMockito.mockStatic(SchedulerAuxUtil.class); + // RestObject restObj=Mockito.mock(RestObject.class); + SchedulerAuxResponseWrapper policyWrapper = Mockito.mock(SchedulerAuxResponseWrapper.class); + PowerMockito.when(SchedulerAuxUtil.wrapResponse(Matchers.any(RestObject.class))).thenReturn(policyWrapper); + Mockito.when(policyWrapper.getResponse()).thenReturn("Success"); + Mockito.when(policyWrapper.getStatus()).thenReturn(200); + + PowerMockito.when(SchedulerAuxRestInterfaceFactory.getInstance()).thenReturn(policyRestInterface); + Mockito.doNothing().when(policyRestInterface).Post(Matchers.anyString(), Matchers.anyObject(), + Matchers.anyString(), Matchers.anyString(), Matchers.anyObject()); + + ResponseEntity responsePolicy = policyController.getPolicyInfo(mockedRequest); + Assert.assertEquals(responsePolicy.getStatusCode(), HttpStatus.OK); + } + + @SuppressWarnings("unchecked") + @Test + public void getPolicyInfoTestexpected() throws Exception { + + JSONObject jsonObject = Mockito.mock(JSONObject.class); + PowerMockito.mockStatic(SchedulerAuxRestInterfaceFactory.class); + PowerMockito.mockStatic(SchedulerProperties.class); + Mockito.when(SchedulerProperties.getProperty(SchedulerProperties.SCHEDULERAUX_GET_CONFIG_VAL)).thenThrow(nullPointerException); + ResponseEntity responsePolicy = policyController.getPolicyInfo(mockedRequest); + Assert.assertEquals(responsePolicy.getStatusCode(), HttpStatus.INTERNAL_SERVER_ERROR); + + } + + + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerTest.java new file mode 100644 index 00000000..0c48f176 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PortalAdminControllerTest.java @@ -0,0 +1,192 @@ + +/*- + * ============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.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPRole; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.exceptions.NoHealthyServiceException; +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 PortalAdminControllerTest extends MockitoTestSuite{ + + @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 getPortalAdminsTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedPortalAdminsList = new ArrayList(); + PortalAdmin portalAdmin= new PortalAdmin(); + + portalAdmin.setUserId((long) 1); + portalAdmin.setLoginId("guestT"); + portalAdmin.setFirstName("Test_FirstName"); + portalAdmin.setLastName("Test_LastName"); + + expectedPortalAdminsList.add(portalAdmin); + + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + + Mockito.when(portalAdminService.getPortalAdmins()).thenReturn(expectedPortalAdminsList); + List actualPortalAdminsList = portalAdminController.getPortalAdmins(mockedRequest, mockedResponse); + assertEquals(actualPortalAdminsList,expectedPortalAdminsList); + + } +// @Test +// public void getPortalAdminsIfUserIsNullTest() +// { +// EPUser user = null; +// Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); +// +// assertNull(portalAdminController.getPortalAdmins(mockedRequest, mockedResponse)); +// +// } + + @Test + public void getPortalAdminsIfUserIsSuperAdminTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + assertNull(portalAdminController.getPortalAdmins(mockedRequest, mockedResponse)); + + } + + + + @Test + public void createPortalAdminTest() + { + 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(); + String sbcid = "Test"; + + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(portalAdminService.createPortalAdmin(sbcid)).thenReturn(expectedFieldValidator); + actualFieldValidator = portalAdminController.createPortalAdmin(mockedRequest, sbcid, mockedResponse); + assertEquals(actualFieldValidator,expectedFieldValidator); + + } + +// @Test +// public void createPortalAdminIfUserIsNullTest() +// { +// //EPUser user = null; +// Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(null); +// String sbcid = "null"; +// assertNull(portalAdminController.createPortalAdmin(mockedRequest, sbcid, mockedResponse)); +// +// } + + @Test + public void createPortalAdminIfUserIsSuperAdminTest() + { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + String sbcid = "Test"; + assertNull(portalAdminController.createPortalAdmin(mockedRequest, sbcid, mockedResponse)); + + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java new file mode 100644 index 00000000..e63ea438 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java @@ -0,0 +1,525 @@ +/*- + * ============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.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; + +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.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.core.RoleController; +import org.onap.portalapp.controller.core.RoleFunctionListController; +import org.onap.portalapp.controller.core.RoleListController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.CentralV2RoleFunction; +import org.onap.portalapp.portal.domain.EPApp; +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.MockitoTestSuite; +import org.onap.portalapp.portal.service.AdminRolesService; +import org.onap.portalapp.portal.service.EPAppService; +import org.onap.portalapp.portal.service.ExternalAccessRolesService; +import org.onap.portalapp.portal.transport.CentralV2Role; +import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.service.AuditService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.servlet.ModelAndView; + +public class RoleManageControllerTest { + + @Mock + RoleController roleController; + + @Mock + RoleListController roleListController; + + @Mock + RoleFunctionListController roleFunctionListController; + + + @Mock + ExternalAccessRolesService externalAccessRolesService; + @Mock + EPUserUtils ePUserUtils = new EPUserUtils(); + + @Mock + ExternalAccessRolesService externalAccessRolesService1 = null; + + @InjectMocks + RoleManageController roleManageController = new RoleManageController(); + + @Mock + EPAppService appService; + + @Mock + AuditService auditService; + + @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 removeRoleRoleFunctionTest() throws Exception + { + + ModelAndView modelandView = new ModelAndView("login.htm"); + Mockito.when(roleController.removeRoleFunction(mockedRequest, mockedResponse)).thenReturn(modelandView); + ModelAndView expectedModelandView = roleManageController.removeRoleRoleFunction(mockedRequest, mockedResponse); + assertEquals(expectedModelandView, modelandView); + } + + @Test + public void addRoleRoRoleFunctionTest() throws Exception + { + ModelAndView modelandView = new ModelAndView("login.htm"); + Mockito.when(roleController.addRoleFunction(mockedRequest, mockedResponse)).thenReturn(modelandView); + ModelAndView expectedModelandView = roleManageController.addRoleRoRoleFunction(mockedRequest, mockedResponse); + assertEquals(expectedModelandView, modelandView); + } + + @Test + public void removeChildRoleTest() throws Exception + { + ModelAndView modelandView = new ModelAndView("login.htm"); + Mockito.when(roleController.removeChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView); + ModelAndView expectedModelandView = roleManageController.removeChildRole(mockedRequest, mockedResponse); + assertEquals(expectedModelandView, modelandView); + } + + + @Test + public void getRoleIfRoleIdNullTest() throws Exception + { + Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp()); + CentralV2Role answer = new CentralV2Role(); + Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(answer); + List finalRoleFunctionList = new ArrayList<>(); + Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenReturn(finalRoleFunctionList); + Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenReturn(null); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + List appList = new ArrayList<>(); + appList.add(CentralApp()); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response); + Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList); + roleManageController.getRole(mockedRequest, mockedResponse, (long)1,null); + +} + + @Test(expected = Exception.class) + public void getRoleExceptionTest() throws Exception + { + Mockito.when(appService.getApp((long) 1)).thenReturn(mockApp()); + CentralV2Role answer = new CentralV2Role(); + Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(answer); + Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenThrow(nullPointerException); + roleManageController.getRole(mockedRequest, mockedResponse, (long)1,null); + +} + @Test + public void getRoleIfRoleIdNotNullTest() throws Exception + { + Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp()); + CentralV2Role answer = new CentralV2Role(); + Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(answer); + List finalRoleFunctionList = new ArrayList<>(); + Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenReturn(finalRoleFunctionList); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + CentralV2Role currentRole = new CentralV2Role(); + SortedSet parentRoles = new TreeSet<>(); + CentralV2Role centralV2Role = new CentralV2Role(); + centralV2Role.setName("test"); + parentRoles.add(centralV2Role); + currentRole.setParentRoles(parentRoles); + Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(currentRole); + List availableChildRoles = new ArrayList<>(); + availableChildRoles.add(currentRole); + Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenReturn(availableChildRoles); + List appList = new ArrayList<>(); + appList.add(CentralApp()); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response); + Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList); + roleManageController.getRole(mockedRequest, mockedResponse, (long)1,(long)1); +} + + public EPApp mockApp() + { + EPApp app = new EPApp(); + + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(false); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + return app; + + } + @Test + public void getRolesTest() throws Exception { + EPApp app = mockApp(); + app.setCentralAuth(true); + List answer = new ArrayList<>(); + Mockito.when(appService.getApp((long) 1)).thenReturn(app); + Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenReturn(answer); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + List appList = new ArrayList<>(); + appList.add(CentralApp()); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response); + Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList); + roleManageController.getRoles(mockedRequest, mockedResponse, (long) 1); + } + + @Test + public void getRolesExceptionTest() throws Exception { + EPApp app = CentralApp(); + Mockito.when(appService.getApp((long) 1)).thenReturn(app); + Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenThrow(new java.lang.Exception()); + roleManageController.getRoles(mockedRequest, mockedResponse, (long) 1); + + } + + @Test + public void getRoleFunctionListTest() throws Exception { + Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp()); + List answer = new ArrayList<>(); + Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenReturn(answer); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + List appList = new ArrayList<>(); + appList.add(CentralApp()); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response); + Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList); + roleManageController.getRoleFunctionList(mockedRequest, mockedResponse, (long) 1); + } + + @Test(expected = Exception.class) + public void getRoleFunctionListExceptionTest() throws Exception { + Mockito.when(appService.getApp((long) 1)).thenReturn(NonCentralApp()); + roleManageController.getRoleFunctionList(mockedRequest, mockedResponse, (long) 1); + } + + @Test + public void saveRoleFunctionTest() throws Exception { + Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp()); + Mockito.doNothing().when(roleFunctionListController).saveRoleFunction(mockedRequest, mockedResponse, "test"); + CentralV2RoleFunction addNewFunc = new CentralV2RoleFunction(); + addNewFunc.setCode("Test"); + addNewFunc.setName("Test"); + CentralV2RoleFunction roleFunction = mockCentralRoleFunction(); + Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(roleFunction); + Mockito.when(externalAccessRolesService.saveCentralRoleFunction(Matchers.anyObject(), Matchers.anyObject())) + .thenReturn(true); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List userList = new ArrayList<>(); + userList.add(user); + List appList = new ArrayList<>(); + appList.add(CentralApp()); + Mockito.when(externalAccessRolesService.getUser("guestT")).thenReturn(userList); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response); + Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList); + roleManageController.saveRoleFunction(mockedRequest, mockedResponse, addNewFunc, (long) 1); + } + + @Test + public void saveRoleFunctionExceptionTest() throws Exception { + Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp()); + Mockito.doNothing().when(roleFunctionListController).saveRoleFunction(mockedRequest, mockedResponse, "test"); + CentralV2RoleFunction addNewFunc = new CentralV2RoleFunction(); + addNewFunc.setCode("Test"); + addNewFunc.setName("Test"); + Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(null); + roleManageController.saveRoleFunction(mockedRequest, mockedResponse, addNewFunc, (long) 1); + } + + @Test + public void saveRoleFunctionIfAppNotCentralizedTest() throws Exception { + CentralV2RoleFunction addNewFunc = new CentralV2RoleFunction(); + addNewFunc.setCode("Test"); + addNewFunc.setName("Test"); + Mockito.when(appService.getApp((long) 1)).thenReturn(NonCentralApp()); + String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}"; + roleManageController.saveRoleFunction(mockedRequest, mockedResponse, addNewFunc, (long) 1); + } + + @Test + public void removeRoleFunctionTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp()); + String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}"; + CentralV2RoleFunction roleFunction = mockCentralRoleFunction(); + Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(roleFunction); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(Matchers.anyString(), Matchers.anyObject())) + .thenReturn(true); + List appList = new ArrayList<>(); + appList.add(CentralApp()); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response); + Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList); + roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1); + } + + @Test + public void removeRoleFunctionExceptionTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp()); + String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}"; + CentralV2RoleFunction roleFunction = mockCentralRoleFunction(); + Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(roleFunction); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(Matchers.anyString(), Matchers.anyObject())) + .thenReturn(false); + List appList = new ArrayList<>(); + appList.add(CentralApp()); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response); + Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList); + roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1); + } + + @Test + public void removeRoleFunctionIfAppNotCentralizedTest() throws Exception { + EPApp app = mockApp(); + app.setCentralAuth(false); + Mockito.when(appService.getApp((long) 1)).thenReturn(app); + String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}"; + roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1); + } + + @Test + public void syncRolesTest() throws Exception { + EPApp app = mockApp(); + app.setId((long) 1); + EPUser user = mockUser.mockEPUser(); + Mockito.when(appService.getApp(1l)).thenReturn(app); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true); + Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app); + List appList = new ArrayList<>(); + appList.add(CentralApp()); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response); + Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList); + PortalRestResponse actual = roleManageController.syncRoles(mockedRequest, mockedResponse, 1l); + PortalRestResponse portalRestResponse = new PortalRestResponse<>(); + portalRestResponse.setMessage("Sync roles completed successfully!"); + portalRestResponse.setResponse("Success"); + portalRestResponse.setStatus(PortalRestStatusEnum.OK); + assertEquals(portalRestResponse, actual); + } + + @Test + public void syncRolesException() throws Exception { + Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException); + PortalRestResponse actual = roleManageController.syncRoles(mockedRequest, mockedResponse, 1l); + PortalRestResponse portalRestResponse = new PortalRestResponse<>(); + portalRestResponse.setMessage(null); + portalRestResponse.setResponse("Failed"); + portalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + assertEquals(portalRestResponse, actual); + } + + @Test + public void syncRolesFunctionsTest() throws Exception { + EPApp app = mockApp(); + app.setId((long) 1); + EPUser user = mockUser.mockEPUser(); + Mockito.when(appService.getApp(1l)).thenReturn(app); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true); + Mockito.doNothing().when(externalAccessRolesService).syncRoleFunctionFromExternalAccessSystem(app); + List appList = new ArrayList<>(); + appList.add(CentralApp()); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response); + Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList); + PortalRestResponse actual = roleManageController.syncFunctions(mockedRequest, mockedResponse, 1l); + PortalRestResponse portalRestResponse = new PortalRestResponse<>(); + portalRestResponse.setMessage("Sync Functions completed successfully!"); + portalRestResponse.setResponse("Success"); + portalRestResponse.setStatus(PortalRestStatusEnum.OK); + assertEquals(portalRestResponse, actual); + } + + @Test + public void syncRolesFunctionsException() throws Exception { + Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException); + PortalRestResponse actual = roleManageController.syncFunctions(mockedRequest, mockedResponse, 1l); + PortalRestResponse portalRestResponse = new PortalRestResponse<>(); + portalRestResponse.setMessage(null); + portalRestResponse.setResponse("Failed"); + portalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + assertEquals(portalRestResponse, actual); + } + + @Test + public void addeChildRoleTest() throws Exception + { + ModelAndView modelandView = new ModelAndView("login.htm"); + Mockito.when(roleController.addChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView); + ModelAndView expectedModelandView = roleManageController.addChildRole(mockedRequest, mockedResponse); + assertEquals(expectedModelandView, modelandView); + } + + @Test + public void removeRoleTest() throws Exception { + List epuserList = new ArrayList<>(); + List appList = new ArrayList<>(); + appList.add(CentralApp()); + EPUser user = mockUser.mockEPUser(); + epuserList.add(user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp()); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + ExternalRequestFieldsValidator res = new ExternalRequestFieldsValidator(true, "success"); + Mockito.when(externalAccessRolesService.deleteDependencyRoleRecord(Matchers.anyLong(), Matchers.anyString(), + Matchers.anyString())).thenReturn(res); + Mockito.when(externalAccessRolesService.getUser(Matchers.anyString())).thenReturn(epuserList); + Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList); + ResponseEntity response = new ResponseEntity<>(HttpStatus.OK); + Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response); + Map expedtedResponse = new HashMap(); + expedtedResponse.put("restCallStatus", " Unauthorized user"); + Map actualResponse = roleManageController.removeRole(mockedRequest, mockedResponse, (long) 1, (long) 1); + assertEquals(actualResponse.size(), expedtedResponse.size()); + + } + + @Test(expected = Exception.class) + public void removeRoleExceptionTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(appService.getApp((long) 1)).thenThrow(nullPointerException); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + roleManageController.removeRole(mockedRequest, mockedResponse, (long) 1, (long) 1); + } + + public CentralV2RoleFunction mockCentralRoleFunction() + { + CentralV2RoleFunction roleFunction = new CentralV2RoleFunction(); + roleFunction.setCode("Test"); + roleFunction.setName("Test"); + roleFunction.setAppId((long) 1); + return roleFunction; + } + + public EPApp CentralApp() + { + EPApp app = mockApp(); + app.setCentralAuth(true); + app.setNameSpace("com.test"); + return app; + } + + public EPApp NonCentralApp() + { + EPApp app = mockApp(); + app.setCentralAuth(false); + return app; + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RolesApprovalSystemControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RolesApprovalSystemControllerTest.java new file mode 100644 index 00000000..281a0cbe --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RolesApprovalSystemControllerTest.java @@ -0,0 +1,373 @@ +/*- + * ============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.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.externalsystemapproval.model.ExternalSystemRoleApproval; +import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser; +import org.onap.portalapp.portal.controller.RolesApprovalSystemController; +import org.onap.portalapp.portal.ecomp.model.PortalRestResponse; +import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.UserRolesService; +import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator; + +public class RolesApprovalSystemControllerTest extends MockitoTestSuite { + + @Mock + UserRolesService userRolesService; + + @InjectMocks + RolesApprovalSystemController rolesApprovalSystemController = new RolesApprovalSystemController(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void postUserProfileIfRolesNullTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Request has no roles"); + expectedportalRestResponse.setResponse("save user profile failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = null; + extSysUser.setRoles(externalSystemRoleApprovalList); + + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .postUserProfile(mockedRequest, extSysUser, mockedResponse); + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void postUserProfileTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Saved Successfully"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApprovalList.add(externalSystemRoleApproval); + extSysUser.setRoles(externalSystemRoleApprovalList); + ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true, + "Saved Successfully"); + + Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "POST")) + .thenReturn(externalRequestFieldsValidator); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .postUserProfile(mockedRequest, extSysUser, mockedResponse); + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void postUserProfileFailureTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Received Bad String"); + expectedportalRestResponse.setResponse("save user profile failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApprovalList.add(externalSystemRoleApproval); + extSysUser.setRoles(externalSystemRoleApprovalList); + ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false, + "Received Bad String"); + Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "POST")) + .thenReturn(externalRequestFieldsValidator); + + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .postUserProfile(mockedRequest, extSysUser, mockedResponse); + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void postUserProfileExceptionTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse("save user profile failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApprovalList.add(externalSystemRoleApproval); + extSysUser.setRoles(externalSystemRoleApprovalList); + Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "POST")).thenThrow(nullPointerException); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .postUserProfile(mockedRequest, extSysUser, mockedResponse); + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void putUserProfileIfLoginIdNullTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Request has no login ID"); + expectedportalRestResponse.setResponse("save user profile failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId(null); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + extSysUser.setRoles(externalSystemRoleApprovalList); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .putUserProfile(mockedRequest, extSysUser, mockedResponse); + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void putUserProfileTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Updated Successfully"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApprovalList.add(externalSystemRoleApproval); + extSysUser.setRoles(externalSystemRoleApprovalList); + ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true, + "Updated Successfully"); + + Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "PUT")) + .thenReturn(externalRequestFieldsValidator); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .putUserProfile(mockedRequest, extSysUser, mockedResponse); + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void putUserProfileFailureTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Received Bad String"); + expectedportalRestResponse.setResponse("save user profile failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApprovalList.add(externalSystemRoleApproval); + extSysUser.setRoles(externalSystemRoleApprovalList); + ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false, + "Received Bad String"); + + Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "PUT")) + .thenReturn(externalRequestFieldsValidator); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .putUserProfile(mockedRequest, extSysUser, mockedResponse); + + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void putUserProfileExceptionTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse("save user profile failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApprovalList.add(externalSystemRoleApproval); + extSysUser.setRoles(externalSystemRoleApprovalList); + Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "PUT")).thenThrow(nullPointerException); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .putUserProfile(mockedRequest, extSysUser, mockedResponse); + + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void deleteUserProfileIfApplicationNameNullTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Request has no application name"); + expectedportalRestResponse.setResponse("delete user profile failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName(null); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + extSysUser.setRoles(externalSystemRoleApprovalList); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .deleteUserProfile(mockedRequest, extSysUser, mockedResponse); + + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void deleteUserProfileIfMyloginrequestIdNullTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Request has no request ID"); + expectedportalRestResponse.setResponse("delete user profile failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId(null); + List externalSystemRoleApprovalList = new ArrayList(); + extSysUser.setRoles(externalSystemRoleApprovalList); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .deleteUserProfile(mockedRequest, extSysUser, mockedResponse); + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void deleteUserProfileTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("Deleted Successfully"); + expectedportalRestResponse.setResponse("Success"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.OK); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApprovalList.add(externalSystemRoleApproval); + extSysUser.setRoles(externalSystemRoleApprovalList); + ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(true, + "Success"); + + Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "DELETE")) + .thenReturn(externalRequestFieldsValidator); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .deleteUserProfile(mockedRequest, extSysUser, mockedResponse); + + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void deleteUserProfileFailureTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage("failed"); + expectedportalRestResponse.setResponse("delete user profile failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApprovalList.add(externalSystemRoleApproval); + extSysUser.setRoles(externalSystemRoleApprovalList); + ExternalRequestFieldsValidator externalRequestFieldsValidator = new ExternalRequestFieldsValidator(false, + "failed"); + + Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "DELETE")) + .thenReturn(externalRequestFieldsValidator); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .deleteUserProfile(mockedRequest, extSysUser, mockedResponse); + + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } + + @Test + public void deleteUserProfileExceptionTest() { + PortalRestResponse expectedportalRestResponse = new PortalRestResponse(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse("delete user profile failed"); + PortalRestStatusEnum portalRestStatusEnum = null; + expectedportalRestResponse.setStatus(portalRestStatusEnum.ERROR); + ExternalSystemUser extSysUser = new ExternalSystemUser(); + extSysUser.setApplicationName("Test_App"); + extSysUser.setLoginId("1"); + extSysUser.setMyloginrequestId("Test"); + List externalSystemRoleApprovalList = new ArrayList(); + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApprovalList.add(externalSystemRoleApproval); + extSysUser.setRoles(externalSystemRoleApprovalList); + Mockito.when(userRolesService.setExternalRequestUserAppRole(extSysUser, "DELETE")).thenThrow(nullPointerException); + PortalRestResponse actualportalRestResponse = rolesApprovalSystemController + .deleteUserProfile(mockedRequest, extSysUser, mockedResponse); + + assertEquals(expectedportalRestResponse, actualportalRestResponse); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java new file mode 100644 index 00000000..bafcb1c0 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SchedulerControllerTest.java @@ -0,0 +1,110 @@ +/*- + * ============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 javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.simple.JSONObject; +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.SchedulerController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.scheduler.SchedulerProperties; +import org.onap.portalapp.portal.scheduler.SchedulerRestInterface; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({UserUtils.class,SystemProperties.class}) + +public class SchedulerControllerTest { + + @Mock + SchedulerRestInterface schedulerRestInterface; + + + + @InjectMocks + SchedulerController schedulerController = new SchedulerController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockEPUser mockUser = new MockEPUser(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void getTimeSlotsTest() throws Exception{ + schedulerController.getTimeSlots(mockedRequest, "12"); + + } + + @Test + public void postCreateNewVNFChangeTest() throws Exception{ + //String testJsonData="{\"domain\":\"ChangeManagement\",\"scheduleName\":\"VnfUpgrade/DWF\",\"userId\":\"su7376\",\"domainData\":[{\"WorkflowName\":\"HEAT Stack Software Update for vNFs\",\"CallbackUrl\":\"http://127.0.0.1:8989/scheduler/v1/loopbacktest/vid\",\"CallbackData\":\"testing\"}],\"schedulingInfo\":{\"normalDurationInSeconds\":60,\"additionalDurationInSeconds\":60,\"concurrencyLimit\":60,\"policyId\":\"SNIRO_CM_1707.Config_MS_Demo_TimeLimitAndVerticalTopology_zone_localTime.1.xml\",\"vnfDetails\":[{\"groupId\":\"group1\",\"node\":[\"satmo415vbc\",\"satmo455vbc\"]}]}}"; + JSONObject jsonObject =Mockito.mock(JSONObject.class); + + schedulerController.postCreateNewVNFChange(mockedRequest, jsonObject); + } + + @Test + public void postSubmitVnfChangeTimeslotsTest() throws Exception{ + JSONObject jsonObject =Mockito.mock(JSONObject.class); + Mockito.when(jsonObject.get("scheduleId")).thenReturn("12"); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.when(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_SUBMIT_NEW_VNF_CHANGE)).thenReturn("/v1/ChangeManagement/schedules/{scheduleId}/approvals"); + schedulerController.postSubmitVnfChangeTimeslots(mockedRequest, jsonObject); + } + +} \ No newline at end of file diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SessionCommunicationControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SessionCommunicationControllerTest.java new file mode 100644 index 00000000..c991dede --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SessionCommunicationControllerTest.java @@ -0,0 +1,96 @@ +/*- + * ============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.drools.core.command.assertion.AssertEquals; +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.sessionmgt.SessionCommunicationController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.service.sessionmgt.ManageService; + +public class SessionCommunicationControllerTest { + + + @Mock + ManageService manageService; + + @InjectMocks + SessionCommunicationController SessionCommunicationController = new SessionCommunicationController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + NullPointerException nullPointerException = new NullPointerException(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + MockEPUser mockUser = new MockEPUser(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + + @Test + public void getSessionSlotCheckIntervalTest() throws Exception + { + Mockito.when(manageService.fetchSessionSlotCheckInterval()).thenReturn(1); + int result = SessionCommunicationController.getSessionSlotCheckInterval(mockedRequest, mockedResponse); + assertEquals(result, 1); + + } + + @Test + public void extendSessionTimeOutsTest() throws Exception + { + Mockito.doNothing().when(manageService).extendSessionTimeOuts("test"); + Boolean result = SessionCommunicationController.extendSessionTimeOuts(mockedRequest, mockedResponse, "test"); + assertEquals(result, true); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestClient.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestClient.java new file mode 100644 index 00000000..a6f0dcdc --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestClient.java @@ -0,0 +1,299 @@ +/*- + * ============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 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.COUNTERSIGN), 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/ab1234/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.COUNTERSIGN), // + 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-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestControllerTest.java new file mode 100644 index 00000000..05604fd0 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextRestControllerTest.java @@ -0,0 +1,144 @@ +package org.onap.portalapp.portal.controller; +/*- + * ============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. + */ + + +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 org.onap.portalapp.portal.controller.SharedContextRestClient; +import org.onap.portalapp.portal.controller.SharedContextTestProperties; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Tests the endpoints exposed by the Shared Context controller in Portal. + */ +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-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextTestProperties.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextTestProperties.java new file mode 100644 index 00000000..49eae75b --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/SharedContextTestProperties.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.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 COUNTERSIGN = "countersign"; + + /** + * 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-common/src/test/java/org/onap/portalapp/portal/controller/TicketEventControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/TicketEventControllerTest.java new file mode 100644 index 00000000..2b3598c4 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/TicketEventControllerTest.java @@ -0,0 +1,207 @@ +/*- + * ============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.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.onap.portalapp.portal.controller.TicketEventController; +import org.onap.portalapp.portal.core.MockEPUser; +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.MockitoTestSuite; +import org.onap.portalapp.portal.service.TicketEventService; +import org.onap.portalapp.portal.service.UserNotificationService; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.fasterxml.jackson.databind.JsonNode; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(UserUtils.class) +public class TicketEventControllerTest { + + @Mock + UserNotificationService userNotificationService; + + @Mock + TicketEventService ticketEventService; + + @InjectMocks + TicketEventController ticketEventController = new TicketEventController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockEPUser mockUser = new MockEPUser(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void saveUserValidationTest() throws Exception { + PortalRestResponse actualPortalRestResponse = new PortalRestResponse(); + PortalRestResponse expectedPortalRestResponse = new PortalRestResponse(); + expectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + expectedPortalRestResponse.setMessage("Invalid Org User ID"); + expectedPortalRestResponse.setResponse(null); + String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site." + + " The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", " + + "\"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601," + + "\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; " + + "ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\"," + + "\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\"," + + "\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": " + + "{\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", " + + "\"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"}," + + "\"SubscriberInfo\": {\"UserList\": [\"guest\"] }}"; + + actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest, + mockedResponse, ticketEventJson); + assertEquals(actualPortalRestResponse, expectedPortalRestResponse); + } + + @Test + public void saveTest() throws Exception { + String UserIds[] = new String[1]; + UserIds[0] = "guest"; + ArrayList users = new ArrayList<>(); + EPUser user = new EPUser(); + user.setOrgUserId("guest"); + user.setId((long)1); + users.add(user); + List userIdlist = new ArrayList<>(); + userIdlist.add("guest"); + JsonNode application = null ; + String ticketEventJson = "{\"application\":\"cbus\",\"event\":{\"body\":{\"ticketStatePhrase\":\"We recently detected a problem with the equipment at your site. " + + "The event is in queue for immediate work.\",\"ivrNotificationFlag\":\"1\",\"expectedRestoreDate\":0,\"bridgeTransport\":\"AOTS\",\"reptRequestType\":0," + + "\"ticketNum\":\"000002000857405\",\"assetID\":\"CISCO_1921C1_ISR_G2\",\"eventDate\":1490545134601," + + "\"eventAbstract\":\"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; " + + "ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\"," + + "\"severity\":\"2 - Major\",\"ticketPriority\":\"3\",\"reportedCustomerImpact\":0,\"testAutoIndicator\":0," + + "\"supportGroupName\":\"US-TEST-ORT\",\"lastModifiedDate\":\"1487687703\",\"messageGroup\":\"SNMP\",\"csi\":0,\"mfabRestoredTime\":0}," + + "\"header\":{\"timestamp\":\"2017-02-21T14:35:05.219+0000\",\"eventSource\":\"aotstm\",\"entityId\":\"000002000857405\",\"sequenceNumber\":2}," + + "\"blinkMsgId\":\"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\":\"130.4.165.158\"},\"SubscriberInfo\":{\"UserList\":[\"guest\"]}}"; + PortalRestResponse actualPortalRestResponse = new PortalRestResponse(); + PortalRestResponse expectedPortalRestResponse = new PortalRestResponse(); + expectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + expectedPortalRestResponse.setMessage("processEventNotification: notification created"); + expectedPortalRestResponse.setResponse("NotificationId"); + + + Mockito.when(userNotificationService.getUsersByOrgIds(userIdlist)).thenReturn(users); + Mockito.when(ticketEventService.getNotificationHyperLink(application, "", "")).thenReturn(""); + actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest, + mockedResponse, ticketEventJson); + assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.OK) == 0); + } + + @Test + public void saveTestForException() throws Exception { + String ticketEventJson = "\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}"; + PortalRestResponse actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest, + mockedResponse, ticketEventJson); + assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0); + } + +// @Test +// public void saveTestForApplicationValid() throws Exception { +// String ticketEventJson = "{\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}"; +// PortalRestResponse actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest, +// mockedResponse, ticketEventJson); +// assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0); +// assertEquals(actualPortalRestResponse.getMessage(), "application is mandatory"); +// +// } + + @Test + public void saveTestForBodyValid() throws Exception { + String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\",\"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}"; + PortalRestResponse actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest, + mockedResponse, ticketEventJson); + assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0); + assertEquals(actualPortalRestResponse.getMessage(), "body is mandatory"); + } + + @Test + public void saveTestForEventSourceValid() throws Exception { + String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}"; + PortalRestResponse actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest, + mockedResponse, ticketEventJson); + assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0); + assertEquals(actualPortalRestResponse.getMessage(), "Message Source is mandatory"); + } + + @Test + public void saveTestForUserListValid() throws Exception { + String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {}}"; + PortalRestResponse actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest, + mockedResponse, ticketEventJson); + assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0); + assertEquals(actualPortalRestResponse.getMessage(), "At least one user Id is mandatory"); + } + + @Test + public void saveTestForApplicationValid() throws Exception { + String ticketEventJson = "{\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}"; + PortalRestResponse actualPortalRestResponse = ticketEventController.handleRequest(mockedRequest, + mockedResponse, ticketEventJson); + assertTrue(actualPortalRestResponse.getStatus().compareTo(PortalRestStatusEnum.ERROR) == 0); + assertEquals(actualPortalRestResponse.getMessage(), "Application is mandatory"); + + } +} \ No newline at end of file diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserControllerTest.java new file mode 100644 index 00000000..205b2355 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserControllerTest.java @@ -0,0 +1,176 @@ +/*- + * ============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 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.UserController; +import org.onap.portalapp.portal.core.MockEPUser; +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.MockitoTestSuite; +import org.onap.portalapp.portal.service.UserService; +import org.onap.portalapp.portal.service.UserServiceImpl; +import org.onap.portalapp.portal.transport.ProfileDetail; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; +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) +public class UserControllerTest extends MockitoTestSuite { + + @InjectMocks + UserController userController = new UserController(); + + @Mock + UserService userService = new UserServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Mock + EPUserUtils ePUserUtils = new EPUserUtils(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + MockEPUser mockUser = new MockEPUser(); + + @Test + public void getLoggedinUserExceptionTest() { + EPUser epUser = null; + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(epUser); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage(null); + expectedResponse.setResponse(null); + PortalRestStatusEnum enu = null; + expectedResponse.setStatus(enu.ERROR); + PortalRestResponse response = userController.getLoggedinUser(mockedRequest); + assertEquals(response, expectedResponse); + } + + @Test + public void getLoggedinUserTest() throws Exception { + EPUser epUser = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(epUser); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("success"); + ProfileDetail profileDetail = new ProfileDetail(); + expectedResponse.setResponse(profileDetail); + PortalRestStatusEnum enu = null; + expectedResponse.setStatus(enu.OK); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(epUser.getLoginPwd())).thenReturn("Password"); + PortalRestResponse response = userController.getLoggedinUser(mockedRequest); + assertEquals(response.getMessage(), expectedResponse.getMessage()); + assertEquals(response.getStatus(), expectedResponse.getStatus()); + } + + @Test + public void modifyLoggedinUserIfProfileNullTest() { + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("java.lang.NullPointerException"); + expectedResponse.setResponse(null); + PortalRestStatusEnum enu = null; + expectedResponse.setStatus(enu.ERROR); + ProfileDetail profileDetail = null; + PortalRestResponse actualResponse = userController.modifyLoggedinUser(mockedRequest, profileDetail); + assertEquals(actualResponse, expectedResponse); + assertEquals(actualResponse.getStatus(), expectedResponse.getStatus()); + } + + @Test + public void modifyLoggedinUserExceptionTest() { + EPUser epUser = null; + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("java.lang.NullPointerException"); + expectedResponse.setResponse(null); + PortalRestStatusEnum enu = null; + expectedResponse.setStatus(enu.ERROR); + ProfileDetail profileDetail = new ProfileDetail(); + profileDetail.setFirstName("Test_FirstName"); + profileDetail.setLastName("Test_LastName"); + profileDetail.setEmail("Test_Email"); + profileDetail.setLoginId("Test_LoginId"); + profileDetail.setLoginPassword("Test_LoginPassword"); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(epUser); + PortalRestResponse actualResponse = userController.modifyLoggedinUser(mockedRequest, profileDetail); + assertEquals(actualResponse, expectedResponse); + + } + + /*@Test + public void modifyLoggedinUserTest() throws Exception { + EPUser epUser = mockUser.mockEPUser(); + PortalRestResponse expectedResponse = new PortalRestResponse(); + expectedResponse.setMessage("success"); + expectedResponse.setResponse(null); + PortalRestStatusEnum enu = null; + expectedResponse.setStatus(enu.OK); + ProfileDetail profileDetail = new ProfileDetail(); + profileDetail.setFirstName("Test_FirstName"); + profileDetail.setLastName("Test_LastName"); + profileDetail.setEmail("Test_Email"); + profileDetail.setLoginId("Test_LoginId"); + profileDetail.setLoginPassword("Test_LoginPassword"); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(epUser); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decrypt(epUser.getLoginPwd())).thenReturn("Password"); + PortalRestResponse actualResponse = userController.modifyLoggedinUser(mockedRequest, profileDetail); + System.out.println(actualResponse); + }*/ +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserNotificationControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserNotificationControllerTest.java new file mode 100644 index 00000000..d829b60d --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserNotificationControllerTest.java @@ -0,0 +1,281 @@ +/*- + * ============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.assertTrue; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.controller.UserNotificationController; +import org.onap.portalapp.portal.core.MockEPUser; +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.MockitoTestSuite; +import org.onap.portalapp.portal.service.FunctionalMenuService; +import org.onap.portalapp.portal.service.FunctionalMenuServiceImpl; +import org.onap.portalapp.portal.service.UserNotificationService; +import org.onap.portalapp.portal.service.UserNotificationServiceImpl; +import org.onap.portalapp.portal.transport.EpNotificationItem; +import org.onap.portalapp.portal.transport.EpNotificationItemVO; +import org.onap.portalapp.portal.transport.FunctionalMenuRole; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(UserUtils.class) +public class UserNotificationControllerTest { + + @Mock + FunctionalMenuService functionalMenuService = new FunctionalMenuServiceImpl(); + + @Mock + UserNotificationService userNotificationService = new UserNotificationServiceImpl(); + + @InjectMocks + UserNotificationController userNotificationController = new UserNotificationController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockEPUser mockUser = new MockEPUser(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void getMenuIdRoleIdTest() { + List expectedMenuRoleList = new ArrayList(); + FunctionalMenuRole functionalMenuRole = new FunctionalMenuRole(); + functionalMenuRole.setId(new Integer(99999999)); + functionalMenuRole.setMenuId((long) 137); + functionalMenuRole.setAppId(new Integer(456)); + functionalMenuRole.setRoleId(new Integer(6214)); + expectedMenuRoleList.add(functionalMenuRole); + List actualFunctionalMenuRoleList = null; + Mockito.when(functionalMenuService.getFunctionalMenuRole()).thenReturn(expectedMenuRoleList); + actualFunctionalMenuRoleList = userNotificationController.getMenuIdRoleId(mockedRequest, mockedResponse); + assertTrue(actualFunctionalMenuRoleList.equals(expectedMenuRoleList)); + + } + + @Test + public void getNotificationsTest() { + EPUser user = mockUser.mockEPUser(); + HttpSession session = mockedRequest.getSession(); + session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedEpNotificationList = new ArrayList(); + EpNotificationItem epNotificationItem = new EpNotificationItem(); + epNotificationItem.setNotificationId((long) 200); + expectedEpNotificationList.add(epNotificationItem); + PortalRestResponse> expectedportalRestResponse = new PortalRestResponse>(); + expectedportalRestResponse.setMessage("success"); + expectedportalRestResponse.setResponse(expectedEpNotificationList); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK); + PortalRestResponse> actualPortalRestResponse = null; + Mockito.when(userNotificationService.getNotifications(user.getId())).thenReturn(expectedEpNotificationList); + actualPortalRestResponse = userNotificationController.getNotifications(mockedRequest, mockedResponse); + assertTrue(expectedportalRestResponse.equals(actualPortalRestResponse)); + + } + + @Test + public void getNotificationsCatchesExceptionTest() { + EPUser user = mockUser.mockEPUser(); + HttpSession session = mockedRequest.getSession(); + session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List expectedEpNotificationList = null; + PortalRestResponse> expectedportalRestResponse = new PortalRestResponse>(); + expectedportalRestResponse.setMessage(null); + expectedportalRestResponse.setResponse(expectedEpNotificationList); + expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + PortalRestResponse> actualPortalRestResponse = null; + Mockito.when(userNotificationService.getNotifications(user.getId())).thenThrow(new NullPointerException()); + actualPortalRestResponse = userNotificationController.getNotifications(mockedRequest, mockedResponse); + assertTrue(expectedportalRestResponse.equals(actualPortalRestResponse)); + } + + @Test + public void getAdminNotificationsTest() { + EPUser user = mockUser.mockEPUser(); + HttpSession session = mockedRequest.getSession(); + session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + List actualEpNotificationsList = new ArrayList(); + List expectedEpNotificationsList = new ArrayList(); + EpNotificationItemVO epNotificationItemVO = new EpNotificationItemVO(); + epNotificationItemVO.setId((long) 1); + expectedEpNotificationsList.add(epNotificationItemVO); + Mockito.when(userNotificationService.getAdminNotificationVOS(Matchers.anyLong())).thenReturn(expectedEpNotificationsList); + actualEpNotificationsList = userNotificationController.getAdminNotifications(mockedRequest, mockedResponse); + assertTrue(actualEpNotificationsList.equals(expectedEpNotificationsList)); + } + + @Test + public void saveTestWhenNotificationIsNull() throws Exception { + EPUser user = mockUser.mockEPUser(); + HttpSession session = mockedRequest.getSession(); + session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + PortalRestResponse actualPortalRestResponse = new PortalRestResponse(); + PortalRestResponse expectedPortalRestResponse = new PortalRestResponse(); + expectedPortalRestResponse.setMessage("FAILURE"); + expectedPortalRestResponse.setResponse("Notification Header cannot be null or empty"); + expectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + + EpNotificationItem notificationItem = null; + actualPortalRestResponse = userNotificationController.save(mockedRequest, mockedResponse, notificationItem); + assertTrue(actualPortalRestResponse.equals(expectedPortalRestResponse)); + } + + @Test + public void saveTestWhenEndTimeIsGreater() throws Exception { + EPUser user = mockUser.mockEPUser(); + HttpSession session = mockedRequest.getSession(); + session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + PortalRestResponse actualPortalRestResponse = new PortalRestResponse(); + PortalRestResponse expectedPortalRestResponse = new PortalRestResponse(); + expectedPortalRestResponse.setMessage("FAILURE"); + expectedPortalRestResponse.setResponse("End Time should be greater than start time"); + expectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + EpNotificationItem notificationItem = new EpNotificationItem(); + notificationItem.setNotificationId((long) 1); + notificationItem.setMsgHeader("Test"); + Date currentDate = new Date(); + Calendar c = Calendar.getInstance(); + c.setTime(currentDate); + c.add(Calendar.DATE, 1); + Date currentDatePlusOne = c.getTime(); + notificationItem.setStartTime(currentDatePlusOne); + notificationItem.setEndTime(currentDate); + + actualPortalRestResponse = userNotificationController.save(mockedRequest, mockedResponse, notificationItem); + assertTrue(actualPortalRestResponse.equals(expectedPortalRestResponse)); + + } + + @Test + public void saveTestWhenNoRoleIDExists() throws Exception { + EPUser user = mockUser.mockEPUser(); + HttpSession session = mockedRequest.getSession(); + session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + PortalRestResponse actualPortalRestResponse = new PortalRestResponse(); + PortalRestResponse expectedPortalRestResponse = new PortalRestResponse(); + expectedPortalRestResponse.setMessage("FAILURE"); + expectedPortalRestResponse.setResponse("No Roles Ids Exist for the selected Roles"); + expectedPortalRestResponse.setStatus(PortalRestStatusEnum.ERROR); + EpNotificationItem notificationItem = new EpNotificationItem(); + notificationItem.setNotificationId((long) 1); + notificationItem.setMsgHeader("Test"); + notificationItem.setIsForAllRoles("N"); + Date currentDate = new Date(); + Calendar c = Calendar.getInstance(); + c.setTime(currentDate); + c.add(Calendar.DATE, 1); + Date currentDatePlusOne = c.getTime(); + notificationItem.setStartTime(currentDate); + notificationItem.setEndTime(currentDatePlusOne); + List roleList = new ArrayList(); + notificationItem.setRoleIds(roleList); + actualPortalRestResponse = userNotificationController.save(mockedRequest, mockedResponse, notificationItem); + assertTrue(actualPortalRestResponse.equals(expectedPortalRestResponse)); + } + + @Test + public void saveTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + HttpSession session = mockedRequest.getSession(); + session.setAttribute("user", user); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + PortalRestResponse actualPortalRestResponse = new PortalRestResponse(); + PortalRestResponse expectedPortalRestResponse = new PortalRestResponse(); + expectedPortalRestResponse.setMessage("SUCCESS"); + expectedPortalRestResponse.setResponse(""); + expectedPortalRestResponse.setStatus(PortalRestStatusEnum.OK); + EpNotificationItem notificationItem = new EpNotificationItem(); + notificationItem.setNotificationId((long) 1); + notificationItem.setMsgHeader("Test"); + notificationItem.setIsForAllRoles("Y"); + Date currentDate = new Date(); + Calendar c = Calendar.getInstance(); + c.setTime(currentDate); + c.add(Calendar.DATE, 1); + Date currentDatePlusOne = c.getTime(); + notificationItem.setStartTime(currentDate); + notificationItem.setEndTime(currentDatePlusOne); + List roleList = new ArrayList(); + Long role1 = (long) 1; + roleList.add(role1); + notificationItem.setRoleIds(roleList); + HttpServletRequest request = mockitoTestSuite.getMockedRequest(); + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(UserUtils.getUserIdAsLong(request)).thenReturn((long) 1); + Mockito.when(userNotificationService.saveNotification(notificationItem)).thenReturn("Test"); + actualPortalRestResponse = userNotificationController.save(mockedRequest, mockedResponse, notificationItem); + assertTrue(actualPortalRestResponse.equals(expectedPortalRestResponse)); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserRolesControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserRolesControllerTest.java new file mode 100644 index 00000000..2897413e --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserRolesControllerTest.java @@ -0,0 +1,326 @@ +/*- + * ============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 javax.servlet.http.HttpSession; + +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.UserRolesController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.domain.EcompAuditLog; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.AdminRolesService; +import org.onap.portalapp.portal.service.SearchService; +import org.onap.portalapp.portal.service.UserRolesService; +import org.onap.portalapp.portal.transport.AppWithRolesForUser; +import org.onap.portalapp.portal.transport.AppsListWithAdminRole; +import org.onap.portalapp.portal.transport.FieldsValidator; +import org.onap.portalapp.portal.transport.RoleInAppForUser; +import org.onap.portalapp.portal.transport.FieldsValidator.FieldName; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +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.DataAccessService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({EcompPortalUtils.class, EPCommonSystemProperties.class, EcompAuditLog.class, SystemProperties.class}) +public class UserRolesControllerTest extends MockitoTestSuite { + + String userid = "ab1234"; + + @Mock + UserRolesService userRolesService; + + @Mock + SearchService searchService; + + @Mock + AuditService auditService; + + @Mock + AdminRolesService adminRolesService; + + @Mock + FieldsValidator fieldsValidator; + + @InjectMocks + UserRolesController userRolesController = new UserRolesController(); + + @Mock + private DataAccessService dataAccessService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Mock + EPUserUtils ePUserUtils = new EPUserUtils(); + + @Mock + EPUser epuser; + + MockEPUser mockUser = new MockEPUser(); + + @Test + public void putAppWithUserRoleRequestTest() { + + FieldsValidator actualFieldsValidator = null; + + AppWithRolesForUser appWithRolesForUser = new AppWithRolesForUser(); + List listofRoles = new ArrayList(); + + appWithRolesForUser.setOrgUserId("guest"); + appWithRolesForUser.setAppId((long) 550); + appWithRolesForUser.setAppName("D2 Services Analytics Dashboard"); + appWithRolesForUser.setAppRoles(listofRoles); + + RoleInAppForUser roleInAppForUser = new RoleInAppForUser(); + roleInAppForUser.setIsApplied(false); + roleInAppForUser.setRoleId((long) 1); + roleInAppForUser.setRoleName("System Administrator"); + + RoleInAppForUser roleInAppForUser1 = new RoleInAppForUser(); + roleInAppForUser1.setIsApplied(true); + roleInAppForUser1.setRoleId((long) 16); + roleInAppForUser1.setRoleName("Standard User"); + + listofRoles.add(roleInAppForUser); + listofRoles.add(roleInAppForUser1); + EPUser user = mockUser.mockEPUser(); + FieldsValidator expectedFieldValidator = new FieldsValidator(); + List fields = new ArrayList<>(); + + expectedFieldValidator.setHttpStatusCode((long) 200); + expectedFieldValidator.setFields(fields); + expectedFieldValidator.setErrorCode(null); + HttpSession session = mockedRequest.getSession(); + session.setAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); + + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(userRolesService.putUserAppRolesRequest(appWithRolesForUser, user)) + .thenReturn(expectedFieldValidator); + + actualFieldsValidator = userRolesController.putAppWithUserRoleRequest(mockedRequest, appWithRolesForUser, + mockedResponse); + assertEquals(expectedFieldValidator.getHttpStatusCode(), actualFieldsValidator.getHttpStatusCode()); + assertEquals(expectedFieldValidator.getErrorCode(), actualFieldsValidator.getErrorCode()); + assertEquals(expectedFieldValidator.getFields(), actualFieldsValidator.getFields()); + + } + + @Test + public void getPhoneBookSearchResultBadPermissionsTest() { + String searchString = "test"; + String actualResult = null; + String expectedResult = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + } + + @Test + public void getPhoneBookSearchResultValidationTest() { + String searchString = " t"; + String actualResult = null; + String expectedResult = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + } + + @Test + public void getPhoneBookSearchResultTest() { + String searchString = "test"; + String actualResult = null; + String expectedResult = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + } + + @Test + public void getAppsWithAdminRoleStateForUserTest(){ + + String orgUserId = "hb123f"; + AppsListWithAdminRole actualResult = new AppsListWithAdminRole(); + AppsListWithAdminRole expectedResult = new AppsListWithAdminRole(); + EPUser user = mockUser.mockEPUser(); + // PowerMockito.mockStatic(EcompPortalUtils.class); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.getAppsWithAdminRoleStateForUser(orgUserId)).thenReturn(actualResult); + + actualResult = userRolesController.getAppsWithAdminRoleStateForUser(mockedRequest, orgUserId, mockedResponse); + assertEquals(expectedResult, actualResult); + } + + /*@Test + public void getAppsWithAdminRoleStateForUserBadRequestTest(){ + + String orgUserId = "hb123f"; + AppsListWithAdminRole actualResult = null; + AppsListWithAdminRole expectedResult = null; + EPUser user = mockUser.mockEPUser(); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.when(EcompPortalUtils.legitimateUserId(orgUserId)).thenReturn(false); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.getAppsWithAdminRoleStateForUser(orgUserId)).thenReturn(actualResult); + + actualResult = userRolesController.getAppsWithAdminRoleStateForUser(mockedRequest, orgUserId, mockedResponse); + assertEquals(expectedResult, actualResult); + }*/ + + @Test + public void putAppsWithAdminRoleStateForUserBadStatusCodeTest(){ + FieldsValidator actualFieldsValidator = null; + AppsListWithAdminRole newAppsListWithAdminRoles = new AppsListWithAdminRole(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List fieldNames = new ArrayList(); + expectedFieldsValidator.setErrorCode(null); + expectedFieldsValidator.setFields(fieldNames); + expectedFieldsValidator.setHttpStatusCode((long)200); + + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + + actualFieldsValidator = userRolesController.putAppsWithAdminRoleStateForUser(mockedRequest, newAppsListWithAdminRoles, mockedResponse); + assertEquals(expectedFieldsValidator, actualFieldsValidator); + } + + + /*@Test + public void putAppsWithAdminRoleStateForUserTest() { + + FieldsValidator actualFieldsValidator = null; + AppsListWithAdminRole newAppsListWithAdminRoles = new AppsListWithAdminRole(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EcompAuditLog.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(SystemProperties.MDC_TIMER)).thenReturn("1400"); + + actualFieldsValidator = userRolesController.putAppsWithAdminRoleStateForUser(mockedRequest, newAppsListWithAdminRoles, mockedResponse); + + System.out.println(actualFieldsValidator); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + }*/ + + /*@Test + public void putAppsWithAdminRoleStateForUserTest(){ + FieldsValidator actualFieldsValidator = null; + AppsListWithAdminRole newAppsListWithAdminRoles = new AppsListWithAdminRole(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List fieldNames = new ArrayList(); + expectedFieldsValidator.setErrorCode(null); + expectedFieldsValidator.setFields(fieldNames); + expectedFieldsValidator.setHttpStatusCode((long)200); + + EPUser user = mockUser.mockEPUser(); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EcompAuditLog.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.setAppsWithAdminRoleStateForUser(newAppsListWithAdminRoles)); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + // Mockito.call(auditService.logActivity(auditLog, null)); +// Mockito.when(SystemProperties.getProperty(EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN)).thenReturn("1400"); +// Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP)).thenReturn("1400"); +// Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP)).thenReturn("1400"); +// Mockito.when(SystemProperties.getProperty(SystemProperties.MDC_TIMER)).thenReturn("1400"); + + actualFieldsValidator = userRolesController.putAppsWithAdminRoleStateForUser(mockedRequest, newAppsListWithAdminRoles, mockedResponse); + assertEquals(expectedFieldsValidator, actualFieldsValidator); + }*/ +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppControllerTest.java new file mode 100644 index 00000000..b65c442d --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WebAnalyticsExtAppControllerTest.java @@ -0,0 +1,147 @@ +/*- + * ============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.io.InputStream; +import java.nio.charset.StandardCharsets; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.IOUtils; +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.WebAnalyticsExtAppController; +import org.onap.portalapp.portal.domain.EPApp; +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.AppsCacheService; +import org.onap.portalapp.portal.service.AppsCacheServiceImple; +import org.onap.portalapp.portal.transport.Analytics; +import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse; +import org.onap.portalsdk.core.service.AuditService; +import org.onap.portalsdk.core.service.AuditServiceImpl; +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; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({SystemProperties.class,IOUtils.class,Object.class}) +public class WebAnalyticsExtAppControllerTest { + + + + @InjectMocks + WebAnalyticsExtAppController webAnalyticsExtAppController = new WebAnalyticsExtAppController(); + + @Mock + AdminRolesService adminRolesService = new AdminRolesServiceImpl(); + + @Mock + AppsCacheService appCacheService = new AppsCacheServiceImple(); + + @Mock + AuditService auditService = new AuditServiceImpl(); + +// @Mock +// InputStream analyticsFileStream; + + + @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 getAnalyticsScriptTest() throws Exception + { + String expectedResponse = "http://www.ecomp.com"; + + InputStream analyticsFileStream = null; + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(IOUtils.class); + Mockito.when(IOUtils.toString(analyticsFileStream, StandardCharsets.UTF_8.name())).thenReturn("PORTAL_ENV_URL"); + Mockito.when(SystemProperties.getProperty("frontend_url")).thenReturn("http://www.ecomp.com/test"); + String actualResponse = webAnalyticsExtAppController.getAnalyticsScript(mockedRequest); +// assertNull(webAnalyticsExtAppController.getAnalyticsScript(mockedRequest)); + + // System.out.println(actualResponse); + assertTrue(actualResponse.equals(expectedResponse)); + }*/ + + /*@Test + public void getAnalyticsScriptExceptionTest() throws Exception + { + String expectedResponse = ""; + InputStream analyticsFileStream = null; + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(IOUtils.class); + Mockito.when(IOUtils.toString(analyticsFileStream, StandardCharsets.UTF_8.name())).thenThrow(nullPointerException); + Mockito.when(SystemProperties.getProperty("frontend_url")).thenReturn("http://www.ecomp.com/test"); + String actualResponse = webAnalyticsExtAppController.getAnalyticsScript(mockedRequest); + assertEquals(actualResponse,expectedResponse); + }*/ + + @Test + public void storeAnalyticsScriptIfAnalyticsNullTest() throws Exception + { + PortalAPIResponse expectedPortalAPIResponse = new PortalAPIResponse(true, "error"); + Analytics analytics= null; + Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(null); + PortalAPIResponse actualPortalAPIResponse = webAnalyticsExtAppController.storeAnalyticsScript(mockedRequest, analytics); + assertTrue(expectedPortalAPIResponse.getMessage().equals(actualPortalAPIResponse.getMessage())); + assertTrue(expectedPortalAPIResponse.getStatus().equals(actualPortalAPIResponse.getStatus())); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java new file mode 100644 index 00000000..50291f07 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogControllerTest.java @@ -0,0 +1,139 @@ +/*- + * ============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 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.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.WidgetsCatalogController; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.WidgetCatalog; +import org.onap.portalapp.portal.domain.WidgetServiceHeaders; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.ConsulHealthService; +import org.onap.portalapp.portal.service.ConsulHealthServiceImpl; +import org.onap.portalapp.portal.service.MicroserviceService; +import org.onap.portalapp.portal.service.MicroserviceServiceImpl; +import org.onap.portalapp.portal.service.WidgetParameterService; +import org.onap.portalapp.portal.service.WidgetParameterServiceImpl; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.onap.portalapp.util.EPUserUtils; +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.http.HttpEntity; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + + +@Ignore +@RunWith(PowerMockRunner.class) +@PrepareForTest({EPUserUtils.class, EcompPortalUtils.class, SystemProperties.class, EPCommonSystemProperties.class}) +public class WidgetsCatalogControllerTest { + + @Mock + ConsulHealthService consulHealthService = new ConsulHealthServiceImpl(); + + @Mock + MicroserviceService microserviceService = new MicroserviceServiceImpl(); + + @Mock + WidgetParameterService widgetParameterService = new WidgetParameterServiceImpl(); + + @InjectMocks + WidgetsCatalogController widgetsCatalogController = new WidgetsCatalogController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Mock + WidgetServiceHeaders widgetServiceHeaders ; + + + @Mock + RestTemplate template = new RestTemplate(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + MockEPUser mockUser = new MockEPUser(); + + @Mock + HttpEntity mockHttpEntity; + + @SuppressWarnings("unchecked") + @Test + public void getUserWidgetCatalogTest() throws RestClientException, Exception{ + + String resourceType = null; + List widgets = new ArrayList<>(); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Mockito.when(EcompPortalUtils.widgetMsProtocol()).thenReturn("test1"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.WIDGET_MS_PROTOCOL)).thenReturn("https"); +// Mockito.when(WidgetServiceHeaders.getInstance()).thenReturn(HttpHeaders.ACCEPT); + Mockito.when(SystemProperties.getProperty("microservices.widget.local.port")).thenReturn("test"); + Mockito.when(consulHealthService.getServiceLocation("widgets-service", + "test")).thenReturn("test.com"); + Mockito.when(new HttpEntity(WidgetServiceHeaders.getInstance())).thenReturn(mockHttpEntity); +// HttpEntity entity = new HttpEntity("helloWorld"); +// ResponseEntity ans = new ResponseEntity<>(statusCode); +// Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), +// Matchers.>any(), Matchers.eq(ArrayList.class))).thenReturn(ans); +// List expectedWidgets = widgetsCatalogController.getUserWidgetCatalog(mockedRequest, mockedResponse, "guestT"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupControllerTest.java new file mode 100644 index 00000000..03031b40 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/WidgetsCatalogMarkupControllerTest.java @@ -0,0 +1,110 @@ +/*- + * ============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.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.portal.controller.WidgetsCatalogMarkupController; +import org.onap.portalapp.portal.domain.WidgetServiceHeaders; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.ConsulHealthService; +import org.onap.portalapp.portal.service.ConsulHealthServiceImpl; +import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; +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.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({WidgetServiceHeaders.class, EcompPortalUtils.class}) +public class WidgetsCatalogMarkupControllerTest extends MockitoTestSuite { + + @InjectMocks + WidgetsCatalogMarkupController widgetsCatalogMarkupController = new WidgetsCatalogMarkupController(); + + @Mock + ConsulHealthService consulHealthService = new ConsulHealthServiceImpl(); + + @Mock + RestTemplate template = new RestTemplate(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Mock + CipherUtil cipherUtil= new CipherUtil(); + + @Mock + EcompPortalUtils ecompPortalUtils =new EcompPortalUtils(); + + @Mock + WidgetServiceHeaders WidgetServiceHeaders ; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @SuppressWarnings("static-access") + @Test + public void getWidgetMarkupTest() throws RestClientException, Exception + { + String whatService = "widgets-service"; + PowerMockito.mockStatic(WidgetServiceHeaders.class); + PowerMockito.mockStatic(EcompPortalUtils.class); + Mockito.when(template.getForObject(EcompPortalUtils.widgetMsProtocol() + "://" + consulHealthService.getServiceLocation(whatService, null) + "/widget/microservices/markup/" + 1, String.class, + WidgetServiceHeaders.getInstance())).thenReturn("Success"); + String response = widgetsCatalogMarkupController.getWidgetMarkup(mockedRequest, mockedResponse, 1); + assertTrue(response.equals("Success")); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/shared-context-test.properties b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/shared-context-test.properties new file mode 100644 index 00000000..56e5907e --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/shared-context-test.properties @@ -0,0 +1,28 @@ +### +# ================================================================================ +# ECOMP Portal +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================ +### + +hostname= www.portal.onap.org +# port = 80 +secure = true +appname = ecompportal +restpath = context +uebkey = xgnLrmNmkfCRnIwa +username = username +countersign = pwd diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/MockEPUser.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/MockEPUser.java new file mode 100644 index 00000000..c5235446 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/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.core; + +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-common/src/test/java/org/onap/portalapp/portal/core/PopulateSampleTestData.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/PopulateSampleTestData.java new file mode 100644 index 00000000..e3eeaa54 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/PopulateSampleTestData.java @@ -0,0 +1,85 @@ +package org.onap.portalapp.portal.core; +/*- + * ============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.openecomp.portalapp.portal.core; +// +//import java.sql.Connection; +//import java.sql.SQLException; +// +//import javax.sql.DataSource; +// +//import org.junit.Before; +//import org.junit.Test; +//import org.openecomp.portalapp.framework.ApplicationCommonContextTestSuite; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.core.io.ClassPathResource; +//import org.springframework.jdbc.datasource.DataSourceUtils; +//import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +// +//public class PopulateSampleTestData extends ApplicationCommonContextTestSuite { +// +// @Autowired +// DataSource dataSource; +// +// @Before +// public void populateTestData() throws SQLException { +// +// String sql = "PopulateTestData.sql"; +// createConnection(sql); +// } +// +// public void createConnection(String sql) { +// Connection connection = null; +// ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); +// populator.addScript(new ClassPathResource(sql)); +// try { +// connection = DataSourceUtils.getConnection(dataSource); +// populator.populate(connection); +// } finally { +// if (connection != null) { +// DataSourceUtils.releaseConnection(connection, dataSource); +// } +// } +// } +// +// @Test +// public void populateTest() { +// assert (true); +// } +// +//} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RemoveSampleTestData.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RemoveSampleTestData.java new file mode 100644 index 00000000..1fa6c7d1 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RemoveSampleTestData.java @@ -0,0 +1,84 @@ +package org.onap.portalapp.portal.core; +/*- + * ============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.openecomp.portalapp.portal.core; +// +//import java.sql.Connection; +//import java.sql.SQLException; +// +//import javax.sql.DataSource; +// +//import org.junit.After; +//import org.junit.Test; +//import org.openecomp.portalapp.framework.ApplicationCommonContextTestSuite; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.core.io.ClassPathResource; +//import org.springframework.jdbc.datasource.DataSourceUtils; +//import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +// +//public class RemoveSampleTestData extends ApplicationCommonContextTestSuite { +// @Autowired +// DataSource dataSource; +// +// public static int count = 0; +// +// @After +// public void removeTestData() throws SQLException { +// String sql = "RemoveTestData.sql"; +// createConnection(sql); +// } +// +// public void createConnection(String sql) { +// Connection connection = null; +// ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); +// populator.addScript(new ClassPathResource(sql)); +// try { +// connection = DataSourceUtils.getConnection(dataSource); +// populator.populate(connection); +// } finally { +// if (connection != null) { +// DataSourceUtils.releaseConnection(connection, dataSource); +// } +// } +// } +// +// @Test +// public void removeTest() { +// assert (true); +// } +//} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RestURLsTestSuite.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RestURLsTestSuite.java new file mode 100644 index 00000000..8bb21812 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RestURLsTestSuite.java @@ -0,0 +1,353 @@ +package org.onap.portalapp.portal.core; +/*- + * ============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.openecomp.portalapp.portal.core; +// +//import static org.junit.Assert.assertEquals; +//import static org.junit.Assert.assertTrue; +// +//import java.io.IOException; +//import java.nio.charset.Charset; +//import java.util.ArrayList; +// +//import org.junit.Assert; +//import org.junit.Test; +//import org.openecomp.portalapp.framework.ApplicationCommonContextTestSuite; +//import org.openecomp.portalapp.portal.domain.EPUser; +//import org.openecomp.portalapp.portal.test.core.MockEPUser; +//import org.openecomp.portalapp.portal.transport.AppNameIdIsAdmin; +//import org.openecomp.portalapp.portal.transport.AppsListWithAdminRole; +//import org.openecomp.portalsdk.core.util.SystemProperties; +//import org.springframework.http.MediaType; +//import org.springframework.test.web.servlet.ResultActions; +//import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +//import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +// +//import com.fasterxml.jackson.annotation.JsonInclude; +//import com.fasterxml.jackson.databind.ObjectMapper; +// +///** +// * +// * Use RestURLsTestSuite to test Rest API URL's +// */ +//public class RestURLsTestSuite extends ApplicationCommonContextTestSuite { +// +// public static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(), +// MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); +// +// String url = null; +// +// MockEPUser mockUser = new MockEPUser(); +// +// public byte[] convertObjectToJsonBytes(Object object) throws IOException { +// ObjectMapper mapper = new ObjectMapper(); +// mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); +// return mapper.writeValueAsBytes(object); +// } +// +// public void requestBuilder(String url) throws Exception { +// EPUser user = mockUser.mockEPUser(); +// +// MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get(url); +// requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); +// ResultActions ra = getMockMvc().perform(requestBuilder); +// assertData(ra); +// } +// +// public void assertData(ResultActions ra) { +// Assert.assertEquals("application/json", ra.andReturn().getResponse().getContentType()); +// Assert.assertEquals(200, ra.andReturn().getResponse().getStatus()); +// +// } +// +// @Test +// public void getMenuItemsTest() throws Exception { +// url = "/portalApi/functionalMenu"; +// requestBuilder(url); +// } +// +// @Test +// public void getMenuItemsForNotificationsTest() throws Exception { +// url = "/portalApi/functionalMenuForNotificationTree"; +// requestBuilder(url); +// } +// +// @Test +// public void getUserAppsTestnew() throws Exception { +// url = "/portalApi/userApps"; +// requestBuilder(url); +// } +// +// @Test +// public void getPersUserAppsTest() throws Exception { +// url = "/portalApi/persUserApps"; +// requestBuilder(url); +// } +// +// @Test +// public void getAppCatalogTest() throws Exception { +// url = "/portalApi/appCatalog"; +// requestBuilder(url); +// } +// +// @Test +// public void getAppListNewTest() throws Exception { +// ResultActions ra = getMockMvc() +// .perform(MockMvcRequestBuilders.get("/portalApi/userApplicationRoles").param("userId", "guest")); +// assertData(ra); +// } +// +// @Test +// public void getAvailableAppListTest() throws Exception { +// url = "/portalApi/availableApps"; +// requestBuilder(url); +// } +// +// @Test +// public void getAllAppsTest() throws Exception { +// url = "/portalApi/allAvailableApps"; +// requestBuilder(url); +// } +// +// @Test +// public void getUserProfileTest() throws Exception { +// url = "/portalApi/userProfile"; +// requestBuilder(url); +// } +// +// @Test +// public void getRolesByAppTest() throws Exception { +// EPUser user = mockUser.mockEPUser(); +// MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/portalApi/adminAppsRoles/550"); +// requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); +// ResultActions ra = getMockMvc().perform(requestBuilder); +// assertData(ra); +// } +// +// @Test +// public void getAppsWithAdminRoleStateForUserTest() throws Exception { +// url = "/portalApi/adminAppsRoles?user=guest"; +// requestBuilder(url); +// +// } +// +// @Test +// public void getUsersFromAppEndpointTest() throws Exception { +// url = "/portalApi/app/550/users"; +// requestBuilder(url); +// } +// +// @Test +// public void getOnboardingAppsTest() throws Exception { +// url = "/portalApi/onboardingApps"; +// requestBuilder(url); +// } +// +// @Test +// public void getMenuItemsForAuthUserTest() throws Exception { +// url = "/portalApi/functionalMenuForAuthUser"; +// requestBuilder(url); +// } +// +// @Test +// public void getMenuItemsForEditingTest() throws Exception { +// url = "/portalApi/functionalMenuForEditing"; +// requestBuilder(url); +// } +// +// @Test +// public void getAppRolesTest() throws Exception { +// url = "/portalApi/appRoles/455"; +// requestBuilder(url); +// } +// +// @Test +// public void regenerateAncestorTableTest() throws Exception { +// +// EPUser user = mockUser.mockEPUser(); +// +// MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders +// .get("/portalApi/regenerateFunctionalMenuAncestors"); +// requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); +// ResultActions ra = getMockMvc().perform(requestBuilder); +// assertEquals("application/json;charset=UTF-8", ra.andReturn().getResponse().getContentType()); +// Assert.assertEquals(200, ra.andReturn().getResponse().getStatus()); +// +// } +// +// @Test +// public void getAppListTest() throws Exception { +// url = "/portalApi/getAppList"; +// requestBuilder(url); +// } +// +// @Test +// public void getFavoritesForUserTest() throws Exception { +// url = "/portalApi/getFavoriteItems"; +// requestBuilder(url); +// } +// +// @Test +// public void getManifestTest() throws Exception { +// url = "/portalApi/manifest"; +// requestBuilder(url); +// } +// +// @Test +// public void getActiveUsersTest() throws Exception { +// url = "/portalApi/dashboard/activeUsers"; +// requestBuilder(url); +// } +// +// @Test +// public void searchPortalTest() throws Exception { +// EPUser user = mockUser.mockEPUser(); +// MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/portalApi/dashboard/search") +// .param("searchString", "guest"); +// requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); +// ResultActions ra = getMockMvc().perform(requestBuilder); +// assertData(ra); +// } +// +// @Test +// public void getWidgetDataTest() throws Exception { +// EPUser user = mockUser.mockEPUser(); +// MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/portalApi/dashboard/widgetData") +// .param("resourceType", "guest"); +// requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); +// ResultActions ra = getMockMvc().perform(requestBuilder); +// assertData(ra); +// } +// +// @Test +// public void getAppsAndContactsTest() throws Exception { +// url = "/portalApi/contactus/allapps"; +// requestBuilder(url); +// } +// +// @Test +// public void getPortalDetailsTest() throws Exception { +// url = "/portalApi/contactus/feedback"; +// requestBuilder(url); +// } +// +// @Test +// public void getAppCategoryFunctionsTest() throws Exception { +// url = "/portalApi/contactus/functions"; +// requestBuilder(url); +// } +// +// @Test +// public void getOnlineUserUpdateRateTest() throws Exception { +// url = "/portalApi/dashboard/onlineUserUpdateRate"; +// requestBuilder(url); +// } +// +// @Test +// public void getMenuIdRoleIdTest() throws Exception { +// url = "/portalApi/getFunctionalMenuRole"; +// requestBuilder(url); +// } +// +// @Test +// public void getNotificationsTest() throws Exception { +// url = "/portalApi/getNotifications"; +// requestBuilder(url); +// } +// +// @Test +// public void getAdminNotificationsTest() throws Exception { +// url = "/portalApi/getAdminNotifications"; +// requestBuilder(url); +// } +// +// @Test +// public void getNotificationAppRolesTest() throws Exception { +// url = "/portalApi/getNotificationAppRoles"; +// requestBuilder(url); +// } +// +// @Test +// public void getNotificationUpdateRateTest() throws Exception { +// url = "/portalApi/notificationUpdateRate"; +// requestBuilder(url); +// } +// +// @Test +// public void notificationReadTest() throws Exception { +// url = "/portalApi/notificationRead?notificationId=262"; +// requestBuilder(url); +// } +// +// @Test +// public void testGetRolesTest() throws Exception { +// url = "/portalApi/notificationRole/248/roles"; +// requestBuilder(url); +// } +// +// @Test +// public void putAppsWithAdminRoleStateForUserTest() throws Exception { +// +// AppsListWithAdminRole appsListWithAdminRole = new AppsListWithAdminRole(); +// appsListWithAdminRole.setOrgUserId("guest"); +// ArrayList appsRoles = new ArrayList(); +// AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin(); +// appNameIdIsAdmin.setId((long) 455); +// appNameIdIsAdmin.setAppName("CCD"); +// appNameIdIsAdmin.setIsAdmin(true); +// appNameIdIsAdmin.setRestrictedApp(false); +// appsRoles.add(appNameIdIsAdmin); +// appsListWithAdminRole.setAppsRoles(appsRoles); +// EPUser user = mockUser.mockEPUser(); +// MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.put("/portalApi/adminAppsRoles") +// .contentType(APPLICATION_JSON_UTF8).content(convertObjectToJsonBytes(appsListWithAdminRole)); +// +// requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user); +// ResultActions ra = getMockMvc().perform(requestBuilder); +// assertData(ra); +// } +// +// @Test +// public void ticketEventControllerForExternalSystem() throws Exception { +// String ticketEventJson = "{\"application\": \"cbus\",\"event\": {\"body\": {\"ticketStatePhrase\": \"We recently detected a problem with the equipment at your site. The event is in queue for immediate work.\", \"ivrNotificationFlag\": \"1\",\"expectedRestoreDate\": 0,\"bridgeTransport\": \"AOTS\", \"reptRequestType\": 0,\"ticketNum\": \"000002000857405\",\"assetID\": \"CISCO_1921C1_ISR_G2\", \"eventDate\": 1490545134601,\"eventAbstract\": \"ospfIfConfigError trap received from Cisco_1921c1_ISR_G2 with arguments: ospfRouterId=Cisco_1921c1_ISR_G2; ospfIfIpAddress=1921c1_288266; ospfAddressLessIf=0; ospfPacketSrc=172.17.0.11; ospfConfigErrorType=2; ospfPacketType=1\",\"severity\": \"2 - Major\",\"ticketPriority\": \"3\",\"reportedCustomerImpact\": 0,\"testAutoIndicator\": 0,\"supportGroupName\": \"US-TEST-ORT\",\"lastModifiedDate\": \"1487687703\",\"messageGroup\": \"SNMP\",\"csi\": 0,\"mfabRestoredTime\": 0},\"header\": {\"timestamp\": \"2017-02-21T14:35:05.219+0000\",\"eventSource\": \"aotstm\",\"entityId\": \"000002000857405\", \"sequenceNumber\": 2 },\"blinkMsgId\": \"f38c071e-1a47-4b55-9e72-1db830100a61\",\"sourceIP\": \"130.4.165.158\"},\"SubscriberInfo\": {\"UserList\": [\"hk8777\"] }}"; +// MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/auxapi/ticketevent") +// .contentType(APPLICATION_JSON_UTF8).content(ticketEventJson); +// ResultActions ra = getMockMvc().perform(requestBuilder); +// assertTrue(ra.andReturn().getResponse().getContentType().contains("application/json")); +// } +//} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AdminUserAppTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AdminUserAppTest.java new file mode 100644 index 00000000..f93fe4a3 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AdminUserAppTest.java @@ -0,0 +1,73 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.AdminUserApp; + +public class AdminUserAppTest { + + public AdminUserApp mockAdminUserApp(){ + + AdminUserApp adminUserApp = new AdminUserApp(); + + adminUserApp.setUserId((long)1); + adminUserApp.setFirstName("test"); + adminUserApp.setLastName("test"); + adminUserApp.setOrgUserId("test"); + adminUserApp.setAppId((long)1); + adminUserApp.setAppName("test"); + + return adminUserApp; + } + + @Test + public void adminUserAppTest(){ + AdminUserApp adminUserApp = mockAdminUserApp(); + + assertEquals(adminUserApp.getUser_Id(), new Long(1)); + assertEquals(adminUserApp.getFirstName(), "test"); + assertEquals(adminUserApp.getLastName(), "test"); + assertEquals(adminUserApp.getOrgUserId(), "test"); + assertEquals(adminUserApp.getAppName(), "test"); + assertEquals(adminUserApp.getAppId(), new Long(1)); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AdminUserApplicationsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AdminUserApplicationsTest.java new file mode 100644 index 00000000..b01efb83 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AdminUserApplicationsTest.java @@ -0,0 +1,94 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import javax.persistence.Column; +import javax.persistence.Id; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.AdminUserApp; +import org.onap.portalapp.portal.domain.AdminUserApplications; + +public class AdminUserApplicationsTest { + + public AdminUserApplications mockAdminUserApplications(){ + + AdminUserApp adminUserApp = new AdminUserApp(); + + adminUserApp.setUserId((long)1); + adminUserApp.setFirstName("test"); + adminUserApp.setLastName("test"); + adminUserApp.setOrgUserId("test"); + adminUserApp.setAppId((long)1); + adminUserApp.setAppName("test"); + + AdminUserApplications adminUserApplications = new AdminUserApplications(adminUserApp); + + adminUserApplications.setUser_Id((long)1); + adminUserApplications.setFirstName("test"); + adminUserApplications.setLastName("test"); + adminUserApplications.setOrgUserId("test"); + return adminUserApplications; + } + + @Test + public void adminUserAppTest(){ + AdminUserApplications adminUserApplications = mockAdminUserApplications(); + AdminUserApp adminUserApp = new AdminUserApp(); + + adminUserApp.setUserId((long)1); + adminUserApp.setFirstName("test"); + adminUserApp.setLastName("test"); + adminUserApp.setOrgUserId("test"); + adminUserApp.setAppId((long)1); + adminUserApp.setAppName("test"); + AdminUserApplications adminUserApplications1 = new AdminUserApplications(adminUserApp); + + assertEquals(adminUserApplications.getUser_Id(), new Long(1)); + assertEquals(adminUserApplications.getFirstName(), "test"); + assertEquals(adminUserApplications.getLastName(), "test"); + assertEquals(adminUserApplications.getOrgUserId(), "test"); + + + assertEquals(adminUserApplications1.getApps().get(0).getAppId(),adminUserApp.getAppId()); + assertEquals(adminUserApplications1.getApps().get(0).getAppName(),adminUserApp.getAppName()); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AppContactUsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AppContactUsTest.java new file mode 100644 index 00000000..ec24c6e4 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/AppContactUsTest.java @@ -0,0 +1,69 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.AppContactUs; + +public class AppContactUsTest { + + public AppContactUs mockAppContactUs(){ + AppContactUs appContactUs = new AppContactUs(); + appContactUs.setDescription("test"); + appContactUs.setContactEmail("test"); + appContactUs.setContactName("test"); + appContactUs.setUrl("test"); + appContactUs.setActiveYN("test"); + + return appContactUs; + } + + @Test + public void mockAppContactUsTest(){ + AppContactUs appContactUs = mockAppContactUs(); + + assertEquals(appContactUs.getDescription(), "test"); + assertEquals(appContactUs.getContactEmail(), "test"); + assertEquals(appContactUs.getContactName(), "test"); + assertEquals(appContactUs.getUrl(), "test"); + assertEquals(appContactUs.getActiveYN(), "test"); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/CentralRoleFunctionTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/CentralRoleFunctionTest.java new file mode 100644 index 00000000..d91ed842 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/CentralRoleFunctionTest.java @@ -0,0 +1,67 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.CentralRoleFunction; + +public class CentralRoleFunctionTest { + + public CentralRoleFunction mockCentralRoleFunction(){ + + CentralRoleFunction centralRoleFunction = new CentralRoleFunction(); + + centralRoleFunction.setCode("test"); + centralRoleFunction.setName("test"); + centralRoleFunction.setId(null); + centralRoleFunction.setEditUrl("test"); + return centralRoleFunction; + } + + @Test + public void centralRoleFunctionTest(){ + CentralRoleFunction centralRoleFunction = mockCentralRoleFunction(); + + assertEquals(centralRoleFunction.getId(), null); + assertEquals(centralRoleFunction.getCode(), "test"); + assertEquals(centralRoleFunction.getName(), "test"); + assertEquals(centralRoleFunction.getEditUrl(), "test"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/CentralV2RoleFunctionTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/CentralV2RoleFunctionTest.java new file mode 100644 index 00000000..345f4576 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/CentralV2RoleFunctionTest.java @@ -0,0 +1,71 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class CentralV2RoleFunctionTest { + + public CentralV2RoleFunction mockCentralRoleFunction(){ + + CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(); + + centralV2RoleFunction.setCode("test"); + centralV2RoleFunction.setName("test"); + centralV2RoleFunction.setAppId((long)1); + centralV2RoleFunction.setEditUrl("test"); + centralV2RoleFunction.setType("testType"); + centralV2RoleFunction.setAction("testAction"); + + return centralV2RoleFunction; + } + + @Test + public void centralRoleFunctionTest(){ + CentralV2RoleFunction centralV2RoleFunction = mockCentralRoleFunction(); + + assertEquals(centralV2RoleFunction.getAppId(), new Long(1)); + assertEquals(centralV2RoleFunction.getCode(), "test"); + assertEquals(centralV2RoleFunction.getName(), "test"); + assertEquals(centralV2RoleFunction.getEditUrl(), "test"); + assertEquals(centralV2RoleFunction.getAction(), "testAction"); + assertEquals(centralV2RoleFunction.getType(), "testType"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPAppRoleFunctionTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPAppRoleFunctionTest.java new file mode 100644 index 00000000..cb936916 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPAppRoleFunctionTest.java @@ -0,0 +1,64 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPAppRoleFunction; + +public class EPAppRoleFunctionTest { + + public EPAppRoleFunction mockEPAppRoleFunction(){ + EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction(); + epAppRoleFunction.setRoleId((long)1); + epAppRoleFunction.setAppId((long)1); + epAppRoleFunction.setCode("test"); + + return epAppRoleFunction; + } + + @Test + public void epAppRoleFunctionTest(){ + EPAppRoleFunction epAppRoleFunction = mockEPAppRoleFunction(); + + assertEquals(epAppRoleFunction.getRoleId(), new Long(1)); + assertEquals(epAppRoleFunction.getAppId(), new Long(1)); + assertEquals(epAppRoleFunction.getCode(), "test"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPAppTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPAppTest.java new file mode 100644 index 00000000..7537ccf2 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPAppTest.java @@ -0,0 +1,98 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPApp; + +public class EPAppTest { + + public EPApp mockEPApp(){ + EPApp epApp = new EPApp(); + + epApp.setName("test"); + epApp.setImageUrl("test"); + epApp.setDescription("test"); + epApp.setNotes("test"); + epApp.setUrl("test"); + epApp.setAlternateUrl("test"); + epApp.setAppRestEndpoint("test"); + epApp.setMlAppName("test"); + epApp.setMlAppAdminId("test"); + epApp.setMotsId((long)1); + epApp.setUsername("test"); + epApp.setAppPassword("test"); + epApp.setOpen(false); + epApp.setEnabled(false); + epApp.setUebTopicName("test"); + epApp.setUebSecret("test"); + epApp.setAppType(1); + epApp.setCentralAuth(false); + epApp.setNameSpace("test"); + + return epApp; + } + + @Test + public void epAppTest(){ + EPApp epApp = mockEPApp(); + + assertEquals(epApp.getName(), "test"); + assertEquals(epApp.getImageUrl(), "test"); + assertEquals(epApp.getDescription(), "test"); + assertEquals(epApp.getNotes(), "test"); + assertEquals(epApp.getUrl(), "test"); + assertEquals(epApp.getAlternateUrl(), "test"); + assertEquals(epApp.getAppRestEndpoint(), "test"); + assertEquals(epApp.getMlAppName(), "test"); + assertEquals(epApp.getMlAppAdminId(), "test"); + assertEquals(epApp.getMotsId(), new Long(1)); + assertEquals(epApp.getUsername(), "test"); + assertEquals(epApp.getAppPassword(), "test"); + assertEquals(epApp.getOpen(), false); + assertEquals(epApp.getEnabled(), false); + assertEquals(epApp.getUebTopicName(), "test"); + assertEquals(epApp.getUebSecret(), "test"); + assertEquals(epApp.getAppType(), Integer.valueOf(1)); + assertEquals(epApp.getCentralAuth(), false); + assertEquals(epApp.getNameSpace(), "test"); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPEndpointAccountTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPEndpointAccountTest.java new file mode 100644 index 00000000..d01860af --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPEndpointAccountTest.java @@ -0,0 +1,66 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPEndpointAccount; + +public class EPEndpointAccountTest { + + public EPEndpointAccount mockEPEndpointAccount(){ + EPEndpointAccount epEndpointAccount = new EPEndpointAccount(); + + epEndpointAccount.setEp_id((long)1); + epEndpointAccount.setAccount_id((long)1); + epEndpointAccount.setId((long)1); + + return epEndpointAccount; + } + + @Test + public void epEndpointAccount(){ + EPEndpointAccount epEndpointAccount = mockEPEndpointAccount(); + assertEquals(epEndpointAccount.getEp_id(), new Long(1)); + assertEquals(epEndpointAccount.getAccount_id(), new Long(1)); + assertEquals(epEndpointAccount.getId(), new Long(1)); + + assertEquals(epEndpointAccount.toString(), "EPEndpointAccount [id=1, ep_id=1, account_id=1]"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPEndpointTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPEndpointTest.java new file mode 100644 index 00000000..79915f25 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPEndpointTest.java @@ -0,0 +1,64 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPEndpoint; + +public class EPEndpointTest { + + public EPEndpoint mockEPEndpoint(){ + EPEndpoint epEndpoint = new EPEndpoint(); + + epEndpoint.setId((long)1); + epEndpoint.setName("test"); + + return epEndpoint; + } + + @Test + public void epEndpointTest(){ + EPEndpoint epEndpoint = mockEPEndpoint(); + + assertEquals(epEndpoint.getId(), new Long(1)); + assertEquals(epEndpoint.getName(), "test"); + assertEquals("EPEndpoint [id=1, name=test]", epEndpoint.toString()); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java new file mode 100644 index 00000000..0b51b3d7 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPRoleTest.java @@ -0,0 +1,73 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPRole; + +public class EPRoleTest { + + public EPRole mockEPRole(){ + EPRole epRole = new EPRole(); + + epRole.setName("test"); + epRole.setActive(false); + epRole.setPriority(1); + epRole.setAppId((long)1); + epRole.setAppRoleId((long)1); + + return epRole; + } + + @Test + public void epRoleTest(){ + EPRole epRole = mockEPRole(); + + assertEquals(epRole.getName(), "test"); + assertEquals(epRole.getActive(), false); + assertEquals(epRole.getPriority().toString(),"1"); + assertEquals(epRole.getAppId(), new Long(1)); + assertEquals(epRole.getAppRoleId(), new Long(1)); + + assertEquals(epRole.toString(), "[Id = null, name = test]"); + + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppCatalogRolesTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppCatalogRolesTest.java new file mode 100644 index 00000000..e90f74fe --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppCatalogRolesTest.java @@ -0,0 +1,69 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPUserAppCatalogRoles; + +public class EPUserAppCatalogRolesTest { + + public EPUserAppCatalogRoles mockEPUserAppCatalogRoles(){ + EPUserAppCatalogRoles epUserAppCatalogRoles = new EPUserAppCatalogRoles(); + + epUserAppCatalogRoles.setRequestedRoleId((long)1); + epUserAppCatalogRoles.setRolename("test"); + epUserAppCatalogRoles.setRequestStatus("status"); + epUserAppCatalogRoles.setAppId((long)1); + + return epUserAppCatalogRoles; + } + + @Test + public void epUserAppCatalogRolesTest(){ + EPUserAppCatalogRoles epUserAppCatalogRoles = mockEPUserAppCatalogRoles(); + + assertEquals(epUserAppCatalogRoles.getRequestedRoleId(), new Long(1)); + assertEquals(epUserAppCatalogRoles.getRolename(), "test"); + assertEquals(epUserAppCatalogRoles.getRequestStatus(), "status"); + assertEquals(epUserAppCatalogRoles.getAppId(), new Long(1)); + + assertEquals("EPUserAppCatalogRoles [requestedRoleId=1, rolename=test, requestStatus=status, appId=1]", epUserAppCatalogRoles.toString()); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesRequestDetailTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesRequestDetailTest.java new file mode 100644 index 00000000..31efff3e --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesRequestDetailTest.java @@ -0,0 +1,88 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPUserAppRolesRequest; +import org.onap.portalapp.portal.domain.EPUserAppRolesRequestDetail; + +public class EPUserAppRolesRequestDetailTest { + + public EPUserAppRolesRequestDetail mockEPUserAppRolesRequestDetail(){ + + EPUserAppRolesRequest epUserAppRolesRequest = new EPUserAppRolesRequest(); + epUserAppRolesRequest.setUserId((long)1); + epUserAppRolesRequest.setAppId((long)1); + epUserAppRolesRequest.setCreated(new Date()); + epUserAppRolesRequest.setUpdatedDate(new Date()); + epUserAppRolesRequest.setRequestStatus("test"); + + EPUserAppRolesRequestDetail epUserAppRolesRequestDetail = new EPUserAppRolesRequestDetail(); + epUserAppRolesRequestDetail.setReqRoleId((long)1); + epUserAppRolesRequestDetail.setReqType("test"); + epUserAppRolesRequestDetail.setEpRequestIdData(epUserAppRolesRequest); + + return epUserAppRolesRequestDetail; + } + + @Test + public void epUserAppRolesRequestDetailTest(){ + + EPUserAppRolesRequest epUserAppRolesRequest = new EPUserAppRolesRequest(); + epUserAppRolesRequest.setUserId((long)1); + epUserAppRolesRequest.setAppId((long)1); + epUserAppRolesRequest.setCreated(new Date()); + epUserAppRolesRequest.setUpdatedDate(new Date()); + epUserAppRolesRequest.setRequestStatus("test"); + + EPUserAppRolesRequestDetail epUserAppRolesRequestDetail = mockEPUserAppRolesRequestDetail(); + + EPUserAppRolesRequestDetail epUserAppRolesRequestDetail1 = new EPUserAppRolesRequestDetail(); + epUserAppRolesRequestDetail1.setReqRoleId((long)1); + epUserAppRolesRequestDetail1.setReqType("test"); + epUserAppRolesRequestDetail1.setEpRequestIdData(epUserAppRolesRequest); + + assertEquals(epUserAppRolesRequestDetail.getReqRoleId(), new Long(1)); + assertEquals(epUserAppRolesRequestDetail.getReqType(), "test"); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesTest.java new file mode 100644 index 00000000..98b2d7bf --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppRolesTest.java @@ -0,0 +1,65 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPUserAppRoles; + +public class EPUserAppRolesTest { + + public EPUserAppRoles mockEPUserAppRoles(){ + EPUserAppRoles epUserAppRoles = new EPUserAppRoles(); + + epUserAppRoles.setRoleId((long)1); + epUserAppRoles.setAppId((long)1); + + return epUserAppRoles; + } + + @Test + public void epUserAppRolesTest(){ + EPUserAppRoles epUserAppRoles = mockEPUserAppRoles(); + + assertEquals(epUserAppRoles.getRoleId(), new Long(1)); + assertEquals(epUserAppRoles.getAppId(), new Long(1)); + assertEquals("EpUserAppRoles [roleId=1, appId=1]", epUserAppRoles.toString()); + } +} + diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppTest.java new file mode 100644 index 00000000..72c5002d --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppTest.java @@ -0,0 +1,122 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.domain.EPRole; +import org.onap.portalapp.portal.domain.EPUserApp; + +public class EPUserAppTest { + + public EPUserApp mockEPUserApp(){ + + EPApp epApp = new EPApp(); + epApp.setName("test"); + epApp.setImageUrl("test"); + epApp.setDescription("test"); + epApp.setNotes("test"); + epApp.setUrl("test"); + epApp.setAlternateUrl("test"); + epApp.setAppRestEndpoint("test"); + epApp.setMlAppName("test"); + epApp.setMlAppAdminId("test"); + epApp.setMotsId((long)1); + epApp.setUsername("test"); + epApp.setAppPassword("test"); + + + //Role + EPRole epRole = new EPRole(); + epRole.setName("test"); + epRole.setActive(false); + epRole.setPriority(1); + epRole.setAppId((long)1); + epRole.setAppRoleId((long)1); + + EPUserApp user = new EPUserApp(); + user.setUserId((long)1); + user.setApp(epApp); + user.setRole(epRole); + user.setPriority((short)32767); + + + return user; + } + + @Test + public void userTest(){ + EPUserApp user = mockEPUserApp(); + + EPApp epApp = new EPApp(); + epApp.setName("test"); + epApp.setImageUrl("test"); + epApp.setDescription("test"); + epApp.setNotes("test"); + epApp.setUrl("test"); + epApp.setAlternateUrl("test"); + epApp.setAppRestEndpoint("test"); + epApp.setMlAppName("test"); + epApp.setMlAppAdminId("test"); + epApp.setMotsId((long)1); + epApp.setUsername("test"); + epApp.setAppPassword("test"); + user.setApp(epApp); + + //Role + EPRole epRole = new EPRole(); + epRole.setName("test"); + epRole.setActive(false); + epRole.setPriority(1); + epRole.setAppId((long)1); + epRole.setAppRoleId((long)1); + + + assertEquals(user.getUserId(),Long.valueOf(1)); + assertEquals(user.getApp(), epApp); + assertEquals(user.getPriority().getClass(), Short.class); + + assertEquals(user.toString(), "[u: 1; a: null, r: null; appRoleId: 1]"); + + assertEquals(user.hashCode(), user.hashCode()); + + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreferenceTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreferenceTest.java new file mode 100644 index 00000000..2923eb2b --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreferenceTest.java @@ -0,0 +1,66 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPUserAppsManualSortPreference; + +public class EPUserAppsManualSortPreferenceTest { + + public EPUserAppsManualSortPreference mockEPUserAppsManualSortPreference(){ + + EPUserAppsManualSortPreference epUserAppsManualSortPreference = new EPUserAppsManualSortPreference(); + epUserAppsManualSortPreference.setUserId(1); + epUserAppsManualSortPreference.setAppId((long)1); + epUserAppsManualSortPreference.setAppManualSortOrder(1); + + return epUserAppsManualSortPreference; + } + + @Test + public void epUserAppsManualSortPreferenceTest(){ + + EPUserAppsManualSortPreference epUserAppsManualSortPreference = mockEPUserAppsManualSortPreference(); + + assertEquals(epUserAppsManualSortPreference.getUserId(), 1); + assertEquals(epUserAppsManualSortPreference.getAppId(), new Long(1)); + assertEquals(epUserAppsManualSortPreference.getAppManualSortOrder(), 1); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsSortPreferenceTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsSortPreferenceTest.java new file mode 100644 index 00000000..e2b49f0a --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsSortPreferenceTest.java @@ -0,0 +1,80 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPUserAppsSortPreference; + +public class EPUserAppsSortPreferenceTest { + + public EPUserAppsSortPreference mockEPUserAppsSortPreferenceTest(){ + + EPUserAppsSortPreference epUserAppsSortPreference = new EPUserAppsSortPreference(); + epUserAppsSortPreference.setUserId(1); + epUserAppsSortPreference.setSortPref("test"); + epUserAppsSortPreference.setId((long)1); + epUserAppsSortPreference.setCreated(new Date()); + epUserAppsSortPreference.setModified(new Date()); + epUserAppsSortPreference.setModifiedId((long)1); + epUserAppsSortPreference.setRowNum((long)1); + epUserAppsSortPreference.setAuditTrail(null); + + return epUserAppsSortPreference; + } + + @Test + public void epUserAppsSortPreferenceTest() { + EPUserAppsSortPreference epUserAppsSortPreference = mockEPUserAppsSortPreferenceTest(); + + assertEquals(epUserAppsSortPreference.getUserId(), 1); + assertEquals(epUserAppsSortPreference.getSortPref(), "test"); + assertEquals(epUserAppsSortPreference.getId(), new Long(1)); +// assertEquals(epUserAppsSortPreference.getCreated(), new Date()); +// assertEquals(epUserAppsSortPreference.getModified(), new Date()); + assertEquals(epUserAppsSortPreference.getModifiedId(), new Long(1)); + assertEquals(epUserAppsSortPreference.getRowNum(), new Long(1)); + assertEquals(epUserAppsSortPreference.getAuditTrail(), null); + + + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserNotificationTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserNotificationTest.java new file mode 100644 index 00000000..9aa9a37d --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserNotificationTest.java @@ -0,0 +1,71 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPUserNotification; + +public class EPUserNotificationTest { + + public EPUserNotification mockEPUserNotification(){ + + EPUserNotification epUserNotification = new EPUserNotification(); + + epUserNotification.setUserId((long)1); + epUserNotification.setNotificationId((long)1); + epUserNotification.setViewed("test"); + epUserNotification.setUpdateTime(new Date()); + + return epUserNotification; + } + + @Test + public void epUserNotificationTest(){ + EPUserNotification epUserNotification = mockEPUserNotification(); + + assertEquals(epUserNotification.getUserId(), new Long(1)); + assertEquals(epUserNotification.getNotificationId(), new Long(1)); + assertEquals(epUserNotification.getViewed(), "test"); + // assertEquals(epUserNotification.getUpdateTime(), new Date()); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserTest.java new file mode 100644 index 00000000..cf1703d5 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserTest.java @@ -0,0 +1,151 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPUser; + +public class EPUserTest { + + public EPUser mockEPUser(){ + + EPUser epUser = new EPUser(); + + epUser.setId((long)1); + epUser.setManagerId((long) 1234); + epUser.setFirstName("test"); + epUser.setLastName("test"); + epUser.setMiddleInitial("test"); + epUser.setPhone("test"); + epUser.setFax("test"); + epUser.setCellular("test"); + epUser.setEmail("test"); + epUser.setAddressId((long) 123); + epUser.setAlertMethodCd("test"); + epUser.setHrid("test"); + epUser.setOrgUserId("test"); + epUser.setOrgCode("test"); + epUser.setAddress1("test"); + epUser.setAddress2("test"); + epUser.setCity("test"); + epUser.setState("test"); + epUser.setZipCode("test"); + epUser.setCountry("test"); + epUser.setOrgManagerUserId("test"); + epUser.setLocationClli("test"); + epUser.setBusinessCountryCode("test"); + epUser.setBusinessCountryName("test"); + epUser.setBusinessUnit("test"); + epUser.setBusinessUnitName("test"); + epUser.setDepartment("test"); + epUser.setDepartmentName("test"); + epUser.setCompanyCode("test"); + epUser.setCompany("test"); + epUser.setZipCodeSuffix("test"); + epUser.setJobTitle("test"); + epUser.setCommandChain("test"); + epUser.setSiloStatus("test"); + epUser.setCostCenter("test"); + epUser.setFinancialLocCode("test"); + epUser.setLoginId("test"); + epUser.setLoginPwd("test"); + epUser.setLastLoginDate(new Date()); + epUser.setActive(false); + epUser.setInternal(false); + epUser.setSelectedProfileId((long) 12345); + epUser.setTimeZoneId((long) 12345); + epUser.setOnline(false); + epUser.setChatId("test"); + return epUser; + + } + + @Test + public void userTest(){ + EPUser user = mockEPUser(); + + assertEquals(user.getId(), new Long(1)); + assertEquals(user.getManagerId(), new Long(1234)); + assertEquals(user.getFirstName(), "test"); + assertEquals(user.getLastName(), "test"); + assertEquals(user.getMiddleInitial(), "test"); + assertEquals(user.getPhone(), "test"); + assertEquals(user.getFax(), "test"); + assertEquals(user.getCellular(), "test"); + assertEquals(user.getEmail(), "test"); + assertEquals(user.getAddressId(), new Long(123) ); + assertEquals(user.getAlertMethodCd(), "test"); + assertEquals(user.getHrid(), "test"); + assertEquals(user.getOrgUserId(), "test"); + assertEquals(user.getOrgCode(), "test"); + assertEquals(user.getAddress1(), "test"); + assertEquals(user.getAddress2(), "test"); + assertEquals(user.getState(), "test"); + assertEquals(user.getZipCode(), "test"); + assertEquals(user.getCountry(), "test"); + assertEquals(user.getOrgManagerUserId(), "test"); + assertEquals(user.getLocationClli(), "test"); + assertEquals(user.getBusinessCountryCode(), "test"); + assertEquals(user.getBusinessCountryName(), "test"); + assertEquals(user.getBusinessUnit(), "test"); + assertEquals(user.getBusinessUnitName(), "test"); + assertEquals(user.getDepartment(), "test"); + assertEquals(user.getDepartmentName(), "test"); + assertEquals(user.getCompanyCode(), "test"); + assertEquals(user.getCompany(), "test"); + assertEquals(user.getZipCodeSuffix(), "test"); + assertEquals(user.getJobTitle(), "test"); + assertEquals(user.getCommandChain(), "test"); + assertEquals(user.getSiloStatus(), "test"); + assertEquals(user.getFinancialLocCode(), "test"); + assertEquals(user.getLoginId(), "test"); + assertEquals(user.getLoginPwd(), "test"); + assertEquals(user.getActive(), false); + assertEquals(user.getInternal(), false); + assertEquals(user.getSelectedProfileId(), new Long (12345)); + assertEquals(user.getTimeZoneId(), new Long (12345)); + assertEquals(user.getChatId(), "test"); + + //assertEquals(user.toString(), "EPUser [orgId=null, managerId=1234, firstName=test, middleInitial=test, lastName=test, phone=test, fax=test, cellular=test, email=test, addressId=123, alertMethodCd=test, hrid=test, orgUserId=test, orgCode=test, address1=test, address2=test, city=test, state=test, zipCode=test, country=test, orgManagerUserId=test, locationClli=test, businessCountryCode=test, businessCountryName=test, businessUnit=test, businessUnitName=test, department=test, departmentName=test, companyCode=test, company=test, zipCodeSuffix=test, jobTitle=test, commandChain=test, siloStatus=test, costCenter=test, financialLocCode=test, loginId=test, loginPwd=test, lastLoginDate=Tue Sep 05 11:04:49 EDT 2017, active=false, internal=false, selectedProfileId=12345, timeZoneId=12345, online=false, chatId=test, isGuest=false, userApps=[], pseudoRoles=[]]"); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreferenceTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreferenceTest.java new file mode 100644 index 00000000..b4b4780d --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreferenceTest.java @@ -0,0 +1,73 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPWidgetsManualSortPreference; + +public class EPWidgetsManualSortPreferenceTest { + + public EPWidgetsManualSortPreference mockEPWidgetsManualSortPreference(){ + EPWidgetsManualSortPreference epWidgetsManualSortPreference = new EPWidgetsManualSortPreference(); + + epWidgetsManualSortPreference.setUserId(1); + epWidgetsManualSortPreference.setWidgetId((long)1); + epWidgetsManualSortPreference.setWidgetRow(1); + epWidgetsManualSortPreference.setWidgetCol(1); + epWidgetsManualSortPreference.setWidgetWidth(1); + epWidgetsManualSortPreference.setWidgetHeight(1); + + return epWidgetsManualSortPreference; + } + + @Test + public void epWidgetsManualSortPreferenceTest(){ + EPWidgetsManualSortPreference epWidgetsManualSortPreference = mockEPWidgetsManualSortPreference(); + + assertEquals(epWidgetsManualSortPreference.getWidgetId(), new Long(1)); + assertEquals(epWidgetsManualSortPreference.getUserId(), 1); + assertEquals(epWidgetsManualSortPreference.getWidgetRow(), 1); + assertEquals(epWidgetsManualSortPreference.getWidgetCol(), 1); + assertEquals(epWidgetsManualSortPreference.getWidgetHeight(), 1); + assertEquals(epWidgetsManualSortPreference.getWidgetWidth(), 1); + + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EcompAppRoleIdTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EcompAppRoleIdTest.java new file mode 100644 index 00000000..96ebcb49 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EcompAppRoleIdTest.java @@ -0,0 +1,70 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EcompAppRoleId; + +public class EcompAppRoleIdTest { + + public EcompAppRoleId mockEcompAppRoleId(){ + + EcompAppRoleId ecompAppRoleId = new EcompAppRoleId(); + + ecompAppRoleId.setAppId((long)1); + ecompAppRoleId.setAppName("test"); + ecompAppRoleId.setRoleId(1); + ecompAppRoleId.setRoleName("test"); + + return ecompAppRoleId; + } + + @Test + public void ecompAppRoleIdTest(){ + + EcompAppRoleId ecompAppRoleId = mockEcompAppRoleId(); + + assertEquals(ecompAppRoleId.getAppId(), new Long(1)); + assertEquals(ecompAppRoleId.getAppName(), "test"); + assertEquals(ecompAppRoleId.getRoleId().toString(), "1"); + assertEquals(ecompAppRoleId.getRoleName(), "test"); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EcompAppRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EcompAppRoleTest.java new file mode 100644 index 00000000..614588da --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EcompAppRoleTest.java @@ -0,0 +1,68 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EcompAppRole; + +public class EcompAppRoleTest { + + public EcompAppRole mockEcompAppRole(){ + EcompAppRole ecompAppRole = new EcompAppRole(); + + ecompAppRole.setAppId((long)1); + ecompAppRole.setAppName("test"); + ecompAppRole.setRoleId(1); + ecompAppRole.setRoleName("test"); + + return ecompAppRole; + } + + @Test + public void ecompAppRoleTest(){ + EcompAppRole ecompAppRole = mockEcompAppRole(); + + assertEquals(ecompAppRole.getAppId(), new Long(1)); + assertEquals(ecompAppRole.getAppName(), "test"); + assertEquals(ecompAppRole.getRoleId().toString(), "1"); + assertEquals(ecompAppRole.getRoleName(), "test"); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalRoleDetailsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalRoleDetailsTest.java new file mode 100644 index 00000000..9c999aee --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalRoleDetailsTest.java @@ -0,0 +1,96 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.EPAppRoleFunction; +import org.onap.portalapp.portal.domain.ExternalRoleDetails; + +public class ExternalRoleDetailsTest { + + public ExternalRoleDetails mockExternalRoleDetails(){ + + List epAppRoleFunctionList = new ArrayList(); + + EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction(); + epAppRoleFunction.setRoleId((long)1); + epAppRoleFunction.setAppId((long)1); + epAppRoleFunction.setCode("test"); + + epAppRoleFunctionList.add(epAppRoleFunction); + + ExternalRoleDetails externalRoleDetails = new ExternalRoleDetails(); + + externalRoleDetails.setName("test"); + externalRoleDetails.setActive(false); + externalRoleDetails.setPriority(1); + externalRoleDetails.setAppId((long)1); + externalRoleDetails.setAppRoleId((long)1); + externalRoleDetails.setPerms(epAppRoleFunctionList); + + return externalRoleDetails; + } + + @Test + public void externalRoleDetailsTest(){ + + List epAppRoleFunctionList = new ArrayList(); + + EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction(); + epAppRoleFunction.setRoleId((long)1); + epAppRoleFunction.setAppId((long)1); + epAppRoleFunction.setCode("test"); + + epAppRoleFunctionList.add(epAppRoleFunction); + + ExternalRoleDetails externalRoleDetails = mockExternalRoleDetails(); + + assertEquals(externalRoleDetails.getAppId(), new Long(1)); + assertEquals(externalRoleDetails.getAppRoleId(), new Long(1)); + assertEquals(externalRoleDetails.getPriority().toString(), "1"); + assertEquals(externalRoleDetails.getName(), "test"); + assertEquals(externalRoleDetails.getPriority().toString(), "1"); + assertEquals(externalRoleDetails.getPerms().size(), epAppRoleFunctionList.size()); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalSystemAccessTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalSystemAccessTest.java new file mode 100644 index 00000000..e818e762 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalSystemAccessTest.java @@ -0,0 +1,64 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.ExternalSystemAccess; + +public class ExternalSystemAccessTest { + + public ExternalSystemAccess mockExternalSystemAccess(){ + ExternalSystemAccess externalSystemAccess = new ExternalSystemAccess("test", false); + + externalSystemAccess.setKey("test"); + externalSystemAccess.setAccessValue(false); + + return externalSystemAccess; + } + + @Test + public void externalSystemAccessTest(){ + ExternalSystemAccess externalSystemAccess = mockExternalSystemAccess(); + + assertEquals(externalSystemAccess.getKey(), "test"); + assertEquals(externalSystemAccess.getAccessValue(), false); + } +} + diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalSystemRoleApprovalTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalSystemRoleApprovalTest.java new file mode 100644 index 00000000..ace2dd83 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ExternalSystemRoleApprovalTest.java @@ -0,0 +1,60 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.externalsystemapproval.model.ExternalSystemRoleApproval; + +public class ExternalSystemRoleApprovalTest { + + public ExternalSystemRoleApproval mockExternalSystemRoleApproval(){ + ExternalSystemRoleApproval externalSystemRoleApproval = new ExternalSystemRoleApproval(); + externalSystemRoleApproval.setRoleName("test"); + + return externalSystemRoleApproval; + } + + @Test + public void externalSystemRoleApprovalTest(){ + ExternalSystemRoleApproval externalSystemRoleApproval = mockExternalSystemRoleApproval(); + + assertEquals(externalSystemRoleApproval.getRoleName(), "test"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/FunctionalMenuItemWithAppIDTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/FunctionalMenuItemWithAppIDTest.java new file mode 100644 index 00000000..488bbd92 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/FunctionalMenuItemWithAppIDTest.java @@ -0,0 +1,65 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.FunctionalMenuItemWithAppID; + +public class FunctionalMenuItemWithAppIDTest { + + public FunctionalMenuItemWithAppID mockFunctionalMenuItemWithAppID(){ + FunctionalMenuItemWithAppID functionalMenuItemWithAppID = new FunctionalMenuItemWithAppID(); + + functionalMenuItemWithAppID.setRestrictedApp(false); + functionalMenuItemWithAppID.setUrl("test"); + + + return functionalMenuItemWithAppID; + } + + @Test + public void functionalMenuItemWithAppIDTest(){ + FunctionalMenuItemWithAppID functionalMenuItemWithAppID = mockFunctionalMenuItemWithAppID(); + + assertEquals(functionalMenuItemWithAppID.toString(), "FunctionalMenuItem [menuId=null, column=null, text=null, parentMenuId=null, url=test, active_yn=null, appid=null, roles=null, restrictedApp=false]"); + + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/GetAccessResultIdTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/GetAccessResultIdTest.java new file mode 100644 index 00000000..5a05949f --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/GetAccessResultIdTest.java @@ -0,0 +1,66 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.GetAccessResultId; + +public class GetAccessResultIdTest { + + public GetAccessResultId mockGetAccessResultId(){ + + GetAccessResultId getAccessResultIdObj = new GetAccessResultId(); + getAccessResultIdObj.setEcompFunction("test"); + getAccessResultIdObj.setAppName("test"); + getAccessResultIdObj.setRoleName("test"); + + return getAccessResultIdObj; + } + + @Test + public void getAccessResultIdObjTest(){ + GetAccessResultId getAccessResultIdObj = mockGetAccessResultId(); + + assertEquals(getAccessResultIdObj.getEcompFunction(), "test"); + assertEquals(getAccessResultIdObj.getAppName(), "test"); + assertEquals(getAccessResultIdObj.getRoleName(), "test"); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/MicroserviceDataTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/MicroserviceDataTest.java new file mode 100644 index 00000000..8f856391 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/MicroserviceDataTest.java @@ -0,0 +1,94 @@ +/*- + * ============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.domain; + +import java.util.ArrayList; +import java.util.List; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.MicroserviceData; +import org.onap.portalapp.portal.domain.MicroserviceParameter; + +public class MicroserviceDataTest { + + public MicroserviceData mockMicroserviceData(){ + + MicroserviceData microserviceData= new MicroserviceData(); + + List parameterList = new ArrayList(); + + MicroserviceParameter microserviceParameter = new MicroserviceParameter(); + microserviceParameter.setId((long)1); + microserviceParameter.setServiceId((long)1); + microserviceParameter.setPara_key("test"); + microserviceParameter.setPara_value("test"); + parameterList.add(microserviceParameter); + + microserviceData.setId((long)1); + microserviceData.setName("test"); + microserviceData.setActive("test"); + microserviceData.setDesc("test"); + microserviceData.setAppId((long)1); + microserviceData.setUrl("test"); + microserviceData.setSecurityType("test"); + microserviceData.setUsername("test"); + microserviceData.setPassword("test"); + + + return microserviceData; + } + + @Test + public void microserviceDataTest(){ + MicroserviceData microserviceData= mockMicroserviceData(); + + assertEquals(microserviceData.getId(), new Long(1)); + assertEquals(microserviceData.getName(), "test"); + assertEquals(microserviceData.getActive(), "test"); + assertEquals(microserviceData.getDesc(), "test"); + // assertEquals(microserviceData.getAppId(), new long(1)); + assertEquals(microserviceData.getUrl(), "test"); + assertEquals(microserviceData.getSecurityType(), "test"); + assertEquals(microserviceData.getUsername(), "test"); + assertEquals(microserviceData.getPassword(), "test"); + + assertEquals(microserviceData.toString(), "MicroserviceData [id=1, name=test, desc=test, appId=1, " + + "url=test, securityType=test, username=test, password=test, parameterList=null]"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/MicroserviceParameterTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/MicroserviceParameterTest.java new file mode 100644 index 00000000..a214738f --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/MicroserviceParameterTest.java @@ -0,0 +1,68 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.MicroserviceParameter; + +public class MicroserviceParameterTest { + + public MicroserviceParameter mockMicroserviceParameter(){ + MicroserviceParameter microserviceParameter = new MicroserviceParameter(); + + microserviceParameter.setId((long)1); + microserviceParameter.setServiceId((long)1); + microserviceParameter.setPara_key("test"); + microserviceParameter.setPara_value("test"); + + return microserviceParameter; + } + + @Test + public void microserviceParameterTest(){ + MicroserviceParameter microserviceParameter = mockMicroserviceParameter(); + assertEquals(microserviceParameter.getId(), new Long(1)); + assertEquals(microserviceParameter.getServiceId(),(long)1); + assertEquals(microserviceParameter.getPara_key(), "test"); + assertEquals(microserviceParameter.getPara_value(), "test"); + + assertEquals(microserviceParameter.toString(), "MicroserviceParameter [id=1, serviceId=1, para_key=test, para_value=test]"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/PersUserAppSelectionTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/PersUserAppSelectionTest.java new file mode 100644 index 00000000..dd397b4d --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/PersUserAppSelectionTest.java @@ -0,0 +1,72 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.PersUserAppSelection; + +public class PersUserAppSelectionTest { + + public PersUserAppSelection mockPersUserAppSelection(){ + + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setUserId((long)1); + persUserAppSelection.setAppId((long)1); + persUserAppSelection.setStatusCode("test"); + + return persUserAppSelection; + } + + @Test + public void persUserAppSelectionTest(){ + + PersUserAppSelection persUserAppSelection1 = new PersUserAppSelection((long)1, (long)1, (long)1,"test"); + + PersUserAppSelection persUserAppSelection = mockPersUserAppSelection(); + + assertEquals(persUserAppSelection.getUserId(), new Long(1)); + assertEquals(persUserAppSelection.getAppId(), new Long(1)); + assertEquals(persUserAppSelection.getStatusCode(), "test"); + assertEquals(persUserAppSelection1.hashCode(), new PersUserAppSelection((long)1, (long)1, (long)1,"test").hashCode()); + assertEquals(persUserAppSelection1, new PersUserAppSelection((long)1, (long)1, (long)1,"test")); + assertTrue(persUserAppSelection1.equals(new PersUserAppSelection((long)1, (long)1, (long)1,"test"))); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/PersUserWidgetSelectionTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/PersUserWidgetSelectionTest.java new file mode 100644 index 00000000..0b787152 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/PersUserWidgetSelectionTest.java @@ -0,0 +1,73 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.PersUserWidgetSelection; + +public class PersUserWidgetSelectionTest { + + public PersUserWidgetSelection mockPersUserWidgetSelection(){ + + PersUserWidgetSelection persUserWidgetSelection = new PersUserWidgetSelection(); + + persUserWidgetSelection.setUserId((long)1); + persUserWidgetSelection.setWidgetId((long)1); + persUserWidgetSelection.setStatusCode("test"); + + return persUserWidgetSelection; + } + + @Test + public void persUserWidgetSelectionTest(){ + PersUserWidgetSelection persUserWidgetSelection = mockPersUserWidgetSelection(); + + PersUserWidgetSelection persUserWidgetSelection1 = new PersUserWidgetSelection((long)1, (long)1, (long)1, "test"); + + assertEquals(persUserWidgetSelection.getUserId(), new Long(1)); + assertEquals(persUserWidgetSelection.getWidgetId(), new Long(1)); + assertEquals(persUserWidgetSelection.getStatusCode(), "test"); + assertEquals(persUserWidgetSelection1, new PersUserWidgetSelection((long)1, (long)1, (long)1, "test")); + assertTrue(persUserWidgetSelection1.equals(new PersUserWidgetSelection((long)1, (long)1, (long)1,"test"))); + assertEquals(persUserWidgetSelection.hashCode(), persUserWidgetSelection1.hashCode()); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ResultTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ResultTest.java new file mode 100644 index 00000000..3cdfeeef --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/ResultTest.java @@ -0,0 +1,66 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.model.Result; + +public class ResultTest { + + public Result mockResult(){ + + Result result= new Result("test"); + + result.setResult("test"); + return result; + } + + @Test + public void resultTest(){ + + Result result = mockResult(); + result.setResult("test"); + + assertEquals(result.getResult(), "test"); + + } + + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/SharedContextTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/SharedContextTest.java new file mode 100644 index 00000000..4c7b464e --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/SharedContextTest.java @@ -0,0 +1,73 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.SharedContext; + +public class SharedContextTest { + + public SharedContext mockSharedContext(){ + + SharedContext sharedContext = new SharedContext(); + sharedContext.setId((long)1); + sharedContext.setCreate_time(new Date()); + sharedContext.setContext_id("test"); + sharedContext.setCkey("test"); + sharedContext.setCvalue("test"); + + return sharedContext; + } + + @Test + public void sharedContextTest(){ + SharedContext sharedContext = mockSharedContext(); + + assertEquals(sharedContext.getId(), new Long(1)); + // assertEquals(sharedContext.getCreate_time(), new Date()); + assertEquals(sharedContext.getContext_id(), "test"); + assertEquals(sharedContext.getCkey(), "test"); + assertEquals(sharedContext.getCvalue(), "test"); + + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/UserIdRoleIdTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/UserIdRoleIdTest.java new file mode 100644 index 00000000..d391288d --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/UserIdRoleIdTest.java @@ -0,0 +1,66 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.UserIdRoleId; + +public class UserIdRoleIdTest { + + public UserIdRoleId mockUserIdRoleId(){ + UserIdRoleId userIdRoleId = new UserIdRoleId(); + userIdRoleId.setUser_Id("test"); + userIdRoleId.setRoleId("test"); + userIdRoleId.setOrgUserId("test"); + userIdRoleId.setAppId("test"); + + return userIdRoleId; + } + + @Test + public void userIdRoleIdTest(){ + UserIdRoleId userIdRoleId = mockUserIdRoleId(); + + assertEquals(userIdRoleId.getUser_Id(), "test"); + assertEquals(userIdRoleId.getRoleId(), "test"); + assertEquals(userIdRoleId.getOrgUserId(), "test"); + assertEquals(userIdRoleId.getAppId(), "test"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetCatalogParameterTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetCatalogParameterTest.java new file mode 100644 index 00000000..31d484d2 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetCatalogParameterTest.java @@ -0,0 +1,70 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.WidgetCatalogParameter; + +public class WidgetCatalogParameterTest { + + public WidgetCatalogParameter mockWidgetCatalogParameter(){ + WidgetCatalogParameter widgetCatalogParameter = new WidgetCatalogParameter(); + + widgetCatalogParameter.setId((long)1); + widgetCatalogParameter.setWidgetId((long)1); + widgetCatalogParameter.setUserId((long)1); + widgetCatalogParameter.setParamId((long)1); + widgetCatalogParameter.setUser_value("test"); + + return widgetCatalogParameter; + } + + @Test + public void widgetCatalogParameterTest(){ + WidgetCatalogParameter widgetCatalogParameter = mockWidgetCatalogParameter(); + + assertEquals(widgetCatalogParameter.getId(), new Long(1)); + assertEquals(widgetCatalogParameter.getWidgetId(), new Long(1)); + assertEquals(widgetCatalogParameter.getUserId(), new Long(1)); + assertEquals(widgetCatalogParameter.getParamId(), new Long(1)); + assertEquals(widgetCatalogParameter.getUser_value(), "test"); + assertEquals(widgetCatalogParameter.toString(), "WidgetCatalogParameter [id=1, widgetId=1, userId=1, paramId=1, user_value=test]"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetCatalogTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetCatalogTest.java new file mode 100644 index 00000000..ce90e49b --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetCatalogTest.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.domain; + +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.App; +import org.onap.portalapp.portal.domain.RoleApp; +import org.onap.portalapp.portal.domain.WidgetCatalog; + +public class WidgetCatalogTest { + + public WidgetCatalog mockWidgetCatalog() { + + WidgetCatalog widgetCatalog = new WidgetCatalog(); + + Set roleAppSet = new HashSet(); + // App + App app = new App(); + app.setAppId((long) 1); + app.setAppName("test"); + + // RoleApp + RoleApp roleApp = new RoleApp(); + roleApp.setRoleId((long) 1); + roleApp.setRoleName("test"); + roleApp.setApp(app); + roleApp.setWidgets(null); + + roleAppSet.add(roleApp); + + widgetCatalog.setId((long) 1); + widgetCatalog.setName("test"); + widgetCatalog.setDesc("test"); + widgetCatalog.setFileLocation("test"); + widgetCatalog.setAllowAllUser("test"); + widgetCatalog.setServiceId((long) 1); + widgetCatalog.setSortOrder("test"); + widgetCatalog.setStatusCode("test"); + + widgetCatalog.setWidgetRoles(roleAppSet); + + return widgetCatalog; + + } + + @Test + public void widgetCatalogTest() { + + // App + App app = new App(); + app.setAppId((long) 1); + app.setAppName("test"); + + Set roleAppSet = new HashSet(); + // RoleApp + RoleApp roleApp = new RoleApp(); + roleApp.setRoleId((long) 1); + roleApp.setRoleName("test"); + roleApp.setApp(app); + roleApp.setWidgets(null); + + roleAppSet.add(roleApp); + + WidgetCatalog widgetCatalog = mockWidgetCatalog(); + + + assertEquals(widgetCatalog.getId(), (long)1); + assertEquals(widgetCatalog.getName(), "test"); + assertEquals(widgetCatalog.getDesc(), "test"); + assertEquals(widgetCatalog.getFileLocation(), "test"); + assertEquals(widgetCatalog.getAllowAllUser(), "test"); + assertEquals(widgetCatalog.getServiceId(), new Long (1)); + assertEquals(widgetCatalog.getSortOrder(), "test"); + assertEquals(widgetCatalog.getStatusCode(), "test"); + assertEquals(widgetCatalog.getWidgetRoles().size(),1); + + assertEquals("WidgetCatalog [id=1, name=test, desc=test, fileLocation=test, allowAllUser=test]", widgetCatalog.toString()); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetParameterResultTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetParameterResultTest.java new file mode 100644 index 00000000..354255bd --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetParameterResultTest.java @@ -0,0 +1,70 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.WidgetParameterResult; + +public class WidgetParameterResultTest { + + public WidgetParameterResult mockWidgetParameterResult(){ + + WidgetParameterResult widgetParameterResult = new WidgetParameterResult(); + widgetParameterResult.setParam_id((long)1); + widgetParameterResult.setParam_key("test"); + widgetParameterResult.setUser_value("test"); + widgetParameterResult.setDefault_value("test"); + + return widgetParameterResult; + } + + @Test + public void widgetParameterResultTest(){ + + WidgetParameterResult widgetParameterResult = mockWidgetParameterResult(); + + assertEquals(widgetParameterResult.getParam_key(), "test"); + assertEquals(widgetParameterResult.getParam_id(), new Long(1)); + assertEquals(widgetParameterResult.getUser_value(), "test"); + assertEquals(widgetParameterResult.getDefault_value(), "test"); + + assertEquals("WidgetParameterResult [param_id=1, param_key=test, user_value=test, default_value=test]", widgetParameterResult.toString()); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetTest.java new file mode 100644 index 00000000..3821c9cc --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/WidgetTest.java @@ -0,0 +1,71 @@ +/*- + * ============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.domain; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.domain.Widget; + +public class WidgetTest { + + public Widget mockWidget(){ + + Widget widget = new Widget(); + widget.setName("test"); + widget.setWidth(100); + widget.setHeight(100); + widget.setUrl("test"); + widget.setAppId((long)1); + + return widget; + } + + @Test + public void widgetTest(){ + Widget widget = mockWidget(); + + assertEquals(widget.getName(), "test"); + assertTrue(widget.getWidth() == 100); + assertTrue(widget.getHeight() == 100); + assertEquals(widget.getUrl(), "test"); + assertEquals(widget.getAppId(), new Long(1)); + + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/exceptions/NoHealthyServiceExceptionTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/exceptions/NoHealthyServiceExceptionTest.java new file mode 100644 index 00000000..62c75cfe --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/exceptions/NoHealthyServiceExceptionTest.java @@ -0,0 +1,60 @@ +/*- + * ============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.exceptions; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.exceptions.NoHealthyServiceException; + +public class NoHealthyServiceExceptionTest { + + public NoHealthyServiceException mockNoHealthyServiceException(){ + NoHealthyServiceException noHealthyServiceException = new NoHealthyServiceException("test"); + + return noHealthyServiceException; + } + + @Test + public void noHealthyServiceExceptionTest(){ + NoHealthyServiceException noHealthyServiceException = mockNoHealthyServiceException(); + + // assertEquals(noHealthyServiceException, new NoHealthyServiceException("test")); + assertEquals(noHealthyServiceException.toString(), "NoHealthyServiceException [] test"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/ApplicationCommonContextTestSuite.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/ApplicationCommonContextTestSuite.java new file mode 100644 index 00000000..764cebab --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/ApplicationCommonContextTestSuite.java @@ -0,0 +1,191 @@ +package org.onap.portalapp.portal.framework; +/*- + * ============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.openecomp.portalapp.portal.framework; +// +//import java.io.IOException; +// +//import org.junit.Before; +//import org.junit.runner.RunWith; +//import org.openecomp.portalsdk.core.conf.AppConfig; +////import org.openecomp.portalapp.conf.ExternalAppConfig; +////import org.openecomp.portalapp.conf.HibernateMappingLocations; +//import org.openecomp.portalsdk.core.conf.HibernateConfiguration; +//import org.openecomp.portalsdk.core.conf.HibernateMappingLocatable; +//import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager; +//import org.openecomp.portalsdk.core.util.CacheManager; +//import org.openecomp.portalsdk.core.util.SystemProperties; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.ComponentScan; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.context.annotation.FilterType; +//import org.springframework.context.annotation.Profile; +//import org.springframework.core.io.ClassPathResource; +//import org.springframework.core.io.Resource; +//import org.springframework.test.context.ActiveProfiles; +//import org.springframework.test.context.ContextConfiguration; +//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +//import org.springframework.test.context.web.AnnotationConfigWebContextLoader; +//import org.springframework.test.context.web.WebAppConfiguration; +//import org.springframework.test.web.servlet.MockMvc; +//import org.springframework.test.web.servlet.setup.MockMvcBuilders; +//import org.springframework.web.context.WebApplicationContext; +//import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +// +///** +// * +// * In order to write a unit test, 1. inherit this class 2. place the "war" +// * folder on your test class's classpath 3. run the test with the following VM +// * argument; This is important because when starting the application from +// * Container, the System Properties file (SystemProperties.java) can have the +// * direct path but, when running from the Mock Junit container, the path should +// * be prefixed with "classpath" to enable the mock container to search for the +// * file in the classpath -Dcontainer.classpath="classpath:" +// */ +// +//@SuppressWarnings("deprecation") +//@RunWith(SpringJUnit4ClassRunner.class) +//@WebAppConfiguration +//@ContextConfiguration(loader = AnnotationConfigWebContextLoader.class, classes = { MockAppConfig.class }) +//@ActiveProfiles(value = "test") +//public class ApplicationCommonContextTestSuite { +// +// @Autowired +// public WebApplicationContext wac; +// +// private MockMvc mockMvc; +// +// @Before +// public void setup() { +// if (mockMvc == null) { +// this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); +// +// } +// } +// +// public Object getBean(String name) { +// return this.wac.getBean(name); +// } +// +// public MockMvc getMockMvc() { +// return mockMvc; +// } +// +// public void setMockMvc(MockMvc mockMvc) { +// this.mockMvc = mockMvc; +// } +// +// public WebApplicationContext getWebApplicationContext() { +// return wac; +// } +// +//} +// +//@Configuration +//@ComponentScan(basePackages = "org.openecomp", excludeFilters = { +// // the following source configurations should not be scanned; instead of +// // using Exclusion filter, we can use the @Profile annotation to exclude +// // them +// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalsdk.core.controller.LogoutController*"), +// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalsdk.core.controller.SDKLoginController*"), +// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalapp.conf.ExternalAppConfig*"), +// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.*.*InitUebHandler*") }) +//@Profile("test") +//class MockAppConfig extends AppConfig { +// +// @Bean +// HibernateMappingLocatable locatable() { +// return new MockHibernateMappingLocations(); +// } +// +// @Bean +// HibernateConfiguration hibConfiguration() { +// return new HibernateConfiguration(); +// } +// +// @Bean +// public SystemProperties systemProperties() { +// return new MockSystemProperties(); +// } +// +// @Bean +// public AbstractCacheManager cacheManager() { +// return new CacheManager() { +// +// public void configure() throws IOException { +// +// } +// }; +// } +// +// public String[] tileDefinitions() { +// return new String[] { "classpath:/WEB-INF/fusion/defs/definitions.xml", +// "classpath:/WEB-INF/defs/definitions.xml" }; +// } +// +// public void addInterceptors(InterceptorRegistry registry) { +// // registry.addInterceptor(new +// // SessionTimeoutInterceptor()).excludePathPatterns(getExcludeUrlPathsForSessionTimeout()); +// // registry.addInterceptor(resourceInterceptor()); +// } +// +// public static class MockSystemProperties extends SystemProperties { +// +// public MockSystemProperties() { +// } +// +// } +// +//} +// +//@Profile("test") +//class MockHibernateMappingLocations implements HibernateMappingLocatable { +// +// public Resource[] getMappingLocations() { +// return new Resource[] { new ClassPathResource("WEB-INF/fusion/orm/Fusion.hbm.xml"), +// new ClassPathResource("WEB-INF/fusion/orm/EP.hbm.xml"), +// new ClassPathResource("WEB-INF/fusion/orm/Workflow.hbm.xml") }; +// +// } +// +// public String[] getPackagesToScan() { +// return new String[] { "org.openecomp", "src" }; +// } +// +//} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/MockitoTestSuite.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/MockitoTestSuite.java new file mode 100644 index 00000000..84356f74 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/MockitoTestSuite.java @@ -0,0 +1,94 @@ +/*- + * ============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-common/src/test/java/org/onap/portalapp/portal/listener/HealthMonitorTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/listener/HealthMonitorTest.java new file mode 100644 index 00000000..929c8e36 --- /dev/null +++ b/ecomp-portal-BE-common/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-common/src/test/java/org/onap/portalapp/portal/model/AppCatalogItemTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCatalogItemTest.java new file mode 100644 index 00000000..819262d1 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCatalogItemTest.java @@ -0,0 +1,72 @@ +/*- + * ============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.model; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.ecomp.model.AppCatalogItem; + +public class AppCatalogItemTest { + + public AppCatalogItem mockAppCatalogItem(){ + AppCatalogItem appCatalogItem = new AppCatalogItem(); + + appCatalogItem.setAlternateUrl("test"); + appCatalogItem.setMlAppName("test"); + + return appCatalogItem; + } + + @Test + public void appCatalogItemTest(){ + AppCatalogItem appCatalogItem = mockAppCatalogItem(); + + AppCatalogItem appCatalogItem1 = new AppCatalogItem(); + appCatalogItem1.setAlternateUrl("test"); + appCatalogItem1.setMlAppName("test"); + + assertEquals(appCatalogItem.getAlternateUrl(), appCatalogItem1.getAlternateUrl()); + assertEquals(appCatalogItem.getMlAppName(), appCatalogItem1.getMlAppName()); + + assertEquals(appCatalogItem.toString(), "AppCatalogItem [id=null, name=null, access=null, select=null, pending=null]"); + assertEquals(appCatalogItem.hashCode(), appCatalogItem1.hashCode()); + assertTrue(appCatalogItem.equals(appCatalogItem1)); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCategoryFunctionsItemTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCategoryFunctionsItemTest.java new file mode 100644 index 00000000..346b427e --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppCategoryFunctionsItemTest.java @@ -0,0 +1,79 @@ +/*- + * ============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.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.portalapp.portal.ecomp.model.AppCategoryFunctionsItem; + +public class AppCategoryFunctionsItemTest { + + public AppCategoryFunctionsItem mockAppCategoryFunctionsItem(){ + AppCategoryFunctionsItem appCategoryFunctionsItem = new AppCategoryFunctionsItem(); + + appCategoryFunctionsItem.setRowId("test"); + appCategoryFunctionsItem.setAppId("test"); + appCategoryFunctionsItem.setApplication("test"); + appCategoryFunctionsItem.setFunctions("test"); + + return appCategoryFunctionsItem; + } + + @Test + public void appCategoryFunctionsItemTest(){ + AppCategoryFunctionsItem appCategoryFunctionsItem = mockAppCategoryFunctionsItem(); + + AppCategoryFunctionsItem appCategoryFunctionsItem1 = new AppCategoryFunctionsItem(); + + appCategoryFunctionsItem1.setRowId("test"); + appCategoryFunctionsItem1.setAppId("test"); + appCategoryFunctionsItem1.setApplication("test"); + appCategoryFunctionsItem1.setFunctions("test"); + + assertEquals(appCategoryFunctionsItem.getRowId(), appCategoryFunctionsItem1.getRowId()); + assertEquals(appCategoryFunctionsItem.getAppId(), appCategoryFunctionsItem1.getAppId()); + assertEquals(appCategoryFunctionsItem.getApplication(), appCategoryFunctionsItem1.getApplication()); + assertEquals(appCategoryFunctionsItem.getFunctions(), appCategoryFunctionsItem1.getFunctions()); + assertEquals(appCategoryFunctionsItem.toString(), "AppCategoryFunctionsItem [rowId=test, appId=test, application=test, category=null, functions=test]"); + assertEquals(appCategoryFunctionsItem.hashCode(), appCategoryFunctionsItem1.hashCode()); + assertTrue(appCategoryFunctionsItem.equals(appCategoryFunctionsItem1)); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppContactUsItemTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppContactUsItemTest.java new file mode 100644 index 00000000..898bd986 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/AppContactUsItemTest.java @@ -0,0 +1,86 @@ +/*- + * ============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.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.portalapp.portal.ecomp.model.AppContactUsItem; + +public class AppContactUsItemTest { + + public AppContactUsItem mockAppContactUsItem(){ + AppContactUsItem appContactUsItem = new AppContactUsItem(); + + appContactUsItem.setAppId((long)1); + appContactUsItem.setAppName("test"); + appContactUsItem.setDescription("test"); + appContactUsItem.setContactName("test"); + appContactUsItem.setContactEmail("test"); + appContactUsItem.setUrl("test"); + appContactUsItem.setActiveYN("test"); + + return appContactUsItem; + } + + @Test + public void appContactUsItemTest(){ + AppContactUsItem appContactUsItem = mockAppContactUsItem(); + + AppContactUsItem appContactUsItem1 = new AppContactUsItem(); + appContactUsItem1.setAppId((long)1); + appContactUsItem1.setAppName("test"); + appContactUsItem1.setDescription("test"); + appContactUsItem1.setContactName("test"); + appContactUsItem1.setContactEmail("test"); + appContactUsItem1.setUrl("test"); + appContactUsItem1.setActiveYN("test"); + + assertEquals(appContactUsItem.getAppId(), appContactUsItem1.getAppId()); + assertEquals(appContactUsItem.getAppName(), appContactUsItem1.getAppName()); + assertEquals(appContactUsItem.getDescription(), appContactUsItem1.getDescription()); + assertEquals(appContactUsItem.getContactName(), appContactUsItem1.getContactName()); + assertEquals(appContactUsItem.getContactEmail(), appContactUsItem1.getContactEmail()); + assertEquals(appContactUsItem.getUrl(), appContactUsItem1.getUrl()); + assertEquals(appContactUsItem.getActiveYN(), appContactUsItem1.getActiveYN()); + assertEquals(appContactUsItem.toString(), "AppContactUsItem [appId=1, appName=test, description=test, contactName=test, contactEmail=test, url=test, activeYN=test]"); + assertEquals(appContactUsItem.hashCode(), appContactUsItem1.hashCode()); + assertTrue(appContactUsItem.equals(appContactUsItem1)); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/SearchResultItemTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/SearchResultItemTest.java new file mode 100644 index 00000000..fac3ecf6 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/model/SearchResultItemTest.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.portal.model; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.ecomp.model.SearchResultItem; + +public class SearchResultItemTest { + + public SearchResultItem mockSearchResultItem(){ + SearchResultItem searchResultItem = new SearchResultItem(); + + searchResultItem.setRowId("test"); + searchResultItem.setCategory("test"); + searchResultItem.setName("test"); + searchResultItem.setTarget("test"); + searchResultItem.setUuid("test"); + + return searchResultItem; + } + + @Test + public void searchResultItemTest(){ + SearchResultItem searchResultItem = mockSearchResultItem(); + + SearchResultItem searchResultItem1 = new SearchResultItem(); + searchResultItem1.setRowId("test"); + searchResultItem1.setCategory("test"); + searchResultItem1.setName("test"); + searchResultItem1.setTarget("test"); + searchResultItem1.setUuid("test"); + + assertEquals(searchResultItem.getRowId(), searchResultItem.getRowId()); + assertEquals(searchResultItem.getCategory(), searchResultItem.getCategory()); + assertEquals(searchResultItem.getName(), searchResultItem.getName()); + assertEquals(searchResultItem.getTarget(), searchResultItem.getTarget()); + assertEquals(searchResultItem.getUuid(), searchResultItem.getUuid()); + assertEquals(searchResultItem.toString(), searchResultItem.toString()); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AppContactUsServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AppContactUsServiceImplTest.java new file mode 100644 index 00000000..aaadbe03 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AppContactUsServiceImplTest.java @@ -0,0 +1,184 @@ +/*- + * ============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.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +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.domain.AppContactUs; +import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.ecomp.model.AppCategoryFunctionsItem; +import org.onap.portalapp.portal.ecomp.model.AppContactUsItem; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.AppContactUsService; +import org.onap.portalapp.portal.service.AppContactUsServiceImpl; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.DataAccessServiceImpl; + +public class AppContactUsServiceImplTest { + + + @Mock + DataAccessService dataAccessService = new DataAccessServiceImpl(); + + @Mock + AppContactUsService AppContactUsService = new AppContactUsServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + AppContactUsServiceImpl appContactUsServiceImpl = new AppContactUsServiceImpl(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + + public EPApp getApp() { + EPApp app = new EPApp(); + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(true); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + return app; + } + @Test + public void getAppContactUsTest() throws Exception + { + + List contactUsItemList = new ArrayList<>(); + AppContactUsItem appContactUsItem= new AppContactUsItem(); + appContactUsItem.setAppName("testNew"); + contactUsItemList.add(appContactUsItem); + AppContactUsItem appContactUsItem1= new AppContactUsItem(); + appContactUsItem1.setAppName("test"); + contactUsItemList.add(appContactUsItem1); + Mockito.when(dataAccessService.executeNamedQuery("getAppContactUsItems", null, null)).thenReturn(contactUsItemList); + List expectedcontactUsItemList = appContactUsServiceImpl.getAppContactUs(); + assertEquals(expectedcontactUsItemList, contactUsItemList); + } + + @Test + public void getAppsAndContactsTest() throws Exception + { + List contactUsItemList = new ArrayList<>(); + AppContactUsItem appContactUsItem= new AppContactUsItem(); + appContactUsItem.setAppName("testNew"); + contactUsItemList.add(appContactUsItem); + AppContactUsItem appContactUsItem1= new AppContactUsItem(); + appContactUsItem1.setAppName("test"); + contactUsItemList.add(appContactUsItem1); + Mockito.when(dataAccessService.executeNamedQuery("getAppsAndContacts", null, null)).thenReturn(contactUsItemList); + List expectedcontactUsItemList = appContactUsServiceImpl.getAppsAndContacts(); + assertEquals(expectedcontactUsItemList, contactUsItemList); + } + + @Test + public void getAppCategoryFunctionsTest() throws Exception + { + List list = new ArrayList<>(); + Mockito.when(dataAccessService.executeNamedQuery("getAppCategoryFunctions", null, null)).thenReturn(list); + List expectedlist = appContactUsServiceImpl.getAppCategoryFunctions(); + assertEquals(list, expectedlist); + } + + @Test(expected = java.lang.Exception.class) + public void saveAppContactUsTest() throws Exception + { + HashMap map = new HashMap(); + List contactUsModelList = new ArrayList<>(); + AppContactUsItem appContactUsItem= new AppContactUsItem(); + appContactUsItem.setAppId((long) 1); + contactUsModelList.add(appContactUsItem); + AppContactUs appContact = new AppContactUs(); + Mockito.when(dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(appContact); + EPApp app = getApp(); + Mockito.when(dataAccessService.getDomainObject(EPApp.class, 1, new HashMap())).thenReturn(app); + AppContactUs contactUs = new AppContactUs(); + contactUs.setApp(app); + contactUs.setDescription(appContactUsItem.getDescription()); + contactUs.setContactName(appContactUsItem.getContactName()); + contactUs.setContactEmail(appContactUsItem.getContactEmail()); + contactUs.setActiveYN(appContactUsItem.getActiveYN()); + contactUs.setUrl(appContactUsItem.getUrl()); + Mockito.doNothing().when(dataAccessService).saveDomainObject(contactUs,map); + appContactUsServiceImpl.saveAppContactUs(contactUsModelList); + } + + @Test(expected = java.lang.NullPointerException.class) + public void deleteContactUsTest() throws Exception + { + HashMap map = new HashMap(); + AppContactUs contactUs = new AppContactUs(); + Mockito.when((AppContactUs) dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(contactUs); + appContactUsServiceImpl.deleteContactUs((long) 1); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/DashboardSearchServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/DashboardSearchServiceImplTest.java new file mode 100644 index 00000000..13f04ae2 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/DashboardSearchServiceImplTest.java @@ -0,0 +1,151 @@ +/*- + * ============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.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +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.core.MockEPUser; +import org.onap.portalapp.portal.ecomp.model.SearchResultItem; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.DashboardSearchServiceImpl; +import org.onap.portalapp.portal.transport.CommonWidget; +import org.onap.portalapp.portal.transport.CommonWidgetMeta; +import org.onap.portalsdk.core.service.DataAccessService; + +public class DashboardSearchServiceImplTest { + + @Mock + DataAccessService dataAccessService; + + @InjectMocks + DashboardSearchServiceImpl dashboardSearchServiceImpl = new DashboardSearchServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + NullPointerException nullPointerException = new NullPointerException(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + MockEPUser mockUser = new MockEPUser(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test + public void searchResultsTest() + { + Map params = new HashMap<>(); + params.put("userId", "guestT"); + params.put("searchQuery", "test"); + + List list = new ArrayList<>(); + SearchResultItem searchResultItem= new SearchResultItem(); + searchResultItem.setCategory("test"); + list.add(searchResultItem); + Mockito.when(dataAccessService.executeNamedQuery("searchPortal", params, null)).thenReturn(list); + Map> result = dashboardSearchServiceImpl.searchResults("guestT", "test"); + assertTrue(result.keySet().contains("test")); + } + + @Test + public void getRelatedUsersTest() + { + List activeUsers = new ArrayList<>(); + Map params = new HashMap<>(); + params.put("userId", "guestT"); + Mockito.when(dataAccessService.executeNamedQuery("relatedUsers", params, null)).thenReturn(activeUsers); + List expectedActiveUsers = dashboardSearchServiceImpl.getRelatedUsers("guestT"); + assertEquals(expectedActiveUsers,activeUsers); + } + @Test + public void getWidgetDataTest() + { + CommonWidgetMeta CommonWidgetMeta = null; + Map params = new HashMap<>(); + params.put("cat", "test"); + @SuppressWarnings("unchecked") + List widgetItems = new ArrayList<>(); + CommonWidget commonWidget = new CommonWidget(); + widgetItems.add(commonWidget); + Mockito.when(dataAccessService.executeNamedQuery("getCommonWidgetItem", params, null)).thenReturn(widgetItems); + CommonWidgetMeta expectedCommonWidgetMeta =dashboardSearchServiceImpl.getWidgetData("test"); + assertEquals(expectedCommonWidgetMeta.getCategory(), "test"); + } + + @Test + public void saveWidgetDataBulkTest() + { + CommonWidgetMeta CommonWidgetMeta = new CommonWidgetMeta(); + List widgetList = new ArrayList<>(); + CommonWidget commonWidget = new CommonWidget(); + widgetList.add(commonWidget); + CommonWidgetMeta.setItems(widgetList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(commonWidget, null); + assertEquals(dashboardSearchServiceImpl.saveWidgetDataBulk(CommonWidgetMeta), "success"); + } + + @Test + public void saveWidgetDataTest() + { + CommonWidget commonWidget = new CommonWidget(); + Mockito.doNothing().when(dataAccessService).saveDomainObject(commonWidget, null); + assertEquals(dashboardSearchServiceImpl.saveWidgetData(commonWidget), "success"); + } + + @Test + public void deleteWidgetDataTest() + { + CommonWidget commonWidget = new CommonWidget(); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(commonWidget, null); + assertEquals(dashboardSearchServiceImpl.deleteWidgetData(commonWidget), "success"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImplTest.java new file mode 100644 index 00000000..345ae3b7 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceCentralizedImplTest.java @@ -0,0 +1,130 @@ +/*- + * ============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.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.apache.commons.codec.DecoderException; +import org.hibernate.SessionFactory; +import org.junit.Before; +import org.junit.Ignore; +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.core.MockEPUser; +import org.onap.portalapp.portal.domain.CentralV2RoleFunction; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.exceptions.RoleFunctionException; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.EPRoleFunctionServiceCentralizedImpl; +import org.onap.portalsdk.core.domain.RoleFunction; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(SystemProperties.class) +@Ignore +public class EPRoleFunctionServiceCentralizedImplTest { + + + @Mock + DataAccessService dataAccessService; + + @Mock + SessionFactory sessionFactory; + + @InjectMocks + EPRoleFunctionServiceCentralizedImpl ePRoleFunctionServiceCentralizedImpl = new EPRoleFunctionServiceCentralizedImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + NullPointerException nullPointerException = new NullPointerException(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + MockEPUser mockUser = new MockEPUser(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test(expected = NullPointerException.class) + public void getRoleFunctions() + { + List getRoleFuncList = new ArrayList<>(); + CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(); + getRoleFuncList.add(centralV2RoleFunction); + List getRoleFuncListOfPortal = new ArrayList<>(); + RoleFunction roleFunction = new RoleFunction(); + getRoleFuncListOfPortal.add(roleFunction); + final Map params = new HashMap<>(); + params.put("appId", (long) 1); + Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(getRoleFuncList); + List expectedGetRoleFuncListOfPortal = ePRoleFunctionServiceCentralizedImpl.getRoleFunctions(); + assertEquals(expectedGetRoleFuncListOfPortal.size(),getRoleFuncListOfPortal.size()); + } + + @Test + public void getRoleFunctionsNewTest() throws RoleFunctionException + { + HttpSession session = mockedRequest.getSession(); + EPUser user = mockUser.mockEPUser(); + user.setId((long) 1); + String userId = user.getId().toString(); + final Map params = new HashMap<>(); + params.put("userId", userId); + @SuppressWarnings("unused") + List getRoleFuncListOfPortal = new ArrayList<>(); + Mockito.when(dataAccessService.executeNamedQuery("getRoleFunctionsOfUser", params, null)).thenReturn(getRoleFuncListOfPortal); + Set getRoleFuncListOfPortalSet = ePRoleFunctionServiceCentralizedImpl.getRoleFunctions(mockedRequest, user); + assertTrue(getRoleFuncListOfPortalSet.size() == 0); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceImplTest.java new file mode 100644 index 00000000..b7bffea1 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleFunctionServiceImplTest.java @@ -0,0 +1,135 @@ +/*- + * ============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.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +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.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPRole; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.EPRoleFunctionServiceImpl; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.domain.RoleFunction; +import org.onap.portalsdk.core.service.DataAccessService; +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; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ SystemProperties.class, EPUserUtils.class }) +public class EPRoleFunctionServiceImplTest { + + @Mock + DataAccessService dataAccessService; + + @InjectMocks + EPRoleFunctionServiceImpl ePRoleFunctionServiceImpl = new EPRoleFunctionServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + NullPointerException nullPointerException = new NullPointerException(); + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + MockEPUser mockUser = new MockEPUser(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test + public void getRoleFunctionsTest() { + List functions = new ArrayList<>(); + Mockito.when(dataAccessService.getList(RoleFunction.class, null)).thenReturn(functions); + List expectedFunctions = ePRoleFunctionServiceImpl.getRoleFunctions(); + assertEquals(expectedFunctions, functions); + } + + @Test + public void getRoleFunctionsRequestTest() { + EPUser user = mockUser.mockEPUser(); + HashSet roleFunctions = new HashSet<>(); + PowerMockito.mockStatic(SystemProperties.class); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME))) + .thenReturn(roleFunctions); + HashSet expectedRoleFunctions = (HashSet) ePRoleFunctionServiceImpl.getRoleFunctions(mockedRequest, user); + assertEquals(expectedRoleFunctions, roleFunctions); + } + + @SuppressWarnings("unchecked") + @Test + public void getRoleFunctionsRequestIfNullTest() { + EPUser user = mockUser.mockEPUser(); + HashSet roleFunctions = null; + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPUserUtils.class); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute(SystemProperties.getProperty(SystemProperties.ROLE_FUNCTIONS_ATTRIBUTE_NAME))) + .thenReturn(roleFunctions); + HashMap roles = new HashMap<>(); + EPRole role = new EPRole(); + SortedSet roleFunctionSet = new TreeSet(); + RoleFunction rolefun = new RoleFunction(); + roleFunctionSet.add(rolefun); + role.setRoleFunctions(roleFunctionSet); + roles.put((long) 1, role); + Mockito.when(EPUserUtils.getRoles(mockedRequest)).thenReturn(roles); + HashSet expectedRoleFunctions = (HashSet) ePRoleFunctionServiceImpl.getRoleFunctions(mockedRequest, user); + assertTrue(expectedRoleFunctions.size() == 1); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java new file mode 100644 index 00000000..4c97b6dd --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPRoleServiceImplTest.java @@ -0,0 +1,245 @@ +/*- + * ============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 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.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPRole; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.EPRoleServiceImpl; +import org.onap.portalsdk.core.domain.RoleFunction; +import org.onap.portalsdk.core.service.DataAccessService; + +public class EPRoleServiceImplTest { + + @Mock + DataAccessService dataAccessService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + EPRoleServiceImpl ePRoleServiceImpl = new EPRoleServiceImpl(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + + @Test + public void getRoleFunctionsTest() { + List roleFunctionList = new ArrayList<>(); + Mockito.when(dataAccessService.getList(RoleFunction.class, null)).thenReturn(roleFunctionList); + List expectedRoleFunctionList = ePRoleServiceImpl.getRoleFunctions(); + assertEquals(roleFunctionList, expectedRoleFunctionList); + } + + @Test + public void getAvailableChildRolesIfRoleIdIsNullTest() { + List roleList = new ArrayList<>(); + EPRole role = new EPRole(); + EPRole role1 = new EPRole(); + role.addChildRole(role1); + roleList.add(role); + Mockito.when(dataAccessService.getList(EPRole.class, null)).thenReturn(roleList); + List expectedRoleList = ePRoleServiceImpl.getAvailableChildRoles(null); + assertEquals(roleList, expectedRoleList); + } + + // @Test + // public void getAvailableChildRolesIfRoleIdNotNullTest() + // { + // List roleList = new ArrayList<>(); + // EPRole role = new EPRole(); + // EPRole role1= new EPRole(); + // role.addChildRole(role1); + // roleList.add(role); + // Mockito.when(dataAccessService.getDomainObject(EPRole.class, 1, + // null)).thenReturn(role); + // Mockito.when(dataAccessService.getList(EPRole.class, + // null)).thenReturn(roleList); + // + // List expectedRoleList = + // ePRoleServiceImpl.getAvailableChildRoles((long) 1); + // System.out.println(expectedRoleList); + // assertEquals(roleList,expectedRoleList); + // } + // + @Test + public void getRoleFunctionTest() { + RoleFunction roleFunction = new RoleFunction(); + Mockito.when(dataAccessService.getDomainObject(RoleFunction.class, "test", null)).thenReturn(roleFunction); + RoleFunction expectedRoleFunction = ePRoleServiceImpl.getRoleFunction("test"); + assertEquals(expectedRoleFunction, roleFunction); + } + + @Test + public void saveRoleFunctionTest() { + EPRole role = new EPRole(); + Mockito.doNothing().when(dataAccessService).saveDomainObject(role, null); + ePRoleServiceImpl.saveRole(role); + } + + @Test + public void deleteRoleFunctionTest() { + RoleFunction roleFunction = new RoleFunction(); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(roleFunction, null); + ePRoleServiceImpl.deleteRoleFunction(roleFunction); + } + + @Test + public void getRoleTest() { + EPRole role = null; + Mockito.when(dataAccessService.getDomainObject(EPRole.class, 1, null)).thenReturn(role); + EPRole expectedRole = ePRoleServiceImpl.getRole((long) 1); + assertEquals(expectedRole, role); + } + + @Test + public void getRoleIfappIdNullTest() { + assertNull(ePRoleServiceImpl.getRole(null, null)); + + } + + @Test + public void getRoleIfappIdNotNullTest() { + List roles = new ArrayList<>(); + EPRole role = new EPRole(); + roles.add(role); + String sql = "SELECT * FROM fn_role where APP_ID = 1 AND APP_ROLE_ID = 1"; + Mockito.when(dataAccessService.executeSQLQuery(sql, EPRole.class, null)).thenReturn(roles); + EPRole expectedRole = ePRoleServiceImpl.getRole((long) 1, (long) 1); + assertEquals(expectedRole, role); + + } + + @Test + public void getRoleIfListSizeIsMoreThan1Test() { + List roles = new ArrayList<>(); + EPRole role = new EPRole(); + EPRole role1 = new EPRole(); + roles.add(role); + roles.add(role1); + String sql = "SELECT * FROM fn_role where APP_ID = 1 AND APP_ROLE_ID = 1"; + Mockito.when(dataAccessService.executeSQLQuery(sql, EPRole.class, null)).thenReturn(roles); + EPRole expectedRole = ePRoleServiceImpl.getRole((long) 1, (long) 1); + assertEquals(expectedRole, role); + + } + + @Test + public void getRoleIfListSizeIsEmptyTest() { + List roles = new ArrayList<>(); + String sql = "SELECT * FROM fn_role where APP_ID = 1 AND APP_ROLE_ID = 1"; + Mockito.when(dataAccessService.executeSQLQuery(sql, EPRole.class, null)).thenReturn(roles); + assertNull(ePRoleServiceImpl.getRole((long) 1, (long) 1)); + + } + + @Test + public void saveRoleTest() { + EPRole role = new EPRole(); + Mockito.doNothing().when(dataAccessService).saveDomainObject(role, null); + ePRoleServiceImpl.saveRole(role); + } + + @Test + public void deleteRoleTest() { + EPRole role = new EPRole(); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(role, null); + ePRoleServiceImpl.deleteRole(role); + } + + @Test + public void getAvailableRolesTest() { + List roleList = new ArrayList<>(); + Mockito.when(dataAccessService.getList(EPRole.class, null)).thenReturn(roleList); + List expectedRoleList = ePRoleServiceImpl.getAvailableRoles(); + assertEquals(expectedRoleList, roleList); + } + + @Test + public void getAppRolesTest() { + final Map portalParams = null; + List roleList = new ArrayList<>(); + Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoles", portalParams, null)).thenReturn(roleList); + assertNull(ePRoleServiceImpl.getAppRole("test", (long) 1)); + + } + + @SuppressWarnings("unchecked") + @Test + public void getAppRolesIfNotPortalTest() { + final Map params = null; + List roleList = new ArrayList<>(); + EPRole role = new EPRole(); + EPRole role1 = new EPRole(); + roleList.add(role); + roleList.add(role1); + Mockito.when((List) dataAccessService.executeNamedQuery("getAppRoles", params, null)) + .thenReturn(roleList); + List expectedRoleList = (List) ePRoleServiceImpl.getAppRole("test", (long) 10); + System.out.println(expectedRoleList); + + } + + @Test + public void saveRoleFunction() { + RoleFunction domainRoleFunction = new RoleFunction(); + Mockito.doNothing().when(dataAccessService).saveDomainObject(domainRoleFunction, null); + ePRoleServiceImpl.saveRoleFunction(domainRoleFunction); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java new file mode 100644 index 00000000..66cfdd31 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java @@ -0,0 +1,456 @@ +/*- + * ============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.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +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.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.CentralV2RoleFunction; +import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.domain.EPAppRoleFunction; +import org.onap.portalapp.portal.domain.EPRole; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.exceptions.InactiveApplicationException; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.transport.EcompUserRoles; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.onap.portalsdk.core.domain.Role; +import org.onap.portalsdk.core.restful.domain.EcompUser; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.DataAccessServiceImpl; +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.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ EcompPortalUtils.class, SystemProperties.class, EPCommonSystemProperties.class }) +public class ExternalAccessRolesServiceImplTest { + @Mock + DataAccessService dataAccessService1 = new DataAccessServiceImpl(); + + @Mock + RestTemplate template = new RestTemplate(); + + @InjectMocks + ExternalAccessRolesServiceImpl externalAccessRolesServiceImpl = new ExternalAccessRolesServiceImpl(); + + @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(); + String uebKey = "test-ueb-key"; + + public EPApp mockApp() { + EPApp app = new EPApp(); + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 10); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(false); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + return app; + } + + @Test + public void getAppRolesIfAppIsPortalTest() throws Exception { + List applicationRoles = new ArrayList<>(); + Mockito.when(dataAccessService1.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles); + List expectedApplicationRoles = externalAccessRolesServiceImpl.getAppRoles((long) 1); + assertEquals(expectedApplicationRoles, applicationRoles); + } + + @Test + public void getAppRolesTest() throws Exception { + List applicationRoles = new ArrayList<>(); + Mockito.when(dataAccessService1.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles); + List expectedApplicationRoles = externalAccessRolesServiceImpl.getAppRoles((long) 10); + assertEquals(expectedApplicationRoles, applicationRoles); + } + + // @SuppressWarnings("null") + // @Test(expected = java.lang.Exception.class) + // public void getAppRolesExceptionTest() throws Exception{ + // List applicationRoles = new ArrayList<>(); + // DataAccessService dataAccessService = null ; + // Mockito.when(dataAccessService.getList(EPRole.class, "where app_id = 10", + // null, null)).thenThrow(nullPointerException); + // List expectedApplicationRoles = + // externalAccessRolesServiceImpl.getAppRoles((long) 10); + // assertEquals(expectedApplicationRoles,applicationRoles); + // } + + @Test + public void getAppExceptionTest() throws Exception { + List app = new ArrayList<>(); + Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null)) + .thenReturn(app); + List expectedapp = externalAccessRolesServiceImpl.getApp(uebKey); + assertEquals(app, expectedapp); + } + + @Test(expected = InactiveApplicationException.class) + public void getAppErrorTest() throws Exception { + List appList = new ArrayList<>(); + EPApp app = mockApp(); + appList.add(app); + final Map appUebkeyParams = new HashMap<>(); + appUebkeyParams.put("appKey", "test-ueb-key"); + Mockito.when(dataAccessService1.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null)) + .thenReturn(appList); + externalAccessRolesServiceImpl.getApp(uebKey); + } + + @Test + public void getAppTest() throws Exception { + List appList = new ArrayList<>(); + EPApp app = mockApp(); + app.setId((long) 1); + appList.add(app); + final Map appUebkeyParams = new HashMap<>(); + appUebkeyParams.put("appKey", "test-ueb-key"); + Mockito.when(dataAccessService1.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null)) + .thenReturn(appList); + List expectedapp = externalAccessRolesServiceImpl.getApp(uebKey); + assertEquals(appList, expectedapp); + } + + @Test + public void addRoleTest() throws Exception { + HttpHeaders headers = new HttpHeaders(); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + String uebKey = "test-ueb-key"; + Role role = new Role(); + role.setId((long) 25); + EPApp app = mockApp(); + app.setEnabled(true); + app.setId((long) 10); + app.setNameSpace("test_namesapce"); + Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers); + List appList = new ArrayList<>(); + appList.add(app); + List roleList = new ArrayList<>(); + EPRole ePRole = new EPRole(); + role.setName("Test Role"); + roleList.add(ePRole); + final Map appUebkeyParams = new HashMap<>(); + appUebkeyParams.put("appKey", "test-ueb-key"); + Mockito.when(dataAccessService1.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null)) + .thenReturn(appList); + final Map getPartnerAppRoleParams = new HashMap<>(); + getPartnerAppRoleParams.put("appRoleId", role.getId()); + getPartnerAppRoleParams.put("appId", app.getId()); + Mockito.when(dataAccessService1.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null)).thenReturn(roleList); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL)) + .thenReturn("Testurl"); + ResponseEntity addResponse = new ResponseEntity<>(HttpStatus.CREATED); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST), + Matchers.>any(), Matchers.eq(String.class))).thenReturn(addResponse); + + assertTrue(externalAccessRolesServiceImpl.addRole(role, uebKey)); + } + + + @Test + public void addRoleMethodNotAllowedTest() throws Exception { + HttpHeaders headers = new HttpHeaders(); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + Role role = new Role(); + role.setId((long) 25); + EPApp app = mockApp(); + app.setEnabled(true); + app.setId((long) 10); + app.setNameSpace("test_namesapce"); + Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers); + List appList = new ArrayList<>(); + appList.add(app); + List roleList = new ArrayList<>(); + EPRole ePRole = new EPRole(); + role.setName("Test Role"); + roleList.add(ePRole); + final Map appUebkeyParams = new HashMap<>(); + appUebkeyParams.put("appKey", "test-ueb-key"); + Mockito.when(dataAccessService1.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null)) + .thenReturn(appList); + final Map getPartnerAppRoleParams = new HashMap<>(); + getPartnerAppRoleParams.put("appRoleId", role.getId()); + getPartnerAppRoleParams.put("appId", app.getId()); + Mockito.when(dataAccessService1.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null)).thenReturn(roleList); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL)) + .thenReturn("Testurl"); + ResponseEntity addResponse = new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST), + Matchers.>any(), Matchers.eq(String.class))).thenReturn(addResponse); + assertFalse(externalAccessRolesServiceImpl.addRole(role, uebKey)); + } + + public EPApp getApp() { + EPApp app = new EPApp(); + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(true); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + return app; + } + + @Test + public void deleteCentralRoleFunctionTest() throws Exception { + final Map params = new HashMap<>(); + EPApp app = mockApp(); + params.put("functionCode", "menu_fun_code"); + params.put("appId", String.valueOf(10)); + List centralRoleFunctionList = new ArrayList<>(); + CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction(); + domainCentralRoleFunction.setCode("menu_fun_code"); + centralRoleFunctionList.add(domainCentralRoleFunction); + Mockito.when(dataAccessService1.executeNamedQuery("getRoleFunction", params, null)) + .thenReturn(centralRoleFunctionList); + ResponseEntity addResponse = new ResponseEntity<>(HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE), + Matchers.>any(), Matchers.eq(String.class))).thenReturn(addResponse); + HttpHeaders headers = new HttpHeaders(); + PowerMockito.mockStatic(EcompPortalUtils.class); + Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers); + + Mockito.doNothing().when(dataAccessService1).deleteDomainObjects(EPAppRoleFunction.class, + "app_id = " + app.getId() + " and function_cd = '" + "menu_fun_code" + "'", null); + + assertTrue(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app)); + } + @Test + public void deleteCentralRoleFunctionFailTest() throws Exception { + final Map params = new HashMap<>(); + EPApp app = mockApp(); + params.put("functionCode", "menu_fun_code"); + params.put("appId", String.valueOf(10)); + List centralRoleFunctionList = new ArrayList<>(); + CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction(); + domainCentralRoleFunction.setCode("menu_fun_code"); + centralRoleFunctionList.add(domainCentralRoleFunction); + HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.NOT_FOUND); + Mockito.when(dataAccessService1.executeNamedQuery("getRoleFunction", params, null)) + .thenReturn(centralRoleFunctionList); + ResponseEntity addResponse = new ResponseEntity<>(HttpStatus.NOT_FOUND); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE), + Matchers.>any(), Matchers.eq(String.class))).thenThrow(httpClientErrorException); + HttpHeaders headers = new HttpHeaders(); + PowerMockito.mockStatic(EcompPortalUtils.class); + Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers); + + Mockito.doNothing().when(dataAccessService1).deleteDomainObjects(EPAppRoleFunction.class, + "app_id = " + app.getId() + " and function_cd = '" + "menu_fun_code" + "'", null); + + boolean returnedValue = externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app); + assertTrue(returnedValue); + } + + @Test + public void deleteCentralRoleFunctionExceptionTest() { + final Map params = new HashMap<>(); + EPApp app = mockApp(); + params.put("functionCd", "menu_fun_code"); + params.put("appId", String.valueOf(10)); + List centralRoleFunctionList = new ArrayList<>(); + CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction(); + domainCentralRoleFunction.setCode("menu_fun_code"); + centralRoleFunctionList.add(domainCentralRoleFunction); + Mockito.when(dataAccessService1.executeNamedQuery("getAppFunctionDetails", params, null)) + .thenThrow(nullPointerException); + assertTrue(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app)); + } + + @Test + public void getUserTest() { + List userList = new ArrayList<>(); + EPUser user = mockUser.mockEPUser(); + userList.add(user); + final Map userParams = new HashMap<>(); + userParams.put("org_user_id", "guestT"); + Mockito.when(dataAccessService1.executeNamedQuery("getEPUserByOrgUserId", userParams, null)) + .thenReturn(userList); + List expectedUserList = externalAccessRolesServiceImpl.getUser("guestT"); + assertEquals(expectedUserList, userList); + } + + + public void saveCentralRoleFunctionTest() throws Exception { + CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(); + centralV2RoleFunction.setCode("menu_test"); + EPApp app = mockApp(); + app.setId((long) 1); + final Map params = new HashMap<>(); + params.put("functionCd", "menu_test"); + params.put("appId", String.valueOf(1)); + PowerMockito.mockStatic(EcompPortalUtils.class); + HttpHeaders headers = new HttpHeaders(); + Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers); + List appRoleFunc = new ArrayList<>(); + appRoleFunc.add(centralV2RoleFunction); + Mockito.when(dataAccessService1.executeNamedQuery("getAppFunctionDetails", params, + null)).thenReturn(appRoleFunc); + ResponseEntity addResponse = new ResponseEntity<>(HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), + Matchers.>any(), Matchers.eq(String.class))).thenReturn(addResponse); + } + +// @Test +// public void getAllAppUsersIfAppIsPortalTest() throws Exception +// { +// List expectedapps = new ArrayList<>(); +// EPApp app = new EPApp(); +// app.setEnabled(true); +// app.setId((long) 1); +// expectedapps.add(app); +// List applicationRoles = new ArrayList<>(); +// Mockito.when(dataAccessService1.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles); +// Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null)).thenReturn(expectedapps); +// externalAccessRolesServiceImpl.getAllAppUsers(uebKey); +// } + + + @Test(expected = IndexOutOfBoundsException.class) + public void getAllAppUsersTest() throws Exception + { + List expectedapps = new ArrayList<>(); + EPApp app = new EPApp(); + app.setEnabled(true); + app.setId((long) 10); + expectedapps.add(app); + List applicationRoles = new ArrayList<>(); + Mockito.when(dataAccessService1.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles); + Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null)).thenReturn(expectedapps); + final Map appParams = new HashMap<>(); + appParams.put("appId", app.getId()); + List userList = new ArrayList<>(); + EcompUserRoles ecompUserRoles = new EcompUserRoles(); + ecompUserRoles.setOrgUserId("guestT"); + ecompUserRoles.setRoleId((long) 1); + ecompUserRoles.setRoleName("test"); + + EcompUserRoles ecompUserRoles2 = new EcompUserRoles(); + ecompUserRoles2.setOrgUserId("guestT"); + ecompUserRoles2.setRoleId((long) 2); + ecompUserRoles2.setRoleName("test new"); + userList.add(ecompUserRoles); + userList.add(ecompUserRoles2); + + Mockito.when(dataAccessService1.executeNamedQuery("ApplicationUserRoles", appParams, null)).thenReturn(userList); + List usersfinalList = externalAccessRolesServiceImpl.getAllAppUsers(uebKey); + assertEquals(usersfinalList.get(0).getRoles().size(), 2); + } + + @Test + public void getGlobalRolesOfPortalTest() + { + Mockito.when(dataAccessService1.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(null); + assertEquals(externalAccessRolesServiceImpl.getGlobalRolesOfPortal(), null); + } + + @Test + public void getGlobalRolesOfPortalExceptionTest() + { + List globalRoles = new ArrayList<>(); + Mockito.when(dataAccessService1.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenThrow(nullPointerException); + assertEquals(externalAccessRolesServiceImpl.getGlobalRolesOfPortal(), globalRoles); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuMockServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuMockServiceImplTest.java new file mode 100644 index 00000000..6655a5d1 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuMockServiceImplTest.java @@ -0,0 +1,222 @@ +/*- + * ============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.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.portal.domain.FunctionalMenuItemWithAppID; +import org.onap.portalapp.portal.service.FunctionalMenuService; +import org.onap.portalapp.portal.service.FunctionalMenuServiceImpl; +import org.onap.portalapp.portal.transport.FavoritesFunctionalMenuItemJson; +import org.onap.portalapp.portal.transport.FunctionalMenuItem; +import org.onap.portalapp.portal.transport.FunctionalMenuRole; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalsdk.core.service.DataAccessService; +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; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({SystemProperties.class, EPCommonSystemProperties.class}) +public class FunctionalMenuMockServiceImplTest { + + @Mock + FunctionalMenuService functionalMenuService; + + @Mock + DataAccessService dataAccessService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + FunctionalMenuServiceImpl functionalMenuServiceImpl= new FunctionalMenuServiceImpl(); + + @Test + public void assignHelpURLsTest(){ + List menuItems = new ArrayList(); + FunctionalMenuItem functionalMenuItem1 = new FunctionalMenuItem(); + functionalMenuItem1.text = "Contact Us"; + FunctionalMenuItem functionalMenuItem2 = new FunctionalMenuItem(); + functionalMenuItem2.text = "Get Access"; + FunctionalMenuItem functionalMenuItem3 = new FunctionalMenuItem(); + functionalMenuItem3.text = "User Guide"; + menuItems.add(functionalMenuItem1); + menuItems.add(functionalMenuItem2); + menuItems.add(functionalMenuItem3); + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.USER_GUIDE_URL)).thenReturn("http://todo_enter_user_guide_link"); +// Mockito.doNothing().when(functionalMenuServiceImpl).assignHelpURLs(menuItems); + functionalMenuServiceImpl.assignHelpURLs(menuItems); + } + + @Test + public void getFunctionalMenuItemsTest(){ + String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, " + + "fn_menu_functional_roles r WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' " + + "UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id FROM fn_menu_functional m " + + "WHERE m.url='' AND UPPER(m.active_yn) = 'Y'"; + List actualResult = new ArrayList(); + List expectedResult = new ArrayList(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItems(true); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFunctionalMenuItemsNegativeTest(){ + String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, " + + "fn_menu_functional_roles r WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' " + + "UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn,-1 app_id FROM fn_menu_functional m " + + "WHERE m.url='' AND UPPER(m.active_yn) = 'Y'"; + List actualResult = new ArrayList(); + List expectedResult = new ArrayList(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItems(false); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFunctionalMenuItemsForNotificationTreeTest(){ + String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, fn_menu_functional_roles r " + + "WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id," + + " m.url, m.active_yn,-1 app_id FROM fn_menu_functional m WHERE m.url='' AND UPPER(m.active_yn) = 'Y'"; + List actualResult = new ArrayList(); + List expectedResult = new ArrayList(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForNotificationTree(true); + assertEquals(actualResult, expectedResult); + + } + + @Test + public void getFunctionalMenuItemsForNotificationNegativeTreeTest(){ + String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn, r.app_id FROM fn_menu_functional m, fn_menu_functional_roles r " + + "WHERE m.menu_id = r.menu_id AND UPPER(m.active_yn) = 'Y' AND r.role_id != '900' UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id," + + " m.url, m.active_yn,-1 app_id FROM fn_menu_functional m WHERE m.url='' AND UPPER(m.active_yn) = 'Y'"; + List actualResult = new ArrayList(); + List expectedResult = new ArrayList(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForNotificationTree(false); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFunctionalMenuItemsForAppTest(){ + String sql = "SELECT DISTINCT m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m.active_yn " + + "FROM fn_menu_functional m, fn_menu_functional m1, fn_menu_functional_ancestors a, fn_menu_functional_roles mr " + + "WHERE mr.app_id='1' AND mr.menu_id = m.menu_id AND UPPER(m.active_yn) = 'Y' AND UPPER(m1.active_yn) ='Y' AND a.menu_id = m.menu_id " + + "AND a.ancestor_menu_id = m1.menu_id"; + Integer appId = 1; + List actualResult = new ArrayList(); + List expectedResult = new ArrayList(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForApp(appId); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFunctionalMenuItemsForUserTest(){ + String orgUserId = "test"; + String sql = "SELECT DISTINCT m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m.active_yn " + + "FROM fn_menu_functional m, fn_menu_functional m1, fn_menu_functional_ancestors a, fn_menu_functional_roles mr, fn_user u , fn_user_role ur " + + "WHERE u.org_user_id='test' AND u.user_id = ur.user_id AND ur.app_id = mr.app_id AND (ur.role_id = mr.role_id OR ur.role_id = '999') " + + "AND m.menu_id = mr.menu_id AND UPPER(m.active_yn) = 'Y' AND UPPER(m1.active_yn) ='Y' AND a.menu_id = m.menu_id " + + "AND a.ancestor_menu_id = m1.menu_id UNION select m1.menu_id, m1.column_num, m1.text, m1.parent_menu_id, m1.url, m1.active_yn " + + "FROM fn_menu_functional m, fn_menu_functional_roles mr, fn_menu_functional m1, fn_menu_functional_ancestors a where a.menu_id = m.menu_id AND a.ancestor_menu_id = m1.menu_id AND m.menu_id != m1.menu_id AND m.menu_id = mr.menu_id AND mr.role_id = '900' AND UPPER(m.active_yn) = 'Y' AND UPPER(m1.active_yn) ='Y' UNION SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn FROM fn_menu_functional m WHERE m.text in ('Favorites','Get Access','Contact Us','Support','User Guide','Help')"; + List actualResult = new ArrayList(); + List expectedResult = new ArrayList(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItemsForUser(orgUserId); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFunctionalMenuItemDetailsTest(){ + Long menuid = 1L; + String sql = "SELECT * FROM fn_menu_functional_roles WHERE menu_id = '1'"; + FunctionalMenuItem actualResult = null; + FunctionalMenuItem expectedResult = null; + List roleItems = new ArrayList(); + Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItemWithAppID.class, null)).thenReturn(roleItems); + + actualResult = functionalMenuServiceImpl.getFunctionalMenuItemDetails(menuid); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getFavoriteItemsTest(){ + Long userId = (long)1; + String sql = "SELECT DISTINCT f.user_id,f.menu_id,m.text,m.url " + + "FROM fn_menu_favorites f, fn_menu_functional m, fn_menu_functional_roles mr " + + "WHERE f.user_id='1' AND f.menu_id = m.menu_id AND f.menu_id = mr.menu_id AND mr.role_id != '900' "; + List actualResult = new ArrayList(); + List expectedResult = new ArrayList(); + + Mockito.when(dataAccessService.executeSQLQuery(sql, FavoritesFunctionalMenuItemJson.class, null)).thenReturn(expectedResult); + + actualResult = functionalMenuServiceImpl.getFavoriteItems(userId); + assertEquals(actualResult, expectedResult); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java new file mode 100644 index 00000000..c954fcbd --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java @@ -0,0 +1,92 @@ +package org.onap.portalapp.portal.service; +/*- + * ============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.openecomp.portalapp.portal.test.service; +// +//import static org.junit.Assert.assertTrue; +// +//import java.util.ArrayList; +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +// +//import org.junit.Test; +//import org.openecomp.portalapp.portal.service.FunctionalMenuService; +//import org.openecomp.portalapp.portal.transport.BusinessCardApplicationRole; +//import org.openecomp.portalapp.portal.transport.FunctionalMenuRole; +//import org.openecomp.portalapp.test.framework.ApplicationCommonContextTestSuite; +//import org.springframework.beans.factory.annotation.Autowired; +// +//public class FunctionalMenuServiceImplTest extends ApplicationCommonContextTestSuite { +// +// @Autowired +// FunctionalMenuService functionalMenuService; +// +// @Test +// public void getAppListTestService() throws Exception { +// +// String userId = "guestT"; +// List userAppRolesActualResult = null; +// +// List userAppRolesExpectedResult = new ArrayList(); +// BusinessCardApplicationRole businessCardApplicationRole = new BusinessCardApplicationRole(); +// businessCardApplicationRole.setAppName("ECOMP Portal"); +// businessCardApplicationRole.setRoleName("System Administrator"); +// userAppRolesExpectedResult.add(businessCardApplicationRole); +// Map params = new HashMap(); +// params.put("userId", userId); +// userAppRolesActualResult = functionalMenuService.getUserAppRolesList(userId); +// assertTrue(userAppRolesActualResult.contains(businessCardApplicationRole)); +// +// } +// +// @Test +// public void getFunctionalMenuRoleTest() throws Exception { +// +// FunctionalMenuRole expectedFunctionalMenuRole = new FunctionalMenuRole(); +// expectedFunctionalMenuRole.setId(new Integer(-1)); +// +// expectedFunctionalMenuRole.setMenuId((long) 137); +// expectedFunctionalMenuRole.setAppId(new Integer(456)); +// expectedFunctionalMenuRole.setRoleId(new Integer(6214)); +// List actualFunctionalMenuRoleList = null; +// actualFunctionalMenuRoleList = functionalMenuService.getFunctionalMenuRole(); +// assertTrue(actualFunctionalMenuRoleList.contains(expectedFunctionalMenuRole)); +// +// } +//} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/GetAccessServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/GetAccessServiceImplTest.java new file mode 100644 index 00000000..70d99cc8 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/GetAccessServiceImplTest.java @@ -0,0 +1,87 @@ +/*- + * ============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.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.domain.GetAccessResult; +import org.onap.portalapp.portal.service.GetAccessServiceImpl; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.DataAccessServiceImpl; + +public class GetAccessServiceImplTest { + + + @Mock + DataAccessService dataAccessService = new DataAccessServiceImpl(); + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + GetAccessServiceImpl getAccessServiceImpl = new GetAccessServiceImpl(); + + MockEPUser mockUser = new MockEPUser(); + + @Test + public void getAppAccessListTest() + { + EPUser user = mockUser.mockEPUser(); + Map params = new HashMap<>(); + params.put("userId", user.getId()); + List appAccessList = new ArrayList<>(); + Mockito.when(dataAccessService.executeNamedQuery("getAppAccessFunctionRole", params, null)).thenReturn(appAccessList); + + List expectedAppAccessList = getAccessServiceImpl.getAppAccessList(user); + assertEquals(expectedAppAccessList, appAccessList); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ManifestServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ManifestServiceImplTest.java new file mode 100644 index 00000000..0c066066 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ManifestServiceImplTest.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.service; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.jar.Attributes; + +import javax.servlet.ServletContext; + +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.service.ManifestServiceImpl; + +public class ManifestServiceImplTest { + + @Mock + ServletContext context; + + @Mock + ServletContext context1 = null; + + @InjectMocks + ManifestServiceImpl manifestServiceImpl = new ManifestServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void getWebappManifestTest() throws IOException { + final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF"; + InputStream inputStream = new ByteArrayInputStream("test data".getBytes()); + Mockito.when(context.getResourceAsStream(MANIFEST_RESOURCE_PATH)).thenReturn(inputStream); + Attributes attributes = manifestServiceImpl.getWebappManifest(); + assertTrue(attributes.size() == 0); + } + + @Test(expected = java.lang.NullPointerException.class) + public void getWebappManifestExceptionTest() throws IOException { + final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF"; + InputStream inputStream = new ByteArrayInputStream("test data".getBytes()); + Mockito.when(context1.getResourceAsStream(MANIFEST_RESOURCE_PATH)).thenThrow(nullPointerException); + Attributes attributes = manifestServiceImpl.getWebappManifest(); + assertTrue(attributes.size() == 0); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PersUserAppServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PersUserAppServiceImplTest.java new file mode 100644 index 00000000..56104e82 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/PersUserAppServiceImplTest.java @@ -0,0 +1,218 @@ +/*- + * ============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 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.core.MockEPUser; +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.domain.PersUserAppSelection; +import org.onap.portalapp.portal.framework.MockitoTestSuite; +import org.onap.portalapp.portal.service.AdminRolesService; +import org.onap.portalapp.portal.service.PersUserAppServiceImpl; +import org.onap.portalapp.portal.service.UserRolesService; +import org.onap.portalsdk.core.service.DataAccessService; + +public class PersUserAppServiceImplTest { + + @Mock + DataAccessService dataAccessService; + @Mock + AdminRolesService adminRolesService; + @Mock + UserRolesService userRolesService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + PersUserAppServiceImpl persUserAppServiceImpl = new PersUserAppServiceImpl(); + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + MockEPUser mockUser = new MockEPUser(); + + public EPApp getApp() { + EPApp app = new EPApp(); + app.setName("Test"); + app.setImageUrl("test"); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(true); + app.setEnabled(false); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + return app; + } + + @Test(expected = IllegalArgumentException.class) + public void setPersUserAppValueIfUserNull() { + persUserAppServiceImpl.setPersUserAppValue(null, null, false, false); + } + + @Test + public void setPersUserAppValueTest() { + EPApp app = getApp(); + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(persUserAppSelection, null); + persUserAppServiceImpl.setPersUserAppValue(user, app, false, true); + } + + @Test + public void setPersUserAppValueIfSelectTest() { + EPApp app = getApp(); + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null); + persUserAppServiceImpl.setPersUserAppValue(user, app, true, true); + } + + @Test + public void setPersUserAppValueIfOpenTest() { + EPApp app = getApp(); + app.setOpen(false); + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null); + persUserAppServiceImpl.setPersUserAppValue(user, app, true, true); + } + + @Test + public void setPersUserAppValueIfAppNotOpenTest() { + EPApp app = getApp(); + app.setOpen(false); + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + List roles = new ArrayList<>(); + EPUserApp epUserApp = new EPUserApp(); + roles.add(epUserApp); + Mockito.when(userRolesService.getCachedAppRolesForUser(app.getId(), user.getId())).thenReturn(roles); + persUserAppServiceImpl.setPersUserAppValue(user, app, true, false); + } + + @Test + public void setPersUserAppValueIfNotPortalAdminTest() { + EPApp app = getApp(); + app.setOpen(false); + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).deleteDomainObject(persUserAppSelection, null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + List roles = new ArrayList<>(); + EPUserApp epUserApp = new EPUserApp(); + roles.add(epUserApp); + Mockito.when(userRolesService.getCachedAppRolesForUser(app.getId(), user.getId())).thenReturn(roles); + persUserAppServiceImpl.setPersUserAppValue(user, app, true, false); + } + + @Test + public void setPersUserAppValueNewTest() { + EPApp app = getApp(); + app.setOpen(false); + EPUser user = mockUser.mockEPUser(); + List persUserAppSelectionList = new ArrayList<>(); + PersUserAppSelection persUserAppSelection = new PersUserAppSelection(); + persUserAppSelection.setId((long) 1); + persUserAppSelectionList.add(persUserAppSelection); + Mockito.when(dataAccessService.getList(PersUserAppSelection.class, "test", null, null)) + .thenReturn(persUserAppSelectionList); + Mockito.doNothing().when(dataAccessService).saveDomainObject(persUserAppSelection, null); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + List roles = new ArrayList<>(); + EPUserApp epUserApp = new EPUserApp(); + roles.add(epUserApp); + Mockito.when(userRolesService.getCachedAppRolesForUser(app.getId(), user.getId())).thenReturn(roles); + persUserAppServiceImpl.setPersUserAppValue(user, app, false, false); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AnalyticsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AnalyticsTest.java new file mode 100644 index 00000000..e92f5cb4 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AnalyticsTest.java @@ -0,0 +1,70 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.Analytics; + +public class AnalyticsTest { + + public Analytics mockAnalytics(){ + Analytics analytics = new Analytics(); + + analytics.setAction("test"); + analytics.setPage("test"); + analytics.setFunction("test"); + analytics.setUserid("test"); + analytics.setType("test"); + + return analytics; + } + + @Test + public void analyticsTest(){ + Analytics analytics = mockAnalytics(); + + assertEquals(analytics.getAction(), "test"); + assertEquals(analytics.getPage(), "test"); + assertEquals(analytics.getFunction(), "test"); + assertEquals(analytics.getUserid(), "test"); + assertEquals(analytics.getType(), "test"); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppCatalogPersonalizationTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppCatalogPersonalizationTest.java new file mode 100644 index 00000000..2a512f71 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppCatalogPersonalizationTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.AppCatalogPersonalization; + +public class AppCatalogPersonalizationTest { + + public AppCatalogPersonalization mockAppCatalogPersonalization(){ + AppCatalogPersonalization appCatalogPersonalization = new AppCatalogPersonalization(); + + return appCatalogPersonalization; + } + + @Test + public void appCatalogPersonalizationTest(){ + AppCatalogPersonalization appCatalogPersonalization = mockAppCatalogPersonalization(); + + AppCatalogPersonalization appCatalogPersonalization1 = new AppCatalogPersonalization(); + + assertEquals(appCatalogPersonalization.hashCode(), appCatalogPersonalization1.hashCode()); + assertTrue(appCatalogPersonalization.equals(appCatalogPersonalization1)); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppNameIdIsAdminTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppNameIdIsAdminTest.java new file mode 100644 index 00000000..4287f3c1 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppNameIdIsAdminTest.java @@ -0,0 +1,75 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.AppNameIdIsAdmin; + +public class AppNameIdIsAdminTest { + + public AppNameIdIsAdmin mockAppNameIdIsAdmin(){ + AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin(); + appNameIdIsAdmin.setId((long)1); + appNameIdIsAdmin.setAppName("test"); + appNameIdIsAdmin.setRestrictedApp(false); + appNameIdIsAdmin.setIsAdmin(false); + return appNameIdIsAdmin; + } + + @Test + public void appNameIdIsAdminTest(){ + AppNameIdIsAdmin appNameIdIsAdmin = mockAppNameIdIsAdmin(); + + AppNameIdIsAdmin appNameIdIsAdmin1 = new AppNameIdIsAdmin(); + appNameIdIsAdmin1.setId((long)1); + appNameIdIsAdmin1.setAppName("test"); + appNameIdIsAdmin1.setRestrictedApp(false); + appNameIdIsAdmin1.setIsAdmin(false); + + assertEquals(appNameIdIsAdmin.getId(), new Long(1)); + assertEquals(appNameIdIsAdmin.getAppName(), "test"); + assertEquals(appNameIdIsAdmin.getRestrictedApp(), false); + assertEquals(appNameIdIsAdmin.getIsAdmin(), false); + + assertEquals(appNameIdIsAdmin.toString(), "AppNameIdIsAdmin [id=1, appName=test, isAdmin=false, restrictedApp=false]"); + assertEquals(appNameIdIsAdmin.hashCode(), appNameIdIsAdmin1.hashCode()); + assertTrue(appNameIdIsAdmin.equals(appNameIdIsAdmin1)); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java new file mode 100644 index 00000000..da05ba36 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppWithRolesForUserTest.java @@ -0,0 +1,70 @@ +/*- + * ============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.transport; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.AppWithRolesForUser; + +import static org.junit.Assert.assertEquals; + +public class AppWithRolesForUserTest { + + public AppWithRolesForUser mockAppWithRolesForUser(){ + AppWithRolesForUser appWithRolesForUser = new AppWithRolesForUser(); + + // List appRoles = new ArrayList(); + + appWithRolesForUser.setOrgUserId("test"); + appWithRolesForUser.setAppId((long)1); + appWithRolesForUser.setAppName("test"); + appWithRolesForUser.setAppRoles(null); + + return appWithRolesForUser; + } + + @Test + public void roleInAppForUserTest(){ + AppWithRolesForUser appWithRolesForUser = mockAppWithRolesForUser(); + + assertEquals(appWithRolesForUser.getOrgUserId(), "test"); + assertEquals(appWithRolesForUser.getAppId(), new Long(1)); + assertEquals(appWithRolesForUser.getAppName(), "test"); + assertEquals(appWithRolesForUser.getAppRoles(), null); + assertEquals(appWithRolesForUser.toString(), "AppWithRolesForUser [orgUserId=test, appId=1, appName=test, appRoles=null]"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppsListWithAdminRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppsListWithAdminRoleTest.java new file mode 100644 index 00000000..fdacc601 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/AppsListWithAdminRoleTest.java @@ -0,0 +1,83 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.AppNameIdIsAdmin; +import org.onap.portalapp.portal.transport.AppsListWithAdminRole; + +public class AppsListWithAdminRoleTest { + + public AppsListWithAdminRole mockAppsListWithAdminRole(){ + AppsListWithAdminRole appsListWithAdminRole = new AppsListWithAdminRole(); + + ArrayList appsRoles = new ArrayList(); + AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin(); + appsRoles.add(appNameIdIsAdmin); + + appsListWithAdminRole.setOrgUserId("test"); + appsListWithAdminRole.setAppsRoles(appsRoles); + + return appsListWithAdminRole; + } + + @Test + public void appsListWithAdminRoleTest(){ + AppsListWithAdminRole appsListWithAdminRole = mockAppsListWithAdminRole(); + + AppsListWithAdminRole appsListWithAdminRole1 = new AppsListWithAdminRole(); + + ArrayList appsRoles = new ArrayList(); + AppNameIdIsAdmin appNameIdIsAdmin = new AppNameIdIsAdmin(); + appsRoles.add(appNameIdIsAdmin); + + appsListWithAdminRole1.setOrgUserId("test"); + appsListWithAdminRole1.setAppsRoles(appsRoles); + + assertEquals(appsListWithAdminRole.getOrgUserId(), "test"); + assertEquals(appsListWithAdminRole.getAppsRoles(), appsRoles); + + assertTrue(appsListWithAdminRole.equals(appsListWithAdminRole1)); + assertEquals(appsListWithAdminRole.hashCode(), appsListWithAdminRole1.hashCode()); + assertEquals(appsListWithAdminRole.toString(), "AppsListWithAdminRole [orgUserId=test, appsRoles=[AppNameIdIsAdmin [id=null, appName=null, isAdmin=null, restrictedApp=null]]]"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadRoleFunctionTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadRoleFunctionTest.java new file mode 100644 index 00000000..7d22f04c --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadRoleFunctionTest.java @@ -0,0 +1,72 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.BulkUploadRoleFunction; + +public class BulkUploadRoleFunctionTest { + + public BulkUploadRoleFunction mockBulkUploadRoleFunction(){ + + BulkUploadRoleFunction bulkUploadRoleFunction = new BulkUploadRoleFunction(); + + bulkUploadRoleFunction.setFunctionName("test"); + bulkUploadRoleFunction.setFunctionCd("test"); + + return bulkUploadRoleFunction; + } + + @Test + public void bulkUploadRoleFunctionTest(){ + BulkUploadRoleFunction bulkUploadRoleFunction = mockBulkUploadRoleFunction(); + + BulkUploadRoleFunction bulkUploadRoleFunction1 = new BulkUploadRoleFunction(); + + bulkUploadRoleFunction1.setFunctionName("test"); + bulkUploadRoleFunction1.setFunctionCd("test"); + + assertEquals(bulkUploadRoleFunction.getFunctionCd(), "test"); + assertEquals(bulkUploadRoleFunction.getFunctionName(), "test"); + assertEquals(bulkUploadRoleFunction.hashCode(), bulkUploadRoleFunction1.hashCode()); + assertTrue(bulkUploadRoleFunction.equals(bulkUploadRoleFunction1)); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadUserRolesTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadUserRolesTest.java new file mode 100644 index 00000000..14bd7edd --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BulkUploadUserRolesTest.java @@ -0,0 +1,74 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.BulkUploadUserRoles; + +public class BulkUploadUserRolesTest { + + public BulkUploadUserRoles mockBulkUploadUserRoles(){ + BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles(); + + bulkUploadUserRoles.setRoleName("test"); + bulkUploadUserRoles.setOrgUserId("test"); + bulkUploadUserRoles.setAppNameSpace("test"); + + return bulkUploadUserRoles; + } + + @Test + public void bulkUploadUserRolesTest(){ + BulkUploadUserRoles bulkUploadUserRoles = mockBulkUploadUserRoles(); + + BulkUploadUserRoles bulkUploadUserRoles1 = new BulkUploadUserRoles(); + + bulkUploadUserRoles1.setRoleName("test"); + bulkUploadUserRoles1.setOrgUserId("test"); + bulkUploadUserRoles1.setAppNameSpace("test"); + + assertEquals(bulkUploadUserRoles.getRoleName(), "test"); + assertEquals(bulkUploadUserRoles.getOrgUserId(), "test"); + assertEquals(bulkUploadUserRoles.getAppNameSpace(), "test"); + + assertEquals(bulkUploadUserRoles.hashCode(), bulkUploadUserRoles1.hashCode()); + assertTrue(bulkUploadUserRoles.equals(bulkUploadUserRoles1)); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BusinessCardApplicationRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BusinessCardApplicationRoleTest.java new file mode 100644 index 00000000..225df010 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BusinessCardApplicationRoleTest.java @@ -0,0 +1,64 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.BusinessCardApplicationRole; + +public class BusinessCardApplicationRoleTest { + + public BusinessCardApplicationRole mockBusinessCardApplicationRole(){ + BusinessCardApplicationRole businessCardApplicationRole = new BusinessCardApplicationRole(); + + return businessCardApplicationRole; + } + + @Test + public void businessCardApplicationRoleTest(){ + BusinessCardApplicationRole businessCardApplicationRole = mockBusinessCardApplicationRole(); + + BusinessCardApplicationRole businessCardApplicationRole1 = new BusinessCardApplicationRole(); + + assertEquals(businessCardApplicationRole.hashCode(), businessCardApplicationRole1.hashCode()); + assertTrue(businessCardApplicationRole.equals(businessCardApplicationRole1)); + assertEquals(businessCardApplicationRole.toString(), "BusinessCardUserApplicationRoles [appName=null, roleName=null]"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BusinessCardApplicationRolesListTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BusinessCardApplicationRolesListTest.java new file mode 100644 index 00000000..c43361d3 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/BusinessCardApplicationRolesListTest.java @@ -0,0 +1,64 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.BusinessCardApplicationRolesList; + +public class BusinessCardApplicationRolesListTest { + + public BusinessCardApplicationRolesList mockBusinessCardApplicationRolesList(){ + BusinessCardApplicationRolesList businessCardApplicationRolesList = new BusinessCardApplicationRolesList(); + + return businessCardApplicationRolesList; + } + + @Test + public void businessCardApplicationRolesListTest(){ + BusinessCardApplicationRolesList businessCardApplicationRolesList = mockBusinessCardApplicationRolesList(); + + BusinessCardApplicationRolesList businessCardApplicationRolesList1 = new BusinessCardApplicationRolesList(); + + assertEquals(businessCardApplicationRolesList.hashCode(), businessCardApplicationRolesList1.hashCode()); + assertTrue(businessCardApplicationRolesList.equals(businessCardApplicationRolesList1)); + assertEquals(businessCardApplicationRolesList.toString(), "BusinessCardUserAppRoles [appName=null, roleNames=null]"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralAppTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralAppTest.java new file mode 100644 index 00000000..1dde2926 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralAppTest.java @@ -0,0 +1,86 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.CentralApp; + +public class CentralAppTest { + + public CentralApp mockCentralApp(){ + CentralApp centralApp = new CentralApp((long)1, null, null, (long)1, (long)1, (long)1, "test", "test", "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, "test", "test", "test", "test"); + return centralApp; + } + + @Test + public void centralAppTest(){ + CentralApp centralApp = mockCentralApp(); + + CentralApp centralApp1 = new CentralApp((long)1, null, null, (long)1, (long)1, (long)1, "test", "test", "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, "test", "test", "test", "test"); + + assertEquals(centralApp.getId(), new Long(1)); + assertEquals(centralApp.getCreatedId(), new Long(1)); + assertEquals(centralApp.getModifiedId(), new Long(1)); + assertEquals(centralApp.getRowNum(), new Long(1)); + assertEquals(centralApp.getName(), "test"); + assertEquals(centralApp.getImageUrl(), "test"); + assertEquals(centralApp.getDescription(), "test"); + assertEquals(centralApp.getNotes(), "test"); + assertEquals(centralApp.getUrl(), "test"); + assertEquals(centralApp.getAlternateUrl(), "test"); + assertEquals(centralApp.getRestEndpoint(), "test"); + assertEquals(centralApp.getMlAppName(), "test"); + assertEquals(centralApp.getMlAppAdminId(), "test"); + assertEquals(centralApp.getMotsId(), "test"); + assertEquals(centralApp.getAppPassword(), "test"); + assertEquals(centralApp.getOpen(), "test"); + assertEquals(centralApp.getEnabled(), "test"); + assertEquals(centralApp.getUsername(), "test"); + assertEquals(centralApp.getUebKey(), "test"); + assertEquals(centralApp.getUebSecret(), "test"); + assertEquals(centralApp.getUebTopicName(), "test"); + + assertTrue(centralApp.equals(centralApp1)); + assertEquals(centralApp.hashCode(), centralApp1.hashCode()); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralRoleTest.java new file mode 100644 index 00000000..1c40be40 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralRoleTest.java @@ -0,0 +1,96 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class CentralRoleTest { + + public CentralV2Role mockCentralRole(){ + CentralV2Role centralV2Role = new CentralV2Role((long)1, null, null, (long)1, (long)1, (long)1, + "test", false, 1, null, null, null); + + centralV2Role.setId((long)1); + centralV2Role.setCreatedId((long)1); + centralV2Role.setModifiedId((long)1); + centralV2Role.setRowNum((long)1); + centralV2Role.setName("test"); + centralV2Role.setActive(false); + centralV2Role.setPriority(1); + + centralV2Role.setCreated(null); + centralV2Role.setModified(null); + centralV2Role.setRoleFunctions(null); + centralV2Role.setChildRoles(null); + centralV2Role.setParentRoles(null); + + return centralV2Role; + } + + @Test + public void centralRoleTest(){ + CentralV2Role centralV2Role = mockCentralRole(); + + CentralV2Role centralRole1 = new CentralV2Role((long)1, null, null, (long)1, (long)1, (long)1, + "test", false, 1, null, null, null); + + CentralV2Role centralRole2 = new CentralV2Role((long)1, "test"); + + assertEquals(centralV2Role.getId(), new Long(1)); + assertEquals(centralV2Role.getCreatedId(), new Long(1)); + assertEquals(centralV2Role.getModifiedId(), new Long(1)); + assertEquals(centralV2Role.getRowNum(), new Long(1)); + assertEquals(centralV2Role.getName(), "test"); + assertEquals(centralV2Role.isActive(), false); + assertEquals(centralV2Role.getCreated(), null); + assertEquals(centralV2Role.getModified(), null); + assertEquals(centralV2Role.getRoleFunctions(), null); + assertEquals(centralV2Role.getChildRoles(), null); + assertEquals(centralV2Role.getParentRoles(), null); + assertEquals(centralV2Role.getPriority().toString(), "1"); + assertEquals(centralV2Role.hashCode(), centralRole1.hashCode()); + assertTrue(centralV2Role.equals(centralRole1)); + assertEquals(centralV2Role, centralRole1); + assertEquals(centralRole2, new CentralV2Role((long)1, "test")); + } + + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserAppTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserAppTest.java new file mode 100644 index 00000000..a04b47a6 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserAppTest.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.portal.transport; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.onap.portalapp.portal.transport.CentralApp; +import org.onap.portalapp.portal.transport.CentralV2Role; +import org.onap.portalapp.portal.transport.CentralV2UserApp; + +public class CentralUserAppTest { + + public CentralV2UserApp mockCentralUserApp(){ + CentralV2UserApp centralV2UserApp = new CentralV2UserApp(); + + CentralApp app = new CentralApp((long)1, null, null, (long)1, (long)1, (long)1, "test", "test", "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, "test", "test", "test", "test"); + + CentralV2Role role = new CentralV2Role(); + + centralV2UserApp.setUserId((long)1); + centralV2UserApp.setApp(app); + centralV2UserApp.setRole(role); + centralV2UserApp.setPriority((short) 123); + + return centralV2UserApp; + } + + @Test + public void centralUserAppTest(){ + CentralV2UserApp centralV2UserApp = mockCentralUserApp(); + + CentralApp app1 = new CentralApp((long)1, null, null, (long)1, (long)1, (long)1, "test", "test", "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, "test", "test", "test", "test"); + + CentralV2Role role1 = new CentralV2Role(); + + assertEquals(centralV2UserApp.getUserId(), new Long(1)); + assertEquals(centralV2UserApp.getPriority(), new Short((short) 123)); + assertEquals(centralV2UserApp.getApp(), app1); + assertEquals(centralV2UserApp.getRole(), role1); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserTest.java new file mode 100644 index 00000000..67c6ee09 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/CentralUserTest.java @@ -0,0 +1,89 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.CentralV2Role; +import org.onap.portalapp.portal.transport.CentralV2User; +import org.onap.portalapp.portal.transport.CentralV2UserApp; + +public class CentralUserTest { + + public CentralV2User mockCentralUser(){ + Set userApps = new HashSet(); + Set pseudoRoles = new HashSet(); + CentralV2User centralV2User = new CentralV2User((long)1, null, null, (long)1, (long)1, (long)1, (long)1, + (long)1, "test", "test", "test", "test", "test", + "test", "test", (long)1, "test", "test", "test", + "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", + "test", "test", "test", "test", "test", + "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, + false, false, (long)1, (long)1, false, "test", userApps, pseudoRoles); + + return centralV2User; + } + + @Test + public void centralRoleTest(){ + CentralV2User centralV2User = mockCentralUser(); + + Set userApps = new HashSet(); + Set pseudoRoles = new HashSet(); + CentralV2User centralV2User1 = new CentralV2User((long)1, null, null, (long)1, (long)1, (long)1, (long)1, + (long)1, "test", "test", "test", "test", "test", + "test", "test", (long)1, "test", "test", "test", + "test", "test", "test", "test", "test", "test", "test", + "test", "test", "test", "test", + "test", "test", "test", "test", "test", + "test", "test", "test", "test", "test", + "test", "test", "test", "test", null, + false, false, (long)1, (long)1, false, "test", userApps, pseudoRoles); + + + assertEquals(centralV2User, centralV2User1); + assertEquals(centralV2User.hashCode(), centralV2User1.hashCode()); + assertTrue(centralV2User.equals(centralV2User1)); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPAppsManualPreferenceTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPAppsManualPreferenceTest.java new file mode 100644 index 00000000..e45ffacc --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPAppsManualPreferenceTest.java @@ -0,0 +1,84 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.EPAppsManualPreference; + +public class EPAppsManualPreferenceTest { + + public EPAppsManualPreference mockEPAppsManualPreference(){ + EPAppsManualPreference epAppsManualPreference = new EPAppsManualPreference(); + + epAppsManualPreference.setAppid((long)1); + epAppsManualPreference.setCol(1); + epAppsManualPreference.setHeaderText("test"); + epAppsManualPreference.setImageLink("test"); + epAppsManualPreference.setOrder(1); + epAppsManualPreference.setRestrictedApp(false); + epAppsManualPreference.setRow(1); + epAppsManualPreference.setSizeX(1); + epAppsManualPreference.setSizeY(1); + epAppsManualPreference.setSubHeaderText("test"); + epAppsManualPreference.setUrl("test"); + epAppsManualPreference.setAddRemoveApps(false); + + return epAppsManualPreference; + } + + @Test + public void epAppsManualPreferenceTest(){ + + EPAppsManualPreference epAppsManualPreference = mockEPAppsManualPreference(); + + assertEquals(epAppsManualPreference.getAppid(), new Long(1)); + assertEquals(epAppsManualPreference.getCol(), 1); + assertEquals(epAppsManualPreference.getHeaderText(), "test"); + assertEquals(epAppsManualPreference.getImageLink(), "test"); + assertEquals(epAppsManualPreference.getOrder(), 1); + assertEquals(epAppsManualPreference.isRestrictedApp(), false); + assertEquals(epAppsManualPreference.getRow(), 1); + assertEquals(epAppsManualPreference.getSizeX(), 1); + assertEquals(epAppsManualPreference.getSizeY(), 1); + assertEquals(epAppsManualPreference.getSubHeaderText(), "test"); + assertEquals(epAppsManualPreference.getUrl(), "test"); + assertEquals(epAppsManualPreference.isAddRemoveApps(), false); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPAppsSortPreferenceTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPAppsSortPreferenceTest.java new file mode 100644 index 00000000..84ae04a6 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPAppsSortPreferenceTest.java @@ -0,0 +1,66 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.EPAppsSortPreference; + +public class EPAppsSortPreferenceTest { + + public EPAppsSortPreference mockEPAppsSortPreference(){ + EPAppsSortPreference epAppsSortPreference = new EPAppsSortPreference(); + + epAppsSortPreference.setIndex(1); + epAppsSortPreference.setValue("test"); + epAppsSortPreference.setTitle("test"); + + return epAppsSortPreference; + } + + @Test + public void epAppsSortPreferenceTest(){ + EPAppsSortPreference epAppsSortPreference = mockEPAppsSortPreference(); + + assertEquals(epAppsSortPreference.getIndex(), 1); + assertEquals(epAppsSortPreference.getValue(), "test"); + assertEquals(epAppsSortPreference.getTitle(), "test"); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPDeleteAppsManualSortPrefTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPDeleteAppsManualSortPrefTest.java new file mode 100644 index 00000000..5aad78ce --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPDeleteAppsManualSortPrefTest.java @@ -0,0 +1,66 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.EPDeleteAppsManualSortPref; + +public class EPDeleteAppsManualSortPrefTest { + + public EPDeleteAppsManualSortPref mockEPDeleteAppsManualSortPref(){ + EPDeleteAppsManualSortPref epDeleteAppsManualSortPref = new EPDeleteAppsManualSortPref(); + + epDeleteAppsManualSortPref.setAppId((long)1); + epDeleteAppsManualSortPref.setSelect(false); + epDeleteAppsManualSortPref.setPending(false); + + return epDeleteAppsManualSortPref; + } + + @Test + public void epDeleteAppsManualSortPrefTest(){ + EPDeleteAppsManualSortPref epDeleteAppsManualSortPref = mockEPDeleteAppsManualSortPref(); + + assertEquals(epDeleteAppsManualSortPref.getAppId(), new Long(1)); + assertEquals(epDeleteAppsManualSortPref.isSelect(), false); + assertEquals(epDeleteAppsManualSortPref.isPending(), false); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPUserAppCurrentRolesTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPUserAppCurrentRolesTest.java new file mode 100644 index 00000000..31296cc4 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPUserAppCurrentRolesTest.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.portal.transport; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.EPUserAppCurrentRoles; + +public class EPUserAppCurrentRolesTest { + + public EPUserAppCurrentRoles mockEPUserAppCurrentRoles(){ + EPUserAppCurrentRoles epUserAppCurrentRoles = new EPUserAppCurrentRoles(); + + epUserAppCurrentRoles.setRoleName("test"); + epUserAppCurrentRoles.setUserId((long)1); + epUserAppCurrentRoles.setPriority("test"); + epUserAppCurrentRoles.setRoleId((long)1); + + return epUserAppCurrentRoles; + } + + @Test + public void epUserAppCurrentRolesTest(){ + EPUserAppCurrentRoles epUserAppCurrentRoles = mockEPUserAppCurrentRoles(); + + EPUserAppCurrentRoles epUserAppCurrentRoles1 = new EPUserAppCurrentRoles(); + + epUserAppCurrentRoles1.setRoleName("test"); + epUserAppCurrentRoles1.setUserId((long)1); + epUserAppCurrentRoles1.setPriority("test"); + epUserAppCurrentRoles1.setRoleId((long)1); + + assertEquals(epUserAppCurrentRoles.getRoleName(), "test"); + assertEquals(epUserAppCurrentRoles.getUserId(), new Long(1)); + assertEquals(epUserAppCurrentRoles.getRoleId(), new Long(1)); + assertEquals(epUserAppCurrentRoles.getPriority(), "test"); + assertEquals(epUserAppCurrentRoles.hashCode(), epUserAppCurrentRoles1.hashCode()); + assertTrue(epUserAppCurrentRoles.equals(epUserAppCurrentRoles1)); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPWidgetsSortPreferenceTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPWidgetsSortPreferenceTest.java new file mode 100644 index 00000000..ef50aef8 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EPWidgetsSortPreferenceTest.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.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.EPWidgetsSortPreference; + +public class EPWidgetsSortPreferenceTest { + + public EPWidgetsSortPreference mockEPWidgetsSortPreference(){ + EPWidgetsSortPreference epWidgetsSortPreference = new EPWidgetsSortPreference(); + + epWidgetsSortPreference.setSizeX(1); + epWidgetsSortPreference.setSizeY(1); + epWidgetsSortPreference.setHeaderText("test"); + epWidgetsSortPreference.setUrl("test"); + epWidgetsSortPreference.setWidgetid((long)1); + epWidgetsSortPreference.setWidgetIdentifier("test"); + epWidgetsSortPreference.setRow(1); + epWidgetsSortPreference.setCol(1); + + return epWidgetsSortPreference; + } + + @Test + public void epWidgetsSortPreferenceTest(){ + EPWidgetsSortPreference epWidgetsSortPreference = mockEPWidgetsSortPreference(); + + assertEquals(epWidgetsSortPreference.getSizeX(), 1); + assertEquals(epWidgetsSortPreference.getSizeY(), 1); + assertEquals(epWidgetsSortPreference.getHeaderText(), "test"); + assertEquals(epWidgetsSortPreference.getUrl(), "test"); + assertEquals(epWidgetsSortPreference.getWidgetid(), new Long(1)); + assertEquals(epWidgetsSortPreference.getWidgetIdentifier(), "test"); + assertEquals(epWidgetsSortPreference.getRow(), 1); + assertEquals(epWidgetsSortPreference.getRow(), 1); + + } + + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EcompUserAppRolesTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EcompUserAppRolesTest.java new file mode 100644 index 00000000..c8b1fdd2 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EcompUserAppRolesTest.java @@ -0,0 +1,70 @@ + +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.EcompUserAppRoles; + +public class EcompUserAppRolesTest { + + public EcompUserAppRoles mockEcompUserAppRoles(){ + EcompUserAppRoles ecompUserAppRoles = new EcompUserAppRoles(); + + ecompUserAppRoles.setAppId("test"); + ecompUserAppRoles.setUserId((long)1); + ecompUserAppRoles.setPriority("test"); + ecompUserAppRoles.setRoleId((long)1); + ecompUserAppRoles.setRoleName("test"); + + return ecompUserAppRoles; + } + + @Test + public void ecompUserAppRolesTest(){ + + EcompUserAppRoles ecompUserAppRoles = mockEcompUserAppRoles(); + + assertEquals(ecompUserAppRoles.getAppId(), "test"); + assertEquals(ecompUserAppRoles.getPriority(), "test"); + assertEquals(ecompUserAppRoles.getRoleName(), "test"); + assertEquals(ecompUserAppRoles.getUserId(), new Long(1)); + assertEquals(ecompUserAppRoles.getRoleId(), new Long(1)); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemExtVOTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemExtVOTest.java new file mode 100644 index 00000000..9f316865 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemExtVOTest.java @@ -0,0 +1,70 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.EpNotificationItemExtVO; + +public class EpNotificationItemExtVOTest { + + public EpNotificationItemExtVO mockEpNotificationItemExtVO(){ + EpNotificationItemExtVO epNotificationItemExtVO = new EpNotificationItemExtVO(); + + //epNotificationItemExtVO.setActiveYn("abc"); + epNotificationItemExtVO.setMsgHeader("test"); + epNotificationItemExtVO.setMsgDescription("test"); + epNotificationItemExtVO.setPriority(1); + epNotificationItemExtVO.setCreatorId(1); + epNotificationItemExtVO.setLoginId("test"); + + return epNotificationItemExtVO; + } + + @Test + public void epNotificationItemExtVOTest(){ + EpNotificationItemExtVO epNotificationItemExtVO = mockEpNotificationItemExtVO(); + + assertEquals(epNotificationItemExtVO.getMsgHeader(), "test"); + assertEquals(epNotificationItemExtVO.getMsgDescription(), "test"); + assertEquals(epNotificationItemExtVO.getPriority().toString(), "1"); + assertEquals(epNotificationItemExtVO.getCreatorId().toString(), "1"); + assertEquals(epNotificationItemExtVO.getLoginId(), "test"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemTest.java new file mode 100644 index 00000000..7f80bc40 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemTest.java @@ -0,0 +1,100 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.EpNotificationItem; + +public class EpNotificationItemTest { + + public EpNotificationItem mockEpNotificationItem(){ + EpNotificationItem epNotificationItem = new EpNotificationItem(); + + epNotificationItem.setNotificationId((long)1); + epNotificationItem.setIsForOnlineUsers("test"); + epNotificationItem.setIsForAllRoles("test"); + epNotificationItem.setActiveYn("test"); + epNotificationItem.setMsgHeader("test"); + epNotificationItem.setMsgDescription("test"); + epNotificationItem.setMsgSource("test"); + + epNotificationItem.setPriority((long)1); + epNotificationItem.setCreatedId((long)1); + epNotificationItem.setNotificationHyperlink("test"); + + return epNotificationItem; + } + + @Test + public void epNotificationItemTest(){ + EpNotificationItem epNotificationItem = mockEpNotificationItem(); + + EpNotificationItem epNotificationItem1 = new EpNotificationItem(); + epNotificationItem1.setNotificationId((long)1); + epNotificationItem1.setIsForOnlineUsers("test"); + epNotificationItem1.setIsForAllRoles("test"); + epNotificationItem1.setActiveYn("test"); + epNotificationItem1.setMsgHeader("test"); + epNotificationItem1.setMsgDescription("test"); + epNotificationItem1.setMsgSource("test"); + + epNotificationItem1.setPriority((long)1); + epNotificationItem1.setCreatedId((long)1); + epNotificationItem1.setNotificationHyperlink("test"); + + assertEquals(epNotificationItem.getNotificationId(), new Long(1)); + assertEquals(epNotificationItem.getIsForOnlineUsers(), "test"); + assertEquals(epNotificationItem.getIsForAllRoles(), "test"); + assertEquals(epNotificationItem.getActiveYn(), "test"); + assertEquals(epNotificationItem.getMsgHeader(), "test"); + assertEquals(epNotificationItem.getMsgDescription(), "test"); + assertEquals(epNotificationItem.getMsgSource(), "test"); + assertEquals(epNotificationItem.getPriority(), new Long(1)); + assertEquals(epNotificationItem.getCreatedId(), new Long(1)); + assertEquals(epNotificationItem.getNotificationHyperlink(), "test"); + + assertEquals(epNotificationItem.toString(), "EpNotificationItem [notificationId=1, isForOnlineUsers=test, isForAllRoles=test, activeYn=test, msgHeader=test, msgDescription=test, msgSource=test, startTime=null, endTime=null, priority=1, creatorId=null, createdDate=null, roles=null, roleIds=null]"); + assertEquals(epNotificationItem.hashCode(), epNotificationItem1.hashCode()); + assertTrue(epNotificationItem.equals(epNotificationItem1)); + + } + +} + + diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemVOTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemVOTest.java new file mode 100644 index 00000000..61bc86f9 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpNotificationItemVOTest.java @@ -0,0 +1,83 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.EpNotificationItemVO; + +public class EpNotificationItemVOTest { + + public EpNotificationItemVO mockEpNotificationItemVO(){ + EpNotificationItemVO epNotificationItemVO = new EpNotificationItemVO(); + + epNotificationItemVO.setNotificationId(1); + epNotificationItemVO.setIsForOnlineUsers('a'); + epNotificationItemVO.setIsForAllRoles('a'); + epNotificationItemVO.setActiveYn('a'); + epNotificationItemVO.setMsgHeader("test"); + epNotificationItemVO.setMsgDescription("test"); + epNotificationItemVO.setMsgSource("test"); + epNotificationItemVO.setPriority(1); + epNotificationItemVO.setCreatorId(1); + epNotificationItemVO.setLoginId("test"); + epNotificationItemVO.setNotificationHyperlink("test"); + + return epNotificationItemVO; + } + + @Test + public void epNotificationItemVOTest(){ + EpNotificationItemVO epNotificationItemVO = mockEpNotificationItemVO(); + + assertEquals(epNotificationItemVO.getNotificationId().toString(), "1"); + /*assertEquals(epNotificationItemVO.getIsForOnlineUsers(), 'a'); + assertEquals(epNotificationItemVO.getIsForAllRoles(), 'a'); + assertEquals(epNotificationItemVO.getActiveYn(), 'a');*/ + assertEquals(epNotificationItemVO.getMsgHeader(), "test"); + assertEquals(epNotificationItemVO.getMsgDescription(), "test"); + assertEquals(epNotificationItemVO.getMsgSource(), "test"); + assertEquals(epNotificationItemVO.getPriority().toString(), "1"); + assertEquals(epNotificationItemVO.getCreatorId().toString(), "1"); + assertEquals(epNotificationItemVO.getLoginId(), "test"); + assertEquals(epNotificationItemVO.getNotificationHyperlink(), "test"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpRoleNotificationItemTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpRoleNotificationItemTest.java new file mode 100644 index 00000000..82592934 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/EpRoleNotificationItemTest.java @@ -0,0 +1,68 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.EpRoleNotificationItem; + +public class EpRoleNotificationItemTest { + + public EpRoleNotificationItem mockEpRoleNotificationItem(){ + EpRoleNotificationItem epRoleNotificationItem = new EpRoleNotificationItem(); + + epRoleNotificationItem.setId((long)1); + epRoleNotificationItem.setNotificationId((long)1); + epRoleNotificationItem.setRoleId(1); + epRoleNotificationItem.setRecvUserId(1); + + return epRoleNotificationItem; + } + + @Test + public void epRoleNotificationItemTest(){ + EpRoleNotificationItem epRoleNotificationItem = mockEpRoleNotificationItem(); + + assertEquals(epRoleNotificationItem.getId(), new Long(1)); + assertEquals(epRoleNotificationItem.getNotificationId(), new Long(1)); + assertEquals(epRoleNotificationItem.getRoleId().toString(), "1"); + assertEquals(epRoleNotificationItem.getRecvUserId().toString(), "1"); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessPermsDetailTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessPermsDetailTest.java new file mode 100644 index 00000000..f4f36d93 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessPermsDetailTest.java @@ -0,0 +1,76 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.ExternalAccessPermsDetail; + +public class ExternalAccessPermsDetailTest { + + public ExternalAccessPermsDetail mockExternalAccessPermsDetail(){ + ExternalAccessPermsDetail externalAccessPermsDetail = new ExternalAccessPermsDetail(); + + List roles = new ArrayList(); + + externalAccessPermsDetail.setType("test"); + externalAccessPermsDetail.setInstance("test"); + externalAccessPermsDetail.setAction("test"); + externalAccessPermsDetail.setDescription("test"); + externalAccessPermsDetail.setRoles(roles); + + return externalAccessPermsDetail; + } + + @Test + public void externalAccessPermsDetailTest(){ + ExternalAccessPermsDetail externalAccessPermsDetail = mockExternalAccessPermsDetail(); + + List roles = new ArrayList(); + + assertEquals(externalAccessPermsDetail.getType(), "test"); + assertEquals(externalAccessPermsDetail.getInstance(), "test"); + assertEquals(externalAccessPermsDetail.getAction(), "test"); + assertEquals(externalAccessPermsDetail.getDescription(), "test"); + assertEquals(externalAccessPermsDetail.getRoles(), roles); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessPermsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessPermsTest.java new file mode 100644 index 00000000..3392f2e6 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessPermsTest.java @@ -0,0 +1,79 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.ExternalAccessPerms; + +public class ExternalAccessPermsTest { + + public ExternalAccessPerms mockExternalAccessPerms(){ + ExternalAccessPerms externalAccessPerms = new ExternalAccessPerms(); + + externalAccessPerms.setType("test"); + externalAccessPerms.setInstance("test"); + externalAccessPerms.setAction("test"); + externalAccessPerms.setDescription("test"); + + return externalAccessPerms; + } + + @Test + public void externalAccessPermsTest(){ + ExternalAccessPerms externalAccessPerms = mockExternalAccessPerms(); + + ExternalAccessPerms externalAccessPerms1 = new ExternalAccessPerms("test", "test", "test"); + ExternalAccessPerms externalAccessPerms2 = new ExternalAccessPerms("test", "test", "test", "test"); + ExternalAccessPerms externalAccessPerms3 = new ExternalAccessPerms(); + externalAccessPerms3.setType("test"); + externalAccessPerms3.setInstance("test"); + externalAccessPerms3.setAction("test"); + externalAccessPerms3.setDescription("test"); + + assertEquals(externalAccessPerms.getType(), "test"); + assertEquals(externalAccessPerms.getInstance(), "test"); + assertEquals(externalAccessPerms.getAction(), "test"); + assertEquals(externalAccessPerms.getDescription(), "test"); + assertEquals(externalAccessPerms.hashCode(), externalAccessPerms3.hashCode()); + + assertTrue(externalAccessPerms1.equals(new ExternalAccessPerms("test", "test", "test"))); + assertTrue(externalAccessPerms2.equals(new ExternalAccessPerms("test", "test", "test", "test"))); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessRolePermsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessRolePermsTest.java new file mode 100644 index 00000000..5e78c9cf --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessRolePermsTest.java @@ -0,0 +1,72 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.ExternalAccessPerms; +import org.onap.portalapp.portal.transport.ExternalAccessRolePerms; + +public class ExternalAccessRolePermsTest { + + public ExternalAccessRolePerms mockExternalAccessRolePerms(){ + ExternalAccessPerms externalAccessPerms = new ExternalAccessPerms(); + externalAccessPerms.setAction("test"); + externalAccessPerms.setDescription("test"); + externalAccessPerms.setInstance("test"); + externalAccessPerms.setType("test"); + ExternalAccessRolePerms ExternalAccessRolePerms = new ExternalAccessRolePerms(externalAccessPerms, "test"); + + return ExternalAccessRolePerms; + } + + @Test + public void externalAccessRolePermsTest(){ + ExternalAccessPerms externalAccessPerms = new ExternalAccessPerms(); + externalAccessPerms.setAction("test"); + externalAccessPerms.setDescription("test"); + externalAccessPerms.setInstance("test"); + externalAccessPerms.setType("test"); + + ExternalAccessRolePerms ExternalAccessRolePerms = mockExternalAccessRolePerms(); + + assertEquals(ExternalAccessRolePerms.getRole(), "test"); + assertEquals(ExternalAccessRolePerms.getPerm(), externalAccessPerms); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessRoleTest.java new file mode 100644 index 00000000..cf00f2be --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessRoleTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.ExternalAccessRole; + +public class ExternalAccessRoleTest { + + public ExternalAccessRole mockExternalAccessRole(){ + ExternalAccessRole externalAccessRole = new ExternalAccessRole(); + + externalAccessRole.setName("test"); + externalAccessRole.setDescription("test"); + + return externalAccessRole; + } + + @Test + public void externalAccessRoleTest(){ + ExternalAccessRole externalAccessRole = mockExternalAccessRole(); + + assertEquals(externalAccessRole.getName(), "test"); + assertEquals(externalAccessRole.getDescription(), "test"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java new file mode 100644 index 00000000..0229ece4 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserRoleDetailTest.java @@ -0,0 +1,84 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.ExternalAccessUserRoleDetail; +import org.onap.portalapp.portal.transport.ExternalRoleDescription; + +public class ExternalAccessUserRoleDetailTest { + + public ExternalAccessUserRoleDetail mockExternalAccessUserRoleDetail(){ + + ExternalRoleDescription externalRoleDescription = new ExternalRoleDescription(); + externalRoleDescription.setId("test"); + externalRoleDescription.setName("test"); + externalRoleDescription.setActive("test"); + externalRoleDescription.setPriority("test"); + externalRoleDescription.setAppId("test"); + externalRoleDescription.setAppRoleId("test"); + + ExternalAccessUserRoleDetail externalAccessUserRoleDetail = new ExternalAccessUserRoleDetail("test", externalRoleDescription); + + externalAccessUserRoleDetail.setName("test"); + externalAccessUserRoleDetail.setDescription(externalRoleDescription); + return externalAccessUserRoleDetail; + } + + @Test + public void externalAccessUserRoleDetailTest(){ + ExternalAccessUserRoleDetail externalAccessUserRoleDetail = mockExternalAccessUserRoleDetail(); + + ExternalRoleDescription externalRoleDescription1 = new ExternalRoleDescription(); + externalRoleDescription1.setId("test"); + externalRoleDescription1.setName("test"); + externalRoleDescription1.setActive("test"); + externalRoleDescription1.setPriority("test"); + externalRoleDescription1.setAppId("test"); + externalRoleDescription1.setAppRoleId("test"); + + ExternalAccessUserRoleDetail externalAccessUserRoleDetail1 = new ExternalAccessUserRoleDetail("test", externalRoleDescription1); + + assertEquals(externalAccessUserRoleDetail.getName(), externalAccessUserRoleDetail1.getName()); + assertEquals(externalAccessUserRoleDetail.getDescription(), externalAccessUserRoleDetail1.getDescription()); + assertEquals(externalAccessUserRoleDetail.hashCode(), externalAccessUserRoleDetail1.hashCode()); + assertTrue(externalAccessUserRoleDetail.equals(externalAccessUserRoleDetail1)); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserTest.java new file mode 100644 index 00000000..81504056 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalAccessUserTest.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.portal.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.ExternalAccessUser; + +public class ExternalAccessUserTest { + + public ExternalAccessUser mockExternalAccessUser(){ + ExternalAccessUser externalAccessUser = new ExternalAccessUser("test", "test"); + + return externalAccessUser; + } + + @Test + public void externalAccessUserTest(){ + ExternalAccessUser externalAccessUser = mockExternalAccessUser(); + + assertEquals(externalAccessUser.getRole(), "test"); + assertEquals(externalAccessUser.getUser(), "test"); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRoleDescriptionTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRoleDescriptionTest.java new file mode 100644 index 00000000..616f86a2 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/ExternalRoleDescriptionTest.java @@ -0,0 +1,72 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.ExternalRoleDescription; + +public class ExternalRoleDescriptionTest { + + public ExternalRoleDescription mockExternalRoleDescription(){ + + ExternalRoleDescription externalRoleDescription = new ExternalRoleDescription(); + + externalRoleDescription.setId("test"); + externalRoleDescription.setName("test"); + externalRoleDescription.setActive("test"); + externalRoleDescription.setPriority("test"); + externalRoleDescription.setAppId("test"); + externalRoleDescription.setAppRoleId("test"); + + return externalRoleDescription; + } + + @Test + public void externalRoleDescriptionTest(){ + ExternalRoleDescription externalRoleDescription = mockExternalRoleDescription(); + + assertEquals(externalRoleDescription.getId(), "test"); + assertEquals(externalRoleDescription.getName(), "test"); + assertEquals(externalRoleDescription.getActive(), "test"); + assertEquals(externalRoleDescription.getPriority(), "test"); + assertEquals(externalRoleDescription.getAppId(), "test"); + assertEquals(externalRoleDescription.getAppRoleId(), "test"); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/FunctionalMenuItemTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/FunctionalMenuItemTest.java new file mode 100644 index 00000000..518c78d3 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/FunctionalMenuItemTest.java @@ -0,0 +1,79 @@ +/*- + * ============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.transport; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.FunctionalMenuItem; + +public class FunctionalMenuItemTest { + + public FunctionalMenuItem mockFunctionalMenuItem(){ + FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem(); + + List roles = new ArrayList(); + + functionalMenuItem.setRestrictedApp(false); + functionalMenuItem.setUrl("test"); + functionalMenuItem.setRoles(roles); + + return functionalMenuItem; + } + + @Test + public void functionalMenuItemTest(){ + FunctionalMenuItem functionalMenuItem = mockFunctionalMenuItem(); + + FunctionalMenuItem functionalMenuItem1 = mockFunctionalMenuItem(); + + List roles = new ArrayList(); + + functionalMenuItem1.setRestrictedApp(false); + functionalMenuItem1.setUrl("test"); + functionalMenuItem1.setRoles(roles); + + assertEquals(functionalMenuItem.getRoles(), functionalMenuItem1.getRoles()); + assertEquals(functionalMenuItem.toString(), "FunctionalMenuItem [menuId=null, column=null, text=null, parentMenuId=null, url=test, active_yn=null, appid=null, roles=[], restrictedApp=false]"); + // assertTrue(functionalMenuItem.normalize(), functionalMenuItem1.normalize()); + } + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/FunctionalMenuRoleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/FunctionalMenuRoleTest.java new file mode 100644 index 00000000..b48867c3 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/FunctionalMenuRoleTest.java @@ -0,0 +1,77 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.FunctionalMenuRole; + +public class FunctionalMenuRoleTest { + + public FunctionalMenuRole mockFunctionalMenuRole(){ + FunctionalMenuRole functionalMenuRole = new FunctionalMenuRole(); + + functionalMenuRole.setId(1); + functionalMenuRole.setMenuId((long)1); + functionalMenuRole.setAppId(1); + functionalMenuRole.setRoleId(1); + + return functionalMenuRole; + } + + @Test + public void functionalMenuRoleTest(){ + FunctionalMenuRole functionalMenuRole = mockFunctionalMenuRole(); + + FunctionalMenuRole functionalMenuRole1 = new FunctionalMenuRole(); + functionalMenuRole1.setId(1); + functionalMenuRole1.setMenuId((long)1); + functionalMenuRole1.setAppId(1); + functionalMenuRole1.setRoleId(1); + + assertEquals(functionalMenuRole.getId().toString(), "1"); + assertEquals(functionalMenuRole.getMenuId(), new Long(1)); + assertEquals(functionalMenuRole.getAppId().toString(), "1"); + assertEquals(functionalMenuRole.getRoleId().toString(), "1"); + assertEquals(functionalMenuRole.toString(), "FunctionalMenuRole [id=1, menuId=1, appId=1, roleId=1]"); + assertTrue(functionalMenuRole.equals(functionalMenuRole1)); + assertEquals(functionalMenuRole.hashCode(), functionalMenuRole1.hashCode()); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteUserWithRolesTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteUserWithRolesTest.java new file mode 100644 index 00000000..aa2f48e0 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RemoteUserWithRolesTest.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.transport; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.RemoteRole; +import org.onap.portalapp.portal.transport.RemoteUserWithRoles; + +public class RemoteUserWithRolesTest { + + public RemoteUserWithRoles mockRemoteUserWithRoles(){ + RemoteUserWithRoles remoteUserWithRoles = new RemoteUserWithRoles(); + + List roles = new ArrayList(); + RemoteRole remoteRole = new RemoteRole(); + remoteRole.setId((long)1); + remoteRole.setName("test"); + roles.add(remoteRole); + + remoteUserWithRoles.setOrgId((long)1); + remoteUserWithRoles.setManagerId((long)1); + remoteUserWithRoles.setFirstName("test"); + remoteUserWithRoles.setMiddleInitial("test"); + remoteUserWithRoles.setLastName("test"); + remoteUserWithRoles.setPhone("test"); + remoteUserWithRoles.setEmail("test"); + remoteUserWithRoles.setHrid("test"); + remoteUserWithRoles.setOrgUserId("test"); + remoteUserWithRoles.setOrgCode("test"); + remoteUserWithRoles.setOrgManagerUserId("test"); + remoteUserWithRoles.setJobTitle("test"); + remoteUserWithRoles.setLoginId("test"); + remoteUserWithRoles.setActive(false); + remoteUserWithRoles.setRoles(roles); + + return remoteUserWithRoles; + } + + @Test + public void remoteUserWithRolesTest(){ + RemoteUserWithRoles remoteUserWithRoles = mockRemoteUserWithRoles(); + + assertEquals(remoteUserWithRoles.getOrgId(), new Long(1)); + assertEquals(remoteUserWithRoles.getManagerId(), new Long(1)); + assertEquals(remoteUserWithRoles.getFirstName(), "test"); + assertEquals(remoteUserWithRoles.getMiddleInitial(), "test"); + assertEquals(remoteUserWithRoles.getLastName(), "test"); + assertEquals(remoteUserWithRoles.getPhone(), "test"); + assertEquals(remoteUserWithRoles.getEmail(), "test"); + assertEquals(remoteUserWithRoles.getHrid(), "test"); + assertEquals(remoteUserWithRoles.getOrgUserId(), "test"); + assertEquals(remoteUserWithRoles.getOrgCode(), "test"); + assertEquals(remoteUserWithRoles.getOrgManagerUserId(), "test"); + assertEquals(remoteUserWithRoles.getJobTitle(), "test"); + assertEquals(remoteUserWithRoles.getLoginId(), "test"); + assertEquals(remoteUserWithRoles.getActive(), false); + assertEquals(remoteUserWithRoles.getRoles().size(), 1); + assertEquals(remoteUserWithRoles.toString(), "RemoteUserWithRoles [orgId=1, managerId=1, firstName=test, middleInitial=test, lastName=test, phone=test, " + + "email=test, hrid=test, orgUserId=test, orgCode=test, orgManagerUserId=test, jobTitle=test, loginId=test, active=false, roles=[RemoteRole [id=1, name=test]]]"); + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RoleInAppForUserTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RoleInAppForUserTest.java new file mode 100644 index 00000000..51d18472 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/RoleInAppForUserTest.java @@ -0,0 +1,74 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.RoleInAppForUser; + +public class RoleInAppForUserTest { + + public RoleInAppForUser mockRoleInAppForUser(){ + RoleInAppForUser roleInAppForUser = new RoleInAppForUser((long)1 , "test"); + roleInAppForUser.setRoleId((long)1); + roleInAppForUser.setRoleName("test"); + roleInAppForUser.setIsApplied(false); + + return roleInAppForUser; + } + + @Test + public void roleInAppForUserTest(){ + RoleInAppForUser roleInAppForUser = mockRoleInAppForUser(); + + RoleInAppForUser roleInAppForUser1 = new RoleInAppForUser((long)1 , "test"); + roleInAppForUser1.setRoleId((long)1); + roleInAppForUser1.setRoleName("test"); + roleInAppForUser1.setIsApplied(false); + + assertEquals(roleInAppForUser.getRoleId(), new Long(1)); + assertEquals(roleInAppForUser.getRoleName(), "test"); + assertEquals(roleInAppForUser.getIsApplied(), false); + + assertEquals(roleInAppForUser.toString(), "RoleInAppForUser [roleId=1, roleName=test, isApplied=false]"); + assertTrue(roleInAppForUser.equals(roleInAppForUser1)); + assertEquals(roleInAppForUser.hashCode(), roleInAppForUser1.hashCode()); + //constructor + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/UserApplicationRolesTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/UserApplicationRolesTest.java new file mode 100644 index 00000000..33596265 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/UserApplicationRolesTest.java @@ -0,0 +1,95 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.RemoteRole; +import org.onap.portalapp.portal.transport.UserApplicationRoles; + +public class UserApplicationRolesTest { + + public UserApplicationRoles mockUserApplicationRoles(){ + UserApplicationRoles userApplicationRoles = new UserApplicationRoles(); + + List roles = new ArrayList(); + RemoteRole remoteRole = new RemoteRole(); + remoteRole.setId((long)1); + remoteRole.setName("test"); + roles.add(remoteRole); + + userApplicationRoles.setAppId((long)1); + userApplicationRoles.setOrgUserId("test"); + userApplicationRoles.setFirstName("test"); + userApplicationRoles.setLastName("test"); + userApplicationRoles.setRoles(roles); + + return userApplicationRoles; + } + + @Test + public void userApplicationRolesTest(){ + UserApplicationRoles userApplicationRoles = mockUserApplicationRoles(); + + UserApplicationRoles userApplicationRoles1 = new UserApplicationRoles(); + + List roles = new ArrayList(); + RemoteRole remoteRole = new RemoteRole(); + remoteRole.setId((long)1); + remoteRole.setName("test"); + roles.add(remoteRole); + + userApplicationRoles1.setAppId((long)1); + userApplicationRoles1.setOrgUserId("test"); + userApplicationRoles1.setFirstName("test"); + userApplicationRoles1.setLastName("test"); + userApplicationRoles1.setRoles(roles); + + assertEquals(userApplicationRoles.getAppId(), userApplicationRoles1.getAppId()); + assertEquals(userApplicationRoles.getOrgUserId(), userApplicationRoles1.getOrgUserId()); + assertEquals(userApplicationRoles.getFirstName(), userApplicationRoles1.getFirstName()); + assertEquals(userApplicationRoles.getLastName(), userApplicationRoles1.getLastName()); + assertEquals(userApplicationRoles.getRoles(), userApplicationRoles1.getRoles()); + + + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/UserWithNameSurnameTitleTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/UserWithNameSurnameTitleTest.java new file mode 100644 index 00000000..3c8e6ce7 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/UserWithNameSurnameTitleTest.java @@ -0,0 +1,56 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.UserWithNameSurnameTitle; + +public class UserWithNameSurnameTitleTest { + + @Test + public void userWithNameSurnameTitleTest(){ + + UserWithNameSurnameTitle userWithNameSurnameTitle = new UserWithNameSurnameTitle("test", "test", "test", "test"); + + assertEquals(userWithNameSurnameTitle, new UserWithNameSurnameTitle("test", "test", "test", "test")); + assertEquals(userWithNameSurnameTitle.hashCode(), new UserWithNameSurnameTitle("test", "test", "test", "test").hashCode()); + assertTrue(userWithNameSurnameTitle.equals(new UserWithNameSurnameTitle("test", "test", "test", "test"))); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/WidgetCatalogPersonalizationTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/WidgetCatalogPersonalizationTest.java new file mode 100644 index 00000000..77e9cdb3 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/transport/WidgetCatalogPersonalizationTest.java @@ -0,0 +1,62 @@ +/*- + * ============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.transport; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.portalapp.portal.transport.WidgetCatalogPersonalization; + +public class WidgetCatalogPersonalizationTest { + + public WidgetCatalogPersonalization mockWidgetCatalogPersonalization(){ + WidgetCatalogPersonalization widgetCatalogPersonalization = new WidgetCatalogPersonalization(); + + widgetCatalogPersonalization.setWidgetId((long)1); + widgetCatalogPersonalization.setSelect(false); + return widgetCatalogPersonalization; + } + + @Test + public void widgetCatalogPersonalizationTest(){ + WidgetCatalogPersonalization widgetCatalogPersonalization = mockWidgetCatalogPersonalization(); + + assertEquals(widgetCatalogPersonalization.getWidgetId(), new Long(1)); + assertEquals(widgetCatalogPersonalization.getSelect(), false); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java new file mode 100644 index 00000000..efc1dab1 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/utils/EcompPortalUtilsTest.java @@ -0,0 +1,56 @@ +/*- + * ============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 legitimateAttuidSuccessTest() { + assertEquals(true, EcompPortalUtils.legitimateUserId("mm016f")); + } + + @Test + public void legitimateAttuidFailureTest() { + assertEquals(false, EcompPortalUtils.legitimateUserId("1#@23456")); + } +} -- cgit 1.2.3-korg