diff --git a/testhelper/open-sds-junit/.gitignore b/testhelper/open-sds-junit/.gitignore new file mode 100644 index 000000000..3fd8b54a1 --- /dev/null +++ b/testhelper/open-sds-junit/.gitignore @@ -0,0 +1,13 @@ +*.iml +.gradle +/local.properties +*.idea +.DS_Store +/build +/captures +**/out/ +**/gen/ +**/bin/ +**/build/ +/environment_variable +/src/main/resources/inputs/download \ No newline at end of file diff --git a/testhelper/open-sds-junit/build.gradle b/testhelper/open-sds-junit/build.gradle new file mode 100644 index 000000000..f38eaf9b0 --- /dev/null +++ b/testhelper/open-sds-junit/build.gradle @@ -0,0 +1,28 @@ +plugins { + id 'java' +} + +group 'www.opensds.io' +version '1.0' + +repositories { + mavenCentral() +} + +sourceCompatibility = 1.8 + +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' + testImplementation('junit:junit:4.13') + testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' + + implementation 'com.google.code.gson:gson:2.8.6' + implementation("com.squareup.okhttp3:okhttp:4.6.0") + compile group: 'org.json', name: 'json', version: '20090211' + implementation("com.google.guava:guava:29.0-jre") + +// implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.475') +// implementation 'com.amazonaws:aws-java-sdk-s3' + compile group: 'uk.co.lucasweb', name: 'aws-v4-signer-java', version: '1.2' +} diff --git a/testhelper/open-sds-junit/environment_variable.txt b/testhelper/open-sds-junit/environment_variable.txt new file mode 100644 index 000000000..3fed77c02 --- /dev/null +++ b/testhelper/open-sds-junit/environment_variable.txt @@ -0,0 +1,4 @@ +// Set your provider details here +src\main\resources\inputs\createbucket +// Before test execute setup this variable in environment variable +HOST_IP=***.***.*.***;INPUT_PATH=D:/SODA-TestProject/OpenSdsGradle;PORT_TENANT_ID=:****;PORT=:**** \ No newline at end of file diff --git a/testhelper/open-sds-junit/gradle/wrapper/gradle-wrapper.jar b/testhelper/open-sds-junit/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..f3d88b1c2 Binary files /dev/null and b/testhelper/open-sds-junit/gradle/wrapper/gradle-wrapper.jar differ diff --git a/testhelper/open-sds-junit/gradle/wrapper/gradle-wrapper.properties b/testhelper/open-sds-junit/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..ba94df845 --- /dev/null +++ b/testhelper/open-sds-junit/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/testhelper/open-sds-junit/gradlew b/testhelper/open-sds-junit/gradlew new file mode 100644 index 000000000..2fe81a7d9 --- /dev/null +++ b/testhelper/open-sds-junit/gradlew @@ -0,0 +1,183 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# 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. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/testhelper/open-sds-junit/gradlew.bat b/testhelper/open-sds-junit/gradlew.bat new file mode 100644 index 000000000..9618d8d96 --- /dev/null +++ b/testhelper/open-sds-junit/gradlew.bat @@ -0,0 +1,100 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/testhelper/open-sds-junit/settings.gradle b/testhelper/open-sds-junit/settings.gradle new file mode 100644 index 000000000..8aec38404 --- /dev/null +++ b/testhelper/open-sds-junit/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'open-sds-junit' + diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/HttpHandler.java b/testhelper/open-sds-junit/src/main/java/com/opensds/HttpHandler.java new file mode 100644 index 000000000..4607c2ed6 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/HttpHandler.java @@ -0,0 +1,271 @@ +package com.opensds; + +import com.google.gson.Gson; +import com.opensds.jsonmodels.akskresponses.AKSKHolder; +import com.opensds.jsonmodels.akskresponses.SignatureKey; +import com.opensds.jsonmodels.authtokensrequests.Project; +import com.opensds.jsonmodels.authtokensrequests.Scope; +import com.opensds.jsonmodels.authtokensresponses.AuthTokenHolder; +import com.opensds.jsonmodels.inputs.addbackend.AddBackendInputHolder; +import com.opensds.jsonmodels.inputs.createbucket.CreateBucketFileInput; +import com.opensds.jsonmodels.logintokensrequests.*; +import com.opensds.jsonmodels.tokensresponses.TokenHolder; +import com.opensds.jsonmodels.typesresponse.TypesHolder; +import com.opensds.utils.BinaryUtils; +import com.opensds.utils.Constant; +import com.opensds.utils.ConstantUrl; +import com.opensds.utils.Logger; +import com.opensds.utils.okhttputils.OkHttpRequests; +import okhttp3.*; +import okio.BufferedSink; +import okio.Okio; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import static com.opensds.utils.HeadersName.*; + +public class HttpHandler extends OkHttpRequests { + private OkHttpClient client = new OkHttpClient(); + + public SignatureKey getAkSkList(String xAuthToken, String userId) { + SignatureKey signatureKey = new SignatureKey(); + String url = ConstantUrl.getInstance().getAksList(userId); + Logger.logString("URL: " + url); + try { + Gson gson = new Gson(); + Map headersMap = new HashMap<>(); + headersMap.put(CONTENT_TYPE, CONTENT_TYPE_JSON); + headersMap.put(X_AUTH_TOKEN, xAuthToken); + Headers headers = Headers.of(headersMap); + Response response = getCall(client, url, headers); + String responseBody = response.body().string(); + Logger.logString("Response: " + responseBody); + AKSKHolder akskHolder = gson.fromJson(responseBody, AKSKHolder.class); + Logger.logObject(akskHolder); + // build the SignatureKey struct and set the values + new Runnable() { + @Override + public void run() { + signatureKey.setSecretAccessKey(akskHolder.getCredentials()[0].getBlobObj().getSecret()); + signatureKey.setAccessKey(akskHolder.getCredentials()[0].getBlobObj().getAccess()); + String regionName = "us-east-1"; + signatureKey.setRegionName(regionName); + String serviceName = "s3"; + signatureKey.setServiceName(serviceName); + } + }.run(); + } catch (Exception e) { + e.printStackTrace(); + } + return signatureKey; + } + + public TokenHolder loginAndGetToken() { + TokenHolder tokenHolder = null; + try { + Auth auth = new Auth(); + auth.setIdentity(new Identity()); + auth.getIdentity().getMethods().add("password"); + auth.getIdentity().setPassword(new Password()); + auth.getIdentity().getPassword().setUser(new User()); + auth.getIdentity().getPassword().getUser().setName("admin"); + auth.getIdentity().getPassword().getUser().setPassword("opensds@123"); + auth.getIdentity().getPassword().getUser().setDomain(new Domain()); + auth.getIdentity().getPassword().getUser().getDomain().setName("Default"); + + AuthHolder authHolder = new AuthHolder(); + authHolder.setAuth(auth); + + Gson gson = new Gson(); + RequestBody requestBody = RequestBody.create(gson.toJson(authHolder), + MediaType.parse("application/json; charset=utf-8")); + String url = ConstantUrl.getInstance().getTokenLogin(); + Logger.logString("URL: " + url); + Map headersMap = new HashMap<>(); + headersMap.put(CONTENT_TYPE, CONTENT_TYPE_JSON); + Headers headers = Headers.of(headersMap); + Response response = postCall(client, url, requestBody, headers); + String responseBody = response.body().string(); + Logger.logString("Response code: " + response.code()); + Logger.logString("Response body: " + responseBody); + tokenHolder = gson.fromJson(responseBody, TokenHolder.class); + tokenHolder.setResponseHeaderSubjectToken(response.header(X_SUBJECT_TOKEN)); + } catch (Exception e) { + e.printStackTrace(); + } + return tokenHolder; + } + + public AuthTokenHolder getAuthToken(String x_auth_token) { + AuthTokenHolder tokenHolder = null; + try { + com.opensds.jsonmodels.authtokensrequests.Auth auth = new com.opensds.jsonmodels.authtokensrequests.Auth(); + auth.setIdentity(new com.opensds.jsonmodels.authtokensrequests.Identity()); + auth.getIdentity().getMethods().add("token"); + auth.getIdentity().setToken(new com.opensds.jsonmodels.authtokensrequests.Token(x_auth_token)); + + auth.setScope(new Scope()); + auth.getScope().setProject(new Project()); + auth.getScope().getProject().setName("admin"); + auth.getScope().getProject().setDomain(new com.opensds.jsonmodels.authtokensrequests.Domain()); + auth.getScope().getProject().getDomain().setId("default"); + com.opensds.jsonmodels.authtokensrequests.AuthHolder authHolder = new com.opensds.jsonmodels + .authtokensrequests.AuthHolder(); + authHolder.setAuth(auth); + + Gson gson = new Gson(); + RequestBody requestBody = RequestBody.create(gson.toJson(authHolder), + MediaType.parse(CONTENT_TYPE_JSON_CHARSET)); + String url = ConstantUrl.getInstance().getTokenLogin(); + Logger.logString("URL: " + url); + Map headersMap = new HashMap<>(); + headersMap.put(CONTENT_TYPE, CONTENT_TYPE_JSON); + Headers headers = Headers.of(headersMap); + Response response = postCall(client, url, requestBody, headers); + String responseBody = response.body().string(); + Logger.logString("Response code: " + response.code()); + Logger.logString("Response body: " + responseBody); + tokenHolder = new com.opensds.jsonmodels.authtokensresponses.AuthTokenHolder(); + tokenHolder = gson.fromJson(responseBody, com.opensds.jsonmodels.authtokensresponses.AuthTokenHolder.class); + tokenHolder.setResponseHeaderSubjectToken(response.header(X_SUBJECT_TOKEN)); + } catch (Exception e) { + e.printStackTrace(); + } + return tokenHolder; + } + + public TypesHolder getTypes(String x_auth_token, String projId) { + TypesHolder typesHolder = null; + try { + Gson gson = new Gson(); + String url = ConstantUrl.getInstance().getTypesUrl(projId); + Logger.logString("URL: " + url); + Map headersMap = new HashMap<>(); + headersMap.put(CONTENT_TYPE, CONTENT_TYPE_JSON); + headersMap.put(X_AUTH_TOKEN, x_auth_token); + Headers headers = Headers.of(headersMap); + Response response = getCall(client, url, headers); + String responseBody = response.body().string(); + Logger.logString("Response code: " + response.code()); + Logger.logString("Response body: " + responseBody); + typesHolder = gson.fromJson(responseBody, TypesHolder.class); + } catch (Exception e) { + e.printStackTrace(); + } + return typesHolder; + } + + public int addBackend(String x_auth_token, String projId, AddBackendInputHolder inputHolder) { + int code = -1; + try { + Gson gson = new Gson(); + RequestBody requestBody = RequestBody.create(gson.toJson(inputHolder), + MediaType.parse(CONTENT_TYPE_JSON_CHARSET)); + String url = ConstantUrl.getInstance().getAddBackendUrl(projId); + Logger.logString("URL: " + url); + Map headersMap = new HashMap<>(); + headersMap.put(CONTENT_TYPE, CONTENT_TYPE_JSON); + headersMap.put(X_AUTH_TOKEN, x_auth_token); + Headers headers = Headers.of(headersMap); + Response response = postCall(client, url, requestBody, headers); + code = response.code(); + Logger.logString("Response code: " + code); + } catch (Exception e) { + e.printStackTrace(); + } + return code; + } + + public int createBucket(CreateBucketFileInput input, String bucketName, SignatureKey signatureKey) { + int code = -1; + try { + String url = ConstantUrl.getInstance().getCreateBucketUrl(bucketName); + RequestBody requestBody = RequestBody.create(input.getXmlPayload(), + MediaType.parse(CONTENT_TYPE_XML)); + String payload = BinaryUtils.toHex(BinaryUtils.hash(input.getXmlPayload())); + Response response = putCallResponse(client, url, payload, requestBody, signatureKey); + code = response.code(); + Logger.logString("Response Code: " + code); + Logger.logString("Response: " + response.body().string()); + } catch (Exception e) { + e.printStackTrace(); + } + return code; + } + + public Response getBuckets(SignatureKey signatureKey) { + String url = ConstantUrl.getInstance().getListBucketUrl(); + return getCallResponse(client, url, signatureKey); + } + + public int uploadObject(SignatureKey signatureKey, String bucketName, String fileName, File mFilePath) { + int code = -1; + try { + RequestBody requestBody = RequestBody.create(mFilePath, + MediaType.parse(CONTENT_TYPE_XML)); + String url = ConstantUrl.getInstance().getUploadObjectUrl(bucketName, fileName); + String payload = BinaryUtils.toHex(BinaryUtils.computeSHA256TreeHash(mFilePath)); + Response response = putCallResponse(client, url, payload, requestBody, signatureKey); + code = response.code(); + Logger.logString("Response Code: " + code); + Logger.logString("Response: " + response.body().string()); + } catch (Exception e) { + e.printStackTrace(); + } + return code; + } + + public Response getBucketObjects(String bucketName, SignatureKey signatureKey) { + String url = ConstantUrl.getInstance().getListOfBucketObjectUrl(bucketName); + return getCallResponse(client, url, signatureKey); + } + + public Response downloadObject(SignatureKey signatureKey, String bucketName, String fileName, String downloadFileName) { + Response response = null; + try { + String url = ConstantUrl.getInstance().getDownloadObjectUrl(bucketName, fileName); + response = getCallResponse(client, url, signatureKey); + int code = response.code(); + if (code == 200) { + BufferedSink sink = Okio.buffer(Okio.sink(new File(Constant.DOWNLOAD_FILES_PATH, downloadFileName))); + sink.writeAll(response.body().source()); + sink.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + return response; + } + + public Response getBackends(String xAuthToken, String tenantId) { + String url = ConstantUrl.getInstance().getBackendsUrl(tenantId); + return getCallWithXauth(client, url, xAuthToken); + } + + public Response getBackend(String xAuthToken, String tenantId, String id) { + String url = ConstantUrl.getInstance().getBackendUrl(tenantId, id); + return getCallWithXauth(client, url, xAuthToken); + } + + public Response getDeleteBackend(String xAuthToken, String tenantId, String id) { + String url = ConstantUrl.getInstance().getDeleteBackendUrl(tenantId, id); + return deleteCallWithXauth(client, url, xAuthToken); + } + + public Response deleteBucketNotEmpty(SignatureKey signatureKey, String bucketName) { + String url = ConstantUrl.getInstance().getDeleteBucketUrl(bucketName); + return deleteCallWithV4Sign(client, url, signatureKey); + } + + public Response deleteObject(SignatureKey signatureKey, String bucketName, String objectName) { + String url = ConstantUrl.getInstance().getDeleteObjectUrl(bucketName, objectName); + return deleteCallWithV4Sign(client, url, signatureKey); + } + + public Response deleteBucket(SignatureKey signatureKey, String bucketName) { + String url = ConstantUrl.getInstance().getDeleteBucketUrl(bucketName); + return deleteCallWithV4Sign(client, url, signatureKey); + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/AKSKHolder.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/AKSKHolder.java new file mode 100644 index 000000000..e9e44c36d --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/AKSKHolder.java @@ -0,0 +1,42 @@ +package com.opensds.jsonmodels.akskresponses; + +import com.google.gson.Gson; + +public class AKSKHolder { + + private Credentials[] credentials; + + private Links links; + + public Credentials[] getCredentials() { + return credentials; + } + + public void setCredentials(Credentials[] credentials) { + this.credentials = credentials; + } + + public Links getLinks() { + return links; + } + + public void setLinks(Links links) { + this.links = links; + } + + @Override + public String toString() { + Gson gson = new Gson(); + StringBuffer sb = new StringBuffer(); + sb.append("AKSKHolder [credentials = "); + for (Credentials c : credentials) { + c.blobObj = gson.fromJson(c.getblob(), Blob.class); + } + for (Credentials c : credentials) { + sb.append("\n\t"); + sb.append(c); + } + sb.append(", \nlinks = " + links + "]"); + return sb.toString(); + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/Blob.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/Blob.java new file mode 100644 index 000000000..345074ecc --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/Blob.java @@ -0,0 +1,37 @@ +package com.opensds.jsonmodels.akskresponses; + +public class Blob { + + + private String access; + + private String secret; + + + public String getAccess() { + return access; + } + + + public void setAccess(String access) { + this.access = access; + } + + + public String getSecret() { + return secret; + } + + + public void setSecret(String secret) { + this.secret = secret; + } + + @Override + public String toString() { + return "Blob{" + + "access='" + access + '\'' + + ", secret='" + secret + '\'' + + '}'; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/Credentials.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/Credentials.java new file mode 100644 index 000000000..335103f5b --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/Credentials.java @@ -0,0 +1,94 @@ +package com.opensds.jsonmodels.akskresponses; + +import com.google.gson.Gson; + +public class Credentials +{ + private String blob; + public Blob blobObj; + + private String user_id; + + private String project_id; + + private Links links; + + private String id; + + private String type; + + public String getblob () + { + return blob; + } + + public void setblob (String blob) + { + this.blob = blob; + Gson gson = new Gson(); + this.blobObj = gson.fromJson(this.blob, Blob.class); + System.out.println(this.blobObj); + } + + public String getUser_id () + { + return user_id; + } + + public void setUser_id (String user_id) + { + this.user_id = user_id; + } + + public String getProject_id () + { + return project_id; + } + + public void setProject_id (String project_id) + { + this.project_id = project_id; + } + + public Links getLinks () + { + return links; + } + + public void setLinks (Links links) + { + this.links = links; + } + + public String getId () + { + return id; + } + + public void setId (String id) + { + this.id = id; + } + + public String getType () + { + return type; + } + + public void setType (String type) + { + this.type = type; + } + + @Override + public String toString() + { + //System.out.println(blobObj); + return "Credential [blob = "+blobObj+", user_id = "+user_id+", project_id = "+project_id+", links = "+links+", id = "+id+", type = "+type+"]"; + } + + public Blob getBlobObj () + { + return blobObj; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/Links.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/Links.java new file mode 100644 index 000000000..01aa3c618 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/Links.java @@ -0,0 +1,22 @@ +package com.opensds.jsonmodels.akskresponses; + +public class Links +{ + private String self; + + public String getSelf () + { + return self; + } + + public void setSelf (String self) + { + this.self = self; + } + + @Override + public String toString() + { + return "Links [self = "+self+"]"; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/SignatureKey.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/SignatureKey.java new file mode 100644 index 000000000..73a8b1931 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/akskresponses/SignatureKey.java @@ -0,0 +1,70 @@ +package com.opensds.jsonmodels.akskresponses; + +public class SignatureKey { + String secretAccessKey; + String dateStamp; + String dayDate; + String regionName; + String serviceName; + String AccessKey; + + public String getSecretAccessKey() { + return secretAccessKey; + } + + public void setSecretAccessKey(String secretAccessKey) { + this.secretAccessKey = secretAccessKey; + } + + public String getDateStamp() { + return dateStamp; + } + + public void setDateStamp(String dateStamp) { + this.dateStamp = dateStamp; + } + + public String getDayDate() { + return dayDate; + } + + public void setDayDate(String dayDate) { + this.dayDate = dayDate; + } + + public String getRegionName() { + return regionName; + } + + public void setRegionName(String regionName) { + this.regionName = regionName; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getAccessKey() { + return AccessKey; + } + + public void setAccessKey(String accessKey) { + AccessKey = accessKey; + } + + @Override + public String toString() { + return "SignatureKey{" + + "secretAccessKey='" + secretAccessKey + '\'' + + ", dateStamp='" + dateStamp + '\'' + + ", dayDate='" + dayDate + '\'' + + ", regionName='" + regionName + '\'' + + ", serviceName='" + serviceName + '\'' + + ", AccessKey='" + AccessKey + '\'' + + '}'; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Auth.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Auth.java new file mode 100644 index 000000000..4acbeb80b --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Auth.java @@ -0,0 +1,38 @@ +package com.opensds.jsonmodels.authtokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Auth { + + @SerializedName("identity") + @Expose + private Identity identity; + @SerializedName("scope") + @Expose + private Scope scope; + + public Identity getIdentity() { + return identity; + } + + public void setIdentity(Identity identity) { + this.identity = identity; + } + + public Scope getScope() { + return scope; + } + + public void setScope(Scope scope) { + this.scope = scope; + } + + @Override + public String toString() { + return "Auth{" + + "identity=" + identity + + ", scope=" + scope + + '}'; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/AuthHolder.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/AuthHolder.java new file mode 100644 index 000000000..ccb980bb9 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/AuthHolder.java @@ -0,0 +1,26 @@ +package com.opensds.jsonmodels.authtokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class AuthHolder { + + @SerializedName("auth") + @Expose + private Auth auth; + + public Auth getAuth() { + return auth; + } + + public void setAuth(Auth auth) { + this.auth = auth; + } + + @Override + public String toString() { + return "AuthHolder{" + + "auth=" + auth + + '}'; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Domain.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Domain.java new file mode 100644 index 000000000..4193a4330 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Domain.java @@ -0,0 +1,26 @@ +package com.opensds.jsonmodels.authtokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Domain { + + @SerializedName("id") + @Expose + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String toString() { + return "Domain{" + + "id='" + id + '\'' + + '}'; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Identity.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Identity.java new file mode 100644 index 000000000..df8063179 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Identity.java @@ -0,0 +1,42 @@ +package com.opensds.jsonmodels.authtokensrequests; + + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; +import java.util.List; + +public class Identity { + + @SerializedName("methods") + @Expose + private List methods = new ArrayList<>(); + @SerializedName("token") + @Expose + private Token token; + + public List getMethods() { + return methods; + } + + public void setMethods(List methods) { + this.methods = methods; + } + + public Token getToken() { + return token; + } + + public void setToken(Token token) { + this.token = token; + } + + @Override + public String toString() { + return "Identity{" + + "methods=" + methods + + ", token=" + token + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Project.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Project.java new file mode 100644 index 000000000..006884b93 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Project.java @@ -0,0 +1,38 @@ +package com.opensds.jsonmodels.authtokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Project { + + @SerializedName("name") + @Expose + private String name; + @SerializedName("domain") + @Expose + private Domain domain; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Domain getDomain() { + return domain; + } + + public void setDomain(Domain domain) { + this.domain = domain; + } + + @Override + public String toString() { + return "Project{" + + "name='" + name + '\'' + + ", domain=" + domain + + '}'; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Scope.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Scope.java new file mode 100644 index 000000000..044993002 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Scope.java @@ -0,0 +1,26 @@ +package com.opensds.jsonmodels.authtokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Scope { + + @SerializedName("project") + @Expose + private Project project; + + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + + @Override + public String toString() { + return "Scope{" + + "project=" + project + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Token.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Token.java new file mode 100644 index 000000000..78b76fb58 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensrequests/Token.java @@ -0,0 +1,30 @@ +package com.opensds.jsonmodels.authtokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Token { + + @SerializedName("id") + @Expose + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String toString() { + return "Token{" + + "id='" + id + '\'' + + '}'; + } + + public Token(String id) { + this.id = id; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/AuthTokenHolder.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/AuthTokenHolder.java new file mode 100644 index 000000000..fc9cca6d3 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/AuthTokenHolder.java @@ -0,0 +1,37 @@ +package com.opensds.jsonmodels.authtokensresponses; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class AuthTokenHolder { + + String responseHeaderSubjectToken; + + @SerializedName("token") + @Expose + private Token token; + + public Token getToken() { + return token; + } + + public void setToken(Token token) { + this.token = token; + } + + @Override + public String toString() { + return "AuthTokenHolder{" + + "responseHeaderSubjectToken='" + responseHeaderSubjectToken + '\'' + + ", token=" + token + + '}'; + } + + public String getResponseHeaderSubjectToken() { + return responseHeaderSubjectToken; + } + + public void setResponseHeaderSubjectToken(String responseHeaderSubjectToken) { + this.responseHeaderSubjectToken = responseHeaderSubjectToken; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Catalog.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Catalog.java new file mode 100644 index 000000000..45ffb8e33 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Catalog.java @@ -0,0 +1,65 @@ +package com.opensds.jsonmodels.authtokensresponses; + + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class Catalog { + + @SerializedName("endpoints") + @Expose + private List endpoints = null; + @SerializedName("type") + @Expose + private String type; + @SerializedName("id") + @Expose + private String id; + @SerializedName("name") + @Expose + private String name; + + public List getEndpoints() { + return endpoints; + } + + public void setEndpoints(List endpoints) { + this.endpoints = endpoints; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Catalog{" + + "endpoints=" + endpoints + + ", type='" + type + '\'' + + ", id='" + id + '\'' + + ", name='" + name + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Domain.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Domain.java new file mode 100644 index 000000000..32ab1e093 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Domain.java @@ -0,0 +1,38 @@ +package com.opensds.jsonmodels.authtokensresponses; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Domain { + + @SerializedName("id") + @Expose + private String id; + @SerializedName("name") + @Expose + private String name; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Domain{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Domain_.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Domain_.java new file mode 100644 index 000000000..8503ea864 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Domain_.java @@ -0,0 +1,38 @@ +package com.opensds.jsonmodels.authtokensresponses; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Domain_ { + + @SerializedName("id") + @Expose + private String id; + @SerializedName("name") + @Expose + private String name; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Domain_{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Endpoint.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Endpoint.java new file mode 100644 index 000000000..9425e1878 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Endpoint.java @@ -0,0 +1,74 @@ +package com.opensds.jsonmodels.authtokensresponses; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Endpoint { + + @SerializedName("region_id") + @Expose + private String regionId; + @SerializedName("url") + @Expose + private String url; + @SerializedName("region") + @Expose + private String region; + @SerializedName("interface") + @Expose + private String _interface; + @SerializedName("id") + @Expose + private String id; + + public String getRegionId() { + return regionId; + } + + public void setRegionId(String regionId) { + this.regionId = regionId; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public String getInterface() { + return _interface; + } + + public void setInterface(String _interface) { + this._interface = _interface; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String toString() { + return "Endpoint{" + + "regionId='" + regionId + '\'' + + ", url='" + url + '\'' + + ", region='" + region + '\'' + + ", _interface='" + _interface + '\'' + + ", id='" + id + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Project.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Project.java new file mode 100644 index 000000000..91e1e9257 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Project.java @@ -0,0 +1,50 @@ +package com.opensds.jsonmodels.authtokensresponses; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Project { + + @SerializedName("domain") + @Expose + private Domain domain; + @SerializedName("id") + @Expose + private String id; + @SerializedName("name") + @Expose + private String name; + + public Domain getDomain() { + return domain; + } + + public void setDomain(Domain domain) { + this.domain = domain; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Project{" + + "domain=" + domain + + ", id='" + id + '\'' + + ", name='" + name + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Role.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Role.java new file mode 100644 index 000000000..5232c377b --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Role.java @@ -0,0 +1,38 @@ +package com.opensds.jsonmodels.authtokensresponses; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Role { + + @SerializedName("id") + @Expose + private String id; + @SerializedName("name") + @Expose + private String name; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "Role{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Token.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Token.java new file mode 100644 index 000000000..debe81b9d --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/Token.java @@ -0,0 +1,124 @@ +package com.opensds.jsonmodels.authtokensresponses; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class Token { + + @SerializedName("is_domain") + @Expose + private Boolean isDomain; + @SerializedName("methods") + @Expose + private List methods = null; + @SerializedName("roles") + @Expose + private List roles = null; + @SerializedName("expires_at") + @Expose + private String expiresAt; + @SerializedName("project") + @Expose + private Project project; + @SerializedName("catalog") + @Expose + private List catalog = null; + @SerializedName("user") + @Expose + private User user; + @SerializedName("audit_ids") + @Expose + private List auditIds = null; + @SerializedName("issued_at") + @Expose + private String issuedAt; + + public Boolean getIsDomain() { + return isDomain; + } + + public void setIsDomain(Boolean isDomain) { + this.isDomain = isDomain; + } + + public List getMethods() { + return methods; + } + + public void setMethods(List methods) { + this.methods = methods; + } + + public List getRoles() { + return roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } + + public String getExpiresAt() { + return expiresAt; + } + + public void setExpiresAt(String expiresAt) { + this.expiresAt = expiresAt; + } + + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } + + public List getCatalog() { + return catalog; + } + + public void setCatalog(List catalog) { + this.catalog = catalog; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public List getAuditIds() { + return auditIds; + } + + public void setAuditIds(List auditIds) { + this.auditIds = auditIds; + } + + public String getIssuedAt() { + return issuedAt; + } + + public void setIssuedAt(String issuedAt) { + this.issuedAt = issuedAt; + } + + @Override + public String toString() { + return "Token{" + + "isDomain=" + isDomain + + ", methods=" + methods + + ", roles=" + roles + + ", expiresAt='" + expiresAt + '\'' + + ", project=" + project + + ", catalog=" + catalog + + ", user=" + user + + ", auditIds=" + auditIds + + ", issuedAt='" + issuedAt + '\'' + + '}'; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/User.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/User.java new file mode 100644 index 000000000..70cbb6996 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/authtokensresponses/User.java @@ -0,0 +1,62 @@ +package com.opensds.jsonmodels.authtokensresponses; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class User { + + @SerializedName("password_expires_at") + @Expose + private Object passwordExpiresAt; + @SerializedName("domain") + @Expose + private Domain_ domain; + @SerializedName("id") + @Expose + private String id; + @SerializedName("name") + @Expose + private String name; + + public Object getPasswordExpiresAt() { + return passwordExpiresAt; + } + + public void setPasswordExpiresAt(Object passwordExpiresAt) { + this.passwordExpiresAt = passwordExpiresAt; + } + + public Domain_ getDomain() { + return domain; + } + + public void setDomain(Domain_ domain) { + this.domain = domain; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "User{" + + "passwordExpiresAt=" + passwordExpiresAt + + ", domain=" + domain + + ", id='" + id + '\'' + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/addbackend/AddBackendInputHolder.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/addbackend/AddBackendInputHolder.java new file mode 100644 index 000000000..d850cc127 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/addbackend/AddBackendInputHolder.java @@ -0,0 +1,68 @@ +package com.opensds.jsonmodels.inputs.addbackend; + +public class AddBackendInputHolder { + String name; + String type; + String region; + String endpoint; + String bucketName; + String security; + String access; + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public String getEndpoint() { + return endpoint; + } + + public void setEndpoint(String endpoint) { + this.endpoint = endpoint; + } + + public String getBucketName() { + return bucketName; + } + + public void setBucketName(String bucketName) { + this.bucketName = bucketName; + } + + public String getSecurity() { + return security; + } + + public void setSecurity(String security) { + this.security = security; + } + + public String getAccess() { + return access; + } + + public void setAccess(String access) { + this.access = access; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/addbackend/Backends.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/addbackend/Backends.java new file mode 100644 index 000000000..8a456bf25 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/addbackend/Backends.java @@ -0,0 +1,100 @@ +package com.opensds.jsonmodels.inputs.addbackend; + +public class Backends +{ + private String bucketName; + + private String endpoint; + + private String tenantId; + + private String name; + + private String id; + + private String type; + + private String region; + + private String userId; + + public String getBucketName () + { + return bucketName; + } + + public void setBucketName (String bucketName) + { + this.bucketName = bucketName; + } + + public String getEndpoint () + { + return endpoint; + } + + public void setEndpoint (String endpoint) + { + this.endpoint = endpoint; + } + + public String getTenantId () + { + return tenantId; + } + + public void setTenantId (String tenantId) + { + this.tenantId = tenantId; + } + + 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 String getType () + { + return type; + } + + public void setType (String type) + { + this.type = type; + } + + public String getRegion () + { + return region; + } + + public void setRegion (String region) + { + this.region = region; + } + + public String getUserId () + { + return userId; + } + + public void setUserId (String userId) + { + this.userId = userId; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/addbackend/BackendsInputHolder.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/addbackend/BackendsInputHolder.java new file mode 100644 index 000000000..98412e84c --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/addbackend/BackendsInputHolder.java @@ -0,0 +1,29 @@ +package com.opensds.jsonmodels.inputs.addbackend; + +import java.util.ArrayList; + +public class BackendsInputHolder +{ + private ArrayList backends; + private String next; + + public String getNext () + { + return next; + } + + public void setNext (String next) + { + this.next = next; + } + + public ArrayList getBackends () + { + return backends; + } + + public void setBackends (ArrayList backends) + { + this.backends = backends; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/createbucket/CreateBucketFileInput.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/createbucket/CreateBucketFileInput.java new file mode 100644 index 000000000..0406e28fc --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/createbucket/CreateBucketFileInput.java @@ -0,0 +1,37 @@ +package com.opensds.jsonmodels.inputs.createbucket; + +public class CreateBucketFileInput { + + private String xmlPayload; + private String xmlRequestTrue; + private String xmlRequestFalse; + + public String getXmlRequestFalse() { + return xmlRequestFalse; + } + + public void setXmlRequestFalse(String xmlRequestFalse) { + this.xmlRequestFalse = xmlRequestFalse; + } + + public String getXmlRequestTrue() { + return xmlRequestTrue; + } + + public void setXmlRequestTrue(String xmlRequestTrue) { + this.xmlRequestTrue = xmlRequestTrue; + } + + public String getXmlPayload() { + return xmlPayload; + } + + public void setXmlPayload(String xmlPayload) { + this.xmlPayload = xmlPayload; + } + + @Override + public String toString() { + return "CreateBucketFileInput [xmlPayload = " + xmlPayload + "]"; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/createbucket/uploadobjectinputfile.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/createbucket/uploadobjectinputfile.java new file mode 100644 index 000000000..4a915089a --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/inputs/createbucket/uploadobjectinputfile.java @@ -0,0 +1,19 @@ +package com.opensds.jsonmodels.inputs.createbucket; + +public class uploadobjectinputfile { + + private String xmlPayload; + + public String getXmlPayload() { + return xmlPayload; + } + + public void setXmlPayload(String xmlPayload) { + this.xmlPayload = xmlPayload; + } + + @Override + public String toString() { + return "uploadobjectinputfile [xmlPayload = " + xmlPayload + "]"; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Auth.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Auth.java new file mode 100644 index 000000000..53f7d2778 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Auth.java @@ -0,0 +1,25 @@ +package com.opensds.jsonmodels.logintokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Auth { + + @SerializedName("identity") + @Expose + private Identity identity; + + public Identity getIdentity() { + return identity; + } + + public void setIdentity(Identity identity) { + this.identity = identity; + } + + @Override + public String toString() { + return new StringBuilder().append("identity").append(identity).toString(); + } + +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/AuthHolder.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/AuthHolder.java new file mode 100644 index 000000000..5ef9d3a4e --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/AuthHolder.java @@ -0,0 +1,26 @@ +package com.opensds.jsonmodels.logintokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class AuthHolder { + + @SerializedName("auth") + @Expose + private Auth auth; + + public Auth getAuth() { + return auth; + } + + public void setAuth(Auth auth) { + this.auth = auth; + } + + @Override + public String toString() { + return "AuthHolder{" + + "auth=" + auth + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Domain.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Domain.java new file mode 100644 index 000000000..adf05c78a --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Domain.java @@ -0,0 +1,25 @@ +package com.opensds.jsonmodels.logintokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Domain { + + @SerializedName("name") + @Expose + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return new StringBuilder().append("name").append(name).toString(); + } + +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Identity.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Identity.java new file mode 100644 index 000000000..e2dde7e2c --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Identity.java @@ -0,0 +1,38 @@ +package com.opensds.jsonmodels.logintokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; +import java.util.List; + +public class Identity { + + @SerializedName("methods") + @Expose + private List methods = new ArrayList<>(); + @SerializedName("password") + @Expose + private Password password; + + public List getMethods() { + return methods; + } + + public void setMethods(List methods) { + this.methods = methods; + } + + public Password getPassword() { + return password; + } + + public void setPassword(Password password) { + this.password = password; + } + + @Override + public String toString() { + return new StringBuilder().append("methods").append(methods).append("password").append(password).toString(); + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Password.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Password.java new file mode 100644 index 000000000..6fc1d85cd --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/Password.java @@ -0,0 +1,25 @@ +package com.opensds.jsonmodels.logintokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Password { + + @SerializedName("user") + @Expose + private User user; + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + @Override + public String toString() { + return new StringBuilder().append("user").append(user).toString(); + } + +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/User.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/User.java new file mode 100644 index 000000000..38c4398c4 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/logintokensrequests/User.java @@ -0,0 +1,47 @@ +package com.opensds.jsonmodels.logintokensrequests; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class User { + + @SerializedName("name") + @Expose + private String name; + @SerializedName("domain") + @Expose + private Domain domain; + @SerializedName("password") + @Expose + private String password; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Domain getDomain() { + return domain; + } + + public void setDomain(Domain domain) { + this.domain = domain; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public String toString() { + return new StringBuilder().append("name").append(name).append("domain").append(domain).append("password").append(password).toString(); + } + +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/Domain.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/Domain.java new file mode 100644 index 000000000..896e7871b --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/Domain.java @@ -0,0 +1,38 @@ +package com.opensds.jsonmodels.tokensresponses; + +import com.google.gson.annotations.SerializedName; + +public class Domain { + + public @SerializedName("id") String id; + public @SerializedName("name") String name; + + public Domain(String id, String name) { + this.id = id; + this.name = name; + } + + public String getid() { + return id; + } + + public void setid(String id) { + this.id = id; + } + + public String getname() { + return name; + } + + public void setname(String name) { + this.name = name; + } + + @Override + public String toString() { + return "\n\tDomain{" + + "\n\t\tid='" + id + '\'' + + "\n\t\tname='" + name + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/Token.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/Token.java new file mode 100644 index 000000000..b47143da9 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/Token.java @@ -0,0 +1,75 @@ +package com.opensds.jsonmodels.tokensresponses; + +import java.util.List; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Token { + + @SerializedName("issued_at") + @Expose + String issuedAt; + @SerializedName("audit_ids") + @Expose + List auditIds = null; + @SerializedName("methods") + @Expose + List methods = null; + @SerializedName("expires_at") + @Expose + String expiresAt; + @SerializedName("user") + @Expose + User user; + + public String getIssuedAt() { + return issuedAt; + } + + public void setIssuedAt(String issuedAt) { + this.issuedAt = issuedAt; + } + + public List getAuditIds() { + return auditIds; + } + + public void setAuditIds(List auditIds) { + this.auditIds = auditIds; + } + + public List getMethods() { + return methods; + } + + public void setMethods(List methods) { + this.methods = methods; + } + + public String getExpiresAt() { + return expiresAt; + } + + public void setExpiresAt(String expiresAt) { + this.expiresAt = expiresAt; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + @Override + public String toString() { + return "\n\tToken{" + + "\n\t\tissuedAt='" + issuedAt + + "\n\t\tauditIds=" + auditIds + + "\n\t\tmethods=" + methods + + "\n\t\texpiresAt='" + expiresAt + + "\n\t\tuser=" + user + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/TokenHolder.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/TokenHolder.java new file mode 100644 index 000000000..1b3b061e6 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/TokenHolder.java @@ -0,0 +1,37 @@ +package com.opensds.jsonmodels.tokensresponses; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class TokenHolder { + + String responseHeaderSubjectToken; + + @SerializedName("token") + @Expose + Token token; + + public Token getToken() { + return token; + } + + public void setToken(Token token) { + this.token = token; + } + + @Override + public String toString() { + return "\n\tTokenHolder{" + + "\n\t\ttoken=" + token + + "\n\treqHeaderToken=" + responseHeaderSubjectToken; + + } + + public String getResponseHeaderSubjectToken() { + return responseHeaderSubjectToken; + } + + public void setResponseHeaderSubjectToken(String responseHeaderSubjectToken) { + this.responseHeaderSubjectToken = responseHeaderSubjectToken; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/User.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/User.java new file mode 100644 index 000000000..b92c7c435 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/tokensresponses/User.java @@ -0,0 +1,62 @@ +package com.opensds.jsonmodels.tokensresponses; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class User { + + @SerializedName("password_expires_at") + @Expose + Object passwordExpiresAt; + @SerializedName("domain") + @Expose + Domain domainHolder; + @SerializedName("id") + @Expose + String id; + @SerializedName("name") + @Expose + String name; + + public Object getPasswordExpiresAt() { + return passwordExpiresAt; + } + + public void setPasswordExpiresAt(Object passwordExpiresAt) { + this.passwordExpiresAt = passwordExpiresAt; + } + + public Domain getDomainHolder() { + return domainHolder; + } + + public void setDomainHolder(Domain domainHolder) { + this.domainHolder = domainHolder; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "\n\tUser{" + + "\n\t\tpasswordExpiresAt=" + passwordExpiresAt + + "\n\t\tdomain=" + domainHolder + + "\n\t\tid='" + id + '\'' + + "\n\t\tname='" + name + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/typesresponse/Type.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/typesresponse/Type.java new file mode 100644 index 000000000..2830deef8 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/typesresponse/Type.java @@ -0,0 +1,38 @@ +package com.opensds.jsonmodels.typesresponse; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Type { + + @SerializedName("name") + @Expose + private String name; + @SerializedName("description") + @Expose + private String description; + + 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; + } + + @Override + public String toString() { + return "Type{" + + "name='" + name + '\'' + + ", description='" + description + '\'' + + '}'; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/typesresponse/TypesHolder.java b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/typesresponse/TypesHolder.java new file mode 100644 index 000000000..32195ddeb --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/jsonmodels/typesresponse/TypesHolder.java @@ -0,0 +1,40 @@ +package com.opensds.jsonmodels.typesresponse; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class TypesHolder { + + @SerializedName("types") + @Expose + private List types = null; + @SerializedName("next") + @Expose + private Integer next; + + public List getTypes() { + return types; + } + + public void setTypes(List types) { + this.types = types; + } + + public Integer getNext() { + return next; + } + + public void setNext(Integer next) { + this.next = next; + } + + @Override + public String toString() { + return "TypesHolder{" + + "types=" + types + + ", next=" + next + + '}'; + } +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/utils/BinaryUtils.java b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/BinaryUtils.java new file mode 100644 index 000000000..c99f08e13 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/BinaryUtils.java @@ -0,0 +1,202 @@ +package com.opensds.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Locale; + +/** + * Utilities for encoding and decoding binary data to and from different forms. + */ +public class BinaryUtils { + static final int ONE_MB = 1024 * 1024; + + /** + * Converts byte data to a Hex-encoded string. + * + * @param data + * data to hex encode. + * + * @return hex-encoded string. + */ + public static String toHex(byte[] data) { + StringBuilder sb = new StringBuilder(data.length * 2); + for (int i = 0; i < data.length; i++) { + String hex = Integer.toHexString(data[i]); + if (hex.length() == 1) { + // Append leading zero. + sb.append("0"); + } else if (hex.length() == 8) { + // Remove ff prefix from negative numbers. + hex = hex.substring(6); + } + sb.append(hex); + } + return sb.toString().toLowerCase(Locale.getDefault()); + } + + /** + * Converts a Hex-encoded data string to the original byte data. + * + * @param hexData + * hex-encoded data to decode. + * @return decoded data from the hex string. + */ + public static byte[] fromHex(String hexData) { + byte[] result = new byte[(hexData.length() + 1) / 2]; + String hexNumber = null; + int stringOffset = 0; + int byteOffset = 0; + while (stringOffset < hexData.length()) { + hexNumber = hexData.substring(stringOffset, stringOffset + 2); + stringOffset += 2; + result[byteOffset++] = (byte) Integer.parseInt(hexNumber, 16); + } + return result; + } + + /** + * Hashes the string contents (assumed to be UTF-8) using the SHA-256 + * algorithm. + */ + public static byte[] hash(String text) { + try { + MessageDigest md = MessageDigest.getInstance("SHA-256"); + md.update(text.getBytes("UTF-8")); + return md.digest(); + } catch (Exception e) { + throw new RuntimeException("Unable to compute hash while signing request: " + e.getMessage(), e); + } + } + + /** + * Computes the SHA-256 tree hash for the given file + * + * @param inputFile + * a File to compute the SHA-256 tree hash for + * @return a byte[] containing the SHA-256 tree hash + * @throws IOException + * Thrown if there's an issue reading the input file + * @throws NoSuchAlgorithmException + */ + public static byte[] computeSHA256TreeHash(File inputFile) throws IOException, + NoSuchAlgorithmException { + + byte[][] chunkSHA256Hashes = getChunkSHA256Hashes(inputFile); + return computeSHA256TreeHash(chunkSHA256Hashes); + } + + /** + * Computes a SHA256 checksum for each 1 MB chunk of the input file. This + * includes the checksum for the last chunk even if it is smaller than 1 MB. + * + * @param file + * A file to compute checksums on + * @return a byte[][] containing the checksums of each 1 MB chunk + * @throws IOException + * Thrown if there's an IOException when reading the file + * @throws NoSuchAlgorithmException + * Thrown if SHA-256 MessageDigest can't be found + */ + public static byte[][] getChunkSHA256Hashes(File file) throws IOException, + NoSuchAlgorithmException { + + MessageDigest md = MessageDigest.getInstance("SHA-256"); + + long numChunks = file.length() / ONE_MB; + if (file.length() % ONE_MB > 0) { + numChunks++; + } + + if (numChunks == 0) { + return new byte[][] { md.digest() }; + } + + byte[][] chunkSHA256Hashes = new byte[(int) numChunks][]; + FileInputStream fileStream = null; + + try { + fileStream = new FileInputStream(file); + byte[] buff = new byte[ONE_MB]; + + int bytesRead; + int idx = 0; + + while ((bytesRead = fileStream.read(buff, 0, ONE_MB)) > 0) { + md.reset(); + md.update(buff, 0, bytesRead); + chunkSHA256Hashes[idx++] = md.digest(); + } + + return chunkSHA256Hashes; + + } finally { + if (fileStream != null) { + try { + fileStream.close(); + } catch (IOException ioe) { + System.err.printf("Exception while closing %s.\n %s", file.getName(), + ioe.getMessage()); + } + } + } + } + + /** + * Computes the SHA-256 tree hash for the passed array of 1 MB chunk + * checksums. + * + * This method uses a pair of arrays to iteratively compute the tree hash + * level by level. Each iteration takes two adjacent elements from the + * previous level source array, computes the SHA-256 hash on their + * concatenated value and places the result in the next level's destination + * array. At the end of an iteration, the destination array becomes the + * source array for the next level. + * + * @param chunkSHA256Hashes + * An array of SHA-256 checksums + * @return A byte[] containing the SHA-256 tree hash for the input chunks + * @throws NoSuchAlgorithmException + * Thrown if SHA-256 MessageDigest can't be found + */ + public static byte[] computeSHA256TreeHash(byte[][] chunkSHA256Hashes) + throws NoSuchAlgorithmException { + + MessageDigest md = MessageDigest.getInstance("SHA-256"); + + byte[][] prevLvlHashes = chunkSHA256Hashes; + + while (prevLvlHashes.length > 1) { + + int len = prevLvlHashes.length / 2; + if (prevLvlHashes.length % 2 != 0) { + len++; + } + + byte[][] currLvlHashes = new byte[len][]; + + int j = 0; + for (int i = 0; i < prevLvlHashes.length; i = i + 2, j++) { + + // If there are at least two elements remaining + if (prevLvlHashes.length - i > 1) { + + // Calculate a digest of the concatenated nodes + md.reset(); + md.update(prevLvlHashes[i]); + md.update(prevLvlHashes[i + 1]); + currLvlHashes[j] = md.digest(); + + } else { // Take care of remaining odd chunk + currLvlHashes[j] = prevLvlHashes[i]; + } + } + + prevLvlHashes = currLvlHashes; + } + + return prevLvlHashes[0]; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/utils/Constant.java b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/Constant.java new file mode 100644 index 000000000..f28ba7341 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/Constant.java @@ -0,0 +1,9 @@ +package com.opensds.utils; + +public class Constant { + public static final String PATH = System.getenv("INPUT_PATH")+"/src/main/resources/inputs/"; + public static final String CREATE_BUCKET_PATH = PATH+"createbucket"; + public static final String EMPTY_FIELD_PATH = PATH+"emptyfield/"; + public static final String RAW_DATA_PATH = PATH+"rawdata"; + public static final String DOWNLOAD_FILES_PATH = PATH+"download"; +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/utils/ConstantUrl.java b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/ConstantUrl.java new file mode 100644 index 000000000..6f1ea5746 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/ConstantUrl.java @@ -0,0 +1,170 @@ +package com.opensds.utils; + +public class ConstantUrl { + private static ConstantUrl mConstantUrl; + private static String URL = null; + private static String PORT_TENANT_ID = null; + private static String PORT = null; + + private ConstantUrl() { + PORT_TENANT_ID = getPortTenantId(); + PORT = getPort(); + URL = getHostIp(); + } + + public static ConstantUrl getInstance() { + Logger.logString("**********************************************************************"); + if (mConstantUrl == null) { + mConstantUrl = new ConstantUrl(); + } + return mConstantUrl; + } + + /** + * Get port: This port used in there is used tenant id url + */ + public String getPortTenantId() { + return System.getenv("PORT_TENANT_ID"); + } + + /** + * Get Port: This port used in S3 services url except login or auth related url. + */ + public String getPort() { + return System.getenv("PORT"); + } + + /** + * Get Host Ip. + */ + public String getHostIp() { + return "http://" + System.getenv("HOST_IP"); + } + + /** + * Get Token Login. + */ + public String getTokenLogin() { + return URL +"/identity/v3/auth/tokens"; + } + + /** + * Get aks list. + * + * @param userId user id. + */ + public String getAksList(String userId) { + return URL +"/identity/v3/credentials?userId="+userId+"&type=ec2"; + } + + /** + * Get Types + * + * @param tenantId tenant id. + */ + public String getTypesUrl(String tenantId) { + return URL+PORT_TENANT_ID+"/"+tenantId+"/types"; + } + + /** + * Add Backend + * + * @param tenantId admin tenant id. + */ + public String getAddBackendUrl(String tenantId) { + return URL+PORT_TENANT_ID+"/"+ tenantId +"/backends"; + } + + /** + * Create Bucket + * + * @param bucketName bucket name. + */ + public String getCreateBucketUrl(String bucketName) { + return URL+PORT+"/"+ bucketName; + } + + /** + * Bucket List + */ + public String getListBucketUrl() { + return URL+PORT+"/"; + } + + /** + * Upload object + * + * @param bucketName bucket name. + * @param fileName file name. + */ + public String getUploadObjectUrl(String bucketName, String fileName) { + return URL+PORT+"/"+ bucketName +"/"+ fileName; + } + + /** + * Get list of bucket object. + * + * @param bucketName bucket name + */ + public String getListOfBucketObjectUrl(String bucketName) { + return URL+PORT+"/"+bucketName; + } + + /** + * Download object + * + * @param bucketName bucket name. + * @param fileName file name. + */ + public String getDownloadObjectUrl(String bucketName, String fileName) { + return URL+PORT+"/"+ bucketName +"/"+ fileName; + } + + /** + * Get Backend List + * + * @param tenantId tenant id. + */ + public String getBackendsUrl(String tenantId) { + return URL+PORT_TENANT_ID+"/"+tenantId+"/backends"; + } + + /** + * Get Backend + * + * @param tenantId tenant id. + * @param id admin tenant id. + */ + public String getBackendUrl(String tenantId, String id) { + return URL+PORT_TENANT_ID+"/"+tenantId+"/backends/"+id; + } + + /** + * Delete Backend + * + * @param tenantId tenant id. + * @param id admin tenant id. + */ + public String getDeleteBackendUrl(String tenantId, String id) { + return URL+PORT_TENANT_ID+"/"+tenantId+"/backends/"+id; + } + + /** + * Delete bucket + * + * @param bucketName bucket name. + */ + public String getDeleteBucketUrl(String bucketName) { + return URL+PORT+"/"+ bucketName; + } + + /** + * Delete object + * + * @param bucketName bucket name. + * @param objectName object name. + */ + public String getDeleteObjectUrl(String bucketName, String objectName) { + return URL+PORT+"/"+bucketName+"/"+objectName; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/utils/HeadersName.java b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/HeadersName.java new file mode 100644 index 000000000..f5ced627b --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/HeadersName.java @@ -0,0 +1,14 @@ +package com.opensds.utils; + +public class HeadersName { + public static final String AUTHORIZATION = "Authorization"; + public static final String CONTENT_TYPE = "Content-Type"; + public static final String CONTENT_TYPE_XML = "application/xml"; + public static final String CONTENT_TYPE_JSON = "application/json"; + public static final String X_AMZ_DATE = "X-Amz-Date"; + public static final String X_AMZ_CONTENT_SHA256 = "x-amz-content-sha256"; + public static final String X_AUTH_TOKEN = "x-auth-token"; + public static final String HOST = "Host"; + public static final String X_SUBJECT_TOKEN = "X-Subject-Token"; + public static final String CONTENT_TYPE_JSON_CHARSET = "application/json; charset=utf-8"; +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/utils/Logger.java b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/Logger.java new file mode 100644 index 000000000..67f0dc038 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/Logger.java @@ -0,0 +1,41 @@ +package com.opensds.utils; + +public class Logger { + + /** + * Print log in string. + * + * @param message Message + */ + public static void logString(String message) { + System.out.println(message); + } + + + /** + * Print log in int. + * + * @param message Message + */ + public static void logInt(Integer message) { + System.out.println(message); + } + + /** + * Print log in double. + * + * @param message Message + */ + public static void logDouble(Double message) { + System.out.println(message); + } + + /** + * Print log in object. + * + * @param message Message + */ + public static void logObject(Object message) { + System.out.println(message); + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/utils/TextUtils.java b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/TextUtils.java new file mode 100644 index 000000000..2f11c89c0 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/TextUtils.java @@ -0,0 +1,12 @@ +package com.opensds.utils; + +public class TextUtils { + /** + * Returns true if the string is null or 0-length. + * @param str the string to be examined + * @return true if str is null or zero length + */ + public static boolean isEmpty(CharSequence str) { + return str == null || str.length() == 0; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/utils/Utils.java b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/Utils.java new file mode 100644 index 000000000..84da66365 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/Utils.java @@ -0,0 +1,101 @@ +package com.opensds.utils; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.text.SimpleDateFormat; +import java.util.*; + +public class Utils { + + /** + * format strings for the date/time and date stamps required during signing + **/ + public static final String ISO8601BasicFormat = "yyyyMMdd'T'HHmmss'Z'"; + + /** + * Get List of files + * + * @param beginPattern begin pattern (bucket) e.g: bucket_b237 + * @param path folder path e.g: resource/inputs + * @return list of files + */ + public static List listFilesMatchingBeginsWithPatternInPath(final String beginPattern, String path) { + List retFileList = new ArrayList<>(); + try { + File dir = new File(path); + assert dir.isDirectory() : "Invalid directory path: "+path; + File[] files = dir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.matches("^" + beginPattern + "+[a-z_1-9-]*.json"); + } + }); + + for (File xmlfile : files) { + retFileList.add(xmlfile); + } + } catch (Exception e) { + e.printStackTrace(); + } + return retFileList; + } + + /** + * Read file content. + * + * @param file file. + * @return file content. + */ + public static String readFileContentsAsString(File file) { + String content = null; + try { + content = new String(Files.readAllBytes(file.toPath())); + } catch (IOException e) { + e.printStackTrace(); + } + return content; + } + + /** + * Get Bucket Name. + * + * @param bucketFile file path + * @return bucket name + */ + public static String getBucketName(File bucketFile){ + return bucketFile.getName().substring(bucketFile.getName().indexOf("_") + 1, + bucketFile.getName().indexOf(".")); + } + + /** + * Get date. + * + * @return date. + */ + public static String getDate() { + Date now = new Date(); + SimpleDateFormat dateTimeFormat = new SimpleDateFormat(ISO8601BasicFormat); + dateTimeFormat.setTimeZone(new SimpleTimeZone(0, "UTC")); + return dateTimeFormat.format(now); + } + + /** + * Get Host + * + * @param url url e.g: http://192.168.34.45:6566 + * @return host e.g: 192.168.34.45:6566 + */ + public static String getHost(String url){ + String host = null; + try { + host = new URI(url).getHost()+":"+new URI(url).getPort(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return host; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/utils/okhttputils/OkHttpRequests.java b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/okhttputils/OkHttpRequests.java new file mode 100644 index 000000000..474bf357a --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/okhttputils/OkHttpRequests.java @@ -0,0 +1,211 @@ +package com.opensds.utils.okhttputils; + +import com.opensds.jsonmodels.akskresponses.SignatureKey; +import com.opensds.utils.*; +import com.opensds.utils.signature.SodaV4Signer; +import okhttp3.*; +import uk.co.lucasweb.aws.v4.signer.Header; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import static com.opensds.utils.HeadersName.*; + +public abstract class OkHttpRequests { + + /** + * Put Call + * + * @param client OkHttpClient object + * @param url url + * @param requestBody RequestBody object + * @param headers Headers + * @return response + * @throws IOException io exception + */ + protected static Response putCall(OkHttpClient client, String url, RequestBody requestBody, + Headers headers) throws IOException { + Request request = new Request.Builder() + .url(url) + .put(requestBody) + .headers(headers) + .build(); + Logger.logString("Request Details: " + request.headers() + " " + request.body() + " " + request.method() + "" + + request.url()); + return client.newCall(request).execute(); + } + + /** + * Post Call + * + * @param client OkHttpClient object + * @param url url + * @param requestBody RequestBody object + * @param headers Headers + * @return Response + * @throws IOException IO Exception + */ + protected static Response postCall(OkHttpClient client, String url, RequestBody requestBody, + Headers headers) throws IOException { + Request request = new Request.Builder() + .url(url) + .post(requestBody) + .headers(headers) + .build(); + Logger.logString("Request Details: " + request.headers() + " " + request.body() + " " + request.method() + "" + + request.url()); + return client.newCall(request).execute(); + } + + /** + * Get Call + * + * @param client OkHttpClient + * @param url URL + * @param headers Headers + * @return Response + * @throws IOException IO Exception + */ + protected static Response getCall(OkHttpClient client, String url, + Headers headers) throws IOException { + Request request = new Request.Builder() + .url(url) + .get() + .headers(headers) + .build(); + Logger.logString("Request Details: " + request.headers() + " " + request.body() + " " + request.method() + "" + + request.url()); + return client.newCall(request).execute(); + } + + /** + * Delete Call + * + * @param client OkHttpClient + * @param url URL + * @param headers Headers + * @return Response + * @throws IOException IO Exception + */ + protected static Response deleteCall(OkHttpClient client, String url, + Headers headers) throws IOException { + Request request = new Request.Builder() + .url(url) + .delete() + .headers(headers) + .build(); + Logger.logString("Request Details: " + request.headers() + " " + request.body() + " " + request.method() + "" + + request.url()); + return client.newCall(request).execute(); + } + + protected static Response getCallResponse(OkHttpClient client, String url, SignatureKey signatureKey) { + Response response = null; + String payload = BinaryUtils.toHex(BinaryUtils.hash("")); + String date = Utils.getDate(); + Logger.logString("URL: " + url); + String host = Utils.getHost(url); + Header[] signHeaders = new Header[]{new Header(HOST, host), + new Header(X_AMZ_DATE, date), + new Header(X_AMZ_CONTENT_SHA256, payload)}; + String authorization = SodaV4Signer.getSignature("GET", url, signatureKey.getAccessKey(), + signatureKey.getSecretAccessKey(), payload, signatureKey.getRegionName(), signHeaders); + Logger.logString("Authorization: " + authorization); + Map headersMap = new HashMap<>(); + headersMap.put(AUTHORIZATION, authorization); + headersMap.put(X_AMZ_CONTENT_SHA256, payload); + headersMap.put(X_AMZ_DATE, date); + Headers headers = Headers.of(headersMap); + try { + response = getCall(client, url, headers); + } catch (Exception e) { + e.printStackTrace(); + } + return response; + } + + protected static Response putCallResponse(OkHttpClient client, String url, + String payload, RequestBody requestBody, + SignatureKey signatureKey) { + Response response = null; + + String date = Utils.getDate(); + Logger.logString("URL: " + url); + String host = Utils.getHost(url); + Header[] signHeaders = new Header[]{new Header(HOST, host), + new Header(X_AMZ_DATE, date), + new Header(X_AMZ_CONTENT_SHA256, payload)}; + String authorization = SodaV4Signer.getSignature("PUT", url, signatureKey.getAccessKey(), + signatureKey.getSecretAccessKey(), payload, signatureKey.getRegionName(), signHeaders); + Logger.logString("Authorization: " + authorization); + Map headersMap = new HashMap<>(); + headersMap.put(HOST, host); + headersMap.put(AUTHORIZATION, authorization); + headersMap.put(X_AMZ_CONTENT_SHA256, payload); + headersMap.put(CONTENT_TYPE, CONTENT_TYPE_XML); + headersMap.put(X_AMZ_DATE, date); + Headers headers = Headers.of(headersMap); + try { + response = putCall(client, url, requestBody, headers); + } catch (IOException e) { + e.printStackTrace(); + } + return response; + } + + protected static Response getCallWithXauth(OkHttpClient client, String url, String xAuthToken){ + Response response = null; + Logger.logString("URL: "+url); + Map headersMap = new HashMap<>(); + headersMap.put(X_AUTH_TOKEN, xAuthToken); + headersMap.put(CONTENT_TYPE, CONTENT_TYPE_JSON); + Headers headers = Headers.of(headersMap); + try { + response = getCall(client, url, headers); + } catch (Exception e) { + e.printStackTrace(); + } + return response; + } + + protected static Response deleteCallWithXauth(OkHttpClient client, String url, String xAuthToken){ + Response response = null; + Logger.logString("URL: "+url); + Map headersMap = new HashMap<>(); + headersMap.put(X_AUTH_TOKEN, xAuthToken); + headersMap.put(CONTENT_TYPE, CONTENT_TYPE_JSON); + Headers headers = Headers.of(headersMap); + try { + response = deleteCall(client, url, headers); + } catch (Exception e) { + e.printStackTrace(); + } + return response; + } + + protected static Response deleteCallWithV4Sign(OkHttpClient client, String url, SignatureKey signatureKey) { + Response response = null; + String payload = BinaryUtils.toHex(BinaryUtils.hash("")); + String date = Utils.getDate(); + Logger.logString("URL: " + url); + String host = Utils.getHost(url); + Header[] signHeaders = new Header[]{new Header(HOST, host), + new Header(X_AMZ_DATE, date), + new Header(X_AMZ_CONTENT_SHA256, payload)}; + String authorization = SodaV4Signer.getSignature("DELETE", url, signatureKey.getAccessKey(), + signatureKey.getSecretAccessKey(), payload, signatureKey.getRegionName(), signHeaders); + Logger.logString("Authorization: " + authorization); + Map headersMap = new HashMap<>(); + headersMap.put(AUTHORIZATION, authorization); + headersMap.put(X_AMZ_CONTENT_SHA256, payload); + headersMap.put(X_AMZ_DATE, date); + Headers headers = Headers.of(headersMap); + try { + response = deleteCall(client, url, headers); + } catch (Exception e) { + e.printStackTrace(); + } + return response; + } +} diff --git a/testhelper/open-sds-junit/src/main/java/com/opensds/utils/signature/SodaV4Signer.java b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/signature/SodaV4Signer.java new file mode 100644 index 000000000..fe8a2741c --- /dev/null +++ b/testhelper/open-sds-junit/src/main/java/com/opensds/utils/signature/SodaV4Signer.java @@ -0,0 +1,41 @@ +package com.opensds.utils.signature; + +import uk.co.lucasweb.aws.v4.signer.Header; +import uk.co.lucasweb.aws.v4.signer.HttpRequest; +import uk.co.lucasweb.aws.v4.signer.Signer; +import uk.co.lucasweb.aws.v4.signer.credentials.AwsCredentials; + +import java.net.URI; +import java.net.URISyntaxException; + +public class SodaV4Signer { + + /** + * Generate v4 Signature. + * + * @param method Method name e.g GET + * @param url URL e.g https://www.opensds.io/ + * @param accessKey Access key get from AKSK API + * @param secretKey Secret key get from AKSK API + * @param payload Request body converted in to SHA265 + * @param regionName Region name + * @param headers Headers + * @return Signature + */ + public static String getSignature(String method, String url, + String accessKey, String secretKey, + String payload, String regionName, Header... headers) { + HttpRequest httpRequest = null; + try { + httpRequest = new HttpRequest(method, new URI(url)); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return Signer.builder() + .awsCredentials(new AwsCredentials(accessKey, secretKey)) + .region(regionName) + .headers(headers) + .buildS3(httpRequest, payload) + .getSignature(); + } +} diff --git a/testhelper/open-sds-junit/src/main/resources/inputs/createbucket/bucket_b13876524.json b/testhelper/open-sds-junit/src/main/resources/inputs/createbucket/bucket_b13876524.json new file mode 100644 index 000000000..ed3148128 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/resources/inputs/createbucket/bucket_b13876524.json @@ -0,0 +1,5 @@ +{ + "xmlRequestFalse":" falsefalsestring", + "xmlRequestTrue":" truefalsestring", + "xmlPayload":"ibm-back0056" +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/resources/inputs/createbucket/ibm-cos_b1321.json b/testhelper/open-sds-junit/src/main/resources/inputs/createbucket/ibm-cos_b1321.json new file mode 100644 index 000000000..2c16d138b --- /dev/null +++ b/testhelper/open-sds-junit/src/main/resources/inputs/createbucket/ibm-cos_b1321.json @@ -0,0 +1,9 @@ +{ + "name": "************", + "type": "************", + "region": "************", + "endpoint": "************", + "bucketName": "************", + "security": "************", + "access": "*************" +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/resources/inputs/emptyfield/bucket_b1324.json b/testhelper/open-sds-junit/src/main/resources/inputs/emptyfield/bucket_b1324.json new file mode 100644 index 000000000..d8ae96d61 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/resources/inputs/emptyfield/bucket_b1324.json @@ -0,0 +1,3 @@ +{ + "xmlPayload":"hdgftr4664" +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/resources/inputs/emptyfield/bucket_emptyvalue.json b/testhelper/open-sds-junit/src/main/resources/inputs/emptyfield/bucket_emptyvalue.json new file mode 100644 index 000000000..a00c2c861 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/resources/inputs/emptyfield/bucket_emptyvalue.json @@ -0,0 +1,3 @@ +{ + "xmlPayload":"" +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/resources/inputs/emptyfield/ibm-cos_b1321.json b/testhelper/open-sds-junit/src/main/resources/inputs/emptyfield/ibm-cos_b1321.json new file mode 100644 index 000000000..02ad01ad8 --- /dev/null +++ b/testhelper/open-sds-junit/src/main/resources/inputs/emptyfield/ibm-cos_b1321.json @@ -0,0 +1,9 @@ +{ + "name": "", + "type": "", + "region": "", + "endpoint": "", + "bucketName": "", + "security": "", + "access": "" +} \ No newline at end of file diff --git a/testhelper/open-sds-junit/src/main/resources/inputs/rawdata/Screenshot_1.jpg b/testhelper/open-sds-junit/src/main/resources/inputs/rawdata/Screenshot_1.jpg new file mode 100644 index 000000000..0fd5f53f9 Binary files /dev/null and b/testhelper/open-sds-junit/src/main/resources/inputs/rawdata/Screenshot_1.jpg differ diff --git a/testhelper/open-sds-junit/src/test/java/CreateBucketBackendTest.java b/testhelper/open-sds-junit/src/test/java/CreateBucketBackendTest.java new file mode 100644 index 000000000..f40b28a59 --- /dev/null +++ b/testhelper/open-sds-junit/src/test/java/CreateBucketBackendTest.java @@ -0,0 +1,864 @@ +import com.google.gson.Gson; +import com.opensds.HttpHandler; +import com.opensds.jsonmodels.akskresponses.SignatureKey; +import com.opensds.jsonmodels.authtokensresponses.AuthTokenHolder; +import com.opensds.jsonmodels.inputs.addbackend.AddBackendInputHolder; +import com.opensds.jsonmodels.inputs.addbackend.Backends; +import com.opensds.jsonmodels.inputs.addbackend.BackendsInputHolder; +import com.opensds.jsonmodels.inputs.createbucket.CreateBucketFileInput; +import com.opensds.jsonmodels.tokensresponses.TokenHolder; +import com.opensds.jsonmodels.typesresponse.Type; +import com.opensds.jsonmodels.typesresponse.TypesHolder; +import com.opensds.utils.Constant; +import com.opensds.utils.Logger; +import com.opensds.utils.TextUtils; +import com.opensds.utils.Utils; +import okhttp3.Response; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.XML; +import org.junit.jupiter.api.*; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.*; + +// how to get POJO from any response JSON, use this site +// http://pojo.sodhanalibrary.com/ + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class CreateBucketBackendTest { + + public static AuthTokenHolder getAuthTokenHolder() { + return mAuthTokenHolder; + } + + public TypesHolder getTypesHolder() { + return mTypesHolder; + } + + public static HttpHandler getHttpHandler() { + return mHttpHandler; + } + + private static AuthTokenHolder mAuthTokenHolder = null; + private static TypesHolder mTypesHolder = null; + private static HttpHandler mHttpHandler = new HttpHandler(); + + @org.junit.jupiter.api.BeforeAll + static void setUp() { + TokenHolder tokenHolder = getHttpHandler().loginAndGetToken(); + mAuthTokenHolder = getHttpHandler().getAuthToken(tokenHolder.getResponseHeaderSubjectToken()); + mTypesHolder = getHttpHandler().getTypes(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + } + + @Test + @Order(1) + @DisplayName("Test creating bucket and backend on OPENSDS") + public void testCreateBucketAndBackend() throws IOException, JSONException { + // load input files for each type and create the backend + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + Gson gson = new Gson(); + // add the backend specified in each file + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + + AddBackendInputHolder inputHolder = gson.fromJson(content, AddBackendInputHolder.class); + int code = getHttpHandler().addBackend(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId(), + inputHolder); + assertEquals(code, 200); + + // backend added, now create buckets + List listOfIBucketInputs = + Utils.listFilesMatchingBeginsWithPatternInPath("bucket", + Constant.CREATE_BUCKET_PATH); + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + // create the bucket specified in each file + for (File bucketFile : listOfIBucketInputs) { + String bucketContent = Utils.readFileContentsAsString(bucketFile); + assertNotNull(bucketContent); + + CreateBucketFileInput bfi = gson.fromJson(bucketContent, CreateBucketFileInput.class); + + // filename format is "bucket_.json", get the bucket name here + String bName = Utils.getBucketName(bucketFile); + + // now create buckets + int cbCode = getHttpHandler().createBucket(bfi, bName, signatureKey); + assertEquals(cbCode, 200); + boolean isBucketExist = testGetListBuckets(bName, signatureKey); + assertTrue(isBucketExist, "Bucket is not exist: "); + } + } + } + } + + /** + * Get bucket list. + * + * @param bName Bucket name + * @param signatureKey Signature key object + * @return boolean If bucket is exist return true else false + * @throws JSONException Json exception + * @throws IOException Io exception + */ + private boolean testGetListBuckets(String bName, SignatureKey signatureKey) + throws JSONException, IOException { + Response listBucketResponse = getHttpHandler().getBuckets(signatureKey); + int resCode = listBucketResponse.code(); + String responseBody = listBucketResponse.body().string(); + Logger.logString("Response Code: " + resCode); + Logger.logString("Response: " + responseBody); + JSONObject jsonObject = XML.toJSONObject(responseBody); + JSONArray jsonObjectBucketList = jsonObject.getJSONObject("ListAllMyBucketsResult") + .getJSONObject("Buckets").getJSONArray("Bucket"); + boolean isBucketExist = false; + for (int i = 0; i < jsonObjectBucketList.length(); i++) { + String bucketName = jsonObjectBucketList.getJSONObject(i).get("Name").toString(); + if (!TextUtils.isEmpty(bucketName)) { + if (bucketName.equals(bName)) { + isBucketExist = true; + } + } + } + return isBucketExist; + } + + @Test + @Order(2) + @DisplayName("Test creating bucket using Invalid name") + public void testCreateBucketUsingCapsName() { + // load input files for each type and create the backend + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + Gson gson = new Gson(); + // add the backend specified in each file + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + + // backend added, now create buckets + List listOfIBucketInputs = + Utils.listFilesMatchingBeginsWithPatternInPath("bucket", + Constant.CREATE_BUCKET_PATH); + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + // create the bucket specified in each file + for (File bucketFile : listOfIBucketInputs) { + String bucketContent = Utils.readFileContentsAsString(bucketFile); + assertNotNull(bucketContent); + + // filename format is "bucket_.json", get the bucket name here + CreateBucketFileInput bfi = gson.fromJson(bucketContent, CreateBucketFileInput.class); + + // now create buckets + int cbCode = getHttpHandler().createBucket(bfi, "RATR_@#", signatureKey); + assertEquals(cbCode, 400); + } + } + } + } + + @Test + @Order(3) + @DisplayName("Test re-creating backend with same name on OPENSDS") + public void testReCreateBackend() { + // load input files for each type and create the backend + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + Gson gson = new Gson(); + // Re-create backend specified in each file + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + + AddBackendInputHolder inputHolder = gson.fromJson(content, AddBackendInputHolder.class); + int code = getHttpHandler().addBackend(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId(), + inputHolder); + assertEquals("Re-create backend with same name:Response code not matched:",code, 409); + } + } + } + + @Test + @Order(4) + @DisplayName("Test re-creating bucket with same name on OPENSDS") + public void testReCreateBucket() { + // load input files for each type and create the backend + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + Gson gson = new Gson(); + // Re-create backend specified in each file + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + List listOfIBucketInputs = + Utils.listFilesMatchingBeginsWithPatternInPath("bucket", + Constant.CREATE_BUCKET_PATH); + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + // create the bucket specified in each file + for (File bucketFile : listOfIBucketInputs) { + String bucketContent = Utils.readFileContentsAsString(bucketFile); + assertNotNull(bucketContent); + + CreateBucketFileInput bfi = gson.fromJson(bucketContent, CreateBucketFileInput.class); + + // filename format is "bucket_.json", get the bucket name here + String bName = Utils.getBucketName(bucketFile); + + // now create buckets + int cbCode = getHttpHandler().createBucket(bfi, bName, signatureKey); + assertEquals("Re-create bucket with same name failed:Response code not matched: " + , cbCode, 409); + } + } + } + } + + @Test + @Order(5) + @DisplayName("Test create bucket with empty name") + public void testCreateBucketWithEmptyName() throws IOException, JSONException { + System.out.println("Verifying response code: Input (Backend name) with empty value in payload and bucket" + + " name is empty"); + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + File bucketFile = new File(Constant.EMPTY_FIELD_PATH, "bucket_emptyvalue.json"); + String bucketContent = Utils.readFileContentsAsString(bucketFile); + assertNotNull(bucketContent); + Gson gson = new Gson(); + CreateBucketFileInput bfi = gson.fromJson(bucketContent, CreateBucketFileInput.class); + int cbCode = getHttpHandler().createBucket(bfi, "", signatureKey); + assertEquals("Bucket name and backend name is empty in payload :Response code not matched: " + , cbCode, 405); + boolean isBucketExist = testGetListBuckets("", signatureKey); + assertFalse(isBucketExist); + + File file = new File(Constant.EMPTY_FIELD_PATH, "bucket_b1324.json"); + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + String bName = file.getName().substring(bucketFile.getName().indexOf("_") + 1, + bucketFile.getName().indexOf(".")); + + CreateBucketFileInput input = gson.fromJson(content, CreateBucketFileInput.class); + int code = getHttpHandler().createBucket(input, bName, signatureKey); + System.out.println("Verifying response code: In input (Backend name) with not valid value but bucket name is valid"); + assertEquals("Backend does not exist:Response code not matched: " + , code, 404); + } + + @Test + @Order(6) + @DisplayName("Test request body with empty value,try to create backend") + public void testRequestBodyWithEmptyFieldBackend() { + Gson gson = new Gson(); + File file = new File(Constant.EMPTY_FIELD_PATH+"ibm-cos_b1321.json"); + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + AddBackendInputHolder inputHolder = gson.fromJson(content, AddBackendInputHolder.class); + int code = getHttpHandler().addBackend(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId(), + inputHolder); + Logger.logObject("Backend Input: "+content); + assertEquals("Request body with empty value:Response code not matched:",code, 400); + } + + @Test + @Order(7) + @DisplayName("Test uploading object in a bucket") + public void testUploadObject() throws IOException, JSONException { + // load input files for each type + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + List listOfIBucketInputs = + Utils.listFilesMatchingBeginsWithPatternInPath("bucket", + Constant.CREATE_BUCKET_PATH); + // Get bucket name. + for (File bucketFile : listOfIBucketInputs) { + String bucketContent = Utils.readFileContentsAsString(bucketFile); + assertNotNull(bucketContent); + String bucketName = Utils.getBucketName(bucketFile); + // Get object for upload. + File fileRawData = new File(Constant.RAW_DATA_PATH); + File[] files = fileRawData.listFiles(); + String mFileName = null; + File mFilePath = null; + for (File fileName : files) { + mFileName = fileName.getName(); + mFilePath = fileName; + + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + int cbCode = getHttpHandler().uploadObject(signatureKey, + bucketName, mFileName, mFilePath); + assertEquals("Uploaded object failed", cbCode, 200); + + //Verifying object is uploaded in bucket. + boolean isUploaded = testGetListOfObjectFromBucket(bucketName, mFileName, signatureKey); + assertTrue(isUploaded,"Object is not uploaded"); + } + } + } + } + } + + /** + * Get List of object from bucket + * + * @param bucketName bucket name + * @param fileName file name + * @param signatureKey signature key object + * @return boolean object is upload then true else false + * @throws JSONException json exception + * @throws IOException io exception + */ + private boolean testGetListOfObjectFromBucket(String bucketName, String fileName, + SignatureKey signatureKey) + throws JSONException, IOException { + Response listObjectResponse = getHttpHandler().getBucketObjects(bucketName, signatureKey); + int resCode = listObjectResponse.code(); + String resBody = listObjectResponse.body().string(); + Logger.logString("Response Code: " + resCode); + Logger.logString("Response: " + resBody); + assertEquals("Get list of object failed", resCode, 200); + JSONObject jsonObject = XML.toJSONObject(resBody); + JSONObject jsonObjectListBucket = jsonObject.getJSONObject("ListBucketResult"); + boolean isUploaded = false; + if (jsonObjectListBucket.has("Contents")) { + if (jsonObjectListBucket.get("Contents") instanceof JSONArray) { + JSONArray objects = jsonObjectListBucket.getJSONArray("Contents"); + for (int i = 0; i < objects.length(); i++) { + if (!TextUtils.isEmpty(objects.getJSONObject(i).get("Key").toString())) { + if (objects.getJSONObject(i).get("Key").toString().equals(fileName)) { + isUploaded = true; + } + } + } + } else { + if (!TextUtils.isEmpty(jsonObjectListBucket.getJSONObject("Contents") + .get("Key").toString())) { + if (jsonObjectListBucket.getJSONObject("Contents").get("Key").toString() + .equals(fileName)) { + isUploaded = true; + } + } + } + } + return isUploaded; + } + + @Test + @Order(8) + @DisplayName("Test uploading object failed scenario") + public void testUploadObjectFailed(){ + File fileRawData = new File(Constant.RAW_DATA_PATH); + File[] files = fileRawData.listFiles(); + String mFileName = null; + File mFilePath = null; + for (File fileName : files) { + mFileName = fileName.getName(); + mFilePath = fileName; + } + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + int cbCode = getHttpHandler().uploadObject(signatureKey, + "bucketName", mFileName, mFilePath); + System.out.println("Verifying Upload object with non existing bucket"); + assertEquals("Upload object with non existing bucket: Response code not matched", cbCode, 404); + + List listOfIBucketInputs = + Utils.listFilesMatchingBeginsWithPatternInPath("bucket", + Constant.CREATE_BUCKET_PATH); + // Get bucket name. + for (File bucketFile : listOfIBucketInputs) { + String bucketName = Utils.getBucketName(bucketFile); + int code = getHttpHandler().uploadObject(signatureKey, + bucketName, "", mFilePath); + System.out.println("Verifying upload object in existing bucket with file name is empty"); + assertEquals("Upload object with existing bucket with file name empty: Response code not matched" + , code, 400); + } + } + + @Test + @Order(9) + @DisplayName("Test verifying download non exist file") + public void testDownloadNonExistFile() throws IOException { + List listOfIBucketInputs = + Utils.listFilesMatchingBeginsWithPatternInPath("bucket", + Constant.CREATE_BUCKET_PATH); + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + for (File bucketFile : listOfIBucketInputs) { + String bucketContent = Utils.readFileContentsAsString(bucketFile); + assertNotNull(bucketContent); + String fileName = "download_image.jpg"; + String bucketName = Utils.getBucketName(bucketFile); + Response response = getHttpHandler().downloadObject(signatureKey, + bucketName, "23455", fileName); + int code = response.code(); + String body = response.body().string(); + Logger.logString("Response Code: " + code); + Logger.logString("Response: " + body); + assertEquals("Downloading non exist file: ", code, 404); + } + } + + @Test + @Order(10) + @DisplayName("Test verifying download file from non exist bucket") + public void testDownloadFileFromNonExistBucket() throws IOException { + String dFileName = "download_image.jpg"; + File fileRawData = new File(Constant.RAW_DATA_PATH); + File[] files = fileRawData.listFiles(); + String mFileName = null; + for (File fileName : files) { + mFileName = fileName.getName(); + } + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + Response response = getHttpHandler().downloadObject(signatureKey, + "hfhfhd", mFileName, dFileName); + int code = response.code(); + String body = response.body().string(); + Logger.logString("Response Code: " + code); + Logger.logString("Response: " + body); + assertEquals("Downloading file from non exist bucket: ", code, 404); + } + + @Test + @Order(11) + @DisplayName("Test verifying download file from non exist bucket and file name") + public void testDownloadNonExistBucketAndFile() throws IOException { + String fileName = "download_image.jpg"; + System.out.println("Verifying download file from non exist bucket and file name"); + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + Response response = getHttpHandler().downloadObject(signatureKey, + "ghjhb", "yuyiyh", fileName); + int code = response.code(); + String body = response.body().string(); + Logger.logString("Response Code: " + code); + Logger.logString("Response: " + body); + assertEquals("Downloading file from non exist bucket and file name: ", code, 404); + assertEquals("Response message is not valid, bucket and filename not exist: ", body); + } + + @Test + @Order(12) + @DisplayName("Test downloading object in a folder") + public void testDownloadObject() throws IOException { + // load input files for each type + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + // backend added, now create buckets + List listOfIBucketInputs = + Utils.listFilesMatchingBeginsWithPatternInPath("bucket", + Constant.CREATE_BUCKET_PATH); + for (File bucketFile : listOfIBucketInputs) { + String bucketContent = Utils.readFileContentsAsString(bucketFile); + assertNotNull(bucketContent); + String bucketName = Utils.getBucketName(bucketFile); + // Get object for upload. + File fileRawData = new File(Constant.RAW_DATA_PATH); + File[] files = fileRawData.listFiles(); + String mFileName = null; + for (File fileName : files) { + mFileName = fileName.getName(); + } + String fileName = "download_image.jpg"; + File filePath = new File(Constant.DOWNLOAD_FILES_PATH); + File downloadedFile = new File(Constant.DOWNLOAD_FILES_PATH, fileName); + if (filePath.exists()) { + if (downloadedFile.exists()) { + boolean isDownloadedFileDeleted = downloadedFile.delete(); + assertTrue(isDownloadedFileDeleted, "Image deleting is failed"); + } else { + assertFalse(downloadedFile.exists()); + } + } else { + filePath.mkdirs(); + } + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + Response response = getHttpHandler().downloadObject(signatureKey, + bucketName, mFileName, fileName); + int code = response.code(); + String body = response.body().string(); + Logger.logString("Response Code: " + code); + Logger.logString("Response: " + body); + assertEquals("Downloading failed", code, 200); + assertTrue(downloadedFile.isFile(), "Downloaded Image is not available"); + } + } + } + } + + @Test + @Order(13) + @DisplayName("Test verifying backends list and single backend") + public void testAddBackendGetBackends() throws IOException { + // load input files for each type. + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + Gson gson = new Gson(); + // add the backend specified in each file + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + AddBackendInputHolder inputHolder = gson.fromJson(content, AddBackendInputHolder.class); + // Get backend list + Response response = getHttpHandler().getBackends(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + int code = response.code(); + String responseBody = response.body().string(); + Logger.logString("Response Code: " + code); + assertEquals("Get Backends List Failed: ",code, 200); + assertNotNull(responseBody); + BackendsInputHolder backendsInputHolder = gson.fromJson(responseBody, + BackendsInputHolder.class); + // Filter backend + List backendFilter = backendsInputHolder.getBackends().stream() + .filter(p -> !TextUtils.isEmpty(p.getName())) + .collect(Collectors.toList()); + + List backend = backendFilter.stream() + .filter(p -> p.getName().equals(inputHolder.getName())) + .collect(Collectors.toList()); + + assertNotNull(backend); + + // Get backend + for (int i = 0; i < backend.size(); i++) { + Response responseBackend = getHttpHandler().getBackend(getAuthTokenHolder() + .getResponseHeaderSubjectToken(), getAuthTokenHolder().getToken() + .getProject().getId(), backend.get(i).getId()); + int resCode = response.code(); + String responseBackendBody = responseBackend.body().string(); + Logger.logString("Response Code: " + resCode); + assertEquals(resCode, 200); + assertNotNull(responseBackendBody); + Backends backends = gson.fromJson(responseBackendBody, Backends.class); + assertNotNull(backends); + assertEquals("Backend name not matched: ", backends.getName(), inputHolder.getName()); + } + } + } + } + + @Test + @Order(14) + @DisplayName("Test verifying non exist backend") + public void testNonExistBackend() { + Response responseBackend = getHttpHandler().getBackend(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId(), "reuiu5475"); + int code = responseBackend.code(); + Logger.logString("Response Code: " + code); + assertEquals("Get backend failed:Response code not matched: ", code, 400); + } + + @Test + @Order(15) + @DisplayName("Test verifying delete non empty backend") + public void testDeleteNonEmptyBackend() throws IOException { + // load input files for each type. + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + Gson gson = new Gson(); + // add the backend specified in each file + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + AddBackendInputHolder inputHolder = gson.fromJson(content, AddBackendInputHolder.class); + + // Get backend list + Response response = getHttpHandler().getBackends(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + int code = response.code(); + Logger.logString("Response Code: " + code); + assertEquals(code, 200); + String responseBody = response.body().string(); + assertNotNull(responseBody); + BackendsInputHolder backendsInputHolder = gson.fromJson(responseBody, + BackendsInputHolder.class); + // Filter backend + List backendFilter = backendsInputHolder.getBackends().stream() + .filter(p -> !TextUtils.isEmpty(p.getName())) + .collect(Collectors.toList()); + + List backend = backendFilter.stream() + .filter(p -> p.getName().equals(inputHolder.getName())) + .collect(Collectors.toList()); + assertNotNull(backend); + + // Get backend + for (int i = 0; i < backend.size(); i++) { + Response responseBackend = getHttpHandler().getBackend(getAuthTokenHolder() + .getResponseHeaderSubjectToken(), getAuthTokenHolder().getToken() + .getProject().getId(), backend.get(i).getId()); + int resCode = response.code(); + String responseBackendBody = responseBackend.body().string(); + Logger.logString("Response Code: " + resCode); + assertEquals(responseBackend.code(), 200); + assertNotNull(responseBackendBody); + Backends backends = gson.fromJson(responseBackendBody, Backends.class); + assertNotNull(backends); + assertEquals(backends.getName(), inputHolder.getName()); + Response responseDeleteBackend= getHttpHandler().getDeleteBackend(getAuthTokenHolder() + .getResponseHeaderSubjectToken(), getAuthTokenHolder().getToken() + .getProject().getId(), backend.get(i).getId()); + int responseCode = responseDeleteBackend.code(); + String resp = responseDeleteBackend.body().string(); + Logger.logString("Response Code: " + responseCode); + Logger.logString("Response: " + resp); + assertEquals("Deleting Non empty backend:Response code not matched: " + ,responseCode, 409); + } + } + } + } + + @Test + @Order(16) + @DisplayName("Test deleting non empty bucket") + public void testDeleteNonEmptyBucket() throws IOException { + // load input files for each type. + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + // add the backend specified in each file + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + List listOfIBucketInputs = + Utils.listFilesMatchingBeginsWithPatternInPath("bucket", + Constant.CREATE_BUCKET_PATH); + // create the bucket specified in each file + for (File bucketFile : listOfIBucketInputs) { + String bucketContent = Utils.readFileContentsAsString(bucketFile); + assertNotNull(bucketContent); + + // filename format is "bucket_.json", get the bucket name here + String bName = Utils.getBucketName(bucketFile); + // Verifying Bucket not empty + Response response = getHttpHandler().deleteBucketNotEmpty(signatureKey, bName); + int responseCode = response.code(); + String responseBody = response.body().string(); + Logger.logString("Response Code: "+responseCode); + Logger.logString("Response: "+responseBody); + assertEquals("Verifying Bucket not empty: ", responseCode, 409); + } + } + } + } + + @Test + @Order(17) + @DisplayName("Test deleting non exist object") + public void testDeleteNonExistObject() throws IOException, JSONException { + // load input files for each type. + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + // add the backend specified in each file + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + + List listOfIBucketInputs = + Utils.listFilesMatchingBeginsWithPatternInPath("bucket", + Constant.CREATE_BUCKET_PATH); + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder() + .getResponseHeaderSubjectToken(), getAuthTokenHolder().getToken() + .getProject().getId()); + // create the bucket specified in each file + for (File bucketFile : listOfIBucketInputs) { + String bucketContent = Utils.readFileContentsAsString(bucketFile); + assertNotNull(bucketContent); + + // filename format is "bucket_.json", get the bucket name here + String bName = Utils.getBucketName(bucketFile); + String fileName = "hjdhj"; + // now delete the object + Response response = getHttpHandler().deleteObject(signatureKey, bName, fileName); + int resCode = response.code(); + String resBody = response.body().string(); + Logger.logString("Response Code: " + resCode); + Logger.logString("Response: " + resBody); + assertEquals("Delete non exist object: Response code not matched: ",resCode, 404); + boolean isUploaded = testGetListOfObjectFromBucket(bName, fileName, signatureKey); + assertFalse(isUploaded,"Object is exist"); + } + } + } + } + + @Test + @Order(18) + @DisplayName("Test deleting non exist object with bucket") + public void testDeleteNonExistObjectWithBucket() throws IOException { + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + String bName = "fhy5657"; + // now delete the object + Response response = getHttpHandler().deleteObject(signatureKey, bName, "hjdhj"); + int code = response.code(); + String body = response.body().string(); + Logger.logString("Response Code: " + code); + Logger.logString("Response: " + body); + assertEquals("Delete non exist object: Response code not matched: ",code, 404); + Response listObjectResponse = getHttpHandler().getBucketObjects(bName,signatureKey); + int resCode = listObjectResponse.code(); + String resBody = listObjectResponse.body().string(); + Logger.logString("Response Code: " + resCode); + Logger.logString("Response: " + resBody); + assertEquals("Bucket name not exist: Response code not matched: ", resCode,404); + } + + @Test + @Order(19) + @DisplayName("Test deleting bucket and object") + public void testDeleteBucketAndObject() throws IOException, JSONException { + // load input files for each type + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + // add the backend specified in each file + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + + List listOfIBucketInputs = + Utils.listFilesMatchingBeginsWithPatternInPath("bucket", + Constant.CREATE_BUCKET_PATH); + SignatureKey signatureKey = getHttpHandler().getAkSkList(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + // create the bucket specified in each file + for (File bucketFile : listOfIBucketInputs) { + String bucketContent = Utils.readFileContentsAsString(bucketFile); + assertNotNull(bucketContent); + + // filename format is "bucket_.json", get the bucket name here + String bName = Utils.getBucketName(bucketFile); + String fileName = "Screenshot_1.jpg"; + // now delete the object + Response response = getHttpHandler().deleteObject(signatureKey, bName, fileName); + int code = response.code(); + String body = response.body().string(); + Logger.logString("Response Code: " + code); + Logger.logString("Response: " + body); + assertFalse(TextUtils.isEmpty(body),"Response message is empty: "); + assertEquals("Verifying object is deleted: Response code not matched: ",code, 204); + boolean isUploaded = testGetListOfObjectFromBucket(bName, fileName, signatureKey); + assertFalse(isUploaded,"Object is not Deleted"); + + // now delete the bucket + Response responseDeleteBucket = getHttpHandler().deleteBucket(signatureKey, bName); + int codeRes = responseDeleteBucket.code(); + String bodyRes = responseDeleteBucket.body().string(); + Logger.logString("Response Code: " + codeRes); + Logger.logString("Response: " + bodyRes); + assertFalse(TextUtils.isEmpty(bodyRes),"Response message is empty: "); + assertNotNull(bodyRes); + assertEquals("Delete bucket may be does not exist: ",codeRes,204); + + boolean isBucketExist = testGetListBuckets(bName, signatureKey); + assertFalse(isBucketExist, "Bucket is exist: "); + } + } + } + } + + @Test + @Order(20) + @DisplayName("Test deleting backend") + public void testDeleteBackend() throws IOException { + // load input files for each type. + for (Type t : getTypesHolder().getTypes()) { + List listOfIInputsForType = + Utils.listFilesMatchingBeginsWithPatternInPath(t.getName(), + Constant.CREATE_BUCKET_PATH); + Gson gson = new Gson(); + // add the backend specified in each file + for (File file : listOfIInputsForType) { + String content = Utils.readFileContentsAsString(file); + assertNotNull(content); + AddBackendInputHolder inputHolder = gson.fromJson(content, AddBackendInputHolder.class); + + // Get backend list + Response response = getHttpHandler().getBackends(getAuthTokenHolder().getResponseHeaderSubjectToken(), + getAuthTokenHolder().getToken().getProject().getId()); + int code = response.code(); + Logger.logString("Response Code: " + code); + assertEquals(code, 200); + String responseBody = response.body().string(); + assertFalse(TextUtils.isEmpty(responseBody),"Response message is empty: "); + BackendsInputHolder backendsInputHolder = gson.fromJson(responseBody, + BackendsInputHolder.class); + // Filter backend + List backendFilter = backendsInputHolder.getBackends().stream() + .filter(p -> !TextUtils.isEmpty(p.getName())) + .collect(Collectors.toList()); + + List backend = backendFilter.stream() + .filter(p -> p.getName().equals(inputHolder.getName())) + .collect(Collectors.toList()); + assertNotNull(backend); + + // Get backend + for (int i = 0; i < backend.size(); i++) { + Response responseDeleteBackend= getHttpHandler().getDeleteBackend(getAuthTokenHolder() + .getResponseHeaderSubjectToken(), getAuthTokenHolder().getToken() + .getProject().getId(), backend.get(i).getId()); + int responseCode = responseDeleteBackend.code(); + String resp = responseDeleteBackend.body().string(); + Logger.logString("Response Code: " + responseCode); + Logger.logString("Response: " + resp); + assertEquals(responseCode, 200); + assertFalse(TextUtils.isEmpty(resp),"Response message is empty: "); + } + } + } + } +} + +