DBSchemaDelegator extends BaseDelegator implements IDBSchemaDelegator { @Override public List<IDbSchema> getDbSchema(final List<String> tableSpecs) throws P4JavaException { String[] args = new String[0]; if (nonNull(tableSpecs)) { args = new String[tableSpecs.size()]; args = tableSpecs.toArray(args); } List<Map<String, Object>> resultMaps = execMapCmdList(DBSCHEMA, args, null); return ResultListBuilder.buildNonNullObjectListFromCommandResultMaps( resultMaps, new Function<Map, IDbSchema>() { @Override public IDbSchema apply(Map map) { return new DbSchema(map); } }); } DBSchemaDelegator(final IOptionsServer server); @Override List<IDbSchema> getDbSchema(final List<String> tableSpecs);  }
@Test public void testGetDbSchemaWithTable() throws Exception { CommandLineArgumentMatcher matcher = new CommandLineArgumentMatcher( new String[] { DB_CONFIG }); when(server.execMapCmdList(eq(DBSCHEMA.toString()), argThat(matcher), eq((Map<String,Object>)null))) .thenReturn(getMockResultMaps()); List<IDbSchema> schemas = dBSchemaDelegator .getDbSchema(Arrays.asList(new String[] { DB_CONFIG })); verify(server).execMapCmdList(eq(DBSCHEMA.toString()), argThat(matcher), eq((Map<String,Object>)null)); assertResult(schemas); }
@Test public void testGetDbSchemaWithoutTable() throws Exception { CommandLineArgumentMatcher matcher = new CommandLineArgumentMatcher(new String[] {}); when(server.execMapCmdList(eq(DBSCHEMA.toString()), argThat(matcher), eq((Map<String,Object>)null))) .thenReturn(getMockResultMaps()); List<IDbSchema> schemas = dBSchemaDelegator.getDbSchema(null); verify(server).execMapCmdList(eq(DBSCHEMA.toString()), argThat(matcher), eq((Map<String,Object>)null)); assertResult(schemas); }
@Test public void testGetDbSchemaWithTable() throws Exception { CommandLineArgumentMatcher matcher = new CommandLineArgumentMatcher( new String[] { DB_CONFIG }); when(server.execMapCmdList(eq(DBSCHEMA.toString()), argThat(matcher), eq(null))) .thenReturn(getMockResultMaps()); List<IDbSchema> schemas = dBSchemaDelegator .getDbSchema(Arrays.asList(new String[] { DB_CONFIG })); verify(server).execMapCmdList(eq(DBSCHEMA.toString()), argThat(matcher), eq(null)); assertResult(schemas); }
@Test public void testGetDbSchemaWithoutTable() throws Exception { CommandLineArgumentMatcher matcher = new CommandLineArgumentMatcher(new String[] {}); when(server.execMapCmdList(eq(DBSCHEMA.toString()), argThat(matcher), eq(null))) .thenReturn(getMockResultMaps()); List<IDbSchema> schemas = dBSchemaDelegator.getDbSchema(null); verify(server).execMapCmdList(eq(DBSCHEMA.toString()), argThat(matcher), eq(null)); assertResult(schemas); }