Package org.cassandraunit.spring

Source Code of org.cassandraunit.spring.CassandraStartAndLoadWithCQLsDatasetAnnotationTest

package org.cassandraunit.spring;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertEquals;

/**
* @author Olivier Bazoud
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = { "classpath:/default-context.xml" })
@TestExecutionListeners({ CassandraUnitTestExecutionListener.class })
@CassandraDataSet(value = { "cql/dataset1.cql", "cql/dataset2.cql" })
@EmbeddedCassandra
public class CassandraStartAndLoadWithCQLsDatasetAnnotationTest {

  @Test
  public void should_work() {
    test();
  }

  @Test
  public void should_work_twice() {
    test();
  }

  private void test() {
    Cluster cluster = Cluster.builder()
        .addContactPoints("127.0.0.1")
        .withPort(9142)
        .build();
    Session session = cluster.connect("cassandra_unit_keyspace");

    ResultSet result = session.execute("select * from testCQLTable1 WHERE id=1690e8da-5bf8-49e8-9583-4dff8a570717");
    String val = result.iterator().next().getString("value");
    assertEquals("1- Cql loaded string", val);

    result = session.execute("select * from testCQLTable2 WHERE id=1690e8da-5bf8-49e8-9583-4dff8a570727");
    val = result.iterator().next().getString("value");
    assertEquals("2- Cql loaded string", val);
  }

}
TOP

Related Classes of org.cassandraunit.spring.CassandraStartAndLoadWithCQLsDatasetAnnotationTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.