1
|
package eu.dnetlib.iis.core.java;
|
2
|
|
3
|
import static org.junit.Assert.assertEquals;
|
4
|
|
5
|
import java.util.Map;
|
6
|
|
7
|
import org.apache.commons.cli.CommandLine;
|
8
|
import org.apache.hadoop.conf.Configuration;
|
9
|
import org.junit.Test;
|
10
|
|
11
|
import eu.dnetlib.iis.core.java.porttype.PortType;
|
12
|
|
13
|
/**
|
14
|
*
|
15
|
* @author Mateusz Kobos
|
16
|
*
|
17
|
*/
|
18
|
class DummyProcess implements Process {
|
19
|
|
20
|
public DummyProcess(){
|
21
|
}
|
22
|
|
23
|
@Override
|
24
|
public Map<String, PortType> getInputPorts() {
|
25
|
return null;
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
public Map<String, PortType> getOutputPorts(){
|
30
|
return null;
|
31
|
}
|
32
|
|
33
|
@Override
|
34
|
public void run(PortBindings portBindings, Configuration configuration,
|
35
|
Map<String, String> parameters){
|
36
|
}
|
37
|
}
|
38
|
|
39
|
class DummyProcessWithParametersConstructor implements Process{
|
40
|
public String[] params;
|
41
|
|
42
|
|
43
|
public DummyProcessWithParametersConstructor(String[] params){
|
44
|
this.params = params;
|
45
|
}
|
46
|
|
47
|
@Override
|
48
|
public Map<String, PortType> getInputPorts() {
|
49
|
return null;
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
public Map<String, PortType> getOutputPorts() {
|
54
|
return null;
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public void run(PortBindings portBindings, Configuration configuration,
|
59
|
Map<String, String> parameters) throws Exception {
|
60
|
}
|
61
|
|
62
|
}
|
63
|
|
64
|
public class CmdLineParserForProcessConstructionTest{
|
65
|
|
66
|
@Test
|
67
|
public void testTrivial() {
|
68
|
String[] args = new String[]{
|
69
|
"eu.dnetlib.iis.core.java.DummyProcess"};
|
70
|
CmdLineParserForProcessConstruction cmdLineParser =
|
71
|
new CmdLineParserForProcessConstruction();
|
72
|
CommandLine cmdLine = CmdLineParser.parse(args);
|
73
|
Process actual = cmdLineParser.run(cmdLine);
|
74
|
assertEquals(DummyProcess.class, actual.getClass());
|
75
|
}
|
76
|
|
77
|
@Test
|
78
|
public void testWithSomeParameters() {
|
79
|
String[] args = new String[]{
|
80
|
"eu.dnetlib.iis.core.java.DummyProcess",
|
81
|
"-Iperson=hdfs://localhost:8020/users/joe/person_input",
|
82
|
"-Idocument=hdfs://localhost:8020/users/joe/doc_input",
|
83
|
"-Omerged=hdfs://localhost:8020/users/joe/merged_out",
|
84
|
"-SclassName=java.util.String"};
|
85
|
CmdLineParserForProcessConstruction cmdLineParser =
|
86
|
new CmdLineParserForProcessConstruction();
|
87
|
CommandLine cmdLine = CmdLineParser.parse(args);
|
88
|
Process actual = cmdLineParser.run(cmdLine);
|
89
|
assertEquals(DummyProcess.class, actual.getClass());
|
90
|
}
|
91
|
|
92
|
@Test
|
93
|
public void testWithSomeParametersWithParametersConstructor() {
|
94
|
String[] constructorParams = new String[]{
|
95
|
"some string", "some other string"};
|
96
|
String[] args = new String[]{
|
97
|
"eu.dnetlib.iis.core.java.DummyProcessWithParametersConstructor",
|
98
|
"-C" + constructorParams[0],
|
99
|
"-C" + constructorParams[1],
|
100
|
"-Iperson=hdfs://localhost:8020/users/joe/person_input",
|
101
|
"-Idocument=hdfs://localhost:8020/users/joe/doc_input",
|
102
|
"-Omerged=hdfs://localhost:8020/users/joe/merged_out",
|
103
|
"-SclassName=java.util.String"};
|
104
|
CmdLineParserForProcessConstruction cmdLineParser =
|
105
|
new CmdLineParserForProcessConstruction();
|
106
|
CommandLine cmdLine = CmdLineParser.parse(args);
|
107
|
DummyProcessWithParametersConstructor actual =
|
108
|
(DummyProcessWithParametersConstructor) cmdLineParser.run(cmdLine);
|
109
|
assertEquals(DummyProcessWithParametersConstructor.class,
|
110
|
actual.getClass());
|
111
|
for(int i = 0; i < constructorParams.length; i++){
|
112
|
assertEquals(constructorParams[i], actual.params[i]);
|
113
|
}
|
114
|
|
115
|
}
|
116
|
}
|