Skip to content

Commit

Permalink
Fixed empty wsk list print, renamed functions, fixed comments, and re…
Browse files Browse the repository at this point in the history
…ordered tests
  • Loading branch information
underwoodb-sd-ibm committed Jun 23, 2017
1 parent c2826b0 commit 392d495
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 349 deletions.
219 changes: 109 additions & 110 deletions tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,74 @@ class ApiGwEndToEndTests

behavior of "Wsk api-experimental"

it should s"create an API and successfully invoke that API" in {
val testName = "APIGWe_HEALTHTEST1"
val testbasepath = "/" + testName + "_bp"
val testrelpath = "/path"
val testurlop = "get"
val testapiname = testName + " API Name"
val actionName = testName + "_echo"
val urlqueryparam = "name"
val urlqueryvalue = "test"

try {
println("cli user: " + cliuser + "; cli namespace: " + clinamespace)

// Create the action for the API
val file = TestUtils.getTestActionFilename(s"echo.js")
wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = SUCCESS_EXIT)

// Create the API
var rr = wsk.apiexperimental.create(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
rr.stdout should include("ok: created API")
val apiurl = rr.stdout.split("\n")(1)
println(s"apiurl: '${apiurl}'")

// Validate the API was successfully created
// List result will look like:
// ok: APIs
// Action Verb API Name URL
// /_//whisk.system/utils/echo get APIGW_HEALTHTEST1 API Name http://172.17.0.1:9001/api/ab9082cd-ea8e-465a-8a65-b491725cc4ef/APIGW_HEALTHTEST1_bp/path
rr = wsk.apiexperimental.list(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
rr.stdout should include("ok: APIs")
rr.stdout should include regex (s"${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
rr.stdout should include(testbasepath + testrelpath)

// Recreate the API using a JSON swagger file
rr = wsk.apiexperimental.get(basepathOrApiName = Some(testbasepath))
val swaggerfile = File.createTempFile("api", ".json")
swaggerfile.deleteOnExit()
val bw = new BufferedWriter(new FileWriter(swaggerfile))
bw.write(rr.stdout)
bw.close()

// Delete API to that it can be recreated again using the generated swagger file
val deleteApiResult = wsk.apiexperimental.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)

// Create the API again, but use the swagger file this time
rr = wsk.apiexperimental.create(swagger = Some(swaggerfile.getAbsolutePath()))
rr.stdout should include("ok: created API")
val swaggerapiurl = rr.stdout.split("\n")(1)
println(s"apiurl: '${swaggerapiurl}'")

// Call the API URL and validate the results
val response = whisk.utils.retry({
val response = RestAssured.given().config(sslconfig).get(s"$swaggerapiurl?$urlqueryparam=$urlqueryvalue")
response.statusCode should be(200)
response
}, 5, Some(1.second))
val responseString = response.body.asString
println("URL invocation response: " + responseString)
responseString.parseJson.asJsObject.fields(urlqueryparam).convertTo[String] should be(urlqueryvalue)

} finally {
println("Deleting action: " + actionName)
val finallydeleteActionResult = wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
println("Deleting API: " + testbasepath)
val finallydeleteApiResult = wsk.apiexperimental.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
}
}

it should "return a list of alphabetized api-experimental" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>

Expand All @@ -85,7 +153,7 @@ class ApiGwEndToEndTests
val base3 = "/BaseTestPath3"

try {
//Create Actions for apiexperimentals
// Create Actions for apiexperimentals
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
assetHelper.withCleaner(wsk.action, actionName1) {
(action, name) => action.create(name, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, web = Some("true"))
Expand Down Expand Up @@ -124,7 +192,7 @@ class ApiGwEndToEndTests
scalaSorted.toString shouldEqual list.toString
scalaSorted.toString shouldEqual listFull.toString
} finally {
//Clean up apiexperimentals
// Clean up apiexperimentals
wsk.apiexperimental.delete(base1, expectedExitCode = DONTCARE_EXIT)
wsk.apiexperimental.delete(base2, expectedExitCode = DONTCARE_EXIT)
wsk.apiexperimental.delete(base3, expectedExitCode = DONTCARE_EXIT)
Expand Down Expand Up @@ -188,8 +256,10 @@ class ApiGwEndToEndTests
}
}

behavior of "Wsk api"

it should s"create an API and successfully invoke that API" in {
val testName = "APIGWe_HEALTHTEST1"
val testName = "APIGW_HEALTHTEST1"
val testbasepath = "/" + testName + "_bp"
val testrelpath = "/path"
val testurlop = "get"
Expand All @@ -201,12 +271,20 @@ class ApiGwEndToEndTests
try {
println("cli user: " + cliuser + "; cli namespace: " + clinamespace)

// Create the action for the API
val file = TestUtils.getTestActionFilename(s"echo.js")
wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = SUCCESS_EXIT)
// Create the action for the API. It must be a "web-action" action.
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, annotations = Map("web-export" -> true.toJson))

// Create the API
var rr = wsk.apiexperimental.create(basepath = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop), action = Some(actionName), apiname = Some(testapiname))
var rr = wsk.api.create(
basepath = Some(testbasepath),
relpath = Some(testrelpath),
operation = Some(testurlop),
action = Some(actionName),
apiname = Some(testapiname),
responsetype = Some("http"),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
rr.stdout should include("ok: created API")
val apiurl = rr.stdout.split("\n")(1)
println(s"apiurl: '${apiurl}'")
Expand All @@ -216,24 +294,39 @@ class ApiGwEndToEndTests
// ok: APIs
// Action Verb API Name URL
// /_//whisk.system/utils/echo get APIGW_HEALTHTEST1 API Name http://172.17.0.1:9001/api/ab9082cd-ea8e-465a-8a65-b491725cc4ef/APIGW_HEALTHTEST1_bp/path
rr = wsk.apiexperimental.list(basepathOrApiName = Some(testbasepath), relpath = Some(testrelpath), operation = Some(testurlop))
rr = wsk.api.list(
basepathOrApiName = Some(testbasepath),
relpath = Some(testrelpath),
operation = Some(testurlop),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
rr.stdout should include("ok: APIs")
rr.stdout should include regex (s"${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
rr.stdout should include(testbasepath + testrelpath)

// Recreate the API using a JSON swagger file
rr = wsk.apiexperimental.get(basepathOrApiName = Some(testbasepath))
rr = wsk.api.get(
basepathOrApiName = Some(testbasepath),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
val swaggerfile = File.createTempFile("api", ".json")
swaggerfile.deleteOnExit()
val bw = new BufferedWriter(new FileWriter(swaggerfile))
bw.write(rr.stdout)
bw.close()

// Delete API to that it can be recreated again using the generated swagger file
val deleteApiResult = wsk.apiexperimental.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
val deleteApiResult = wsk.api.delete(
basepathOrApiName = testbasepath,
expectedExitCode = DONTCARE_EXIT,
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)

// Create the API again, but use the swagger file this time
rr = wsk.apiexperimental.create(swagger = Some(swaggerfile.getAbsolutePath()))
rr = wsk.api.create(
swagger = Some(swaggerfile.getAbsolutePath()),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
rr.stdout should include("ok: created API")
val swaggerapiurl = rr.stdout.split("\n")(1)
println(s"apiurl: '${swaggerapiurl}'")
Expand All @@ -252,12 +345,14 @@ class ApiGwEndToEndTests
println("Deleting action: " + actionName)
val finallydeleteActionResult = wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
println("Deleting API: " + testbasepath)
val finallydeleteApiResult = wsk.apiexperimental.delete(basepathOrApiName = testbasepath, expectedExitCode = DONTCARE_EXIT)
val finallydeleteApiResult = wsk.api.delete(
basepathOrApiName = testbasepath,
expectedExitCode = DONTCARE_EXIT,
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
}
}

behavior of "Wsk api"

it should "return a list of alphabetized api" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>

Expand Down Expand Up @@ -379,100 +474,4 @@ class ApiGwEndToEndTests
wsk.api.delete(base3, expectedExitCode = DONTCARE_EXIT, cliCfgFile = Some(cliWskPropsFile.getCanonicalPath()))
}
}


it should s"create an API and successfully invoke that API" in {
val testName = "APIGW_HEALTHTEST1"
val testbasepath = "/" + testName + "_bp"
val testrelpath = "/path"
val testurlop = "get"
val testapiname = testName + " API Name"
val actionName = testName + "_echo"
val urlqueryparam = "name"
val urlqueryvalue = "test"

try {
println("cli user: " + cliuser + "; cli namespace: " + clinamespace)

// Create the action for the API. It must be a "web-action" action.
val file = TestUtils.getTestActionFilename(s"echo-web-http.js")
wsk.action.create(name = actionName, artifact = Some(file), expectedExitCode = SUCCESS_EXIT, annotations = Map("web-export" -> true.toJson))

// Create the API
var rr = wsk.api.create(
basepath = Some(testbasepath),
relpath = Some(testrelpath),
operation = Some(testurlop),
action = Some(actionName),
apiname = Some(testapiname),
responsetype = Some("http"),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
rr.stdout should include("ok: created API")
val apiurl = rr.stdout.split("\n")(1)
println(s"apiurl: '${apiurl}'")

// Validate the API was successfully created
// List result will look like:
// ok: APIs
// Action Verb API Name URL
// /_//whisk.system/utils/echo get APIGW_HEALTHTEST1 API Name http://172.17.0.1:9001/api/ab9082cd-ea8e-465a-8a65-b491725cc4ef/APIGW_HEALTHTEST1_bp/path
rr = wsk.api.list(
basepathOrApiName = Some(testbasepath),
relpath = Some(testrelpath),
operation = Some(testurlop),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
rr.stdout should include("ok: APIs")
rr.stdout should include regex (s"${actionName}\\s+${testurlop}\\s+${testapiname}\\s+")
rr.stdout should include(testbasepath + testrelpath)

// Recreate the API using a JSON swagger file
rr = wsk.api.get(
basepathOrApiName = Some(testbasepath),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
val swaggerfile = File.createTempFile("api", ".json")
swaggerfile.deleteOnExit()
val bw = new BufferedWriter(new FileWriter(swaggerfile))
bw.write(rr.stdout)
bw.close()

// Delete API to that it can be recreated again using the generated swagger file
val deleteApiResult = wsk.api.delete(
basepathOrApiName = testbasepath,
expectedExitCode = DONTCARE_EXIT,
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)

// Create the API again, but use the swagger file this time
rr = wsk.api.create(
swagger = Some(swaggerfile.getAbsolutePath()),
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
rr.stdout should include("ok: created API")
val swaggerapiurl = rr.stdout.split("\n")(1)
println(s"apiurl: '${swaggerapiurl}'")

// Call the API URL and validate the results
val response = whisk.utils.retry({
val response = RestAssured.given().config(sslconfig).get(s"$swaggerapiurl?$urlqueryparam=$urlqueryvalue")
response.statusCode should be(200)
response
}, 5, Some(1.second))
val responseString = response.body.asString
println("URL invocation response: " + responseString)
responseString.parseJson.asJsObject.fields(urlqueryparam).convertTo[String] should be(urlqueryvalue)

} finally {
println("Deleting action: " + actionName)
val finallydeleteActionResult = wsk.action.delete(name = actionName, expectedExitCode = DONTCARE_EXIT)
println("Deleting API: " + testbasepath)
val finallydeleteApiResult = wsk.api.delete(
basepathOrApiName = testbasepath,
expectedExitCode = DONTCARE_EXIT,
cliCfgFile = Some(cliWskPropsFile.getCanonicalPath())
)
}
}
}
Loading

0 comments on commit 392d495

Please sign in to comment.