@@ -109,7 +109,7 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
109109 rr.stdout should include(testbasepath + testrelpath)
110110 }
111111
112- def verifyApiGet (rr : RunResult , apihost: String ): Unit = {
112+ def verifyApiGet (rr : RunResult , apihost : String ): Unit = {
113113 rr.stdout should include regex (s """ "operationId": \\ s+"getPathWithSub_pathsInIt" """ )
114114 rr.stdout should include regex (s """ "target-url": \\ s+"https:// $apihost""" )
115115 }
@@ -187,7 +187,7 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
187187 return swaggerfile
188188 }
189189
190- def getSwaggerUrl (rr : RunResult ) : String = {
190+ def getSwaggerUrl (rr : RunResult ): String = {
191191 rr.stdout.split(" \n " )(1 )
192192 }
193193
@@ -207,15 +207,30 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
207207 }
208208
209209 def getParametersFromJson (json : JsObject , pathName : String ): Vector [JsValue ] = {
210- json.fields(" paths" ).asJsObject.fields(pathName).asJsObject.fields(" get" ).asJsObject.fields(" parameters" ).convertTo[JsArray ].elements
210+ json
211+ .fields(" paths" )
212+ .asJsObject
213+ .fields(pathName)
214+ .asJsObject
215+ .fields(" get" )
216+ .asJsObject
217+ .fields(" parameters" )
218+ .convertTo[JsArray ]
219+ .elements
211220 }
212221
213222 def getSslConfig (): RestAssuredConfig = {
214223 // force RestAssured to allow all hosts in SSL certificates
215- new RestAssuredConfig ().sslConfig(new SSLConfig ().keystore(" keystore" , WhiskProperties .getSslCertificateChallenge).allowAllHostnames())
224+ new RestAssuredConfig ()
225+ .sslConfig(new SSLConfig ().keystore(" keystore" , WhiskProperties .getSslCertificateChallenge).allowAllHostnames())
216226 }
217227
218- def validateParameter (parameter : JsObject , name : String , in : String , required : Boolean , pType : String , description : String ): Unit = {
228+ def validateParameter (parameter : JsObject ,
229+ name : String ,
230+ in : String ,
231+ required : Boolean ,
232+ pType : String ,
233+ description : String ): Unit = {
219234 parameter.fields(" name" ) should be(name.toJson)
220235 parameter.fields(" in" ) should be(in.toJson)
221236 parameter.fields(" required" ) should be(required.toJson)
@@ -227,68 +242,66 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
227242
228243 behavior of " Cli Wsk api creation with path parameters with swagger"
229244
230- it should " create the API when swagger file contains path parameters" in withAssetCleaner(
231- wskprops) { (wp, assetHelper) =>
232- val actionName = " cli_apigwtest_path_param_swagger_action"
233- val apiName = " /guest/v1"
234- val reqPath = " \\ $\\ (request.path\\ )"
235- val testRelPath = " /api2/greeting2/{name}"
236- val testUrlName = " scooby"
237- val testRelPathGet = s " /api2/greeting2/ $testUrlName"
238- val testUrlOp = " get"
239- var file = TestUtils .getTestActionFilename(s " echo-web-http.js " )
240- val hostRegex = " %HOST%" .r
241- assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true ) {
242- (action, _) =>
245+ it should " create the API when swagger file contains path parameters" in withAssetCleaner(wskprops) {
246+ (wp, assetHelper) =>
247+ val actionName = " cli_apigwtest_path_param_swagger_action"
248+ val apiName = " /guest/v1"
249+ val reqPath = " \\ $\\ (request.path\\ )"
250+ val testRelPath = " /api2/greeting2/{name}"
251+ val testUrlName = " scooby"
252+ val testRelPathGet = s " /api2/greeting2/ $testUrlName"
253+ val testUrlOp = " get"
254+ var file = TestUtils .getTestActionFilename(s " echo-web-http.js " )
255+ val hostRegex = " %HOST%" .r
256+ assetHelper.withCleaner(wsk.action, actionName, confirmDelete = true ) { (action, _) =>
243257 action.create(actionName, Some (file), web = Some (" true" ))
244- }
245- try {
246- // Create the API
247- var rr : RunResult = apiCreate(
248- basepath = Some (apiName),
249- relpath = Some (testRelPath),
250- operation = Some (testUrlOp),
251- action = Some (actionName),
252- responsetype = Some (" http" )
253- )
254- verifyApiCreated(rr)
255-
256- // Get the api so we can create the swagger from the returned output
257- rr = apiGet(basepathOrApiName = Some (apiName))
258- rr.stdout should include regex (s """ target-url.* ${actionName}.http ${reqPath}""" )
259- val swaggerFile = writeSwaggerFile(rr)
260-
261- // Delete the api so we can re-create it using the swagger
262- rr = apiDelete(basepathOrApiName = apiName)
263- verifyApiDeleted(rr)
264-
265- // Create the api using the swagger file.
266- rr = apiCreate(swagger = Some (swaggerFile.getAbsolutePath()), expectedExitCode = SUCCESS_EXIT )
267- verifyApiCreated(rr)
268- val swaggerApiUrl = getSwaggerUrl(rr).replace(" {name}" , testUrlName)
269-
270- // Lets validate that the swagger we get from the create contains the correct info.
271- rr = apiGet(basepathOrApiName = Some (apiName))
272- rr.stdout should include regex (s """ target-url.* ${actionName}.http ${reqPath}""" )
273-
274- val params = getParametersFromJson(rr.stdout.parseJson.asJsObject, testRelPath)
275- params.size should be(1 )
276- validateParameter(params(0 ).asJsObject, " name" , " path" , true , " string" , " Default description for 'name'" )
277-
278- // Lets call the swagger url so we can make sure the response is valid and contains our path in the ow path
279- val apiToInvoke = s " $swaggerApiUrl"
280- println(s " Invoking: ' ${apiToInvoke}' " )
281- val response = whisk.utils.retry({
282- val response = RestAssured .given ().config(getSslConfig()).get(s " $apiToInvoke" )
283- response.statusCode should be(200 )
284- response
285- }, 6 , Some (2 .second))
286- val jsonResponse = response.body.asString.parseJson.asJsObject
287-
288- jsonResponse.fields(" __ow_path" ).toString should include (testRelPathGet)
289- } finally {
290- apiDelete(basepathOrApiName = apiName)
291- }
258+ }
259+ try {
260+ // Create the API
261+ var rr : RunResult = apiCreate(
262+ basepath = Some (apiName),
263+ relpath = Some (testRelPath),
264+ operation = Some (testUrlOp),
265+ action = Some (actionName),
266+ responsetype = Some (" http" ))
267+ verifyApiCreated(rr)
268+
269+ // Get the api so we can create the swagger from the returned output
270+ rr = apiGet(basepathOrApiName = Some (apiName))
271+ rr.stdout should include regex (s """ target-url.* ${actionName}.http ${reqPath}""" )
272+ val swaggerFile = writeSwaggerFile(rr)
273+
274+ // Delete the api so we can re-create it using the swagger
275+ rr = apiDelete(basepathOrApiName = apiName)
276+ verifyApiDeleted(rr)
277+
278+ // Create the api using the swagger file.
279+ rr = apiCreate(swagger = Some (swaggerFile.getAbsolutePath()), expectedExitCode = SUCCESS_EXIT )
280+ verifyApiCreated(rr)
281+ val swaggerApiUrl = getSwaggerUrl(rr).replace(" {name}" , testUrlName)
282+
283+ // Lets validate that the swagger we get from the create contains the correct info.
284+ rr = apiGet(basepathOrApiName = Some (apiName))
285+ rr.stdout should include regex (s """ target-url.* ${actionName}.http ${reqPath}""" )
286+
287+ val params = getParametersFromJson(rr.stdout.parseJson.asJsObject, testRelPath)
288+ params.size should be(1 )
289+ validateParameter(params(0 ).asJsObject, " name" , " path" , true , " string" , " Default description for 'name'" )
290+
291+ // Lets call the swagger url so we can make sure the response is valid and contains our path in the ow path
292+ val apiToInvoke = s " $swaggerApiUrl"
293+ println(s " Invoking: ' ${apiToInvoke}' " )
294+ val response = whisk.utils.retry({
295+ val response = RestAssured .given ().config(getSslConfig()).get(s " $apiToInvoke" )
296+ response.statusCode should be(200 )
297+ response
298+ }, 6 , Some (2 .second))
299+ val jsonResponse = response.body.asString.parseJson.asJsObject
300+
301+ jsonResponse.fields(" __ow_path" ).toString should include(testRelPathGet)
302+ } finally {
303+ apiDelete(basepathOrApiName = apiName)
304+ }
292305 }
293306
294307 it should " reject an api commands with an invalid path parameter" in {
@@ -493,7 +506,6 @@ abstract class ApiGwCliBasicTests extends BaseApiGwTests {
493506 }
494507 }
495508
496-
497509 it should " verify get API name " in {
498510 val testName = " CLI_APIGWTEST3"
499511 val testbasepath = " /" + testName + " _bp"
0 commit comments