Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play 2.9 & Scala 3 #321

Merged
merged 8 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.10, 2.13.1]
java: [temurin@8]
scala: [2.13.1, 3.3.1]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 2.13.1? The latest 2.13.x release is 2.13.12
Is this a typo, like everywhere in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.13.1 was the previously set version of Scala that this project was using, I avoided bumping anything more than I needed to get this project to work with Play 2.9 and Scala 3

java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
java-version: 11
cache: sbt

- name: Lint
Expand Down Expand Up @@ -65,38 +65,38 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [2.12.18]
java: [temurin@8]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
java-version: 11
cache: sbt

- name: Download target directories (2.12.10)
- name: Download target directories (2.13.1)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.12.10-${{ matrix.java }}
name: target-${{ matrix.os }}-2.13.1-${{ matrix.java }}

- name: Inflate target directories (2.12.10)
- name: Inflate target directories (2.13.1)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.1)
- name: Download target directories (3.3.1)
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.13.1-${{ matrix.java }}
name: target-${{ matrix.os }}-3.3.1-${{ matrix.java }}

- name: Inflate target directories (2.13.1)
- name: Inflate target directories (3.3.1)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ await(ws.url("http://dns/url").get()).body == "http response"

Add MockWS as test dependency in the `build.sbt`:

* for Play 2.9.x:
```scala
libraryDependencies += "de.leanovate.play-mockws" %% "play-mockws" % "2.9.0" % Test
```
* for Play 2.8.x:
```scala
libraryDependencies += "de.leanovate.play-mockws" %% "play-mockws" % "2.8.0" % Test
Expand Down Expand Up @@ -143,6 +147,7 @@ Other examples can be found in the [tests](src/test/scala/mockws/).

## Compatibility Matrix

- MockWS 2.9.x is actually only compatible with Play 2.9.y., with Scala 3 or 2.13.
- MockWS 2.8.x is actually only compatible with Play 2.8.y., with Scala 2.13 or 2.12.
- MockWS 2.6.x is actually only compatible with Play 2.6.y., with Scala 2.12 or 2.11.
- MockWS 2.5.x is actually only compatible with Play 2.5.y., with Scala 2.11.
Expand Down
6 changes: 6 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release notes

# 2.9.0

This release targets Play 2.9 and Akka 2.6. Scala 2.12 and Java 8 are longer supported.

See [v2.9.0](https://github.com/leanovate/play-mockws/releases/tag/v2.9.0) for a full list of changes.

## 2.8.1

- add support for request filters (#150) @avdv
Expand Down
17 changes: 9 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ scalacOptions ++= Seq("-deprecation", "-feature")

organization := "de.leanovate.play-mockws"

val playVersion = "2.8.1"
val playVersion = "2.9.0"

ThisBuild / crossScalaVersions := List("2.12.10", "2.13.1")
ThisBuild / crossScalaVersions := List("2.13.1", "3.3.1")

fork := true

resolvers += "Typesafe repository".at("https://repo.typesafe.com/typesafe/releases/")

libraryDependencies ++= Seq(
"com.typesafe.play" %% "play" % playVersion % "provided",
"com.typesafe.play" %% "play-ahc-ws" % playVersion % "provided",
"com.typesafe.play" %% "play-test" % playVersion % "provided",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.1.6"
"com.typesafe.play" %% "play" % playVersion % "provided",
"com.typesafe.play" %% "play-ahc-ws" % playVersion % "provided",
"com.typesafe.play" %% "play-test" % playVersion % "provided",
)

libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.8",
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.8.0",
"org.scalatest" %% "scalatest" % "3.2.17",
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.11.0",
"org.scalacheck" %% "scalacheck" % "1.15.4",
"org.mockito" % "mockito-core" % "3.11.0"
).map(_ % Test)

Release.settings

ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("11"))

// code linting
ThisBuild / githubWorkflowBuildPreamble += WorkflowStep.Run(
commands = List("scripts/validate-code check"),
Expand Down
3 changes: 2 additions & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sbt.version = 1.9.3
sbt.version = 1.9.7

5 changes: 5 additions & 0 deletions src/main/scala/mockws/FakeWSRequestHolder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ case class FakeWSRequestHolder(
/* Not implemented. */
val calc: Option[WSSignatureCalculator] = None
val followRedirects: Option[Boolean] = None
val disableUrlEncoding: Option[Boolean] = None
val proxyServer: Option[WSProxyServer] = None
val virtualHost: Option[String] = None

Expand All @@ -55,6 +56,8 @@ case class FakeWSRequestHolder(

def withFollowRedirects(follow: Boolean): Self = this

def withDisableUrlEncoding(disableUrlEncoding: Boolean): Self = this

def withProxyServer(proxyServer: WSProxyServer): Self = this

def withVirtualHost(vh: String): Self = this
Expand All @@ -65,6 +68,8 @@ case class FakeWSRequestHolder(

def withCookies(cookie: WSCookie*): Self = copy(cookies = this.cookies ++ cookie.toSeq)

override def addCookies(cookies: WSCookie*): Self = withCookies(this.cookies ++ cookies: _*)

def withHeaders(hdrs: (String, String)*): Self = withHttpHeaders(hdrs: _*)

def withHttpHeaders(hdrs: (String, String)*): Self = {
Expand Down
12 changes: 6 additions & 6 deletions src/test/scala/mockws/AuthenticationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class AuthenticationTest extends AnyFunSuite with Matchers with ScalaCheckProper
}
}

val wsResponseOk = await(ws.url("/").withAuth("user", "s3cr3t", WSAuthScheme.BASIC).get)
val wsResponseOk = await(ws.url("/").withAuth("user", "s3cr3t", WSAuthScheme.BASIC).get())
wsResponseOk.status shouldEqual OK

val wsResponseUnauthorized = await(ws.url("/").withAuth("user", "secret", WSAuthScheme.BASIC).get)
val wsResponseUnauthorized = await(ws.url("/").withAuth("user", "secret", WSAuthScheme.BASIC).get())
wsResponseUnauthorized.status shouldEqual UNAUTHORIZED

ws.close()
Expand All @@ -45,16 +45,16 @@ class AuthenticationTest extends AnyFunSuite with Matchers with ScalaCheckProper
}

a[UnsupportedOperationException] shouldBe thrownBy(
await(ws.url("/").withAuth("user", "s3cr3t", WSAuthScheme.NTLM).get)
await(ws.url("/").withAuth("user", "s3cr3t", WSAuthScheme.NTLM).get())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions must be called using parenthesis in Scala now

)
a[UnsupportedOperationException] shouldBe thrownBy(
await(ws.url("/").withAuth("user", "s3cr3t", WSAuthScheme.DIGEST).get)
await(ws.url("/").withAuth("user", "s3cr3t", WSAuthScheme.DIGEST).get())
)
a[UnsupportedOperationException] shouldBe thrownBy(
await(ws.url("/").withAuth("user", "s3cr3t", WSAuthScheme.KERBEROS).get)
await(ws.url("/").withAuth("user", "s3cr3t", WSAuthScheme.KERBEROS).get())
)
a[UnsupportedOperationException] shouldBe thrownBy(
await(ws.url("/").withAuth("user", "s3cr3t", WSAuthScheme.SPNEGO).get)
await(ws.url("/").withAuth("user", "s3cr3t", WSAuthScheme.SPNEGO).get())
)

}
Expand Down
1 change: 1 addition & 0 deletions src/test/scala/mockws/Example.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import scala.concurrent.Future
import scala.util.Try
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
import play.api.libs.ws.readableAsString

object ImplementationToTest {

Expand Down
11 changes: 7 additions & 4 deletions src/test/scala/mockws/MockWSTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import scala.concurrent.Future
import scala.concurrent.duration._
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import play.api.libs.ws.writeableOf_String
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are implicit BodyParser implementations for reading and writting Strings to request bodies. They now need to be imported explicitly in Scala 3 (I think? Scala 3 compilation wouldn't work unless I did).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same "issue" in my projects, not sure if that's really intended though.

import play.api.libs.ws.readableAsString
import play.api.libs.ws.writeableOf_JsValue

/**
* Tests that [[MockWS]] simulates a WS client
Expand Down Expand Up @@ -180,7 +183,7 @@ class MockWSTest extends AnyFunSuite with Matchers with ScalaCheckPropertyChecks
}
}

val wsResponse = await(ws.url("/").addHttpHeaders(CONTENT_TYPE -> "hello/world").get)
val wsResponse = await(ws.url("/").addHttpHeaders(CONTENT_TYPE -> "hello/world").get())
wsResponse.status shouldEqual OK
wsResponse.body shouldEqual "hello/world"
ws.close()
Expand All @@ -198,7 +201,7 @@ class MockWSTest extends AnyFunSuite with Matchers with ScalaCheckPropertyChecks
}
}

val wsResponse = await(ws.url("/uri").addQueryStringParameters(q -> v).get)
val wsResponse = await(ws.url("/uri").addQueryStringParameters(q -> v).get())
wsResponse.status shouldEqual OK
wsResponse.body shouldEqual v
ws.close()
Expand All @@ -218,8 +221,8 @@ class MockWSTest extends AnyFunSuite with Matchers with ScalaCheckPropertyChecks
}
}

await(ws.url("/uri").addHttpHeaders(Seq(q -> v): _*).get)
await(ws.url("/uri").addQueryStringParameters(Seq(q -> v): _*).get)
await(ws.url("/uri").addHttpHeaders(Seq(q -> v): _*).get())
await(ws.url("/uri").addQueryStringParameters(Seq(q -> v): _*).get())
ws.close()
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/test/scala/mockws/StreamingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import play.api.mvc.MultipartFormData.DataPart
import play.api.mvc.MultipartFormData.FilePart
import play.api.mvc.MultipartFormData.Part
import play.api.mvc.Results._
import play.api.mvc.AnyContent
import play.api.mvc.Request
import play.api.mvc.ResponseHeader
import play.api.mvc.Result
import play.api.test.FakeRequest
import play.api.test.Helpers._
import play.api.libs.ws.readableAsString

import scala.collection.immutable.Seq
import scala.concurrent.ExecutionContext.Implicits._
Expand Down Expand Up @@ -122,7 +125,7 @@ class StreamingTest extends AnyFunSuite with Matchers with ScalaCheckPropertyChe
ws.close()
}

val streamBackAction = Action { req =>
val streamBackAction = Action { (req: Request[AnyContent]) =>
val inputWords: Seq[String] = Seq() ++ req.body.asMultipartFormData.toSeq.flatMap(_.dataParts("k1"))
val returnWords = Seq(req.method + ": ") ++ inputWords
val outputStream: Source[ByteString, _] = Source(returnWords.map(v => ByteString(v)))
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ThisBuild / version := "2.8.2-SNAPSHOT"
ThisBuild / version := "2.9.0"