package me.prettyprint.cassandra.service;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.Set;

import me.prettyprint.cassandra.BaseEmbededServerSetupTest;

import org.apache.cassandra.thrift.KsDef;
import org.apache.cassandra.thrift.NotFoundException;
import org.apache.cassandra.thrift.TokenRange;
import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransportException;
import org.junit.Before;
import org.junit.Test;


public class CassandraClusterTest extends BaseEmbededServerSetupTest { 
  
  private Cluster cassandraCluster;
  private CassandraHostConfigurator cassandraHostConfigurator;

  
  @Before
  public void setupCase() throws TTransportException, TException, IllegalArgumentException,
          NotFoundException, UnknownHostException, Exception {
    cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170");        
    cassandraCluster = new Cluster("Test Cluster", cassandraHostConfigurator);
  }
  
  @Test
  public void testDescribeKeyspaces() throws Exception {
    List<KsDef> keyspaces = cassandraCluster.describeKeyspaces();
    assertEquals(2,keyspaces.size());
  }
  
  @Test
  public void testDescribeClusterName() throws Exception {
    assertEquals("Test Cluster",cassandraCluster.describeClusterName());
  }
  
  /**
   * This will need to be updated as we update the Thrift API, but probably a good sanity check
   * 
   */
  @Test
  public void testDescribeThriftVersion() throws Exception {
    assertEquals("10.0.0",cassandraCluster.describeThriftVersion());
  }

  @Test
  public void testDescribeRing() throws Exception {
    List<TokenRange> ring = cassandraCluster.describeRing("Keyspace1");
    assertEquals(1, ring.size());
  }
  
  
  
  @Test
  public void testDescribeKeyspace() throws Exception {
    KsDef keyspaceDetail = cassandraCluster.describeKeyspace("Keyspace1");
    assertNotNull(keyspaceDetail);
    assertEquals(6,keyspaceDetail.cf_defs.size());    
  }
  
}

@@ -192,52 +192,8 @@
 ist;
-%0Aimport java.util.Map;%0Aimport java.util.Set;
 %0A%0Aim
@@ -607,20 +607,17 @@
 upTest %7B
- %0A  
+%0A
 %0A  priva
@@ -709,19 +709,17 @@
 rator;%0A%0A
-  
 %0A
+
   @Befor
@@ -955,24 +955,16 @@
 :9170%22);
-        
 %0A    cas
@@ -1035,27 +1035,25 @@
 rator);%0A  %7D%0A
-  
 %0A
+
   @Test%0A  pu
@@ -1213,19 +1213,17 @@
 ));%0A  %7D%0A
-  
 %0A
+
   @Test%0A
@@ -1358,19 +1358,17 @@
 ));%0A  %7D%0A
-  
 %0A
+
   /**%0A  
@@ -1465,17 +1465,16 @@
 eck%0A   *
- 
 %0A   */%0A 
@@ -1560,17 +1560,17 @@
 quals(%221
-0
+1
 .0.0%22,ca
@@ -1785,24 +1785,18 @@
 ));%0A  %7D%0A
-  %0A  %0A  
+%0A%0A
 %0A  @Test
@@ -1983,10 +1983,11 @@
 als(
-6,
+7, 
 keys
@@ -2017,18 +2017,12 @@
 ());
-    
 %0A  %7D%0A
-  
 %0A%7D%0A

Fix CassandraClusterTest to work with the new thrift version and new cassandra.yaml configuration