Skip to content

Commit

Permalink
Add tests for DynamicObjectSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmior committed Mar 7, 2024
1 parent 56bb6ee commit aa2078e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import org.json4s._
import utils.JsonPointer

object DynamicObjectSchema {
def apply(
value: JsonSchema[_]
)(implicit p: JsonoidParams): DynamicObjectSchema = {
val props = SchemaProperties.empty[Map[String, JsonSchema[_]]]
props.add(DynamicObjectTypeProperty(value))

DynamicObjectSchema(props)(p)
}

val AllProperties: SchemaProperties[Map[String, JsonSchema[_]]] = {
val props = SchemaProperties.empty[Map[String, JsonSchema[_]]]
props.add(DynamicObjectTypeProperty())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.dataunitylab.jsonoid.discovery
package schemas

import org.json4s._

import UnitSpec.pointerFromString

class DynamicObjectSchemaSpec extends UnitSpec {
private val objectSchema = DynamicObjectSchema(BooleanSchema())

behavior of "DynamicObjectSchema"

it should "be able to find subschemas by pointer" in {
objectSchema.findByPointer("/foo").value shouldBe BooleanSchema()
}

it should "not detect anomalies for valid values" in {
objectSchema
.isAnomalous(JObject(List(("foo", JBool(true)))))
.shouldBe(false)
}

it should "detect anomalies for invalid values" in {
objectSchema
.isAnomalous(JObject(List(("foo", JString("bar")))))
.shouldBe(true)
}

it should "not detect anomalies for non-object values" in {
objectSchema.properties.flatMap(
_.collectAnomalies(JString("foo"))
) shouldBe empty
}
}

0 comments on commit aa2078e

Please sign in to comment.