├── README.md ├── .gitignore ├── issue_template.md ├── testgrid-scripts ├── s3 │ ├── s3_test.sh │ ├── s3_testgrid.yaml │ └── s3_deployement.sh └── utils │ ├── test_runner.sh │ ├── common_utils.sh │ ├── wait_for_pod_ready.sh │ ├── deployment_utils.sh │ ├── usage.sh │ └── setup_deployment_env.sh ├── connectors └── s3-tests │ ├── src │ └── test │ │ ├── resources │ │ ├── testng.xml │ │ └── s3test │ │ │ └── s3_b7a_service.bal │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── integration │ │ └── ballerina │ │ └── test │ │ └── S3Test.java │ └── pom.xml ├── pull_request_template.md ├── pom.xml └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # NOTE 2 | ballerina-integrator-scenario-tests is deprecated and is no longer maintained. This repository will be moved to the attic. 3 | 4 | # ballerina-integrator-scenario-tests 5 | The ballerina integrator connector test cases, deployment scripts, and test-grid job configs persisted in this repository. The test grid will use them to perform scenario-based testing. 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | -------------------------------------------------------------------------------- /issue_template.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | 4 | **Suggested Labels:** 5 | 6 | 7 | **Suggested Assignees:** 8 | 9 | 10 | **Affected Product Version:** 11 | 12 | **OS, DB, other environment details and versions:** 13 | 14 | **Steps to reproduce:** 15 | 16 | 17 | **Related Issues:** 18 | -------------------------------------------------------------------------------- /testgrid-scripts/s3/s3_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2019, WSO2 Inc. (http://wso2.org) All Rights Reserved. 3 | # 4 | # WSO2 Inc. licenses this file to you under the Apache License, 5 | # Version 2.0 (the "License"); you may not use this file except 6 | # in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | set -e 19 | 20 | parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 21 | grand_parent_path=$(dirname ${parent_path}) 22 | . ${grand_parent_path}/utils/test_runner.sh 23 | 24 | INPUT_DIR=$2 25 | OUTPUT_DIR=$4 26 | 27 | echo "Running s3_test.sh file" 28 | 29 | export input_dir="${INPUT_DIR}" 30 | cd ../../connectors/s3-tests 31 | 32 | run_test s3_tests ${OUTPUT_DIR} 33 | -------------------------------------------------------------------------------- /testgrid-scripts/utils/test_runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2019, WSO2 Inc. (http://wso2.org) All Rights Reserved. 3 | # 4 | # WSO2 Inc. licenses this file to you under the Apache License, 5 | # Version 2.0 (the "License"); you may not use this file except 6 | # in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | run_test() { 19 | local scenario_name=$1; 20 | local outpur_directory=$2; 21 | 22 | mvn clean install -fae 23 | 24 | echo "Copying surefire-reports to ${outpur_directory}" 25 | mkdir -p ${outpur_directory}/scenarios/${scenario_name} 26 | find ./* -name "surefire-reports" -exec cp --parents -r {} ${outpur_directory}/scenarios/${scenario_name} \; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /connectors/s3-tests/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /testgrid-scripts/utils/common_utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2019, WSO2 Inc. (http://wso2.org) All Rights Reserved. 3 | # 4 | # WSO2 Inc. licenses this file to you under the Apache License, 5 | # Version 2.0 (the "License"); you may not use this file except 6 | # in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Read a property file to a given associative array 19 | # 20 | # $1 - Property file 21 | # $2 - associative array 22 | # How to call 23 | # declare -A somearray 24 | # read_property_file testplan-props.properties somearray 25 | read_property_file() { 26 | local property_file_path=$1 27 | # Read configuration into an associative array 28 | # IFS is the 'internal field separator'. In this case, your file uses '=' 29 | local -n configArray=$2 30 | IFS="=" 31 | while read -r key value 32 | do 33 | [[ -n $key ]] && configArray[$key]=$value 34 | done < ${property_file_path} 35 | unset IFS 36 | } 37 | 38 | # Write key value pairs in a given associative array to a given property file 39 | # 40 | # $1 - file path 41 | # $2 - associative array of key value pairs 42 | write_to_properties_file() { 43 | local properties_file_path=$1 44 | local -n properties_array=$2 45 | 46 | # Keys are accessed through exclamation point 47 | for i in ${!properties_array[@]} 48 | do 49 | echo ${i}=${properties_array[$i]} >> ${properties_file_path} 50 | done 51 | } 52 | -------------------------------------------------------------------------------- /testgrid-scripts/utils/wait_for_pod_ready.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2019, WSO2 Inc. (http://wso2.org) All Rights Reserved. 3 | # 4 | # WSO2 Inc. licenses this file to you under the Apache License, 5 | # Version 2.0 (the "License"); you may not use this file except 6 | # in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | pod_ready() { 19 | [[ "$(kubectl get pods "$1" -o 'jsonpath={.status.conditions[?(@.type=="Ready")].status}')" == 'True' ]] 20 | } 21 | 22 | pods_ready() { 23 | local pod 24 | 25 | [[ "$#" == 0 ]] && return 0 26 | 27 | for pod in $pods; do 28 | #If pod is not ready returns 1 29 | pod_ready "$pod" || return 1 30 | done 31 | # All pods ready 32 | echo "All pods ready" 33 | 34 | return 0 35 | } 36 | 37 | wait_until_pods_ready() { 38 | local period interval i pods 39 | 40 | if [[ $# != 2 ]]; then 41 | echo "Usage: wait-until-pods-ready PERIOD INTERVAL" >&2 42 | echo "" >&2 43 | echo "This script waits for all pods to be ready in the current namespace." >&2 44 | 45 | return 1 46 | fi 47 | 48 | period="$1" 49 | interval="$2" 50 | 51 | for ((i=0; i<$period; i+=$interval)); do 52 | pods="$(kubectl get pods -o 'jsonpath={.items[*].metadata.name}')" 53 | if pods_ready $pods; then 54 | return 0 55 | fi 56 | 57 | echo "Waiting for the pods to be ready..." 58 | sleep "$interval" 59 | done 60 | 61 | echo "Waited for $period seconds, but all pods are not ready yet." 62 | return 1 63 | } 64 | 65 | wait_until_pods_ready $@ 66 | -------------------------------------------------------------------------------- /connectors/s3-tests/pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 22 | 23 | 4.0.0 24 | org.wso2.ballerina-integrator 25 | s3-tests 26 | 0.1.0-SNAPSHOT 27 | 28 | org.wso2.ballerina-integrator 29 | ballerina-integrator-testgrid-scenarios 30 | 0.0.1-SNAPSHOT 31 | ../../pom.xml 32 | 33 | 34 | 35 | 36 | io.rest-assured 37 | rest-assured 38 | 3.1.0 39 | test 40 | 41 | 42 | org.testng 43 | testng 44 | 6.14.3 45 | test 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /testgrid-scripts/s3/s3_testgrid.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019, WSO2 Inc. (http://wso2.com) All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | version: '0.9' 16 | emailToList: "thishani@wso2.com, integration-group@wso2.com" 17 | infrastructureConfig: 18 | iacProvider: KUBERNETES 19 | infrastructureProvider: GKE 20 | containerOrchestrationEngine: None 21 | includes: 22 | - CentOS-7.5 23 | - MySQL-5.7 24 | - OPEN_JDK8 25 | provisioners: 26 | - name: kubernetes working environment 27 | description: Provision Infra for running intg tests 28 | remoteRepository: "https://github.com/wso2/ballerina-integrator-scenario-tests.git" 29 | scripts: 30 | - name: 'kubernetes-create-environment' 31 | description: '' 32 | type: KUBERNETES 33 | phase: CREATE 34 | - name: 'kubernetes-destroy-environment' 35 | type: KUBERNETES 36 | phase: DESTROY 37 | deploymentConfig: 38 | deploymentPatterns: 39 | - name: 'deployment' 40 | remoteRepository: "https://github.com/wso2/ballerina-integrator-scenario-tests.git" 41 | description: 'deployment of the resources in the gke' 42 | scripts: 43 | - name: 'ballerina-integrator-deployment' 44 | type: SHELL 45 | file: testgrid-scripts/s3/s3_deployement.sh 46 | inputParameters: 47 | BallerinaVersion: "1.0.0" 48 | isDebugEnabled: "true" 49 | TestGroup: "s3_test" 50 | scenarioConfigs: 51 | - testType: TESTNG 52 | remoteRepository: "https://github.com/wso2/ballerina-integrator-scenario-tests.git" 53 | name: "ballerina-integrator-testgrid-scenarios" 54 | description: "scenarios" 55 | file: testgrid-scripts/s3/s3_test.sh 56 | -------------------------------------------------------------------------------- /testgrid-scripts/utils/deployment_utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2019, WSO2 Inc. (http://wso2.org) All Rights Reserved. 3 | # 4 | # WSO2 Inc. licenses this file to you under the Apache License, 5 | # Version 2.0 (the "License"); you may not use this file except 6 | # in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | readonly utils_parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 19 | 20 | # Install the provided Ballerina version 21 | # 22 | # $1 - Ballerina version 23 | install_ballerina() { 24 | local ballerina_version=$1 25 | if [[ "${ballerina_version}" = "" ]]; then 26 | echo "Ballerina version not provided!" 27 | exit 2 28 | fi 29 | echo "Installing Ballerina version: ${ballerina_version}" 30 | wget https://product-dist.ballerina.io/downloads/${ballerina_version}/ballerina-linux-installer-x64-${ballerina_version}.deb --quiet 31 | local wget_output=$? 32 | if [ ${wget_output} -ne 0 ]; then 33 | echo "Ballerina download failed!" 34 | exit 2; 35 | fi 36 | sudo dpkg -i ballerina-linux-installer-x64-${ballerina_version}.deb 37 | ballerina version 38 | readonly ballerina_home=/usr/lib/ballerina/ballerina-${ballerina_version} 39 | echo "Ballerina Home: ${ballerina_home}" 40 | } 41 | 42 | # Generates a random namespace name 43 | generate_random_namespace() { 44 | echo "kubernetes-namespace"-$(generate_random_name) 45 | } 46 | 47 | # Generates a random database name 48 | generate_random_name() { 49 | local new_uuid=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1) 50 | echo ${new_uuid} 51 | } 52 | 53 | # Wait for pod readiness 54 | wait_for_pod_readiness() { 55 | local timeout=300 56 | local interval=20 57 | bash ${utils_parent_path}/wait_for_pod_ready.sh ${timeout} ${interval} 58 | 59 | # Temporary sleep to check whether app eventually becomes ready.. 60 | # Ideally there should have been a kubernetes readiness probe 61 | # which would make sure the "Ready" status would actually mean 62 | # the pod is ready to accept requests (app is ready) so the above 63 | # readiness script would suffice 64 | sleep 240s 65 | } 66 | -------------------------------------------------------------------------------- /testgrid-scripts/utils/usage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2019, WSO2 Inc. (http://wso2.org) All Rights Reserved. 3 | # 4 | # WSO2 Inc. licenses this file to you under the Apache License, 5 | # Version 2.0 (the "License"); you may not use this file except 6 | # in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | readonly WORK_DIR=`pwd` 19 | 20 | function usage() 21 | { 22 | echo " 23 | Usage bash test.sh --input-dir /workspace/data-bucket/in --output-dir /workspace/data-bucket/out 24 | Following are the expected input parameters. all of these are optional 25 | --input-dir | -i : input directory for test.sh 26 | --output-dir | -o : output directory for test.sh 27 | " 28 | } 29 | 30 | # Process inputs 31 | # ex. bash test.sh --input-dir --output-dir 32 | optspec=":hiom-:" 33 | while getopts "$optspec" optchar; do 34 | case "${optchar}" in 35 | -) 36 | case "${OPTARG}" in 37 | input-dir) 38 | val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 )) 39 | input_dir=$val 40 | ;; 41 | output-dir) 42 | val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 )) 43 | output_dir=$val 44 | ;; 45 | *) 46 | usage 47 | if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then 48 | echo "Unknown option --${OPTARG}" >&2 49 | fi 50 | ;; 51 | esac;; 52 | h) 53 | usage 54 | exit 2 55 | ;; 56 | o) 57 | output_dir=$val 58 | ;; 59 | i) 60 | input_dir=$val 61 | ;; 62 | *) 63 | usage 64 | if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then 65 | echo "Non-option argument: '-${OPTARG}'" >&2 66 | fi 67 | ;; 68 | esac 69 | done 70 | 71 | echo "working Directory : ${HOME}" 72 | echo "input directory : ${input_dir}" 73 | echo "output directory : ${output_dir}" 74 | 75 | export DATA_BUCKET_LOCATION=${input_dir} 76 | -------------------------------------------------------------------------------- /pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Purpose 2 | > Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc. 3 | 4 | ## Goals 5 | > Describe the solutions that this feature/fix will introduce to resolve the problems described above 6 | 7 | ## Approach 8 | > Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here. 9 | 10 | ## User stories 11 | > Summary of user stories addressed by this change> 12 | 13 | ## Release note 14 | > Brief description of the new feature or bug fix as it will appear in the release notes 15 | 16 | ## Documentation 17 | > Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact 18 | 19 | ## Training 20 | > Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable 21 | 22 | ## Certification 23 | > Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why. 24 | 25 | ## Marketing 26 | > Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable 27 | 28 | ## Automation tests 29 | - Unit tests 30 | > Code coverage information 31 | - Integration tests 32 | > Details about the test cases and coverage 33 | 34 | ## Security checks 35 | - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no 36 | - Ran FindSecurityBugs plugin and verified report? yes/no 37 | - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no 38 | 39 | ## Samples 40 | > Provide high-level details about the samples related to this feature 41 | 42 | ## Related PRs 43 | > List any other related PRs 44 | 45 | ## Migrations (if applicable) 46 | > Describe migration steps and platforms on which migration has been tested 47 | 48 | ## Test environment 49 | > List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested 50 | 51 | ## Learning 52 | > Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem. -------------------------------------------------------------------------------- /testgrid-scripts/utils/setup_deployment_env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2019, WSO2 Inc. (http://wso2.org) All Rights Reserved. 3 | # 4 | # WSO2 Inc. licenses this file to you under the Apache License, 5 | # Version 2.0 (the "License"); you may not use this file except 6 | # in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | set -o errexit 19 | set -o pipefail 20 | set -o nounset 21 | 22 | trap propagate_cleanup_properties EXIT 23 | 24 | setup_deployment_env() { 25 | local parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 26 | . ${parent_path}/common_utils.sh 27 | . ${parent_path}/deployment_utils.sh 28 | 29 | declare -g -A infra_config 30 | cat ${input_dir}/infrastructure.properties 31 | read_property_file "${input_dir}/infrastructure.properties" infra_config 32 | 33 | 34 | readonly docker_user=${infra_config["dockerhub_ballerina_scenarios_username"]} 35 | readonly docker_password=${infra_config["dockerhub_ballerina_scenarios_password"]} 36 | 37 | # Create a custom random namespace 38 | readonly cluster_namespace=$(generate_random_namespace) 39 | kubectl create namespace ${cluster_namespace} 40 | # Enforce the created namespace for future kubectl usages 41 | kubectl config set-context $(kubectl config current-context) --namespace=${cluster_namespace} 42 | 43 | local ballerina_version_type=${infra_config["BallerinaVersionType"]:-""} 44 | 45 | 46 | local ballerina_version_in_yaml="${infra_config["BallerinaVersion"]:-""}" 47 | if [ "${ballerina_version_in_yaml}" = "" ]; then 48 | echo "No information provided regarding the Ballerina version to use! Please add BallerinaVersion into deploymentConfig inputParameters." 49 | exit 2 50 | fi 51 | install_ballerina ${ballerina_version_in_yaml} 52 | 53 | 54 | local ballerina_version_cmd_output="$(${ballerina_home}/bin/ballerina version)" 55 | ballerina_version=$(sed "s:Ballerina ::g" <<< ${ballerina_version_cmd_output}) 56 | 57 | echo "TestGroup=${infra_config["TestGroup"]}" >> ${output_dir}/deployment.properties 58 | } 59 | 60 | propagate_cleanup_properties() { 61 | # Store namespace to be cleaned up at the end 62 | echo "NamespacesToCleanup=${cluster_namespace}" >> ${output_dir}/infrastructure-cleanup.properties 63 | } 64 | 65 | if setup_deployment_env; then 66 | echo "Deployment set up successful" 67 | else 68 | exit 1 69 | fi 70 | -------------------------------------------------------------------------------- /connectors/s3-tests/src/test/java/org/wso2/integration/ballerina/test/S3Test.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | package org.wso2.integration.ballerina.test; 18 | 19 | import io.restassured.RestAssured; 20 | import io.restassured.response.Response; 21 | import org.testng.Assert; 22 | import org.testng.annotations.BeforeTest; 23 | import org.testng.annotations.Test; 24 | 25 | import java.io.FileInputStream; 26 | import java.io.InputStream; 27 | import java.util.Properties; 28 | 29 | import static io.restassured.RestAssured.given; 30 | 31 | public class S3Test { 32 | private static final String INPUTS_LOCATION = System.getenv("input_dir"); 33 | private static String externalip; 34 | private static String nodeport; 35 | private static String namespace; 36 | 37 | static void initParams() throws Exception { 38 | InputStream input = new FileInputStream(INPUTS_LOCATION + "/deployment.properties"); 39 | Properties props = new Properties(); 40 | props.load(input); 41 | externalip = props.getProperty("ExternalIP"); 42 | nodeport = props.getProperty("NodePort"); 43 | namespace = props.getProperty("namespace"); 44 | } 45 | 46 | @BeforeTest 47 | public void init() throws Exception { 48 | try { 49 | initParams(); 50 | RestAssured.baseURI = "http://" + externalip + ":" + nodeport + "/amazons3/"; 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | @Test 57 | public void testCreatebucket() { 58 | Response response = given(). 59 | when(). 60 | post("http://" + externalip + ":" + nodeport + "/amazons3/ballerina-integrator-bucket25"); 61 | Assert.assertTrue(response.statusCode() == 200); 62 | } 63 | 64 | @Test(dependsOnMethods = { "testCreatebucket" }) 65 | public void testDeletebucket() { 66 | Response response = given(). 67 | when(). 68 | delete("http://" + externalip + ":" + nodeport + "/amazons3/ballerina-integrator-bucket25"); 69 | Assert.assertTrue(response.statusCode() == 200); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /testgrid-scripts/s3/s3_deployement.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Copyright (c) 2019, WSO2 Inc. (http://wso2.com) All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -e 17 | 18 | input_dir=$2 19 | output_dir=$4 20 | 21 | deployment_s3_parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) 22 | deployment_s3_grand_parent_path=$(dirname ${deployment_s3_parent_path}) 23 | 24 | . ${deployment_s3_grand_parent_path}/utils/usage.sh 25 | . ${deployment_s3_grand_parent_path}/utils/setup_deployment_env.sh 26 | 27 | ballerina_integrator_aws_s3_access_key=${infra_config["ballerina_integrator_aws_s3_access_key"]} 28 | ballerina_integrator_aws_s3_secret_key=${infra_config["ballerina_integrator_aws_s3_secret_key"]} 29 | 30 | setup_deployment(){ 31 | download_s3 32 | build_bal_service 33 | wait_for_pod_readiness 34 | write_properties_to_data_bucket 35 | } 36 | 37 | #Download S3 connector 38 | download_s3(){ 39 | git clone https://github.com/wso2-ballerina/module-amazons3.git 40 | cd module-amazons3 41 | ${ballerina_home}/bin/ballerina build -c --skip-tests amazons3 42 | cd .. 43 | echo "=== S3 setup successfully ===" 44 | } 45 | 46 | #Copy ballerina service to s3 47 | build_bal_service(){ 48 | cp -r connectors/s3-tests/src/test/resources/s3test ./module-amazons3/src 49 | cd module-amazons3 50 | touch ballerina.conf 51 | chmod -R 766 ballerina.conf 52 | 53 | echo "ACCESS_KEY_ID="\"$ballerina_integrator_aws_s3_access_key\" >> ./ballerina.conf 54 | echo "SECRET_ACCESS_KEY="\"$ballerina_integrator_aws_s3_secret_key\" >> ./ballerina.conf 55 | 56 | ${ballerina_home}/bin/ballerina build s3test --b7a.config.file=./ballerina.conf 57 | 58 | echo "=== Ballerina service built successfully ===" 59 | 60 | # Run generated docker 61 | kubectl apply -f ./target/kubernetes/s3test --namespace=${cluster_namespace} 62 | } 63 | 64 | write_properties_to_data_bucket() { 65 | local external_ip=$(kubectl get nodes -o=jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}') 66 | local node_port=$(kubectl get svc awss3ep-svc -o=jsonpath='{.spec.ports[0].nodePort}') 67 | declare -A deployment_props 68 | deployment_props["ExternalIP"]=${external_ip} 69 | deployment_props["NodePort"]=${node_port} 70 | deployment_props["namespace"]=${cluster_namespace} 71 | write_to_properties_file ${output_dir}/deployment.properties deployment_props 72 | echo "ExternalIP: ${external_ip}" 73 | echo "NodePort: ${node_port}" 74 | 75 | } 76 | 77 | setup_deployment 78 | 79 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | org.wso2.ballerina-integrator 22 | 0.1.0-SNAPSHOT 23 | 24 | connectors/s3-tests 25 | 26 | 4.0.0 27 | ballerina-integrator-scenario-tests 28 | Ballerina Integrator - Scenario Test 29 | pom 30 | 31 | 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-compiler-plugin 36 | ${maven.compiler.plugin.version} 37 | 38 | 1.8 39 | 1.8 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.apache.maven.plugins 47 | maven-surefire-plugin 48 | ${maven.surefire.plugin.version} 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.slf4j 58 | slf4j-api 59 | ${slf4j.version} 60 | 61 | 62 | org.testng 63 | testng 64 | ${testng.version} 65 | 66 | 67 | 68 | 69 | 70 | 2.22.1 71 | 3.8.0 72 | 1.7.26 73 | 6.14.3 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /connectors/s3-tests/src/test/resources/s3test/s3_b7a_service.bal: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 2 | // 3 | // WSO2 Inc. licenses this file to you under the Apache License, 4 | // Version 2.0 (the "License"); you may not use this file except 5 | // in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, 11 | // software distributed under the License is distributed on an 12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. See the License for the 14 | // specific language governing permissions and limitations 15 | // under the License. 16 | 17 | import ballerina/config; 18 | import ballerina/http; 19 | import ballerina/kubernetes; 20 | import ballerina/log; 21 | import wso2/amazons3; 22 | 23 | // Constants for error code and messages. 24 | 25 | const string RESPOND_ERROR_MSG = "Error in responding to client."; 26 | const string CLIENT_CREATION_ERROR_MSG = "Error while creating the AmazonS3 client."; 27 | const string BUCKET_CREATION_ERROR_MSG = "Error while creating bucket on Amazon S3."; 28 | const string BUCKET_DELETION_ERROR_MSG = "Error while deleting bucket from Amazon S3."; 29 | 30 | // Read accessKey and secretKey from config files. 31 | string accessKeyId = config:getAsString("ACCESS_KEY_ID"); 32 | string secretAccessKey = config:getAsString("SECRET_ACCESS_KEY"); 33 | 34 | // Create Amazons3 client configration with the above accesskey and secretKey values. 35 | amazons3:ClientConfiguration amazonS3Config = { 36 | accessKeyId: accessKeyId, 37 | secretAccessKey: secretAccessKey, 38 | clientConfig: { 39 | http1Settings: {chunking: http:CHUNKING_NEVER} 40 | } 41 | }; 42 | 43 | //Add `@kubernetes:Service` to a listner endpoint to expose the endpoint as Kubernetes Service. 44 | @kubernetes:Service { 45 | //Service type is `NodePort`. 46 | serviceType: "NodePort" 47 | } 48 | //Add `@kubernetes:Ingress` to a listner endpoint to expose the endpoint as Kubernetes Ingress. 49 | @kubernetes:Ingress { 50 | //Hostname of the service is `abc.com`. 51 | hostname: "s3.bi.wso2.com" 52 | } 53 | listener http:Listener awsS3EP = new http:Listener(9090); 54 | 55 | //Add `@kubernetes:ConfigMap` annotation to a Ballerina service to mount configs to the container. 56 | @kubernetes:ConfigMap { 57 | //Path to the ballerina.conf file. 58 | //If a releative path is provided, the path should be releative to where the `ballerina build` command is executed. 59 | conf: "./ballerina.conf" 60 | } 61 | //Add `@kubernetes:Deployment` annotation to a Ballerna service to generate Kuberenetes Deployment for a Ballerina module. 62 | @kubernetes:Deployment { 63 | image: "ballerinaintegrator/s3_connector_test:v.1.0", 64 | name: "s3_connector_test", 65 | username: "ballerinaintegrator", 66 | password: "ballerinaintegrator", 67 | push: true, 68 | imagePullPolicy: "Always" 69 | } 70 | @http:ServiceConfig { 71 | basePath: "/amazons3" 72 | } 73 | service amazonS3Service on awsS3EP { 74 | @http:ResourceConfig { 75 | methods: ["POST"], 76 | path: "/{bucketName}" 77 | } 78 | // Function to create a new bucket. 79 | resource function createBucket(http:Caller caller, http:Request request, string bucketName) { 80 | // Create AmazonS3 client with the above amazonS3Config. 81 | amazons3:AmazonS3Client | error amazonS3Client = new (amazonS3Config); 82 | // Define new response. 83 | http:Response backendResponse = new (); 84 | 85 | if (amazonS3Client is amazons3:AmazonS3Client) { 86 | var response = amazonS3Client->createBucket(<@untainted>bucketName); 87 | if (response is error) { 88 | createAndSendErrorResponse(caller, <@untainted>response.detail()?.message, 89 | BUCKET_CREATION_ERROR_MSG); 90 | } else { 91 | // If there is no error, then bucket created successfully. Send the success response. 92 | backendResponse.setTextPayload(<@untainted>string `${bucketName} created on Amazon S3.`, 93 | contentType = "text/plain"); 94 | respondAndHandleError(caller, backendResponse, RESPOND_ERROR_MSG); 95 | } 96 | } else { 97 | createAndSendErrorResponse(caller, amazonS3Client.detail()?.message, CLIENT_CREATION_ERROR_MSG); 98 | } 99 | } 100 | 101 | @http:ResourceConfig { 102 | methods: ["DELETE"], 103 | path: "/{bucketName}" 104 | } 105 | // Function to delete bucket. 106 | resource function deleteBucket(http:Caller caller, http:Request request, string bucketName) { 107 | // Create AmazonS3 client with the above amazonS3Config. 108 | amazons3:AmazonS3Client | error amazonS3Client = new (amazonS3Config); 109 | // Define new response. 110 | http:Response backendResponse = new (); 111 | if (amazonS3Client is amazons3:AmazonS3Client) { 112 | var response = amazonS3Client->deleteBucket(<@untainted>bucketName); 113 | if (response is error) { 114 | createAndSendErrorResponse(caller, <@untainted>response.detail()?.message, 115 | BUCKET_DELETION_ERROR_MSG); 116 | } else { 117 | // If there is no error, then bucket deleted successfully. Send the success response. 118 | backendResponse.setTextPayload(<@untainted>string `${bucketName} deleted from Amazon S3.`, 119 | contentType = "text/plain"); 120 | respondAndHandleError(caller, backendResponse, RESPOND_ERROR_MSG); 121 | } 122 | } else { 123 | createAndSendErrorResponse(caller, amazonS3Client.detail()?.message, CLIENT_CREATION_ERROR_MSG); 124 | } 125 | } 126 | } 127 | 128 | // Function to create the error response. 129 | function createAndSendErrorResponse(http:Caller caller, string errorMessage, string respondErrorMsg) { 130 | http:Response response = new; 131 | //Set 500 status code. 132 | response.statusCode = http:STATUS_INTERNAL_SERVER_ERROR; 133 | //Set the error message to the error response payload. 134 | response.setPayload(errorMessage); 135 | respondAndHandleError(caller, response, respondErrorMsg); 136 | } 137 | 138 | // Function to send the response back to the client and handle the error. 139 | function respondAndHandleError(http:Caller caller, http:Response response, string respondErrorMsg) { 140 | // Send response to the caller. 141 | var respond = caller->respond(response); 142 | if (respond is error) { 143 | log:printError(respondErrorMsg, err = respond); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------