HelpPageCommand extends AbstractCommand { @Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { String returnCommand = null; String subCommand = safeReadLine(reader, false); if (subCommand.equals(HELP_OBJECT_SUB_COMMAND_NAME)) { returnCommand = getHelpObject(reader); } else if (subCommand.equals(HELP_CLASS_SUB_COMMAND_NAME)) { returnCommand = getHelpClass(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown Help SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); } HelpPageCommand(); @Override void execute(String commandName, BufferedReader reader, BufferedWriter writer); final static String HELP_COMMAND_NAME; final static String HELP_OBJECT_SUB_COMMAND_NAME; final static String HELP_CLASS_SUB_COMMAND_NAME; }
@Test public void testHelpObject() { String inputCommand = "o\n" + target + "\nn\ntrue\ne\n"; try { assertTrue(gateway.getBindings().containsKey(target)); command.execute("h", new BufferedReader(new StringReader(inputCommand)), writer); String page = sWriter.toString(); System.out.println(page); assertTrue(page.length() > 1); assertTrue(page.contains("method1")); assertTrue(page.contains("getField1")); } catch (Exception e) { e.printStackTrace(); fail(); } }
@Test public void testHelpObjectWithPattern() { String inputCommand = "o\n" + target + "\nsm*\ntrue\ne\n"; try { assertTrue(gateway.getBindings().containsKey(target)); command.execute("h", new BufferedReader(new StringReader(inputCommand)), writer); String page = sWriter.toString(); System.out.println(page); assertTrue(page.length() > 1); assertTrue(page.contains("method1")); assertTrue(!page.contains("getField1")); } catch (Exception e) { e.printStackTrace(); fail(); } }
@Test public void testHelpObjectWithPattern2() { String inputCommand = "o\n" + target + "\nsgetField1(*\ntrue\ne\n"; try { assertTrue(gateway.getBindings().containsKey(target)); command.execute("h", new BufferedReader(new StringReader(inputCommand)), writer); String page = sWriter.toString(); System.out.println(page); assertTrue(page.length() > 1); assertTrue(!page.contains("method1")); assertTrue(page.contains("getField1")); } catch (Exception e) { e.printStackTrace(); fail(); } }
@Test public void testHelpClass() { String inputCommand = "c\n" + ExampleClass.class.getName() + "\nn\ntrue\ne\n"; try { assertTrue(gateway.getBindings().containsKey(target)); command.execute("h", new BufferedReader(new StringReader(inputCommand)), writer); String page = sWriter.toString(); System.out.println(page); assertTrue(page.length() > 1); assertTrue(page.contains("method1")); assertTrue(page.contains("getField1")); } catch (Exception e) { e.printStackTrace(); fail(); } }
@Test public void testHelpClassPattern() { String inputCommand = "c\n" + ExampleClass.class.getName() + "\nsm*\ntrue\ne\n"; try { assertTrue(gateway.getBindings().containsKey(target)); command.execute("h", new BufferedReader(new StringReader(inputCommand)), writer); String page = sWriter.toString(); System.out.println(page); assertTrue(page.length() > 1); assertTrue(page.contains("method1")); assertTrue(!page.contains("getField1")); } catch (Exception e) { e.printStackTrace(); fail(); } }