Skip to content

Commit dd80156

Browse files
authored
Merge branch 'Baeldung:master' into test-rearrangement
2 parents 7d0d971 + 14c3446 commit dd80156

Some content is hidden

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

56 files changed

+796
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ In this repository, we have classified the tests in 4 categories.
66
| -- |---------------------------------------------------------------------------------------------------------------------------------------------------------------|
77
| Unit Tests | Smallest unit of testing, that are not dependent on external tools or services |
88
| Integration Tests | IntegrationTests means those tests that use some automatic setup within our environment like in-memory Mongo, h2 database etc which don't need explicit setup |
9-
| Live Tests | Tests that depends on some external services (like httpbin.org, or some internet-based links) |
9+
| Live Tests | Tests that depends on some external services (like httpbin.org, or some internet-based links) or require a running component (eg: starting a Spring Boot application) |
1010
| Manual Tests | The tests where we need to set up an environment explicitly(for e.g. docker), without which the tests can't be run |
1111

1212

alias.sbt

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

build.sbt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ ThisBuild / organization := "com.baeldung"
66
ThisBuild / organizationName := "core-scala"
77

88
val jUnitInterface = "com.github.sbt" % "junit-interface" % "0.13.3" % "test"
9-
val catsEffect = "org.typelevel" %% "cats-effect" % "3.5.0"
10-
val catEffectTest = "org.typelevel" %% "cats-effect-testkit" % "3.5.0" % Test
9+
val catsEffect = "org.typelevel" %% "cats-effect" % "3.5.1"
10+
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"
1313
val embedMongoVersion = "4.7.0"
@@ -260,7 +260,7 @@ lazy val scala_libraries = (project in file("scala-libraries"))
260260

261261
val circeVersion = "0.14.5"
262262
val monixVersion = "3.4.1"
263-
val elastic4sVersion = "8.7.0"
263+
val elastic4sVersion = "8.7.1"
264264
val sparkVersion = "3.4.0"
265265

266266
val sparkCoreDep = "org.apache.spark" %% "spark-core" % sparkVersion
@@ -308,7 +308,7 @@ lazy val scala_libraries_2 = (project in file("scala-libraries-2"))
308308
)
309309

310310
val http4sBlaze = "0.23.15"
311-
val http4sVersion = "0.23.20"
311+
val http4sVersion = "0.23.22"
312312
val osLibVersion = "0.9.1"
313313
lazy val scala_libraries_3 = (project in file("scala-libraries-3"))
314314
.settings(
@@ -374,7 +374,7 @@ lazy val scala_libraries_4 = (project in file("scala-libraries-4"))
374374
),
375375
libraryDependencies ++= Seq(
376376
"software.amazon.awssdk" % "s3" % "2.20.85",
377-
"com.amazonaws" % "aws-java-sdk-s3" % "1.12.488" % IntegrationTest,
377+
"com.amazonaws" % "aws-java-sdk-s3" % "1.12.501" % IntegrationTest,
378378
"com.dimafeng" %% "testcontainers-scala-scalatest" % "0.40.16" % IntegrationTest,
379379
"com.dimafeng" %% "testcontainers-scala-localstack-v2" % "0.40.16" % IntegrationTest
380380
),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.arrival.controller
2+
3+
import com.baeldung.arrival.service.ArrivalService
4+
import play.api.libs.json.Json
5+
import play.api.mvc.{BaseController, ControllerComponents}
6+
7+
import javax.inject.Inject
8+
import scala.concurrent.ExecutionContext
9+
10+
class ArrivalController @Inject()(arrivalService: ArrivalService, val controllerComponents: ControllerComponents)(implicit ec: ExecutionContext) extends BaseController {
11+
12+
def index() = Action.async { _ =>
13+
arrivalService.getArrivals().map(arrivals => Ok(Json.toJson(arrivals)))
14+
}
15+
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.arrival.controller.action
2+
3+
import play.api.mvc._
4+
5+
import scala.concurrent.{ExecutionContext, Future}
6+
7+
trait SourceActions {
8+
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"))
15+
}
16+
}
17+
}
18+
19+
override protected def executionContext: ExecutionContext = ec
20+
}
21+
22+
def SourceAction(anyContentParser: BodyParser[AnyContent])(implicit ec: ExecutionContext): ActionBuilder[Request, AnyContent] =
23+
new ActionBuilderImpl[AnyContent](anyContentParser) andThen SourceActionFilter
24+
25+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.arrival.db.manager
2+
3+
import slick.basic.DatabaseConfig
4+
import slick.dbio.DBIO
5+
6+
import scala.concurrent.Future
7+
8+
trait DbManager {
9+
10+
def dbConfig: DatabaseConfig[_]
11+
12+
def execute[T](dbio: DBIO[T]): Future[T] = dbConfig.db.run(dbio)
13+
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.arrival.db.manager
2+
3+
import slick.basic.DatabaseConfig
4+
import slick.jdbc.H2Profile
5+
6+
import javax.inject.Inject
7+
8+
class H2Manager @Inject()(val dbConfig: DatabaseConfig[H2Profile]) extends DbManager
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.arrival.db.manager
2+
3+
import slick.basic.DatabaseConfig
4+
import slick.jdbc.PostgresProfile
5+
6+
import javax.inject.Inject
7+
8+
class PostgresManager @Inject()(val dbConfig: DatabaseConfig[PostgresProfile]) extends DbManager
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.arrival.db.repository
2+
3+
import play.api.libs.json.{Json, OFormat}
4+
import slick.dbio.DBIO
5+
6+
case class Arrival(planeId: Long, origin: String, destination: String, plane: String)
7+
8+
object Arrival {
9+
implicit val format: OFormat[Arrival] = Json.format[Arrival]
10+
}
11+
12+
trait ArrivalRepository {
13+
def getArrivals: DBIO[Seq[Arrival]]
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.arrival.db.repository
2+
3+
import slick.dbio.DBIO
4+
5+
class MockArrivalRepository extends ArrivalRepository {
6+
override def getArrivals: DBIO[Seq[Arrival]] = DBIO.successful(
7+
List(
8+
Arrival(1L, "origin-1", "destination-1", "F16"),
9+
Arrival(2L, "origin-2", "destination-2", "F22"),
10+
Arrival(3L, "origin-3", "destination-3", "SR71")
11+
)
12+
)
13+
}

0 commit comments

Comments
 (0)