use of org.webpieces.util.cmdline2.Arguments in project webpieces by deanhiller.
the class RouterServiceFactory method create.
public static RouterService create(String testName, MeterRegistry metrics, VirtualFile routersFile, TemplateApi templateApi, Module... routerOverrides) {
File baseWorkingDir = FileFactory.getBaseWorkingDir();
Arguments arguments = new CommandLineParser().parse();
RouterConfig config = new RouterConfig(baseWorkingDir, testName).setMetaFile(routersFile).setSecretKey(SecretKeyInfo.generateForTest());
RouterService svc = create(metrics, config, templateApi, routerOverrides);
svc.configure(arguments);
arguments.checkConsumedCorrectly();
return svc;
}
use of org.webpieces.util.cmdline2.Arguments 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.Arguments in project webpieces by deanhiller.
the class CmdLineParser2Test method testOptionalConsumedTwiceDifferentDefaultValueThrowsException.
@Test
public void testOptionalConsumedTwiceDifferentDefaultValueThrowsException() {
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
parse.createOptionalArg("key1", "123", "key1 help", (s) -> convertInt(s));
parse.createOptionalArg("key1", "555", "help for different use of same key to give info on his need", (s) -> convertInt(s));
try {
parse.checkConsumedCorrectly();
Assert.fail("Should fail since defaults are different");
} 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.IllegalStateException: Bug, two people consuming key -key1 but both provide different defaults. default1=123 default2=555\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:5 foundKey:true foundValue:true\n" + " (optional, default: 555)help for different use of same key to give info on his need\n" + " Value Parsed:5 foundKey:true foundValue:true\n" + "", e.getMessage());
List<Throwable> errors = e.getErrors();
Assert.assertEquals(1, errors.size());
Assert.assertEquals("Bug, two people consuming key -key1 but both provide different defaults. default1=123 default2=555", errors.get(0).getMessage());
}
}
use of org.webpieces.util.cmdline2.Arguments in project webpieces by deanhiller.
the class CmdLineParser2Test method testExtraArgumentFails.
@Test
public void testExtraArgumentFails() {
String[] args = new String[] { "-key1=5", "-key2" };
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));
try {
parse.checkConsumedCorrectly();
Assert.fail("Should fail since someone says key1 is optional and another says it's required");
} catch (CommandLineException e) {
List<Throwable> errors = e.getErrors();
Assert.assertEquals(1, errors.size());
Assert.assertEquals("Key=key2 was not defined anywhere in the program", errors.get(0).getMessage());
}
}
use of org.webpieces.util.cmdline2.Arguments in project webpieces by deanhiller.
the class CmdLineParser2Test method testFailWithNoDash.
@Test
public void testFailWithNoDash() {
String[] args = new String[] { "-key1=3", "key2=6" };
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("key2", "key2 help", (s) -> convertInt(s));
try {
parse.checkConsumedCorrectly();
Assert.fail("Should fail since there is no -");
} catch (CommandLineException e) {
List<Throwable> errors = e.getErrors();
Assert.assertEquals(2, errors.size());
Assert.assertEquals("Argument 'key2=6' has a key that does not start with - which is required", errors.get(0).getMessage());
Assert.assertEquals("Argument -key2 is required but was not supplied. help='key2 help'", errors.get(1).getMessage());
}
}
Aggregations