FossologySshConnector { public int runInFossologyViaSsh(String command) { return runInFossologyViaSsh(command, EMPTY_INPUT, BLACK_HOLE); } @Autowired  FossologySshConnector(JSchSessionProvider jSchSessionProvider, FossologySettings fossologySettings); int runInFossologyViaSsh(String command); int runInFossologyViaSsh(String command, InputStream stdin); int runInFossologyViaSsh(String command, OutputStream stdout); int runInFossologyViaSsh(String command, InputStream stdin, OutputStream stdout);  }
@Test public void testRunInFossologyViaSsh() throws Exception { final int exitCode = fossologySshConnector.runInFossologyViaSsh("cmd"); assertThat(exitCode, greaterThanOrEqualTo(0)); verify(jSchSessionProvider).getSession(connectionTimeout); verify(jSchSessionProvider, atLeastOnce()).closeSession(session); verify(channel, atLeastOnce()).disconnect(); }
@Test public void testRunInFossologyViaSsh1() throws Exception { InputStream stdin = mock(InputStream.class); final int exitCode = fossologySshConnector.runInFossologyViaSsh("cmd", stdin); assertThat(exitCode, greaterThanOrEqualTo(0)); verify(jSchSessionProvider).getSession(connectionTimeout); verify(jSchSessionProvider, atLeastOnce()).closeSession(any(Session.class)); verify(channel, atLeastOnce()).disconnect(); }
@Test public void testRunInFossologyViaSsh2() throws Exception { InputStream stdin = mock(InputStream.class); OutputStream stdout = mock(OutputStream.class); final int exitCode = fossologySshConnector.runInFossologyViaSsh("cmd", stdin, stdout); assertThat(exitCode, greaterThanOrEqualTo(0)); verify(jSchSessionProvider).getSession(connectionTimeout); verify(channel, atLeastOnce()).disconnect(); verify(jSchSessionProvider, atLeastOnce()).closeSession(session); }
@Test public void testRunInFossologyViaSsh3() throws Exception { OutputStream stdout = mock(OutputStream.class); doAnswer(new Answer<Integer>() { @Override public Integer answer(InvocationOnMock invocation) throws Throwable { final Object[] arguments = invocation.getArguments(); final InputStream inputStream = (InputStream) arguments[1]; assertThat(inputStream.read(), is(-1)); return 1; } }).when(fossologySshConnector).runInFossologyViaSsh(anyString(), any(InputStream.class), any(OutputStream.class)); final int exitCode = fossologySshConnector.runInFossologyViaSsh("cmd", stdout); assertThat(exitCode, greaterThanOrEqualTo(0)); verify(fossologySshConnector).runInFossologyViaSsh(eq("cmd"), any(InputStream.class), eq(stdout)); }