TemplatesCommand extends CommandSupport { @Override public Object doExecuteWithContext(CloudStackClient client, PrintStream out) throws Exception { out.printf("CloudStack templates for provider %s\n", getProvider().getId()); for (Template template : client.getTemplateClient().listTemplates()) { out.printf("---\n%s\n", template.toString()); } out.println(); return null; } TemplatesCommand(DefaultProviderConfig providerConfig); @Override Object doExecuteWithContext(CloudStackClient client, PrintStream out); static final String NAME; }
@Test public void testTemplatesCommandPrintsTheTemplates() throws Exception { final TemplatesCommand templatesCommand = new TemplatesCommand(defaultProviderConfig); final TemplateClient templateClient = mock(TemplateClient.class); when(client.getTemplateClient()).thenReturn(templateClient); when(templateClient.listTemplates()).thenReturn(templates); templatesCommand.doExecuteWithContext(client, out); out.close(); assertThat(byteArrayOutputStream.toString()).contains("template-1").contains("template-one"); }