Skip to content

Commit

Permalink
#1693 Incorrectly merged SchemaControllerV3IntegrationSuite fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1844 committed May 27, 2022
1 parent cab3ae0 commit b3ffe43
Showing 1 changed file with 0 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1076,295 +1076,4 @@ class SchemaControllerV3IntegrationSuite extends BaseRestApiTestV3 with BeforeAn
}
}
}

s"GET $apiUrl/{name}/used-in" should {
"return 200" when {
"there are used-in records" in {
val schema1 = SchemaFactory.getDummySchema(name = "schema", version = 1)
val schema2 = SchemaFactory.getDummySchema(name = "schema", version = 2)
schemaFixture.add(schema1, schema2)

val datasetA = DatasetFactory.getDummyDataset(name = "datasetA", schemaName = "schema", schemaVersion = 1)
val datasetB = DatasetFactory.getDummyDataset(name = "datasetB", schemaName = "schema", schemaVersion = 1, disabled = true)
datasetFixture.add(datasetA, datasetB)

val mappingTableA = MappingTableFactory.getDummyMappingTable(name = "mappingA", schemaName = "schema", schemaVersion = 1)
val mappingTableB = MappingTableFactory.getDummyMappingTable(name = "mappingB", schemaName = "schema", schemaVersion = 1, disabled = true)
val mappingTableC = MappingTableFactory.getDummyMappingTable(name = "mappingC", schemaName = "schema", schemaVersion = 2)
mappingTableFixture.add(mappingTableA, mappingTableB, mappingTableC)


val response = sendGet[UsedIn](s"$apiUrl/schema/used-in")
assertOk(response)

// datasetB and mappingB are disabled -> not reported
// mappingC is reported, even though it schema is tied to schema-v2, because disabling is done on the whole entity in API v3
response.getBody shouldBe UsedIn(
datasets = Some(Seq(MenasReference(None, "datasetA", 1))),
mappingTables = Some(Seq(MenasReference(None, "mappingA", 1), MenasReference(None, "mappingC", 1)))
)
}
}
}

s"GET $apiUrl/{name}/{version}/used-in" should {
"return 200" when {
"there are used-in records for particular version" in {
val schema1 = SchemaFactory.getDummySchema(name = "schema", version = 1)
val schema2 = SchemaFactory.getDummySchema(name = "schema", version = 2)
schemaFixture.add(schema1, schema2)

val datasetA = DatasetFactory.getDummyDataset(name = "datasetA", schemaName = "schema", schemaVersion = 1)
val datasetB = DatasetFactory.getDummyDataset(name = "datasetB", schemaName = "schema", schemaVersion = 1, disabled = true)
datasetFixture.add(datasetA, datasetB)

val mappingTableA = MappingTableFactory.getDummyMappingTable(name = "mappingA", schemaName = "schema", schemaVersion = 1)
val mappingTableB = MappingTableFactory.getDummyMappingTable(name = "mappingB", schemaName = "schema", schemaVersion = 1, disabled = true)
val mappingTableC = MappingTableFactory.getDummyMappingTable(name = "mappingC", schemaName = "schema", schemaVersion = 2)
mappingTableFixture.add(mappingTableA, mappingTableB, mappingTableC)


val response = sendGet[UsedIn](s"$apiUrl/schema/1/used-in")
assertOk(response)

// datasetB and mappingB are disabled -> not reported
// mappingC is tied to schema v2 -> not reported
response.getBody shouldBe UsedIn(
datasets = Some(Seq(MenasReference(None, "datasetA", 1))),
mappingTables = Some(Seq(MenasReference(None, "mappingA", 1)))
)
}
}
}

s"PUT $apiUrl/{name}" can {
"return 200" when {
"a Schema with the given name exists" should {
"enable the Schema with the given name" in {
val schA1 = SchemaFactory.getDummySchema(name = "schA", version = 1, disabled = true)
val schA2 = SchemaFactory.getDummySchema(name = "schA", version = 2, disabled = true)
val schB = SchemaFactory.getDummySchema(name = "schB", version = 1, disabled = true)
schemaFixture.add(schA1, schA2, schB)

val response = sendPut[String, DisabledPayload](s"$apiUrl/schA")
assertOk(response)
response.getBody shouldBe DisabledPayload(disabled = false)

// all versions now enabled
val responseA1 = sendGet[Schema](s"$apiUrl/schA/1")
assertOk(responseA1)
responseA1.getBody.disabled shouldBe false

val responseA2 = sendGet[Schema](s"$apiUrl/schA/2")
assertOk(responseA2)
responseA2.getBody.disabled shouldBe false

// unrelated schema unaffected
val responseB = sendGet[Schema](s"$apiUrl/schB/1")
assertOk(responseB)
responseB.getBody.disabled shouldBe true
}
}

"a Schema with the given name exists and there have mixed disabled states (historical)" should {
"enable all versions the schema with the given name" in {
val schA1 = SchemaFactory.getDummySchema(name = "schA", version = 1, disabled = true)
val schA2 = SchemaFactory.getDummySchema(name = "schA", version = 2, disabled = false)
schemaFixture.add(schA1, schA2)

val response = sendPut[String, DisabledPayload](s"$apiUrl/schA")
assertOk(response)
response.getBody shouldBe DisabledPayload(disabled = false)

// all versions enabled
val responseA1 = sendGet[Schema](s"$apiUrl/schA/1")
assertOk(responseA1)
responseA1.getBody.disabled shouldBe false

val responseA2 = sendGet[Schema](s"$apiUrl/schA/2")
assertOk(responseA2)
responseA2.getBody.disabled shouldBe false
}
}
}

"return 404" when {
"no Schema with the given name exists" should {
"enable nothing" in {
val response = sendPut[String, DisabledPayload](s"$apiUrl/aSchema")
assertNotFound(response)
}
}
}

}

s"DELETE $apiUrl/{name}" can {
"return 200" when {
"a Schema with the given name exists" should {
"disable the schema with the given name" in {
val schA1 = SchemaFactory.getDummySchema(name = "schA", version = 1)
val schA2 = SchemaFactory.getDummySchema(name = "schA", version = 2)
val schB = SchemaFactory.getDummySchema(name = "schB", version = 1)
schemaFixture.add(schA1, schA2, schB)

val response = sendDelete[DisabledPayload](s"$apiUrl/schA")
assertOk(response)
response.getBody shouldBe DisabledPayload(disabled = true)

// all versions disabled
val responseA1 = sendGet[Schema](s"$apiUrl/schA/1")
assertOk(responseA1)
responseA1.getBody.disabled shouldBe true

val responseA2 = sendGet[Schema](s"$apiUrl/schA/2")
assertOk(responseA2)
responseA2.getBody.disabled shouldBe true

// unrelated schema unaffected
val responseB = sendGet[Schema](s"$apiUrl/schB/1")
assertOk(responseB)
responseB.getBody.disabled shouldBe false
}
}

"a Schema with the given name exists and there have mixed (historical) disabled states " should {
"disable all versions the schema with the given name" in {
val schA1 = SchemaFactory.getDummySchema(name = "schA", version = 1, disabled = true)
val schA2 = SchemaFactory.getDummySchema(name = "schA", version = 2, disabled = false)
schemaFixture.add(schA1, schA2)

val response = sendDelete[DisabledPayload](s"$apiUrl/schA")
assertOk(response)
response.getBody shouldBe DisabledPayload(disabled = true)

// all versions disabled
val responseA1 = sendGet[Schema](s"$apiUrl/schA/1")
assertOk(responseA1)
responseA1.getBody.disabled shouldBe true

val responseA2 = sendGet[Schema](s"$apiUrl/schA/2")
assertOk(responseA2)
responseA2.getBody.disabled shouldBe true
}
}
"the Schema is only used in disabled Datasets" should {
"disable the Schema" in {
val dataset = DatasetFactory.getDummyDataset(schemaName = "schema", schemaVersion = 1, disabled = true)
datasetFixture.add(dataset)
val schema1 = SchemaFactory.getDummySchema(name = "schema", version = 1)
val schema2 = SchemaFactory.getDummySchema(name = "schema", version = 2)
schemaFixture.add(schema1, schema2)

val response = sendDelete[DisabledPayload](s"$apiUrl/schema")

assertOk(response)
response.getBody shouldBe DisabledPayload(disabled = true)

// all versions disabled
val responseA1 = sendGet[Schema](s"$apiUrl/schema/1")
assertOk(responseA1)
responseA1.getBody.disabled shouldBe true

val responseA2 = sendGet[Schema](s"$apiUrl/schema/2")
assertOk(responseA2)
responseA2.getBody.disabled shouldBe true
}
}
"the Schema is only used in disabled MappingTables" should {
"disable the Schema" in {
val mappingTable = MappingTableFactory.getDummyMappingTable(schemaName = "schema", schemaVersion = 1, disabled = true)
mappingTableFixture.add(mappingTable)
val schema1 = SchemaFactory.getDummySchema(name = "schema", version = 1)
val schema2 = SchemaFactory.getDummySchema(name = "schema", version = 2)
schemaFixture.add(schema1, schema2)

val response = sendDelete[DisabledPayload](s"$apiUrl/schema")

assertOk(response)
response.getBody shouldBe DisabledPayload(disabled = true)

// all versions disabled
val responseA1 = sendGet[Schema](s"$apiUrl/schema/1")
assertOk(responseA1)
responseA1.getBody.disabled shouldBe true

val responseA2 = sendGet[Schema](s"$apiUrl/schema/2")
assertOk(responseA2)
responseA2.getBody.disabled shouldBe true
}
}
}

"return 400" when {
"the Schema is used by an enabled Dataset" should {
"return a list of the entities the Schema is used in" in {
val schema1 = SchemaFactory.getDummySchema(name = "schema", version = 1)
val schema2 = SchemaFactory.getDummySchema(name = "schema", version = 2)
schemaFixture.add(schema1, schema2)

val dataset1 = DatasetFactory.getDummyDataset(name = "dataset1", schemaName = "schema", schemaVersion = 1)
val dataset2 = DatasetFactory.getDummyDataset(name = "dataset2", version = 7, schemaName = "schema", schemaVersion = 2)
val dataset3 = DatasetFactory.getDummyDataset(name = "dataset3", schemaName = "anotherSchema", schemaVersion = 8) // moot
val disabledDs = DatasetFactory.getDummyDataset(name = "disabledDs", schemaName = "schema", schemaVersion = 2, disabled = true)
datasetFixture.add(dataset1, dataset2, dataset3, disabledDs)

val response = sendDelete[EntityInUseException](s"$apiUrl/schema")

assertBadRequest(response)
response.getBody shouldBe EntityInUseException("""Cannot disable entity "schema", because it is used in the following entities""",
UsedIn(Some(Seq(MenasReference(None, "dataset1", 1), MenasReference(None, "dataset2", 7))), None)
)
}
}
"the Schema is used by a enabled MappingTable" should {
"return a list of the entities the Schema is used in" in {
val schema1 = SchemaFactory.getDummySchema(name = "schema", version = 1)
val schema2 = SchemaFactory.getDummySchema(name = "schema", version = 2)
schemaFixture.add(schema1, schema2)

val mappingTable1 = MappingTableFactory.getDummyMappingTable(name = "mapping1", schemaName = "schema", schemaVersion = 1, disabled = false)
val mappingTable2 = MappingTableFactory.getDummyMappingTable(name = "mapping2", schemaName = "schema", schemaVersion = 2, disabled = false)
mappingTableFixture.add(mappingTable1, mappingTable2)

val response = sendDelete[EntityInUseException](s"$apiUrl/schema")
assertBadRequest(response)

response.getBody shouldBe EntityInUseException("""Cannot disable entity "schema", because it is used in the following entities""",
UsedIn(None, Some(Seq(MenasReference(None, "mapping1", 1), MenasReference(None, "mapping2", 1))))
)
}
}
"the Schema is used by combination of MT and DS" should {
"return a list of the entities the Schema is used in" in {
val schema1 = SchemaFactory.getDummySchema(name = "schema", version = 1)
val schema2 = SchemaFactory.getDummySchema(name = "schema", version = 2)
schemaFixture.add(schema1, schema2)

val mappingTable1 = MappingTableFactory.getDummyMappingTable(name = "mapping1", schemaName = "schema", schemaVersion = 1, disabled = false)
mappingTableFixture.add(mappingTable1)

val dataset2 = DatasetFactory.getDummyDataset(name = "dataset2", schemaName = "schema", schemaVersion = 2)
datasetFixture.add(dataset2)

val response = sendDelete[EntityInUseException](s"$apiUrl/schema")
assertBadRequest(response)

response.getBody shouldBe EntityInUseException("""Cannot disable entity "schema", because it is used in the following entities""",
UsedIn(Some(Seq(MenasReference(None, "dataset2", 1))), Some(Seq(MenasReference(None, "mapping1", 1))))
)
}
}
}

"return 404" when {
"no Schema with the given name exists" should {
"disable nothing" in {
val response = sendDelete[String](s"$apiUrl/aSchema")
assertNotFound(response)
}
}
}
}

}

0 comments on commit b3ffe43

Please sign in to comment.