Skip to content

Commit

Permalink
Merge pull request #439 from dwijnand/play-m4
Browse files Browse the repository at this point in the history
Upgrade to Play 2.7.0-M4 / ScalaTest + Play 4.0.0-M5
  • Loading branch information
dwijnand authored Oct 18, 2018
2 parents 6d3a08b + 9901d6a commit c1fad01
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 485 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ package akka.grpc.scalatestplus.play
import akka.grpc.internal.AkkaGrpcClientFactory
import akka.grpc.play.AkkaGrpcClientHelpers
import akka.grpc.scaladsl.AkkaGrpcClient
import org.scalatestplus.play.NewServerProvider
import play.api.test.RunningServer
import play.api.Application
import play.api.test.{ DefaultTestServerFactory, RunningServer }
import scala.reflect.ClassTag
import org.scalatest.TestData
import org.scalatestplus.play.BaseOneServerPerTest

/**
* Helpers to test gRPC clients with Play using ScalaTest.
*
* Mixes a method into [[AkkaGrpcClientHelpers]] that knows how to configure
*/
trait ServerGrpcClient extends AkkaGrpcClientHelpers { this: NewServerProvider =>
trait ServerGrpcClient extends AkkaGrpcClientHelpers { this: BaseOneServerPerTest =>

/** Configure the factory by combining the current app and server information */
implicit def configuredAkkaGrpcClientFactory[T <: AkkaGrpcClient: ClassTag](implicit running: RunningServer): AkkaGrpcClientFactory.Configured[T] = {
AkkaGrpcClientHelpers.factoryForAppEndpoints(running.app, running.endpoints)
}

override protected def newServerForTest(app: Application, testData: TestData): RunningServer =
DefaultTestServerFactory.start(app)

}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
package akka.grpc.scalatestplus.play

import org.scalatest.concurrent.{ IntegrationPatience, ScalaFutures }
import org.scalatestplus.play.{ NewGuiceOneServerPerTest, PlaySpec }
import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.guice.GuiceOneServerPerTest
import play.api.Application
import play.api.inject.bind
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.ws.WSClient
import play.api.routing.Router

import example.myapp.helloworld.grpc.helloworld.{ GreeterService, GreeterServiceImpl, GreeterServiceClient, HelloRequest }
import example.myapp.helloworld.grpc.helloworld.{ GreeterService, GreeterServiceClient, GreeterServiceImpl, HelloRequest }

/**
* Test for the Play gRPC ScalaTest APIs
*/
class PlayScalaTestSpec extends PlaySpec with ServerGrpcClient
with NewGuiceOneServerPerTest with ScalaFutures with IntegrationPatience {
class PlayScalaTestSpec extends PlaySpec with GuiceOneServerPerTest with ServerGrpcClient
with ScalaFutures with IntegrationPatience {

override def fakeApplication(): Application = {
GuiceApplicationBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import scala.reflect.ClassTag
import akka.grpc.internal.AkkaGrpcClientFactory
import akka.grpc.play.AkkaGrpcClientHelpers
import akka.grpc.scaladsl.AkkaGrpcClient
import play.api.test.{ NewForServer, RunningServer }
import play.api.test.RunningServer

/**
* Helpers to test gRPC clients with Play using Specs2.
*
* Mixes a method into [[AkkaGrpcClientHelpers]] that knows how to configure
* gRPC clients for the running server.
*/
trait ServerGrpcClient extends AkkaGrpcClientHelpers { this: NewForServer =>
trait ServerGrpcClient extends AkkaGrpcClientHelpers {

/** Configure the factory by combining the app and the current implicit server information */
implicit def configuredAkkaGrpcClientFactory[T <: AkkaGrpcClient: ClassTag](implicit running: RunningServer): AkkaGrpcClientFactory.Configured[T] = {
Expand Down
22 changes: 0 additions & 22 deletions play-specs2/src/main/scala/play/api/test/NewForServer.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import example.myapp.helloworld.grpc.helloworld.{ GreeterService, GreeterService
* Test for the Play gRPC Specs2 APIs
*/
@RunWith(classOf[JUnitRunner])
class PlaySpecs2Spec extends NewForServer with ServerGrpcClient with PlaySpecification with ApplicationFactories {
class PlaySpecs2Spec extends ForServer with ServerGrpcClient with PlaySpecification with ApplicationFactories {

protected def applicationFactory: ApplicationFactory =
appFromGuice(GuiceApplicationBuilder().overrides(bind[Router].to[GreeterServiceImpl]))
withGuiceApp(GuiceApplicationBuilder().overrides(bind[Router].to[GreeterServiceImpl]))

// RICH: Still need to work out how to make WSClient work properly with endpoints
def wsUrl(path: String)(implicit running: RunningServer): WSRequest = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import akka.actor.ActorSystem;
import akka.grpc.GrpcClientSettings;

import play.api.test.NewTestServer;
import play.api.test.ServerEndpoint;
import play.api.test.ServerEndpoints;
import play.api.test.RunningServer;
import play.core.server.ServerEndpoint;
import play.core.server.ServerEndpoints;

import javax.net.ssl.SSLContext;

Expand All @@ -20,9 +20,9 @@ public final class JavaAkkaGrpcClientHelpers {
private JavaAkkaGrpcClientHelpers() {}

/** Creates a GrpcClientSettings from the given NewTestServer. */
public static GrpcClientSettings grpcClientSettings(final NewTestServer testServer) {
final ServerEndpoint http2Endpoint = getHttp2Endpoint(testServer.endpoints());
return grpcClientSettings(http2Endpoint, testServer.testServer().application().actorSystem());
public static GrpcClientSettings grpcClientSettings(final RunningServer runningServer) {
final ServerEndpoint http2Endpoint = getHttp2Endpoint(runningServer.endpoints());
return grpcClientSettings(http2Endpoint, runningServer.app().actorSystem());
}

/**
Expand All @@ -32,7 +32,7 @@ public static GrpcClientSettings grpcClientSettings(final NewTestServer testServ
*/
public static ServerEndpoint getHttp2Endpoint(final ServerEndpoints serverEndpoints) {
final scala.collection.Traversable<ServerEndpoint> possibleEndpoints =
serverEndpoints.endpoints().filter(func(e->e.httpVersions().contains("2")));
serverEndpoints.endpoints().filter(func(e->e.expectedHttpVersions().contains("2")));
if (possibleEndpoints.size() != 1) {
throw new IllegalArgumentException(String.format(
"gRPC client can't automatically find HTTP/2 connection: " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ package akka.grpc.play
import java.util.concurrent.TimeUnit

import akka.actor.ActorSystem
import akka.grpc.GrpcClientSettings
import akka.grpc.internal.AkkaGrpcClientFactory
import akka.grpc.scaladsl.AkkaGrpcClient
import akka.stream.Materializer
import com.typesafe.config.{ Config, ConfigFactory, ConfigValueFactory }
import javax.net.ssl.SSLContext
import play.api.Application
import play.api.test.{ ServerEndpoint, ServerEndpoints }
import play.core.server.{ ServerEndpoint, ServerEndpoints }

import scala.concurrent.duration.Duration
import scala.concurrent.{ Await, ExecutionContext }
Expand Down
53 changes: 0 additions & 53 deletions play-testkit/src/main/scala/play/api/test/ApplicationFactory.scala

This file was deleted.

20 changes: 0 additions & 20 deletions play-testkit/src/main/scala/play/api/test/NewTestServer.scala

This file was deleted.

Loading

0 comments on commit c1fad01

Please sign in to comment.