-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PrintStreamReporter back to project
- Loading branch information
Chris O'Meara
committed
Jan 9, 2017
1 parent
9638f24
commit 3f6345d
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/scala/com/chrisomeara/pillar/PrintStreamReporter.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,28 @@ | ||
package com.chrisomeara.pillar | ||
|
||
import java.io.PrintStream | ||
import java.util.Date | ||
|
||
import com.datastax.driver.core.Session | ||
|
||
class PrintStreamReporter(stream: PrintStream) extends Reporter { | ||
override def initializing(session: Session, keyspace: String, replicationOptions: ReplicationOptions) { | ||
stream.println(s"Initializing $keyspace") | ||
} | ||
|
||
override def migrating(session: Session, dateRestriction: Option[Date]) { | ||
stream.println(s"Migrating with date restriction $dateRestriction") | ||
} | ||
|
||
override def applying(migration: Migration) { | ||
stream.println(s"Applying ${migration.authoredAt.getTime}: ${migration.description}") | ||
} | ||
|
||
override def reversing(migration: Migration) { | ||
stream.println(s"Reversing ${migration.authoredAt.getTime}: ${migration.description}") | ||
} | ||
|
||
override def destroying(session: Session, keyspace: String) { | ||
stream.println(s"Destroying $keyspace") | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/scala/com/chrisomeara/pillar/PrintStreamReporterSpec.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,55 @@ | ||
package com.chrisomeara.pillar | ||
|
||
import com.datastax.driver.core.Session | ||
import org.scalatest._ | ||
import org.scalatest.matchers.ShouldMatchers | ||
import java.io.{ByteArrayOutputStream, PrintStream} | ||
import java.util.Date | ||
|
||
import org.scalatest.mock.MockitoSugar | ||
|
||
class PrintStreamReporterSpec extends FunSpec with MockitoSugar with Matchers with OneInstancePerTest { | ||
val session = mock[Session] | ||
val migration = Migration("creates things table", new Date(1370489972546L), Seq("up"), Some(Seq("down"))) | ||
val output = new ByteArrayOutputStream() | ||
val stream = new PrintStream(output) | ||
val reporter = new PrintStreamReporter(stream) | ||
val keyspace = "myks" | ||
|
||
describe("#initializing") { | ||
it("should print to the stream") { | ||
reporter.initializing(session, keyspace, ReplicationOptions.default) | ||
output.toString should equal("Initializing myks\n") | ||
} | ||
} | ||
|
||
describe("#migrating") { | ||
describe("without date restriction") { | ||
it("should print to the stream") { | ||
reporter.migrating(session, None) | ||
output.toString should equal("Migrating with date restriction None\n") | ||
} | ||
} | ||
} | ||
|
||
describe("#applying") { | ||
it("should print to the stream") { | ||
reporter.applying(migration) | ||
output.toString should equal("Applying 1370489972546: creates things table\n") | ||
} | ||
} | ||
|
||
describe("#reversing") { | ||
it("should print to the stream") { | ||
reporter.reversing(migration) | ||
output.toString should equal("Reversing 1370489972546: creates things table\n") | ||
} | ||
} | ||
|
||
describe("#destroying") { | ||
it("should print to the stream") { | ||
reporter.destroying(session, keyspace) | ||
output.toString should equal("Destroying myks\n") | ||
} | ||
} | ||
} |