diff --git a/tests/src/actionContainers/JavaActionContainerTests.scala b/tests/src/actionContainers/JavaActionContainerTests.scala index c8f6c8479ee426505306148d1b6c47124ed2defb..5125b4cd354d19cb477bb8b0481a925c9e7b183b 100644 --- a/tests/src/actionContainers/JavaActionContainerTests.scala +++ b/tests/src/actionContainers/JavaActionContainerTests.scala @@ -120,6 +120,35 @@ class JavaActionContainerTests extends FlatSpec with Matchers with WskActorSyste err.trim shouldBe empty } + it should "handle unicode in source, input params, logs, and result" in { + val (out, err) = withJavaContainer { c => + val jar = JarBuilder.mkBase64Jar( + Seq("example", "HelloWhisk.java") -> """ + | package example; + | + | import com.google.gson.JsonObject; + | + | public class HelloWhisk { + | public static JsonObject main(JsonObject args) { + | String delimiter = args.getAsJsonPrimitive("delimiter").getAsString(); + | JsonObject response = new JsonObject(); + | String str = delimiter + " ☃ " + delimiter; + | System.out.println(str); + | response.addProperty("winter", str); + | return response; + | } + | } + """.stripMargin) + + val (initCode, _) = c.init(initPayload("example.HelloWhisk", jar)) + val (runCode, runRes) = c.run(runPayload(JsObject("delimiter" -> JsString("â„")))) + runRes.get.fields.get("winter") shouldBe Some(JsString("℠☃ â„")) + } + + out should include("℠☃ â„") + err.trim shouldBe empty + } + it should "fail to initialize with bad code" in { val (out, err) = withJavaContainer { c => // This is valid zip file containing a single file, but not a valid diff --git a/tests/src/system/basic/WskBasicNodeTests.scala b/tests/src/system/basic/WskBasicNodeTests.scala index 0a85ab7547c3012a2200c2cbcbdf177e550feb05..9225584f9f5d62ed9d8922e2688c7fcae26e8a74 100644 --- a/tests/src/system/basic/WskBasicNodeTests.scala +++ b/tests/src/system/basic/WskBasicNodeTests.scala @@ -147,25 +147,6 @@ class WskBasicNodeTests } } - it should "Ensure that UTF-8 in supported in source files, input params, logs, and output results" in withAssetCleaner(wskprops) { - (wp, assetHelper) => - val name = "unicodeGalore" - - assetHelper.withCleaner(wsk.action, name) { - (action, _) => - action.create(name, Some(TestUtils.getTestActionFilename("unicode.js"))) - } - - withActivation(wsk.activation, wsk.action.invoke(name, parameters = Map("delimiter" -> JsString("â„")))) { - activation => - val response = activation.response - response.result.get.fields.get("error") shouldBe empty - response.result.get.fields.get("winter") should be(Some(JsString("℠☃ â„"))) - - activation.logs.toList.flatten.mkString(" ") should include("℠☃ â„") - } - } - // TODO: remove this tests and its assets when "whisk.js" is removed entirely as it is no longer necessary it should "Ensure that whisk.invoke() returns a promise" in withAssetCleaner(wskprops) { val expectedDuration = 3.seconds diff --git a/tests/src/system/basic/WskUnicodeTests.scala b/tests/src/system/basic/WskUnicodeTests.scala new file mode 100644 index 0000000000000000000000000000000000000000..b1188534a8af4ae9f1e86d85dea9b6bfc3fdd2b4 --- /dev/null +++ b/tests/src/system/basic/WskUnicodeTests.scala @@ -0,0 +1,60 @@ +/* + * 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 system.basic + +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +import common.JsHelpers +import common.TestHelpers +import common.TestUtils +import common.Wsk +import common.WskProps +import common.WskTestHelpers +import spray.json._ + +@RunWith(classOf[JUnitRunner]) +class WskUnicodeTests + extends TestHelpers + with WskTestHelpers + with JsHelpers { + + implicit val wskprops = WskProps() + val wsk = new Wsk + + Map("node" -> "unicode.js", "java" -> "unicode.jar").foreach { + case (k, file) => + s"$k action" should "Ensure that UTF-8 in supported in source files, input params, logs, and output results" in withAssetCleaner(wskprops) { + (wp, assetHelper) => + val name = s"unicodeGalore.$k" + + assetHelper.withCleaner(wsk.action, name) { + (action, _) => + action.create(name, Some(TestUtils.getTestActionFilename(file)), main = if (k == "java") Some("Unicode") else None) + } + + withActivation(wsk.activation, wsk.action.invoke(name, parameters = Map("delimiter" -> JsString("â„")))) { + activation => + val response = activation.response + response.result.get.fields.get("error") shouldBe empty + response.result.get.fields.get("winter") should be(Some(JsString("℠☃ â„"))) + + activation.logs.toList.flatten.mkString(" ") should include("℠☃ â„") + } + } + } +}