Skip to content

Commit

Permalink
Get rid of inheritance in test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuthan committed Aug 29, 2024
1 parent b620124 commit 296621e
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,29 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

import org.mkuthan.streamprocessing.test.scio.JobTestScioContext
import org.mkuthan.streamprocessing.toll.application.TollJobFixtures
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothDiagnostic
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothEntry
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothEntryFixture
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothExit
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothExitFixture
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothStats
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothStatsFixture
import org.mkuthan.streamprocessing.toll.domain.registration.VehicleRegistration
import org.mkuthan.streamprocessing.toll.domain.registration.VehicleRegistrationFixture
import org.mkuthan.streamprocessing.toll.domain.vehicle.TotalVehicleTimes
import org.mkuthan.streamprocessing.toll.domain.vehicle.TotalVehicleTimesFixture
import org.mkuthan.streamprocessing.toll.domain.vehicle.VehiclesWithExpiredRegistration
import org.mkuthan.streamprocessing.toll.domain.vehicle.VehiclesWithExpiredRegistrationFixture

class TollBatchJobTest extends AnyFlatSpec with Matchers
with JobTestScioContext
with TollJobFixtures
with TollBatchJobIo {
with TollBatchJobIo
with TollBoothEntryFixture
with TollBoothExitFixture
with TollBoothStatsFixture
with TotalVehicleTimesFixture
with VehicleRegistrationFixture
with VehiclesWithExpiredRegistrationFixture {

"Toll job" should "run in the batch mode" in {
JobTest[TollBatchJob.type]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
package org.mkuthan.streamprocessing.toll.application
package org.mkuthan.streamprocessing.toll.application.streaming

import org.joda.time.Instant

import org.mkuthan.streamprocessing.infrastructure.pubsub.PubsubDeadLetter
import org.mkuthan.streamprocessing.shared.common.Diagnostic
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothEntry
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothEntryFixture
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothExit
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothExitFixture
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothStatsFixture
import org.mkuthan.streamprocessing.toll.domain.registration.VehicleRegistration
import org.mkuthan.streamprocessing.toll.domain.registration.VehicleRegistrationFixture
import org.mkuthan.streamprocessing.toll.domain.vehicle.TotalVehicleTimesFixture
import org.mkuthan.streamprocessing.toll.domain.vehicle.VehiclesWithExpiredRegistrationFixture

trait TollJobFixtures
extends TollBoothEntryFixture
with TollBoothExitFixture
with TollBoothStatsFixture
with TotalVehicleTimesFixture
with VehicleRegistrationFixture
with VehiclesWithExpiredRegistrationFixture {
trait TollStreamingJobFixtures {

final val tollBoothEntryPubsubDeadLetter: PubsubDeadLetter[TollBoothEntry.Payload] =
PubsubDeadLetter("any entry payload".getBytes, Map(), "any entry error")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,30 @@ import org.mkuthan.streamprocessing.shared.common.Diagnostic
import org.mkuthan.streamprocessing.shared.common.Message
import org.mkuthan.streamprocessing.test.scio.syntax._
import org.mkuthan.streamprocessing.test.scio.JobTestScioContext
import org.mkuthan.streamprocessing.toll.application.TollJobFixtures
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothDiagnostic
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothEntry
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothEntryFixture
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothExit
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothExitFixture
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothStats
import org.mkuthan.streamprocessing.toll.domain.booth.TollBoothStatsFixture
import org.mkuthan.streamprocessing.toll.domain.registration.VehicleRegistration
import org.mkuthan.streamprocessing.toll.domain.registration.VehicleRegistrationFixture
import org.mkuthan.streamprocessing.toll.domain.vehicle.TotalVehicleTimes
import org.mkuthan.streamprocessing.toll.domain.vehicle.TotalVehicleTimesFixture
import org.mkuthan.streamprocessing.toll.domain.vehicle.VehiclesWithExpiredRegistration
import org.mkuthan.streamprocessing.toll.domain.vehicle.VehiclesWithExpiredRegistrationFixture

class TollStreamingJobTest extends AnyFlatSpec with Matchers
with JobTestScioContext
with TollJobFixtures
with TollStreamingJobIo {
with TollStreamingJobIo
with TollStreamingJobFixtures
with TollBoothEntryFixture
with TollBoothExitFixture
with TollBoothStatsFixture
with TotalVehicleTimesFixture
with VehicleRegistrationFixture
with VehiclesWithExpiredRegistrationFixture {

"Toll job" should "run in the streaming mode" in {
JobTest[TollStreamingJob.type]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ trait TollBoothEntryFixture {
licensePlate = LicensePlate(anyTollBoothEntryPayload.license_plate)
)
}

object TollBoothEntryFixture extends TollBoothEntryFixture
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ trait TollBoothExitFixture {
licensePlate = LicensePlate(anyTollBoothExitPayload.license_plate)
)
}

object TollBoothExitFixture extends TollBoothExitFixture
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ trait TollBoothStatsFixture {
last_entry_time = anyTollBoothStats.lastEntryTime
)
}

object TollBoothStatsFixture extends TollBoothEntryFixture
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ trait VehicleRegistrationFixture {
expired = defaultExpired == "1"
)
}

object VehicleRegistrationFixture extends VehicleRegistrationFixture
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ trait TotalVehicleTimesFixture {
duration_seconds = anyTotalVehicleTimes.duration.getStandardSeconds
)
}

object TotalVehicleTimesFixture extends TotalVehicleTimesFixture
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ trait VehiclesWithExpiredRegistrationFixture {
Map(VehiclesWithExpiredRegistration.TimestampAttribute -> createdAt.toString)
)
}

object VehiclesWithExpiredRegistrationFixture extends VehiclesWithExpiredRegistrationFixture

0 comments on commit 296621e

Please sign in to comment.