11package dev .mongocamp .driver .mongodb .schema
22
3- import dev .mongocamp .driver .mongodb .test .TestDatabase .{PersonDAO , PersonDocumentDAO }
3+ import dev .mongocamp .driver .mongodb .test .TestDatabase .{ PersonDAO , PersonDocumentDAO }
44import dev .mongocamp .driver .mongodb ._
55import dev .mongocamp .driver .mongodb .relation .RelationDemoDatabase ._
6- import org .specs2 .mutable .{Before , Specification }
6+ import org .specs2 .mutable .{ Before , Specification }
77
88import scala .util .Try
99
@@ -14,25 +14,25 @@ class SchemaSpec extends Specification with Before {
1414 " Schema" should {
1515 " analyse Json Schema from document dao" in {
1616 // #region schema-analysis
17- val schemaExplorer = new SchemaExplorer ()
17+ val schemaExplorer = new SchemaExplorer ()
1818 val schemaAnalysis = schemaExplorer.analyzeSchema(PersonDocumentDAO )
1919 // #endregion schema-analysis
20- schemaJson.contains( " \" $schema \" : \" https://json-schema.org/draft/2020-12/schema \" " ) must beTrue
21- schemaJson.contains( " \" Friends \" : " ) must beTrue
22- schemaJson.contains( " \" title \" : \" Friends \" " ) must beTrue
23- schemaJson.contains( " \" People \" : " ) must beTrue
24- schemaJson.contains( " \" title \" : \" People \" " ) must beTrue
25- val idPattern1 = schemaJson.contains( " \" _id\" :{ \" pattern \" : \" ^([a-fA-F0-9]{2})+$ \" , \" type \" : \" string \" } " )
26- val idPattern2 = schemaJson.contains( " \" _id \" :{ \" type \" : \" string \" , \" pattern \" : \" ^([a-fA-F0-9]{2})+$ \" } " )
27- (idPattern1 || idPattern2) must beTrue
28- schemaJson.contains( " \" isActive \" :{ \" type \" : \" boolean \" } " ) must beTrue
20+ schemaAnalysis.count must beEqualTo( 200 )
21+ schemaAnalysis.sample must beEqualTo( 200 )
22+ schemaAnalysis.percentageOfAnalysed must beEqualTo( 1.0 )
23+ schemaAnalysis.fields.size must beEqualTo( 20 )
24+ val idField = schemaAnalysis.fields.head
25+ idField.name must beEqualTo( " _id" )
26+ idField.fieldTypes.head.fieldType must beEqualTo( " objectId " )
27+ idField.fieldTypes.head.count must beEqualTo( 200 )
28+ idField.fieldTypes.head.percentageOfParent must beEqualTo( 1.0 )
2929 }
3030
3131 " detect Json Schema from document dao" in {
3232 // #region schema-explorer
33- val schemaExplorer = new SchemaExplorer ()
34- val schema = schemaExplorer.detectSchema(PersonDocumentDAO )
35- val schemaJson = schema.toJson
33+ val schemaExplorer = new SchemaExplorer ()
34+ val schema = schemaExplorer.detectSchema(PersonDocumentDAO )
35+ val schemaJson = schema.toJson
3636 // #endregion schema-explorer
3737 schemaJson.contains(" \" $schema\" :\" https://json-schema.org/draft/2020-12/schema\" " ) must beTrue
3838 schemaJson.contains(" \" Friends\" :" ) must beTrue
0 commit comments