{
  "testcases": [ {
    "name": "Update Article - Data Driven",
    "teststeps": [ {
      "name": "Set up database data",
      "type": "DB",
      "endpoint": {
        "type": "DB",
        "url": "jdbc:h2:${atb.data.dir}/database/sample;AUTO_SERVER=TRUE",
        "username": "user"
      },
      "apiRequest": {
        "@type": "DbRequest",
        "sqlScript": "-- Clear the table\ndelete from article;\n\n-- Create two article records\ninsert into article (id, title, content) values (1, 'article1', 'content1');\ninsert into article (id, title, content) values (2, 'article2', 'content2');"
      }
    }, {
      "name": "Invoke the API to update article",
      "type": "HTTP",
      "endpoint": {
        "type": "HTTP",
        "url": "http://localhost:8090/api/articles/2"
      },
      "apiRequest": {
        "@type": "HttpRequest",
        "method": "PUT",
        "headers": [ {
          "name": "Content-Type",
          "value": "application/json"
        } ],
        "body": "{\n  \"id\": 2,\n  \"title\": \"${input.article.title}\",\n  \"content\": \"Once upon a time ...\"\n}"
      },
      "assertions": [ {
        "name": "StatusCodeEqual",
        "type": "StatusCodeEqual",
        "otherProperties": {
          "statusCode": "${expected.api.response.status.code}"
        }
      }, {
        "name": "JSONEqual",
        "type": "JsonEqual",
        "otherProperties": {
          "expectedJSON": "${expected.api.response.json}"
        }
      } ]
    }, {
      "name": "Check database data",
      "type": "DB",
      "endpoint": {
        "type": "DB",
        "url": "jdbc:h2:${atb.data.dir}/database/sample;AUTO_SERVER=TRUE",
        "username": "user"
      },
      "apiRequest": {
        "@type": "DbRequest",
        "sqlScript": "select id, title, content from article;"
      },
      "assertions": [ {
        "name": "JSONEqual",
        "type": "JsonEqual",
        "otherProperties": {
          "expectedJSON": "${expected.result.database.data}"
        }
      } ]
    } ],
    "dataTable": {
      "columns": [ {
        "name": "Caption"
      }, {
        "name": "input.article.title"
      }, {
        "name": "expected.api.response.status.code"
      }, {
        "name": "expected.api.response.json"
      }, {
        "name": "expected.result.database.data"
      } ],
      "rows": [ {
        "Caption": {
          "value": "Positive"
        },
        "input.article.title": {
          "value": "article2"
        },
        "expected.api.response.status.code": {
          "value": "200"
        },
        "expected.api.response.json": {
          "value": "{\n  \"id\": 2,\n  \"title\": \"article2\",\n  \"content\": \"Once upon a time ...\"\n}"
        },
        "expected.result.database.data": {
          "value": "[\n    {\n        \"ID\": 1,\n        \"TITLE\": \"article1\",\n        \"CONTENT\": \"content1\"\n    },\n    {\n        \"ID\": 2,\n        \"TITLE\": \"article2\",\n        \"CONTENT\": \"Once upon a time ...\"\n    }\n]"
        }
      }, {
        "Caption": {
          "value": "Negative - article title too long"
        },
        "input.article.title": {
          "value": "looooooooooooooo ooooooooooooo oooooooooooong title"
        },
        "expected.api.response.status.code": {
          "value": "500"
        },
        "expected.api.response.json": {
          "value": "{\n  \"code\": 500,\n  \"message\": \"#{json-unit.ignore}\",\n  \"details\": \"#{json-unit.regex}.*Value too long for column \\\"TITLE[\\\\s\\\\S]*\"\n}"
        },
        "expected.result.database.data": {
          "value": "[\n    {\n        \"ID\": 1,\n        \"TITLE\": \"article1\",\n        \"CONTENT\": \"content1\"\n    },\n    {\n        \"ID\": 2,\n        \"TITLE\": \"article2\",\n        \"CONTENT\": \"content2\"\n    }\n]"
        }
      } ]
    }
  } ]
}