Skip to content

Commit 6273d8a

Browse files
author
Nick Grippin
committed
tests complete
1 parent c547b14 commit 6273d8a

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package hmda.publication.reports.aggregate
2+
3+
import hmda.publication.reports.protocol.aggregate.A52Protocol._
4+
import org.scalatest.{ MustMatchers, PropSpec }
5+
import org.scalatest.prop.PropertyChecks
6+
import spray.json._
7+
import AggregateReportGenerators._
8+
9+
class A52ProtocolSpec extends PropSpec with PropertyChecks with MustMatchers {
10+
11+
property("A52 Report must convert to and from JSON") {
12+
forAll(a52Gen) { a52 =>
13+
a52.toJson.convertTo[A52] mustBe a52
14+
}
15+
}
16+
17+
property("A52 Report must serialize to the correct JSON format") {
18+
forAll(a52Gen) { a52 =>
19+
a52.toJson mustBe JsObject(
20+
"table" -> JsString("5-2"),
21+
"type" -> JsString("Aggregate"),
22+
"desc" -> JsString("Disposition of Applications for Conventional Home-Purchase Loans, 1-to-4 Family and Manufactured Home Dwellings, by Income, Race, and Ethnicity of Applicant"),
23+
"year" -> JsNumber(a52.year),
24+
"reportDate" -> JsString(a52.reportDate),
25+
"msa" -> a52.msa.toJson,
26+
"applicantIncomes" -> a52.applicantIncomes.toJson,
27+
"total" -> a52.total.toJson
28+
)
29+
}
30+
}
31+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)