|
| 1 | +package hmda.publication.reports.aggregate |
| 2 | + |
| 3 | +import akka.NotUsed |
| 4 | +import akka.actor.ActorSystem |
| 5 | +import akka.stream.ActorMaterializer |
| 6 | +import akka.stream.scaladsl.Source |
| 7 | +import hmda.model.fi.lar.{ LarGenerators, LoanApplicationRegister } |
| 8 | +import hmda.model.publication.reports.ActionTakenTypeEnum._ |
| 9 | +import hmda.model.publication.reports.ApplicantIncomeEnum.LessThan50PercentOfMSAMedian |
| 10 | +import hmda.model.publication.reports.{ EthnicityBorrowerCharacteristic, MSAReport, MinorityStatusBorrowerCharacteristic, RaceBorrowerCharacteristic } |
| 11 | +import hmda.query.model.filing.LoanApplicationRegisterQuery |
| 12 | +import hmda.query.repository.filing.LarConverter._ |
| 13 | +import org.scalacheck.Gen |
| 14 | +import org.scalatest.{ AsyncWordSpec, BeforeAndAfterAll, MustMatchers } |
| 15 | + |
| 16 | +class A52Spec extends AsyncWordSpec with MustMatchers with LarGenerators with BeforeAndAfterAll { |
| 17 | + |
| 18 | + implicit val system = ActorSystem() |
| 19 | + implicit val ec = system.dispatcher |
| 20 | + implicit val materializer = ActorMaterializer() |
| 21 | + |
| 22 | + override def afterAll(): Unit = { |
| 23 | + super.afterAll() |
| 24 | + system.terminate() |
| 25 | + } |
| 26 | + |
| 27 | + val fips = 18700 //Corvallis, OR |
| 28 | + def propType = Gen.oneOf(1, 2).sample.get |
| 29 | + |
| 30 | + val lars = lar100ListGen.sample.get.map { lar: LoanApplicationRegister => |
| 31 | + val geo = lar.geography.copy(msa = fips.toString) |
| 32 | + val loan = lar.loan.copy(loanType = 1, propertyType = propType, purpose = 1) |
| 33 | + lar.copy(geography = geo, loan = loan) |
| 34 | + } |
| 35 | + |
| 36 | + val source: Source[LoanApplicationRegisterQuery, NotUsed] = Source |
| 37 | + .fromIterator(() => lars.toIterator) |
| 38 | + .map(lar => toLoanApplicationRegisterQuery(lar)) |
| 39 | + |
| 40 | + val expectedDispositions = List(ApplicationReceived, LoansOriginated, ApprovedButNotAccepted, ApplicationsDenied, ApplicationsWithdrawn, ClosedForIncompleteness) |
| 41 | + |
| 42 | + "Generate a Disclosure 5-1 report" in { |
| 43 | + A52.generate(source, fips).map { result => |
| 44 | + |
| 45 | + result.msa mustBe MSAReport("18700", "Corvallis, OR", "OR", "Oregon") |
| 46 | + result.table mustBe "5-2" |
| 47 | + result.applicantIncomes.size mustBe 5 |
| 48 | + |
| 49 | + val lowestIncome = result.applicantIncomes.head |
| 50 | + lowestIncome.applicantIncome mustBe LessThan50PercentOfMSAMedian |
| 51 | + |
| 52 | + val races = lowestIncome.borrowerCharacteristics.head.asInstanceOf[RaceBorrowerCharacteristic].races |
| 53 | + races.size mustBe 8 |
| 54 | + |
| 55 | + val ethnicities = lowestIncome.borrowerCharacteristics(1).asInstanceOf[EthnicityBorrowerCharacteristic].ethnicities |
| 56 | + ethnicities.size mustBe 4 |
| 57 | + |
| 58 | + val minorityStatuses = lowestIncome.borrowerCharacteristics(2).asInstanceOf[MinorityStatusBorrowerCharacteristic].minoritystatus |
| 59 | + minorityStatuses.size mustBe 2 |
| 60 | + |
| 61 | + races.head.dispositions.map(_.disposition) mustBe expectedDispositions |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | +} |
0 commit comments