Skip to content

Commit c463918

Browse files
authored
Merge pull request #1 from Baeldung/master
updating pr
2 parents c8b74a2 + ba2245e commit c463918

File tree

78 files changed

+1065
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1065
-117
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ project/plugins/project/
1616
.scala_dependencies
1717
.worksheet
1818
.idea
19+
!/project/Versions.scala
1920
/project/
2021
!project/build.properties
2122
out

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = 3.7.7
1+
version = 3.7.10
22
runner.dialect = scala3
33
fileOverride {
44
"glob:**/scala-2-modules/**" {

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ In this repository, we have classified the tests in 4 categories.
1111

1212

1313
Here is a table describing about the different categories of tests and how they can be executed in this project.
14+
Note that these commands are defined at the root level of the project and hence are accessible only from the root project(not directly within each submodule).
1415

1516
| Category | Sbt command | Test class location | Test class name format |
1617
|-------------------------|-------------------|----------------------------------------|-------------------------------------------------------------------------------------------------------------------------|

alias.sbt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
addCommandAlias("specialTests", "testOnly com.baeldung.scala.scalatest.runner.ScalaTestRunnerTests -- -z \"spaces\" -n \"BooleanTests\"")
1+
addCommandAlias(
2+
"specialTests",
3+
"testOnly com.baeldung.scala.scalatest.runner.ScalaTestRunnerTests -- -z \"spaces\" -n \"BooleanTests\""
4+
)
25

3-
addCommandAlias("compileAndRunSpecialTest","compile;specialTests")
6+
addCommandAlias("compileAndRunSpecialTest", "compile;specialTests")

build.sbt

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
val scalaV = "2.13.11"
2-
val scala3Version = "3.2.2"
1+
val scalaV = ScalaVersions.scala2Version
2+
val scala3Version = ScalaVersions.scala3Version
33
ThisBuild / scalaVersion := scalaV
44
ThisBuild / version := "1.0-SNAPSHOT"
55
ThisBuild / organization := "com.baeldung"
@@ -10,7 +10,7 @@ val catsEffect = "org.typelevel" %% "cats-effect" % "3.5.1"
1010
val catEffectTest = "org.typelevel" %% "cats-effect-testkit" % "3.5.1" % Test
1111
val scalaReflection = "org.scala-lang" % "scala-reflect" % scalaV
1212
val logback = "ch.qos.logback" % "logback-classic" % "1.3.8"
13-
val embedMongoVersion = "4.7.0"
13+
val embedMongoVersion = "4.7.1"
1414

1515
val scalaTestDeps = Seq(
1616
"org.scalatest" %% "scalatest" % "3.2.16" % Test,
@@ -46,7 +46,7 @@ lazy val scala_core_3 = (project in file("scala-core-3"))
4646
libraryDependencies ++= scalaTestDeps,
4747
libraryDependencies += jUnitInterface,
4848
libraryDependencies += scalaReflection,
49-
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "2.1.0"
49+
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "2.2.0"
5050
)
5151

5252
lazy val scala_core_4 = (project in file("scala-core-4"))
@@ -175,7 +175,7 @@ lazy val scala_akka_dependencies: Seq[ModuleID] = Seq(
175175
"com.typesafe.akka" %% "akka-actor-testkit-typed" % AkkaVersion % Test,
176176
"com.lightbend.akka" %% "akka-stream-alpakka-mongodb" % "5.0.0",
177177
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
178-
"org.mongodb.scala" %% "mongo-scala-driver" % "4.10.1",
178+
"org.mongodb.scala" %% "mongo-scala-driver" % "4.10.2",
179179
"com.lightbend.akka" %% "akka-stream-alpakka-file" % "5.0.0",
180180
jUnitInterface,
181181
embeddedMongo % Test,
@@ -230,7 +230,6 @@ val fs2Version = "3.7.0"
230230
val AkkaVersion = "2.8.0"
231231
val AkkaHttpVersion = "10.5.0"
232232
val reactiveMongo = "1.0.10"
233-
val spireVersion = "0.18.0"
234233

235234
lazy val scala_libraries = (project in file("scala-libraries"))
236235
.settings(
@@ -241,7 +240,7 @@ lazy val scala_libraries = (project in file("scala-libraries"))
241240
"com.github.julien-truffaut" %% "monocle-macro" % monocleVersion,
242241
"com.github.julien-truffaut" %% "monocle-law" % monocleVersion % "test",
243242
"com.typesafe.slick" %% "slick" % slickVersion,
244-
"com.h2database" % "h2" % "2.1.214",
243+
"com.h2database" % "h2" % "2.2.220",
245244
"com.chuusai" %% "shapeless" % shapelessVersion,
246245
"org.scalaz" %% "scalaz-core" % scalazVersion,
247246
"co.fs2" %% "fs2-core" % fs2Version,
@@ -260,7 +259,7 @@ lazy val scala_libraries = (project in file("scala-libraries"))
260259

261260
val circeVersion = "0.14.5"
262261
val monixVersion = "3.4.1"
263-
val elastic4sVersion = "8.7.1"
262+
val elastic4sVersion = "8.8.1"
264263
val sparkVersion = "3.4.1"
265264

266265
val sparkCoreDep = "org.apache.spark" %% "spark-core" % sparkVersion
@@ -280,7 +279,7 @@ lazy val scala_libraries_2 = (project in file("scala-libraries-2"))
280279
"com.github.cb372" %% "scalacache-guava" % "0.28.0",
281280
"com.github.cb372" %% "scalacache-cats-effect" % "0.28.0",
282281
"com.github.cb372" %% "scalacache-caffeine" % "0.28.0",
283-
"com.beachape" %% "enumeratum" % "1.7.2"
282+
"com.beachape" %% "enumeratum" % "1.7.3"
284283
),
285284
libraryDependencies ++= Seq(
286285
"com.typesafe.play" %% "play-slick" % "5.1.0",
@@ -308,7 +307,7 @@ lazy val scala_libraries_2 = (project in file("scala-libraries-2"))
308307
)
309308

310309
val http4sBlaze = "0.23.15"
311-
val http4sVersion = "0.23.22"
310+
val http4sVersion = "0.23.23"
312311
val osLibVersion = "0.9.1"
313312
lazy val scala_libraries_3 = (project in file("scala-libraries-3"))
314313
.settings(
@@ -322,7 +321,7 @@ lazy val scala_libraries_3 = (project in file("scala-libraries-3"))
322321
"org.http4s" %% "http4s-dsl" % http4sVersion,
323322
"org.http4s" %% "http4s-blaze-server" % http4sBlaze,
324323
"org.http4s" %% "http4s-blaze-client" % http4sBlaze,
325-
"com.beachape" %% "enumeratum" % "1.7.2",
324+
"com.beachape" %% "enumeratum" % "1.7.3",
326325
"com.github.pureconfig" %% "pureconfig" % "0.17.4",
327326
"com.github.pureconfig" %% "pureconfig-enumeratum" % "0.17.4",
328327
"com.typesafe" % "config" % "1.4.2",
@@ -373,8 +372,8 @@ lazy val scala_libraries_4 = (project in file("scala-libraries-4"))
373372
"org.testcontainers" % "pulsar" % "1.18.3" % IntegrationTest
374373
),
375374
libraryDependencies ++= Seq(
376-
"software.amazon.awssdk" % "s3" % "2.20.98",
377-
"com.amazonaws" % "aws-java-sdk-s3" % "1.12.501" % IntegrationTest,
375+
"software.amazon.awssdk" % "s3" % "2.20.111",
376+
"com.amazonaws" % "aws-java-sdk-s3" % "1.12.514" % IntegrationTest,
378377
"com.dimafeng" %% "testcontainers-scala-scalatest" % "0.40.17" % IntegrationTest,
379378
"com.dimafeng" %% "testcontainers-scala-localstack-v2" % "0.40.17" % IntegrationTest
380379
),
@@ -386,15 +385,34 @@ lazy val scala_libraries_4 = (project in file("scala-libraries-4"))
386385
IntegrationTest / fork := true
387386
)
388387

388+
val spireVersion = "0.18.0"
389+
val kafkaVersion = "3.5.0"
390+
val pureconfigVersion = "0.17.4"
391+
val jackSonVersion = "2.15.1"
392+
val log4jApiScalaVersion = "12.0"
393+
val log4jVersion = "2.20.0"
394+
val avro4sVersion = "3.1.1"
395+
val kafkaAvroSerializer = "6.0.0"
396+
389397
lazy val scala_libraries_5 = (project in file("scala-libraries-5"))
390398
.settings(
391399
name := "scala-libraries-5",
400+
resolvers += "Kafka avro serializer" at "https://packages.confluent.io/maven",
392401
scalaVersion := scalaV,
393402
libraryDependencies ++= scalaTestDeps,
394403
libraryDependencies ++= Seq(
395404
sparkSqlDep,
396405
sparkCoreDep,
397-
"org.typelevel" %% "spire" % spireVersion
406+
"org.typelevel" %% "spire" % spireVersion,
407+
"org.apache.kafka" % "kafka-clients" % kafkaVersion,
408+
"com.github.pureconfig" %% "pureconfig" % pureconfigVersion,
409+
"com.fasterxml.jackson.core" % "jackson-databind" % jackSonVersion,
410+
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % jackSonVersion,
411+
"com.fasterxml.jackson.module" %% "jackson-module-scala" % jackSonVersion,
412+
"com.sksamuel.avro4s" %% "avro4s-core" % avro4sVersion,
413+
"io.confluent" % "kafka-avro-serializer" % kafkaAvroSerializer,
414+
"org.apache.logging.log4j" %% "log4j-api-scala" % log4jApiScalaVersion,
415+
"org.apache.logging.log4j" % "log4j-core" % log4jVersion % Runtime
398416
)
399417
)
400418

@@ -483,7 +501,7 @@ Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-eG")
483501

484502
lazy val scala212 = (project in file("scala-2-modules/scala212"))
485503
.settings(
486-
scalaVersion := "2.12.18",
504+
scalaVersion := ScalaVersions.scala212Version,
487505
name := "scala212",
488506
libraryDependencies ++= scalaTestDeps
489507
)
@@ -512,3 +530,5 @@ addCommandAlias(
512530
"liveTests",
513531
""";ci; set ThisBuild/IntegrationTest/testOptions += Tests.Filter(t => t.endsWith("LiveTest")); it:test""".stripMargin
514532
)
533+
534+
lazy val playGroup = (project in file("play-scala"))

play-scala/application-tests/app/com/baeldung/arrival/controller/ArrivalController.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import play.api.mvc.{BaseController, ControllerComponents}
77
import javax.inject.Inject
88
import scala.concurrent.ExecutionContext
99

10-
class ArrivalController @Inject()(arrivalService: ArrivalService, val controllerComponents: ControllerComponents)(implicit ec: ExecutionContext) extends BaseController {
10+
class ArrivalController @Inject() (
11+
arrivalService: ArrivalService,
12+
val controllerComponents: ControllerComponents
13+
)(implicit ec: ExecutionContext)
14+
extends BaseController {
1115

1216
def index() = Action.async { _ =>
1317
arrivalService.getArrivals().map(arrivals => Ok(Json.toJson(arrivals)))

play-scala/application-tests/app/com/baeldung/arrival/controller/action/SourceActions.scala

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@ import scala.concurrent.{ExecutionContext, Future}
66

77
trait SourceActions {
88

9-
def SourceActionFilter(implicit ec: ExecutionContext): ActionFilter[Request] = new ActionFilter[Request] {
10-
override protected def filter[A](request: Request[A]): Future[Option[Result]] = {
11-
Future.successful {
12-
request.headers.get("source") match {
13-
case Some(_) => None
14-
case None => Some(Results.BadRequest("Source header is absent"))
9+
def SourceActionFilter(implicit ec: ExecutionContext): ActionFilter[Request] =
10+
new ActionFilter[Request] {
11+
override protected def filter[A](
12+
request: Request[A]
13+
): Future[Option[Result]] = {
14+
Future.successful {
15+
request.headers.get("source") match {
16+
case Some(_) => None
17+
case None => Some(Results.BadRequest("Source header is absent"))
18+
}
1519
}
1620
}
17-
}
1821

19-
override protected def executionContext: ExecutionContext = ec
20-
}
22+
override protected def executionContext: ExecutionContext = ec
23+
}
2124

22-
def SourceAction(anyContentParser: BodyParser[AnyContent])(implicit ec: ExecutionContext): ActionBuilder[Request, AnyContent] =
23-
new ActionBuilderImpl[AnyContent](anyContentParser) andThen SourceActionFilter
25+
def SourceAction(
26+
anyContentParser: BodyParser[AnyContent]
27+
)(implicit ec: ExecutionContext): ActionBuilder[Request, AnyContent] =
28+
new ActionBuilderImpl[AnyContent](
29+
anyContentParser
30+
) andThen SourceActionFilter
2431

2532
}

play-scala/application-tests/app/com/baeldung/arrival/db/manager/H2Manager.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ import slick.jdbc.H2Profile
55

66
import javax.inject.Inject
77

8-
class H2Manager @Inject()(val dbConfig: DatabaseConfig[H2Profile]) extends DbManager
8+
class H2Manager @Inject() (val dbConfig: DatabaseConfig[H2Profile])
9+
extends DbManager

play-scala/application-tests/app/com/baeldung/arrival/db/manager/PostgresManager.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ import slick.jdbc.PostgresProfile
55

66
import javax.inject.Inject
77

8-
class PostgresManager @Inject()(val dbConfig: DatabaseConfig[PostgresProfile]) extends DbManager
8+
class PostgresManager @Inject() (val dbConfig: DatabaseConfig[PostgresProfile])
9+
extends DbManager

play-scala/application-tests/app/com/baeldung/arrival/db/repository/ArrivalRepository.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ package com.baeldung.arrival.db.repository
33
import play.api.libs.json.{Json, OFormat}
44
import slick.dbio.DBIO
55

6-
case class Arrival(planeId: Long, origin: String, destination: String, plane: String)
6+
case class Arrival(
7+
planeId: Long,
8+
origin: String,
9+
destination: String,
10+
plane: String
11+
)
712

813
object Arrival {
914
implicit val format: OFormat[Arrival] = Json.format[Arrival]

play-scala/application-tests/app/com/baeldung/arrival/db/repository/SlickArrivalRepository.scala

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import slick.jdbc.JdbcProfile
55
import javax.inject.Inject
66
import scala.concurrent.ExecutionContext
77

8-
class SlickArrivalRepository @Inject()(val dbProfile: JdbcProfile)(implicit ec: ExecutionContext) extends ArrivalRepository {
9-
8+
class SlickArrivalRepository @Inject() (val dbProfile: JdbcProfile)(implicit
9+
ec: ExecutionContext
10+
) extends ArrivalRepository {
1011

1112
import dbProfile.api._
1213

@@ -20,14 +21,18 @@ class SlickArrivalRepository @Inject()(val dbProfile: JdbcProfile)(implicit ec:
2021

2122
def plane = column[String]("plane")
2223

23-
def * = (id, origin, destination, plane) <> ((Arrival.apply _).tupled, Arrival.unapply)
24+
def * = (
25+
id,
26+
origin,
27+
destination,
28+
plane
29+
) <> ((Arrival.apply _).tupled, Arrival.unapply)
2430
}
2531

26-
/**
27-
* The starting point for all queries on the people table.
28-
*/
32+
/** The starting point for all queries on the people table.
33+
*/
2934
private val arrivals = TableQuery[ArrivalTable]
3035

3136
def getArrivals: DBIO[Seq[Arrival]] = arrivals.result
3237

33-
}
38+
}

play-scala/application-tests/app/com/baeldung/arrival/modules/H2Module.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ class H2Module extends AbstractModule {
1414
}
1515

1616
@Provides
17-
def dbProfile(@NamedDatabase("h2") dbConfigProvider: DatabaseConfigProvider): JdbcProfile = {
17+
def dbProfile(
18+
@NamedDatabase("h2") dbConfigProvider: DatabaseConfigProvider
19+
): JdbcProfile = {
1820
dbConfigProvider.get[H2Profile].profile
1921
}
2022

2123
@Provides
22-
def dbConfig(@NamedDatabase("h2") dbConfigProvider: DatabaseConfigProvider): DatabaseConfig[H2Profile] = {
24+
def dbConfig(
25+
@NamedDatabase("h2") dbConfigProvider: DatabaseConfigProvider
26+
): DatabaseConfig[H2Profile] = {
2327
dbConfigProvider.get[H2Profile]
2428
}
2529

play-scala/application-tests/app/com/baeldung/arrival/modules/MockDbModule.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.baeldung.arrival.modules
22

3-
import com.baeldung.arrival.db.repository.{ArrivalRepository, MockArrivalRepository}
3+
import com.baeldung.arrival.db.repository.{
4+
ArrivalRepository,
5+
MockArrivalRepository
6+
}
47
import com.google.inject.AbstractModule
58

69
class MockDbModule extends AbstractModule {

play-scala/application-tests/app/com/baeldung/arrival/modules/PostgresModule.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ class PostgresModule extends AbstractModule {
1414
}
1515

1616
@Provides
17-
def dbProfile(@NamedDatabase("postgres") dbConfigProvider: DatabaseConfigProvider): JdbcProfile = {
17+
def dbProfile(
18+
@NamedDatabase("postgres") dbConfigProvider: DatabaseConfigProvider
19+
): JdbcProfile = {
1820
dbConfigProvider.get[PostgresProfile].profile
1921
}
2022

2123
@Provides
22-
def dbConfig(@NamedDatabase("postgres") dbConfigProvider: DatabaseConfigProvider): DatabaseConfig[PostgresProfile] = {
24+
def dbConfig(
25+
@NamedDatabase("postgres") dbConfigProvider: DatabaseConfigProvider
26+
): DatabaseConfig[PostgresProfile] = {
2327
dbConfigProvider.get[PostgresProfile]
2428
}
2529

play-scala/application-tests/app/com/baeldung/arrival/modules/SlickModule.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.baeldung.arrival.modules
22

3-
import com.baeldung.arrival.db.repository.{ArrivalRepository, SlickArrivalRepository}
3+
import com.baeldung.arrival.db.repository.{
4+
ArrivalRepository,
5+
SlickArrivalRepository
6+
}
47
import com.google.inject.AbstractModule
58

69
class SlickModule extends AbstractModule {

play-scala/application-tests/app/com/baeldung/arrival/service/ArrivalDecoratorService.scala

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,26 @@ trait Size {
1313
def long: Boolean
1414
}
1515

16-
class ArrivalDecoratorService @Inject()(configuration: Configuration) {
16+
class ArrivalDecoratorService @Inject() (configuration: Configuration) {
1717

1818
private val maximumShortNameLength = configuration.get[Int]("short-name-max")
19-
private val maximumMediumNameLength = configuration.get[Int]("medium-name-max")
20-
21-
def decorate(undecorated: Arrival): Arrival with Size = new Arrival(undecorated.planeId, undecorated.origin, undecorated.destination, undecorated.plane) with Size {
22-
override def short: Boolean = undecorated.plane.length <= maximumShortNameLength
23-
24-
override def medium: Boolean = undecorated.plane.length > maximumShortNameLength && undecorated.plane.length <= maximumMediumNameLength
25-
26-
override def long: Boolean = undecorated.plane.length > maximumMediumNameLength
19+
private val maximumMediumNameLength =
20+
configuration.get[Int]("medium-name-max")
21+
22+
def decorate(undecorated: Arrival): Arrival with Size = new Arrival(
23+
undecorated.planeId,
24+
undecorated.origin,
25+
undecorated.destination,
26+
undecorated.plane
27+
) with Size {
28+
override def short: Boolean =
29+
undecorated.plane.length <= maximumShortNameLength
30+
31+
override def medium: Boolean =
32+
undecorated.plane.length > maximumShortNameLength && undecorated.plane.length <= maximumMediumNameLength
33+
34+
override def long: Boolean =
35+
undecorated.plane.length > maximumMediumNameLength
2736
}
2837

2938
}

0 commit comments

Comments
 (0)