blob: 7b1d37b1ba4c5e14f22d2de047eca2ded7d8f6c8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jrt.tool;
import com.yahoo.jrt.Request;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
/**
* @author bratseth
*/
public class RpcInvokerTest extends junit.framework.TestCase {
public RpcInvokerTest(String name) {
super(name);
}
public void test0Args() {
assertCorrectArguments("");
}
public void test1StringShorthanArgs() {
assertCorrectArguments("foo");
}
public void test2StringArgs() {
assertCorrectArguments("s:foo s:bar");
}
public void test2StringShorthandArgs() {
assertCorrectArguments("foo bar");
}
protected void assertCorrectArguments(String argString) {
RpcInvoker invoker=new RpcInvoker();
List<String> args=toList(argString);
Request request=invoker.createRequest("testmethod",args);
for (int i=0; i<args.size(); i++) {
// Strip type here if present
String arg=args.get(i);
if (arg.length()>=1 && arg.charAt(1)==':')
arg=arg.substring(2);
assertEquals(arg,request.parameters().get(i).toString());
}
}
private List<String> toList(String argsString) {
List<String> argsList=new ArrayList<String>();
String[] argsArray=argsString.split(" ");
for (String arg : argsArray) {
if (arg.trim().length()==0) continue;
argsList.add(arg);
}
return argsList;
}
}
|