use of org.webpieces.util.cmdline2.CommandLineParser in project webpieces by deanhiller.
the class PrivateWebserverForTest method init.
private void init(PrivateTestConfig testConfig, String... args) {
// read here and checked for correctness on last line of server construction
Arguments arguments = new CommandLineParser().parse(args);
String filePath = System.getProperty("user.dir");
log.info("property user.dir=" + filePath);
File baseWorkingDir = FileFactory.getBaseWorkingDir();
// 3 pieces to the webserver so a configuration for each piece
WebServerConfig config = new WebServerConfig().setPlatformOverrides(testConfig.getPlatformOverrides());
RouterConfig routerConfig = new RouterConfig(baseWorkingDir, "webpiecesTestSuite").setMetaFile(testConfig.getMetaFile()).setWebappOverrides(testConfig.getAppOverrides()).setFileEncoding(CHAR_SET_TO_USE).setDefaultResponseBodyEncoding(CHAR_SET_TO_USE).setCachedCompressedDirectory(cacheDir).setSecretKey(SecretKeyInfo.generateForTest()).setTokenCheckOn(testConfig.isUseTokenCheck());
TemplateConfig templateConfig = new TemplateConfig();
webServer = WebServerFactory.create(config, routerConfig, templateConfig, arguments);
arguments.checkConsumedCorrectly();
}
use of org.webpieces.util.cmdline2.CommandLineParser in project webpieces by deanhiller.
the class CmdLineParser2Test method testKeyIsOptionalAndRequiredNotPassedInShouldFail.
@Test
public void testKeyIsOptionalAndRequiredNotPassedInShouldFail() {
String[] args = new String[] {};
Arguments parse = new CommandLineParser().parse(args);
// different default values not allowed. both must default to same thing
// this is a weird case
parse.createOptionalArg("key1", "123", "key1 help", (s) -> convertInt(s));
parse.createRequiredArg("key1", "key1 help from different plugin, and reasons are different", (s) -> convertInt(s));
try {
parse.checkConsumedCorrectly();
} catch (CommandLineException e) {
Assert.assertEquals("Errors converting command line arguments:\n" + "(Call CommandLineException.getErrors to get the stack trace of each failure)\n" + "java.lang.IllegalArgumentException: Argument -key1 is required but was not supplied. help='key1 help from different plugin, and reasons are different'\n" + "\n" + "Dynamically generated help(depends on which plugins you pull in):\n" + " -key1 following usages:\n" + " (optional, default: 123)key1 help\n" + " Value Parsed:null foundKey:false foundValue:false\n" + " key1 help from different plugin, and reasons are different\n" + " Value Parsed:null foundKey:false foundValue:false\n", e.getMessage());
}
}
use of org.webpieces.util.cmdline2.CommandLineParser in project webpieces by deanhiller.
the class CmdLineParser2Test method testDeveloperHasInvalidDefaultValueAndRequiredMissing.
@Test
public void testDeveloperHasInvalidDefaultValueAndRequiredMissing() {
String[] args = new String[] { "-key1=something" };
Arguments parse = new CommandLineParser().parse(args);
parse.createOptionalArg("key1", "invalid", "key1 help", (s) -> convertInt(s));
parse.createRequiredArg("key3", "Some key3", (s) -> s);
try {
parse.checkConsumedCorrectly();
Assert.fail("Should have thrown telling developer all errors");
} catch (CommandLineException e) {
List<Throwable> errors = e.getErrors();
Assert.assertEquals(2, errors.size());
Assert.assertEquals("Bug, The defaultValue conversion test failed. key=key1 value=invalid", errors.get(0).getMessage());
Assert.assertEquals("Argument -key3 is required but was not supplied. help='Some key3'", errors.get(1).getMessage());
}
}
use of org.webpieces.util.cmdline2.CommandLineParser in project webpieces by deanhiller.
the class CmdLineParser2Test method testKeyIsOptionalAndRequiredPassedInShouldSucceed.
@Test
public void testKeyIsOptionalAndRequiredPassedInShouldSucceed() {
String[] args = new String[] { "-key1=5" };
Arguments parse = new CommandLineParser().parse(args);
// different default values not allowed. both must default to same thing
// this is a weird case
Supplier<Integer> val1 = parse.createOptionalArg("key1", "123", "key1 help", (s) -> convertInt(s));
Supplier<Integer> val2 = parse.createRequiredArg("key1", "key1 help", (s) -> convertInt(s));
parse.checkConsumedCorrectly();
Assert.assertEquals(Integer.valueOf(5), val1.get());
Assert.assertEquals(Integer.valueOf(5), val2.get());
}
use of org.webpieces.util.cmdline2.CommandLineParser in project webpieces by deanhiller.
the class TestProdRouter method bothServers.
@SuppressWarnings("rawtypes")
@Parameterized.Parameters
public static Collection bothServers() {
String moduleFileContents = AppModules.class.getName();
VirtualFile f = new VirtualFileInputStream(moduleFileContents.getBytes(), "testAppModules");
File baseWorkingDir = FileFactory.getBaseWorkingDir();
TestModule module = new TestModule();
Arguments args = new CommandLineParser().parse();
RouterConfig config = new RouterConfig(baseWorkingDir, "TestProdRouter").setMetaFile(f).setWebappOverrides(module).setSecretKey(SecretKeyInfo.generateForTest());
SimpleMeterRegistry metrics = new SimpleMeterRegistry();
TemplateApi nullApi = new NullTemplateApi();
RouterService prodSvc = RouterServiceFactory.create(metrics, config, nullApi);
prodSvc.configure(args);
args.checkConsumedCorrectly();
return Arrays.asList(new Object[][] { { prodSvc, module } });
}
Aggregations