@@ -18,9 +18,10 @@ func TestSubscriptionManagerSuite(t *testing.T) {
1818type SubscriptionManagerSuite struct {
1919 suite.Suite
2020
21- localDevice api.DeviceLocalInterface
22- remoteDevice api.DeviceRemoteInterface
23- sut api.SubscriptionManagerInterface
21+ localDevice api.DeviceLocalInterface
22+ remoteDevice ,
23+ remoteDevice2 api.DeviceRemoteInterface
24+ sut api.SubscriptionManagerInterface
2425}
2526
2627func (suite * SubscriptionManagerSuite ) WriteShipMessageWithPayload ([]byte ) {}
@@ -31,9 +32,12 @@ func (suite *SubscriptionManagerSuite) SetupSuite() {
3132 ski := "test"
3233 sender := NewSender (suite )
3334 suite .remoteDevice = NewDeviceRemote (suite .localDevice , ski , sender )
34-
3535 _ = suite .localDevice .SetupRemoteDevice (ski , suite )
3636
37+ ski2 := "test2"
38+ suite .remoteDevice2 = NewDeviceRemote (suite .localDevice , ski2 , sender )
39+ _ = suite .localDevice .SetupRemoteDevice (ski2 , suite )
40+
3741 suite .sut = NewSubscriptionManager (suite .localDevice )
3842}
3943
@@ -49,13 +53,28 @@ func (suite *SubscriptionManagerSuite) Test_Subscriptions() {
4953 remoteFeature := NewFeatureRemote (remoteEntity .NextFeatureId (), remoteEntity , model .FeatureTypeTypeDeviceDiagnosis , model .RoleTypeClient )
5054 remoteFeature .Address ().Device = util .Ptr (model .AddressDeviceType ("remoteDevice" ))
5155 remoteEntity .AddFeature (remoteFeature )
56+ remoteEntity .Address ().Device = util .Ptr (model .AddressDeviceType ("remoteDevice" ))
5257
5358 subscrRequest := model.SubscriptionManagementRequestCallType {
5459 ClientAddress : remoteFeature .Address (),
5560 ServerAddress : localFeature .Address (),
5661 ServerFeatureType : util .Ptr (model .FeatureTypeTypeDeviceDiagnosis ),
5762 }
5863
64+ remoteEntity2 := NewEntityRemote (suite .remoteDevice2 , model .EntityTypeTypeEVSE , []model.AddressEntityType {1 })
65+ suite .remoteDevice2 .AddEntity (remoteEntity2 )
66+
67+ remoteFeature2 := NewFeatureRemote (remoteEntity2 .NextFeatureId (), remoteEntity2 , model .FeatureTypeTypeDeviceDiagnosis , model .RoleTypeClient )
68+ remoteFeature2 .Address ().Device = util .Ptr (model .AddressDeviceType ("remoteDevice2" ))
69+ remoteEntity2 .AddFeature (remoteFeature2 )
70+ remoteEntity2 .Address ().Device = util .Ptr (model .AddressDeviceType ("remoteDevice2" ))
71+
72+ subscrRequest2 := model.SubscriptionManagementRequestCallType {
73+ ClientAddress : remoteFeature2 .Address (),
74+ ServerAddress : localFeature .Address (),
75+ ServerFeatureType : util .Ptr (model .FeatureTypeTypeDeviceDiagnosis ),
76+ }
77+
5978 subMgr := suite .localDevice .SubscriptionManager ()
6079 err := subMgr .AddSubscription (suite .remoteDevice , subscrRequest )
6180 assert .Nil (suite .T (), err )
@@ -69,6 +88,12 @@ func (suite *SubscriptionManagerSuite) Test_Subscriptions() {
6988 subs = subMgr .Subscriptions (suite .remoteDevice )
7089 assert .Equal (suite .T (), 1 , len (subs ))
7190
91+ err = subMgr .AddSubscription (suite .remoteDevice2 , subscrRequest2 )
92+ assert .Nil (suite .T (), err )
93+
94+ subs = subMgr .Subscriptions (suite .remoteDevice2 )
95+ assert .Equal (suite .T (), 1 , len (subs ))
96+
7297 subscrDelete := model.SubscriptionManagementDeleteCallType {
7398 ClientAddress : remoteFeature .Address (),
7499 ServerAddress : localFeature .Address (),
@@ -90,8 +115,21 @@ func (suite *SubscriptionManagerSuite) Test_Subscriptions() {
90115 subs = subMgr .Subscriptions (suite .remoteDevice )
91116 assert .Equal (suite .T (), 1 , len (subs ))
92117
118+ subMgr .RemoveSubscriptionsForEntity (nil )
119+
120+ subs = subMgr .Subscriptions (suite .remoteDevice )
121+ assert .Equal (suite .T (), 1 , len (subs ))
122+
123+ subMgr .RemoveSubscriptionsForDevice (nil )
124+
125+ subs = subMgr .Subscriptions (suite .remoteDevice )
126+ assert .Equal (suite .T (), 1 , len (subs ))
127+
93128 subMgr .RemoveSubscriptionsForDevice (suite .remoteDevice )
94129
95130 subs = subMgr .Subscriptions (suite .remoteDevice )
96131 assert .Equal (suite .T (), 0 , len (subs ))
132+
133+ subs = subMgr .Subscriptions (suite .remoteDevice2 )
134+ assert .Equal (suite .T (), 1 , len (subs ))
97135}
0 commit comments