@Test public void testAllOptions() throws Exception { ClusterControllerFactory factory = mock(ClusterControllerFactory.class); ClusterController controller = mock(ClusterController.class); when(factory.create((String) any())).thenReturn(controller); DestroyClusterCommand command = new DestroyClusterCommand(factory); Map<String, File> keys = KeyPair.generateTemporaryFiles(); int rc = command.run(null, out, null, Lists.newArrayList( "--instance-templates", "1 noop", "--service-name", "test-service", "--cluster-name", "test-cluster", "--provider", "rackspace", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath(), "--version", "version-string" )); assertThat(rc, is(0)); Configuration conf = new PropertiesConfiguration(); conf.addProperty("whirr.version", "version-string"); conf.addProperty("whirr.instance-templates", "1 noop"); ClusterSpec expectedClusterSpec = ClusterSpec.withTemporaryKeys(conf); expectedClusterSpec.setServiceName("test-service"); expectedClusterSpec.setProvider("rackspace"); expectedClusterSpec.setIdentity("myusername"); expectedClusterSpec.setCredential("mypassword"); expectedClusterSpec.setClusterName("test-cluster"); expectedClusterSpec.setPrivateKey(keys.get("private")); expectedClusterSpec.setPublicKey(keys.get("public")); verify(factory).create("test-service"); verify(controller).destroyCluster(expectedClusterSpec); }
@Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[args.size()])); if (!optionSet.nonOptionArguments().isEmpty()) { printUsage(err); return -1; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } }
DestroyClusterCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[args.size()])); if (!optionSet.nonOptionArguments().isEmpty()) { printUsage(err); return -1; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } }
DestroyClusterCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[args.size()])); if (!optionSet.nonOptionArguments().isEmpty()) { printUsage(err); return -1; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } DestroyClusterCommand();  DestroyClusterCommand(ClusterControllerFactory factory); }
DestroyClusterCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[args.size()])); if (!optionSet.nonOptionArguments().isEmpty()) { printUsage(err); return -1; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } DestroyClusterCommand();  DestroyClusterCommand(ClusterControllerFactory factory); @Override int run(InputStream in, PrintStream out, PrintStream err,
                 List<String> args); int run(InputStream in, PrintStream out, PrintStream err,
                 ClusterSpec clusterSpec); }
DestroyClusterCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[args.size()])); if (!optionSet.nonOptionArguments().isEmpty()) { printUsage(err); return -1; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -1; } } DestroyClusterCommand();  DestroyClusterCommand(ClusterControllerFactory factory); @Override int run(InputStream in, PrintStream out, PrintStream err,
                 List<String> args); int run(InputStream in, PrintStream out, PrintStream err,
                 ClusterSpec clusterSpec);  }