From f51a3e2b128f0b96bc9ed67dfc3081f4b41d1303 Mon Sep 17 00:00:00 2001 From: "Kishore Reddy, Gujja (kg811t)" Date: Fri, 8 Jun 2018 16:40:16 -0400 Subject: Junit Test Cases & Raptors Issue-ID: PORTAL-273. PORTAL-301 Covered JUNITS for sdk modules and RAPTOR reports fixes Change-Id: Ifaf3bf06f0ec123051a791cc8e7f10662f97a525 Signed-off-by: Kishore Reddy, Gujja (kg811t) --- .gitignore | 2 +- ecomp-sdk/epsdk-aaf/pom.xml | 35 +- .../authorization/domain/ExternalAccessPerms.java | 2 +- .../domain/ExternalAccessPermsDetail.java | 2 +- .../authorization/domain/ExternalAccessRole.java | 2 +- .../domain/ExternalAccessRolePerms.java | 2 +- .../authorization/domain/ExternalAccessUser.java | 2 +- .../domain/ExternalAccessUserRoleDetail.java | 2 +- .../authorization/domain/ExternalAuthUserRole.java | 2 +- .../domain/ExternalRoleDescription.java | 2 +- .../exception/UserNotFoundException.java | 2 +- .../service/LoginExternalAuthService.java | 2 +- .../service/LoginExternalAuthServiceImpl.java | 4 +- .../authorization/service/UserApiService.java | 2 +- .../authorization/service/UserApiServiceImpl.java | 46 +- .../util/EcompExternalAuthProperties.java | 2 +- .../authorization/util/EcompExternalAuthUtils.java | 6 +- .../domain/ExternalAccessPermsDetailTest.java | 94 + .../domain/ExternalAccessPermsTest.java | 86 + .../domain/ExternalAccessRolePermsTest.java | 68 + .../domain/ExternalAccessRoleTest.java | 59 + .../domain/ExternalAccessUserRoleDetailTest.java | 99 + .../domain/ExternalAccessUserTest.java | 56 + .../domain/ExternalAuthUserRoleTest.java | 64 + .../domain/ExternalRoleDescriptionTest.java | 94 + .../service/LoginExternalAuthServiceImplTest.java | 185 ++ .../service/UserApiServiceImplTest.java | 313 ++ .../util/EcompExternalAuthPropertiesTest.java | 59 + .../util/EcompExternalAuthUtilsTest.java | 127 + .../external/framework/MockitoTestSuite.java | 94 + ecomp-sdk/epsdk-analytics/pom.xml | 2 +- .../portalsdk/analytics/gmap/line/LineInfo.java | 2 +- .../analytics/gmap/node/NodeCollection.java | 2 +- .../portalsdk/analytics/model/ReportLoader.java | 2 +- .../model/definition/ReportDefinition.java | 147 + .../model/definition/wizard/ColumnEditJSON.java | 103 + .../model/definition/wizard/DefinitionJSON.java | 83 +- .../model/definition/wizard/FormEditJSON.java | 17 +- .../model/definition/wizard/SearchFieldJSON.java | 7 + .../portalsdk/analytics/model/pdf/PageEvent.java | 22 - .../analytics/model/runtime/ChartD3Helper.java | 105 +- .../analytics/model/runtime/ReportRuntime.java | 1 + .../onap/portalsdk/analytics/system/Globals.java | 7 + .../system/fusion/web/RaptorControllerAsync.java | 248 +- .../controller/AbstractDummyController.java | 43 + .../analytics/controller/ActionHandlerTest.java | 1259 ++++++++ .../analytics/controller/ActionMappingTest.java | 70 + .../portalsdk/analytics/controller/ActionTest.java | 89 + .../analytics/controller/ControllerTest.java | 262 ++ .../analytics/controller/DummyController.java | 50 + .../analytics/controller/ErrorHandlerTest.java | 191 ++ .../controller/PrivateDummyController.java | 42 + .../controller/WizardSequenceCrossTabTest.java | 87 + .../controller/WizardSequenceDashboardTest.java | 82 + .../controller/WizardSequenceLinearTest.java | 87 + .../WizardSequenceSQLBasedCrossTabTest.java | 86 + .../controller/WizardSequenceSQLBasedHiveTest.java | 87 + ...WizardSequenceSQLBasedLinearDataminingTest.java | 88 + .../WizardSequenceSQLBasedLinearTest.java | 85 + .../analytics/controller/WizardSequenceTest.java | 78 + .../analytics/gmap/line/LineCollectionTest.java | 141 + .../analytics/gmap/line/LineInfoTest.java | 117 + .../portalsdk/analytics/gmap/line/LineTest.java | 48 +- .../analytics/gmap/map/ColorPropertiesTest.java | 93 + .../portalsdk/analytics/gmap/map/NovaMapTest.java | 148 + .../analytics/gmap/map/layer/SwingLayerTest.java | 112 + .../analytics/gmap/node/NodeCollectionTest.java | 122 + .../analytics/gmap/node/NodeInfoTest.java | 130 + .../portalsdk/analytics/gmap/node/NodeTest.java | 15 +- .../portalsdk/analytics/model/DataCacheTest.java | 328 +++ .../analytics/model/ReportHandlerTest.java | 3094 ++++++++++++++++---- .../model/base/ChartSeqComparatorTest.java | 66 + .../analytics/model/base/IdNameColLookupTest.java | 75 + .../analytics/model/base/IdNameListTest.java | 82 + .../analytics/model/base/IdNameLookupTest.java | 76 + .../analytics/model/base/IdNameSqlTest.java | 80 + .../analytics/model/base/IdNameValueTest.java | 69 + .../analytics/model/base/NameComparatorTest.java | 64 + .../model/base/OrderBySeqComparatorTest.java | 65 + .../model/base/OrderSeqComparatorTest.java | 64 + .../analytics/model/base/ReportSecurityTest.java | 105 + .../analytics/model/base/ReportUserRoleTest.java | 74 + .../model/definition/DBColumnInfoTest.java | 73 + .../model/definition/DrillDownParamDefTest.java | 62 + .../analytics/model/definition/MarkerTest.java | 79 + .../model/definition/ReportLogEntryTest.java | 75 + .../analytics/model/definition/ReportMapTest.java | 75 + .../model/definition/ReportScheduleTest.java | 454 ++- .../model/definition/SecurityEntryTest.java | 71 + .../analytics/model/definition/TableJoinTest.java | 71 + .../model/definition/TableSourceTest.java | 76 + .../definition/wizard/IdNameBooleanJSONTest.java | 2 +- .../model/definition/wizard/MessageJSONTest.java | 63 + .../model/definition/wizard/RaptorErrorTest.java | 67 + .../analytics/model/pdf/PageEventTest.java | 184 ++ .../portalsdk/analytics/model/pdf/PdfBeanTest.java | 113 + .../model/runtime/BarChartOptionsTest.java | 79 + .../model/runtime/ChartWebRuntimeTest.java | 117 + .../model/runtime/CommonChartOptionsTest.java | 81 + .../model/runtime/ErrorJSONRuntimeTest.java | 63 + .../runtime/FlexTimeSeriesChartOptionsTest.java | 64 + .../model/runtime/FormatProcessorTest.java | 82 + .../analytics/model/runtime/ItemTest.java | 63 + .../analytics/model/runtime/LookupDBInfoTest.java | 67 + .../analytics/model/runtime/RangeAxisJSONTest.java | 77 + .../model/runtime/RaptorControllerAsyncTest.java | 102 +- .../runtime/ReportParamDateValueParserTest.java | 67 + .../runtime/ReportParamValuesForPDFExcelTest.java | 133 + .../model/runtime/TimeSeriesChartOptionsTest.java | 73 + .../onap/portalsdk/analytics/util/UtilsTest.java | 192 ++ .../analytics/xmlobj/ActionHandlerTest.java | 547 ---- .../analytics/xmlobj/ChartJSONHelperTest.java | 15 +- .../analytics/xmlobj/PdfReportHandlerTest.java | 2164 +++++++++++++- .../analytics/xmlobj/ReportRuntimeTest.java | 689 ++++- .../analytics/xmlobj/ReportWrapperTest.java | 617 +++- ecomp-sdk/epsdk-app-common/pom.xml | 2 +- .../controller/core/AngularAdminController.java | 3 +- ecomp-sdk/epsdk-app-os/README.md | 1 + ecomp-sdk/epsdk-app-os/pom.xml | 2 +- ecomp-sdk/epsdk-app-overlay/pom.xml | 2 +- .../ds2-reports/report-chart-controller.js | 56 +- .../DS2-controllers/ds2-reports/report-router.js | 80 +- .../ds2-reports/report-run-controller.js | 99 +- .../ds2-reports/report-search-controller.js | 70 +- .../ds2-reports/report-step-controller.js | 1850 +++++------- .../ds2-raptor-report/raptorReportFactory.js | 79 + .../ds2-raptor-report/reportModalControllers.js | 423 +++ .../DS2-view-models/ds2-reports/all-reports.html | 9 +- .../ds2-reports/directive/dynamicform.js | 39 +- .../ds2-reports/modal/report-del-confirm.html | 38 +- .../modal/report-formfield-del-confirm.html | 37 +- .../modal/report-security-role-del-confirm.html | 39 +- .../modal/report-security-user-del-confirm.html | 38 +- .../modal/report-user-role-confirm-toggle.html | 41 +- .../ds2-reports/modal/report-wizard-col-edit.html | 338 ++- .../modal/report-wizard-formfield-edit.html | 253 +- .../modal/report-wizard-test-run-sql.html | 89 +- .../ds2-reports/report-chart-wizard.html | 1897 ++++++------ .../DS2-view-models/ds2-reports/report-run.html | 156 +- .../DS2-view-models/ds2-reports/report-search.html | 7 +- .../DS2-view-models/ds2-reports/report-step.html | 35 + .../DS2-view-models/ds2-reports/steps/step1.html | 213 ++ .../DS2-view-models/ds2-reports/steps/step2.html | 26 + .../DS2-view-models/ds2-reports/steps/step3.html | 34 + .../DS2-view-models/ds2-reports/steps/step4.html | 47 + .../DS2-view-models/ds2-reports/steps/step5.html | 172 ++ .../DS2-view-models/ds2-reports/steps/step6.html | 34 + .../DS2-view-models/ds2-reports/steps/step7.html | 16 + .../ds2-reports/wz_steps/json/step1.json | 22 +- ecomp-sdk/epsdk-core/pom.xml | 8 +- .../core/web/support/JsonMessageTest.java | 16 + .../core/web/support/MessagesListTest.java | 9 +- .../portalsdk/core/web/support/UserUtilsTest.java | 164 ++ ecomp-sdk/epsdk-domain/pom.xml | 4 +- ecomp-sdk/epsdk-fw/pom.xml | 2 +- ecomp-sdk/epsdk-music/pom.xml | 13 +- .../music/conf/EnableMuscicHttpSession.java | 2 +- .../music/conf/MusicSessionRepository.java | 2 +- .../onap/portalapp/music/model/RestResponse.java | 1 + .../onap/portalapp/music/util/MusicProperties.java | 1 - .../org/onap/portalapp/music/util/MusicUtil.java | 2 + .../conf/MusicSessionRepositoryHandlerTest.java | 103 + .../music/conf/MusicSessionRepositoryTest.java | 95 + .../portalapp/music/conf/MusicSessionTest.java | 262 ++ .../portalapp/music/model/RestResponseTest.java | 58 + .../portalapp/music/service/MusicServiceTest.java | 248 ++ .../portalapp/music/util/MusicPropertiesTest.java | 53 + .../onap/portalapp/music/util/MusicUtilTest.java | 145 + ecomp-sdk/epsdk-workflow/pom.xml | 2 +- ecomp-sdk/pom.xml | 2 +- 170 files changed, 20337 insertions(+), 3976 deletions(-) create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetailTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePermsTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRoleTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetailTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRoleTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescriptionTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImplTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthPropertiesTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtilsTest.java create mode 100644 ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/framework/MockitoTestSuite.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/AbstractDummyController.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionMappingTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ControllerTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/DummyController.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ErrorHandlerTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/PrivateDummyController.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceCrossTabTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceDashboardTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceLinearTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedCrossTabTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedHiveTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearDataminingTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineCollectionTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineInfoTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/ColorPropertiesTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/layer/SwingLayerTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeCollectionTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeInfoTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ChartSeqComparatorTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameColLookupTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameListTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameLookupTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameSqlTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameValueTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/NameComparatorTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderBySeqComparatorTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderSeqComparatorTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportSecurityTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportUserRoleTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DBColumnInfoTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DrillDownParamDefTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/MarkerTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportLogEntryTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportMapTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/SecurityEntryTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableJoinTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableSourceTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/MessageJSONTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/RaptorErrorTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PageEventTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PdfBeanTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/BarChartOptionsTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntimeTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/CommonChartOptionsTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ErrorJSONRuntimeTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FlexTimeSeriesChartOptionsTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FormatProcessorTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ItemTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/LookupDBInfoTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RangeAxisJSONTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParserTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamValuesForPDFExcelTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/TimeSeriesChartOptionsTest.java create mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java delete mode 100644 ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-services/ds2-raptor-report/reportModalControllers.js create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-step.html create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step1.html create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step2.html create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step3.html create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step4.html create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step5.html create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step6.html create mode 100644 ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step7.html create mode 100644 ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/UserUtilsTest.java create mode 100644 ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryHandlerTest.java create mode 100644 ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryTest.java create mode 100644 ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionTest.java create mode 100644 ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/model/RestResponseTest.java create mode 100644 ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/service/MusicServiceTest.java create mode 100644 ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/util/MusicPropertiesTest.java create mode 100644 ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/util/MusicUtilTest.java diff --git a/.gitignore b/.gitignore index c2996350..bc1a505b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ ecomp-sdk/*/null*.csv ecomp-sdk/*/null* ecomp-sdk/*/jacoco.exec ecomp-sdk/*/target -test.txt +test*.txt diff --git a/ecomp-sdk/epsdk-aaf/pom.xml b/ecomp-sdk/epsdk-aaf/pom.xml index cccfc833..f3d22f61 100644 --- a/ecomp-sdk/epsdk-aaf/pom.xml +++ b/ecomp-sdk/epsdk-aaf/pom.xml @@ -1,16 +1,18 @@ - + 4.0.0 org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT org.onap.portal.sdk epsdk-aaf - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT jar ONAP Portal SDK AAF Authorization @@ -49,6 +51,25 @@ eelf-core 1.0.0 + + + org.jacoco + org.jacoco.agent + ${jacoco.version} + runtime + + + junit + junit + 4.12 + test + + + org.mockito + mockito-core + 1.10.19 + test + org.springframework @@ -117,12 +138,6 @@ jackson-databind 2.6.3 - - junit - junit - 3.8.1 - test - @@ -154,7 +169,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.7.0 1.8 1.8 diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPerms.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPerms.java index 80956e64..a598a4c4 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPerms.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPerms.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.domain; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetail.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetail.java index fab7d2c0..47c613b0 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetail.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetail.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.domain; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRole.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRole.java index a14a4b5f..8c191181 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRole.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRole.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.domain; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePerms.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePerms.java index f38b2f9f..95b4f0c4 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePerms.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePerms.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.domain; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUser.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUser.java index 3ca88991..aafd9c1b 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUser.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUser.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.domain; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetail.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetail.java index 5106f387..929bd351 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetail.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetail.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.domain; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRole.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRole.java index 33e21f2c..67d83ff6 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRole.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRole.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.domain; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescription.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescription.java index d09db15d..68effb0c 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescription.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescription.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.domain; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/exception/UserNotFoundException.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/exception/UserNotFoundException.java index 8d15b44c..785bbf95 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/exception/UserNotFoundException.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/exception/UserNotFoundException.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.exception; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthService.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthService.java index 8f387f98..0ad02460 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthService.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthService.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.service; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImpl.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImpl.java index d2ccfc2e..173e9e7d 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImpl.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImpl.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.service; @@ -59,6 +59,7 @@ import org.onap.portalsdk.core.web.support.AppUtils; import org.onap.portalsdk.core.web.support.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service("loginExternalAuthService") public class LoginExternalAuthServiceImpl implements LoginExternalAuthService { @@ -79,6 +80,7 @@ public class LoginExternalAuthServiceImpl implements LoginExternalAuthService { @Override @SuppressWarnings("rawtypes") + @Transactional public LoginBean findUser(LoginBean bean, String menuPropertiesFilename, Map additionalParams, boolean matchPassword, HttpServletRequest request) throws Exception { diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/UserApiService.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/UserApiService.java index 6eb312b6..14aeaf5e 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/UserApiService.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/UserApiService.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.service; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImpl.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImpl.java index 8425f7da..fb320c17 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImpl.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImpl.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.service; @@ -207,28 +207,30 @@ public class UserApiServiceImpl implements UserApiService { role.setPriority(Integer.valueOf(roleDesc.getPriority())); } } - for (ExternalAccessPerms extPerm : roleDesc.getPermissions()) { - RoleFunction roleFunction = new RoleFunction(); - roleFunction.setCode(extPerm.getInstance()); - roleFunction.setAction(extPerm.getAction()); - if (extPerm.getDescription() != null - && EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { - roleFunction.setName(extPerm.getDescription()); - } else if (extPerm.getDescription() == null - && EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { - roleFunction.setName(extPerm.getType().substring(namespace.length() + 1) + "|" - + extPerm.getInstance() + "|" + extPerm.getAction()); - } else if (extPerm.getDescription() == null - && !EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { - roleFunction.setName( - extPerm.getType() + "|" + extPerm.getInstance() + "|" + extPerm.getAction()); + if (roleDesc.getPermissions() != null) { + for (ExternalAccessPerms extPerm : roleDesc.getPermissions()) { + RoleFunction roleFunction = new RoleFunction(); + roleFunction.setCode(extPerm.getInstance()); + roleFunction.setAction(extPerm.getAction()); + if (extPerm.getDescription() != null + && EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { + roleFunction.setName(extPerm.getDescription()); + } else if (extPerm.getDescription() == null + && EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { + roleFunction.setName(extPerm.getType().substring(namespace.length() + 1) + "|" + + extPerm.getInstance() + "|" + extPerm.getAction()); + } else if (extPerm.getDescription() == null + && !EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { + roleFunction.setName( + extPerm.getType() + "|" + extPerm.getInstance() + "|" + extPerm.getAction()); + } + if (EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { + roleFunction.setType(extPerm.getType().substring(namespace.length() + 1)); + } else { + roleFunction.setType(extPerm.getType()); + } + roleFunctions.add(roleFunction); } - if (EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) { - roleFunction.setType(extPerm.getType().substring(namespace.length() + 1)); - } else { - roleFunction.setType(extPerm.getType()); - } - roleFunctions.add(roleFunction); } } role.setRoleFunctions(roleFunctions); diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthProperties.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthProperties.java index a680a672..87d4c1fd 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthProperties.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthProperties.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.util; diff --git a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtils.java b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtils.java index 56b1527e..6f4ff29a 100644 --- a/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtils.java +++ b/ecomp-sdk/epsdk-aaf/src/main/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtils.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.portalsdk.external.authorization.util; @@ -44,7 +44,6 @@ import javax.xml.bind.DatatypeConverter; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.util.CipherUtil; import org.onap.portalsdk.core.util.SystemProperties; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -53,9 +52,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class EcompExternalAuthUtils { private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EcompExternalAuthUtils.class); - - @Autowired - CipherUtil cipherUtil; public static final String EXT_EMPTY_JSON_STRING = "{}"; public static final String EXT_ROLE_FIELD = "role"; diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetailTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetailTest.java new file mode 100644 index 00000000..43dcc827 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetailTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class ExternalAccessPermsDetailTest { + + public ExternalAccessPermsDetail mockExternalAccessPermsDetailTest() { + List roles = new ArrayList<>(); + roles.add("test_role"); + roles.add("test_role2"); + ExternalAccessPermsDetail mockExtPermsDetailTest = new ExternalAccessPermsDetail(); + mockExtPermsDetailTest.setAction("*"); + mockExtPermsDetailTest.setDescription("test_name"); + mockExtPermsDetailTest.setType("test_type"); + mockExtPermsDetailTest.setInstance("test_instance"); + mockExtPermsDetailTest.setRoles(roles); + return mockExtPermsDetailTest; + } + + @Test + public void externalAccessPermsDetailTest() { + List roles = new ArrayList<>(); + roles.add("test_role"); + roles.add("test_role2"); + ExternalAccessPermsDetail extPermsDetailTest = new ExternalAccessPermsDetail(); + ExternalAccessPermsDetail extPermsDetailTest2 = new ExternalAccessPermsDetail("test_type", "test_instance", "*", + "test_name"); + ExternalAccessPermsDetail extPermsDetailTest3 = new ExternalAccessPermsDetail("test_type", "test_instance", "*", + roles, "test_name"); + extPermsDetailTest.setAction("*"); + extPermsDetailTest.setDescription("test_name"); + extPermsDetailTest.setType("test_type"); + extPermsDetailTest.setInstance("test_instance"); + extPermsDetailTest.setRoles(roles); + assertEquals(extPermsDetailTest.getAction(), mockExternalAccessPermsDetailTest().getAction()); + assertEquals(extPermsDetailTest.getType(), mockExternalAccessPermsDetailTest().getType()); + assertEquals(extPermsDetailTest.getInstance(), mockExternalAccessPermsDetailTest().getInstance()); + assertEquals(extPermsDetailTest.getDescription(), mockExternalAccessPermsDetailTest().getDescription()); + assertEquals(extPermsDetailTest.getRoles(), mockExternalAccessPermsDetailTest().getRoles()); + assertEquals(extPermsDetailTest2.getAction(), mockExternalAccessPermsDetailTest().getAction()); + assertEquals(extPermsDetailTest2.getType(), mockExternalAccessPermsDetailTest().getType()); + assertEquals(extPermsDetailTest2.getInstance(), mockExternalAccessPermsDetailTest().getInstance()); + assertEquals(extPermsDetailTest2.getDescription(), mockExternalAccessPermsDetailTest().getDescription()); + assertEquals(extPermsDetailTest2.getRoles(), null); + assertEquals(extPermsDetailTest3.getAction(), mockExternalAccessPermsDetailTest().getAction()); + assertEquals(extPermsDetailTest3.getType(), mockExternalAccessPermsDetailTest().getType()); + assertEquals(extPermsDetailTest3.getInstance(), mockExternalAccessPermsDetailTest().getInstance()); + assertEquals(extPermsDetailTest3.getDescription(), mockExternalAccessPermsDetailTest().getDescription()); + assertEquals(extPermsDetailTest3.getRoles(), mockExternalAccessPermsDetailTest().getRoles()); + } + +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsTest.java new file mode 100644 index 00000000..0f3a65a5 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsTest.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class ExternalAccessPermsTest { + + public ExternalAccessPerms mockExternalAccessPermsTest() { + ExternalAccessPerms mockExtPermsTest = new ExternalAccessPerms(); + mockExtPermsTest.setAction("*"); + mockExtPermsTest.setDescription("test_name"); + mockExtPermsTest.setType("test_type"); + mockExtPermsTest.setInstance("test_instance"); + return mockExtPermsTest; + } + + @Test + public void externalAccessPermsTest() { + List roles = new ArrayList<>(); + roles.add("test_role"); + roles.add("test_role2"); + ExternalAccessPerms extPermsDetailTest = new ExternalAccessPerms(); + ExternalAccessPerms extPermsDetailTest2 = new ExternalAccessPerms("test_type", "test_instance", "*"); + ExternalAccessPerms extPermsDetailTest3 = new ExternalAccessPerms("test_type", "test_instance", "*", + "test_name"); + extPermsDetailTest.setAction("*"); + extPermsDetailTest.setDescription("test_name"); + extPermsDetailTest.setType("test_type"); + extPermsDetailTest.setInstance("test_instance"); + assertEquals(extPermsDetailTest.getAction(), mockExternalAccessPermsTest().getAction()); + assertEquals(extPermsDetailTest.getType(), mockExternalAccessPermsTest().getType()); + assertEquals(extPermsDetailTest.getInstance(), mockExternalAccessPermsTest().getInstance()); + assertEquals(extPermsDetailTest.getDescription(), mockExternalAccessPermsTest().getDescription()); + assertEquals(extPermsDetailTest2.getAction(), mockExternalAccessPermsTest().getAction()); + assertEquals(extPermsDetailTest2.getType(), mockExternalAccessPermsTest().getType()); + assertEquals(extPermsDetailTest2.getInstance(), mockExternalAccessPermsTest().getInstance()); + assertEquals(null, extPermsDetailTest2.getDescription()); + assertEquals(extPermsDetailTest3.getAction(), mockExternalAccessPermsTest().getAction()); + assertEquals(extPermsDetailTest3.getType(), mockExternalAccessPermsTest().getType()); + assertEquals(extPermsDetailTest3.getInstance(), mockExternalAccessPermsTest().getInstance()); + assertEquals(extPermsDetailTest3.getDescription(), mockExternalAccessPermsTest().getDescription()); + assertEquals(true, new ExternalAccessPerms("test_type", "test_instance", "*", "test_name") + .equals(new ExternalAccessPerms("test_type", "test_instance", "*", "test_name"))); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePermsTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePermsTest.java new file mode 100644 index 00000000..acb14c65 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePermsTest.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ExternalAccessRolePermsTest { + + public ExternalAccessRolePerms mockExternalAccessRolePermsTest() { + ExternalAccessPerms mockPerm = new ExternalAccessPerms(); + mockPerm.setAction("*"); + mockPerm.setDescription("test_name"); + mockPerm.setType("test_type"); + mockPerm.setInstance("test_instance"); + ExternalAccessRolePerms mockExtRolePermsTest = new ExternalAccessRolePerms(mockPerm, "test_role"); + return mockExtRolePermsTest; + } + + @Test + public void externalAccessRolePermsTest() { + ExternalAccessPerms perm = new ExternalAccessPerms(); + perm.setAction("*"); + perm.setDescription("test_name"); + perm.setType("test_type"); + perm.setInstance("test_instance"); + ExternalAccessRolePerms mockExtRolePermsTest = new ExternalAccessRolePerms(perm, "test_role"); + assertEquals(mockExtRolePermsTest.getRole(), mockExternalAccessRolePermsTest().getRole()); + assertEquals(mockExtRolePermsTest.getPerm(), mockExternalAccessRolePermsTest().getPerm()); + } + +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRoleTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRoleTest.java new file mode 100644 index 00000000..aa498aa0 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRoleTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ExternalAccessRoleTest { + + public ExternalAccessRole mockExternalAccessRoleTest() { + ExternalAccessRole mockRole = new ExternalAccessRole(); + mockRole.setName("test_role"); + mockRole.setDescription("test_role_description"); + return mockRole; + } + + @Test + public void externalAccessRolePermsTest() { + ExternalAccessRole role = new ExternalAccessRole("test_role", "test_role_description"); + assertEquals(role.getName(), mockExternalAccessRoleTest().getName()); + assertEquals(role.getDescription(), mockExternalAccessRoleTest().getDescription()); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetailTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetailTest.java new file mode 100644 index 00000000..5e750543 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetailTest.java @@ -0,0 +1,99 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class ExternalAccessUserRoleDetailTest { + + public ExternalAccessUserRoleDetail mockExternalAccessUserRoleDetailTest() { + List mockPerms = new ArrayList<>(); + ExternalAccessPerms mockExtPermsTest = new ExternalAccessPerms(); + mockExtPermsTest.setAction("*"); + mockExtPermsTest.setDescription("test_name"); + mockExtPermsTest.setType("test_type"); + mockExtPermsTest.setInstance("test_instance"); + mockPerms.add(mockExtPermsTest); + ExternalRoleDescription mockRoleDesc = new ExternalRoleDescription(); + mockRoleDesc.setActive("true"); + mockRoleDesc.setAppId("1"); + mockRoleDesc.setAppRoleId("1"); + mockRoleDesc.setId("1"); + mockRoleDesc.setPriority("1"); + mockRoleDesc.setName("test"); + mockRoleDesc.setPermissions(mockPerms); + ExternalAccessUserRoleDetail mockExtUserRoleDetailTest = new ExternalAccessUserRoleDetail(); + mockExtUserRoleDetailTest.setName("test"); + mockExtUserRoleDetailTest.setDescription(mockRoleDesc); + return mockExtUserRoleDetailTest; + } + + @Test + public void externalAccessPermsTest() { + List perms = new ArrayList<>(); + ExternalAccessPerms extPermsTest = new ExternalAccessPerms(); + extPermsTest.setAction("*"); + extPermsTest.setDescription("test_name"); + extPermsTest.setType("test_type"); + extPermsTest.setInstance("test_instance"); + perms.add(extPermsTest); + ExternalRoleDescription roleDesc = new ExternalRoleDescription(); + roleDesc.setActive("true"); + roleDesc.setAppId("1"); + roleDesc.setAppRoleId("1"); + roleDesc.setId("1"); + roleDesc.setPriority("1"); + roleDesc.setName("test"); + roleDesc.setPermissions(perms); + ExternalAccessUserRoleDetail extUserRoleDetailTest = new ExternalAccessUserRoleDetail(); + extUserRoleDetailTest.setName("test"); + extUserRoleDetailTest.setDescription(roleDesc); + ExternalAccessUserRoleDetail extUserRoleDetailTest2 = new ExternalAccessUserRoleDetail("test", roleDesc); + assertEquals(extUserRoleDetailTest.getName(), mockExternalAccessUserRoleDetailTest().getName()); + assertEquals(extUserRoleDetailTest.getDescription(), mockExternalAccessUserRoleDetailTest().getDescription()); + assertEquals(extUserRoleDetailTest2.getName(), mockExternalAccessUserRoleDetailTest().getName()); + assertEquals(extUserRoleDetailTest2.getDescription(), mockExternalAccessUserRoleDetailTest().getDescription()); + assertEquals(true, new ExternalAccessUserRoleDetail("test",roleDesc) + .equals(new ExternalAccessUserRoleDetail("test",roleDesc))); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserTest.java new file mode 100644 index 00000000..18909b74 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserTest.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ExternalAccessUserTest { + + public ExternalAccessUser mockExternalAccessUserTest() { + return new ExternalAccessUser("test", "test123"); + } + + @Test + public void externalAccessUserTest() { + ExternalAccessUser extUserTest = new ExternalAccessUser("test", "test123"); + assertEquals(extUserTest.getUser(), mockExternalAccessUserTest().getUser()); + assertEquals(extUserTest.getRole(), mockExternalAccessUserTest().getRole()); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRoleTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRoleTest.java new file mode 100644 index 00000000..c295a537 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRoleTest.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ExternalAuthUserRoleTest { + + public ExternalAuthUserRole mockExternalAccessUserTest() { + ExternalAuthUserRole mockExtAuthUserRole = new ExternalAuthUserRole(); + mockExtAuthUserRole.setUser("test123"); + mockExtAuthUserRole.setRole("test"); + mockExtAuthUserRole.setExpiryDate("1/1/1111"); + return mockExtAuthUserRole; + } + + @Test + public void externalAuthUserRoleTest() { + ExternalAuthUserRole extAuthUserRole = new ExternalAuthUserRole(); + extAuthUserRole.setUser("test123"); + extAuthUserRole.setRole("test"); + extAuthUserRole.setExpiryDate("1/1/1111"); + assertEquals(extAuthUserRole.getRole(), mockExternalAccessUserTest().getRole()); + assertEquals(extAuthUserRole.getUser(), mockExternalAccessUserTest().getUser()); + assertEquals(extAuthUserRole.getExpiryDate(), mockExternalAccessUserTest().getExpiryDate()); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescriptionTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescriptionTest.java new file mode 100644 index 00000000..251f8303 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescriptionTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class ExternalRoleDescriptionTest { + + public ExternalRoleDescription mockExternalRoleDescriptionTest() { + List mockPerms = new ArrayList<>(); + ExternalAccessPerms mockExtPermsTest = new ExternalAccessPerms(); + mockExtPermsTest.setAction("*"); + mockExtPermsTest.setDescription("test_name"); + mockExtPermsTest.setType("test_type"); + mockExtPermsTest.setInstance("test_instance"); + mockPerms.add(mockExtPermsTest); + ExternalRoleDescription mockExtRoleDesc = new ExternalRoleDescription(); + mockExtRoleDesc.setActive("true"); + mockExtRoleDesc.setAppRoleId("1"); + mockExtRoleDesc.setAppId("1"); + mockExtRoleDesc.setId("1"); + mockExtRoleDesc.setName("test"); + mockExtRoleDesc.setPermissions(mockPerms); + mockExtRoleDesc.setPriority("1"); + return mockExtRoleDesc; + } + + @Test + public void externalRoleDescriptionTest() { + List perms = new ArrayList<>(); + ExternalAccessPerms extPermsTest = new ExternalAccessPerms(); + extPermsTest.setAction("*"); + extPermsTest.setDescription("test_name"); + extPermsTest.setType("test_type"); + extPermsTest.setInstance("test_instance"); + perms.add(extPermsTest); + ExternalRoleDescription extRoleDesc = new ExternalRoleDescription(); + extRoleDesc.setActive("true"); + extRoleDesc.setAppRoleId("1"); + extRoleDesc.setAppId("1"); + extRoleDesc.setId("1"); + extRoleDesc.setName("test"); + extRoleDesc.setPermissions(perms); + extRoleDesc.setPriority("1"); + assertEquals(extRoleDesc.getActive(), mockExternalRoleDescriptionTest().getActive()); + assertEquals(extRoleDesc.getAppId(), mockExternalRoleDescriptionTest().getAppId()); + assertEquals(extRoleDesc.getAppRoleId(), mockExternalRoleDescriptionTest().getAppRoleId()); + assertEquals(extRoleDesc.getId(), mockExternalRoleDescriptionTest().getId()); + assertEquals(extRoleDesc.getName(), mockExternalRoleDescriptionTest().getName()); + assertEquals(extRoleDesc.getPriority(), mockExternalRoleDescriptionTest().getPriority()); + assertEquals(extRoleDesc.getPermissions(), mockExternalRoleDescriptionTest().getPermissions()); + assertEquals(true, extRoleDesc.equals(mockExternalRoleDescriptionTest())); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImplTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImplTest.java new file mode 100644 index 00000000..ae6eb975 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImplTest.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.service; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +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.onap.portalsdk.core.command.LoginBean; +import org.onap.portalsdk.core.domain.App; +import org.onap.portalsdk.core.domain.Role; +import org.onap.portalsdk.core.domain.RoleFunction; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.domain.UserApp; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.external.framework.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +@RunWith(PowerMockRunner.class) +@PrepareForTest({AppUtils.class, UserUtils.class, SystemProperties.class}) +public class LoginExternalAuthServiceImplTest { + + @InjectMocks + private LoginExternalAuthServiceImpl loginExternalAuthServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Mock + private UserApiService userApiService; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Before + public void setup() { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(UserUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + } + + private User userObj() { + User user = new User(); + user.setEmail("test@mail.com"); + user.setFirstName("Test_firstname"); + user.setHrid("test_hrid"); + user.setJobTitle("test_jobtitle"); + user.setLastName("test_lastname"); + user.setLoginId("test123"); + user.setOrgManagerUserId("test456"); + user.setMiddleInitial("test_middlename"); + user.setOrgCode("testcode"); + user.setOrgId(1l); + user.setOrgUserId("test123"); + user.setActive(true); + user.setLastLoginDate(new Date()); + RoleFunction roleFunction = new RoleFunction(); + roleFunction.setId(12L); + roleFunction.setName("Role Function"); + + Set roleFunctions = new TreeSet(); + roleFunctions.add(roleFunction); + + Role role = new Role(); + role.setName("Role"); + role.setActive(true); + role.setRoleFunctions(roleFunctions); + Set userApps = new TreeSet(); + UserApp userApp = new UserApp(); + userApp.setUserId(1L); + userApp.setApp(getApp()); + userApp.setRole(role); + userApps.add(userApp); + user.setUserApps(userApps); + return user; + } + + public App getApp() { + App app = new App(); + app.setId(new Long(1)); + app.setName("Default"); + return app; + } + + @Test + public void findUserTest() throws Exception { + LoginBean bean = new LoginBean(); + bean.setUserid("test123"); + Map additionalParams = new HashMap<>(); + User user = userObj(); + user.setId(1l); + List usersId = new ArrayList<>(); + usersId.add(user.getId()); + List users = new ArrayList<>(); + users.add(user); + Mockito.when(userApiService.getUser(bean.getUserid(), mockedRequest)).thenReturn(user); + Map params = new HashMap<>(); + params.put("orgUserId", "test123"); + Mockito.when(dataAccessService.executeNamedQuery("getUserIdByorgUserId", params, null)).thenReturn(usersId); + Map params2 = new HashMap<>(); + params.put("org_user_id", "test123"); + Mockito.when(dataAccessService.executeNamedQuery("getUserByOrgUserId", params2, new HashMap())).thenReturn(users); + LoginBean expected = loginExternalAuthServiceImpl.findUser(bean, "menu", additionalParams, mockedRequest); + assertNotNull(expected); + } + + @Test + public void findUserForNewUserTest() throws Exception { + LoginBean bean = new LoginBean(); + bean.setUserid("test123"); + Map additionalParams = new HashMap<>(); + User user = userObj(); + List usersId = new ArrayList<>(); + usersId.add(user.getId()); + List users = new ArrayList<>(); + users.add(user); + Mockito.when(userApiService.getUser(bean.getUserid(), mockedRequest)).thenReturn(user); + Map params = new HashMap<>(); + params.put("orgUserId", "test123"); + Mockito.when(dataAccessService.executeNamedQuery("getUserIdByorgUserId", params, null)).thenReturn(usersId); + Map params2 = new HashMap<>(); + params.put("org_user_id", "test123"); + Mockito.when(dataAccessService.executeNamedQuery("getUserByOrgUserId", params2, new HashMap())).thenReturn(null); + LoginBean expected = loginExternalAuthServiceImpl.findUser(bean, "menu", additionalParams, mockedRequest); + assertNotNull(expected); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java new file mode 100644 index 00000000..d93b03c1 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java @@ -0,0 +1,313 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.service; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +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.portalsdk.core.command.PostSearchBean; +import org.onap.portalsdk.core.command.support.SearchResult; +import org.onap.portalsdk.core.domain.App; +import org.onap.portalsdk.core.domain.Role; +import org.onap.portalsdk.core.domain.RoleFunction; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.domain.UserApp; +import org.onap.portalsdk.core.service.AppService; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.LdapService; +import org.onap.portalsdk.core.service.PostSearchService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.external.authorization.util.EcompExternalAuthProperties; +import org.onap.portalsdk.external.authorization.util.EcompExternalAuthUtils; +import org.onap.portalsdk.external.framework.MockitoTestSuite; +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.RestTemplate; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +@RunWith(PowerMockRunner.class) +@PrepareForTest({ EcompExternalAuthProperties.class, EcompExternalAuthUtils.class }) +public class UserApiServiceImplTest { + + private static final String APP_ID = "appId"; + + private static final String PRIORITY = "priority"; + + private static final String ACTIVE = "active"; + + private static final String ROLE_NAME = "name"; + + private static final String APP_ROLE_ID = "appRoleId"; + + private static final String ID = "id"; + + @InjectMocks + private UserApiServiceImpl UserApiServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Mock + private LoginExternalAuthService loginAAFService; + + @Mock + private LdapService ldapService; + + @Mock + private PostSearchService postSearchService; + + @Mock + private AppService appService; + + @Mock + RestTemplate template = new RestTemplate(); + + @Before + public void setup() throws Exception { + PowerMockito.mockStatic(EcompExternalAuthProperties.class); + PowerMockito.mockStatic(EcompExternalAuthUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_NAMESPACE)) + .thenReturn("com.test.app2"); + Mockito.when(EcompExternalAuthUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(new HttpHeaders()); + Mockito.when(EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_USER_DOMAIN)) + .thenReturn("@test.com"); + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + private User userObj() { + User user = new User(); + user.setEmail("test@mail.com"); + user.setFirstName("Test_firstname"); + user.setHrid("test_hrid"); + user.setJobTitle("test_jobtitle"); + user.setLastName("test_lastname"); + user.setLoginId("test123"); + user.setOrgManagerUserId("test456"); + user.setMiddleInitial("test_middlename"); + user.setOrgCode("testcode"); + user.setOrgId(1l); + user.setOrgUserId("test123"); + user.setActive(true); + user.setLastLoginDate(new Date()); + RoleFunction roleFunction = new RoleFunction(); + roleFunction.setId(12L); + roleFunction.setName("Role Function"); + + Set roleFunctions = new TreeSet(); + roleFunctions.add(roleFunction); + + Role role = new Role(); + role.setName("Role"); + role.setActive(true); + role.setRoleFunctions(roleFunctions); + Set userApps = new TreeSet(); + UserApp userApp = new UserApp(); + userApp.setUserId(1L); + userApp.setApp(getApp()); + userApp.setRole(role); + userApps.add(userApp); + user.setUserApps(userApps); + return user; + } + + public App getApp() { + App app = new App(); + app.setId(new Long(1)); + app.setName("Default"); + return app; + } + + @Test + public void getUserTest() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + Map roleDesc = new LinkedHashMap<>(); + roleDesc.put(ID, "1"); + roleDesc.put(ROLE_NAME, "test_role"); + roleDesc.put(ACTIVE, String.valueOf(true)); + roleDesc.put(PRIORITY, String.valueOf(1)); + roleDesc.put(APP_ID, String.valueOf(1)); + roleDesc.put(APP_ROLE_ID, String.valueOf(1l)); + String addDesc = mapper.writeValueAsString(roleDesc); + JSONObject mockJsonObjectRole = new JSONObject(); + JSONObject mockJsonObjectRole2 = new JSONObject(); + JSONObject mockJsonObjectRole3 = new JSONObject(); + JSONObject mockJsonObjectRole4 = new JSONObject(); + JSONObject mockJsonObjectRole5 = new JSONObject(); + JSONObject mockJsonObjectPerm1 = new JSONObject(); + JSONObject mockJsonObjectPerm2 = new JSONObject(); + mockJsonObjectPerm1.put("type", "com.test.app2.test_type"); + mockJsonObjectPerm1.put("instance", "test_instance"); + mockJsonObjectPerm1.put("action", "*"); + mockJsonObjectPerm2.put("type", "com.test.app.test_type2"); + mockJsonObjectPerm2.put("instance", "test_instance2"); + mockJsonObjectPerm2.put("action", "*"); + List permsList = new ArrayList<>(); + permsList.add(mockJsonObjectPerm1); + permsList.add(mockJsonObjectPerm2); + mockJsonObjectRole.put("name", "com.test.app2.test_role"); + mockJsonObjectRole2.put("name", "com.test.app2.test_role2"); + mockJsonObjectRole2.put("perms", permsList); + mockJsonObjectRole2.put("description", addDesc); + mockJsonObjectRole3.put("name", "com.test.app2.Account_Administrator"); + mockJsonObjectRole4.put("name", "com.test.app2.admin"); + mockJsonObjectRole5.put("name", "com.test.app2.owner"); + List userRolesList = new ArrayList<>(); + JSONObject mockJsonObjectFinalUserRole = new JSONObject(); + userRolesList.add(mockJsonObjectRole); + userRolesList.add(mockJsonObjectRole2); + userRolesList.add(mockJsonObjectRole3); + userRolesList.add(mockJsonObjectRole4); + userRolesList.add(mockJsonObjectRole5); + mockJsonObjectFinalUserRole.put("role", userRolesList); + Mockito.when(EcompExternalAuthUtils.isJSONValid(addDesc)).thenReturn(true); + ResponseEntity response = new ResponseEntity<>(mockJsonObjectFinalUserRole.toString(), HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), + Matchers.>any(), Matchers.eq(String.class))).thenReturn(response); + Mockito.when(EcompExternalAuthUtils.checkNameSpaceMatching(Matchers.anyString(), Matchers.anyString())) + .thenReturn(true); + Mockito.when(loginAAFService.findUserWithoutPwd("test123")).thenReturn(userObj()); + Mockito.when(appService.getApp(1l)).thenReturn(getApp()); + User actual = UserApiServiceImpl.getUser("test123", mockedRequest); + assertNotNull(actual); + } + + @Test + public void getNewUserNullExceptionTest() throws Exception { + JSONObject mockJsonObjectRole = new JSONObject(); + JSONObject mockJsonObjectRole2 = new JSONObject(); + JSONObject mockJsonObjectRole3 = new JSONObject(); + JSONObject mockJsonObjectPerm1 = new JSONObject(); + JSONObject mockJsonObjectPerm2 = new JSONObject(); + mockJsonObjectPerm1.put("type", "com.test.app2.test_type"); + mockJsonObjectPerm1.put("instance", "test_instance"); + mockJsonObjectPerm1.put("action", "*"); + mockJsonObjectPerm2.put("type", "com.test.app.test_type2"); + mockJsonObjectPerm2.put("instance", "test_instance2"); + mockJsonObjectPerm2.put("action", "*"); + List permsList = new ArrayList<>(); + permsList.add(mockJsonObjectPerm1); + permsList.add(mockJsonObjectPerm2); + mockJsonObjectRole.put("name", "com.test.app2.test_role"); + mockJsonObjectRole2.put("name", "com.test.app2.test_role2"); + mockJsonObjectRole2.put("perms", permsList); + mockJsonObjectRole3.put("name", "com.test.app2.Account_Administrator"); + List userRolesList = new ArrayList<>(); + JSONObject mockJsonObjectFinalUserRole = new JSONObject(); + userRolesList.add(mockJsonObjectRole); + userRolesList.add(mockJsonObjectRole2); + userRolesList.add(mockJsonObjectRole3); + mockJsonObjectFinalUserRole.put("role", userRolesList); + ResponseEntity response = new ResponseEntity<>(mockJsonObjectFinalUserRole.toString(), HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), + Matchers.>any(), Matchers.eq(String.class))).thenReturn(response); + Mockito.when(EcompExternalAuthUtils.checkNameSpaceMatching(Matchers.anyString(), Matchers.anyString())) + .thenReturn(true); + Mockito.when(loginAAFService.findUserWithoutPwd("test123")).thenReturn(null); + Mockito.when(appService.getApp(1l)).thenReturn(getApp()); + PostSearchBean postSearchBean = new PostSearchBean(); + postSearchBean.setOrgUserId("test123"); + SearchResult result = new SearchResult(); + result.add(userObj()); + Mockito.when(ldapService.searchPost(postSearchBean.getUser(), postSearchBean.getSortBy1(), + postSearchBean.getSortBy2(), postSearchBean.getSortBy3(), postSearchBean.getPageNo(), + postSearchBean.getNewDataSize(), 1)).thenReturn(result); + User user = UserApiServiceImpl.getUser("test123", mockedRequest); + assertNull(user); + } + + @Test + public void getRoleFunctionsTest() throws Exception { + JSONObject mockJsonObjectPerms = new JSONObject(); + JSONObject mockJsonObjectPerm1 = new JSONObject(); + JSONObject mockJsonObjectPerm2 = new JSONObject(); + JSONObject mockJsonObjectPerm3 = new JSONObject(); + mockJsonObjectPerm1.put("type", "com.test.app2.test_type"); + mockJsonObjectPerm1.put("instance", "test_instance"); + mockJsonObjectPerm1.put("action", "*"); + mockJsonObjectPerm2.put("type", "com.test.app2.test_type2"); + mockJsonObjectPerm2.put("instance", "test_instance2"); + mockJsonObjectPerm2.put("action", "*"); + mockJsonObjectPerm2.put("description", "test_name"); + mockJsonObjectPerm3.put("type", "com.test.app3.test_type3"); + mockJsonObjectPerm3.put("instance", "test_instance3"); + mockJsonObjectPerm3.put("action", "*"); + List permsList = new ArrayList<>(); + permsList.add(mockJsonObjectPerm1); + permsList.add(mockJsonObjectPerm2); + mockJsonObjectPerms.put("perm", permsList); + ResponseEntity response = new ResponseEntity<>(mockJsonObjectPerms.toString(), HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), + Matchers.>any(), Matchers.eq(String.class))).thenReturn(response); + List actual = UserApiServiceImpl.getRoleFunctions("test123"); + assertNotNull(actual); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthPropertiesTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthPropertiesTest.java new file mode 100644 index 00000000..24c19622 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthPropertiesTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.util; + +import static org.junit.Assert.assertNull; + +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Properties.class }) +public class EcompExternalAuthPropertiesTest { + + @Test + public void getPropertyTest() { + String actual = EcompExternalAuthProperties.getProperty("test"); + assertNull(actual); + } + +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtilsTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtilsTest.java new file mode 100644 index 00000000..b35a1cda --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtilsTest.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.util; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +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.http.HttpHeaders; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ EcompExternalAuthProperties.class, CipherUtil.class }) +public class EcompExternalAuthUtilsTest { + + public static final String EXT_EMPTY_JSON_STRING = "{}"; + public static final String EXT_ROLE_FIELD = "role"; + public static final String EXT_PERM_FIELD = "perm"; + public static final String EXT_PERM_FIELD_TYPE = "type"; + public static final String EXT_PERM_ACCESS = ".access"; + public static final String EXT_ROLE_FIELD_NAME = "name"; + public static final String EXT_NULL_VALUE = "null"; + public static final String EXT_FIELD_DESCRIPTION = "description"; + public static final String EXT_FIELD_PERMS = "perms"; + public static final String EXT_ROLE_FIELD_OWNER = ".owner"; + public static final String EXT_ROLE_FIELD_ADMIN = ".admin"; + + @Before + public void setup() { + PowerMockito.mockStatic(EcompExternalAuthProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_USER_NAME)) + .thenReturn("test_username"); + Mockito.when(EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_PASSWORD)) + .thenReturn("test_password"); + MockitoAnnotations.initMocks(this); + } + + @Test + public void base64encodeKeyForAAFBasicAuthTest() throws Exception { + Mockito.when( + CipherUtil.decryptPKC("test_password", SystemProperties.getProperty(SystemProperties.Decryption_Key))) + .thenReturn("test_decrypted_password"); + HttpHeaders actual = EcompExternalAuthUtils.base64encodeKeyForAAFBasicAuth(); + assertNotNull(actual); + } + + @Test(expected = NullPointerException.class) + public void base64encodeKeyForAAFBasicAuthDecryptPassExceptionTest() throws Exception { + Mockito.when( + CipherUtil.decryptPKC("test_password", SystemProperties.getProperty(SystemProperties.Decryption_Key))) + .thenThrow(new NullPointerException()); + EcompExternalAuthUtils.base64encodeKeyForAAFBasicAuth(); + } + + @Test + public void checkNameSpaceMatchingTest() throws Exception { + EcompExternalAuthUtils.checkNameSpaceMatching("com.test.app.role.name", "com.test.app.role"); + } + + @Test + public void checkNameSpaceNotMatchingTest() throws Exception { + PowerMockito.mockStatic(EcompExternalAuthProperties.class); + EcompExternalAuthUtils.checkNameSpaceMatching("com.test.app2.role.name", "com.test.app.role"); + } + + @Test + public void checkNameSpaceMatchingLengthTest() throws Exception { + EcompExternalAuthUtils.checkNameSpaceMatching("com.test.app2.role", "com.test.app2.role.test"); + } + + @Test + public void isJsonValidTest() { + boolean actual = EcompExternalAuthUtils.isJSONValid("{\"test\":\"test\"}"); + assertTrue(actual); + } + + @Test + public void isJsonValidFailTest() { + boolean actual = EcompExternalAuthUtils.isJSONValid("{\"test\":\"test\""); + assertFalse(actual); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/framework/MockitoTestSuite.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/framework/MockitoTestSuite.java new file mode 100644 index 00000000..adc1b27a --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/framework/MockitoTestSuite.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.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-sdk/epsdk-analytics/pom.xml b/ecomp-sdk/epsdk-analytics/pom.xml index bcf202d5..3a2fd1a2 100644 --- a/ecomp-sdk/epsdk-analytics/pom.xml +++ b/ecomp-sdk/epsdk-analytics/pom.xml @@ -5,7 +5,7 @@ org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineInfo.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineInfo.java index d8fa23e3..26f33a35 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineInfo.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/line/LineInfo.java @@ -72,12 +72,12 @@ public class LineInfo { public LineInfo clone() { LineInfo lineInfo = new LineInfo(nodeID1, nodeID2); + lineInfo.setLineID(lineID); lineInfo.geoCoordinate1.longitude = geoCoordinate1.longitude; lineInfo.geoCoordinate1.latitude = geoCoordinate1.latitude; lineInfo.geoCoordinate2.longitude = geoCoordinate2.longitude; lineInfo.geoCoordinate2.latitude = geoCoordinate2.latitude; lineInfo.setDescription(lineDescription); - lineInfo.setLineID(lineID); lineInfo.setLineType(lineType); lineInfo.setMoveable(moveable); lineInfo.setDeleteable(deleteable); diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/node/NodeCollection.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/node/NodeCollection.java index 86f85be2..5c3f938a 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/node/NodeCollection.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/gmap/node/NodeCollection.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportLoader.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportLoader.java index 378c6a87..66d6e965 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportLoader.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/ReportLoader.java @@ -583,7 +583,7 @@ public class ReportLoader extends org.onap.portalsdk.analytics.RaptorObject { String query = Globals.getLoadQuickLinks(); query = query.replace("[userID]", ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(),userID)); - query = query.replace("[roleList.toString()]", ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(),roleList.toString())); + query = query.replace("[roleList.toString()]", roleList.toString()); query = query.replace("[nvls(menuId)]", ESAPI.encoder().encodeForSQL( SecurityCodecUtil.getCodec(),nvls(menuId))); DataSet ds = DbUtils diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportDefinition.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportDefinition.java index 44a05512..72eb64b8 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportDefinition.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/ReportDefinition.java @@ -1422,6 +1422,153 @@ public class ReportDefinition extends ReportWrapper implements Serializable { resetCache(false); } // parseReportSQL + public void parseReportSQL(String sql, boolean storeInSession) throws RaptorException { + StringBuffer parsedSQL = new StringBuffer(); + + Vector updatedReportCols = new Vector(); + + curSQLParsePos = 0; + int lastParsePos = curSQLParsePos; + String lastToken = null; + String nextToken = getNextSQLParseToken(sql, true); + + String dbInfo = getDBInfo(); + boolean isCYMBALScript = false; + if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) { + try { + org.onap.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.onap.portalsdk.analytics.util.RemDbInfo(); + String dbType = remDbInfo.getDBType(dbInfo); + if (dbType.equals("DAYTONA") && !(nextToken.toUpperCase().equals("SELECT"))) { + isCYMBALScript = true; + } + } catch (Exception ex) { + throw new RaptorException(ex); + } + } + if ( isCYMBALScript == false ) { + while (nextToken.length() > 0) { + if (parsedSQL.length() == 0) { + if (nextToken.toUpperCase().equals("SELECT")) + parsedSQL.append("SELECT "); + else + throw new org.onap.portalsdk.analytics.error.ValidationException( + "The SQL must start with the SELECT keyword."); + } else if (nextToken.toUpperCase().equals("DISTINCT") + && parsedSQL.toString().equals("SELECT ")) { + parsedSQL.append("DISTINCT "); + } else if (nextToken.equals("*") + && (parsedSQL.toString().equals("SELECT ") || parsedSQL.toString().equals( + "SELECT DISTINCT "))) { + throw new org.onap.portalsdk.analytics.error.ValidationException( + "You cannot use \"SELECT *\". Please specify select columns/expressions."); + } else if (nextToken.toUpperCase().equals("FROM")) { + if (lastToken != null) { + updatedReportCols.add(getParseSQLDataColumn(lastToken, null, parsedSQL, + updatedReportCols, false)); + lastToken = null; + } + + parsedSQL.append(" \n"); + while (lastParsePos < sql.length() + && Character.isWhitespace(sql.charAt(lastParsePos))) + lastParsePos++; + parsedSQL.append(sql.substring(lastParsePos)); + break; + } else { + if (nextToken.charAt(nextToken.length() - 1) == ',') { + // The token ends with , + nextToken = nextToken.substring(0, nextToken.length() - 1); + + if (nextToken.length() == 0) { + if (lastToken != null) { + updatedReportCols.add(getParseSQLDataColumn(lastToken, null, + parsedSQL, updatedReportCols, false)); + lastToken = null; + } // else just comma => ignore it + } else { + if (lastToken != null) { + updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken, + parsedSQL, updatedReportCols, false)); + lastToken = null; + } else + updatedReportCols.add(getParseSQLDataColumn(nextToken, null, + parsedSQL, updatedReportCols, false)); + } + } else { + // The token doesn't end with , + if (lastToken == null) + lastToken = nextToken; + else { + String token = getNextSQLParseToken(sql, false); + if (!token.toUpperCase().equals("FROM")) + throw new org.onap.portalsdk.analytics.error.ValidationException( + "|FROM keyword or a comma expected after [" + nextToken + + "]."); + + updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken, + parsedSQL, updatedReportCols, false)); + lastToken = null; + } // else + } // else + } // else + + lastParsePos = curSQLParsePos; + nextToken = getNextSQLParseToken(sql, true); + } // while + } else { // if CYMBAL Script + curSQLParsePos = 0; + Pattern re = null; + Matcher matcher = null; + String extracted = null; + nextToken = getNextCYMBALSQLParseToken(sql,true); + while (nextToken.length() > 0) { + if (lastToken == null) lastToken = nextToken; + + if( lastToken.toUpperCase().startsWith("DO DISPLAY")) { + re = Pattern.compile("each(.*)\\[.(.*?)\\]"); //\\[(.*?)\\] + matcher = re.matcher(nextToken); + if (matcher.find()) { + extracted = matcher.group(); + re = Pattern.compile("\\[(.*?)\\]"); + matcher = re.matcher(nextToken); + if(matcher.find()) { + extracted = matcher.group(); + extracted = extracted.substring(1,extracted.length()-1); + StringTokenizer sToken = new StringTokenizer(extracted, ","); + while(sToken.hasMoreTokens()) { + String str1 = sToken.nextToken().trim().substring(1); + updatedReportCols.add(getParseSQLDataColumn("", str1, + new StringBuffer(""), updatedReportCols, true)); + } + } + + } + + } + lastToken = nextToken; + nextToken = getNextCYMBALSQLParseToken(sql, true); + } + + } + if (updatedReportCols.size() == 0) + throw new org.onap.portalsdk.analytics.error.ValidationException( + "The SQL statement must have at least one column in the SELECT clause."); + if (getDataSourceList().getDataSource().size() == 0) + addDataSourceType(new ObjectFactory(), "du0", "DUAL", "", "DUAL", null, null, null); + DataSourceType dst = (DataSourceType) getDataSourceList().getDataSource().get(0); + dst.getDataColumnList().getDataColumn().clear(); + + for (int i = 0; i < updatedReportCols.size(); i++) { + DataColumnType dct = (DataColumnType) updatedReportCols.get(i); + dct.setTableId(dst.getTableId()); + dct.setOrderSeq(i + 1); + dst.getDataColumnList().getDataColumn().add(dct); + } // for + if(storeInSession) + setReportSQL(parsedSQL.toString()); + resetCache(false); + } // parseReportSQL + private String getNextCYMBALSQLParseToken(String sql, boolean updateParsePos) { int braketCount = 0; boolean isInsideQuote = false; diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/ColumnEditJSON.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/ColumnEditJSON.java index e5fc94ae..3281eee7 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/ColumnEditJSON.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/ColumnEditJSON.java @@ -48,6 +48,14 @@ public class ColumnEditJSON implements WizardJSON { private String displayHeaderAlignment; private boolean sortable; private boolean visible; + private Integer displayWidth; + private Integer displayWidthInPixel; + private String colType; + private Integer groupByPos; + private Integer level; + private String dataType; + private String noWrap; + private Integer indentation; private String drilldownURL; private String drilldownParams; @@ -55,6 +63,13 @@ public class ColumnEditJSON implements WizardJSON { private String errorMessage; private String errorStackTrace; + private String depeondsOnForField; + private String subTotalCustomText; + private boolean hideRepeatedKey; + private Integer colspan; + private String displayName; + private String displayTotal; + public String getTabId() { return tabId; } @@ -133,5 +148,93 @@ public class ColumnEditJSON implements WizardJSON { public void setDrilldownType(String drilldownType) { this.drilldownType = drilldownType; } + + public Integer getDisplayWidth() { + return displayWidth; + } + public void setDisplayWidth(Integer displayWidth) { + this.displayWidth = displayWidth; + } + public Integer getDisplayWidthInPixel() { + return displayWidthInPixel; + } + public void setDisplayWidthInPixel(Integer displayWidthInPixel) { + this.displayWidthInPixel = displayWidthInPixel; + } + public Integer getGroupByPos() { + return groupByPos; + } + public void setGroupByPos(Integer groupByPos) { + this.groupByPos = groupByPos; + } + public Integer getLevel() { + return level; + } + public void setLevel(Integer level) { + this.level = level; + } + public String getDataType() { + return dataType; + } + public void setDataType(String dataType) { + this.dataType = dataType; + } + public String getNoWrap() { + return noWrap; + } + public void setNoWrap(String noWrap) { + this.noWrap = noWrap; + } + public Integer getIndentation() { + return indentation; + } + public void setIndentation(Integer indentation) { + this.indentation = indentation; + } + public String getColType() { + return colType; + } + public void setColType(String colType) { + this.colType = colType; + } + public String getDepeondsOnForField() { + return depeondsOnForField; + } + public void setDepeondsOnForField(String depeondsOnForField) { + this.depeondsOnForField = depeondsOnForField; + } + public String getSubTotalCustomText() { + return subTotalCustomText; + } + public void setSubTotalCustomText(String subTotalCustomText) { + this.subTotalCustomText = subTotalCustomText; + } + public boolean isHideRepeatedKey() { + return hideRepeatedKey; + } + public void setHideRepeatedKey(boolean hideRepeatedKey) { + this.hideRepeatedKey = hideRepeatedKey; + } + public Integer getColspan() { + return colspan; + } + public void setColspan(Integer colspan) { + this.colspan = colspan; + } + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + public String getDisplayTotal() { + return displayTotal; + } + public void setDisplayTotal(String displayTotal) { + this.displayTotal = displayTotal; + } + + + } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/DefinitionJSON.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/DefinitionJSON.java index 73ac97d8..47b1ef9e 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/DefinitionJSON.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/DefinitionJSON.java @@ -64,7 +64,15 @@ public class DefinitionJSON implements WizardJSON { private Integer numFormCols; private String reportTitle; private String reportSubTitle; - + private String oneTimeRec; + private String hourlyRec; + private String dailyRec; + private String dailyMFRec; + private String weeklyRec; + private String monthlyRec; + private String allowScheduler; + private String sizedByContent; + private String repDefType; @Override public String getTabName() { return tabName; @@ -246,7 +254,78 @@ public class DefinitionJSON implements WizardJSON { public void setReportSubTitle(String reportSubTitle) { this.reportSubTitle = reportSubTitle; } + + public String getOneTimeRec() { + return oneTimeRec; + } + + public void setOneTimeRec(String oneTimeRec) { + this.oneTimeRec = oneTimeRec; + } + + public String getHourlyRec() { + return hourlyRec; + } + + public void setHourlyRec(String hourlyRec) { + this.hourlyRec = hourlyRec; + } + + public String getDailyRec() { + return dailyRec; + } + + public void setDailyRec(String dailyRec) { + this.dailyRec = dailyRec; + } + + public String getDailyMFRec() { + return dailyMFRec; + } + + public void setDailyMFRec(String dailyMFRec) { + this.dailyMFRec = dailyMFRec; + } + + public String getWeeklyRec() { + return weeklyRec; + } + + public void setWeeklyRec(String weeklyRec) { + this.weeklyRec = weeklyRec; + } + + public String getMonthlyRec() { + return monthlyRec; + } + + public void setMonthlyRec(String monthlyRec) { + this.monthlyRec = monthlyRec; + } + + public String getAllowScheduler() { + return allowScheduler; + } + + public void setAllowScheduler(String allowScheduler) { + this.allowScheduler = allowScheduler; + } + + public String getSizedByContent() { + return sizedByContent; + } + + public void setSizedByContent(String sizedByContent) { + this.sizedByContent = sizedByContent; + } + + public String getRepDefType() { + return repDefType; + } + + public void setRepDefType(String repDefType) { + this.repDefType = repDefType; + } - } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/FormEditJSON.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/FormEditJSON.java index bc39006f..e8238534 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/FormEditJSON.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/FormEditJSON.java @@ -48,6 +48,7 @@ public class FormEditJSON implements WizardJSON { private String fieldName; private String fieldType; private boolean visible; + private boolean groupFormField; private String defaultValue; private String fieldDefaultSQL; private String fieldSQL; @@ -56,7 +57,7 @@ public class FormEditJSON implements WizardJSON { private String message; private String errorMessage; private String errorStackTrace; - + private Integer orderSeq; public String getMessage() { return message; @@ -145,5 +146,19 @@ public class FormEditJSON implements WizardJSON { public void setFieldSQL(String fieldSQL) { this.fieldSQL = fieldSQL; } + public boolean isGroupFormField() { + return groupFormField; + } + public void setGroupFormField(boolean groupFormField) { + this.groupFormField = groupFormField; + } + public Integer getOrderSeq() { + return orderSeq; + } + public void setOrderSeq(Integer orderSeq) { + this.orderSeq = orderSeq; + } + + } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/SearchFieldJSON.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/SearchFieldJSON.java index b3cfe243..f80ba993 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/SearchFieldJSON.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/definition/wizard/SearchFieldJSON.java @@ -41,6 +41,7 @@ public class SearchFieldJSON implements ElementJSON { private String id; private String name; + private Integer orderSeq; public String getId() { return id; } @@ -53,6 +54,12 @@ public class SearchFieldJSON implements ElementJSON { public void setName(String name) { this.name = name; } + public Integer getOrderSeq() { + return orderSeq; + } + public void setOrderSeq(Integer orderSeq) { + this.orderSeq = orderSeq; + } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PageEvent.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PageEvent.java index cfae1ab3..5ed8f9f6 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PageEvent.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PageEvent.java @@ -75,20 +75,6 @@ class PageEvent extends PdfPageEventHelper { public PageEvent(PdfBean pb) { this.pb = pb; } - - private int getWidthEntries(int howManyLogos){ - int widthEntries = 0; - - if(howManyLogos == 2) - widthEntries = 3; - else - if(howManyLogos == 1) - widthEntries = 2; - else - widthEntries = 0; - - return widthEntries; - } private int getHowManyLogos(){ int howManyLogos = 0; @@ -220,13 +206,6 @@ class PageEvent extends PdfPageEventHelper { table.addCell(new Paragraph(pb.getLeftFooter(), font)); } - private void addHeaderDummy(PdfPTable table, Font font) { - Font font1 = new Font(font); - font1.setSize(Globals.getPDFFooterFontSize()); - - table.addCell(new Paragraph("Header row", font1)); - } - private void addLogo(PdfPTable table, Font font, String imgSrc, int alignment, int absoluteSize) { Image img = null; @@ -243,7 +222,6 @@ class PageEvent extends PdfPageEventHelper { //log that the input file couldnt be loaded - } else{ - //img.scaleAbsolute(absoluteSize, absoluteSize); img.scalePercent(absoluteSize, absoluteSize); PdfPCell cell = new PdfPCell(img); cell.setBorderColor(Color.WHITE); diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java index 80860912..ec83ffbf 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java @@ -47,6 +47,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; +import java.util.GregorianCalendar; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -54,6 +55,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; +import java.util.TimeZone; import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -68,6 +70,7 @@ import org.onap.portalsdk.analytics.model.ReportHandler; import org.onap.portalsdk.analytics.model.base.ChartSeqComparator; import org.onap.portalsdk.analytics.system.AppUtils; import org.onap.portalsdk.analytics.system.ConnectionUtils; +import org.onap.portalsdk.analytics.system.Globals; import org.onap.portalsdk.analytics.util.AppConstants; import org.onap.portalsdk.analytics.util.DataSet; import org.onap.portalsdk.analytics.util.HtmlStripper; @@ -1804,6 +1807,9 @@ public class ChartD3Helper { } wholeScript.append(" .tickFormat(function(d) { \n"); + wholeScript.append(" var local_dt = new Date(); \n var utc = d + (local_dt.getTimezoneOffset() * 60000);\n"); + wholeScript.append(" var nd = new Date(utc + (3600000*"+getCurrentTimezoneOffset()+")); "); + if(formatFlag==DAYFLAG) wholeScript.append(" return d3.time.format('%m/%d/%Y')(new Date(d)) }); \n"); else if(formatFlag==HOURFLAG) @@ -3569,6 +3575,11 @@ public class ChartD3Helper { return title; } + public java.util.Date timezoneConversion(SimpleDateFormat sdf, String dateStr) { + // sdf.setTimeZone(TimeZone.getTimeZone("GMT")); + return sdf.parse(dateStr, new ParsePosition(0)); + } + public java.util.Date getDateFromDateStr(String dateStr) { SimpleDateFormat MMDDYYYYFormat = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat EEEMMDDYYYYFormat = new SimpleDateFormat("EEE, MM/dd/yyyy"); //2012-11-01 00:00:00 @@ -3619,117 +3630,142 @@ public class ChartD3Helper { int flagDate = 10; */ - date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYYYHHMMSSFormat, dateStr); if(date!=null) formatFlag = SECFLAG; if(date==null) { - date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = EEEMMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(EEEMMDDYYYYFormat, dateStr); if(date!=null) formatFlag = DAYOFTHEWEEKFLAG; } if(date==null) { - date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYYYHHMMFormat, dateStr); if(date!=null) formatFlag = MINFLAG; } if(date==null) { //MMDDYYYYHHFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYYYHHFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYYYHHFormat, dateStr); if(date!=null) formatFlag = HOURFLAG; } if(date==null) { - date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYYYFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0)); + //date = YYYYMMDDFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(YYYYMMDDFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = timestampFormat.parse(dateStr, new ParsePosition(0)); + //date = timestampFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(timestampFormat, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) { - date = timestampHrFormat.parse(dateStr, new ParsePosition(0)); + //date = timestampHrFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(timestampHrFormat, dateStr); if(date!=null) formatFlag = HOURFLAG; } if(date==null) { - date = timestampDayFormat.parse(dateStr, new ParsePosition(0)); + //date = timestampDayFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(timestampDayFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = MONYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MONYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MONYYYYFormat, dateStr); if(date!=null) formatFlag = MONTHFLAG; } if(date==null) { - date = MMYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MMYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMYYYYFormat, dateStr); if(date!=null) formatFlag = MONTHFLAG; } if(date==null) { - date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MMMMMDDYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMMMMDDYYYYFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MONTHYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MONTHYYYYFormat, dateStr); if(date!=null) formatFlag = MONTHFLAG; } if(date==null) { - date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + //date = YYYYMMDDHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(YYYYMMDDHHMMSSFormat, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) { - date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0)); + //date = YYYYMMDDHHMMFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(YYYYMMDDHHMMFormat, dateStr); if(date!=null) formatFlag = MINFLAG; } if(date==null) { - date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + //date = DDMONYYYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(DDMONYYYYHHMMSSFormat, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) { - date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + //date = DDMONYYYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(DDMONYYYYHHMMFormat, dateStr); if(date!=null) formatFlag = MINFLAG; } if(date==null) { - date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = DDMONYYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(DDMONYYYYFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYHHMMSSFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYHHMMSSFormat, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) { - date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYHHMMFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYHHMMFormat, dateStr); if(date!=null) formatFlag = MINFLAG; } if(date==null) { - date = MMDDYYFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYFormat, dateStr); if(date!=null) formatFlag = DAYFLAG; } if(date==null) { - date = timestampFormat1.parse(dateStr, new ParsePosition(0)); + //date = timestampFormat1.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(timestampFormat1, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) { - date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0)); + //date = MMDDYYYYHHMMZFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(MMDDYYYYHHMMZFormat, dateStr); if(date!=null) formatFlag = MINFLAG; } if(date==null) { - date = YYYYFormat.parse(dateStr, new ParsePosition(0)); + //date = YYYYFormat.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(YYYYFormat, dateStr); /* Some random numbers should not satisfy this year format. */ if(dateStr.length()>4) date = null; if(date!=null) formatFlag = YEARFLAG; } if(date==null) { - date = timestamp_W_dash.parse(dateStr, new ParsePosition(0)); + //date = timestamp_W_dash.parse(dateStr, new ParsePosition(0)); + date = timezoneConversion(timestamp_W_dash, dateStr); if(date!=null) formatFlag = SECFLAG; } if(date==null) @@ -4085,6 +4121,23 @@ public class ChartD3Helper { return valuesMap; - } + } + + public static int getCurrentTimezoneOffset() { + + TimeZone tz = TimeZone.getDefault(); + java.util.Calendar cal = GregorianCalendar.getInstance(tz); + int offsetInMillis = tz.getOffset(cal.getTimeInMillis()); + int hourOffset = Math.abs(offsetInMillis / 3600000) * 60; + boolean isDST = tz.inDaylightTime(new java.util.Date()); + if(isDST){ + hourOffset += 60; + } + int offset = hourOffset + Math.abs((offsetInMillis / 60000) % 60); + if (offsetInMillis > 0) + offset *= -1; + + return Globals.getTimezoneOffset(); + } } diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportRuntime.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportRuntime.java index 529790e9..bb99318f 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportRuntime.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ReportRuntime.java @@ -2895,6 +2895,7 @@ public List getMapMarkers(ReportData rd, org.onap.portalsdk.analytics.xmlobj.Rep reportJSONRuntime.setReportID(getReportID()); reportJSONRuntime.setReportName(getReportName()); reportJSONRuntime.setReportSubTitle(getReportSubTitle()); + reportJSONRuntime.setAllowEdit(isAllowEdit(request)); reportJSONRuntime.setNumFormCols(getNumFormColsAsInt()); ArrayList formFieldValues = new ArrayList(); ArrayList formFieldJSONList = new ArrayList(); diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/Globals.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/Globals.java index f0991e94..a1196808 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/Globals.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/Globals.java @@ -1530,6 +1530,13 @@ public class Globals extends org.onap.portalsdk.analytics.RaptorObject { } } + public static int getTimezoneOffset() { + try { + return Integer.parseInt(nvls(raptorProperties.getProperty("time_zone_offset"), new Integer(0).toString()).trim()); + } catch (Exception ex) { return 0;} + } + + //new method added to get the help message for schedule tab public static String getScheduleHelpMessage() { return nvls(raptorProperties.getProperty("schedule_help_text"),"").trim(); diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java index b2ce1b7d..e06a1765 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/web/RaptorControllerAsync.java @@ -66,9 +66,13 @@ import org.onap.portalsdk.analytics.error.RaptorRuntimeException; import org.onap.portalsdk.analytics.error.ReportSQLException; import org.onap.portalsdk.analytics.model.DataCache; import org.onap.portalsdk.analytics.model.ReportHandler; +import org.onap.portalsdk.analytics.model.ReportLoader; +import org.onap.portalsdk.analytics.model.base.IdNameList; import org.onap.portalsdk.analytics.model.base.IdNameValue; import org.onap.portalsdk.analytics.model.base.ReportUserRole; +import org.onap.portalsdk.analytics.model.definition.DrillDownParamDef; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; +import org.onap.portalsdk.analytics.model.definition.ReportLogEntry; import org.onap.portalsdk.analytics.model.definition.SecurityEntry; import org.onap.portalsdk.analytics.model.definition.wizard.ColumnEditJSON; import org.onap.portalsdk.analytics.model.definition.wizard.ColumnJSON; @@ -296,6 +300,20 @@ public class RaptorControllerAsync extends RestrictedBaseController { } } + @RequestMapping(value = "/report/wizard/drill_down_param/{parameter}", method = RequestMethod.GET, produces = "application/json") + public @ResponseBody List getDrillDownParamDef (@PathVariable("parameter") String parameter, HttpServletRequest request, HttpServletResponse response) + throws IOException, RaptorException { + List list = new ArrayList<>(); + String[] tmepArray = null; + if(parameter!=null){ + tmepArray = parameter.split("&"); + } + for(String str:tmepArray){ + list.add(new DrillDownParamDef(str)); + } + return list; + } + @RequestMapping(value = "/report/wizard/list_columns", method = RequestMethod.GET, produces = "application/json") public @ResponseBody ArrayList listColumns(HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException { @@ -307,7 +325,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { for (DataColumnType reportColumnType : reportColumnList) { columnJSON = new ColumnJSON(); columnJSON.setId(reportColumnType.getColId()); - columnJSON.setName(reportColumnType.getColName()); + columnJSON.setName(reportColumnType.getDisplayName()); listJSON.add(columnJSON); } return listJSON; @@ -375,6 +393,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { String fieldDisplay = fft.getFieldName(); fieldJSON.setId(fieldId); fieldJSON.setName(fieldDisplay); + fieldJSON.setOrderSeq(fft.getOrderBySeq()); listJSON.add(fieldJSON); } } @@ -501,20 +520,15 @@ public class RaptorControllerAsync extends RestrictedBaseController { fft.setFieldDefaultSQL(formEditJSON.getFieldDefaultSQL()); fft.setFieldSQL(formEditJSON.getFieldSQL()); fft.setValidationType(formEditJSON.getValidationType()); - + fft.setGroupFormField(formEditJSON.isGroupFormField()); + fft.setOrderBySeq(formEditJSON.getOrderSeq()); // clear predefined value - if (fft.getPredefinedValueList() != null) { - for (Iterator iter = fft.getPredefinedValueList().getPredefinedValue() - .iterator(); iter.hasNext();) - iter.remove(); - } - + PredefinedValueList predefinedValueList = new ObjectFactory().createPredefinedValueList(); + fft.setPredefinedValueList(predefinedValueList); + List predefList = formEditJSON.getPredefinedValueList(); if (predefList != null && predefList.size() > 0) { for (IdNameBooleanJSON item : predefList) { - PredefinedValueList predefinedValueList = new ObjectFactory() - .createPredefinedValueList(); - fft.setPredefinedValueList(predefinedValueList); fft.getPredefinedValueList().getPredefinedValue().add(item.getId()); } } @@ -540,6 +554,52 @@ public class RaptorControllerAsync extends RestrictedBaseController { return messageJSON; } + + @RequestMapping(value = "report/wizard/add_formfield_tab_data", method = RequestMethod.POST) + public @ResponseBody MessageJSON addFFTabWiseData(@RequestBody FormEditJSON formEditJSON, + HttpServletRequest request, HttpServletResponse response) throws IOException, RaptorException { + ReportDefinition rdef = null; + rdef = (ReportDefinition) request.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION); + + MessageJSON messageJSON = new MessageJSON(); + try { + if (rdef != null) { + FormEditJSON wizardJSON = new FormEditJSON(); + wizardJSON.setTabId("FormEdit"); + wizardJSON.setTabName("Form Edit"); + String fieldId =""; + if(rdef.getFormFieldList()==null || rdef.getFormFieldList().getFormField()==null || rdef.getFormFieldList().getFormField().size()==0) + fieldId = "ff1"; + else + fieldId = "ff"+(rdef.getFormFieldList().getFormField().size()+1); + FormFieldType currField = rdef.addFormFieldType(new ObjectFactory(), "", "", "", "", "", "", "", "", null, null, "",""); + currField.setFieldId(fieldId); + currField.setFieldName(formEditJSON.getFieldName()); + currField.setFieldType(formEditJSON.getFieldType()==null?null:formEditJSON.getFieldType()); + currField.setVisible(formEditJSON.isVisible()?"Y":"N"); + currField.setDefaultValue(formEditJSON.getDefaultValue()); + currField.setFieldDefaultSQL(formEditJSON.getFieldDefaultSQL()); + currField.setFieldSQL(formEditJSON.getFieldSQL()); + currField.setValidationType(formEditJSON.getValidationType()); + currField.setGroupFormField(formEditJSON.isGroupFormField()); + persistReportDefinition(request, rdef); + + messageJSON.setMessage("Success formfield Details of given report is saved in session."); + messageJSON.setAnyStacktrace(rdef.getReportID() + " is added to session and DB."); + + } else { + messageJSON.setMessage("Report Definition is not in session"); + messageJSON.setAnyStacktrace("Report Definition is not in session"); + + } + } catch (Exception ex) { + messageJSON.setMessage("Error occured while formfield details Tab"); + messageJSON.setAnyStacktrace(getStackTrace(ex)); + return messageJSON; + } + + return messageJSON; + } @RequestMapping(value = "report/wizard/save_col_tab_data", method = RequestMethod.POST) public @ResponseBody MessageJSON saveColTabWiseData(@RequestBody ColumnEditJSON columnEditJSON, @@ -558,6 +618,18 @@ public class RaptorControllerAsync extends RestrictedBaseController { // columnJSON = new ColumnJSON(); if (reportColumnType.getColId().equals(colId)) { reportColumnType.setColName(columnEditJSON.getColName()); + reportColumnType.setDependsOnFormField(columnEditJSON.getDepeondsOnForField()==null?"":columnEditJSON.getDepeondsOnForField()); + reportColumnType.setColType(columnEditJSON.getDataType()==null?"":columnEditJSON.getDataType()); + reportColumnType.setDbColName(columnEditJSON.getDataType()==null?"":columnEditJSON.getDataType()); + reportColumnType.setGroupByPos(columnEditJSON.getGroupByPos()); + reportColumnType.setSubTotalCustomText(columnEditJSON.getSubTotalCustomText()); + reportColumnType.setHideRepeatedKey(columnEditJSON.isHideRepeatedKey()); + reportColumnType.setLevel(columnEditJSON.getLevel()); + reportColumnType.setColspan(columnEditJSON.getColspan()); + reportColumnType.setDisplayName(columnEditJSON.getDisplayName()); + reportColumnType.setDisplayWidthInPxls(columnEditJSON.getDisplayWidthInPixel()==null?null:String.valueOf(columnEditJSON.getDisplayWidthInPixel())); + reportColumnType.setNowrap(columnEditJSON.getNoWrap()); + reportColumnType.setIndentation(columnEditJSON.getIndentation()); reportColumnType.setDisplayAlignment(columnEditJSON.getDisplayAlignment()); reportColumnType.setDisplayHeaderAlignment(columnEditJSON.getDisplayHeaderAlignment()); reportColumnType.setIsSortable(columnEditJSON.isSortable()); @@ -565,7 +637,9 @@ public class RaptorControllerAsync extends RestrictedBaseController { reportColumnType.setDrillDownURL(columnEditJSON.getDrilldownURL()); reportColumnType.setDrillDownParams(columnEditJSON.getDrilldownParams()); reportColumnType.setDrillDownType(columnEditJSON.getDrilldownType()); - + if(columnEditJSON.getDisplayTotal()!=null) + reportColumnType.setDisplayTotal(columnEditJSON.getDisplayTotal()); + } } @@ -650,22 +724,28 @@ public class RaptorControllerAsync extends RestrictedBaseController { rdef.setFormHelpText(formHelpText); Integer pageSize = definitionJSON.getPageSize(); - rdef.setPageSize(pageSize); + if(pageSize!=null) + rdef.setPageSize(pageSize); List menuIds = definitionJSON.getDisplayArea(); - for (IdNameBooleanJSON menuId : menuIds) { - if (menuId.isSelected()) { - rdef.setMenuID(menuId.getName()); - } + if(menuIds!=null){ + for (IdNameBooleanJSON menuId : menuIds) { + if (menuId.isSelected()) { + rdef.setMenuID(menuId.getName()); + } + } } + Boolean hideFormFieldsAfterRun = definitionJSON.getHideFormFieldsAfterRun(); - rdef.setHideFormFieldAfterRun(hideFormFieldsAfterRun); + rdef.setHideFormFieldAfterRun(hideFormFieldsAfterRun==null?false:hideFormFieldsAfterRun); Integer maxRowsInExcelCSVDownload = definitionJSON.getMaxRowsInExcelCSVDownload(); - rdef.setMaxRowsInExcelDownload(maxRowsInExcelCSVDownload); + if(maxRowsInExcelCSVDownload!=null) + rdef.setMaxRowsInExcelDownload(maxRowsInExcelCSVDownload); Integer frozenColumns = definitionJSON.getFrozenColumns(); - rdef.setFrozenColumns(frozenColumns); + if(frozenColumns!=null) + rdef.setFrozenColumns(frozenColumns); String dataGridAlign = definitionJSON.getDataGridAlign(); rdef.setDataGridAlign(dataGridAlign); String emptyMessage = definitionJSON.getEmptyMessage(); @@ -674,10 +754,11 @@ public class RaptorControllerAsync extends RestrictedBaseController { rdef.setDataContainerHeight(dataContainerHeight); String dataContainerWidth = definitionJSON.getDataContainerWidth(); rdef.setDataContainerWidth(dataContainerWidth); - boolean runtimeColSortDisabled = definitionJSON.getRuntimeColSortDisabled(); - rdef.setRuntimeColSortDisabled(runtimeColSortDisabled); + Boolean runtimeColSortDisabled = definitionJSON.getRuntimeColSortDisabled(); + rdef.setRuntimeColSortDisabled(runtimeColSortDisabled==null?false:runtimeColSortDisabled); Integer numFormCols = definitionJSON.getNumFormCols(); - rdef.setNumFormCols(Integer.toString(numFormCols)); + if(numFormCols!=null) + rdef.setNumFormCols(Integer.toString(numFormCols)); String reportTitle = definitionJSON.getReportTitle(); rdef.setReportTitle(reportTitle); String reportSubTitle = definitionJSON.getReportSubTitle(); @@ -685,24 +766,45 @@ public class RaptorControllerAsync extends RestrictedBaseController { List displayOptions = definitionJSON.getDisplayOptions(); StringBuffer displayOptionStr = new StringBuffer("NNNNNNN"); - for (NameBooleanJSON displayOption : displayOptions) { - if (displayOption.isSelected()) { - if (displayOption.getName().equals("HideFormFields")) { - displayOptionStr.setCharAt(0, 'Y'); - } else if (displayOption.getName().equals("HideChart")) { - displayOptionStr.setCharAt(1, 'Y'); - } else if (displayOption.getName().equals("HideReportData")) { - displayOptionStr.setCharAt(2, 'Y'); - } else if (displayOption.getName().equals("HideExcel")) { - displayOptionStr.setCharAt(5, 'Y'); - } else if (displayOption.getName().equals("HidePdf")) { - displayOptionStr.setCharAt(6, 'Y'); + if(displayOptions!=null){ + for (NameBooleanJSON displayOption : displayOptions) { + if (displayOption.isSelected()) { + if (displayOption.getName().equals("HideFormFields")) { + displayOptionStr.setCharAt(0, 'Y'); + } else if (displayOption.getName().equals("HideChart")) { + displayOptionStr.setCharAt(1, 'Y'); + } else if (displayOption.getName().equals("HideReportData")) { + displayOptionStr.setCharAt(2, 'Y'); + } else if (displayOption.getName().equals("HideExcel")) { + displayOptionStr.setCharAt(5, 'Y'); + } else if (displayOption.getName().equals("HidePdf")) { + displayOptionStr.setCharAt(6, 'Y'); + } } - } + } } - - rdef.setDisplayOptions(displayOptionStr.toString()); + + if(displayOptionStr!=null) + rdef.setDisplayOptions(displayOptionStr.toString()); + + if(definitionJSON.getAllowScheduler()!=null) + rdef.setAllowSchedule(definitionJSON.getAllowScheduler().equals("true")?"Y":"N"); + if(definitionJSON.getSizedByContent()!=null) + rdef.setSizedByContent(definitionJSON.getSizedByContent().equals("true")?"Y":"N"); + if(definitionJSON.getOneTimeRec()!=null) + rdef.setIsOneTimeScheduleAllowed(definitionJSON.getOneTimeRec().equals("true")?"Y":"N"); + if(definitionJSON.getHourlyRec()!=null) + rdef.setIsHourlyScheduleAllowed(definitionJSON.getHourlyRec().equals("true")?"Y":"N"); + if(definitionJSON.getDailyRec()!=null) + rdef.setIsDailyScheduleAllowed(definitionJSON.getDailyRec().equals("true")?"Y":"N"); + if(definitionJSON.getDailyMFRec()!=null) + rdef.setIsDailyMFScheduleAllowed(definitionJSON.getDailyMFRec().equals("true")?"Y":"N"); + if(definitionJSON.getWeeklyRec()!=null) + rdef.setIsWeeklyScheduleAllowed(definitionJSON.getWeeklyRec().equals("true")?"Y":"N"); + if(definitionJSON.getMonthlyRec()!=null) + rdef.setIsMonthlyScheduleAllowed(definitionJSON.getMonthlyRec().equals("true")?"Y":"N"); + } if (id.equals("Create")) { rdef.persistReport(request); @@ -779,7 +881,8 @@ public class RaptorControllerAsync extends RestrictedBaseController { wizardJSON.setFieldDefaultSQL(fft.getFieldDefaultSQL()); wizardJSON.setFieldSQL(fft.getFieldSQL()); wizardJSON.setValidationType(fft.getValidationType()); - + wizardJSON.setGroupFormField(fft.isGroupFormField()); + wizardJSON.setOrderSeq(fft.getOrderBySeq()); PredefinedValueList preDefined = fft.getPredefinedValueList(); if (preDefined != null) { @@ -847,7 +950,20 @@ public class RaptorControllerAsync extends RestrictedBaseController { reportColumnType.getDrillDownParams() == null ? "" : reportColumnType.getDrillDownParams()); wizardJSON.setDrilldownType( reportColumnType.getDrillDownType() == null ? "" : reportColumnType.getDrillDownType()); - + wizardJSON.setDataType(reportColumnType.getDbColType() == null ? "" :reportColumnType.getDbColType()); + wizardJSON.setGroupByPos(reportColumnType.getGroupByPos()); + wizardJSON.setLevel(reportColumnType.getLevel()); + wizardJSON.setDisplayWidth(reportColumnType.getDisplayWidth()); + wizardJSON.setNoWrap(reportColumnType.getNowrap() == null ? "" : reportColumnType.getNowrap()); + wizardJSON.setIndentation(reportColumnType.getIndentation()); + + wizardJSON.setDepeondsOnForField(reportColumnType.getDependsOnFormField() ==null?"":reportColumnType.getDependsOnFormField()); + wizardJSON.setSubTotalCustomText(reportColumnType.getSubTotalCustomText()==null?"":reportColumnType.getSubTotalCustomText()); + + wizardJSON.setHideRepeatedKey(reportColumnType.isHideRepeatedKey()==null?false:reportColumnType.isHideRepeatedKey()); + wizardJSON.setColspan(reportColumnType.getColspan()==null?null:reportColumnType.getColspan()); + wizardJSON.setDisplayName(reportColumnType.getDisplayName()); + wizardJSON.setDisplayTotal(reportColumnType.getDisplayTotal()); } } } else { @@ -905,6 +1021,17 @@ public class RaptorControllerAsync extends RestrictedBaseController { return wizardJSON; } + @RequestMapping(value = { "/report/wizard/retrieveTotalForTheColList" }, method = RequestMethod.GET) + public @ResponseBody List getTotalForTheCol(HttpServletRequest request) + throws IOException, RaptorException { + IdNameList idNameList = AppConstants.TOTAL_FUNCTIONS; + List list = new ArrayList<>(); + for(int i=0; i getReportUserList(HttpServletRequest request) throws IOException, RaptorException { @@ -1339,7 +1466,17 @@ public class RaptorControllerAsync extends RestrictedBaseController { wizardJSON.setNumFormCols((rdef != null) ? rdef.getNumFormColsAsInt() : 1); wizardJSON.setReportTitle((rdef != null) ? rdef.getReportTitle() : ""); wizardJSON.setReportSubTitle((rdef != null) ? rdef.getReportSubTitle() : ""); - + + /*Robert add*/ + wizardJSON.setOneTimeRec((rdef != null) ? rdef.getIsOneTimeScheduleAllowed() : "false"); + wizardJSON.setHourlyRec((rdef != null) ? rdef.getIsHourlyScheduleAllowed() : "false"); + wizardJSON.setDailyRec((rdef != null) ? rdef.getIsDailyScheduleAllowed() : "false"); + wizardJSON.setDailyMFRec((rdef != null) ? rdef.getIsDailyMFScheduleAllowed() : "false"); + wizardJSON.setWeeklyRec((rdef != null) ? rdef.getIsWeeklyScheduleAllowed() : "false"); + wizardJSON.setMonthlyRec((rdef != null) ? rdef.getIsMonthlyScheduleAllowed() : "false"); + wizardJSON.setAllowScheduler((rdef != null) ? rdef.getAllowSchedule() : "false"); + wizardJSON.setSizedByContent((rdef != null) ? rdef.getSizedByContentOption() : "false"); + wizardJSON.setRepDefType(rdef.getReportDefType()); } ObjectMapper mapper = new ObjectMapper(); @@ -1357,7 +1494,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { RaptorResponse raptorResponse = new RaptorResponse(); String sql = queryJSON.getQuery(); String jsonInString = ""; - + ServletContext servletContext = request.getSession().getServletContext(); if (!Globals.isSystemInitialized()) { Globals.initializeSystem(servletContext); @@ -1440,7 +1577,7 @@ public class RaptorControllerAsync extends RestrictedBaseController { QueryResultJSON queryResultJSON = new QueryResultJSON(); queryResultJSON.setQuery(queryJSON.getQuery()); String query = XSSFilter.filterRequestOnlyScript(queryJSON.getQuery()); - rdef.parseReportSQL(query); + rdef.parseReportSQL(query,validate); queryResultJSON.setQuery(query); int numColumns = ds.getColumnCount(); @@ -1548,6 +1685,23 @@ public class RaptorControllerAsync extends RestrictedBaseController { return raptorResponse; } + + + @RequestMapping(value = "/report/wizard/get_report_log/{reportID}", method = RequestMethod.GET) + public @ResponseBody ArrayList getLogs(@PathVariable("reportID") String reportId, HttpServletRequest request, + HttpServletResponse ReportLogEntry) throws IOException { + ArrayList arrayList = new ArrayList<>(); + try { + Vector v = ReportLoader.loadReportLogEntries(reportId); + for(ReportLogEntry r:v ){ + arrayList.add(r); + } + } catch (RaptorException e) { + logger.error(EELFLoggerDelegate.errorLogger, + "RaptorControllerAsync getLogs.", e); + } + return arrayList; + } @RequestMapping(value = "save_chart", method = RequestMethod.POST) public void reportChartReceive(@RequestBody ChartJSON chartJSON, HttpServletRequest request, @@ -1627,7 +1781,12 @@ public class RaptorControllerAsync extends RestrictedBaseController { dct.setChartSeq(-1); // if we set it to -1, means this range axis will not be included else dct.setChartSeq(++r); - dct.setColOnChart("0"); + + if (!dct.getColId().equals(domainAxis)) { + dct.setColOnChart("0"); + }else{ + dct.setChartSeq(-1); + } dct.setYAxis(rangeYAxis); // +"|"+dct.getColId()); dct.setChartGroup(rangeChartGroup); // +"|"+dct.getColId()); dct.setChartColor(rangeColor); @@ -1646,7 +1805,6 @@ public class RaptorControllerAsync extends RestrictedBaseController { } } - reportRuntime.setChartLeftAxisLabel(chartJSON.getPrimaryAxisLabel()); reportRuntime.setChartRightAxisLabel(chartJSON.getSecondaryAxisLabel()); diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/AbstractDummyController.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/AbstractDummyController.java new file mode 100644 index 00000000..9381f41c --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/AbstractDummyController.java @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +public abstract class AbstractDummyController { + +} + diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java new file mode 100644 index 00000000..71d3a1b5 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionHandlerTest.java @@ -0,0 +1,1259 @@ +package org.onap.portalsdk.analytics.controller; +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.whenNew; + +import java.io.IOException; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Vector; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.io.FilenameUtils; +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.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.DataCache; +import org.onap.portalsdk.analytics.model.ReportHandler; +import org.onap.portalsdk.analytics.model.ReportLoader; +import org.onap.portalsdk.analytics.model.SearchHandler; +import org.onap.portalsdk.analytics.model.base.IdNameColLookup; +import org.onap.portalsdk.analytics.model.base.IdNameList; +import org.onap.portalsdk.analytics.model.base.ReportWrapper; +import org.onap.portalsdk.analytics.model.definition.ReportDefinition; +import org.onap.portalsdk.analytics.model.definition.ReportSchedule; +import org.onap.portalsdk.analytics.model.runtime.ChartWebRuntime; +import org.onap.portalsdk.analytics.model.runtime.FormField; +import org.onap.portalsdk.analytics.model.runtime.ReportFormFields; +import org.onap.portalsdk.analytics.model.runtime.ReportJSONRuntime; +import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; +import org.onap.portalsdk.analytics.model.runtime.VisualManager; +import org.onap.portalsdk.analytics.model.search.ReportSearchResultJSON; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.ConnectionUtils; +import org.onap.portalsdk.analytics.system.DbUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.system.IAppUtils; +import org.onap.portalsdk.analytics.system.fusion.domain.QuickLink; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.util.Utils; +import org.onap.portalsdk.analytics.view.ReportData; +import org.onap.portalsdk.analytics.xmlobj.ChartAdditionalOptions; +import org.onap.portalsdk.analytics.xmlobj.CustomReportType; +import org.onap.portalsdk.analytics.xmlobj.DashboardReports; +import org.onap.portalsdk.analytics.xmlobj.DataColumnList; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; +import org.onap.portalsdk.analytics.xmlobj.DataSourceList; +import org.onap.portalsdk.analytics.xmlobj.DataSourceType; +import org.onap.portalsdk.analytics.xmlobj.FormFieldList; +import org.onap.portalsdk.analytics.xmlobj.FormFieldType; +import org.onap.portalsdk.analytics.xmlobj.FormatList; +import org.onap.portalsdk.analytics.xmlobj.FormatType; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.onap.portalsdk.analytics.xmlobj.Reports; +import org.onap.portalsdk.analytics.xmlobj.SemaphoreType; +import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum; +import org.onap.portalsdk.core.util.SecurityCodecUtil; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.owasp.esapi.ESAPI; +import org.owasp.esapi.Encoder; +import org.owasp.esapi.codecs.Codec; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ AppUtils.class, UserUtils.class, ESAPI.class, AppConstants.class, AlarmSeverityEnum.class, ReportWrapper.class, + ReportDefinition.class, SecurityCodecUtil.class, Globals.class, DbUtils.class, ReportLoader.class, ConnectionUtils.class, FilenameUtils.class, Utils.class, ReportRuntime.class, DataCache.class, ActionHandler.class}) +public class ActionHandlerTest { + + @InjectMocks + ActionHandler actionHandler = new ActionHandler(); + + @Mock + Connection connection; + @Mock + PreparedStatement stmt; + @Mock + ResultSet rs; + @Mock + java.sql.Clob clob; + @Mock + InputStream in; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + + @SuppressWarnings("unchecked") + @Test + public void reportRunTest_WhenReportTypeIsNotEqualToDashboard() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(ReportWrapper.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mock(AppConstants.class); + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); + when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = Mockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(DbUtils.getConnection()).thenReturn(connection); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); + when(rr.getReportID()).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); + when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); + String str = "namedesctypefalsefalseidfalse"; + when(connection.prepareStatement("1")).thenReturn(stmt); + when(stmt.executeQuery()).thenReturn(rs); + when(Globals.isWeblogicServer()).thenReturn(true); + when(rs.getClob(1)).thenReturn(clob); + when(rs.next()).thenReturn(true); + when(clob.getAsciiStream()).thenReturn(in); + when(in.read(Matchers.any())).thenReturn(1); + when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); + when(AppUtils.nvl("Y")).thenReturn("Y"); + when(AppUtils.nvl("bottom")).thenReturn("Y"); + when(AppUtils.nvl("test")).thenReturn("test|"); + when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); + when(ReportLoader.isDashboardType("-1")).thenReturn(false); + ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); + whenNew(ReportDefinition.class) + .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) + .thenReturn(rdf); + when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); + CustomReportType crType = Mockito.mock(CustomReportType.class); + when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); + when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); + when(Globals.getTimeFormat()).thenReturn("[reportID]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + when(set.getString(Matchers.anyInt(), Matchers.any(String.class))).thenReturn("test"); + when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + List formFieldTypeList = new ArrayList<>(); + formFieldTypeList.add(formFieldType); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + when(formFieldList.getFormField()).thenReturn(formFieldTypeList); + Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); + when(Globals.getRequestParams()).thenReturn("test,case"); + when( Globals.getSessionParams()).thenReturn("test,abc"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + + DataSourceList dataSourceList = new DataSourceList(); + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + //dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + //dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + when(rr.getReportFormFields()).thenReturn(reportFormFields); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + Enumeration enums; + Vector attrs = new Vector(); + attrs.add("ff_test"); + enums = attrs.elements(); + when(rr.getParamKeys()).thenReturn(enums); + + DashboardReports daashBoard = Mockito.mock(DashboardReports.class); + when(rdf.getDashBoardReports()).thenReturn(daashBoard); + when(daashBoard.getReportsList()).thenReturn(new ArrayList()); + String testHTML = "
[Report#123][Report#124]
[Report#125][Report#126]
"; + when(rr.getDashboardLayoutHTML()).thenReturn(testHTML); + when(rr.getReportType()).thenReturn("test"); + when(mockedRequest.getParameter("refresh")).thenReturn("N"); + when(rr.getDisplayContent()).thenReturn(true); + + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_VISUAL_ACTION)).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_DETAIL_ID)).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_DETAIL_ID)).thenReturn("test"); + when(rr.isDisplayOptionHideMap()).thenReturn(true); + when(mockedRequest.getSession().getAttribute("isEmbedded")).thenReturn(true); + when(rr.isDrillDownURLInPopupPresent()).thenReturn(true); + ArrayList aL = new ArrayList<>(); + ReportRuntime rr1 = PowerMockito.mock(ReportRuntime.class); + when(rr1.getReportID()).thenReturn("test1"); + when(rr1.getReportType()).thenReturn("test"); + aL.add(rr1); + when(mockedRequest.getSession().getAttribute(AppConstants.DRILLDOWN_REPORTS_LIST)).thenReturn(aL); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_RESET_PARAMS)).thenReturn(true); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_RESET_ACTION)).thenReturn(false); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_GO_BACK)).thenReturn(true); + + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + @Test + public void reportRunExceptionTest() { + when(mockedRequest.getParameter("action")).thenReturn("test"); + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(true); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + @SuppressWarnings("unchecked") + @Test + public void reportRunTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(ReportWrapper.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mock(AppConstants.class); + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); + when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = Mockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(DbUtils.getConnection()).thenReturn(connection); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(AppConstants.RT_DASHBOARD); + when(rr.getReportID()).thenReturn(AppConstants.RT_DASHBOARD); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); + when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); + String str = "namedesctypefalsefalseidfalse"; + when(connection.prepareStatement("1")).thenReturn(stmt); + when(stmt.executeQuery()).thenReturn(rs); + when(Globals.isWeblogicServer()).thenReturn(true); + when(rs.getClob(1)).thenReturn(clob); + when(rs.next()).thenReturn(true); + when(clob.getAsciiStream()).thenReturn(in); + when(in.read(Matchers.any())).thenReturn(1); + when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); + when(AppUtils.nvl("Y")).thenReturn("Y"); + when(AppUtils.nvl("bottom")).thenReturn("Y"); + when(AppUtils.nvl("test")).thenReturn("test|"); + when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); + when(ReportLoader.isDashboardType("-1")).thenReturn(false); + ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); + whenNew(ReportDefinition.class) + .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) + .thenReturn(rdf); + when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); + CustomReportType crType = Mockito.mock(CustomReportType.class); + when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); + when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); + when(Globals.getTimeFormat()).thenReturn("[reportID]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + List formFieldTypeList = new ArrayList<>(); + formFieldTypeList.add(formFieldType); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + when(formFieldList.getFormField()).thenReturn(formFieldTypeList); + Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); + when(Globals.getRequestParams()).thenReturn("test,case"); + when( Globals.getSessionParams()).thenReturn("test,abc"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + + DataSourceList dataSourceList = new DataSourceList(); + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + //dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + //dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + when(rr.getReportFormFields()).thenReturn(reportFormFields); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + Enumeration enums; + Vector attrs = new Vector(); + attrs.add("ff_test"); + enums = attrs.elements(); + when(rr.getParamKeys()).thenReturn(enums); + + DashboardReports daashBoard = Mockito.mock(DashboardReports.class); + when(rdf.getDashBoardReports()).thenReturn(daashBoard); + when(daashBoard.getReportsList()).thenReturn(new ArrayList()); + String testHTML = "
[Report#123][Report#124]
[Report#125][Report#126]
"; + when(rr.getDashboardLayoutHTML()).thenReturn(testHTML); + when(rr.getReportType()).thenReturn(AppConstants.RT_DASHBOARD); + when(mockedRequest.getParameter("refresh")).thenReturn("N"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_DISPLAY_CONTENT)).thenReturn(true); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + + + @SuppressWarnings("unchecked") + @Test + public void reportRunRaptorReportExceptionTest() throws Exception { + try { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(ReportWrapper.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mock(AppConstants.class); + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); + when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = Mockito.mock(DataSet.class); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(DbUtils.getConnection()).thenReturn(connection); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test2"); + when(rr.getReportID()).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); + when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); + String str = "namedesctypefalsefalseidfalse"; + when(connection.prepareStatement("1")).thenReturn(stmt); + when(stmt.executeQuery()).thenReturn(rs); + when(Globals.isWeblogicServer()).thenReturn(true); + when(rs.getClob(1)).thenReturn(clob); + when(rs.next()).thenReturn(true); + when(clob.getAsciiStream()).thenReturn(in); + when(in.read(Matchers.any())).thenReturn(1); + when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); + when(AppUtils.nvl("Y")).thenReturn("Y"); + when(AppUtils.nvl("bottom")).thenReturn("Y"); + when(AppUtils.nvl("test")).thenReturn("test|"); + when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); + when(ReportLoader.isDashboardType("-1")).thenReturn(false); + ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); + whenNew(ReportDefinition.class) + .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) + .thenReturn(rdf); + when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); + CustomReportType crType = Mockito.mock(CustomReportType.class); + when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); + when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); + when(Globals.getTimeFormat()).thenReturn("[reportID]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + List formFieldTypeList = new ArrayList<>(); + formFieldTypeList.add(formFieldType); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + when(formFieldList.getFormField()).thenReturn(formFieldTypeList); + Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); + when(Globals.getRequestParams()).thenReturn("test,case"); + when( Globals.getSessionParams()).thenReturn("test,abc"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + + DataSourceList dataSourceList = new DataSourceList(); + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + //dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + //dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + when(rr.getReportType()).thenReturn(AppConstants.RT_DASHBOARD); + + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + when(rr.getReportFormFields()).thenReturn(reportFormFields); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + Enumeration enums; + Vector attrs = new Vector(); + attrs.add("ff_test"); + enums = attrs.elements(); + when(rr.getParamKeys()).thenReturn(enums); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + }catch(Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void reportRunForCSVDownloadTest() throws Exception { + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(mockedRequest.getParameter("r_action")).thenReturn("report.csv.download"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn(""); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(true); + when(rr.getReportType()).thenReturn(AppConstants.RT_LINEAR); + when(rr.getReportDataSQL(Matchers.anyString(), Matchers.anyInt(), Matchers.any())).thenReturn("test"); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = new DataSet(); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + @Test + public void reportRunForExcelDownloadTest() throws Exception { + when(mockedRequest.getParameter("action")).thenReturn("test"); + when(mockedRequest.getParameter("r_action")).thenReturn("report.download.excel2007"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn(""); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_REFRESH)).thenReturn(true); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(false); + when(rr.getReportType()).thenReturn(AppConstants.RT_LINEAR); + when(rr.getReportDataSQL(Matchers.anyString(), Matchers.anyInt(), Matchers.any())).thenReturn("test"); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = new DataSet(); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + + public ReportRuntime mockReportRunTime1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + when(Globals.getReportUserAccess()).thenReturn("test"); + ResultSet rs = PowerMockito.mock(ResultSet.class); + ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); + when(rsmd.getColumnCount()).thenReturn(1); + when(rs.getMetaData()).thenReturn(rsmd); + DataSet datset = PowerMockito.mock(DataSet.class); + // datset = new DataSet(rs); + when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); + when(Globals.getNewScheduleData()).thenReturn("test"); + CustomReportType customReportType = new CustomReportType(); + DataSourceList dataSourceList = new DataSourceList(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnTypeList.add(dataColumnType); + customReportType.setReportType("test"); + customReportType.setReportTitle("test"); + customReportType.setDataSourceList(dataSourceList); + ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions(); + chartAdditionalOptions.setLabelAngle("test"); + chartAdditionalOptions.setTimeSeriesRender("test"); + chartAdditionalOptions.setMultiSeries(false); + customReportType.setChartAdditionalOptions(chartAdditionalOptions); + ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", + "1", true); + PowerMockito.mockStatic(UserUtils.class); + when(Globals.getRequestParams()).thenReturn("test"); + when(Globals.getSessionParams()).thenReturn("test"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test12"); + ReportRuntime rr = new ReportRuntime(reportWrapper, mockedRequest); + rr.setLegendLabelAngle("test"); + rr.setMultiSeries(false); + rr.setChartType("test"); + return rr; + } + + + @Test + public void reportRunTestCase1() throws Exception { + when(mockedRequest.getParameter("action")).thenReturn("test"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = PowerMockito.mock(DataSet.class); + when(set.isEmpty()).thenReturn(false); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); + PowerMockito.mockStatic(ReportLoader.class); + when(ReportLoader.loadCustomReportXML(Matchers.anyString())).thenReturn("test"); + assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); + } + + + @Test + public void reportDeleteTest() throws Exception { + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(AlarmSeverityEnum.class); + DataSet set = Mockito.mock(DataSet.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1"); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("1"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(Globals.getReportSecurity()).thenReturn("[rw.getReportID()]"); + when(Globals.getReportUserAccess()).thenReturn("[reportID]"); + when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); + when(Globals.getDeleteOnlyByOwner()).thenReturn(true); + when(Globals.getLogVariablesInSession()).thenReturn("test"); + HttpSession session = Mockito.mock(HttpSession.class); + when(session.getAttribute(Matchers.anyString())).thenReturn(rr); + when(session.getAttribute(Matchers.anyString())).thenReturn(rd); + assertEquals(actionHandler.reportDelete(mockedRequest, "10").getClass(), String.class); + } + + + @Test + public void reportSearchTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + actionHandler.reportSearch(mockedRequest, "10"); + } + + + @Test + public void reportChartRunTest() throws Exception { + ChartWebRuntime cwr = PowerMockito.mock(ChartWebRuntime.class); + whenNew(ChartWebRuntime.class).withNoArguments().thenReturn(cwr); + when(cwr.generateChart(mockedRequest,false)).thenReturn("testReport"); + assertEquals("testReport", actionHandler.reportChartRun(mockedRequest, "10")); + } + + @Test + public void reportSearchUserTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals("test", actionHandler.reportSearchUser(mockedRequest, "10")); + } + + @Test + public void reportSearchPublicTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals("test", actionHandler.reportSearchPublic(mockedRequest, "10")); + } + + @Test + public void reportSearchFavoritesTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getImgFolderURL()).thenReturn("test"); + SearchHandler sh = Mockito.mock(SearchHandler.class); + whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); + ReportSearchResultJSON rsrj = Mockito.mock(ReportSearchResultJSON.class); + when(sh.loadReportSearchResult(mockedRequest)).thenReturn(rsrj); + when(rsrj.getJSONString()).thenReturn("test"); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + assertEquals("test", actionHandler.reportSearchFavorites(mockedRequest, "10")); + } + + @Test + public void reportChartDataRunTest() throws Exception { + ChartWebRuntime cwr = Mockito.mock(ChartWebRuntime.class); + whenNew(ChartWebRuntime.class).withNoArguments().thenReturn(cwr); + when(cwr.generateChart(mockedRequest)).thenReturn("testReport"); + assertEquals("testReport", actionHandler.reportChartDataRun(mockedRequest, "10")); + } + + + @Test + public void processScheduleDeleteTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(Globals.class); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_SCHEDULE_ID)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test2"); + ReportHandler rh = Mockito.mock(ReportHandler.class); + ReportDefinition rdef = Mockito.mock(ReportDefinition.class); + whenNew(ReportHandler.class).withNoArguments().thenReturn(rh); + when(rh.loadReportDefinition(mockedRequest, "test2")).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, "myScheduleRepId")).thenReturn("test3"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportSchedule rs = Mockito.mock(ReportSchedule.class); + whenNew(ReportSchedule.class).withArguments(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)).thenReturn(rs); + Connection con = Mockito.mock(Connection.class); + when(DbUtils.startTransaction()).thenReturn(con); + PowerMockito.doNothing().when(rs).deleteScheduleData(con); + PowerMockito.doNothing().when(DbUtils.class, "commitTransaction", new Object[]{con}); + PowerMockito.doNothing().when(DbUtils.class, "clearConnection", new Object[]{con}); + when(mockedRequest.getParameter("action")).thenReturn("report.download.excel2007"); + + when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_REFRESH)).thenReturn(true); + when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(false); + when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + when(Globals.getDownloadAllEmailSent()).thenReturn("test"); + DataSet set = PowerMockito.mock(DataSet.class); + when(set.isEmpty()).thenReturn(false); + when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); + PowerMockito.mockStatic(ReportLoader.class); + when(ReportLoader.loadCustomReportXML(Matchers.anyString())).thenReturn("test"); + PowerMockito.doNothing().when(rr).logReportExecutionTime(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)); + assertEquals(String.class, actionHandler.processScheduleDelete(mockedRequest, "10").getClass()); + } + + @Test + public void testFormFieldRun() { + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportJSONRuntime rjr = Mockito.mock(ReportJSONRuntime.class); + when(rr.createFormFieldJSONRuntime(mockedRequest)).thenReturn(rjr); + assertEquals(String.class, actionHandler.formFieldRun(mockedRequest, "10").getClass()); + } + + @Test + public void testGetReportData() throws RaptorException { + PowerMockito.mockStatic(ConnectionUtils.class); + PowerMockito.mockStatic(AppUtils.class); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + ReportFormFields rff = PowerMockito.mock(ReportFormFields.class); + FormField ff = PowerMockito.mock(FormField.class); + SemaphoreType st = PowerMockito.mock(SemaphoreType.class); + FormatList fl = PowerMockito.mock(FormatList.class); + FormatType ft = PowerMockito.mock(FormatType.class); + VisualManager visualManager = PowerMockito.mock(VisualManager.class); + List ftList = new ArrayList<>(); + ftList.add(ft); + List dctList= new ArrayList<>(); + DataColumnType dct = new DataColumnType(); + dct.setColId("1"); + dct.setDisplayName("testData"); + dct.setColType("DATE"); + dct.setDependsOnFormField("[testFieldDisplayName]"); + dct.setSemaphoreId("testSemaphoreId"); + dct.setColFormat("testColFormat"); + dct.setDrillDownURL("testDrillDownUrl"); + dct.setVisible(true); + dct.setDisplayWidthInPxls("testDisplayWidthInPxls"); + dct.setDisplayHeaderAlignment("testDisplayHeaderAlignment"); + dctList.add(dct); + when(rr.getAllColumns()).thenReturn(dctList); + when(rr.getReportFormFields()).thenReturn(rff); + when(rr.getDBInfo()).thenReturn("testDB"); + when(rr.getReportDefType()).thenReturn(AppConstants.RD_SQL_BASED); + when(rr.getSemaphoreById(Mockito.any())).thenReturn(st); + when(rr.getChildReportFormFields(Mockito.any(HttpServletRequest.class), Mockito.any(String.class))).thenReturn(rff); + when(rr.getVisualManager()).thenReturn(visualManager); + DataSet ds = PowerMockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + when(ds.getRowCount()).thenReturn(1); + when(ds.getString(Mockito.any(Integer.class),Mockito.any(Integer.class))).thenReturn("testDataValue"); + when(rff.size()).thenReturn(1); + when(rff.getFormField(Mockito.any(Integer.class))).thenReturn(ff); + when(ff.getFieldDisplayName()).thenReturn("testFieldDisplayName"); + when(ff.getFieldName()).thenReturn("testFieldName"); + when(mockedRequest.getParameter("testFieldName")).thenReturn("testFieldValue"); + when(st.getFormatList()).thenReturn(fl); + when(st.getSemaphoreType()).thenReturn(AppConstants.ST_ROW); + when(fl.getFormat()).thenReturn(ftList); + when(ft.getLessThanValue()).thenReturn("10"); + when(visualManager.isColumnVisible(Mockito.any(String.class))).thenReturn(true); + when(visualManager.getSortByColId()).thenReturn("1"); + assertEquals(ReportData.class, actionHandler.getReportData(rr, mockedRequest, "test", 10).getClass()); + } + + @Test(expected = IOException.class) + public void testDownloadAll() throws InterruptedException, IOException, Exception { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(FilenameUtils.class); + PowerMockito.mockStatic(Utils.class); + PowerMockito.mockStatic(ReportRuntime.class); + when(AppUtils.getRequestValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + when(AppUtils.getUserEmail(mockedRequest)).thenReturn("test@mail.com"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, "log_id")).thenReturn("testLogID"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(Globals.getDownloadAllEmailSent()).thenReturn("testEmailSentQuery"); + when(Globals.getDownloadAllGenKey()).thenReturn("testGenerateKeyQuery"); + when(Globals.getShellScriptDir()).thenReturn("./"); + DataSet ds = PowerMockito.mock(DataSet.class); + when(DbUtils.executeQuery(Mockito.any(String.class), Mockito.eq(1))).thenReturn(ds); + when(DbUtils.executeQuery(Mockito.any(String.class))).thenReturn(ds); + when(ds.isEmpty()).thenReturn(false); + when(ds.getString(0,"user_id")).thenReturn("testUserID"); + when(ds.getString(0,"rep_id")).thenReturn("testReportID"); + when(ds.getRowCount()).thenReturn(1); + when(ds.getString(0,0)).thenReturn("testScheduleId"); + when(FilenameUtils.normalize(Mockito.any(String.class))).thenReturn("testFile.txt"); + when(Utils.isDownloadFileExists(Mockito.any(String.class))).thenReturn(true); + when(Utils.getLatestDownloadableFile(Mockito.any(String.class))).thenReturn("testLastDownloadedFile.txt"); + List dctList= new ArrayList<>(); + DataColumnType dct = new DataColumnType(); + dct.setDisplayName("testData"); + dctList.add(dct); + when(rr.getAllColumns()).thenReturn(dctList); + when(mockedRequest.getParameter("refresh")).thenReturn("N"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(rr.getReportID()).thenReturn("testReportID"); + actionHandler.downloadAll(mockedRequest, "10"); + } + + @Test + public void testRunSQLPopup() throws ReportSQLException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(Utils.class); + PowerMockito.mockStatic(ConnectionUtils.class); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_FORMATTED_SQL)).thenReturn("SELECT * FROM TEST"); + when(AppUtils.getRequestNvlValue(mockedRequest,AppConstants.RI_CHK_FIELD_SQL)).thenReturn("N"); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); + formFieldList.getFormField().add(formFieldType); + when(rdef.getFormFieldList()).thenReturn(formFieldList); + when(rdef.getFormFieldDisplayName(formFieldType)).thenReturn("testField"); + when(mockedRequest.getParameter("remoteDbPrefix")).thenReturn("testDB"); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(Utils.replaceInString(Mockito.any(String.class),Mockito.any(String.class),Mockito.any(String.class))).thenReturn("testString"); + when(Globals.getRequestParams()).thenReturn("test"); + when(Globals.getSessionParams()).thenReturn("test"); + DataSet ds = PowerMockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class), Mockito.eq(true))).thenReturn(ds); + when(ds.getRowCount()).thenReturn(1); + when(ds.getString(Mockito.any(Integer.class),Mockito.any(Integer.class))).thenReturn("testDataValue"); + PowerMockito.mockStatic(ESAPI.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + actionHandler.testRunSQLPopup(mockedRequest, "10"); + } + + @Test + public void testSchedCondPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_FORMATTED_SQL)).thenReturn("testSQL"); + when(Globals.getTestSchedCondPopup()).thenReturn("testQuery"); + when(mockedRequest.getParameter("remoteDbPrefix")).thenReturn("testDB"); + DataSet ds = PowerMockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + when(ds.getRowCount()).thenReturn(1); + actionHandler.testSchedCondPopup(mockedRequest, "10"); + } + + @Test + public void testReportShowSQLPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + when(rdef.generateSQL(Mockito.any(String.class),Mockito.any(HttpServletRequest.class))).thenReturn("testReportSQL"); + actionHandler.reportShowSQLPopup(mockedRequest, "10"); + } + + + @Test + public void testReportFilterDataPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_COLUMN_ID)).thenReturn("testColID"); + when(rdef.getDBInfo()).thenReturn(null); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("testDB"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_RESET_PARAMS)).thenReturn(false); + IdNameColLookup lookUp = Mockito.mock(IdNameColLookup.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_COLUMN_LOOKUP)).thenReturn(lookUp); + when(lookUp.getColId()).thenReturn("testColID"); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_SEARCH_STRING)).thenReturn("testSearchStr"); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_CONTAIN_FLAG)).thenReturn(true); + actionHandler.reportFilterDataPopup(mockedRequest, "10"); + } + + @Test + public void testReportImportSave() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + String str = "namedesctypefalsefalseidfalse"; + when(AppUtils.getRequestValue(mockedRequest, "reportXML")).thenReturn(str); + ReportHandler rh = Mockito.mock(ReportHandler.class); + ReportDefinition rdef = Mockito.mock(ReportDefinition.class); + whenNew(ReportHandler.class).withNoArguments().thenReturn(rh); + when(rh.createReportDefinition(mockedRequest, "-1", str)).thenReturn(rdef); + PowerMockito.doNothing().when(rdef).updateReportDefType(); + PowerMockito.doNothing().when(rdef).generateWizardSequence(mockedRequest); + when(rdef.getReportName()).thenReturn("test"); + PowerMockito.doNothing().when(rdef).setReportName("Import: test"); + PowerMockito.doNothing().when(rdef).clearAllDrillDowns(); + actionHandler.reportImportSave(mockedRequest, "10"); + } + + @Test + public void testProcessSchedule() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.mockStatic(DbUtils.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE)).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, AppConstants.RI_ACTION)).thenReturn("test"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_SCHEDULE_ID)).thenReturn(""); + ReportSchedule rs = Mockito.mock(ReportSchedule.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE)).thenReturn(rs); + when(rs.getScheduleID()).thenReturn("testSchecduleID"); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("testReportID"); + when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + when(ReportLoader.doesUserCanScheduleReport(Mockito.any(HttpServletRequest.class), Mockito.any(String.class))).thenReturn(true); + when(rs.getFormFields()).thenReturn("testField"); + when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + Connection con = Mockito.mock(Connection.class); + when(DbUtils.startTransaction()).thenReturn(con); + actionHandler.processSchedule(mockedRequest, "10"); + } + + @Test(expected=RuntimeException.class) + public void testProcessSchedule_WhenReportScheduleIsNull() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_SCHEDULE)).thenReturn(null); + when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(""); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + actionHandler.processSchedule(mockedRequest, "10"); + } + + @Test + public void testReportValuesMapDefPopup() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(AppUtils.getRequestNvlValue(mockedRequest, "colName")).thenReturn("testCol"); + when(AppUtils.getRequestNvlValue(mockedRequest, "displayName")).thenReturn("testDisplayName"); + when(AppUtils.getRequestNvlValue(mockedRequest, "displayFormat")).thenReturn("testDisplayFormat"); + when(AppUtils.getRequestNvlValue(mockedRequest, "tableId")).thenReturn("testTableId"); + when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("testDB"); + when(Globals.getReportValuesMapDefA()).thenReturn("testA"); + when(Globals.getReportValuesMapDefB()).thenReturn("testB"); + when(Globals.getReportValuesMapDefC()).thenReturn("testC"); + when(Globals.getReportValuesMapDefD()).thenReturn("testD"); + when(Globals.getDefaultPageSize()).thenReturn(10); + DataSourceType ds = Mockito.mock(DataSourceType.class); + when(ds.getTableName()).thenReturn("testTable"); + when(rdef.getTableById(Mockito.any(String.class))).thenReturn(ds); + DataSet data = Mockito.mock(DataSet.class); + when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(data); + actionHandler.reportValuesMapDefPopup(mockedRequest, "10"); + } + + @Test + public void testReportFormFieldPopup() { + PowerMockito.mockStatic(AppUtils.class); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, + "defaultValue", "helpText", new ArrayList<>(), false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + when(rr.getFormField(Mockito.any(String.class))).thenReturn(formField); + ReportFormFields rff = PowerMockito.mock(ReportFormFields.class); + when(rr.getReportFormFields()).thenReturn(rff); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + IdNameList lookup = Mockito.mock(IdNameList.class); + when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_TEXTFIELD_POP)).thenReturn(true); + actionHandler.reportFormFieldPopup(mockedRequest, "10"); + } + + @Test + public void testReportCreate() throws Exception { + PowerMockito.mockStatic(ReportDefinition.class); + PowerMockito.mockStatic(DataCache.class); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(ReportDefinition.createBlank(mockedRequest)).thenReturn(rdef); + PowerMockito.doNothing().when(DataCache.class, "refreshReportTableSources", new Object[]{}); + actionHandler.reportCreate(mockedRequest, "10"); + } + + @Test + public void testRefreshCache() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DataCache.class); + Enumeration enum1 = Mockito.mock(Enumeration.class); + HttpSession session = mockedRequest.getSession(); + when(session.getAttributeNames()).thenReturn(enum1); + PowerMockito.doNothing().when(DataCache.class, "refreshAll", new Object[]{}); + IAppUtils iau = Mockito.mock(IAppUtils.class); + when(Globals.getAppUtils()).thenReturn(iau); + PowerMockito.doNothing().when(iau).resetUserCache(); + actionHandler.refreshCache(mockedRequest, "10"); + } + + @Test + public void testProcessScheduleReportListd() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ReportLoader.class); + when(AppUtils.getRequestNvlValue(mockedRequest, "schedule_reports")).thenReturn("reportID"); + when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + when(ReportLoader.doesUserCanScheduleReport(mockedRequest, null)).thenReturn(true); + ReportDefinition rdef = PowerMockito.mock(ReportDefinition.class); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + when(rdef.getReportID()).thenReturn("reportID"); + actionHandler.processScheduleReportList(mockedRequest, "10"); + } + + + @Test + public void testGetQuickLinksJSON() throws Exception { + PowerMockito.mockStatic(SecurityCodecUtil.class); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(ReportLoader.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + when(SecurityCodecUtil.getCodec()).thenReturn(codec); + when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + ArrayList qList = new ArrayList(); + qList.add(new QuickLink()); + when(ReportLoader.getQuickLinksJSON(Mockito.any(HttpServletRequest.class), Mockito.any(String.class), Mockito.eq(true))).thenReturn(qList); + actionHandler.getQuickLinksJSON(mockedRequest, "10"); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionMappingTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionMappingTest.java new file mode 100644 index 00000000..ce883537 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionMappingTest.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ActionMappingTest { + + ActionMapping actionMapping; + Action action; + private String ACTION = "testAction"; + private String CONTROLLER_CLASS = "testController"; + private String CONTROLLER_METHOD = "test"; + private String JSP_NAME = "testJsp"; + + @Before + public void init() { + actionMapping = new ActionMapping(); + action = new Action(ACTION, CONTROLLER_CLASS, CONTROLLER_METHOD, JSP_NAME); + actionMapping.addAction(action); + } + + @Test + public void testGetAction() { + Action localAction = (Action)actionMapping.get(ACTION); + assertEquals(ACTION, localAction.getAction()); + assertEquals(CONTROLLER_CLASS, localAction.getControllerClass()); + assertEquals(CONTROLLER_METHOD, localAction.getControllerMethod()); + assertEquals(JSP_NAME, localAction.getJspName()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionTest.java new file mode 100644 index 00000000..06fa42fe --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ActionTest.java @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + */ + +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.onap.portalsdk.analytics.controller.Action; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class ActionTest { + + Action action; + private String ACTION = "testAction"; + private String CONTROLLER_CLASS = "testController"; + private String CONTROLLER_METHOD = "test"; + private String JSP_NAME = "testJsp"; + + @Before + public void init() { + action = new Action(ACTION, CONTROLLER_CLASS, CONTROLLER_METHOD, JSP_NAME); + } + + @Test + public void testNotNull() { + assertNotNull(action); + } + + @Test + public void testActionAttributes() { + assertEquals(ACTION, action.getAction()); + assertEquals(CONTROLLER_CLASS, action.getControllerClass()); + assertEquals(CONTROLLER_METHOD, action.getControllerMethod()); + assertEquals(JSP_NAME, action.getJspName()); + } + + @Test + public void testParse() { + String configFileEntry = "testAction testController test testJsp"; + Action localAction = action.parse(configFileEntry); + assertEquals(ACTION, localAction.getAction()); + assertEquals(CONTROLLER_CLASS, localAction.getControllerClass()); + assertEquals(CONTROLLER_METHOD, localAction.getControllerMethod()); + assertEquals(JSP_NAME, localAction.getJspName()); + } +} \ No newline at end of file diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ControllerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ControllerTest.java new file mode 100644 index 00000000..0bcf8637 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ControllerTest.java @@ -0,0 +1,262 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + */ +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +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.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, AppUtils.class}) +public class ControllerTest { + Controller controller; + String ACTION_KEY = "testAction"; + Action action; + ActionMapping actionMapping; + private String ACTION = "testAction"; + private String CONTROLLER_CLASS = "org.onap.portalsdk.analytics.controller.DummyController"; + private String PRIVATE_CONTROLLER_CLASS = "org.onap.portalsdk.analytics.controller.PrivateDummyController"; + private String ABSTRACT_CONTROLLER_CLASS = "org.onap.portalsdk.analytics.controller.AbstractDummyController"; + private String CONTROLLER_METHOD = "view"; + private String JSP_NAME = "testJsp"; + private String ERROR_PAGE = "errorPage"; + private String ERROR_MESSAGE = "testErrorMessage"; + private String TEST_ID = "testID"; + private String REPORT_NAME = "testReport"; + private String REPORT_SQL = "testReportSQL"; + private String LOG_VAR_IN_SESSION = "test"; + + @Before + public void setup() { + controller = new Controller(); + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockResponse = mockitoTestSuite.getMockedResponse(); + + @Test + public void processRequestTest_WhenClassNotFoundException() throws Exception { + actionMapping = new ActionMapping(); + action = new Action(ACTION, "AdminController", CONTROLLER_METHOD, JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + @Test + public void processRequestTest_WhenActionIsNull() throws Exception { + actionMapping = new ActionMapping(); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + @Test + public void processRequestTest() throws Exception { + actionMapping = new ActionMapping(); + action = new Action("report.run", CONTROLLER_CLASS, CONTROLLER_METHOD, JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(JSP_NAME, controller.processRequest(mockedRequest)); + } + + + @Test + public void processRequestTest_WithNoSuchMethodException() throws Exception { + actionMapping = new ActionMapping(); + action = new Action(ACTION, CONTROLLER_CLASS, "viewHome", JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + + @Test + public void handleRequestTest() throws Exception { + actionMapping = new ActionMapping(); + action = new Action("report.run", CONTROLLER_CLASS, CONTROLLER_METHOD, JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + ServletContext sc= Mockito.mock(ServletContext.class); + RequestDispatcher mockedRequestDispatcher = Mockito.mock(RequestDispatcher.class); + when(sc.getRequestDispatcher(Mockito.any(String.class))).thenReturn(mockedRequestDispatcher); + Mockito.doNothing().when(mockedRequestDispatcher).forward(Mockito.any(HttpServletRequest.class), Mockito.any(HttpServletResponse.class)); + controller.handleRequest(mockedRequest, mockResponse,sc); + } + + @Test + public void processRequestTest_WithIllegalAccess() throws Exception { + actionMapping = new ActionMapping(); + action = new Action(ACTION, PRIVATE_CONTROLLER_CLASS, "", JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + + @Test + public void processRequestTest_WithInvocationTargetException() throws Exception { + actionMapping = new ActionMapping(); + action = new Action(ACTION, CONTROLLER_CLASS, "throwInvocationTarget", JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + + @Test + public void processRequestTest_WithInstantiationException() throws Exception { + actionMapping = new ActionMapping(); + action = new Action(ACTION, ABSTRACT_CONTROLLER_CLASS, "throwInstantiation", JSP_NAME); + actionMapping.addAction(action); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getRaptorActionMapping()).thenReturn(actionMapping); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(ERROR_PAGE); + assertEquals(ERROR_PAGE, controller.processRequest(ACTION_KEY, mockedRequest)); + } + + + + +} \ No newline at end of file diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/DummyController.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/DummyController.java new file mode 100644 index 00000000..94ec5dc9 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/DummyController.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + */ +package org.onap.portalsdk.analytics.controller; + +import java.lang.reflect.InvocationTargetException; + +import javax.servlet.http.HttpServletRequest; + +class DummyController{ + public String view(HttpServletRequest request, String jspName) { + return jspName; + } + public void throwInvocationTarget(HttpServletRequest request, String jspName) throws InvocationTargetException { + throw new InvocationTargetException(null, ""); + } +} \ No newline at end of file diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ErrorHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ErrorHandlerTest.java new file mode 100644 index 00000000..6c84ce12 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/ErrorHandlerTest.java @@ -0,0 +1,191 @@ +package org.onap.portalsdk.analytics.controller; +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +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.MockitoAnnotations; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.definition.ReportDefinition; +import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, AppUtils.class}) +public class ErrorHandlerTest { + + ErrorHandler errorHandler; + private String ERROR_MESSAGE = "testErrorMessage"; + private String TEST_PAGE = "testPage"; + private String TEST_ID = "testID"; + private String REPORT_NAME = "testReport"; + private String REPORT_SQL = "testReportSQL"; + private String LOG_VAR_IN_SESSION = "test"; + + @Before + public void setup() { + errorHandler = new ErrorHandler(); + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test + public void processErrorTest() { + when(mockedRequest.getAttribute(AppConstants.RI_ERROR_LIST)).thenReturn(null); + errorHandler.processError(mockedRequest, ERROR_MESSAGE); + } + + @Test + public void processErrorRaptorExceptionTest() { + when(mockedRequest.getAttribute(AppConstants.RI_ERROR_LIST)).thenReturn(null); + RaptorException re = new RaptorException(ERROR_MESSAGE); + errorHandler.processError(mockedRequest, re); + } + + @Test + public void processFatalErrorTest_WhenReportWrapperIsNotNull() throws Exception{ + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(TEST_PAGE); + assertEquals(TEST_PAGE, errorHandler.processFatalError(mockedRequest, rse)); + } + + @Test + public void processFatalErrorTest_WhenReportDefinitionIsNotNull() throws Exception{ + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); + when(rd.getReportID()).thenReturn(TEST_ID); + when(rd.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rd); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPage()).thenReturn(TEST_PAGE); + assertEquals(TEST_PAGE, errorHandler.processFatalError(mockedRequest, rse)); + } + + @Test + public void processFatalErrorJSONTest_WhenReportWrapperIsNotNull() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + String jsonString = errorHandler.processFatalErrorJSON(mockedRequest, rse); + assertTrue(jsonString.contains(ERROR_MESSAGE)); + } + + @Test + public void processFatalErrorJSONTest_WhenReportDefinitionIsNotNull() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + HttpSession session = mockedRequest.getSession(); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); + when(rd.getReportID()).thenReturn(TEST_ID); + when(rd.getReportName()).thenReturn(REPORT_NAME); + when(session.getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rd); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + String jsonString = errorHandler.processFatalErrorJSON(mockedRequest, rse); + assertTrue(jsonString.contains(ERROR_MESSAGE)); + } + + @Test + public void processFatalErrorWMenuTest_WhenReportWrapperIsNotNull() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + when(rr.getReportID()).thenReturn(TEST_ID); + when(rr.getReportName()).thenReturn(REPORT_NAME); + HttpSession session = mockedRequest.getSession(); + when(session.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPageWMenu()).thenReturn(TEST_PAGE); + assertEquals(TEST_PAGE, errorHandler.processFatalErrorWMenu(mockedRequest, rse)); + } + + @Test + public void processFatalErrorWMenuTest_WhenReportDefinitionIsNotNull() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + when(Globals.getLogVariablesInSession()).thenReturn(LOG_VAR_IN_SESSION); + ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); + when(rd.getReportID()).thenReturn(TEST_ID); + when(rd.getReportName()).thenReturn(REPORT_NAME); + HttpSession session = mockedRequest.getSession(); + when(session.getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rd); + ReportSQLException rse = new ReportSQLException(ERROR_MESSAGE,REPORT_SQL); + PowerMockito.doNothing().when(AppUtils.class, "processErrorNotification", new Object[]{mockedRequest, rse}); + when(AppUtils.getErrorPageWMenu()).thenReturn(TEST_PAGE); + assertEquals(TEST_PAGE, errorHandler.processFatalErrorWMenu(mockedRequest, rse)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/PrivateDummyController.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/PrivateDummyController.java new file mode 100644 index 00000000..25e0b3d9 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/PrivateDummyController.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +public class PrivateDummyController { + private PrivateDummyController() {} +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceCrossTabTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceCrossTabTest.java new file mode 100644 index 00000000..8b836554 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceCrossTabTest.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceCrossTabTest { + + WizardSequenceCrossTab wizardSequenceCrossTab; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceCrossTab = new WizardSequenceCrossTab(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceCrossTab); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION,wizardSequenceCrossTab.get(0)); + assertEquals(AppConstants.WS_TABLES,wizardSequenceCrossTab.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceCrossTab.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceCrossTab.get(3)); + assertEquals(AppConstants.WS_FILTERS, wizardSequenceCrossTab.get(4)); + assertEquals(AppConstants.WS_JAVASCRIPT, wizardSequenceCrossTab.get(5)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceCrossTab.get(6)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceCrossTab.get(7)); + assertEquals(AppConstants.WS_RUN, wizardSequenceCrossTab.get(8)); + } + + @Test + public void testSize() { + assertEquals(9,wizardSequenceCrossTab.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceDashboardTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceDashboardTest.java new file mode 100644 index 00000000..f733c154 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceDashboardTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceDashboardTest { + + WizardSequenceDashboard wizardSequenceDashboard; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceDashboard = new WizardSequenceDashboard(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceDashboard); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION, wizardSequenceDashboard.get(0)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceDashboard.get(1)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceDashboard.get(2)); + assertEquals(AppConstants.WS_RUN, wizardSequenceDashboard.get(3)); + } + + @Test + public void testSize() { + assertEquals(4, wizardSequenceDashboard.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceLinearTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceLinearTest.java new file mode 100644 index 00000000..b5ae1488 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceLinearTest.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceLinearTest { + + WizardSequenceLinear wizardSequenceLinear; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceLinear = new WizardSequenceLinear(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceLinear); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION,wizardSequenceLinear.get(0)); + assertEquals(AppConstants.WS_TABLES,wizardSequenceLinear.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceLinear.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceLinear.get(3)); + assertEquals(AppConstants.WS_FILTERS, wizardSequenceLinear.get(4)); + assertEquals(AppConstants.WS_SORTING, wizardSequenceLinear.get(5)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceLinear.get(6)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceLinear.get(7)); + assertEquals(AppConstants.WS_RUN, wizardSequenceLinear.get(8)); + } + + @Test + public void testSize() { + assertEquals(9,wizardSequenceLinear.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedCrossTabTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedCrossTabTest.java new file mode 100644 index 00000000..d4ceaff1 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedCrossTabTest.java @@ -0,0 +1,86 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceSQLBasedCrossTabTest { + + WizardSequenceSQLBasedCrossTab wizardSequenceSQLBasedCrossTab; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceSQLBasedCrossTab = new WizardSequenceSQLBasedCrossTab(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceSQLBasedCrossTab); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION,wizardSequenceSQLBasedCrossTab.get(0)); + assertEquals(AppConstants.WS_SQL,wizardSequenceSQLBasedCrossTab.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceSQLBasedCrossTab.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceSQLBasedCrossTab.get(3)); + assertEquals(AppConstants.WS_JAVASCRIPT, wizardSequenceSQLBasedCrossTab.get(4)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceSQLBasedCrossTab.get(5)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceSQLBasedCrossTab.get(6)); + assertEquals(AppConstants.WS_RUN, wizardSequenceSQLBasedCrossTab.get(7)); + } + + @Test + public void testSize() { + assertEquals(8,wizardSequenceSQLBasedCrossTab.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedHiveTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedHiveTest.java new file mode 100644 index 00000000..d64738a2 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedHiveTest.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceSQLBasedHiveTest { + + WizardSequenceSQLBasedHive wizardSequenceSQLBasedHive; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceSQLBasedHive = new WizardSequenceSQLBasedHive(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceSQLBasedHive); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION, wizardSequenceSQLBasedHive.get(0)); + assertEquals(AppConstants.WS_SQL, wizardSequenceSQLBasedHive.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceSQLBasedHive.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceSQLBasedHive.get(3)); + assertEquals(AppConstants.WS_JAVASCRIPT, wizardSequenceSQLBasedHive.get(4)); + assertEquals(AppConstants.WS_CHART, wizardSequenceSQLBasedHive.get(5)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceSQLBasedHive.get(6)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceSQLBasedHive.get(7)); + assertEquals(AppConstants.WS_RUN, wizardSequenceSQLBasedHive.get(8)); + } + + @Test + public void testSize() { + assertEquals(9, wizardSequenceSQLBasedHive.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearDataminingTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearDataminingTest.java new file mode 100644 index 00000000..19c3e7e0 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearDataminingTest.java @@ -0,0 +1,88 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceSQLBasedLinearDataminingTest { + + WizardSequenceSQLBasedLinearDatamining wizardSequenceSQLBasedLinearDatamining; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceSQLBasedLinearDatamining = new WizardSequenceSQLBasedLinearDatamining(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceSQLBasedLinearDatamining); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION, wizardSequenceSQLBasedLinearDatamining.get(0)); + assertEquals(AppConstants.WS_SQL, wizardSequenceSQLBasedLinearDatamining.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceSQLBasedLinearDatamining.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceSQLBasedLinearDatamining.get(3)); + assertEquals(AppConstants.WS_DATA_FORECASTING, wizardSequenceSQLBasedLinearDatamining.get(4)); + assertEquals(AppConstants.WS_JAVASCRIPT, wizardSequenceSQLBasedLinearDatamining.get(5)); + assertEquals(AppConstants.WS_CHART, wizardSequenceSQLBasedLinearDatamining.get(6)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceSQLBasedLinearDatamining.get(7)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceSQLBasedLinearDatamining.get(8)); + assertEquals(AppConstants.WS_RUN, wizardSequenceSQLBasedLinearDatamining.get(9)); + } + + @Test + public void testSize() { + assertEquals(10, wizardSequenceSQLBasedLinearDatamining.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearTest.java new file mode 100644 index 00000000..94d8e6b9 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceSQLBasedLinearTest.java @@ -0,0 +1,85 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class WizardSequenceSQLBasedLinearTest { + + WizardSequenceSQLBasedLinear wizardSequenceSQLBasedLinear; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getEnableReportLog()).thenReturn(true); + wizardSequenceSQLBasedLinear = new WizardSequenceSQLBasedLinear(true); + } + + @Test + public void testNotNull() { + assertNotNull(wizardSequenceSQLBasedLinear); + } + + @Test + public void testIndexValues() { + assertEquals(AppConstants.WS_DEFINITION,wizardSequenceSQLBasedLinear.get(0)); + assertEquals(AppConstants.WS_SQL,wizardSequenceSQLBasedLinear.get(1)); + assertEquals(AppConstants.WS_COLUMNS, wizardSequenceSQLBasedLinear.get(2)); + assertEquals(AppConstants.WS_FORM_FIELDS, wizardSequenceSQLBasedLinear.get(3)); + assertEquals(AppConstants.WS_USER_ACCESS, wizardSequenceSQLBasedLinear.get(4)); + assertEquals(AppConstants.WS_REPORT_LOG, wizardSequenceSQLBasedLinear.get(5)); + assertEquals(AppConstants.WS_RUN, wizardSequenceSQLBasedLinear.get(6)); + } + + @Test + public void testSize() { + assertEquals(7,wizardSequenceSQLBasedLinear.size()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceTest.java new file mode 100644 index 00000000..76842d05 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/controller/WizardSequenceTest.java @@ -0,0 +1,78 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.controller; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.util.AppConstants; + +public class WizardSequenceTest { + WizardSequence wizardSequence; + + @Before + public void init() { + wizardSequence = new WizardSequence(); + } + + @Test + public void testPerformActionWithWABackAction() { + wizardSequence.performAction(AppConstants.WA_BACK, null); + assertEquals(1, wizardSequence.getCurrentStepIndex()); + } + + @Test + public void testPerformActionWithWAAddAction() { + wizardSequence.performAction(AppConstants.WA_ADD, null); + assertEquals(AppConstants.WA_ADD, wizardSequence.getCurrentSubStep()); + } + + + @Test + public void testPerformActionWithWANextAction() { + wizardSequence.performAction(AppConstants.WA_NEXT, null); + assertEquals("", wizardSequence.getCurrentSubStep()); + } + + @Test + public void testPerformGoToStep() { + wizardSequence.performGoToStep(AppConstants.WS_DEFINITION); + assertEquals("", wizardSequence.getCurrentSubStep()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineCollectionTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineCollectionTest.java new file mode 100644 index 00000000..13b7fbfe --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineCollectionTest.java @@ -0,0 +1,141 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.analytics.gmap.line; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.List; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; + +public class LineCollectionTest { + + LineCollection lineCollection; + LineInfo lineInfo; + private String LINE_ID = "lineID"; + private String LINE_TYPE = "test"; + private String NODE1 = "nodeID1"; + private String NODE2 = "nodeID2"; + + @Before + public void init() throws Exception { + lineCollection = new LineCollection(); + lineInfo = new LineInfo(NODE1, NODE2); + lineInfo.setLineID(LINE_ID); + lineInfo.setLineType(LINE_TYPE); + lineCollection.addLine(lineInfo); + lineCollection.addSelectedLine(LINE_ID); + } + + @Test + public void testGetLineCollection() { + List lineInfoList = lineCollection.getLineCollection(); + assertNotNull(lineInfoList); + assertEquals(1,lineCollection.getSize()); + } + + @Test + public void testGetSelectedLine() { + Set selectedLine = lineCollection.getSelectedLine(); + assertNotNull(selectedLine); + } + + @Test + public void testContainsSelectedLine() { + assertEquals(true,lineCollection.containSelectedLine(LINE_ID)); + } + + @Test + public void testRemoveSelectedLine() { + lineCollection.removeSelectedLine(LINE_ID); + assertEquals(false,lineCollection.containSelectedLine(LINE_ID)); + } + + @Test + public void testClearAllCollection() { + lineCollection.addSelectedLine(LINE_ID); + lineCollection.clearAllCollection(); + assertEquals(false,lineCollection.containSelectedLine(LINE_ID)); + } + + @Test + public void testGetLineByLineID() { + LineInfo lineInfo = lineCollection.getLine(LINE_ID); + assertEquals("lineID", lineInfo.getLineID()); + } + + @Test + public void testGetLineByLineIDAndType() { + LineInfo lineInfo = lineCollection.getLine(LINE_ID,LINE_TYPE); + assertEquals("lineID", lineInfo.getLineID()); + assertEquals("test", lineInfo.getLineType()); + } + + @Test + public void testGetLineByNode() { + LineInfo lineInfo = lineCollection.getLine(NODE1,NODE2,true); + assertEquals("nodeID1", lineInfo.getNodeID1()); + assertEquals("nodeID2", lineInfo.getNodeID2()); + } + + @Test + public void testGetWildCardLine() { + String[] lineIDArr = lineCollection.getWildCardLine("li"); + assertEquals("lineID", lineIDArr[0]); + } + + @Test + public void testRemoveLineByLineID() { + LineInfo lineInfo = lineCollection.removeLine(LINE_ID); + LineInfo lineInfo1 = lineCollection.getLine(lineInfo.getLineID()); + lineCollection.addLine(lineInfo1); + assertNull(lineInfo1); + } + + @Test + public void testRemoveLineByLineIDAndType() { + LineInfo lineInfo = lineCollection.removeLine(LINE_ID,LINE_TYPE); + LineInfo lineInfo1 = lineCollection.getLine(lineInfo.getLineID()); + assertNull(lineInfo1); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineInfoTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineInfoTest.java new file mode 100644 index 00000000..5ff6e78b --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineInfoTest.java @@ -0,0 +1,117 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.gmap.line; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +public class LineInfoTest { + + LineInfo lineInfo; + + private String NODE_ID1 = "nodeID1"; + private String NODE_ID2 = "nodeID2"; + private String LINE_ID = "lineID"; + private String LINE_TYPE = "lineType"; + private String LINE_DESCRIPTION = "lineDescription"; + private boolean MOVEABLE = true; + private boolean DELETEABLE = true; + private int STATE = 1; + + @Before + public void init() { + lineInfo = new LineInfo(NODE_ID1, NODE_ID2); + lineInfo.setNodeID1(NODE_ID1); + lineInfo.setNodeID2(NODE_ID2); + lineInfo.setLineID(LINE_ID); + lineInfo.setLineType(LINE_TYPE); + lineInfo.setDescription(LINE_DESCRIPTION); + lineInfo.setMoveable(MOVEABLE); + lineInfo.setDeleteable(DELETEABLE); + lineInfo.setState(STATE); + Map lineAttributes = new HashMap<>(); + lineAttributes.put("x_length", "200cm"); + lineInfo.initializeAttributes(lineAttributes); + lineInfo.setAttribute("x_length", "300cm"); + } + + @Test + public void testNotNull() { + assertNotNull(lineInfo); + } + + @Test + public void testLineInfoProperties() { + assertEquals(NODE_ID1, lineInfo.getNodeID1()); + assertEquals(NODE_ID2, lineInfo.getNodeID2()); + assertEquals(LINE_ID, lineInfo.getLineID()); + assertEquals(LINE_TYPE, lineInfo.getLineType()); + assertEquals(LINE_DESCRIPTION, lineInfo.getDescription()); + assertEquals(MOVEABLE, lineInfo.isMoveable()); + assertEquals(DELETEABLE, lineInfo.isDeleteable()); + assertEquals(STATE, lineInfo.getState()); + assertEquals("300cm", lineInfo.getAttribute("x_length")); + } + + @Test + public void testClone() { + LineInfo lineInfo2 = lineInfo.clone(); + assertEquals(NODE_ID1, lineInfo2.getNodeID1()); + assertEquals(NODE_ID2, lineInfo2.getNodeID2()); + assertEquals(LINE_ID, lineInfo2.getLineID()); + assertEquals(LINE_TYPE, lineInfo2.getLineType()); + assertEquals(LINE_DESCRIPTION, lineInfo2.getDescription()); + assertEquals(MOVEABLE, lineInfo2.isMoveable()); + assertEquals(DELETEABLE, lineInfo2.isDeleteable()); + assertEquals(STATE, lineInfo2.getState()); + } + + @Test + public void getAttributeInternalKeys() { + List list = lineInfo.getAttributeInternalKeys(); + assertEquals("length", list.get(0)); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java index c3ea5ead..dc4171ce 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/line/LineTest.java @@ -37,23 +37,55 @@ */ package org.onap.portalsdk.analytics.gmap.line; +import static org.junit.Assert.assertNotNull; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; import org.onap.portalsdk.analytics.gmap.map.NovaMap; - +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.test.util.ReflectionTestUtils; +@RunWith(PowerMockRunner.class) +@PrepareForTest({Line.class}) public class LineTest { + Line line; + Point2D screenPoint; + private String LINE_ID = "lineID"; + private String LINE_TYPE = "test"; + private String NODE1 = "nodeID1"; + private String NODE2 = "nodeID2"; - public Line mockLineTest() - { + @Before + public void init() throws Exception{ NovaMap novaMap= new NovaMap(); novaMap.setDataLoaded("dataLoaded"); - Line line = new Line(novaMap); - return line; + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + LineCollection lineCollection = Mockito.mock(LineCollection.class); + ArrayList list = new ArrayList(); + LineInfo lineInfo = new LineInfo(NODE1, NODE2); + lineInfo.setLineID(LINE_ID); + lineInfo.setLineType(LINE_TYPE); + lineCollection.addLine(lineInfo); + lineCollection.addSelectedLine(LINE_ID); + list.add(lineInfo); + PowerMockito.whenNew(LineCollection.class).withNoArguments().thenReturn(lineCollection); + Mockito.when(lineCollection.getLineCollection()).thenReturn(list); + screenPoint = Mockito.mock(Point2D.class); + line = new Line(novaMap); } @Test - public void lineExistTest() - { - Line line = mockLineTest(); + public void lineExistTest(){ + assertNotNull(line); + line.lineExist(screenPoint); } } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/ColorPropertiesTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/ColorPropertiesTest.java new file mode 100644 index 00000000..07d9a926 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/ColorPropertiesTest.java @@ -0,0 +1,93 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.gmap.map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.awt.Color; + +import org.junit.Before; +import org.junit.Test; + +public class ColorPropertiesTest { + + ColorProperties colorProperties; + private String TYPE = "type"; + private String COLOR = "10,10,10"; + private String SHAPE = "circle"; + private String SIZE = "100"; + private int NUMBER = 1; + + @Before + public void init() { + NovaMap map = new NovaMap(); + colorProperties = new ColorProperties(map); + colorProperties.setColor(TYPE, COLOR); + colorProperties.setShape(TYPE, SHAPE); + colorProperties.setSize(TYPE, SIZE); + colorProperties.setShape(TYPE, NUMBER, SHAPE); + } + + @Test + public void testNotNull() { + assertNotNull(colorProperties); + } + + @Test + public void testGetColor() { + Color color1 = new Color(10,10,10); + Color color2 = colorProperties.getColor(TYPE); + assertEquals(true, color1.equals(color2)); + } + + @Test + public void testGetShape() { + assertEquals(SHAPE, colorProperties.getShape(TYPE)); + } + + @Test + public void testGetShapeWithNumber() { + assertEquals(SHAPE, colorProperties.getShape(TYPE, NUMBER)); + } + + @Test + public void testGetSize() { + assertEquals(100, colorProperties.getSize(TYPE)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java new file mode 100644 index 00000000..7be34b74 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/NovaMapTest.java @@ -0,0 +1,148 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.gmap.map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.awt.Rectangle; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.util.HashSet; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.gmap.line.Line; +import org.onap.portalsdk.analytics.gmap.map.layer.SwingLayer; +import org.onap.portalsdk.analytics.gmap.node.Node; +import org.springframework.test.util.ReflectionTestUtils; + +public class NovaMapTest { + + NovaMap novaMap; + private SwingLayer swingLayer; + + @Before + public void init() { + novaMap = new NovaMap(); + swingLayer = new SwingLayer(novaMap); + novaMap.setBoundingBox(10, 10); + novaMap.setNode(new Node(novaMap)); + novaMap.setLine(new Line(novaMap)); + novaMap.setColorProperties(new ColorProperties(novaMap)); + novaMap.setZoomLevel(10); + novaMap.addShowList("test-1"); + novaMap.addShowList("test-2", 10); + novaMap.addSwingLayer(swingLayer); + novaMap.setCurrentYearMonth("2018/05"); + novaMap.setDefaultBoundary(new Rectangle2D.Double()); + novaMap.setShowLegend(true); + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + } + + + @Test + public void testNotNull() { + assertNotNull(novaMap); + } + + @Test + public void testNovaMapProperties() { + assertEquals(Rectangle.class, novaMap.getBoundingBox().getClass()); + assertEquals(Node.class, novaMap.getNode().getClass()); + assertEquals(Line.class, novaMap.getLine().getClass()); + assertEquals(ColorProperties.class, novaMap.getColorProperties().getClass()); + assertEquals(10, novaMap.getZoomLevel()); + assertEquals(HashSet.class, novaMap.getShowList().getClass()); + assertEquals(SwingLayer.class, novaMap.getSwingLayers().get(0).getClass()); + assertEquals("2018/05", novaMap.getCurrentYearMonth()); + assertNotNull(novaMap.getDefaultBoundary()); + assertTrue(novaMap.isShowLegend()); + assertEquals(2, novaMap.getShowListSize()); + assertTrue(novaMap.containsShowList("test-1")); + assertTrue(novaMap.containsShowList("test-2", 10)); + novaMap.removeShowList("test-1"); + novaMap.removeShowList("test-2", 10); + novaMap.clearShowList(); + assertEquals(0, novaMap.getShowListSize()); + novaMap.removeSwingLayer(swingLayer); + novaMap.clearSwingLayers(); + assertNotEquals(null, novaMap.getTransform()); + } + + @Test + public void testGetBestZoomLevel() { + novaMap.getBestZoomLevel(13.13d, 28.28d, 23.13d, 38.28d, 10d, 10d); + } + + @Test + public void testGetPixelPos() { + novaMap.getPixelPos(13.13d, 28.28d); + } + + @Test + public void testGetLonLatFromPixel() { + novaMap.getLonLatFromPixel(10, 20); + } + + @Test + public void testGetImage() { + HttpServletRequest reuqest = Mockito.mock(HttpServletRequest.class); + novaMap.getImage(reuqest, new Rectangle2D.Double()); + } + + @Test + public void testSingleLeftClick() { + novaMap.singleLeftClick(13.13d, 10.10d, new Rectangle2D.Double()); + } + + @Test(expected=NullPointerException.class) + public void testSingleLeftClick_WhenTransFormIsNull() { + ReflectionTestUtils.setField(novaMap, "transform", null); + Rectangle2D.Double rd =new Rectangle2D.Double(); + rd.setRect(10d, 10d, 10d, 10d); + novaMap.singleLeftClick(13.13d, 10.10d, new Rectangle2D.Double()); + } + + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/layer/SwingLayerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/layer/SwingLayerTest.java new file mode 100644 index 00000000..e52d01b6 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/map/layer/SwingLayerTest.java @@ -0,0 +1,112 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.gmap.map.layer; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.gmap.line.Line; +import org.onap.portalsdk.analytics.gmap.map.ColorProperties; +import org.onap.portalsdk.analytics.gmap.map.NovaMap; +import org.onap.portalsdk.analytics.gmap.node.Node; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.springframework.test.util.ReflectionTestUtils; + +public class SwingLayerTest { + + SwingLayer swingLayer; + NovaMap novaMap; + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + Graphics2D g2d; + Graphics2D g2Legend; + + @Before + public void init() { + novaMap = new NovaMap(); + swingLayer = new SwingLayer(novaMap); + novaMap.setBoundingBox(10, 10); + novaMap.setNode(new Node(novaMap)); + novaMap.setLine(new Line(novaMap)); + novaMap.setColorProperties(new ColorProperties(novaMap)); + novaMap.setZoomLevel(10); + novaMap.addShowList("test-1"); + novaMap.addShowList("test-2", 10); + novaMap.addSwingLayer(swingLayer); + novaMap.setCurrentYearMonth("2018/05"); + novaMap.setDefaultBoundary(new Rectangle2D.Double()); + novaMap.setShowLegend(true); + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + Node nodeObj = new Node(new NovaMap()); + nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true); + nodeObj.addNode(13.14d, 10.11d, "nodeType", "nodeID", "type=international|year=2017", 13, true, true); + nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true); + novaMap.setNode(nodeObj); + swingLayer = new SwingLayer(novaMap); + BufferedImage image = new BufferedImage(novaMap.getBoundingBox().width, novaMap.getBoundingBox().height, BufferedImage.TYPE_INT_ARGB); + g2d = image.createGraphics(); + BufferedImage legendImage = new BufferedImage(novaMap.getBoundingBox().width, (int) (20 * novaMap.getShowListSize()) + 20, + BufferedImage.TYPE_INT_ARGB); + g2Legend = legendImage.createGraphics(); + g2Legend.setBackground(Color.WHITE); + } + + @Test + public void teestPaintLayer_WhenID1NotEqualToID2() { + Mockito.when(mockedRequest.getAttribute("server_process_id")).thenReturn("1"); + Mockito.when(mockedRequest.getSession().getAttribute("server_process_id")).thenReturn("2"); + swingLayer.paintLayer(mockedRequest, g2d, novaMap.getBoundingBox(), new Rectangle2D.Double(), g2Legend); + } + + @Test + public void teestPaintLayer_WhenID1EqualToID2() { + Mockito.when(mockedRequest.getAttribute("server_process_id")).thenReturn("1"); + Mockito.when(mockedRequest.getSession().getAttribute("server_process_id")).thenReturn("1"); + Rectangle2D rd = new Rectangle2D.Double(); + rd.setFrame(14064d, 12366d, 10d, 10d); + swingLayer.paintLayer(mockedRequest, g2d, novaMap.getBoundingBox(), rd, g2Legend); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeCollectionTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeCollectionTest.java new file mode 100644 index 00000000..1bd35c37 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeCollectionTest.java @@ -0,0 +1,122 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.gmap.node; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class NodeCollectionTest { + + NodeCollection nodeCollection; + private String NODE_ID = "nodeID"; + private String NODE_TYPE = "nodeType"; + + @Before + public void init() { + nodeCollection = new NodeCollection(); + NodeInfo nodeInfo = new NodeInfo(NODE_ID); + nodeInfo.setNodeType(NODE_TYPE); + nodeCollection.setNodeID(NODE_ID); + nodeCollection.addNode(nodeInfo); + nodeCollection.addSelectedNode(NODE_ID); + nodeCollection.addSelectedNode(NODE_ID, NODE_TYPE); + } + + @Test + public void testNotNull() { + assertNotNull(nodeCollection); + } + + @Test + public void testGetNode() { + NodeInfo nodeInfo = nodeCollection.getNode(NODE_ID+NODE_TYPE); + assertEquals(NODE_TYPE, nodeInfo.getNodeType()); + assertEquals(NODE_ID, nodeInfo.getNodeID()); + } + + @Test + public void testContainSelectedNodeByNodeID() { + assertEquals(true, nodeCollection.containSelectedNode(NODE_ID)); + } + + @Test + public void testContainSelectedNodeByNodeIDAndType() { + assertEquals(true, nodeCollection.containSelectedNode(NODE_ID, NODE_TYPE)); + } + + @Test + public void testRemoveSelectedNodeByNodeID() { + nodeCollection.removeSelectedNode(NODE_ID); + assertEquals(false, nodeCollection.containSelectedNode(NODE_ID)); + } + + @Test + public void testRemoveSelectedNodeByNodeIDAndNodeType() { + nodeCollection.removeSelectedNode(NODE_ID, NODE_TYPE); + assertEquals(false, nodeCollection.containSelectedNode(NODE_ID, NODE_TYPE)); + } + + @Test + public void testGetNodeID() { + assertEquals(NODE_ID, nodeCollection.getNodeID()); + } + + @Test + public void testGetSelectedNode() { + assertEquals(2, nodeCollection.getSelectedNode().size()); + } + + @Test + public void testClearNode() { + nodeCollection.clearNode(); + } + + @Test + public void testClearAllCollection() { + nodeCollection.clearAllCollection(); + } + + @Test + public void testGetSize() { + nodeCollection.clearAllCollection(); + assertEquals(0, nodeCollection.getSize()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeInfoTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeInfoTest.java new file mode 100644 index 00000000..bdc66784 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeInfoTest.java @@ -0,0 +1,130 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.gmap.node; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +public class NodeInfoTest { + + NodeInfo nodeInfo; + + private String NODE_ID = "nodeID"; + private String NODE_TYPE = "nodeType"; + private boolean MOVEABLE = true; + private boolean DELETEABLE = true; + private int STATE = 1; + + @Before + public void init() { + nodeInfo = new NodeInfo(NODE_ID); + nodeInfo.setNodeID(NODE_ID); + nodeInfo.setNodeType(NODE_TYPE); + nodeInfo.setMoveable(MOVEABLE); + nodeInfo.setDeleteable(DELETEABLE); + nodeInfo.setState(STATE); + List lineIDs = new ArrayList<>(); + lineIDs.add("test"); + nodeInfo.setLineIDS(lineIDs); + } + + @Test + public void testNotNull() { + assertNotNull(nodeInfo); + } + + @Test + public void testNodeInfoProperties() { + assertEquals(NODE_ID, nodeInfo.getNodeID()); + assertEquals(NODE_TYPE, nodeInfo.getNodeType()); + assertEquals(MOVEABLE, nodeInfo.isMoveable()); + assertEquals(DELETEABLE, nodeInfo.isDeleteable()); + assertEquals(STATE, nodeInfo.getState()); + } + + @Test + public void testAddLineID() { + nodeInfo.addLineID("test", "test"); + assertEquals("test>>test", nodeInfo.getLineID("test", "test")); + } + + @Test + public void testremoveLineID() { + nodeInfo.removeLineID("test", "test"); + assertEquals(null, nodeInfo.getLineID("test", "test")); + } + + @Test + public void testGetLineIDS() { + nodeInfo.getLineIDS(); + assertEquals("test", nodeInfo.getLineIDS().get(0)); + } + + @Test + public void testPrintLineIDS() { + nodeInfo.printLineIDS(); + } + + @Test + public void testCloneLineIDS() { + assertEquals("test",nodeInfo.cloneLineIDS().get(0)); + } + + @Test + public void testInitializeAttributes() { + MapnodeAttributes = new HashMap<>(); + nodeAttributes.put("test", "test"); + nodeInfo.initializeAttributes(nodeAttributes); + assertEquals("test",nodeInfo.getAttribute("test")); + assertEquals("test",nodeInfo.getAttributeKeys().get(0)); + } + + @Test + public void testClone() { + assertEquals("test",nodeInfo.clone().cloneLineIDS().get(0)); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java index 1f7b710e..a6cd2933 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/gmap/node/NodeTest.java @@ -1,5 +1,5 @@ /* - * ============LICENxSE_START========================================== + * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== * Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -40,13 +40,18 @@ package org.onap.portalsdk.analytics.gmap.node; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.awt.Point; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.junit.Test; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.gmap.map.ColorProperties; import org.onap.portalsdk.analytics.gmap.map.NovaMap; import org.onap.portalsdk.analytics.gmap.node.Node; +import org.springframework.test.util.ReflectionTestUtils; public class NodeTest { @@ -158,8 +163,12 @@ public class NodeTest { @Test public void testNodeExist() { - Node nodeObj = new Node(new NovaMap()); - + NovaMap novaMap = new NovaMap(); + novaMap.addShowList("nodeType"); + novaMap.addShowList("nodeType"); + novaMap.setColorProperties(new ColorProperties(novaMap)); + ReflectionTestUtils.setField(novaMap, "transform", new AffineTransform()); + Node nodeObj = new Node(novaMap); nodeObj.addNode(13.13d, 10.10d, "nodeType", "nodeID", "type=domestic|year=2016", 13, true, true); nodeObj.addNode(13.14d, 10.11d, "nodeType", "nodeID", "type=international|year=2017", 13, true, true); nodeObj.addNode(13.15d, 10.12d, "nodeType", "nodeID", "type=local|year=2018", 13, true, true); diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java new file mode 100644 index 00000000..a9b1bac2 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/DataCacheTest.java @@ -0,0 +1,328 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +package org.onap.portalsdk.analytics.model; + +import java.util.Vector; + +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.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.pdf.PdfReportHandler; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.DbUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.DataSet; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Globals.class, DbUtils.class, AppUtils.class }) +public class DataCacheTest { + @InjectMocks + DataCache dataCache = new DataCache(); + + @Before + public void init() throws Exception { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Mock + DataSet ds; + + @SuppressWarnings("static-access") + @Test + public void getDataViewActionsTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheDataViewActions()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery("test")).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(1, 0)).thenReturn("test"); + dataCache.getDataViewActions(); + } + + @SuppressWarnings("static-access") + @Test + public void getPublicReportIdNamesTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePublicReportIdNames()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery("test")).thenReturn(ds); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getPublicReportIdNames(); + } + + @SuppressWarnings("static-access") + @Test + public void getPublicReportIdNamesTest1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePublicReportIdNames()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery("test")).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getPublicReportIdNames(); + } + + @SuppressWarnings("static-access") + @Test + public void getPrivateAccessibleReportIdNamesTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePrivateAccessibleNamesA()).thenReturn("test"); + Mockito.when(Globals.getThePrivateAccessibleNamesB()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + dataCache.getPrivateAccessibleReportIdNames("test12", vc); + } + + @SuppressWarnings("static-access") + @Test + public void getPrivateAccessibleReportIdNamesTest1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getThePrivateAccessibleNamesA()).thenReturn("test"); + Mockito.when(Globals.getThePrivateAccessibleNamesB()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + dataCache.getPrivateAccessibleReportIdNames("test12", vc); + } + + @SuppressWarnings("static-access") + @Test + public void getGroupAccessibleReportIdNamesTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheGroupAccessibleNamesA()).thenReturn("test"); + Mockito.when(Globals.getTheGroupAccessibleNamesB()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + dataCache.getGroupAccessibleReportIdNames("test12", vc); + } + + @SuppressWarnings("static-access") + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void getTableSourceTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + dataCache.getTableSource("tableName", "dBinfo", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getTableSourceTest1() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + Mockito.when(Globals.grabTheReportTableC()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getTableSource("tableName", "dBinfo", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getTableSourceTest2() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + Mockito.when(Globals.grabTheReportTableC()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Mockito.when(Globals.grabTheReportTableElse()).thenReturn("abcd"); + dataCache.getTableSource("tableName", "local", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getTableSourceTest3() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(false); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.grabTheReportTableA()).thenReturn("tablename"); + Mockito.when(Globals.grabTheReportTableIf()).thenReturn("reporttable"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + Mockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); + Mockito.when(Globals.grabTheReportTableB()).thenReturn("tableB"); + Mockito.when(Globals.grabTheReportTableC()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Mockito.when(Globals.grabTheReportTableElse()).thenReturn("abcd"); + dataCache.getTableSource("tableName", "local", vc, "test12", mockedRequest); + } + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getReportTableJoins(); + } + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest1() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(0); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + dataCache.getReportTableJoins(); + } + + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest2() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(0); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(false); + dataCache.getReportTableJoins(vc); + } + + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest3() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(0); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Mockito.when(Globals.getTheReportTableJoins()).thenReturn("test"); + dataCache.getReportTableJoins(vc); + } + + @SuppressWarnings("static-access") + @Test + public void getReportTableJoinsTest4() throws Exception + { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getTheReportTableCrJoin()).thenReturn("test"); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); + Vector vc = new Vector(); + vc.add("test"); + vc.add("test1"); + Mockito.when(Globals.getRestrictTablesByRole()).thenReturn(true); + Mockito.when(Globals.getTheReportTableJoins()).thenReturn("test"); + dataCache.getReportTableJoins(vc); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java index 6a21dd10..77950ae7 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/ReportHandlerTest.java @@ -36,11 +36,8 @@ * */ - package org.onap.portalsdk.analytics.model; - - import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -52,6 +49,7 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -83,7 +81,10 @@ import org.onap.portalsdk.analytics.view.DataRow; import org.onap.portalsdk.analytics.view.DataValue; import org.onap.portalsdk.analytics.view.ReportColumnHeaderRows; import org.onap.portalsdk.analytics.view.ReportData; +import org.onap.portalsdk.analytics.view.ReportDataRows; import org.onap.portalsdk.analytics.view.ReportRowHeaderCols; +import org.onap.portalsdk.analytics.view.RowHeader; +import org.onap.portalsdk.analytics.view.RowHeaderCol; import org.onap.portalsdk.analytics.xmlobj.DataColumnList; import org.onap.portalsdk.analytics.xmlobj.DataColumnType; import org.onap.portalsdk.analytics.xmlobj.DataSourceList; @@ -98,43 +99,43 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; - @RunWith(PowerMockRunner.class) -@PrepareForTest({Globals.class, DbUtils.class, ESAPI.class, IAppUtils.class, AppUtils.class, ConnectionUtils.class}) +@PrepareForTest({ Globals.class, DbUtils.class, ESAPI.class, IAppUtils.class, AppUtils.class, ConnectionUtils.class, + ReportLoader.class, HashMap.class }) public class ReportHandlerTest { private ReportHandler reportHandler; - + @Mock HttpServletRequest httpServletRequest; @Mock HttpServletResponse httpServletResponse; - + @Mock ServletOutputStream servletOutputStream; - + @Mock ServletContext servletContext; - + @Mock HttpSession httpSession; @Mock AppUtils appUtils; - + @Mock ReportRuntime reportRuntime; - + @Mock ReportDefinition reportDefinition; @Mock WizardSequence wizardSequence; - + @Mock Encoder encoder; - + @Mock IAppUtils iAppUtils; @@ -143,92 +144,74 @@ public class ReportHandlerTest { @Mock FileOutputStream fileOutputStream; - + @Mock PrintWriter printWriter; - + @Mock DataSourceList dataSourceList; - - @Mock + + @Mock ReportRowHeaderCols reportRowHeaderCols; - + @Mock ReportColumnHeaderRows reportColumnHeaderRows; - + @Mock + ReportDataRows reportDataRows; + @Mock Writer iowriter; - + @Mock File file; @Mock Connection connection; - + @Mock Statement statement; - + @Mock ResultSet resultSet; - + @Mock ResultSetMetaData resultSetMetaData; private String REPORT_ID = "1000"; - + @Before - public void setUp() throws Exception { - + public void setUp() throws Exception { + PowerMockito.mockStatic(DbUtils.class); PowerMockito.mockStatic(Globals.class); PowerMockito.mockStatic(IAppUtils.class); PowerMockito.mockStatic(ESAPI.class); PowerMockito.mockStatic(AppUtils.class); PowerMockito.mockStatic(ConnectionUtils.class); - + PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(file); - Mockito.when(file.createNewFile()).thenReturn(true); - - PowerMockito.whenNew(FileInputStream.class).withArguments(Matchers.anyString()).thenReturn(fileInputStream); - PowerMockito.whenNew(FileOutputStream.class).withArguments(Matchers.anyString()).thenReturn(fileOutputStream); + Mockito.when(file.createNewFile()).thenReturn(true); - /* - PowerMockito.whenNew(FileOutputStream.class).withArguments(Matchers.anyString()).thenAnswer( - - new Answer() { - - @Override - public FileOutputStream answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - String string = (String)args[0]; - - System.out.println("------------------------------ callled -------------------------=============>>>>>>>>>>>>>>>> " + string); - - return fileOutputStream; - } - - - } - ); - */ + PowerMockito.whenNew(FileInputStream.class).withArguments(Matchers.anyString()).thenReturn(fileInputStream); + PowerMockito.whenNew(FileOutputStream.class).withArguments(Matchers.anyString()).thenReturn(fileOutputStream); Mockito.when(httpServletRequest.getSession()).thenReturn(httpSession); Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(reportDefinition); Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime); - + Mockito.when(reportRuntime.getReportID()).thenReturn(REPORT_ID); - + PowerMockito.when(ESAPI.encoder()).thenReturn(encoder); PowerMockito.when(Globals.getAppUtils()).thenReturn(iAppUtils); - + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); - - //Mockito.when(appUtils.getUserID(httpServletRequest)).thenReturn("USER1"); + + // Mockito.when(appUtils.getUserID(httpServletRequest)).thenReturn("USER1"); reportHandler = Mockito.spy(ReportHandler.class); } - + @Test public void testSaveAsExcelFile_case1() { String saveOutput = ""; @@ -236,7 +219,7 @@ public class ReportHandlerTest { DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); @@ -246,19 +229,19 @@ public class ReportHandlerTest { PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - ArrayList paramList = null; + ArrayList paramList = null; paramList = new ArrayList(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); - + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + String para = ""; - - int i=1; - while(i<20) { - para = para + "

This is a paragraph.

" + "\n" + "

This is another paragraph.

" + "\n"; + + int i = 1; + while (i < 20) { + para = para + "

This is a paragraph.

" + "\n" + "

This is another paragraph.

" + "\n"; i++; } @@ -270,42 +253,27 @@ public class ReportHandlerTest { Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); - //ReflectionTestUtils.setField(reportData, "reportRowHeaderCols", reportRowHeaderCols); saveOutput = reportHandler.saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); - //Assert.assertNotNull(saveOutput); - Mockito.verify(reportHandler, Mockito.times(1)).saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); + Mockito.verify(reportHandler, Mockito.times(1)).saveAsExcelFile(httpServletRequest, reportData, null, + "Report 1", "Report 1 Desc"); } - - - - - @Test public void testSaveAsExcelFile_case2() throws Exception { String saveOutput = ""; ReportData reportData = prepareReportData(); DataSourceList dataSourceList = new DataSourceList(); - List listDataSourceType = dataSourceList.getDataSource(); - DataSourceType dataSourceType1 = new DataSourceType(); - DataColumnList dataColumnList1 = new DataColumnList(); - List listDataColumnType1 = dataColumnList1.getDataColumn(); - + List listDataColumnType1 = dataColumnList1.getDataColumn(); DataColumnType dataColumnType1 = new DataColumnType(); dataColumnType1.setSemaphoreId("Id1"); listDataColumnType1.add(dataColumnType1); - dataSourceType1.setDataColumnList(dataColumnList1); - listDataSourceType.add(dataSourceType1); - - reportData.setReportDataList(prepareDataRowList()); - PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); @@ -315,19 +283,19 @@ public class ReportHandlerTest { PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - ArrayList paramList = null; + ArrayList paramList = null; paramList = new ArrayList(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); - + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + String para = ""; - - int i=1; - while(i<20) { - para = para + "

This is a paragraph.

" + "\n" + "

This is another paragraph.

" + "\n"; + + int i = 1; + while (i < 20) { + para = para + "

This is a paragraph.

" + "\n" + "

This is another paragraph.

" + "\n"; i++; } @@ -339,23 +307,21 @@ public class ReportHandlerTest { Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); - //ReflectionTestUtils.setField(reportData, "reportRowHeaderCols", reportRowHeaderCols); - - SemaphoreList semaphoreList = new SemaphoreList(); + SemaphoreList semaphoreList = new SemaphoreList(); List listSemaphoreType = semaphoreList.getSemaphore(); - + SemaphoreType st1 = new SemaphoreType(); SemaphoreType st2 = new SemaphoreType(); FormatList formatList = new FormatList(); - + List listFormatType = formatList.getFormat(); - + FormatType formatType1 = new FormatType(); FormatType formatType2 = new FormatType(); - + listFormatType.add(formatType1); - + formatType2.setBgColor("blue"); formatType2.setFontColor("black"); formatType2.setBold(true); @@ -365,101 +331,80 @@ public class ReportHandlerTest { formatType2.setUnderline(true); formatType2.setUnderline(true); formatType2.setFontSize("20"); - + listFormatType.add(formatType2); - - + st1.setSemaphoreName("Name1"); - st1.setSemaphoreId("Id1"); - - st1.setFormatList(formatList); - + st1.setSemaphoreId("Id1"); + + st1.setFormatList(formatList); + st2.setSemaphoreName("Name2"); - st2.setSemaphoreId("Id2"); - - st2.setFormatList(formatList); - listSemaphoreType.add(st1); - listSemaphoreType.add(st2); - - mockHttpAttribute(AppConstants.RI_REPORT_ID, REPORT_ID); - + st2.setSemaphoreId("Id2"); + + st2.setFormatList(formatList); + listSemaphoreType.add(st1); + listSemaphoreType.add(st2); + + mockHttpAttribute(AppConstants.RI_REPORT_ID, REPORT_ID); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); Mockito.when(reportRuntime.getSemaphoreList()).thenReturn(semaphoreList); Mockito.when(reportDefinition.addSemaphore(Mockito.anyObject(), Mockito.anyObject())).thenReturn(st1); - - - + saveOutput = reportHandler.saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); - //Assert.assertNotNull(saveOutput); - Mockito.verify(reportHandler, Mockito.times(1)).saveAsExcelFile(httpServletRequest, reportData, null, "Report 1", "Report 1 Desc"); + Mockito.verify(reportHandler, Mockito.times(1)).saveAsExcelFile(httpServletRequest, reportData, null, + "Report 1", "Report 1 Desc"); } - - + private ArrayList prepareDataRowList() { + ArrayList alDataRow = new ArrayList(); - - - - - - - - - - - - - - - private ArrayList prepareDataRowList(){ - ArrayList alDataRow = new ArrayList(); - DataRow dataRow = new DataRow(); - + dataRow.setRowNum(1); dataRow.setRowFormat(true); - + DataValue dataValue1 = new DataValue(); dataValue1.setColId("REPORT_ID"); dataValue1.setColName("REPORT_ID"); dataValue1.setDisplayName("REPORT ID"); - dataValue1.setVisible(true); - + dataValue1.setVisible(true); + DataValue dataValue2 = new DataValue(); dataValue2.setColId("ORDER_ID"); dataValue2.setColName("ORDER_ID"); dataValue2.setDisplayName("ORDER ID"); dataValue2.setVisible(true); - + dataRow.addDataValue(dataValue1); dataRow.addDataValue(dataValue2); - + alDataRow.add(dataRow); - + return alDataRow; } - + private ReportData prepareReportData() { - + ReportData reportData = new ReportData(1, true); reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); - + DataRow dataRow = new DataRow(); - + dataRow.setRowNum(1); dataRow.setRowFormat(true); - + reportData.addRowNumbers(1, prepareDataRowList()); - + return reportData; } - @Test public void testCreateExcelFileContent_case1() throws Exception { ReportData reportData = prepareReportData(); - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); @@ -478,37 +423,38 @@ public class ReportHandlerTest { Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 2); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); - Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 2); + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); - } - + @Test public void testCreateExcelFileContent_case2() throws Exception { ReportData reportData = prepareReportData(); - + DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); - ArrayList paramList = null; + ArrayList paramList = null; paramList = new ArrayList(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); - + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); @@ -518,46 +464,37 @@ public class ReportHandlerTest { Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); - /* - PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getPrintFooterInDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - */ - reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 1); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 1); } - @Test public void testCreateExcelFileContent_case3() throws Exception { ReportData reportData = prepareReportData(); - + DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); - ArrayList paramList = null; + ArrayList paramList = null; paramList = new ArrayList(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); @@ -567,54 +504,41 @@ public class ReportHandlerTest { Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); - - + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); - /* - PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getPrintFooterInDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - */ - reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 3); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); } - - @Test - public void testCreateExcel2007FileContent_case1() throws Exception { - - + public void testCreateExcelFileContent_case4() throws Exception { ReportData reportData = prepareReportData(); - + DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); - ArrayList paramList = null; + ArrayList paramList = null; paramList = new ArrayList(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); @@ -624,57 +548,43 @@ public class ReportHandlerTest { Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); - - + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - /* - PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getPrintFooterInDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - */ - reportHandler.createExcel2007FileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 3); - } - - - @Test - public void testCreateExcel2007FileContent_case2() throws Exception { - - + public void testCreateExcelFileContent_case5() throws Exception { ReportData reportData = prepareReportData(); - + DataSourceList dataSourceList = new DataSourceList(); reportData.setReportDataList(prepareDataRowList()); - - + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); - ArrayList paramList = null; + ArrayList paramList = null; paramList = new ArrayList(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - - Mockito.when(reportRuntime.getReportID()).thenReturn(REPORT_ID); - Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); @@ -683,404 +593,2516 @@ public class ReportHandlerTest { Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); - Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn(REPORT_ID); - + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); - Map mapReportRuntime = new TreeMap(); - Map mapReportData = new TreeMap(); - - mapReportRuntime.put("ReportRuntime#1", reportRuntime); - mapReportData.put("ReportData#1", reportData); - - Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(mapReportRuntime); - - Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(mapReportData); - - Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); - Mockito.when(reportRuntime.getTemplateFile()).thenReturn(""); - Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - /* - PowerMockito.when(Globals.getShowDescrAtRuntime()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getPrintFooterInDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - */ - reportHandler.createExcel2007FileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "PORTAL_USER", 3); - - } - - - - - - - - - - - - @Test - public void testCreateCSVFileContent_WithoutSql_case1() throws Exception { + public void testCreateExcelFileContent_case6() throws Exception { ReportData reportData = prepareReportData(); - - Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); - mockHttpAttribute("pdfAttachmentKey", "PdfKey"); - mockHttpAttribute("log_id", "Log#1234"); - mockHttpAttribute("user_id", "demo"); - mockHttpAttribute("raw", "false"); + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); - Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); - Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); - Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); - - mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, null); + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); - - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); - PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); - PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - - ArrayList paramList = null; + ArrayList paramList = null; paramList = new ArrayList(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); - - Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); - - //Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); - - Mockito.when(reportRuntime.getWholeSQL()).thenReturn(""); - - - Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - reportHandler.createCSVFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse); - } - - @Test - public void testCreateCSVFileContent_WithSql_case1() throws Exception { - ReportData reportData = prepareReportData(); - - Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); - - mockHttpAttribute("pdfAttachmentKey", "PdfKey"); - mockHttpAttribute("log_id", "Log#1234"); - mockHttpAttribute("user_id", "demo"); - mockHttpAttribute("raw", "false"); Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); - - mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); - - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); - PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); - PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); - PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - - Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); - Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet); - Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); - Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(1); - Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); - Mockito.when(resultSetMetaData.getColumnLabel(Mockito.anyInt())).thenReturn("column1"); - Mockito.when(resultSet.getString(Mockito.anyInt())).thenReturn("value1"); - - - ArrayList paramList = null; - paramList = new ArrayList(); - paramList.add(new IdNameValue("Name", "Portal SDK")); - paramList.add(new IdNameValue("Org", "ONAP")); - paramList.add(new IdNameValue("Status", "Active")); + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); - Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); - - Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); - - + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - reportHandler.createCSVFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse); - } - - private void mockHttpAttribute(String attributeName, String attributeValue) { - Mockito.when(httpServletRequest.getAttribute(attributeName)).thenReturn(attributeValue); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + private ReportData prepareReportData1() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData2() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setDisplayTotal("SUM("); + value.setBold(true); + DataValue value1 = null; + // value1.setColId("test"); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData3() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("date"); + value.setColName("date"); + value.setDisplayTotal("SUM("); + value.setBold(true); + DataValue value1 = null; + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData4() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setColName("date"); + value.setDisplayTotal("SUM("); + value.setBold(true); + DataValue value1 = null; + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData5() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setColName("date"); + value.setDisplayTotal("SUM("); + value.setBold(true); + DataValue value1 = new DataValue(); + value1.setColId("test"); + value1.setColName("date"); + value1.setDisplayTotal("SUM("); + value1.setBold(false); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData6() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setColName("date"); + value.setDisplayTotal("SUM("); + value.setDisplayValue("$Test123"); + value.setBold(true); + DataValue value1 = new DataValue(); + value1.setColId("test"); + value1.setColName("date"); + value1.setDisplayTotal("SUM("); + value1.setColName("test999"); + value1.setBold(false); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + private ReportData prepareReportData7() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setColName("date"); + value.setDisplayTotal("SUM("); + value.setDisplayValue("$Test123."); + value.setBold(true); + DataValue value1 = new DataValue(); + value1.setColId("test"); + value1.setColName("date"); + value1.setDisplayTotal("SUM("); + value1.setColName("test999"); + value1.setDisplayValue("$Test123."); + value1.setBold(false); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; + } + + + private ReportData prepareReportData8() { + + ReportData reportData = new ReportData(1, true); + reportData.createColumn("REPORT_ID", "REPORT ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + reportData.createColumn("ORDER_ID", "ORDER ID", "500", "right", true, "Asc", true, 1, 1, 1, true); + + DataRow dataRow = new DataRow(); + + dataRow.setRowNum(1); + dataRow.setRowFormat(true); + + reportData.addRowNumbers(1, prepareDataRowList()); + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setColName(null); + value.setDisplayTotal("SUM("); + value.setDisplayValue("$Test123"); + value.setBold(true); + DataValue value1 = new DataValue(); + value1.setColId("test"); + value1.setColName("date"); + value1.setDisplayTotal("SUM("); + value1.setColName("test999"); + value1.setBold(false); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + reportData.reportDataTotalRow = reportDataRows; + reportData.reportDataRows = reportDataRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + RowHeader rowHeader = new RowHeader(); + rowHeaderCol.add(rowHeader); + RowHeader rowHeader1 = new RowHeader(); + rowHeaderCol.add(rowHeader1); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + RowHeader rowHeader2 = new RowHeader(); + rowHeaderCol1.add(rowHeader2); + RowHeader rowHeader3 = new RowHeader(); + RowHeader rowHeader6 = new RowHeader(); + rowHeaderCol1.add(rowHeader3); + rowHeaderCol1.add(rowHeader6); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + RowHeaderCol rowHeaderCol2 = new RowHeaderCol(); + RowHeader rowHeader5 = new RowHeader(); + RowHeader rowHeader4 = new RowHeader(); + rowHeaderCol2.add(rowHeader5); + rowHeaderCol2.add(rowHeader4); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol2); + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + + return reportData; } + @Test - public void testCreateHTMLFileContent_WithoutSql_case1() throws Exception { + public void testCreateExcelFileContent_case7() throws Exception { + ReportData reportData = prepareReportData1(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case8() throws Exception { + ReportData reportData = prepareReportData1(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case9() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case10() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("$test"); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case35() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("test."); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case36() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1,"); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + + + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case11() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("$1"); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case12() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("$.1"); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test + public void testCreateExcel2007FileContent_case1() throws Exception { + + ReportData reportData = prepareReportData(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + reportHandler.createExcel2007FileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test + public void testCreateExcel2007FileContent_case2() throws Exception { + + ReportData reportData = prepareReportData(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getReportID()).thenReturn(REPORT_ID); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn(REPORT_ID); + + Map mapReportRuntime = new TreeMap(); + Map mapReportData = new TreeMap(); + + mapReportRuntime.put("ReportRuntime#1", reportRuntime); + mapReportData.put("ReportData#1", reportData); + + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)) + .thenReturn(mapReportRuntime); + + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(mapReportData); + + Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); + Mockito.when(reportRuntime.getTemplateFile()).thenReturn(""); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + reportHandler.createExcel2007FileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test + public void testCreateCSVFileContent_WithoutSql_case1() throws Exception { + ReportData reportData = prepareReportData(); + + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + + mockHttpAttribute("pdfAttachmentKey", "PdfKey"); + mockHttpAttribute("log_id", "Log#1234"); + mockHttpAttribute("user_id", "demo"); + mockHttpAttribute("raw", "false"); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, null); + + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); + PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); + PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); + + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + Mockito.when(reportRuntime.getWholeSQL()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + reportHandler.createCSVFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse); + } + + @Test + public void testCreateCSVFileContent_WithSql_case1() throws Exception { + ReportData reportData = prepareReportData(); + + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + + mockHttpAttribute("pdfAttachmentKey", "PdfKey"); + mockHttpAttribute("log_id", "Log#1234"); + mockHttpAttribute("user_id", "demo"); + mockHttpAttribute("raw", "false"); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); + + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(false); + PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); + PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); + PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); + + Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + + Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(1); + Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); + + Mockito.when(resultSetMetaData.getColumnLabel(Mockito.anyInt())).thenReturn("column1"); + Mockito.when(resultSet.getString(Mockito.anyInt())).thenReturn("value1"); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); + + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + reportHandler.createCSVFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse); + } + + private void mockHttpAttribute(String attributeName, String attributeValue) { + Mockito.when(httpServletRequest.getAttribute(attributeName)).thenReturn(attributeValue); + } + + @Test + public void testCreateHTMLFileContent_WithoutSql_case1() throws Exception { + + ReportData reportData = prepareReportData(); + + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + + mockHttpAttribute("pdfAttachmentKey", "PdfKey"); + mockHttpAttribute("log_id", "Log#1234"); + mockHttpAttribute("user_id", "demo"); + mockHttpAttribute("raw", "false"); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, null); + + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); + PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); + PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); + + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + Mockito.when(reportRuntime.getWholeSQL()).thenReturn(""); + + Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + reportHandler.createHTMLFileContent(iowriter, reportData, reportRuntime, "", httpServletRequest, + httpServletResponse); + } + + @Test(expected = RaptorException.class) + public void testCreateHTMLFileContent_WithSql_case1() throws Exception { + + ReportData reportData = prepareReportData(); + + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + + mockHttpAttribute("pdfAttachmentKey", "PdfKey"); + mockHttpAttribute("log_id", "Log#1234"); + mockHttpAttribute("user_id", "demo"); + mockHttpAttribute("raw", "false"); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); + + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); + PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); + PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); + + Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + + Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(1); + Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); + + Mockito.when(resultSetMetaData.getColumnLabel(Mockito.anyInt())).thenReturn("column1"); + Mockito.when(resultSet.getString(Mockito.anyInt())).thenReturn("value1"); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); + + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + + Mockito.when(reportRuntime.getWholeSQL()).thenReturn(""); + + Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + reportHandler.createHTMLFileContent(iowriter, reportData, reportRuntime, + "select column1 from table1 where column2='test'", httpServletRequest, httpServletResponse); + } + + @Test + public void testCreateFlatFileContent_case1() throws IOException, Exception { + ReportData reportData = prepareReportData(); + + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + + mockHttpAttribute("pdfAttachmentKey", "PdfKey"); + mockHttpAttribute("log_id", "Log#1234"); + mockHttpAttribute("user_id", "demo"); + mockHttpAttribute("raw", "false"); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + + mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); + + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); + PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); + PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); + PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); + + Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + + Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); + Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); + + Mockito.when(reportRuntime.loadReportData(Mockito.anyInt(), Mockito.anyString(), Mockito.anyInt(), + Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(reportData); + + Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + DataColumnType dataColumnType1 = new DataColumnType(); + + dataColumnType1.setTableId("reportaccess"); + dataColumnType1.setDbColName("REP_ID"); + dataColumnType1.setColName("REP_ID"); + dataColumnType1.setDbColType("INTEGER"); + dataColumnType1.setDisplayName("Report Id"); + + DataColumnType dataColumnType2 = new DataColumnType(); + + dataColumnType2.setTableId("reportaccess"); + dataColumnType2.setDbColName("ORDER_NO"); + dataColumnType2.setColName("ORDER_NO"); + dataColumnType2.setDbColType("INTEGER"); + dataColumnType2.setDisplayName("Order No"); + + List listDataColumnType = new ArrayList(); + listDataColumnType.add(dataColumnType1); + listDataColumnType.add(dataColumnType2); + + Mockito.when(reportRuntime.getAllColumns()).thenReturn(listDataColumnType); + + reportHandler.createFlatFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "USER#1"); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case15() throws Exception { + ReportData reportData = prepareReportData3(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("$test"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case16() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011 11:11:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case17() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011 11:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case18() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/11 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case19() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011 11:11:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case25() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1/1/2011 1:11:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case26() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1/1/2011 1:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case27() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1/1/2011"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case28() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("2011/1/1"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case29() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("2011-1-1 1:11:11"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case30() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("111 2011"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case31() throws Exception { + ReportData reportData = prepareReportData4(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); + + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1/2011"); + java.util.HashMap dataTypeMap = Mockito.mock(HashMap.class); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withNoArguments().thenReturn(dataTypeMap); + + Mockito.when(dataTypeMap.get("test")).thenReturn("test"); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); + + } + + - ReportData reportData = prepareReportData(); - - Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + @Test(expected = java.lang.NullPointerException.class) + public void testCreateExcelFileContent_case20() throws Exception { + ReportData reportData = prepareReportData5(); - mockHttpAttribute("pdfAttachmentKey", "PdfKey"); - mockHttpAttribute("log_id", "Log#1234"); - mockHttpAttribute("user_id", "demo"); - mockHttpAttribute("raw", "false"); + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); - - mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, null); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); - PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); - PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - - ArrayList paramList = null; - paramList = new ArrayList(); - paramList.add(new IdNameValue("Name", "Portal SDK")); - paramList.add(new IdNameValue("Org", "ONAP")); - paramList.add(new IdNameValue("Status", "Active")); + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); - Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); - - Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); - - - //Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); - - Mockito.when(reportRuntime.getWholeSQL()).thenReturn(""); + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); - Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); - Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - reportHandler.createHTMLFileContent(iowriter, reportData, reportRuntime, "", httpServletRequest, httpServletResponse); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); + + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); + } - @Test(expected =RaptorException.class) - public void testCreateHTMLFileContent_WithSql_case1() throws Exception { - - ReportData reportData = prepareReportData(); - - Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + @Test(expected = java.lang.NullPointerException.class) + public void testCreateExcelFileContent_case21() throws Exception { + ReportData reportData = prepareReportData6(); - mockHttpAttribute("pdfAttachmentKey", "PdfKey"); - mockHttpAttribute("log_id", "Log#1234"); - mockHttpAttribute("user_id", "demo"); - mockHttpAttribute("raw", "false"); + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); - - mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); - - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); - PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); - PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - - Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); - Mockito.when(connection.createStatement()).thenReturn(statement); - - Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet); - Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); - Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(1); - Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - Mockito.when(resultSetMetaData.getColumnLabel(Mockito.anyInt())).thenReturn("column1"); - Mockito.when(resultSet.getString(Mockito.anyInt())).thenReturn("value1"); - - ArrayList paramList = null; - paramList = new ArrayList(); - paramList.add(new IdNameValue("Name", "Portal SDK")); - paramList.add(new IdNameValue("Org", "ONAP")); - paramList.add(new IdNameValue("Status", "Active")); + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); - Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("(column1='Y'~column2='N')"); - - Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); - - - //Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); - - Mockito.when(reportRuntime.getWholeSQL()).thenReturn(""); + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); - Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); - Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - - reportHandler.createHTMLFileContent(iowriter, reportData, reportRuntime, "select column1 from table1 where column2='test'", httpServletRequest, httpServletResponse); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011 11:11:11"); + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); + } + + @Test(expected = java.lang.NullPointerException.class) + public void testCreateExcelFileContent_case22() throws Exception { + ReportData reportData = prepareReportData6(); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011 11:11:11"); + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); + } - @Test - public void testCreateFlatFileContent_case1() throws IOException, Exception { - ReportData reportData = prepareReportData(); - + @Test(expected = java.lang.NullPointerException.class) + public void testCreateExcelFileContent_case23() throws Exception { + ReportData reportData = prepareReportData7(); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); + + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - mockHttpAttribute("pdfAttachmentKey", "PdfKey"); - mockHttpAttribute("log_id", "Log#1234"); - mockHttpAttribute("user_id", "demo"); - mockHttpAttribute("raw", "false"); + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011"); + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); + + } + + @Test(expected = java.lang.NullPointerException.class) + public void testCreateExcelFileContent_case24() throws Exception { + ReportData reportData = prepareReportData8(); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(false); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(false); Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); - - mockHttpAttribute(AppConstants.RI_REPORT_SQL_WHOLE, "select column1 from table1 where column2='test'"); - - PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); - PowerMockito.when(Globals.getFooterFirstLine()).thenReturn("Footer First Line"); - PowerMockito.when(Globals.getFooterSecondLine()).thenReturn("Footer Second Line"); - PowerMockito.when(Globals.getPrintParamsInCSVDownload()).thenReturn(true); - PowerMockito.when(Globals.getShowDisclaimer()).thenReturn(true); - - Mockito.when(ConnectionUtils.getConnection(Mockito.anyString())).thenReturn(connection); - Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - Mockito.when(statement.executeQuery(Mockito.anyString())).thenReturn(resultSet); - Mockito.when(resultSet.next()).thenReturn(true).thenReturn(false); + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); + + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 2); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("11/11/2011"); + Mockito.verify(reportHandler, Mockito.times(1)).createExcelFileContent(iowriter, reportData, reportRuntime, + httpServletRequest, httpServletResponse, "PORTAL_USER", 2); + + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case37() throws Exception { + ReportData reportData = prepareReportData2(); + + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); + + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); - - ArrayList paramList = null; + ArrayList paramList = null; paramList = new ArrayList(); paramList.add(new IdNameValue("Name", "Portal SDK")); paramList.add(new IdNameValue("Org", "ONAP")); paramList.add(new IdNameValue("Status", "Active")); - Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_CROSSTAB); - Mockito.when(reportRuntime.getWholeSQL()).thenReturn("select column1 from table1 where column2='test'"); - Mockito.when(reportRuntime.loadReportData(Mockito.anyInt(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyObject(), Mockito.anyBoolean())).thenReturn(reportData); + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); + + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); + + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); + + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); + + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); - Mockito.when(httpServletResponse.getWriter()).thenReturn(printWriter); Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - DataColumnType dataColumnType1 = new DataColumnType(); - - dataColumnType1.setTableId("reportaccess"); - dataColumnType1.setDbColName("REP_ID"); - dataColumnType1.setColName("REP_ID"); - dataColumnType1.setDbColType("INTEGER"); - dataColumnType1.setDisplayName("Report Id"); - - DataColumnType dataColumnType2 = new DataColumnType(); - - dataColumnType2.setTableId("reportaccess"); - dataColumnType2.setDbColName("ORDER_NO"); - dataColumnType2.setColName("ORDER_NO"); - dataColumnType2.setDbColType("INTEGER"); - dataColumnType2.setDisplayName("Order No"); - - List listDataColumnType = new ArrayList(); - listDataColumnType.add(dataColumnType1); - listDataColumnType.add(dataColumnType2); - - Mockito.when(reportRuntime.getAllColumns()).thenReturn(listDataColumnType); - - - reportHandler.createFlatFileContent(iowriter, reportData, reportRuntime, httpServletRequest, httpServletResponse, "USER#1"); - - } - - - /* + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); - @Test + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("1."); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - @Test - public void testSaveAsExcelFileHttpServletRequestReportDataArrayListStringStringInt() { - fail("Not yet implemented"); } + + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void testCreateExcelFileContent_case38() throws Exception { + ReportData reportData = prepareReportData2(); - @Test - public void testCreateExcelFileContent() { - fail("Not yet implemented"); - } + DataSourceList dataSourceList = new DataSourceList(); + reportData.setReportDataList(prepareDataRowList()); - @Test - public void testCreateFlatFileContent() { - fail("Not yet implemented"); - } + PowerMockito.when(Globals.getSheetName()).thenReturn("Raptor Reports"); + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.getPrintParamsInDownload()).thenReturn(true); + ArrayList paramList = null; + paramList = new ArrayList(); + paramList.add(new IdNameValue("Name", "Portal SDK")); + paramList.add(new IdNameValue("Org", "ONAP")); + paramList.add(new IdNameValue("Status", "Active")); - @Test - public void testSaveXMLFile() { - fail("Not yet implemented"); - } + Mockito.when(reportRuntime.getParamNameValuePairsforPDFExcel(httpServletRequest, 1)).thenReturn(paramList); - @Test - public void testLoadReportRuntimeHttpServletRequestString() { - fail("Not yet implemented"); - } + Mockito.when(reportRuntime.getReportTitle()).thenReturn("Raptor Reports Excel"); + Mockito.when(reportRuntime.getReportName()).thenReturn("Report for ONAP Portal"); + Mockito.when(reportRuntime.getReportDescr()).thenReturn("Report for ONAP Portal Desc"); + Mockito.when(reportRuntime.getDataSourceList()).thenReturn(dataSourceList); - @Test - public void testLoadReportRuntimeHttpServletRequestStringBoolean() { - fail("Not yet implemented"); - } + Mockito.when(reportRuntime.getVisibleColumnCount()).thenReturn(3); + Mockito.when(reportRuntime.getReportType()).thenReturn(AppConstants.RT_LINEAR); + Mockito.when(reportRuntime.getDbInfo()).thenReturn("tetDB"); - @Test - public void testLoadReportRuntimeHttpServletRequestStringBooleanInt() { - fail("Not yet implemented"); - } + Mockito.when(httpSession.getAttribute("drilldown_index")).thenReturn("1"); + Mockito.when(httpSession.getAttribute("TITLE_1")).thenReturn("ONAP Report"); + Mockito.when(httpSession.getAttribute("SUBTITLE_1")).thenReturn("ONAP Portal SDK Raptor"); - @Test - public void testCreateReportDefinition() { - fail("Not yet implemented"); - } + Mockito.when(httpSession.getAttribute("SI_DASHBOARD_REP_ID")).thenReturn(REPORT_ID); + Mockito.when(httpSession.getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(null); - @Test - public void testLoadReportDefinition() { - fail("Not yet implemented"); - } + Mockito.when(iAppUtils.getTempFolderPath()).thenReturn(""); - @Test - public void testSetSheetName() { - fail("Not yet implemented"); - } + Mockito.when(httpServletResponse.getOutputStream()).thenReturn(servletOutputStream); - @Test - public void testGetSheetName() { - fail("Not yet implemented"); - } + PowerMockito.when(Globals.getPrintTitleInDownload()).thenReturn(true); + PowerMockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); - @Test - public void testGetColumnCountForDownloadFile() { - fail("Not yet implemented"); - } + Mockito.when(reportRuntime.getFormFieldComments(httpServletRequest)).thenReturn("test:|:"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.getSystemDateTime()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.when(Globals.getScheduleDatePattern()).thenReturn("MM/dd/yyyy kk:mm:ss"); + PowerMockito.when(Globals.disclaimerPositionedTopInCSVExcel()).thenReturn(true); + PowerMockito.when(reportRuntime.getWholeSQL()).thenReturn("test sql"); + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(connection); + Mockito.when(connection.createStatement()).thenReturn(statement); + Mockito.when(statement.executeQuery(Matchers.anyString())).thenReturn(resultSet); + Mockito.when(resultSet.getMetaData()).thenReturn(resultSetMetaData); + Mockito.when(resultSetMetaData.getColumnCount()).thenReturn(2); + Mockito.when(resultSetMetaData.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(httpSession.getAttribute("FOOTER_" + 1)).thenReturn("footer"); + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(Matchers.anyInt())).thenReturn("test,."); + java.util.HashMap dataTypeMap = new java.util.HashMap(); + dataTypeMap.put("test", "test"); + PowerMockito.whenNew(java.util.HashMap.class).withAnyArguments().thenReturn(dataTypeMap); + reportHandler.createExcelFileContent(iowriter, reportData, reportRuntime, httpServletRequest, + httpServletResponse, "PORTAL_USER", 3); - @Test - public void testCreateHTMLFileContent() { - fail("Not yet implemented"); } - */ } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ChartSeqComparatorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ChartSeqComparatorTest.java new file mode 100644 index 00000000..25b70b8b --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ChartSeqComparatorTest.java @@ -0,0 +1,66 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.base; + +import static org.junit.Assert.assertNotEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; + +public class ChartSeqComparatorTest { + + ChartSeqComparator chartSeqComparator; + + private Integer CHAR_SEQ = 1000; + + @Before + public void init() { + chartSeqComparator = new ChartSeqComparator(); + } + + + @Test + public void testCompare() { + DataColumnType dct1 = new DataColumnType(); + DataColumnType dct2 = new DataColumnType(); + dct1.setChartSeq(CHAR_SEQ); + dct2.setChartSeq(CHAR_SEQ); + assertNotEquals(true, chartSeqComparator.compare(dct1, dct2)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameColLookupTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameColLookupTest.java new file mode 100644 index 00000000..9269d240 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameColLookupTest.java @@ -0,0 +1,75 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class IdNameColLookupTest { + + IdNameColLookup idNameColLookup; + + private String COL_ID = "colId"; + private String DB_TABLE_NAME = "dbTableName"; + private String DB_ID_FIELD = "dbIdField"; + private String DB_NAME_FIELD = "dbNameField"; + private String DB_SORT_BY_FIELD = "dbSortByField"; + + @Before + public void init() { + idNameColLookup = new IdNameColLookup(COL_ID, DB_TABLE_NAME, DB_ID_FIELD, DB_NAME_FIELD, DB_SORT_BY_FIELD); + } + + @Test + public void testNotNull() { + assertNotNull(idNameColLookup); + } + + @Test + public void testIdNameColLookupProperties() { + assertEquals(COL_ID, idNameColLookup.getColId()); + assertEquals(DB_TABLE_NAME, idNameColLookup.getDbTableName()); + assertEquals(DB_ID_FIELD, idNameColLookup.getDbIdField()); + assertEquals(DB_NAME_FIELD, idNameColLookup.getDbNameField()); + assertEquals(DB_SORT_BY_FIELD, idNameColLookup.getDbSortByField()); + } +} + diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameListTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameListTest.java new file mode 100644 index 00000000..cff2eb83 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameListTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.base; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.portalsdk.analytics.system.Globals; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class}) +public class IdNameListTest { + + IdNameList idNameList; + + private String ID = "testID"; + private String NAME = "test"; + private boolean DEFAULT_VALUE = true; + private boolean READ_ONLY = true; + + @Before + public void init() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(Globals.getFormFieldsListSize()).thenReturn(100); + idNameList = new IdNameList(); + idNameList.addValue(ID, NAME, DEFAULT_VALUE, READ_ONLY); + } + + @Test + public void testGetIdByName() { + assertEquals(ID, idNameList.getIdByName(NAME)); + } + + @Test + public void testGetNameById() { + assertEquals(NAME, idNameList.getNameById(ID)); + } + + + + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameLookupTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameLookupTest.java new file mode 100644 index 00000000..725d179d --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameLookupTest.java @@ -0,0 +1,76 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class IdNameLookupTest { + + IdNameLookup idNameLookup; + + private String DB_TABLE_NAME = "dbTableName"; + private String DB_ID_FIELD = "dbIdField"; + private String DB_NAME_FIELD = "dbNameField"; + private String DB_SORT_BY_FIELD = "dbSortByField"; + private String DEFAULT_SQL = "defaultSQL"; + private boolean TEXT_FIELD = true; + + @Before + public void init() { + idNameLookup = new IdNameLookup(DB_TABLE_NAME, DB_ID_FIELD, DB_NAME_FIELD, DB_SORT_BY_FIELD, DEFAULT_SQL, TEXT_FIELD); + } + + @Test + public void testNotNull() { + assertNotNull(idNameLookup); + } + + @Test + public void testIdNameLookupProperties() { + assertEquals(DB_TABLE_NAME, idNameLookup.getDbTableName()); + assertEquals(DB_ID_FIELD, idNameLookup.getDbIdField()); + assertEquals(DB_NAME_FIELD, idNameLookup.getDbNameField()); + assertEquals(DB_SORT_BY_FIELD, idNameLookup.getDbSortByField()); + assertEquals(DEFAULT_SQL, idNameLookup.getDefaultSQL()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameSqlTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameSqlTest.java new file mode 100644 index 00000000..78e8dffa --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameSqlTest.java @@ -0,0 +1,80 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.analytics.model.base; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.system.ConnectionUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.util.RemDbInfo; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, IdNameSql.class, ConnectionUtils.class}) +public class IdNameSqlTest { + + IdNameSql idNameSql; + + @Before + public void init() { + idNameSql = new IdNameSql("select * from test", "select * from test"); + } + + @Test + public void testLoadData() throws Exception { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(Globals.getDBType()).thenReturn("test"); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.anyString())).thenReturn("test"); + Mockito.when(Globals.getReportSqlForFormfield()).thenReturn("test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(), Mockito.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + idNameSql.loadData("select", 10, "testDB"); + } +} + diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameValueTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameValueTest.java new file mode 100644 index 00000000..0c798684 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/IdNameValueTest.java @@ -0,0 +1,69 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class IdNameValueTest { + + IdNameValue idNameValue; + + private String ID = "id"; + private String NMAE = "name"; + + @Before + public void init() { + idNameValue = new IdNameValue(ID, NMAE); + } + + @Test + public void testNotNull() { + assertNotNull(idNameValue); + } + + @Test + public void testIdNameValueProperties() { + assertEquals(ID, idNameValue.getId()); + assertEquals(NMAE, idNameValue.getName()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/NameComparatorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/NameComparatorTest.java new file mode 100644 index 00000000..8d9c3385 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/NameComparatorTest.java @@ -0,0 +1,64 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.base; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class NameComparatorTest { + + NameComparator nameComparator; + private String NAME = "name"; + + @Before + public void init() { + nameComparator = new NameComparator(); + } + + @Test + public void testCompare() { + IdNameValue idNameValue1 = new IdNameValue(); + idNameValue1.setName(NAME); + IdNameValue idNameValue2 = new IdNameValue(); + idNameValue2.setName(NAME); + + assertEquals(0, nameComparator.compare(idNameValue1, idNameValue2)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderBySeqComparatorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderBySeqComparatorTest.java new file mode 100644 index 00000000..cd403e7c --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderBySeqComparatorTest.java @@ -0,0 +1,65 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.base; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; + +public class OrderBySeqComparatorTest { + + OrderBySeqComparator orderBySeqComparator; + private Integer CHAR_SEQ = 100; + + @Before + public void init() { + orderBySeqComparator = new OrderBySeqComparator(); + } + + @Test + public void testCompare() { + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setOrderBySeq(CHAR_SEQ); + DataColumnType dataColumnType2 = new DataColumnType(); + dataColumnType2.setOrderBySeq(CHAR_SEQ); + + assertEquals(0, orderBySeqComparator.compare(dataColumnType1, dataColumnType2)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderSeqComparatorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderSeqComparatorTest.java new file mode 100644 index 00000000..dd6c7050 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/OrderSeqComparatorTest.java @@ -0,0 +1,64 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.base; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; + +public class OrderSeqComparatorTest { + OrderSeqComparator orderSeqComparator; + private Integer CHAR_SEQ = 100; + + @Before + public void init() { + orderSeqComparator = new OrderSeqComparator(); + } + + @Test + public void testCompare() { + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setOrderSeq(CHAR_SEQ); + DataColumnType dataColumnType2 = new DataColumnType(); + dataColumnType2.setOrderSeq(CHAR_SEQ); + + assertEquals(0, orderSeqComparator.compare(dataColumnType1, dataColumnType2)); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportSecurityTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportSecurityTest.java new file mode 100644 index 00000000..c8a2a97e --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportSecurityTest.java @@ -0,0 +1,105 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.base; + +import java.util.Vector; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.DbUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({AppUtils.class, Globals.class, DbUtils.class}) +public class ReportSecurityTest { + + ReportSecurity reportSecurity; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Before + public void setUp() throws RaptorException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getReportSecurity()).thenReturn("select * from test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(DbUtils.executeQuery(Mockito.anyString())).thenReturn(ds); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(Globals.getReportUserAccess()).thenReturn("select * test"); + reportSecurity = new ReportSecurity("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("USERID"); + Vector userRoles = new Vector(); + userRoles.add("test"); + Mockito.when(AppUtils.getUserRoles(Mockito.anyString())).thenReturn(userRoles); + Mockito.when(AppUtils.getUserName(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.getAdminRoleIDs()).thenReturn(userRoles); + Mockito.when(AppUtils.getUserRoles(mockedRequest)).thenReturn(userRoles); + Mockito.when(Globals.getDeleteOnlyByOwner()).thenReturn(false); + } + + @Test + public void testCheckUserReadAccess() throws RaptorException { + reportSecurity.checkUserReadAccess(mockedRequest, null); + } + + @Test + public void testCheckUserWriteAccess() throws RaptorException { + reportSecurity.checkUserWriteAccess(mockedRequest); + } + + @Test + public void testCheckUserDeleteAccess() throws RaptorException { + reportSecurity.checkUserWriteAccess(mockedRequest); + } + + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportUserRoleTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportUserRoleTest.java new file mode 100644 index 00000000..19d1eddc --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/base/ReportUserRoleTest.java @@ -0,0 +1,74 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.analytics.model.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class ReportUserRoleTest { + + ReportUserRole reportUserRole; + private Long REP_ID = 1L; + private Long ORDER_NO = 2L; + private Long ROLE_ID = 3L; + private Long USER_ID = 4L; + private String READ_ONLY_YN = "Y"; + + @Before + public void init() { + reportUserRole = new ReportUserRole(REP_ID, ORDER_NO, ROLE_ID, USER_ID, READ_ONLY_YN); + } + + @Test + public void testNotNull() { + assertNotNull(reportUserRole); + } + + @Test + public void testReportUserRoleProperties() { + assertEquals(REP_ID, reportUserRole.getRepId()); + assertEquals(ORDER_NO, reportUserRole.getOrderNo()); + assertEquals(ROLE_ID, reportUserRole.getRoleId()); + assertEquals(USER_ID, reportUserRole.getUserId()); + assertEquals(READ_ONLY_YN, reportUserRole.getReadOnlyYn()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DBColumnInfoTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DBColumnInfoTest.java new file mode 100644 index 00000000..c4e9d7f4 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DBColumnInfoTest.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class DBColumnInfoTest { + + DBColumnInfo dbColumnInfo; + + private String TABLE_NAME = "tableName"; + private String COL_NAME = "colName"; + private String COL_TYPE = "colType"; + private String LABEL = "label"; + + @Before + public void init() { + dbColumnInfo = new DBColumnInfo(TABLE_NAME, COL_NAME, COL_TYPE, LABEL); + } + + @Test + public void testNotNull() { + assertNotNull(dbColumnInfo); + } + + @Test + public void testDBColumnInfoProperties() { + assertEquals(TABLE_NAME, dbColumnInfo.getTableName()); + assertEquals(COL_NAME, dbColumnInfo.getColName()); + assertEquals(COL_TYPE, dbColumnInfo.getColType()); + assertEquals(LABEL, dbColumnInfo.getLabel()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DrillDownParamDefTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DrillDownParamDefTest.java new file mode 100644 index 00000000..df1d5693 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/DrillDownParamDefTest.java @@ -0,0 +1,62 @@ +/* + * ============LICENxSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.definition; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class DrillDownParamDefTest { + + DrillDownParamDef drillDownParamDef; + String DRILL_DOWN_PARAM_DEF_STR = "fieldName=[valColId!valFieldId]"; + + @Before + public void init() { + drillDownParamDef = new DrillDownParamDef(DRILL_DOWN_PARAM_DEF_STR); + } + + @Test + public void testDrillDownParamDefProperties() { + assertEquals("fieldName", drillDownParamDef.getFieldName()); + assertEquals("valColId", drillDownParamDef.getValColId()); + assertEquals("valFieldId", drillDownParamDef.getValFieldId()); + assertEquals("4", drillDownParamDef.getValType()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/MarkerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/MarkerTest.java new file mode 100644 index 00000000..3aa5d24e --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/MarkerTest.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class MarkerTest { + + Marker marker; + + private String MARKER_COLOR = "markerColor"; + private String ADDRESS_COLUMN = "addressColumn"; + private String DATA_COLUMN = "dataColumn"; + private String ADDRESS = "address"; + private String DATA = "data"; + private String COLOR = "color"; + + @Before + public void init() { + marker = new Marker(MARKER_COLOR, ADDRESS_COLUMN, DATA_COLUMN); + marker.setAddress(ADDRESS); + marker.setData(DATA); + marker.setColor(COLOR); + } + + @Test + public void testNotNull() { + assertNotNull(marker); + } + + @Test + public void testMarkerProperties() { + assertEquals(MARKER_COLOR, marker.getMarkerColor()); + assertEquals(ADDRESS_COLUMN, marker.getAddressColumn()); + assertEquals(DATA_COLUMN, marker.getDataColumn()); + assertEquals(DATA, marker.getData()); + assertEquals(COLOR, marker.getColor()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportLogEntryTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportLogEntryTest.java new file mode 100644 index 00000000..d92f2565 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportLogEntryTest.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class ReportLogEntryTest { + + ReportLogEntry reportlogEntry; + + private String LOGTIME = "logTime"; + private String USERNAME = "userName"; + private String ACTION = "action"; + private String TIME_TAKEN = "timeTaken"; + private String RUN_ICON = "runIcon"; + + @Before + public void init() { + reportlogEntry = new ReportLogEntry(LOGTIME, USERNAME, ACTION, TIME_TAKEN, RUN_ICON); + } + + @Test + public void testNotNull() { + assertNotNull(reportlogEntry); + } + + @Test + public void testReportLogEntryProperties() { + assertEquals(LOGTIME, reportlogEntry.getLogTime()); + assertEquals(USERNAME, reportlogEntry.getUserName()); + assertEquals(ACTION, reportlogEntry.getAction()); + assertEquals(TIME_TAKEN, reportlogEntry.getTimeTaken()); + assertEquals(RUN_ICON, reportlogEntry.getRunIcon()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportMapTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportMapTest.java new file mode 100644 index 00000000..fcbae7bc --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportMapTest.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class ReportMapTest { + + ReportMap reportMap; + + private String MARKER_COLOR = "markerColor"; + private String ADDRESS_COLUMN = "addressColumn"; + private String DATA_COLUMN = "dataColumn"; + private String IS_MAP_ALLOWED_YN = "isMapAllowedYN"; + private String ADD_ADDRESS_IN_DATA_YN = "addAddressInDataYN"; + + @Before + public void init() { + reportMap = new ReportMap(MARKER_COLOR, ADDRESS_COLUMN, DATA_COLUMN, IS_MAP_ALLOWED_YN, ADD_ADDRESS_IN_DATA_YN); + } + + @Test + public void testNotNull() { + assertNotNull(reportMap); + } + + @Test + public void testReportMapProperties() { + assertEquals(MARKER_COLOR, reportMap.getMarkerColor()); + assertEquals(ADDRESS_COLUMN, reportMap.getAddressColumn()); + assertEquals(DATA_COLUMN, reportMap.getDataColumn()); + assertEquals(IS_MAP_ALLOWED_YN, reportMap.getIsMapAllowedYN()); + assertEquals(ADD_ADDRESS_IN_DATA_YN, reportMap.getAddAddressInDataYN()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java index 40ab05de..3ba80d9f 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/ReportScheduleTest.java @@ -37,36 +37,56 @@ */ package org.onap.portalsdk.analytics.model.definition; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.FileInputStream; import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.portalsdk.analytics.error.RaptorException; import org.onap.portalsdk.analytics.error.ReportSQLException; +import org.onap.portalsdk.analytics.model.base.IdNameValue; +import org.onap.portalsdk.analytics.model.runtime.FormField; +import org.onap.portalsdk.analytics.model.runtime.ReportParamValues; import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.ConnectionUtils; import org.onap.portalsdk.analytics.system.DbUtils; import org.onap.portalsdk.analytics.system.Globals; import org.onap.portalsdk.analytics.util.AppConstants; import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.util.RemDbInfo; +import org.onap.portalsdk.analytics.xmlobj.DataColumnType; +import org.onap.portalsdk.analytics.xmlobj.DataSourceType; +import org.onap.portalsdk.analytics.xmlobj.FormFieldList; +import org.onap.portalsdk.analytics.xmlobj.FormFieldType; import org.owasp.esapi.ESAPI; import org.owasp.esapi.Encoder; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import com.mchange.v2.debug.ThreadNameStackTraceRecorder; + @RunWith(PowerMockRunner.class) -@PrepareForTest({ AppUtils.class, Globals.class, DbUtils.class, AppUtils.class, ESAPI.class}) +@PrepareForTest({ AppUtils.class, Globals.class, DbUtils.class, AppUtils.class, ESAPI.class, ConnectionUtils.class, ReportSchedule.class}) public class ReportScheduleTest { @@ -116,7 +136,8 @@ public class ReportScheduleTest { PowerMockito.mockStatic(DbUtils.class); PowerMockito.mockStatic(AppUtils.class); PowerMockito.mockStatic(ESAPI.class); - + PowerMockito.mockStatic(ConnectionUtils.class); + MockitoAnnotations.initMocks(this); Mockito.when(httpSession.getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(reportRuntime); @@ -166,7 +187,13 @@ public class ReportScheduleTest { Mockito.when(dataSet1.getString(Mockito.anyInt(), Mockito.anyString())).thenReturn("Some Value2"); reportSchedule = new ReportSchedule(REPORT_ID, USER_ID, true, httpServletRequest); - + reportSchedule.setEncryptMode("test"); + reportSchedule.setEndAMPM("AM"); + reportSchedule.setEndHour("10"); + reportSchedule.setEndMin("00"); + reportSchedule.addZero("0"); + + /* Mockito.when(dataSet1.getString(Mockito.anyInt(), Mockito.anyObject())).thenAnswer(new Answer() { @@ -345,6 +372,353 @@ public class ReportScheduleTest { reportSchedule.persistScheduleData(connection, httpServletRequest); } + @Test + public void testPersistScheduleData_FormFieldList_case1() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + formFieldList.getFormField().add(formFieldType); + Mockito.when(reportRuntime.getFormFieldList()).thenReturn(formFieldList); + Mockito.when(reportRuntime.getFormFieldDisplayName(Mockito.any(FormFieldType.class))).thenReturn("test"); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + Mockito.when(reportRuntime.getReportParamValues()).thenReturn(paramValues); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(reportRuntime.formatListValue(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(DataColumnType.class), + Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(DataSourceType.class), Mockito.any(String.class))).thenReturn(""); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true); + + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setConditionSQL("SELECT WHEN FROM TABLE WHERE AND [test] ORDER BY"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + + @Test + public void testPersistScheduleData_FormFieldList_case2() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + formFieldList.getFormField().add(formFieldType); + Mockito.when(reportRuntime.getFormFieldList()).thenReturn(formFieldList); + Mockito.when(reportRuntime.getFormFieldDisplayName(Mockito.any(FormFieldType.class))).thenReturn("test"); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + Mockito.when(reportRuntime.getReportParamValues()).thenReturn(paramValues); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.any(String.class))).thenReturn("DAYTONA"); + Mockito.when(reportRuntime.formatListValue(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(DataColumnType.class), + Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(DataSourceType.class), Mockito.any(String.class))).thenReturn("test"); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true); + + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setConditionSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + + @Test + public void testPersistScheduleData_FormFieldList_case3() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + formFieldType.setValidationType(FormField.VT_TIMESTAMP_MIN); + formFieldList.getFormField().add(formFieldType); + Mockito.when(reportRuntime.getFormFieldList()).thenReturn(formFieldList); + Mockito.when(reportRuntime.getFormFieldDisplayName(Mockito.any(FormFieldType.class))).thenReturn("report_id"); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + Mockito.when(reportRuntime.getReportParamValues()).thenReturn(paramValues); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.any(String.class))).thenReturn("DAYTONA"); + Mockito.when(reportRuntime.formatListValue(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(DataColumnType.class), + Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(DataSourceType.class), Mockito.any(String.class))).thenReturn("test"); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true); + + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setConditionSQL("SELECT WHEN FROM TABLE WHERE [report_id] ORDER BY"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + + @Test + public void testPersistScheduleData_FormFieldList_case4() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + formFieldType.setValidationType(FormField.VT_TIMESTAMP_MIN); + formFieldList.getFormField().add(formFieldType); + Mockito.when(reportRuntime.getFormFieldList()).thenReturn(formFieldList); + Mockito.when(reportRuntime.getFormFieldDisplayName(Mockito.any(FormFieldType.class))).thenReturn("report_id"); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + Mockito.when(reportRuntime.getReportParamValues()).thenReturn(paramValues); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.any(String.class))).thenReturn("DAYTONA"); + Mockito.when(reportRuntime.formatListValue(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(DataColumnType.class), + Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(DataSourceType.class), Mockito.any(String.class))).thenReturn("test"); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true); + + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setConditionSQL("SELECT WHEN FROM TABLE WHERE [report_id] ORDER BY"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + + @Test + public void testPersistScheduleData_FormFieldList_case5() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + FormFieldType formFieldType = new FormFieldType(); + formFieldType.setFieldId("test"); + formFieldType.setColId("1"); + formFieldType.setFieldName("test"); + formFieldType.setFieldType("type"); + formFieldType.setValidationType("validation"); + formFieldType.setMandatory("Y"); + formFieldType.setDefaultValue("test"); + formFieldType.setGroupFormField(true); + formFieldType.setValidationType(FormField.VT_TIMESTAMP_SEC); + formFieldList.getFormField().add(formFieldType); + Mockito.when(reportRuntime.getFormFieldList()).thenReturn(formFieldList); + Mockito.when(reportRuntime.getFormFieldDisplayName(Mockito.any(FormFieldType.class))).thenReturn("report_id"); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + Mockito.when(reportRuntime.getReportParamValues()).thenReturn(paramValues); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.any(String.class))).thenReturn("TESTDB"); + Mockito.when(reportRuntime.formatListValue(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(DataColumnType.class), + Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.any(DataSourceType.class), Mockito.any(String.class))).thenReturn("test"); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(resultSet.next()).thenReturn(true); + + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setConditionSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + + + @Test + public void testPersistScheduleData_WithRaptorException() throws Exception { + String execute_update = "DELETE FROM cr_report_schedule_users WHERE rep_id = [reportID] and schedule_id = [getScheduleID()]"; + String execute_update_users = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], [emailToUsers.get(i)).getId()], NULL, [(i + 1)])"; + String execute_update_roles = "INSERT INTO cr_report_schedule_users (schedule_id, rep_id, user_id, role_id, order_no) VALUES([getScheduleID()], [reportID], NULL, [emailToRoles.get(i)).getId()], [((emailToUsers.size() + i + 1)])"; + String execute_update_activity = "INSERT into cr_schedule_activity_log (schedule_id, notes, run_time) values ([getScheduleID()],'Submitted:Schedule',TO_DATE('[getRunDate()] [getRunHour()]:[getRunMin()] [getRunAMPM()]', 'MM/DD/YYYY HH:MI AM'))"; + String persist_cond_sql_update = "update cr_report_schedule set condition_large_sql = '' where schedule_id = [scheduleId]"; + String new_schedule_data = "select coalesce(max(schedule_id),0)+1 AS sequence from cr_report_schedule"; + String persist_cond_sql_set = "update cr_report_schedule set condition_sql = ? where schedule_id = [scheduleId]"; + + PowerMockito.when(DbUtils.executeQuery(Mockito.anyObject(), Mockito.anyString())).thenReturn(dataSet1); + PowerMockito.when(Globals.getExecuteUpdate()).thenReturn(execute_update); + PowerMockito.when(Globals.getExecuteUpdateUsers()).thenReturn(execute_update_users); + PowerMockito.when(Globals.getExecuteUpdateRoles()).thenReturn(execute_update_roles); + PowerMockito.when(Globals.getExecuteUpdateActivity()).thenReturn(execute_update_activity); + PowerMockito.when(Globals.getPersistCondSqlUpdate()).thenReturn(persist_cond_sql_update); + PowerMockito.when(Globals.isPostgreSQL()).thenReturn(true); + PowerMockito.when(Globals.getPersistCondSqlSet()).thenReturn(persist_cond_sql_update); + + PowerMockito.when(Globals.getRequestParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParams()).thenReturn("1, 2, 3"); + PowerMockito.when(Globals.getSessionParamsForScheduling()).thenReturn("login_id"); + PowerMockito.when(Globals.getNewScheduleData()).thenReturn(new_schedule_data); + Mockito.when(reportRuntime.getDBInfo()).thenReturn(AppConstants.DB_DEV); + + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeUpdate()).thenReturn(1); + Mockito.when(resultSet.next()).thenReturn(false); + Mockito.when(dataSet1.getRowCount()).thenReturn(0); + + + reportSchedule.setSchedEnabled("N"); + reportSchedule.setStartDate("10/10/2018"); + reportSchedule.setEndDate("10/10/2019"); + reportSchedule.setRunDate("10/10/2019"); + reportSchedule.setRecurrence("Y"); + reportSchedule.addEmailToUser("UserID1", "UserName1"); + reportSchedule.addEmailToRole("roleId1", "roleName1"); + reportSchedule.setConditionSQL("SELECT coalesce(cr.owner_id, cr.create_id) owner_id, cr.create_id, DATE_FORMAT(cr.create_date, '[Globals.getTimeFormat()]') create_date, maint_id, DATE_FORMAT(cr.maint_date, '[Globals.getTimeFormat()]') update_date, cr.menu_id, cr.menu_approved_yn FROM cr_report cr WHERE cr.rep_id= [reportID]"); + + reportSchedule.persistScheduleData(connection, httpServletRequest); + } + @Test public void testDeleteScheduleData_case1() throws RaptorException { @@ -416,10 +790,9 @@ public class ReportScheduleTest { ReportSchedule.loadConditionalSQL("scheduleId#123"); } - /* - @Test - public void testLoadConditionalSQL_Error_case2() throws Exception { + @Test(expected=RaptorException.class) + public void testLoadConditionalSQL_Error_case2() throws Exception { String load_cond_sql = "SELECT condition_large_sql FROM cr_report_schedule WHERE schedule_id=?"; Mockito.when(DbUtils.getConnection()).thenReturn(connection); Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); @@ -433,50 +806,73 @@ public class ReportScheduleTest { PowerMockito.when(Globals.getLoadCondSql()).thenReturn(load_cond_sql); ReportSchedule.loadConditionalSQL("scheduleId#123"); - }*/ - + } - /* + @Test + public void testLoadConditionalSQL_Error_case3() throws Exception { + String load_cond_sql = "SELECT condition_large_sql FROM cr_report_schedule WHERE schedule_id=?"; + Mockito.when(DbUtils.getConnection()).thenReturn(connection); + Mockito.when(connection.prepareStatement(Mockito.anyString())).thenReturn(preparedStatement); + Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); + Mockito.when(Globals.isWeblogicServer()).thenReturn(false); + Mockito.when(Globals.isPostgreSQL()).thenReturn(false); + Mockito.when(Globals.isMySQL()).thenReturn(true); + + Mockito.when(resultSet.next()).thenReturn(true); + Mockito.when(resultSet.getString(1)).thenThrow(new SQLException()); + PowerMockito.when(Globals.getLoadCondSql()).thenReturn(load_cond_sql); + + ReportSchedule.loadConditionalSQL("scheduleId#123"); + } + @Test public void testAddEmailArrayToUser() { - fail("Not yet implemented"); + ArrayList allSelectedUsers= new ArrayList<>(); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + idNameValue.setName("test"); + idNameValue.setReadOnly(true); + idNameValue.setDefaultValue(true); + allSelectedUsers.add(idNameValue); + reportSchedule.addEmailArrayToUser(allSelectedUsers); + assertEquals("1",((IdNameValue)reportSchedule.getEmailToUsers().get(0)).getId()); } @Test public void testRemoveEmailToUser() { - fail("Not yet implemented"); + reportSchedule.removeEmailToUser("1"); } - @Test - public void testAddEmailToRole() { - fail("Not yet implemented"); - } @Test public void testAddEmailArrayToRole() { - fail("Not yet implemented"); + ArrayList allSelectedUsers= new ArrayList<>(); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("roleID1"); + idNameValue.setName("roleName1"); + idNameValue.setReadOnly(true); + idNameValue.setDefaultValue(true); + allSelectedUsers.add(idNameValue); + reportSchedule.addEmailArrayToRole(allSelectedUsers); + assertEquals("roleID1",((IdNameValue)reportSchedule.getEmailToRoles().get(0)).getId()); } - + @Test public void testRemoveEmailToRole() { - fail("Not yet implemented"); + reportSchedule.removeEmailToRole("roleID1"); } @Test - public void testPersistScheduleData() { - fail("Not yet implemented"); + public void testIsAttachmentMode() { + reportSchedule.setAttachmentMode("Y"); + assertTrue(reportSchedule.isAttachmentMode()); } @Test - public void testDeleteScheduleData() { - fail("Not yet implemented"); + public void testSetConditional() { + reportSchedule.setConditional("Y"); + assertEquals("Y",reportSchedule.getConditional()); } - - @Test - public void testLoadConditionalSQL() { - fail("Not yet implemented"); - } - */ - + } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/SecurityEntryTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/SecurityEntryTest.java new file mode 100644 index 00000000..156a2adf --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/SecurityEntryTest.java @@ -0,0 +1,71 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class SecurityEntryTest { + + SecurityEntry securityEntry; + + private String ID = "testID"; + private String NAME = "testName"; + private boolean READ_ONLY = true; + + @Before + public void init() { + securityEntry = new SecurityEntry(ID, NAME, READ_ONLY); + } + + @Test + public void testNotNull() { + assertNotNull(securityEntry); + } + + @Test + public void testTableJoinProperties() { + assertEquals(ID, securityEntry.getId()); + assertEquals(NAME, securityEntry.getName()); + assertEquals(READ_ONLY, securityEntry.isReadOnly()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableJoinTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableJoinTest.java new file mode 100644 index 00000000..d7912415 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableJoinTest.java @@ -0,0 +1,71 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class TableJoinTest { + + TableJoin tableJoin; + + private String SRC_TABLE_NAME = "srcTableName"; + private String DEST_TABLE_NAME = "destTableName"; + private String JOIN_EXPR = "joinExpr"; + + @Before + public void init() { + tableJoin = new TableJoin(SRC_TABLE_NAME, DEST_TABLE_NAME, JOIN_EXPR); + } + + @Test + public void testNotNull() { + assertNotNull(tableJoin); + } + + @Test + public void testTableJoinProperties() { + assertEquals(SRC_TABLE_NAME, tableJoin.getSrcTableName()); + assertEquals(DEST_TABLE_NAME, tableJoin.getDestTableName()); + assertEquals(JOIN_EXPR, tableJoin.getJoinExpr()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableSourceTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableSourceTest.java new file mode 100644 index 00000000..c6554c12 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/TableSourceTest.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.definition; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; + +public class TableSourceTest { + + TableSource tableSource; + + private String TABLE_NAME = "tableName"; + private String DISPLAY_NAME = "displayName"; + private String PK_FIELDS = "pkFields"; + private String VIEW_ACTION = "viewAction"; + private String IS_LARGE_DATA = "isLargeData"; + private String FILTER_SQL = "filterSql"; + + @Before + public void init() { + tableSource = new TableSource(TABLE_NAME, DISPLAY_NAME, PK_FIELDS, VIEW_ACTION, IS_LARGE_DATA, FILTER_SQL); + } + + @Test + public void testNotNull() { + assertNotNull(tableSource); + } + + @Test + public void testTableSourceProperties() { + assertEquals(TABLE_NAME, tableSource.getTableName()); + assertEquals(DISPLAY_NAME, tableSource.getDisplayName()); + assertEquals(PK_FIELDS, tableSource.getPkFields()); + assertEquals(VIEW_ACTION, tableSource.getViewAction()); + assertEquals(IS_LARGE_DATA, tableSource.getIsLargeData()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/IdNameBooleanJSONTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/IdNameBooleanJSONTest.java index 3bdb5bc1..e1f99ec0 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/IdNameBooleanJSONTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/IdNameBooleanJSONTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/MessageJSONTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/MessageJSONTest.java new file mode 100644 index 00000000..da99f464 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/MessageJSONTest.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.definition.wizard; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class MessageJSONTest { + + MessageJSON messageJSON; + private String MESSAGE = "testMessage"; + private String ANY_STACKTRACE = "testStacktrace"; + + @Before + public void init() { + messageJSON = new MessageJSON(); + messageJSON.setMessage(MESSAGE); + messageJSON.setAnyStacktrace(ANY_STACKTRACE); + } + + @Test + public void testNotNull() { + assertEquals(MESSAGE, messageJSON.getMessage()); + assertEquals(ANY_STACKTRACE, messageJSON.getAnyStacktrace()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/RaptorErrorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/RaptorErrorTest.java new file mode 100644 index 00000000..271e2d5a --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/definition/wizard/RaptorErrorTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.definition.wizard; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class RaptorErrorTest { + + RaptorError raptorError1; + RaptorError raptorError2; + private String MESSAGE = "theMessage"; + private Throwable THROWABLE = new Throwable(MESSAGE); + + @Before + public void init() { + raptorError1 = new RaptorError(MESSAGE); + raptorError2 = new RaptorError(MESSAGE, THROWABLE); + } + + @Test + public void testRaptorErrorMessage() { + assertEquals(MESSAGE, raptorError1.error().get("message")); + } + + @Test + public void testRaptorErrorThrowable() { + assertEquals(THROWABLE.toString(), raptorError2.error().get("exception")); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PageEventTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PageEventTest.java new file mode 100644 index 00000000..4b94657d --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PageEventTest.java @@ -0,0 +1,184 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.pdf; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.lowagie.text.Document; +import com.lowagie.text.Font; +import com.lowagie.text.Rectangle; +import com.lowagie.text.pdf.PdfContentByte; +import com.lowagie.text.pdf.PdfWriter; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Globals.class, AppUtils.class, PdfReportHandler.class }) +public class PageEventTest { + + PdfBean pb = Mockito.mock(PdfBean.class); + PageEvent pageEvent = new PageEvent(pb); + @Mock + Document document; + @Mock + PdfWriter writer; + @Mock + Font font; + @Mock + PdfContentByte pdfContentByte; + + Rectangle rectangle = new Rectangle(1, 1, 1, 1); + + @Test + public void onStartPageTest() { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getFooterFontFamily()).thenReturn("test"); + Mockito.when(Globals.getFooterFontSize()).thenReturn((float) 1.1); + Mockito.when(pb.getLogo1Url()).thenReturn(""); + Mockito.when(pb.getLogo2Url()).thenReturn(""); + pageEvent.onStartPage(writer, document); + } + + @Test(expected = java.lang.RuntimeException.class) + public void onStartPage1Test() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getFooterFontFamily()).thenReturn("test"); + Mockito.when(Globals.getFooterFontSize()).thenReturn((float) 1.1); + Mockito.when(pb.getLogo1Url()).thenReturn("test"); + Mockito.when(pb.getLogo2Url()).thenReturn("test"); + Mockito.when(AppUtils.getImgFolderURL()).thenReturn("test"); + Mockito.when(pb.getFullWebContextPath()).thenReturn("testpath"); + Mockito.when(AppUtils.isNotEmpty(Matchers.anyString())).thenReturn(true); + Mockito.when(document.getPageSize()).thenReturn(rectangle); + Mockito.when(document.leftMargin()).thenReturn((float) 1.0); + Mockito.when(document.rightMargin()).thenReturn((float) 0.1); + Mockito.when(writer.getDirectContent()).thenReturn(pdfContentByte); + pageEvent.onStartPage(writer, document); + } + + @Test(expected = java.lang.RuntimeException.class) + public void onStartPage2Test() { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getFooterFontFamily()).thenReturn("test"); + Mockito.when(Globals.getFooterFontSize()).thenReturn((float) 1.1); + + Mockito.when(pb.getLogo1Url()).thenReturn(""); + Mockito.when(pb.getLogo2Url()).thenReturn("test"); + Mockito.when(AppUtils.getImgFolderURL()).thenReturn("test"); + Mockito.when(pb.getFullWebContextPath()).thenReturn("testpath"); + Mockito.when(AppUtils.isNotEmpty(Matchers.anyString())).thenReturn(true); + Mockito.when(document.getPageSize()).thenReturn(rectangle); + Mockito.when(document.leftMargin()).thenReturn((float) 1.0); + Mockito.when(document.rightMargin()).thenReturn((float) 0.1); + Mockito.when(writer.getDirectContent()).thenReturn(pdfContentByte); + pageEvent.onStartPage(writer, document); + } + + @Test(expected = java.lang.Exception.class) + public void onEndPageTest() { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getFooterFontFamily()).thenReturn("test"); + Mockito.when(Globals.getFooterFontSize()).thenReturn((float) 1.1); + Mockito.when(pb.getLogo1Url()).thenReturn(""); + Mockito.when(pb.getLogo2Url()).thenReturn(""); + pageEvent.onEndPage(writer, document); + } + + @Test(expected = java.lang.Exception.class) + public void onEndPage1Test() { + Rectangle rectangle1 = Mockito.mock(Rectangle.class); + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getFooterFontFamily()).thenReturn("test"); + Mockito.when(Globals.getFooterFontSize()).thenReturn((float) 1.1); + Mockito.when(pb.getLogo1Url()).thenReturn(""); + Mockito.when(pb.getLogo2Url()).thenReturn(""); + Mockito.when(pb.getTimestampPattern()).thenReturn("11/11/2011 11:11:11"); + PowerMockito.mockStatic(PdfReportHandler.class); + Mockito.when(PdfReportHandler.currentTime(Matchers.anyString())).thenReturn("test"); + Mockito.when(document.getPageSize()).thenReturn(rectangle1); + Mockito.when(rectangle1.width()).thenReturn((float) 20); + Mockito.when(document.leftMargin()).thenReturn((float) 11.0); + Mockito.when(document.rightMargin()).thenReturn((float) 0.1); + Mockito.when(writer.getDirectContent()).thenReturn(pdfContentByte); + pageEvent.onEndPage(writer, document); + } + + @SuppressWarnings("static-access") + @Test + public void getPageHeightTest() { + Rectangle rectangle1 = Mockito.mock(Rectangle.class); + Mockito.when(document.getPageSize()).thenReturn(rectangle1); + Mockito.when(rectangle1.width()).thenReturn((float) 20); + Mockito.when(document.leftMargin()).thenReturn((float) 11.0); + Mockito.when(document.rightMargin()).thenReturn((float) 0.1); + pageEvent.getPageHeight(document); + } + + @Test + public void pdfbeanTest() { + PdfBean pb = new PdfBean(); + pb.setLeftFooter("leftFooter"); + assertEquals(pb.getLeftFooter(), "leftFooter"); + pb.setTitle("title"); + assertEquals(pb.getTitle(), "title"); + pb.setCurrentPage(1); + assertEquals(pb.getCurrentPage(), 1); + assertEquals(pb.getTimestampPattern(), null); + assertEquals(pb.getWhereToShowPageNumber(), 0); + assertTrue(pb.isPageNumberAtHeader()); + assertFalse(pb.isPageNumberAtFooter()); + assertEquals(pb.getLogo1Url(), null); + assertEquals(pb.getLogo2Url(), null); + assertEquals(pb.getLogo1Size(), null); + assertEquals(pb.getLogo2Size(), null); + assertEquals(pb.getFullWebContextPath(), null); + assertEquals(pb.toString(), "title 1 null null 0 false false"); + pb.setAttachmentOfEmail(false); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PdfBeanTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PdfBeanTest.java new file mode 100644 index 00000000..a1db0d82 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/pdf/PdfBeanTest.java @@ -0,0 +1,113 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.pdf; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class PdfBeanTest { + PdfBean pdfBean; + + public static final int NUMBER_IN_HEADER = 0; + public static final int NUMBER_IN_FOOTER = 1; + public static final int NUMBER_IN_BOTH = 2; + + private boolean ALTERNATE_COLOR = true; + private boolean IS_PORTRAIT = true; + private boolean IS_COVER_PAGE_INCLUDED = true; + private boolean IS_DISPLAY_CHART = true; + private int CURRENT_PAGE = 1; + private int WHERE_TO_SHOW_PAGE_NUMBER = 2; + private String USER_ID = "userID"; + private String TIMESTAMP_PATTERN = "timestampPattern"; + private String TITLE = "title"; + private String LEFT_FOOTER = "leftFooter"; + private String PAGE_SIZE = "pageSize"; + private boolean IS_ATTACHMENT_OF_EMAIL = true; + private String LOGO1_URL = "logo1Url"; + private Integer LOGO1_SIZE = 100; + private String LOGO2_URL= "logo2Url"; + private Integer LOGO2_SIZE = 200; + private String FULL_WEB_CONTEXT_PATH = "fullWebContextPath"; + + + @Before + public void init() { + pdfBean = new PdfBean(); + pdfBean.setAlternateColor(ALTERNATE_COLOR); + pdfBean.setPortrait(IS_PORTRAIT); + pdfBean.setCoverPageIncluded(IS_COVER_PAGE_INCLUDED); + pdfBean.setDisplayChart(IS_DISPLAY_CHART); + pdfBean.setCurrentPage(CURRENT_PAGE); + pdfBean.setWhereToShowPageNumber(WHERE_TO_SHOW_PAGE_NUMBER); + pdfBean.setUserId(USER_ID); + pdfBean.setTimestampPattern(TIMESTAMP_PATTERN); + pdfBean.setTitle(TITLE); + pdfBean.setLeftFooter(LEFT_FOOTER); + pdfBean.setPagesize(PAGE_SIZE); + pdfBean.setAttachmentOfEmail(IS_ATTACHMENT_OF_EMAIL); + pdfBean.setLogo1Url(LOGO1_URL); + pdfBean.setLogo1Size(LOGO1_SIZE); + pdfBean.setLogo2Url(LOGO2_URL); + pdfBean.setLogo2Size(LOGO2_SIZE); + pdfBean.setFullWebContextPath(FULL_WEB_CONTEXT_PATH); + } + + @Test + public void testPdfBeanProperties() { + assertEquals(ALTERNATE_COLOR, pdfBean.isAlternateColor()); + assertEquals(IS_PORTRAIT, pdfBean.isPortrait()); + assertEquals(IS_COVER_PAGE_INCLUDED, pdfBean.isCoverPageIncluded()); + assertEquals(IS_DISPLAY_CHART, pdfBean.isDisplayChart()); + assertEquals(CURRENT_PAGE, pdfBean.getCurrentPage()); + assertEquals(2, pdfBean.getWhereToShowPageNumber()); + assertEquals(USER_ID, pdfBean.getUserId()); + assertEquals(TIMESTAMP_PATTERN, pdfBean.getTimestampPattern()); + assertEquals(TITLE, pdfBean.getTitle()); + assertEquals(LEFT_FOOTER, pdfBean.getLeftFooter()); + assertEquals(PAGE_SIZE, pdfBean.getPagesize()); + assertEquals(IS_ATTACHMENT_OF_EMAIL, pdfBean.isAttachmentOfEmail()); + assertEquals(LOGO1_URL, pdfBean.getLogo1Url()); + assertEquals(LOGO1_SIZE, pdfBean.getLogo1Size()); + assertEquals(LOGO2_URL, pdfBean.getLogo2Url()); + assertEquals(LOGO2_SIZE, pdfBean.getLogo2Size()); + assertEquals(FULL_WEB_CONTEXT_PATH, pdfBean.getFullWebContextPath()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/BarChartOptionsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/BarChartOptionsTest.java new file mode 100644 index 00000000..d7422e94 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/BarChartOptionsTest.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class BarChartOptionsTest { + BarChartOptions barChartOptions; + + private boolean VERTICAL_ORIENTATION = true; + private boolean STACKED_CHART = true; + private boolean DISPLAY_BAR_CONTROLS = true; + private boolean X_AXIS_DATE_TYPE = true; + private boolean MINIMIZE_X_AXIS_TICKERS = true; + private boolean TIME_AXIS = true; + private boolean Y_AXIS_LOG_SCALE = true; + + @Before + public void init() { + barChartOptions = new BarChartOptions(); + barChartOptions.setVerticalOrientation(VERTICAL_ORIENTATION); + barChartOptions.setStackedChart(STACKED_CHART); + barChartOptions.setDisplayBarControls(DISPLAY_BAR_CONTROLS); + barChartOptions.setxAxisDateType(X_AXIS_DATE_TYPE); + barChartOptions.setMinimizeXAxisTickers(MINIMIZE_X_AXIS_TICKERS); + barChartOptions.setTimeAxis(TIME_AXIS); + barChartOptions.setyAxisLogScale(Y_AXIS_LOG_SCALE); + } + + @Test + public void testBarChartOptionsProperties() { + assertEquals(VERTICAL_ORIENTATION, barChartOptions.isVerticalOrientation()); + assertEquals(STACKED_CHART, barChartOptions.isStackedChart()); + assertEquals(DISPLAY_BAR_CONTROLS, barChartOptions.isDisplayBarControls()); + assertEquals(X_AXIS_DATE_TYPE, barChartOptions.isxAxisDateType()); + assertEquals(MINIMIZE_X_AXIS_TICKERS, barChartOptions.isMinimizeXAxisTickers()); + assertEquals(TIME_AXIS, barChartOptions.isTimeAxis()); + assertEquals(Y_AXIS_LOG_SCALE, barChartOptions.isyAxisLogScale()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntimeTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntimeTest.java new file mode 100644 index 00000000..2dce46c0 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntimeTest.java @@ -0,0 +1,117 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import java.util.ArrayList; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.model.base.ReportWrapper; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +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, AppUtils.class}) +public class ChartWebRuntimeTest { + ChartWebRuntime chartWebRuntime; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Before + public void init() { + chartWebRuntime = new ChartWebRuntime(); + ArrayList chartList = new ArrayList<>(); + chartList.add("test"); + ArrayList infoList = new ArrayList<>(); + infoList.add("test"); + chartWebRuntime.setChartList(chartList); + chartWebRuntime.setInfoList(infoList); + chartWebRuntime.setTotalSql("select * from test"); + } + + @Test + public void testBarChartOptionsProperties() throws RaptorException { + PowerMockito.mockStatic(UserUtils.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(mockedRequest.getParameter("action")).thenReturn("test"); + Mockito.when(UserUtils.getUserId(mockedRequest)).thenReturn(10); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + Mockito.when(AppUtils.nvl(Mockito.anyString())).thenReturn("test"); + Mockito.when(mockedRequest.getParameter("refresh")).thenReturn("N"); + Mockito.when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1"); + Mockito.when(AppUtils.getRequestNvlValue(Mockito.any(HttpServletRequest.class), Mockito.anyString())).thenReturn("test"); + ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); + Mockito.when(rr.getReportID()).thenReturn("1"); + Mockito.when(rr.getReportType()).thenReturn("Hive"); + Mockito.when(rr.getReportSQL()).thenReturn("select * from test"); + Mockito.when(rr.getLegendLabelAngle()).thenReturn("standard"); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", new ArrayList(), true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", new ArrayList(), false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", new ArrayList(), false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + Mockito.when(rr.getReportFormFields()).thenReturn(reportFormFields); + Mockito.when(rr.getReportDefType()).thenReturn(AppConstants.RD_SQL_BASED); + Mockito.when(rr.getReportTitle()).thenReturn("test"); + Mockito.when(mockedRequest.getParameterValues(Matchers.anyString())).thenReturn(new String[] { "test" }); + chartWebRuntime.generateChart(mockedRequest); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/CommonChartOptionsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/CommonChartOptionsTest.java new file mode 100644 index 00000000..c8bee8ec --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/CommonChartOptionsTest.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class CommonChartOptionsTest { + CommonChartOptions commonChartOptions; + + private String LEGEND_POSITION = "top"; + private String LEGEND_LABEL_ANGLE = "up45"; + private boolean HIDE_LEGEND = false; + private boolean ANIMATE_ANIMATED_CHART = true; + private int TOP_MARGIN = 30; + private int BOTTOM_MARGIN = 50; + private int LEFT_MARGIN = 100; + private int RIGHT_MARGIN = 60; + + @Before + public void init(){ + commonChartOptions = new CommonChartOptions(); + commonChartOptions.setLegendPosition(LEGEND_POSITION); + commonChartOptions.setLegendLabelAngle(LEGEND_LABEL_ANGLE); + commonChartOptions.setHideLegend(HIDE_LEGEND); + commonChartOptions.setAnimateAnimatedChart(ANIMATE_ANIMATED_CHART); + commonChartOptions.setTopMargin(TOP_MARGIN); + commonChartOptions.setBottomMargin(BOTTOM_MARGIN); + commonChartOptions.setLeftMargin(LEFT_MARGIN); + commonChartOptions.setRightMargin(RIGHT_MARGIN); + } + + @Test + public void testCommonChartOptionsProperties(){ + assertEquals(LEGEND_POSITION, commonChartOptions.getLegendPosition()); + assertEquals(LEGEND_LABEL_ANGLE, commonChartOptions.getLegendLabelAngle()); + assertEquals(HIDE_LEGEND, commonChartOptions.isHideLegend()); + assertEquals(ANIMATE_ANIMATED_CHART, commonChartOptions.isAnimateAnimatedChart()); + assertEquals(TOP_MARGIN, commonChartOptions.getTopMargin()); + assertEquals(BOTTOM_MARGIN, commonChartOptions.getBottomMargin()); + assertEquals(LEFT_MARGIN, commonChartOptions.getLeftMargin()); + assertEquals(RIGHT_MARGIN, commonChartOptions.getRightMargin()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ErrorJSONRuntimeTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ErrorJSONRuntimeTest.java new file mode 100644 index 00000000..c5b42989 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ErrorJSONRuntimeTest.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ErrorJSONRuntimeTest { + ErrorJSONRuntime errorJSONRuntime; + + private String ERROR_MESSAGE = "testMesage"; + private String STACKTRACE = "testStacktrace"; + + @Before + public void init(){ + errorJSONRuntime = new ErrorJSONRuntime(); + errorJSONRuntime.setErrormessage(ERROR_MESSAGE); + errorJSONRuntime.setStacktrace(STACKTRACE); + } + + @Test + public void testErrorJSONRuntimeProperties(){ + assertEquals(ERROR_MESSAGE, errorJSONRuntime.getErrormessage()); + assertEquals(STACKTRACE, errorJSONRuntime.getStacktrace()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FlexTimeSeriesChartOptionsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FlexTimeSeriesChartOptionsTest.java new file mode 100644 index 00000000..85fede3e --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FlexTimeSeriesChartOptionsTest.java @@ -0,0 +1,64 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class FlexTimeSeriesChartOptionsTest { + FlexTimeSeriesChartOptions flexTimeSeriesChartOptions; + + private int ZOOM_IN = 25; + private String TIME_AXIS_TYPE = ""; + + @Before + public void init(){ + flexTimeSeriesChartOptions = new FlexTimeSeriesChartOptions(); + flexTimeSeriesChartOptions.setZoomIn(ZOOM_IN); + flexTimeSeriesChartOptions.setTimeAxisType(TIME_AXIS_TYPE); + } + + @Test + public void testFlexTimeSeriesChartOptionsProperties(){ + assertEquals(ZOOM_IN, flexTimeSeriesChartOptions.getZoomIn()); + assertEquals(TIME_AXIS_TYPE, flexTimeSeriesChartOptions.getTimeAxisType()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FormatProcessorTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FormatProcessorTest.java new file mode 100644 index 00000000..d89074cd --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/FormatProcessorTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Before; +import org.junit.Test; +import org.onap.portalsdk.analytics.xmlobj.FormatList; +import org.onap.portalsdk.analytics.xmlobj.FormatType; +import org.onap.portalsdk.analytics.xmlobj.SemaphoreType; + +public class FormatProcessorTest { + FormatProcessor formatProcessor; + + @Before + public void init(){ + SemaphoreType semaphoreType = new SemaphoreType(); + semaphoreType.setSemaphoreName("semaphoreName"); + semaphoreType.setSemaphoreType("semaphoreType"); + semaphoreType.setComment("comment"); + semaphoreType.setTarget("target"); + FormatList formatList = new FormatList(); + FormatType formatType = new FormatType(); + formatType.setLessThanValue("lessThanValue"); + formatType.setExpression("expression"); + formatType.setBold(false); + formatType.setItalic(false); + formatType.setUnderline(false); + formatType.setBgColor("bgColor"); + formatType.setFontColor("fontColor"); + formatType.setFontFace("fontFace"); + formatType.setFontSize("fontSize"); + formatType.setAlignment("alignment"); + formatType.setComment("comment"); + formatType.setFormatId("formatId"); + formatList.getFormat().add(formatType); + semaphoreType.setFormatList(formatList); + semaphoreType.setSemaphoreId("semaphoreId"); + formatProcessor = new FormatProcessor(semaphoreType, "test", "test", true); + } + + @Test + public void testNotNull(){ + assertNotNull(formatProcessor); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ItemTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ItemTest.java new file mode 100644 index 00000000..086b9d9d --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ItemTest.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class ItemTest { + Item item; + + private String ID = "testID"; + private String NAME = "name"; + + @Before + public void init(){ + item = new Item(); + item.setId(ID); + item.setName(NAME); + } + + @Test + public void testItemProperties(){ + assertEquals(ID, item.getId()); + assertEquals(NAME, item.getName()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/LookupDBInfoTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/LookupDBInfoTest.java new file mode 100644 index 00000000..71ad8c28 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/LookupDBInfoTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class LookupDBInfoTest { + LookupDBInfo lookupDBInfo; + + private String TABLE_NAME = "tableName"; + private String FIELD_NAME = "fieldName"; + private String LOOKUP_TABLE = "lookupTable"; + private String LOOKUP_ID_FIELD = "lookupIdField"; + private String LOOKUP_NAME_FIELD = "lookupNameField"; + + @Before + public void init(){ + lookupDBInfo = new LookupDBInfo(TABLE_NAME, FIELD_NAME, LOOKUP_TABLE, LOOKUP_ID_FIELD, LOOKUP_NAME_FIELD); + } + + @Test + public void testItemProperties(){ + assertEquals(TABLE_NAME, lookupDBInfo.getTableName()); + assertEquals(FIELD_NAME, lookupDBInfo.getFieldName()); + assertEquals(LOOKUP_TABLE, lookupDBInfo.getLookupTable()); + assertEquals(LOOKUP_ID_FIELD, lookupDBInfo.getLookupIdField()); + assertEquals(LOOKUP_NAME_FIELD, lookupDBInfo.getLookupNameField()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RangeAxisJSONTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RangeAxisJSONTest.java new file mode 100644 index 00000000..e0a9b371 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RangeAxisJSONTest.java @@ -0,0 +1,77 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class RangeAxisJSONTest { + RangeAxisJSON rangeAxisJSON; + + private RangeAxisLabelJSON rangeAxisLabelJSON; + private RangeColorJSON rangeColorJSON; + private RangeLineTypeJSON rangeLineTypeJSON; + private String RANGE_CHART_GROUP = "rangeChartGroup"; + private String RANGE_Y_AXIS = "rangeYAxis"; + private boolean SHOW_AS_AREA = true; + + @Before + public void init(){ + rangeAxisLabelJSON = new RangeAxisLabelJSON(); + rangeColorJSON = new RangeColorJSON(); + rangeLineTypeJSON = new RangeLineTypeJSON(); + rangeAxisJSON = new RangeAxisJSON(); + rangeAxisJSON.setRangeAxisLabelJSON(rangeAxisLabelJSON); + rangeAxisJSON.setRangeColorJSON(rangeColorJSON); + rangeAxisJSON.setRangeLineTypeJSON(rangeLineTypeJSON); + rangeAxisJSON.setRangeChartGroup(RANGE_CHART_GROUP); + rangeAxisJSON.setRangeYAxis(RANGE_Y_AXIS); + rangeAxisJSON.setShowAsArea(SHOW_AS_AREA); + } + + @Test + public void testItemProperties(){ + assertEquals(rangeAxisLabelJSON, rangeAxisJSON.getRangeAxisLabelJSON()); + assertEquals(rangeColorJSON, rangeAxisJSON.getRangeColorJSON()); + assertEquals(rangeLineTypeJSON, rangeAxisJSON.getRangeLineTypeJSON()); + assertEquals(RANGE_Y_AXIS, rangeAxisJSON.getRangeYAxis()); + assertEquals(SHOW_AS_AREA, rangeAxisJSON.isShowAsArea()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RaptorControllerAsyncTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RaptorControllerAsyncTest.java index 07e1745b..c5010c1a 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RaptorControllerAsyncTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/RaptorControllerAsyncTest.java @@ -39,13 +39,16 @@ package org.onap.portalsdk.analytics.model.runtime; import static org.junit.Assert.assertEquals; +import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StringWriter; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Vector; import javax.servlet.ServletContext; @@ -71,6 +74,7 @@ import org.onap.portalsdk.analytics.model.ReportLoader; import org.onap.portalsdk.analytics.model.base.IdNameValue; import org.onap.portalsdk.analytics.model.base.ReportWrapper; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; +import org.onap.portalsdk.analytics.model.definition.SecurityEntry; import org.onap.portalsdk.analytics.model.definition.wizard.ColumnJSON; import org.onap.portalsdk.analytics.model.definition.wizard.DefinitionJSON; import org.onap.portalsdk.analytics.system.AppUtils; @@ -104,7 +108,7 @@ import org.powermock.reflect.exceptions.MethodInvocationException; @RunWith(PowerMockRunner.class) @PrepareForTest({ AppConstants.class, Globals.class, AppUtils.class, ReportWrapper.class, DataCache.class, DbUtils.class, DataSet.class , ReportLoader.class ,ReportRuntime.class, Utils.class, ESAPI.class, - Codec.class,SecurityCodecUtil.class , ConnectionUtils.class, XSSFilter.class}) + Codec.class,SecurityCodecUtil.class , ConnectionUtils.class, XSSFilter.class, RaptorControllerAsync.class}) public class RaptorControllerAsyncTest { @InjectMocks @@ -617,4 +621,100 @@ public class RaptorControllerAsyncTest { return chartJSON; } + @Test + public void listChildReportColsTest() throws Exception { + ReportRuntime rr = Mockito.mock(ReportRuntime.class); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportRuntime(Mockito.any(HttpServletRequest.class), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(rr); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setColName("test"); + dataColumnType.setColId("1"); + dataColumnTypeList.add(dataColumnType); + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + raptorControllerAsync.listChildReportCols("reportID", mockedRequest, mockedResponse); + } + + @Test + public void listChildReportFormFieldsTest() throws Exception { + ReportRuntime rr = Mockito.mock(ReportRuntime.class); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportRuntime(Mockito.any(HttpServletRequest.class), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(rr); + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + Mockito.when(rr.getReportFormFields()).thenReturn(reportFormFields); + raptorControllerAsync.listChildReportFormFields("reportID", mockedRequest, mockedResponse); + } + + @Test + public void getReportSecurityUsersTest() throws Exception { + ReportDefinition rdef = Mockito.mock(ReportDefinition.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + Vector vc = new Vector<>(); + vc.add(new SecurityEntry("1", "test", true)); + Mockito.when(rdef.getReportUsers(mockedRequest)).thenReturn(vc); + raptorControllerAsync.getReportSecurityUsers(mockedRequest); + } + + @Test + public void getReportSecurityRolesTest() throws Exception { + ReportDefinition rdef = Mockito.mock(ReportDefinition.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + Vector vc = new Vector<>(); + vc.add(new SecurityEntry("1", "test", true)); + Mockito.when(rdef.getReportRoles(mockedRequest)).thenReturn(vc); + raptorControllerAsync.getReportSecurityRoles(mockedRequest); + } + + public ReportDefinition mockReportDefinition() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(DbUtils.class); + Mockito.when(Globals.getReportUserAccess()).thenReturn("test"); + DataSet datset = PowerMockito.mock(DataSet.class); + Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); + Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); + CustomReportType customReportType = new CustomReportType(); + customReportType.setReportType("test"); + FormFieldList formFieldList = new FormFieldList(); + formFieldList.setComment("test"); + customReportType.setFormFieldList(formFieldList); + customReportType.setPublic(true); + customReportType.setReportType("test"); + customReportType.setReportTitle("test"); + ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", + "1", true); + reportWrapper.setReportDefType("SQL-based"); + ReportDefinition reportDefinition = new ReportDefinition(reportWrapper, mockedRequest); + return reportDefinition; + } + @Test + public void retrieveDefTabWiseDataTest() throws Exception { + PowerMockito.mockStatic(AppUtils.class); + ReportDefinition rdef = mockReportDefinition(); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_DEFINITION)).thenReturn(rdef); + Map pathVariables = new HashMap<>(); + pathVariables.put("id", "InSession"); + pathVariables.put("detailId", "test"); + Vector vc = new Vector<>(); + vc.add("test"); + PowerMockito.when(AppUtils.getQuickLinksMenuIDs()).thenReturn(vc); + raptorControllerAsync.retrieveDefTabWiseData(pathVariables, mockedRequest, mockedResponse); + } + + + } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParserTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParserTest.java new file mode 100644 index 00000000..88bcd6b9 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamDateValueParserTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class ReportParamDateValueParserTest { + + @Test + public void testIsDateHrParam() { + assertFalse(ReportParamDateValueParser.isDateHrParam("29-MAY-2018")); + } + + @Test + public void testIsDateParam() { + assertTrue(ReportParamDateValueParser.isDateParam("29-MAY-2018")); + } + + @Test + public void testFormatDateParamValue() { + assertNotNull(ReportParamDateValueParser.formatDateParamValue("29-MAY-2018")); + } + + @Test + public void testFormatDateHrParamValue() { + assertNotNull(ReportParamDateValueParser.formatDateHrParamValue("29-MAY-2018")); + } +} \ No newline at end of file diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamValuesForPDFExcelTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamValuesForPDFExcelTest.java new file mode 100644 index 00000000..e9e43a7e --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/ReportParamValuesForPDFExcelTest.java @@ -0,0 +1,133 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +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.Matchers; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.model.base.ReportWrapper; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.ConnectionUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.util.AppConstants; +import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.onap.portalsdk.core.util.SecurityCodecUtil; +import org.owasp.esapi.ESAPI; +import org.owasp.esapi.Encoder; +import org.owasp.esapi.codecs.Codec; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, ESAPI.class, AppUtils.class, SecurityCodecUtil.class, ConnectionUtils.class}) +public class ReportParamValuesForPDFExcelTest { + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + ReportParamValuesForPDFExcel reportParamValuesForPDFExcel; + ReportFormFields reportFormFields; + ReportRuntime rr; + @Before + public void setUp() throws RaptorException { + rr = Mockito.mock(ReportRuntime.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + reportFormFields = new ReportFormFields(rw, mockedRequest); + List predefinedValues = new ArrayList(); + FormField formField = Mockito.mock(FormField.class); + Mockito.when(formField.getFieldName()).thenReturn("fftest"); + Mockito.when(formField.getFieldDisplayName()).thenReturn("fieldDisplayName"); + Mockito.when(formField.getBaseSQLForPDFExcel()).thenReturn("select * from test"); + Mockito.when(formField.getFieldDefaultSQL()).thenReturn("select * from test"); + reportFormFields.add(formField); + Mockito.when(rr.getReportFormFields()).thenReturn(reportFormFields); + Mockito.when(rr.getReportType()).thenReturn("test"); + Mockito.when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + Mockito.when(Globals.getRequestParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(),Mockito.anyInt())).thenReturn("test"); + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(),Mockito.anyString())).thenReturn(ds); + } + + @Test + public void testSetParamValues_WithCombo() throws Exception { + Mockito.when(reportFormFields.getFormField(0).getFieldType()).thenReturn(FormField.FFT_COMBO_BOX); + Mockito.when(reportFormFields.getFormField(0).getValidationType()).thenReturn(FormField.VT_TIMESTAMP_HR); + ReportParamValues params = new ReportParamValues(reportFormFields, "test"); + Mockito.when(rr.getParamKeys()).thenReturn(params.keys()); + reportParamValuesForPDFExcel = new ReportParamValuesForPDFExcel(reportFormFields, "test"); + reportParamValuesForPDFExcel.setParamValues(mockedRequest, true); + } + + @Test + public void testSetParamValues_WithCheckBox() throws Exception { + Mockito.when(reportFormFields.getFormField(0).getFieldType()).thenReturn(FormField.FFT_CHECK_BOX); + Mockito.when(reportFormFields.getFormField(0).getValidationType()).thenReturn(FormField.VT_TIMESTAMP_MIN); + ReportParamValues params = new ReportParamValues(reportFormFields, "test"); + Mockito.when(rr.getParamKeys()).thenReturn(params.keys()); + reportParamValuesForPDFExcel = new ReportParamValuesForPDFExcel(reportFormFields, "test"); + reportParamValuesForPDFExcel.setParamValues(mockedRequest, true); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/TimeSeriesChartOptionsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/TimeSeriesChartOptionsTest.java new file mode 100644 index 00000000..1d555574 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/model/runtime/TimeSeriesChartOptionsTest.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalsdk.analytics.model.runtime; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class TimeSeriesChartOptionsTest { + TimeSeriesChartOptions timeSeriesChartOptions; + + private String LINE_CHART_RENDERER = "lineChartRenderer"; + private boolean MULTI_SERIES = true; + private boolean NON_TIME_AXIS = true; + private boolean SHOW_X_AXIS_LABEL = true; + private boolean ADD_X_AXIS_TICKER = true; + + @Before + public void init() { + timeSeriesChartOptions = new TimeSeriesChartOptions(); + timeSeriesChartOptions.setLineChartRenderer(LINE_CHART_RENDERER); + timeSeriesChartOptions.setMultiSeries(MULTI_SERIES);; + timeSeriesChartOptions.setNonTimeAxis(NON_TIME_AXIS); + timeSeriesChartOptions.setShowXAxisLabel(SHOW_X_AXIS_LABEL); + timeSeriesChartOptions.setAddXAxisTicker(ADD_X_AXIS_TICKER); + } + + @Test + public void testBarChartOptionsProperties() { + assertEquals(LINE_CHART_RENDERER, timeSeriesChartOptions.getLineChartRenderer()); + assertEquals(MULTI_SERIES, timeSeriesChartOptions.isMultiSeries()); + assertEquals(NON_TIME_AXIS, timeSeriesChartOptions.isNonTimeAxis()); + assertEquals(SHOW_X_AXIS_LABEL, timeSeriesChartOptions.isShowXAxisLabel()); + assertEquals(ADD_X_AXIS_TICKER, timeSeriesChartOptions.isAddXAxisTicker()); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java new file mode 100644 index 00000000..63a72c37 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/util/UtilsTest.java @@ -0,0 +1,192 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portalsdk.analytics.util; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.model.base.IdNameValue; +import org.onap.portalsdk.analytics.system.AppUtils; +import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.xmlobj.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Globals.class, AppUtils.class, Utils.class}) +public class UtilsTest { + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpSession session = mockedRequest.getSession(); + + @Test + public void getUsersNotInListTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForUsers()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllUsers(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Utils.getUsersNotInList(list, mockedRequest); + } + + @Test + public void getRolesNotInListTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForRoles()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllRoles(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Mockito.when(AppUtils.getSuperRoleID()).thenReturn("1"); + Utils.getRolesNotInList(list, mockedRequest); + } + + @Test + public void getUsersNotInListLatestTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForUsers()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllUsers(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Utils.getUsersNotInListLatest(list, mockedRequest); + } + + @Test + public void getRolesNotInListLatestTest() throws RaptorException { + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(Globals.getCustomizedScheduleQueryForRoles()).thenReturn("select * from test"); + Mockito.when(AppUtils.getUserBackdoorLoginId(mockedRequest)).thenReturn("test"); + Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + Mockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); + IdNameValue idNameValue = new IdNameValue(); + idNameValue.setId("1"); + Vector vc = new Vector(); + vc.add(idNameValue); + List list = new ArrayList(); + list.add(idNameValue); + Mockito.when(AppUtils.getAllRoles(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(vc); + Mockito.when(AppUtils.getSuperRoleID()).thenReturn("1"); + Utils.getRolesNotInListLatest(list, mockedRequest); + } + + @Test + public void isDownloadFileExistsTest() throws Exception { + File file = Mockito.mock(File.class); + String[] fileNames = new String[] {"test.txt"}; + Mockito.when(file.list()).thenReturn(fileNames); + PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(file); + Utils.isDownloadFileExists("test"); + } + + @Test + public void getLatestDownloadableFileTest() throws Exception { + File file = Mockito.mock(File.class); + String[] fileNames = new String[] {"test.txt","test1.txt"}; + Mockito.when(file.list()).thenReturn(fileNames); + PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(file); + Utils.getLatestDownloadableFile("test"); + } + + @Test + public void javaSafeTest() throws Exception { + Utils.javaSafe("Hel'oo world!"); + } + + @Test(expected=RuntimeException.class) + public void _assertTest() throws Exception { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getDebugLevel()).thenReturn(1); + Utils._assert(false, "errorMsg"); + } + + @Test + public void getCurrentDateTimeTest() { + Utils.getCurrentDateTime(); + } + + @Test + public void htmlEncodeTest() { + Utils.htmlEncode("test"); + } + + +} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java deleted file mode 100644 index 9abd87fe..00000000 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ActionHandlerTest.java +++ /dev/null @@ -1,547 +0,0 @@ -/* - * ============LICENSE_START========================================== - * ONAP Portal SDK - * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * =================================================================== - * - * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the "License"); - * you may not use this software except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); - * you may not use this documentation except in compliance with the License. - * You may obtain a copy of the License at - * - * https://creativecommons.org/licenses/by/4.0/ - * - * Unless required by applicable law or agreed to in writing, documentation - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============LICENSE_END============================================ - * - * - */ -package org.onap.portalsdk.analytics.xmlobj; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; -import static org.powermock.api.mockito.PowerMockito.whenNew; - -import java.io.InputStream; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.junit.Before; -import org.junit.Ignore; -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.portalsdk.analytics.controller.ActionHandler; -import org.onap.portalsdk.analytics.model.ReportLoader; -import org.onap.portalsdk.analytics.model.SearchHandler; -import org.onap.portalsdk.analytics.model.base.ReportWrapper; -import org.onap.portalsdk.analytics.model.definition.ReportDefinition; -import org.onap.portalsdk.analytics.model.runtime.ChartWebRuntime; -import org.onap.portalsdk.analytics.model.runtime.FormField; -import org.onap.portalsdk.analytics.model.runtime.ReportFormFields; -import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; -import org.onap.portalsdk.analytics.system.AppUtils; -import org.onap.portalsdk.analytics.system.DbUtils; -import org.onap.portalsdk.analytics.system.Globals; -import org.onap.portalsdk.analytics.util.AppConstants; -import org.onap.portalsdk.analytics.util.DataSet; -import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum; -import org.onap.portalsdk.core.util.SecurityCodecUtil; -import org.onap.portalsdk.core.web.support.UserUtils; -import org.owasp.esapi.ESAPI; -import org.owasp.esapi.Encoder; -import org.owasp.esapi.codecs.Codec; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ AppUtils.class, UserUtils.class, ESAPI.class, AppConstants.class, AlarmSeverityEnum.class, ReportWrapper.class, - ReportDefinition.class, SecurityCodecUtil.class, Globals.class, DbUtils.class, ReportLoader.class }) -public class ActionHandlerTest { - - @InjectMocks - ActionHandler actionHandler = new ActionHandler(); - - @Mock - Connection connection; - @Mock - PreparedStatement stmt; - @Mock - ResultSet rs; - @Mock - java.sql.Clob clob; - @Mock - InputStream in; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); - HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - - @Test - public void reportRunExceptionTest() { - when(mockedRequest.getParameter("action")).thenReturn("test"); - PowerMockito.mockStatic(AppUtils.class); - when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(true); - assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); - } - - @SuppressWarnings("unchecked") - @Test - public void reportRunRaptorReportExceptionTest() throws Exception { - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - PowerMockito.mockStatic(ReportLoader.class); - PowerMockito.mockStatic(ReportWrapper.class); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mock(AppConstants.class); - PowerMockito.mockStatic(ReportDefinition.class); - PowerMockito.mockStatic(ESAPI.class); - PowerMockito.mockStatic(SecurityCodecUtil.class); - when(mockedRequest.getParameter("action")).thenReturn("test"); - when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); - when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("testxyz"); - ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); - when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); - when(mockedRequest.getSession().getAttribute("FirstDashReport")).thenReturn(rr); - when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.download"); - Encoder encoder = PowerMockito.mock(Encoder.class); - when(ESAPI.encoder()).thenReturn(encoder); - Codec codec = PowerMockito.mock(Codec.class); - when(SecurityCodecUtil.getCodec()).thenReturn(codec); - when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); - when(Globals.getDownloadAllEmailSent()).thenReturn("test"); - DataSet set = Mockito.mock(DataSet.class); - when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); - when(DbUtils.getConnection()).thenReturn(connection); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test2"); - when(rr.getReportID()).thenReturn("test"); - when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); - when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); - String str = "namedesctypefalsefalseidfalse"; - when(connection.prepareStatement("1")).thenReturn(stmt); - when(stmt.executeQuery()).thenReturn(rs); - when(Globals.isWeblogicServer()).thenReturn(true); - when(rs.getClob(1)).thenReturn(clob); - when(rs.next()).thenReturn(true); - when(clob.getAsciiStream()).thenReturn(in); - when(in.read(Matchers.any())).thenReturn(1); - when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); - when(AppUtils.nvl("Y")).thenReturn("Y"); - when(AppUtils.nvl("bottom")).thenReturn("Y"); - when(AppUtils.nvl("test")).thenReturn("test|"); - when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); - when(ReportLoader.isDashboardType("-1")).thenReturn(false); - ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); - whenNew(ReportDefinition.class) - .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) - .thenReturn(rdf); - when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); - CustomReportType crType = Mockito.mock(CustomReportType.class); - when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); - when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); - when(Globals.getTimeFormat()).thenReturn("[reportID]"); - when(Globals.getReportUserAccess()).thenReturn("[reportID]"); - when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); - when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); - when(ReportLoader.loadCustomReportXML("test2")).thenReturn(str); - FormFieldType formFieldType = new FormFieldType(); - formFieldType.setFieldId("test"); - formFieldType.setColId("1"); - formFieldType.setFieldName("test"); - formFieldType.setFieldType("type"); - formFieldType.setValidationType("validation"); - formFieldType.setMandatory("Y"); - formFieldType.setDefaultValue("test"); - formFieldType.setGroupFormField(true); - List formFieldTypeList = new ArrayList<>(); - formFieldTypeList.add(formFieldType); - FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class); - when(formFieldList.getFormField()).thenReturn(formFieldTypeList); - Mockito.when(crType.getFormFieldList()).thenReturn(formFieldList); - when(Globals.getRequestParams()).thenReturn("test,case"); - when( Globals.getSessionParams()).thenReturn("test,abc"); - when(Globals.getSessionParamsForScheduling()).thenReturn("test"); - - DataSourceList dataSourceList = new DataSourceList(); - List list = new ArrayList<>(); - DataSourceType dataSourceType = new DataSourceType(); - dataSourceType.setTableName("test"); - dataSourceType.setRefTableId("1"); - dataSourceType.setTableId("1"); - List dataColumnTypeList = new ArrayList<>(); - DataColumnType dataColumnType = new DataColumnType(); - dataColumnType.setChartGroup("test"); - dataColumnType.setYAxis("test"); - dataColumnType.setColName("[test"); - dataColumnType.setColOnChart("LEGEND"); - dataColumnType.setDisplayName("chart_total"); - dataColumnType.setColId("1"); - dataColumnType.setTableId("1"); - dataColumnType.setColType("DATE"); - dataColumnType.setCrossTabValue("ROW"); - dataColumnType.setPdfDisplayWidthInPxls("0.0"); - dataColumnType.setVisible(true); - dataColumnType.setCalculated(true); - dataColumnTypeList.add(dataColumnType); - DataColumnType dataColumnType1 = new DataColumnType(); - dataColumnType1.setCrossTabValue("COLUMN"); - dataColumnType1.setColId("1"); - dataColumnType1.setVisible(true); - dataColumnType1.setPdfDisplayWidthInPxls("1.0"); - dataColumnTypeList.add(dataColumnType1); - - DataColumnList dataColumnList = new DataColumnList(); - dataColumnList.dataColumn = dataColumnTypeList; - dataSourceType.setDataColumnList(dataColumnList); - list.add(dataSourceType); - dataSourceList.dataSource = list; - when(crType.getDataSourceList()).thenReturn(dataSourceList); - when(rr.getReportType()).thenReturn(AppConstants.RT_DASHBOARD); - - List predefinedValues = new ArrayList<>(); - ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); - ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); - FormField formField = new FormField("test", "fieldDisplayName", FormField.FFT_COMBO_BOX, "validationType", false, - "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", - "rangeEndDateSQL", "multiSelectListSize"); - FormField formField1 = new FormField("test", "fieldDisplayName", FormField.FFT_LIST_MULTI, "validationType", false, - "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", - "rangeEndDateSQL", "multiSelectListSize"); - FormField formField2 = new FormField("test", "fieldDisplayName", FormField.FFT_BLANK, "validationType", false, - "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", - "rangeEndDateSQL", "multiSelectListSize"); - - reportFormFields.add(formField); - reportFormFields.add(formField1); - reportFormFields.add(formField2); - rr.setReportFormFields(null); - rr.setReportFormFields(reportFormFields); - when(rr.getReportFormFields()).thenReturn(reportFormFields); - when(mockedRequest.getSession().getAttribute("remoteDB")).thenReturn("test"); - Enumeration enums; - Vector attrs = new Vector(); - attrs.add("ff_test"); - enums = attrs.elements(); - when(rr.getParamKeys()).thenReturn(enums); - assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); - } - - - @Test - public void reportRunForCSVDownloadTest() throws Exception { - when(mockedRequest.getParameter("action")).thenReturn("test"); - when(mockedRequest.getParameter("r_action")).thenReturn("report.csv.download"); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - - when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); - when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn(""); - ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); - when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); - when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); - when(AppUtils.getRequestFlag(mockedRequest, "fromReportLog")).thenReturn(true); - when(rr.getReportType()).thenReturn(AppConstants.RT_LINEAR); - when(rr.getReportDataSQL(Matchers.anyString(), Matchers.anyInt(), Matchers.any())).thenReturn("test"); - PowerMockito.mockStatic(ESAPI.class); - Encoder encoder = PowerMockito.mock(Encoder.class); - when(ESAPI.encoder()).thenReturn(encoder); - Codec codec = PowerMockito.mock(Codec.class); - PowerMockito.mockStatic(SecurityCodecUtil.class); - when(SecurityCodecUtil.getCodec()).thenReturn(codec); - when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); - when(Globals.getDownloadAllEmailSent()).thenReturn("test"); - DataSet set = new DataSet(); - when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); - assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); - } - - public ReportRuntime mockReportRunTime1() throws Exception { - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - when(Globals.getReportUserAccess()).thenReturn("test"); - ResultSet rs = PowerMockito.mock(ResultSet.class); - ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); - when(rsmd.getColumnCount()).thenReturn(1); - when(rs.getMetaData()).thenReturn(rsmd); - DataSet datset = PowerMockito.mock(DataSet.class); - // datset = new DataSet(rs); - when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); - when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); - when(Globals.getNewScheduleData()).thenReturn("test"); - CustomReportType customReportType = new CustomReportType(); - DataSourceList dataSourceList = new DataSourceList(); - DataSourceType dataSourceType = new DataSourceType(); - dataSourceType.setTableName("test"); - dataSourceType.setRefTableId("1"); - dataSourceType.setTableId("1"); - List dataColumnTypeList = new ArrayList<>(); - DataColumnType dataColumnType = new DataColumnType(); - dataColumnType.setChartGroup("test"); - dataColumnType.setYAxis("test"); - dataColumnType.setColName("[test"); - dataColumnType.setColOnChart("LEGEND"); - dataColumnType.setDisplayName("chart_total"); - dataColumnType.setColId("1"); - dataColumnType.setTableId("1"); - dataColumnType.setColType("DATE"); - dataColumnTypeList.add(dataColumnType); - customReportType.setReportType("test"); - customReportType.setReportTitle("test"); - customReportType.setDataSourceList(dataSourceList); - ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions(); - chartAdditionalOptions.setLabelAngle("test"); - chartAdditionalOptions.setTimeSeriesRender("test"); - chartAdditionalOptions.setMultiSeries(false); - customReportType.setChartAdditionalOptions(chartAdditionalOptions); - ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", - "1", true); - PowerMockito.mockStatic(UserUtils.class); - when(Globals.getRequestParams()).thenReturn("test"); - when(Globals.getSessionParams()).thenReturn("test"); - when(Globals.getSessionParamsForScheduling()).thenReturn("test"); - PowerMockito.mockStatic(AppUtils.class); - when(AppUtils.getUserID(mockedRequest)).thenReturn("test12"); - ReportRuntime rr = new ReportRuntime(reportWrapper, mockedRequest); - rr.setLegendLabelAngle("test"); - rr.setMultiSeries(false); - rr.setChartType("test"); - return rr; - } - - - @Test - public void reportRunTestCase1() throws Exception { - when(mockedRequest.getParameter("action")).thenReturn("test"); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - - when(AppUtils.getRequestFlag(mockedRequest, "fromDashboard")).thenReturn(false); - when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); - ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); - when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); - - PowerMockito.mockStatic(ESAPI.class); - Encoder encoder = PowerMockito.mock(Encoder.class); - when(ESAPI.encoder()).thenReturn(encoder); - Codec codec = PowerMockito.mock(Codec.class); - PowerMockito.mockStatic(SecurityCodecUtil.class); - when(SecurityCodecUtil.getCodec()).thenReturn(codec); - when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); - when(Globals.getDownloadAllEmailSent()).thenReturn("test"); - DataSet set = PowerMockito.mock(DataSet.class); - when(set.isEmpty()).thenReturn(false); - when(DbUtils.executeQuery(Matchers.anyString(), Matchers.anyInt())).thenReturn(set); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn(null); - PowerMockito.mockStatic(ReportLoader.class); - when(ReportLoader.loadCustomReportXML(Matchers.anyString())).thenReturn("test"); - assertEquals(actionHandler.reportRun(mockedRequest, "test").getClass(), String.class); - } - - - @Test - public void reportDeleteTest() throws Exception { - PowerMockito.mockStatic(ESAPI.class); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - PowerMockito.mockStatic(AlarmSeverityEnum.class); - DataSet set = Mockito.mock(DataSet.class); - Encoder encoder = PowerMockito.mock(Encoder.class); - ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); - ReportDefinition rd = PowerMockito.mock(ReportDefinition.class); - when(ESAPI.encoder()).thenReturn(encoder); - Codec codec = PowerMockito.mock(Codec.class); - PowerMockito.mockStatic(SecurityCodecUtil.class); - when(SecurityCodecUtil.getCodec()).thenReturn(codec); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1"); - when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("1"); - when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); - when(Globals.getReportSecurity()).thenReturn("[rw.getReportID()]"); - when(Globals.getReportUserAccess()).thenReturn("[reportID]"); - when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); - when(Globals.getDeleteOnlyByOwner()).thenReturn(true); - when(Globals.getLogVariablesInSession()).thenReturn("test"); - HttpSession session = Mockito.mock(HttpSession.class); - when(session.getAttribute(Matchers.anyString())).thenReturn(rr); - when(session.getAttribute(Matchers.anyString())).thenReturn(rd); - assertEquals(actionHandler.reportDelete(mockedRequest, "10").getClass(), String.class); - } - - - @Test - public void reportSearchTest() throws Exception { - PowerMockito.mockStatic(ESAPI.class); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - when(AppUtils.getImgFolderURL()).thenReturn("test"); - when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_F_REPORT_ID)).thenReturn("test"); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_F_REPORT_NAME)).thenReturn("test"); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_SORT_ORDER)).thenReturn("f_owner_id"); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_LIST_CATEGORY)).thenReturn("test"); - when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_USER_REPORTS)).thenReturn(true); - when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_PUBLIC_REPORTS)).thenReturn(true); - when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_FAVORITE_REPORTS)).thenReturn(true); - when(AppUtils.nvl(Matchers.anyString())).thenReturn("te"); - when(Globals.getLoadReportSearchResult()).thenReturn("test"); - when(Globals.getLoadReportSearchRepIdSql()).thenReturn("test"); - when(Globals.getLoadReportSearchInstr()).thenReturn("test"); - when(Globals.getLoadReportSearchResultUser()).thenReturn("test"); - when(Globals.getLoadReportSearchResultPublic()).thenReturn("test"); - when(Globals.getLoadReportSearchResultFav()).thenReturn("test"); - when(Globals.getLoadReportSearchResultSort()).thenReturn("test"); - when(AppUtils.getRequestNvlValue(mockedRequest, "r_page")).thenReturn("10"); - Vector vc = new Vector<>(); - vc.add("test"); - vc.add("test2"); - when(AppUtils.getUserRoles(mockedRequest)).thenReturn(vc); - when(AppUtils.isSuperUser(mockedRequest)).thenReturn(false); - DataSet set = Mockito.mock(DataSet.class); - when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); - Enumeration enums; - Vector attrs = new Vector(); - attrs.add("parent_test"); - attrs.add("child_test"); - enums = attrs.elements(); - when(mockedRequest.getSession().getAttributeNames()).thenReturn(enums); - when(mockedRequest.getParameter("rep_id")).thenReturn("test"); - when(mockedRequest.getParameter("rep_id_options")).thenReturn("test"); - when(mockedRequest.getParameter("rep_name_options")).thenReturn("test"); - when(mockedRequest.getParameter("rep_name")).thenReturn("test"); - SearchHandler sh = Mockito.mock(SearchHandler.class); - whenNew(SearchHandler.class).withNoArguments().thenReturn(sh); - actionHandler.reportSearch(mockedRequest, "10"); - } - - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test(expected = NullPointerException.class) - public void reportChartRunTest() throws Exception { - PowerMockito.mockStatic(Globals.class); - PowerMockito.mockStatic(DbUtils.class); - PowerMockito.mockStatic(ReportLoader.class); - PowerMockito.mockStatic(ReportWrapper.class); - PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(ReportDefinition.class); - PowerMockito.mockStatic(ESAPI.class); - PowerMockito.mockStatic(SecurityCodecUtil.class); - PowerMockito.mockStatic(UserUtils.class); - when(UserUtils.getUserId(mockedRequest)).thenReturn(1); - when(AppUtils.isAdminUser(mockedRequest)).thenReturn(true); - when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); - Map roles = new HashMap<>(); - roles.put("role1", "test1"); - roles.put("role2", "test2"); - when(UserUtils.getRoles(mockedRequest)).thenReturn(roles); - when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("chart.data.json"); - ChartWebRuntime cwr = Mockito.mock(ChartWebRuntime.class); - whenNew(ChartWebRuntime.class).withNoArguments().thenReturn(cwr); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("test"); - ReportRuntime rr = PowerMockito.mock(ReportRuntime.class); - when(DbUtils.getConnection()).thenReturn(connection); - when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_REPORT_ID)).thenReturn("1"); - when(rr.getReportID()).thenReturn("test"); - when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_SHOW_BACK_BTN)).thenReturn(true); - when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String"); - String str = "Hivenamedesctypefalsefalseidfalse"; - when(connection.prepareStatement("1")).thenReturn(stmt); - when(stmt.executeQuery()).thenReturn(rs); - when(Globals.isWeblogicServer()).thenReturn(true); - when(rs.getClob(1)).thenReturn(clob); - when(rs.next()).thenReturn(true); - when(clob.getAsciiStream()).thenReturn(in); - when(in.read(Matchers.any())).thenReturn(1); - when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); - when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); - when(AppUtils.getRequestNvlValue(Matchers.any(), Matchers.anyString())).thenReturn("test"); - when(AppUtils.nvl("Y")).thenReturn("Y"); - when(AppUtils.nvl("bottom")).thenReturn("Y"); - when(AppUtils.nvl("test")).thenReturn("test|"); - when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); - when(ReportLoader.isDashboardType("-1")).thenReturn(false); - ReportDefinition rdf = PowerMockito.mock(ReportDefinition.class); - whenNew(ReportDefinition.class) - .withArguments(Matchers.any(ReportWrapper.class), Matchers.any(HttpServletRequest.class)) - .thenReturn(rdf); - PowerMockito.mockStatic(ReportDefinition.class); - when(ReportDefinition.unmarshal(Mockito.anyString(), Mockito.anyString(), Mockito.anyObject())).thenReturn(rdf); - CustomReportType crType = Mockito.mock(CustomReportType.class); - when(ReportWrapper.unmarshalCR(Matchers.anyString())).thenReturn(crType); - when(Globals.getReportWrapperFormat()).thenReturn("[Globals.getTimeFormat()]"); - when(Globals.getTimeFormat()).thenReturn("[reportID]"); - when(Globals.getReportUserAccess()).thenReturn("[reportID]"); - DataSet set = PowerMockito.mock(DataSet.class); - when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(set); - when(set.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn("test"); - whenNew(ReportRuntime.class).withArguments(Matchers.any(CustomReportType.class), Matchers.anyString(), - Matchers.any(HttpServletRequest.class), Matchers.anyString(), Matchers.anyString(), - Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), - Matchers.anyBoolean()).thenReturn(rr); - DataSourceList dsl = Mockito.mock(DataSourceList.class); - List list = new ArrayList<>(); - DataSourceType sr1 = new DataSourceType(); - sr1.setComment("test"); - sr1.setRefDefinition("test"); - sr1.setDataColumnList(new DataColumnList()); - sr1.setTableId("test"); - sr1.setTableName("test"); - list.add(sr1); - when(crType.getDataSourceList()).thenReturn(dsl); - when(dsl.getDataSource()).thenReturn(list); - DashboardReports rps = Mockito.mock(DashboardReports.class); - List reportList = new ArrayList<>(); - Reports rp = new Reports(); - rp.setBgcolor("white"); - rp.setReportId("1"); - reportList.add(rp); - when(rdf.getDashBoardReports()).thenReturn(rps); - when(rps.getReportsList()).thenReturn(reportList); - when(ReportLoader.loadCustomReportXML("1")).thenReturn(str); - actionHandler.reportChartRun(mockedRequest, "10"); - } -} diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ChartJSONHelperTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ChartJSONHelperTest.java index f69c5dae..8901e73b 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ChartJSONHelperTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ChartJSONHelperTest.java @@ -70,6 +70,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.portalsdk.analytics.error.RaptorException; +import org.onap.portalsdk.analytics.model.ReportHandler; import org.onap.portalsdk.analytics.model.ReportLoader; import org.onap.portalsdk.analytics.model.base.ReportWrapper; import org.onap.portalsdk.analytics.model.runtime.ChartJSONHelper; @@ -89,7 +90,7 @@ import org.powermock.modules.junit4.PowerMockRunner; import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(PowerMockRunner.class) -@PrepareForTest({UserUtils.class,AppUtils.class, DbUtils.class, ReportRuntime.class, Globals.class, UserUtils.class,ReportLoader.class}) +@PrepareForTest({UserUtils.class,AppUtils.class, DbUtils.class, ReportRuntime.class, Globals.class, UserUtils.class,ReportLoader.class,ChartJSONHelper.class}) public class ChartJSONHelperTest { @InjectMocks @@ -116,7 +117,7 @@ public class ChartJSONHelperTest { HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - @Test(expected = java.lang.ClassCastException.class) + @Test(expected = java.lang.NullPointerException.class) public void generateJSONTest() throws RaptorException, Exception { EcompRole role = new EcompRole(); @@ -142,6 +143,8 @@ public class ChartJSONHelperTest { rr.setChartType("BarChart3D"); rr.setMultiSeries(true); rr.setDashboardType(true); + rr.setLegendLabelAngle("standard"); + rr.setWholeSQL("SELECT * FROM test"); Mockito.when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); PowerMockito.mockStatic(Globals.class); @@ -165,7 +168,7 @@ public class ChartJSONHelperTest { Mockito.when(rs.next()).thenReturn(true); Mockito.when(clob.getAsciiStream()).thenReturn(in); Mockito.when(in.read(Matchers.any())).thenReturn(1); -// PowerMockito.mockStatic(ReportRuntime.class); + PowerMockito.mockStatic(ReportRuntime.class); Mockito.when(ReportRuntime.unmarshal(str, "1", mockedRequest)).thenReturn(rr); Mockito.when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); Mockito.when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard"); @@ -175,7 +178,10 @@ public class ChartJSONHelperTest { Mockito.when(AppUtils.nvl("test")).thenReturn("test|"); Mockito.when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1"); Mockito.when(ReportLoader.isDashboardType("-1")).thenReturn(false); - assertEquals(chartJSONHelper.generateJSON("1", mockedRequest, false).getClass(), String.class); + ReportHandler reportHandler = Mockito.mock(ReportHandler.class); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportRuntime(Mockito.any(HttpServletRequest.class), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyInt())).thenReturn(rr); + assertEquals(chartJSONHelper.generateJSON("1", mockedRequest, true).getClass(), String.class); } @@ -368,6 +374,7 @@ public class ChartJSONHelperTest { dataColumnType.setColId("1"); dataColumnType.setTableId("1"); dataColumnType.setColType("DATE"); + dataColumnType.setColOnChart("LEGEND"); dataColumnTypeList.add(dataColumnType); DataColumnList dataColumnList = new DataColumnList(); dataColumnList.dataColumn = dataColumnTypeList; diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/PdfReportHandlerTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/PdfReportHandlerTest.java index c94dd41a..76dd83ed 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/PdfReportHandlerTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/PdfReportHandlerTest.java @@ -51,6 +51,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.TreeMap; +import java.util.Vector; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -60,11 +61,12 @@ import org.junit.Before; import org.junit.Ignore; 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.portalsdk.analytics.model.DataCache; +import org.onap.portalsdk.analytics.model.ReportHandler; import org.onap.portalsdk.analytics.model.ReportLoader; import org.onap.portalsdk.analytics.model.base.ReportWrapper; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; @@ -83,6 +85,8 @@ import org.onap.portalsdk.analytics.util.XSSFilter; import org.onap.portalsdk.analytics.view.ColumnHeader; import org.onap.portalsdk.analytics.view.ColumnHeaderRow; import org.onap.portalsdk.analytics.view.DataRow; +import org.onap.portalsdk.analytics.view.DataValue; +import org.onap.portalsdk.analytics.view.HtmlFormatter; import org.onap.portalsdk.analytics.view.ReportColumnHeaderRows; import org.onap.portalsdk.analytics.view.ReportData; import org.onap.portalsdk.analytics.view.ReportDataRows; @@ -99,33 +103,38 @@ import org.powermock.modules.junit4.PowerMockRunner; import com.lowagie.text.Document; import com.lowagie.text.Image; +import com.lowagie.text.Rectangle; @RunWith(PowerMockRunner.class) -@PrepareForTest({ PdfReportHandler.class, PdfReportHandlerTest.class, AppConstants.class, Globals.class, AppUtils.class, ReportWrapper.class, DataCache.class, - DbUtils.class, DataSet.class, Font.class, ReportLoader.class, ReportRuntime.class, Utils.class, ESAPI.class, Codec.class, - SecurityCodecUtil.class, ConnectionUtils.class, XSSFilter.class, ReportDefinition.class, UserUtils.class}) +@PrepareForTest({ PdfReportHandler.class, PdfReportHandlerTest.class, AppConstants.class, Globals.class, AppUtils.class, + ReportWrapper.class, DataCache.class, DbUtils.class, DataSet.class, Font.class, ReportLoader.class, + ReportRuntime.class, Utils.class, ESAPI.class, Codec.class, SecurityCodecUtil.class, ConnectionUtils.class, + XSSFilter.class, ReportDefinition.class, UserUtils.class, Color.class }) public class PdfReportHandlerTest { - @InjectMocks - PdfReportHandler pdfReportHandler; - + PdfReportHandler pdfReportHandler = new PdfReportHandler(); + @Mock + ReportHandler reportHandler; + @Mock + ReportDefinition rdef; + @Before - public void init() throws Exception { + public void init() throws Exception { PowerMockito.mockStatic(Globals.class); PowerMockito.mockStatic(AppUtils.class); - PowerMockito.mockStatic(DbUtils.class); + PowerMockito.mockStatic(DbUtils.class); MockitoAnnotations.initMocks(this); } - + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); - - @Ignore + + @Ignore @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void createPdfFileContentTest() throws Exception { - Document doc = mock(Document.class); + Document doc = mock(Document.class); PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); PowerMockito.when(doc.newPage()).thenReturn(true); when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); @@ -160,7 +169,7 @@ public class PdfReportHandlerTest { when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); } - + @Ignore @SuppressWarnings({ "rawtypes", "unchecked" }) @Test @@ -173,8 +182,8 @@ public class PdfReportHandlerTest { ReportRuntime rr = mock(ReportRuntime.class); ReportData rd = mock(ReportData.class); - ReportDataRows rdr = new ReportDataRows(); - CustomReportType crType = mock(CustomReportType.class); + ReportDataRows rdr = new ReportDataRows(); + CustomReportType crType = mock(CustomReportType.class); Connection conn = mock(Connection.class); Statement st = mock(Statement.class); ResultSet resSet = mock(ResultSet.class); @@ -222,12 +231,12 @@ public class PdfReportHandlerTest { list.add(dataSourceType); dataSourceList.dataSource = list; when(crType.getDataSourceList()).thenReturn(dataSourceList); - + when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(conn); when(conn.createStatement()).thenReturn(st); - when( st.executeQuery(Matchers.anyString())).thenReturn(resSet); + when(st.executeQuery(Matchers.anyString())).thenReturn(resSet); when(resSet.getMetaData()).thenReturn(resSetMD); - + when(mockedRequest.getParameter("parent")).thenReturn("parent_test"); when(mockedRequest.getSession().getAttribute("parent_test_rr")).thenReturn(rr); when(mockedRequest.getSession().getAttribute("parent_test_rd")).thenReturn(rd); @@ -242,7 +251,7 @@ public class PdfReportHandlerTest { columnHeaderRow.add(columnHeader); reportColumnHeaderRows.add(columnHeaderRow); rd.reportColumnHeaderRows = reportColumnHeaderRows; - + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); RowHeaderCol rowHeaderCol = new RowHeaderCol(); RowHeader rowHeader = new RowHeader(); @@ -258,14 +267,13 @@ public class PdfReportHandlerTest { when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.edit"); when(mockedRequest.getParameter(AppConstants.RI_WIZARD_ACTION)).thenReturn("test"); - when(mockedRequest.getSession().getAttribute( - AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); Mockito.when(Globals.getNewScheduleData()).thenReturn("test"); DataSet datset = PowerMockito.mock(DataSet.class); when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); - - Document doc = mock(Document.class); + + Document doc = mock(Document.class); PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); PowerMockito.when(doc.newPage()).thenReturn(true); when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); @@ -297,7 +305,7 @@ public class PdfReportHandlerTest { when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); } - + @Ignore @SuppressWarnings({ "rawtypes", "unchecked" }) @Test @@ -313,8 +321,8 @@ public class PdfReportHandlerTest { when(htmlStr.stripHtml(Matchers.anyString())).thenReturn("test"); ReportRuntime rr = mock(ReportRuntime.class); ReportData rd = mock(ReportData.class); - ReportDataRows rdr = new ReportDataRows(); - CustomReportType crType = mock(CustomReportType.class); + ReportDataRows rdr = new ReportDataRows(); + CustomReportType crType = mock(CustomReportType.class); Connection conn = mock(Connection.class); Statement st = mock(Statement.class); ResultSet resSet = mock(ResultSet.class); @@ -362,12 +370,12 @@ public class PdfReportHandlerTest { list.add(dataSourceType); dataSourceList.dataSource = list; when(crType.getDataSourceList()).thenReturn(dataSourceList); - + when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(conn); when(conn.createStatement()).thenReturn(st); - when( st.executeQuery(Matchers.anyString())).thenReturn(resSet); + when(st.executeQuery(Matchers.anyString())).thenReturn(resSet); when(resSet.getMetaData()).thenReturn(resSetMD); - + when(mockedRequest.getParameter("parent")).thenReturn("parent_test"); when(mockedRequest.getSession().getAttribute("parent_test_rr")).thenReturn(rr); when(mockedRequest.getSession().getAttribute("parent_test_rd")).thenReturn(rd); @@ -382,20 +390,19 @@ public class PdfReportHandlerTest { columnHeaderRow.add(columnHeader); reportColumnHeaderRows.add(columnHeaderRow); rd.reportColumnHeaderRows = reportColumnHeaderRows; - + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); rd.reportRowHeaderCols = reportRowHeaderCols; when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("report.edit"); when(mockedRequest.getParameter(AppConstants.RI_WIZARD_ACTION)).thenReturn("test"); - when(mockedRequest.getSession().getAttribute( - AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr); Mockito.when(Globals.getNewScheduleData()).thenReturn("test"); DataSet datset = PowerMockito.mock(DataSet.class); when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset); when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null); - - Document doc = mock(Document.class); + + Document doc = mock(Document.class); PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); PowerMockito.when(doc.newPage()).thenReturn(true); when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); @@ -427,13 +434,13 @@ public class PdfReportHandlerTest { when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 2); } - + @SuppressWarnings({ "rawtypes", "unchecked", "static-access" }) @Test public void createPdfFileContent2Test() throws Exception { PowerMockito.mockStatic(Image.class); - Document doc = mock(Document.class); - CustomReportType crType = mock(CustomReportType.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); DataSet ds = mock(DataSet.class); PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); @@ -472,13 +479,13 @@ public class PdfReportHandlerTest { when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); List chartGroups = new ArrayList<>(); when(rr.getAllChartGroups()).thenReturn(chartGroups); - ReportParamValues reportValues= new ReportParamValues(); + ReportParamValues reportValues = new ReportParamValues(); when(rr.getReportParamValues()).thenReturn(reportValues); when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); HashMap requestParams = new HashMap<>(); requestParams.put("", "test"); - + DataSourceList dataSourceList = new DataSourceList(); List list = new ArrayList<>(); @@ -515,7 +522,7 @@ public class PdfReportHandlerTest { list.add(dataSourceType); dataSourceList.dataSource = list; when(crType.getDataSourceList()).thenReturn(dataSourceList); - + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); ds.set(0, "test"); when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); @@ -531,5 +538,2078 @@ public class PdfReportHandlerTest { when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); } - + + @Test + public void createPdfFileContent_case5Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + rd.reportDataRows = rdr; + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("test"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent_case6Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + rd.reportDataRows = rdr; + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("test"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(2); + + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + Mockito.when(rdef.getAllColumns()).thenReturn(dataColumnTypeList); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent_case7Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + rd.reportDataRows = rdr; + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("test"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(2); + + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + Mockito.when(rdef.getAllColumns()).thenReturn(dataColumnTypeList); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + when(mockedRequest.getSession().getAttribute("TITLE_0")).thenReturn("title"); + when(mockedRequest.getSession().getAttribute("drilldown_index")).thenReturn("drilldown_index"); + when(mockedRequest.getSession().getAttribute("SUBTITLE_0")).thenReturn("subtitle"); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void createPdfFileContent_case8Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + rd.reportDataRows = rdr; + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(2); + + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + List dataColumnTypeList1 = new ArrayList<>(); + Mockito.when(rdef.getAllColumns()).thenReturn(dataColumnTypeList); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + when(mockedRequest.getSession().getAttribute("TITLE_0")).thenReturn("title"); + when(mockedRequest.getSession().getAttribute("drilldown_index")).thenReturn("drilldown_index"); + when(mockedRequest.getSession().getAttribute("SUBTITLE_0")).thenReturn("subtitle"); + Mockito.when(mockedRequest.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE)).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(conn); + Mockito.when(conn.createStatement()).thenReturn(st); + Mockito.when(st.executeQuery(Matchers.anyString())).thenReturn(resSet); + Mockito.when(resSet.getMetaData()).thenReturn(resSetMD); + Mockito.when(resSetMD.getColumnCount()).thenReturn(2); + Mockito.when(resSet.next()).thenReturn(true); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test(expected = org.onap.portalsdk.analytics.error.RaptorException.class) + public void createPdfFileContent_case9Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataRow dataRow2 = new DataRow(); + + ArrayList dataValueList = new ArrayList<>(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setVisible(true); + DataValue value1 = new DataValue(); + DataValue value2 = new DataValue(); + + dataValueList.add(value); + dataValueList.add(value1); + dataValueList.add(value2); + dataRow.addDataValue(value); + dataRow.addDataValue(value1); + dataRow.addDataValue(value2); + dataRow.setDataValueList(dataValueList); + + dataRow2.addDataValue(value); + dataRow2.addDataValue(value1); + dataRow2.addDataValue(value2); + dataRow2.setDataValueList(dataValueList); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + dataRow1.addDataValue(value2); + dataRow1.setDataValueList(dataValueList); + + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow2); + reportDataRows.add(dataRow2); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(2); + + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + List dataColumnTypeList1 = new ArrayList<>(); + Mockito.when(rdef.getAllColumns()).thenReturn(dataColumnTypeList); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + when(mockedRequest.getSession().getAttribute("TITLE_0")).thenReturn("title"); + when(mockedRequest.getSession().getAttribute("drilldown_index")).thenReturn("drilldown_index"); + when(mockedRequest.getSession().getAttribute("SUBTITLE_0")).thenReturn("subtitle"); + Mockito.when(mockedRequest.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE)).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(conn); + Mockito.when(conn.createStatement()).thenReturn(st); + Mockito.when(st.executeQuery(Matchers.anyString())).thenReturn(resSet); + Mockito.when(resSet.getMetaData()).thenReturn(resSetMD); + Mockito.when(resSetMD.getColumnCount()).thenReturn(2); + Mockito.when(resSet.next()).thenReturn(true); + Mockito.when(resSetMD.getColumnLabel(Matchers.anyInt())).thenReturn("test"); + Mockito.when(resSet.getString(Matchers.anyInt())).thenReturn("test"); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent10Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn("TimeSeriesChart"); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent11Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn("BarChart3D"); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent12Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn("BarChart3D"); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test|123"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("chart_total"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test|123"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test(expected = java.lang.NullPointerException.class) + public void createPdfFileContent13Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + Rectangle rectangle = Mockito.mock(Rectangle.class); + Mockito.when(doc.getPageSize()).thenReturn(rectangle); + Mockito.when(rectangle.rotate()).thenReturn(rectangle); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(""); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test|123"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("chart_total"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test|123"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataRow dataRow2 = new DataRow(); + + ArrayList dataValueList = new ArrayList<>(); + DataValue value = new DataValue(); + value.setColId("test"); + value.setVisible(true); + value.setBold(true); + HtmlFormatter cfmt = new HtmlFormatter(); + value.setCellFormatter(cfmt); + DataValue value1 = new DataValue(); + HtmlFormatter cfmt1 = new HtmlFormatter(); + cfmt1.setBold(true); + cfmt1.setItalic(true); + cfmt1.setUnderline(true); + cfmt1.setFontColor("red"); + cfmt1.setFontSize("1.1"); + value1.setRowFormatter(cfmt1); + + DataValue value2 = new DataValue(); + value2.setColId("test"); + value2.setVisible(true); + value2.setBold(true); + dataValueList.add(value); + dataValueList.add(value1); + dataValueList.add(value2); + dataRow.addDataValue(value); + dataRow.addDataValue(value1); + dataRow.addDataValue(value2); + dataRow.setDataValueList(dataValueList); + + dataRow2.addDataValue(value); + dataRow2.addDataValue(value1); + dataRow2.addDataValue(value2); + dataRow2.setDataValueList(dataValueList); + + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + dataRow1.addDataValue(value2); + dataRow1.setDataValueList(dataValueList); + + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow2); + reportDataRows.add(dataRow2); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + + RowHeader rowHeader = new RowHeader(); + RowHeader rowHeader1 = new RowHeader(); + RowHeader rowHeader2 = new RowHeader(); + + rowHeader.setBold(false); + rowHeader1.setBold(true); + rowHeaderCol.add(rowHeader); + rowHeaderCol.add(rowHeader1); + rowHeaderCol.add(rowHeader2); + + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + + rowHeaderCol1.add(rowHeader); + rowHeaderCol1.add(rowHeader1); + rowHeaderCol1.add(rowHeader2); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(reportHandler.loadReportRuntime(Matchers.any(HttpServletRequest.class), Matchers.anyString(), + Matchers.anyBoolean(), Matchers.anyInt())).thenReturn(rr); + Mockito.when(rr.getPDFOrientation()).thenReturn("orientation"); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(1); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + Mockito.when(Globals.getDataFontSizeOffset()).thenReturn((float) 1.0); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent14Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + Rectangle rectangle = Mockito.mock(Rectangle.class); + Mockito.when(doc.getPageSize()).thenReturn(rectangle); + Mockito.when(rectangle.rotate()).thenReturn(rectangle); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(""); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test|123"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("chart_total"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test|123"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + + ReportDataRows reportDataRows1 = new ReportDataRows(); + + rd.reportDataRows = reportDataRows1; + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataTotalRow = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + + RowHeader rowHeader = new RowHeader(); + RowHeader rowHeader1 = new RowHeader(); + RowHeader rowHeader2 = new RowHeader(); + + rowHeader.setBold(false); + rowHeader1.setBold(true); + rowHeaderCol.add(rowHeader); + rowHeaderCol.add(rowHeader1); + rowHeaderCol.add(rowHeader2); + + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + + rowHeaderCol1.add(rowHeader); + rowHeaderCol1.add(rowHeader1); + rowHeaderCol1.add(rowHeader2); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(reportHandler.loadReportRuntime(Matchers.any(HttpServletRequest.class), Matchers.anyString(), + Matchers.anyBoolean(), Matchers.anyInt())).thenReturn(rr); + Mockito.when(rr.getPDFOrientation()).thenReturn("orientation"); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(1); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + Mockito.when(Globals.getDataFontSizeOffset()).thenReturn((float) 1.0); + when(mockedRequest.getSession().getAttribute("FOOTER_0")).thenReturn("footer"); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent15Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + Rectangle rectangle = Mockito.mock(Rectangle.class); + Mockito.when(doc.getPageSize()).thenReturn(rectangle); + Mockito.when(rectangle.rotate()).thenReturn(rectangle); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(""); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test|123"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("chart_total"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test|123"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + Mockito.when(rr.getReportType()).thenReturn("Cross-Tab"); + + ReportDataRows reportDataRows1 = new ReportDataRows(); + + rd.reportDataRows = reportDataRows1; + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataTotalRow = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + + RowHeader rowHeader = new RowHeader(); + RowHeader rowHeader1 = new RowHeader(); + RowHeader rowHeader2 = new RowHeader(); + + rowHeader.setBold(false); + rowHeader1.setBold(true); + rowHeaderCol.add(rowHeader); + rowHeaderCol.add(rowHeader1); + rowHeaderCol.add(rowHeader2); + + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + + rowHeaderCol1.add(rowHeader); + rowHeaderCol1.add(rowHeader1); + rowHeaderCol1.add(rowHeader2); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(reportHandler.loadReportRuntime(Matchers.any(HttpServletRequest.class), Matchers.anyString(), + Matchers.anyBoolean(), Matchers.anyInt())).thenReturn(rr); + Mockito.when(rr.getPDFOrientation()).thenReturn("orientation"); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(1); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + Mockito.when(Globals.getDataFontSizeOffset()).thenReturn((float) 1.0); + when(mockedRequest.getSession().getAttribute("FOOTER_0")).thenReturn("footer"); + + List getReportDataList = new ArrayList<>(); + getReportDataList.add(dataRow); + getReportDataList.add(dataRow1); + Mockito.when(rd.getReportDataList()).thenReturn(getReportDataList); + + Vector rowValues = new Vector(); + rowValues.add(value1); + rowValues.add(value1); + + ArrayList dataValueList = new ArrayList<>(); + value.setColId("test"); + value.setVisible(true); + DataValue value2 = new DataValue(); + HtmlFormatter cfmt = new HtmlFormatter(); + value.setCellFormatter(cfmt); + + dataValueList.add(value); + dataValueList.add(value1); + dataValueList.add(value2); + dataRow.addDataValue(value); + dataRow.addDataValue(value1); + dataRow.addDataValue(value2); + dataRow.setDataValueList(dataValueList); + dataRow1.setDataValueList(dataValueList); + + dataRow.setRowValues(rowValues); + dataRow1.setRowValues(rowValues); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void createPdfFileContent_case15Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + ReportDataRows rdr = new ReportDataRows(); + Connection conn = mock(Connection.class); + Statement st = mock(Statement.class); + ResultSet resSet = mock(ResultSet.class); + ResultSetMetaData resSetMD = mock(ResultSetMetaData.class); + DataRow dr = new DataRow(); + rdr.add(dr); + rd.reportDataRows = rdr; + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieOrder")).thenReturn("row"); + when(AppUtils.getRequestNvlValue(mockedRequest, "multiplePieLabelDisplay")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(AppConstants.GT_PIE_MULTIPLE); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).thenReturn("test123"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_REPORT_DATA)).thenReturn(rd); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(2); + + List dataColumnTypeList = mockDataList(); + List dataColumnTypeList1 = new ArrayList<>(); + Mockito.when(rdef.getAllColumns()).thenReturn(dataColumnTypeList); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + when(mockedRequest.getSession().getAttribute("TITLE_0")).thenReturn("title"); + when(mockedRequest.getSession().getAttribute("drilldown_index")).thenReturn("drilldown_index"); + when(mockedRequest.getSession().getAttribute("SUBTITLE_0")).thenReturn("subtitle"); + Mockito.when(mockedRequest.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE)).thenReturn("test"); + PowerMockito.mockStatic(ConnectionUtils.class); + + Mockito.when(ConnectionUtils.getConnection(Matchers.anyString())).thenReturn(conn); + Mockito.when(conn.createStatement()).thenReturn(st); + Mockito.when(st.executeQuery(Matchers.anyString())).thenReturn(resSet); + Mockito.when(resSet.getMetaData()).thenReturn(resSetMD); + Mockito.when(resSetMD.getColumnCount()).thenReturn(2); + Mockito.when(resSet.next()).thenReturn(false); + + rd.reportDataTotalRow = reportDataRows; + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 3); + } + + @Test + public void currentTimeTest() { + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getTimeZone()).thenReturn("EST"); + pdfReportHandler.currentTime("11/11/2011 11:11:11"); + } + + public List mockDataList() { + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + return dataColumnTypeList; + } + + + + @Test(expected = java.lang.NullPointerException.class) + public void createPdfFileContent17Test() throws Exception { + PowerMockito.mockStatic(Image.class); + Document doc = mock(Document.class); + CustomReportType crType = mock(CustomReportType.class); + DataSet ds = mock(DataSet.class); + PowerMockito.whenNew(Document.class).withNoArguments().thenReturn(doc); + PowerMockito.when(doc.newPage()).thenReturn(true); + Rectangle rectangle = Mockito.mock(Rectangle.class); + Mockito.when(doc.getPageSize()).thenReturn(rectangle); + Mockito.when(rectangle.rotate()).thenReturn(rectangle); + when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + ReportRuntime rr = mock(ReportRuntime.class); + ReportData rd = mock(ReportData.class); + when(Globals.isCoverPageNeeded()).thenReturn(true); + when(Globals.getSessionInfoForTheCoverPage()).thenReturn("test,test1"); + when(AppUtils.getRequestNvlValue(mockedRequest, "test1")).thenReturn("test1"); + when(rr.isPDFCoverPage()).thenReturn(true); + when(rr.getReportID()).thenReturn("test"); + when(rr.getPDFOrientation()).thenReturn("portait"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartOrientation")).thenReturn("vertical"); + when(AppUtils.getRequestNvlValue(mockedRequest, "secondaryChartRenderer")).thenReturn("test"); + when(AppUtils.getRequestNvlValue(mockedRequest, "chartDisplay")).thenReturn("3D"); + when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr); + when(mockedRequest.getSession().getAttribute("dashboard_report_id")).thenReturn("test123"); + ServletContext servConxt = mock(ServletContext.class); + when(mockedRequest.getSession().getServletContext()).thenReturn(servConxt); + when(servConxt.getRealPath(File.separator)).thenReturn("testpath"); + when(rr.getChartType()).thenReturn(""); + when(rr.getDisplayChart()).thenReturn(true); + ArrayList paramNamePDFValues = new ArrayList(); + paramNamePDFValues.add("test1"); + paramNamePDFValues.add("test2"); + when(rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2)).thenReturn(paramNamePDFValues); + when(rr.getFormFieldComments(mockedRequest)).thenReturn("test"); + when(rr.getLegendPosition()).thenReturn("test"); + when(rr.hideChartToolTips()).thenReturn(true); + when(AppUtils.getRequestNvlValue(mockedRequest, "hideLegend")).thenReturn("Y"); + when(rr.getLegendLabelAngle()).thenReturn("test"); + when(rr.getMaxLabelsInDomainAxis()).thenReturn("test"); + when(rr.getRangeAxisLowerLimit()).thenReturn("10"); + when(rr.getRangeAxisUpperLimit()).thenReturn("10"); + when(AppUtils.getRequestNvlValue(mockedRequest, "totalOnChart")).thenReturn("Y"); + List chartGroups = new ArrayList<>(); + chartGroups.add("test|123"); + when(rr.getAllChartGroups()).thenReturn(chartGroups); + ReportParamValues reportValues = new ReportParamValues(); + when(rr.getReportParamValues()).thenReturn(reportValues); + when(rr.getFormFieldFilled(rr.getChartLeftAxisLabel())).thenReturn("test"); + when(rr.getFormFieldFilled(rr.getChartRightAxisLabel())).thenReturn("test"); + HashMap requestParams = new HashMap<>(); + requestParams.put("", "test"); + + DataSourceList dataSourceList = new DataSourceList(); + + List list = new ArrayList<>(); + DataSourceType dataSourceType = new DataSourceType(); + dataSourceType.setTableName("test"); + dataSourceType.setRefTableId("1"); + dataSourceType.setTableId("1"); + List dataColumnTypeList = new ArrayList<>(); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("chart_total"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("chart_total"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setDependsOnFormField("test"); + dataColumnType.setColType("DATE"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setPdfDisplayWidthInPxls("0.0"); + dataColumnType.setVisible(true); + dataColumnType.setCalculated(true); + dataColumnType.setColType("chart_total"); + dataColumnTypeList.add(dataColumnType); + DataColumnType dataColumnType1 = new DataColumnType(); + dataColumnType1.setCrossTabValue("COLUMN"); + dataColumnType1.setColId("1"); + dataColumnType1.setVisible(true); + dataColumnType1.setPdfDisplayWidthInPxls("1.0"); + dataColumnTypeList.add(dataColumnType1); + + DataColumnList dataColumnList = new DataColumnList(); + dataColumnList.dataColumn = dataColumnTypeList; + dataSourceType.setDataColumnList(dataColumnList); + list.add(dataSourceType); + dataSourceList.dataSource = list; + when(crType.getDataSourceList()).thenReturn(dataSourceList); + + when(Globals.getRequestParamtersMap(mockedRequest, false)).thenReturn(requestParams); + ds.set(0, "test"); + when(mockedRequest.getSession().getAttribute(AppConstants.RI_CHART_DATA)).thenReturn(ds); + when(rr.hasSeriesColumn()).thenReturn(true); + TreeMap values = new TreeMap<>(); + values.put("test", rr); + TreeMap values2 = new TreeMap<>(); + values2.put("test3", rd); + TreeMap values3 = new TreeMap<>(); + values3.put("test4", "c"); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP)).thenReturn(values); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP)).thenReturn(values2); + when(mockedRequest.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP)).thenReturn(values3); + + Mockito.when(rr.getAllColumns()).thenReturn(dataColumnTypeList); + ArrayList chartValueColAxis = new ArrayList(); + chartValueColAxis.add("test|123"); + Mockito.when(rr.getChartValueColumnAxisList(Matchers.anyInt(), Matchers.any(HashMap.class))) + .thenReturn(chartValueColAxis); + Mockito.when(rr.getReportType()).thenReturn("Linear"); + + + + ReportDataRows reportDataRows = new ReportDataRows(); + DataRow dataRow1 = new DataRow(); + DataRow dataRow = new DataRow(); + + DataValue value = new DataValue(); + DataValue value1 = new DataValue(); + dataRow1.addDataValue(value); + dataRow1.addDataValue(value1); + reportDataRows.addDataRow(dataRow1); + reportDataRows.add(dataRow1); + reportDataRows.addDataRow(dataRow); + reportDataRows.add(dataRow); + rd.reportDataTotalRow = reportDataRows; + rd.reportDataRows = reportDataRows; + + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + + RowHeader rowHeader = new RowHeader(); + RowHeader rowHeader1 = new RowHeader(); + RowHeader rowHeader2 = new RowHeader(); + + rowHeader.setBold(false); + rowHeader1.setBold(true); + rowHeaderCol.add(rowHeader); + rowHeaderCol.add(rowHeader1); + rowHeaderCol.add(rowHeader2); + + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + + rowHeaderCol1.add(rowHeader); + rowHeaderCol1.add(rowHeader1); + rowHeaderCol1.add(rowHeader2); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + + PowerMockito.whenNew(ReportHandler.class).withNoArguments().thenReturn(reportHandler); + Mockito.when(reportHandler.loadReportDefinition(Matchers.any(HttpServletRequest.class), Matchers.anyString())) + .thenReturn(rdef); + Mockito.when(reportHandler.loadReportRuntime(Matchers.any(HttpServletRequest.class), Matchers.anyString(), + Matchers.anyBoolean(), Matchers.anyInt())).thenReturn(rr); + Mockito.when(rr.getPDFOrientation()).thenReturn("orientation"); + Mockito.when(rdef.getVisibleColumnCount()).thenReturn(1); + Mockito.when(Globals.getDataTableHeaderFontColor()).thenReturn("test"); + PowerMockito.mockStatic(Color.class); + Color color = new Color(1); + Mockito.when(Color.decode(Matchers.anyString())).thenReturn(color); + Mockito.when(Globals.getDataFontSizeOffset()).thenReturn((float) 1.0); + when(mockedRequest.getSession().getAttribute("FOOTER_0")).thenReturn("footer"); + List newlist = new ArrayList<>(); + newlist.add(1); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)) + .thenReturn(newlist); + Mockito.when(rd.getTotalColumnCount()).thenReturn(2); + pdfReportHandler.createPdfFileContent(mockedRequest, mockedResponse, 2); + } + + } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportRuntimeTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportRuntimeTest.java index 668304fd..0bdaeb0f 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportRuntimeTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportRuntimeTest.java @@ -37,9 +37,15 @@ */ package org.onap.portalsdk.analytics.xmlobj; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.sql.Connection; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.util.ArrayList; +import java.util.Enumeration; import java.util.List; import java.util.Vector; @@ -57,7 +63,9 @@ import org.onap.portalsdk.analytics.model.base.ReportWrapper; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; import org.onap.portalsdk.analytics.model.runtime.FormField; import org.onap.portalsdk.analytics.model.runtime.ReportFormFields; +import org.onap.portalsdk.analytics.model.runtime.ReportJSONRuntime; import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; +import org.onap.portalsdk.analytics.model.runtime.VisualManager; import org.onap.portalsdk.analytics.system.AppUtils; import org.onap.portalsdk.analytics.system.ConnectionUtils; import org.onap.portalsdk.analytics.system.DbUtils; @@ -69,10 +77,16 @@ import org.onap.portalsdk.analytics.util.Utils; import org.onap.portalsdk.analytics.util.XSSFilter; import org.onap.portalsdk.analytics.view.ColumnHeader; import org.onap.portalsdk.analytics.view.ColumnHeaderRow; +import org.onap.portalsdk.analytics.view.ColumnVisual; +import org.onap.portalsdk.analytics.view.DataRow; +import org.onap.portalsdk.analytics.view.DataValue; +import org.onap.portalsdk.analytics.view.HtmlFormatter; import org.onap.portalsdk.analytics.view.ReportColumnHeaderRows; import org.onap.portalsdk.analytics.view.ReportData; +import org.onap.portalsdk.analytics.view.ReportDataRows; import org.onap.portalsdk.analytics.view.ReportRowHeaderCols; import org.onap.portalsdk.analytics.view.RowHeaderCol; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SecurityCodecUtil; import org.onap.portalsdk.core.web.support.UserUtils; import org.owasp.esapi.ESAPI; @@ -123,10 +137,13 @@ public class ReportRuntimeTest { dataColumnType.setColId("1"); dataColumnType.setTableId("1"); dataColumnType.setColType("DATE"); - dataColumnType.setDependsOnFormField("tes[t"); + dataColumnType.setDependsOnFormField("[test]"); dataColumnType.setDrillDownParams("drilldown[#]"); dataColumnType.setCrossTabValue("VALUE"); - dataColumnType.setDrillDownURL("url"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + dataColumnType.setOrderBySeq(10); + dataColumnType.setVisible(true); dataColumnTypeList.add(dataColumnType); DataColumnList dataColumnList = new DataColumnList(); dataColumnList.dataColumn = dataColumnTypeList; @@ -176,8 +193,46 @@ public class ReportRuntimeTest { rr.setLegendLabelAngle("test"); rr.setMultiSeries(false); rr.setChartType("test"); + rr.setXmlFileName("test"); + rr.setXmlFileURL("test"); + rr.setFlatFileName("test"); + rr.setExcelPageFileName("test"); + rr.setTotalSql("test"); + rr.setDisplayMode(10); + rr.setDateOption(10); return rr; } + + @Test + public void testReportRuntimeProperties() throws Exception { + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(ReportLoader.isDashboardType(Mockito.any(String.class))).thenReturn(true); + ReportRuntime rr = mockReportRunTime1(); + assertEquals("test", rr.getXmlFileURL()); + assertEquals("test", rr.getXmlFileName()); + assertEquals("test", rr.getFlatFileName()); + assertEquals("test", rr.getExcelPageFileName()); + assertTrue(rr.getDisplayForm()); + assertTrue(rr.getDisplayContent()); + assertEquals(-1, rr.getCachedPageNo()); + assertEquals(null, rr.getCachedSQL()); + assertTrue(rr.isDashboardType()); + assertEquals("test", rr.getParamValue("test")); + assertEquals("test", rr.getParamDisplayValue("test")); + rr.getParamKeys(); + rr.getParamKeysForPDFExcel(); + assertEquals("test", rr.getParamValueForPDFExcel("test")); + assertEquals(FormField.class, rr.getFormField("test").getClass()); + assertEquals("test", rr.getTotalSql()); + assertEquals(VisualManager.class, rr.getVisualManager().getClass()); + assertEquals(" null) x ", rr.getReportSQLWithRowNum("test", true)); + assertEquals(10, rr.getDisplayMode()); + assertEquals(10, rr.getDateOption()); + assertFalse(rr.isDisplayColTotals()); + assertFalse(rr.isDisplayRowTotals()); + rr.showColVisual("test"); + rr.sortColVisual("test"); + } @Test public void getParamNameValuePairsTest() throws Exception { @@ -188,13 +243,53 @@ public class ReportRuntimeTest { @Test public void getParamNameValuePairsforPDFExcelTest() throws Exception { ReportRuntime rr = mockReportRunTime1(); - rr.setReportFormFields(null); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ESAPI.class); List predefinedValues = new ArrayList<>(); ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + + + Mockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn("test,test"); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute("test")).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("test"); + rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2); + + } + + @Test + public void getParamNameValuePairsforPDFExcelTest_WhenIsScheduleFlagTrue() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ESAPI.class); + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", "rangeEndDateSQL", "multiSelectListSize"); @@ -208,17 +303,23 @@ public class ReportRuntimeTest { rr.setReportFormFields(null); rr.setReportFormFields(reportFormFields); - PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn("test,test"); HttpSession session = mockedRequest.getSession(); Mockito.when(session.getAttribute("test")).thenReturn("test"); Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,test"); + Mockito.when(AppUtils.getRequestValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("test"); rr.getParamNameValuePairsforPDFExcel(mockedRequest, 2); } - @Test(expected = java.lang.ArrayIndexOutOfBoundsException.class) + @Test public void getParamNameValuePairsforPDFExcel1Test() throws Exception { ReportRuntime rr = mockReportRunTime1(); rr.setReportFormFields(null); @@ -226,7 +327,7 @@ public class ReportRuntimeTest { ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", true, - "defaultValue", "helpText", predefinedValues, true, "dependsOn", null, null, "rangeStartDateSQL", + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", "rangeEndDateSQL", "multiSelectListSize"); FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", @@ -241,15 +342,65 @@ public class ReportRuntimeTest { reportFormFields.add(formField2); reportFormFields.add(formField3); - rr.setReportFormFields(null); rr.setReportFormFields(reportFormFields); + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn(";test,;test"); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute("test")).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + rr.getParamNameValuePairsforPDFExcel(mockedRequest, 1); + } + + @Test + public void getParamNameValuePairsforPDFExcel1Test_WhenIsScheduleFlagTrue() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + rr.setReportFormFields(null); + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", true, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField3 = PowerMockito.mock(FormField.class); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + reportFormFields.add(formField3); + + rr.setReportFormFields(reportFormFields); PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ESAPI.class); Mockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); - Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn("test,test"); + Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn(";test,;test"); + Mockito.when(Globals.getDisplayScheduleSessionParamInPDFEXCEL()).thenReturn(";test,;test"); HttpSession session = mockedRequest.getSession(); Mockito.when(session.getAttribute("test")).thenReturn("test"); Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getRequestValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("DATE"); + rr.getParamNameValuePairsforPDFExcel(mockedRequest, 1); + + } + + @Test + public void getParamNameValuePairsforPDFExcelTest_WhenValueExistInSession() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + List paramList = new ArrayList<>(); + paramList.add("test"); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO)).thenReturn(paramList); rr.getParamNameValuePairsforPDFExcel(mockedRequest, 1); } @@ -257,7 +408,40 @@ public class ReportRuntimeTest { @Test public void getFormFieldCommentsTest() throws Exception { ReportRuntime rr = mockReportRunTime1(); - rr.getCustomReport().getFormFieldList().setComment(""); + rr.getCustomReport().getFormFieldList().setComment("test"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ESAPI.class); + List predefinedValues = new ArrayList<>(); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField1 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + FormField formField2 = new FormField("test", "fieldDisplayName", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", predefinedValues, false, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + + reportFormFields.add(formField); + reportFormFields.add(formField1); + reportFormFields.add(formField2); + rr.setReportFormFields(null); + rr.setReportFormFields(reportFormFields); + + + Mockito.when(Globals.customizeFormFieldInfo()).thenReturn(true); + Mockito.when(Globals.getDisplaySessionParamInPDFEXCEL()).thenReturn("test,test"); + HttpSession session = mockedRequest.getSession(); + Mockito.when(session.getAttribute("test")).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,test"); + Mockito.when(AppUtils.getRequestValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Mockito.when(encoder.canonicalize(Mockito.anyString())).thenReturn("DATE"); rr.getFormFieldComments(mockedRequest); } @@ -265,8 +449,7 @@ public class ReportRuntimeTest { public void loadChartDataTest() throws Exception { ReportRuntime rr = mockReportRunTime1(); rr.getCustomReport().getFormFieldList().setComment(""); - DataSet ds = PowerMockito.mock(DataSet.class); - rr.setChartDataCache(ds); + rr.setChartDataCache(null); rr.loadChartData("test", mockedRequest); } @@ -304,6 +487,40 @@ public class ReportRuntimeTest { rr.getCustomReport().getFormFieldList().setComment(""); rr.getCustomReport().setReportType("Linear"); rr.setWholeSQL("testFROMORDERBY"); + rr.getFormFieldList().getFormField().get(0).setGroupFormField(true); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test]"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + dataColumnType.setVisible(true); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); + dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test]"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("COLUMN"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); DataSet ds = PowerMockito.mock(DataSet.class); rr.setChartDataCache(ds); PowerMockito.mockStatic(AppUtils.class); @@ -312,13 +529,156 @@ public class ReportRuntimeTest { Mockito.when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("actionsession"); Mockito.when(ConnectionUtils.getDataSet(Matchers.anyString(), Matchers.anyString())).thenReturn(ds); Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getColumnCount()).thenReturn(1); + Mockito.when(ds.getColumnName(Mockito.anyInt())).thenReturn("1"); Mockito.when(Globals.getGenerateSubsetSql()).thenReturn("subsetSql"); Mockito.when(Globals.getReportSqlOnlyFirstPart()).thenReturn("subsetSql"); Mockito.when(Globals.getReportSqlOnlySecondPartA()).thenReturn("secondpartA"); Mockito.when(Globals.getReportSqlOnlySecondPartB()).thenReturn("secondpartB"); Mockito.when(AppUtils.isNotEmpty(Matchers.anyString())).thenReturn(false); Mockito.when(Globals.getDBType()).thenReturn("db"); - rr.loadReportData(1, "userId", 1, mockedRequest, false); + + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + Mockito.when(Globals.getLoadCrosstabReportData()).thenReturn("test FROM ORDER BY"); + ReportData rd = PowerMockito.mock(ReportData.class); + PowerMockito.whenNew(ReportData.class).withArguments(Mockito.anyInt(), Mockito.anyBoolean()).thenReturn(rd); + ReportDataRows reportDataRows = new ReportDataRows(); + rd.reportDataRows= reportDataRows; + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(), Mockito.anyString())).thenReturn(ds); + ReportRuntime rr1 = PowerMockito.mock(ReportRuntime.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr1); + Mockito.when(rr1.getReportID()).thenReturn("lDownUrl"); + Mockito.when(rr1.getReportFormFields()).thenReturn(rr.getReportFormFields()); + rr.setDisplayColTotals(true); + rr.setDisplayRowTotals(true); + Mockito.when(Globals.getCacheCurPageData()).thenReturn(true); + Mockito.when(mockedRequest.getParameter(Mockito.anyString())).thenReturn("test"); + rr.loadReportData(1, "userId", 1, mockedRequest, true); + } + + @Test(expected=RuntimeException.class) + public void loadReportData1Test_WhenReportDataSizeIsLessThanZero() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + rr.getCustomReport().getFormFieldList().setComment(""); + rr.getCustomReport().setReportType("Linear"); + rr.setWholeSQL("SELECT report_id test FROM WHERE ORDER BY"); + rr.setPageSize(-2); + rr.getFormFieldList().getFormField().get(0).setGroupFormField(true); + rr.setDBInfo("DEV"); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test]"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + dataColumnType.setVisible(true); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); + dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test]"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("COLUMN"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); + DataSet ds = PowerMockito.mock(DataSet.class); + rr.setChartDataCache(ds); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(AppUtils.getRequestFlag(mockedRequest, AppConstants.RI_GO_BACK)).thenReturn(false); + Mockito.when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("actionsession"); + Mockito.when(ConnectionUtils.getDataSet(Matchers.anyString(), Matchers.anyString())).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(-1); + Mockito.when(Globals.getGenerateSubsetSql()).thenReturn("subsetSql"); + Mockito.when(Globals.getReportSqlOnlyFirstPart()).thenReturn("subsetSql"); + Mockito.when(Globals.getReportSqlOnlySecondPartA()).thenReturn("secondpartA"); + Mockito.when(Globals.getReportSqlOnlySecondPartB()).thenReturn("secondpartB"); + Mockito.when(AppUtils.isNotEmpty(Matchers.anyString())).thenReturn(false); + Mockito.when(Globals.getDBType()).thenReturn("db"); + + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + Mockito.when(Globals.getLoadCrosstabReportData()).thenReturn("test FROM ORDER BY"); + ReportData rd = PowerMockito.mock(ReportData.class); + PowerMockito.whenNew(ReportData.class).withArguments(Mockito.anyInt(), Mockito.anyBoolean()).thenReturn(rd); + ReportDataRows reportDataRows = new ReportDataRows(); + rd.reportDataRows= reportDataRows; + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ColumnHeaderRow columnHeaderRow = new ColumnHeaderRow(); + ColumnHeader columnHeader = new ColumnHeader(); + columnHeaderRow.add(columnHeader); + ColumnHeader columnHeader1 = new ColumnHeader(); + columnHeader1.setRowSpan(1); + columnHeaderRow.add(columnHeader1); + reportColumnHeaderRows.add(columnHeaderRow); + rd.reportColumnHeaderRows = reportColumnHeaderRows; + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + RowHeaderCol rowHeaderCol1 = new RowHeaderCol(); + rowHeaderCol1.add("test1"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); + rd.reportRowHeaderCols = reportRowHeaderCols; + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(), Mockito.anyString())).thenReturn(ds); + ReportRuntime rr1 = PowerMockito.mock(ReportRuntime.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr1); + Mockito.when(rr1.getReportID()).thenReturn("lDownUrl"); + Mockito.when(rr1.getReportFormFields()).thenReturn(rr.getReportFormFields()); + rr.setDisplayColTotals(true); + rr.setDisplayRowTotals(true); + Mockito.when(Globals.getCacheCurPageData()).thenReturn(true); + Mockito.when(mockedRequest.getParameter(Mockito.anyString())).thenReturn("test"); + rr.getCustomReport().setDbInfo("DAYTONA"); + RemDbInfo rdemo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(rdemo); + Mockito.when(rdemo.getDBType(Matchers.anyString())).thenReturn("DAYTONA"); + rr.loadReportData(1, "userId", 1, mockedRequest, true); } @Test @@ -356,6 +716,39 @@ public class ReportRuntimeTest { rr.getCustomReport().getFormFieldList().setComment(""); rr.getCustomReport().setReportType("Cross-Tab"); rr.setWholeSQL("testFROMORDERBY"); + DataColumnType dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("ROW"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + dataColumnType.setVisible(true); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); + dataColumnType = new DataColumnType(); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("1"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("[test]"); + dataColumnType.setDrillDownParams("drilldown[#]"); + dataColumnType.setCrossTabValue("COLUMN"); + dataColumnType.setDrillDownURL("drillDownUrl"); + dataColumnType.setDisplayTotal("test|test2"); + rr.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().add(dataColumnType); + rr.getAllColumns().add(dataColumnType); DataSet ds = PowerMockito.mock(DataSet.class); rr.setChartDataCache(ds); PowerMockito.mockStatic(AppUtils.class); @@ -364,10 +757,13 @@ public class ReportRuntimeTest { Mockito.when(mockedRequest.getParameter(AppConstants.RI_ACTION)).thenReturn("actionsession"); Mockito.when(ConnectionUtils.getDataSet(Matchers.anyString(), Matchers.anyString())).thenReturn(ds); Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getColumnCount()).thenReturn(1); + Mockito.when(ds.getColumnName(Mockito.anyInt())).thenReturn("1"); Mockito.when(Globals.getGenerateSubsetSql()).thenReturn("subsetSql"); Mockito.when(Globals.getReportSqlOnlyFirstPart()).thenReturn("subsetSql"); Mockito.when(Globals.getReportSqlOnlySecondPartA()).thenReturn("secondpartA"); Mockito.when(Globals.getReportSqlOnlySecondPartB()).thenReturn("secondpartB"); + Mockito.when(Globals.getMergeCrosstabRowHeadings()).thenReturn(true); Mockito.when(AppUtils.isNotEmpty(Matchers.anyString())).thenReturn(false); Mockito.when(Globals.getDBType()).thenReturn("db"); PowerMockito.mockStatic(ESAPI.class); @@ -377,7 +773,7 @@ public class ReportRuntimeTest { Codec codec = PowerMockito.mock(Codec.class); Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); - Mockito.when(Globals.getLoadCrosstabReportData()).thenReturn("reportdata"); + Mockito.when(Globals.getLoadCrosstabReportData()).thenReturn("test FROM ORDER BY"); ReportData rd = PowerMockito.mock(ReportData.class); PowerMockito.whenNew(ReportData.class).withArguments(Mockito.anyInt(), Mockito.anyBoolean()).thenReturn(rd); ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); @@ -397,6 +793,14 @@ public class ReportRuntimeTest { reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); reportRowHeaderCols.addRowHeaderCol(rowHeaderCol1); rd.reportRowHeaderCols = reportRowHeaderCols; + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(), Mockito.anyString())).thenReturn(ds); + ReportRuntime rr1 = PowerMockito.mock(ReportRuntime.class); + Mockito.when(mockedRequest.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME)).thenReturn(rr1); + Mockito.when(rr1.getReportID()).thenReturn("nUrl"); + Mockito.when(rr1.getReportFormFields()).thenReturn(rr.getReportFormFields()); + rr.setDisplayColTotals(true); + rr.setDisplayRowTotals(true); + Mockito.when(Globals.getMergeCrosstabRowHeadings()).thenReturn(true); rr.loadReportData(1, "userId", 1, mockedRequest, false); } @@ -512,6 +916,49 @@ public class ReportRuntimeTest { Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyString())).thenReturn("test"); rr.parseDrillDownURL(1, ds, dataColumnType, mockedRequest, reportFormFields); } + + @Test + public void parseDrillDownURL2Test() throws Exception { + DataSet ds = PowerMockito.mock(DataSet.class); + ReportRuntime rr = mockReportRunTime1(); + DataColumnType dataColumnType = rr.getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().get(0); + dataColumnType.setChartGroup("test"); + dataColumnType.setYAxis("test"); + dataColumnType.setColName("[test"); + dataColumnType.setColOnChart("LEGEND"); + dataColumnType.setDisplayName("testLEGEND"); + dataColumnType.setColId("test"); + dataColumnType.setTableId("1"); + dataColumnType.setColType("DATE"); + dataColumnType.setDependsOnFormField("tes[t"); + dataColumnType.setDrillDownParams("drilldown[test!test]"); + dataColumnType.setCrossTabValue("VALUE"); + dataColumnType.setDrillDownURL("testutilstest1"); + ReportWrapper rw = PowerMockito.mock(ReportWrapper.class); + ReportFormFields reportFormFields = new ReportFormFields(rw, mockedRequest); + FormField formField = new FormField("test", "testLEGEND", "TEXTAREA", "validationType", false, + "defaultValue", "helpText", new ArrayList(), true, "dependsOn", null, null, "rangeStartDateSQL", + "rangeEndDateSQL", "multiSelectListSize"); + reportFormFields.add(formField); + PowerMockito.mockStatic(DataCache.class); + PowerMockito.mockStatic(AppUtils.class); + + Vector vc = new Vector<>(); + vc.add("test"); + Mockito.when(DataCache.getDataViewActions()).thenReturn(vc); + Mockito.when(Globals.getPassRequestParamInDrilldown()).thenReturn(true); + Mockito.when(Globals.getRequestParams()).thenReturn("FFtest,1"); + Mockito.when(Globals.getRequestParams()).thenReturn("test,1"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,2"); + Mockito.when(Globals.getSessionParams()).thenReturn("FFtest,2"); + + Mockito.when(mockedRequest.getParameter(Matchers.anyString())).thenReturn("test"); + Mockito.when(AppUtils.getBaseActionURL()).thenReturn("testutils"); + Mockito.when(AppUtils.getBaseActionParam()).thenReturn("utils"); + Mockito.when(ds.getString(Matchers.anyInt(), Matchers.anyString())).thenReturn("test"); + Mockito.when(mockedRequest.getSession().getAttribute("FFTEST")).thenReturn("test"); + rr.parseDrillDownURL(1, ds, dataColumnType, mockedRequest, reportFormFields); + } @Test public void parseReportSQLTest() throws Exception { @@ -537,6 +984,13 @@ public class ReportRuntimeTest { rr.getCustomReport().setDbInfo("test"); rr.parseReportSQL("select * from test"); } + + @Test + public void parseReportSQL5Test() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + rr.getCustomReport().setDbInfo("test"); + rr.parseReportSQL("select id,report_id from test"); + } @Test(expected = org.onap.portalsdk.analytics.error.ValidationException.class) public void parseReportSQL4Test() throws Exception { @@ -547,6 +1001,7 @@ public class ReportRuntimeTest { Mockito.when(rdemo.getDBType(Matchers.anyString())).thenReturn("DAYTONA"); rr.parseReportSQL(""); } + @Test public void setDisplayFlagsTest() throws Exception { @@ -912,4 +1367,212 @@ public class ReportRuntimeTest { rr.parseAndFillWithCurrentValues(mockedRequest, "test", formField); } + + @Test + public void testParseAndFillReq_Session_UserValues_WhenStartWithff() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + Mockito.when(Globals.getRequestParams()).thenReturn("fftest"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn(""); + PowerMockito.when(AppUtils.nvl(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getAttribute(Mockito.any(String.class))).thenReturn("test"); + rr.parseAndFillReq_Session_UserValues(mockedRequest, "SELECT FROM test", "userID"); + } + + @Test + public void testCreateFormFieldJSONRuntime() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + Mockito.when(Globals.getRequestParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.when(AppUtils.nvl(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + rr.createFormFieldJSONRuntime(mockedRequest); + } + + + + @Test + public void testCreateReportJSONRuntime() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + ReportData rd = mockReportData(); + PowerMockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + PowerMockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + PowerMockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); + Mockito.when(Globals.getRequestParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.when(AppUtils.nvl(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + rr.createReportJSONRuntime(mockedRequest, rd); + } + + @Test + public void testPersistLinearReport() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(Utils.class); + PowerMockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + PowerMockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + PowerMockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); + Mockito.when(Globals.getRequestParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.when(AppUtils.nvl(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(Utils.getCurrentDateTime()).thenReturn("20/05/2018"); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.doNothing().when(ReportLoader.class, "updateCustomReportRec", new Object[] {Mockito.any(Connection.class), Mockito.any(ReportRuntime.class), Mockito.any(String.class)}); + PowerMockito.doNothing().when(ReportLoader.class, "createReportLogEntry", new Object[] {Mockito.any(Connection.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)}); + rr.persistLinearReport(mockedRequest); + } + + @Test + public void testPersistDashboardReport() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(Utils.class); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test"); + PowerMockito.when(Utils.getCurrentDateTime()).thenReturn("10/05/2018"); + PowerMockito.when(AppUtils.isAdminUser(mockedRequest)).thenReturn(false); + PowerMockito.when(AppUtils.isSuperUser(mockedRequest)).thenReturn(true); + Mockito.when(Globals.getRequestParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParams()).thenReturn("test"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test"); + PowerMockito.when(AppUtils.nvl(Mockito.any(String.class))).thenReturn("test"); + Mockito.when(mockedRequest.getParameter(Mockito.any(String.class))).thenReturn("test"); + PowerMockito.doNothing().when(ReportLoader.class, "updateCustomReportRec", new Object[] {Mockito.any(Connection.class), Mockito.any(ReportRuntime.class), Mockito.any(String.class)}); + PowerMockito.doNothing().when(ReportLoader.class, "createReportLogEntry", new Object[] {Mockito.any(Connection.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)}); + rr.persistDashboardReport(mockedRequest); + } + + public ReportData mockReportData() { + ReportColumnHeaderRows reportColumnHeaderRows = new ReportColumnHeaderRows(); + ReportDataRows reportDataRows = new ReportDataRows(); + + DataRow dataRow = new DataRow(); + DataValue dataValue = new DataValue(); + dataValue.setDisplayName("displayName"); + dataValue.setDisplayCalculatedValue("displayCalculatedValue"); + dataValue.setDrillDownURL("drillDownURL"); + dataValue.setDrillDowninPoPUp(false); + dataValue.setIndentation("indentation"); + dataValue.setAlignment("alignment"); + dataValue.setVisible(false); + dataValue.setHidden(false); + HtmlFormatter formatter = new HtmlFormatter(); + dataValue.setCellFormatter(formatter); + dataValue.setBold(false); + dataValue.setRowFormatter(formatter); + dataValue.setFormatId("formatId"); + dataValue.setCellFormat(false); + dataValue.setColId("colId"); + dataValue.setDisplayName("displayName"); + dataValue.setNowrap("nowrap"); + dataValue.setHyperlinkURL("hyperlinkURL"); + dataValue.setDisplayType("displayType"); + dataValue.setActionImg("actionImg"); + dataRow.addDataValue(dataValue); + reportDataRows.addDataRow(dataRow); + ArrayList list = new ArrayList<>(); + list.add(dataValue); + dataRow.setDataValueList(list); + ReportData reportData = new ReportData(1, true); + ReportRowHeaderCols reportRowHeaderCols = new ReportRowHeaderCols(); + RowHeaderCol rowHeaderCol = new RowHeaderCol(); + rowHeaderCol.add("test"); + reportRowHeaderCols.addRowHeaderCol(rowHeaderCol); + reportData.reportColumnHeaderRows = reportColumnHeaderRows; + reportData.reportTotalRowHeaderCols = reportRowHeaderCols; + reportData.reportDataRows = reportDataRows; + + Vector vc = new Vector<>(); + ColumnVisual col = new ColumnVisual("colId", "colDisplay", true, "sortType"); + vc.add(col); + reportData.setColumnVisuals(vc); + return reportData; + } + + public ReportMap mockReportMap() { + ReportMap reportMap = new ReportMap(); + reportMap.setMarkerColor("test"); + reportMap.setUseDefaultSize("size"); + reportMap.setHeight("height"); + reportMap.setWidth("width"); + reportMap.setIsMapAllowedYN("isMapAllowedYN"); + reportMap.setAddAddressInDataYN("addAddressInDataYN"); + reportMap.setAddressColumn("column"); + reportMap.setDataColumn("data"); + reportMap.setDefaultMapType("dafaultType"); + reportMap.setLatColumn("latColumn"); + reportMap.setLongColumn("longColumn"); + reportMap.setColorColumn("colorColumn"); + reportMap.setLegendColumn("legendColumn"); + Marker marker = new Marker(); + marker.setMarkerColor("markerColor"); + marker.setDataHeader("dataHeader"); + marker.setAddressColumn("addressColumn"); + marker.setDataColumn("dataColumn"); + reportMap.getMarkers().add(marker); + return reportMap; + } + + @Test + public void testGetMapMarkers() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + ReportData rd = mockReportData(); + ReportMap rm = mockReportMap(); + rr.getMapMarkers(rd, rm); + } + + @Test + public void testHideColVisual() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + rr.hideColVisual("test"); + } + + @Test + public void testResetVisualSettings() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + rr.resetVisualSettings(); + } + + @Test + public void testLogReportRun() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.doNothing().when(ReportLoader.class, "createReportLogEntry", new Object[] {Mockito.any(Connection.class), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),Mockito.anyString()}); + rr.logReportRun("userID", "100 ms", "formFields"); + } + + @Test + public void testLogReportExecutionTime() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.doNothing().when(ReportLoader.class, "createReportLogEntryForExecutionTime", new Object[] {Mockito.any(Connection.class), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),Mockito.anyString()} ); + rr.logReportExecutionTime("userID", "100 ms", "test", "formFields"); + } + + @Test + public void testLogReportExecutionTimeFromLogList() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(ReportLoader.class); + PowerMockito.doNothing().when(ReportLoader.class, "createReportLogEntryForExecutionTime", new Object[] {Mockito.any(Connection.class), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),Mockito.anyString()} ); + rr.logReportExecutionTimeFromLogList("userID", "100 ms", "formFields"); + } + + @Test + public void testGenerateColumnDataTotalsLinear() throws Exception { + ReportRuntime rr = mockReportRunTime1(); + PowerMockito.mockStatic(ConnectionUtils.class); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.anyString(),Mockito.anyString())).thenReturn(ds); + ArrayList list = (ArrayList) rr.getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn(); + rr.generateColumnDataTotalsLinear(list, "userID", "dbInfo", "reportSQL"); + } + } diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportWrapperTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportWrapperTest.java index ece90c8c..de3f4fff 100644 --- a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportWrapperTest.java +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/xmlobj/ReportWrapperTest.java @@ -37,11 +37,12 @@ */ package org.onap.portalsdk.analytics.xmlobj; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.sql.ResultSet; import java.sql.ResultSetMetaData; -import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -54,12 +55,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mockito; -import org.onap.portalsdk.analytics.error.RaptorException; import org.onap.portalsdk.analytics.model.DataCache; import org.onap.portalsdk.analytics.model.ReportLoader; import org.onap.portalsdk.analytics.model.base.ReportWrapper; import org.onap.portalsdk.analytics.model.definition.ReportDefinition; import org.onap.portalsdk.analytics.model.definition.TableSource; +import org.onap.portalsdk.analytics.model.runtime.FormField; import org.onap.portalsdk.analytics.model.runtime.ReportParamValues; import org.onap.portalsdk.analytics.model.runtime.ReportRuntime; import org.onap.portalsdk.analytics.system.AppUtils; @@ -68,6 +69,7 @@ import org.onap.portalsdk.analytics.system.DbUtils; import org.onap.portalsdk.analytics.system.Globals; import org.onap.portalsdk.analytics.util.AppConstants; import org.onap.portalsdk.analytics.util.DataSet; +import org.onap.portalsdk.analytics.util.RemDbInfo; import org.onap.portalsdk.analytics.util.SQLCorrector; import org.onap.portalsdk.analytics.util.Utils; import org.onap.portalsdk.analytics.util.XSSFilter; @@ -83,7 +85,7 @@ import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) @PrepareForTest({ AppConstants.class, Globals.class, AppUtils.class, DataCache.class, DbUtils.class, DataSet.class, ReportLoader.class, ReportRuntime.class, Utils.class, ESAPI.class, Codec.class, SecurityCodecUtil.class, - ConnectionUtils.class, XSSFilter.class, ReportDefinition.class, UserUtils.class }) + ConnectionUtils.class, XSSFilter.class, ReportDefinition.class, UserUtils.class, ReportWrapper.class }) public class ReportWrapperTest { MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); @@ -93,7 +95,10 @@ public class ReportWrapperTest { public ReportWrapper mockReportWrapper() throws Exception { PowerMockito.mockStatic(Globals.class); PowerMockito.mockStatic(DbUtils.class); + PowerMockito.when(Globals.getReportWrapperFormat()).thenReturn("test"); + PowerMockito.when(Globals.getTimeFormat()).thenReturn("test"); Mockito.when(Globals.getReportUserAccess()).thenReturn("test"); + Mockito.when(Globals.getReportSecurity()).thenReturn("test"); ResultSet rs = PowerMockito.mock(ResultSet.class); ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class); Mockito.when(rsmd.getColumnCount()).thenReturn(1); @@ -132,16 +137,8 @@ public class ReportWrapperTest { dataSourceType.setDataColumnList(dataColumnList); list.add(dataSourceType); dataSourceList.dataSource = list; - customReportType.setReportType("test"); - customReportType.setReportTitle("test"); - customReportType.setChartMultiSeries("Y"); customReportType.setDataSourceList(dataSourceList); - customReportType.setChartMultiSeries("Y"); - customReportType.setChartRightAxisLabel("test"); - customReportType.setChartLeftAxisLabel("test"); ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions(); - chartAdditionalOptions.setLabelAngle("test"); - chartAdditionalOptions.setTimeSeriesRender("test"); chartAdditionalOptions.setMultiSeries(false); customReportType.setChartAdditionalOptions(chartAdditionalOptions); FormFieldList formFieldList = new FormFieldList(); @@ -159,15 +156,382 @@ public class ReportWrapperTest { // FormFieldType formFieldType1 = new FormFieldType(); formFields.add(formFieldType); // formFields.add(formFieldType1); - formFieldList.formField = formFields; customReportType.setFormFieldList(formFieldList); - ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", + DashboardReports dr = new DashboardReports(); + customReportType.setDashBoardReports(dr); + customReportType.setDrillURLInPoPUpPresent(true); + List javascriptItem = new ArrayList<>(); + JavascriptItemType ji = new JavascriptItemType(); + ji.setId("1"); + ji.setCallText("test"); + ji.setFieldId("2"); + JavascriptList javascriptList = new JavascriptList(); + javascriptList.setJavascriptItem(javascriptItem); + customReportType.setJavascriptList(javascriptList); + FormatType ft = new FormatType(); + ft.setAlignment("left"); + FormatList fl = new FormatList(); + fl.getFormat().add(ft); + SemaphoreType st = new SemaphoreType(); + st.setComment("test"); + st.setFormatList(fl); + st.setSemaphoreId("1"); + st.setSemaphoreName("test"); + st.setTarget("test"); + SemaphoreList smlist = new SemaphoreList(); + smlist.getSemaphore().add(st); + customReportType.setSemaphoreList(smlist); + chartAdditionalOptions.setChartOrientation("test"); + chartAdditionalOptions.setSecondaryChartRenderer("test"); + chartAdditionalOptions.setHideToolTips("test"); + chartAdditionalOptions.setHidechartLegend("test"); + chartAdditionalOptions.setLegendPosition("test"); + chartAdditionalOptions.setLabelAngle("test"); + chartAdditionalOptions.setIntervalFromdate("test"); + chartAdditionalOptions.setIntervalTodate("test"); + chartAdditionalOptions.setIntervalLabel("test"); + chartAdditionalOptions.setLastSeriesALineChart("test"); + chartAdditionalOptions.setLastSeriesABarChart("test"); + chartAdditionalOptions.setMaxLabelsInDomainAxis("test"); + chartAdditionalOptions.setLinearRegression("test"); + chartAdditionalOptions.setLinearRegressionColor("test"); + chartAdditionalOptions.setExponentialRegressionColor("test"); + chartAdditionalOptions.setMaxRegression("test"); + chartAdditionalOptions.setRangeAxisUpperLimit("test"); + chartAdditionalOptions.setRangeAxisLowerLimit("test"); + chartAdditionalOptions.setOverlayItemValueOnStackBar("test"); + chartAdditionalOptions.setAnimate(true); + chartAdditionalOptions.setKeepDomainAxisValueAsString("test"); + chartAdditionalOptions.setAnimateAnimatedChart(true); + chartAdditionalOptions.setStacked(true); + chartAdditionalOptions.setBarControls(true); + chartAdditionalOptions.setXAxisDateType(true); + chartAdditionalOptions.setLessXaxisTickers(true); + chartAdditionalOptions.setTimeAxis(true); + chartAdditionalOptions.setTimeSeriesRender("test"); + chartAdditionalOptions.setLeftMargin(10); + chartAdditionalOptions.setRightMargin(10); + chartAdditionalOptions.setTopMargin(10); + chartAdditionalOptions.setBottomMargin(10); + ReportMap rm = new ReportMap(); + rm.setMarkerColor("test"); + rm.setUseDefaultSize("10"); + rm.setHeight("10cm"); + rm.setWidth("10cm"); + rm.setIsMapAllowedYN("Y"); + rm.setAddAddressInDataYN("Y"); + rm.setAddressColumn("test"); + rm.setDataColumn("test"); + rm.setDefaultMapType("test"); + rm.setLatColumn("test"); + rm.setLegendColumn("test"); + rm.setLongColumn("test"); + rm.setColorColumn("test"); + Marker marker = new Marker(); + marker.setAddressColumn("test"); + marker.setDataColumn("test"); + marker.setDataHeader("test"); + marker.setMarkerColor("test"); + rm.getMarkers().add(marker); + customReportType.setReportMap(rm); + ChartDrillOptions chartDrillOptions = new ChartDrillOptions(); + ChartDrillFormfield cdff = new ChartDrillFormfield(); + cdff.setFormfield("test"); + chartDrillOptions.getTargetFormfield().add(cdff); + customReportType.setChartDrillOptions(chartDrillOptions); + customReportType.setReportSQL("test"); + dataSourceType.setRefDefinition("test"); + dataSourceType.setComment("test"); + dataColumnType.setDisplayWidthInPxls("test"); + dataColumnType.setDisplayAlignment("test"); + dataColumnType.setDisplayHeaderAlignment("test"); + dataColumnType.setColType(AppConstants.CT_HYPERLINK); + dataColumnType.setHyperlinkType("IMAGE"); + dataColumnType.setIndentation(10); + dataColumnType.setColFormat("test"); + dataColumnType.setOrderBySeq(10); + dataColumnType.setOrderByAscDesc("test"); + dataColumnType.setDisplayTotal("test"); + dataColumnType.setChartColor("test"); + dataColumnType.setChartLineType("test"); + dataColumnType.setIsRangeAxisFilled(true); + dataColumnType.setChartSeries(true); + dataColumnType.setCreateInNewChart(true); + dataColumnType.setDrillDownType("test"); + dataColumnType.setDrillinPoPUp(true); + dataColumnType.setComment("test"); + dataColumnType.setSemaphoreId("test"); + dataColumnType.setDbColType("test"); + dataColumnType.setNowrap("test"); + dataColumnType.setEnhancedPagination(true); + dataColumnType.setDataMiningCol("test"); + ColFilterList colFilterList = new ColFilterList(); + ColFilterType colFilterType = new ColFilterType(); + colFilterType.setArgValue("[test]"); + colFilterType.setCloseBrackets("test"); + colFilterType.setColId("test"); + colFilterType.setComment("test"); + colFilterType.setExpression("test"); + colFilterType.setFilterSeq(10); + colFilterType.setJoinCondition("test"); + colFilterType.setOpenBrackets("test"); + colFilterType.setArgType("FORM"); + colFilterList.getColFilter().add(colFilterType); + dataColumnType.setColFilterList(colFilterList); + formFieldType.setVisible("test"); + formFieldType.setFieldSQL("test"); + formFieldType.setFieldDefaultSQL("test"); + //fft.setRangeStartDate(); + formFieldType.setRangeEndDateSQL("test"); + formFieldType.setRangeStartDateSQL("test"); + //fft.setRangeEndDate(value); + formFieldType.setComment("test"); + formFieldType.setDependsOn("test"); + formFieldType.setGroupFormField(true); + formFieldType.setMultiSelectListSize("test"); + PredefinedValueList predefinedValueList = new PredefinedValueList(); + List values = new ArrayList<>(); + values.add("test"); + predefinedValueList.predefinedValue= values; + formFieldType.setPredefinedValueList(predefinedValueList); + DataminingOptions dataminingOptions = new DataminingOptions(); + customReportType.setDataminingOptions(dataminingOptions); + ReportWrapper reportWrapper = new ReportWrapper(customReportType, "1", null, "testId", "test", "test", "1", "1", true); - reportWrapper.setWholeSQL("test"); + reportWrapper.setWholeSQL("test"); + reportWrapper.setPdfImg("testLogo"); + reportWrapper.setEmptyMessage("test"); + reportWrapper.setDrillReportIdForChart("test"); + reportWrapper.setDrillXAxisFormField("test"); + reportWrapper.setDrillYAxisFormField("test"); + reportWrapper.setDrillYAxisFormField("test"); + reportWrapper.setDrillSeriesFormField("test"); + reportWrapper.setDataGridAlign("test"); + reportWrapper.setWidthNoColumn("test"); + reportWrapper.setClassifier("test"); + reportWrapper.setForecastingPeriod("10"); + reportWrapper.setForecastingTimeFormat("test"); + reportWrapper.setReportSQLOnlyFirstPart("test"); + reportWrapper.setReportSQLWithRowNum("test"); + reportWrapper.setIsWeeklyScheduleAllowed("true"); + reportWrapper.setIsOneTimeScheduleAllowed("true"); + reportWrapper.setIsMonthlyScheduleAllowed("true"); + reportWrapper.setIsHourlyScheduleAllowed("true"); + reportWrapper.setIsDailyScheduleAllowed("true"); + reportWrapper.setIsDailyMFScheduleAllowed("true"); + reportWrapper.setHideFormFieldAfterRun(true); + reportWrapper.setChartTypeFixed("test"); + reportWrapper.setDrillDownURLInPopupPresent(true); + reportWrapper.setLinearRegression("test"); + reportWrapper.setCustomizedRegressionPoint("test"); + reportWrapper.setLinearRegressionColor("test"); + reportWrapper.setExponentialRegressionColor("test"); + reportWrapper.setTimeSeriesRender("test"); + reportWrapper.setShowXAxisLabel(true); + reportWrapper.setAddXAxisTickers(true); + reportWrapper.setZoomIn(10); + reportWrapper.setTimeAxisType("test"); + reportWrapper.setToggleLayout(true); + reportWrapper.setShowPageSize(true); + reportWrapper.setChartToolTips("test"); + reportWrapper.setDomainAxisValuesAsString("test"); + reportWrapper.setJumpTo(10); + reportWrapper.setSearchPageSize(10); + reportWrapper.setShowGotoOption(true); + reportWrapper.setShowNavPos(true); + reportWrapper.setPageNav(true); + reportWrapper.setNavPosition("test"); + reportWrapper.setDashboardEditor("test"); + DashboardEditorReport dashboardEditorReport =new DashboardEditorReport(); + dashboardEditorReport.setDataType("test"); + dashboardEditorReport.setPosition("test"); + dashboardEditorReport.setReportId("test"); + dashboardEditorReport.setReportName("test"); + DashboardEditorList deList = new DashboardEditorList(); + deList.getEditorList().add(dashboardEditorReport); + reportWrapper.setDashboardEditorList(deList); + reportWrapper.setPDFFont("test"); + reportWrapper.setPDFFontSize(10); + reportWrapper.setPDFOrientation("test"); + reportWrapper.setPDFLogo1("test"); + reportWrapper.setPDFLogo1Size(10); + reportWrapper.setPDFLogo2("test"); + reportWrapper.setPDFLogo2Size(10); + reportWrapper.setPDFCoverPage(true); + reportWrapper.setPDFFooter1("test"); + reportWrapper.setPDFFooter2("test"); + reportWrapper.setMultiGroupColumn("test"); + reportWrapper.setTopDown("test"); + reportWrapper.setSizedByContent("test"); + reportWrapper.setPageSize(10); + reportWrapper.setAllowSchedule("test"); + reportWrapper.setMaxRowsInExcelDownload (10); + reportWrapper.setReportInNewWindow(true); + reportWrapper.setDisplayFolderTree(true); + reportWrapper.setReportDescr("test"); + reportWrapper.setChartMultiplePieOrder("test"); + reportWrapper.setChartMultiplePieLabelDisplay("test"); + reportWrapper.setSecondaryChartRenderer("test"); + reportWrapper.setOverlayItemValueOnStackBar("test"); + reportWrapper.setIntervalFromdate("test"); + reportWrapper.setIntervalLabel("test"); + reportWrapper.setIntervalTodate("test"); + reportWrapper.setMaxLabelsInDomainAxis("test"); + reportWrapper.setLastSeriesALineChart("test"); + reportWrapper.setLastSeriesABarChart("test"); + reportWrapper.setChartDisplay("test"); + ObjectFactory objFactory = new ObjectFactory(); + reportWrapper.addDashboardReportsNew(objFactory); + reportWrapper.addPDFAdditionalOptions(objFactory); + reportWrapper.setChartTypeFixed("test"); + reportWrapper.setChartMultiSeries("test"); + reportWrapper.setReportTitle("test"); + reportWrapper.setReportSubTitle("test"); + reportWrapper.setReportHeader("test"); + reportWrapper.setReportFooter("test"); + reportWrapper.setNumFormCols("test"); + reportWrapper.setNumDashCols("test"); + reportWrapper.setDisplayOptions("test"); + reportWrapper.setDataContainerHeight("test"); + reportWrapper.setDataContainerWidth("test"); + reportWrapper.setDashboardOptions("test"); + reportWrapper.setDashboardLayoutHTML("testHTML"); + reportWrapper.setReportType("test"); + reportWrapper.setChartRightAxisLabel("test"); + reportWrapper.setChartLeftAxisLabel("test"); + reportWrapper.setDBInfo("testDB"); + reportWrapper.setChartWidth("100 cm"); + reportWrapper.setChartHeight("100 cm"); + reportWrapper.setFrozenColumns(10); + reportWrapper.setComment("test"); + reportWrapper.setDashboardType(true); + reportWrapper.setJavascriptElement("test"); + reportWrapper.setFolderId("1"); + reportWrapper.setReportMap(rm); + reportWrapper.setReportChartDrillOptions(chartDrillOptions); + reportWrapper.setFormHelpText("test"); + DataSet ds= Mockito.mock(DataSet.class); + PowerMockito.when(DbUtils.executeQuery(Mockito.any(String.class))).thenReturn(ds); + PowerMockito.when(ds.getString(Mockito.anyInt(),Mockito.anyInt())).thenReturn("test"); + PowerMockito.when(ds.getRowCount()).thenReturn(1); + return reportWrapper; } + @Test + public void testReportWrapperProperties() throws Exception { + ReportWrapper rw = mockReportWrapper(); + assertTrue(rw.isDisplayFolderTree()); + assertTrue(rw.isHideFormFieldAfterRun()); + assertTrue(rw.isReportInNewWindow()); + assertTrue(rw.isDrillDownURLInPopupPresent()); + assertFalse(rw.isChartTypeFixed()); + assertFalse(rw.displayPieOrderinRunPage()); + assertFalse(rw.isMultiplePieOrderByRow()); + assertFalse(rw.isMultiplePieOrderByColumn()); + assertFalse(rw.displayPieLabelDisplayinRunPage()); + assertEquals("test", rw.getMultiplePieLabelDisplay()); + assertFalse(rw.displayChartDisplayinRunPage()); + assertFalse(rw.isChartDisplayIn3D()); + assertTrue(rw.isChartAnimate()); + assertTrue(rw.isXAxisDateType()); + assertFalse(rw.displayChartOrientationInRunPage()); + assertFalse(rw.isVerticalOrientation()); + assertFalse(rw.displaySecondaryChartRendererInRunPage()); + assertFalse(rw.displayIntervalInputInRunPage()); + assertFalse(rw.showLegendDisplayOptionsInRunPage()); + assertFalse(rw.isLastSeriesALineChart()); + assertFalse(rw.hideChartToolTips()); + assertFalse(rw.keepDomainAxisValueInChartAsString()); + assertTrue(rw.isDashboardType()); + assertTrue(rw.isToggleLayout()); + assertTrue(rw.isShowPageSize()); + assertTrue(rw.isShowNavPos()); + assertTrue(rw.isShowGotoOption()); + assertTrue(rw.isPageNav()); + assertTrue(rw.isPDFCoverPage()); + assertFalse(rw.isAllowSchedule()); + assertFalse(rw.isMultiGroupColumn()); + assertFalse(rw.isTopDown()); + assertFalse(rw.isSizedByContent()); + assertFalse(rw.isDashboardOptionHideChart()); + assertFalse(rw.isDashboardOptionHideData()); + assertFalse(rw.isDashboardOptionHideBtns()); + assertFalse(rw.isDisplayOptionHideForm()); + assertFalse(rw.isDisplayOptionHideData()); + assertFalse(rw.isDisplayOptionHideBtns()); + assertFalse(rw.isDisplayOptionHideMap()); + assertFalse(rw.isDisplayOptionHideExcelIcons()); + assertFalse(rw.isDisplayOptionHidePDFIcons()); + assertEquals("test", rw.getChartTypeFixed()); + assertEquals("test", rw.getLinearRegression()); + assertEquals("test", rw.getCustomizedRegressionPoint()); + assertEquals("test", rw.getLinearRegressionColor()); + assertEquals(0, rw.getChartWidthAsInt()); + assertEquals("test", rw.getExponentialRegressionColor()); + assertEquals("test", rw.getSecondaryChartRenderer()); + assertEquals("test", rw.getOverlayItemValueOnStackBar()); + assertEquals("test", rw.getIntervalFromdate()); + assertEquals("test", rw.getIntervalTodate()); + assertEquals("test", rw.getIntervalLabel()); + assertEquals("test", rw.getMaxLabelsInDomainAxis()); + assertEquals(0, rw.getChartHeightAsInt()); + assertEquals("test", rw.getReportHeader()); + assertEquals("test", rw.getReportFooter()); + assertEquals("test", rw.getNumDashCols()); + assertEquals(1, rw.getNumDashColsAsInt()); + assertEquals("test", rw.getNumFormCols()); + assertEquals(5, rw.getNumFormColsAsInt()); + assertEquals(10, rw.getJumpTo()); + assertEquals("test", rw.getNavPosition()); + assertEquals(null, rw.getDashboardEditorList()); + assertEquals(PDFAdditionalOptions.class, rw.getPDFAdditionalOptions().getClass()); + assertEquals(null, rw.getPDFFont()); + assertEquals(9, rw.getPDFFontSize()); + assertEquals("landscape", rw.getPDFOrientation()); + assertEquals(null, rw.getPDFLogo1()); + assertEquals(0, rw.getPDFLogo1Size()); + assertEquals(null, rw.getPDFLogo2()); + assertEquals(0, rw.getPDFLogo2Size()); + assertEquals(null, rw.getPDFFooter1()); + assertEquals(null, rw.getPDFFooter2()); + assertEquals("test", rw.getDataContainerHeight()); + assertEquals("test", rw.getDataContainerWidth()); + assertEquals("test", rw.getAllowSchedule()); + assertEquals("test", rw.getMultiGroupColumn()); + assertEquals(0, rw.getMaxGroupLevel()); + assertEquals(ChartAdditionalOptions.class, rw.getChartAdditionalOptions().getClass()); + assertEquals(DataminingOptions.class, rw.getDataminingOptions().getClass()); + assertEquals(DashboardReports.class, rw.getDashBoardReports().getClass()); + assertEquals(DashboardReportsNew.class, rw.getDashBoardReportsNew().getClass()); + assertEquals("test", rw.getClassifier()); + assertEquals(10, rw.getForecastingPeriod()); + assertEquals("test", rw.getForecastingTimeFormat()); + assertEquals(10, rw.getFrozenColumns()); + assertEquals("testLogo", rw.getPdfImg()); + assertEquals("test", rw.getEmptyMessage()); + assertEquals("test", rw.getDrillReportIdForChart()); + assertEquals("test", rw.getDrillXAxisFormField()); + assertEquals("test", rw.getDrillYAxisFormField()); + assertEquals("test", rw.getDrillSeriesFormField()); + assertEquals("test", rw.getDataGridAlign()); + assertEquals("test", rw.getWidthNoColumn()); + assertEquals(10, rw.getSearchPageSize()); + assertEquals(null, rw.getDashboardEditor()); + assertEquals(ReportMap.class, rw.getReportMap().getClass()); + assertEquals(ChartDrillOptions.class, rw.getReportChartDrillOptions().getClass()); + assertEquals("test", rw.getFormHelpText()); + assertEquals("test", rw.getReportSQLWithRowNum()); + assertEquals("true", rw.getIsWeeklyScheduleAllowed()); + assertEquals("true", rw.getIsOneTimeScheduleAllowed()); + assertEquals("true", rw.getIsMonthlyScheduleAllowed()); + assertEquals("true", rw.getIsHourlyScheduleAllowed()); + assertEquals("true", rw.getIsDailyScheduleAllowed()); + assertEquals("true", rw.getIsDailyMFScheduleAllowed()); + assertEquals("1", rw.getFolderId()); + } + @Test public void cloneCustomReportTest() throws Exception { ReportWrapper rw = mockReportWrapper(); @@ -237,16 +601,16 @@ public class ReportWrapperTest { public void rwTest() throws Exception { ReportWrapper rw = new ReportWrapper(mockReportWrapper()); assertEquals(rw.getCustomReport().getClass(), CustomReportType.class); - assertEquals(rw.getReportID(), "-1"); - assertEquals(rw.getMenuID(), "1"); + assertEquals(rw.getReportID(), "1"); + assertEquals(rw.getMenuID(), ""); assertFalse(rw.checkMenuIDSelected("test")); - assertTrue(rw.isMenuApproved()); - assertEquals(rw.getReportDefType(), ""); + assertFalse(rw.isMenuApproved()); + assertEquals(rw.getReportDefType(), "SQL-based"); rw.setMenuID("test"); rw.setMenuApproved(false); rw.setReportDefType("test"); rw.updateReportDefType(); - assertEquals(rw.getJavascriptElement(), null); + assertEquals(rw.getJavascriptElement(), "test"); } @Test @@ -727,6 +1091,166 @@ public class ReportWrapperTest { Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(true); rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); } + + @Test + public void generateSQLSQLBased2Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] AND ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(true); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } + + @Test + public void generateSQLSQLBased3Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(true); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } + + @Test + public void generateSQLSQLBased4Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + rw.getFormFieldList().formField.get(0).setValidationType(FormField.VT_TIMESTAMP_HR); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } + + @Test + public void generateSQLSQLBased5Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + rw.getFormFieldList().formField.get(0).setValidationType(FormField.VT_TIMESTAMP_MIN); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } + + @Test + public void generateSQLSQLBased6Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn("test"); + rw.getFormFieldList().formField.get(0).setValidationType(FormField.VT_TIMESTAMP_SEC); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } + + @Test + public void generateSQLSQLBased7Test() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ReportParamValues paramValues = PowerMockito.mock(ReportParamValues.class); + PowerMockito.mockStatic(Globals.class); + PowerMockito.mockStatic(ConnectionUtils.class); + Mockito.when(Globals.getRequestParams()).thenReturn("test,req"); + Mockito.when(Globals.getSessionParams()).thenReturn("test,session"); + Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test,sessionSche"); + rw.getCustomReport().setReportSQL("SELECT WHEN FROM TABLE WHERE [test] ORDER BY"); + PowerMockito.mockStatic(ESAPI.class); + PowerMockito.mockStatic(SecurityCodecUtil.class); + Encoder encoder = PowerMockito.mock(Encoder.class); + Mockito.when(ESAPI.encoder()).thenReturn(encoder); + Codec codec = PowerMockito.mock(Codec.class); + Mockito.when(SecurityCodecUtil.getCodec()).thenReturn(codec); + Mockito.when(encoder.encodeForSQL(Matchers.any(Codec.class), Matchers.anyString())).thenReturn("select *"); + rw.getFormFieldList().formField.get(0).setFieldType("BLANK1"); + Mockito.when(paramValues.isParameterMultiValue(Matchers.anyString())).thenReturn(false); + Mockito.when(paramValues.isParameterTextAreaValueAndModified(Mockito.any(String.class))).thenReturn(true); + //Mockito.when(paramValues.getParamValue(Mockito.any(String.class))).thenReturn("select test"); + DataSet ds = Mockito.mock(DataSet.class); + Mockito.when(ConnectionUtils.getDataSet(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(ds); + Mockito.when(ds.getRowCount()).thenReturn(1); + Mockito.when(ds.getString(Mockito.anyInt(), Mockito.anyInt())).thenReturn(""); + RemDbInfo remDbInfo = Mockito.mock(RemDbInfo.class); + PowerMockito.whenNew(RemDbInfo.class).withNoArguments().thenReturn(remDbInfo); + Mockito.when(remDbInfo.getDBType(Mockito.any(String.class))).thenReturn("DAYTONA"); + rw.generateSQLSQLBased(paramValues, "overrideSortByColId", "overrideSortByAscDesc", "userId", mockedRequest); + } @Test public void generateSQLVisualTest() throws Exception { @@ -853,7 +1377,7 @@ public class ReportWrapperTest { @Test public void getFrozenColumnId1Test() throws Exception { ReportWrapper rw = mockReportWrapper(); - rw.getCustomReport().setFrozenColumns(1); + rw.setFrozenColumns(1); rw.getCustomReport().getDataSourceList().getDataSource().get(0).getDataColumnList().getDataColumn().get(0) .setVisible(true); rw.getFrozenColumnId(); @@ -1146,4 +1670,55 @@ public class ReportWrapperTest { DataSourceType dataSourceType = new DataSourceType(); rw.formatListValue("[MAX_VALUE]", "[MAX_VALUE]", dataColumnType, false, false, dataSourceType, "listBaseSQL"); } + + @Test + public void testIsChartDrillDownContainsName() throws Exception { + ReportWrapper rw = mockReportWrapper(); + rw.isChartDrillDownContainsName("test"); + } + + @Test + public void testCloneChartDrillFormfield() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ObjectFactory objFactory = new ObjectFactory(); + ChartDrillFormfield cdff = new ChartDrillFormfield(); + cdff.setFormfield("test"); + rw.cloneChartDrillFormfield(objFactory, cdff); + } + + @Test + public void testCloneMarkerType() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ObjectFactory objFactory = new ObjectFactory(); + Marker marker = new Marker(); + marker.setAddressColumn("test"); + marker.setDataColumn("test"); + marker.setDataHeader("test"); + marker.setMarkerColor("test"); + rw.cloneMarkerType(objFactory, marker); + } + + @Test + public void testCloneDashboardType() throws Exception { + ReportWrapper rw = mockReportWrapper(); + ObjectFactory objFactory = new ObjectFactory(); + Reports reports = new Reports(); + reports.setBgcolor("test"); + reports.setReportId("1"); + rw.cloneDashboardType(objFactory, reports); + } + + @Test + public void testIsEnhancedPaginationNeeded() throws Exception { + ReportWrapper rw = mockReportWrapper(); + rw.isEnhancedPaginationNeeded(); + } + + @Test + public void testGetColumnWhichNeedEnhancedPagination() throws Exception { + ReportWrapper rw = mockReportWrapper(); + rw.getColumnWhichNeedEnhancedPagination(); + } + + } \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-common/pom.xml b/ecomp-sdk/epsdk-app-common/pom.xml index 2d38b6a5..5757988b 100644 --- a/ecomp-sdk/epsdk-app-common/pom.xml +++ b/ecomp-sdk/epsdk-app-common/pom.xml @@ -5,7 +5,7 @@ org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/AngularAdminController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/AngularAdminController.java index 3aeb0147..138a805d 100644 --- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/AngularAdminController.java +++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/AngularAdminController.java @@ -49,9 +49,8 @@ import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping("/") public class AngularAdminController extends RestrictedBaseController{ - public static final String API_VERSION = "/v3"; - @RequestMapping(value = {API_VERSION + "/userProfile" }, method = RequestMethod.GET) + @RequestMapping(value = {"/userProfile" }, method = RequestMethod.GET) public ModelAndView view() { Map model = new HashMap<>(); return new ModelAndView("user_profile_list","model", model); diff --git a/ecomp-sdk/epsdk-app-os/README.md b/ecomp-sdk/epsdk-app-os/README.md index c61ebe63..675919bb 100644 --- a/ecomp-sdk/epsdk-app-os/README.md +++ b/ecomp-sdk/epsdk-app-os/README.md @@ -14,6 +14,7 @@ https://www.eclipse.org/m2e-wtp/ ## Release Notes Version 2.3.0 - PORTAL 254 ECOMP AAF jar +- PORTAL-281 Portal SDK AAF jar throws null pointer exception Version 2.2.0 - PORTAL 136 Junits for SDK diff --git a/ecomp-sdk/epsdk-app-os/pom.xml b/ecomp-sdk/epsdk-app-os/pom.xml index 733a1798..8b67bd5b 100644 --- a/ecomp-sdk/epsdk-app-os/pom.xml +++ b/ecomp-sdk/epsdk-app-os/pom.xml @@ -10,7 +10,7 @@ org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT diff --git a/ecomp-sdk/epsdk-app-overlay/pom.xml b/ecomp-sdk/epsdk-app-overlay/pom.xml index f0d15a73..98143b71 100644 --- a/ecomp-sdk/epsdk-app-overlay/pom.xml +++ b/ecomp-sdk/epsdk-app-overlay/pom.xml @@ -5,7 +5,7 @@ org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-chart-controller.js b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-chart-controller.js index 8fa14643..b15205fc 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-chart-controller.js +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-chart-controller.js @@ -1,4 +1,4 @@ -appDS2.controller('reportChartController', function ($scope, $rootScope, $timeout, $window, $http, $routeParams,modalService) { +appDS2.controller('reportChartController', function ($scope, $rootScope, $timeout, $window, $modal, $http, $routeParams,modalService) { $scope.showLoader = true; $scope.commonOptionOpen = false; $scope.additionalOptionOpen = false; @@ -15,11 +15,16 @@ appDS2.controller('reportChartController', function ($scope, $rootScope, $timeou $scope.populateChrtWzdFields = function() { $scope.reportRunJson = {}; + $scope.showLoader=true; $http.get("raptor.htm?action=chart.json&c_master="+$routeParams.reportId).then(function (response) { + $scope.showLoader=false; $scope.reportRunJson = response.data; //Set chart type - $scope.reportRunJson.commonChartOptions.animateAnimatedChart = $scope.reportRunJson.commonChartOptions.animateAnimatedChart+""; - $scope.reportRunJson.commonChartOptions.hideLegend = $scope.reportRunJson.commonChartOptions.hideLegend + ""; + if($scope.reportRunJson.commonChartOptions!=null){ + $scope.reportRunJson.commonChartOptions.animateAnimatedChart = $scope.reportRunJson.commonChartOptions.animateAnimatedChart+""; + $scope.reportRunJson.commonChartOptions.hideLegend = $scope.reportRunJson.commonChartOptions.hideLegend + ""; + } + $scope.reportRunJson.showTitle = $scope.reportRunJson.showTitle + ""; // if barChartOptions is not null @@ -126,9 +131,11 @@ appDS2.controller('reportChartController', function ($scope, $rootScope, $timeou $scope.saveChartData = function() { $scope.showLoader = true; - - $scope.reportRunJson.commonChartOptions.animateAnimatedChart = ($scope.reportRunJson.commonChartOptions.animateAnimatedChart=="true") - $scope.reportRunJson.commonChartOptions.hideLegend = ($scope.reportRunJson.commonChartOptions.hideLegend=="true"); + if($scope.reportRunJson.commonChartOptions){ + $scope.reportRunJson.commonChartOptions.animateAnimatedChart = ($scope.reportRunJson.commonChartOptions.animateAnimatedChart=="true") + $scope.reportRunJson.commonChartOptions.hideLegend = ($scope.reportRunJson.commonChartOptions.hideLegend=="true"); + } + $scope.reportRunJson.showTitle = ($scope.reportRunJson.showTitle=="true"); $scope.reportRunJson.chartTypeJSON = { @@ -190,12 +197,12 @@ appDS2.controller('reportChartController', function ($scope, $rootScope, $timeou //add the remove list to the json $scope.reportRunJson.rangeAxisRemoveList= $scope.rangeAxisRemoveList; $http.post("save_chart", JSON.stringify($scope.reportRunJson)).success(function(data, status) { - $scope.successSubmit=true; + $scope.successSubmit=true; $scope.showLoader = false; $scope.reportRunJson.commonChartOptions.animateAnimatedChart = $scope.reportRunJson.commonChartOptions.animateAnimatedChart+""; $scope.reportRunJson.commonChartOptions.hideLegend = $scope.reportRunJson.commonChartOptions.hideLegend + ""; $scope.reportRunJson.showTitle = $scope.reportRunJson.showTitle + ""; - if ($scope.reportRunJson.chartType == "BarChart3D") { + if ($scope.reportRunJson.chartType == "BarChart3D" && $scope.reportRunJson.barChartOptions) { $scope.reportRunJson.barChartOptions.displayBarControls = $scope.reportRunJson.barChartOptions.displayBarControls+""; $scope.reportRunJson.barChartOptions.minimizeXAxisTickers = $scope.reportRunJson.barChartOptions.minimizeXAxisTickers+""; $scope.reportRunJson.barChartOptions.stackedChart = $scope.reportRunJson.barChartOptions.stackedChart+""; @@ -203,6 +210,7 @@ appDS2.controller('reportChartController', function ($scope, $rootScope, $timeou $scope.reportRunJson.barChartOptions.verticalOrientation = $scope.reportRunJson.barChartOptions.verticalOrientation +""; $scope.reportRunJson.barChartOptions.xAxisDateType = $scope.reportRunJson.barChartOptions.xAxisDateType +""; } + $scope.successPopUp(); $scope.populateChrtWzdFields(); }) } @@ -419,6 +427,38 @@ appDS2.controller('reportChartController', function ($scope, $rootScope, $timeou $rootScope.isViewRendering = false; }); + $scope.successPopUp = function (msg) { + var modalInstance = $modal.open({ + templateUrl: 'app/fusion/scripts/DS2-modal/success_modal.html', + controller: ModalInstanceCtrl, + sizeClass: 'modal-small', + resolve: { + msg: function () { + var message = { + title: '', + text: msg + }; + return message; + } + } + }); + }; + + $scope.errorPopUp = function (msg) { + var modalInstance = $modal.open({ + templateUrl: 'app/fusion/scripts/DS2-modal/error_modal.html', + controller: ModalInstanceCtrl, + sizeClass: 'modal-small', + resolve: { + msg: function () { + return msg; + } + } + }); + }; + var ModalInstanceCtrl = function ($scope, $modalInstance, msg,$rootScope) { + $scope.msg=msg; + } }); diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-router.js b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-router.js index 1e22cca3..58913a40 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-router.js +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-router.js @@ -1,41 +1,41 @@ appDS2.config(['$routeProvider', - function($routeProvider) { - $routeProvider. - when('/', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/report-search.html', - controller: 'reportSearchController' - }). - when('/report_search', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/report-search.html', - controller: 'reportSearchController' - }). - when('/report_run/:reportUrlParams*', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/report-run.html', - controller: 'reportRunController' - }). - when('/report_chart_wizard/:reportId', { - templateUrl: 'static/fusion/raptor/ebz/report_chart_wizard.html', - controller: 'ChartController' - }). - when('/report_chart/:reportId', { - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/report-chart-wizard.html', - controller: 'reportChartController' - }). - when("/report_wizard", { - templateUrl : "app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/report-step.html", - controller: "reportStepController" - }). - when("/report_wizard/:reportId", { - templateUrl : "app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/report-step.html", - controller: "reportStepController" - }). - when("/report_wizard/:reportMode/:reportId", { - templateUrl : "app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/report-step.html", - controller: "reportStepController" - }). - when("/report_import", { - templateUrl : "app/fusion/scripts/DS2-view-models/ds2-reports/report-import.html", - controller: "reportImportController" - }) - ; - }]); \ No newline at end of file + function($routeProvider) { + $routeProvider. + when('/', { + templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/report-search.html', + controller: 'reportSearchController' + }). + when('/report_search', { + templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/report-search.html', + controller: 'reportSearchController' + }). + when('/report_run/:reportUrlParams*', { + templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/report-run.html', + controller: 'reportRunController' + }). + when('/report_chart_wizard/:reportId', { + templateUrl: 'static/fusion/raptor/ebz/report_chart_wizard.html', + controller: 'ChartController' + }). + when('/report_chart/:reportId', { + templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/report-chart-wizard.html', + controller: 'reportChartController' + }). + when("/report_wizard", { + templateUrl : "app/fusion/scripts/DS2-view-models/ds2-reports/report-step.html", + controller: "reportStepController" + }). + when("/report_wizard/:reportId", { + templateUrl : "app/fusion/scripts/DS2-view-models/ds2-reports/report-step.html", + controller: "reportStepController" + }). + when("/report_wizard/:reportMode/:reportId", { + templateUrl : "app/fusion/scripts/DS2-view-models/ds2-reports/report-step.html", + controller: "reportStepController" + }). + when("/report_import", { + templateUrl : "app/fusion/scripts/DS2-view-models/ds2-reports/report-import.html", + controller: "reportImportController" + }) + ; +}]); \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-run-controller.js b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-run-controller.js index 6eb0afe6..daa47900 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-run-controller.js +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-run-controller.js @@ -1,5 +1,5 @@ -appDS2.controller("reportRunController", ['$scope','$rootScope','$routeParams','$http','dateFilter', '$window', '$timeout', 'rowSorter', - function ($scope,$rootScope,$routeParams,$http,dateFilter,$window,$timeout,rowSorter) { +appDS2.controller("reportRunController", ['$scope','$rootScope','$routeParams','$http','dateFilter', '$window', '$timeout', 'rowSorter','$modal', + function ($scope,$rootScope,$routeParams,$http,dateFilter,$window,$timeout,rowSorter,$modal) { $scope.dateformat = "MM/dd/yyyy"; $scope.datetimeformat = "MM/dd/yyyy hh:mm a"; $scope.showFormFields = false; @@ -14,7 +14,7 @@ appDS2.controller("reportRunController", ['$scope','$rootScope','$routeParams',' value: false }; $scope.isInProgress = true; - + $scope.showLoader=false; if($routeParams.reportUrlParams.indexOf("parent___params===")>-1) { $scope.showBackButton = true; $scope.parentReportUrlParams = $routeParams.reportUrlParams.substring($routeParams.reportUrlParams.indexOf("parent___params===")+18); @@ -67,36 +67,41 @@ appDS2.controller("reportRunController", ['$scope','$rootScope','$routeParams',' function(response){ // console.log(response); $scope.isInProgress = false; - $scope.reportData = response.data; - // console.log('reportData report run container response',$scope.reportData); - if ($scope.reportData.reportTitle) { - $scope.reportData.reportHeading = $scope.reportData.reportTitle; - if ($scope.reportData.reportSubTitle) { - $scope.reportData.reportSubTitle = $scope.reportData.reportSubTitle; + if(response.data.errormessage!=null && response.data.errormessage!=''){ + $scope.errorPopUp(response.data.errormessage); + }else{ + $scope.reportData = response.data; + // console.log('reportData report run container response',$scope.reportData); + if ($scope.reportData.reportTitle) { + $scope.reportData.reportHeading = $scope.reportData.reportTitle; + if ($scope.reportData.reportSubTitle) { + $scope.reportData.reportSubTitle = $scope.reportData.reportSubTitle; + } } + else + $scope.reportData.reportHeading = $scope.reportData.reportName; + if(!$scope.urlParams.hideChart && $scope.reportData.chartAvailable && $scope.reportData.totalRows>1){ + // console.log('raptor.htm?action=chart.run&'+convertQueryString($scope.urlParams)); + $http.get('raptor.htm?action=chart.run&'+convertQueryString($scope.urlParams)).then( + function(response){ + $scope.showChart = true; + document.getElementById('chartiframe').contentWindow.document.write(response.data); + document.getElementById('chartiframe').contentWindow.document.close(); + }); + } + + if($scope.reportData.displayForm && $scope.reportData.formFieldList && $scope.reportData.formFieldList.length>0 && !$scope.urlParams.hideFormFields){ + $scope.showFormFields = true; + } } - else - $scope.reportData.reportHeading = $scope.reportData.reportName; - if(!$scope.urlParams.hideChart && $scope.reportData.chartAvailable && $scope.reportData.totalRows>1){ - // console.log('raptor.htm?action=chart.run&'+convertQueryString($scope.urlParams)); - $http.get('raptor.htm?action=chart.run&'+convertQueryString($scope.urlParams)).then( - function(response){ - $scope.showChart = true; - document.getElementById('chartiframe').contentWindow.document.write(response.data); - document.getElementById('chartiframe').contentWindow.document.close(); - }); - } - - if($scope.reportData.displayForm && $scope.reportData.formFieldList && $scope.reportData.formFieldList.length>0 && !$scope.urlParams.hideFormFields){ - $scope.showFormFields = true; - } + }); $scope.getFormFieldSelectedValuesAsURL = function(){ var formFieldsUrl = ''; $scope.reportData.formFieldList.forEach(function(formField) { if(formField.fieldType==='LIST_BOX') { - if($scope.formFieldSelectedValues && $scope.formFieldSelectedValues[formField.fieldId] && $scope.formFieldSelectedValues[formField.fieldId].value != '') { - formFieldsUrl = formFieldsUrl+formField.fieldId+'='+$scope.formFieldSelectedValues[formField.fieldId].value+'&'; + if($scope.formFieldSelectedValues && $scope.formFieldSelectedValues[formField.fieldId] ) { + formFieldsUrl = formFieldsUrl+formField.fieldId+'='+$scope.formFieldSelectedValues[formField.fieldId]+'&'; } } else if(formField.fieldType==='LIST_MULTI_SELECT') { if($scope.formFieldSelectedValues[formField.fieldId].length >0) { @@ -114,11 +119,13 @@ appDS2.controller("reportRunController", ['$scope','$rootScope','$routeParams',' formFieldsUrl = formFieldsUrl+formField.fieldId+'='+$scope.formFieldSelectedValues[formField.fieldId]+'&'; } }); + //formFieldsUrl = str.slice(0, -1); return formFieldsUrl; } $scope.runReport = function(pagination){ + $scope.showLoader=true; var formFieldsUrl = $scope.getFormFieldSelectedValuesAsURL(); /*if ($scope.reportData.reportTitle) $scope.reportData.reportHeading = $scope.reportData.reportTitle; @@ -149,6 +156,7 @@ appDS2.controller("reportRunController", ['$scope','$rootScope','$routeParams',' // console.log('raptor.htm?action=report.run.container&c_master='+$scope.urlParams.c_master+'&'+formFieldsUrl+'refresh=Y&display_content=Y&r_page='+(paginationOptions.pageNumber-1)); $http.get('raptor.htm?action=report.run.container&c_master='+$scope.urlParams.c_master+'&'+formFieldsUrl+'refresh=Y&display_content=Y&r_page='+(paginationOptions.pageNumber-1)).then( function(response){ + $scope.showLoader=false; $scope.reportData = response.data; if ($scope.reportData.reportTitle) { $scope.reportData.reportHeading = $scope.reportData.reportTitle; @@ -207,6 +215,7 @@ appDS2.controller("reportRunController", ['$scope','$rootScope','$routeParams',' paginationTemplate: correctTotalPaginationTemplate, columnDefs: [], data: [], + enableSorting: true, enableGridMenu: true, enableSelectAll: true, gridMenuCustomItems : [ @@ -218,10 +227,10 @@ appDS2.controller("reportRunController", ['$scope','$rootScope','$routeParams',' action : function($event) { $window.open($scope.reportEditURL,'_self'); }, order : 211 }, - { title : 'Export All data as Excel 2007', + /*{ title : 'Export All data as Excel 2007', action : function($event) { $window.open('raptor.htm?c_master='+$scope.reportData.reportID+'&r_action=report.download.excel2007.session','_self'); - }, order : 212 }, + }, order : 212 },*/ { title : 'Export All data as Excel', action : function($event) { $window.open('raptor.htm?c_master='+$scope.reportData.reportID+'&r_action=report.download.excel.session','_self'); @@ -323,9 +332,43 @@ appDS2.controller("reportRunController", ['$scope','$rootScope','$routeParams',' $http.get('raptor.htm?action=report.formfields.run.container&c_master='+$scope.reportData.reportID+'&'+formFieldsUrl).then( function(response){ $scope.reportData = response.data; + if($scope.reportData.reportHeading==null || $scope.reportData.reportHeading=='') + $scope.reportData.reportHeading = ($scope.reportData.reportTitle=='')?$scope.reportData.reportName:$scope.reportData.reportTitle; }); }; $timeout(function() { $rootScope.isViewRendering = false; }); + $scope.successPopUp = function (msg) { + var modalInstance = $modal.open({ + templateUrl: 'app/fusion/scripts/DS2-modal/success_modal.html', + controller: ModalInstanceCtrl, + sizeClass: 'modal-small', + resolve: { + msg: function () { + var message = { + title: '', + text: msg + }; + return message; + } + } + }); + }; + + $scope.errorPopUp = function (msg) { + var modalInstance = $modal.open({ + templateUrl: 'app/fusion/scripts/DS2-modal/error_modal.html', + controller: ModalInstanceCtrl, + sizeClass: 'modal-small', + resolve: { + msg: function () { + return msg; + } + } + }); + }; + var ModalInstanceCtrl = function ($scope, $modalInstance, msg,$rootScope) { + $scope.msg=msg; + } }]); diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-search-controller.js b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-search-controller.js index e1c5e1e8..36a541ed 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-search-controller.js +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-search-controller.js @@ -2,13 +2,17 @@ appDS2.requires.push('ui.grid'); appDS2.requires.push('ui.grid.pagination'); appDS2.requires.push('ui.grid.resizeColumns'); appDS2.controller("reportSearchController", ['$scope','$rootScope','$http','$timeout','uiGridConstants','$modal','$q','$log','raptorReportFactory',function ($scope,$rootScope,$http,$timeout,uiGridConstants,$modal,$q,$log,raptorReportFactory) { - + $scope.showLoader=false; $scope.getSearchData = function(){ + $scope.showLoader=true; + raptorReportFactory.getSearchData().then(function(data){ $scope.searchdData = data; },function(error){ $log.error("raptorReportFactory: getSearchData failed."); - }); + }).finally(function() { + $scope.showLoader=false;// Always execute this on both error and success + });; } $scope.getSearchData(); @@ -21,12 +25,15 @@ appDS2.controller("reportSearchController", ['$scope','$rootScope','$http','$tim if($scope.reportName && $scope.reportName!=''){ searchParams = searchParams+'&rep_name='+$scope.reportName+'&rep_name_options='+$scope.operatorRepName.index; } - + $scope.showLoader=true; var pageSearchParameter = ($scope.paginationOptions.pageNumber-1)+searchParams raptorReportFactory.getSearchDataAtPage(pageSearchParameter).then(function(data){ $scope.searchdData = data },function(error){ $log.error("raptorReportFactory: getSearchDataAtPage failed."); + }).finally(function() { + $scope.showLoader=false;// Always execute this on both error and success + }); }; @@ -37,6 +44,57 @@ appDS2.controller("reportSearchController", ['$scope','$rootScope','$http','$tim sort: null }; + function convertValue(v){ + return parseInt(v.displayValue); + } + + $scope.getSortingAlgorithm= function (columnName) { + return function(a, b, rowA, rowB, direction) { + console.log("sorting by column " + columnName,a,b); + if(columnName=='rep_id'){ + if(a && b && a.displayValue && b.displayValue){ + if (convertValue(a) == convertValue(b)) return 0; + if (convertValue(a) < convertValue(b)) return -1; + if (convertValue(a) > convertValue(b)) return 1; + }else{ + return 0; + } + }else if(columnName=='rep_name'){ + if(a && b && a.displayValue && b.displayValue){ + if (a.displayValue == b.displayValue) return 0; + if (a.displayValue < b.displayValue) return -1; + if (a.displayValue > b.displayValue) return 1; + }else{ + return 0; + } + }else if(columnName=='descr'){ + if(a && b && a.displayValue && b.displayValue){ + if (a.displayValue == b.displayValue) return 0; + if (a.displayValue < b.displayValue) return -1; + if (a.displayValue > b.displayValue) return 1; + }else{ + return 0; + } + }else if(columnName=='owner'){ + if(a && b && a.displayValue && b.displayValue){ + if (a.displayValue == b.displayValue) return 0; + if (a.displayValue < b.displayValue) return -1; + if (a.displayValue > b.displayValue) return 1; + }else{ + return 0; + } + }else if(columnName=='create_date'){ + if(a && b && a.displayValue && b.displayValue){ + if (a.displayValue == b.displayValue) return 0; + if (a.displayValue < b.displayValue) return -1; + if (a.displayValue > b.displayValue) return 1; + }else{ + return 0; + } + } + } + }; + var correctTotalPaginationTemplate = //same as normal template, but fixed totals: {{(((grid.options.paginationCurrentPage-1)*grid.options.paginationPageSize)+1)}} {{(grid.options.paginationCurrentPage*grid.options.paginationPageSize>grid.options.totalItems?grid.options.totalItems:grid.options.paginationCurrentPage*grid.options.paginationPageSize)}} "
0\">/ {{ paginationApi.getTotalPages() }}
1\"> {{sizesLabel}}
{{grid.options.paginationPageSize}} {{sizesLabel}}
0\">{{(((grid.options.paginationCurrentPage-1)*grid.options.paginationPageSize)+1)}} - {{(grid.options.paginationCurrentPage*grid.options.paginationPageSize>grid.options.totalItems?grid.options.totalItems:grid.options.paginationCurrentPage*grid.options.paginationPageSize)}} {{paginationOf}} {{grid.options.totalItems}} {{totalItemsLabel}}
"; @@ -103,15 +161,15 @@ appDS2.controller("reportSearchController", ['$scope','$rootScope','$http','$tim } else { $scope.gridOptions.columnDefs.push({ displayName: entry.columnTitle, field: entry.columnId, enableSorting: true, + sortingAlgorithm: $scope.getSortingAlgorithm(entry.columnId), cellTemplate: '
{{COL_FIELD.displayValue}}
' }); } }); - + $scope.gridOptions.useExternalPagination=true; $scope.gridOptions.paginationPageSizes= [$scope.searchdData.metaReport.pageSize]; - $scope.gridOptions.paginationPageSize= $scope.searchdData.metaReport.pageSize; + $scope.gridOptions.paginationPageSize= 50;//$scope.searchdData.metaReport.pageSize; $scope.gridOptions.totalItems = $scope.searchdData.metaReport.totalSize; - $scope.gridOptions.data = []; $scope.searchdData.rows[0].forEach(function(entry) { var localData = {}; diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-step-controller.js b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-step-controller.js index 3196b336..43f877c3 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-step-controller.js +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-controllers/ds2-reports/report-step-controller.js @@ -1,1263 +1,763 @@ appDS2.controller('reportStepController', function($scope,$http,$location, $routeParams, $q, $modal,$log,$window, raptorReportFactory, stepFormFactory) { + /*****************Init values*********************/ + $scope.reportIdURL = $routeParams.reportId; + $scope.isEdit = ($scope.reportIdURL==null||$scope.reportIdURL=='')?false:true; + $scope.isDefReady = $scope.isEdit; + $scope.activeTabsId = 'definition'; + $scope.pageMsg ='' + $scope.stepNum = 0; + $scope.stepTabs=[ + { + title: 'Definition', + id: 'definition', + uniqueId: 'uniqueStep1', + tabPanelId: 'definitionTab', + disabled: false + + }, { + title: 'SQL', + id: 'sql', + uniqueId: 'uniqueStep2', + tabPanelId: 'sqlTab', + disabled: (!$scope.isDefReady) + }, { + title: 'Columns', + id: 'columns', + uniqueId: 'uniqueTab3x', + tabPanelId: 'columnsTab', + disabled: (!$scope.isDefReady) + }, { + title: 'Form Fields', + id: 'formFields', + uniqueId: 'uniqueTab4x', + tabPanelId: 'formFieldsTab', + disabled: (!$scope.isDefReady) + }, { + title: 'Security', + id: 'security', + uniqueId: 'uniqueTab5x', + tabPanelId: 'securityTab', + disabled: (!$scope.isDefReady) + }, { + title: 'Log', + id: 'log', + uniqueId: 'uniqueTab6x', + tabPanelId: 'logTab', + disabled: (!$scope.isDefReady) + }, { + title: 'Run', + id: 'run', + uniqueId: 'uniqueTab7x', + tabPanelId: 'runTab', + disabled: (!$scope.isDefReady) + } + + ]; + $scope.$watch('activeTabsId', function (newVal, oldVal) { + if(newVal !== oldVal) { + $scope.init(); + } + }); - $scope.showLoader = true; - // tabs for report wizard steps: - $scope.activeTabsId = 'Definition'; - $scope.addReportUserId = {'id':''}; - $scope.addReportRoleId = {'id':''}; - // For all the dropdown box, please declare the active selection variable in the following manner: - // $scope.selectedOpt = {}; - // $scope.selectedOpt.value = ""; + $scope.renderStep = function(stepNum){ + var containerElement = angular.element(document.getElementById("stepView")); + containerElement.empty(); + $scope.stepNum = stepNum; + var jsonSrcName = getJsonSrcName(stepNum); + stepFormFactory.renderForm(jsonSrcName, containerElement, $scope); + } + $scope.next = function(){ + $scope.stepNum = $scope.stepNum +1; + $scope.activeTabsId = $scope.stepTabs[$scope.stepNum].id; + }; + + + $scope.previous = function(){ + $scope.stepNum = $scope.stepNum -1; + $scope.activeTabsId = $scope.stepTabs[$scope.stepNum].id; + } + + /*******************Step 1 Definitions****************/ + $scope.displayOptions={ + hideFormFields:false, + hideChart:false, + hideReportData:false, + hideExcel:false, + hidePdf:false + } + $scope.reportIdURL = $routeParams.reportId; + $scope.definitionData={}; + $scope.definitionData.displayOptions=[ + {name:'HideFormFields', selected:false}, + {name:'HideChart', selected:false}, + {name:'HideReportData', selected:false}, + {name:'HideExcel', selected:false}, + {name:'HidePdf', selected:false} + ] + + $scope.pageSizeValues=['10','25','50','100','500']; + $scope.pageSizeOptions =[]; + $scope.maxRowValues = ['500','1000','2000','3000','4000','5000','10000','15000','20000','25000','30000','35000','40000','45000','50000','65000'] + $scope.maxRowOptions =[]; + $scope.frozenColValues = ['0','1','2','3','4']; + $scope.frozenColOptions =[]; + $scope.dataGridAlignValues = ['Left','Right','Center']; + $scope.dataGridAlignOptions =[]; + $scope.dataContainerValues = ['10','20','30','40','50','60','70','80','90','100','110','120','130','140','150','160','170','180','190','200']; + $scope.dataContainerOptions =[]; + $scope.runTimeFormNumValues = ['1','2','3','4']; + $scope.runTimeFormNumOptions =[]; + /******create*****/ + if(!$scope.isEdit){ + $scope.definitionData.reportType = 'Linear'; + $scope.definitionData.dbInfo = 'Local'; + } + /****end create***/ + + /*functions*/ $scope.getDefinitionById = function(id) { + $scope.showLoader=true; raptorReportFactory.getDefinitionByReportId(id).then(function(data){ - $scope.loadDefinition(data); + $scope.showLoader=false; $scope.definitionData = data; $scope.showLoader = false; + for(x in data.displayOptions){ + if(data.displayOptions[x].name=='HideFormFields') + $scope.displayOptions.hideFormFields = data.displayOptions[x].selected; + else if(data.displayOptions[x].name=='HideChart') + $scope.displayOptions.hideChart = data.displayOptions[x].selected; + else if(data.displayOptions[x].name=='HideReportData') + $scope.displayOptions.hideReportData = data.displayOptions[x].selected; + else if(data.displayOptions[x].name=='HideExcel') + $scope.displayOptions.hideExcel = data.displayOptions[x].selected; + else if(data.displayOptions[x].name=='HidePdf') + $scope.displayOptions.hidePdf = data.displayOptions[x].selected; + } + + $scope.definitionData.frozenColumns = $scope.definitionData.frozenColumns+''; + $scope.definitionData.numFormCols = $scope.definitionData.numFormCols+''; + $scope.definitionData.allowScheduler = data.allowScheduler=='Y'?true:false; + $scope.definitionData.sizedByContent = data.sizedByContent=='Y'?true:false; + + $scope.definitionData.oneTimeRec = data.oneTimeRec=='Y'?true:false; + $scope.definitionData.hourlyRec = data.hourlyRec=='Y'?true:false; + $scope.definitionData.dailyRec = data.dailyRec=='Y'?true:false; + $scope.definitionData.dailyMFRec = data.dailyMFRec=='Y'?true:false; + $scope.definitionData.weeklyRec = data.weeklyRec=='Y'?true:false; + $scope.definitionData.monthlyRec = data.monthlyRec=='Y'?true:false; + + if($scope.definitionData.reportTitle==null || $scope.definitionData.reportTitle=='') + $scope.definitionData.reportTitle = $scope.definitionData.reportName; },function(error){ - $log.error("raptorReportFactory: getSearchData failed."); + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getDefinitionById failed."); $scope.showLoader = false; }); } - $scope.addReportSecurityUser = function(userId) { - raptorReportFactory.addReportSecurityUser(userId).then(function(data){ - $scope.loadSecurityPage(); - },function(error){ - $log.error("raptorReportFactory: addReportSecurityUser failed."); - }); + $scope.constructureDefDropDown = function(){ + for(i in $scope.pageSizeValues){ + var v = { + value :$scope.pageSizeValues[i], + text :$scope.pageSizeValues[i] + } + $scope.pageSizeOptions.push(v); + } + for(i in $scope.maxRowValues){ + var v = { + value :$scope.maxRowValues[i], + text :$scope.maxRowValues[i] + } + $scope.maxRowOptions.push(v); + } + for(i in $scope.frozenColValues){ + var v = { + value :$scope.frozenColValues[i]+'', + text :$scope.frozenColValues[i] + } + $scope.frozenColOptions.push(v); + } + for(i in $scope.dataGridAlignValues){ + var v = { + value :$scope.dataGridAlignValues[i].toLowerCase(), + text :$scope.dataGridAlignValues[i] + } + $scope.dataGridAlignOptions.push(v); + } + for(i in $scope.dataContainerValues){ + var v = { + value :$scope.dataContainerValues[i], + text :$scope.dataContainerValues[i] + } + $scope.dataContainerOptions.push(v); + } + for(i in $scope.runTimeFormNumValues){ + var v = { + value :$scope.runTimeFormNumValues[i], + text :$scope.runTimeFormNumValues[i] + } + $scope.runTimeFormNumOptions.push(v); + } } - - $scope.removeReportSecurityUser = function(securityUser) { - var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-user-del-confirm.html', - sizeClass: 'modal-large', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory','securityUser', function ($scope, $modalInstance, $http, $log, raptorReportFactory,securityUser) { - $scope.securityUserName = securityUser.name; - $scope.ok = function() { - raptorReportFactory.removeReportSecurityUser(securityUser.id).then(function(data){ - $modalInstance.close(); - },function(error){ - $log.error("raptorReportFactory: removeReportSecurityUser failed."); - }); - } - $scope.cancel = function() { - $modalInstance.dismiss(); - }; - }], - resolve:{ - securityUser: function(){ - return securityUser; - } - } - }); - modalInstance.result.then(function () { - $scope.loadSecurityPage(); - }, function () { - }); - }; - - - $scope.addReportSecurityRole = function(roleId) { - raptorReportFactory.addReportSecurityRole(roleId).then(function(data){ - $scope.loadSecurityPage(); - },function(error){ - $log.error("raptorReportFactory: addReportSecurityRole failed."); - }); - } - - $scope.removeReportSecurityRole = function(securityRole) { - var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-role-del-confirm.html', - sizeClass: 'modal-large', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory','securityRole', function ($scope, $modalInstance, $http, $log, raptorReportFactory,securityRole) { - $scope.securityRoleName = securityRole.name; - $scope.ok = function() { - raptorReportFactory.removeReportSecurityRole(securityRole.id).then(function(data){ - $modalInstance.close(); - },function(error){ - $log.error("raptorReportFactory: removeReportSecurityRole failed."); - }); - } - $scope.cancel = function() { - $modalInstance.dismiss(); - }; - }], - resolve:{ - securityRole: function(){ - return securityRole; - } - } - }); - modalInstance.result.then(function () { - $scope.loadSecurityPage(); - }, function () { - }); - } - $scope.saveReportSecurityInfo = function(userId, isPublic) { - var securityInfo = {'userId':userId+"",'isPublic':isPublic}; - raptorReportFactory.updateReportSecurityInfo(securityInfo).then(function(data){ - $scope.loadSecurityPage(); - },function(error){ - $log.error("raptorReportFactory: updateReportSecurityInfo failed."); - }); - }; - - $scope.createNewDefinition = function() { - raptorReportFactory.createNewDefinition().then(function(data){ - $scope.loadDefinition(data); - $scope.definitionData = data; - $scope.showLoader = false; + $scope.constructDef = function(){ + var data =Object.assign({}, $scope.definitionData); + for(x in $scope.definitionData.displayOptions){ + if($scope.definitionData.displayOptions[x].name=='HideFormFields') + data.displayOptions[x].selected = $scope.displayOptions.hideFormFields + else if($scope.definitionData.displayOptions[x].name=='HideChart') + data.displayOptions[x].selected = $scope.displayOptions.hideChart + else if($scope.definitionData.displayOptions[x].name=='HideReportData') + data.displayOptions[x].selected = $scope.displayOptions.hideReportData + else if($scope.definitionData.displayOptions[x].name=='HideExcel') + data.displayOptions[x].selected = $scope.displayOptions.hideExcel + else if($scope.definitionData.displayOptions[x].name=='HidePdf') + data.displayOptions[x].selected = $scope.displayOptions.hidePdf + } + if(data.pageSize==null || data.pageSize.startsWith("Select")) + data.pageSize = null; + if(data.maxRowsInExcelCSVDownload==null || data.maxRowsInExcelCSVDownload.startsWith("Select")) + data.maxRowsInExcelCSVDownload = null; + if(data.frozenColumns==null || data.frozenColumns.startsWith("Select")) + data.frozenColumns = null; + if(data.dataGridAlign==null || data.dataGridAlign.startsWith("Select")) + data.dataGridAlign = null; + if(data.dataContainerHeight==null || data.dataContainerHeight.startsWith("Select")) + data.dataContainerHeight = null; + if(data.dataContainerWidth ==null || data.dataContainerWidth.startsWith("Select")) + data.dataContainerWidth = null; + if(data.numFormCols ==null || data.numFormCols.startsWith("Select")) + data.numFormCols = null; + + if(!$scope.isEdit) + data.reportId=-1; + if(data.reportTitle==null || data.reportTitle=='') + data.reportTitle = data.reportName; + return data; + } + $scope.updateDef = function(){ + $scope.showLoader=true; + var dataToSave = $scope.constructDef(); + raptorReportFactory.updateDefinition(dataToSave,$scope.isEdit).then(function(data){ + $scope.successPopUp('Definition is updated'); + for(x in $scope.stepTabs){ + $scope.stepTabs[x].disabled=false; + } + $scope.showLoader=false; },function(error){ - $log.error("raptorReportFactory: getSearchData failed."); + $scope.errorPopUp(error); + $log.error("report-step-controller: updateDefinition by Id failed."); }); - } - - var initializeCreateReport = function() { - $scope["selectedReportType"] ={}; - $scope.selectedReportType.value ="linear"; - $scope.selectedReportType2 ={}; - $scope.selectedReportType2.value =""; - $scope.selectedDataSource ={}; - $scope.selectedDataSource.value="local"; - $scope.sqlScript = "SELECT "; - $scope.pageSize = {"value":"50"}; } - - - var loadSqlInSession = function(){ + /*******************Step1 Ends****************/ + /*******************Step2 SQL****************/ + $scope.pageisCreating = false; + $scope.sqlScript={ + value:'' + }; + $scope.sqlTestTableData=''; + /*function*/ + $scope.getSql = function(){ + $scope.showLoader = true; raptorReportFactory.getSqlInSession().then(function(data){ $scope.sqlInSessionJSON = data; - $scope.sqlScript = data.query; - $scope.showLoader = false; + $scope.sqlScript.value = data.query; + $scope.showLoader = false; },function(error){ + $scope.errorPopUp(error); $log.error("raptorReportFactory: getSearchData failed."); }); - }; - - initializeCreateReport(); - if ($routeParams.reportMode) { - if ($routeParams.reportMode=="copy") { - raptorReportFactory.copyReportById($routeParams.reportId).then(function(data){ - $scope.$emit('RefreshInsession'); - },function(error){ - $log.error("raptorReportFactory: deleteFormFieldById failed."); - }); - } else if ($routeParams.reportMode=="import") { - $scope.$emit('RefreshInsession'); - } - } else if ($routeParams.reportId) { - $scope.getDefinitionById($routeParams.reportId); - $scope.isEdit = true; - $scope.reportId = $routeParams.reportId; - } else { - $scope.isEdit = false; - $scope.createNewDefinition(); - } - - - $scope.RunCurrentReport = function (){ - $window.location.href = "#/report_run/c_master="+$scope.reportId+"&refresh=Y"; - } - - $scope.deleteFormField = function(rowData) { - var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-formfield-del-confirm.html', - sizeClass: 'modal-large', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory','rowData', function ($scope, $modalInstance, $http, $log, raptorReportFactory, rowData) { - $scope.tempFieldId = rowData.id; - $scope.ok = function() { - raptorReportFactory.deleteFormFieldById(rowData.id).then(function(data){ - $modalInstance.close(); - },function(error){ - $log.error("raptorReportFactory: deleteFormFieldById failed."); - }); - } - $scope.cancel = function() { - $modalInstance.dismiss(); - }; - }], - resolve:{ - rowData: function(){ - return rowData; - } - } - }); - modalInstance.result.then(function () { - $scope.$emit('RefreshFormField'); - }, function () { - }); - } - - $scope.loadDefinition = function(definitionData) { - $scope.reportId = definitionData.reportId+""; - $scope.reportName = definitionData.reportName; - $scope.reportDescr = definitionData.reportDescr; - $scope.formHelpText = definitionData.formHelpText; - $scope.selectedPageSize = {"value": definitionData.pageSize+''}; - $scope.selectedMaxRowsInExcelCSVDownload = {"value": definitionData.maxRowsInExcelCSVDownload}; - $scope.reportTitle = definitionData.reportTitle; - $scope.reportSubTitle = definitionData.reportSubTitle; - $scope.selectedNumFormCols ={"value": definitionData.numFormCols+''}; - $scope.selectedFrozenColumns={"value": definitionData.frozenColumns+''}; - $scope.selectedDataGridAlign = {"value":definitionData.dataGridAlign+''}; - $scope.emptyMessage = definitionData.emptyMessage+''; - $scope.selectedDataContainerHeight = {"value":definitionData.dataContainerHeight+''}; - $scope.selectedDataContainerWidth = {"value":definitionData.dataContainerWidth+''}; - var displayAreaValue = "null" - for (var i=0; i<3; i++ ) { - if (definitionData.displayArea[i].selected) { - displayAreaValue = definitionData.displayArea[i].name; - } - } - $scope.selectedDisplayArea = {"value":displayAreaValue+""}; - - $scope.hideFormFieldsAfterRunSelected = {"value": definitionData.hideFormFieldsAfterRun} - - $scope.hideFormFieldsSelected = {"value":definitionData.displayOptions[0].selected}; - $scope.hideChartSelected = {"value":definitionData.displayOptions[1].selected}; - $scope.hideReportDataSelected = {"value":definitionData.displayOptions[2].selected}; - $scope.hideExcelSelected = {"value":definitionData.displayOptions[3].selected}; - $scope.hidePdfSelected = {"value":definitionData.displayOptions[4].selected}; - $scope.runtimeColSortDisabled = {"value":definitionData.runtimeColSortDisabled}; - $scope.showLoader = false; - } - - - var setDefinition = function(){ - $scope.updatedDefJson = { - "tabName" : "Definition", - "tabId" : "Def", - "reportId" : ($scope.isEdit?$scope.reportId+'':"-1"), - "reportName" : $scope.reportName, - "reportDescr" : $scope.reportDescr, - "reportType" : "Linear", - "dbInfo" : "local", - "formHelpText" : $scope.formHelpText, - "pageSize" : Number($scope.selectedPageSize.value), - "displayArea" : [ { - "id" : "HOME", - "name" : "HOME", - "selected" : ($scope.selectedDisplayArea.value=="HOME") - }, { - "id" : "CUSTOMER", - "name" : "CUSTOMER", - "selected" : ($scope.selectedDisplayArea.value==="CUSTOMER") - }, { - "id" : "REPORTS", - "name" : "REPORTS", - "selected" : ($scope.selectedDisplayArea.value==="REPORTS") - } ], - "hideFormFieldsAfterRun" : $scope.hideFormFieldsAfterRunSelected.value, - "maxRowsInExcelCSVDownload" : Number($scope.selectedMaxRowsInExcelCSVDownload.value), - "frozenColumns" : Number($scope.selectedFrozenColumns.value), - "dataGridAlign" : $scope.selectedDataGridAlign.value, - "emptyMessage" : $scope.emptyMessage, - "dataContainerHeight" : $scope.selectedDataContainerHeight.value, - "dataContainerWidth" : $scope.selectedDataContainerWidth.value, - "displayOptions" : [ { - "name" : "HideFormFields", - "selected" : $scope.hideFormFieldsSelected.value - }, { - "name" : "HideChart", - "selected" : $scope.hideChartSelected.value - }, { - "name" : "HideReportData", - "selected" : $scope.hideReportDataSelected.value - }, { - "name" : "HideExcel", - "selected" : $scope.hideExcelSelected.value - }, { - "name" : "HidePdf", - "selected" : $scope.hidePdfSelected.value - } ], - "runtimeColSortDisabled" : $scope.runtimeColSortDisabled.value, - "numFormCols" : Number($scope.selectedNumFormCols.value), - "reportTitle" : $scope.reportTitle, - "reportSubTitle" : $scope.reportSubTitle - } - } - - var updateDefinitionData = function() { - setDefinition(); - raptorReportFactory.updateDefinition($scope.updatedDefJson,$scope.isEdit).then(function(data){ - },function(error){ - $log.error("raptorReportFactory: updateDefinition by Id failed."); - }); - } - - var saveNewDefinitionData = function() { - setDefinition(); - raptorReportFactory.saveNewDefinition($scope.updatedDefJson).then(function(data){ - },function(error){ - $log.error("raptorReportFactory: saveNewDefinition by Id failed."); - }); - } - $scope.testRunSql = function(){ - var queryJSON = {query: $scope.sqlScript}; + $scope.showLoader=true; + var queryJSON = {query: $scope.sqlScript.value}; queryJSON = JSON.stringify(queryJSON); raptorReportFactory.testRunSQL(queryJSON).then(function(data){ + $scope.showLoader=false; var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html', - sizeClass: 'modal-large', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory','queriedData', function ($scope, $modalInstance, $http, $log, raptorReportFactory, queriedData) { - var init = function() { - $scope.isError = false; - if (queriedData.errormessage) { - $scope.isError = true; - $scope.errormessage = queriedData.errormessage; - $scope.stacktrace = queriedData.stacktrace; - } else { - $scope.queryData = queriedData; - } - } - init(); - $scope.close = function() { - $modalInstance.dismiss(); - }; - }], + scope: $scope, + animation: $scope.animationsEnabled, + templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html', + windowClass:'modal-docked', + sizeClass: 'modal-large', + controller: testRunSqlController, resolve:{ queriedData: function(){ - return data; + return data; } - } - }) + } + }); + modalInstance.result.finally(function () { + if(!$scope.isEdit){ + $scope.showLoader=true; + $scope.pageisCreating = true; + $scope.pageMsg = 'Please wait while we are creating the report. Page will be reloaded after the creation is done.' + raptorReportFactory.getDefinitionInSession().then(function(data){ + var newReportId = data.reportId; + if(newReportId!=null && newReportId!='' && newReportId!=-1) + $window.location.href = "#/report_wizard/"+newReportId; + + $scope.showLoader = false; + $scope.pageisCreating = false; + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: get Definition In Session failed."); + $scope.showLoader = false; + }); + } + }); + },function(error){ + $scope.errorPopUp(error); $log.error("raptorReportFactory: test run SQL failed."); }); } + + /*******************Step2 End****************/ + /*******************Step3 Column****************/ + $scope.colTableRowData=''; + $scope.isEditCol= true; + + $scope.getColumn = function(){ + $scope.showLoader = true; + raptorReportFactory.getColumnList().then(function(data){ + $scope.colTableRowData = data; + $scope.showLoader = false; + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: get column list failed."); + }); + } + + $scope.openColumnPopup = function (rowData) { + var modalInstance = $modal.open({ + scope: $scope, + animation: $scope.animationsEnabled, + templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-col-edit.html', + windowClass:'modal-docked', + sizeClass: 'modal-jumbo', + controller: openColumnPopupController, + resolve:{ + colData: function(){ + return rowData; + } + } + }); + modalInstance.result.finally(function () { + $scope.getColumn(); + }); + }; + /*******************Step3 End****************/ + /*******************Step4 Starts Form Fields****************/ + + $scope.dataProcessing = false; + $scope.formFieldData = []; + $scope.getFormFieldList = function(){ + $scope.showLoader= true; + $scope.formFieldData = []; + raptorReportFactory.getFormFieldList().then(function(data){ + $scope.showLoader= false; + $scope.formFieldData = data; + $scope.formFieldData.sort(function(obj1, obj2) { + // Ascending: first age less than the previous + return obj1.orderSeq - obj2.orderSeq; + }); + $scope.showLoader = false; + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: get formfields failed."); + $scope.showLoader = false; + }); + } + + $scope.formFieldReOrder = function(upID, downID){ + + $scope.moveUpFF={}; + $scope.moveDownFF={}; + $scope.showLoader=true; + raptorReportFactory.getFormFieldEditInfoById(upID).then(function(data){ + $scope.moveUpFF = data; + raptorReportFactory.getFormFieldEditInfoById(downID).then(function(data){ + $scope.moveDownFF = data; + var downOrder = $scope.moveDownFF.orderSeq; + $scope.moveDownFF.orderSeq = $scope.moveUpFF.orderSeq; + $scope.moveUpFF.orderSeq = downOrder; + raptorReportFactory.saveFormFieldEditInfo($scope.moveDownFF).then(function(data){ + raptorReportFactory.saveFormFieldEditInfo($scope.moveUpFF).then(function(data){ + $scope.successPopUp(''); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: saveFormFieldEditInfo failed."); + }).finally(function() { + $scope.showLoader=false; + $scope.getFormFieldList(); + }) + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: saveFormFieldEditInfo failed."); + }); + + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getColumnEditInfoById failed."); + }); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getColumnEditInfoById failed."); + }) + + + } + $scope.formFieldVerifySQL= function(sqlScript){ var queryJSON = {query: sqlScript}; queryJSON = JSON.stringify(queryJSON); raptorReportFactory.formFieldVerifySQL(queryJSON).then(function(data){ var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html', - sizeClass: 'modal-large', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory','queriedData', function ($scope, $modalInstance, $http, $log, raptorReportFactory, queriedData) { - var init = function() { - $scope.isError = false; - if (queriedData.errormessage) { - $scope.isError = true; - $scope.errormessage = queriedData.errormessage; - $scope.stacktrace = queriedData.stacktrace; - } else { - $scope.queryData = queriedData; - } - } - init(); - $scope.close = function() { - $modalInstance.dismiss(); - }; - }], + scope: $scope, + animation: $scope.animationsEnabled, + templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html', + sizeClass: 'modal-large', + controller: formFieldVerifySQLController, resolve:{ queriedData: function(){ - return data; + return data; } - } - }) - + } + }) + },function(error){ + $scope.errorPopUp(error); $log.error("raptorReportFactory: test run SQL failed."); }); } - /* $scope.selectedDataSource.allowSchedule={}; - $scope.selectedDataSource.allowSchedule.value=""*/ - - var getJsonSrcName = function(stepNum){ - var JsonSrcPrefix = "app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/json/step" - return JsonSrcPrefix + stepNum +".json"; - } - - $scope.gTabs = [ - { - title: 'Definition', - id: 'Definition', - uniqueId: 'uniqueTab1x', - tabPanelId: 'threetab1x' - }, { - title: 'SQL', - id: 'SQL', - uniqueId: 'uniqueTab2x', - tabPanelId: 'threetab2x', - disabled: (!$scope.isEdit) - }, { - title: 'Columns', - id: 'Columns', - uniqueId: 'uniqueTab3x', - tabPanelId: 'threetab3x', - disabled: (!$scope.isEdit) - }, { - title: 'Form Fields', - id: 'Form Fields', - uniqueId: 'uniqueTab4x', - tabPanelId: 'threetab4x', - disabled: (!$scope.isEdit) - }, { - title: 'Security', - id: 'Security', - uniqueId: 'uniqueTab5x', - tabPanelId: 'threetab5x', - disabled: (!$scope.isEdit) - }, { - title: 'Run', - id: 'Run', - uniqueId: 'uniqueTab6x', - tabPanelId: 'threetab6x', - disabled: (!$scope.isEdit) - } - ]; - - $scope.unhideAllOtherTabs = function(){ - for (var selectedTab = 0; selectedTab < $scope.gTabs.length; selectedTab++) { - $scope.gTabs[selectedTab].disabled = false; - } - } - - $scope.openColumnPopup = function (rowData) { - var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-col-edit.html', - sizeClass: 'modal-large', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory','colData', function ($scope, $modalInstance, $http, $log, raptorReportFactory, colData) { - raptorReportFactory.getColumnEditInfoById(colData.id).then(function(data){ - $scope.columnEditData = data; - $scope.colId = data.colId; -/* $scope.colName = data.colName;*/ - $scope.colName = {'value':data.colName+''}; - $scope.selectedDisplayAlignment = {"value":data.displayAlignment+''}; - $scope.selectedDisplayHeaderAlignment = {"value":data.displayHeaderAlignment+''}; - $scope.sortable = {"value":''+data.sortable}; - $scope.visible = {"value":''+data.visible}; - $scope.drilldownURL = data.drilldownURL; - $scope.drilldownParams = data.drilldownParams; - $scope.drilldownType = data.drilldownType; - $scope.selectedDrillDownReport = {"value":""}; - - - },function(error){ - $log.error("raptorReportFactory: getColumnEditInfoById failed."); - }); - - var init = function() { - - raptorReportFactory.getDrillDownReportList().then(function(data2){ - $scope.drilldownReports = data2; - },function(error){ - $log.error("raptorReportFactory: getDrillDownReportList failed."); - }); - -/* $scope.colTableRowData = colData;*/ - $scope.displayAlignmentOptions = [ - {value:"null", text:""}, - {value:"Left", text:"Left"}, - {value:"Center", text:"Center"}, - {value:"Right", text:"Right"} - ]; - $scope.ynOptions = [ - {value:"true", text:"Yes"}, - {value:"false", text:"No"} - ]; - $scope.drillDownOptions = [ - {value:"drillDownOpt1", text:"drillDownOpt1"}, - {value:"drillDownOpt2", text:"drillDownOpt2"}, - {value:"drillDownOpt3", text:"drillDownOpt3"} - ]; - } - - init(); - $scope.$watch('selectedDrillDownReport.value',function(){ - if ($scope.selectedDrillDownReport) { - $scope.$emit('openDrillDownpage',$scope.selectedDrillDownReport.value); - } - }); - - $scope.save = function() { - var drilldownURL = "";//raptorReportFactory.drillDownPopupOptions - //raptorReportFactory.drillDownPopupOptions.radioGroup - var colInfo = { - "tabId" : "ColEdit", - "tabName" : "Column Edit", - "colId" : $scope.colId, - "colName" : $scope.colName.value, - "displayAlignment" : ($scope.selectedDisplayAlignment.value=="null")?null:$scope.selectedDisplayAlignment.value, - "displayHeaderAlignment" : ($scope.selectedDisplayHeaderAlignment.value=="null")?null:$scope.selectedDisplayHeaderAlignment.value, - "sortable" : ($scope.sortable.value=="true"), - "visible" : ($scope.visible.value=="true"), - "drilldownURL" : raptorReportFactory.drillDownURL, - "drilldownParams" : raptorReportFactory.drillDownParams, - "drilldownType" : "" - } - raptorReportFactory.saveColumnEditInfo(colInfo).then(function(data){ - $modalInstance.close(); - },function(error){ - $log.error("raptorReportFactory: getColumnEditInfoById failed."); - }); - }; - - $scope.cancel = function() { - $modalInstance.dismiss(); - }; - }], - resolve:{ - colData: function(){ - return rowData; - } - } - }); - - modalInstance.result.then(function () { - $scope.$emit('RefreshColumnList'); - }, function () { - }); - }; - - - $scope.throwReportNameMissingError = function () { - var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-report-name-validation.html', - sizeClass: 'modal-small', - controller: ['$scope', '$modalInstance', '$http', '$log', function ($scope, $modalInstance, $http, $log) { - $scope.close = function() { - $modalInstance.dismiss(); - }; - }] - }); - modalInstance.result.then(function () { - }, function () { - }); - }; - - - $scope.addNewFormField = function () { - var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html', - sizeClass: 'modal-large', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory', function ($scope, $modalInstance, $http, $log, raptorReportFactory) { - raptorReportFactory.getFormFieldEditInfoById("add").then(function(data){ - $scope.formFieldEditData = data; - $scope.fieldId = $scope.formFieldEditData.fieldId; - $scope.fieldName ={"value": $scope.formFieldEditData.fieldName}; - $scope.selectedVisible = {"value":$scope.formFieldEditData.visible+''}; - $scope.defaultValue = {"value": $scope.formFieldEditData.defaultValue}; - $scope.fieldDefaultSQL = {"value": $scope.formFieldEditData.fieldDefaultSQL}; - $scope.fieldSqlContent = {"value": $scope.formFieldEditData.fieldSQL}; - $scope.selectedValidationType = {"value":$scope.formFieldEditData.validationType +''}; - $scope.selectedFieldType = {"value":$scope.formFieldEditData.fieldType +''}; - $scope.sqlDefaultValueSelected= {value:false}; - $scope.sqlDefaultValueSelected ={"value":false}; - if (($scope.fieldDefaultSQL.value)&&($scope.fieldDefaultSQL.value!="")) { - $scope.sqlDefaultValueSelected.value =true; - } - },function(error){ - $log.error("raptorReportFactory: getColumnEditInfoById failed."); - }); - - - $scope.ynOptions = [ - {value:"true", text:"Yes"}, - {value:"false", text:"No"} - ]; - - $scope.verifyFieldValueOptions = [ - {value:"DATE", text:"Date"}, - {value:"TIME_STAMP_HOUR", text:"TimeStamp (Hour)"}, - {value:"TIME_STAMP_HOUR_MIN", text:"TimeStamp (Hour,Min)"}, - {value:"HIDDEN", text:"Hidden"} - ] - - $scope.fieldTypeOptions = [ - {value:"TEXT", text:"Text Box"}, - {value:"LIST_BOX", text:"List Box"}, - {value:"LIST_MULTI_SELECT", text:"Multi-select List Box"}, - {value:"HIDDEN", text:"Hidden"} - ]; - - $scope.save = function() { - var formFieldJSON = { - "tabId" : "FormEdit", - "tabName" : "Form Edit", - "fieldId" : $scope.fieldId, - "fieldName" : $scope.fieldName.value, - "fieldType" : $scope.selectedFieldType.value, - "visible" : ($scope.selectedVisible.value=="true"), - "defaultValue" : ($scope.sqlDefaultValueSelected.value?'':$scope.defaultValue.value), - "fieldDefaultSQL" : ($scope.sqlDefaultValueSelected.value?$scope.fieldDefaultSQL.value:""), - "fieldSQL" :$scope.fieldSqlContent.value, - "validationType" : "NONE", - "predefinedValueList" :null - } - raptorReportFactory.saveFormFieldEditInfo(formFieldJSON).then(function(data){ - $modalInstance.close(); - },function(error){ - $log.error("raptorReportFactory: saveFormFieldEditInfo failed."); - }); - }; - - $scope.cancel = function() { - $modalInstance.dismiss(); - }; - }] - }); - modalInstance.result.then(function () { - $scope.$emit('RefreshFormField'); - }, function () { - }); - }; - - $scope.openFormFieldPopup = function (rowData) { - var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html', - sizeClass: 'modal-large', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory','fieldData', function ($scope, $modalInstance, $http, $log, raptorReportFactory, fieldData) { - var init = function() { - raptorReportFactory.getFormFieldEditInfoById(fieldData.id).then(function(data){ - $scope.formFieldEditData = data; - $scope.fieldId = $scope.formFieldEditData.fieldId; - $scope.fieldName = {"value":$scope.formFieldEditData.fieldName}; - $scope.selectedVisible = {"value":$scope.formFieldEditData.visible+''}; - $scope.defaultValue = {"value":$scope.formFieldEditData.defaultValue}; - $scope.fieldDefaultSQL = {"value": $scope.formFieldEditData.fieldDefaultSQL}; - $scope.fieldSqlContent = {"value": $scope.formFieldEditData.fieldSQL}; - $scope.selectedValidationType = {"value":$scope.formFieldEditData.validationType +''}; - $scope.selectedFieldType = {"value":$scope.formFieldEditData.fieldType +''}; - $scope.sqlDefaultValueSelected ={"value":false}; - if (($scope.fieldDefaultSQL.value)&&($scope.fieldDefaultSQL.value!="")) { - $scope.sqlDefaultValueSelected.value =true; - } - },function(error){ - $log.error("raptorReportFactory: getColumnEditInfoById failed."); - }); - - $scope.ynOptions = [ - {value:"true", text:"Yes"}, - {value:"false", text:"No"} - ]; - - $scope.verifyFieldValueOptions = [ - {value:"DATE", text:"Date"}, - {value:"TIME_STAMP_HOUR", text:"TimeStamp (Hour)"}, - {value:"TIME_STAMP_HOUR_MIN", text:"TimeStamp (Hour,Min)"}, - {value:"HIDDEN", text:"Hidden"} - ] - - $scope.fieldTypeOptions = [ - {value:"TEXT", text:"Text Box"}, - {value:"LIST_BOX", text:"List Box"}, - {value:"LIST_MULTI_SELECT", text:"Multi-select List Box"}, - {value:"HIDDEN", text:"Hidden"} - ]; - - } - - init(); - - $scope.save = function() { - var formFieldJSON = { - "tabId" : "FormEdit", - "tabName" : "Form Edit", - "fieldId" : $scope.fieldId, - "fieldName" : $scope.fieldName.value, - "fieldType" : $scope.selectedFieldType.value, - "visible" : ($scope.selectedVisible.value=="true"), - "defaultValue" : ($scope.sqlDefaultValueSelected.value?'':$scope.defaultValue.value), - "fieldDefaultSQL" : ($scope.sqlDefaultValueSelected.value?$scope.fieldDefaultSQL.value:""), - "fieldSQL" :$scope.fieldSqlContent.value, - "validationType" : "NONE", - "predefinedValueList" :null - } - raptorReportFactory.saveFormFieldEditInfo(formFieldJSON).then(function(data){ - $modalInstance.close(); - },function(error){ - $log.error("raptorReportFactory: saveFormFieldEditInfo failed."); - }); - }; - - $scope.cancel = function() { - $modalInstance.dismiss(); - }; - }], - resolve:{ - fieldData: function(){ - return rowData; - } - } - }); - - modalInstance.result.then(function () { - $scope.$emit('RefreshFormField'); - }, function () { - }); - }; - - $scope.openDrillDownReportPopup = function (reportId,parentReportId) { - var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-drilldown-edit.html', - sizeClass: 'modal-large', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory','reportId', function ($scope, $modalInstance, $http, $log, raptorReportFactory, reportId) { - - $scope.drillDownOptionList =[]; - $scope.selectedvalueradioGroup = {"name":""}; - $scope.selectedChildReportFormField = {"value":""}; - $scope.selectedChildReportColumn = {"value":""}; - $scope.fixedValue = {"value":""}; - $scope.suppressValues = {"value":""}; + $scope.openFormFieldPopup = function (rowData,type) { + $scope.type= type; + var modalInstance = $modal.open({ + scope: $scope, + animation: true, + templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html', + sizeClass: 'modal-large', + controller: openFormFieldPopupController, + resolve:{ + fieldData: function(){ + return rowData; + } + } + }); - raptorReportFactory.getChildReportFormField(reportId).then(function(data){ - for (var i=0;i1){ - $scope.unhideAllOtherTabs(); - } - break; - } - } - } - }); - - $scope.loadSecurityPage = function() { - $scope.showLoader = true; - raptorReportFactory.resetSecurityLoadingCounter(); - - //API call 1: + //API call 1: raptorReportFactory.getSecurityReportOwnerList().then(function(data){ - $scope.reportOwnerList = data; + $scope.reportOwnerList = data; raptorReportFactory.icrementSecurityLoadingCounter(); if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;}; - },function(error){ - $log.error("raptorReportFactory: getSecurityReportOwnerList failed."); - }); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getSecurityReportOwnerList failed."); + }); //API call 2: get report role list raptorReportFactory.getReportRoleList().then(function(data){ - $scope.reportRoleList = data; + $scope.reportRoleList = data; raptorReportFactory.icrementSecurityLoadingCounter(); if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;}; },function(error){ - $log.error("raptorReportFactory: getReportRoleList failed."); - }); + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getReportRoleList failed."); + }); //API call 3: get security page basic info raptorReportFactory.getReportSecurityInfo().then(function(data){ - $scope.reportSecurityInfo = data; - $scope.reportOwnerId ={id: $scope.reportSecurityInfo.ownerId}; + $scope.reportSecurityInfo = data; + $scope.reportOwnerId ={id: $scope.reportSecurityInfo.ownerId}; raptorReportFactory.icrementSecurityLoadingCounter(); if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;}; - },function(error){ - $log.error("raptorReportFactory: getReportSecurityInfo failed."); - $scope.showLoader = false;}); - + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getReportSecurityInfo failed."); + $scope.showLoader = false;}); + //API call 4: retrieve security users raptorReportFactory.getReportSecurityUsers().then(function(data){ - $scope.reportSecurityUsers = data; - for (var i=0; i<$scope.reportSecurityUsers.length;i++) { - $scope.reportSecurityUsers[i]["accessAllowed"] = !$scope.reportSecurityUsers[i]["readOnly"]; - } - raptorReportFactory.icrementSecurityLoadingCounter(); + + $scope.reportSecurityUsers = data; + for (var i=0; i<$scope.reportSecurityUsers.length;i++) { + $scope.reportSecurityUsers[i]["accessAllowed"] = !$scope.reportSecurityUsers[i]["readOnly"]; + $scope.reportSecurityUsers[i].runAccess = true; // need to check why 1702 version is making it true always + } + raptorReportFactory.icrementSecurityLoadingCounter(); if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;}; - },function(error){ - $log.error("raptorReportFactory: reportSecurityUsers failed."); - }); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: reportSecurityUsers failed."); + }); //API call 5: retrieve security roles raptorReportFactory.getReportSecurityRoles().then(function(data){ - $scope.reportSecurityRoles = data; - for (var i=0; i<$scope.reportSecurityRoles.length;i++) { - $scope.reportSecurityRoles[i]["accessAllowed"] = !$scope.reportSecurityRoles[i]["readOnly"]; - } - + $scope.reportSecurityRoles = data; + for (var i=0; i<$scope.reportSecurityRoles.length;i++) { + $scope.reportSecurityRoles[i]["accessAllowed"] = !$scope.reportSecurityRoles[i]["readOnly"]; + $scope.reportSecurityRoles[i].runAccess = true; // need to check why 1702 version is making it true always + } + raptorReportFactory.icrementSecurityLoadingCounter(); if(raptorReportFactory.checkSecurityLoadingCounter()){$scope.showLoader = false;}; - },function(error){ - $log.error("raptorReportFactory: reportSecurityRoles failed."); - }); - } - - - $scope.renderStep = function(stepNum){ - var containerElement = angular.element(document.getElementById("stepView")); - containerElement.empty(); - $scope.stepNum = stepNum; - var jsonSrcName = getJsonSrcName(stepNum); - stepFormFactory.renderForm(jsonSrcName, containerElement, $scope); - } - - $scope.toggleUserEditAccessActive = function(rowData) { - var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html', - sizeClass: 'modal-small', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory','rowData', function ($scope, $modalInstance, $http, $log, raptorReportFactory, rowData) { - $scope.rowData = rowData; - $scope.toggleEditAccessStatus = function(rowData) { - raptorReportFactory.toggleUserEditAccess(rowData); - $modalInstance.close(); - }; - - $scope.cancelEditAccessToggle = function(rowData) { - rowData.accessAllowed = ! rowData.accessAllowed; - $modalInstance.dismiss('cancel');} - }], - resolve:{ - rowData: function(){ - return rowData; - } - } - }); - modalInstance.result.then(function () { - - }, function () { - }); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: reportSecurityRoles failed."); + }); } - - $scope.toggleRoleEditAccessActive = function(rowData) { - var modalInstance = $modal.open({ - scope: $scope, - animation: $scope.animationsEnabled, - templateUrl: 'app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html', - sizeClass: 'modal-small', - controller: ['$scope', '$modalInstance', '$http', '$log','raptorReportFactory','rowData', function ($scope, $modalInstance, $http, $log, raptorReportFactory, rowData) { - $scope.rowData = rowData; - $scope.toggleEditAccessStatus = function(rowData) { - raptorReportFactory.toggleRoleEditAccess(rowData); - $modalInstance.close(); - }; - - $scope.cancelEditAccessToggle = function(rowData) { - rowData.accessAllowed = ! rowData.accessAllowed; - $modalInstance.dismiss('cancel');} - }], - resolve:{ - rowData: function(){ - return rowData; - } - } - }); - modalInstance.result.then(function () { - - }, function () { - }); + $scope.addReportSecurityUser = function(userId) { + $scope.showLoader=true; + raptorReportFactory.addReportSecurityUser(userId).then(function(data){ + $scope.loadSecurityPage(); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: addReportSecurityUser failed."); + }).finally(function() { + $scope.showLoader=false; + }); } - - - - - - // initialize the page at step 1; - $scope.renderStep(1); - - // create a message to display in our view - $scope.allProjects = []; - if(!$routeParams.step && $routeParams.step == "") $routeParams.step = 1; - if($routeParams.proj && $routeParams.proj > 0) - $scope.projid = $routeParams.proj; - if($routeParams.step) - $scope.stepNum = $routeParams.step; - else - $scope.stepNum = 1; - - $scope.jsonSrcName = getJsonSrcName($scope.stepNum); - - $scope.selectAction = function () { - var containerElement = angular.element(document.getElementById("stepView")); - containerElement.empty(); - $scope.project_name = this.prj.projectName; - $scope.stepNum = 1; - var stepNum = $scope.stepNum; - var jsonSrcName = getJsonSrcName(stepNum); - stepFormFactory.renderForm(jsonSrcName, containerElement, $scope); - renderProject(this.prj.id, 1); - }; - - - $scope.createAction = function () { - var containerElement = angular.element(document.getElementById("stepView")); - containerElement.empty(); - $scope.stepNum = 1; - var stepNum = $scope.stepNum; - $scope.jsonSrcName = "app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/json/step"+$scope.stepNum +".json"; - var jsonSrcName = $scope.jsonSrcName; - stepFormFactory.renderForm(jsonSrcName, containerElement, $scope); - }; - // select current project - renderProject = function (proj_id, stepNum) { - var userSelectedPrjId = proj_id; - $http({ - method: 'GET', - url: 'get_selected_project_data', - params:{'selectedPrjId':userSelectedPrjId, 'step': stepNum} - }).then(function successCallback(response) { - var selectedproject = response.data; - $scope.projid = userSelectedPrjId; - //$scope.allProjects = projectLists; - //$location.path('/'+userSelectedPrjId+'/'+stepNum); - var div = d3.select("#stepView"); - div.select("[name='proj_id']").text(userSelectedPrjId); - div.select("[name='proj_id']").property("value", userSelectedPrjId); - d3.select("[name='project_id']").property("value", userSelectedPrjId); - var h3Text = div.select("h3").text(); - div.select("h3").text($scope.project_name+ " - " + h3Text); - for (var key in selectedproject) { - if (selectedproject.hasOwnProperty(key)) { - var val = selectedproject[key]; - var formElement = d3.selectAll("[name='" + key + "']"); - if(formElement[0].length > 0) - console.log(formElement.attr("type")); - if(formElement[0].length > 0 && formElement.attr("type") === "radio") { - var formRadio = d3.selectAll("[id='" + key +"_"+val + "']"); - formRadio.property('checked', true); - } - if(formElement[0].length > 0 && formElement.property("type") === "textarea") { - div.select("textarea[name='" + key +"']").property('value', val); - } - if(formElement[0].length > 0 && formElement.attr("type") === "text") { - var formText = d3.selectAll("[name='" + key + "']"); - formText.property("value", val); - } - if(formElement[0].length > 0 && formElement.html().startsWith(" 0 && formElementOther.attr("type") === "checkbox") { - var formCheckbox = d3.selectAll("[name='" + key +"_"+val + "']"); - formRadio.property('checked', true); - } - } - } - } - - - - }); - } - - //submit function - $scope.submit = function(){ - let defer = $q.defer(); - - var div = d3.select("#stepView"); - var jsonSrcName = $scope.jsonSrcName; - var stepNum = $scope.stepNum; - var values = ""; - $http({ - method: 'GET', - url: jsonSrcName - }).then(function successCallback(response) { - var json = response.data; - var step = json.step; - if(step > 0) { - var sections = json.content.sections; - sections.forEach(function(d, i) { - var elements = d.elements; - if(elements) { - //elements.forEach(function(element, elementIndex) { - values += "{"; - values += "\"step\""+ ":\"" + step + "\","; - values += "\"proj_id\""+ ":\"" + d3.select('input[name="project_id"]').property("value") + "\","; - - for (elementIndex = 0; elementIndex < elements.length; elementIndex++) { - var element = elements[elementIndex]; - - if(elementIndex > 0) values += ","; - values += "\""+element.name +"\""+ ":" ; - if(element.input === "hidden") { - values += "\""+div.select('input[name="'+element.name+'"]').property("value") +"\""; - } - if(element.input === "radio") { - values += "\""+ div.select('input[name="'+element.name+'"]:checked').property("value") +"\""; - } - if(element.input === "checkbox") { - var checkOptions = element.options; - values += "[{"; - checkOptions.forEach(function(d, i) { - // if(document.getElementById("'"+element.name+"_"+d.id+"'") != null) - values += "\""+d.id+"\""+ ":" + div.select('input[name="'+element.name+"_"+d.id+'"]').property("checked") ; - if(i=($scope.drilDownFormField.length-1)){ + var id = $scope.drilDownFormField[i].id; + drillDownParams+= id+"="; + } + }else + drillDownParams+=$scope.drillDownParams[i].fieldName+"="; + if( selectedRadio == (i+'-1')){//'Fixed Value' + drillDownParams+= $scope.drillDownParams[i].valValue+ampStr; + }else if( selectedRadio == (i+'-2')){//'Value of Column' + drillDownParams+= ('['+$scope.drillDownParams[i].valColId+']'+ampStr); + }else if( selectedRadio == (i+'-3')){//'Value of form field' + drillDownParams+= ('[!'+$scope.drillDownParams[i].valFieldId+']'+ampStr); + }else if( selectedRadio == (i+'-4')){//'Value set' + if($scope.drillDownParams[i].valColId!='' && $scope.drillDownParams[i].valFieldId!='' && $scope.drillDownParams[i].valColId!='Select' && $scope.drillDownParams[i].valFieldId!='Select') + drillDownParams+= ('['+$scope.drillDownParams[i].valColId+'!'+$scope.drillDownParams[i].valFieldId+']'+ampStr); + } + } + } + drillDownParams = drillDownParams.substring(0, drillDownParams.length - 1); + $scope.colInfo.drilldownParams = drillDownParams; + $scope.isEditCol=true; + }; + $scope.selectedDrillReportFormField = []; + $scope.drillDownParams = {}; + $scope.getDrillReportFormField = function(ddReportId,param){ + $scope.isEditCol = false; + $scope.processingData = true; + + raptorReportFactory.getChildReportFormField(ddReportId).then(function(data){ + $scope.drilDownFormField = data; + for(var i in data){ + var array = [ + {selection: 'No Value', value:'Accept Default', radioGroup :i+'-'+'0'}, + {selection: 'Fixed Value', value:'Accept Default' , radioGroup :i+'-'+'1'}, + {selection: 'Value of Column', value:'Accept Default', radioGroup :i+'-'+'2'}, + {selection: 'Value of form field', value:'Accept Default', radioGroup :i+'-'+'3'}, + {selection: 'Value set', value:'Pass the value of the selected column if not empty, otherwise pass the value of the selected form field', radioGroup :i+'-'+'4'} + ] + $scope.drilDownValues.push(array); + } + + if(param!=''){ + raptorReportFactory.getDrillDownParamDef(param).then(function(dataDD){ + var temp = $scope.drilDownFormField; + $scope.drillDownParams = []; + for(var i in $scope.drilDownFormField){ + $scope.selectedDrillReportFormField[i] = i+'-0'; + var tmp = { + fieldName: $scope.drilDownFormField[i].id, + valColId:'', + ValFieldId:'', + valType:'', + valValue:'' + }; + $scope.drillDownParams.push(tmp); + } + for(var i in $scope.drilDownFormField){ + for(var j in dataDD){ + if($scope.drilDownFormField[i].id == dataDD[j].fieldName){ + $scope.selectedDrillReportFormField[i] = i+'-'+dataDD[j].valType; + $scope.drillDownParams[i] = dataDD[j]; + } + } + } + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getChildReportFormField failed."); + }).finally(function() { + $scope.processingData=false; + }); + }else{ + $scope.processingData = false; + } + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getChildReportFormField failed."); + }); + + raptorReportFactory.getChildReportFormField($scope.colInfo.drilldownURL).then(function(data){ + $scope.childReportFF =data; + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getChildReportFormField failed."); + }); + + raptorReportFactory.getChildReportColumn($routeParams.reportId).then(function(data){ + $scope.childReportCol =data; + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getChildReportFormField failed."); + }); + } +} + + +var openFormFieldPopupController = function ($scope, $modalInstance, $http, $log, raptorReportFactory, fieldData) { + $scope.formFieldEditData = {}; + $scope.sqlAsDefaultValue ={ + value:false + }; + $scope.predefinedValues ={ + value:'' + }; + var init = function() { + if($scope.type=='edit'){ + $scope.dataProcessing = true; + raptorReportFactory.getFormFieldEditInfoById(fieldData.id).then(function(data){ + $scope.dataProcessing = false; + $scope.formFieldEditData = data; + if($scope.formFieldEditData.fieldDefaultSQL) + $scope.sqlAsDefaultValue.value = true; + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: getColumnEditInfoById failed."); + }).finally(function() { + $scope.dataProcessing=false; + }); + }else{ + $scope.formFieldEditData ={ + groupFormField: false, + visible:"true" + }; + } + $scope.ynOptions = [ + {value:"true", text:"Yes"}, + {value:"false", text:"No"} + ]; + $scope.verifyFieldValueOptions = [ + {value:null, text:"--- Do Not Perform Validation ---"}, + {value:"DATE", text:"Date"}, + {value:"TIMESTAMP_HR", text:"TimeStamp (Hour)"}, + {value:"TIMESTAMP_MIN", text:"TimeStamp (Hour,Min)"}, + {value:"TIMESTAMP_SEC", text:"TimeStamp (Hour,Min,Sec)"}, + {value:"INTEGER", text:"Integer"}, + {value:"POSITIVE_INTEGER", text:"Positive Integer"}, + {value:"NON_NEGATIVE_INTEGER", text:"Positive Integer. Cannot Be Zero"}, + {value:"FLOAT", text:"Any Number"}, + {value:"NON_NEGATIVE_FLOAT", text:"Positive Number"}, + {value:"POSITIVE_FLOAT", text:"Positive Number. Cannot Be Zero"} + ] + $scope.fieldTypeOptions = [ + {value:"TEXT", text:"Text Box"}, + {value:"LIST_BOX", text:"List Box"}, + {value:"LIST_MULTI_SELECT", text:"Multi-select List Box"}, + {value:"HIDDEN", text:"Hidden"} + ]; + } + init(); + $scope.save = function() { + if($scope.sqlAsDefaultValue.value && ($scope.formFieldEditData.fieldDefaultSQL==null || $scope.formFieldEditData.fieldDefaultSQL=='')){ + $scope.errorPopUp("if SQL as Default Value is checked, 'Default SQL' and 'SQL Generating Custom List of Values' fields cannot be empty"); + return; + }else if(!$scope.sqlAsDefaultValue.value){ + $scope.formFieldEditData.fieldDefaultSQL=null; + } + $scope.dataProcessing = true; + console.log($scope.formFieldEditData.validationType); + if($scope.formFieldEditData.validationType=='Select') + $scope.formFieldEditData.validationType = ''; + raptorReportFactory.saveFormFieldEditInfo($scope.formFieldEditData).then(function(data){ + $scope.dataProcessing = false; + $scope.successPopUp(''); + $modalInstance.close(); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: saveFormFieldEditInfo failed."); + }).finally(function() { + $scope.dataProcessing=false; + }); + }; + + $scope.add = function() { + $scope.dataProcessing = true; + $scope.formFieldEditData.visible== + raptorReportFactory.addFormFieldEditInfo($scope.formFieldEditData).then(function(data){ + $scope.dataProcessing = false; + $modalInstance.close(); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: add FormFieldEditInfo failed."); + }).finally(function() { + $scope.dataProcessing=false; + }); + }; + + $scope.addPredefinedValueList = function() { + if($scope.formFieldEditData.predefinedValueList==null) + $scope.formFieldEditData.predefinedValueList=[]; + var item ={ + id:$scope.predefinedValues.value, + name:$scope.predefinedValues.value, + selected:false + }; + if($scope.predefinedValues.value!=null && $scope.predefinedValues.value!='') + $scope.formFieldEditData.predefinedValueList.push(item); + }; + + $scope.removePredefinedValueList = function(removeVal) { + var removeIndex = null; + for(i in $scope.formFieldEditData.predefinedValueList){ + if($scope.formFieldEditData.predefinedValueList[i].id == removeVal){ + removeIndex= i; + break; + } + } + $scope.formFieldEditData.predefinedValueList.splice(removeIndex, 1) + }; + + $scope.cancel = function() { + $modalInstance.dismiss(); + }; +} + + +var deleteFormFieldController = function ($scope, $modalInstance, $http, $log, raptorReportFactory, rowData) { + $scope.tempFieldId = rowData.id; + $scope.ok = function() { + raptorReportFactory.deleteFormFieldById(rowData.id).then(function(data){ + $modalInstance.close(); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: deleteFormFieldById failed."); + }); + } + $scope.cancel = function() { + $modalInstance.dismiss(); + }; +} + +var removeReportSecurityUserController = function ($scope, $modalInstance, $http, $log, raptorReportFactory,securityUser) { + $scope.securityUserName = securityUser.name; + $scope.ok = function() { + raptorReportFactory.removeReportSecurityUser(securityUser.id).then(function(data){ + $modalInstance.close(); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: removeReportSecurityUser failed."); + }); + } + $scope.cancel = function() { + $modalInstance.dismiss(); + }; +} + +var removeReportSecurityRoleController = function ($scope, $modalInstance, $http, $log, raptorReportFactory,securityRole) { + $scope.securityRoleName = securityRole.name; + $scope.ok = function() { + raptorReportFactory.removeReportSecurityRole(securityRole.id).then(function(data){ + $modalInstance.close(); + },function(error){ + $scope.errorPopUp(error); + $log.error("raptorReportFactory: removeReportSecurityRole failed."); + }); + } + $scope.cancel = function() { + $modalInstance.dismiss(); + }; +} + +var formFieldVerifySQLController = function ($scope, $modalInstance, $http, $log, raptorReportFactory, queriedData) { + var init = function() { + $scope.isError = false; + if (queriedData.errormessage) { + $scope.isError = true; + $scope.errormessage = queriedData.errormessage; + $scope.stacktrace = queriedData.stacktrace; + } else { + $scope.queryData = queriedData; + } + } + init(); + $scope.close = function() { + $modalInstance.dismiss(); + }; +} +var toggleUserEditAccessActiveController = function ($scope, $modalInstance, $http, $log, raptorReportFactory, rowData) { + $scope.rowData = rowData; + $scope.toggleEditAccessStatus = function(rowData) { + raptorReportFactory.toggleUserEditAccess(rowData); + $modalInstance.close(); + }; + + $scope.cancelEditAccessToggle = function(rowData) { + rowData.accessAllowed = ! rowData.accessAllowed; + $modalInstance.dismiss('cancel');} +} + +var toggleRoleEditAccessActiveController = function ($scope, $modalInstance, $http, $log, raptorReportFactory, rowData) { + $scope.rowData = rowData; + $scope.toggleEditAccessStatus = function(rowData) { + raptorReportFactory.toggleRoleEditAccess(rowData); + $modalInstance.close(); + }; + + $scope.cancelEditAccessToggle = function(rowData) { + rowData.accessAllowed = ! rowData.accessAllowed; + $modalInstance.dismiss('cancel');} +} \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/all-reports.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/all-reports.html index 7f470d40..ce70dc58 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/all-reports.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/all-reports.html @@ -21,7 +21,6 @@ - @@ -66,12 +65,14 @@ + + -
- +
+
- + diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/directive/dynamicform.js b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/directive/dynamicform.js index 9064b0dc..5147719f 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/directive/dynamicform.js +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/directive/dynamicform.js @@ -12,22 +12,42 @@ appDS2 link: function ($scope, element, attrs) { $scope.element=element; $scope.datetimeformat = "MM/dd/yyyy hh:mm a"; - console.log("$scope"); - console.log($scope); $scope.buildField = function (field, parentElement) { var x = ''; if(field.visible) { + if (field.fieldType === 'LIST_MULTI_SELECT') { - x = angular.element('
'+ + /*x = angular.element('
'+ '
'+ ''+ - '
'); + '');*/ + + x = angular.element( + '
'+ + '

'+field.fieldDisplayName+'

'+ + '
'+ + ''+ + '
'+ + '
'+ + '
'+ + '
'); } else if (field.fieldType === 'LIST_BOX') { - x = angular.element('
'); + var temp = + '
'+ + ''+ + ''+ + '
'; + + x = angular.element(temp); + //x = angular.element('
'); } else if((field.fieldType === 'text' || field.fieldType === 'TEXT') && field.validationType === 'DATE'){ - x = angular.element('
'); + x = angular.element('
'); } else if((field.fieldType === 'text' || field.fieldType === 'TEXT') && field.validationType === 'TIMESTAMP_MIN'){ x = angular.element('
'); } else if(field.fieldType === 'text' || field.fieldType === 'TEXT'){ @@ -35,9 +55,10 @@ appDS2 } else if(field.fieldType === 'CHECK_BOX'){ x = angular.element('
'); } + parentElement.append(x); + $compile(x)($scope); } - parentElement.append(x); - $compile(x)($scope); + }; $scope.buildForm = function() { // create elements and a @@ -80,7 +101,7 @@ appDS2 formField.formFieldValues.forEach(function(entry,i) { $scope.formFieldLuValues[formField.fieldId].push({ index: i, value: entry.id, title: entry.name}); if(entry.defaultValue){ - $scope.ngModel[formField.fieldId]={ index: i, value: entry.id, title: entry.name}; + //$scope.ngModel[formField.fieldId]={ index: i, value: entry.id, title: entry.name}; } }); } diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-del-confirm.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-del-confirm.html index da255bbf..3f0338c9 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-del-confirm.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-del-confirm.html @@ -1,26 +1,18 @@ -
-
-

Remove Report

-
- -
+ +
+

Remove Report

+
+
-
-
- -
- -
- - - -
+
+
+

The selected report will be removed. Do you want to continue

+
+ \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-formfield-del-confirm.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-formfield-del-confirm.html index 7bdf5a29..20dd9202 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-formfield-del-confirm.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-formfield-del-confirm.html @@ -1,26 +1,17 @@ -
-
-

Remove Formfield

-
- -
+
+

Remove Formfield

+
+
-
-
- -
- -
- - - -
+
+
+ The selected formfield {{tempFieldId}} will be removed. Do you want to continue? +
+ \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-role-del-confirm.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-role-del-confirm.html index 01d1e609..629b9a91 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-role-del-confirm.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-role-del-confirm.html @@ -1,26 +1,19 @@ -
-
-

Remove Report Role

-
- -
+ +
+

Remove Report Role

+
+
-
-
- -
- -
- - - -
+
+
+ {{securityRoleName}} + will be removed. Would you want to continue? +
+ \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-user-del-confirm.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-user-del-confirm.html index 6620fe7c..5af1b227 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-user-del-confirm.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-security-user-del-confirm.html @@ -1,26 +1,18 @@ -
-
-

Remove Report User

-
- -
+
+

Remove Report User

+
+
-
-
- -
- -
- - - -
+
+
+ {{securityUserName}} + will be removed. Would you want to continue? +
+ \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html index 21bb046f..06f2049a 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-user-role-confirm-toggle.html @@ -1,23 +1,24 @@ -
-
-

-

Confirm

-
- -
+ +
+

+ +

+

Confirm

+
+
-
- You are about to {{rowData.accessAllowed?"grant":"revoke"}} {{rowData.name}} edit access. Would you like to continue? -
- +
+ You are about to {{rowData.accessAllowed?"grant":"revoke"}} + {{rowData.name}} edit access. Would you like to continue? +
+ diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-col-edit.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-col-edit.html index e74f89a8..3aadf27e 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-col-edit.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-col-edit.html @@ -1,130 +1,232 @@ -
-
-

Report Column - Edit

-
- -
+
+

Report Column - Edit

+
+
-
-
- - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Column ID:{{columnEditData.colId}}
Display Name:
Display Alignment: - -
Display Header Alignment: - -
Sortable: - -
Visible: - -
Drill-down Link: - -
- - - \ No newline at end of file + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Column ID:{{colInfo.colId}}
Column Name:{{colInfo.colName}}
Depends on formfield:
Datatype: + +
Group By Pos: + +
Custom Text for Sub-Total:
Hide Repeated Values: + +
Multi Group Column Level: + +
Multi group Column Range : Colspan: + +
Display Name: + +
Display Width (In Pxls): + +
No Wrap ?: + +
Indent Parameter to display value: + +
Display Alignment: + +
Display Header Alignment: + +
Sortable: + +
Visible: + +
Drill-down Link: + +
Total for the column: + +
+ + + + + + + + + + + + + + + + + +
{{ff.name}}
+ + {{ dd.selection }} + Accept default + +
+ +
+
+ + + +
+ + + + + + +
+ + + \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html index c88eb596..3c17ff7b 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-formfield-edit.html @@ -1,149 +1,154 @@ -
-
-

Report Form Field - Edit

-
- -
+
+

Report Form Field - Edit

+
+
-
-
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
+
+ +
+
+
Field Name:
Field Type: - -
Visible: - -
SQL as Default Value: - -
Default Value:
Default SQL: - - -

-
SQL Generating Custom List of Values: - - -

-
+ + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + - -
Field Name:
Field Type:
Visible: + +
Is used in Group By Clause? + +
SQL as Default Value: + +
Default SQL: + + +

+ +

+
Default Value:
-
- -
-
+
+ \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html index a7955cad..e3fda72b 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/modal/report-wizard-test-run-sql.html @@ -1,62 +1,57 @@ - - -
-
-

SQL Test Run - {{isError?'Failed':'Executed'}}

-
- -
+ --> +
+

SQL Test Run - + {{isError?'Failed':'Executed'}}

+
+
-
-
- -
- -
-

Error Message:


-

{{errormessage}}

-

Stack Trace:


-

{{stacktrace}}

+
+
+
-
- - - - - - - - - - +
+

Error Message:

+
+

{{errormessage}}

+

Stack Trace:

+
+

{{stacktrace}}

-
-
{{colName}}
{{rowData[keyName]}}
-
- + +
+
-
\ No newline at end of file +
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-chart-wizard.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-chart-wizard.html index 8558729e..ed3c4ba9 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-chart-wizard.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-chart-wizard.html @@ -1,897 +1,1080 @@
-

Report Chart Configuration

+

Report Chart Configuration

-
- -
+
+ +
-
-
- - - - - - - - - - - - - - -
Chart Type
- -
- - - - - - - - - - - - - - -
Width (px)Height (px)
- - - -
- - - - - - - - - -
-
- - - - - -
Title
- - - -
- - - - - - - - - - - - - - - -
Domain AxisCategory
- - - -
- - -
- - - - - - - - - - - - - - - - - - - - - - - -
Range AxisY AxisChart TitleColorLine Type
- - - - - - - - - - - - - - - -
-
+
+
+
+ +
+ + + + + + + - - -
-
-
-
-
- - -
-
-
-
-
- -
-
- -
- -
-
- -
-
- -
-
- Show - Hide -
-
- - -
-
-
-
- -
-
-
-
-
- -
-
-
-
-
-
-
- - -
-
- -
- -
-
- -
- -
-
-
-
- -
-
-
-
- -
-
- -
- -
- Add - - Remove -
-
-
-
-
- - - -
-
- -
-
-
- -
-
-
-
- -
-
-
- -

-
-
- - - - -
- - - - - -
-
-
- Vertical - Horizontal +
+ + + + + +
Chart Type
+ + + + + + + + + + + + + + +
Width (px)Height (px)
+ + + + + + + + + +
+
+ + + + + +
Title
+ + + + + + + + + + + + + + + +
Domain AxisCategory
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + +
Range AxisY AxisChart TitleColorLine Type
+ + + + +
+
+ +
+
- -
-
- Yes - No -
- -
-
- Yes - No -
- -
-
- Yes - No -
- -
-
- Yes - No -

- -
-
- Yes - No -
- -
-
- - -
-
- - -
- {{reportRunJson.chartType}} -
- - - -
-
+
-
- Line - Area +
+
- -
-
- -

- -
-
- -
- -
-
- Yes - No -
- -
-
- Yes - No -
-
-
- - - - -
- -
- - - - -
-
-
-
- -
- -
-
- Weekly - Daily - Hourly - 30 Min + + +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+ +
+
Show Hide +
+
+ + +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+
+ + +
+
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+ + +
+
+
+
+ + + +
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+ + + + +
+ + + + + +
+
+
Vertical Horizontal +
+ +
+
Yes No +
+ +
+
Yes No +
+ +
+
+ Yes No +
+ +
+
Yes No +
+
+ +
+
Yes No +
+ +
+
+ + +
+
+ +
+
+ {{reportRunJson.chartType}} +
+ + + +
+
+
+
Line Area +
+ +
+
+
+
+ +
+
+
+ +
+
Yes No +
+ +
+
Yes No +
+
+
+ +
+ +
+ +
+ + + + +
+
+
+
+ +
+ +
+
+ Weekly Daily Hourly 30 Min +
+
+
+
+ +
+ + + + + + + + + + + +
+
+
+
up 45° up 90° down 45° down 90° Standard +
+ +
+
+ Top Bottom +
+
+ +
+
Yes No +
+ +
+
Yes No +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Save + Run
-
-
-
-
- -
- - - - - - - - - - - -
-
-
-
- up 45° - up 90° - down 45° - down 90° - Standard -
- -
-
- Top - Bottom -

- -
-
- Yes - No -
- -
-
- Yes - No -

- -
-
- -
-
-
- -
-
-
- -
-
-
- -

-
-
-
-
-

- Save - Run -
-
- - -
-
-
Additional Options
-

-

-
-
- -
-
-
- -
-
- - - - - - - - - - - - - - -
Primary Axis LabelSecondary Axis Label
- - - -
- - - - - - - - - - - - - - -
Range Axis Minimum RangeMaximum Range
- - - -
-
+
+ + +
+
+
Additional + Options
+

+
+
+ +
- -
- - - - -
-
-
Bar Chart Options
-

-

-
-
- -
-
-
- -
+ +
- - - - - - - - - - - - - - - - - - - - - -
OrientationStackedShow ControlsXAxis Date TypeDisplay less XAxis tickers
- - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
Is Time Axis?Log Scale (Y Axis)
- - - - -
-
+ + + + + + + + + + + + + + +
Primary Axis LabelSecondary Axis Label
+
+ + + + + + + + + + + + + + +
Range Axis Minimum RangeMaximum Range
+ +
+
-
-
- - - - - -
-
-
Time Series Chart Options
-

-

-
-
- -
-
-
- -
-
- - - - - - - - - - - - - - - - - - - -
Render asX Axis LabelX Axis TickersIs Time Axis?Multi Series
- - - - - - - - - - -
-
+ + + + + +
+
+
Bar + Chart Options
+

+
+
+ +
- -
- - - - -
-
-
Common Options
-

-

-
-
- -
-
-
- -
-
-
-
- - - - - - - - - -
-
- - -
-
- - - -
Legend AngleLegend Position
- - - - - - - - -
- - - + +
+
+
- - - - - + + + + + + + + - - -
-
- - -
-
- - - - + + + + + + + + + + +
LegendAnimation
OrientationStackedShow ControlsXAxis Date TypeDisplay less XAxis tickers
- - - - - - -
+ + + + + + + + + + + + + +
Is Time Axis?Log Scale (Y Axis)
+
+
+ + + + + +
+
+
Time + Series Chart Options
+

+
+
+ +
+
+
+
+
- - - - - - + + + + + + + - - - - - - - - + + + + + + + + +
Top MarginBottom MarginLeft MarginRight Margin
Render asX Axis LabelX Axis TickersIs Time Axis?Multi Series
- - - - - - - -
-
-
-
- - +
+
+
+ -
-
+ + +
+
+
Common + Options
+

+
+
+ +
+
+
+
+
+
+
+ + + + + + + + + +
+
+ + +
+
+ + + +
Legend AngleLegend Position
+ + + + + + + + + + + + +
+
+ + +
+
+ + + + +
LegendAnimation
+ + + + + + + + + + + + + + + + + + +
Top MarginBottom MarginLeft MarginRight Margin
+
+
+
+ + +
+
- - - - -
+ + + + +
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-run.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-run.html index aaa1cac0..7b2c23e1 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-run.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-run.html @@ -1,96 +1,124 @@ -
-
-

{{reportData.reportHeading}}

-
- +
+
+
+

{{reportData.reportHeading}}

+
+
+ +
+
+
-
- + +
+
+
+
+ +
+

{{reportData.reportSubTitle}}

-
- -
+
Loading...
+ +
+ +
+
+ +
+ + +
+
+
+
+
+ {{reportData.message}} +
+
+
-

{{reportData.reportSubTitle}}

- -
Loading...
- -
- -

- -
- - -
-
-
-
-
- {{reportData.message}} -
-
-
-
- -
+ +
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-search.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-search.html index 7524acca..2fd0e436 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-search.html +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-search.html @@ -29,7 +29,7 @@ body {
- +
@@ -41,12 +41,15 @@ body {
- +
+
+

diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-step.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-step.html new file mode 100644 index 00000000..9550ac33 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/report-step.html @@ -0,0 +1,35 @@ +
+
+
+ + + {{tab.title}} + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step1.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step1.html new file mode 100644 index 00000000..a9baadf8 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step1.html @@ -0,0 +1,213 @@ +

Step 1 - Report Definition

+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ + +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+
+ +
+ + +
+
+ + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step2.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step2.html new file mode 100644 index 00000000..e21af0c8 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step2.html @@ -0,0 +1,26 @@ +

Step 2 - Report SQL

+ +
+ +
+

{{pageMsg}}

+
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+ + diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step3.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step3.html new file mode 100644 index 00000000..e1f02a1c --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step3.html @@ -0,0 +1,34 @@ +

Step 3 - Report Columns

+
+ +
+
+
+ + + + + + + + + + + + + + + + + +
NoIDDisplay NameEdit
{{$index+1}}{{rowData.id}}{{rowData.name}}
+
+ + +
+ + diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step4.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step4.html new file mode 100644 index 00000000..dc3be5c8 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step4.html @@ -0,0 +1,47 @@ +

Step 4 - Report Form Fields

+
+ +
+
+
+

Report Form Fields 4

+ + + + + + + + + + + + + + + + + + + +
Order NumberField NameEditOrderDelete
{{rowData.orderSeq}}{{rowData.name}}[{{rowData.id}}] + + + + + + +
+
+
+ +
+ + +
+ + diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step5.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step5.html new file mode 100644 index 00000000..13278029 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step5.html @@ -0,0 +1,172 @@ + +

Step 5 - Report Security

+ +
+ +
+
+
+
+
+ + + + + + + + + + + + + + + +
Created By: {{reportSecurityInfo.createdUser}}Created Date: {{reportSecurityInfo.createdDate}}
Last Updated By: {{reportSecurityInfo.updateUser}}Last Updated: {{reportSecurityInfo.updatedDate}}
Report Owner: + + Public? (All users can run the report): +
+
+ +
+

Report Users

+ + + + + + + + + + + + + + + + + + + +
NoUser NameRun AccessEdit AccessRemove
{{$index+1}}{{reportUser.name}} + +
+
+
+

Grant Access To:

+
+ +
+
+ +
+
+ +
+

Report Roles

+ + + + + + + + + + + + + + + + + + + +
NoRole NameRun AccessEdit AccessRemove
{{$index+1}}{{reportRole.name}} + +
+
+

Grant Access To:

+
+ +
+
+ +
+
+
+ +
+
+
+ + +
+ +
+ + diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step6.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step6.html new file mode 100644 index 00000000..4849190a --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step6.html @@ -0,0 +1,34 @@ +

Step 6 - Report Log

+ +
+ +
+
+
+

Report Logs

+ + + + + + + + + + + + + + + + + +
NoUser NameLog TimeAction
{{$index+1}}{{rowData.userName}}{{rowData.logTime}}{{rowData.action}}
+
+ + +
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step7.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step7.html new file mode 100644 index 00000000..298cce8f --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/steps/step7.html @@ -0,0 +1,16 @@ +

Step 7 - Report Run

+ +
+ +
+
+
+ +
+ +
+ + diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/json/step1.json b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/json/step1.json index 66562d4b..abdbd023 100644 --- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/json/step1.json +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2-reports/wz_steps/json/step1.json @@ -11,7 +11,13 @@ "name": "proj_id", "displayName": "Project Id", "defaultValue": "" - }, + }, + { + "input": "text", + "name": "reportId", + "displayName": "Report ID:", + "defaultValue": "" + }, { "input": "text", "name": "reportName", @@ -75,9 +81,17 @@ "defaultValue": "no", "action": "", "action_img": "", - "checkboxes":[{"value":"homeSelected.value", "text":"HOME"}, - {"value":"customerSelected.value", "text":"CUSTOMER"}, - {"value":"reportsSelected.value", "text":"REPORTS"} + "checkboxes":[ + {"value":"homeSelected", "text":"HOME"}, + {"value":"customerSelected", "text":"CUSTOMER"}, + {"value":"reportsSelected", "text":"REPORTS"}, + {"value":"utilSelected", "text":"Utilization"}, + {"value":"tmSelected", "text":"Tunnel Management"}, + {"value":"trSelected", "text":"Tunnel Routing"}, + {"value":"cmSelected", "text":"Capacity Management"}, + {"value":"tlSelected", "text":"Traffic Loss"}, + {"value":"smSelected", "text":"System Monitoring"}, + {"value":"netOperateSelected", "text":"Network Operation Monitoring"} ] }, diff --git a/ecomp-sdk/epsdk-core/pom.xml b/ecomp-sdk/epsdk-core/pom.xml index d15b18ff..0e78c057 100644 --- a/ecomp-sdk/epsdk-core/pom.xml +++ b/ecomp-sdk/epsdk-core/pom.xml @@ -6,7 +6,7 @@ org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT @@ -451,7 +451,7 @@ org.apache.poi poi - 3.17 + 3.5-FINAL commons-logging @@ -466,7 +466,7 @@ org.apache.poi poi-ooxml - 3.17 + 3.5-FINAL commons-logging @@ -481,7 +481,7 @@ org.apache.poi poi-scratchpad - 3.17 + 3.5-FINAL commons-logging diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/JsonMessageTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/JsonMessageTest.java index 0e732a91..fbc95cd5 100644 --- a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/JsonMessageTest.java +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/JsonMessageTest.java @@ -38,6 +38,7 @@ package org.onap.portalsdk.core.web.support; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.junit.Test; @@ -66,4 +67,19 @@ public class JsonMessageTest { assertEquals(jsonMessage.getData2(), jsonMessage1.getData2()); assertEquals(jsonMessage.getData3(), jsonMessage1.getData3()); } + + @SuppressWarnings("static-access") + @Test + public void buildJsonResponseTest(){ + JsonMessage jsonMsg = mockJsonMessage(); + assertNotNull(jsonMsg.buildJsonResponse(true, "test")); + } + + @SuppressWarnings("static-access") + @Test + public void buildJsonResponseExceptionTest(){ + JsonMessage jsonMsg = mockJsonMessage(); + assertNotNull(jsonMsg.buildJsonResponse(new Exception("test exception"))); + } + } diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/MessagesListTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/MessagesListTest.java index 4d13eda1..a7951210 100644 --- a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/MessagesListTest.java +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/MessagesListTest.java @@ -39,6 +39,8 @@ package org.onap.portalsdk.core.web.support; import static org.junit.Assert.*; +import java.util.ArrayList; + import org.junit.Test; public class MessagesListTest { @@ -63,11 +65,14 @@ public class MessagesListTest { messagesList.setIncludeCauseInCustomExceptions(false); messagesList.setSuccessMessageDisplayed(false); messagesList.setSuccessMessages(null); - assertEquals(messagesList.getExceptionMessages(), messagesList1.getExceptionMessages()); assertEquals(messagesList.getSuccessMessages(), messagesList1.getSuccessMessages()); assertEquals(messagesList.isIncludeCauseInCustomExceptions(), messagesList1.isIncludeCauseInCustomExceptions()); assertEquals(messagesList.isSuccessMessageDisplayed(), messagesList1.isSuccessMessageDisplayed()); - + messagesList = new MessagesList(); + messagesList.addSuccessMessage(new FeedbackMessage()); + messagesList.addExceptionMessage(new FeedbackMessage()); + assertTrue(messagesList.hasExceptionMessages()); + assertTrue(messagesList.hasSuccessMessages()); } } diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/UserUtilsTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/UserUtilsTest.java new file mode 100644 index 00000000..fe63b70a --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/UserUtilsTest.java @@ -0,0 +1,164 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.core.web.support; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.servlet.ServletContext; +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.Mock; +import org.mockito.Mockito; +import org.onap.portalsdk.core.domain.MenuData; +import org.onap.portalsdk.core.domain.Role; +import org.onap.portalsdk.core.domain.RoleFunction; +import org.onap.portalsdk.core.domain.User; +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({AppUtils.class, SystemProperties.class}) +public class UserUtilsTest { + @Mock + HttpServletRequest request; + @Mock + HttpSession session; + @Mock + User user; + @Mock + ServletContext servletContext; + + SortedSet roles; + + @Before + public void setUp() { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(AppUtils.getSession(request)).thenReturn(session); + Mockito.when(request.getSession(true)).thenReturn(session); + Mockito.when(request.getSession()).thenReturn(session); + Mockito.when(session.getServletContext()).thenReturn(servletContext); + Mockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("user"); + Mockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)).thenReturn("1"); + Mockito.when(session.getAttribute("user")).thenReturn(user); + SortedSet roles = new TreeSet<>(); + Role role = new Role(); + role.setActive(true); + role.setId(1L); + Set roleFunctionSet = new HashSet<>(); + RoleFunction rf = new RoleFunction(); + rf.setName("test"); + rf.setCode("test"); + rf.setType("test"); + rf.setAction("test"); + roleFunctionSet.add(rf); + role.setRoleFunctions(roleFunctionSet); + Role childRole = new Role(); + childRole.setActive(true); + childRole.setId(1L); + HashSet childRoles = new HashSet<>(); + childRoles.add(childRole); + role.setChildRoles(childRoles); + roles.add(role); + Mockito.when(user.getRoles()).thenReturn(roles); + } + + @Test + public void testSetUserSession() { + Set set = new HashSet<>(); + MenuData menuData = new MenuData(); + menuData.setFunctionCd("test"); + set.add(menuData); + List roleFunctionList = new ArrayList<>(); + roleFunctionList.add(new RoleFunction()); + UserUtils.setUserSession(request, user, set, set, "test", roleFunctionList); + } + + @Test + public void testHasRole() { + UserUtils.hasRole(request, "1"); + } + + @Test + public void testHasRoleByUser() { + UserUtils.hasRole(user, "1"); + } + + @Test + public void testGetLoginMethod() { + UserUtils.getLoginMethod(request); + } + + @Test + public void testGetUserId() { + UserUtils.getUserId(request); + } + + @Test + public void testGetStackTrace() { + UserUtils.getStackTrace(new Exception("test exception")); + } + + @Test + public void testConvertToEcompUser() { + UserUtils.convertToEcompUser(user); + } + + @Test + public void testGetRequestId() { + Enumeration headerNames = Mockito.mock(Enumeration.class); + Mockito.when(headerNames.hasMoreElements()).thenReturn(true); + Mockito.when(headerNames.nextElement()).thenReturn("X-ECOMP-RequestID"); + Mockito.when(request.getHeader("X-ECOMP-RequestID")).thenReturn("test"); + Mockito.when(request.getHeaderNames()).thenReturn(headerNames); + UserUtils.getRequestId(request); + } +} diff --git a/ecomp-sdk/epsdk-domain/pom.xml b/ecomp-sdk/epsdk-domain/pom.xml index 34a55ac4..06ef3b13 100644 --- a/ecomp-sdk/epsdk-domain/pom.xml +++ b/ecomp-sdk/epsdk-domain/pom.xml @@ -5,12 +5,12 @@ org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT org.onap.portal.sdk epsdk-domain - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT jar ONAP Portal SDK Domain diff --git a/ecomp-sdk/epsdk-fw/pom.xml b/ecomp-sdk/epsdk-fw/pom.xml index 91487ad8..e1da0300 100644 --- a/ecomp-sdk/epsdk-fw/pom.xml +++ b/ecomp-sdk/epsdk-fw/pom.xml @@ -6,7 +6,7 @@ org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT diff --git a/ecomp-sdk/epsdk-music/pom.xml b/ecomp-sdk/epsdk-music/pom.xml index 45ebddc3..e6296c1b 100644 --- a/ecomp-sdk/epsdk-music/pom.xml +++ b/ecomp-sdk/epsdk-music/pom.xml @@ -5,12 +5,12 @@ org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT org.onap.portal.sdk epsdk-music - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT jar ONAP Portal SDK Music @@ -28,7 +28,7 @@ junit junit - 3.8.1 + 4.12 test @@ -164,6 +164,13 @@ logback-classic 1.2.3 + + + org.jacoco + org.jacoco.agent + ${jacoco.version} + runtime + diff --git a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/conf/EnableMuscicHttpSession.java b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/conf/EnableMuscicHttpSession.java index 586d04ad..f44cf3f3 100644 --- a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/conf/EnableMuscicHttpSession.java +++ b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/conf/EnableMuscicHttpSession.java @@ -33,7 +33,7 @@ * * ============LICENSE_END============================================ * - *. + * */ package org.onap.portalapp.music.conf; diff --git a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/conf/MusicSessionRepository.java b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/conf/MusicSessionRepository.java index 4bebfc2b..f2f8fee5 100644 --- a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/conf/MusicSessionRepository.java +++ b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/conf/MusicSessionRepository.java @@ -38,8 +38,8 @@ package org.onap.portalapp.music.conf; import java.time.Duration; -import java.util.Map; +import org.springframework.session.MapSession; import org.springframework.session.Session; import org.springframework.session.SessionRepository; import org.springframework.session.events.SessionDeletedEvent; diff --git a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/model/RestResponse.java b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/model/RestResponse.java index 5a3a7416..0326e8e0 100644 --- a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/model/RestResponse.java +++ b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/model/RestResponse.java @@ -91,6 +91,7 @@ public class RestResponse { return result; } + @SuppressWarnings("rawtypes") @Override public boolean equals(Object obj) { if (this == obj) diff --git a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicProperties.java b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicProperties.java index 5aae01d0..9aae9770 100644 --- a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicProperties.java +++ b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicProperties.java @@ -44,7 +44,6 @@ import java.io.InputStream; import java.util.Properties; import org.onap.music.eelf.logging.EELFLoggerDelegate; -import org.onap.portalapp.music.service.MusicService; public class MusicProperties { diff --git a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicUtil.java b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicUtil.java index a62c929c..15c3bb0c 100644 --- a/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicUtil.java +++ b/ecomp-sdk/epsdk-music/src/main/java/org/onap/portalapp/music/util/MusicUtil.java @@ -73,6 +73,7 @@ public class MusicUtil { return sessionAttrNameSet.contains(key); } + @SuppressWarnings("unchecked") public static T musicRestResponseDataParsing(ResultSet rs, String attributeName) throws Exception{ logger.debug(EELFLoggerDelegate.debugLogger, "musicRestResponseDataParsing: start"); Row row = rs.one(); @@ -85,6 +86,7 @@ public class MusicUtil { return null; } + @SuppressWarnings("unchecked") public static T musicDeserialize (ByteBuffer byteBuf) throws Exception{ logger.debug(EELFLoggerDelegate.debugLogger, "musicDeserialize: start"); ByteArrayInputStream byteArr = new ByteArrayInputStream(byteBuf.array()); diff --git a/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryHandlerTest.java b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryHandlerTest.java new file mode 100644 index 00000000..b5a28af8 --- /dev/null +++ b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryHandlerTest.java @@ -0,0 +1,103 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalapp.music.conf; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +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.music.datastore.PreparedQueryObject; +import org.onap.music.main.MusicCore; +import org.onap.portalapp.music.service.MusicService; +import org.onap.portalapp.music.util.MusicUtil; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.session.Session; + +import com.datastax.driver.core.ResultSet; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MusicUtil.class, MusicCore.class}) +public class MusicSessionRepositoryHandlerTest { + + @Mock + private MusicService musicService; + + @Mock + ResultSet resultSet; + + @Before + public void setUp() { + PowerMockito.mockStatic(MusicUtil.class); + PowerMockito.mockStatic(MusicCore.class); + Mockito.when(MusicUtil.isCached()).thenReturn(true); + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + MusicSessionRepositoryHandler musicSessionRepositoryHandler = new MusicSessionRepositoryHandler(); + + MusicSession ms = new MusicSession(); + + + @SuppressWarnings("static-access") + @Test + public void getTest() throws Exception { + Mockito.when(MusicCore.get(Matchers.any(PreparedQueryObject.class))).thenReturn(resultSet); + Mockito.when(musicService.getMetaAttribute("test_id")).thenReturn(ms); + Session session = musicSessionRepositoryHandler.get("test_id"); + assertNotNull(session); + } + + @SuppressWarnings("static-access") + @Test + public void getFailWithIdTest() throws Exception { + Mockito.when(MusicCore.get(Matchers.any(PreparedQueryObject.class))).thenReturn(resultSet); + Mockito.when((musicService).getMetaAttribute("test_id")).thenThrow(new NullPointerException()); + Session session = musicSessionRepositoryHandler.get("test_id"); + assertNull(session); + } +} diff --git a/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryTest.java b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryTest.java new file mode 100644 index 00000000..1f6af366 --- /dev/null +++ b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionRepositoryTest.java @@ -0,0 +1,95 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalapp.music.conf; + +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.music.service.MusicService; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.session.Session; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MusicSession.class, MusicService.class, Session.class}) +public class MusicSessionRepositoryTest { + + + @Mock + MusicSessionRepositoryHandler handler; + + @Mock + Session session; + + @InjectMocks + MusicSessionRepository musicSessionRepository; + + MusicSession musSession = mock(MusicSession.class); + + @Before + public void setUp() throws Exception { + PowerMockito.mockStatic(MusicService.class); + PowerMockito.mockStatic(MusicSession.class); + PowerMockito.mockStatic(Session.class); + MockitoAnnotations.initMocks(this); + } + + @Test + public void setDefaultMaxInactiveIntervalTest() throws Exception { + PowerMockito.whenNew(MusicSessionRepositoryHandler.class).withNoArguments().thenReturn(handler); + musicSessionRepository.setDefaultMaxInactiveInterval(10); + } + + @Test + public void findByIdTest() { + assertNull(musicSessionRepository.findById("1")); + } + + @Test + public void deleteByIdTest() { + musicSessionRepository.deleteById("1"); + } + +} diff --git a/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionTest.java b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionTest.java new file mode 100644 index 00000000..65290d48 --- /dev/null +++ b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/conf/MusicSessionTest.java @@ -0,0 +1,262 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalapp.music.conf; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.time.Duration; +import java.time.Instant; +import java.util.Set; +import java.util.TreeSet; + +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.music.exceptions.MusicLockingException; +import org.onap.music.exceptions.MusicServiceException; +import org.onap.music.main.ReturnType; +import org.onap.portalapp.music.service.MusicService; +import org.onap.portalapp.music.util.MusicProperties; +import org.onap.portalapp.music.util.MusicUtil; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.session.Session; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ MusicUtil.class, MusicProperties.class, MusicService.class }) +public class MusicSessionTest { + + @InjectMocks + MusicSession musicSession = new MusicSession(); + + @Mock + Session session; + + Duration duration = Duration.ofSeconds(100); + + @Before + public void setUp() { + PowerMockito.mockStatic(MusicUtil.class); + PowerMockito.mockStatic(MusicProperties.class); + PowerMockito.mockStatic(MusicService.class); + Mockito.when(MusicUtil.isCached()).thenReturn(true); + MockitoAnnotations.initMocks(this); + } + + @Mock + ReturnType rt; + + @Test + public void setLastAccessedTimeTest() { + Instant instant = Instant.now(); + musicSession.setLastAccessedTime(instant); + } + + @Test + public void setLastAccessedTimeNullPointerExceptionTest() throws Exception { + Instant instant = Instant.now(); + Mockito.when(MusicService.setAttribute(Matchers.anyString(), Matchers.any(Instant.class), Matchers.anyString())) + .thenThrow(new NullPointerException()); + musicSession.setLastAccessedTime(instant); + } + + @Test + public void musicSession() { + Set values = new TreeSet<>(); + values.add("testAttName"); + values.add("testAttName2"); + Mockito.when(session.getId()).thenReturn("testId"); + Mockito.when(session.getAttributeNames()).thenReturn(values); + Mockito.when(session.getAttribute("testAttName")).thenReturn("testAttName"); + Mockito.when(session.getAttribute("testAttName2")).thenReturn("testAttName2"); + MusicSession musSession = new MusicSession(session); + assertNotNull(musSession); + } + + @Test + public void getCreationTimeTest() throws Exception { + Instant instant = Instant.now(); + Mockito.when(MusicService.getAttribute(Matchers.anyString(), Matchers.anyString())) + .thenReturn(String.valueOf(instant)); + assertNotNull(musicSession.getCreationTime()); + } + + @Test + public void getCreationTimeInstantNowTest() throws Exception { + Mockito.when(MusicService.getAttribute(Matchers.anyString(), Matchers.anyString())).thenReturn(null); + assertNotNull(musicSession.getCreationTime()); + } + + @Test + public void getCreationTimeNullPointerExceptionTest() throws Exception { + Mockito.when(MusicService.getAttribute(Matchers.anyString(), Matchers.anyString())) + .thenThrow(new NullPointerException()); + assertNull(musicSession.getCreationTime()); + } + + @Test + public void getLastAccessedTimeTest() throws Exception { + Instant instant = Instant.now(); + Mockito.when(MusicService.getAttribute(Matchers.anyString(), Matchers.anyString())) + .thenReturn(String.valueOf(instant)); + assertNotNull(musicSession.getCreationTime()); + } + + @Test + public void getLastAccessedTimeInstantNowTest() throws Exception { + Mockito.when(MusicService.getAttribute(Matchers.anyString(), Matchers.anyString())).thenReturn(null); + assertNotNull(musicSession.getCreationTime()); + } + + @Test + public void getLastAccessedTimeNullPointerExceptionTest() throws Exception { + Mockito.when(MusicService.getAttribute(Matchers.anyString(), Matchers.anyString())) + .thenThrow(new NullPointerException()); + assertNull(musicSession.getCreationTime()); + } + + @Test + public void setMaxInactiveIntervalTest() throws Exception { + Mockito.when(MusicService.setAttribute(Matchers.anyString(), Matchers.anyString(), Matchers.anyString())) + .thenReturn(rt); + musicSession.setMaxInactiveInterval(duration); + } + + @Test + public void setMaxInactiveIntervalNullPointerExceptionTest() throws Exception { + Mockito.when(MusicService.setAttribute(Matchers.anyString(), Matchers.anyString(), Matchers.anyString())) + .thenThrow(new NullPointerException()); + musicSession.setMaxInactiveInterval(duration); + } + + @Test + public void getMaxInactiveIntervalTest() throws Exception { + Mockito.when(MusicService.getAttribute(Matchers.anyString(), Matchers.anyString())) + .thenReturn(String.valueOf(duration)); + assertNotNull(musicSession.getMaxInactiveInterval()); + } + + @Test + public void getMaxInactiveIntervalDefaultDurationIntervalTest() throws Exception { + Mockito.when(MusicService.getAttribute(Matchers.anyString(), Matchers.anyString())).thenReturn(null); + assertNotNull(musicSession.getMaxInactiveInterval()); + } + + @Test + public void isExpiredFalseTest() throws Exception { + assertFalse(musicSession.isExpired()); + + } + + @Test + public void getAttributeTest() throws Exception { + Mockito.when(MusicService.getAttribute(Matchers.anyString(), Matchers.anyString())).thenReturn("test"); + assertNotNull(musicSession.getAttribute("test")); + } + + @Test + public void getAttributeNullPointerExceptionTest() throws Exception { + Mockito.when(MusicService.getAttribute(Matchers.anyString(), Matchers.anyString())) + .thenThrow(new NullPointerException()); + assertNull(musicSession.getAttribute("test")); + } + + @Test + public void getAttributeNamesTest() { + Set sessionAttrsDummy = new TreeSet<>(); + assertEquals(sessionAttrsDummy, musicSession.getAttributeNames()); + } + + @Test + public void setAttributeTest() throws Exception { + Mockito.when(MusicService.setAttribute(Matchers.anyString(), Matchers.any(Object.class), Matchers.anyString())) + .thenReturn(rt); + musicSession.setAttribute("test_attr_name", "test_attr_value"); + } + + @Test + public void setAttributeExceptionTest() throws Exception { + Mockito.when(MusicService.setAttribute(Matchers.anyString(), Matchers.any(Object.class), Matchers.anyString())) + .thenThrow(new NullPointerException()); + musicSession.setAttribute("test_attr_name", "test_attr_value"); + } + + @Test + public void setAttributeValueNullTest() throws Exception { + Mockito.when(MusicService.setAttribute(Matchers.anyString(), Matchers.any(Object.class), Matchers.anyString())) + .thenReturn(rt); + musicSession.setAttribute("test_attr_name", null); + } + + @Test + public void removeAttributeMusicServiceExceptionTest() throws MusicServiceException, MusicLockingException { + Mockito.when(MusicService.removeAttribute(Matchers.anyString(), Matchers.anyString())) + .thenThrow(new MusicServiceException()); + musicSession.removeAttribute("test_attr_name"); + } + + @Test + public void removeAttributeMusicLockingExceptionTest() throws MusicServiceException, MusicLockingException { + Mockito.when(MusicService.removeAttribute(Matchers.anyString(), Matchers.anyString())) + .thenThrow(new MusicLockingException()); + musicSession.removeAttribute("test_attr_name"); + } + + @Test + public void setCreationTime() { + Instant instant = Instant.now(); + musicSession.setCreationTime(instant); + } + + @Test + public void setCreationExceptionTime() throws Exception { + Instant instant = Instant.now(); + Mockito.when(MusicService.setAttribute(Matchers.anyString(), Matchers.any(Instant.class), Matchers.anyString())) + .thenThrow(new MusicLockingException()); + musicSession.setCreationTime(instant); + } +} diff --git a/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/model/RestResponseTest.java b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/model/RestResponseTest.java new file mode 100644 index 00000000..2f2dfaaa --- /dev/null +++ b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/model/RestResponseTest.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START========================================== + * ONAP + * =================================================================== + * 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============================================ + * + * + */ +package org.onap.portalapp.music.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class RestResponseTest { + + @Test + public void restResponseTest() { + RestResponse expected = new RestResponse<>(); + expected.setMessage("testMessage"); + expected.setResponse("testResponse"); + expected.setStatus(RestStatusEnum.ERROR); + RestResponse actual = new RestResponse(RestStatusEnum.ERROR, "testMessage", "testResponse"); + assertEquals(expected, actual); + assertEquals(expected.hashCode(), actual.hashCode()); + assertTrue(actual.equals(expected)); + } +} diff --git a/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/service/MusicServiceTest.java b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/service/MusicServiceTest.java new file mode 100644 index 00000000..b5479371 --- /dev/null +++ b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/service/MusicServiceTest.java @@ -0,0 +1,248 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalapp.music.service; + +import java.nio.ByteBuffer; +import java.time.Duration; +import java.time.Instant; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.music.datastore.PreparedQueryObject; +import org.onap.music.exceptions.MusicLockingException; +import org.onap.music.exceptions.MusicServiceException; +import org.onap.music.main.MusicCore; +import org.onap.music.main.ReturnType; +import org.onap.portalapp.music.util.MusicProperties; +import org.onap.portalapp.music.util.MusicUtil; +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.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.session.Session; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.web.client.RestTemplate; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MusicUtil.class, MusicCore.class, MusicProperties.class}) +public class MusicServiceTest { + @Mock + ReturnType returnType; + @Mock + ResultSet resultSet; + @Mock + RestTemplate restTemplate; + @Mock + Session session; + @Mock + Row row; + + @SuppressWarnings("unchecked") + @Before + public void setUp() throws MusicLockingException, MusicServiceException { + PowerMockito.mockStatic(MusicUtil.class); + PowerMockito.mockStatic(MusicCore.class); + Mockito.when(returnType.getMessage()).thenReturn("test"); + Mockito.when(row.getString(Mockito.anyString())).thenReturn("test"); + Mockito.when(resultSet.one()).thenReturn(row); + Mockito.when(MusicCore.atomicPut(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(PreparedQueryObject.class), Mockito.any(MusicCore.Condition.class))).thenReturn(returnType); + Mockito.when(MusicCore.eventualPut(Mockito.any(PreparedQueryObject.class))).thenReturn(returnType); + Mockito.when(MusicCore.atomicGet(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(PreparedQueryObject.class))).thenReturn(resultSet); + Mockito.when(MusicCore.get(Mockito.any(PreparedQueryObject.class))).thenReturn(resultSet); + Mockito.when(session.getAttribute(Mockito.anyString())).thenReturn("test"); + ResponseEntity entityResponse = Mockito.mock(ResponseEntity.class); + Mockito.when(entityResponse.getBody()).thenReturn("Success"); + Mockito.when(restTemplate.exchange(Mockito.any(String.class), Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class), Mockito.eq(String.class))).thenReturn(entityResponse); + Mockito.when(session.getCreationTime()).thenReturn(Instant.EPOCH); + Mockito.when(session.getLastAccessedTime()).thenReturn(Instant.EPOCH); + Mockito.when(session.getMaxInactiveInterval()).thenReturn(Duration.ZERO); + Mockito.when(MusicUtil.cleanUp()).thenReturn(true); + } + + @Test + public void testSetAttribute_WhenIsMetaIsTrue() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicPut", true); + Mockito.when(MusicUtil.isSessionMetaAttr(Mockito.anyString())).thenReturn(true); + MusicService.setAttribute("test", "test", "1"); + } + + @Test + public void testSetAttribute_WhenIsMetaIsFalse() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicPut", false); + Mockito.when(MusicUtil.isSessionMetaAttr(Mockito.anyString())).thenReturn(false); + ByteBuffer bb = Mockito.mock(ByteBuffer.class); + Mockito.when(MusicUtil.musicSerialize(Mockito.anyObject())).thenReturn(bb); + MusicService.setAttribute("test", "test", "1"); + } + + @Test + public void testSetMetaAttribute_WhenIsAutomicPutIsTrue() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicPut", true); + MusicService.setMetaAttribute(session); + } + + @Test + public void testSetMetaAttribute_WhenIsAutomicPutIsFalse() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicPut", false); + + MusicService.setMetaAttribute(session); + } + + @Test + public void testGetMetaAttribute_WhenIsAutomicPutIsTrue() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicGet", true); + MusicService.getMetaAttribute("test"); + } + + @Test + public void testGetMetaAttribute_WhenIsAutomicPutIsFalse() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicGet", false); + MusicService.getMetaAttribute("test"); + } + + @Test + public void testGetAttribute_WhenIsAutomicPutIsTrue() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicGet", true); + Mockito.when(MusicUtil.isSessionMetaAttr(Mockito.anyString())).thenReturn(true); + MusicService.getAttribute("test", "1"); + } + + @Test + public void testGetAttribute_WhenIsAutomicPutIsFalse() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicGet", false); + Mockito.when(MusicUtil.isSessionMetaAttr(Mockito.anyString())).thenReturn(false); + MusicService.getAttribute("test", "1"); + } + + @Test + public void testRemoveAttribute_WhenIsMetaIsTrue() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicPut", true); + Mockito.when(MusicUtil.isSessionMetaAttr(Mockito.anyString())).thenReturn(true); + MusicService.removeAttribute("test", "1"); + } + + @Test + public void testRemoveAttribute_WhenIsMetaIsFalse() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicPut", false); + Mockito.when(MusicUtil.isSessionMetaAttr(Mockito.anyString())).thenReturn(false); + ByteBuffer bb = Mockito.mock(ByteBuffer.class); + Mockito.when(MusicUtil.musicSerialize(Mockito.anyObject())).thenReturn(bb); + MusicService.removeAttribute("test", "1"); + } + + @Test + public void testRemoveSession_WhenIsMetaIsTrue() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicPut", true); + Mockito.when(MusicUtil.isSessionMetaAttr(Mockito.anyString())).thenReturn(true); + MusicService.removeSession("1"); + } + + @Test + public void testRemoveSession_WhenIsMetaIsFalse() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicPut", false); + Mockito.when(MusicUtil.isSessionMetaAttr(Mockito.anyString())).thenReturn(false); + ByteBuffer bb = Mockito.mock(ByteBuffer.class); + Mockito.when(MusicUtil.musicSerialize(Mockito.anyObject())).thenReturn(bb); + MusicService.removeSession("1"); + } + + @Test + public void testSetAttributeAPI_WhenIsMetaIsTrue() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "template", restTemplate); + MusicService.setAttributeAPI("test", "test", session, "test", "test", true); + } + + @Test + public void testSetAttributeAPI_WhenIsMetaIsFalse() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "template", null); + MusicService.setAttributeAPI("test", "test", session, "test", "test", false); + } + + @Test + public void testGetAttributeAPI_WhenIsMetaIsTrue() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "template", restTemplate); + MusicService.getAttributeAPI("test", session, "test", true); + } + + @Test + public void testGetAttributeAPI_WhenIsMetaIsFalse() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "template", null); + MusicService.getAttributeAPI("test", session, "test", false); + } + + @Test + public void testRemoveAttributeAPI_WhenIsMetaIsTrue() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "template", restTemplate); + MusicService.removeAttributeAPI("test", "1", true); + } + + @Test + public void testRemoveAttributeAPI_WhenIsMetaIsFalse() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "template", null); + MusicService.removeAttributeAPI("test", "1", false); + } + + @Test + public void testcleanUpMusic_WhenIsAutomicFlagsTrue() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicPut", true); + ReflectionTestUtils.setField(MusicService.class, "isAtomicGet", true); + Mockito.when(resultSet.one()).thenReturn(null); + PowerMockito.mockStatic(MusicProperties.class); + Mockito.when(MusicProperties.getProperty("music.cleanup.threshold")).thenReturn("0"); + MusicService.cleanUpMusic(); + } + + @Test + public void testcleanUpMusic_WhenIsAutomicFlagsFalse() throws Exception { + ReflectionTestUtils.setField(MusicService.class, "isAtomicPut", false); + ReflectionTestUtils.setField(MusicService.class, "isAtomicGet", false); + Mockito.when(resultSet.one()).thenReturn(null); + PowerMockito.mockStatic(MusicProperties.class); + Mockito.when(MusicProperties.getProperty("music.cleanup.threshold")).thenReturn("0"); + MusicService.cleanUpMusic(); + } + +} diff --git a/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/util/MusicPropertiesTest.java b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/util/MusicPropertiesTest.java new file mode 100644 index 00000000..27f7ed6c --- /dev/null +++ b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/util/MusicPropertiesTest.java @@ -0,0 +1,53 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalapp.music.util; + +import static org.junit.Assert.assertNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class MusicPropertiesTest { + + @Test + public void getPropertyTest() { + assertNull(MusicProperties.getProperty("test")); + } +} diff --git a/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/util/MusicUtilTest.java b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/util/MusicUtilTest.java new file mode 100644 index 00000000..008dcdfc --- /dev/null +++ b/ecomp-sdk/epsdk-music/src/test/java/org/onap/portalapp/music/util/MusicUtilTest.java @@ -0,0 +1,145 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ +package org.onap.portalapp.music.util; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.music.conf.MusicSession; +import org.onap.portalapp.music.service.MusicService; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ MusicProperties.class, MusicSession.class, MusicService.class, MusicCleanUp.class }) +public class MusicUtilTest { + + ResultSet result = Mockito.mock(ResultSet.class); + + Row rw = Mockito.mock(Row.class); + + @Before + public void setUp() throws Exception { + MusicCleanUp musCleapUp = mock(MusicCleanUp.class); + PowerMockito.mockStatic(MusicProperties.class); + PowerMockito.mockStatic(MusicSession.class); + PowerMockito.mockStatic(MusicService.class); + PowerMockito.mockStatic(MusicCleanUp.class); + Mockito.when(MusicProperties.getProperty(MusicProperties.MUSIC_ATOMIC_PUT)).thenReturn("atomic-put"); + Mockito.when(MusicProperties.getProperty(MusicProperties.MUSIC_ATOMIC_GET)).thenReturn("atomic-get"); + Mockito.when(MusicProperties.getProperty(MusicProperties.MUSIC_CACHE)).thenReturn("cache"); + Mockito.when(MusicProperties.getProperty(MusicProperties.MUSIC_EXCLUDE_API)).thenReturn("test1,test2"); + PowerMockito.when(MusicProperties.getProperty(MusicProperties.MUSIC_SERIALIZE_COMPRESS)).thenReturn("compress"); + PowerMockito.when(MusicCleanUp.getInstance()).thenReturn(musCleapUp); + PowerMockito.when(musCleapUp.getLastCleanUpTime()).thenReturn(null); + MockitoAnnotations.initMocks(this); + } + + @Test + public void isSessionMetaAttrTest() { + assertTrue(MusicUtil.isSessionMetaAttr("CREATION_TIME")); + } + + @Test + public void musicRestResponseDataParsingTest() throws Exception { + List rows = new ArrayList(); + Mockito.doReturn("creation time").when(rw).getString("CREATION_TIME"); + rows.add(rw); + Mockito.doReturn(rows.get(0)).when(result).one(); + assertNotNull(MusicUtil.musicRestResponseDataParsing(result, "CREATION_TIME")); + } + + @Test + public void getMusicExcludedAPITest() { + assertNotNull(MusicUtil.getMusicExcludedAPI()); + } + + @Test + public void isExcludedApiTest() { + assertTrue(MusicUtil.isExcludedApi("test1")); + } + + @Test + public void isExcludedApiFalseTest() { + assertFalse(MusicUtil.isExcludedApi("test3")); + } + + @Test + public void isMusicSerializeCompressReturnFalseTest() { + assertFalse(MusicUtil.isMusicSerializeCompress()); + } + + @Test + public void isAtomicPutTest() { + assertFalse(MusicUtil.isAtomicPut()); + } + + @Test + public void isAtomicGetTest() { + assertFalse(MusicUtil.isAtomicGet()); + } + + @Test + public void isCachedTest() { + assertFalse(MusicUtil.isCached()); + } + + @Test + public void convertHoursToMillSecTest() { + assertNotNull(MusicUtil.convertHoursToMillSec(1)); + } + + @Test + public void cleanUpTest() { + assertFalse(MusicUtil.cleanUp()); + } +} diff --git a/ecomp-sdk/epsdk-workflow/pom.xml b/ecomp-sdk/epsdk-workflow/pom.xml index eaac5a44..24d6b650 100644 --- a/ecomp-sdk/epsdk-workflow/pom.xml +++ b/ecomp-sdk/epsdk-workflow/pom.xml @@ -5,7 +5,7 @@ org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT diff --git a/ecomp-sdk/pom.xml b/ecomp-sdk/pom.xml index 8acbdac6..4f812a90 100644 --- a/ecomp-sdk/pom.xml +++ b/ecomp-sdk/pom.xml @@ -14,7 +14,7 @@ org.onap.portal.sdk epsdk-project - 2.4.0-SNAPSHOT + 2.5.0-SNAPSHOT pom portal-sdk https://wiki.onap.org/display/DW/Portal -- cgit 1.2.3-korg