org.jline.terminal.impl.DumbTerminal Java Examples

The following examples show how to use org.jline.terminal.impl.DumbTerminal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseNonExistingDB() throws Exception {
	Executor executor = mock(Executor.class);
	doThrow(new SqlExecutionException("mocked exception")).when(executor).useDatabase(any(), any());
	InputStream inputStream = new ByteArrayInputStream("use db;\n".getBytes());
	// don't care about the output
	OutputStream outputStream = new OutputStream() {
		@Override
		public void write(int b) throws IOException {
		}
	};
	CliClient cliClient = null;
	try (Terminal terminal = new DumbTerminal(inputStream, outputStream)) {
		cliClient = new CliClient(terminal, new SessionContext("test-session", new Environment()), executor);
		cliClient.open();
		verify(executor).useDatabase(any(), any());
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #2
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseNonExistingCatalog() throws Exception {
	Executor executor = mock(Executor.class);
	doThrow(new SqlExecutionException("mocked exception")).when(executor).useCatalog(any(), any());
	InputStream inputStream = new ByteArrayInputStream("use catalog cat;\n".getBytes());
	// don't care about the output
	OutputStream outputStream = new OutputStream() {
		@Override
		public void write(int b) throws IOException {
		}
	};
	CliClient cliClient = null;
	try (Terminal terminal = new DumbTerminal(inputStream, outputStream)) {
		cliClient = new CliClient(terminal, new SessionContext("test-session", new Environment()), executor);
		cliClient.open();
		verify(executor).useCatalog(any(), any());
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #3
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseNonExistingDB() throws Exception {
	TestingExecutor executor = new TestingExecutorBuilder()
		.setUseDatabaseConsumer((ignored1, ignored2) -> {
			throw new SqlExecutionException("mocked exception");
		})
		.build();
	InputStream inputStream = new ByteArrayInputStream("use db;\n".getBytes());
	SessionContext session = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(session);

	CliClient cliClient = null;
	try (Terminal terminal = new DumbTerminal(inputStream, new MockOutputStream())) {
		cliClient = new CliClient(terminal, sessionId, executor, File.createTempFile("history", "tmp").toPath());

		cliClient.open();
		assertThat(executor.getNumUseDatabaseCalls(), is(1));
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #4
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseNonExistingCatalog() throws Exception {
	TestingExecutor executor = new TestingExecutorBuilder()
		.setUseCatalogConsumer((ignored1, ignored2) -> {
			throw new SqlExecutionException("mocked exception");
		})
		.build();

	InputStream inputStream = new ByteArrayInputStream("use catalog cat;\n".getBytes());
	CliClient cliClient = null;
	SessionContext sessionContext = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(sessionContext);

	try (Terminal terminal = new DumbTerminal(inputStream, new MockOutputStream())) {
		cliClient = new CliClient(terminal, sessionId, executor, File.createTempFile("history", "tmp").toPath());
		cliClient.open();
		assertThat(executor.getNumUseCatalogCalls(), is(1));
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #5
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTableWithInvalidDdl() throws Exception {
	TestingExecutor executor = new TestingExecutorBuilder().build();

	// proctimee() is invalid
	InputStream inputStream = new ByteArrayInputStream("create table tbl(a int, b as proctimee());\n".getBytes());
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
	CliClient cliClient = null;
	SessionContext sessionContext = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(sessionContext);

	try (Terminal terminal = new DumbTerminal(inputStream, outputStream)) {
		cliClient = new CliClient(terminal, sessionId, executor, File.createTempFile("history", "tmp").toPath());
		cliClient.open();
		String output = new String(outputStream.toByteArray());
		assertTrue(output.contains("No match found for function signature proctimee()"));
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #6
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testHistoryFile() throws Exception {
	final SessionContext context = new SessionContext("test-session", new Environment());
	final MockExecutor mockExecutor = new MockExecutor();
	String sessionId = mockExecutor.openSession(context);

	InputStream inputStream = new ByteArrayInputStream("help;\nuse catalog cat;\n".getBytes());
	CliClient cliClient = null;
	try (Terminal terminal = new DumbTerminal(inputStream, new MockOutputStream())) {
		Path historyFilePath = File.createTempFile("history", "tmp").toPath();
		cliClient = new CliClient(terminal, sessionId, mockExecutor, historyFilePath);
		cliClient.open();
		List<String> content = Files.readAllLines(historyFilePath);
		assertEquals(2, content.size());
		assertTrue(content.get(0).contains("help"));
		assertTrue(content.get(1).contains("use catalog cat"));
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #7
Source File: CliClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * execute a sql statement and return the terminal output as string.
 */
private String testExecuteSql(TestingExecutor executor, String sql) throws IOException {
	InputStream inputStream = new ByteArrayInputStream((sql + "\n").getBytes());
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
	CliClient cliClient = null;
	SessionContext sessionContext = new SessionContext("test-session", new Environment());
	String sessionId = executor.openSession(sessionContext);

	try (Terminal terminal = new DumbTerminal(inputStream, outputStream)) {
		cliClient = new CliClient(terminal, sessionId, executor, File.createTempFile("history", "tmp").toPath());
		cliClient.open();
		return new String(outputStream.toByteArray());
	} finally {
		if (cliClient != null) {
			cliClient.close();
		}
	}
}
 
Example #8
Source File: TerminalUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static Terminal createDummyTerminal() {
	try {
		return new DumbTerminal(new MockInputStream(), new MockOutputStream());
	} catch (IOException e) {
		throw new RuntimeException("Unable to create dummy terminal.");
	}
}
 
Example #9
Source File: TerminalUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static Terminal createDummyTerminal() {
	try {
		return new DumbTerminal(new MockInputStream(), new MockOutputStream());
	} catch (IOException e) {
		throw new RuntimeException("Unable to create dummy terminal.");
	}
}
 
Example #10
Source File: TerminalUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static Terminal createDummyTerminal(OutputStream out) {
	try {
		return new DumbTerminal(new MockInputStream(), out);
	} catch (IOException e) {
		throw new RuntimeException("Unable to create dummy terminal.");
	}
}
 
Example #11
Source File: SqlLineArgsTest.java    From sqlline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testTableOutputWithZeroMaxWidthAndExistingTerminal() {
  try {
    new MockUp<DumbTerminal>() {
      @Mock
      public Size getSize() {
        return new Size(80, 20);
      }
    };
    final LineReaderBuilder lineReaderBuilder = LineReaderBuilder.builder()
        .parser(new SqlLineParser(sqlLine))
        .terminal(TerminalBuilder.builder().dumb(true).build());
    sqlLine.setLineReader(lineReaderBuilder.build());
    final String script = "!set maxwidth 0\n"
        + "!set incremental true\n"
        + "values (1, cast(null as integer), cast(null as varchar(3)));\n";
    checkScriptFile(script, false,
        equalTo(SqlLine.Status.OK),
        containsString(
            "+-------------+-------------+-----+\n"
                + "|     C1      |     C2      | C3  |\n"
                + "+-------------+-------------+-----+\n"
                + "| 1           | null        |     |\n"
                + "+-------------+-------------+-----+\n"));
  } catch (Exception e) {
    fail("Test failed with ", e);
  }
}
 
Example #12
Source File: SqlLineArgsTest.java    From sqlline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testAnsiConsoleFormatWithZeroMaxWidthAndExistingTerminal() {
  try {
    new MockUp<DumbTerminal>() {
      @Mock
      public Size getSize() {
        return new Size(80, 20);
      }
    };
    final LineReaderBuilder lineReaderBuilder = LineReaderBuilder.builder()
        .parser(new SqlLineParser(sqlLine))
        .terminal(TerminalBuilder.builder().dumb(true).build());
    sqlLine.setLineReader(lineReaderBuilder.build());
    final String script = "!set maxwidth 0\n"
        + "!set incremental true \n"
        + "!set outputformat ansiconsole \n"
        + "!all \n"
        + "values \n"
        + "(1, '2') \n"
        + ";\n";
    final String line1 = ""
        + "C1          C2\n"
        + "1           2 \n";
    checkScriptFile(script, false,
        equalTo(SqlLine.Status.OK),
        containsString(line1));
  } catch (Exception e) {
    fail("Test failed with ", e);
  }
}