@Test public void testSubCommands() { String inputCommand1 = JVMViewCommand.CREATE_VIEW_SUB_COMMAND_NAME + "\n" + "custom" + "\ne\n"; String inputCommand2 = JVMViewCommand.IMPORT_SUB_COMMAND_NAME + "\nro0\n" + "java.util.*" + "\ne\n"; String inputCommand3 = JVMViewCommand.IMPORT_SUB_COMMAND_NAME + "\nro0\n" + "java.io.File" + "\ne\n"; String inputCommand4 = JVMViewCommand.REMOVE_IMPORT_SUB_COMMAND_NAME + "\nro0\n" + "java.io.File" + "\ne\n"; String inputCommand5 = JVMViewCommand.REMOVE_IMPORT_SUB_COMMAND_NAME + "\nro0\n" + "java.lang.*" + "\ne\n"; String inputCommand6 = JVMViewCommand.IMPORT_SUB_COMMAND_NAME + "\nrj\n" + "java.util.*" + "\ne\n"; try { command.execute("r", new BufferedReader(new StringReader(inputCommand1)), writer); assertEquals("!yro0\n", sWriter.toString()); JVMView view = (JVMView) gateway.getObject("o0"); command.execute("r", new BufferedReader(new StringReader(inputCommand2)), writer); assertEquals("!yro0\n!yv\n", sWriter.toString()); assertEquals(2, view.getStarImports().size()); assertTrue(view.getStarImports().contains("java.util")); command.execute("r", new BufferedReader(new StringReader(inputCommand3)), writer); assertEquals("!yro0\n!yv\n!yv\n", sWriter.toString()); assertTrue(view.getSingleImportsMap().containsKey("File")); assertEquals(1, view.getSingleImportsMap().size()); command.execute("r", new BufferedReader(new StringReader(inputCommand2)), writer); assertEquals("!yro0\n!yv\n!yv\n!yv\n", sWriter.toString()); assertEquals(2, view.getStarImports().size()); command.execute("r", new BufferedReader(new StringReader(inputCommand3)), writer); assertEquals("!yro0\n!yv\n!yv\n!yv\n!yv\n", sWriter.toString()); assertTrue(view.getSingleImportsMap().containsKey("File")); assertEquals(1, view.getSingleImportsMap().size()); command.execute("r", new BufferedReader(new StringReader(inputCommand4)), writer); assertEquals("!yro0\n!yv\n!yv\n!yv\n!yv\n!ybtrue\n", sWriter.toString()); assertFalse(view.getSingleImportsMap().containsKey("File")); assertEquals(0, view.getSingleImportsMap().size()); command.execute("r", new BufferedReader(new StringReader(inputCommand4)), writer); assertEquals("!yro0\n!yv\n!yv\n!yv\n!yv\n!ybtrue\n!ybfalse\n", sWriter.toString()); assertFalse(view.getSingleImportsMap().containsKey("File")); assertEquals(0, view.getSingleImportsMap().size()); command.execute("r", new BufferedReader(new StringReader(inputCommand5)), writer); assertEquals("!yro0\n!yv\n!yv\n!yv\n!yv\n!ybtrue\n!ybfalse\n!ybtrue\n", sWriter.toString()); assertFalse(view.getStarImports().contains("java.lang.*")); assertEquals(1, view.getStarImports().size()); command.execute("r", new BufferedReader(new StringReader(inputCommand5)), writer); assertEquals("!yro0\n!yv\n!yv\n!yv\n!yv\n!ybtrue\n!ybfalse\n!ybtrue\n!ybfalse\n", sWriter.toString()); assertFalse(view.getStarImports().contains("java.lang.*")); assertEquals(1, view.getStarImports().size()); command.execute("r", new BufferedReader(new StringReader(inputCommand6)), writer); assertEquals("!yro0\n!yv\n!yv\n!yv\n!yv\n!ybtrue\n!ybfalse\n!ybtrue\n!ybfalse\n!yv\n", sWriter.toString()); assertFalse(gateway.getDefaultJVMView().getStarImports().contains("java.util.*")); assertEquals(2, gateway.getDefaultJVMView().getStarImports().size()); } catch (Exception e) { e.printStackTrace(); fail(); } }
@Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { char subCommand = safeReadLine(reader).charAt(0); String returnCommand = null; if (subCommand == CREATE_VIEW_SUB_COMMAND_NAME) { returnCommand = createJVMView(reader); } else if (subCommand == IMPORT_SUB_COMMAND_NAME) { returnCommand = doImport(reader); } else if (subCommand == REMOVE_IMPORT_SUB_COMMAND_NAME) { returnCommand = removeImport(reader); } else if (subCommand == SEARCH_SUB_COMMAND_NAME) { returnCommand = search(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown JVM View SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); }
JVMViewCommand extends AbstractCommand { @Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { char subCommand = safeReadLine(reader).charAt(0); String returnCommand = null; if (subCommand == CREATE_VIEW_SUB_COMMAND_NAME) { returnCommand = createJVMView(reader); } else if (subCommand == IMPORT_SUB_COMMAND_NAME) { returnCommand = doImport(reader); } else if (subCommand == REMOVE_IMPORT_SUB_COMMAND_NAME) { returnCommand = removeImport(reader); } else if (subCommand == SEARCH_SUB_COMMAND_NAME) { returnCommand = search(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown JVM View SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); } }
JVMViewCommand extends AbstractCommand { @Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { char subCommand = safeReadLine(reader).charAt(0); String returnCommand = null; if (subCommand == CREATE_VIEW_SUB_COMMAND_NAME) { returnCommand = createJVMView(reader); } else if (subCommand == IMPORT_SUB_COMMAND_NAME) { returnCommand = doImport(reader); } else if (subCommand == REMOVE_IMPORT_SUB_COMMAND_NAME) { returnCommand = removeImport(reader); } else if (subCommand == SEARCH_SUB_COMMAND_NAME) { returnCommand = search(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown JVM View SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); } JVMViewCommand(); }
JVMViewCommand extends AbstractCommand { @Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { char subCommand = safeReadLine(reader).charAt(0); String returnCommand = null; if (subCommand == CREATE_VIEW_SUB_COMMAND_NAME) { returnCommand = createJVMView(reader); } else if (subCommand == IMPORT_SUB_COMMAND_NAME) { returnCommand = doImport(reader); } else if (subCommand == REMOVE_IMPORT_SUB_COMMAND_NAME) { returnCommand = removeImport(reader); } else if (subCommand == SEARCH_SUB_COMMAND_NAME) { returnCommand = search(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown JVM View SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); } JVMViewCommand(); @Override void execute(String commandName, BufferedReader reader, BufferedWriter writer); @Override void init(Gateway gateway, Py4JServerConnection connection); }
JVMViewCommand extends AbstractCommand { @Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { char subCommand = safeReadLine(reader).charAt(0); String returnCommand = null; if (subCommand == CREATE_VIEW_SUB_COMMAND_NAME) { returnCommand = createJVMView(reader); } else if (subCommand == IMPORT_SUB_COMMAND_NAME) { returnCommand = doImport(reader); } else if (subCommand == REMOVE_IMPORT_SUB_COMMAND_NAME) { returnCommand = removeImport(reader); } else if (subCommand == SEARCH_SUB_COMMAND_NAME) { returnCommand = search(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown JVM View SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); } JVMViewCommand(); @Override void execute(String commandName, BufferedReader reader, BufferedWriter writer); @Override void init(Gateway gateway, Py4JServerConnection connection); final static char CREATE_VIEW_SUB_COMMAND_NAME; final static char IMPORT_SUB_COMMAND_NAME; final static char REMOVE_IMPORT_SUB_COMMAND_NAME; final static char SEARCH_SUB_COMMAND_NAME; static final String JVMVIEW_COMMAND_NAME; }