Skip to content
Snippets Groups Projects
Commit 63050098 authored by Rodric Rabbah's avatar Rodric Rabbah Committed by sjfink
Browse files

Fix for Java actions and UTF8.

parent 84770aa0
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
/*
* 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("❄ ☃ ❄")
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment