Skip to content

Commit

Permalink
Merge pull request edgexfoundry#329 from cloudxxx8/issue-328
Browse files Browse the repository at this point in the history
fix: replace ID to Id in V2
  • Loading branch information
judehung authored Oct 12, 2020
2 parents cbb80de + 24f5622 commit 70ac9f3
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 118 deletions.
6 changes: 3 additions & 3 deletions v2/dtos/common/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import v2 "github.com/edgexfoundry/go-mod-core-contracts/v2"
// This object and its properties correspond to the BaseRequest object in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-data/2.x#/BaseRequest
type BaseRequest struct {
RequestID string `json:"requestId" validate:"len=0|uuid"`
RequestId string `json:"requestId" validate:"len=0|uuid"`
}

// BaseResponse defines the base content for response DTOs (data transfer objects).
// This object and its properties correspond to the BaseResponse object in the APIv2 specification:
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-data/2.x#/BaseResponse
type BaseResponse struct {
Versionable `json:",inline"`
RequestID string `json:"requestId"`
RequestId string `json:"requestId"`
Message interface{} `json:"message,omitempty"`
StatusCode int `json:"statusCode"`
}
Expand All @@ -44,7 +44,7 @@ func NewBaseResponseNoMessage(requestId string, statusCode int) BaseResponse {
func NewBaseResponse(requestId string, message string, statusCode int) BaseResponse {
return BaseResponse{
Versionable: NewVersionable(),
RequestID: requestId,
RequestId: requestId,
Message: message,
StatusCode: statusCode,
}
Expand Down
24 changes: 12 additions & 12 deletions v2/dtos/common/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ import (
)

func TestNewBaseResponse(t *testing.T) {
expectedRequestID := "123456"
expectedRequestId := "123456"
expectedStatusCode := 200
expectedMessage := "unit test message"
actual := NewBaseResponse(expectedRequestID, expectedMessage, expectedStatusCode)
actual := NewBaseResponse(expectedRequestId, expectedMessage, expectedStatusCode)

assert.Equal(t, expectedRequestID, actual.RequestID)
assert.Equal(t, expectedRequestId, actual.RequestId)
assert.Equal(t, expectedStatusCode, actual.StatusCode)
assert.Equal(t, expectedMessage, actual.Message)
}

func TestNewBaseResponseNoMessage(t *testing.T) {
expectedRequestID := "123456"
expectedRequestId := "123456"
expectedStatusCode := 200
actual := NewBaseResponseNoMessage(expectedRequestID, expectedStatusCode)
actual := NewBaseResponseNoMessage(expectedRequestId, expectedStatusCode)

assert.Equal(t, expectedRequestID, actual.RequestID)
assert.Equal(t, expectedRequestId, actual.RequestId)
assert.Equal(t, expectedStatusCode, actual.StatusCode)
assert.Empty(t, actual.Message)
}
Expand All @@ -41,25 +41,25 @@ func TestNewVersionable(t *testing.T) {
}

func TestNewBaseWithIdResponse(t *testing.T) {
expectedRequestID := "123456"
expectedRequestId := "123456"
expectedStatusCode := 200
expectedMessage := "unit test message"
expectedId := "7a1707f0-166f-4c4b-bc9d-1d54c74e0137"
actual := NewBaseWithIdResponse(expectedRequestID, expectedMessage, expectedStatusCode, expectedId)
actual := NewBaseWithIdResponse(expectedRequestId, expectedMessage, expectedStatusCode, expectedId)

assert.Equal(t, expectedRequestID, actual.RequestID)
assert.Equal(t, expectedRequestId, actual.RequestId)
assert.Equal(t, expectedStatusCode, actual.StatusCode)
assert.Equal(t, expectedMessage, actual.Message)
assert.Equal(t, expectedId, actual.Id)
}

func TestNewBaseWithIdResponseNoMessage(t *testing.T) {
expectedRequestID := "123456"
expectedRequestId := "123456"
expectedStatusCode := 200
expectedId := "7a1707f0-166f-4c4b-bc9d-1d54c74e0137"
actual := NewBaseWithIdResponseNoMessage(expectedRequestID, expectedStatusCode, expectedId)
actual := NewBaseWithIdResponseNoMessage(expectedRequestId, expectedStatusCode, expectedId)

assert.Equal(t, expectedRequestID, actual.RequestID)
assert.Equal(t, expectedRequestId, actual.RequestId)
assert.Equal(t, expectedStatusCode, actual.StatusCode)
assert.Equal(t, expectedId, actual.Id)
}
4 changes: 2 additions & 2 deletions v2/dtos/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-data/2.x#/Event
type Event struct {
common.Versionable `json:",inline"`
ID string `json:"id" validate:"required,uuid"`
Id string `json:"id" validate:"required,uuid"`
Pushed int64 `json:"pushed,omitempty"`
DeviceName string `json:"deviceName" validate:"required"`
Created int64 `json:"created"`
Expand All @@ -42,7 +42,7 @@ func FromEventModelToDTO(event models.Event) Event {

return Event{
Versionable: common.Versionable{ApiVersion: v2.ApiVersion},
ID: event.Id,
Id: event.Id,
Pushed: event.Pushed,
DeviceName: event.DeviceName,
Created: event.Created,
Expand Down
4 changes: 2 additions & 2 deletions v2/dtos/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var valid = models.Event{

var expectedDTO = Event{
Versionable: common.Versionable{ApiVersion: v2.ApiVersion},
ID: TestUUID,
Id: TestUUID,
Pushed: TestTimestamp,
DeviceName: TestDeviceName,
Created: TestTimestamp,
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestFromEventModelToDTO(t *testing.T) {
func TestEvent_ToXML(t *testing.T) {
// Since the order in map is random we have to verify the individual items exists without depending on order
contains := []string{
"<Event><ApiVersion>v2</ApiVersion><ID>7a1707f0-166f-4c4b-bc9d-1d54c74e0137</ID><Pushed>1594963842</Pushed><DeviceName>TestDevice</DeviceName><Created>1594963842</Created><Origin>1594963842</Origin><Tags>",
"<Event><ApiVersion>v2</ApiVersion><Id>7a1707f0-166f-4c4b-bc9d-1d54c74e0137</Id><Pushed>1594963842</Pushed><DeviceName>TestDevice</DeviceName><Created>1594963842</Created><Origin>1594963842</Origin><Tags>",
"<GatewayID>Houston-0001</GatewayID>",
"<Latitude>29.630771</Latitude>",
"<Longitude>-95.377603</Longitude>",
Expand Down
28 changes: 14 additions & 14 deletions v2/dtos/requests/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var testProtocols = map[string]dtos.ProtocolProperties{
}
var testAddDevice = AddDeviceRequest{
BaseRequest: common.BaseRequest{
RequestID: ExampleUUID,
RequestId: ExampleUUID,
},
Device: dtos.Device{
Name: TestDeviceName,
Expand All @@ -54,7 +54,7 @@ var testAddDevice = AddDeviceRequest{
var testNowTime = time.Now().Unix()
var testUpdateDevice = UpdateDeviceRequest{
BaseRequest: common.BaseRequest{
RequestID: ExampleUUID,
RequestId: ExampleUUID,
},
Device: mockUpdateDevice(),
}
Expand Down Expand Up @@ -88,10 +88,10 @@ func TestAddDeviceRequest_Validate(t *testing.T) {
valid := testAddDevice
invalidFrequency := testAddDevice
invalidFrequency.Device.AutoEvents = testAutoEventsWithInvalidFrequency
noReqID := testAddDevice
noReqID.RequestID = ""
invalidReqID := testAddDevice
invalidReqID.RequestID = "abc"
noReqId := testAddDevice
noReqId.RequestId = ""
invalidReqId := testAddDevice
invalidReqId.RequestId = "abc"
noDeviceName := testAddDevice
noDeviceName.Device.Name = ""
noServiceName := testAddDevice
Expand All @@ -115,8 +115,8 @@ func TestAddDeviceRequest_Validate(t *testing.T) {
}{
{"valid AddDeviceRequest", valid, false},
{"invalid AddDeviceRequest, invalid autoEvent frequency", invalidFrequency, true},
{"valid AddDeviceRequest, no Request Id", noReqID, false},
{"invalid AddDeviceRequest, Request Id is not an uuid", invalidReqID, true},
{"valid AddDeviceRequest, no Request Id", noReqId, false},
{"invalid AddDeviceRequest, Request Id is not an uuid", invalidReqId, true},
{"invalid AddDeviceRequest, no DeviceName", noDeviceName, true},
{"invalid AddDeviceRequest, no ServiceName", noServiceName, true},
{"invalid AddDeviceRequest, no ProfileName", noProfileName, true},
Expand Down Expand Up @@ -227,10 +227,10 @@ func TestUpdateDeviceRequest_Validate(t *testing.T) {
validWithoutId.Device.Id = nil
validWithoutDeviceName := testUpdateDevice
validWithoutDeviceName.Device.Name = nil
noReqID := testUpdateDevice
noReqID.RequestID = ""
invalidReqID := testUpdateDevice
invalidReqID.RequestID = "123"
noReqId := testUpdateDevice
noReqId.RequestId = ""
invalidReqId := testUpdateDevice
invalidReqId.RequestId = "123"
noIdAndDeviceName := testUpdateDevice
noIdAndDeviceName.Device.Id = nil
noIdAndDeviceName.Device.Name = nil
Expand All @@ -251,8 +251,8 @@ func TestUpdateDeviceRequest_Validate(t *testing.T) {
{"valid UpdateDeviceRequest", valid, false},
{"valid UpdateDeviceRequest without Id", validWithoutId, false},
{"valid UpdateDeviceRequest without Name", validWithoutDeviceName, false},
{"valid UpdateDeviceRequest, no Request Id", noReqID, false},
{"invalid UpdateDeviceRequest, Request Id is not an uuid", invalidReqID, true},
{"valid UpdateDeviceRequest, no Request Id", noReqId, false},
{"invalid UpdateDeviceRequest, Request Id is not an uuid", invalidReqId, true},
{"invalid UpdateDeviceRequest, invalid admin state", invalidAdminState, true},
{"invalid UpdateDeviceRequest, invalid operating state", invalidOperatingState, true},
{"invalid UpdateDeviceRequest, invalid autoEvent frequency", invalidFrequency, true},
Expand Down
2 changes: 1 addition & 1 deletion v2/dtos/requests/deviceprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var testCoreCommands = []dtos.Command{{

var testAddDeviceProfileReq = DeviceProfileRequest{
BaseRequest: common.BaseRequest{
RequestID: ExampleUUID,
RequestId: ExampleUUID,
},
Profile: dtos.DeviceProfile{
Name: TestDeviceProfileName,
Expand Down
28 changes: 14 additions & 14 deletions v2/dtos/requests/deviceservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

var testAddDeviceService = AddDeviceServiceRequest{
BaseRequest: common.BaseRequest{
RequestID: ExampleUUID,
RequestId: ExampleUUID,
},
Service: dtos.DeviceService{
Name: TestDeviceServiceName,
Expand All @@ -33,7 +33,7 @@ var testAddDeviceService = AddDeviceServiceRequest{

var testUpdateDeviceService = UpdateDeviceServiceRequest{
BaseRequest: common.BaseRequest{
RequestID: ExampleUUID,
RequestId: ExampleUUID,
},
Service: mockDeviceServiceDTO(),
}
Expand All @@ -56,10 +56,10 @@ func mockDeviceServiceDTO() dtos.UpdateDeviceService {

func TestAddDeviceServiceRequest_Validate(t *testing.T) {
valid := testAddDeviceService
noReqID := testAddDeviceService
noReqID.RequestID = ""
invalidReqID := testAddDeviceService
invalidReqID.RequestID = "jfdw324"
noReqId := testAddDeviceService
noReqId.RequestId = ""
invalidReqId := testAddDeviceService
invalidReqId.RequestId = "jfdw324"
noName := testAddDeviceService
noName.Service.Name = ""
noOperatingState := testAddDeviceService
Expand All @@ -80,8 +80,8 @@ func TestAddDeviceServiceRequest_Validate(t *testing.T) {
expectError bool
}{
{"valid AddDeviceServiceRequest", valid, false},
{"valid AddDeviceServiceRequest, no Request Id", noReqID, false},
{"invalid AddDeviceServiceRequest, Request Id is not an uuid", invalidReqID, true},
{"valid AddDeviceServiceRequest, no Request Id", noReqId, false},
{"invalid AddDeviceServiceRequest, Request Id is not an uuid", invalidReqId, true},
{"invalid AddDeviceServiceRequest, no Name", noName, true},
{"invalid AddDeviceServiceRequest, no OperatingState", noOperatingState, true},
{"invalid AddDeviceServiceRequest, invalid OperatingState", invalidOperatingState, true},
Expand Down Expand Up @@ -179,10 +179,10 @@ func TestUpdateDeviceServiceRequest_Validate(t *testing.T) {
validWithoutId.Service.Id = nil
validWithoutName := valid
validWithoutName.Service.Name = nil
noReqID := valid
noReqID.RequestID = ""
invalidReqID := valid
invalidReqID.RequestID = "2h022mc"
noReqId := valid
noReqId.RequestId = ""
invalidReqId := valid
invalidReqId.RequestId = "2h022mc"
noIdAndName := valid
noIdAndName.Service.Id = nil
noIdAndName.Service.Name = nil
Expand All @@ -199,8 +199,8 @@ func TestUpdateDeviceServiceRequest_Validate(t *testing.T) {
{"valid UpdateDeviceServiceRequest", valid, false},
{"valid UpdateDeviceServiceRequest without Id", validWithoutId, false},
{"valid UpdateDeviceServiceRequest without name", validWithoutName, false},
{"valid UpdateDeviceServiceRequest, no Request Id", noReqID, false},
{"invalid UpdateDeviceServiceRequest, no Request Id", invalidReqID, true},
{"valid UpdateDeviceServiceRequest, no Request Id", noReqId, false},
{"invalid UpdateDeviceServiceRequest, no Request Id", invalidReqId, true},
{"invalid UpdateDeviceServiceRequest, no Id and Name", noIdAndName, true},
{"invalid UpdateDeviceServiceRequest, invalid OperatingState", invalidOperatingState, true},
{"invalid UpdateDeviceServiceRequest, invalid AdminState", invalidAdminState, true},
Expand Down
2 changes: 1 addition & 1 deletion v2/dtos/requests/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func AddEventReqToEventModels(addRequests []AddEventRequest) (events []models.Ev
tags[tag] = value
}

e.Id = a.Event.ID
e.Id = a.Event.Id
e.DeviceName = a.Event.DeviceName
e.Origin = a.Event.Origin
e.Readings = readings
Expand Down
28 changes: 14 additions & 14 deletions v2/dtos/requests/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (

var testAddEvent = AddEventRequest{
BaseRequest: common.BaseRequest{
RequestID: ExampleUUID,
RequestId: ExampleUUID,
},
Event: dtos.Event{
ID: ExampleUUID,
Id: ExampleUUID,
DeviceName: TestDeviceName,
Origin: TestOriginTime,
Readings: []dtos.BaseReading{{
Expand All @@ -43,14 +43,14 @@ var testAddEvent = AddEventRequest{

func TestAddEventRequest_Validate(t *testing.T) {
valid := testAddEvent
noReqID := testAddEvent
noReqID.RequestID = ""
invalidReqID := testAddEvent
invalidReqID.RequestID = "xxy"
noEventID := testAddEvent
noEventID.Event.ID = ""
invalidEventID := testAddEvent
invalidEventID.Event.ID = "gj93j2-v92hvi3h"
noReqId := testAddEvent
noReqId.RequestId = ""
invalidReqId := testAddEvent
invalidReqId.RequestId = "xxy"
noEventId := testAddEvent
noEventId.Event.Id = ""
invalidEventId := testAddEvent
invalidEventId.Event.Id = "gj93j2-v92hvi3h"
noDeviceName := testAddEvent
noDeviceName.Event.DeviceName = ""
noOrigin := testAddEvent
Expand Down Expand Up @@ -161,10 +161,10 @@ func TestAddEventRequest_Validate(t *testing.T) {
expectError bool
}{
{"valid AddEventRequest", valid, false},
{"valid AddEventRequest, no Request Id", noReqID, false},
{"invalid AddEventRequest, Request Id is not an uuid", invalidReqID, true},
{"invalid AddEventRequest, no Event Id", noEventID, true},
{"invalid AddEventRequest, Event Id is not an uuid", invalidEventID, true},
{"valid AddEventRequest, no Request Id", noReqId, false},
{"invalid AddEventRequest, Request Id is not an uuid", invalidReqId, true},
{"invalid AddEventRequest, no Event Id", noEventId, true},
{"invalid AddEventRequest, Event Id is not an uuid", invalidEventId, true},
{"invalid AddEventRequest, no DeviceName", noDeviceName, true},
{"invalid AddEventRequest, no Origin", noOrigin, true},
{"invalid AddEventRequest, no Reading", noReading, true},
Expand Down
12 changes: 6 additions & 6 deletions v2/dtos/responses/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ import (
)

func TestNewDeviceResponse(t *testing.T) {
expectedRequestID := "123456"
expectedRequestId := "123456"
expectedStatusCode := 200
expectedMessage := "unit test message"
expectedDevice := dtos.Device{Name: "test device"}
actual := NewDeviceResponse(expectedRequestID, expectedMessage, expectedStatusCode, expectedDevice)
actual := NewDeviceResponse(expectedRequestId, expectedMessage, expectedStatusCode, expectedDevice)

assert.Equal(t, expectedRequestID, actual.RequestID)
assert.Equal(t, expectedRequestId, actual.RequestId)
assert.Equal(t, expectedStatusCode, actual.StatusCode)
assert.Equal(t, expectedMessage, actual.Message)
assert.Equal(t, expectedDevice, actual.Device)
}

func TestNewDeviceResponseNoMessage(t *testing.T) {
expectedRequestID := "123456"
expectedRequestId := "123456"
expectedStatusCode := 200
expectedDevice := dtos.Device{Name: "test device"}
actual := NewDeviceResponseNoMessage(expectedRequestID, expectedStatusCode, expectedDevice)
actual := NewDeviceResponseNoMessage(expectedRequestId, expectedStatusCode, expectedDevice)

assert.Equal(t, expectedRequestID, actual.RequestID)
assert.Equal(t, expectedRequestId, actual.RequestId)
assert.Equal(t, expectedStatusCode, actual.StatusCode)
assert.Equal(t, expectedDevice, actual.Device)
}
12 changes: 6 additions & 6 deletions v2/dtos/responses/deviceprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ import (
)

func TestNewDeviceProfileResponse(t *testing.T) {
expectedRequestID := "123456"
expectedRequestId := "123456"
expectedStatusCode := 200
expectedMessage := "unit test message"
expectedDeviceProfile := dtos.DeviceProfile{Name: "test device profile"}
actual := NewDeviceProfileResponse(expectedRequestID, expectedMessage, expectedStatusCode, expectedDeviceProfile)
actual := NewDeviceProfileResponse(expectedRequestId, expectedMessage, expectedStatusCode, expectedDeviceProfile)

assert.Equal(t, expectedRequestID, actual.RequestID)
assert.Equal(t, expectedRequestId, actual.RequestId)
assert.Equal(t, expectedStatusCode, actual.StatusCode)
assert.Equal(t, expectedMessage, actual.Message)
assert.Equal(t, expectedDeviceProfile, actual.Profile)
}

func TestNewDeviceProfileResponseNoMessage(t *testing.T) {
expectedRequestID := "123456"
expectedRequestId := "123456"
expectedStatusCode := 200
expectedDeviceProfile := dtos.DeviceProfile{Name: "test device profile"}
actual := NewDeviceProfileResponseNoMessage(expectedRequestID, expectedStatusCode, expectedDeviceProfile)
actual := NewDeviceProfileResponseNoMessage(expectedRequestId, expectedStatusCode, expectedDeviceProfile)

assert.Equal(t, expectedRequestID, actual.RequestID)
assert.Equal(t, expectedRequestId, actual.RequestId)
assert.Equal(t, expectedStatusCode, actual.StatusCode)
assert.Equal(t, expectedDeviceProfile, actual.Profile)
}
Loading

0 comments on commit 70ac9f3

Please sign in to comment.