@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); DeployCommand command = new DeployCommand(new Shell(), configuration, Paths.get(getClass().getResource("/deploy-command-test.yml").getPath())); Map<String, String> options = new HashMap<>(); List<String> args = new ArrayList<>(); args.add("core"); command.run(new Line("deploy", options, args)); assertThat(configuration.size(), is(3)); assertThat(configuration.get("default"), is("profile-1")); Shell shell = new Shell(); command = spy(new DeployCommand(shell, configuration, Paths.get("/path/to/not-found.yml"))); Map<String, String> c = new HashMap<>(); c.put("endpoint", "https: doReturn(c).when(command, "deploy", anyString()); doNothing().when(command, "touch"); doNothing().when(command, "write"); doReturn(new ArrayList<>()).when(command, "read"); args = new ArrayList<>(); args.add("profile-3"); command.run(new Line("deploy", options, args)); assertThat(configuration.size(), is(4)); assertThat(configuration.get("default"), is("profile-3")); assertThat(shell.commands().size(), is(6)); assertThat(shell.commands().get(new ConfigureCommand(null, null, null).name()), instanceOf(ConfigureCommand.class)); assertThat(shell.commands().get(new InjectCommand(null, null).name()), instanceOf(InjectCommand.class)); assertThat(shell.commands().get(new EjectCommand(null, null).name()), instanceOf(EjectCommand.class)); assertThat(shell.commands().get(new StatusCommand(null, null).name()), instanceOf(StatusCommand.class)); assertThat(shell.commands().get(new FaultsCommand(null, null).name()), instanceOf(FaultsCommand.class)); assertThat(shell.commands().get(new PushCommand(null, null).name()), instanceOf(PushCommand.class)); verifyPrivate(command, times(1)).invoke("deploy", anyString()); verifyPrivate(command, times(1)).invoke("touch"); verifyPrivate(command, times(1)).invoke("write"); shell = new Shell(); command = spy(new DeployCommand(shell, configuration, Paths.get(getClass().getResource("/deploy-command-test.yml").getPath()))); c = new HashMap<>(); c.put("endpoint", "https: doReturn(c).when(command, "deploy", anyString()); doNothing().when(command, "touch"); doNothing().when(command, "write"); args = new ArrayList<>(); args.add("profile-4"); command.run(new Line("deploy", options, args)); assertThat(configuration.size(), is(5)); assertThat(configuration.get("default"), is("profile-4")); assertThat(shell.commands().size(), is(6)); assertThat(shell.commands().get(new ConfigureCommand(null, null, null).name()), instanceOf(ConfigureCommand.class)); assertThat(shell.commands().get(new InjectCommand(null, null).name()), instanceOf(InjectCommand.class)); assertThat(shell.commands().get(new EjectCommand(null, null).name()), instanceOf(EjectCommand.class)); assertThat(shell.commands().get(new StatusCommand(null, null).name()), instanceOf(StatusCommand.class)); assertThat(shell.commands().get(new FaultsCommand(null, null).name()), instanceOf(FaultsCommand.class)); assertThat(shell.commands().get(new PushCommand(null, null).name()), instanceOf(PushCommand.class)); verifyPrivate(command, times(1)).invoke("deploy", anyString()); verifyPrivate(command, never()).invoke("touch"); verifyPrivate(command, times(1)).invoke("write"); command = new DeployCommand(new Shell(), configuration, Paths.get(getClass().getResource("/deploy-command-test.yml").getPath())); args = new ArrayList<>(); command.run(new Line("deploy", options, args)); assertThat(configuration.size(), is(5)); assertThat(configuration.get("default"), is("profile-4")); command = new DeployCommand(new Shell(), configuration, Paths.get(getClass().getResource("/deploy-command-test.yml").getPath())); args = new ArrayList<>(); args.add("profile-1"); args.add("profile-2"); command.run(new Line("deploy", options, args)); assertThat(configuration.size(), is(5)); assertThat(configuration.get("default"), is("profile-4")); }
@Override public void run(Line line) throws Exception { if (line.args().size() == 1) { String profile = line.args().get(0); if (profile != null && !profile.isEmpty() && !profile.equals("core")) { try { Map<String, String> c = deploy(profile); configuration.put("default", profile); configuration.put(profile, c); if (Files.notExists(path)) { touch(); } write(); shell.console().prompt("prodigy|" + profile + "> "); log.info("Default profile has been updated with [" + profile + "]"); log.debug("Configuration file [" + path + "] updated"); read().stream().forEach(log::debug); Command command = new ConfigureCommand(shell, configuration, path); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + ConfigureCommand.class.getName() + "] enabled"); } command = new InjectCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + InjectCommand.class.getName() + "] enabled"); } command = new EjectCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + EjectCommand.class.getName() + "] enabled"); } command = new StatusCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + StatusCommand.class.getName() + "] enabled"); } command = new FaultsCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + FaultsCommand.class.getName() + "] enabled"); } command = new PushCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + PushCommand.class.getName() + "] enabled"); } shell.console().println("Prodigy has been successfully deployed for profile [" + profile + "]"); } catch (Exception e) { log.warn(e.getMessage(), e); } return; } } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); }
DeployCommand implements Command { @Override public void run(Line line) throws Exception { if (line.args().size() == 1) { String profile = line.args().get(0); if (profile != null && !profile.isEmpty() && !profile.equals("core")) { try { Map<String, String> c = deploy(profile); configuration.put("default", profile); configuration.put(profile, c); if (Files.notExists(path)) { touch(); } write(); shell.console().prompt("prodigy|" + profile + "> "); log.info("Default profile has been updated with [" + profile + "]"); log.debug("Configuration file [" + path + "] updated"); read().stream().forEach(log::debug); Command command = new ConfigureCommand(shell, configuration, path); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + ConfigureCommand.class.getName() + "] enabled"); } command = new InjectCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + InjectCommand.class.getName() + "] enabled"); } command = new EjectCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + EjectCommand.class.getName() + "] enabled"); } command = new StatusCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + StatusCommand.class.getName() + "] enabled"); } command = new FaultsCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + FaultsCommand.class.getName() + "] enabled"); } command = new PushCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + PushCommand.class.getName() + "] enabled"); } shell.console().println("Prodigy has been successfully deployed for profile [" + profile + "]"); } catch (Exception e) { log.warn(e.getMessage(), e); } return; } } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); } }
DeployCommand implements Command { @Override public void run(Line line) throws Exception { if (line.args().size() == 1) { String profile = line.args().get(0); if (profile != null && !profile.isEmpty() && !profile.equals("core")) { try { Map<String, String> c = deploy(profile); configuration.put("default", profile); configuration.put(profile, c); if (Files.notExists(path)) { touch(); } write(); shell.console().prompt("prodigy|" + profile + "> "); log.info("Default profile has been updated with [" + profile + "]"); log.debug("Configuration file [" + path + "] updated"); read().stream().forEach(log::debug); Command command = new ConfigureCommand(shell, configuration, path); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + ConfigureCommand.class.getName() + "] enabled"); } command = new InjectCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + InjectCommand.class.getName() + "] enabled"); } command = new EjectCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + EjectCommand.class.getName() + "] enabled"); } command = new StatusCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + StatusCommand.class.getName() + "] enabled"); } command = new FaultsCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + FaultsCommand.class.getName() + "] enabled"); } command = new PushCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + PushCommand.class.getName() + "] enabled"); } shell.console().println("Prodigy has been successfully deployed for profile [" + profile + "]"); } catch (Exception e) { log.warn(e.getMessage(), e); } return; } } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); } DeployCommand(Shell shell, Map<String, Object> configuration, Path path); }
DeployCommand implements Command { @Override public void run(Line line) throws Exception { if (line.args().size() == 1) { String profile = line.args().get(0); if (profile != null && !profile.isEmpty() && !profile.equals("core")) { try { Map<String, String> c = deploy(profile); configuration.put("default", profile); configuration.put(profile, c); if (Files.notExists(path)) { touch(); } write(); shell.console().prompt("prodigy|" + profile + "> "); log.info("Default profile has been updated with [" + profile + "]"); log.debug("Configuration file [" + path + "] updated"); read().stream().forEach(log::debug); Command command = new ConfigureCommand(shell, configuration, path); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + ConfigureCommand.class.getName() + "] enabled"); } command = new InjectCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + InjectCommand.class.getName() + "] enabled"); } command = new EjectCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + EjectCommand.class.getName() + "] enabled"); } command = new StatusCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + StatusCommand.class.getName() + "] enabled"); } command = new FaultsCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + FaultsCommand.class.getName() + "] enabled"); } command = new PushCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + PushCommand.class.getName() + "] enabled"); } shell.console().println("Prodigy has been successfully deployed for profile [" + profile + "]"); } catch (Exception e) { log.warn(e.getMessage(), e); } return; } } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); } DeployCommand(Shell shell, Map<String, Object> configuration, Path path); @Override String name(); @Override Usage usage(); @Override void run(Line line); void cloudFormation(AmazonCloudFormation cloudFormation); void s3(AmazonS3 s3); }
DeployCommand implements Command { @Override public void run(Line line) throws Exception { if (line.args().size() == 1) { String profile = line.args().get(0); if (profile != null && !profile.isEmpty() && !profile.equals("core")) { try { Map<String, String> c = deploy(profile); configuration.put("default", profile); configuration.put(profile, c); if (Files.notExists(path)) { touch(); } write(); shell.console().prompt("prodigy|" + profile + "> "); log.info("Default profile has been updated with [" + profile + "]"); log.debug("Configuration file [" + path + "] updated"); read().stream().forEach(log::debug); Command command = new ConfigureCommand(shell, configuration, path); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + ConfigureCommand.class.getName() + "] enabled"); } command = new InjectCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + InjectCommand.class.getName() + "] enabled"); } command = new EjectCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + EjectCommand.class.getName() + "] enabled"); } command = new StatusCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + StatusCommand.class.getName() + "] enabled"); } command = new FaultsCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + FaultsCommand.class.getName() + "] enabled"); } command = new PushCommand(shell, configuration); if (!shell.commands().containsKey(command.name())) { shell.register(command); log.debug("Command [" + PushCommand.class.getName() + "] enabled"); } shell.console().println("Prodigy has been successfully deployed for profile [" + profile + "]"); } catch (Exception e) { log.warn(e.getMessage(), e); } return; } } shell.console().println("Unsupported usage"); shell.console().println(usage().toString()); } DeployCommand(Shell shell, Map<String, Object> configuration, Path path); @Override String name(); @Override Usage usage(); @Override void run(Line line); void cloudFormation(AmazonCloudFormation cloudFormation); void s3(AmazonS3 s3);  }