@Test public void testRun() throws Exception { Map<String, Object> configuration = new HashMap<>(); configuration.put("default", "profile-1"); Map<String, String> profile1 = new HashMap<>(); profile1.put("endpoint", "https: configuration.put("profile-1", profile1); Map<String, String> profile2 = new HashMap<>(); profile2.put("endpoint", "https: configuration.put("profile-2", profile2); ConfigureCommand command = new ConfigureCommand(new Shell(), configuration, Paths.get(getClass().getResource("/configure-command-test.yml").getPath())); command.run(new Line("configure", new HashMap<>(), new ArrayList<>())); assertThat(configuration.size(), is(3)); assertThat(configuration.get("default"), is("profile-1")); command = new ConfigureCommand(new Shell(), configuration, Paths.get(getClass().getResource("/configure-command-test.yml").getPath())); Map<String, String> options = new HashMap<>(); options.put("default", null); List<String> args = new ArrayList<>(); args.add("not-found"); command.run(new Line("configure", options, args)); assertThat(configuration.size(), is(3)); assertThat(configuration.get("default"), is("profile-1")); command = spy(new ConfigureCommand(new Shell(), configuration, Paths.get(getClass().getResource("/configure-command-test.yml").getPath()))); doNothing().when(command, "write"); args = new ArrayList<>(); args.add("profile-2"); command.run(new Line("configure", options, args)); assertThat(configuration.size(), is(3)); assertThat(configuration.get("default"), is("profile-2")); verifyPrivate(command, times(1)).invoke("write"); configuration = new HashMap<>(); configuration.put("default", "profile-1"); options = new HashMap<>(); options.put("default", null); args = new ArrayList<>(); command.run(new Line("configure", options, args)); assertThat(configuration.size(), is(1)); assertThat(configuration.get("default"), is("profile-1")); options = new HashMap<>(); args = new ArrayList<>(); args.add("profile-2"); command.run(new Line("configure", options, args)); assertThat(configuration.size(), is(1)); assertThat(configuration.get("default"), is("profile-1")); args = new ArrayList<>(); args.add("profile-2"); args.add("profile-3"); command.run(new Line("configure", options, args)); assertThat(configuration.size(), is(1)); assertThat(configuration.get("default"), is("profile-1")); }
@Override public void run(Line line) throws Exception { if (line.args().size() == 1) { String profile = line.args().get(0); if (line.options().containsKey("default")) { if (!configuration.containsKey(profile)) { log.warn("Profile [" + profile + "] does not exist. Run deploy <profile> command first"); return; } configuration.put("default", profile); write(); shell.console().prompt("prodigy|" + profile + "> "); log.info("Default profile has been updated with [" + profile + "]"); log.debug("Configuration file [" + path + "] updated"); Files.readAllLines(path).stream().forEach(shell.console()::println); return; } } else if (line.args().isEmpty()) { if (line.options().isEmpty()) { read().stream().forEach(shell.console()::println); return; } } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); }
ConfigureCommand implements Command { @Override public void run(Line line) throws Exception { if (line.args().size() == 1) { String profile = line.args().get(0); if (line.options().containsKey("default")) { if (!configuration.containsKey(profile)) { log.warn("Profile [" + profile + "] does not exist. Run deploy <profile> command first"); return; } configuration.put("default", profile); write(); shell.console().prompt("prodigy|" + profile + "> "); log.info("Default profile has been updated with [" + profile + "]"); log.debug("Configuration file [" + path + "] updated"); Files.readAllLines(path).stream().forEach(shell.console()::println); return; } } else if (line.args().isEmpty()) { if (line.options().isEmpty()) { read().stream().forEach(shell.console()::println); return; } } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); } }
ConfigureCommand implements Command { @Override public void run(Line line) throws Exception { if (line.args().size() == 1) { String profile = line.args().get(0); if (line.options().containsKey("default")) { if (!configuration.containsKey(profile)) { log.warn("Profile [" + profile + "] does not exist. Run deploy <profile> command first"); return; } configuration.put("default", profile); write(); shell.console().prompt("prodigy|" + profile + "> "); log.info("Default profile has been updated with [" + profile + "]"); log.debug("Configuration file [" + path + "] updated"); Files.readAllLines(path).stream().forEach(shell.console()::println); return; } } else if (line.args().isEmpty()) { if (line.options().isEmpty()) { read().stream().forEach(shell.console()::println); return; } } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); } ConfigureCommand(Shell shell, Map<String, Object> configuration, Path path); }
ConfigureCommand implements Command { @Override public void run(Line line) throws Exception { if (line.args().size() == 1) { String profile = line.args().get(0); if (line.options().containsKey("default")) { if (!configuration.containsKey(profile)) { log.warn("Profile [" + profile + "] does not exist. Run deploy <profile> command first"); return; } configuration.put("default", profile); write(); shell.console().prompt("prodigy|" + profile + "> "); log.info("Default profile has been updated with [" + profile + "]"); log.debug("Configuration file [" + path + "] updated"); Files.readAllLines(path).stream().forEach(shell.console()::println); return; } } else if (line.args().isEmpty()) { if (line.options().isEmpty()) { read().stream().forEach(shell.console()::println); return; } } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); } ConfigureCommand(Shell shell, Map<String, Object> configuration, Path path); @Override String name(); @Override Usage usage(); @Override void run(Line line); }
ConfigureCommand implements Command { @Override public void run(Line line) throws Exception { if (line.args().size() == 1) { String profile = line.args().get(0); if (line.options().containsKey("default")) { if (!configuration.containsKey(profile)) { log.warn("Profile [" + profile + "] does not exist. Run deploy <profile> command first"); return; } configuration.put("default", profile); write(); shell.console().prompt("prodigy|" + profile + "> "); log.info("Default profile has been updated with [" + profile + "]"); log.debug("Configuration file [" + path + "] updated"); Files.readAllLines(path).stream().forEach(shell.console()::println); return; } } else if (line.args().isEmpty()) { if (line.options().isEmpty()) { read().stream().forEach(shell.console()::println); return; } } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); } ConfigureCommand(Shell shell, Map<String, Object> configuration, Path path); @Override String name(); @Override Usage usage(); @Override void run(Line line);  }