Play 2.4 value routesImport is not a member of object play.Play.autoImport.PlayKeys - playframework-2.4

I am getting this error after migrating to 2.4 from 2.3. What is the right import statement I should use?
error: value routesImport is not a member of object play.Play.autoImport.PlayKeys
PlayKeys.routesImport += "se.radley.plugin.salat.Binders._",
I have these import statements:
import sbt._
import Keys._
import play.Play.autoImport._
import PlayKeys._
import WebKeys._

Should be like this:
import play.sbt.routes.RoutesKeys
...
RoutesKeys.routesImport += "se.radley.plugin.salat.Binders._"

Related

Ammonite Ivy Import Fails For Joda Time

I have the following in my predef.sc file and when I load Ammonite via my terminal, it fails for one library, the joda-time:
import $ivy.`org.typelevel::cats-core:2.1.1`, cats._, cats.implicits._
import $ivy.`org.scalatest::scalatest:3.0.8`,org.scalatest._
import $ivy.`org.scalacheck::scalacheck:1.14.0`
import $ivy.`io.monix::monix:3.1.0`
import $ivy.`dev.zio::zio:1.0.0-RC18`
import $ivy.`com.github.nscala-time::nscala-time:2.26.0`
import $ivy.`org.typelevel::cats-effect:2.1.2`
import $ivy.`com.github.chocpanda::scalacheck-magnolia:0.3.1`
import $ivy.`io.chrisdavenport::cats-scalacheck:0.2.0`
import $ivy.`net.ruippeixotog::scala-scraper:2.2.0`
import $ivy.`com.softwaremill.sttp.client3::core:3.1.9`
import $ivy.`joda-time::joda-time:2.10.14`
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.Future
import scala.util.{Failure, Success}
import scala.concurrent.Await
import monix.eval.Task
import org.scalacheck.{Arbitrary, Gen}
import com.github.nscala_time.time.Imports.DateTime
import com.github.nscala_time.time.Imports.DateTimeFormat
import org.scalacheck.magnolia._
import net.ruippeixotog.scalascraper.browser.JsoupBrowser
import net.ruippeixotog.scalascraper.dsl.DSL._
import net.ruippeixotog.scalascraper.dsl.DSL.Extract._
import net.ruippeixotog.scalascraper.dsl.DSL.Parse._
import sttp.client3._
import monix.reactive.Observable
import monix.execution.Ack.Continue
import monix.execution.{Ack, Scheduler}
import monix.reactive.observers.Subscriber
import monix.execution.Scheduler.Implicits.global
import org.joda.time.{DateTime, Days, Interval, Weeks}
import scala.math.Integral.Implicits._
The actual error message:
joesan#joesan-S-14-v5:~$ amm
Loading...
Failed to resolve ivy dependencies:Error downloading joda-time:joda-time_2.13:2.10.14
not found: /home/joesan/.ivy2/local/joda-time/joda-time_2.13/2.10.14/ivys/ivy.xml
not found: https://repo1.maven.org/maven2/joda-time/joda-time_2.13/2.10.14/joda-time_2.13-2.10.14.pom
I got it resolved by adding a dependency to the nscala-time as below:
import $ivy.`com.github.nscala-time::nscala-time:2.30.0`
import com.github.nscala_time.time.Imports._
Not sure why this was able to resolve while the joda-time not!

when I upgraded my ReactiveMongo library dependencies from 0.11.0.play24 to 0.11.14-play24 it throws me error

I'am upgrading the play from 2.4.3 to 2.5.2 in the process I was able to upgrade the play but when I upgraded the reactive mongo library dependency from 0.11.0.play24 to 0.11.14-play24 it was throwing following errors
found : (String, play.api.libs.json.JsValue)
[error] required: reactivemongo.bson.Producer[reactivemongo.bson.BSONElement]
[error] (which expands to) reactivemongo.bson.Producer[(String, reactivemongo.bson.BSONValue)]
[error] Error occurred in an application involving default arguments.
[error] claimsCollection.update(BSONDocument("id" -> claimId), BSONDocument("$set" -> BSONDocument("status"-> "Approved" , "updationDate" -> Json.toJson(ZonedDateTime.now()))))
[error]
The code I have written like this
import com.greenroom6.auth.models.claims.Claims
import javax.inject.Inject
import play.modules.reactivemongo.ReactiveMongoApi
import play.modules.reactivemongo.json.collection.JSONCollection
import scala.concurrent.ExecutionContext
import com.greenroom6.auth.util.UniqueIdGenerator
import reactivemongo.bson.BSONDocument
import play.api.libs.json.{Json,JsObject}
import play.modules.reactivemongo.json._
import scala.concurrent.Future
import reactivemongo.api.commands.WriteResult
import reactivemongo.api.ReadPreference
import java.time.ZonedDateTime
import play.modules.reactivemongo.json._,ImplicitBSONHandlers._
import reactivemongo.bson._
import play.modules.reactivemongo.ReactiveMongoComponents
class ClaimsDaoImpl #Inject()(reactivemongo : ReactiveMongoApi) extends ClaimsDao {
protected def claimsCollection = reactivemongo.db.collection[JSONCollection]("claims")
def claimProfile(claim:Claims)(implicit ec :ExecutionContext): Future[WriteResult] = {
val claimTosave = claim.copy(id = Some(UniqueIdGenerator.generate), status = "Pending" )
claimsCollection.save(claimTosave)
}
def approveClaim(claimId:String)(implicit ec :ExecutionContext): Future[WriteResult] = {
claimsCollection.update(BSONDocument("id" -> claimId), BSONDocument("$set" -> BSONDocument("status"-> "Approved" , "updationDate" -> Json.toJson(ZonedDateTime.now()))))
}
}
What should I require to do to resolve the issue?
I think you have the wrong dependency. According to their Github Page: ReactiveMongo/Play-ReactiveMongo
val reactiveMongoVer = "0.11.14"
// only for Play 2.5.x
libraryDependencies ++= Seq(
"org.reactivemongo" %% "play2-reactivemongo" % reactiveMongoVer
)
Instead it seems you use this:
// only for Play 2.4.x
libraryDependencies ++= Seq(
"org.reactivemongo" %% "play2-reactivemongo" % s"$reactiveMongoVer-play24"
)

Failed assertion with automated initialisation of database in Cassandra

Completely new to Cassandra. Tried to initialize a database in Cassandra using phantom-dsl. I received this error message.
*** RUN ABORTED ***
java.lang.AssertionError: assertion failed: no symbol could be loaded from class com.datastax.driver.core.Cluster in package core with name Cluster and classloader sun.misc.Launcher$AppClassLoader#279f2327
at scala.reflect.runtime.JavaMirrors$JavaMirror.scala$reflect$runtime$JavaMirrors$JavaMirror$$classToScala1(JavaMirrors.scala:1021)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToScala$1.apply(JavaMirrors.scala:980)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToScala$1.apply(JavaMirrors.scala:980)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$toScala$1.apply(JavaMirrors.scala:97)
at scala.reflect.runtime.TwoWayCaches$TwoWayCache$$anonfun$toScala$1.apply(TwoWayCaches.scala:39)
at scala.reflect.runtime.Gil$class.gilSynchronized(Gil.scala:19)
at scala.reflect.runtime.JavaUniverse.gilSynchronized(JavaUniverse.scala:16)
at scala.reflect.runtime.TwoWayCaches$TwoWayCache.toScala(TwoWayCaches.scala:34)
at scala.reflect.runtime.JavaMirrors$JavaMirror.toScala(JavaMirrors.scala:95)
at scala.reflect.runtime.JavaMirrors$JavaMirror.classToScala(JavaMirrors.scala:980)
I am not really sure whether it is an issue with the Connector in phantom-dsl or the ClusterBuilder in datastax-driver.
Connector.scala
package com.neruti.db
import com.neruti.db.models._
import com.websudos.phantom.database.Database
import com.websudos.phantom.connectors.ContactPoints
import com.websudos.phantom.dsl.KeySpaceDef
object Connector {
val host= Seq("localhost")
val port = 9160
val keySpace: String = "nrt_entities"
// val inet = InetAddress.getByName
lazy val connector = ContactPoints(host,port).withClusterBuilder(
_.withCredentials("cassandra", "cassandra")
).keySpace(keySpace)
}
CassandraSpec.scala
package com.neruti.db
import com.neruti.User
import com.neruti.db.models._
import com.neruti.db.databases._
import com.neruti.db.services._
import com.neruti.db.Connector._
import java.util.UUID
import com.datastax.driver.core.ResultSet
import org.scalatest._
import org.scalatest.{BeforeAndAfterAll,FlatSpec,Matchers,ShouldMatchers}
import org.scalatest.concurrent.ScalaFutures
import org.scalamock.scalatest.MockFactory
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
abstract class BaseCassandraSpec extends FlatSpec
with BeforeAndAfterAll
with Inspectors
with Matchers
with OptionValues
with ScalaFutures
class CassandraTest extends BaseCassandraSpec
with ProductionDatabase
with UserService
with Connector.connector.Connector{
val user = User(
Some("foobar"),
Some("foo#foobar.com"),
Some(UUID.randomUUID()),
)
override protected def beforeAll(): Unit = {
Await.result(database.userModel.create(user),10.seconds)
}
}
Looks there may be multiple issues you are looking at:
The latest version of phantom is 2.1.3, I'd strongly recommend using that, especially if you are just starting out. The migration guide is here in case you need it.
The entire reflection mechanism has been replaced in the latest version, so that error should magically go away. With respect to testing and generating objects, I would also look to include com.outworkers.util.testing, which is freely available on Maven Central
libraryDependencies ++= Seq(
//..,
"com.outworkers" %% "phantom-dsl" % "2.1.3",
"com.outworkers" %% "util-testing" % "0.30.1" % Test
)
This will offer you automated case class generation:
import com.outworkers.util.testing._
val sample = gen[User]

Verify order of sequence calls with Mockito

I want to verify the order of sequence calls, but it didn't work as I expected.
import akka.actor.ActorSystem
import akka.testkit.TestKit
import org.scalatest._
import org.specs2.mock.Mockito
class Test extends TestKit(ActorSystem("testSystem"))
with WordSpecLike
with BeforeAndAfterAll
with PrivateMethodTester
with `enter code here`Mockito
{
val m = mock[java.util.List[String]]
m.get(0) returns "one"
there was two(m).get(2) //do not throw any error, why???
}
I'm using
scala 2.11.7,
specs2-core 3.6.6,
specs2-mock 3.6.6,
scalatest 2.2.4
thx
I don't think you can mix Specs2 and ScalaTest.
You shuld remove import org.scalatest._ and use import org.specs2.mutable.SpecificationLike instead.
import akka.testkit.TestKit
import akka.actor.ActorSystem
import org.specs2.mock.Mockito
import org.specs2.mutable.SpecificationLike
class Test extends TestKit(ActorSystem("testSystem"))
with Mockito
with SpecificationLike
{
"it" should{
"raise error" in {
val m = mock[java.util.List[String]]
m.get(0) returns "one"
there was two(m).get(2)
}
}
}
Now you can see that sbt test returns something like.
[error] The mock was not called as expected:
[error] Wanted but not invoked:
[error] list.get(2);
[error] -> at Test$$anonfun$1$$anonfun$apply$1$$anonfun$apply$3.apply(Test.scala:14)
[error] Actually, there were zero interactions with this mock. (Test.scala:14)

Not solved import controllers.Application in Scala´s Play framework

I´m developing a Play Framework project in Scala, but I not able to get correctly the import controllers.Application reference.
The snippet bellow focus on the onStart method at my Global.scala file, that is located inside the app directory. What is going under the hood? Why can´t I get this easy import done correctly?
import play.api._
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.concurrent._
import play.api.Play.current
import scala.concurrent.duration._
import scala.util.Random
import model.StatusUpdate
object Global extends GlobalSettings {
override def onStart(app: Application) {
import controllers.{Application => App}
// Definition of the onStart method.
}
My Application.scala file that is located in the controllers directory is defined as bellow:
package controllers
import play.api._
import play.api.libs.iteratee._
import play.api.libs.json._
import play.api.mvc._
object Application extends Controller {
//Definition of methods
}