From a87f460cd149daa51814bfd1606e6b12a39f9958 Mon Sep 17 00:00:00 2001 From: Tunahan Cicek Date: Tue, 14 Nov 2023 10:53:23 +0100 Subject: [PATCH] add automated Tests --- .github/workflows/semantic-hub-e2e-test.yml | 69 ++++ e2e-tests/requirements.txt | 3 + e2e-tests/semantic-hub/common.yaml | 73 ++++ e2e-tests/semantic-hub/test_api.tavern.yaml | 400 ++++++++++++++++++++ 4 files changed, 545 insertions(+) create mode 100644 .github/workflows/semantic-hub-e2e-test.yml create mode 100644 e2e-tests/requirements.txt create mode 100644 e2e-tests/semantic-hub/common.yaml create mode 100644 e2e-tests/semantic-hub/test_api.tavern.yaml diff --git a/.github/workflows/semantic-hub-e2e-test.yml b/.github/workflows/semantic-hub-e2e-test.yml new file mode 100644 index 00000000..3a4a3548 --- /dev/null +++ b/.github/workflows/semantic-hub-e2e-test.yml @@ -0,0 +1,69 @@ +############################################################### +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# SPDX-License-Identifier: Apache-2.0 +############################################################### +name: Semantic-hub End-to-End tests + +on: + workflow_dispatch: + inputs: + bearerToken: + description: 'bearerToken' + required: true + semantichubUrl: + description: 'semantic-hub-Url' + required: true + +jobs: + end_to_end_tests: + runs-on: ubuntu-latest + name: Execute End-to-End tests + + steps: + - name: Mask Input Credentials + run: | + mask_client_bearer_token=$(jq -r '.inputs.bearerToken' $GITHUB_EVENT_PATH) + echo ::add-mask::$mask_client_bearer_token + echo mask_client_bearer_token=$mask_client_bearer_token >> $GITHUB_ENV + + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: "3.8" + check-latest: true + + - name: Install python dependencies + working-directory: ./e2e-tests + run: | + pip install -r requirements.txt + + - name: Install python dependencies + working-directory: ./e2e-tests/semantic-hub + run: | + py.test . -vv --html=./output/report.html --self-contained-html + env: + BEARER_TOKEN: ${{ env.mask_client_bearer_token }} + SEMANTIC_HUB_API_URL: ${{ inputs.semantichubUrl }} + - name: Upload test report + uses: actions/upload-artifact@v3 + if: always() + with: + name: semantic-hub-e2e-test-report + path: ./e2e-tests/semantic-hub/output/report.html \ No newline at end of file diff --git a/e2e-tests/requirements.txt b/e2e-tests/requirements.txt new file mode 100644 index 00000000..f1c58910 --- /dev/null +++ b/e2e-tests/requirements.txt @@ -0,0 +1,3 @@ +pytest==7.1.2 +tavern==1.23.3 +pytest-html==3.1.1 diff --git a/e2e-tests/semantic-hub/common.yaml b/e2e-tests/semantic-hub/common.yaml new file mode 100644 index 00000000..a98a8d71 --- /dev/null +++ b/e2e-tests/semantic-hub/common.yaml @@ -0,0 +1,73 @@ +############################################################### +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# SPDX-License-Identifier: Apache-2.0 +############################################################### +name: Common variable definitions +description: + Contains common variable definitions. + +variables: + semantic_hub_api_url: "{tavern.env_vars.SEMANTIC_HUB_API_URL}" + bearer_token: "{tavern.env_vars.BEARER_TOKEN}" + model_bamm_urn: urn:bamm:org.eclipse.tractusx.semantics.test:1.0.0#EndToEndTest + model_bamm_urn_encoded: urn%3Abamm%3Aorg.eclipse.tractusx.semantics.test%3A1.0.0%23EndToEndTest + model_bamm_package_urn_encoded: urn%3Abamm%3Aorg.eclipse.tractusx.semantics.test%3A1.0.0%23 + model_bamm_name: EndToEndTest + model_bamm_version: 1.0.0 + model_bamm_ttl: | + @prefix : . + @prefix bamm: . + @prefix bamm-c: . + @prefix xsd: . + + :EndToEndTest + a bamm:Aspect ; + bamm:name "EndToEndTest" ; + bamm:preferredName "EndToEndTest en"@en ; + bamm:preferredName "EndToEndTest de"@de ; + bamm:properties ( :detail ) ; + bamm:operations ( ) . + + :detail a bamm:Property ; + bamm:name "testString" ; + bamm:exampleValue "Example Value Test" ; + bamm:characteristic bamm-c:Text . + + model_samm_urn: urn:samm:org.eclipse.tractusx.semantics.test:1.0.0#EndToEndTest + model_samm_urn_encoded: urn%3Asamm%3Aorg.eclipse.tractusx.semantics.test%3A1.0.0%23EndToEndTest + model_samm_package_urn_encoded: urn%3Asamm%3Aorg.eclipse.tractusx.semantics.test%3A1.0.0%23 + model_samm_name: EndToEndTest + model_samm_version: 1.0.0 + model_samm_ttl: | + @prefix : . + @prefix samm: . + @prefix bamm-c: . + @prefix xsd: . + + :EndToEndTest + a samm:Aspect ; + samm:name "EndToEndTest" ; + samm:preferredName "EndToEndTest en"@en ; + samm:preferredName "EndToEndTest de"@de ; + samm:properties ( :detail ) ; + samm:operations ( ) . + + :detail a samm:Property ; + samm:name "testString" ; + samm:exampleValue "Example Value Test" ; + samm:characteristic bamm-c:Text . \ No newline at end of file diff --git a/e2e-tests/semantic-hub/test_api.tavern.yaml b/e2e-tests/semantic-hub/test_api.tavern.yaml new file mode 100644 index 00000000..b80bce9f --- /dev/null +++ b/e2e-tests/semantic-hub/test_api.tavern.yaml @@ -0,0 +1,400 @@ +############################################################### +# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# SPDX-License-Identifier: Apache-2.0 +############################################################### +test_name: Test APIs are protected with authentication + +includes: + - !include common.yaml + +stages: + - name: Test get models without access token + request: + url: "{semantic_hub_api_url:s}/api/v1/models?pageSize=10&page=0" + method: GET + response: + status_code: 401 + + - name: Authenticated request + request: + url: "{semantic_hub_api_url:s}/api/v1/models?pageSize=10&page=0" + method: GET + headers: + Content-Type: application/json + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/json + +--- +test_name: Test create, read, update and delete a model for BAMM + +includes: + - !include common.yaml + +stages: + - name: Create model expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models?status=DRAFT&type=BAMM" + method: POST + headers: + Content-Type: text/plain + Accept: application/json + Authorization: "Bearer {bearer_token:s}" + data: "{model_bamm_ttl:s}" + + response: + status_code: 200 + headers: + content-type: application/json + + - name: Get model by urn + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_bamm_urn_encoded:s}" + method: GET + headers: + Content-Type: application/json + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/json + json: + urn: "{model_bamm_urn:s}" + version: "{model_bamm_version:s}" + name: "{model_bamm_name:s}" + type: BAMM + status: DRAFT + + - name: Update model + request: + url: "{semantic_hub_api_url:s}/api/v1/models?status=DRAFT&type=BAMM" + method: PUT + headers: + Content-Type: text/plain + Accept: application/json + Authorization: "Bearer {bearer_token:s}" + data: "{model_bamm_ttl:s}" + + response: + status_code: 200 + json: + urn: "{model_bamm_urn:s}" + version: "{model_bamm_version:s}" + name: "{model_bamm_name:s}" + type: BAMM + status: DRAFT + + - name: Delete model by package urn + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_bamm_package_urn_encoded:s}" + method: DELETE + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 204 + +--- + +test_name: Test create, read, update and delete a model for SAMM + +includes: + - !include common.yaml + +stages: + - name: Create model expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models?status=DRAFT&type=SAMM" + method: POST + headers: + Content-Type: text/plain + Accept: application/json + Authorization: "Bearer {bearer_token:s}" + data: "{model_samm_ttl:s}" + + response: + status_code: 200 + headers: + content-type: application/json + + - name: Get model by urn + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_samm_urn_encoded:s}" + method: GET + headers: + Content-Type: application/json + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/json + json: + urn: "{model_samm_urn:s}" + version: "{model_samm_version:s}" + name: "{model_samm_name:s}" + type: SAMM + status: DRAFT + + - name: Update model + request: + url: "{semantic_hub_api_url:s}/api/v1/models?status=DRAFT&type=SAMM" + method: PUT + headers: + Content-Type: text/plain + Accept: application/json + Authorization: "Bearer {bearer_token:s}" + data: "{model_samm_ttl:s}" + + response: + status_code: 200 + json: + urn: "{model_samm_urn:s}" + version: "{model_samm_version:s}" + name: "{model_samm_name:s}" + type: SAMM + status: DRAFT + + - name: Delete model by package urn + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_samm_package_urn_encoded:s}" + method: DELETE + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 204 + +--- + +test_name: Test model artifcat generation for BAMM + +includes: + - !include common.yaml + +stages: + - name: Create model expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models?status=DRAFT&type=BAMM" + method: POST + headers: + Content-Type: text/plain + Accept: application/json + Authorization: "Bearer {bearer_token:s}" + data: "{model_bamm_ttl:s}" + + response: + status_code: 200 + headers: + content-type: application/json + + - name: Get model as file expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_bamm_urn_encoded:s}/file" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: text/turtle;charset=UTF-8 + + - name: Get model as diagram expect success + skip: True + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_bamm_urn_encoded:s}/diagram" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: image/png + + - name: Get model as documentation expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_bamm_urn_encoded:s}/documentation" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: text/html + + - name: Get model as json-schema expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_bamm_urn_encoded:s}/json-schema" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/schema+json + + - name: Get model as openapi expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_bamm_urn_encoded:s}/openapi?baseUrl=example.com" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/json + + - name: Get model as example-payload expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_bamm_urn_encoded:s}/example-payload" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/json + + - name: Get model as aasx expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_bamm_urn_encoded:s}/aas" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/xml + + - name: Delete model by package urn (cleanup) + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_bamm_package_urn_encoded:s}" + method: DELETE + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 204 + +--- + +test_name: Test model artifcat generation for SAMM + +includes: + - !include common.yaml + +stages: + - name: Create model expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models?status=DRAFT&type=SAMM" + method: POST + headers: + Content-Type: text/plain + Accept: application/json + Authorization: "Bearer {bearer_token:s}" + data: "{model_samm_ttl:s}" + + response: + status_code: 200 + headers: + content-type: application/json + + - name: Get model as file expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_samm_urn_encoded:s}/file" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: text/turtle;charset=UTF-8 + + - name: Get model as diagram expect success + skip: True + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_samm_urn_encoded:s}/diagram" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: image/png + + - name: Get model as documentation expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_samm_urn_encoded:s}/documentation" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: text/html + + - name: Get model as json-schema expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_samm_urn_encoded:s}/json-schema" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/schema+json + + - name: Get model as openapi expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_samm_urn_encoded:s}/openapi?baseUrl=example.com" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/json + + - name: Get model as example-payload expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_samm_urn_encoded:s}/example-payload" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/json + + - name: Get model as aasx expect success + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_samm_urn_encoded:s}/aas" + method: GET + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 200 + headers: + content-type: application/xml + + - name: Delete model by package urn (cleanup) + request: + url: "{semantic_hub_api_url:s}/api/v1/models/{model_samm_package_urn_encoded:s}" + method: DELETE + headers: + Authorization: "Bearer {bearer_token:s}" + response: + status_code: 204 \ No newline at end of file