GetClientLibAction extends EndpointsToolAction { @Override public boolean execute() throws ClassNotFoundException, IOException, ApiConfigException { String warPath = getWarPath(warOption); List<String> serviceClassNames = getServiceClassNames(warPath); if (serviceClassNames.isEmpty()) { return false; } getClientLib(computeClassPath(warPath, getClassPath(classPathOption)), getLanguage(languageOption), getOutputPath(outputOption), serviceClassNames, getBuildSystem(buildSystemOption), getHostname(hostnameOption, warPath), getBasePath(basePathOption), getDebug(debugOption) ); return true; } GetClientLibAction(); @Override boolean execute(); Object getClientLib(URL[] classPath, String language, String outputDirPath,
      List<String> serviceClassNames, String buildSystem, String hostname, String basePath,
      boolean debug); @Override String getUsageString(); static final String NAME; }
@Test public void testGetClientLibWithDebugOutput() throws Exception { tool.execute(new String[]{GetClientLibAction.NAME, option(EndpointsToolAction.OPTION_CLASS_PATH_SHORT), "classPath", option(EndpointsToolAction.OPTION_LANGUAGE_SHORT), "java", option(EndpointsToolAction.OPTION_OUTPUT_DIR_SHORT), "outputDir", option(EndpointsToolAction.OPTION_DEBUG, false), option(EndpointsToolAction.OPTION_HOSTNAME_SHORT), "foo.com", option(EndpointsToolAction.OPTION_BASE_PATH_SHORT), "/api", "MyService", "MyService2"}); assertFalse(usagePrinted); assertThat(Lists.newArrayList(classPath)) .containsExactly(new File("classPath").toURI().toURL(), new File(new File(EndpointsToolAction.DEFAULT_WAR_PATH).getAbsoluteFile(), "/WEB-INF/classes") .toURI() .toURL()); assertEquals("java", language); assertEquals("outputDir", outputDirPath); assertStringsEqual(Arrays.asList("MyService", "MyService2"), serviceClassNames); assertEquals(null, buildSystem); assertTrue(debugOutput); assertThat(hostname).isEqualTo("foo.com"); assertThat(basePath).isEqualTo("/api"); }
@Test public void testMissingOption() throws Exception { tool.execute(new String[]{GetClientLibAction.NAME, option(EndpointsToolAction.OPTION_CLASS_PATH_SHORT), "classPath", option(EndpointsToolAction.OPTION_HOSTNAME_SHORT), "foo.com", "MyService"}); assertFalse(usagePrinted); assertThat(Lists.newArrayList(classPath)) .containsExactly(new File("classPath").toURI().toURL(), new File(new File(EndpointsToolAction.DEFAULT_WAR_PATH).getAbsoluteFile(), "/WEB-INF/classes") .toURI() .toURL()); assertEquals(EndpointsToolAction.DEFAULT_LANGUAGE, language); assertEquals(EndpointsToolAction.DEFAULT_OUTPUT_PATH, outputDirPath); assertStringsEqual(Arrays.asList("MyService"), serviceClassNames); }
@Test public void testMissingArgument() throws Exception { tool.execute(new String[]{ GetClientLibAction.NAME, option(EndpointsToolAction.OPTION_CLASS_PATH_SHORT), "classPath", option(EndpointsToolAction.OPTION_OUTPUT_DIR_SHORT), "outputDir"}); assertTrue(usagePrinted); }
@Test public void testGetClientLibWithBuildSystem() throws Exception { tool.execute(new String[]{GetClientLibAction.NAME, option(EndpointsToolAction.OPTION_CLASS_PATH_SHORT), "classPath", option(EndpointsToolAction.OPTION_LANGUAGE_SHORT), "java", option(EndpointsToolAction.OPTION_OUTPUT_DIR_SHORT), "outputDir", option(EndpointsToolAction.OPTION_BUILD_SYSTEM_SHORT), "maven", option(EndpointsToolAction.OPTION_HOSTNAME_SHORT), "foo.com", "MyService", "MyService2"}); assertFalse(usagePrinted); assertThat(Lists.newArrayList(classPath)) .containsExactly(new File("classPath").toURI().toURL(), new File(new File(EndpointsToolAction.DEFAULT_WAR_PATH).getAbsoluteFile(), "/WEB-INF/classes") .toURI() .toURL()); assertEquals("java", language); assertEquals("outputDir", outputDirPath); assertStringsEqual(Arrays.asList("MyService", "MyService2"), serviceClassNames); assertEquals("maven", buildSystem); assertFalse(debugOutput); }