Skip to content

Commit

Permalink
Bump Vert.x to 4.5.6-SNAPSHOT, Bump Scala to 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-brm committed Mar 15, 2024
1 parent 3d55997 commit aa96386
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 137 deletions.
21 changes: 17 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
</licenses>

<properties>
<scala.version>3.3.1</scala.version>
<junit.version>5.10.2</junit.version>
<scala.version>3.4.0</scala.version>
<slf4j.version>2.0.11</slf4j.version>
<stack.version>${project.version}</stack.version>
</properties>

Expand All @@ -54,7 +56,14 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.11</version>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>co.helmethair</groupId>
Expand All @@ -64,12 +73,12 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.1</version>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.1</version>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
Expand All @@ -90,6 +99,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public class Templates {
put(JSON_ARRAY, TypeInfo::getName);
put(ENUM, TypeInfo::getName);
put(OTHER, type -> getNonGenericType(type.getName()));
put(ASYNC_RESULT, t -> "AsyncResult" + (!((ParameterizedTypeInfo) t).getArgs().isEmpty() ? "[" + fromTypeToScalaTypeString(((ParameterizedTypeInfo) t).getArgs().get(0)) + "]" : "[_]"));
put(CLASS_TYPE, t -> "Class" + (((ParameterizedTypeInfo) t).getArgs().isEmpty() ? "[_]" : "[" + ((ParameterizedTypeInfo) t).getArgs().stream().map(Templates::fromTypeToScalaTypeString).collect(Collectors.joining(", ")) + "]"));
put(ASYNC_RESULT, t -> "AsyncResult" + (!((ParameterizedTypeInfo) t).getArgs().isEmpty() ? "[" + fromTypeToScalaTypeString(((ParameterizedTypeInfo) t).getArgs().get(0)) + "]" : "[?]"));
put(CLASS_TYPE, t -> "Class" + (((ParameterizedTypeInfo) t).getArgs().isEmpty() ? "[?]" : "[" + ((ParameterizedTypeInfo) t).getArgs().stream().map(Templates::fromTypeToScalaTypeString).collect(Collectors.joining(", ")) + "]"));

put(API, t -> {
String ret = getNonGenericType(t.getName());
if (t.isParameterized()) {
if (((ParameterizedTypeInfo) t).getArgs().isEmpty()) {
ret += "[_]";
ret += "[?]";
} else {
ret += "[" + ((ParameterizedTypeInfo) t).getArgs().stream().map(Templates::fromTypeToScalaTypeString).collect(Collectors.joining(", ")) + "]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
}
}

private def listToJsArr(a: Seq[_]) = JsonArray(a: _*)
private def listToJsArr(a: Seq[?]) = JsonArray(a*)
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@ package io.vertx.lang.scala.itest.db.jdbc

import io.vertx.core.Vertx
import io.vertx.jdbcclient.JDBCPool
import io.vertx.lang.scala.ImplicitConversions.{vertxFutureToScalaFuture, vertxFutureVoidToScalaFutureUnit}
import io.vertx.lang.scala.{asScala, VertxExecutionContext}
import io.vertx.lang.scala.itest.db.{ID, ToDoDatabaseService}
import io.vertx.lang.scala.ImplicitConversions.vertxFutureToScalaFuture
import io.vertx.lang.scala.itest.db.ID
import io.vertx.lang.scala.itest.domain.ToDo.{Date, Note, Time, Title}
import io.vertx.lang.scala.itest.domain.{title, ToDo}
import io.vertx.lang.scala.json.Json
import io.vertx.lang.scala.{asScala, VertxExecutionContext}
import io.vertx.scala.core.JsonObject
import io.vertx.scala.jdbcclient.JDBCConnectOptions
import io.vertx.scala.sqlclient.PoolOptions
import io.vertx.sqlclient.Pool
import org.scalatest.Checkpoints.Checkpoint
import org.scalatest.{BeforeAndAfter, FutureOutcome, ParallelTestExecution, Succeeded}
import org.scalatest.compatible.Assertion
import org.scalatest.funspec.FixtureAsyncFunSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.{FutureOutcome, ParallelTestExecution, Succeeded}

import java.util.concurrent.TimeUnit
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.jdk.CollectionConverters.*
import scala.language.implicitConversions
import io.vertx.scala.jdbcclient.JDBCConnectOptions
import io.vertx.scala.sqlclient.PoolOptions

class ToDoDatabaseJdbcSpec extends FixtureAsyncFunSpec, Matchers, ParallelTestExecution:

Expand Down
5 changes: 5 additions & 0 deletions vertx-lang-scala-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,48 @@ import io.vertx.lang.scala.*
import io.vertx.lang.scala.json.{Json, JsonObject}
import io.vertx.lang.scala.testing.TypeUtility.typeName
import io.vertx.scala.core.DeploymentOptions
import org.scalatest.BeforeAndAfter
import org.scalatest.BeforeAndAfterAll
import org.scalatest.flatspec.AsyncFlatSpec
import org.slf4j.{Logger, LoggerFactory}

import scala.concurrent.Await
import scala.concurrent.duration.*
import scala.language.postfixOps
import scala.util.{Failure, Success}
import org.slf4j.Logger
import org.slf4j.LoggerFactory

abstract class VerticleTesting[A <: ScalaVerticle](using TypeName[A]) extends AsyncFlatSpec, BeforeAndAfter:
val vertx: Vertx = Vertx.vertx()
val typeName: String = TypeUtility.typeName[A]
val log: Logger = LoggerFactory.getLogger(typeName)
abstract class VerticleTesting[A <: ScalaVerticle](using TypeName[A]) extends AsyncFlatSpec, BeforeAndAfterAll:
val vertx: Vertx = Vertx.vertx()
private val typeName: String = TypeUtility.typeName[A]
private val log: Logger = LoggerFactory.getLogger(typeName)
private var deploymentId = ""
given vertxExecutionContext: VertxExecutionContext = VertxExecutionContext(vertx, vertx.getOrCreateContext())
private var deploymentId = ""

def config(): JsonObject = Json.obj()
private def config(): JsonObject = Json.obj()

before {
override def beforeAll(): Unit = {
log.info(s"Deploying $typeName...")
deploymentId = Await.result(
vertx
.deployVerticle("scala:" + typeName, DeploymentOptions().setConfig(config())).asScala
.deployVerticle("scala:" + typeName, DeploymentOptions().setConfig(config()))
.asScala
.andThen {
case Success(id) =>
log.info(s"Deployment of $typeName done, got ID: $id")
id
case Failure(t) =>
log.error(s"Deployment of $typeName failed: ${t.getMessage}")
throw new RuntimeException(t)
case Success(id) => log.info("Deployment of {} done, got ID: {}", typeName, id)
case Failure(ex) => log.error("Deployment of {} failed: {}", typeName, ex.getMessage)
},
10000 millis
)
}

after {
override def afterAll(): Unit = {
log.info(s"Undeploying $typeName...")
Await.result(
vertx.undeploy(deploymentId).asScala
.andThen {
case Success(_) => log.info(s"$typeName undeployed")
case Failure(t) => throw new RuntimeException(t)
},
vertx
.undeploy(deploymentId)
.asScala
.andThen {
case Success(_) => log.info("{} undeployed", typeName)
case Failure(t) => log.error("Cannot undeploy {}", typeName, t)
},
10000 millis
)
}



This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.vertx.lang.scala.testing

import io.vertx.ext.web.Router
import io.vertx.lang.scala.ImplicitConversions.vertxFutureToScalaFuture
import io.vertx.lang.scala.json.json
import io.vertx.lang.scala.*
import org.slf4j.{Logger, LoggerFactory}

import scala.concurrent.Future
import scala.language.implicitConversions

class TestVerticle extends ScalaVerticle:

val log: Logger = LoggerFactory.getLogger(classOf[TestVerticle])

override def asyncStart: Future[Unit] =
log.debug("asyncStart!")
val router = Router.router(vertx)
router
.get("/ping")
.handler(_.json(json"""{ "message": "pong" }"""))
router
.get("/hello")
.handler(_.response.putHeader("content-type", "text/plain").end("Hello from Vert.x!"))
router
.delete("/account")
.handler(_.json(json"""{ "message": "ok" }"""))
vertx.createHttpServer
.requestHandler(router)
.listen(8888, "0.0.0.0")
.mapEmpty
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.vertx.lang.scala.testing

import io.vertx.core.http.HttpClientAgent
import io.vertx.lang.scala.*
import io.vertx.lang.scala.ImplicitConversions.vertxFutureToScalaFuture
import io.vertx.lang.scala.json.{json, Json}
import io.vertx.scala.core.*
import org.scalatest.FutureOutcome
import org.scalatest.matchers.should.Matchers

import scala.compiletime.uninitialized
import scala.language.implicitConversions

class VerticleTestingSpec extends VerticleTesting[TestVerticle], Matchers:

var httpClient: HttpClientAgent = uninitialized

override def withFixture(test: NoArgAsyncTest): FutureOutcome = {
httpClient = vertx.createHttpClient()
complete {
super.withFixture(test)
} lastly {
httpClient.close()
}
}

"VerticleTesting" should "provide a Vertx instance" in {
vertx should not be null
}

it should "provide a given VertxExecutionContext instance" in {
summon[VertxExecutionContext] should not be null
}

"TestVerticle" should "bind to 8888 and answer with 'Hello from Vert.x!'" in {
for {
req <- httpClient.request(RequestOptions(absoluteURI = "http://127.0.0.1:8888/hello"))
res <- req.send
body <- res.body
assertion = body.toString("UTF-8") should equal("Hello from Vert.x!")
} yield assertion
}

it should "answer with a pong when pinged" in {
for {
req <- httpClient.request(RequestOptions(absoluteURI = "http://127.0.0.1:8888/ping"))
res <- req.send
body <- res.body
assertion = body.toJsonValue should equal(Json.obj("""{ "message": "pong" }"""))
} yield assertion
}

it should "answer with ok when DELETE /account is called" in {
for {
req <- httpClient.request(HttpMethod("DELETE"), 8888, "127.0.0.1", "/account")
res <- req.send
body <- res.body
assertion = body.toJsonValue should equal(json"""{ "message": "ok" }""")
} yield assertion
}
9 changes: 5 additions & 4 deletions vertx-lang-scala/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ lazy val root = project
.settings(
name := "Vert.x for Scala",
libraryDependencies ++= Seq(
"io.vertx" % "vertx-web" % version.value,
"io.vertx" %% "vertx-lang-scala" % version.value,
"io.vertx" %% "vertx-lang-scala-test" % version.value,
"org.scalatest" %% "scalatest" % "3.3.0-SNAP4",
"io.vertx" % "vertx-web" % version.value,
"io.vertx" %% "vertx-lang-scala" % version.value,
"io.vertx" %% "vertx-lang-scala-test" % version.value,
"org.scalatest" %% "scalatest" % "3.3.0-SNAP4" % Test,
"org.scalatestplus" %% "scalacheck-1-17" % "3.2.18.0" % Test,
),
scalacOptions ++= Seq("-deprecation", "-feature"),
)
5 changes: 5 additions & 0 deletions vertx-lang-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@
<artifactId>scalacheck-1-17_3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Loading

0 comments on commit aa96386

Please sign in to comment.