| /* |
| * Copyright 2015-2016 IBM Corporation |
| * |
| * 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 |
| * |
| * http://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. |
| */ |
| |
| package whisk.core.cli.test |
| |
| import spray.json.JsObject |
| import spray.json.JsArray |
| import spray.json.JsString |
| import spray.json.JsNumber |
| import spray.json.JsBoolean |
| |
| object JsonArgsForTests { |
| |
| def getEscapedJSONTestArgInput(parameters: Boolean = true) = Seq( |
| if (parameters) "-p" else "-a", |
| "\"key\"with\\escapes", // key: key"with\escapes (will be converted to JSON string "key\"with\\escapes") |
| "{\"valid\": \"JSON\"}", // value: {"valid":"JSON"} |
| if (parameters) "-p" else "-a", |
| "another\"escape\"", // key: another"escape" (will be converted to JSON string "another\"escape\"") |
| "{\"valid\": \"\\nJ\\rO\\tS\\bN\\f\"}", // value: {"valid":"\nJ\rO\tS\bN\f"} JSON strings can escape: \n, \r, \t, \b, \f |
| // NOTE: When uncommentting these tests, be sure to include the expected response in getEscapedJSONTestArgOutput() |
| // if (parameters) "-p" else "-a", |
| // "escape\\again", // key: escape\again (will be converted to JSON string "escape\\again") |
| // "{\"valid\": \"JS\\u2312ON\"}", // value: {"valid":"JS\u2312ON"} JSON strings can have escaped 4 digit unicode |
| // if (parameters) "-p" else "-a", |
| // "mykey", // key: mykey (will be converted to JSON string "key") |
| // "{\"valid\": \"JS\\/ON\"}", // value: {"valid":"JS\/ON"} JSON strings can have escaped \/ |
| if (parameters) "-p" else "-a", |
| "key1", // key: key (will be converted to JSON string "key") |
| "{\"nonascii\": \"日本語\"}", // value: {"nonascii":"日本語"} JSON strings can have non-ascii |
| if (parameters) "-p" else "-a", |
| "key2", // key: key (will be converted to JSON string "key") |
| "{\"valid\": \"J\\\\SO\\\"N\"}" // value: {"valid":"J\\SO\"N"} JSON strings can have escaped \\ and \" |
| ) |
| |
| def getEscapedJSONTestArgOutput() = JsArray( |
| JsObject( |
| "key" -> JsString("\"key\"with\\escapes"), |
| "value" -> JsObject( |
| "valid" -> JsString("JSON") |
| ) |
| ), |
| JsObject( |
| "key" -> JsString("another\"escape\""), |
| "value" -> JsObject( |
| "valid" -> JsString("\nJ\rO\tS\bN\f") |
| ) |
| ), |
| JsObject( |
| "key" -> JsString("key1"), |
| "value" -> JsObject( |
| "nonascii" -> JsString("日本語") |
| ) |
| ), |
| JsObject( |
| "key" -> JsString("key2"), |
| "value" -> JsObject( |
| "valid" -> JsString("J\\SO\"N") |
| ) |
| ) |
| ) |
| |
| def getValidJSONTestArgOutput() = JsArray( |
| JsObject( |
| "key" -> JsString("number"), |
| "value" -> JsNumber(8) |
| ), |
| JsObject( |
| "key" -> JsString("objArr"), |
| "value" -> JsArray( |
| JsObject( |
| "name" -> JsString("someName"), |
| "required" -> JsBoolean(true) |
| ), |
| JsObject( |
| "name" -> JsString("events"), |
| "count" -> JsNumber(10) |
| ) |
| ) |
| ), |
| JsObject( |
| "key" -> JsString("strArr"), |
| "value" -> JsArray( |
| JsString("44"), |
| JsString("55") |
| ) |
| ), |
| JsObject( |
| "key" -> JsString("string"), |
| "value" -> JsString("This is a string") |
| ), |
| JsObject( |
| "key" -> JsString("numArr"), |
| "value" -> JsArray( |
| JsNumber(44), |
| JsNumber(55) |
| ) |
| ), |
| JsObject( |
| "key" -> JsString("object"), |
| "value" -> JsObject( |
| "objString" -> JsString("aString"), |
| "objStrNum" -> JsString("123"), |
| "objNum" -> JsNumber(300), |
| "objBool" -> JsBoolean(false), |
| "objNumArr" -> JsArray( |
| JsNumber(1), |
| JsNumber(2) |
| ), |
| "objStrArr" -> JsArray( |
| JsString("1"), |
| JsString("2") |
| ) |
| ) |
| ), |
| JsObject( |
| "key" -> JsString("strNum"), |
| "value" -> JsString("9") |
| ) |
| ) |
| |
| def getValidJSONTestArgInput() = Map( |
| "string" -> JsString("This is a string"), |
| "strNum" -> JsString("9"), |
| "number" -> JsNumber(8), |
| "numArr" -> JsArray( |
| JsNumber(44), |
| JsNumber(55) |
| ), |
| "strArr" -> JsArray( |
| JsString("44"), |
| JsString("55") |
| ), |
| "objArr" -> JsArray( |
| JsObject( |
| "name" -> JsString("someName"), |
| "required" -> JsBoolean(true) |
| ), |
| JsObject( |
| "name" -> JsString("events"), |
| "count" -> JsNumber(10) |
| ) |
| ), |
| "object" -> JsObject( |
| "objString" -> JsString("aString"), |
| "objStrNum" -> JsString("123"), |
| "objNum" -> JsNumber(300), |
| "objBool" -> JsBoolean(false), |
| "objNumArr" -> JsArray( |
| JsNumber(1), |
| JsNumber(2) |
| ), |
| "objStrArr" -> JsArray( |
| JsString("1"), |
| JsString("2") |
| ) |
| ) |
| ) |
| } |