> No worries. If you don't mind, please share whatever you end up with on the
> list so that others can benefit :)

Sure! It is nothing fancy but here is what I did (some simple code to
show):

Snippet code:
...
class TeamSnippet {

  def list(html: NodeSeq):NodeSeq = {

    val team = getTeamModel()
    val user = getUserModel()

    if (user.currentUser.isEmpty) {
      throw new Exception("Should be logged in to use
TeamSnippet.list")
    }

    val teams:List[Team] = team.findByUser(user.currentUser.open_!)

    teams.flatMap(item =>
      bind("team", html,
           "name" -> <span>{item.name}</span>))
  }

  protected def getTeamModel():MetaTeam = Team
  protected def getUserModel():MetaUser = User
}
...

and the specs unti test:

object myTeamSnippetTestObj extends Specification with Mockito
{
  "TeamSnippet" should {
    "return current user's teams if 'list' method is called" in {

      val teamDbMock = mock[MetaTeam]
      val userDbMock = mock[MetaUser]

      val currentUser = new User()
      val t1 = new Team
      val t2 = new Team

      t1.name("TeamName1")
      t2.name("TeamName2")

      teamDbMock.findByUser(currentUser) returns List(t1, t2)
      userDbMock.currentUser returns Box(currentUser)

      val teamSnippet = new TeamSnippet() {
        override protected def getTeamModel(): MetaTeam = teamDbMock
        override protected def getUserModel(): MetaUser = userDbMock
      }

      val nodeSeq = <td><team:name/></td>

      val response = teamSnippet.list(nodeSeq)
      response must notBeNull
      val tds = response \\ "td"

      tds mustNotBe(Nil)

      tds.length mustBe 2
      tds(0).child(0).text must beEqualTo("TeamName1")
      tds(1).child(0).text must beEqualTo("TeamName2")
    }
  }
}

The point is to create traits that wraps the model's functions and
then mock those interfaces. Basic stuff ;)

- Erik

>
> Derek
>
> On Sun, Apr 19, 2009 at 3:15 AM, [email protected] <
>
> [email protected]> wrote:
>
> > Hi,
>
> > Thanks for the idea. Actually I probably just had a bad day when when
> > I sent this question. I tried to create mocks for those object classes
> > (ClassName.type) but naturally I should create mocks for the trait of
> > those model classes.
>
> > For E2E testing I have been thinking something similar that you
> > proposed.
>
> > Thanks for the help!
>
> > - Erik
>
> > On Apr 19, 8:59 am, Derek Chen-Becker <[email protected]> wrote:
> > > That should be "...to determine how to set up..."
>
> > > On Sat, Apr 18, 2009 at 11:59 PM, Derek Chen-Becker
> > > <[email protected]>wrote:
>
> > > > Would using the run mode to determine to set up a Derby or HSQL DB for
> > test
> > > > purposes in your Boot class work? Usually I use this method combined
> > with
> > > > DBUnit to load test data.
>
> > > > Derek
>
> > > > On Fri, Apr 17, 2009 at 3:43 PM, [email protected] <
> > > > [email protected]> wrote:
>
> > > >> Hi,
>
> > > >> I'm a little bit puzzled about the problem of mocking multiple models
> > > >> in one class.  My problem is following:
>
> > > >> I have a snippet that uses two models. To be able to test the snippet
> > > >> I would need to create Mock objects for both of those models and
> > > >> especially for the object part of the model (to able to mock those
> > > >> find, create etc. methods).
>
> > > >> Now I'm wondering how to actually do that in lift&scala.  I think my
> > > >> brain is still thinking too much in C++/Java because my old ways
> > > >> didn't really work :)
>
> > > >> Thanks beforehand for any help!
>
> > > >> - Erik

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to