Skip to content
Snippets Groups Projects
Commit 0f332386 authored by Philippe Suter's avatar Philippe Suter Committed by Rodric Rabbah
Browse files

Java CLI action creation test.

parent 5e030fa6
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -4,7 +4,13 @@ import com.google.gson.JsonObject;
public class HelloJava {
public static JsonObject main(JsonObject args) {
String name = args.getAsJsonPrimitive("name").getAsString();
String name;
try {
name = args.getAsJsonPrimitive("name").getAsString();
} catch(Exception e) {
name = "stranger";
}
JsonObject response = new JsonObject();
response.addProperty("greeting", "Hello " + name + "!");
......
/*
* 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 static common.WskCli.Item.Action;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.google.code.tempusfugit.concurrency.ParallelRunner;
import common.Pair;
import common.TestUtils;
import common.WskCli;
@RunWith(ParallelRunner.class)
public class CLIJavaTests {
private static final WskCli wsk = new WskCli();
private static final int DEFAULT_WAIT = 30;
/**
* Test the Java "hello world" demo sequence
*/
@Test(timeout = 120 * 1000)
public void helloWorldJava() throws Exception {
final String actionName = "helloJava";
long start = System.currentTimeMillis();
try {
wsk.sanitize(Action, actionName);
wsk.createAction(actionName, TestUtils.getCatalogFilename("samples/helloJava/build/libs/helloJava.jar"));
final String activationIds[] = { null, null };
activationIds[0] = wsk.invoke(actionName, new HashMap<String, String>());
activationIds[1] = wsk.invoke(actionName, TestUtils.makeParameter(Pair.make("name", "Sir")));
final String expected[] = { "Hello stranger!", "Hello Sir!" };
for (int i = 0; i < activationIds.length; i++) {
boolean pass = wsk.checkResultFor(activationIds[i], expected[i], DEFAULT_WAIT);
assertTrue("Did not find " + expected[i] + " in activation " + activationIds[i], pass);
}
long duration = System.currentTimeMillis() - start;
assertTrue("Test took " + duration + "ms -- this is too slow.", duration < DEFAULT_WAIT * 1000);
} finally {
wsk.delete(Action, actionName);
}
}
}
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