Skip to content

Commit 18d9f4f

Browse files
authored
Merge pull request #113 from srl295/simple-fakebroker
use fakebroker to test gp-cli
2 parents 99d3eeb + f4eae1d commit 18d9f4f

5 files changed

Lines changed: 134 additions & 1 deletion

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
/target/
22
/bin/
3+
/test-gpconfig.json
4+
/test-fakebroker.json
5+

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jdk:
1313
- oraclejdk8
1414

1515
before_install:
16-
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
16+
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
17+
- curl $GP_FAKE_BROKER > test-fakebroker.json
1718

1819
after_success:
1920
- mvn clean cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:report -Dcobertura.report.format=xml

gp-cli/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,12 @@
104104
<artifactId>gp-res-filter</artifactId>
105105
<version>1.2.3-SNAPSHOT</version>
106106
</dependency>
107+
108+
<dependency>
109+
<groupId>junit</groupId>
110+
<artifactId>junit</artifactId>
111+
<version>4.12</version>
112+
<scope>test</scope>
113+
</dependency>
107114
</dependencies>
108115
</project>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright IBM Corp. 2018
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.ibm.g11n.pipeline.tools.cli;
18+
19+
import static org.junit.Assert.assertTrue;
20+
import static org.junit.Assume.assumeNotNull;
21+
22+
import java.io.File;
23+
import java.io.FileReader;
24+
import java.io.FileWriter;
25+
import java.io.IOException;
26+
import java.io.Reader;
27+
import java.io.Writer;
28+
import java.util.LinkedList;
29+
import java.util.List;
30+
31+
import com.google.gson.JsonElement;
32+
import com.google.gson.JsonObject;
33+
import com.google.gson.JsonParser;
34+
35+
public class FakebrokerMgr {
36+
37+
public static String FB_FILE = System.getProperty("GP_FAKEBROKER_FILE", "../test-fakebroker.json");
38+
public static String GPCONFIG_FILE = System.getProperty("GP_CONFIG_FILE", "../test-gpconfig.json");
39+
40+
public static File getConfigFile() {
41+
final File gpconfig = new File(GPCONFIG_FILE);
42+
final File fbfile = new File(FB_FILE);
43+
if(!gpconfig.isFile()) {
44+
if(fbfile.isFile()) {
45+
try (final Reader reader = new FileReader(fbfile)) {
46+
JsonElement parse = new JsonParser().parse(reader);
47+
JsonObject o = parse.getAsJsonObject();
48+
JsonObject creds = o.get("credentials").getAsJsonObject();
49+
try (final Writer writer = new FileWriter(gpconfig)) {
50+
writer.write(creds.toString()); // ?
51+
}
52+
} catch (IOException e) {
53+
e.printStackTrace();
54+
System.err.println("Could not convert " + fbfile.getAbsolutePath() + " to "
55+
+ gpconfig.getAbsolutePath());
56+
return null;
57+
}
58+
// convert fbFile to gpconfig
59+
System.err.println("Converted " + fbfile.getAbsolutePath() + " to "
60+
+ gpconfig.getAbsolutePath());
61+
return gpconfig;
62+
} else {
63+
System.err.println("no fakebroker file:" + fbfile.getAbsolutePath());
64+
return null;
65+
}
66+
} else {
67+
// System.out.println("OK: " + gpconfig.getAbsolutePath());
68+
return gpconfig;
69+
}
70+
}
71+
72+
public static void run(String... args) {
73+
final File gpconfig = getConfigFile();
74+
assumeNotNull(gpconfig); // skip test if not set
75+
assertTrue("Usage: run(\"list\", …) - arg count " + args.length, args.length > 0);
76+
final List<String> newArgs = new LinkedList<String>();
77+
final String verb = args[0];
78+
newArgs.add(verb); // verb
79+
newArgs.add("-j");
80+
newArgs.add(gpconfig.getAbsolutePath());
81+
for (int i = 1; i < args.length; i++) {
82+
newArgs.add(args[i]); // add the rest of the args
83+
}
84+
String[] asArray = newArgs.toArray(new String[0]);
85+
System.out.println("GPCmd: " + asArray);
86+
GPCmd.main(asArray);
87+
}
88+
89+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright IBM Corp. 2018
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.ibm.g11n.pipeline.tools.cli;
18+
19+
import org.junit.Test;
20+
21+
/**
22+
* @see ListBundlesCmd
23+
* @author srl
24+
*
25+
*/
26+
public class ListBundlesCmdTest {
27+
28+
@Test
29+
public void test() {
30+
FakebrokerMgr.run("list");
31+
}
32+
33+
}

0 commit comments

Comments
 (0)