blob: f4bc4c44f4a48f256d35ffa6eee33c3282bb6f39 (
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
60
61
62
|
// Copyright Yahoo. 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 org.junit.Test;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
/**
* @author bratseth
*/
public class RpcInvokerTest {
@Test
public void test0Args() {
assertCorrectArguments("");
}
@Test
public void test1StringShorthanArgs() {
assertCorrectArguments("foo");
}
@Test
public void test2StringArgs() {
assertCorrectArguments("s:foo s:bar");
}
@Test
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;
}
}
|