Skip to content

thingsBoard设备管理接口文档

环境说明


题目说明

  • 测试方法:请使用所学的测试用例设计方法例如等价类、边界值等方法完成 web 自动化和接口自动化测试
  • 场景说明见下方业务流程
  • 断言方式:根据不同业务,断言返回结果是否正确

自动化场景

  • 功能模块:设备
  • 测试点:对设备的增、删、改、查

业务流程-添加设备

uml diagram


业务流程-查询设备

uml diagram


业务流程-修改设备

uml diagram


业务流程-删除设备

uml diagram


场景

  • 登录
  • 新增设备
  • 查询设备
  • 修改设备
  • 删除设备

登录-获取token

  • 请求url:https://thingsboard.stu.hogwarts.ceshiren.com/api/auth/login

  • 请求方式:post

  • 请求参数:{"username": username,"password": password}

  • 接口返回:

{
  'token': 'eyJhbGciOiJIUzUxMiJ9',  # 使用此token进行登录
  'refreshToken': 'r6U6RfH3Hc_Tj8QGEx7xVr4Nmckg',
  'scope': None
}

业务流程-创建设备

uml diagram


创建设备-请求示例

  • 请求url:https://thingsboard.stu.hogwarts.ceshiren.com/api/device

  • 请求方式为:post

  • 请求头:{"X-Authorization": Bearer token}

  • 示例:登录接口返回token为:xxxxxx,则请求头为:{"X-Authorization": Bearer xxxxxx}


{
  "name": "hogwarts",  // 名称
  "label": "hogwarts_tag",  // 标签
  "deviceProfileId": {
    "entityType": "DEVICE_PROFILE",   // 默认值
    "id": "eec576e0-eca9-11ed-b839-b910c19eb442"  // 默认值
  },
  "additionalInfo": {
    "gateway": "false",  // 默认值
    "overwriteActivityTime": "false",  // 默认值
    "description": "霍格沃兹测试开发学社"  // 说明
  },
}            

创建设备-响应结果

{
  'id': {
    'entityType': 'DEVICE',
    'id': '177cfd40-f62a-11ed-afdc-53eb80421d86'
  },
  'createdTime': 1684484670888,
  'additionalInfo': {
    'gateway': 'false',
    'overwriteActivityTime': 'false',
    'description': '测试选项'
  },
  'tenantId': {
    'entityType': 'TENANT',
    'id': '0ebd8110-e578-11ed-854b-71497f176d4c'
  },
  'customerId': {
    'entityType': 'CUSTOMER',
    'id': '13814000-1dd2-11b2-8080-808080808080'
  },
  'name': 'hogwarts_test',
  'type': '孤孤咕咕咕',
  'label': 'hogwarts_tag',
  'deviceProfileId': {
    'entityType': 'DEVICE_PROFILE',
    'id': 'eec576e0-eca9-11ed-b839-b910c19eb442'
  },
  'deviceData': {
    'configuration': {
      'type': 'DEFAULT'
    },
    'transportConfiguration': {
      'type': 'DEFAULT'
    }
  },
  'firmwareId': None,
  'softwareId': None,
  'externalId': None
}

注意 'id': '177cfd40-f62a-11ed-afdc-53eb80421d86' 为创建设备返回的id,具体id根据自己调用创建接口返回的id为准


业务流程-查询设备

uml diagram


查询设备-请求示例

  • 请求url:https://thingsboard.stu.hogwarts.ceshiren.com/api/tenant/devices
  • 请求方式为:get
  • 请求参数:deviceName为创建设备的名字
  • 示例:设备名称为hogwarts,则请求的url为:https://thingsboard.stu.hogwarts.ceshiren.com/api/tenant/devices?deviceName=hogwarts

  • 请求头:{"X-Authorization": Bearer token}

  • 示例:登录接口返回token为:xxxxxx,则请求头为:{"X-Authorization": Bearer xxxxxx}


查询设备-响应结果

{
  'id': {
    'entityType': 'DEVICE',
    'id': '177cfd40-f62a-11ed-afdc-53eb80421d86'
  },
  'createdTime': 1684484670888,
  'additionalInfo': {
    'gateway': 'false',
    'overwriteActivityTime': 'false',
    'description': '第四届火焰杯决赛测试选项'
  },
  'tenantId': {
    'entityType': 'TENANT',
    'id': '0ebd8110-e578-11ed-854b-71497f176d4c'
  },
  'customerId': {
    'entityType': 'CUSTOMER',
    'id': '13814000-1dd2-11b2-8080-808080808080'
  },
  'name': 'hogwarts_test',
  'type': '孤孤咕咕咕',
  'label': 'hogwarts_tag',
  'deviceProfileId': {
    'entityType': 'DEVICE_PROFILE',
    'id': 'eec576e0-eca9-11ed-b839-b910c19eb442'
  },
  'deviceData': {
    'configuration': {
      'type': 'DEFAULT'
    },
    'transportConfiguration': {
      'type': 'DEFAULT'
    }
  },
  'firmwareId': None,
  'softwareId': None,
  'externalId': None
}

业务流程-修改设备

uml diagram


修改设备-请求示例

  • 请求url:https://thingsboard.stu.hogwarts.ceshiren.com/api/device

  • 请求方式为:post

  • 请求头:{"X-Authorization": Bearer token}

  • 示例:登录接口返回token为:xxxxxx,则请求头为:{"X-Authorization": Bearer xxxxxx}

  • 请求参数:

{
  'id': {
    'entityType': 'DEVICE',
    'id': '177cfd40-f62a-11ed-afdc-53eb80421d86'  // 要修改的设备id,即创建接口返回的设备id
  },
  "name": "hogwarts2",  // 要修改的设备名称
  "label": "hogwarts_tag2", // 要修改的设备标签
  "deviceProfileId": {
    "entityType": "DEVICE_PROFILE", // 默认
    "id": "eec576e0-eca9-11ed-b839-b910c19eb442" // 默认
  },
  "additionalInfo": {
    "gateway": "false", // 默认
    "overwriteActivityTime": "false", // 默认
    "description": "hogwarts" // 要修改的描述
  },

}

修改设备-响应结果

{
  'id': {
    'entityType': 'DEVICE',
    'id': '5b4b83f0-f622-11ed-afdd-53eb80421d86'
  },
  'createdTime': 0,
  'additionalInfo': {
    'gateway': 'false',
    'overwriteActivityTime': 'false',
    'description': '第四届火焰杯决赛2'
  },
  'tenantId': {
    'entityType': 'TENANT',
    'id': '0ebd8110-e578-11ed-854b-71497f176d4c'
  },
  'customerId': {
    'entityType': 'CUSTOMER',
    'id': '13814000-1dd2-11b2-8080-808080808080'
  },
  'name': 'hogwarts2',
  'type': '孤孤咕咕咕',
  'label': 'hogwarts_tag2',
  'deviceProfileId': {
    'entityType': 'DEVICE_PROFILE',
    'id': 'eec576e0-eca9-11ed-b839-b910c19eb442'
  },
  'deviceData': {
    'configuration': {
      'type': 'DEFAULT'
    },
    'transportConfiguration': {
      'type': 'DEFAULT'
    }
  },
  'firmwareId': None,
  'softwareId': None,
  'externalId': None
}

业务流程-删除设备

uml diagram

删除设备-请求示例

  • 请求url:https://thingsboard.stu.hogwarts.ceshiren.com/api/device/<device_id>

  • 示例:设备id为xxxx,则请求的url为:https://thingsboard.stu.hogwarts.ceshiren.com/api/device/xxxx

  • 请求方式为:delete

  • 请求头:{"X-Authorization": Bearer token}

  • 示例:登录接口返回token为:xxxxxx,则请求头为:{"X-Authorization": Bearer xxxxxx}


删除设备-响应结果

  • 接口响应状态码为:200代表删除成功