ColumnsFunction implements Function<DataContainer> { @Override public DataContainer apply(List<Object> objects) { String tableName = String.valueOf(objects.get(0)); if (!tablesAware.getTables().contains(tableName)) { throw new IllegalArgumentException(String.format("Table %s does not exist", tableName)); } DataContainer dataContainer = new DataContainer(Arrays.asList(COLUMN_NAME, TYPE, DEFAULT_VALUE, INDEXED)); tablesAware.getColumns(tableName).forEach(c -> { String columnName = c.getName(); boolean isIndexed = indexStorage.getSignatures().stream() .anyMatch(s -> s.getDesiredColumns().containsKey(tableName) && s.getDesiredColumns().get(tableName).contains(columnName) ); dataContainer.addRow(Arrays.asList( columnName, humanizeType(c.getType()), String.valueOf(c.getDefaultValue()), String.valueOf(isIndexed) )); }); return dataContainer; } @Autowired  ColumnsFunction(TablesAware tablesAware, IndexStorage indexStorage); @Override Set<String> validateInput(List<Object> args); @Override Class<DataContainer> getReturnType(); @Override FunctionName getName(); @Override DataContainer apply(List<Object> objects); @Override String getSignature(); @Override String getDescription();  }
@Test public void testApply() { DataContainer data = function.apply(Collections.singletonList(INSTANCES_TABLE)); assertThat(data.getColumnNames(), contains("column_name", "type", "default_value", "indexed")); assertThat(data.getRows(), hasSize(tablesAware.getColumns(INSTANCES_TABLE).size())); }
@Test(expected = IllegalArgumentException.class) public void testMissingTable() { function.apply(Collections.singletonList("missing_table")); }