Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test
- import com.mongodb.casbah.Imports._
- import com.novus.salat.dao.{ModelCompanion, SalatDAO}
- import java.io._
- import models._
- import models.util._
- import org.apache.commons.net.ftp._
- import org.scala_tools.time.Imports._
- import org.specs2.mutable._
- import play.api._
- import play.api.Play.current
- import play.api.test._
- import play.api.test.Helpers._
- import scala.sys.process._
- import scalaxb._
- import zpProtocol._
- class XMLImportSpec extends Specification {
- override def is = args(sequential = true) ^ super.is
- val log = play.api.Logger
- "Database" should {
- "be filled with data from XML files" in new FakeApp() {
- "download" must beAWritablePath
- val dnloads = tree(new File("download")).toArray
- def imported = for {
- f <- dnloads if (f.isFile && f.getName.endsWith(".xml"))
- nodes = xml.XML.loadFile("download/" + f.getName)
- parsed = scalaxb.fromXML[ZpBaseType](nodes)
- } yield parsed
- var cnt = 0
- for(rec <- imported) {
- rec.zpbasetypeoption must beAnInstanceOf[Seq[Any]]
- PublicOrder.insert(rec) must beSome
- MongoConnection()(play.api.Play.configuration.getString("mongodb.default.db").get).getLastError.get("err") must beNull
- cnt += 1
- }
- cnt aka "import iterations" must_== imported.length
- PublicOrder.collection aka "the imported collection" must haveSize(imported.length)
- }
- }
- step (DeregisterXMLStandardTypesSerializer())
- }
- trait FakeApp extends Around {
- val db_name = "offers_db_test"
- def mongoTestDatabase() = Map("mongodb.default.db" -> db_name,
- "source.ftp" -> "ftp.uzp.gov.pl")
- object FakeApp extends FakeApplication(additionalConfiguration = mongoTestDatabase())
- val Some(ftpAddr) = FakeApp.configuration.getString("source.ftp")
- def around[T <% org.specs2.execute.Result](test: =>T) = running(FakeApplication(additionalConfiguration = mongoTestDatabase())) {
- test // run tests inside a fake application
- }
- def tree(root: File, skipHidden: Boolean = true): Stream[File] =
- if (!root.exists || (skipHidden && root.isHidden)) Stream.empty
- else root #:: (
- root.listFiles match {
- case null => Stream.empty
- case files => files.toStream.flatMap(tree(_, skipHidden))
- })
- }
Add Comment
Please, Sign In to add comment