From eaf5706321c88c17dc26a1eb2b35742ae1eeacb0 Mon Sep 17 00:00:00 2001 From: "Stone, Avi (as206k)" Date: Thu, 12 Apr 2018 15:57:26 +0300 Subject: DCAE-D ci initial commit DCAE-D ci initial commit Change-Id: I79313e4f2ce42452ff8e3ff2f5a17a5d1eaf4492 Issue-ID: SDC-1218 Signed-off-by: Stone, Avi (as206k) --- pom.xml | 85 ++++++ scripts/copyWarToEnv.sh | 50 ++++ scripts/remove-vfcmts/README.md | 11 + scripts/remove-vfcmts/filter-vfcmts.py | 19 ++ scripts/remove-vfcmts/get-unique-id.py | 15 + scripts/remove-vfcmts/get-uniques-only.py | 12 + scripts/remove-vfcmts/run.sh | 29 ++ scripts/remove-vfcmts/setup.sh | 4 + .../dcae/ci/api/healthcheck/HealthcheckTest.java | 62 ++++ .../ecomp/dcae/ci/api/tests/DcaeRestBaseTest.java | 196 +++++++++++++ .../tests/blueprint/SaveCompositionPositve.java | 110 +++++++ .../composition/CompositionControllerApiTests.java | 203 +++++++++++++ .../CompositionElementsControllerTests.java | 198 +++++++++++++ .../CompositionMicroServicesApiTests.java | 154 ++++++++++ .../composition/GetCompositionControllerTests.java | 106 +++++++ .../SaveAndSubmitCompositionFullFlowTest.java | 115 ++++++++ .../dcae/ci/api/tests/lifeCycle/ArrangeHelper.java | 68 +++++ .../dcae/ci/api/tests/lifeCycle/PutCertify.java | 49 ++++ .../dcae/ci/api/tests/lifeCycle/PutCheckin.java | 145 ++++++++++ .../dcae/ci/api/tests/lifeCycle/PutCheckout.java | 148 ++++++++++ .../ci/api/tests/ruleEditor/GetDefinitionTest.java | 137 +++++++++ .../ruleEditor/GetListEventsAndVersionsTest.java | 47 +++ .../tests/ruleEditor/RuleEditorControllerTest.java | 319 +++++++++++++++++++++ .../tests/services/attachment/GetAttachment.java | 62 ++++ .../tests/services/attachment/PostAttachment.java | 172 +++++++++++ .../instance/GetServiceInstanceNagative.java | 24 ++ .../instance/GetServiceInstancePositive.java | 122 ++++++++ .../services/list/GetAllServicesNagative.java | 48 ++++ .../services/list/GetAllServicesPositive.java | 72 +++++ .../api/tests/vfcmt/CreateMonitoringComponent.java | 253 ++++++++++++++++ .../ecomp/dcae/ci/api/tests/vfcmt/CreateVfcmt.java | 140 +++++++++ .../vfcmt/GetAllMonitoringTemplateVfcmts.java | 60 ++++ .../dcae/ci/api/tests/vfcmt/GetAllVfcmts.java | 54 ++++ .../ci/api/tests/vfcmt/GetVfcmtsForMigration.java | 104 +++++++ .../dcae/ci/api/tests/vfcmt/VfcmtCreationFlow.java | 37 +++ .../ci/entities/composition/items/Artifact.java | 109 +++++++ .../dcae/ci/entities/composition/items/Data.java | 21 ++ .../entities/composition/items/DcaeComponents.java | 54 ++++ .../ci/entities/composition/items/Element.java | 55 ++++ .../dcae/ci/entities/composition/items/Error.java | 8 + .../dcae/ci/entities/composition/items/Item.java | 220 ++++++++++++++ .../dcae/ci/entities/composition/items/Model.java | 65 +++++ .../composition/rightMenu/element/Artifact.java | 109 +++++++ .../composition/rightMenu/element/Item.java | 220 ++++++++++++++ .../rightMenu/element/ItemsElement.java | 55 ++++ .../composition/rightMenu/element/Model.java | 65 +++++ .../composition/rightMenu/element/Service.java | 21 ++ .../composition/rightMenu/elements/Element.java | 76 +++++ .../composition/rightMenu/elements/Elements.java | 18 ++ .../entities/composition/services/CiService.java | 11 + .../dcae/ci/entities/composition/services/Vfi.java | 21 ++ .../ci/entities/rule_editor/SaveRuleError.java | 27 ++ .../ecomp/dcae/ci/entities/sdc/SdcCategory.java | 20 ++ .../ecomp/dcae/ci/entities/sdc/SdcComponent.java | 40 +++ .../dcae/ci/entities/sdc/SdcComponentMetadata.java | 12 + .../com/att/ecomp/dcae/ci/run/RunTestSuite.java | 11 + .../dcae/ci/ui/pages/DCAECompositionPage.java | 70 +++++ .../ecomp/dcae/ci/ui/pages/DCAEGeneralPage.java | 41 +++ .../att/ecomp/dcae/ci/ui/pages/DCAEHomePage.java | 27 ++ .../att/ecomp/dcae/ci/ui/pages/DCAELeftPanel.java | 28 ++ .../ecomp/dcae/ci/ui/pages/DCAEServicesPage.java | 38 +++ .../dcae/ci/ui/pages/SDCCreateServicePage.java | 175 +++++++++++ .../ecomp/dcae/ci/ui/pages/SDCCreateVFPage.java | 123 ++++++++ .../att/ecomp/dcae/ci/ui/pages/SDCHomePage.java | 60 ++++ .../att/ecomp/dcae/ci/ui/rule_editor/BaseTest.java | 143 +++++++++ .../dcae/ci/ui/rule_editor/TranslateResult.java | 32 +++ .../ui/rule_editor/components/BaseComponenet.java | 15 + .../ci/ui/rule_editor/components/HomePage.java | 113 ++++++++ .../ci/ui/rule_editor/components/LoginPage.java | 39 +++ .../ui/rule_editor/components/RuleComponent.java | 40 +++ .../ci/ui/rule_editor/components/RulePopup.java | 141 +++++++++ .../components/actions/ActionComponent.java | 48 ++++ .../rule_editor/components/actions/ActionType.java | 7 + .../components/actions/ConcatActionComponent.java | 31 ++ .../components/actions/CopyActionComponent.java | 24 ++ .../components/actions/MapActionComponent.java | 44 +++ .../actions/from/DeleteableFromComponent.java | 26 ++ .../actions/from/RegexFromComponent.java | 38 +++ .../actions/from/SimpleFromComponent.java | 34 +++ .../components/condition/ConditionComponent.java | 34 +++ .../dcae/ci/ui/rule_editor/tests/SanityTest.java | 150 ++++++++++ .../com/att/ecomp/dcae/ci/ui/setup/ConfigTest.java | 83 ++++++ .../ecomp/dcae/ci/ui/setup/DcaeConfiguration.java | 48 ++++ .../com/att/ecomp/dcae/ci/ui/tests/DCAESanity.java | 99 +++++++ .../com/att/ecomp/dcae/ci/ui/tests/SanityTest.java | 108 +++++++ .../att/ecomp/dcae/ci/ui/tests/ServiceTest.java | 42 +++ .../tests/verificator/CompositionVerificator.java | 16 ++ .../ui/tests/verificator/ServiceVerificator.java | 22 ++ .../com/att/ecomp/dcae/ci/ui/utils/ByTest.java | 17 ++ .../com/att/ecomp/dcae/ci/ui/utils/Locator.java | 74 +++++ .../att/ecomp/dcae/ci/ui/utils/NestedFilter.java | 28 ++ .../att/ecomp/dcae/ci/ui/utils/NestedFinder.java | 28 ++ .../dcae/ci/utilities/ConfigurationReader.java | 41 +++ .../ecomp/dcae/ci/utilities/DcaeEntityClient.java | 139 +++++++++ .../ecomp/dcae/ci/utilities/DcaeRestClient.java | 247 ++++++++++++++++ .../ecomp/dcae/ci/utilities/DcaeTestConstants.java | 19 ++ .../com/att/ecomp/dcae/ci/utilities/DcaeUtil.java | 200 +++++++++++++ .../com/att/ecomp/dcae/ci/utilities/Report.java | 26 ++ .../dcae/ci/utilities/SdcInternalApiClient.java | 131 +++++++++ .../att/ecomp/dcae/ci/utilities/StringUtils.java | 16 ++ src/main/resources/conf/conf.yaml | 28 ++ src/main/resources/conf/credentials.yaml | 48 ++++ src/main/resources/conf/credentials.yaml_prod | 48 ++++ src/main/resources/conf/credentials.yaml_webtest | 48 ++++ src/main/resources/conf/dcae_tests_conf.yaml.erb | 28 ++ src/main/resources/conf/log4j.properties | 34 +++ src/main/resources/scripts/run.sh | 50 ++++ src/main/resources/testSuite/testSuite.xml | 31 ++ src/main/resources/testSuite/testSuiteSelenium.xml | 10 + 109 files changed, 7898 insertions(+) create mode 100644 pom.xml create mode 100644 scripts/copyWarToEnv.sh create mode 100644 scripts/remove-vfcmts/README.md create mode 100644 scripts/remove-vfcmts/filter-vfcmts.py create mode 100644 scripts/remove-vfcmts/get-unique-id.py create mode 100644 scripts/remove-vfcmts/get-uniques-only.py create mode 100644 scripts/remove-vfcmts/run.sh create mode 100644 scripts/remove-vfcmts/setup.sh create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/healthcheck/HealthcheckTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/DcaeRestBaseTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/blueprint/SaveCompositionPositve.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionControllerApiTests.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionElementsControllerTests.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionMicroServicesApiTests.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/GetCompositionControllerTests.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/SaveAndSubmitCompositionFullFlowTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/ArrangeHelper.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCertify.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCheckin.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCheckout.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/GetDefinitionTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/GetListEventsAndVersionsTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/RuleEditorControllerTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/services/attachment/GetAttachment.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/services/attachment/PostAttachment.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/services/instance/GetServiceInstanceNagative.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/services/instance/GetServiceInstancePositive.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/services/list/GetAllServicesNagative.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/services/list/GetAllServicesPositive.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/CreateMonitoringComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/CreateVfcmt.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetAllMonitoringTemplateVfcmts.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetAllVfcmts.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetVfcmtsForMigration.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/VfcmtCreationFlow.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Artifact.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Data.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/DcaeComponents.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Element.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Error.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Item.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Model.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Artifact.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Item.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/ItemsElement.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Model.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Service.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/elements/Element.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/elements/Elements.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/services/CiService.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/composition/services/Vfi.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/rule_editor/SaveRuleError.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcCategory.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcComponentMetadata.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/run/RunTestSuite.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAECompositionPage.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEGeneralPage.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEHomePage.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAELeftPanel.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEServicesPage.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCCreateServicePage.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCCreateVFPage.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCHomePage.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/BaseTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/TranslateResult.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/BaseComponenet.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/HomePage.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/LoginPage.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/RuleComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/RulePopup.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ActionComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ActionType.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ConcatActionComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/CopyActionComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/MapActionComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/DeleteableFromComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/RegexFromComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/SimpleFromComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/condition/ConditionComponent.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/tests/SanityTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/setup/ConfigTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/setup/DcaeConfiguration.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/tests/DCAESanity.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/tests/SanityTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/tests/ServiceTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/tests/verificator/CompositionVerificator.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/tests/verificator/ServiceVerificator.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/utils/ByTest.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/utils/Locator.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/utils/NestedFilter.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/ui/utils/NestedFinder.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/utilities/ConfigurationReader.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeEntityClient.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeRestClient.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeTestConstants.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeUtil.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/utilities/Report.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/utilities/SdcInternalApiClient.java create mode 100644 src/main/java/com/att/ecomp/dcae/ci/utilities/StringUtils.java create mode 100644 src/main/resources/conf/conf.yaml create mode 100644 src/main/resources/conf/credentials.yaml create mode 100644 src/main/resources/conf/credentials.yaml_prod create mode 100644 src/main/resources/conf/credentials.yaml_webtest create mode 100644 src/main/resources/conf/dcae_tests_conf.yaml.erb create mode 100644 src/main/resources/conf/log4j.properties create mode 100644 src/main/resources/scripts/run.sh create mode 100644 src/main/resources/testSuite/testSuite.xml create mode 100644 src/main/resources/testSuite/testSuiteSelenium.xml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d039caf --- /dev/null +++ b/pom.xml @@ -0,0 +1,85 @@ + + 4.0.0 + org.onap.sdc.dcae-ci-tests + dcae-ci-tests + 1806.0.1-SNAPSHOT + DCAE Tests + jar + Tests for DCAE Designer + + + 1.8 + 1.8 + + + + + + org.openecomp.d2 + ui-api-ci + 1.0.1-SNAPSHOT + + + + + org.assertj + assertj-core + 3.8.0 + compile + + + + org.onap.sdc.dcae.property + DCAE-DT-PROPERTY + ${project.version} + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.5.5 + + + create.jar.with.dependencies + package + + single + + + + + com.att.ecomp.dcae.ci.run.RunTestSuite + + + + jar-with-dependencies + + + + + + + + + + + nexus + 2020 + http://mavencentral.it.att.com:8084/nexus/content/groups/2020SAPC/ + default + + + + ATT public + ATT public + http://mavencentral.it.att.com:8084/nexus/content/groups/att-public-group/ + default + + + + + diff --git a/scripts/copyWarToEnv.sh b/scripts/copyWarToEnv.sh new file mode 100644 index 0000000..b855ae0 --- /dev/null +++ b/scripts/copyWarToEnv.sh @@ -0,0 +1,50 @@ +#!/bin/bash +if [ $# -ne 2 ] +then + echo "No arguments supplied. Please pass CURRENT_WAR NEW_WAR_URL" + exit 1 +fi + +CURRENT_WAR=$1 +NEW_WAR_URL=$2 +WEBAPPS=/opt/app/jetty/base/fe/webapps +BACKUP_DIR=/opt/app/jetty/base/fe +LOG_DIR=/opt/logs/fe + +# echo "sudo to root user..." +# sudo /usr/localcw/bin/eksh -c "sudo -i" + +echo "creating BACKUPS directory if not already exists..." +mkdir -p $BACKUP_DIR/BACKUPS +chmod 777 $BACKUP_DIR/BACKUPS + +echo "jettyFE server stopping..." +service jettyFE stop + +cd $WEBAPPS + +echo "backing up current war file…" +# Define a timestamp function +timestamp=$(date +%Y%m%d%H%M%S) +mv $CURRENT_WAR* $BACKUP_DIR/BACKUPS/$CURRENT_WAR.backup_${timestamp} + +echo "downloading file from NEXUS. File="$NEW_WAR_URL +cd $WEBAPPS +wget $NEW_WAR_URL + +echo "chown and chmod..." +chown m98835:mechid * +chmod 775 * + +echo "Deleting all logs…" +if [ -d LOG_DIR ]; +then + rm –rf LOG_DIR/*; +fi + +echo "jettyFE server starting..." +service jettyFE start + +echo "open log" +cd $LOG_DIR +tailf "`ls -t | head -1`" \ No newline at end of file diff --git a/scripts/remove-vfcmts/README.md b/scripts/remove-vfcmts/README.md new file mode 100644 index 0000000..19bae49 --- /dev/null +++ b/scripts/remove-vfcmts/README.md @@ -0,0 +1,11 @@ +# Remove all VFCMTs + +## Setup +1. Execute dos2unix on all script files: `find . -type f -print0 | xargs -0 dos2unix` +2. Give execute permissions to setup.sh: `chmod +x setup.sh` +3. Run `./setup.sh` + +## Usage +Run `run.sh` with the path to the *exportGraph file* + +Example: `./run.sh "/var/tmp/exportGraph.1500391226269.json"` diff --git a/scripts/remove-vfcmts/filter-vfcmts.py b/scripts/remove-vfcmts/filter-vfcmts.py new file mode 100644 index 0000000..54c77e3 --- /dev/null +++ b/scripts/remove-vfcmts/filter-vfcmts.py @@ -0,0 +1,19 @@ +#!python -u + +import sys +import json + + +def is_vfcmt(str_json): + data = json.loads(str_json) + try: + resource_type = data["properties"]["resourceType"] + value = resource_type[0]["value"] + return value == "VFCMT" + except: + return False + + +for line in sys.stdin: + if is_vfcmt(line): + print line, \ No newline at end of file diff --git a/scripts/remove-vfcmts/get-unique-id.py b/scripts/remove-vfcmts/get-unique-id.py new file mode 100644 index 0000000..28b342d --- /dev/null +++ b/scripts/remove-vfcmts/get-unique-id.py @@ -0,0 +1,15 @@ +#!python -u + +import sys +import json + + +def get_unique_id(str_json): + data = json.loads(str_json) + str_metadata_value = data["properties"]["metadata"][0]["value"] + metadata_value = json.loads(str_metadata_value) + return metadata_value["uniqueId"] + + +for line in sys.stdin: + print get_unique_id(line) \ No newline at end of file diff --git a/scripts/remove-vfcmts/get-uniques-only.py b/scripts/remove-vfcmts/get-uniques-only.py new file mode 100644 index 0000000..a05a380 --- /dev/null +++ b/scripts/remove-vfcmts/get-uniques-only.py @@ -0,0 +1,12 @@ +#!python -u + +import sys +import json + + +uniques = set() +for line in sys.stdin: + uniques.add(line) + +for item in uniques: + print item, \ No newline at end of file diff --git a/scripts/remove-vfcmts/run.sh b/scripts/remove-vfcmts/run.sh new file mode 100644 index 0000000..65c40ab --- /dev/null +++ b/scripts/remove-vfcmts/run.sh @@ -0,0 +1,29 @@ +src_file=$1 + +echo "getting all vfcmt resources ids..." +cat $src_file \ +| python filter-vfcmts.py \ +| tee temp/vfcmts.txt \ +| python get-unique-id.py \ +| tr -d '\r' \ +| tee temp/vfcmts-unique-ids.txt +echo "number of vfcmts:" `cat temp/vfcmts.txt | wc -l ` +echo "number of unique vfcmts:" `cat temp/vfcmts-unique-ids.txt | python get-uniques-only.py | wc -l` + +read -p "Press enter to start delete" + +while read -r line; do + echo -e "\nDeleting $line ..." + curl -sS "http://localhost:8080/sdc2/rest/v1/catalog/resources/$line" \ + -X DELETE \ + -H "Content-Type: application/json" \ + -H "Accept: application/json" \ + -H "USER_ID: jh0003" +done { + assertHealthStructure(softly, hcData, "DCAE Designer"); + List componentsInfo = hcData.getComponentsInfo(); + softly.assertThat(componentsInfo).extracting("healthCheckComponent").contains("BE", "TOSCA_LAB"); + assertHealthComponentStructure(softly, hcData.getComponentsInfo().get(0)); + assertHealthComponentStructure(softly, hcData.getComponentsInfo().get(1)); + }); + } + + private void assertHealthStructure(SoftAssertions softly, HealthResponse hcData, String name) { + softly.assertThat(hcData.getHealthCheckComponent()).isEqualTo(name); + softly.assertThat(hcData.getHealthCheckStatus()).isEqualTo("UP"); + softly.assertThat(hcData.getSdcVersion()).isNotEmpty(); + softly.assertThat(hcData.getDescription()).isNotEmpty(); + } + + private void assertHealthComponentStructure(SoftAssertions softly, ComponentsInfo hcData) { + softly.assertThat(hcData.getHealthCheckStatus()).isEqualTo("UP"); + softly.assertThat(hcData.getVersion()).isNotEmpty(); + softly.assertThat(hcData.getDescription()).isNotEmpty(); + } +} \ No newline at end of file diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/DcaeRestBaseTest.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/DcaeRestBaseTest.java new file mode 100644 index 0000000..2dd0646 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/DcaeRestBaseTest.java @@ -0,0 +1,196 @@ +package com.att.ecomp.dcae.ci.api.tests; + +import com.att.ecomp.dcae.ci.entities.composition.services.CiService; +import com.att.ecomp.dcae.ci.entities.sdc.SdcComponent; +import com.att.ecomp.dcae.ci.utilities.*; +import org.openecomp.d2.ci.datatypes.Configuration; +import org.openecomp.d2.ci.setup.SetupReport; + +import com.aventstack.extentreports.Status; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.onap.sdc.dcae.composition.model.Requirement; +import org.onap.sdc.dcae.composition.model.Value; +import org.onap.sdc.dcae.composition.model.deserializer.RequirementDeserializer; +import org.onap.sdc.dcae.composition.model.deserializer.ValueDeserializer; +import org.onap.sdc.dcae.composition.restmodels.ruleeditor.ActionDeserializer; +import org.onap.sdc.dcae.composition.restmodels.ruleeditor.BaseAction; +import org.onap.sdc.dcae.composition.restmodels.ruleeditor.BaseCondition; +import org.onap.sdc.dcae.composition.restmodels.ruleeditor.ConditionDeserializer; +import org.onap.sdc.dcae.composition.services.Artifact; +import org.onap.sdc.dcae.composition.services.Resource; +import org.onap.sdc.dcae.composition.services.Service; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import org.openecomp.d2.ci.api.ElementFactory; +import org.openecomp.d2.ci.api.ResponseParser; +import org.openecomp.d2.ci.api.ServiceRestUtils; +import org.openecomp.d2.ci.api.VfRestUtils; +import org.openecomp.d2.ci.datatypes.*; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.utilities.GeneralUtility; +import org.testng.annotations.AfterSuite; + +import java.io.IOException; +import java.util.*; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Collections; + + +public class DcaeRestBaseTest extends SetupReport { + + public static Gson gson = null; + protected DcaeEntityClient client = new DcaeEntityClient(); + + public DcaeRestBaseTest() { + super(); + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(Requirement.class, new RequirementDeserializer()); + gsonBuilder.registerTypeAdapter(Value.class, new ValueDeserializer()); + gsonBuilder.registerTypeAdapter(BaseAction.class, new ActionDeserializer()); + gsonBuilder.registerTypeAdapter(BaseCondition.class, new ConditionDeserializer()); + gson = gsonBuilder.create(); + } + + @Override + protected Configuration getEnvConfiguration() { + return ConfigurationReader.getConfiguration(); + } + + protected Service createServiceWithVFiAsSdcDesigner() throws Exception{ + ExtentTestActions.log(Status.INFO, "Create Service with VFi as SDC Designer method started"); + ServiceReqDetails defaultService = ElementFactory.getDefaultService(); + + ExtentTestActions.log(Status.INFO, "Going to create service with name " + defaultService.getName()); + ResourceReqDetails vf = ElementFactory.getDefaultResource(ResourceTypeEnum.VF); + + User defaultUser = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + + RestResponse createServiceRes = ServiceRestUtils.createService(defaultService, defaultUser); + Status logSts = checkForErrors(createServiceRes); + ExtentTestActions.log(logSts, "Service with uuid " + defaultService.getUUID() +" created"); + + RestResponse createResourceRes = VfRestUtils.createResource(vf, defaultUser); + logSts = checkForErrors(createResourceRes); + ExtentTestActions.log(logSts, "VF with uuid " + vf.getUUID() +" created"); + + RestResponse changeResourceStateRes = VfRestUtils.changeResourceState(vf, defaultUser, LifeCycleStatesEnum.CHECKIN); + logSts = checkForErrors(changeResourceStateRes); + ExtentTestActions.log(logSts, "VF with uuid " + vf.getUUID() + " was checked in"); + + RestResponse createVfiRes = ServiceRestUtils.createComponentInstance(defaultService, vf, defaultUser, ComponentTypeEnum.RESOURCE, true); + logSts = checkForErrors(createVfiRes); + ExtentTestActions.log(logSts, "VF instance added to service"); + + String vfiName = ResponseParser.getValueFromJsonResponse(createVfiRes.getResponse(), "name"); + return convertToDcaeServiceWithVfi(defaultService, vfiName); + + } + + private Status checkForErrors(RestResponse httpResponse) { + Status logSts = httpResponse.getStatusCode()==200 || httpResponse.getStatusCode()==201 ? Status.INFO : Status.ERROR; + assertThat(httpResponse.getStatusCode()).isIn(200, 201); + return logSts; + } + + // converts from ui-api-ci object to dcae-ci object (partial construction) + private Service convertToDcaeServiceWithVfi(ServiceReqDetails service, String vfiName){ + Service newService = new CiService(service); + Resource newVfi = new Resource(); + newVfi.setResourceInstanceName(vfiName); + newService.setResources(Arrays.asList(newVfi)); + return newService; + } + + protected Vfcmt createVfcmt() throws IOException { + String newName = "CI" + GeneralUtility.generateUUIDforSufix(); + Report.log(Status.INFO, "createVfcmt start"); + RestResponse res = DcaeRestClient.createVfcmt(newName, "description"); + Report.log(Status.INFO, "createVfcmt response=%s", res); + assertThat(res.getStatusCode()).isEqualTo(200); + return gson.fromJson(res.getResponse(), Vfcmt.class); + } + + protected Artifact fetchVfcmtArtifactMetadataByName(String vfcmtUid, String artifactName) throws IOException { + Report.log(Status.INFO, "fetchVfcmtArtifactMetadataByName, vfcmtUid="+vfcmtUid+", artifactName"+artifactName); + RestResponse res = DcaeRestClient.getResourceDetails(vfcmtUid); + Resource vfcmt = gson.fromJson(res.getResponse(), Resource.class); + return vfcmt.getArtifacts().stream() + .filter(a -> artifactName.equalsIgnoreCase(a.getArtifactName())) + .findAny() + .orElse(null); + } + + //***** delete all assets created by test users - uses internal SDC API ****// + + @AfterSuite(alwaysRun = true) + public static void cleanup() throws IOException { + + final String resources = "resources"; + final String services = "services"; + List testUsers = Collections.synchronizedList(Arrays.asList(UserRoleEnum.DESIGNER.getUserId(), UserRoleEnum.DESIGNER2.getUserId())); + Map> testComponents = testUsers.parallelStream() + .map(DcaeRestBaseTest::getSafeComponentByUser) + .flatMap(m -> m.entrySet().stream()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> { + v1.addAll(v2); + return v1; + })); + collectAllResourceIds(Collections.synchronizedList(testComponents.get(resources))).parallelStream().forEach(id -> deleteAsset(resources, id)); + collectAllServiceIds(Collections.synchronizedList(testComponents.get(services))).parallelStream().forEach(id -> deleteAsset(services, id)); + SdcInternalApiClient.deleteMarkedResources(); + SdcInternalApiClient.deleteMarkedServices(); + } + + private static Set getUidsToDelete(String context, SdcComponent component) { + try { + return Arrays.asList("0.1", "1.0").contains(component.getVersion()) ? Collections.singleton(component.getUniqueId()) : + new HashSet<>(SdcInternalApiClient.getAssetMetadata(context, component.getUniqueId(), component.getLastUpdaterUserId()).getMetadata().getAllVersions().values()); + } catch (Exception e) { + Report.log(Status.ERROR, "failed to fetch sdc component: %s, Error: %s", component.getUniqueId(), e); + return Collections.emptySet(); + } + } + + private static Set collectAllResourceIds(List resources) { + Predicate deleteResource = p -> Arrays.asList("VF", "VFCMT").contains(p.getResourceType()) && !"Base Monitoring Template".equals(p.getCategories().get(0).getSubcategories().get(0).getName()); + Set resourceIds = Collections.synchronizedSet(resources.parallelStream() + .filter(deleteResource) + .map(r -> getUidsToDelete("resources", r)) + .flatMap(Set::stream) + .collect(Collectors.toSet())); + Report.log(Status.INFO, "collected %s resourceIds", resourceIds.size()); + return resourceIds; + } + + private static Set collectAllServiceIds(List services) { + Set serviceIds = Collections.synchronizedSet(services.parallelStream() + .map(c -> getUidsToDelete("services", c)) + .flatMap(Set::stream) + .collect(Collectors.toSet())); + Report.log(Status.INFO, "collected %s serviceIds", serviceIds.size()); + return serviceIds; + } + + private static Map> getSafeComponentByUser(String userId) { + try { + return SdcInternalApiClient.getAssetsByUser(userId); + } catch (Exception e){ + Report.log(Status.ERROR, "failed to fetch followed components. Error: %s", e); + return new HashMap<>(); + } + } + + private static void deleteAsset(String context, String id) { + try { + Report.log(Status.INFO, "about to delete sdc asset(%s): %s", context, id); + SdcInternalApiClient.deleteAssetFromSdc(context, id); + } catch (Exception e){ + Report.log(Status.ERROR, "failed to delete sdc asset(%s): %s, Error: %s" ,context, id, e); + } + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/blueprint/SaveCompositionPositve.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/blueprint/SaveCompositionPositve.java new file mode 100644 index 0000000..17dcce8 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/blueprint/SaveCompositionPositve.java @@ -0,0 +1,110 @@ +package com.att.ecomp.dcae.ci.api.tests.blueprint; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.DcaeUtil; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.att.ecomp.dcae.ci.utilities.StringUtils; +import com.aventstack.extentreports.Status; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.text.WordUtils; +import org.assertj.core.api.SoftAssertions; +import org.onap.sdc.dcae.composition.restmodels.sdc.Resource; +import org.onap.sdc.dcae.composition.services.Service; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SaveCompositionPositve extends DcaeRestBaseTest { + + private RestResponse response; + private static final String VFCMT_NAME = "teSt.__.monitoring---TempLATE."; + + private Vfcmt createVFCMTAndServiceWithVFIAndAttach() throws Exception{ + Report.log(Status.INFO, "createVFCMTAndServiceWithVFIAndAttach start"); + Vfcmt newVfcmt = createNewVfcmt(); + + // create a service in sdc + Service newService = createServiceWithVFiAsSdcDesigner(); + + String serviceUuid = newService.getUuid(); + String vfiName = newService.getResources().get(0).getResourceInstanceName(); + String vfcmtId = newVfcmt.getUuid(); + + // attach VFCMT to vfi and service (creation of svc_reference file in the BE) + Report.log(Status.INFO, "Going to attach the created service and VFi to the VFCMT"); + RestResponse res = DcaeRestClient.attachVfiRef(vfcmtId, serviceUuid, vfiName); + Report.log(Status.INFO, "attachment result="+res); + + return newVfcmt; + } + + private Vfcmt createNewVfcmtWithoutArtifact() throws Exception{ + Report.log(Status.INFO, "createNewVfcmtWithoutArtifact"); + Vfcmt newVfcmt = createNewVfcmt(); + return newVfcmt; + } + + private Vfcmt createNewVfcmt() throws Exception { + String randomSuffix = WordUtils.capitalize(RandomStringUtils.randomAlphanumeric(4).toLowerCase()); + Vfcmt newVfcmt = createVfcmtInstance(randomSuffix); + return newVfcmt; + } + + private Vfcmt createVfcmtInstance(String randomSuffix) throws Exception{ + String newName = VFCMT_NAME + randomSuffix; + RestResponse res = DcaeRestClient.createVfcmt(newName,"description"); + assertThat(res.getStatusCode()).isEqualTo(200); + return gson.fromJson(res.getResponse(), Vfcmt.class); + } + + + + @Test + public void test_responseStatusOkAndCreateMode() throws Exception{ + // assert + ExtentTestActions.log(Status.INFO, "Save Composition init"); + Vfcmt vfcmtWithoutArtifactUuid = createNewVfcmtWithoutArtifact(); + String uuid = vfcmtWithoutArtifactUuid.getUuid(); + String lastUpdaterUserId = vfcmtWithoutArtifactUuid.getLastUpdaterUserId(); + response = DcaeRestClient.saveComposition(uuid, lastUpdaterUserId); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + ExtentTestActions.log(Status.INFO, "Verifing response status is 200"); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + softly.assertThat((gson.fromJson(response.getResponse(), Resource.class)).getVersion()) + .as("version") + .isEqualTo("0.1"); + }); + } + + @Test + public void test_updateMode() throws Exception { + // assert + ExtentTestActions.log(Status.INFO, "Save Composition init"); + Vfcmt vfcmtWithArtifactUuid = createVFCMTAndServiceWithVFIAndAttach(); + String uuid = vfcmtWithArtifactUuid.getUuid(); + String lastUpdaterUserId = vfcmtWithArtifactUuid.getLastUpdaterUserId(); + ExtentTestActions.log(Status.INFO, "New VFCMT uuid="+uuid+", lastUpdaterUserId="+lastUpdaterUserId); + //generate cdump + String cdump = DcaeUtil.generateCdumpFromSnmpModels(uuid); + // save composition.yml + ExtentTestActions.log(Status.INFO, "Going to Save the composition now"); + DcaeRestClient.saveComposition(uuid, lastUpdaterUserId, cdump); + // update + response = DcaeRestClient.saveComposition(uuid, lastUpdaterUserId, cdump); + ExtentTestActions.log(Status.DEBUG, "Save composition Response: " + StringUtils.truncate(response)); + ExtentTestActions.log(Status.INFO, "Verifying response status is 200"); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + softly.assertThat((gson.fromJson(response.getResponse(), Resource.class)).getVersion()) + .as("version") + .isEqualTo("0.3"); + }); + } + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionControllerApiTests.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionControllerApiTests.java new file mode 100644 index 0000000..9f8833b --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionControllerApiTests.java @@ -0,0 +1,203 @@ +package com.att.ecomp.dcae.ci.api.tests.composition; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.text.WordUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.json.simple.parser.ParseException; +import org.onap.sdc.dcae.composition.services.Artifact; +import org.onap.sdc.dcae.composition.util.DcaeBeConstants; +import org.openecomp.d2.ci.api.ResponseParser; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.testng.annotations.Test; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import org.onap.sdc.dcae.composition.services.Resource; +import org.onap.sdc.dcae.composition.services.Service; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.DcaeUtil; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; +import com.google.gson.JsonObject; + +public class CompositionControllerApiTests extends DcaeRestBaseTest { + + private static final String EVENT_PROC_BP_YAML = "event_proc_bp.yaml"; + private static final String CREATE_BLUEPRINT_DESCRIPTION = "creating new artifact blueprint on the service vfi"; + private static final String UPDATE_BLUEPRINT_DESCRIPTION = "updating artifact blueprint on the service vfi"; + private static final String VFCMT_NAME = "teSt.__.monitoring---TempLATE."; + private static final String NORMALIZED_VFCMT_NAME = "TestMonitoringTemplate"; + + @Test + public void createMultipleBlueprintsTest() throws Exception { + Report.log(Status.INFO, "createMultipleBlueprintsTest start"); + String randomSuffix = WordUtils.capitalize(RandomStringUtils.randomAlphanumeric(4).toLowerCase()); + Vfcmt newVfcmt = createVfcmt(randomSuffix); + + // create a service in sdc + Service newService = createServiceWithVFiAsSdcDesigner(); + + String serviceUuid = newService.getUuid(); + String vfiName = newService.getResources().get(0).getResourceInstanceName(); + String vfcmtId = newVfcmt.getUuid(); + + // attach VFCMT to vfi + Report.log(Status.INFO, "Trying to attach the service+vfi to the vfcmt. serviceUuid="+serviceUuid+", vfiName="+vfiName+", vfcmtId="+vfcmtId); + RestResponse res = DcaeRestClient.attachVfiRef(vfcmtId, serviceUuid, vfiName); + assertThat(res.getStatusCode()).isEqualTo(200); + + //generate and save composition.yml(cdump) + generateAndSaveCdump(vfcmtId); + + String bpType1 = "bpType t1"; + String bpType2 = "bpType T2"; + String normalizedVfcmtName = NORMALIZED_VFCMT_NAME + randomSuffix; + List> expectedBpDetails = Arrays.asList(buildBlueprintDetails(bpType1, normalizedVfcmtName), buildBlueprintDetails(bpType2, normalizedVfcmtName)); + + // submit - generate and save type1 blueprint artifact + Report.log(Status.INFO, "Going to Submit the composition with vfcmtId="+vfcmtId+", serviceUuid="+serviceUuid+", vfiName="+vfiName+", TYPE1="+bpType1); + res = DcaeRestClient.submitComposition(vfcmtId, serviceUuid, vfiName, bpType1); + assertBlueprintSuccessResponse(res); + + // 1806 US 374593 assert vfcmt is certified + res = DcaeRestClient.getResourceDetails(vfcmtId); + newVfcmt = gson.fromJson(res.getResponse(), Vfcmt.class); + Report.log(Status.INFO, "Checking lifecycle state of vfcmt after first blueprint submission. State = {}", newVfcmt.getLifecycleState()); + assertThat(newVfcmt.getLifecycleState()).isEqualTo(DcaeBeConstants.LifecycleStateEnum.CERTIFIED.name()); + Report.log(Status.INFO, "Checking version of vfcmt after first blueprint submission. Version = {}", newVfcmt.getVersion()); + assertThat(newVfcmt.getVersion()).isEqualTo("1.0"); + + res = DcaeRestClient.checkoutVfcmt(vfcmtId, newVfcmt.getLastUpdaterUserId()); + newVfcmt = gson.fromJson(res.getResponse(), Vfcmt.class); + vfcmtId = newVfcmt.getUuid(); + // submit - generate and save type2 blueprint artifact + Report.log(Status.INFO, "Going to Submit the composition with vfcmtId="+vfcmtId+", serviceUuid="+serviceUuid+", vfiName="+vfiName+", TYPE2="+bpType2); + res = DcaeRestClient.submitComposition(vfcmtId, serviceUuid, vfiName, bpType2); + assertBlueprintSuccessResponse(res); + res = DcaeRestClient.getResourceDetails(vfcmtId); + newVfcmt = gson.fromJson(res.getResponse(), Vfcmt.class); + Report.log(Status.INFO, "Checking lifecycle state of vfcmt after checkout and second blueprint submission. State = {}", newVfcmt.getLifecycleState()); + assertThat(newVfcmt.getLifecycleState()).isEqualTo(DcaeBeConstants.LifecycleStateEnum.CERTIFIED.name()); + Report.log(Status.INFO, "Checking version of vfcmt after checkout and second blueprint submission. Version = {}", newVfcmt.getVersion()); + assertThat(newVfcmt.getVersion()).isEqualTo("2.0"); + assertBlueprintsExistOnVfiAfterUpload(expectedBpDetails, serviceUuid, vfiName); + } + + + @Test + public void updateBlueprintTest() throws Exception { + Report.log(Status.INFO, "updateBlueprintTest start"); + String randomSuffix = WordUtils.capitalize(RandomStringUtils.randomAlphanumeric(4).toLowerCase()); + Vfcmt newVfcmt = createVfcmt(randomSuffix); + + // create a service in sdc + Service newService = createServiceWithVFiAsSdcDesigner(); + + String serviceUuid = newService.getUuid(); + String vfiName = newService.getResources().get(0).getResourceInstanceName(); + String vfcmtId = newVfcmt.getUuid(); + + // attach VFCMT to vfi + RestResponse res = DcaeRestClient.attachVfiRef(vfcmtId, serviceUuid, vfiName); + assertThat(res.getStatusCode()).isEqualTo(200); + + generateAndSaveCdump(vfcmtId); + + String normalizedVfcmtName = NORMALIZED_VFCMT_NAME + randomSuffix; + String bpType1 = "bpType 1"; + ImmutablePair expectedBpDetails = buildBlueprintDetails(bpType1, normalizedVfcmtName); + + // submit - generate and save type1 blueprint artifact + Report.log(Status.INFO, "Going to Submit the composition with vfcmtId="+vfcmtId+", serviceUuid="+serviceUuid+", vfiName="+vfiName+", bpType1="+bpType1); + res = DcaeRestClient.submitComposition(vfcmtId, serviceUuid, vfiName, bpType1); + assertBlueprintSuccessResponse(res); + // assert initial version exists + assertBlueprintExistsOnVfi(expectedBpDetails, serviceUuid, vfiName, CREATE_BLUEPRINT_DESCRIPTION); + + // submit - regenerate and save type1 blueprint artifact + Report.log(Status.INFO, "Going to Submit the composition with vfcmtId="+vfcmtId+", serviceUuid="+serviceUuid+", vfiName="+vfiName+", bpType1="+bpType1); + res = DcaeRestClient.submitComposition(vfcmtId, serviceUuid, vfiName, bpType1); + assertBlueprintSuccessResponse(res); + // assert blueprint updated + assertBlueprintExistsOnVfi(expectedBpDetails, serviceUuid, vfiName, UPDATE_BLUEPRINT_DESCRIPTION); + + } + + + private void assertBlueprintSuccessResponse(RestResponse response){ + assertThat(response.getStatusCode()).isEqualTo(200); + assertThat(ResponseParser.getValueFromJsonResponse(response.getResponse(), "successResponse")).isNotNull(); + } + + private void assertBlueprintsExistOnVfiAfterUpload(List> expectedBpDetails, String serviceId, String vfiName) throws IOException{ + List vfiArtifact = fetchVfiArtifacts(serviceId, vfiName); + List> vfiArtifactDetails = vfiArtifact.stream() + .map(a -> new ImmutablePair<>(a.getArtifactLabel(), a.getArtifactName())) + .collect(Collectors.toList()); + for(ImmutablePair bp : expectedBpDetails){ + assertThat(vfiArtifactDetails).contains(bp); + } + } + + private void assertBlueprintExistsOnVfi(ImmutablePair expectedBpDetails, String serviceId, String vfiName, String description) throws IOException{ + List vfiArtifact = fetchVfiArtifacts(serviceId, vfiName); + Predicate artifactPredicate = p -> expectedBpDetails.getLeft().equals(p.getArtifactLabel()) && expectedBpDetails.getRight().equals(p.getArtifactName()) && description.equals(p.getArtifactDescription()); + Artifact artifact = vfiArtifact.stream() + .filter(artifactPredicate) + .findAny() + .orElse(null); + assertThat(artifact).isNotNull(); + } + + + private List fetchVfiArtifacts(String serviceId, String vfiName) throws IOException { + Report.log(Status.INFO, "fetchVfiArtifacts start"); + RestResponse serviceRes = DcaeRestClient.getServicesInstance(serviceId); + Report.log(Status.INFO, "fetchVfiArtifacts response=%s", serviceRes); + Service service = gson.fromJson(serviceRes.getResponse(), Service.class); + Resource vfi = service.getResources().stream() + .filter(p -> p.getResourceInstanceName().equals(vfiName)) + .findAny() + .orElse(null); + assertThat(vfi).isNotNull(); + return vfi.getArtifacts(); + } + + private ImmutablePair buildBlueprintDetails(String bpType, String normalizedVfcmtName) { + return new ImmutablePair<>("blueprint"+bpType.toLowerCase().replaceAll(" ", ""),bpType.replaceAll(" ", "-")+"."+normalizedVfcmtName+"."+EVENT_PROC_BP_YAML); + } + + + private Vfcmt createVfcmt(String randomSuffix) throws IOException { + String newName = VFCMT_NAME + randomSuffix; + Report.log(Status.DEBUG, "createVfcmt start. VFCMT Name="+newName); + RestResponse res = DcaeRestClient.createVfcmt(newName,"description"); + Report.log(Status.DEBUG, "Create VFCMT response=%s", res); + assertThat(res.getStatusCode()).isEqualTo(200); + return gson.fromJson(res.getResponse(), Vfcmt.class); + } + + private void generateAndSaveCdump(String vfcmtId) throws ParseException, IOException { + Report.log(Status.DEBUG, "generateAndSaveCdump start"); + RestResponse res = DcaeUtil.SdcElementsModelType.getItemModelFromSdc(0); + assertThat(res.getStatusCode()).isEqualTo(200); + JsonObject cdump = DcaeRestClient.generateCdumpInput(vfcmtId); + Report.log(Status.DEBUG, "Generated cdump="+cdump); + cdump.add("nodes", DcaeUtil.parseNodesFromDcaeModelAndAssignUiNid(res.getResponse())); + Report.log(Status.DEBUG, "save composition - generate and save composition.yml artifact"); + res = DcaeRestClient.saveComposition(vfcmtId, DcaeRestClient.getDefaultUser().getUserId(), cdump.toString()); + Report.log(Status.DEBUG, "Save composition result="+res); + assertThat(res.getStatusCode()).isEqualTo(200); + } + + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionElementsControllerTests.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionElementsControllerTests.java new file mode 100644 index 0000000..46a62c0 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionElementsControllerTests.java @@ -0,0 +1,198 @@ +package com.att.ecomp.dcae.ci.api.tests.composition; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.List; +import java.util.stream.Collectors; + +import org.assertj.core.api.SoftAssertions; +import org.onap.sdc.dcae.composition.model.Model; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.entities.composition.rightMenu.element.Item; +import com.att.ecomp.dcae.ci.entities.composition.rightMenu.elements.Element; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; + +public class CompositionElementsControllerTests extends DcaeRestBaseTest { + + JsonParser parser = new JsonParser(); + + @Test + public void test_getAllElements() throws IOException{ + Report.log(Status.INFO, "test_getAllElements start"); + RestResponse response = DcaeRestClient.getElements(); + Report.log(Status.INFO, "getElements response=%s", response); + JsonElement getElementJsonResponse = getElementsJson(response); + Type listType = new TypeToken>(){}.getType(); + List responseData = gson.fromJson(getElementJsonResponse, listType); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + softly.assertThat(getElementJsonResponse.toString()).isNotEmpty(); + softly.assertThat(responseData).extracting("itemId") + .containsExactlyInAnyOrder("Policy","Utility","Microservice","Database","Collector","Analytics","Source"); + }); + } + + + @DataProvider(name="item") + public static Object[][] allElementsItems() throws IOException{ + RestResponse response = DcaeRestClient.getElements(); + JsonElement getElementJsonResponse = getElementsJson(response); + Type listType = new TypeToken>(){}.getType(); + List responseData = gson.fromJson(getElementJsonResponse, listType); + return responseData + .stream() + .map(x -> new Object[]{ x.getItemId() } ) + .collect(Collectors.toList()) + .toArray(new Object[responseData.size()][1]); + } + + @Test(dataProvider ="item") + public void test_getAllElementsByItemId(String itemName) throws IOException{ + Report.log(Status.INFO, "test_getAllElementsByItemId start"); + RestResponse response = DcaeRestClient.getItem(itemName); + Report.log(Status.INFO, "getItem response=%s", response); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + }); + } + + @Test + public void test_getModelData() throws IOException{ + Report.log(Status.INFO, "test_getModelData start"); + RestResponse responseGetElements = DcaeRestClient.getElements(); + JsonElement obj = getElementsJson(responseGetElements); + String elementItemName = getElementItemName(obj); + + RestResponse responseElementsItem = DcaeRestClient.getItem(elementItemName); + JsonElement elementsById = parser.parse(responseElementsItem.getResponse()); + JsonElement itemData = elementsById.getAsJsonObject().get("data").getAsJsonObject().get("element").getAsJsonObject().get("items"); + + String elemId = getElementItemID(itemData); + Report.log(Status.INFO, "test_getModelData start"); + + RestResponse response = DcaeRestClient.getItemModel(elemId); + Report.log(Status.INFO, "getItemModel response=%s", response); + JsonElement responseJson = parser.parse(response.getResponse()); + JsonElement itemModelData = responseJson.getAsJsonObject().get("data").getAsJsonObject().get("model"); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + softly.assertThat(itemModelData.toString()).isNotEmpty(); + }); + } + + @Test + public void test_getTypeData() throws IOException{ + Report.log(Status.INFO, "test_getTypeData start"); + RestResponse responseGetElements = DcaeRestClient.getElements(); + JsonElement obj = getElementsJson(responseGetElements); + String elementItemName = getElementItemName(obj); + + RestResponse responseElementsItem = DcaeRestClient.getItem(elementItemName); + JsonElement elementsById = parser.parse(responseElementsItem.getResponse()); + JsonElement itemData = elementsById.getAsJsonObject().get("data").getAsJsonObject().get("element").getAsJsonObject().get("items"); + + String elemId = getElementItemID(itemData); + RestResponse responseModel = DcaeRestClient.getItemModel(elemId); + JsonElement jsonRes = parser.parse(responseModel.getResponse()); + JsonElement jsonModel = jsonRes.getAsJsonObject().get("data").getAsJsonObject().get("model").getAsJsonObject(); + Model model = gson.fromJson(jsonModel, Model.class); + List nodesDataTypes = model.getNodes().stream() + .map(y -> y.getType()) + .collect(Collectors.toList()); + + nodesDataTypes.forEach(z -> Report.log(Status.INFO, "All types inside model: " + z)); + String nodeType = nodesDataTypes.get(0); + RestResponse response = DcaeRestClient.getItemType(elemId, nodeType); + JsonElement elementsById2 = parser.parse(response.getResponse()); + JsonElement data2 = elementsById2.getAsJsonObject().get("data").getAsJsonObject().get("type").getAsJsonObject(); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + softly.assertThat(data2.toString()).isNotEmpty(); + }); + } + + /**************** nagative ***************/ + @Test + public void test_getAllElementsByNonExistItemId() throws IOException{ + Report.log(Status.INFO, "test_getAllElementsByNonExistItemId start"); + RestResponse response = DcaeRestClient.getItem("notExist"); + JsonElement elementsById = parser.parse(response.getResponse()); + JsonElement exception = elementsById.getAsJsonObject().get("error").getAsJsonObject().get("exception"); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + softly.assertThat(exception.toString()).isNotEmpty(); + }); + } + + @Test + public void test_getErrorNonExistingModelData() throws IOException{ + Report.log(Status.INFO, "test_getErrorNonExistingModelData start"); + RestResponse response = DcaeRestClient.getItemModel("notExist"); + JsonElement elementsById = parser.parse(response.getResponse()); + JsonElement exception = elementsById.getAsJsonObject().get("error"); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(500); + softly.assertThat(exception.toString()).isNotEmpty(); + }); + } + + @Test + public void test_getErrorNonExistingItemType() throws IOException{ + Report.log(Status.INFO, "test_getErrorNonExistingItemType start"); + RestResponse response = DcaeRestClient.getItemType("notExistId","nonType"); + JsonElement elementsById = parser.parse(response.getResponse()); + JsonElement exception = elementsById.getAsJsonObject().get("error"); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(500); + softly.assertThat(exception.toString()).isNotEmpty(); + }); + } + + /******************** private ********************/ + private static JsonElement getElementsJson(RestResponse response) { + JsonParser parser = new JsonParser(); + JsonElement element = parser.parse(response.getResponse()); + JsonElement obj = element.getAsJsonObject().get("data").getAsJsonObject().get("elements"); + return obj; + } + + private String getElementItemName(JsonElement obj) { + Type listType = new TypeToken>(){}.getType(); + List fromJson = gson.fromJson(obj, listType); + List collect = fromJson.stream().filter(x->x.getName().equals("Collector")).collect(Collectors.toList()); + Element element = collect.get(0); + String elementItemName = element.getName(); + return elementItemName; + } + + private String getElementItemID(JsonElement data) { + Type listType = new TypeToken>(){}.getType(); + List elementsItemFoi = gson.fromJson(data, listType); + Report.log(Status.INFO, "getElementItemID for FOI collector"); + List foiItemData = elementsItemFoi.stream().filter(x->x.getName().equals("FOI")).collect(Collectors.toList()); + if(foiItemData!=null && foiItemData.size()>0){ + Item item = foiItemData.get(0); + String elemId = item.getItemId(); + return elemId; + }else{ + Report.log(Status.ERROR, "getElementItemID for FOI collector failed. Does the CI environment has FOI Collector component in it??"); + return null; + } + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionMicroServicesApiTests.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionMicroServicesApiTests.java new file mode 100644 index 0000000..52fae05 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/CompositionMicroServicesApiTests.java @@ -0,0 +1,154 @@ +package com.att.ecomp.dcae.ci.api.tests.composition; + +import static org.assertj.core.api.Assertions.*; + +import org.onap.sdc.dcae.composition.model.ModelDcae; +import org.testng.annotations.*; + +import java.io.IOException; + +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.openecomp.d2.ci.datatypes.http.RestResponse; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.DcaeTestConstants; +import com.att.ecomp.dcae.ci.utilities.DcaeUtil; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + + +public class CompositionMicroServicesApiTests extends DcaeRestBaseTest { + + @Test + public void getAllElementsTest() throws IOException, ParseException{ + Report.log(Status.INFO, "getAllElementsTest start"); + RestResponse services = DcaeRestClient.getElements(); + Report.log(Status.INFO, "getAllElementsTest response=%s", services); + assertThat(services.getStatusCode().intValue()).isEqualTo(200); +// System.out.println(services); + String response = services.getResponse(); + JSONParser parser = new JSONParser(); + JSONObject o = (JSONObject) parser.parse(response); + JSONObject ele = (JSONObject) o.get("data"); + String arrString = ele.get(("elements")).toString(); +// System.out.println(arrString); + assertThat(arrString) + .as("Check that elements not empty") + .isNotEmpty(); + } + + @Test + public void getMsElementsTest() throws IOException, ParseException{ + Report.log(Status.INFO, "getMsElementsTest start"); + RestResponse services = DcaeUtil.SdcElementsModelType.getMsElements(); + Report.log(Status.INFO, "getMsElementsTest response=%s", services); + assertThat(services.getStatusCode().intValue()).isEqualTo(200); +// System.out.println(services); + String response = services.getResponse(); + JSONParser parser = new JSONParser(); + JSONObject o = (JSONObject) parser.parse(response); + JSONObject ele = (JSONObject) o.get("data"); + String arrString = ele.get(("element")).toString(); +// System.out.println(arrString); + assertThat(arrString) + .as("Check that elements not empty") + .isNotEmpty(); + } + + @Test + public void getItemModelTest() throws IOException{ + Report.log(Status.INFO, "getItemModelTest start"); + RestResponse itemModelRes = DcaeUtil.SdcElementsModelType.getItemModelFromSdc(2); + Report.log(Status.INFO, "getItemModelTest response=%s", itemModelRes); + assertThat(itemModelRes.getStatusCode().intValue()).isEqualTo(200); + + String response = itemModelRes.getResponse(); + JSONObject object = (JSONObject) JSONValue.parse(response); + String errorMsg = object.get("error").toString(); + assertThat(errorMsg).isEqualTo(DcaeTestConstants.Composition.EMPTY_OBJECT); + } + + @Test + public void getItemTypeTest() throws IOException{ + Report.log(Status.INFO, "getItemModelTest start"); + RestResponse itemModelRes = DcaeUtil.SdcElementsModelType.getItemModelFromSdc(2); + Report.log(Status.INFO, "itemModelRes response=%s", itemModelRes); + String response = itemModelRes.getResponse(); + + String uuid = DcaeUtil.SdcElementsModelType.getItemUuid(2); + + ModelDcae model = gson.fromJson(response, ModelDcae.class); + Report.log(Status.INFO, "model "+model); + String type = model.getData().getModel().getNodes().get(0).getType(); + Report.log(Status.INFO, "type "+type); + + RestResponse services = DcaeRestClient.getItemType(uuid, type); + assertThat(services.getStatusCode().intValue()).isEqualTo(200); + } + +// @Test +// public void saveCompositionCheckoutConflictTest() throws IOException{ +// // pull checkout VFCMT +// Vfcmt checkoutVFCMT = DcaeUtil.CatalogReources.checkoutVFCMT(); +// // call API +// RestResponse saveComposition = DcaeRestClient.saveComposition(checkoutVFCMT.getUuid(), checkoutVFCMT.getLastUpdaterUserId()); +// System.out.println(saveComposition); +// assertThat(saveComposition.getStatusCode()) +// .as("status 500") +// .isEqualTo(500); +// } +// +// @Test +// public void saveCompositionTest() throws IOException{ +// // Create new VFCMT +// Resource createNewVfcmtObject = DcaeUtil.CatalogReources.createNewVfcmtObject(); +// // Call SDC API to create the new VFCMT +// RestResponse resNewVfcmt = DcaeRestClient.createVfcmt(createNewVfcmtObject.getResourceInstanceName(),createNewVfcmtObject.getDescription()); +// +// Vfcmt newVfcmt = gson.fromJson(resNewVfcmt.getResponse(), Vfcmt.class); +// +// // call api +// RestResponse saveComposition = DcaeRestClient.saveComposition(newVfcmt.getUuid(), newVfcmt.getLastUpdaterUserId()); +// System.out.println(saveComposition); +// String response = saveComposition.getResponse(); +// +// String msg = "Artifact created"; +// int errorIndex = response.indexOf(msg); +// assertThat(errorIndex) +// .as("Conflict of checkout") +// .isGreaterThan(-1); +// } + +// @Test +// public void submitCompositionTest() throws IOException{ +// // pull checkout VFCMT +// Vfcmt checkoutVFCMT = DcaeUtil.CatalogReources.checkoutVFCMT(); +// String componentId = checkoutVFCMT.getUuid(); +// /* TODO: create new service (requires SDC api support) instead of using a random one that already exists */ +// ThinService oneService = DcaeUtil.Services.getOneService(componentId,0); +// Resource oneVfInstance = DcaeUtil.Services.getOneVfInstance(oneService, 0); +// RestResponse submitCompositionRes = DcaeRestClient +// .submitComposition(componentId, oneService.getUuid(), oneVfInstance.getResourceInstanceName()); +// String response = submitCompositionRes.getResponse(); +// int errorIndex = response.indexOf(DcaeTestConstants.Sdc.State.CONFLICT); +// assertThat("Conflict of checkout",errorIndex, greaterThan(-1)); +// } + +//TODO Block need to get shai service +// @Test +// public void submitCompositionTest() throws IOException{ +// String componentId = DcaeUtil.CatalogReources.getComponentID(202); +// ThinService oneService = DcaeUtil.Services.getOneService(0); +// Resource oneVfInstance = DcaeUtil.Services.getOneVfInstance(oneService, 0); +// RestResponse submitCompositionRes = DcaeRestClient +// .submitComposition(componentId, oneService.getUuid(), oneVfInstance.getResourceInstanceName()); +// String response = submitCompositionRes.getResponse(); +// JSONObject object = (JSONObject) JSONValue.parse(response); +// assertThat("Success response is not null", object.get("successResponse"), is(notNullValue())); +// } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/GetCompositionControllerTests.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/GetCompositionControllerTests.java new file mode 100644 index 0000000..3493536 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/GetCompositionControllerTests.java @@ -0,0 +1,106 @@ +package com.att.ecomp.dcae.ci.api.tests.composition; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.text.WordUtils; +import org.assertj.core.api.SoftAssertions; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import org.onap.sdc.dcae.composition.services.Service; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.DcaeUtil; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class GetCompositionControllerTests extends DcaeRestBaseTest { + + private static final String VFCMT_NAME = "teSt.__.monitoring---TempLATE."; + + @Test + public void test_getComposition() throws Exception{ + Report.log(Status.INFO, "test_getComposition start"); + Vfcmt vfcmtWithArtifactUuid = createServiceAndVfiAndVfcmtAndAttach(); + String uuid = vfcmtWithArtifactUuid.getUuid(); + String lastUpdaterUserId = vfcmtWithArtifactUuid.getLastUpdaterUserId(); + Report.log(Status.INFO, "the created VFCMT uuid is:"+uuid+", going to save composition now"); + saveComposition(uuid, lastUpdaterUserId); + Report.log(Status.INFO, "Composition saved"); + + ExtentTestActions.log(Status.INFO, "Get Composition - execute"); + RestResponse response = DcaeRestClient.getComposition(uuid); + JSONObject resData = (JSONObject) JSONValue.parse(response.getResponse()); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + softly.assertThat(resData.get("successResponse").toString()).isNotEmpty(); + }); + } + + @Test + public void test_getCompositionNoArtifact() throws Exception{ + ExtentTestActions.log(Status.INFO, "test_getCompositionNoArtifact Get Composition - create vfcmt"); + + Vfcmt newVfcmt = createNewVfcmt(); + String uuid = newVfcmt.getUuid(); + + ExtentTestActions.log(Status.INFO, "Get Composition - execute"); + RestResponse response = DcaeRestClient.getComposition(uuid); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(204); + }); + } + + private void saveComposition(String uuid, String lastUpdaterUserId) throws Exception, IOException { + //generate cdump + String cdump = generateAndSaveCdump(uuid); + // save composition.yml + DcaeRestClient.saveComposition(uuid, lastUpdaterUserId, cdump); + } + + private Vfcmt createServiceAndVfiAndVfcmtAndAttach() throws Exception{ + Vfcmt newVfcmt = createNewVfcmt(); + + // create a service in sdc + Service newService = createServiceWithVFiAsSdcDesigner(); + + String serviceUuid = newService.getUuid(); + String vfiName = newService.getResources().get(0).getResourceInstanceName(); + String vfcmtId = newVfcmt.getUuid(); + + // attach VFCMT to vfi + RestResponse res = DcaeRestClient.attachVfiRef(vfcmtId, serviceUuid, vfiName); + + return newVfcmt; + } + + private Vfcmt createNewVfcmt() throws Exception { + String randomSuffix = WordUtils.capitalize(RandomStringUtils.randomAlphanumeric(4).toLowerCase()); + Vfcmt newVfcmt = createVfcmtInstance(randomSuffix); + return newVfcmt; + } + + private Vfcmt createVfcmtInstance(String randomSuffix) throws Exception{ + String newName = VFCMT_NAME + randomSuffix; + RestResponse res = DcaeRestClient.createVfcmt(newName,"description"); + assertThat(res.getStatusCode()).isEqualTo(200); + return gson.fromJson(res.getResponse(), Vfcmt.class); + } + private String generateAndSaveCdump(String vfcmtId) throws Exception{ + JsonArray snmpModelItemFromSdc = DcaeUtil.SdcElementsModelType.getSNMPModelItemFromSdc(); + JsonObject cdump = DcaeRestClient.generateCdumpInput(vfcmtId); + cdump.add("nodes", snmpModelItemFromSdc); + return cdump.toString(); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/SaveAndSubmitCompositionFullFlowTest.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/SaveAndSubmitCompositionFullFlowTest.java new file mode 100644 index 0000000..aaeebdc --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/composition/SaveAndSubmitCompositionFullFlowTest.java @@ -0,0 +1,115 @@ +package com.att.ecomp.dcae.ci.api.tests.composition; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.aventstack.extentreports.Status; +import com.google.gson.reflect.TypeToken; +import org.onap.sdc.dcae.composition.restmodels.CreateMcResponse; +import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest; +import org.onap.sdc.dcae.composition.restmodels.MonitoringComponent; +import org.onap.sdc.dcae.composition.restmodels.sdc.ExternalReferencesMap; +import org.onap.sdc.dcae.composition.restmodels.sdc.Resource; +import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed; +import org.onap.sdc.dcae.composition.services.Service; +import org.onap.sdc.dcae.composition.util.DcaeBeConstants; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SaveAndSubmitCompositionFullFlowTest extends DcaeRestBaseTest { + + private Resource baseTemplate = null; + + + @BeforeClass + public void setup() { + try { + ExtentTestActions.log(Status.INFO, "running before class - find a base template"); + Resource[] resources = gson.fromJson(DcaeRestClient.getAllMonitoringTemplatesVfcmts().getResponse(), Resource[].class); + if (resources.length > 0){ + baseTemplate = resources[0]; + } + } catch (Exception e) { + ExtentTestActions.log(Status.ERROR, e); + } + } + + + @Test + public void saveAndSubmitCompositionSuccessTest() throws Exception { + + CreateVFCMTRequest request = new CreateVFCMTRequest(); + // If you crashed here (below) it is because your environment has no Base Monitoring Templates + request.setTemplateUuid(baseTemplate.getUuid()); + Service service = createServiceWithVFiAsSdcDesigner(); + request.setVfiName(service.getResources().get(0).getResourceInstanceName()); + request.setServiceUuid(service.getUuid()); + DcaeRestClient.fillCreateMcRequestMandatoryFields(request); + + RestResponse response = DcaeRestClient.createMc(gson.toJson(request)); + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + + CreateMcResponse mcResponse = gson.fromJson(response.getResponse(), CreateMcResponse.class); + ExtentTestActions.log(Status.INFO, "Vfcmt created successfully. About to update composition"); + String initialUuid = mcResponse.getVfcmt().getUuid(); + response = DcaeRestClient.saveComposition(request.getServiceUuid(), request.getVfiName(), initialUuid, gson.toJson(mcResponse.getCdump())); + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + + ResourceDetailed mc = gson.fromJson(response.getResponse(), ResourceDetailed.class); + // the save action should check the mc out then in - promoting the version + assertThat(mc.getLifecycleState()).isEqualTo(DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name()); + assertThat(mc.getVersion()).isEqualTo("0.2"); + + ExtentTestActions.log(Status.INFO, "About to submit the composition"); + response = DcaeRestClient.submitComposition(request.getServiceUuid(), request.getVfiName(), mc.getUuid()); + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + // the submit action should certify the mc. + ExtentTestActions.log(Status.INFO, "Save new composition version after submit"); + response = DcaeRestClient.saveComposition(request.getServiceUuid(), request.getVfiName(), initialUuid, gson.toJson(mcResponse.getCdump())); + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + // the save action should promote the mc version to 1.1 and create a new reference to it - both references should be kept at this point + mc = gson.fromJson(response.getResponse(), ResourceDetailed.class); + assertThat(mc.getLifecycleState()).isEqualTo(DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name()); + assertThat(mc.getVersion()).isEqualTo("1.1"); + + response = DcaeRestClient.getServiceExternalReferences(service.getUuid(), service.getVersion()); + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + ExtentTestActions.log(Status.INFO, "Verify service vfi has references to both mc versions"); + Type typeToken = new TypeToken>>(){}.getType(); + Map> monitoringComponents = gson.fromJson(response.getResponse(), typeToken); + assertThat(monitoringComponents.get("monitoringComponents").size()).isEqualTo(2); + ExtentTestActions.log(Status.INFO, "About to re-submit the composition"); + response = DcaeRestClient.submitComposition(request.getServiceUuid(), request.getVfiName(), mc.getUuid()); + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + // a successful submission of the new version should result in the deletion of the previous reference + response = DcaeRestClient.getServiceExternalReferences(service.getUuid(), service.getVersion()); + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + monitoringComponents = gson.fromJson(response.getResponse(), typeToken); + List mcList = monitoringComponents.get("monitoringComponents"); + assertThat(mcList.size()).isEqualTo(1); + assertThat(mcList.get(0).getUuid()).isEqualTo(mc.getUuid()); + + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/ArrangeHelper.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/ArrangeHelper.java new file mode 100644 index 0000000..933fc38 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/ArrangeHelper.java @@ -0,0 +1,68 @@ +package com.att.ecomp.dcae.ci.api.tests.lifeCycle; + +import static org.assertj.core.api.Assertions.fail; + +import com.att.ecomp.dcae.ci.utilities.DcaeEntityClient; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; + +public class ArrangeHelper { + + private DcaeEntityClient client; + + public ArrangeHelper(DcaeEntityClient client) { + this.client = client; + } + + /** + * Tries to arrange checkedin vfcmt. + * If unable to do so, fails test with arrange error message + * @param userId - lastUpdater of the returned vfcmt + * @return checkedin vfcmt + */ + public Vfcmt getCheckedinVfcmt(String userId) { + Vfcmt vfcmt = null; + try { + vfcmt = client.createCheckedinVfcmt(userId); + } catch (Exception err) { + fail("could not arrange test: ", err); + } + return vfcmt; + } + + /** + * Tries to arrange checkedin vfcmt. + * If unable to do so, fails test with arrange error message + * @return checkedin vfcmt + */ + public Vfcmt getCheckedinVfcmt() { + String userId = DcaeRestClient.getDefaultUser().getUserId(); + return getCheckedinVfcmt(userId); + } + + /** + * Tries to arrange checkedout vfcmt. + * If unable to do so, fails test with arrange error message + * @param userId - lastUpdater of the returned vfcmt + * @return checkedout vfcmt + */ + public Vfcmt getCheckedoutVfcmt(String userId) { + Vfcmt vfcmt = null; + try { + vfcmt = client.createCheckedoutVfcmt(userId); + } catch (Exception err) { + fail("could not arrange test: ", err); + } + return vfcmt; + } + + /** + * Tries to arrange checkedout vfcmt. + * If unable to do so, fails test with arrange error message + * @return checkedout vfcmt + */ + public Vfcmt getCheckedoutVfcmt() { + String userId = DcaeRestClient.getDefaultUser().getUserId(); + return getCheckedoutVfcmt(userId); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCertify.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCertify.java new file mode 100644 index 0000000..4081b20 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCertify.java @@ -0,0 +1,49 @@ +package com.att.ecomp.dcae.ci.api.tests.lifeCycle; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.aventstack.extentreports.Status; +import org.assertj.core.api.SoftAssertions; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import org.testng.annotations.Test; + +public class PutCertify extends DcaeRestBaseTest { + + private ArrangeHelper arrange = new ArrangeHelper(client); + + /* Positive */ + + @Test + public void certifyVfcmt_success() throws Exception { + // arrange + Vfcmt vfcmt = arrange.getCheckedinVfcmt(); + // act + ExtentTestActions.log(Status.INFO, "Calling certify vfcmt with lastUpdater as user (designer role)"); + RestResponse response = DcaeRestClient.certifyVfcmt(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId()); + // assert + Vfcmt vfcmtAfterCheckin = gson.fromJson(response.getResponse(), Vfcmt.class); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).isEqualTo(200); + softly.assertThat(vfcmtAfterCheckin.getLifecycleState()).isEqualTo("CERTIFIED"); + }); + } + + + /* Negative */ + + @Test + public void notReadyForCertification_statusCode500() throws Exception { + // arrange + Vfcmt vfcmt = arrange.getCheckedoutVfcmt(); + // act + ExtentTestActions.log(Status.INFO, "Calling certify on a checked out vfcmt"); + RestResponse response = DcaeRestClient.certifyVfcmt(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId()); + // assert + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).isEqualTo(500); + }); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCheckin.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCheckin.java new file mode 100644 index 0000000..45f71e0 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCheckin.java @@ -0,0 +1,145 @@ +package com.att.ecomp.dcae.ci.api.tests.lifeCycle; + +import java.io.IOException; +import java.util.UUID; + +import org.assertj.core.api.SoftAssertions; +import org.openecomp.d2.ci.api.ElementFactory; +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.*; +import static org.assertj.core.api.Assertions.*; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.StringUtils; +import com.aventstack.extentreports.Status; + +public class PutCheckin extends DcaeRestBaseTest{ + + private ArrangeHelper arrange = new ArrangeHelper(client); + + /* Positive */ + + @Test + public void checkedoutVfcmt_success() throws Exception { + // arrange + Vfcmt vfcmt = arrange.getCheckedoutVfcmt(); + // act + ExtentTestActions.log(Status.INFO, "Checkin the vfcmt with it's lastUpdater user"); + RestResponse response = checkinVfcmt(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId()); + // assert + Vfcmt vfcmtAfterCheckin = gson.fromJson(response.getResponse(), Vfcmt.class); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).isEqualTo(200); + softly.assertThat(vfcmtAfterCheckin.getLifecycleState()).contains("CHECKIN"); + }); + } + + /* Negative */ + + @Test + public void alreadyCheckedinVfcmt_statusCode409() throws Exception { + // arrange + Vfcmt vfcmt = arrange.getCheckedinVfcmt(); + // act + ExtentTestActions.log(Status.INFO, "Checkin the vfcmt AGAIN with it's lastUpdater user"); + RestResponse response = checkinVfcmt(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId()); + // assert + assertThat(response.getStatusCode()).isEqualTo(409); + } + + @Test + public void invalidVfcmtUuid_statusCode400() throws Exception { + // arrange + String userId = DcaeRestClient.getDefaultUser().getUserId(); + // act + ExtentTestActions.log(Status.INFO, "Checkin with an invalid-uuid as vfcmt-uuid"); + RestResponse response = checkinVfcmt("invalid-vfcmt-uuid", userId); + // assert + assertThat(response.getStatusCode()).isEqualTo(400); + } + + @Test + public void nonExistingUuid_statusCode409() throws Exception { + // arrange + String uuid = UUID.randomUUID().toString(); + String userId = DcaeRestClient.getDefaultUser().getUserId(); + // act + ExtentTestActions.log(Status.INFO, "Checkin with a non-existing vfcmt-uuid"); + RestResponse response = checkinVfcmt(uuid, userId); + // assert + assertThat(response.getStatusCode()).isEqualTo(409); + } + + @Test + public void nonExistingUser_statusCode403() throws Exception { + // arrange + Vfcmt vfcmt = arrange.getCheckedoutVfcmt(); + // act + ExtentTestActions.log(Status.INFO, "Checkin with a non-existing user"); + RestResponse response = checkinVfcmt(vfcmt.getUuid(), "anonymus"); + // assert + assertThat(response.getStatusCode()).isEqualTo(403); + } + + @Test + public void notLastUser_statusCode403() throws Exception { + // arrange + String user1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId(); + String user2 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER2).getUserId(); + Vfcmt vfcmt = arrange.getCheckedoutVfcmt(user1); + // act + ExtentTestActions.log(Status.INFO, "Checkin the vfcmt with different user: " + user2); + RestResponse response = checkinVfcmt(vfcmt.getUuid(), user2); + // assert + assertThat(response.getStatusCode()).isEqualTo(403); + } + + @Test + public void invalidAssetType_statusCode400() throws Exception { + // arrange + String assetType = "kengero"; + String userId = DcaeRestClient.getDefaultUser().getUserId(); + Vfcmt vfcmt = arrange.getCheckedoutVfcmt(); + // act + ExtentTestActions.log(Status.INFO, "Checkin the vfcmt with invalid asset-type"); + RestResponse response = checkinGeneral(assetType, userId, vfcmt); + // assert + assertThat(response.getStatusCode()).isEqualTo(400); + } + + + /* Private Methods */ + + /** + * Performs checkin on a general vfcmt/service, use this in test action + * @param assetType + * @param userId + * @param vfcmt + * @return + * @throws IOException + */ + private RestResponse checkinGeneral(String assetType, String userId, Vfcmt vfcmt) throws IOException { + RestResponse response = DcaeRestClient.checkinGeneral(assetType, vfcmt.getUuid(), userId); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + return response; + } + + /** + * Performs checkin on vfcmt, use this in test action + * @param vfcmtUuid + * @param userId + * @return + * @throws IOException + */ + private RestResponse checkinVfcmt(String vfcmtUuid, String userId) throws IOException { + RestResponse response = DcaeRestClient.checkinVfcmt(vfcmtUuid, userId); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + return response; + } + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCheckout.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCheckout.java new file mode 100644 index 0000000..5696ee3 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/lifeCycle/PutCheckout.java @@ -0,0 +1,148 @@ +package com.att.ecomp.dcae.ci.api.tests.lifeCycle; + +import java.io.IOException; +import java.util.UUID; + +import org.assertj.core.api.SoftAssertions; +import org.openecomp.d2.ci.api.ElementFactory; +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.*; +import static org.assertj.core.api.Assertions.*; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.StringUtils; +import com.aventstack.extentreports.Status; + +public class PutCheckout extends DcaeRestBaseTest{ + + private ArrangeHelper arrange = new ArrangeHelper(client); + + /* Positive */ + + @Test + public void checkedinVfcmt_success() throws Exception { + // arrange + Vfcmt vfcmt = arrange.getCheckedinVfcmt(); + // act + ExtentTestActions.log(Status.INFO, "Checkout the vfcmt with it's lastUpdater user"); + RestResponse response = checkoutVfcmt(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId()); + // assert + Vfcmt vfcmtAfterCheckout = gson.fromJson(response.getResponse(), Vfcmt.class); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).isEqualTo(200); + softly.assertThat(vfcmtAfterCheckout.getLifecycleState()).contains("CHECKOUT"); + }); + } + + @Test + public void notLastUser_success() throws Exception { + // arrange + String user1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId(); + String user2 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER2).getUserId(); + Vfcmt vfcmt = arrange.getCheckedinVfcmt(user1); + // act + ExtentTestActions.log(Status.INFO, "Checkout the vfcmt with different user: " + user2); + RestResponse response = checkoutVfcmt(vfcmt.getUuid(), user2); + // assert + Vfcmt vfcmtAfterCheckout = gson.fromJson(response.getResponse(), Vfcmt.class); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).isEqualTo(200); + softly.assertThat(vfcmtAfterCheckout.getLifecycleState()).contains("CHECKOUT"); + }); + } + + + /* Negative */ + + @Test + public void alreadyCheckedoutVfcmt_statusCode403() throws Exception { + // arrange + Vfcmt vfcmt = arrange.getCheckedoutVfcmt(); + // act + ExtentTestActions.log(Status.INFO, "Checkout the vfcmt with it's lastUpdater user"); + RestResponse response = checkoutVfcmt(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId()); + // assert + assertThat(response.getStatusCode()).isEqualTo(403); + } + + @Test + public void invalidVfcmtUuid_statusCode400() throws Exception { + // arrange + String userId = DcaeRestClient.getDefaultUser().getUserId(); + // act + ExtentTestActions.log(Status.INFO, "Checkout with an invalid-uuid as vfcmt-uuid"); + RestResponse response = checkoutVfcmt("invalid-vfcmt-uuid", userId); + // assert + assertThat(response.getStatusCode()).isEqualTo(400); + } + + @Test + public void nonExistingUuid_statusCode409() throws Exception { + // arrange + String uuid = UUID.randomUUID().toString(); + String userId = DcaeRestClient.getDefaultUser().getUserId(); + // act + ExtentTestActions.log(Status.INFO, "Checkin with a non-existing vfcmt-uuid"); + RestResponse response = checkoutVfcmt(uuid, userId); + // assert + assertThat(response.getStatusCode()).isEqualTo(409); + } + + @Test + public void nonExistingUser_statusCode403() throws Exception { + // arrange + Vfcmt vfcmt = arrange.getCheckedinVfcmt(); + // act + ExtentTestActions.log(Status.INFO, "Checkin with a non-existing user"); + RestResponse response = checkoutVfcmt(vfcmt.getUuid(), "anonymus"); + // assert + assertThat(response.getStatusCode()).isEqualTo(403); + } + + @Test + public void invalidAssetType_statusCode400() throws Exception { + // arrange + String assetType = "kengero"; + String userId = DcaeRestClient.getDefaultUser().getUserId(); + Vfcmt vfcmt = arrange.getCheckedoutVfcmt(); + // act + ExtentTestActions.log(Status.INFO, "Checkout the vfcmt with invalid asset-type"); + RestResponse response = checkoutGeneral(assetType, userId, vfcmt); + // assert + assertThat(response.getStatusCode()).isEqualTo(400); + } + + + /* Private Methods */ + + /** + * Performs checkout on a general vfcmt/service and logs the response + * @param assetType + * @param userId + * @param vfcmt + * @return + * @throws IOException + */ + private RestResponse checkoutGeneral(String assetType, String userId, Vfcmt vfcmt) throws IOException { + RestResponse response = DcaeRestClient.checkinGeneral(assetType, vfcmt.getUuid(), userId); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + return response; + } + + /** + * Performs checkout on vfcmt and logs the response + * @param vfcmtUuid + * @param userId + * @return + * @throws IOException + */ + private RestResponse checkoutVfcmt(String vfcmtUuid, String userId) throws IOException { + RestResponse response = DcaeRestClient.checkoutVfcmt(vfcmtUuid, userId); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + return response; + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/GetDefinitionTest.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/GetDefinitionTest.java new file mode 100644 index 0000000..358f45a --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/GetDefinitionTest.java @@ -0,0 +1,137 @@ +package com.att.ecomp.dcae.ci.api.tests.ruleEditor; + +import java.lang.reflect.Field; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.assertj.core.api.SoftAssertions; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.onap.sdc.dcae.composition.restmodels.ruleeditor.EventTypeDefinitionUI; +import org.onap.sdc.dcae.composition.restmodels.ruleeditor.EventTypesByVersionUI; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; + +public class GetDefinitionTest extends DcaeRestBaseTest { + + @DataProvider(name = "EventTypes") + public static Object[][] getVesVersions() { + Gson gson = new GsonBuilder().create(); + try { + Report.log(Status.INFO, "Requesting VES event types"); + RestResponse response = DcaeRestClient.getVesEventTypes(); + Report.logDebug("Response", response); + if (response.getStatusCode() != 200) { + throw new Exception(response.toString()); + } + EventTypesByVersionUI[] eventsByVersionList = gson.fromJson(response.getResponse(), EventTypesByVersionUI[].class); + + return Arrays.stream(eventsByVersionList) + .flatMap(version -> version.getEventTypes().stream() + .map( event -> new Object[] {version.getVersion(), event} ) + ).toArray(Object[][]::new); + + } catch (Exception err) { + Report.log(Status.ERROR, "Unable to get ves event types\nException: %s", err.toString()); + return new Object[][] {}; + } + } + + + /* Positive */ + + @Test(dataProvider = "EventTypes") + public void testParameterized(String version, String eventType) throws Exception { + // arrange + + Report.log(Status.INFO, "testParameterized. version="+version+", eventType="+eventType); + + Gson gsonStrict = new GsonBuilder() + .registerTypeAdapter(EventTypeDefinitionUI.class, new StrictJsonDeserializer()) + .create(); + + // act + RestResponse response = DcaeRestClient.getVesDataTypes(version, eventType); + Report.logDebug("Response", response); + // assert + + EventTypeDefinitionUI[] resBody = gson.fromJson(response.getResponse(), EventTypeDefinitionUI[].class); + List resBodyFlat = flatten(Arrays.asList(resBody)); + Report.logDebug("resBodyFlat", gsonStrict.toJson(resBodyFlat)); + + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + + softly.assertThat(resBodyFlat).extracting("name").as("name") + .doesNotContain(StringUtils.EMPTY) + .doesNotContainNull(); + + softly.assertThat(resBodyFlat).extracting("id").as("id") + .doesNotContain(StringUtils.EMPTY) + .doesNotContainNull(); + }); + } + + + /* Negative */ + + + + + /* Private Methods */ + + public class StrictJsonDeserializer implements JsonDeserializer { + private Gson gson = new Gson(); + + @Override + public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + try { + Field[] declaredFields = Class.forName(typeOfT.getTypeName()).getDeclaredFields(); + Arrays.asList(declaredFields).stream() + .map(field -> field.getName()) + .forEach(fieldName -> { + if (json.getAsJsonObject().has(fieldName) == false) { + throw new JsonParseException(String.format("Missing field '%s'", fieldName)); + } + }); + } catch (SecurityException e) { + throw new JsonParseException("unable to parse", e); + } catch (ClassNotFoundException e) { + throw new JsonParseException("unable to parse", e); + } + return gson.fromJson(json, typeOfT); + } + + } + + + private List flatten(List events) { + List result = new ArrayList(); + events.stream().forEach(e -> { + List children = e.getChildren(); + result.add(e); // add this node + if (children != null) { + result.addAll(flatten(children)); // add child nodes recursively + } + }); + return result; + } + + /* Negative */ + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/GetListEventsAndVersionsTest.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/GetListEventsAndVersionsTest.java new file mode 100644 index 0000000..66ca1cb --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/GetListEventsAndVersionsTest.java @@ -0,0 +1,47 @@ +package com.att.ecomp.dcae.ci.api.tests.ruleEditor; + +import org.apache.commons.collections.SetUtils; +import org.apache.commons.lang3.StringUtils; +import org.assertj.core.api.SoftAssertions; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.onap.sdc.dcae.composition.restmodels.ruleeditor.EventTypesByVersionUI; +import org.testng.annotations.Test; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class GetListEventsAndVersionsTest extends DcaeRestBaseTest { + + /* Positive */ + + @Test + public void test_successResponse() throws Exception { + // act + Report.log(Status.INFO, "test_successResponse: Requesting VES event types"); + RestResponse response = DcaeRestClient.getVesEventTypes(); + Report.logDebug("Response", response); + // assert + EventTypesByVersionUI[] resBody = gson.fromJson(response.getResponse(), EventTypesByVersionUI[].class); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + + softly.assertThat(resBody).as("response body").isNotEmpty(); + + softly.assertThat(resBody).extracting("version").as("version") + .doesNotContain(StringUtils.EMPTY) + .doesNotContainNull(); + + softly.assertThat(resBody).extracting("eventTypes").as("eventTypes list") + .doesNotContain(SetUtils.EMPTY_SET) + .doesNotContainNull(); + softly.assertThat(resBody).flatExtracting("eventTypes").as("eventTypes list (flatten)") + .doesNotContainAnyElementsOf(EventTypesByVersionUI.DEFAULT_EVENTS) + .doesNotContain(StringUtils.EMPTY) + .doesNotContainNull(); + }); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/RuleEditorControllerTest.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/RuleEditorControllerTest.java new file mode 100644 index 0000000..73b51be --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/ruleEditor/RuleEditorControllerTest.java @@ -0,0 +1,319 @@ +package com.att.ecomp.dcae.ci.api.tests.ruleEditor; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.entities.rule_editor.SaveRuleError; +import org.onap.sdc.dcae.composition.services.Artifact; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.JsonObject; +import org.onap.sdc.dcae.composition.restmodels.ruleeditor.MappingRules; +import org.onap.sdc.dcae.composition.restmodels.ruleeditor.Rule; +import org.openecomp.d2.ci.api.ElementFactory; +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.testng.annotations.Test; +import org.assertj.core.api.SoftAssertions; +import org.openecomp.d2.ci.datatypes.http.RestResponse; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.testng.Assert.fail; + +import java.util.List; + +public class RuleEditorControllerTest extends DcaeRestBaseTest { + + private String ruleRequestBody = + "{version:4.1,eventType:syslogFields,description:newRule,actions:[{from:{value:fromField,regex:\"\"},target:event.commonEventHeader.target,id:id,actionType:copy}," + + "{actionType:concat,from:{values:[{value:concat1},{value:_concat2}]},target:concatTargetField},{actionType:copy,from:{value:extractFromHere,regex:\"([^:]*):.*\"},target:regexTargetField}," + + "{actionType:map,from:{value:fromField},target:mapTargetField,map:{values:[{key:sourceVal1,value:targetVal1},{key:sourceVal2,value:targetVal2}],haveDefault:true,default:'\"\"'}}," + + "{actionType:\"Date Formatter\",id:98908,from:{value:\"${dateFormatterFrom}\"},target:dateFormatterTarget,dateFormatter:{toTimezone:UVW,fromTimezone:XYZ,fromFormat:inputFormat,toFormat:outputFormat}}]," + + "condition:{left:\"${leftOperand}\",operator:contains,right:[rightOperand1,rightOperand2]}}"; + + @Test + public void saveNewMappingRulesArtifactSuccessTest() throws Exception { + Report.log(Status.INFO, "test start"); + Vfcmt vfcmt = createVfcmt(); + RestResponse res = saveCompositionAndFirstRuleSuccess(vfcmt, "map", "n.1.map", "param1", ruleRequestBody); + JsonObject jsonRes = gson.fromJson(res.getResponse(), JsonObject.class); + assertThat(jsonRes.get("version").getAsString()).isEqualTo("4.1"); + assertThat(jsonRes.get("eventType").getAsString()).isEqualTo("syslogFields"); + assertThat(jsonRes.get("uid")).isNotNull(); + String expectedArtifactName = "map_n.1.map_param1_MappingRules.json"; + Artifact savedArtifact = fetchVfcmtArtifactMetadataByName(vfcmt.getUuid(), expectedArtifactName); + assertThat(savedArtifact).isNotNull(); + } + + @Test + public void translateSnmpMappingRuleWithAllActionTypesSuccessTest() throws Exception { + String expectedTranslation = "{\"processing\":[{\"phase\":\"snmp_map\",\"processors\":[{\"array\":\"varbinds\",\"datacolumn\":\"varbind_value\",\"keycolumn\":\"varbind_oid\",\"class\":\"SnmpConvertor\"}," + + "{\"phase\":\"%s\",\"class\":\"RunPhase\"}]},{\"phase\":\"%s\",\"filter\":{\"filters\":[{\"string\":\"${leftOperand}\",\"value\":\"rightOperand1\",\"class\":\"Contains\"}," + + "{\"string\":\"${leftOperand}\",\"value\":\"rightOperand2\",\"class\":\"Contains\"}],\"class\":\"Or\"}," + + "\"processors\":[{\"updates\":{\"event.commonEventHeader.target\":\"fromField\",\"concatTargetField\":\"concat1_concat2\"},\"class\":\"Set\"}," + + "{\"regex\":\"([^:]*):.*\",\"field\":\"regexTargetField\",\"value\":\"extractFromHere\",\"class\":\"ExtractText\"}," + + "{\"map\":{\"sourceVal1\":\"targetVal1\",\"sourceVal2\":\"targetVal2\"},\"field\":\"fromField\",\"toField\":\"mapTargetField\",\"default\":\"\",\"class\":\"MapAlarmValues\"}," + + "{\"fromFormat\":\"inputFormat\",\"fromTz\":\"XYZ\",\"toField\":\"dateFormatterTarget\",\"toFormat\":\"outputFormat\",\"toTz\":\"UVW\",\"value\":\"${dateFormatterFrom}\",\"class\":\"DateFormatter\"}]}," + + "{\"phase\":\"%s\",\"processors\":[{\"phase\":\"map_publish\",\"class\":\"RunPhase\"}]}]}"; + Vfcmt vfcmt = createVfcmt(); + String name = vfcmt.getName(); + saveCompositionAndFirstRuleSuccess(vfcmt, "map", "map", "param1", ruleRequestBody); + RestResponse res = DcaeRestClient.translateRules(vfcmt.getUuid(),"map", "map", "param1", "SNMP"); + Report.log(Status.INFO, "translateRules response= "+res); + assertThat(res.getStatusCode()).isEqualTo(200); + assertThat(res.getResponse()).isEqualTo(String.format(expectedTranslation, name, name, name)); + } + + @Test + public void addNewRuleToExistingArtifact() throws Exception{ + Vfcmt vfcmt = createVfcmt(); + String nid = "n.565663636.0"; + RestResponse res = saveCompositionAndFirstRuleSuccess(vfcmt, "map", nid, "param1", ruleRequestBody); + Rule rule1 = gson.fromJson(res.getResponse(), Rule.class); + res = DcaeRestClient.saveRule(vfcmt.getUuid(), "map", nid, "param1", ruleRequestBody); + Report.log(Status.INFO, "saveRule response= "+res); + Rule rule2 = gson.fromJson(res.getResponse(), Rule.class); + RestResponse responseGetRules = DcaeRestClient.getRules(vfcmt.getUuid(),"map", nid, "param1"); + Report.log(Status.INFO, "getRules response= "+responseGetRules); + MappingRules rules = gson.fromJson(responseGetRules.getResponse(), MappingRules.class); + Report.log(Status.INFO, "MappingRules="+responseGetRules.getResponse()); + assertThat(rules.getRules()).hasSize(2); + assertThat(rules.getRules().keySet()).containsOnly(rule1.getUid(), rule2.getUid()); + } + + @Test + public void editExistingRuleInArtifact() throws Exception{ + Vfcmt vfcmt = createVfcmt(); + String updated = "This is an update"; + RestResponse res = saveCompositionAndFirstRuleSuccess(vfcmt, "map", "map", "param1", ruleRequestBody); + Rule rule = gson.fromJson(res.getResponse(), Rule.class); + Report.log(Status.INFO, "save rule response=%s", res.getResponse()); + res = DcaeRestClient.getRules(vfcmt.getUuid(),"map", "map", "param1"); + Report.log(Status.INFO, "getRules3 response= "+res); + MappingRules rules = gson.fromJson(res.getResponse(), MappingRules.class); + Report.log(Status.INFO, "MappingRules1="+res.getResponse()); + assertThat(rules.getRules().get(rule.getUid()).getDescription()).isEqualTo("newRule"); + assertThat(rules.getRules().keySet()).containsOnly(rule.getUid()); + rule.setDescription(updated); + DcaeRestClient.saveRule(vfcmt.getUuid(), "map", "map", "param1", rule.toJson()); + Report.log(Status.INFO, "saveRule response= "+res); + res = DcaeRestClient.getRules(vfcmt.getUuid(),"map", "map", "param1"); + Report.log(Status.INFO, "getRules2 response= "+res); + rules = gson.fromJson(res.getResponse(), MappingRules.class); + Report.log(Status.INFO, "MappingRules2="+res.getResponse()); + assertThat(rules.getRules()).hasSize(1); + assertThat(rules.getRules().get(rule.getUid()).getDescription()).isEqualTo(updated); + } + + @Test + public void editRuleInArtifactNoSuchIdErrorTest() throws Exception { + String expectedError = "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC6036\",\"text\":\"Error - Failed to save rule. Internal persistence error\",\"variables\":[],\"formattedErrorMessage\":\"Error - Failed to save rule. Internal persistence error\"}},\"notes\":\"\"}"; + Vfcmt vfcmt = createVfcmt(); + RestResponse res = saveCompositionAndFirstRuleSuccess(vfcmt, "map", "map", "param1", ruleRequestBody); + Rule rule = gson.fromJson(res.getResponse(), Rule.class); + Report.log(Status.INFO, "rule="+rule); + rule.setUid("NoSuchUid"); + res = DcaeRestClient.saveRule(vfcmt.getUuid(), "map", "map", "param1", rule.toJson()); + Report.log(Status.INFO, "saveRule response= "+res); + assertThat(res.getStatusCode()).isEqualTo(409); + assertThat(res.getResponse()).isEqualTo(expectedError); + } + + + @Test + public void getAllRules() throws Exception{ + Vfcmt vfcmt = createVfcmt(); + RestResponse res = saveCompositionAndFirstRuleSuccess(vfcmt, "map", "map", "param1", ruleRequestBody); + String uid1 = gson.fromJson(res.getResponse(), JsonObject.class).get("uid").getAsString(); + //save two more rules + res = DcaeRestClient.saveRule(vfcmt.getUuid(), "map", "map", "param1", ruleRequestBody); + Report.log(Status.INFO, "saveRule1 response= "+res); + String uid2 = gson.fromJson(res.getResponse(), JsonObject.class).get("uid").getAsString(); + res = DcaeRestClient.saveRule(vfcmt.getUuid(), "map", "map", "param1", ruleRequestBody); + Report.log(Status.INFO, "saveRule2 response= "+res); + String uid3 = gson.fromJson(res.getResponse(), JsonObject.class).get("uid").getAsString(); + res = DcaeRestClient.getRules(vfcmt.getUuid(),"map", "map", "param1"); + Report.log(Status.INFO, "getRules response= "+res); + JsonObject jsonRes = gson.fromJson(res.getResponse(), JsonObject.class); + Report.log(Status.INFO, "jsonRes="+jsonRes); + assertThat(jsonRes.get("schema")).isNotNull(); + MappingRules actualRules = gson.fromJson(res.getResponse(), MappingRules.class); + Report.log(Status.INFO, "MappingRules="+res.getResponse()); + assertThat(actualRules.getRules()).hasSize(3); + assertThat(actualRules.getRules().keySet()).containsOnly(uid1, uid2, uid3); + } + + + @Test + public void deleteRuleSuccessTest() throws Exception{ + Vfcmt vfcmt = createVfcmt(); + //save first rule + RestResponse res = saveCompositionAndFirstRuleSuccess(vfcmt, "map", "map", "param1", ruleRequestBody); + String uid1 = gson.fromJson(res.getResponse(), JsonObject.class).get("uid").getAsString(); + // save second rule + res = DcaeRestClient.saveRule(vfcmt.getUuid(), "map", "map", "param1", ruleRequestBody); + Report.log(Status.INFO, "saveRule response= "+res); + String uid2 = gson.fromJson(res.getResponse(), JsonObject.class).get("uid").getAsString(); + res = DcaeRestClient.getRules(vfcmt.getUuid(),"map", "map", "param1"); + Report.log(Status.INFO, "getRules1 response= "+res); + MappingRules actualRules = gson.fromJson(res.getResponse(), MappingRules.class); + Report.log(Status.INFO, "MappingRules1="+res.getResponse()); + // get all rules should return both + assertThat(actualRules.getRules()).hasSize(2); + assertThat(actualRules.getRules().keySet()).containsOnly(uid1, uid2); + // delete a rule + res = DcaeRestClient.deleteRule(vfcmt.getUuid(),"map", "map", "param1", uid2); + Report.log(Status.INFO, "deleteRule1 response= "+res); + assertThat(res.getStatusCode()).isEqualTo(200); + res = DcaeRestClient.getRules(vfcmt.getUuid(),"map", "map", "param1"); + Report.log(Status.INFO, "getRules2 response= "+res); + actualRules = gson.fromJson(res.getResponse(), MappingRules.class); + Report.log(Status.INFO, "MappingRules2="+res.getResponse()); + // get rules should return one rule + assertThat(actualRules.getRules()).hasSize(1); + assertThat(actualRules.getRules().keySet()).containsOnly(uid1); + // delete the last rule - artifact should be deleted + res = DcaeRestClient.deleteRule(vfcmt.getUuid(),"map", "map", "param1", uid1); + Report.log(Status.INFO, "deleteRule2 response= "+res); + assertThat(res.getStatusCode()).isEqualTo(200); + String expectedArtifactName = "map_map_param1_MappingRules.json"; + Artifact savedArtifact = fetchVfcmtArtifactMetadataByName(vfcmt.getUuid(), expectedArtifactName); + Report.log(Status.INFO, "savedArtifact= "+savedArtifact); + assertThat(savedArtifact).isNull(); + // get rules should return empty + res = DcaeRestClient.getRules(vfcmt.getUuid(),"map", "map", "param1"); + Report.log(Status.INFO, "getRules3 response= "+res); + assertThat(res.getStatusCode()).isEqualTo(200); + assertThat(res.getResponse()).isEqualTo("{}"); + + } + + @Test + public void invalidJsonRuleFormatTest() throws Exception{ + String expectedError = "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC6035\",\"text\":\"Error - Rule format is invalid: %1.\",\"variables\":[\"java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $\"],\"formattedErrorMessage\":\"Error - Rule format is invalid: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $.\"}},\"notes\":\"\"}"; + RestResponse res = DcaeRestClient.saveRule("someId", "someName", "someNid", "someParam", "gibberish" ); + assertThat(res.getStatusCode()).isEqualTo(400); + assertThat(res.getResponse()).isEqualTo(expectedError); + } + + @Test + public void invalidActionTypeTest() throws Exception { + String expectedError = "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC6035\",\"text\":\"Error - Rule format is invalid: %1.\",\"variables\":[\"Undefined action type: gibberish\"],\"formattedErrorMessage\":\"Error - Rule format is invalid: Undefined action type: gibberish.\"}},\"notes\":\"\"}"; + RestResponse res = DcaeRestClient.saveRule("someId", "someName", "someNid", "someParam", "{actions:[{actionType:gibberish}]}"); + assertThat(res.getStatusCode()).isEqualTo(400); + assertThat(res.getResponse()).isEqualTo(expectedError); + } + + @Test + public void conflictingUsersErrorTest() throws Exception { + Vfcmt vfcmt = createVfcmt(); + RestResponse res = DcaeRestClient.saveComposition(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId(), "{\"nid\":\"map\"}"); + assertThat(res.getStatusCode()).isEqualTo(200); + //check out by other user then try to save rule by current user + res = DcaeRestClient.checkoutVfcmt(vfcmt.getUuid(), ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER2).getUserId()); + assertThat(res.getStatusCode()).isEqualTo(200); + res = DcaeRestClient.saveRule(vfcmt.getUuid(), "map", "map", "someParam", ruleRequestBody); + assertThat(res.getStatusCode()).isEqualTo(403); + } + + @Test + public void uploadArtifactSdcErrorTest() throws Exception { + String expectedError = "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC6036\",\"text\":\"Error - Failed to save rule. Internal persistence error\",\"variables\":[],\"formattedErrorMessage\":\"Error - Failed to save rule. Internal persistence error\"}},\"notes\":\"Error: Invalid content.\"}"; + Vfcmt vfcmt = createVfcmt(); + RestResponse res = DcaeRestClient.saveComposition(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId(), "{\"nid\":\"map\"}"); + assertThat(res.getStatusCode()).isEqualTo(200); + // Generated artifact label would be invalid and should fail when submitted to SDC + res = DcaeRestClient.saveRule(vfcmt.getUuid(), "map", "map", "()someParam", ruleRequestBody); + assertThat(res.getStatusCode()).isEqualTo(409); + assertThat(res.getResponse()).isEqualTo(expectedError); + } + + @Test + public void saveMappingRuleNoSuchNidErrorTest() throws Exception { + String expectedError = "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC6114\",\"text\":\"DCAE component %1 not found in composition\",\"variables\":[\"noSuchComponent\"],\"formattedErrorMessage\":\"DCAE component noSuchComponent not found in composition\"}},\"notes\":\"\"}"; + Vfcmt vfcmt = createVfcmt(); + RestResponse res = DcaeRestClient.saveComposition(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId(), "{\"nid\":\"map\"}"); + assertThat(res.getStatusCode()).isEqualTo(200); + res = DcaeRestClient.saveRule(vfcmt.getUuid(), "noSuchComponent", "noSuchComponent", "someParam", ruleRequestBody); + assertThat(res.getStatusCode()).isEqualTo(400); + assertThat(res.getResponse()).isEqualTo(expectedError); + } + + + @Test + public void deleteRuleNoSuchIdTest() throws Exception { + String expectedError = "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC6115\",\"text\":\"Delete rule failed. Internal persistence error\",\"variables\":[],\"formattedErrorMessage\":\"Delete rule failed. Internal persistence error\"}},\"notes\":\"\"}"; + Vfcmt vfcmt = createVfcmt(); + //save rule + saveCompositionAndFirstRuleSuccess(vfcmt, "map", "map", "param1", ruleRequestBody); + RestResponse res = DcaeRestClient.deleteRule(vfcmt.getUuid(),"map", "map", "param1", "noSuchRuleId"); + Report.log(Status.INFO, "deleteRule response=%s", res); + assertThat(res.getStatusCode()).isEqualTo(409); + assertThat(res.getResponse()).isEqualTo(expectedError); + } + + // After first rule is saved the mappingRules.json artifact is available for get/delete/edit tests + private RestResponse saveCompositionAndFirstRuleSuccess(Vfcmt vfcmt, String dcaeCompName, String nid, String configParam, String body) throws Exception { + // generate and save a composition.yml + Report.log(Status.INFO, "saveCompositionAndFirstRuleSuccess start"); + RestResponse res = DcaeRestClient.saveComposition(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId(), String.format("{\"nid\":\"%s\"}", nid)); + Report.log(Status.INFO, "saveComposition response=%s", res); + assertThat(res.getStatusCode()).isEqualTo(200); + + res = DcaeRestClient.saveRule(vfcmt.getUuid(), dcaeCompName, nid, configParam, body); + Report.log(Status.INFO, "saveRule response=%s", res); + assertThat(res.getStatusCode()).isEqualTo(200); + return res; + } + + + @Test + public void saveMappingRuleNegativeTest_BadResponse() throws Exception { + // arrange + Report.log(Status.INFO, "Arrangeing test..."); + ObjectMapper mapper = new ObjectMapper(); + String badRuleRequestBody = "{\"version\":\"5.3\",\"eventType\":\"syslogFields\",\"uid\":\"\",\"description\":\"map rules\"," + + "\"actions\":[{actionType:\"Date Formatter\",from:{value:whatever}},{\"id\":\"22fdded0-c9eb-11e7-83c1-3592231134a4\",\"actionType\":\"map\",\"from\":{\"value\":\"AAA\",\"regex\":\"\",\"state\":\"closed\",\"values\":[{\"value\":\"\"},{\"value\":\"\"}]},\"target\":\"BBB\",\"map\":{\"values\":[{\"key\":\"foo\",\"value\":\"bar\"}],\"haveDefault\":true,\"default\":\"\"}},{\"id\":\"2d6fab00-c9eb-11e7-83c1-3592231134a4\",\"actionType\":\"map\",\"from\":{\"value\":\"\",\"regex\":\"\",\"state\":\"closed\",\"values\":[{\"value\":\"\"},{\"value\":\"\"}]},\"target\":\"DDD\",\"map\":{\"values\":[{\"key\":\"foo\",\"value\":\"bar\"}],\"haveDefault\":false,\"default\":\"\"}},{\"id\":\"60bff5a0-c9eb-11e7-83c1-3592231134a4\",\"actionType\":\"map\",\"from\":{\"value\":\"EEE\",\"regex\":\"\",\"state\":\"closed\",\"values\":[{\"value\":\"\"},{\"value\":\"\"}]},\"target\":\"\",\"map\":{\"values\":[{\"key\":\"foo\",\"value\":\"bar\"}],\"haveDefault\":false,\"default\":\"\"}},{\"id\":\"75ea0ce0-c9eb-11e7-83c1-3592231134a4\",\"actionType\":\"map\",\"from\":{\"value\":\"FFF\",\"regex\":\"\",\"state\":\"closed\",\"values\":[{\"value\":\"\"},{\"value\":\"\"}]},\"target\":\"GGG\",\"map\":{\"values\":[{\"key\":\"foo\",\"value\":\"bar\"},{\"key\":\"\",\"value\":\"\"}],\"haveDefault\":false,\"default\":\"\"}},{\"id\":\"75ea0ce0-c9eb-11e7-83c1-3592231134a4\",\"actionType\":\"map\",\"from\":{\"value\":\"FFF\",\"regex\":\"\",\"state\":\"closed\",\"values\":[{\"value\":\"\"},{\"value\":\"\"}]},\"target\":\"GGG\",\"map\":{\"values\":[{\"key\":\"foo\",\"value\":\"bar\"},{\"key\":\"foo\",\"value\":\"not bar\"}],\"haveDefault\":false,\"default\":\"\"}}],\"condition\":null}"; + Vfcmt vfcmt = createVfcmt(); + Report.log(Status.INFO, "Saving composition of a fake cdump..."); + RestResponse res = DcaeRestClient.saveComposition(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId(), "{\"nid\":\"map\"}"); + Report.logDebug("saveComposition response", res); + if (res.getStatusCode() != 200) { + fail("Unable to arrange test, save composition failed\n" + res.toString()); + } + // act + Report.log(Status.INFO, "Executing..."); + Report.logDebug("Request body", badRuleRequestBody); + RestResponse targetRes = DcaeRestClient.saveRule(vfcmt.getUuid(), "noSuchComponent", "map", "someParam", badRuleRequestBody); + Report.logDebug("saveRule response", targetRes); + // assert + Report.log(Status.INFO, "Asserting..."); + List errors = mapper.readValue(targetRes.getResponse(), SaveRuleError.class).getFormattedErrors(); // parse response + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(targetRes.getStatusCode()).isEqualTo(400); + softly.assertThat(errors).containsExactlyInAnyOrder( + "Please fill the default value of map action to BBB", + "Please fill the from field of map action to DDD", + "Please fill the target field of map action to ", + "Please fill all key-value pairs of map action to GGG", + "Error: Duplication in map keys exists, please modify rule configuration", + "Please fill the target field of Date Formatter action to null", + "Please fill the to timezone field of Date Formatter action to null", + "Please fill the from timezone field of Date Formatter action to null", + "Please fill the from format field of Date Formatter action to null", + "Please fill the to format field of Date Formatter action to null" + ); + }); + } + + @Test + public void translateInvalidFlowTypeFailureTest() throws Exception { + String expectedError = "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC6116\",\"text\":\"Translation failed. Reason: %s\",\"variables\":[\"%s\"],\"formattedErrorMessage\":\"Translation failed. Reason: %s\"}},\"notes\":\"\"}"; + RestResponse res = DcaeRestClient.translateRules("someId","map", "map", "param1", "noSuchFlowType"); + assertThat(res.getStatusCode()).isEqualTo(400); + assertThat(res.getResponse()).isEqualTo(String.format(expectedError, "%1", "Flow type noSuchFlowType not found", "Flow type noSuchFlowType not found")); + res = DcaeRestClient.translateRules("someId","map", "map", "param1", null); + assertThat(res.getStatusCode()).isEqualTo(400); + assertThat(res.getResponse()).isEqualTo(String.format(expectedError, "%1", "Flow type null not found", "Flow type null not found")); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/attachment/GetAttachment.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/attachment/GetAttachment.java new file mode 100644 index 0000000..a1c9193 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/attachment/GetAttachment.java @@ -0,0 +1,62 @@ +package com.att.ecomp.dcae.ci.api.tests.services.attachment; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; + +import static org.assertj.core.api.Assertions.*; + +import java.util.UUID; + +import org.assertj.core.api.SoftAssertions; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.testng.annotations.*; + +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class GetAttachment extends DcaeRestBaseTest { + + /* Positive */ + + @Test + public void testNewVfcmt_noAttachedService() throws Exception { + Report.log(Status.INFO, "testNewVfcmt_noAttachedService start"); + // arrange + Vfcmt vfcmt = client.createVfcmt(); + // act + RestResponse response = DcaeRestClient.getAttachedService(vfcmt.getUuid()); + // assert + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + JSONObject resData = (JSONObject) JSONValue.parse(response.getResponse()); + softly.assertThat(resData.get("successResponse")) + .as("successResponse") + .isEqualTo("No Artifacts"); + }); + } + + /* Negative */ + + @Test + public void testNonUuidVfcmt_responseStatus404() throws Exception { + // act + RestResponse response = DcaeRestClient.getAttachedService("I am not a uuid"); + // assert + assertThat(response.getStatusCode()).as("status code").isEqualTo(404); + } + + @Test + public void testNonExistingVfcmt_responseStatus404() throws Exception { + // arrange + String fakeUuid = UUID.randomUUID().toString(); + // act + RestResponse response = DcaeRestClient.getAttachedService(fakeUuid); + // assert + assertThat(response.getStatusCode()).as("status code").isEqualTo(404); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/attachment/PostAttachment.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/attachment/PostAttachment.java new file mode 100644 index 0000000..afd018f --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/attachment/PostAttachment.java @@ -0,0 +1,172 @@ +package com.att.ecomp.dcae.ci.api.tests.services.attachment; + +import static org.assertj.core.api.Assertions.*; + +import com.att.ecomp.dcae.ci.entities.composition.services.Vfi; +import org.assertj.core.api.SoftAssertions; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import org.testng.annotations.*; + +import java.util.UUID; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.openecomp.d2.ci.datatypes.ResourceReqDetails; +import org.openecomp.d2.ci.datatypes.ServiceReqDetails; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.SdcInternalApiClient; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class PostAttachment extends DcaeRestBaseTest { + + /* Positive */ + + @Test + public void vfcmtWithVfi_responseStatusOk() throws Exception { + // arrange + Vfcmt vfcmt; + Vfi vfi; + try { + vfcmt = client.createCheckedinVfcmt(); + vfi = arrangeVfi(); + } catch (Exception err) { + throw new Exception("Could not arrange test", err); + } + // act + Report.log(Status.INFO, "Attaching vfcmt [%s] to vfi [%s]", vfcmt.getUuid(), vfi.getName()); + RestResponse response = DcaeRestClient.attachVfiRef(vfcmt.getUuid(), vfi.getContainer().getUUID(), vfi.getName()); + Report.logDebug("Response:", response); + // assert + JSONObject resData = (JSONObject) JSONValue.parse(response.getResponse()); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + softly.assertThat(resData.get("successResponse")) + .as("successResponse") + .isEqualTo("Artifact updated"); + }); + } + + + @Test + public void vfcmtAlreadyAttached_responseStatusOk() throws Exception { + // arrange + Vfcmt vfcmt; + Vfi vfi; + try { + vfcmt = client.createCheckedinVfcmt(); + Report.log(Status.INFO, "Arranging first attachment"); + arrangeAttachmentToNewVfi(vfcmt); + vfi = arrangeVfi(); + } catch (Exception err) { + throw new Exception("Could not arrange test", err); + } + // act + Report.log(Status.INFO, "Updating attachment of vfcmt [%s] to a new vfi [%s]", vfcmt.getUuid(), vfi.getName()); + RestResponse response = DcaeRestClient.attachVfiRef(vfcmt.getUuid(), vfi.getContainer().getUUID(), vfi.getName()); + Report.logDebug("Response:", response); + // assert + JSONObject resData = (JSONObject) JSONValue.parse(response.getResponse()); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + softly.assertThat(resData.get("successResponse")) + .as("successResponse") + .isEqualTo("Artifact updated"); + }); + } + + + /* Negative */ + + + @Test + public void vfWithVfi_statusCode400() throws Exception { + // arrange + ResourceReqDetails vf; + Vfi vfi; + try { + Report.log(Status.INFO, "Create vf"); + vf = SdcInternalApiClient.createVf(); + vfi = arrangeVfi(); + } catch (Exception err) { + throw new Exception("Could not arrange test", err); + } + // act + Report.log(Status.INFO, "Attaching vf [%s] to vfi [%s]", vf.getUUID(), vfi.getName()); + RestResponse response = DcaeRestClient.attachVfiRef(vf.getUUID(), vfi.getContainer().getUUID(), vfi.getName()); + Report.logDebug("Response:", response); + // assert + assertThat(response.getStatusCode()).as("status code").isEqualTo(400); + } + + + @Test + public void vfcmtWithFakeServiceAndFakeVfi_statusCode404() throws Exception { + // arrange + Vfcmt vfcmt; + String fakeServiceUuid = UUID.randomUUID().toString(); + String fakeVfiName = "fakeVfi"; + try { + vfcmt = client.createCheckedinVfcmt(); + fakeServiceUuid = UUID.randomUUID().toString(); + fakeVfiName = "fakeVfi"; + } catch (Exception err) { + throw new Exception("Could not arrange test", err); + } + // act + Report.log(Status.INFO, "Attaching real vfcmt [%s] to fake service [%s] (random uuid) and fake vfi [%s]", vfcmt.getUuid(), fakeServiceUuid, fakeVfiName); + RestResponse response = DcaeRestClient.attachVfiRef(vfcmt.getUuid(), fakeServiceUuid, fakeVfiName); + Report.logDebug("Response:", response); + // assert + assertThat(response.getStatusCode()).as("status code").isEqualTo(404); + } + + + @Test + public void vfcmtWithFakeVfi_statusCode404() throws Exception { + // arrange + Vfcmt vfcmt; + Vfi vfi; + try { + vfcmt = client.createCheckedinVfcmt(); + Report.log(Status.INFO, "Create service"); + ServiceReqDetails service = SdcInternalApiClient.createService(); + vfi = new Vfi("fakeVfi", service); + } catch (Exception err) { + throw new Exception("Could not arrange test", err); + } + // act + Report.log(Status.INFO, "Attaching vfcmt [%s] to real service [%s] and fake vfi [%s]", vfcmt.getUuid(), vfi.getContainer().getUUID(), vfi.getName()); + RestResponse response = DcaeRestClient.attachVfiRef(vfcmt.getUuid(), vfi.getContainer().getUUID(), vfi.getName()); + Report.logDebug("Response:", response); + // assert + assertThat(response.getStatusCode()).as("status code").isEqualTo(404); + } + + + /* Private Methods */ + + private Vfi arrangeVfi() throws Exception { + Report.log(Status.INFO, "Create service"); + ServiceReqDetails service = SdcInternalApiClient.createService(); + Report.log(Status.INFO, "Create vf"); + ResourceReqDetails vf = SdcInternalApiClient.createVf(); + Report.log(Status.INFO, "Checkin vf"); + ResourceReqDetails vfCheckedin = SdcInternalApiClient.checkinVf(vf); + Report.log(Status.INFO, "Create vfi from (service [%s] + vf [%s])", service.getUUID(), vf.getUUID()); + return SdcInternalApiClient.createVfi(service, vf); + } + + + private void arrangeAttachmentToNewVfi(Vfcmt vfcmt) throws Exception { + Vfi vfi = arrangeVfi(); + Report.log(Status.INFO, "Attaching vfcmt [%s] to vfi [%s]", vfcmt.getUuid(), vfi.getName()); + RestResponse response = DcaeRestClient.attachVfiRef(vfcmt.getUuid(), vfi.getContainer().getUUID(), vfi.getName()); + Report.logDebug("Response:", response); + if (response.getStatusCode() != 200) { + throw new Exception("Failed to attach vfcmt to vfi\nResponse: " + response.toString()); + } + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/instance/GetServiceInstanceNagative.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/instance/GetServiceInstanceNagative.java new file mode 100644 index 0000000..582bc9b --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/instance/GetServiceInstanceNagative.java @@ -0,0 +1,24 @@ +package com.att.ecomp.dcae.ci.api.tests.services.instance; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.aventstack.extentreports.Status; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +public class GetServiceInstanceNagative extends DcaeRestBaseTest { + + @Test + public void test_invalidServiceID() throws IOException{ + ExtentTestActions.log(Status.INFO, "Send invalid service Instance"); + RestResponse response = DcaeRestClient.getServicesInstance("123456789"); + ExtentTestActions.log(Status.INFO, "Verifying response status is 404"); + assertThat(response.getStatusCode()).as("response status").isEqualTo(404); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/instance/GetServiceInstancePositive.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/instance/GetServiceInstancePositive.java new file mode 100644 index 0000000..a724b39 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/instance/GetServiceInstancePositive.java @@ -0,0 +1,122 @@ +package com.att.ecomp.dcae.ci.api.tests.services.instance; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +import org.assertj.core.api.SoftAssertions; +import org.onap.sdc.dcae.composition.restmodels.sdc.ServiceDetailed; +import org.onap.sdc.dcae.composition.services.Resource; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.onap.sdc.dcae.composition.restmodels.DcaeMinimizedService; +import org.springframework.util.CollectionUtils; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; + +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.StringUtils; +import com.aventstack.extentreports.Status; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; + +public class GetServiceInstancePositive extends DcaeRestBaseTest { + + private RestResponse response; + + @BeforeClass + public void executeApiCall() throws Exception { + // arrange + DcaeMinimizedService service = arrangeService(); + try { + // act + ExtentTestActions.log(Status.INFO, "Get all VFIs for service [" + service.getUuid() + "]"); + response = DcaeRestClient.getServicesInstance(service.getUuid()); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + } catch (Exception err) { + ExtentTestActions.log(Status.FAIL, "Unable to execute api call: " + err.toString()); + err.printStackTrace(); + } + } + + private DcaeMinimizedService arrangeService() throws Exception { + DcaeMinimizedService service = null; + try { + Predicate hasVfi = p -> !CollectionUtils.isEmpty(getService(p.getUuid()).getResources()); + Vfcmt vfcmt = client.createCheckedoutVfcmt(); + ExtentTestActions.log(Status.INFO, "Created vfcmt [" + vfcmt.getUuid() + "]"); + ExtentTestActions.log(Status.INFO, "Get all services for vfcmt [" + vfcmt.getUuid() + "]"); + RestResponse responseServices = DcaeRestClient.getServices(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId()); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(responseServices)); + DcaeMinimizedService[] servicesList = gson.fromJson(responseServices.getResponse(), DcaeMinimizedService[].class); + // TODO: create a service instead of picking a random one + // find a service with a vfi + service = Arrays.stream(servicesList).filter(hasVfi).findAny().orElse(null); + } catch (Exception err) { + ExtentTestActions.log(Status.ERROR, "Could not arrange test: " + err.toString()); + } + return service; + } + + private ServiceDetailed getService(String serviceId) { + ServiceDetailed service = null; + try { + service = gson.fromJson(DcaeRestClient.getServicesInstance(serviceId).getResponse(), ServiceDetailed.class); + } catch (Exception e) { + ExtentTestActions.log(Status.ERROR, "Could not arrange test: " + e.toString()); + } + return service; + } + + @Test + public void test_responseStatusOk() throws IOException{ + // assert + ExtentTestActions.log(Status.INFO, "Verifing response status is 200"); + assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + } + + @Test + public void test_atLeastOneOrMoreResources() throws IOException{ + // assert + ExtentTestActions.log(Status.INFO, "Parsing response to a one service instance"); + List resourceList = getResourceListFromJsonResponse(); + ExtentTestActions.log(Status.INFO, "validating parsed response structure"); + assertThat(resourceList).size().isGreaterThanOrEqualTo(1); // TODO: create a VFI for the service instead of picking a random one + } + + @Test + public void test_responseIsValidStructure() throws IOException{ + // assert + ExtentTestActions.log(Status.INFO, "Parsing response to a one service instance"); + + List resourceList = getResourceListFromJsonResponse(); + + ExtentTestActions.log(Status.INFO, "validating parsed response structure"); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(resourceList.get(0).getResourceInstanceName()).isNotEmpty(); + softly.assertThat(resourceList.get(0).getResourceInvariantUUID()).isNotEmpty(); + }); + } + + + /*** private method ***/ + private List getResourceListFromJsonResponse() { + JsonParser jsonParser = new JsonParser(); + JsonObject responseJson = (JsonObject)jsonParser.parse(response.getResponse()); + JsonArray resources = responseJson.getAsJsonArray("resources"); + Type listType = new TypeToken>(){}.getType(); + List resourceList = gson.fromJson(resources, listType); + return resourceList; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/list/GetAllServicesNagative.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/list/GetAllServicesNagative.java new file mode 100644 index 0000000..a1935ae --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/list/GetAllServicesNagative.java @@ -0,0 +1,48 @@ +package com.att.ecomp.dcae.ci.api.tests.services.list; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.testng.Assert.fail; + +import java.io.IOException; + +import org.openecomp.d2.ci.api.ElementFactory; +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.Test; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.StringUtils; +import com.aventstack.extentreports.Status; + +public class GetAllServicesNagative extends DcaeRestBaseTest { + + @Test + public void userNotLastUpdater_statusCode403() throws Exception{ + // arrange + String user1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER).getUserId(); + String user2 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER2).getUserId(); + Vfcmt vfcmt = null; + try { + vfcmt = client.createCheckedoutVfcmt(user1); + } catch (Exception err) { + fail("Unable to arrange test", err); + } + // act + ExtentTestActions.log(Status.INFO, "GetServices for user that is not the vfcmt last-updater"); + RestResponse response = getServices(vfcmt.getUuid(), user2); + // assert + assertThat(response.getStatusCode()).as("response status").isEqualTo(403); + } + + + /* Private Methods */ + + private RestResponse getServices(String uuid, String user2) throws IOException { + RestResponse response = DcaeRestClient.getServices(uuid, user2); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + return response; + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/list/GetAllServicesPositive.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/list/GetAllServicesPositive.java new file mode 100644 index 0000000..88a7b71 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/services/list/GetAllServicesPositive.java @@ -0,0 +1,72 @@ +package com.att.ecomp.dcae.ci.api.tests.services.list; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.List; + +import org.assertj.core.api.SoftAssertions; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.onap.sdc.dcae.composition.restmodels.sdc.Service; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.StringUtils; +import com.aventstack.extentreports.Status; +import com.google.gson.reflect.TypeToken; + +public class GetAllServicesPositive extends DcaeRestBaseTest { + + private RestResponse response; + + @BeforeClass + public void executeApiCall() throws Exception { + ExtentTestActions.log(Status.INFO, "@BeforeClass --> executeApiCall"); + Vfcmt component = client.createCheckedoutVfcmt(); + String uuid = component.getUuid(); + String userIdLastUpdaterUserId = component.getLastUpdaterUserId(); + try { + // act + ExtentTestActions.log(Status.INFO, "Get all services"); + response = DcaeRestClient.getServices(uuid, userIdLastUpdaterUserId); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + } catch (Exception err) { + ExtentTestActions.log(Status.ERROR, err); + err.printStackTrace(); + } + } + + @Test + public void test_responseStatusOk() throws IOException{ + // assert + ExtentTestActions.log(Status.INFO, "Verifing response status is 200"); + assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + } + + @Test + public void test_responseIsValidStructure() throws IOException{ + // assert + ExtentTestActions.log(Status.INFO, "Parsing response to a List of Services"); + Type listType = new TypeToken>(){}.getType(); + List servicesList = gson.fromJson(response.getResponse(), listType); + Service service = servicesList.get(0); + + ExtentTestActions.log(Status.INFO, "validating parsed response structure"); + + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(service.getInvariantUUID()).isNotEmpty(); + softly.assertThat(service.getLastUpdaterUserId()).isNotEmpty(); + softly.assertThat(service.getName()).isNotEmpty(); + softly.assertThat(service.getUuid()).isNotEmpty(); + softly.assertThat(service.getLifecycleState()).isNotEmpty(); + softly.assertThat(service.getVersion()).isNotEmpty(); + }); + } + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/CreateMonitoringComponent.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/CreateMonitoringComponent.java new file mode 100644 index 0000000..33dd50f --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/CreateMonitoringComponent.java @@ -0,0 +1,253 @@ +package com.att.ecomp.dcae.ci.api.tests.vfcmt; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.StringUtils; +import com.aventstack.extentreports.Status; +import org.onap.sdc.dcae.composition.restmodels.CreateMcResponse; +import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest; +import org.onap.sdc.dcae.composition.restmodels.ImportVFCMTRequest; +import org.onap.sdc.dcae.composition.restmodels.MessageResponse; +import org.onap.sdc.dcae.composition.restmodels.sdc.Resource; +import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed; +import org.onap.sdc.dcae.composition.services.Service; +import org.onap.sdc.dcae.composition.util.DcaeBeConstants; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import org.openecomp.d2.ci.api.ElementFactory; +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CreateMonitoringComponent extends DcaeRestBaseTest { + + private RestResponse response; + private Resource res = null; + + + @BeforeClass + public void executeApiCall() { + // arrange + try { + // act + ExtentTestActions.log(Status.INFO, "Creating vfcmt"); + RestResponse clientResponse = DcaeRestClient.getAllMonitoringTemplatesVfcmts(); + Resource[] resources = gson.fromJson(clientResponse.getResponse(),Resource[].class); + if (resources.length > 0){ + res = resources[0]; + } + } catch (Exception err) { + ExtentTestActions.log(Status.ERROR, err); + } + } + + @Test + public void testCreateMonitoringComponentSuccess() throws IOException { + + Service service; + + try { + service = createServiceWithVFiAsSdcDesigner(); + } catch (Exception e) { + ExtentTestActions.log(Status.ERROR, e); + return; + } + + CreateVFCMTRequest request = new CreateVFCMTRequest(); + // If you crashed here (below) it is because your environment has no Base Monitoring Templates + request.setTemplateUuid(res.getUuid()); + request.setVfiName(service.getResources().get(0).getResourceInstanceName()); + request.setServiceUuid(service.getUuid()); + DcaeRestClient.fillCreateMcRequestMandatoryFields(request); + + response = DcaeRestClient.createMc(gson.toJson(request)); + + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + + CreateMcResponse mcResponse = gson.fromJson(response.getResponse(),CreateMcResponse.class); + + String vfUuid = mcResponse.getVfcmt().getUuid(); + String vfCdump = gson.toJson(mcResponse.getCdump()); + assertThat(vfCdump.contains(vfUuid)).isTrue(); + + RestResponse r = DcaeRestClient.getAttachedService(vfUuid); + assertThat(r.getResponse().contains(service.getUuid())).isTrue(); + + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + } + + @Test + public void testCreateMonitoringComponentBadUser() throws IOException { + + String fakeUserId = "anonymous"; + CreateVFCMTRequest request = new CreateVFCMTRequest(); + // If you crashed here (below) it is because your environment has no Base Monitoring Templates + request.setTemplateUuid(res.getUuid()); + DcaeRestClient.fillCreateMcRequestMandatoryFields(request); + + response = DcaeRestClient.createMc(gson.toJson(request),fakeUserId); + + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + // assert + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(403); + } + + @Test + public void testImportMonitoringComponentBothFlagsFalseSuccess() throws Exception { + + Service service; + + try { + service = createServiceWithVFiAsSdcDesigner(); + } catch (Exception e) { + ExtentTestActions.log(Status.ERROR, e); + return; + } + + String vfiName = service.getResources().get(0).getResourceInstanceName(); + Vfcmt vfcmt = prepareMockVfcmtForImport(); + ImportVFCMTRequest request = new ImportVFCMTRequest(); + request.setTemplateUuid(vfcmt.getUuid()); + request.setVfiName(vfiName); + request.setServiceUuid(service.getUuid()); + DcaeRestClient.fillCreateMcRequestMandatoryFields(request); + + response = DcaeRestClient.importMc(gson.toJson(request)); + + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + + // the service vfi should now have an external reference record to the vfcmt + response = DcaeRestClient.getServiceExternalReferences(service.getUuid(), service.getVersion()); + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + Map> refs = gson.fromJson(response.getResponse(), Map.class); + assertThat(vfcmt.getUuid().equals(refs.get("monitoringComponents").get(0).get("uuid"))).isTrue(); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + } + + @Test + public void testImportMonitoringComponentCloneFalseUpdateFlowTypeTrueSuccess() throws Exception { + + Service service; + + try { + service = createServiceWithVFiAsSdcDesigner(); + } catch (Exception e) { + ExtentTestActions.log(Status.ERROR, e); + return; + } + + String vfiName = service.getResources().get(0).getResourceInstanceName(); + Vfcmt vfcmt = prepareMockVfcmtForImport(); + ImportVFCMTRequest request = new ImportVFCMTRequest(); + request.setUpdateFlowType(true); + request.setTemplateUuid(vfcmt.getUuid()); + request.setVfiName(vfiName); + request.setServiceUuid(service.getUuid()); + DcaeRestClient.fillCreateMcRequestMandatoryFields(request); + + response = DcaeRestClient.importMc(gson.toJson(request)); + + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + + // TODO update to one GET call after editMC is implemented + // assert that the vfcmt was updated as expected (version, owner, lifecycle) + response = DcaeRestClient.getResourceDetails(vfcmt.getUuid()); + ResourceDetailed updatedMC = gson.fromJson(response.getResponse(), ResourceDetailed.class); + assertThat(updatedMC.getVersion()).isEqualTo("0.2"); + assertThat(updatedMC.getLastUpdaterUserId()).isEqualTo(DcaeRestClient.getDefaultUser().getUserId()); + assertThat(updatedMC.getLifecycleState()).isEqualTo(DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKIN.name()); + // assert that the updated cdump includes 'flowType' + + response = DcaeRestClient.getComposition(vfcmt.getUuid()); + String cdump = gson.fromJson(response.getResponse(), MessageResponse.class).getSuccessResponse(); + assertThat(cdump).isEqualTo("{\"flowType\":\"flowType_xxx\",\"cid\":\"1234567\"}"); + ExtentTestActions.log(Status.DEBUG, "Response updated mock cdump: " + cdump); + } + + @Test + public void testImportMonitoringComponentBothFlagsTrueSuccess() throws Exception { + + Service service; + + try { + service = createServiceWithVFiAsSdcDesigner(); + } catch (Exception e) { + ExtentTestActions.log(Status.ERROR, e); + return; + } + + String vfiName = service.getResources().get(0).getResourceInstanceName(); + Vfcmt vfcmt = prepareMockVfcmtForImport(); + ImportVFCMTRequest request = new ImportVFCMTRequest(); + request.setUpdateFlowType(true); + request.setCloneVFCMT(true); + request.setTemplateUuid(vfcmt.getUuid()); + request.setVfiName(vfiName); + request.setServiceUuid(service.getUuid()); + DcaeRestClient.fillCreateMcRequestMandatoryFields(request); + + response = DcaeRestClient.importMc(gson.toJson(request)); + + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(200); + + // assert that the vfcmt was cloned, the flowType updated and the reference artifact created + CreateMcResponse mcResponse = gson.fromJson(response.getResponse(),CreateMcResponse.class); + + assertThat(mcResponse.getVfcmt().getFlowType()).isEqualTo("flowType_xxx"); + // check the reference artifact + response = DcaeRestClient.getAttachedService(mcResponse.getVfcmt().getUuid()); + String ref = gson.fromJson(response.getResponse(), MessageResponse.class).getSuccessResponse(); + assertThat(ref).isEqualTo(service.getUuid()+"/resources/"+vfiName); + + ExtentTestActions.log(Status.DEBUG, "Response cloned Monitoring component: " + mcResponse); + } + + @Test + public void testImportMonitoringComponentServiceNotFoundFailure() throws Exception { + + Vfcmt vfcmt = prepareMockVfcmtForImport(); + ImportVFCMTRequest request = new ImportVFCMTRequest(); + request.setTemplateUuid(vfcmt.getUuid()); + DcaeRestClient.fillCreateMcRequestMandatoryFields(request); + response = DcaeRestClient.importMc(gson.toJson(request)); + + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(404); + + ExtentTestActions.log(Status.DEBUG, "Error response: " + response.getResponse()); + // assert vfcmt version was not increased + response = DcaeRestClient.getResourceDetails(vfcmt.getUuid()); + vfcmt = gson.fromJson(response.getResponse(), Vfcmt.class); + assertThat(vfcmt.getVersion()).isEqualTo("0.1"); + } + + + private Vfcmt prepareMockVfcmtForImport() throws IOException { + RestResponse createResponse = DcaeRestClient.createVfcmt(StringUtils.randomString("CI-", 20), "description", ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER2).getUserId()); + Vfcmt vfcmt = gson.fromJson(createResponse.getResponse(), Vfcmt.class); + // create a composition artifact + DcaeRestClient.saveComposition(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId(), "{\"cid\":\"1234567\"}"); + return vfcmt; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/CreateVfcmt.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/CreateVfcmt.java new file mode 100644 index 0000000..deb1020 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/CreateVfcmt.java @@ -0,0 +1,140 @@ +package com.att.ecomp.dcae.ci.api.tests.vfcmt; + +import static org.assertj.core.api.Assertions.*; + +import java.io.IOException; + +import org.assertj.core.api.SoftAssertions; +import org.openecomp.d2.ci.api.ElementFactory; +import org.openecomp.d2.ci.datatypes.User; +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.*; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.DcaeTestConstants; +import com.aventstack.extentreports.Status; +import com.att.ecomp.dcae.ci.utilities.StringUtils; + +public class CreateVfcmt extends DcaeRestBaseTest { + + private Vfcmt input; + private RestResponse response; + + @BeforeClass + public void executeApiCall() { + // arrange + input = new Vfcmt(); + input.setName(StringUtils.randomString("CI-", 20)); + input.setDescription(StringUtils.randomString("", 10)); + try { + // act + ExtentTestActions.log(Status.INFO, "Creating vfcmt"); + response = DcaeRestClient.createVfcmt(input.getName(), input.getDescription()); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + } catch (Exception err) { + ExtentTestActions.log(Status.ERROR, err); + err.printStackTrace(); + } + } + + /* Positive tests */ + + @Test + public void test_responseStatusOk() throws IOException { + // assert + ExtentTestActions.log(Status.INFO, "Verifing response status is 200"); + assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + } + + @Test + public void test_responseIsValidStructure() throws IOException { + // assert + ExtentTestActions.log(Status.INFO, "Parsing response to a VFCMT"); + Vfcmt createdVfcmt = gson.fromJson(response.getResponse(), Vfcmt.class); + ExtentTestActions.log(Status.INFO, "validating parsed response structure"); + SoftAssertions.assertSoftly(softly -> { + softly.assertThat(createdVfcmt.getCategory()).isEqualTo("Template"); + softly.assertThat(createdVfcmt.getInvariantUUID()).isNotEmpty(); + softly.assertThat(createdVfcmt.getUuid()).isNotEmpty(); + softly.assertThat(createdVfcmt.getLastUpdaterUserId()).isEqualTo(DcaeRestClient.getDefaultUser().getUserId()); + softly.assertThat(createdVfcmt.getLifecycleState()).isEqualTo(DcaeTestConstants.Sdc.State.NOT_CERTIFIED_CHECKOUT); + softly.assertThat(createdVfcmt.getName()).isEqualTo(input.getName()); + softly.assertThat(createdVfcmt.getDescription()).isEqualTo(input.getDescription()); + softly.assertThat(createdVfcmt.getResourceType()).isEqualTo("VFCMT"); + softly.assertThat(createdVfcmt.getSubCategory()).isEqualTo("Monitoring Template"); + softly.assertThat(createdVfcmt.getVersion()).isEqualTo("0.1"); + }); + } + + /* Negative tests */ + +// @Test +// public void testNameLengthGraterThen50_TBD() throws IOException { +// // arrange +// int length = 51; +// String name = StringUtils.randomString("CI-", length); +// String description = StringUtils.randomString("", 10); +// // act +// RestResponse response = DcaeRestClient.createVfcmt(name, description); +// // assert +// +// } + + @Test + public void testWithNonExistingUser_status403() throws IOException { + // arrange + String fakeUserId = "anonymous"; + String name = StringUtils.randomString("CI-", 20); + String description = StringUtils.randomString("", 10); + // act + ExtentTestActions.log(Status.INFO, "Creating vfcmt with fake user"); + RestResponse response = DcaeRestClient.createVfcmt(name, description, fakeUserId); + ExtentTestActions.log(Status.DEBUG, "response: " + StringUtils.truncate(response)); + // assert + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(403); + } + + @Test + public void testCreateTwoVfcmtsWithSameName_status409() throws IOException { + // arrange + String name = StringUtils.randomString("CI-", 20); + ExtentTestActions.log(Status.INFO, "Creating first vfcmt with name '" + name + "'"); + RestResponse response1 = DcaeRestClient.createVfcmt(name, StringUtils.randomString("", 10)); + ExtentTestActions.log(Status.DEBUG, "First Response: " + StringUtils.truncate(response1)); + if (response1.getStatusCode() != 200) { + fail("unable to arrange test - could not create the first vfcmt"); + } + // act + ExtentTestActions.log(Status.INFO, "Creating second vfcmt with same name '" + name + "'"); + RestResponse response2 = DcaeRestClient.createVfcmt(name, StringUtils.randomString("", 10)); + ExtentTestActions.log(Status.DEBUG, "Second response: " + StringUtils.truncate(response2)); + // assert + assertThat(response2.getStatusCode()) + .as("second status code") + .isEqualTo(409); + } + + @Test + public void testWithNonDesignerRole_status403() throws IOException { + // arrange + User tester = ElementFactory.getDefaultUser(UserRoleEnum.TESTER); + String name = StringUtils.randomString("CI-", 20); + String description = StringUtils.randomString("", 10); + // act + ExtentTestActions.log(Status.INFO, "Creating vfcmt with role tester"); + RestResponse response = DcaeRestClient.createVfcmt(name, description, tester.getUserId()); + ExtentTestActions.log(Status.DEBUG, "response: " + StringUtils.truncate(response)); + // assert + assertThat(response.getStatusCode()) + .as("status code") + .isEqualTo(403); + } + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetAllMonitoringTemplateVfcmts.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetAllMonitoringTemplateVfcmts.java new file mode 100644 index 0000000..874c00d --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetAllMonitoringTemplateVfcmts.java @@ -0,0 +1,60 @@ +package com.att.ecomp.dcae.ci.api.tests.vfcmt; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.StringUtils; +import com.aventstack.extentreports.Status; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class GetAllMonitoringTemplateVfcmts extends DcaeRestBaseTest { + + private RestResponse response; + private static final String BASE_MONITORING_TEMPLATE = "Base Monitoring Template"; + + @BeforeClass + public void executeApiCall() { + try { + // act + ExtentTestActions.log(Status.INFO, "Fetching all monitoring templates vfcmt resources"); + response = DcaeRestClient.getAllMonitoringTemplatesVfcmts(); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + } catch (Exception err) { + ExtentTestActions.log(Status.ERROR, err); + } + } + + @Test + public void testResponseStatusOk() { + // assert + ExtentTestActions.log(Status.INFO, "Verifying response status is 200"); + assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + } + + @Test + public void testResponseBodyIsListOfVfcmtsOnly() { + // assert + ExtentTestActions.log(Status.INFO, "Parsing response to a list of monitoring template VFCMTs"); + Vfcmt[] vfcmtList = gson.fromJson(response.getResponse(), Vfcmt[].class); + + ExtentTestActions.log(Status.INFO, "Verifying we got items"); + assertThat(vfcmtList).isNotEmpty(); + + ExtentTestActions.log(Status.INFO, "Verifying all items of the parsed response are VFCMTs"); + assertThat(vfcmtList) + .as("response data") + .extracting("resourceType") + .containsOnly("VFCMT"); + + ExtentTestActions.log(Status.INFO, "Verifying that all items of the parsed response are monitoring template VFCMTs"); + assertThat(vfcmtList) + .as("response data") + .extracting("subCategory") + .containsOnly(BASE_MONITORING_TEMPLATE); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetAllVfcmts.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetAllVfcmts.java new file mode 100644 index 0000000..3483de7 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetAllVfcmts.java @@ -0,0 +1,54 @@ +package com.att.ecomp.dcae.ci.api.tests.vfcmt; + +import static org.assertj.core.api.Assertions.*; + +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.*; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.StringUtils; +import com.aventstack.extentreports.Status; + +public class GetAllVfcmts extends DcaeRestBaseTest { + + private RestResponse response; + + @BeforeClass + public void executeApiCall() { + try { + // act + ExtentTestActions.log(Status.INFO, "Fetching all vfcmt resources"); + response = DcaeRestClient.getAllVfcmts(); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + } catch (Exception err) { + ExtentTestActions.log(Status.ERROR, err); + err.printStackTrace(); + } + } + + /* Positive tests */ + + @Test + public void testResponseStatusOk() { + // assert + ExtentTestActions.log(Status.INFO, "Verifing response status is 200"); + assertThat(response.getStatusCode()).as("response status").isEqualTo(200); + } + + @Test + public void testResponseBodyIsListOfVfcmtsOnly() { + // assert + ExtentTestActions.log(Status.INFO, "Parsing response to a list of VFCMTs"); + Vfcmt[] vfcmtList = gson.fromJson(response.getResponse(), Vfcmt[].class); + ExtentTestActions.log(Status.INFO, "Verifing all items of the parsed response are VFCMTs"); + assertThat(vfcmtList) + .as("response data") + .extracting("resourceType") + .containsOnly("VFCMT"); + } + + /* Negative tests */ +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetVfcmtsForMigration.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetVfcmtsForMigration.java new file mode 100644 index 0000000..f63ab7f --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/GetVfcmtsForMigration.java @@ -0,0 +1,104 @@ +package com.att.ecomp.dcae.ci.api.tests.vfcmt; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.StringUtils; +import com.aventstack.extentreports.Status; +import org.onap.sdc.dcae.composition.restmodels.CreateMcResponse; +import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest; +import org.onap.sdc.dcae.composition.restmodels.sdc.Resource; +import org.onap.sdc.dcae.composition.services.Service; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class GetVfcmtsForMigration extends DcaeRestBaseTest { + + private static final String STATUS_CODE = "status code"; + private RestResponse response; + private Resource res = null; + + @BeforeClass + public void executeApiCall() { + try { + // act + ExtentTestActions.log(Status.INFO, "Selecting vfcmt resources for migration"); + response = DcaeRestClient.getVfcmtsForMigration("services","1111111","1.3"); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + + ExtentTestActions.log(Status.INFO, "getAllMonitoringTemplatesVfcmts"); + RestResponse clientResponse = DcaeRestClient.getAllMonitoringTemplatesVfcmts(); + Resource[] resources = gson.fromJson(clientResponse.getResponse(),Resource[].class); + if (resources.length > 0){ + res = resources[0]; + } + } catch (Exception err) { + ExtentTestActions.log(Status.ERROR, err); + err.printStackTrace(); + } + } + + @Test + public void testResponseStatus500ServiceNotFound() { + // assert + ExtentTestActions.log(Status.INFO, "Verifing response status is 500"); + assertThat(response.getStatusCode()).as("response status").isEqualTo(500); + assertThat(response.getResponse().contains("resource was not found")); + } + + // If tests are taking too long: consider removing this very tedious and long test + @Test + public void testCreateMonitoringComponentSuccess() throws IOException { + CreateVFCMTRequest request = new CreateVFCMTRequest(); + + request.setDescription("Test description"); + + Service service; + + try { + service = createServiceWithVFiAsSdcDesigner(); + } catch (Exception e) { + e.printStackTrace(); + return; + } + + // If you crashed here (below) it is because your environment has no Base Monitoring Templates + request.setTemplateUuid(res.getUuid()); + if (service != null) { + request.setServiceUuid(service.getUuid()); + } + request.setVfiName(service.getResources().get(0).getResourceInstanceName()); + + List listOfVfcmtsConnectedToService = new ArrayList<>(); + for (int i = 0 ; i < 4 ; i++){ + request.setName(StringUtils.randomString("CI-", 20)); + addMandatoryInputFieldsToRequestObject(request); + response = DcaeRestClient.createMc(gson.toJson(request)); + assertThat(response.getStatusCode()).as(STATUS_CODE).isEqualTo(200); + CreateMcResponse mcResponse = gson.fromJson(response.getResponse(),CreateMcResponse.class); + String key = mcResponse.getVfcmt().getUuid(); + String value = gson.toJson(mcResponse.getCdump()); + assertThat(value.contains(key)).isTrue(); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + listOfVfcmtsConnectedToService.add(key); + } + + response = DcaeRestClient.getVfcmtsForMigration("services",service.getUuid(),service.getVersion()); + assertThat(response.getStatusCode()).as(STATUS_CODE).isEqualTo(200); + + listOfVfcmtsConnectedToService.forEach( s -> assertThat(response.getResponse().contains(s)).isFalse()); + + response = DcaeRestClient.getAllVfcmts(); + assertThat(response.getStatusCode()).as(STATUS_CODE).isEqualTo(200); + + listOfVfcmtsConnectedToService.forEach( s -> assertThat(response.getResponse().contains(s)).isTrue()); + + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/VfcmtCreationFlow.java b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/VfcmtCreationFlow.java new file mode 100644 index 0000000..34f4686 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/api/tests/vfcmt/VfcmtCreationFlow.java @@ -0,0 +1,37 @@ +package com.att.ecomp.dcae.ci.api.tests.vfcmt; + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.testng.annotations.*; +import static org.assertj.core.api.Assertions.*; + +import com.att.ecomp.dcae.ci.api.tests.DcaeRestBaseTest; +import com.aventstack.extentreports.Status; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; + +public class VfcmtCreationFlow extends DcaeRestBaseTest { + + private Vfcmt[] vfcmtsBeforeAdd; + private Vfcmt newVfcmt; + private Vfcmt[] vfcmtsAfterAdd; + + @BeforeClass + public void executeFlow() throws Exception { + ExtentTestActions.log(Status.INFO, "@BeforeClass --> executeFlow (getAllVfcmts)"); + try { + // act + vfcmtsBeforeAdd = client.getAllVfcmts(); + newVfcmt = client.createVfcmt(); + vfcmtsAfterAdd = client.getAllVfcmts(); + } catch (Exception err) { + ExtentTestActions.log(Status.ERROR, err); + err.printStackTrace(); + } + } + + @Test + public void test_numberOfVfcmtsIncresed() { + ExtentTestActions.log(Status.INFO, String.format("asserting (after[%d] > before[%d])", vfcmtsAfterAdd.length, vfcmtsBeforeAdd.length)); + // assert + assertThat(vfcmtsAfterAdd.length).isGreaterThan(vfcmtsBeforeAdd.length); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Artifact.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Artifact.java new file mode 100644 index 0000000..c7687d2 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Artifact.java @@ -0,0 +1,109 @@ + +package com.att.ecomp.dcae.ci.entities.composition.items; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Artifact { + + @SerializedName("artifactChecksum") + @Expose + private String artifactChecksum; + @SerializedName("artifactType") + @Expose + private String artifactType; + @SerializedName("artifactUUID") + @Expose + private String artifactUUID; + @SerializedName("artifactVersion") + @Expose + private String artifactVersion; + @SerializedName("artifactName") + @Expose + private String artifactName; + @SerializedName("artifactGroupType") + @Expose + private String artifactGroupType; + @SerializedName("artifactURL") + @Expose + private String artifactURL; + @SerializedName("artifactDescription") + @Expose + private String artifactDescription; + @SerializedName("artifactLabel") + @Expose + private String artifactLabel; + + public String getArtifactChecksum() { + return artifactChecksum; + } + + public void setArtifactChecksum(String artifactChecksum) { + this.artifactChecksum = artifactChecksum; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactUUID() { + return artifactUUID; + } + + public void setArtifactUUID(String artifactUUID) { + this.artifactUUID = artifactUUID; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getArtifactGroupType() { + return artifactGroupType; + } + + public void setArtifactGroupType(String artifactGroupType) { + this.artifactGroupType = artifactGroupType; + } + + public String getArtifactURL() { + return artifactURL; + } + + public void setArtifactURL(String artifactURL) { + this.artifactURL = artifactURL; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public String getArtifactLabel() { + return artifactLabel; + } + + public void setArtifactLabel(String artifactLabel) { + this.artifactLabel = artifactLabel; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Data.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Data.java new file mode 100644 index 0000000..267c296 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Data.java @@ -0,0 +1,21 @@ + +package com.att.ecomp.dcae.ci.entities.composition.items; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Data { + + @SerializedName("element") + @Expose + private Element element; + + public Element getElement() { + return element; + } + + public void setElement(Element element) { + this.element = element; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/DcaeComponents.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/DcaeComponents.java new file mode 100644 index 0000000..26a7000 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/DcaeComponents.java @@ -0,0 +1,54 @@ + +package com.att.ecomp.dcae.ci.entities.composition.items; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class DcaeComponents { + + @SerializedName("id") + @Expose + private Object id; + @SerializedName("timestamp") + @Expose + private Integer timestamp; + @SerializedName("data") + @Expose + private Data data; + @SerializedName("error") + @Expose + private Error error; + + public Object getId() { + return id; + } + + public void setId(Object id) { + this.id = id; + } + + public Integer getTimestamp() { + return timestamp; + } + + public void setTimestamp(Integer timestamp) { + this.timestamp = timestamp; + } + + public Data getData() { + return data; + } + + public void setData(Data data) { + this.data = data; + } + + public Error getError() { + return error; + } + + public void setError(Error error) { + this.error = error; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Element.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Element.java new file mode 100644 index 0000000..f681587 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Element.java @@ -0,0 +1,55 @@ + +package com.att.ecomp.dcae.ci.entities.composition.items; + +import java.util.List; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Element { + + @SerializedName("itemId") + @Expose + private String itemId; + @SerializedName("name") + @Expose + private String name; + @SerializedName("id") + @Expose + private String id; + @SerializedName("items") + @Expose + private List items = null; + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Error.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Error.java new file mode 100644 index 0000000..b1a1f49 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Error.java @@ -0,0 +1,8 @@ + +package com.att.ecomp.dcae.ci.entities.composition.items; + + +public class Error { + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Item.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Item.java new file mode 100644 index 0000000..777e4aa --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Item.java @@ -0,0 +1,220 @@ + +package com.att.ecomp.dcae.ci.entities.composition.items; + +import java.util.List; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Item { + + @SerializedName("lifecycleState") + @Expose + private String lifecycleState; + @SerializedName("models") + @Expose + private List models = null; + @SerializedName("subCategory") + @Expose + private String subCategory; + @SerializedName("catalog") + @Expose + private String catalog; + @SerializedName("lastUpdaterUserId") + @Expose + private String lastUpdaterUserId; + @SerializedName("description") + @Expose + private String description; + @SerializedName("uuid") + @Expose + private String uuid; + @SerializedName("version") + @Expose + private String version; + @SerializedName("itemId") + @Expose + private String itemId; + @SerializedName("catalogId") + @Expose + private Integer catalogId; + @SerializedName("toscaModelURL") + @Expose + private String toscaModelURL; + @SerializedName("name") + @Expose + private String name; + @SerializedName("invariantUUID") + @Expose + private String invariantUUID; + @SerializedName("id") + @Expose + private Integer id; + @SerializedName("category") + @Expose + private String category; + @SerializedName("lastUpdaterFullName") + @Expose + private String lastUpdaterFullName; + @SerializedName("toscaResourceName") + @Expose + private String toscaResourceName; + @SerializedName("resourceType") + @Expose + private String resourceType; + @SerializedName("artifacts") + @Expose + private List artifacts = null; + + public String getLifecycleState() { + return lifecycleState; + } + + public void setLifecycleState(String lifecycleState) { + this.lifecycleState = lifecycleState; + } + + public List getModels() { + return models; + } + + public void setModels(List models) { + this.models = models; + } + + public String getSubCategory() { + return subCategory; + } + + public void setSubCategory(String subCategory) { + this.subCategory = subCategory; + } + + public String getCatalog() { + return catalog; + } + + public void setCatalog(String catalog) { + this.catalog = catalog; + } + + public String getLastUpdaterUserId() { + return lastUpdaterUserId; + } + + public void setLastUpdaterUserId(String lastUpdaterUserId) { + this.lastUpdaterUserId = lastUpdaterUserId; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public Integer getCatalogId() { + return catalogId; + } + + public void setCatalogId(Integer catalogId) { + this.catalogId = catalogId; + } + + public String getToscaModelURL() { + return toscaModelURL; + } + + public void setToscaModelURL(String toscaModelURL) { + this.toscaModelURL = toscaModelURL; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getInvariantUUID() { + return invariantUUID; + } + + public void setInvariantUUID(String invariantUUID) { + this.invariantUUID = invariantUUID; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getLastUpdaterFullName() { + return lastUpdaterFullName; + } + + public void setLastUpdaterFullName(String lastUpdaterFullName) { + this.lastUpdaterFullName = lastUpdaterFullName; + } + + public String getToscaResourceName() { + return toscaResourceName; + } + + public void setToscaResourceName(String toscaResourceName) { + this.toscaResourceName = toscaResourceName; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public List getArtifacts() { + return artifacts; + } + + public void setArtifacts(List artifacts) { + this.artifacts = artifacts; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Model.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Model.java new file mode 100644 index 0000000..a1b732f --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/items/Model.java @@ -0,0 +1,65 @@ + +package com.att.ecomp.dcae.ci.entities.composition.items; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Model { + + @SerializedName("itemId") + @Expose + private String itemId; + @SerializedName("name") + @Expose + private String name; + @SerializedName("description") + @Expose + private String description; + @SerializedName("id") + @Expose + private String id; + @SerializedName("version") + @Expose + private String version; + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Artifact.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Artifact.java new file mode 100644 index 0000000..413fda7 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Artifact.java @@ -0,0 +1,109 @@ + +package com.att.ecomp.dcae.ci.entities.composition.rightMenu.element; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Artifact { + + @SerializedName("artifactChecksum") + @Expose + private String artifactChecksum; + @SerializedName("artifactType") + @Expose + private String artifactType; + @SerializedName("artifactUUID") + @Expose + private String artifactUUID; + @SerializedName("artifactVersion") + @Expose + private String artifactVersion; + @SerializedName("artifactName") + @Expose + private String artifactName; + @SerializedName("artifactGroupType") + @Expose + private String artifactGroupType; + @SerializedName("artifactURL") + @Expose + private String artifactURL; + @SerializedName("artifactDescription") + @Expose + private String artifactDescription; + @SerializedName("artifactLabel") + @Expose + private String artifactLabel; + + public String getArtifactChecksum() { + return artifactChecksum; + } + + public void setArtifactChecksum(String artifactChecksum) { + this.artifactChecksum = artifactChecksum; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactUUID() { + return artifactUUID; + } + + public void setArtifactUUID(String artifactUUID) { + this.artifactUUID = artifactUUID; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getArtifactGroupType() { + return artifactGroupType; + } + + public void setArtifactGroupType(String artifactGroupType) { + this.artifactGroupType = artifactGroupType; + } + + public String getArtifactURL() { + return artifactURL; + } + + public void setArtifactURL(String artifactURL) { + this.artifactURL = artifactURL; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public String getArtifactLabel() { + return artifactLabel; + } + + public void setArtifactLabel(String artifactLabel) { + this.artifactLabel = artifactLabel; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Item.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Item.java new file mode 100644 index 0000000..f0b5cfa --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Item.java @@ -0,0 +1,220 @@ + +package com.att.ecomp.dcae.ci.entities.composition.rightMenu.element; + +import java.util.List; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Item { + + @SerializedName("lifecycleState") + @Expose + private String lifecycleState; + @SerializedName("models") + @Expose + private List models = null; + @SerializedName("subCategory") + @Expose + private String subCategory; + @SerializedName("catalog") + @Expose + private String catalog; + @SerializedName("lastUpdaterUserId") + @Expose + private String lastUpdaterUserId; + @SerializedName("description") + @Expose + private String description; + @SerializedName("uuid") + @Expose + private String uuid; + @SerializedName("version") + @Expose + private String version; + @SerializedName("itemId") + @Expose + private String itemId; + @SerializedName("catalogId") + @Expose + private Integer catalogId; + @SerializedName("toscaModelURL") + @Expose + private String toscaModelURL; + @SerializedName("name") + @Expose + private String name; + @SerializedName("invariantUUID") + @Expose + private String invariantUUID; + @SerializedName("id") + @Expose + private Integer id; + @SerializedName("category") + @Expose + private String category; + @SerializedName("lastUpdaterFullName") + @Expose + private String lastUpdaterFullName; + @SerializedName("toscaResourceName") + @Expose + private String toscaResourceName; + @SerializedName("resourceType") + @Expose + private String resourceType; + @SerializedName("artifacts") + @Expose + private List artifacts = null; + + public String getLifecycleState() { + return lifecycleState; + } + + public void setLifecycleState(String lifecycleState) { + this.lifecycleState = lifecycleState; + } + + public List getModels() { + return models; + } + + public void setModels(List models) { + this.models = models; + } + + public String getSubCategory() { + return subCategory; + } + + public void setSubCategory(String subCategory) { + this.subCategory = subCategory; + } + + public String getCatalog() { + return catalog; + } + + public void setCatalog(String catalog) { + this.catalog = catalog; + } + + public String getLastUpdaterUserId() { + return lastUpdaterUserId; + } + + public void setLastUpdaterUserId(String lastUpdaterUserId) { + this.lastUpdaterUserId = lastUpdaterUserId; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public Integer getCatalogId() { + return catalogId; + } + + public void setCatalogId(Integer catalogId) { + this.catalogId = catalogId; + } + + public String getToscaModelURL() { + return toscaModelURL; + } + + public void setToscaModelURL(String toscaModelURL) { + this.toscaModelURL = toscaModelURL; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getInvariantUUID() { + return invariantUUID; + } + + public void setInvariantUUID(String invariantUUID) { + this.invariantUUID = invariantUUID; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getLastUpdaterFullName() { + return lastUpdaterFullName; + } + + public void setLastUpdaterFullName(String lastUpdaterFullName) { + this.lastUpdaterFullName = lastUpdaterFullName; + } + + public String getToscaResourceName() { + return toscaResourceName; + } + + public void setToscaResourceName(String toscaResourceName) { + this.toscaResourceName = toscaResourceName; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public List getArtifacts() { + return artifacts; + } + + public void setArtifacts(List artifacts) { + this.artifacts = artifacts; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/ItemsElement.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/ItemsElement.java new file mode 100644 index 0000000..f1fce3e --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/ItemsElement.java @@ -0,0 +1,55 @@ + +package com.att.ecomp.dcae.ci.entities.composition.rightMenu.element; + +import java.util.List; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class ItemsElement { + + @SerializedName("itemId") + @Expose + private String itemId; + @SerializedName("name") + @Expose + private String name; + @SerializedName("id") + @Expose + private Integer id; + @SerializedName("items") + @Expose + private List items = null; + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Model.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Model.java new file mode 100644 index 0000000..b5e7fad --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Model.java @@ -0,0 +1,65 @@ + +package com.att.ecomp.dcae.ci.entities.composition.rightMenu.element; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Model { + + @SerializedName("itemId") + @Expose + private String itemId; + @SerializedName("name") + @Expose + private String name; + @SerializedName("description") + @Expose + private String description; + @SerializedName("id") + @Expose + private String id; + @SerializedName("version") + @Expose + private String version; + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Service.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Service.java new file mode 100644 index 0000000..7001293 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/element/Service.java @@ -0,0 +1,21 @@ + +package com.att.ecomp.dcae.ci.entities.composition.rightMenu.element; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Service { + + @SerializedName("element") + @Expose + private ItemsElement element; + + public ItemsElement getElement() { + return element; + } + + public void setElement(ItemsElement element) { + this.element = element; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/elements/Element.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/elements/Element.java new file mode 100644 index 0000000..eb8e592 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/elements/Element.java @@ -0,0 +1,76 @@ +package com.att.ecomp.dcae.ci.entities.composition.rightMenu.elements; + +import java.util.List; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Element { + +@SerializedName("itemId") +@Expose +private String itemId; +@SerializedName("catalogId") +@Expose +private Integer catalogId; +@SerializedName("catalog") +@Expose +private String catalog; +@SerializedName("name") +@Expose +private String name; +@SerializedName("id") +@Expose +private Integer id; +@SerializedName("labels") +@Expose +private List labels = null; + +public String getItemId() { +return itemId; +} + +public void setItemId(String itemId) { +this.itemId = itemId; +} + +public Integer getCatalogId() { +return catalogId; +} + +public void setCatalogId(Integer catalogId) { +this.catalogId = catalogId; +} + +public String getCatalog() { +return catalog; +} + +public void setCatalog(String catalog) { +this.catalog = catalog; +} + +public String getName() { +return name; +} + +public void setName(String name) { +this.name = name; +} + +public Integer getId() { +return id; +} + +public void setId(Integer id) { +this.id = id; +} + +public List getLabels() { +return labels; +} + +public void setLabels(List labels) { +this.labels = labels; +} + +} \ No newline at end of file diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/elements/Elements.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/elements/Elements.java new file mode 100644 index 0000000..aea6e20 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/rightMenu/elements/Elements.java @@ -0,0 +1,18 @@ +package com.att.ecomp.dcae.ci.entities.composition.rightMenu.elements; +import java.util.List; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Elements { + @SerializedName("elements") + @Expose + private List elements = null; + + public List getElements() { + return elements; + } + + public void setElements(List elements) { + this.elements = elements; + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/services/CiService.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/services/CiService.java new file mode 100644 index 0000000..7921965 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/services/CiService.java @@ -0,0 +1,11 @@ +package com.att.ecomp.dcae.ci.entities.composition.services; + +import org.onap.sdc.dcae.composition.services.Service; +import org.openecomp.d2.ci.datatypes.ServiceReqDetails; + +public class CiService extends Service { + // converts from ui-api-ci object to dcae-ci object (partial construction) + public CiService(ServiceReqDetails service) { + super(service.getName(), service.getUUID(), service.getVersion()); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/composition/services/Vfi.java b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/services/Vfi.java new file mode 100644 index 0000000..dcf74cb --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/composition/services/Vfi.java @@ -0,0 +1,21 @@ +package com.att.ecomp.dcae.ci.entities.composition.services; + +import org.openecomp.d2.ci.datatypes.ServiceReqDetails; + +public class Vfi { + private String name; + private ServiceReqDetails container; + + public Vfi(String name, ServiceReqDetails container) { + this.name = name; + this.container = container; + } + + public String getName() { + return name; + } + + public ServiceReqDetails getContainer() { + return container; + } +} \ No newline at end of file diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/rule_editor/SaveRuleError.java b/src/main/java/com/att/ecomp/dcae/ci/entities/rule_editor/SaveRuleError.java new file mode 100644 index 0000000..7af5e51 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/rule_editor/SaveRuleError.java @@ -0,0 +1,27 @@ +package com.att.ecomp.dcae.ci.entities.rule_editor; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class SaveRuleError { + private Map requestError; + private String notes; + + @JsonCreator + public SaveRuleError( + @JsonProperty("requestError") Map requestError, @JsonProperty("notes") String notes) { + this.requestError = requestError; + this.notes = notes; + } + + + + public List getFormattedErrors() { + List> errors = (List>)requestError.get("serviceExceptions"); + return errors.stream().map(e -> e.get("formattedErrorMessage")).collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcCategory.java b/src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcCategory.java new file mode 100644 index 0000000..dd82f7d --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcCategory.java @@ -0,0 +1,20 @@ +package com.att.ecomp.dcae.ci.entities.sdc; + +import java.util.List; + +public class SdcCategory { + + private String name; + private List subcategories; + + + public String getName() { + return name; + } + + public List getSubcategories() { + return subcategories; + } + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcComponent.java b/src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcComponent.java new file mode 100644 index 0000000..386d3de --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcComponent.java @@ -0,0 +1,40 @@ +package com.att.ecomp.dcae.ci.entities.sdc; + +import java.util.List; +import java.util.Map; + +public class SdcComponent { + + private String lastUpdaterUserId; + private String uniqueId; + private String version; + private String resourceType; + private List categories; + private Map allVersions; + + public String getLastUpdaterUserId() { + return lastUpdaterUserId; + } + + public String getUniqueId() { + return uniqueId; + } + + public String getVersion() { + return version; + } + + public String getResourceType() { + return resourceType; + } + + public List getCategories() { + return categories; + } + + public Map getAllVersions() { + return allVersions; + } + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcComponentMetadata.java b/src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcComponentMetadata.java new file mode 100644 index 0000000..0ebf94c --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/entities/sdc/SdcComponentMetadata.java @@ -0,0 +1,12 @@ +package com.att.ecomp.dcae.ci.entities.sdc; + + +public class SdcComponentMetadata { + + private SdcComponent metadata; + + public SdcComponent getMetadata() { + return metadata; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/run/RunTestSuite.java b/src/main/java/com/att/ecomp/dcae/ci/run/RunTestSuite.java new file mode 100644 index 0000000..67639a2 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/run/RunTestSuite.java @@ -0,0 +1,11 @@ +package com.att.ecomp.dcae.ci.run; + +import org.openecomp.d2.ci.run.RunTest; + +public class RunTestSuite { + + public static void main(String[] args) { + RunTest.runTestSuite(); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAECompositionPage.java b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAECompositionPage.java new file mode 100644 index 0000000..9098d23 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAECompositionPage.java @@ -0,0 +1,70 @@ +package com.att.ecomp.dcae.ci.ui.pages; + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.tests.verificator.CompositionVerificator; +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class DCAECompositionPage { + + public static WebElement expandList(String listname) + { + ExtentTestActions.log(Status.INFO,String.format("Expand %s list", listname)); + GeneralUIUtils.clickOnElementByTestId(listname); + GeneralUIUtils.ultimateWait(); + WebDriver driver = GeneralUIUtils.getDriver(); + WebDriverWait wait = new WebDriverWait(driver, 10); + WebElement categoryElement = driver.findElement(ByTest.id(listname)).findElement(By.xpath("./..")); + return wait.until(Locator.from(categoryElement).findVisible(By.cssSelector(".draggable"), 0)); + } + + public static void addItemFromList(WebElement item) + { + ExtentTestActions.log(Status.INFO,String.format("Click on %s item", item.getText())); + item.click(); + GeneralUIUtils.ultimateWait(); + + } + + public static void clickSave() + { + ExtentTestActions.log(Status.INFO,"Click save button"); + GeneralUIUtils.clickOnElementByTestId("SaveButton"); + GeneralUIUtils.ultimateWait(); + GeneralUIUtils.waitForElementInVisibilityByTestId("saveMsg"); + String actualSaveRes = GeneralUIUtils.getWebElementByTestID("saveMsg").getText(); + CompositionVerificator.verifySaveSuccessfully(actualSaveRes); + GeneralUIUtils.ultimateWait(); + } + + public static void clickSubmit() + { + ExtentTestActions.log(Status.INFO,"Click submit button"); + GeneralUIUtils.clickOnElementByTestId("SubmitButton"); + GeneralUIUtils.ultimateWait(); + GeneralUIUtils.waitForElementInVisibilityByTestId("submitMsg"); + String actualSubmitRes = GeneralUIUtils.getWebElementByTestID("submitMsg").getText(); + CompositionVerificator.verifySubmitSuccessfully(actualSubmitRes); + GeneralUIUtils.ultimateWait(); + } + + public static void SelectFlowType(String flowType) { + Report.log(Status.INFO, "Selecting flow type '%s'", flowType); + WebDriver driver = GeneralUIUtils.getDriver(); + Select flowTypeSelect = new Select(driver.findElement(ByTest.id("flowTypeSelect"))); + flowTypeSelect.selectByVisibleText(flowType); + } +} + + + + diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEGeneralPage.java b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEGeneralPage.java new file mode 100644 index 0000000..f1f947a --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEGeneralPage.java @@ -0,0 +1,41 @@ +package com.att.ecomp.dcae.ci.ui.pages; + +import java.util.UUID; + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; +import org.openqa.selenium.WebElement; +import com.aventstack.extentreports.Status; + +public class DCAEGeneralPage { + + public static String addAssetName(String name) + { + WebElement nameTextbox = GeneralUIUtils.getWebElementByTestID("name"); + String assetName = name + UUID.randomUUID(); + nameTextbox.clear(); + nameTextbox.sendKeys(assetName); + GeneralUIUtils.ultimateWait(); + ExtentTestActions.log(Status.INFO,String.format("Add asset name: %s.", assetName)); + return assetName; + } + + public static void addAssetDescription(String description) + { + ExtentTestActions.log(Status.INFO,"Add asset description"); + WebElement descriptionTextbox = GeneralUIUtils.getWebElementByTestID("description"); + descriptionTextbox.clear(); + descriptionTextbox.sendKeys(description); + GeneralUIUtils.ultimateWait(); + } + + + public static void clickSaveAsset() throws Exception + { + ExtentTestActions.log(Status.INFO,"Click Save asset"); + GeneralUIUtils.waitForElementInVisibilityByTestId("Save-General"); + GeneralUIUtils.clickOnElementByTestId("Save-General"); + GeneralUIUtils.ultimateWait(); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEHomePage.java b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEHomePage.java new file mode 100644 index 0000000..17ee026 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEHomePage.java @@ -0,0 +1,27 @@ +package com.att.ecomp.dcae.ci.ui.pages; + + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; + +import com.aventstack.extentreports.Status; + + +public class DCAEHomePage { + + + + public static void clickOnDcaeTab() + { + ExtentTestActions.log(Status.INFO,"Clicking on DCAE Tab"); + GeneralUIUtils.clickOnElementByTestId("main-menu-button-dcae"); + GeneralUIUtils.ultimateWait(); + } + + public static void clickOnCreateNewAsset() + { + ExtentTestActions.log(Status.INFO,"Clicking on Create new asset button"); + GeneralUIUtils.clickOnElementByTestId("AddButtonsArea"); + GeneralUIUtils.ultimateWait(); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAELeftPanel.java b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAELeftPanel.java new file mode 100644 index 0000000..563c42b --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAELeftPanel.java @@ -0,0 +1,28 @@ +package com.att.ecomp.dcae.ci.ui.pages; + + + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; + +import com.aventstack.extentreports.Status; + +public class DCAELeftPanel { + + public static void navigateToServices() + { + ExtentTestActions.log(Status.INFO,"Navigate to Services internal tab"); + GeneralUIUtils.clickOnElementByTestId("dcae-menu-item-Services"); + GeneralUIUtils.ultimateWait(); + } + + public static void navigateToComposition() + { + ExtentTestActions.log(Status.INFO,"Navigate to Composition internal tab"); + GeneralUIUtils.clickOnElementByTestId("dcae-menu-item-Composition"); + GeneralUIUtils.ultimateWait(); + } + + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEServicesPage.java b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEServicesPage.java new file mode 100644 index 0000000..f935715 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/DCAEServicesPage.java @@ -0,0 +1,38 @@ +package com.att.ecomp.dcae.ci.ui.pages; + + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; + +import com.aventstack.extentreports.Status; + +public class DCAEServicesPage { + + public static void selectService(String serviceName) + { + GeneralUIUtils.ultimateWait(); + ExtentTestActions.log(Status.INFO,String.format("Select Service: %s from services dropdown", serviceName)); + GeneralUIUtils.getSelectList(serviceName, "Service Name SelectList"); + GeneralUIUtils.ultimateWait(); + } + + public static void selectVNFI(String VNFIName) + { + GeneralUIUtils.ultimateWait(); + VNFIName = VNFIName + " 0"; + ExtentTestActions.log(Status.INFO,String.format("Select VNFI: %s from VNFIs dropdown", VNFIName)); + GeneralUIUtils.getSelectList(VNFIName, "VNFI Name SelectList"); + GeneralUIUtils.ultimateWait(); + } + + + public static void clickAttach(String VNFIName) + { + ExtentTestActions.log(Status.INFO,"Click attach button"); + GeneralUIUtils.clickOnElementByTestId("Attach Button"); + GeneralUIUtils.ultimateWait(); + VNFIName = VNFIName + " 0"; + GeneralUIUtils.waitForElementInVisibilityByTestId(VNFIName); // Element to wait for after object is attached. + GeneralUIUtils.ultimateWait(); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCCreateServicePage.java b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCCreateServicePage.java new file mode 100644 index 0000000..4bf9fc4 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCCreateServicePage.java @@ -0,0 +1,175 @@ +package com.att.ecomp.dcae.ci.ui.pages; + +import java.util.UUID; + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Action; +import org.openqa.selenium.interactions.Actions; + +import com.aventstack.extentreports.Status; + +public class SDCCreateServicePage +{ + public static String addServiceName() + { + GeneralUIUtils.waitForElementInVisibilityByTestId("name"); + WebElement serviceNameTextbox = GeneralUIUtils.getWebElementByTestID("name"); + serviceNameTextbox.clear(); + String serviceName = "Service" + UUID.randomUUID(); + ExtentTestActions.log(Status.INFO, String.format("Add Service Name: %s", serviceName)); + serviceNameTextbox.sendKeys(serviceName); + GeneralUIUtils.ultimateWait(); + return serviceName; + } + + public static void addServiceCategory(String category) + { + ExtentTestActions.log(Status.INFO, String.format("Add %s Category", category)); + GeneralUIUtils.waitForElementInVisibilityByTestId("selectGeneralCategory"); + GeneralUIUtils.getSelectList(category, "selectGeneralCategory"); + GeneralUIUtils.ultimateWait(); + } + + public static void addServiceDescription() + { + ExtentTestActions.log(Status.INFO,"Add Service Desc"); + GeneralUIUtils.waitForElementInVisibilityByTestId("description"); + WebElement serviceDescTextbox = GeneralUIUtils.getWebElementByTestID("description"); + serviceDescTextbox.clear(); + String serviceDesc = "Desc"; + serviceDescTextbox.sendKeys(serviceDesc); + GeneralUIUtils.ultimateWait(); + } + + public static void addServiceDescriptionProjectCode() + { + ExtentTestActions.log(Status.INFO,"Add Service Project Code"); + GeneralUIUtils.waitForElementInVisibilityByTestId("projectCode"); + WebElement projectCodeTextbox = GeneralUIUtils.getWebElementByTestID("projectCode"); + projectCodeTextbox.clear(); + String projectCode = "12345"; + projectCodeTextbox.sendKeys(projectCode); + GeneralUIUtils.ultimateWait(); + } + + public static String addAllServiceMandtoryFields(String category) + { + String serviceName = addServiceName(); + addServiceCategory(category); + addServiceDescription(); + addServiceDescriptionProjectCode(); + + return serviceName; + } + + public static void clickOnCreateServiceButton() + { + ExtentTestActions.log(Status.INFO,"Click on Create Service Button"); + GeneralUIUtils.waitForElementInVisibilityByTestId("create/save"); + GeneralUIUtils.clickOnElementByTestId("create/save"); + GeneralUIUtils.ultimateWait(); + } + + public static void clickOnCheckInServiceButton() + { + ExtentTestActions.log(Status.INFO,"Click on Check In Service Button"); + GeneralUIUtils.waitForElementInVisibilityByTestId("check_in"); + GeneralUIUtils.clickOnElementByTestId("check_in"); + GeneralUIUtils.ultimateWait(); + } + + public static void addCheckInMessage() + { + ExtentTestActions.log(Status.INFO,"Add check in message in pop window"); + GeneralUIUtils.waitForElementInVisibilityByTestId("checkindialog"); + WebElement checkInDialogTextbox = GeneralUIUtils.getWebElementByTestID("checkindialog"); + checkInDialogTextbox.clear(); + String vfCheckInDialog = "Text"; + checkInDialogTextbox.sendKeys(vfCheckInDialog); + GeneralUIUtils.ultimateWait(); + } + + public static void clickOnCheckInOKFButton() + { + ExtentTestActions.log(Status.INFO,"Click OK in check in pop up window"); + GeneralUIUtils.waitForElementInVisibilityByTestId("OK"); + GeneralUIUtils.clickOnElementByTestId("OK"); + GeneralUIUtils.ultimateWait(); + } + + public static void checkInService() + { + clickOnCheckInServiceButton(); + addCheckInMessage(); + clickOnCheckInOKFButton(); + } + + public static void clickOnServiceCompsitionTab() + { + ExtentTestActions.log(Status.INFO,"Click on Service composition tab"); + GeneralUIUtils.waitForElementInVisibilityByTestId("CompositionLeftSideMenu"); + GeneralUIUtils.clickOnElementByTestId("CompositionLeftSideMenu"); + GeneralUIUtils.ultimateWait(); + } + + + public static void searchAssetOnCompsitionTab(String assetName) + { + ExtentTestActions.log(Status.INFO,String.format("Search for %s in Service composition", assetName)); + GeneralUIUtils.waitForElementInVisibilityByTestId("searchAsset"); + WebElement compositionSearchTextbox = GeneralUIUtils.getWebElementByTestID("searchAsset"); + compositionSearchTextbox.clear(); + compositionSearchTextbox.sendKeys(assetName); + GeneralUIUtils.ultimateWait(); + } + + public static void dragAndDropAssetToCanvas(String assetName) + { + ExtentTestActions.log(Status.INFO,String.format("Drag and drop %s to Canvas", assetName)); + GeneralUIUtils.waitForElementInVisibilityByTestId("searchAsset"); + WebElement vfElementFrom = GeneralUIUtils.getWebElementByTestID("leftbar-section-content-item-" + assetName); + WebElement canvasElementTo = GeneralUIUtils.getWebElementByTestID("canvas"); + GeneralUIUtils.ultimateWait(); + WebDriver driver = GeneralUIUtils.getDriver(); + Actions builder = new Actions(driver); + Action dragAndDrop = builder.clickAndHold(vfElementFrom).moveToElement(canvasElementTo).release(canvasElementTo).build(); + dragAndDrop.perform(); + GeneralUIUtils.ultimateWait(); + } + + public static void addAssetToCanvas(String assetName) + { + searchAssetOnCompsitionTab(assetName); + dragAndDropAssetToCanvas(assetName); + } + + public static void clickOnElementInCanavs() + { + ExtentTestActions.log(Status.INFO,"Click on VF in Canavs"); + GeneralUIUtils.waitForElementInVisibilityByTestId("canvas"); + WebElement canvasElement = GeneralUIUtils.getWebElementByTestID("canvas"); + GeneralUIUtils.ultimateWait(); + WebDriver driver = GeneralUIUtils.getDriver(); + Actions actions = new Actions(driver); + actions.moveToElement(canvasElement, 1316, 661); + actions.clickAndHold(); + actions.moveToElement(canvasElement, 1316, 661); + actions.release(); + actions.perform(); + GeneralUIUtils.ultimateWait(); + } + + public static void clickOnArtifactTab() + { + ExtentTestActions.log(Status.INFO,"Click on Artifcat"); + GeneralUIUtils.getWebElementByTestID("deployment-artifact-tab"); + GeneralUIUtils.clickOnElementByTestId("deployment-artifact-tab"); + } + + + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCCreateVFPage.java b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCCreateVFPage.java new file mode 100644 index 0000000..d7a30ba --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCCreateVFPage.java @@ -0,0 +1,123 @@ +package com.att.ecomp.dcae.ci.ui.pages; + +import java.util.UUID; + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; +import org.openqa.selenium.WebElement; + +import com.aventstack.extentreports.Status; + +public class SDCCreateVFPage +{ + public static String addVFName() + { + GeneralUIUtils.waitForElementInVisibilityByTestId("name"); + WebElement vfNameTextbox = GeneralUIUtils.getWebElementByTestID("name"); + vfNameTextbox.clear(); + String vfName = "VF" + UUID.randomUUID(); + vfNameTextbox.sendKeys(vfName); + ExtentTestActions.log(Status.INFO, String.format("Add VF Name: %s",vfName)); + GeneralUIUtils.ultimateWait(); + return vfName; + } + + public static void addVFCategory(String category) + { + ExtentTestActions.log(Status.INFO, String.format("Add %s Category", category)); + GeneralUIUtils.waitForElementInVisibilityByTestId("selectGeneralCategory"); + GeneralUIUtils.getSelectList(category, "selectGeneralCategory"); + GeneralUIUtils.ultimateWait(); + } + + public static void addVFDescription() + { + ExtentTestActions.log(Status.INFO,"Add VF Desc"); + GeneralUIUtils.waitForElementInVisibilityByTestId("description"); + WebElement vfdescTextbox = GeneralUIUtils.getWebElementByTestID("description"); + vfdescTextbox.clear(); + String vfDesc = "Desc"; + vfdescTextbox.sendKeys(vfDesc); + GeneralUIUtils.ultimateWait(); + } + + public static void addVFVendorName() + { + ExtentTestActions.log(Status.INFO,"Add VF Vendor Name"); + GeneralUIUtils.waitForElementInVisibilityByTestId("vendorName"); + WebElement vendorTextbox = GeneralUIUtils.getWebElementByTestID("vendorName"); + vendorTextbox.clear(); + String vfVendorName = "Vendor"; + vendorTextbox.sendKeys(vfVendorName); + GeneralUIUtils.ultimateWait(); + } + + public static void addVFVendorRelease() + { + ExtentTestActions.log(Status.INFO,"Add VF Vendor Release"); + GeneralUIUtils.waitForElementInVisibilityByTestId("vendorRelease"); + WebElement vendorReleaseTextbox = GeneralUIUtils.getWebElementByTestID("vendorRelease"); + vendorReleaseTextbox.clear(); + String vfVendorRelease = "1"; + vendorReleaseTextbox.sendKeys(vfVendorRelease); + GeneralUIUtils.ultimateWait(); + } + + public static String addAllVFMandtoryFields(String category) + { + String vfName = addVFName(); + addVFCategory(category); + addVFDescription(); + addVFVendorName(); + addVFVendorRelease(); + + return vfName; + } + + public static void clickOnCreateVFButton() + { + ExtentTestActions.log(Status.INFO,"Click on Create VF Button"); + GeneralUIUtils.waitForElementInVisibilityByTestId("create/save"); + GeneralUIUtils.clickOnElementByTestId("create/save"); + GeneralUIUtils.ultimateWait(); + } + + public static void clickOnCheckInVFButton() + { + ExtentTestActions.log(Status.INFO,"Click on Check In VF Button"); + GeneralUIUtils.waitForElementInVisibilityByTestId("check_in"); + GeneralUIUtils.clickOnElementByTestId("check_in"); + GeneralUIUtils.ultimateWait(); + } + + public static void addCheckInMessage() + { + ExtentTestActions.log(Status.INFO,"Add check in message in pop window"); + GeneralUIUtils.waitForElementInVisibilityByTestId("checkindialog"); + WebElement checkInDialogTextbox = GeneralUIUtils.getWebElementByTestID("checkindialog"); + checkInDialogTextbox.clear(); + String vfCheckInDialog = "Text"; + checkInDialogTextbox.sendKeys(vfCheckInDialog); + GeneralUIUtils.ultimateWait(); + } + + public static void clickOnCheckInOKFButton() + { + ExtentTestActions.log(Status.INFO,"Click OK in check in pop up window"); + GeneralUIUtils.waitForElementInVisibilityByTestId("OK"); + GeneralUIUtils.clickOnElementByTestId("OK"); + GeneralUIUtils.ultimateWait(); + } + + public static void checkInVF() + { + clickOnCheckInVFButton(); + addCheckInMessage(); + clickOnCheckInOKFButton(); + } + + + + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCHomePage.java b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCHomePage.java new file mode 100644 index 0000000..00a4e4e --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/pages/SDCHomePage.java @@ -0,0 +1,60 @@ +package com.att.ecomp.dcae.ci.ui.pages; + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.setup.SetupCDTest; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; +import org.openqa.selenium.WebElement; + +import com.att.ecomp.dcae.ci.utilities.ConfigurationReader; +import com.aventstack.extentreports.Status; + +public class SDCHomePage +{ + + public static void clickOnAddVf() + { + ExtentTestActions.log(Status.INFO,"Clicking on Add VF button"); + GeneralUIUtils.waitForElementInVisibilityByTestId("AddButtonsArea"); + GeneralUIUtils.hoverOnAreaByTestId("AddButtonsArea"); + GeneralUIUtils.waitForElementInVisibilityByTestId("createResourceButton"); + GeneralUIUtils.clickOnElementByTestId("createResourceButton"); + GeneralUIUtils.ultimateWait(); + } + + public static void clickOnAddsService() + { + ExtentTestActions.log(Status.INFO,"Clicking on Add Service button"); + GeneralUIUtils.waitForElementInVisibilityByTestId("AddButtonsArea"); + GeneralUIUtils.hoverOnAreaByTestId("AddButtonsArea"); + GeneralUIUtils.waitForElementInVisibilityByTestId("createServiceButton"); + GeneralUIUtils.clickOnElementByTestId("createServiceButton"); + GeneralUIUtils.ultimateWait(); + } + + public static void searchForElement(String name) + { + ExtentTestActions.log(Status.INFO,"Search for element in Homepage"); + GeneralUIUtils.waitForElementInVisibilityByTestId("main-menu-input-search"); + WebElement searchTextbox = GeneralUIUtils.getWebElementByTestID("main-menu-input-search"); + searchTextbox.clear(); + searchTextbox.sendKeys(name); + GeneralUIUtils.ultimateWait(); + } + + public static void clickOnElement(String name) + { + ExtentTestActions.log(Status.INFO,"Clicking on Add VF button"); + GeneralUIUtils.waitForElementInVisibilityByTestId(name); + GeneralUIUtils.clickOnElementByTestId(name); + GeneralUIUtils.ultimateWait(); + } + + public static void clickOnHomeTab() throws Exception { + ExtentTestActions.log(Status.INFO,"Navigate to SDC Homepage"); + GeneralUIUtils.clickOnElementByCSS("div[class=triangle] span"); // Temp workaround... need to click by data-tests-id + GeneralUIUtils.ultimateWait(); + GeneralUIUtils.clickOnElementByTestId("sub-menu-button-home"); + GeneralUIUtils.ultimateWait(); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/BaseTest.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/BaseTest.java new file mode 100644 index 0000000..a197dd3 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/BaseTest.java @@ -0,0 +1,143 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor; + +import java.io.File; +import java.util.Map; + +import org.openecomp.d2.ci.datatypes.Configuration; +import org.openecomp.d2.ci.datatypes.UserCredentials; +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.setup.DriverFactory; +import org.openecomp.d2.ci.utilities.FileHandling; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.web.util.UriComponentsBuilder; +import org.testng.annotations.BeforeMethod; + +import com.att.ecomp.dcae.ci.ui.rule_editor.components.LoginPage; +import com.att.ecomp.dcae.ci.utilities.ConfigurationReader; +import com.att.ecomp.dcae.ci.utilities.DcaeEntityClient; +import com.att.ecomp.dcae.ci.utilities.DcaeRestClient; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class BaseTest extends DriverFactory { + + private String baseUrl = ConfigurationReader.getConfiguration().getRuleEditorUrl(); + private final long defaultTimeout = 90; + protected WebDriverWait defaultTimeoutWait; + + @BeforeMethod + protected void setupTest(){ + try { + /** + * this is surrounded by a try block because of a bug in TestNg that causes 'afterMethod' to not be called + * when an exception is thrown in the 'beforeMethod' - this prevents the ExtentReport from producing a report + */ + + Report.log(Status.INFO, "Setting up..."); + LinkedMultiValueMap params = arrangeRequiredParams(); + String url = UriComponentsBuilder.fromHttpUrl(baseUrl).queryParams(params).build().toUriString(); + Report.log(Status.INFO, "Deleting cookies..."); + WebDriver driver = getDriver(); + driver.manage().deleteAllCookies(); + Report.log(Status.INFO, "Navigating to URL: %s", url); + driver.navigate().to(url); + Report.log(Status.INFO, "Checking if diverted to login page..."); + defaultTimeoutWait = new WebDriverWait(driver, defaultTimeout); + if (LoginPage.isCurrentPage(driver)) { + Report.log(Status.INFO, "Preforming login..."); + WebElement root = driver.findElement(By.cssSelector("body")); + LoginPage loginPage = new LoginPage(defaultTimeoutWait, root); + loginPage.login(getUserCredentials()); + Report.log(Status.INFO, "Refreshing..."); + driver.navigate().refresh(); // refresh fixes missing cookies after login + Report.log(Status.INFO, "Logged-in successfully."); + } else { + Report.log(Status.INFO, "Not in login page."); + } + Report.log(Status.INFO, "Setup done."); + } catch (Exception err) { + Report.fatal("Error during setup", err); + } + } + + protected LinkedMultiValueMap arrangeRequiredParams() throws Exception { + String userId = getUserCredentials().getUserId(); + DcaeEntityClient dcaeEntityClient = new DcaeEntityClient(); + Report.log(Status.INFO, "Creating vfcmt..."); + Vfcmt vfcmt = dcaeEntityClient.createVfcmt(userId); +// Report.log(Status.INFO, "Generating cdump of snmp (simulated drag of snmp component)..."); + String cdump = getFakeCdump(); + Report.log(Status.INFO, "Saving composition..."); + RestResponse saveResponse = DcaeRestClient.saveComposition(vfcmt.getUuid(), userId, cdump); + if (saveResponse.getStatusCode() != 200) { + throw new Exception("Save composition failed.\nDetails: " + saveResponse.toString()); + } + LinkedMultiValueMap params = new LinkedMultiValueMap(); + params.add("vfcmtUuid", vfcmt.getUuid()); + params.add("nodeName", "map"); + params.add("nodeId", "map"); + params.add("fieldName", "fake"); + params.add("userId", userId); + params.add("flowType", "FOI"); + return params; + } + + protected LinkedMultiValueMap arrangeFakeParams() { + LinkedMultiValueMap params = new LinkedMultiValueMap(); + params.add("vfcmtUuid", "aece8152-a97f-4ec4-9a42-941d8e586f97"); + params.add("nodeName", "map"); + params.add("nodeId", "map"); + params.add("fieldName", "fake"); + params.add("userId", "fakeo"); + params.add("flowType", "FOI"); + return params; + } + + private static String getFakeCdump() { + return "{\"nid\":\"map\"}"; + } + + protected UserRoleEnum getUserRole() + { + return UserRoleEnum.DESIGNER; + } + + @Override + protected Configuration getEnvConfiguration() { + return ConfigurationReader.getConfiguration(); + } + + @Override + protected UserCredentials getUserCredentials() { + try { + String userRole = getUserRole().name().toLowerCase(); + String credentialsFile = System.getProperty("credentials.file"); + if (credentialsFile == null) + credentialsFile = ConfigurationReader.confPath() + "credentials.yaml"; + File file = new File(credentialsFile); + if (!file.exists()){ + throw new Exception("Please provide a credentails file"); + } + Map credentialsParsedFile = FileHandling.parseYamlFile(credentialsFile); + Map credentialsMap = (Map) credentialsParsedFile.get(userRole); + String userId = (String) credentialsMap.get("username"); + String password = (String) credentialsMap.get("password"); + String firstname = (String) credentialsMap.get("firstname"); + String lastname = (String) credentialsMap.get("lastname"); + + return new UserCredentials(userId, password, firstname, lastname, null); + + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/TranslateResult.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/TranslateResult.java new file mode 100644 index 0000000..22545b9 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/TranslateResult.java @@ -0,0 +1,32 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor; + +import com.fasterxml.jackson.annotation.*; + +public class TranslateResult { + + public enum Status { + ok, + error + } + + private Status status; + private String data; + + @JsonCreator + public TranslateResult( + @JsonProperty("status") Status status, + @JsonProperty("data") String data) { + + this.status = status; + this.data = data; + } + + public Status getStatus() { + return status; + } + + public String getData() { + return data; + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/BaseComponenet.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/BaseComponenet.java new file mode 100644 index 0000000..c159af9 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/BaseComponenet.java @@ -0,0 +1,15 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class BaseComponenet { + + protected WebDriverWait wait; + protected WebElement root; + + public BaseComponenet(WebDriverWait timeout, WebElement element) { + this.wait = timeout; + this.root = element; + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/HomePage.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/HomePage.java new file mode 100644 index 0000000..47ab468 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/HomePage.java @@ -0,0 +1,113 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components; + +import static org.testng.Assert.fail; + +import java.util.Arrays; + +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.rule_editor.TranslateResult; +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class HomePage extends BaseComponenet { + + public HomePage(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public void waitForLoaderFinish() { + Report.log(Status.INFO, "Wait for loader finish..."); + ByTest loaderTestId = ByTest.id("loader"); + WebElement loader = wait.until(Locator.from(root).find(loaderTestId, 0)); // wait until loader appears + wait.until(ExpectedConditions.invisibilityOfAllElements(Arrays.asList(loader))); // wait until loader disappears + } + + public void load(String version, String eventType) { + Report.log(Status.INFO, "Selecting version..."); + select(ByTest.id("selectVersion"), version); + Report.log(Status.INFO, "Selecting event-type..."); + select(ByTest.id("selectEventType"), eventType); + } + + public RuleComponent getRule(int index) { + WebElement ruleElement = wait.until(Locator.from(root).findVisible(ByTest.id("ruleElement"), index)); + return new RuleComponent(wait, ruleElement); + } + + private WebElement getRulePopupElem() { + return wait.until(Locator.from(root).findVisible(ByTest.id("popupRuleEditor"), 0)); + } + + public WebElement getRoot() { + return root; + } + + public RulePopup clickAddFirstRule() { + Report.log(Status.INFO, "Clicking add-rule..."); + wait.until(Locator.from(root).findVisible(ByTest.id("btnAddFirstRule"), 0)).click(); + WebElement popupAddRule = getRulePopupElem(); + Report.log(Status.INFO, "Rule popup visible"); + return new RulePopup(wait, popupAddRule); + } + + public RulePopup clickAddMoreRule() { + Report.log(Status.INFO, "Clicking add-rule..."); + wait.until(Locator.from(root).findVisible(ByTest.id("addMoreRule"), 0)).click(); + WebElement popupAddRule = getRulePopupElem(); + Report.log(Status.INFO, "Rule popup visible"); + return new RulePopup(wait, popupAddRule); + } + + public void clickOnRuleDeleteConfirmPopup (){ + Report.log(Status.INFO, "Click on delete on popup confirmation"); + WebElement deletePopup = wait.until(Locator.from(root).findVisible(ByTest.id("delete-popup"), 0)); + wait.until(Locator.from(root).findVisible(ByTest.id("btnDelete"), 0)).click(); + waitForLoaderFinish(); + } + + public void clickTranslate() { + Report.log(Status.INFO, "Clicking Translate..."); + wait.until(Locator.from(root).findVisible(ByTest.id("btnTranslate"), 0)).click(); + waitForLoaderFinish(); + } + + public void clickCancel() { + Report.log(Status.INFO, "Clicking Cancel..."); + wait.until(Locator.from(root).findVisible(ByTest.id("btnCancel"), 0)).click(); + } + + public String getTranslation(WebDriver driver) throws Exception { + Report.log(Status.INFO, "Retriving translation result..."); + Object result = (Object) ((JavascriptExecutor) driver).executeScript("return window.translateResult;"); + ObjectMapper mapper = new ObjectMapper(); + TranslateResult parsedResult = mapper.convertValue(result, TranslateResult.class); + switch(parsedResult.getStatus()) { + case error: + fail(String.format("translate error: %s", parsedResult.getData())); + break; + case ok: + Report.logDebug("translation:", parsedResult.getData()); + return parsedResult.getData(); + } + throw new Exception(String.format("invalid status argument. expected (ok/error) but got %s", parsedResult.getData())); + } + + /* Private Methods */ + + private void select(ByTest by, String option) { + WebElement selectElement = wait.until(Locator.from(root).findVisible(by, 0)); + wait.until(Locator.from(selectElement).find(ByTest.id("option"), 0)); // wait for dynamic options + Select versionSelect = new Select(selectElement); + versionSelect.selectByVisibleText(option); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/LoginPage.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/LoginPage.java new file mode 100644 index 0000000..cc17481 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/LoginPage.java @@ -0,0 +1,39 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components; + +import org.openecomp.d2.ci.datatypes.UserCredentials; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class LoginPage extends BaseComponenet { + + public LoginPage(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public void login(String userId, String password) { + Report.log(Status.INFO, "Filling input userid..."); + root.findElement(By.name("userid")).sendKeys(userId); + Report.log(Status.INFO, "Filling input password..."); + root.findElement(By.name("password")).sendKeys(password); + Report.log(Status.INFO, "Clicking submit..."); + root.findElement(By.name("btnSubmit")).click(); + Report.log(Status.INFO, "Waiting for login success page..."); + wait.until(ExpectedConditions.titleIs("AT&T - Log On Successful")); + Report.log(Status.INFO, "Clicking OK..."); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("successOK"))).click(); + } + + public void login(UserCredentials credentials) { + login(credentials.getUserId(), credentials.getPassword()); + } + + public static boolean isCurrentPage(WebDriver driver) { + return driver.getTitle().equals("AT&T Security Server: Login"); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/RuleComponent.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/RuleComponent.java new file mode 100644 index 0000000..94bf547 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/RuleComponent.java @@ -0,0 +1,40 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class RuleComponent extends BaseComponenet { + + public RuleComponent(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public String getDescription(){ + Report.log(Status.INFO, "Get rule description"); + return root.getText(); + } + + public RulePopup clickEdit(WebDriver driver, WebElement homePageRoot){ + Report.log(Status.INFO, "Click on edit..."); + Actions action = new Actions(driver); + action.moveToElement(root).perform(); + wait.until(Locator.from(root).findVisible(ByTest.id("editRule"), 0)).click(); + WebElement rulePopupElem = wait.until(Locator.from(homePageRoot).findVisible(ByTest.id("popupRuleEditor"), 0)); + return new RulePopup(wait, rulePopupElem); + } + + public void clickDelete(WebDriver driver){ + Report.log(Status.INFO, "Click on delete..."); + Actions action = new Actions(driver); + action.moveToElement(root).perform(); + wait.until(Locator.from(root).findVisible(ByTest.id("deleteRule"), 0)).click(); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/RulePopup.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/RulePopup.java new file mode 100644 index 0000000..1cde952 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/RulePopup.java @@ -0,0 +1,141 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components; + +import java.util.Arrays; + +import org.apache.commons.lang3.NotImplementedException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.ActionComponent; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.ActionType; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.ConcatActionComponent; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.CopyActionComponent; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.MapActionComponent; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.condition.ConditionComponent; +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class RulePopup extends BaseComponenet { + + public RulePopup(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public String getDescription() { + Report.log(Status.INFO, "get input description..."); + return wait.until(Locator.from(root).findVisible(ByTest.id("inputDescription"), 0)).getAttribute("value"); + } + + public void setDescription(String text) { + Report.log(Status.INFO, "Filling input description..."); + wait.until(Locator.from(root).findVisible(ByTest.id("inputDescription"), 0)).sendKeys(text); + } + + public ActionComponent getAction(ActionType actionType, int index) { + WebElement actionElement = wait.until(Locator.from(root).findVisible(ByTest.id("action"), index)); + ActionComponent newActionComponent = createAction(actionType, wait, actionElement); + return newActionComponent; + } + + public CopyActionComponent addCopyAction(int index) { + return (CopyActionComponent) addAction(ActionType.Copy, index); + } + + public ConcatActionComponent addConcatAction(int index) { + return (ConcatActionComponent) addAction(ActionType.Concat, index); + } + + public MapActionComponent addMapAction(int index) { + return (MapActionComponent) addAction(ActionType.Map, index); + } + + public WebElement getErrorList(){ + return wait.until(Locator.from(root).findVisible(ByTest.id("errorList"), 0)); + } + + public void clickOnAddCondition(){ + wait.until(Locator.from(root).find(ByTest.id("isCondition"), 0)).click(); + } + + public void addSimpleCondition(){ + clickOnAddCondition(); + Report.log(Status.INFO, "Create and fill simple condition"); + ConditionComponent condition = new ConditionComponent(wait,root); + condition.setLeftField(0, "A"); + condition.setRightField(0, "B"); + condition.selectOperator(0, "Contains"); + } + + public void addComplexCondition(){ + Report.log(Status.INFO, "Click on add condition checkbox"); + clickOnAddCondition(); + Report.log(Status.INFO, "Create and fill top condition"); + ConditionComponent condition1 = new ConditionComponent(wait,root); + condition1.setLeftField(0, "A"); + condition1.setRightField(0, "B"); + condition1.selectOperator(0, "Contains"); + Report.log(Status.INFO, "Click on add group condition"); + wait.until(Locator.from(root).findVisible(ByTest.id("addConditionGroup"), 0)).click(); + Report.log(Status.INFO, "Create and fill first nested condition"); + ConditionComponent innerCondition1 = new ConditionComponent(wait,root); + condition1.setLeftField(1, "C"); + condition1.setRightField(1, "D"); + condition1.selectOperator(1, "Contains"); + Report.log(Status.INFO, "Create and fill second nested condition"); + ConditionComponent innerCondition2 = new ConditionComponent(wait,root); + condition1.setLeftField(2, "E"); + condition1.setRightField(2, "F"); + condition1.selectOperator(2, "Contains"); + } + + public void clickSave() { + Report.log(Status.INFO, "Clicking Save (changes on rule-editor)..."); + wait.until(Locator.from(root).findVisible(ByTest.id("btnSave"), 0)).click(); + waitForLoaderFinish(); + } + + public void clickCancel() { + Report.log(Status.INFO, "Clicking Cancel (changes on rule-editor)..."); + wait.until(Locator.from(root).findVisible(ByTest.id("btnCancel"), 0)).click(); + } + + + /* Private Methods */ + + private void waitForLoaderFinish() { + Report.log(Status.INFO, "Wait for loader finish..."); + ByTest loaderTestId = ByTest.id("loader"); + WebElement loader = root.findElement(loaderTestId); + wait.until(ExpectedConditions.invisibilityOfAllElements(Arrays.asList(loader))); // wait until loader disappears + } + + private ActionComponent addAction(ActionType actionType, int index) { + Report.log(Status.INFO, "Selecting action..."); + WebElement actionElement = wait.until(Locator.from(root).findVisible(ByTest.id("selectAction"), 0)); + Select actionSelect = new Select(actionElement); + actionSelect.selectByVisibleText(actionType.toString()); + Report.log(Status.INFO, "Clicking Add Action..."); + wait.until(Locator.from(root).findVisible(ByTest.id("btnAddAction"), 0)).click(); + return getAction(actionType, index); + } + + private static ActionComponent createAction(ActionType actionType, WebDriverWait wait, WebElement newActionElement) { + switch (actionType) { + case Concat: + return new ConcatActionComponent(wait, newActionElement); + case Copy: + return new CopyActionComponent(wait, newActionElement); + case Map: + return new MapActionComponent(wait, newActionElement); + default: + throw new IllegalArgumentException(String.format("action type '%s' not supported", actionType)); + } + } + + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ActionComponent.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ActionComponent.java new file mode 100644 index 0000000..c12931a --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ActionComponent.java @@ -0,0 +1,48 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components.actions; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.rule_editor.components.BaseComponenet; +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class ActionComponent extends BaseComponenet { + + public ActionComponent(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public void delete() { + Report.log(Status.INFO, "click on delete action"); + wait.until(Locator.from(root).findVisible(ByTest.id("deleteAction"), 0)).click(); + } + + public void setTarget(String target) { + Report.log(Status.INFO, "Filling input target..."); + getTargetElement().clear(); + getTargetElement().sendKeys(target); + } + + public void setTargetFromTree(){ + Report.log(Status.INFO, "Pick target from tree"); + wait.until(Locator.from(root).findVisible(ByTest.id("openTargetTree"), 0)).click(); + Report.log(Status.INFO, "Click on tree toggle"); + wait.until(Locator.from(root).findVisible(ByTest.cssSelector(".toggle-children-wrapper"),0)).click(); + Report.log(Status.INFO, "Click on first target node"); + wait.until(Locator.from(root).findVisible(ByTest.id("targetNode"), 1)).click(); + } + + public String getTarget() { + Report.log(Status.INFO, "get input target..."); + return getTargetElement().getAttribute("value"); + } + + /* Private Methods */ + + private WebElement getTargetElement() { + return wait.until(Locator.from(root).findVisible(ByTest.id("inputTarget"), 0)); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ActionType.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ActionType.java new file mode 100644 index 0000000..4cb4a28 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ActionType.java @@ -0,0 +1,7 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components.actions; + +public enum ActionType { + Copy, + Concat, + Map +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ConcatActionComponent.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ConcatActionComponent.java new file mode 100644 index 0000000..435441e --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/ConcatActionComponent.java @@ -0,0 +1,31 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components.actions; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.from.DeleteableFromComponent; +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + + +public class ConcatActionComponent extends ActionComponent { + + public ConcatActionComponent(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public DeleteableFromComponent clickAddInput(int index) { + Report.log(Status.INFO, "Clicking on add input (another from)..."); + wait.until(Locator.from(root).findVisible(ByTest.id("btnAddInput"), 0)).click(); + return getFromComponent(index); + } + + public DeleteableFromComponent getFromComponent(int index) { + Report.log(Status.INFO, "Getting from component at index %d...", index); + WebElement fromElement = wait.until(Locator.from(root).findVisible(ByTest.id("fromComponent"), index)); + return new DeleteableFromComponent(wait, fromElement); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/CopyActionComponent.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/CopyActionComponent.java new file mode 100644 index 0000000..3241ce6 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/CopyActionComponent.java @@ -0,0 +1,24 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components.actions; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.from.RegexFromComponent; +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class CopyActionComponent extends ActionComponent { + + public CopyActionComponent(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public RegexFromComponent getFromComponent() { + Report.log(Status.INFO, "Getting fromComponent..."); + WebElement fromElement = wait.until(Locator.from(root).findVisible(ByTest.id("fromComponent"), 0)); + return new RegexFromComponent(wait, fromElement); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/MapActionComponent.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/MapActionComponent.java new file mode 100644 index 0000000..37efe17 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/MapActionComponent.java @@ -0,0 +1,44 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components.actions; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.from.RegexFromComponent; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.from.SimpleFromComponent; +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class MapActionComponent extends ActionComponent { + + public MapActionComponent(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public SimpleFromComponent getFromComponent() { + Report.log(Status.INFO, "getting simple from component"); + WebElement fromElement = wait.until(Locator.from(root).findVisible(ByTest.id("fromComponent"), 0)); + return new SimpleFromComponent(wait, fromElement); + } + + public void openDefaultOption(){ + Report.log(Status.INFO, "open default opention by click on checkbox"); + wait.until(Locator.from(root).find(ByTest.id("defaultCheckbox"), 0)).click(); + } + + public void setDefaultData(String value){ + Report.log(Status.INFO, "set default field with a value"); + wait.until(Locator.from(root).findVisible(ByTest.id("defaultInput"), 0)).sendKeys(value); + } + + public void setKeyData(String value){ + Report.log(Status.INFO, "set map key with a value"); + wait.until(Locator.from(root).findVisible(ByTest.id("key"), 0)).sendKeys(value); + } + + public void setValueData(String value){ + Report.log(Status.INFO, "set map value with a value"); + wait.until(Locator.from(root).findVisible(ByTest.id("value"), 0)).sendKeys(value); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/DeleteableFromComponent.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/DeleteableFromComponent.java new file mode 100644 index 0000000..4037419 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/DeleteableFromComponent.java @@ -0,0 +1,26 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.from; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class DeleteableFromComponent extends SimpleFromComponent { + + public DeleteableFromComponent(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public void clickDelete(WebDriver driver) { + Report.log(Status.INFO, "Click on delete from..."); + Actions action = new Actions(driver); + action.moveToElement(root).perform(); + wait.until(Locator.from(root).findVisible(ByTest.id("btnDelete"), 0)).click(); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/RegexFromComponent.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/RegexFromComponent.java new file mode 100644 index 0000000..159d0c9 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/RegexFromComponent.java @@ -0,0 +1,38 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.from; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class RegexFromComponent extends SimpleFromComponent { + + public RegexFromComponent(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public void clickRegex() { + Report.log(Status.INFO, "Clicking regex button..."); + wait.until(Locator.from(root).findVisible(ByTest.id("btnFromRegex"), 0)).click(); + } + + public String getRegex() { + Report.log(Status.INFO, "Getting regex from..."); + return getRegexElement().getAttribute("value"); + } + + public void setRegex(String value) { + Report.log(Status.INFO, "Setting regex from..."); + getRegexElement().clear(); + getRegexElement().sendKeys(value); + } + + /* Private Methods */ + + private WebElement getRegexElement() { + return wait.until(Locator.from(root).findVisible(ByTest.id("inputFromRegex"), 0)); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/SimpleFromComponent.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/SimpleFromComponent.java new file mode 100644 index 0000000..a7cba3d --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/actions/from/SimpleFromComponent.java @@ -0,0 +1,34 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.from; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.rule_editor.components.BaseComponenet; +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class SimpleFromComponent extends BaseComponenet { + + public SimpleFromComponent(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public String getValue() { + Report.log(Status.INFO, "Getting input from..."); + return getFromValueElement().getAttribute("value"); + } + + public void setValue(String value) { + Report.log(Status.INFO, "Setting input from..."); + getFromValueElement().clear(); + getFromValueElement().sendKeys(value); + } + + /* Private Methods */ + + private WebElement getFromValueElement() { + return wait.until(Locator.from(root).findVisible(ByTest.id("valueInput"), 0)); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/condition/ConditionComponent.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/condition/ConditionComponent.java new file mode 100644 index 0000000..12ab277 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/components/condition/ConditionComponent.java @@ -0,0 +1,34 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.components.condition; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.att.ecomp.dcae.ci.ui.rule_editor.components.BaseComponenet; +import com.att.ecomp.dcae.ci.ui.utils.ByTest; +import com.att.ecomp.dcae.ci.ui.utils.Locator; + +public class ConditionComponent extends BaseComponenet{ + + public ConditionComponent(WebDriverWait timeout, WebElement element) { + super(timeout, element); + } + + public void setLeftField(int index, String value){ + WebElement left = wait.until(Locator.from(root).findVisible(ByTest.id("left"), index)); + left.clear(); + left.sendKeys(value); + } + + public void setRightField(int index, String value){ + WebElement right = wait.until(Locator.from(root).findVisible(ByTest.id("right"), index)); + right.clear(); + right.sendKeys(value); + } + + public void selectOperator(int index, String value){ + WebElement operatorElement = wait.until(Locator.from(root).findVisible(ByTest.id("selectOperator"), index)); + Select operatorSelect = new Select(operatorElement); + operatorSelect.selectByVisibleText(value); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/tests/SanityTest.java b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/tests/SanityTest.java new file mode 100644 index 0000000..9f31ddd --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/rule_editor/tests/SanityTest.java @@ -0,0 +1,150 @@ +package com.att.ecomp.dcae.ci.ui.rule_editor.tests; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.testng.annotations.Test; + +import com.att.ecomp.dcae.ci.ui.rule_editor.BaseTest; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.HomePage; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.RuleComponent; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.RulePopup; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.ActionType; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.ConcatActionComponent; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.CopyActionComponent; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.MapActionComponent; +import com.att.ecomp.dcae.ci.ui.rule_editor.components.actions.from.RegexFromComponent; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public class SanityTest extends BaseTest { + + @Test + public void testTranslateOfSingleCopyAction() throws Exception { + WebDriver driver = getDriver(); + ExtentTestActions.log(Status.INFO, "test start"); + List findElements = driver.findElements(By.cssSelector("[data-tests-id*=\"map\" i]")); + + + WebElement appElement; + HomePage homePage = initHomePage(driver); + homePage.load("5.3", "syslog"); + setRule1(homePage.clickAddFirstRule()); + setRule2(homePage.clickAddMoreRule(), driver); + RulePopup editRule1 = homePage.getRule(0).clickEdit(driver, homePage.getRoot()); + validateRule1(editRule1); + editRule1 = homePage.getRule(0).clickEdit(driver, homePage.getRoot()); + editRule1(editRule1); + RuleComponent firstRuleinList = verifyRuleListDescription(homePage); + deleteRuleFromRuleList(driver, homePage, firstRuleinList); + translateRuleList(driver, homePage); + refreshAndVerifyGetRules(driver); + } + + private void refreshAndVerifyGetRules(WebDriver driver) { + Report.log(Status.INFO, "Refresh and verify getting rule list"); + HomePage homePage; + RuleComponent firstRuleinList; + driver.navigate().refresh(); + homePage = initHomePage(driver); + firstRuleinList = homePage.getRule(0); + assertThat(firstRuleinList.getDescription()).contains("Yanir Manor"); + } + + private void translateRuleList(WebDriver driver, HomePage homePage) throws Exception { + Report.log(Status.INFO, "Translate rule list"); + homePage.clickTranslate(); + String translation = homePage.getTranslation(driver); + assertThat(translation).isNotEmpty(); + } + + private void deleteRuleFromRuleList(WebDriver driver, HomePage homePage, RuleComponent firstRuleinList) { + Report.log(Status.INFO, "Delete the first rule from list"); + firstRuleinList.clickDelete(driver); + homePage.clickOnRuleDeleteConfirmPopup(); + } + + private RuleComponent verifyRuleListDescription(HomePage homePage) { + Report.log(Status.INFO, "Verify Rule List Description"); + RuleComponent firstRuleinList = homePage.getRule(0); + assertThat(firstRuleinList.getDescription()).contains("Oren Levi"); + return firstRuleinList; + } + + private HomePage initHomePage(WebDriver driver) { + WebElement appElement = driver.findElement(By.cssSelector("body")); + HomePage homePage = new HomePage(defaultTimeoutWait, appElement); + homePage.waitForLoaderFinish(); + return homePage; + } + + private void setRule1(RulePopup rulePopup) { + Report.log(Status.INFO, "Set first rule"); + rulePopup.setDescription("Oren Levi"); + CopyActionComponent copyAction = rulePopup.addCopyAction(0); + rulePopup.clickSave(); + WebElement errorList = rulePopup.getErrorList(); + assertThat(errorList.getText()).isNotEmpty(); + rulePopup.addSimpleCondition(); + RegexFromComponent fromComponent = copyAction.getFromComponent(); + fromComponent.setValue("Argentina"); + fromComponent.clickRegex(); + fromComponent.setRegex("*"); + copyAction.setTarget("Mexico"); + rulePopup.clickSave(); + } + + private void validateRule1(RulePopup rulePopup) { + Report.log(Status.INFO, "Validate first rule"); + assertThat(rulePopup.getDescription()).isEqualTo("Oren Levi"); + CopyActionComponent copyAction = (CopyActionComponent) rulePopup.getAction(ActionType.Copy, 0); + RegexFromComponent fromComponent = copyAction.getFromComponent(); + assertThat(fromComponent.getValue()).isEqualTo("Argentina"); + assertThat(fromComponent.getRegex()).isEqualTo("*"); + assertThat(copyAction.getTarget()).isEqualTo("Mexico"); + rulePopup.clickCancel(); + } + + private void editRule1(RulePopup rulePopup) { + Report.log(Status.INFO, "Edit first rule"); + CopyActionComponent copyAction = (CopyActionComponent) rulePopup.getAction(ActionType.Copy, 0); + RegexFromComponent fromComponent = copyAction.getFromComponent(); + fromComponent.setValue("Brazil"); + fromComponent.setRegex("**"); + copyAction.setTarget("Canada"); + rulePopup.clickSave(); + } + + private void setRule2(RulePopup rulePopup, WebDriver driver) { + Report.log(Status.INFO, "Set second rule"); + rulePopup.setDescription("Yanir Manor"); + + Report.log(Status.INFO, "Add complex condition"); + rulePopup.addComplexCondition(); + + Report.log(Status.INFO, "Add concat action"); + ConcatActionComponent concatAction = rulePopup.addConcatAction(0); + concatAction.getFromComponent(0).setValue("Oren"); + concatAction.getFromComponent(1).setValue("Levi"); + concatAction.clickAddInput(2).setValue("yanir"); + concatAction.getFromComponent(1).clickDelete(driver); + concatAction.setTargetFromTree(); + + Report.log(Status.INFO, "Add map action"); + MapActionComponent mapAction = rulePopup.addMapAction(1); + mapAction.getFromComponent().setValue("Mapfrom"); + mapAction.setTarget("MapTarget"); + mapAction.openDefaultOption(); + mapAction.setDefaultData("default data"); + mapAction.setKeyData("A"); + mapAction.setValueData("B"); + + rulePopup.clickSave(); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/setup/ConfigTest.java b/src/main/java/com/att/ecomp/dcae/ci/ui/setup/ConfigTest.java new file mode 100644 index 0000000..1f6f59a --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/setup/ConfigTest.java @@ -0,0 +1,83 @@ +package com.att.ecomp.dcae.ci.ui.setup; + +import java.io.File; +import java.util.Map; + +import org.openecomp.d2.ci.datatypes.Configuration; +import org.openecomp.d2.ci.datatypes.UserCredentials; +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openecomp.d2.ci.setup.SetupCDTest; +import org.openecomp.d2.ci.utilities.FileHandling; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; +import org.openecomp.d2.ci.utilities.LoginUtils; +import org.openqa.selenium.WebElement; +import org.testng.annotations.BeforeMethod; + +import com.att.ecomp.dcae.ci.utilities.ConfigurationReader; +import com.att.ecomp.dcae.ci.utilities.Report; +import com.aventstack.extentreports.Status; + +public abstract class ConfigTest extends SetupCDTest { + + protected abstract UserRoleEnum getUserRole(); + + @Override + protected Configuration getEnvConfiguration() { + return ConfigurationReader.getConfiguration(); + } + + @Override + protected UserCredentials getUserCredentials() { + try { + String userRole = getUserRole().name().toLowerCase(); + String credentialsFile = System.getProperty("credentials.file"); + if (credentialsFile == null) + credentialsFile = ConfigurationReader.confPath() + "credentials.yaml"; + File file = new File(credentialsFile); + if (!file.exists()){ + throw new Exception("Please provide a credentails file"); + } + Map credentialsParsedFile = FileHandling.parseYamlFile(credentialsFile); + Map credentialsMap = (Map) credentialsParsedFile.get(userRole); + String userId = (String) credentialsMap.get("username"); + String password = (String) credentialsMap.get("password"); + String firstname = (String) credentialsMap.get("firstname"); + String lastname = (String) credentialsMap.get("lastname"); + + UserCredentials userCredentials = new UserCredentials(userId, password, firstname, lastname, null); + Report.log(Status.INFO, "Using user Credentials="+userCredentials); + return userCredentials; + + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + @Override + protected void loginToLocalSimulator(UserCredentials user) { + LoginUtils.loginToLocalWebsealSimulator(user); + } + + @BeforeMethod + public void beforeTest(){ + try{ + if(getEnvConfiguration().getUrl().contains("localhost")) + { + GeneralUIUtils.ultimateWait(); + } + else + { + WebElement close = GeneralUIUtils.getWebElementByClassName("sdc-welcome-close"); + close.click(); + GeneralUIUtils.ultimateWait(); + } + } + catch(Exception e){ + Report.logDebug("Exception has occured in beforeTest - unable to proceed to test ", e); + e.printStackTrace(); + } + } + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/setup/DcaeConfiguration.java b/src/main/java/com/att/ecomp/dcae/ci/ui/setup/DcaeConfiguration.java new file mode 100644 index 0000000..2eee2b4 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/setup/DcaeConfiguration.java @@ -0,0 +1,48 @@ +package com.att.ecomp.dcae.ci.ui.setup; + +import org.openecomp.d2.ci.datatypes.Configuration; + +public class DcaeConfiguration extends Configuration { + + private String apiPath; + private String dcaeBeHost; + private String dcaeBePort; + private String ruleEditorUrl; + + + + public String getApiPath() { + return apiPath; + } + + public void setApiPath(String apiPath) { + this.apiPath = apiPath; + } + + public String getDcaeBeHost() { + return dcaeBeHost; + } + + public void setDcaeBeHost(String dcaeBeHost) { + this.dcaeBeHost = dcaeBeHost; + } + + public String getDcaeBePort() { + return dcaeBePort; + } + + public void setDcaeBePort(String dcaeBePort) { + this.dcaeBePort = dcaeBePort; + } + + public String getRuleEditorUrl() { + return ruleEditorUrl; + } + + public void setRuleEditorUrl(String ruleEditorUrl) { + this.ruleEditorUrl = ruleEditorUrl; + } + + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/tests/DCAESanity.java b/src/main/java/com/att/ecomp/dcae/ci/ui/tests/DCAESanity.java new file mode 100644 index 0000000..b7f2441 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/tests/DCAESanity.java @@ -0,0 +1,99 @@ +package com.att.ecomp.dcae.ci.ui.tests; + +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; +import org.openqa.selenium.WebElement; +import org.testng.annotations.Test; +import com.att.ecomp.dcae.ci.ui.pages.DCAECompositionPage; +import com.att.ecomp.dcae.ci.ui.pages.DCAEGeneralPage; +import com.att.ecomp.dcae.ci.ui.pages.DCAEHomePage; +import com.att.ecomp.dcae.ci.ui.pages.DCAELeftPanel; +import com.att.ecomp.dcae.ci.ui.pages.DCAEServicesPage; +import com.att.ecomp.dcae.ci.ui.pages.SDCCreateServicePage; +import com.att.ecomp.dcae.ci.ui.pages.SDCCreateVFPage; +import com.att.ecomp.dcae.ci.ui.pages.SDCHomePage; +import com.att.ecomp.dcae.ci.ui.setup.ConfigTest; +import com.att.ecomp.dcae.ci.ui.tests.verificator.ServiceVerificator; +import com.aventstack.extentreports.Status; + +public class DCAESanity extends ConfigTest{ + + @Override + protected UserRoleEnum getUserRole() { + // TODO Auto-generated method stub + return UserRoleEnum.DESIGNER; + } + + @Test (description = "DCAE Main scenario", groups={"Sanity"}) + public void sanityTestSDCSection() throws Exception + { + String vfName; + String serviceName; + + // ------------------ SDC-Side: Create VF -------------------------- + + System.out.println("Start Test"); + + SDCHomePage.clickOnAddVf(); + vfName = SDCCreateVFPage.addAllVFMandtoryFields("Utility"); //Creates VF, need to send only the desired category name + SDCCreateVFPage.clickOnCreateVFButton(); + SDCCreateVFPage.checkInVF(); + + // ------------------ SDC-Side: Create Service --------------------- + SDCHomePage.clickOnAddsService(); + serviceName = SDCCreateServicePage.addAllServiceMandtoryFields("Network L1-3"); + SDCCreateServicePage.clickOnCreateServiceButton(); + SDCCreateServicePage.clickOnServiceCompsitionTab(); + SDCCreateServicePage.addAssetToCanvas(vfName); + SDCCreateServicePage.checkInService(); + + // ------------------ DCAE-Side: Create Asset ------------------- + + DCAEHomePage.clickOnDcaeTab(); + DCAEHomePage.clickOnCreateNewAsset(); + + String assetName = DCAEGeneralPage.addAssetName("Asset Name"); + DCAEGeneralPage.addAssetDescription("Asset Description"); + DCAEGeneralPage.clickSaveAsset(); + + DCAELeftPanel.navigateToServices(); + + DCAEServicesPage.selectService(serviceName); + DCAEServicesPage.selectVNFI(vfName); + DCAEServicesPage.clickAttach(vfName); + + DCAELeftPanel.navigateToComposition(); + + WebElement item = DCAECompositionPage.expandList("Microservice"); + DCAECompositionPage.addItemFromList(item); + DCAECompositionPage.SelectFlowType("Syslog"); + DCAECompositionPage.clickSave(); + DCAECompositionPage.clickSubmit(); + + //------------------ Verify Blue Print + + SDCHomePage.clickOnHomeTab(); + SDCHomePage.searchForElement(serviceName); + SDCHomePage.clickOnElement(serviceName); + try + { + SDCCreateServicePage.clickOnServiceCompsitionTab(); + } + catch(Exception e) + { + GeneralUIUtils.getDriver().navigate().refresh(); + SDCCreateServicePage.clickOnServiceCompsitionTab(); + ExtentTestActions.log(Status.WARNING,"SDC UI known Bug - Blank page with text: {{getStatus()}}, the browser was refreshed to bypass this bug."); + } + + SDCCreateServicePage.clickOnElementInCanavs(); + SDCCreateServicePage.clickOnArtifactTab(); + ServiceVerificator.verifyBluePrintArtifactExist(assetName); + + ExtentTestActions.log(Status.INFO, "Test Ended."); + + System.out.println("End Test"); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/tests/SanityTest.java b/src/main/java/com/att/ecomp/dcae/ci/ui/tests/SanityTest.java new file mode 100644 index 0000000..a13a12e --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/tests/SanityTest.java @@ -0,0 +1,108 @@ +package com.att.ecomp.dcae.ci.ui.tests; + +import org.openecomp.d2.ci.datatypes.Configuration; +import org.openecomp.d2.ci.datatypes.UserCredentials; +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openqa.selenium.WebElement; +import org.testng.annotations.Test; +import com.att.ecomp.dcae.ci.ui.pages.DCAECompositionPage; +import com.att.ecomp.dcae.ci.ui.pages.DCAEGeneralPage; +import com.att.ecomp.dcae.ci.ui.pages.DCAEHomePage; +import com.att.ecomp.dcae.ci.ui.pages.DCAELeftPanel; +import com.att.ecomp.dcae.ci.ui.pages.DCAEServicesPage; +import com.att.ecomp.dcae.ci.ui.pages.SDCCreateServicePage; +import com.att.ecomp.dcae.ci.ui.pages.SDCCreateVFPage; +import com.att.ecomp.dcae.ci.ui.pages.SDCHomePage; +import com.att.ecomp.dcae.ci.ui.setup.ConfigTest; + +public class SanityTest extends ConfigTest{ + + + public Configuration configuration = ConfigTest.getConfiguration(); + + + @Override + protected UserRoleEnum getUserRole() { + return UserRoleEnum.DESIGNER; + } + + + // Only when running locally + @Override + public void navigateAndLogin(UserCredentials userCredentials) throws Exception { + + navigateToUrl(configuration.getUrl()); + } + + + @Test (description = "DCAE Main scenario", groups={"Sanity"}) + public void sanityTestDCAESection() throws InterruptedException{ + + //HomePage.clickOnDcaeTab(); // not needed on local + + + + + + + + ////------TO DELETE + String vfName; + String serviceName; + + // ------------------ SDC-Side: Create VF -------------------------- + + System.out.println("Start Test"); + + SDCCreateServicePage.clickOnElementInCanavs(); + + SDCHomePage.clickOnAddVf(); + vfName = SDCCreateVFPage.addAllVFMandtoryFields("Microservice"); //Creates VF, need to send only the desired category name + SDCCreateVFPage.clickOnCreateVFButton(); + SDCCreateVFPage.checkInVF(); + + // ------------------ SDC-Side: Create Service --------------------- + SDCHomePage.clickOnAddsService(); + serviceName = SDCCreateServicePage.addAllServiceMandtoryFields("Network L1-3"); + SDCCreateServicePage.clickOnCreateServiceButton(); + SDCCreateServicePage.clickOnServiceCompsitionTab(); + SDCCreateServicePage.addAssetToCanvas(vfName); + SDCCreateServicePage.checkInService(); + + + ////------TO DELETE + + + + + + + + + + + System.out.println("Start Test"); + + DCAEHomePage.clickOnCreateNewAsset(); + + DCAEGeneralPage.addAssetName("Asset Name"); + DCAEGeneralPage.addAssetDescription("Asset Description"); +// DCAEGeneralPage.clickSaveAsset(); + + DCAELeftPanel.navigateToServices(); + + DCAEServicesPage.selectService("Servicedbb463a1-50bb-4aef-b84c-8c2bb9a8f866"); + DCAEServicesPage.selectVNFI("VF30ca7676-35c5-4c3c-9cc8-a06c23b17872"); + DCAEServicesPage.clickAttach("VF30ca7676-35c5-4c3c-9cc8-a06c23b17872"); + + DCAELeftPanel.navigateToComposition(); + + WebElement item = DCAECompositionPage.expandList("Microservice"); + DCAECompositionPage.addItemFromList(item); + DCAECompositionPage.clickSave(); + DCAECompositionPage.clickSubmit(); + + System.out.println("End Test"); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/tests/ServiceTest.java b/src/main/java/com/att/ecomp/dcae/ci/ui/tests/ServiceTest.java new file mode 100644 index 0000000..bc99033 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/tests/ServiceTest.java @@ -0,0 +1,42 @@ +package com.att.ecomp.dcae.ci.ui.tests; + +import java.util.UUID; + +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; +import org.openqa.selenium.WebElement; +import org.testng.annotations.Test; + +import com.att.ecomp.dcae.ci.ui.pages.DCAEHomePage; +import com.att.ecomp.dcae.ci.ui.setup.ConfigTest; + +public class ServiceTest extends ConfigTest { + + @Override + protected UserRoleEnum getUserRole() { + return UserRoleEnum.DESIGNER; + } + + @Test + public void createServiceTest(){ + DCAEHomePage.clickOnDcaeTab(); + + GeneralUIUtils.hoverOnAreaByTestId("AddButtonsArea"); + GeneralUIUtils.findByText("Add Service Assurance Template").click(); + GeneralUIUtils.ultimateWait(); + + WebElement nameTextbox = GeneralUIUtils.getWebElementByTestID("name"); + nameTextbox.clear(); + nameTextbox.sendKeys("autoServicer" + UUID.randomUUID()); + + WebElement descriptionTextbox = GeneralUIUtils.getWebElementByTestID("description"); + descriptionTextbox.clear(); + descriptionTextbox.sendKeys("new service"); + + GeneralUIUtils.findByText("Create").click(); + GeneralUIUtils.ultimateWait(); + } + + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/tests/verificator/CompositionVerificator.java b/src/main/java/com/att/ecomp/dcae/ci/ui/tests/verificator/CompositionVerificator.java new file mode 100644 index 0000000..59faa2a --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/tests/verificator/CompositionVerificator.java @@ -0,0 +1,16 @@ +package com.att.ecomp.dcae.ci.ui.tests.verificator; + +import static org.testng.Assert.assertTrue; + +public class CompositionVerificator { + + public static void verifySaveSuccessfully(String actualSaveRes) + { + assertTrue(actualSaveRes.startsWith("Composition Created")); + } + + public static void verifySubmitSuccessfully(String actualSubmitRes) { + assertTrue(actualSubmitRes.equalsIgnoreCase("Blueprint Created")); + + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/tests/verificator/ServiceVerificator.java b/src/main/java/com/att/ecomp/dcae/ci/ui/tests/verificator/ServiceVerificator.java new file mode 100644 index 0000000..99957cf --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/tests/verificator/ServiceVerificator.java @@ -0,0 +1,22 @@ +package com.att.ecomp.dcae.ci.ui.tests.verificator; + +import org.openecomp.d2.ci.report.ExtentTestActions; +import org.openecomp.d2.ci.utilities.GeneralUIUtils; + +import com.aventstack.extentreports.Status; + +import static org.testng.Assert.assertTrue; + +public class ServiceVerificator +{ + public static void verifyBluePrintArtifactExist(String name) + { + ExtentTestActions.log(Status.INFO,"Verifying Blue Print artifact exist"); + String artifactName = "Foi" + "." + name.replaceAll("\\s+","").replaceAll("-", "") + ".event_proc_bp.yaml"; + GeneralUIUtils.waitForElementInVisibilityByTestId("artifactName-blueprint-foi"); + String actualBluePrintFileName = GeneralUIUtils.getWebElementByTestID("artifactName-blueprint-foi").getText(); + assertTrue(artifactName.equalsIgnoreCase(actualBluePrintFileName)); + ExtentTestActions.log(Status.INFO, String.format("Actual Blue print file name is: %s.", actualBluePrintFileName)); + GeneralUIUtils.ultimateWait(); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/utils/ByTest.java b/src/main/java/com/att/ecomp/dcae/ci/ui/utils/ByTest.java new file mode 100644 index 0000000..ab59b28 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/utils/ByTest.java @@ -0,0 +1,17 @@ +package com.att.ecomp.dcae.ci.ui.utils; + +import org.openqa.selenium.By.ByCssSelector; + +public class ByTest extends ByCssSelector { + + private static final long serialVersionUID = 7435597710732625685L; // auto generated - does nothing + + protected ByTest(String cssSelector) { + super(cssSelector); + } + + public static ByTest id(String id) { + return new ByTest(String.format("[data-tests-id=\"%s\"]", id)); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/utils/Locator.java b/src/main/java/com/att/ecomp/dcae/ci/ui/utils/Locator.java new file mode 100644 index 0000000..7e625d5 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/utils/Locator.java @@ -0,0 +1,74 @@ +package com.att.ecomp.dcae.ci.ui.utils; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; + +public class Locator { + + private WebElement element; + + private Locator(WebElement element) { + this.element = element; + } + + public static Locator from(WebElement element) { + return new Locator(element); + } + + public ExpectedCondition find(By by, int index) { + return new NestedFinder(this.element, by) { + @Override + protected WebElement predicate(List elements) { + return (elements.size() > index) ? elements.get(index) : null; + } + + @Override + public String toString() { + return "element located by " + by; + } + }; + } + + public ExpectedCondition findVisible(By by, int index) { + return new NestedFinder(this.element, by) { + @Override + protected WebElement predicate(List elements) { + return visibleElementsOrNull(elements, index); + } + + @Override + public String toString() { + return "visibility of element located by " + by; + } + }; + } + + public ExpectedCondition> findNoVisible(By by) { + return new NestedFilter(this.element, by) { + @Override + protected List predicate(List elements) { + WebElement visible = visibleElementsOrNull(elements, 0); + return (visible != null) ? null : new ArrayList(); + } + + @Override + public String toString() { + return "no visible elements located by " + by; + } + }; + } + + private static WebElement visibleElementsOrNull(List elements, int index) { + List visibles = elements.stream() + .filter(elem -> elem.isDisplayed()) + .collect(Collectors.toList()); + return (visibles.size() > index) ? visibles.get(index) : null; + } + + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/utils/NestedFilter.java b/src/main/java/com/att/ecomp/dcae/ci/ui/utils/NestedFilter.java new file mode 100644 index 0000000..925fea5 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/utils/NestedFilter.java @@ -0,0 +1,28 @@ +package com.att.ecomp.dcae.ci.ui.utils; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; + +public abstract class NestedFilter implements ExpectedCondition> { + + private WebElement parent; + private By by; + + public NestedFilter(WebElement parent, By by) { + this.parent = parent; + this.by = by; + } + + abstract protected List predicate(List elements); + + @Override + public List apply(WebDriver input) { + List elements = parent.findElements(by); + return predicate(elements); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/ui/utils/NestedFinder.java b/src/main/java/com/att/ecomp/dcae/ci/ui/utils/NestedFinder.java new file mode 100644 index 0000000..ead2bef --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/ui/utils/NestedFinder.java @@ -0,0 +1,28 @@ +package com.att.ecomp.dcae.ci.ui.utils; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; + +public abstract class NestedFinder implements ExpectedCondition { + + private WebElement parent; + private By by; + + public NestedFinder(WebElement parent, By by) { + this.parent = parent; + this.by = by; + } + + abstract protected WebElement predicate(List elements); + + @Override + public WebElement apply(WebDriver input) { + List elements = parent.findElements(by); + return predicate(elements); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/utilities/ConfigurationReader.java b/src/main/java/com/att/ecomp/dcae/ci/utilities/ConfigurationReader.java new file mode 100644 index 0000000..1736d9a --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/utilities/ConfigurationReader.java @@ -0,0 +1,41 @@ +package com.att.ecomp.dcae.ci.utilities; + +import java.io.File; + +import org.openecomp.d2.ci.datatypes.Configuration; + +import com.att.ecomp.dcae.ci.ui.setup.DcaeConfiguration; + +public class ConfigurationReader { + + private static DcaeConfiguration config; + + public static DcaeConfiguration getConfiguration() { + if (config == null){ + File file = getConfigFile(); + config = Configuration.loadConfigFile(file, DcaeConfiguration.class); + } + return config; + } + + public static File getConfigFile() { + String configFile = System.getProperty("config.resource"); + if (configFile == null){ + configFile = configurationFile(); + } + File file = new File(configFile); + if (false == file.exists()) { + throw new RuntimeException("The config file " + configFile + " cannot be found."); + } + return file; + } + + private static String configurationFile() { + return confPath() + File.separator + "conf.yaml"; + } + + public static String confPath() { + return System.getProperty("user.dir") + File.separator + "src" + File.separator + "main" + File.separator + "resources" + + File.separator + "conf" + File.separator ; + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeEntityClient.java b/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeEntityClient.java new file mode 100644 index 0000000..c2a401d --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeEntityClient.java @@ -0,0 +1,139 @@ +package com.att.ecomp.dcae.ci.utilities; + +import org.openecomp.d2.ci.datatypes.devObjects.LifecycleStateEnum; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.openecomp.d2.ci.report.ExtentTestActions; + +import com.aventstack.extentreports.Status; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.onap.sdc.dcae.composition.model.Requirement; +import org.onap.sdc.dcae.composition.model.Value; +import org.onap.sdc.dcae.composition.model.deserializer.RequirementDeserializer; +import org.onap.sdc.dcae.composition.model.deserializer.ValueDeserializer; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; + +public class DcaeEntityClient { + + protected Gson gson; + + public DcaeEntityClient() { + super(); + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(Requirement.class, new RequirementDeserializer()); + gsonBuilder.registerTypeAdapter(Value.class, new ValueDeserializer()); + gson = gsonBuilder.create(); + } + + /* VFCMT */ + + /** + * + * @param name + * @param description + * @param userId + * @return + * @throws Exception + */ + public Vfcmt createVfcmt(String name, String description, String userId) throws Exception { + RestResponse response = DcaeRestClient.createVfcmt(name, description, userId); + ExtentTestActions.log(Status.DEBUG, "Create VFCMT Response: " + StringUtils.truncate(response)); + if (response.getStatusCode() != 200) { + throw new Exception("Response: " + StringUtils.truncate(response)); + } + return gson.fromJson(response.getResponse(), Vfcmt.class); + } + + /** + * + * @param userId + * @return + * @throws Exception + */ + public Vfcmt createVfcmt(String userId) throws Exception { + String name = StringUtils.randomString("CI-", 20); + String description = "This vfcmt was created by automated ci tests"; + Vfcmt createVfcmt = createVfcmt(name, description, userId); + Report.log(Status.INFO, "createVfcmt result="+createVfcmt); + return createVfcmt; + } + + /** + * + * @return + * @throws Exception + */ + public Vfcmt createVfcmt() throws Exception { + return createVfcmt(DcaeRestClient.getDefaultUser().getUserId()); + } + + /** + * + * @return + * @throws Exception + */ + public Vfcmt[] getAllVfcmts() throws Exception { + ExtentTestActions.log(Status.INFO, "Fetching all vfcmt resources"); + RestResponse response = DcaeRestClient.getAllVfcmts(); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + if (response.getStatusCode() != 200) { + throw new Exception("Response: " + StringUtils.truncate(response)); + } + return gson.fromJson(response.getResponse(), Vfcmt[].class); + } + + /** + * + * @param userId + * @return + * @throws Exception + */ + public Vfcmt createCheckedoutVfcmt(String userId) throws Exception { + ExtentTestActions.log(Status.INFO, "Creating vfcmt..."); + Vfcmt vfcmt = createVfcmt(userId); + if (vfcmt.getLifecycleState().equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name()) == false) { + throw new Exception("created vfcmt is not in checkout state!"); + } + return vfcmt; + } + + /** + * + * @return + * @throws Exception + */ + public Vfcmt createCheckedoutVfcmt() throws Exception { + String userId = DcaeRestClient.getDefaultUser().getUserId(); + Report.log(Status.INFO, "Going to create checked out VFCMT with user="+userId); + return createCheckedoutVfcmt(userId); + } + + /** + * + * @param userId + * @return + * @throws Exception + */ + public Vfcmt createCheckedinVfcmt(String userId) throws Exception { + ExtentTestActions.log(Status.INFO, "Creating vfcmt"); + Vfcmt vfcmt = createVfcmt(userId); + ExtentTestActions.log(Status.INFO, "Checkin the vfcmt"); + RestResponse response = DcaeRestClient.checkinVfcmt(vfcmt.getUuid(), vfcmt.getLastUpdaterUserId()); + ExtentTestActions.log(Status.DEBUG, "Response: " + StringUtils.truncate(response)); + Vfcmt vfcmtAfterCheckin = gson.fromJson(response.getResponse(), Vfcmt.class); + if (response.getStatusCode() != 200) { + throw new Exception("Unable to checkin newly created vfcmt"); + } + return vfcmtAfterCheckin; + } + + /** + * + * @return + * @throws Exception + */ + public Vfcmt createCheckedinVfcmt() throws Exception { + String userId = DcaeRestClient.getDefaultUser().getUserId(); + return createCheckedinVfcmt(userId); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeRestClient.java b/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeRestClient.java new file mode 100644 index 0000000..a776d20 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeRestClient.java @@ -0,0 +1,247 @@ +package com.att.ecomp.dcae.ci.utilities; + +import com.att.ecomp.dcae.ci.ui.setup.DcaeConfiguration; +import com.aventstack.extentreports.Status; +import com.google.common.net.UrlEscapers; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import org.json.simple.JSONObject; +import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import org.openecomp.d2.ci.api.BaseRestUtils; +import org.openecomp.d2.ci.api.ElementFactory; +import org.openecomp.d2.ci.datatypes.User; +import org.openecomp.d2.ci.datatypes.UserRoleEnum; +import org.openecomp.d2.ci.datatypes.http.RestResponse; + +import java.io.IOException; + +public class DcaeRestClient extends BaseRestUtils { + + private static User defaultUser = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + + public static User getDefaultUser() { + return defaultUser; + } + + protected static String getApiUrl(String path) { + DcaeConfiguration configuration = ConfigurationReader.getConfiguration(); + + String dcaeBePort = configuration.getDcaeBePort(); + String dcaeBeHost = configuration.getDcaeBeHost(); + String apiPath = configuration.getApiPath(); + if(System.getProperty("dcaeBeHost")!=null){ + dcaeBeHost = System.getProperty("dcaeBeHost"); + System.out.println("dcaeBeHost was configured via system property: "+dcaeBeHost); + } + if(System.getProperty("dcaeBePort")!=null){ + dcaeBePort = System.getProperty("dcaeBePort"); + System.out.println("dcaeBePort was configured via system property: "+dcaeBePort); + } + if(System.getProperty("apiPath")!=null){ + apiPath = System.getProperty("apiPath"); + System.out.println("apiPath was configured via system property: "+apiPath); + } + + return String.format("%s:%s%s%s", dcaeBeHost, dcaeBePort, apiPath, path); + } + + /* HealthCheck */ + + public static RestResponse getHealthcheck() throws IOException { + return sendGet(getApiUrl("/healthCheck"), null); + } + + /* VFCMT */ + + public static RestResponse getAllVfcmts() throws IOException { + return sendGet(getApiUrl("/getResourcesByCategory"), defaultUser.getUserId()); + } + + public static RestResponse getAllMonitoringTemplatesVfcmts() throws IOException { + return sendGet(getApiUrl("/getResourcesByMonitoringTemplateCategory"), defaultUser.getUserId()); + } + + public static RestResponse getVfcmtsForMigration(String contextType,String serviceUuid, String serviceVersion) throws IOException{ + + return sendGet(getApiUrl("/" + contextType + "/" + serviceUuid + "/" + serviceVersion + "/getVfcmtsForMigration"), defaultUser.getUserId()); + } + + public static RestResponse createVfcmt(String name, String description, String userId) throws IOException { + JSONObject newVfcmtJSON = newVfcmtJSON(name, description); + return sendPost(getApiUrl("/createVFCMT"), newVfcmtJSON.toString(), userId, "application/json"); + } + + public static RestResponse createMc(String request) throws IOException { + return sendPost(getApiUrl("/createMC"), request, defaultUser.getUserId(), "application/json"); + } + + public static RestResponse createMc(String request,String userId) throws IOException { + return sendPost(getApiUrl("/createMC"), request, userId, "application/json"); + } + + public static RestResponse createVfcmt(String name, String description) throws IOException{ + return createVfcmt(name, description, defaultUser.getUserId()); + } + + public static RestResponse importMc(String request) throws IOException { + return sendPost(getApiUrl("/importMC"), request, defaultUser.getUserId(), "application/json"); + } + + public static RestResponse getAttachedService(String vfcmtUuid) throws IOException { + Report.log(Status.INFO, "getAttachedService for VFCMT uuid="+vfcmtUuid); + RestResponse res = sendGet(getApiUrl("/" + vfcmtUuid + "/attachment"), defaultUser.getUserId()); + Report.log(Status.INFO, "getAttachedService result=%s", res); + return res; + } + + public static RestResponse getServiceExternalReferences(String serviceUuid, String version) throws IOException { + Report.log(Status.INFO, "getServiceExternalReferences for service uuid="+serviceUuid); + RestResponse res = sendGet(getApiUrl("/services/" + serviceUuid + "/" + version + "/monitoringComponents"), defaultUser.getUserId()); + Report.log(Status.INFO, "getServiceExternalReferences result=%s", res); + return res; + } + + /* VF */ + + public static RestResponse getServices(String VFCMTId, String userId) throws IOException{ + return sendGet(getApiUrl("/services/"+VFCMTId), userId); + } + + public static RestResponse getServicesInstance(String uuid) throws IOException{ + return sendGet(getApiUrl("/service/"+uuid), defaultUser.getUserId()); + } + + public static RestResponse attachVfiRef(String vfcmtUuid, String serviceId, String vfiName) throws IOException{ + Report.log(Status.INFO, "attachVfiRef start"); + JSONObject jsonAttachObj = new JSONObject(); + jsonAttachObj.put("serviceUuid", serviceId); + jsonAttachObj.put("instanceName", vfiName); + + return sendPost(getApiUrl("/" + vfcmtUuid + "/attachment"), jsonAttachObj.toString(), defaultUser.getUserId(), "application/json"); + } + + public static RestResponse getResourceDetails(String componentId) throws IOException{ + return sendGet(getApiUrl("/resource/"+ componentId), defaultUser.getUserId()); + } + + + public static RestResponse getElements() throws IOException{ + return sendGet(getApiUrl("/elements"), defaultUser.getUserId()); + } + public static RestResponse getItem(String element) throws IOException{ + return sendGet(getApiUrl("/"+ element +"/elements"), defaultUser.getUserId()); + } + public static RestResponse getItemModel(String elementId) throws IOException{ + return sendGet(getApiUrl("/"+ elementId +"/model"), defaultUser.getUserId()); + } + public static RestResponse getItemType(String elementId, String type) throws IOException{ + return sendGet(getApiUrl("/"+ elementId +"/type/"+ type +"/"), defaultUser.getUserId()); + } + public static RestResponse saveComposition(String componentId, String userId) throws IOException{ + JsonObject json = generateCdumpInput(componentId); + return saveComposition(componentId, userId, json.toString()); + } + + // edit composition new flow - service context + public static RestResponse saveComposition(String serviceUuid, String vfiName, String vfcmtUuid, String body) throws IOException{ + return sendPost(getApiUrl(String.format("/services/%s/%s/saveComposition/%s", serviceUuid, UrlEscapers.urlFragmentEscaper().escape(vfiName), vfcmtUuid)), body, defaultUser.getUserId(), "application/json"); + } + + // submit composition new flow - service context + public static RestResponse submitComposition(String serviceUuid, String vfiName, String vfcmtUuid) throws IOException { + return sendPost(getApiUrl(String.format("/services/createBluePrint/%s/%s/%s", vfcmtUuid, serviceUuid, UrlEscapers.urlFragmentEscaper().escape(vfiName))), "", defaultUser.getUserId(), "application/json"); + } + + public static RestResponse saveComposition(String componentId, String userId, String body) throws IOException{ + return sendPost(getApiUrl("/saveComposition/"+componentId), body, userId, "application/json"); + } + + public static RestResponse getComposition(String componentId) throws IOException{ + return sendGet(getApiUrl("/getComposition/"+ componentId), defaultUser.getUserId()); + } + public static RestResponse submitComposition(String componentId, String serviceUuid, String vnfiName, String monitoringType) throws IOException{ + return sendPost(getApiUrl("/createBluePrint/"+ componentId +"/"+ serviceUuid +"/"+ UrlEscapers.urlFragmentEscaper().escape(vnfiName) + "/"+ UrlEscapers.urlFragmentEscaper().escape(monitoringType)), "" ,defaultUser.getUserId(), "application/json"); + } + + /* Life Cycle */ + + public static RestResponse checkinVfcmt(String vfcmtUuid, String userId) throws IOException { + return checkinGeneral("vfcmt", vfcmtUuid, userId); + } + + public static RestResponse checkinGeneral(String assetType, String vfcmtUuid, String userId) throws IOException { + return sendPut(getApiUrl(String.format("/checkin/%s/%s", assetType, vfcmtUuid)), null, userId, null); + } + + public static RestResponse checkoutVfcmt(String vfcmtUuid, String userId) throws IOException { + return checkoutGeneral("vfcmt", vfcmtUuid, userId); + } + + private static RestResponse checkoutGeneral(String assetType, String vfcmtUuid, String userId) throws IOException { + return sendPut(getApiUrl(String.format("/checkout/%s/%s", assetType, vfcmtUuid)), null, userId, null); + } + + public static RestResponse certifyVfcmt(String vfcmtUuid, String userId) throws IOException { + return sendPut(getApiUrl(String.format("/certify/vfcmt/%s", vfcmtUuid)), null, userId, null); + } + + /* Rule Editor */ + + public static RestResponse getVesEventTypes() throws IOException { + return sendGet(getApiUrl("/rule-editor/list-events-by-versions"), defaultUser.getUserId()); + } + + public static RestResponse getVesDataTypes(String vesVersion, String eventType) throws IOException { + return sendGet(getApiUrl(String.format("/rule-editor/definition/%s/%s", vesVersion, eventType)), defaultUser.getUserId()); + } + + public static RestResponse saveRule(String vfcmtUid, String dcaeCompName, String nid, String configParam, String body) throws IOException { + return sendPost(getApiUrl(String.format("/rule-editor/rule/%s/%s/%s/%s", vfcmtUid, dcaeCompName, nid, configParam)), body, defaultUser.getUserId(), "application/json" ); + } + + public static RestResponse getRules(String vfcmtUid, String dcaeCompName, String nid, String configParam) throws IOException { + return sendGet(getApiUrl(String.format("/rule-editor/rule/%s/%s/%s/%s", vfcmtUid, dcaeCompName, nid, configParam)), defaultUser.getUserId()); + } + + public static RestResponse deleteRule(String vfcmtUid, String dcaeCompName, String nid, String configParam, String ruleUid) throws IOException { + return sendDelete(getApiUrl(String.format("/rule-editor/rule/%s/%s/%s/%s/%s", vfcmtUid, dcaeCompName, nid, configParam, ruleUid)), defaultUser.getUserId()); + } + + public static RestResponse translateRules(String vfcmtUid, String dcaeCompName, String nid, String configParam, String flowType) throws IOException { + return sendGet(getApiUrl(String.format("/rule-editor/rule/translate/%s/%s/%s/%s?flowType=%s", vfcmtUid, dcaeCompName, nid, configParam, flowType)), defaultUser.getUserId()); + } + + + private static JSONObject newVfcmtJSON(String name, String description) { + JSONObject json = new JSONObject(); + json.put("name", name); + json.put("description", description); + return json; + } + + public static void fillCreateMcRequestMandatoryFields(T request) { + request.setFlowType("flowType_xxx"); + request.setContextType("services"); + request.setName(StringUtils.randomString("CI-", 20)); + request.setDescription("create test vfcmt"); + if(null == request.getVfiName()) { + request.setVfiName("whatsInAName"); + } + if(null == request.getServiceUuid()) { + request.setServiceUuid("service5659860"); + } + } + + public static JsonObject generateCdumpInput(String componentId) { + JsonObject json = new JsonObject(); + json.addProperty("cid", componentId); + json.addProperty("version", 0); + json.add("nodes", new JsonArray()); + json.add("relations", new JsonArray()); + json.add("inputs", new JsonArray()); + json.add("outputs", new JsonArray()); + return json; + + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeTestConstants.java b/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeTestConstants.java new file mode 100644 index 0000000..355a687 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeTestConstants.java @@ -0,0 +1,19 @@ +package com.att.ecomp.dcae.ci.utilities; + +public class DcaeTestConstants { + + public class Composition{ + public static final String Microservice = "Microservice"; + public static final String EMPTY_OBJECT = "{}"; + } + + public class Sdc{ + public class State{ + public static final String NOT_CERTIFIED_CHECKOUT = "NOT_CERTIFIED_CHECKOUT"; + public static final String NOT_CERTIFIED_CHECKIN = "NOT_CERTIFIED_CHECKIN"; + public static final String CONFLICT = "Conflict"; + public static final String CERTIFIED = "CERTIFIED"; + + } + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeUtil.java b/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeUtil.java new file mode 100644 index 0000000..9999b3d --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/utilities/DcaeUtil.java @@ -0,0 +1,200 @@ +package com.att.ecomp.dcae.ci.utilities; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import com.google.gson.*; +import org.apache.commons.lang3.RandomStringUtils; + +import org.json.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.ParseException; +import org.openecomp.d2.ci.datatypes.http.RestResponse; +import org.testng.Assert; + +import com.att.ecomp.dcae.ci.entities.composition.items.DcaeComponents; +import org.onap.sdc.dcae.composition.services.Resource; +import org.onap.sdc.dcae.composition.services.Service; +import org.onap.sdc.dcae.composition.services.ThinService; +import org.onap.sdc.dcae.composition.vfcmt.Vfcmt; +import com.aventstack.extentreports.Status; + + +public class DcaeUtil { + public static Gson gson = new Gson(); + + public static class CatalogReources { + public static Vfcmt[] getAllReourcesFromAsdc() throws IOException{ + RestResponse allResources = DcaeRestClient.getAllVfcmts(); + return gson.fromJson(allResources.getResponse(), Vfcmt[].class); + } + + public static Vfcmt getResourceByName(String resName) throws IOException{ + Vfcmt[] vfcmts = getAllReourcesFromAsdc(); + List vfcmtsStr = Arrays.stream(vfcmts). + filter(item -> item.getName().equals(resName)). + collect(Collectors.toList()); + + return vfcmtsStr.get(0); + } + + public static Vfcmt getOneResourceFromList(int index) throws IOException{ + Vfcmt[] vfcmtList = getAllReourcesFromAsdc(); + return vfcmtList[index]; + } + + public static String getComponentID(int index) throws IOException{ + Vfcmt vfcmt = getOneResourceFromList(0); + return vfcmt.getUuid(); + } + + public static Resource createNewVfcmtObject() throws IOException{ + Resource res = new Resource(); + res.setResourceInstanceName("LiavNewVFCMT" + RandomStringUtils.randomAlphanumeric(20)); + res.setDescription("This is a test VFCMT"); + return res; + } + + public static Vfcmt notCheckoutVFCMT() throws IOException{ /* TODO: remove this function and use instead in DcaeEntityClient.getCheckedoutVfcmt() */ + Vfcmt[] vfcmtList = getAllReourcesFromAsdc(); + List vfcmtsStr = Arrays.stream(vfcmtList). + filter(item -> (item.getLifecycleState().equals(DcaeTestConstants.Sdc.State.NOT_CERTIFIED_CHECKOUT) == false)). + collect(Collectors.toList()); + + return vfcmtsStr.get(0); + } + + public static Vfcmt vfcmtNotUserOwner(String user) throws IOException{ + Vfcmt[] vfcmtList = getAllReourcesFromAsdc(); + List vfcmtsStr = Arrays.stream(vfcmtList) + .filter(item -> (item.getLastUpdaterUserId().equals(user) == false)) + .collect(Collectors.toList()); + + return vfcmtsStr.get(0); + } + + } + + public static class Services{ + public static ThinService[] getServices(String VFCMTId, String userId) throws IOException{ + RestResponse services = null; + try{ + services = DcaeRestClient.getServices(VFCMTId, userId); + }catch(Exception e){ + System.err.println("Exception occurred while trying to fetch all resources from SDC: "+e); + return null; + } + Assert.assertTrue(services.getStatusCode().intValue() == 200); + String response = services.getResponse(); + ThinService[] serviceList = gson.fromJson(response, ThinService[].class); + return serviceList.length > 0 ? serviceList : null; + } + + public static ThinService getOneService(String VFCMTId,int index, String userId) throws IOException { + ThinService[] services = getServices(VFCMTId, userId); + return services[index]; + } + + + public static List getVfListInstance(ThinService thinService) throws IOException { + RestResponse serviceInstancRes = null; + try{ + serviceInstancRes = DcaeRestClient.getServicesInstance(thinService.getUuid()); + }catch(Exception e){ + System.err.println("Exception occurred while trying to fetch List of VF instances from SDC service ("+thinService+"). Exception: "+e); + return null; + } + Assert.assertTrue(serviceInstancRes.getStatusCode().intValue() == 200); + String serviceInstancList = serviceInstancRes.getResponse(); + Service service = gson.fromJson(serviceInstancList, Service.class); + return service.getResources(); + } + + public static Resource getOneVfInstance(ThinService thinService,int index) throws IOException { + List resources = getVfListInstance(thinService); + return resources.get(index); + } + + } + + + public static class SdcElementsModelType{ + public static RestResponse getMsElements() throws IOException{ + return DcaeRestClient.getItem(DcaeTestConstants.Composition.Microservice); + } + + + + public static JsonArray getSNMPModelItemFromSdc() throws Exception{ + RestResponse resMsElements = getMsElements(); + JsonParser jsonParser = new JsonParser(); + JsonObject responseJson = (JsonObject)jsonParser.parse(resMsElements.getResponse()); + JsonArray itemJsonArray = responseJson.get("data").getAsJsonObject().get("element").getAsJsonObject().get("items").getAsJsonArray(); + Report.logDebug("DCAE Components items", itemJsonArray); + Service[] services = gson.fromJson(itemJsonArray, Service[].class); + Report.log(Status.DEBUG, "Trying to find a certified VF which its name starts with supplement/map/enrich"); + List collectIds = Arrays.stream(services) + .filter(x -> x.getLifecycleState().equals("CERTIFIED") && x.getModels().size() > 0 && (x.getName().startsWith("supplement") || x.getName().startsWith("map") || x.getName().startsWith("enrich"))) + .map(Service::getUuid) + .collect(Collectors.toList()); + if(collectIds==null || collectIds.size()==0){ + Report.log(Status.ERROR, "Could find any SNMP DCAE Component"); + } + JsonArray models = new JsonArray(); + for (String id : collectIds) { + RestResponse res = DcaeRestClient.getItemModel(id); + models.addAll(parseNodesFromDcaeModelAndAssignUiNid(res.getResponse())); + } + + return models; + } + + public static RestResponse getItemModelFromSdc(int itemNumber) throws IOException{ + String uuid = getItemUuid(itemNumber); + return DcaeRestClient.getItemModel(uuid); + } + + public static String getItemUuid(int itemNumber) throws IOException{ + DcaeComponents dcaeComponents = getDcaeComponents(); + return dcaeComponents.getData().getElement().getItems().get(itemNumber).getUuid(); + } + + public static DcaeComponents getDcaeComponents() throws IOException{ + RestResponse services = getMsElements(); + String response = services.getResponse(); + return gson.fromJson(response, DcaeComponents.class); + } + } + + public static JsonArray parseNodesFromDcaeModelAndAssignUiNid(String response) throws ParseException { + JsonParser parser = new JsonParser(); + JsonObject data = parser.parse(response).getAsJsonObject().get("data").getAsJsonObject(); + JsonObject model = data.get("model").getAsJsonObject(); + JsonArray nodes = model.get("nodes").getAsJsonArray(); + nodes.forEach((n) -> + n.getAsJsonObject().add("nid", n.getAsJsonObject().get("name")) + ); + Report.logDebug("nodes after adding ui nid", nodes); + return nodes; + } + + public static String generateCdumpFromSnmpModels(String vfcmtId) throws Exception { + JsonArray snmpModelItemFromSdc = SdcElementsModelType.getSNMPModelItemFromSdc(); + JsonObject cdump = DcaeRestClient.generateCdumpInput(vfcmtId); + cdump.add("nodes", snmpModelItemFromSdc); + Report.logDebug("cdump", cdump); + return cdump.toString(); + } + + + + /* private JSONObject getServiceInstance(JSONObject service) throws IOException { + RestResponse serviceInstancRes = DcaeRestClient.getServicesInstance(service.get("uuid").toString()); + Assert.assertTrue(serviceInstancRes.getStatusCode().intValue() == 200); + String serviceInstancList = serviceInstancRes.getResponse(); + return (JSONObject) JSONValue.parse(serviceInstancList); +}*/ + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/utilities/Report.java b/src/main/java/com/att/ecomp/dcae/ci/utilities/Report.java new file mode 100644 index 0000000..f2fe6fb --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/utilities/Report.java @@ -0,0 +1,26 @@ +package com.att.ecomp.dcae.ci.utilities; + +import org.openecomp.d2.ci.report.ExtentTestActions; + +import com.aventstack.extentreports.Status; + +public class Report { + + public static void log(Status status, String format, Object... args) { + ExtentTestActions.log(status, String.format(format, args)); + } + + public static void logDebug(String message, Object obj) { + log(Status.DEBUG, "%s %s", message, wrapWithTextareaRO(obj.toString())); + } + + public static void fatal(String message, Exception err) { + log(Status.FATAL, "%s %s", message, wrapWithTextareaRO(err.toString())); + } + + /* Private members */ + + private static String wrapWithTextareaRO(String str) { + return String.format("", str); + } +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/utilities/SdcInternalApiClient.java b/src/main/java/com/att/ecomp/dcae/ci/utilities/SdcInternalApiClient.java new file mode 100644 index 0000000..4adade1 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/utilities/SdcInternalApiClient.java @@ -0,0 +1,131 @@ +package com.att.ecomp.dcae.ci.utilities; + +import com.att.ecomp.dcae.ci.entities.composition.services.Vfi; +import com.att.ecomp.dcae.ci.entities.sdc.SdcComponent; +import com.att.ecomp.dcae.ci.entities.sdc.SdcComponentMetadata; +import com.att.ecomp.dcae.ci.ui.setup.DcaeConfiguration; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import org.openecomp.d2.ci.api.BaseRestUtils; +import org.openecomp.d2.ci.api.ElementFactory; +import org.openecomp.d2.ci.api.ServiceRestUtils; +import org.openecomp.d2.ci.api.VfRestUtils; +import org.openecomp.d2.ci.datatypes.*; +import org.openecomp.d2.ci.datatypes.http.RestResponse; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SdcInternalApiClient extends BaseRestUtils { + + private static Gson gson = (new GsonBuilder()).create(); + private static User defaultUser = DcaeRestClient.getDefaultUser(); + + /** + * + * @return + * @throws Exception + */ + public static ServiceReqDetails createService() throws Exception { + ServiceReqDetails defaultService = ElementFactory.getDefaultService(); + RestResponse response = ServiceRestUtils.createService(defaultService, defaultUser); + Report.logDebug("Response:", response); + if (response.getStatusCode() != 201) { + throw new Exception("Unable to create service.\nResponse: " + response.toString()); + } + return gson.fromJson(response.getResponse(), ServiceReqDetails.class); + } + + /** + * + * @return + * @throws Exception + */ + public static ResourceReqDetails createVf() throws Exception { + ResourceReqDetails defaultVf = ElementFactory.getDefaultResource(ResourceTypeEnum.VF); + RestResponse response = VfRestUtils.createResource(defaultVf, defaultUser); + Report.logDebug("Response:", response); + if (response.getStatusCode() != 201) { + throw new Exception("Unable to create vf.\nResponse: " + response.toString()); + } + return gson.fromJson(response.getResponse(), ResourceReqDetails.class); + } + + /** + * + * @param vf + * @return + * @throws Exception + */ + public static ResourceReqDetails checkinVf(ResourceReqDetails vf) throws Exception { + RestResponse response = VfRestUtils.changeResourceState(vf, defaultUser, LifeCycleStatesEnum.CHECKIN); + Report.logDebug("Response:", response); + if (response.getStatusCode() != 200) { + throw new Exception("Unable to checkin vf.\nResponse: " + response.toString()); + } + return gson.fromJson(response.getResponse(), ResourceReqDetails.class); + } + + /** + * + * @param service + * @param vf + * @return + * @throws Exception + */ + public static Vfi createVfi(ServiceReqDetails service, ResourceReqDetails vf) throws Exception { + RestResponse response = ServiceRestUtils.createComponentInstance(service, vf, defaultUser, ComponentTypeEnum.RESOURCE, true); + Report.logDebug("Response:", response); + if (response.getStatusCode() != 201) { + throw new Exception("Unable to create vfi.\nResponse: " + response.toString()); + } + try { + JsonObject resBody = new JsonParser().parse(response.getResponse()).getAsJsonObject(); + String vfiName = resBody.get("name").getAsString(); + return new Vfi(vfiName, service); + } catch (Exception err) { + throw new Exception(String.format("Unable to parse vfi name\nResponse: %s\n", response), err); + } + } + + // DELETE - Clean up // + + public static RestResponse deleteAssetFromSdc(String context, String uniqueId) throws IOException { + DcaeConfiguration configuration = ConfigurationReader.getConfiguration(); + String url = String.format("%s:%s/sdc2/rest/v1/catalog/%s/%s", configuration.getBeHost(), configuration.getBePort(), context, uniqueId); + return sendDelete(url, ElementFactory.getDefaultUser(UserRoleEnum.ADMIN).getUserId()); + } + + public static RestResponse deleteMarkedResources() throws IOException { + DcaeConfiguration configuration = ConfigurationReader.getConfiguration(); + String url = String.format("%s:%s/sdc2/rest/v1/inactiveComponents/resource", configuration.getBeHost(), configuration.getBePort()); + return sendDelete(url, ElementFactory.getDefaultUser(UserRoleEnum.ADMIN).getUserId()); + } + + public static RestResponse deleteMarkedServices() throws IOException { + DcaeConfiguration configuration = ConfigurationReader.getConfiguration(); + String url = String.format("%s:%s/sdc2/rest/v1/inactiveComponents/service", configuration.getBeHost(), configuration.getBePort()); + return sendDelete(url, ElementFactory.getDefaultUser(UserRoleEnum.ADMIN).getUserId()); + } + + public static Map> getAssetsByUser(String userId) throws IOException { + DcaeConfiguration configuration = ConfigurationReader.getConfiguration(); + String url = String.format("%s:%s/sdc2/rest/v1/followed", configuration.getBeHost(), configuration.getBePort()); + RestResponse restResponse = sendGet(url, userId); + return 200 == restResponse.getStatusCode() ? gson.fromJson(restResponse.getResponse(), new TypeToken>>(){}.getType()) : new HashMap<>(); + } + + + public static SdcComponentMetadata getAssetMetadata(String context, String uniqueId, String userId) throws IOException { + DcaeConfiguration configuration = ConfigurationReader.getConfiguration(); + String url = String.format("%s:%s/sdc2/rest/v1/catalog/%s/%s/filteredDataByParams?include=metadata", configuration.getBeHost(), configuration.getBePort(), context, uniqueId); + RestResponse restResponse = sendGet(url, userId); + return gson.fromJson(restResponse.getResponse(), SdcComponentMetadata.class); + } + +} diff --git a/src/main/java/com/att/ecomp/dcae/ci/utilities/StringUtils.java b/src/main/java/com/att/ecomp/dcae/ci/utilities/StringUtils.java new file mode 100644 index 0000000..90c5602 --- /dev/null +++ b/src/main/java/com/att/ecomp/dcae/ci/utilities/StringUtils.java @@ -0,0 +1,16 @@ +package com.att.ecomp.dcae.ci.utilities; + +import org.apache.commons.lang3.RandomStringUtils; + +import com.google.common.base.Ascii; + +public class StringUtils { + + public static String randomString(String prefix, int length) { + return prefix + RandomStringUtils.randomAlphanumeric(length - prefix.length()); + } + + public static String truncate(Object obj) { + return Ascii.truncate(obj.toString(), 160, "..."); + } +} diff --git a/src/main/resources/conf/conf.yaml b/src/main/resources/conf/conf.yaml new file mode 100644 index 0000000..41a7d82 --- /dev/null +++ b/src/main/resources/conf/conf.yaml @@ -0,0 +1,28 @@ +dcaeBeHost: http://localhost +dcaeBePort: 8080 +#dcaeBePort: 8446 --> [in local PC testing] 8080 --> [in remote CI] +beHost: https://zldcrdm2sdc4cbe01.3f1a87.rdm2.tci.att.com +bePort: 8443 +feHost: 127.0.0.1 +fePort: 8181 +ruleEditorUrl: http://localhost:4200 +#apiPath: "/dcae" --> [in local PC testing] +apiPath: "" +url: https://www.e-access.att.com/DCAE-CIO1/sdc1/portal +remoteTestingMachineIP: null +remoteTestingMachinePort: 88 +remoteTesting: false +browser: null +systemUnderDebug: null +reportDBhost: null +reportDBport: 88 +captureTraffic: false +useBrowserMobProxy: false +stopOnClassFailure: null +reportFileName: UI_Extent_Report.html +reportFolder: ./ExtentReport/ +numOfAttemptsToRefresh: 22 +rerun: false +windowsDownloadDirectory: null +screenshotFolder: ./ExtentReport/screenshots/ +harFilesFolder: ./ExtentReport/har_files/ \ No newline at end of file diff --git a/src/main/resources/conf/credentials.yaml b/src/main/resources/conf/credentials.yaml new file mode 100644 index 0000000..481b12b --- /dev/null +++ b/src/main/resources/conf/credentials.yaml @@ -0,0 +1,48 @@ + designer: { + username: m08740, + password: 272v!suAL37, + firstname: ASDC, + lastname: VITI + } + admin: { + username: m08741, + password: 863B@rroN27, + firstname: ASDC, + lastname: VITI + } + ops: { + username: m08742, + password: 364K!NDRed63, + firstname: ASDC, + lastname: VITI + } + tester: { + username: m08743, + password: 373m@rBLE28, + firstname: ASDC, + lastname: VITI + } + governor: { + username: m08744, + password: 742M!DDLE44, + firstname: ASDC, + lastname: VITI + } + product_strategist1: { + username: m08745, + password: 824S@Nder35, + firstname: ASDC, + lastname: VITI + } + product_manager1: { + username: m08746, + password: 747ICK!Y99, + firstname: ASDC, + lastname: VITI + } + product_local: { + username: m08747, + password: 623z!Ggy75, + firstname: ASDC, + lastname: VITI + } \ No newline at end of file diff --git a/src/main/resources/conf/credentials.yaml_prod b/src/main/resources/conf/credentials.yaml_prod new file mode 100644 index 0000000..481b12b --- /dev/null +++ b/src/main/resources/conf/credentials.yaml_prod @@ -0,0 +1,48 @@ + designer: { + username: m08740, + password: 272v!suAL37, + firstname: ASDC, + lastname: VITI + } + admin: { + username: m08741, + password: 863B@rroN27, + firstname: ASDC, + lastname: VITI + } + ops: { + username: m08742, + password: 364K!NDRed63, + firstname: ASDC, + lastname: VITI + } + tester: { + username: m08743, + password: 373m@rBLE28, + firstname: ASDC, + lastname: VITI + } + governor: { + username: m08744, + password: 742M!DDLE44, + firstname: ASDC, + lastname: VITI + } + product_strategist1: { + username: m08745, + password: 824S@Nder35, + firstname: ASDC, + lastname: VITI + } + product_manager1: { + username: m08746, + password: 747ICK!Y99, + firstname: ASDC, + lastname: VITI + } + product_local: { + username: m08747, + password: 623z!Ggy75, + firstname: ASDC, + lastname: VITI + } \ No newline at end of file diff --git a/src/main/resources/conf/credentials.yaml_webtest b/src/main/resources/conf/credentials.yaml_webtest new file mode 100644 index 0000000..ab37f7b --- /dev/null +++ b/src/main/resources/conf/credentials.yaml_webtest @@ -0,0 +1,48 @@ + designer: { + username: cs0008, + password: 123123a, + firstname: ASDC, + lastname: KASPIN + } + admin: { + username: jh0003, + password: 123123a, + firstname: ASDC, + lastname: KASPIN + } + ops: { + username: af0006, + password: 123123a, + firstname: ASDC, + lastname: KASPIN + } + tester: { + username: kb0004, + password: 123123a, + firstname: ASDC, + lastname: KASPIN + } + governor: { + username: ah0002, + password: 123123a, + firstname: ASDC, + lastname: KASPIN + } + product_strategist: { + username: m99126, + password: 1910-FruitGum, + firstname: ASDC, + lastname: KASPIN + } + product_manager: { + username: m99127, + password: 747-Airplane, + firstname: ASDC, + lastname: KASPIN + } + product_local: { + username: pm0001, + password: 123123a, + firstname: ASDC, + lastname: KASPIN + } \ No newline at end of file diff --git a/src/main/resources/conf/dcae_tests_conf.yaml.erb b/src/main/resources/conf/dcae_tests_conf.yaml.erb new file mode 100644 index 0000000..46784ba --- /dev/null +++ b/src/main/resources/conf/dcae_tests_conf.yaml.erb @@ -0,0 +1,28 @@ +dcaeBeHost: <%= @protocol %>://<%= @catalogbe_ip %> +dcaeBePort: <%= @catalogbe_port %> +beHost: <%= @protocol %>://<%= @catalogbe_ip %> +bePort: <%= @catalogbe_port %> +feHost: <%= @protocol %>://<%= @catalogfe_ip %> +fePort: <%= @catalogfe_port %> +apiPath: "/dcae" +url: <%= @url %> +remoteTestingMachineIP: null +remoteTestingMachinePort: 88 +remoteTesting: false +browser: null +systemUnderDebug: null +reportDBhost: null +reportDBport: 88 +captureTraffic: false +useBrowserMobProxy: false +stopOnClassFailure: null +reportFileName: UI_Extent_Report.html +reportFolder: ./ExtentReport/ +numOfAttemptsToRefresh: 22 +rerun: false +windowsDownloadDirectory: null +screenshotFolder: ./ExtentReport/screenshots/ +harFilesFolder: ./ExtentReport/har_files/ +ruleEditorUrl: <%= @url %>/../../rule_engine + + diff --git a/src/main/resources/conf/log4j.properties b/src/main/resources/conf/log4j.properties new file mode 100644 index 0000000..bef72a9 --- /dev/null +++ b/src/main/resources/conf/log4j.properties @@ -0,0 +1,34 @@ +# Define the root logger with appender file +log4j.rootLogger = DEBUG, FILE, stdout + +# Define the file appender +log4j.appender.FILE=org.apache.log4j.RollingFileAppender +log4j.appender.FILE.File=${targetlog}logs/ci-log.out + +# Define the layout for file appender +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p [%10c] : %m%n + +# Set the maximum file size before rollover +log4j.appender.FILE.maxFileSize=5MB + +# Set the the backup index +log4j.appender.FILE.maxBackupIndex=10 + + +############################################################# + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +#log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p %10c:%L - %m%n + +log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG +log4j.logger.com.thinkaurelius.titan.diskstorage.cassandra.CassandraTransaction=INFO, FILE, stdout + +log4j.logger.org.onap.sdc.ci.tests.utils=TRACE, FILE, stdout +log4j.additivity.org.onap.sdc.ci.tests.utils=false + + diff --git a/src/main/resources/scripts/run.sh b/src/main/resources/scripts/run.sh new file mode 100644 index 0000000..b262832 --- /dev/null +++ b/src/main/resources/scripts/run.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +function help_usage () +{ + echo + echo "$0 ( )" + echo + exit 2 +} + +function isBoolean () +{ + PARAM_NAME=$1 + VALUE=$2 + if [[ ${VALUE} != "true" ]] && [[ ${VALUE} != "false" ]]; then + echo "Valid parameter" ${PARAM_NAME} "values are: true/false" + help_usage + fi +} + +#main +[ $# -lt 2 ] && help_usage + +JAR_FILE=$1 +SUITE_FILE=$2 + +CURRENT_DIR=`pwd` +BASEDIR=$(dirname $0) +if [ ${BASEDIR:0:1} = "/" ] +then + FULL_PATH=$BASEDIR +else + FULL_PATH=$CURRENT_DIR/$BASEDIR +fi +LOGS_PROP_FILE=file:${FULL_PATH}/conf/log4j.properties +CONF_FILE=${FULL_PATH}/conf/conf.yaml +CREDENTIALS_FILE=${FULL_PATH}/conf/credentials.yaml +MainClass=com.att.ecomp.dcae.ci.run.RunTestSuite + + +cmd="java -Dconfig.resource=${CONF_FILE} -Dcredentials.file=${CREDENTIALS_FILE} -Dlog4j.configuration=${LOGS_PROP_FILE} -DtestSuite=${SUITE_FILE} -cp $JAR_FILE ${MainClass} &" +$cmd + +status=`echo $?` + +echo "##################################################" +echo "################# status is ${status} #################" +echo "##################################################" + +exit $status diff --git a/src/main/resources/testSuite/testSuite.xml b/src/main/resources/testSuite/testSuite.xml new file mode 100644 index 0000000..a3fee3b --- /dev/null +++ b/src/main/resources/testSuite/testSuite.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/testSuite/testSuiteSelenium.xml b/src/main/resources/testSuite/testSuiteSelenium.xml new file mode 100644 index 0000000..a79677a --- /dev/null +++ b/src/main/resources/testSuite/testSuiteSelenium.xml @@ -0,0 +1,10 @@ + + + + + + + + + + -- cgit 1.2.3-korg