@@ -4,73 +4,163 @@ SystemHotSwapper test case
4
4
Class {
5
5
#name : #SystemHotSwapperTest ,
6
6
#superclass : #TestCase ,
7
+ #instVars : [
8
+ ' composite'
9
+ ],
7
10
#category : #' Kepler-System-Tests'
8
11
}
9
12
10
- { #category : #tests }
11
- SystemHotSwapperTest >> testCantSwapWhenTheInterfaceIsNotImplemented [
13
+ { #category : #private }
14
+ SystemHotSwapperTest >> assert: aSubsystem implements: anInterfaceKey [
12
15
13
- | composite cms newCMS |
16
+ self assert: ( self is: anInterfaceKey implementedBy: aSubsystem )
17
+ ]
14
18
15
- cms := SampleCustomerSystem new .
19
+ { #category : #private }
20
+ SystemHotSwapperTest >> deny: aSubsystem implements: anInterfaceKey [
21
+
22
+ self deny: ( self is: anInterfaceKey implementedBy: aSubsystem )
23
+ ]
24
+
25
+ { #category : #private }
26
+ SystemHotSwapperTest >> is: anInterfaceKey implementedBy: aSubsystem [
27
+
28
+ ^ aSubsystem implements: ( composite interfaceAt: anInterfaceKey )
29
+ ]
30
+
31
+ { #category : #running }
32
+ SystemHotSwapperTest >> setUp [
33
+
34
+ super setUp.
16
35
composite := CompositeSystem new
17
- register: cms;
18
- yourself .
19
- composite startUp.
36
+ ]
20
37
21
- newCMS := FixedCustomerSystem new .
38
+ { #category : #running }
39
+ SystemHotSwapperTest >> tearDown [
40
+
41
+ composite shutDown.
42
+ super tearDown
43
+ ]
44
+
45
+ { #category : #tests }
46
+ SystemHotSwapperTest >> testCantSwapWhenTheInterfaceIsNotImplemented [
47
+
48
+ composite
49
+ register: SampleCustomerSystem new ;
50
+ startUp.
22
51
23
52
self
24
- should: [ ( SystemHotSwapper swapSystemImplementing: #CustomerManagementSystem with: newCMS) applyTo: composite ]
53
+ should: [ SystemHotSwapper swapSystemImplementing: #CustomerManagementSystem with: FixedCustomerSystem new ]
25
54
raise: SystemControlError
26
55
withMessageText: ' CMS is not implementing Customer Management'
27
56
]
28
57
29
58
{ #category : #tests }
30
59
SystemHotSwapperTest >> testSwapping [
31
60
32
- | composite cms newCMS |
61
+ | cms newCMS |
33
62
34
63
cms := SampleCustomerSystem new .
35
- composite := CompositeSystem new
64
+ composite
36
65
register: cms;
37
- yourself .
38
- composite startUp.
66
+ startUp.
39
67
40
68
cms addCustomer: ' John' .
41
69
42
70
newCMS := FixedCustomerSystem new .
43
71
44
- self deny: cms = newCMS.
45
-
46
72
self
47
73
assert: composite >> #CustomerQueryingSystem equals: cms;
48
- assert: (composite >> #CustomerQueryingSystem ) customers size equals: 1 .
74
+ assert: ( composite >> #CustomerQueryingSystem ) customers size equals: 1 .
49
75
50
- (SystemHotSwapper swapSystemImplementing: #CustomerQueryingSystem with: newCMS) applyTo: composite.
76
+ ( SystemHotSwapper swapSystemImplementing: #CustomerQueryingSystem with: newCMS )
77
+ applyTo: composite.
51
78
52
79
self
53
80
assert: composite >> #CustomerQueryingSystem equals: newCMS;
54
- assert: (composite >> #CustomerQueryingSystem ) customers size equals: 2
81
+ assert: ( composite >> #CustomerQueryingSystem ) customers size equals: 2
82
+ ]
83
+
84
+ { #category : #tests }
85
+ SystemHotSwapperTest >> testSwappingFailedWhenReplacementsAreMissingSomeInterfaces [
86
+
87
+ | cms pms swapper |
88
+
89
+ cms := SampleCustomerSystem new .
90
+ pms := SampleProjectSystem new .
91
+ composite
92
+ register: cms;
93
+ register: pms;
94
+ startUp.
95
+
96
+ self
97
+ assert: composite >> #CustomerManagementSystem equals: cms;
98
+ assert: pms >> #CustomerQueryingSystem equals: cms.
99
+
100
+ swapper := SystemHotSwapper
101
+ swapSystemImplementing: #CustomerManagementSystem
102
+ with: FixedCustomerManagementSystem new .
103
+
104
+ self
105
+ should: [ swapper applyTo: composite ]
106
+ raise: SystemControlError
107
+ withMessageText: ' System implementing "Customer Querying" not found.'
108
+ ]
109
+
110
+ { #category : #tests }
111
+ SystemHotSwapperTest >> testSwappingOneImplementationWithTwoOthers [
112
+
113
+ " This test checks that a system implementing more than one interface can be replaced
114
+ by two or more systems implementing the required interfaces"
115
+
116
+ | cms managementSystem queryingSystem |
117
+
118
+ cms := SampleCustomerSystem new .
119
+ composite
120
+ register: cms;
121
+ startUp.
122
+
123
+ self
124
+ assert: cms implements: #CustomerQueryingSystem ;
125
+ assert: cms implements: #CustomerManagementSystem .
126
+
127
+ managementSystem := FixedCustomerManagementSystem new .
128
+ self
129
+ assert: managementSystem implements: #CustomerManagementSystem ;
130
+ deny: managementSystem implements: #CustomerQueryingSystem .
131
+
132
+ queryingSystem := FixedCustomerSystem new .
133
+ self
134
+ assert: queryingSystem implements: #CustomerQueryingSystem ;
135
+ deny: queryingSystem implements: #CustomerManagementSystem .
136
+
137
+ self
138
+ assert: composite >> #CustomerQueryingSystem equals: cms;
139
+ assert: composite >> #CustomerManagementSystem equals: cms.
140
+
141
+ ( SystemHotSwapper
142
+ swapSystemImplementingAll: #(#CustomerQueryingSystem #CustomerManagementSystem)
143
+ with: ( Array with: queryingSystem with: managementSystem ) ) applyTo: composite.
144
+
145
+ self
146
+ assert: composite >> #CustomerQueryingSystem equals: queryingSystem;
147
+ assert: composite >> #CustomerManagementSystem equals: managementSystem
55
148
]
56
149
57
150
{ #category : #tests }
58
151
SystemHotSwapperTest >> testSwappingSystemWithDependents [
59
152
60
- | composite cms newCMS pms |
153
+ | cms newCMS pms |
61
154
62
155
cms := SampleCustomerSystem new .
63
156
pms := SampleProjectSystem new .
64
- composite := CompositeSystem new
157
+ composite
65
158
register: cms;
66
159
register: pms;
67
- yourself .
68
- composite startUp.
160
+ startUp.
69
161
70
162
newCMS := FixedCustomerSystem new .
71
163
72
- self deny: cms = newCMS.
73
-
74
164
self
75
165
assert: composite >> #CustomerQueryingSystem equals: cms;
76
166
assert: pms >> #CustomerQueryingSystem equals: cms.
0 commit comments