use of org.webpieces.util.cmdline2.Arguments in project webpieces by deanhiller.
the class DevRouterFactory method create.
public static RouterService create(String testName, MeterRegistry metrics, VirtualFile routersFile, CompileConfig compileConfig, 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, compileConfig, templateApi);
svc.configure(arguments);
arguments.checkConsumedCorrectly();
return svc;
}
use of org.webpieces.util.cmdline2.Arguments 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.Arguments 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.Arguments 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.Arguments 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