SaveToCassandraOperationsService { public void alterTable(String streamName, Set<String> oldColumnNames, List<ColumnNameTypeValue> columns) { StringBuilder sb = new StringBuilder(); for (Entry<String, String> entry : getStreamFieldsAndTypes(columns).entrySet()) { if (!oldColumnNames.contains(entry.getKey())) { sb.append(String.format("ALTER TABLE %s.%s ADD %s %s;", STREAMING.STREAMING_KEYSPACE_NAME, addQuotes(streamName), addQuotes(entry.getKey()), entry.getValue())); } } if (!"".equals(sb.toString())) { session.execute(sb.toString()); } } SaveToCassandraOperationsService(Session session); Boolean check(); void refreshTablenames(); void checkKeyspace(); void createKeyspace(String keyspaceName); void createTable(String tableName, List<ColumnNameTypeValue> columns, String timestampColumnName); Insert createInsertStatement(String streamName, List<ColumnNameTypeValue> columns, String timestampColumnName); void alterTable(String streamName, Set<String> oldColumnNames, List<ColumnNameTypeValue> columns); HashMap<String, Integer> getTableNames(); Session getSession();  }
@Test public void testAlterTable() throws Exception { Exception ex= null; try { columns.add(new ColumnNameTypeValue("newfield", ColumnType.STRING, "my new value")); Set<String> oldColumnNamesnew= new ListOrderedSet(); oldColumnNamesnew.add("id"); oldColumnNamesnew.add("name"); oldColumnNamesnew.add("enabled"); oldColumnNamesnew.add("timestamp"); service.alterTable(TABLE, oldColumnNamesnew, columns); } catch (Exception e) { ex= e; } assertEquals("Expected null but exception found", null, ex); }