@@ -26,7 +26,8 @@ import org.junit.runner.RunWith
2626import org .scalatest .junit .JUnitRunner
2727
2828import scala .concurrent .duration .DurationInt
29- import scala .util .parsing .json .JSON
29+
30+ import spray .json ._
3031
3132/**
3233 * Tests for basic CLI usage. Some of these tests require a deployed backend.
@@ -84,7 +85,6 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
8485 val testUrlOp = " get"
8586 val testApiName = testName + " API Name"
8687 val actionName = testName + " _action"
87- var exception : Throwable = null
8888 val reqPath = " \\ $\\ (request.path\\ )"
8989
9090 // Create the action for the API. It must be a "web-action" action.
@@ -111,10 +111,10 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
111111 rr.stdout should include(s " ${actionName}" )
112112 rr.stdout should include regex (""" "cors":\s*\{\s*\n\s*"enabled":\s*true""" )
113113 rr.stdout should include regex (s """ target-url.* ${actionName}.http ${reqPath}""" )
114- val params = getParametersFromJson(rr, testRelPath)
114+ val params = getParametersFromJson(rr.stdout.parseJson.asJsObject , testRelPath)
115115 params.size should be(2 )
116- validateParameter(params(0 ), " with" , " path" , true , " string" , " Default description for 'with'" )
117- validateParameter(params(1 ), " path" , " path" , true , " string" , " Default description for 'path'" )
116+ validateParameter(params(0 ).asJsObject , " with" , " path" , true , " string" , " Default description for 'with'" )
117+ validateParameter(params(1 ).asJsObject , " path" , " path" , true , " string" , " Default description for 'path'" )
118118
119119 // Lets call the swagger url so we can make sure the response is valid and contains our path in the ow path
120120 val apiToInvoke = s " $swaggerApiUrl"
@@ -124,15 +124,12 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
124124 response.statusCode should be(200 )
125125 response
126126 }, 6 , Some (2 .second))
127- val jsonReponse = JSON .parseFull(response.asString()).asInstanceOf [Option [Map [String , String ]]].get
128- jsonReponse.get(" __ow_path" ).get should not be (" " )
129- jsonReponse.get(" __ow_path" ).get should include (testRelPathGet)
130- } catch {
131- case unknown : Throwable => exception = unknown
127+ val jsonResponse = response.body.asString.parseJson.asJsObject
128+
129+ jsonResponse.fields(" __ow_path" ).toString should include (testRelPathGet)
132130 } finally {
133131 apiDelete(basepathOrApiName = testBasePath)
134132 }
135- assert(exception == null )
136133 }
137134
138135 it should " create api with path parameters and pass them into the action bound to the api" in withAssetCleaner(
@@ -148,7 +145,6 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
148145 val testUrlOp = " get"
149146 val testApiName = testName + " API Name"
150147 val actionName = testName + " _action"
151- var exception : Throwable = null
152148 val reqPath = " \\ $\\ (request.path\\ )"
153149 // Create the action for the API. It must be a "web-action" action.
154150 val file = TestUtils .getTestActionFilename(s " echo-web-http.js " )
@@ -175,14 +171,14 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
175171 rr.stdout should include(s " ${actionName}" )
176172 rr.stdout should include regex (""" "cors":\s*\{\s*\n\s*"enabled":\s*true""" )
177173 rr.stdout should include regex (s """ target-url.* ${actionName}.http ${reqPath}""" )
178- val params = getParametersFromJson(rr, testRelPath)
174+ val params = getParametersFromJson(rr.stdout.parseJson.asJsObject , testRelPath)
179175
180176 // should have 4, not 5 parameter definitions (i.e. don't define "extra" twice
181177 params.size should be(4 )
182- validateParameter(params(0 ), " with" , " path" , true , " string" , " Default description for 'with'" )
183- validateParameter(params(1 ), " double" , " path" , true , " string" , " Default description for 'double'" )
184- validateParameter(params(2 ), " extra" , " path" , true , " string" , " Default description for 'extra'" )
185- validateParameter(params(3 ), " path" , " path" , true , " string" , " Default description for 'path'" )
178+ validateParameter(params(0 ).asJsObject , " with" , " path" , true , " string" , " Default description for 'with'" )
179+ validateParameter(params(1 ).asJsObject , " double" , " path" , true , " string" , " Default description for 'double'" )
180+ validateParameter(params(2 ).asJsObject , " extra" , " path" , true , " string" , " Default description for 'extra'" )
181+ validateParameter(params(3 ).asJsObject , " path" , " path" , true , " string" , " Default description for 'path'" )
186182
187183 // Lets call the swagger url so we can make sure the response is valid and contains our path in the ow path
188184 val apiToInvoke = s " $swaggerApiUrl"
@@ -192,14 +188,11 @@ class ApiGwCliTests extends ApiGwCliBasicTests {
192188 response.statusCode should be(200 )
193189 response
194190 }, 6 , Some (2 .second))
195- val jsonReponse = JSON .parseFull(response.asString()).asInstanceOf [Option [Map [String , String ]]].get
196- jsonReponse.get(" __ow_path" ).get should not be (" " )
197- jsonReponse.get(" __ow_path" ).get should include (testRelPathGet)
198- } catch {
199- case unknown : Throwable => exception = unknown
191+ val jsonResponse = response.body.asString.parseJson.asJsObject
192+
193+ jsonResponse.fields(" __ow_path" ).toString should include (testRelPathGet)
200194 } finally {
201195 apiDelete(basepathOrApiName = testBasePath)
202196 }
203- assert(exception == null )
204197 }
205198}
0 commit comments