Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingjian Wu committed Apr 10, 2024
1 parent 1ecb1ce commit 716cae4
Showing 1 changed file with 33 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,62 +226,47 @@ class MetacatSmokeSpec extends Specification {

// assert that the json representation keeps the name fidelity
def expectedJsonString = """
"fields": [
{
"name": "name",
"type": "chararray"
},
{
"name": "address",
"type": {
"type": "row",
"fields": [
{
"name": "NAME",
"type": "chararray"
}
]
}
},
{
"name": "nestedArray",
"type": {
"type": "array",
"elementType": {
{
"type": "row",
"fields": [
{
"name": "name",
"type": "chararray"
},
{
"name": "address",
"type": {
"type": "row",
"fields": [
{
"name": "FIELD1",
"type": "chararray"
},
{
"name": "field2",
"name": "NAME",
"type": "chararray"
}
]
}
},
{
"name": "nestedArray",
"type": {
"type": "array",
"elementType": {
"type": "row",
"fields": [
{
"name": "FIELD1",
"type": "chararray"
},
{
"name": "field2",
"type": "chararray"
}
]
}
}
}
}
]
"""

def parsedExpectedJson = jsonSlurper.parseText(expectedJsonString)
// Compare the JSON array result and the parsed expected JSON
assert nestedFieldDto.jsonType.fields == parsedExpectedJson : "The JSON array result differs from the expected JSON string"

// 1. assert the first level fieldName fidelity
def firstLevelFields = nestedFieldDto.jsonType.fields
def firstLevelFieldNames = firstLevelFields.collect { it.name }
assert ["name", "address", "nestedArray"] == firstLevelFieldNames : "The first level nested fields names differ from the expected. They are: $firstLevelFieldNames"

// 2. assert that the second level fieldName in address Struct keeps its fieldname fidelity
def addressStruct = firstLevelFields[1]
assert addressStruct.type.fields[0].name == "NAME" : "The second level fieldName in address Struct differ from the expected. They are: $addressStruct.type.fields.name"

// 3. assert that the second level fieldName in nestedArray keeps its fieldname fidelity
def nestedArray = firstLevelFields[2]
assert nestedArray.type.elementType.fields[0].name == "FIELD1" : "The second level fieldName in nestedArray differ from the expected. They are: $addressStruct.type.fields.name"

]
}
"""
cleanup:
api.deleteTable(catalogName, databaseName, tableName)
}
Expand Down

0 comments on commit 716cae4

Please sign in to comment.