EntryPointParser { public EntryPoint parse(Map<String, String> machineAttributes) throws InfrastructureException { String command = machineAttributes.get(MachineConfig.CONTAINER_COMMAND_ATTRIBUTE); String args = machineAttributes.get(MachineConfig.CONTAINER_ARGS_ATTRIBUTE); List<String> commandList = command == null ? emptyList() : parseAsList(command, MachineConfig.CONTAINER_COMMAND_ATTRIBUTE); List<String> argList = args == null ? emptyList() : parseAsList(args, MachineConfig.CONTAINER_ARGS_ATTRIBUTE); return new EntryPoint(commandList, argList); }  EntryPoint parse(Map<String, String> machineAttributes); String serializeEntry(List<String> entry);  }
@Test public void shouldParseCommandAndArgFromYAMLList() throws Exception { Map<String, String> cfg = new HashMap<>(); cfg.put(MachineConfig.CONTAINER_COMMAND_ATTRIBUTE, "['/bin/sh', '''yaml quoting ftw''']"); cfg.put(MachineConfig.CONTAINER_ARGS_ATTRIBUTE, "['x', 'y', '''z']"); EntryPointParser parser = new EntryPointParser(); EntryPoint ep = parser.parse(cfg); assertEquals(asList("/bin/sh", "'yaml quoting ftw'"), ep.getCommand()); assertEquals(asList("x", "y", "'z"), ep.getArguments()); }
@Test public void shouldParseCommandFromYAMLList() throws Exception { Map<String, String> cfg = new HashMap<>(); cfg.put(MachineConfig.CONTAINER_COMMAND_ATTRIBUTE, "['/bin/sh', '''yaml quoting ftw''']"); EntryPointParser parser = new EntryPointParser(); EntryPoint ep = parser.parse(cfg); assertEquals(asList("/bin/sh", "'yaml quoting ftw'"), ep.getCommand()); assertEquals(emptyList(), ep.getArguments()); }
@Test public void shouldParseArgsFromYAMLList() throws Exception { Map<String, String> cfg = new HashMap<>(); cfg.put(MachineConfig.CONTAINER_ARGS_ATTRIBUTE, "['x', 'y', '''z', --yes]"); EntryPointParser parser = new EntryPointParser(); EntryPoint ep = parser.parse(cfg); assertEquals(emptyList(), ep.getCommand()); assertEquals(asList("x", "y", "'z", "--yes"), ep.getArguments()); }
@Test(dataProvider = "invalidEntryProvider", expectedExceptions = InfrastructureException.class) public void shouldFailOnOtherYAMLDataType(String invalidEntry) throws InfrastructureException { Map<String, String> cfg = new HashMap<>(); cfg.put(MachineConfig.CONTAINER_ARGS_ATTRIBUTE, invalidEntry); EntryPointParser parser = new EntryPointParser(); parser.parse(cfg); }