mongodb - Salat Dao - not acessible via JUnit -


i have following class:

package backend.link  import org.bson.types.objectid import com.novus.salat.annotations.raw.salat import com.novus.salat.dao.modelcompanion import com.novus.salat.dao.salatdao import model.hybrid.hybridentity import play.api.play.current import se.radley.plugin.salat.mongocollection import com.novus.salat.annotations.raw.key import backend.data.mongodblayer import com.mongodb.casbah.commons.mongodbobject import backend.data.spacedao import backend.data.pagedao import backend.data.userdao import se.radley.plugin.salat._ import org.bson.types.objectid import com.novus.salat.{ typehintfrequency, stringtypehintstrategy, context } import play.api.play import play.api.play.current  /*   adding custom salat context work play's classloader   using example from:   https://github.com/leon/play-salat/blob/master/sample/app/models/mongocontext.scala */ package object mongocontext {   implicit val context = {     val context = new context {       val name = "global"       override val typehintstrategy = stringtypehintstrategy(when = typehintfrequency.whennecessary, typehint = "_t")     }     context.registerglobalkeyoverride(remapthis = "id", tothisinstead = "_id")     context.registerclassloader(play.classloader)     context   } } import mongocontext._  /**  * class storing hybridlinks  */ case class hybridlink(   @key("_id") id: objectid = new objectid,   val name: string,   val origin_id: string,   val origin_type: string,   val target_id: string,   val target_type: string)  /**  * companion object hybridlink acts dao  */ object hybridlink extends modelcompanion[hybridlink, objectid] {    def collection = mongodblayer.mongodb("hybridlink")   val dao = new salatdao[hybridlink, objectid](collection) {}    def apply(name: string, origin: hybridentity, target: hybridentity): hybridlink =     {       hybridlink(null, name, origin.id, origin.getclass().getname(), target.id, target.getclass().getname())     }    /**    * finds objects pointing hybridentity    */   def findbyreferenced(entity: hybridentity): list[hybridentity] = {     val = find(mongodbobject("target_id" -> entity.id, "target_type" -> entity.getclass().getname()))     val linklist = it.tolist     (link <- linklist)       yield this.gethybridentitybyclassandid(link.origin_type, link.origin_id)    }    /**    * finds objects pointed @ hybridentity    */   def findreferencing(entity: hybridentity): list[hybridentity] = {     val = find(mongodbobject("origin_id" -> entity.id, "origin_type" -> entity.getclass().getname()))     val linklist = it.tolist     (link <- linklist)       yield this.gethybridentitybyclassandid(link.target_type, link.target_id)   }    /**    * finds list of outgoing links    */   def findreferencinglinks(entity: hybridentity): list[hybridlink] = {     val = find(mongodbobject("origin_id" -> entity.id, "origin_type" -> entity.getclass().getname()))     val linklist = it.tolist     return linklist   }    /**    * returns list of links reference specified hbyridentity    */    def findincominglinks(entity: hybridentity): list[hybridlink] = {     val = find(mongodbobject("target_id" -> entity.id, "target_type" -> entity.getclass().getname()))     val linklist = it.tolist     return linklist   }    /**    * retrieves corresponding hbyridentity id , type    */   def gethybridentitybyclassandid(cls: string, id: string): hybridentity =     cls match {       case "model.hybrid.space" => spacedao.findbyid(id)       case "model.hybrid.page" => pagedao.findbyid(id)       case _ => throw new illegalargumentexception("couldnt find corresponding dao class " + cls)     }    /**    * helper method removing references pointing specified hybridentity    */   def removeallreferences(entity: hybridentity): unit =     {       remove(mongodbobject("target.id" -> entity.id, "target._typehint" -> entity.getclass().getname()))     }  } 

as can see uses custom context work play's class loader.

however cannot acess in junit test.

i error msg: "java.lang.noclassdeffounderror: not initialize class backend.link.hybridlink$ @ backend.core.search.linkservice$.linkobjects(linkservice.scala:31)"

any ideas on how tackle problem appreciated-

that pretty dumb of me, didn't include test method :/ (sorry that)

i forgot add:

@test def testimport() {     running(fakeapplication()) {       //test code goes here     } 

now works charm.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -