forked from outworkers/phantom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
181 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 22 additions & 2 deletions
24
...om-connectors/src/test/scala/com/websudos/phantom/connectors/ConnectorReferenceTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
package com.websudos.phantom.connectors | ||
|
||
import org.scalatest.FlatSpec | ||
import org.scalatest.{ FlatSpec, Matchers } | ||
|
||
class ConnectorReferenceTest extends FlatSpec { | ||
|
||
trait MyConnector extends SimpleCassandraConnector { | ||
implicit val keySpace = KeySpace("test") | ||
} | ||
|
||
object Test extends MyConnector | ||
|
||
object Test2 extends MyConnector | ||
|
||
|
||
class ConnectorReferenceTest extends FlatSpec with Matchers { | ||
it should "reference the same session inside multiple mixins of the same connector" in { | ||
(Test.session eq Test2.session) shouldEqual true | ||
} | ||
|
||
it should "reference the same manager inside multiple mixins of the same connctor" in { | ||
(Test.manager eq Test2.manager) shouldEqual true | ||
} | ||
|
||
it should "reference the same cluster inside multiple mixins of the same connctor" in { | ||
(Test.manager.clusterRef eq Test2.manager.clusterRef) shouldEqual true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
phantom-dsl/src/main/scala/com/websudos/phantom/builder/serializers/DeleteQueryBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.websudos.phantom.builder.serializers | ||
|
||
import com.websudos.phantom.builder.query.CQLQuery | ||
import com.websudos.phantom.builder.syntax.CQLSyntax | ||
|
||
private[builder] class DeleteQueryBuilder { | ||
def delete(table: String): CQLQuery = { | ||
CQLQuery(CQLSyntax.delete) | ||
.forcePad.append(CQLSyntax.from) | ||
.forcePad.append(table) | ||
} | ||
|
||
def deleteColumn(table: String, column: String): CQLQuery = { | ||
CQLQuery(CQLSyntax.delete) | ||
.forcePad.append(column) | ||
.forcePad.append(CQLSyntax.from) | ||
.forcePad.append(table) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
phantom-dsl/src/test/scala/com/websudos/phantom/builder/query/CQLQueryTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.websudos.phantom.builder.query | ||
|
||
import org.scalatest.{Matchers, FlatSpec} | ||
import com.websudos.util.testing._ | ||
|
||
class CQLQueryTest extends FlatSpec with Matchers { | ||
it should "create an empty CQL query using the empty method on the companion object" in { | ||
CQLQuery.empty.queryString shouldEqual "" | ||
} | ||
|
||
it should "automatically serialize a list of strings using the apply method from the companion object" in { | ||
val list = List("test", "test2") | ||
|
||
CQLQuery(list).queryString shouldEqual "test, test2" | ||
} | ||
|
||
it should "escape strings without single quotes inside them by wrapping the string in single quotes" in { | ||
val test = gen[String] | ||
CQLQuery.escape(test) shouldEqual s"'$test'" | ||
} | ||
|
||
it should "escape single quotes inside a string using the scape method of the companion" in { | ||
val test = "test'" | ||
CQLQuery.escape(test) shouldEqual "'test'''" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...rc/test/scala/com/websudos/phantom/builder/serializers/CreateQuerySerialisationTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.websudos.phantom.builder.serializers | ||
|
||
import com.websudos.phantom.builder.query.QueryBuilderTest | ||
import com.websudos.phantom.tables.TimeSeriesTable | ||
|
||
class CreateQuerySerialisationTest extends QueryBuilderTest { | ||
"The CREATE query builder" - { | ||
"should generate clustering keys for a schema queries" - { | ||
val qb = TimeSeriesTable.defineTableKey() | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...-dsl/src/test/scala/com/websudos/phantom/builder/serializers/DeleteQueryBuilderTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
package com.websudos.phantom.builder.serializers | ||
|
||
import com.websudos.phantom.builder.QueryBuilder | ||
import com.websudos.phantom.builder.query.QueryBuilderTest | ||
|
||
class DeleteQueryBuilderTest extends QueryBuilderTest { | ||
"The DELETE query builder" - { | ||
|
||
"should allow specifying column delete queries" - { | ||
val qb = QueryBuilder.Delete.deleteColumn("table", "col").queryString | ||
qb shouldEqual "DELETE col FROM table" | ||
} | ||
|
||
"should allow specifying full delete queries" - { | ||
val qb = QueryBuilder.Delete.delete("table").queryString | ||
qb shouldEqual "DELETE FROM table" | ||
} | ||
} | ||
} |
8 changes: 7 additions & 1 deletion
8
...rc/test/scala/com/websudos/phantom/builder/serializers/DeleteQuerySerialisationTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package com.websudos.phantom.builder.serializers | ||
|
||
import com.websudos.phantom.builder.query.QueryBuilderTest | ||
import com.websudos.phantom.tables.BasicTable | ||
|
||
class DeleteQuerySerialisationTest extends QueryBuilderTest { | ||
"The DELETE query builder" - { | ||
|
||
"The DELETE query builder" - { | ||
"should generate table column deletion queries" - { | ||
"should create a delete query for a single column" - { | ||
BasicTable.delete(_.id) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.