Skip to content

Commit

Permalink
Add more nodemanagement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Dec 30, 2023
1 parent 1bdad4f commit a79cf5f
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 49 deletions.
9 changes: 9 additions & 0 deletions spine/nodemanagement_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ func NewNodeManagementBindingRequestCallType(clientAddress *model.FeatureAddress
}
}

func NewNodeManagementBindingDeleteCallType(clientAddress *model.FeatureAddressType, serverAddress *model.FeatureAddressType) *model.NodeManagementBindingDeleteCallType {
return &model.NodeManagementBindingDeleteCallType{
BindingDelete: &model.BindingManagementDeleteCallType{
ClientAddress: clientAddress,
ServerAddress: serverAddress,
},
}
}

// route bindings request calls to the appropriate feature implementation and add the bindings to the current list
func (r *NodeManagementImpl) processReadBindingData(message *Message) error {

Expand Down
9 changes: 9 additions & 0 deletions spine/nodemanagement_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ func NewNodeManagementSubscriptionRequestCallType(clientAddress *model.FeatureAd
}
}

func NewNodeManagementSubscriptionDeleteCallType(clientAddress *model.FeatureAddressType, serverAddress *model.FeatureAddressType, featureType model.FeatureTypeType) *model.NodeManagementSubscriptionDeleteCallType {
return &model.NodeManagementSubscriptionDeleteCallType{
SubscriptionDelete: &model.SubscriptionManagementDeleteCallType{
ClientAddress: clientAddress,
ServerAddress: serverAddress,
},
}
}

// route subscription request calls to the appropriate feature implementation and add the subscription to the current list
func (r *NodeManagementImpl) processReadSubscriptionData(message *Message) error {

Expand Down
146 changes: 97 additions & 49 deletions spine/nodemanagement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,94 @@ import (
"github.com/stretchr/testify/mock"
)

func TestNodemanagement_SubscriptionRequestCall(t *testing.T) {
func TestNodemanagement_BindingCalls(t *testing.T) {
const bindingEntityId uint = 1
const featureType = model.FeatureTypeTypeLoadControl

// const serverName = "Server"
// const clientName = "Client"
senderMock := mocks.NewSender(t)

serverFeature := createLocalDeviceAndFeature(bindingEntityId, featureType, model.RoleTypeServer)
clientFeature := createRemoteDeviceAndFeature(bindingEntityId, featureType, model.RoleTypeClient, senderMock)

senderMock.On("Reply", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
cmd := args.Get(2).(model.CmdType)
assert.Equal(t, 1, len(cmd.NodeManagementBindingData.BindingEntry))
assert.True(t, reflect.DeepEqual(cmd.NodeManagementBindingData.BindingEntry[0].ClientAddress, clientFeature.Address()))
assert.True(t, reflect.DeepEqual(cmd.NodeManagementBindingData.BindingEntry[0].ServerAddress, serverFeature.Address()))
}).Return(nil).Once()

requestMsg := spine.Message{
Cmd: model.CmdType{
NodeManagementBindingRequestCall: spine.NewNodeManagementBindingRequestCallType(
clientFeature.Address(), serverFeature.Address(), featureType),
},
CmdClassifier: model.CmdClassifierTypeCall,
FeatureRemote: clientFeature,
}

sut := spine.NewNodeManagementImpl(0, serverFeature.Entity())

// Act
err := sut.HandleMessage(&requestMsg)
if assert.Nil(t, err) {

dataMsg := spine.Message{
Cmd: model.CmdType{
NodeManagementBindingData: &model.NodeManagementBindingDataType{},
},
CmdClassifier: model.CmdClassifierTypeCall,
FeatureRemote: clientFeature,
}
err = sut.HandleMessage(&dataMsg)
assert.Nil(t, err)
}

senderMock.On("Reply", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
cmd := args.Get(2).(model.CmdType)
assert.Equal(t, 0, len(cmd.NodeManagementBindingData.BindingEntry))
}).Return(nil).Once()

deleteMsg := spine.Message{
Cmd: model.CmdType{
NodeManagementBindingDeleteCall: spine.NewNodeManagementBindingDeleteCallType(
clientFeature.Address(), serverFeature.Address()),
},
CmdClassifier: model.CmdClassifierTypeCall,
FeatureRemote: clientFeature,
}

// Act
err = sut.HandleMessage(&deleteMsg)
if assert.Nil(t, err) {

dataMsg := spine.Message{
Cmd: model.CmdType{
NodeManagementBindingData: &model.NodeManagementBindingDataType{},
},
CmdClassifier: model.CmdClassifierTypeCall,
FeatureRemote: clientFeature,
}
err = sut.HandleMessage(&dataMsg)
assert.Nil(t, err)
}
}

func TestNodemanagement_SubscriptionCalls(t *testing.T) {
const subscriptionEntityId uint = 1
//const subscriptionFeatureId uint = 2
const featureType = model.FeatureTypeTypeDeviceClassification

senderMock := mocks.NewSender(t)

//localDevice := NewDeviceLocalImpl(model.AddressDeviceType("server"))

serverFeature := createLocalDeviceAndFeature(subscriptionEntityId, featureType, model.RoleTypeServer)
clientFeature := createRemoteDeviceAndFeature(subscriptionEntityId, featureType, model.RoleTypeClient, senderMock)

// serverAddress := featureAddress(serverName, subscriptionEntityId, subscriptionFeatureId)
// clientAddress := featureAddress(clientName, subscriptionEntityId, subscriptionFeatureId)
senderMock.On("Reply", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
cmd := args.Get(2).(model.CmdType)
assert.Equal(t, 1, len(cmd.NodeManagementSubscriptionData.SubscriptionEntry))
assert.True(t, reflect.DeepEqual(cmd.NodeManagementSubscriptionData.SubscriptionEntry[0].ClientAddress, clientFeature.Address()))
assert.True(t, reflect.DeepEqual(cmd.NodeManagementSubscriptionData.SubscriptionEntry[0].ServerAddress, serverFeature.Address()))

}).Return(nil).Once()

// serverFeatureMock := newFeatureLocalMock(serverAddress, model.RoleTypeServer, featureType, senderMock)
// clientFeatureMock := newFeatureRemoteMock(clientAddress, model.RoleTypeClient, featureType)

requestMsg := spine.Message{
Cmd: model.CmdType{
NodeManagementSubscriptionRequestCall: spine.NewNodeManagementSubscriptionRequestCallType(
Expand All @@ -65,44 +124,33 @@ func TestNodemanagement_SubscriptionRequestCall(t *testing.T) {
err = sut.HandleMessage(&dataMsg)
assert.Nil(t, err)
}
}

// func newFeatureLocalMock(address *model.FeatureAddressType, role model.RoleType, ftype model.FeatureTypeType, sender spine.Sender) *mocks.FeatureLocal {
// deviceMock := new(mocks.DeviceLocal)
// entityMock := new(mocks.EntityLocal)
// featureMock := new(mocks.FeatureLocal)

// deviceMock.On("FeatureByAddress", address).Return(featureMock)
// deviceMock.On("Address").Return(address.Device)
// deviceMock.On("Sender").Return(sender)

// entityMock.On("Device").Return(deviceMock)
// entityMock.On("Address").Return(address.Entity)

// featureMock.On("Role").Return(role)
// featureMock.On("Type").Return(model.FeatureTypeEnumType(ftype))
// featureMock.On("Device").Return(deviceMock)
// featureMock.On("Entity").Return(entityMock)

// return featureMock
// }

// func newFeatureRemoteMock(address *model.FeatureAddressType, role model.RoleType, ftype model.FeatureTypeType) *mocks.FeatureRemote {
// deviceMock := new(mocks.DeviceRemote)
// entityMock := new(mocks.EntityRemote)
// featureMock := new(mocks.FeatureRemote)

// deviceMock.On("FeatureByAddress", address).Return(featureMock)
// deviceMock.On("Address").Return(address.Device)
// //deviceMock.On("Sender").Return(sender)
senderMock.On("Reply", mock.Anything, mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
cmd := args.Get(2).(model.CmdType)
assert.Equal(t, 0, len(cmd.NodeManagementSubscriptionData.SubscriptionEntry))
}).Return(nil).Once()

// entityMock.On("Device").Return(deviceMock)
// entityMock.On("Address").Return(address.Entity)
deleteMsg := spine.Message{
Cmd: model.CmdType{
NodeManagementSubscriptionDeleteCall: spine.NewNodeManagementSubscriptionDeleteCallType(
clientFeature.Address(), serverFeature.Address(), featureType),
},
CmdClassifier: model.CmdClassifierTypeCall,
FeatureRemote: clientFeature,
}

// featureMock.On("Role").Return(role)
// featureMock.On("Type").Return(model.FeatureTypeEnumType(ftype))
// featureMock.On("Device").Return(deviceMock)
// featureMock.On("Entity").Return(entityMock)
// Act
err = sut.HandleMessage(&deleteMsg)
if assert.Nil(t, err) {

// return featureMock
// }
dataMsg := spine.Message{
Cmd: model.CmdType{
NodeManagementSubscriptionData: &model.NodeManagementSubscriptionDataType{},
},
CmdClassifier: model.CmdClassifierTypeCall,
FeatureRemote: clientFeature,
}
err = sut.HandleMessage(&dataMsg)
assert.Nil(t, err)
}
}

0 comments on commit a79cf5f

Please sign in to comment.