Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Jan 11, 2021
1 parent c2f0ffc commit c0ef9f5
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ protected RiotApp app() {
return new RiotDb();
}

protected String applicationName() {
@Override
protected String appName() {
return "riot-db";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ protected RiotApp app() {
return new RiotFile();
}

@Override
protected String appName() {
return "riot-file";
}

protected <T> List<T> readAll(AbstractItemCountingItemStreamItemReader<T> reader) throws Exception {
reader.open(new ExecutionContext());
List<T> records = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ protected RiotApp app() {
return new RiotGen();
}

@Override
protected String appName() {
return "riot-gen";
}

@Test
public void genFakerHash() throws Exception {
executeFile("/import-hmset.txt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ protected RiotApp app() {
return new RiotRedis();
}

@Override
protected String appName() {
return "riot-redis";
}

@BeforeEach
public void setupTarget() {
targetRedisURI = RedisURI.create(targetRedis.getHost(), targetRedis.getFirstMappedPort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ protected RiotApp app() {
return new RiotRedis();
}

@Override
protected String appName() {
return "riot-redis";
}

@Override
protected String connectionArgs() {
return "-u " + String.join(" ", sourceURIs.stream().map(String::valueOf).collect(Collectors.toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ protected RiotApp app() {
return new RiotStream();
}

@Override
protected String appName() {
return "riot-stream";
}

@Override
protected String process(String command) {
return super.process(command).replace("localhost:9092", kafka.getBootstrapServers());
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/com/redislabs/riot/RiotApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
@Command(usageHelpAutoWidth = true, sortOptions = false, versionProvider = ManifestVersionProvider.class, subcommands = HiddenGenerateCompletion.class, abbreviateSynopsis = true)
public class RiotApp implements Runnable {

@Getter
@Spec
private Model.CommandSpec commandSpec;

private static final String ROOT_LOGGER = "";

@Option(names = {"-H", "--help"}, usageHelp = true, description = "Show this help message and exit.")
Expand Down
22 changes: 10 additions & 12 deletions test/src/main/java/com/redislabs/riot/test/AbstractRiotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ public abstract class AbstractRiotTest {
protected static final int REDIS_PORT = 6379;
private final static String COMMAND_PREAMBLE = "❯";

protected String commandPrefix(RiotApp app) {
return COMMAND_PREAMBLE + " " + applicationName(app);
protected String commandPrefix() {
return COMMAND_PREAMBLE + " " + appName();
}

private String applicationName(RiotApp app) {
return app.getCommandSpec().name();
}
protected abstract String appName();

private String removePreamble(RiotApp app, String command) {
if (command.startsWith(commandPrefix(app))) {
return command.substring(commandPrefix(app).length());
private String removePreamble(String command) {
if (command.startsWith(commandPrefix())) {
return command.substring(commandPrefix().length());
}
return command;
}
Expand All @@ -38,20 +36,20 @@ protected Object command(String file) throws Exception {

protected Object command(RiotApp app, String file) throws Exception {
CommandLine commandLine = app.commandLine();
CommandLine.ParseResult parseResult = app.parse(commandLine, args(app, file));
CommandLine.ParseResult parseResult = app.parse(commandLine, args(file));
return parseResult.subcommand().commandSpec().commandLine().getCommand();
}

private String[] args(RiotApp app, String filename) throws Exception {
private String[] args(String filename) throws Exception {
try (InputStream inputStream = getClass().getResourceAsStream(filename)) {
String command = IOUtils.toString(inputStream, Charset.defaultCharset());
return CommandLineUtils.translateCommandline(process(removePreamble(app, command)));
return CommandLineUtils.translateCommandline(process(removePreamble(command)));
}
}

protected int executeFile(String filename) throws Exception {
RiotApp app = app();
return app.execute(args(app, filename));
return app.execute(args(filename));
}

protected String process(String command) {
Expand Down

0 comments on commit c0ef9f5

Please sign in to comment.