aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorKseniya Tomskikh <ktomskih@datamonsters.co>2017-08-10 19:25:00 +0600
committerKseniya Tomskikh <ktomskih@datamonsters.co>2017-08-11 14:41:30 +0600
commit9e60edb6216fce615b13f9bcc68d8f86258b85c3 (patch)
tree04ca0ec035cabd617bc215f470166d507cdc4f27 /src/test
parentef9517e1b8f599fbdd15c474cf7dfea61e803c2f (diff)
downloadrest-query-9e60edb6216fce615b13f9bcc68d8f86258b85c3.tar.gz
rest-query-9e60edb6216fce615b13f9bcc68d8f86258b85c3.tar.bz2
rest-query-9e60edb6216fce615b13f9bcc68d8f86258b85c3.zip
PDSUI-2188 Created and fixed test for json formats of TriC
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ArmFormatTestSuite.scala36
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatTestSuite.scala68
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatTestSuite.scala63
-rw-r--r--src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialFormatTestSuite.scala50
4 files changed, 217 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ArmFormatTestSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ArmFormatTestSuite.scala
new file mode 100644
index 0000000..4a4b3c4
--- /dev/null
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/ArmFormatTestSuite.scala
@@ -0,0 +1,36 @@
+package xyz.driver.pdsuidomain.formats.json.sprayformats
+
+import spray.json._
+import org.scalatest.{FlatSpec, Matchers}
+import xyz.driver.pdsuicommon.domain.{LongId, StringId}
+import xyz.driver.pdsuidomain.entities.Arm
+
+class ArmFormatTestSuite extends FlatSpec with Matchers {
+ import arm._
+
+ "Json format for Arm" should "read and write correct JSON" in {
+ val arm = Arm(
+ id = LongId(10),
+ trialId = StringId("NCT000001"),
+ name = "arm name",
+ originalName = "orig arm name"
+ )
+ val writtenJson = armFormat.write(arm)
+
+ writtenJson should be("""{"id":10,"trialId":"NCT000001","name":"arm name","originalName":"orig arm name"}""".parseJson)
+
+ val createArmJson = """{"trialId":"NCT000001","name":"arm name"}""".parseJson
+ val parsedArm = armFormat.read(createArmJson)
+ val expectedCreatedArm = arm.copy(
+ id = LongId(0),
+ originalName = "arm name"
+ )
+ parsedArm should be(expectedCreatedArm)
+
+ val updateArmJson = """{"name":"new arm name"}""".parseJson
+ val expectedUpdatedArm = arm.copy(name = "new arm name")
+ val parsedUpdateArm = applyUpdateToArm(updateArmJson, arm)
+ parsedUpdateArm should be(expectedUpdatedArm)
+ }
+
+}
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatTestSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatTestSuite.scala
new file mode 100644
index 0000000..0167620
--- /dev/null
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/CriterionFormatTestSuite.scala
@@ -0,0 +1,68 @@
+package xyz.driver.pdsuidomain.formats.json.sprayformats
+
+import spray.json._
+import org.scalatest.{FlatSpec, Matchers}
+import xyz.driver.pdsuicommon.domain.{LongId, StringId}
+import xyz.driver.pdsuidomain.entities.{Arm, Criterion, CriterionLabel}
+import xyz.driver.pdsuidomain.services.CriterionService.RichCriterion
+
+class CriterionFormatTestSuite extends FlatSpec with Matchers {
+ import criterion._
+
+ "Json format for Criterion" should "read and write correct JSON" in {
+ val criterion = Criterion(
+ id = LongId(10),
+ trialId = StringId("NCT000001"),
+ text = Some("text"),
+ isCompound = false,
+ meta = "{}"
+ )
+ val labels = List(
+ CriterionLabel(
+ id = LongId(1L),
+ labelId = Some(LongId(101)),
+ criterionId = criterion.id,
+ categoryId = Some(LongId(3)),
+ value = Some(true),
+ isDefining = true
+ ),
+ CriterionLabel(
+ id = LongId(2L),
+ labelId = Some(LongId(102)),
+ criterionId = criterion.id,
+ categoryId = Some(LongId(3)),
+ value = Some(false),
+ isDefining = true
+ )
+ )
+ val arms = List(LongId[Arm](20), LongId[Arm](21), LongId[Arm](21))
+ val richCriterion = RichCriterion(
+ criterion = criterion,
+ armIds = arms,
+ labels = labels
+ )
+ val writtenJson = richCriterionFormat.write(richCriterion)
+
+ writtenJson should be(
+ """{"text":"text","isCompound":false,"trialId":"NCT000001","arms":[20,21,21],"id":10,"meta":"{}",
+ "labels":[{"labelId":101,"categoryId":3,"value":"Yes","isDefining":true},
+ {"labelId":102,"categoryId":3,"value":"No","isDefining":true}]}""".parseJson)
+
+ val createCriterionJson =
+ """{"text":"text","isCompound":false,"trialId":"NCT000001",
+ "arms":[20,21,21],"meta":"{}","labels":[{"labelId":101,"categoryId":3,"value":"Yes","isDefining":true},
+ {"labelId":102,"categoryId":3,"value":"No","isDefining":true}]}""".parseJson
+ val parsedRichCriterion = richCriterionFormat.read(createCriterionJson)
+ val expectedRichCriterion = richCriterion.copy(
+ criterion = criterion.copy(id = LongId(0)),
+ labels = labels.map(_.copy(id = LongId(0), criterionId = LongId(0)))
+ )
+ parsedRichCriterion should be(expectedRichCriterion)
+
+ val updateCriterionJson = """{"meta":null,"text":"new text","isCompound":true}""".parseJson
+ val expectedUpdatedCriterion = richCriterion.copy(criterion = criterion.copy(text = Some("new text"), isCompound = true, meta = "{}"))
+ val parsedUpdateCriterion = applyUpdateToCriterion(updateCriterionJson, richCriterion)
+ parsedUpdateCriterion should be(expectedUpdatedCriterion)
+ }
+
+}
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatTestSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatTestSuite.scala
new file mode 100644
index 0000000..280b2a7
--- /dev/null
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/InterventionFormatTestSuite.scala
@@ -0,0 +1,63 @@
+package xyz.driver.pdsuidomain.formats.json.sprayformats
+
+import spray.json._
+import org.scalatest.{FlatSpec, Matchers}
+import xyz.driver.pdsuicommon.domain.{LongId, StringId}
+import xyz.driver.pdsuidomain.entities.{Intervention, InterventionArm, InterventionType, InterventionWithArms}
+
+class InterventionFormatTestSuite extends FlatSpec with Matchers {
+ import intervention._
+
+ "Json format for Intervention" should "read and write correct JSON" in {
+ val intervention = Intervention(
+ id = LongId(1),
+ trialId = StringId("NCT000001"),
+ name = "intervention name",
+ originalName = "orig name",
+ typeId = Some(LongId(10)),
+ originalType = Some("orig type"),
+ description = "",
+ originalDescription = "",
+ isActive = true
+ )
+ val arms = List(
+ InterventionArm(interventionId = intervention.id, armId = LongId(20)),
+ InterventionArm(interventionId = intervention.id, armId = LongId(21)),
+ InterventionArm(interventionId = intervention.id, armId = LongId(22))
+ )
+ val orig = InterventionWithArms(
+ intervention = intervention,
+ arms = arms
+ )
+ val writtenJson = interventionWriter.write(orig)
+
+ writtenJson should be(
+ """{"id":1,"name":"intervention name","typeId":10,"description":"","isActive":true,"arms":[20,21,22],
+ "trialId":"NCT000001","originalName":"orig name","originalDescription":"","originalType":"orig type"}""".parseJson)
+
+ val updateInterventionJson = """{"description":"descr","arms":[21,22]}""".parseJson
+ val expectedUpdatedIntervention = orig.copy(
+ intervention = intervention.copy(description = "descr"),
+ arms = List(
+ InterventionArm(interventionId = intervention.id, armId = LongId(21)),
+ InterventionArm(interventionId = intervention.id, armId = LongId(22))
+ )
+ )
+ val parsedUpdateIntervention = applyUpdateToInterventionWithArms(updateInterventionJson, orig)
+ parsedUpdateIntervention should be(expectedUpdatedIntervention)
+ }
+
+ "Json format for InterventionType" should "read and write correct JSON" in {
+ val interventionType = InterventionType(
+ id = LongId(10),
+ name = "type name"
+ )
+ val writtenJson = interventionTypeFormat.write(interventionType)
+
+ writtenJson should be("""{"id":10,"name":"type name"}""".parseJson)
+
+ val parsedInterventionType = interventionTypeFormat.read(writtenJson)
+ parsedInterventionType should be(interventionType)
+ }
+
+}
diff --git a/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialFormatTestSuite.scala b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialFormatTestSuite.scala
new file mode 100644
index 0000000..397d2aa
--- /dev/null
+++ b/src/test/scala/xyz/driver/pdsuidomain/formats/json/sprayformats/TrialFormatTestSuite.scala
@@ -0,0 +1,50 @@
+package xyz.driver.pdsuidomain.formats.json.sprayformats
+
+import java.time.LocalDateTime
+
+import spray.json._
+import org.scalatest.{FlatSpec, Matchers}
+import xyz.driver.pdsuicommon.domain.{LongId, StringId, UuidId}
+import xyz.driver.pdsuidomain.entities.Trial
+
+class TrialFormatTestSuite extends FlatSpec with Matchers {
+ import trial._
+
+ "Json format for Trial" should "read and write correct JSON" in {
+ val orig = Trial(
+ id = StringId("NCT000001"),
+ externalId = UuidId("40892a07-c638-49d2-9795-1edfefbbcc7c"),
+ status = Trial.Status.New,
+ assignee = None,
+ previousStatus = None,
+ previousAssignee = None,
+ lastActiveUserId = None,
+ lastUpdate = LocalDateTime.parse("2017-08-10T18:16:19"),
+ condition = Trial.Condition.Breast,
+ phase = "",
+ hypothesisId = Some(UuidId("3b80b2e2-5372-4cf5-a342-6e4ebe10fafd")),
+ studyDesignId = Some(LongId(321)),
+ originalStudyDesign = None,
+ isPartner = false,
+ overview = None,
+ overviewTemplate = "",
+ isUpdated = false,
+ title = "trial title",
+ originalTitle = "orig trial title"
+ )
+ val writtenJson = trialWriter.write(orig)
+
+ writtenJson should be (
+ """{"isPartner":false,"assignee":null,"lastUpdate":"2017-08-10T18:16:19Z","previousStatus":null,
+ "isUpdated":false,"overviewTemplate":"","phase":"","originalStudyDesignId":null,
+ "hypothesisId":"3b80b2e2-5372-4cf5-a342-6e4ebe10fafd","originalTitle":"orig trial title",
+ "studyDesignId":321,"lastActiveUser":null,"externalid":"40892a07-c638-49d2-9795-1edfefbbcc7c",
+ "id":"NCT000001","condition":"Breast","status":"New","overview":null,"previousAssignee":null,"title":"trial title"}""".parseJson)
+
+ val updateTrialJson = """{"hypothesisId":null,"overview":"new overview"}""".parseJson
+ val expectedUpdatedTrial = orig.copy(hypothesisId = None, overview = Some("new overview"))
+ val parsedUpdateTrial = applyUpdateToTrial(updateTrialJson, orig)
+ parsedUpdateTrial should be(expectedUpdatedTrial)
+
+ }
+}