Lift-Buch-Code is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

Commita55d7bad2c948eb19...
/srctestscalacomlehrkraftnewsmodel
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.lehrkraftnews.model

import com.lehrkraftnews.util.MailProperties
import net.liftweb.util.Log
import org.scalatest.Assertions
import net.liftweb.mapper._

/**
 * Zweck: Stellt eine mit definierten Beispieldaten gefüllte Datenbank zur Verfügung.
 * @author Christoph Knabe
 * @since 2010-09-01
 */
object DatabaseUtil extends Assertions {


  val boot = new bootstrap.liftweb.Boot

  /**Creates a connection to the database and the schema for all model classes.*/
  lazy val initORMapper: Unit = {
    DB.defineConnectionManager(DefaultConnectionIdentifier, boot.DBVendor)
    Schemifier.schemify(true, Log.infoF _, modelMetaObjects : _ *)
  }

  /**Zählt für alle Model-Klassen deren Meta-Objekte auf.*/
  val modelMetaObjects = List(User, Subscription, News)

  /**Deletes all rows in the tables for all model classes.*/
  private lazy val deleteAllRows = {
    User.bulkDelete_!!()
    Subscription.bulkDelete_!!()
    News.bulkDelete_!!()
  }

  /**Populates the database with 1 admin, 5 teachers, and 1 student for test purposes.*/
  lazy val populateDatabase = {
    initORMapper
    deleteAllRows
    createUsers
  }

  /**Erzeugt Beispielbenutzer für die Testsuite. Diese sind ein Administrator, 5 Lehrkräfte und ein Student.*/
  private def createUsers {
    //BEGIN(createUsers)
    boot.makeSureAdminExists
    //val mailPropertyEntries = MailProperties.getAll
    _createUser(User.Teacher, "Knabe", "Christoph", MailProperties("mail.teacher.1"))
    _createUser(User.Teacher, "Triel", "Bernd Holger", MailProperties("mail.teacher.2"))
    _createUser(User.Student, "Heinrich", "Theodor Friedrich", MailProperties("mail.student"))
    _createUser(User.Teacher, "Merkel", "Angela", "Angela.Merkel@bundesdeutschland.de")
    _createUser(User.Teacher, "Brandt", "Willi", "Willi.Brandt@beuth-hochschule.de")
    _createUser(User.Teacher, "Obama", "Barack", "Barack.Obama@beuth-hochschule.de")
    //END(createUsers)
  }

  /** Assures existence of a validated user with the given attributes and the password "test". */
  private def _createUser(role: String, lastName: String, firstName: String, eMail: String): Unit = {
    val newUser = User.create.firstName(firstName).lastName(lastName).userRole(role).email(eMail).password("passwort").validated(true)
    newUser.save
    val found = User.findAll(
      By(User.lastName, lastName)
    )
    val foundUser = found(0)
    assert(newUser === foundUser)
    assert(foundUser.lastName === lastName)
    assert(foundUser.firstName === firstName)
    assert(foundUser.email === eMail)
    assert(foundUser.validated === true)
    assert(foundUser.validate === noErrors)
  }

  private val noErrors = List()


}//object
Ajax-loader Loading, please wait...