@@ -18,9 +18,10 @@ func TestSubscriptionManagerSuite(t *testing.T) {
18
18
type SubscriptionManagerSuite struct {
19
19
suite.Suite
20
20
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
24
25
}
25
26
26
27
func (suite * SubscriptionManagerSuite ) WriteShipMessageWithPayload ([]byte ) {}
@@ -31,9 +32,12 @@ func (suite *SubscriptionManagerSuite) SetupSuite() {
31
32
ski := "test"
32
33
sender := NewSender (suite )
33
34
suite .remoteDevice = NewDeviceRemote (suite .localDevice , ski , sender )
34
-
35
35
_ = suite .localDevice .SetupRemoteDevice (ski , suite )
36
36
37
+ ski2 := "test2"
38
+ suite .remoteDevice2 = NewDeviceRemote (suite .localDevice , ski2 , sender )
39
+ _ = suite .localDevice .SetupRemoteDevice (ski2 , suite )
40
+
37
41
suite .sut = NewSubscriptionManager (suite .localDevice )
38
42
}
39
43
@@ -49,13 +53,28 @@ func (suite *SubscriptionManagerSuite) Test_Subscriptions() {
49
53
remoteFeature := NewFeatureRemote (remoteEntity .NextFeatureId (), remoteEntity , model .FeatureTypeTypeDeviceDiagnosis , model .RoleTypeClient )
50
54
remoteFeature .Address ().Device = util .Ptr (model .AddressDeviceType ("remoteDevice" ))
51
55
remoteEntity .AddFeature (remoteFeature )
56
+ remoteEntity .Address ().Device = util .Ptr (model .AddressDeviceType ("remoteDevice" ))
52
57
53
58
subscrRequest := model.SubscriptionManagementRequestCallType {
54
59
ClientAddress : remoteFeature .Address (),
55
60
ServerAddress : localFeature .Address (),
56
61
ServerFeatureType : util .Ptr (model .FeatureTypeTypeDeviceDiagnosis ),
57
62
}
58
63
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
+
59
78
subMgr := suite .localDevice .SubscriptionManager ()
60
79
err := subMgr .AddSubscription (suite .remoteDevice , subscrRequest )
61
80
assert .Nil (suite .T (), err )
@@ -69,6 +88,12 @@ func (suite *SubscriptionManagerSuite) Test_Subscriptions() {
69
88
subs = subMgr .Subscriptions (suite .remoteDevice )
70
89
assert .Equal (suite .T (), 1 , len (subs ))
71
90
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
+
72
97
subscrDelete := model.SubscriptionManagementDeleteCallType {
73
98
ClientAddress : remoteFeature .Address (),
74
99
ServerAddress : localFeature .Address (),
@@ -90,8 +115,21 @@ func (suite *SubscriptionManagerSuite) Test_Subscriptions() {
90
115
subs = subMgr .Subscriptions (suite .remoteDevice )
91
116
assert .Equal (suite .T (), 1 , len (subs ))
92
117
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
+
93
128
subMgr .RemoveSubscriptionsForDevice (suite .remoteDevice )
94
129
95
130
subs = subMgr .Subscriptions (suite .remoteDevice )
96
131
assert .Equal (suite .T (), 0 , len (subs ))
132
+
133
+ subs = subMgr .Subscriptions (suite .remoteDevice2 )
134
+ assert .Equal (suite .T (), 1 , len (subs ))
97
135
}
0 commit comments