Repository: metamodel
Updated Branches:
  refs/heads/master 3c4c12673 -> 287309422


METAMODEL-154: Fixed
Fixes #29


Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo
Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/28730942
Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/28730942
Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/28730942

Branch: refs/heads/master
Commit: 287309422d7d3c4f032dcd40c31cf2d8baec03a6
Parents: 3c4c126
Author: Alberto Rodriguez <arodrig...@stratio.com>
Authored: Fri Jun 19 08:25:59 2015 +0200
Committer: Alberto Rodriguez <arodrig...@stratio.com>
Committed: Fri Jun 19 08:25:59 2015 +0200

----------------------------------------------------------------------
 CHANGES.md                                      |   1 +
 cassandra/pom.xml                               |  31 ++++-
 .../cassandra/CassandraDataContextTest.java     | 114 ++++++-------------
 .../metamodel/cassandra/CassandraTestCase.java  |  95 ----------------
 pom.xml                                         |   4 +-
 5 files changed, 66 insertions(+), 179 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metamodel/blob/28730942/CHANGES.md
----------------------------------------------------------------------
diff --git a/CHANGES.md b/CHANGES.md
index d463e99..fe6046a 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -4,6 +4,7 @@
  * [METAMODEL-152] - Fixed an issue of not clearing schema cache when 
refreshSchemas() is invoked.
  * [METAMODEL-149] - Added support for COUNTER data type in Cassandra.
  * [METAMODEL-151] - Added support for DOUBLE data type mapping in PostgreSQL
+ * [METAMODEL-154] - Use embedded Cassandra server for integration tests.
 
 ### Apache MetaModel 4.3.4
 

http://git-wip-us.apache.org/repos/asf/metamodel/blob/28730942/cassandra/pom.xml
----------------------------------------------------------------------
diff --git a/cassandra/pom.xml b/cassandra/pom.xml
index d132945..d1ef41f 100644
--- a/cassandra/pom.xml
+++ b/cassandra/pom.xml
@@ -50,5 +50,34 @@
                        <artifactId>junit</artifactId>
                        <scope>test</scope>
                </dependency>
+        <dependency>
+            <groupId>org.cassandraunit</groupId>
+            <artifactId>cassandra-unit</artifactId>
+            <version>2.1.3.1</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
-</project>
\ No newline at end of file
+
+    <profiles>
+        <profile>
+            <id>jdk6</id>
+            <activation>
+                <jdk>1.6</jdk>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <version>2.18.1</version>
+                        <configuration>
+                            <excludes>
+                                
<exclude>**/CassandraDataContextTest.java</exclude>
+                            </excludes>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+</project>

http://git-wip-us.apache.org/repos/asf/metamodel/blob/28730942/cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraDataContextTest.java
----------------------------------------------------------------------
diff --git 
a/cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraDataContextTest.java
 
b/cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraDataContextTest.java
index 931a4fd..c00bea3 100644
--- 
a/cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraDataContextTest.java
+++ 
b/cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraDataContextTest.java
@@ -22,21 +22,24 @@ import java.util.Arrays;
 import java.util.List;
 import javax.swing.table.TableModel;
 
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Session;
+import junit.framework.TestCase;
 import org.apache.metamodel.data.DataSet;
 import org.apache.metamodel.data.DataSetTableModel;
 import org.apache.metamodel.data.FilteredDataSet;
 import org.apache.metamodel.query.Query;
 import org.apache.metamodel.schema.ColumnType;
 import org.apache.metamodel.schema.Table;
+import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
 
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.Session;
-
-public class CassandraDataContextTest extends CassandraTestCase {
-
+public class CassandraDataContextTest extends TestCase {
     private CassandraSimpleClient client = new CassandraSimpleClient();
     private Cluster cluster;
     private CassandraDataContext dc;
+    private int defaultCassandraPort = 9142;
+    private String cassandraNode = "127.0.0.1";
+    private String keyspaceName = "my_keyspace";
     private String testTableName = "songs";
     private String testCounterTableName = "counter";
     private String firstRowId = "756716f7-2e54-4715-9f00-91dcbea6cf51";
@@ -50,32 +53,26 @@ public class CassandraDataContextTest extends 
CassandraTestCase {
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        if (isConfigured()) {
-            client.connect(getHostname(), getPort());
-            cluster = client.getCluster();
-            Session session = cluster.connect();
-            dc = new CassandraDataContext(cluster, getKeyspaceName());
-            createCassandraKeySpaceAndTables(session);
-            populateCassandraTableWithSomeData(session);
-            populateCassandraCounterTableWithSomeData(session);
-        }
+        EmbeddedCassandraServerHelper.startEmbeddedCassandra();
+        client.connect(cassandraNode, defaultCassandraPort);
+        cluster = client.getCluster();
+        Session session = cluster.connect();
+        createCassandraKeySpaceAndTable(session);
+        populateCassandraTableWithSomeData(session);
+        populateCassandraCounterTableWithSomeData(session);
+        dc = new CassandraDataContext(cluster, keyspaceName);
     }
 
     @Override
     protected void tearDown() throws Exception {
         super.tearDown();
-        if (isConfigured()) {
-            client.close();
-        }
+        client.close();
     }
 
     public void testSchemaAndSimpleQuery() throws Exception {
-        if (!isConfigured()) {
-            System.err.println(getInvalidConfigurationMessage());
-            return;
-        }
-
-        assertEquals("[" + testCounterTableName +", "+testTableName + "]", 
Arrays.toString(dc.getDefaultSchema().getTableNames()));
+        String existingTables = 
Arrays.toString(dc.getDefaultSchema().getTableNames());
+        assertTrue(existingTables.contains(testTableName));
+        assertTrue(existingTables.contains(testCounterTableName));
 
         Table table = dc.getDefaultSchema().getTableByName(testTableName);
 
@@ -103,14 +100,10 @@ public class CassandraDataContextTest extends 
CassandraTestCase {
     }
 
     public void testWhereColumnEqualsValues() throws Exception {
-        if (!isConfigured()) {
-            System.err.println(getInvalidConfigurationMessage());
-            return;
-        }
         DataSet ds = 
dc.query().from(testTableName).select("id").and("title").where("id").isEquals(firstRowId)
                 .execute();
-        assertEquals(FilteredDataSet.class, ds.getClass());
 
+        assertEquals(FilteredDataSet.class, ds.getClass());
         try {
             assertTrue(ds.next());
             assertEquals("Row[values=[" + firstRowId + ", " + firstRowTitle + 
"]]", ds.getRow().toString());
@@ -121,13 +114,8 @@ public class CassandraDataContextTest extends 
CassandraTestCase {
     }
 
     public void testWhereColumnInValues() throws Exception {
-        if (!isConfigured()) {
-            System.err.println(getInvalidConfigurationMessage());
-            return;
-        }
         DataSet ds = 
dc.query().from(testTableName).select("id").and("title").where("title")
                 .in(firstRowTitle, secondRowTitle).orderBy("id").execute();
-
         try {
             assertTrue(ds.next());
             assertEquals("Row[values=[" + firstRowId + ", " + firstRowTitle + 
"]]", ds.getRow().toString());
@@ -140,70 +128,46 @@ public class CassandraDataContextTest extends 
CassandraTestCase {
     }
 
     public void testMaxRows() throws Exception {
-        if (!isConfigured()) {
-            System.err.println(getInvalidConfigurationMessage());
-            return;
-        }
         Table table = dc.getDefaultSchema().getTableByName(testTableName);
         Query query = new 
Query().from(table).select(table.getColumns()).setMaxRows(2);
         DataSet dataSet = dc.executeQuery(query);
-
         TableModel tableModel = new DataSetTableModel(dataSet);
+
         assertEquals(2, tableModel.getRowCount());
     }
 
     public void testCountQuery() throws Exception {
-        if (!isConfigured()) {
-            System.err.println(getInvalidConfigurationMessage());
-            return;
-        }
         Table table = dc.getDefaultSchema().getTableByName(testTableName);
         Query q = new Query().selectCount().from(table);
-
         List<Object[]> data = dc.executeQuery(q).toObjectArrays();
         assertEquals(1, data.size());
         Object[] row = data.get(0);
+
         assertEquals(1, row.length);
         assertEquals("[3]", Arrays.toString(row));
     }
 
     public void testQueryForANonExistingTable() throws Exception {
-        if (!isConfigured()) {
-            System.err.println(getInvalidConfigurationMessage());
-            return;
-        }
         boolean thrown = false;
         try {
             
dc.query().from("nonExistingTable").select("user").and("message").execute();
         } catch (IllegalArgumentException IAex) {
             thrown = true;
-        } finally {
-            // ds.close();
         }
         assertTrue(thrown);
     }
 
     public void testQueryForAnExistingTableAndNonExistingField() throws 
Exception {
-        if (!isConfigured()) {
-            System.err.println(getInvalidConfigurationMessage());
-            return;
-        }
         boolean thrown = false;
         try {
             
dc.query().from(testTableName).select("nonExistingField").execute();
         } catch (IllegalArgumentException IAex) {
             thrown = true;
-        } finally {
-            // ds.close();
         }
         assertTrue(thrown);
     }
 
     public void testNonExistentKeystore() {
-        if (!isConfigured()) {
-            System.err.println(getInvalidConfigurationMessage());
-            return;
-        }
         try {
             new CassandraDataContext(cluster, "nonExistentKeyspace");
             fail();
@@ -213,10 +177,6 @@ public class CassandraDataContextTest extends 
CassandraTestCase {
     }
 
     public void testCounterDataType() throws Exception {
-        if (!isConfigured()) {
-            System.err.println(getInvalidConfigurationMessage());
-            return;
-        }
         Table table = 
dc.getDefaultSchema().getTableByName(testCounterTableName);
 
         assertEquals(ColumnType.BIGINT, 
table.getColumnByName("counter_value").getType());
@@ -234,40 +194,32 @@ public class CassandraDataContextTest extends 
CassandraTestCase {
         }
     }
 
-    private void createCassandraKeySpaceAndTables(Session session) {
-        session.execute("CREATE KEYSPACE IF NOT EXISTS " + getKeyspaceName() + 
" WITH replication "
+    private void createCassandraKeySpaceAndTable(Session session) {
+        session.execute("CREATE KEYSPACE IF NOT EXISTS " + keyspaceName + " 
WITH replication "
                 + "= {'class':'SimpleStrategy', 'replication_factor':1};");
-        session.execute("DROP TABLE IF EXISTS " + getKeyspaceName() + "." + 
testTableName + ";");
-        session.execute("CREATE TABLE IF NOT EXISTS " + getKeyspaceName() + 
"." + testTableName + " ("
+        session.execute("DROP TABLE IF EXISTS " + keyspaceName + "." + 
testTableName + ";");
+        session.execute("CREATE TABLE IF NOT EXISTS " + keyspaceName + "." + 
testTableName + " ("
                 + "id uuid PRIMARY KEY," + "title text," + "hit boolean," + 
"duration float," + "position int,"
                 + "creationtime timestamp" + ");");
-        session.execute("DROP TABLE IF EXISTS " + getKeyspaceName() + "." + 
testCounterTableName + ";");
-        session.execute("CREATE TABLE IF NOT EXISTS " + getKeyspaceName() + 
"." + testCounterTableName + " ("
+        session.execute("DROP TABLE IF EXISTS " + keyspaceName + "." + 
testCounterTableName + ";");
+        session.execute("CREATE TABLE IF NOT EXISTS " + keyspaceName + "." + 
testCounterTableName + " ("
                 + "counter_value counter, url_name varchar, PRIMARY KEY 
(url_name)" + ");");
     }
 
     private void populateCassandraTableWithSomeData(Session session) {
-
-        // create 1 record
-        session.execute("INSERT INTO " + getKeyspaceName() + "." + 
testTableName
+        session.execute("INSERT INTO " + keyspaceName + "." + testTableName
                 + " (id, title, hit, duration, position, creationtime) " + 
"VALUES (" + firstRowId + ","
                 + "'My first song'," + "false," + "2.15," + "1," + 
"dateof(now()))" + ";");
-
-        // create 1 record
-        session.execute("INSERT INTO " + getKeyspaceName() + "." + 
testTableName
+        session.execute("INSERT INTO " + keyspaceName + "." + testTableName
                 + " (id, title, hit, duration, position, creationtime) " + 
"VALUES (" + secondRowId + ","
                 + "'My second song'," + "true," + "2.55," + "2," + 
"dateof(now()))" + ";");
-
-        // create 1 record
-        session.execute("INSERT INTO " + getKeyspaceName() + "." + 
testTableName
+        session.execute("INSERT INTO " + keyspaceName + "." + testTableName
                 + " (id, title, hit, duration, position, creationtime) " + 
"VALUES (" + thirdRowId + ","
                 + "'My third song'," + "false," + "3.15," + "3," + 
"dateof(now()))" + ";");
     }
 
     private void populateCassandraCounterTableWithSomeData(Session session) {
-
-        // create 1 record
-        session.execute("UPDATE " + getKeyspaceName() + "." + 
testCounterTableName
+        session.execute("UPDATE " + keyspaceName + "." + testCounterTableName
                 + " SET counter_value = counter_value + 1 WHERE url_name='" + 
urlName + "';");
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/metamodel/blob/28730942/cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraTestCase.java
----------------------------------------------------------------------
diff --git 
a/cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraTestCase.java 
b/cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraTestCase.java
deleted file mode 100644
index 18b5fb3..0000000
--- 
a/cassandra/src/test/java/org/apache/metamodel/cassandra/CassandraTestCase.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.metamodel.cassandra;
-
-import junit.framework.TestCase;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.Properties;
-
-public abstract class CassandraTestCase extends TestCase {
-
-    private static final String DEFAULT_TEST_KEYSPACE_NAME = "my_keyspace";
-    private static final Integer DEFAULT_TEST_PORT = 9042;
-
-    private String _hostname;
-    private Integer _port;
-    private String _keySpaceName;
-    private boolean _configured;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        final Properties properties = new Properties();
-        final File file = new File(getPropertyFilePath());
-        if (file.exists()) {
-            properties.load(new FileReader(file));
-            _hostname = properties.getProperty("cassandra.hostname");
-
-            _keySpaceName = properties.getProperty("cassandra.keyspace");
-            if (_keySpaceName == null || _keySpaceName.isEmpty()) {
-                _keySpaceName = DEFAULT_TEST_KEYSPACE_NAME;
-            }
-            
-            final String portString = 
properties.getProperty("cassandra.port"); 
-            if (portString == null || portString.isEmpty()) {
-                _port = DEFAULT_TEST_PORT;
-            } else {
-                _port = new Integer(portString);
-            }
-
-            _configured = (_hostname != null && !_hostname.isEmpty());
-
-            if (_configured) {
-                System.out.println("Loaded Cassandra configuration. Hostname=" 
+ _hostname + ", Keyspace="
-                        + _keySpaceName);
-            }
-        } else {
-            _configured = false;
-        }
-    }
-
-    private String getPropertyFilePath() {
-        String userHome = System.getProperty("user.home");
-        return userHome + 
"/metamodel-integrationtest-configuration.properties";
-    }
-
-    protected String getInvalidConfigurationMessage() {
-        return "!!! WARN !!! Cassandra module ignored\r\n" + "Please configure 
cassandra connection locally ("
-                + getPropertyFilePath() + "), to run integration tests";
-    }
-
-    public String getHostname() {
-        return _hostname;
-    }
-    
-    public String getKeyspaceName() {
-        return _keySpaceName;
-    }
-
-    public Integer getPort() {
-        return _port;
-    }
-
-    public boolean isConfigured() {
-        return _configured;
-    }
-}

http://git-wip-us.apache.org/repos/asf/metamodel/blob/28730942/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 31b39e1..fe33fcd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -269,8 +269,8 @@ under the License.
                                                        <rules>
                                                                
<bannedDependencies>
                                                                        
<excludes>
-                                                                               
<exclude>commons-logging:commons-logging</exclude>
-                                                                               
<exclude>org.codehaus.jackson</exclude>
+                                                                               
<exclude>commons-logging:commons-logging:compile</exclude>
+                                                                               
<exclude>org.codehaus.jackson:compile</exclude>
                                                                        
</excludes>
                                                                
</bannedDependencies>
                                                        </rules>

Reply via email to