7
7
import com .github .containersolutions .operator .sample .TestCustomResource ;
8
8
import io .fabric8 .kubernetes .api .model .ObjectMetaBuilder ;
9
9
import io .fabric8 .kubernetes .client .CustomResource ;
10
- import io .fabric8 .kubernetes .client .CustomResourceDoneable ;
11
- import io .fabric8 .kubernetes .client .CustomResourceList ;
12
10
import io .fabric8 .kubernetes .client .Watcher ;
13
- import io .fabric8 .kubernetes .client .dsl .Replaceable ;
14
- import io .fabric8 .kubernetes .client .dsl .internal .CustomResourceOperationsImpl ;
15
11
import org .junit .jupiter .api .BeforeEach ;
16
12
import org .junit .jupiter .api .Test ;
17
13
import org .mockito .ArgumentMatchers ;
@@ -27,19 +23,19 @@ class EventDispatcherTest {
27
23
private CustomResource testCustomResource ;
28
24
private EventDispatcher eventDispatcher ;
29
25
private ResourceController <CustomResource > resourceController = mock (ResourceController .class );
30
- private CustomResourceOperationsImpl < CustomResource , CustomResourceList < CustomResource >,
31
- CustomResourceDoneable < CustomResource >> resourceOperation = mock ( CustomResourceOperationsImpl . class );
26
+ private EventDispatcher . CustomResourceReplaceFacade customResourceReplaceFacade = mock ( EventDispatcher . CustomResourceReplaceFacade . class );
27
+
32
28
33
29
@ BeforeEach
34
30
void setup () {
35
- eventDispatcher = new EventDispatcher (resourceController , resourceOperation ,
36
- Controller .DEFAULT_FINALIZER );
31
+ eventDispatcher = new EventDispatcher (resourceController ,
32
+ Controller .DEFAULT_FINALIZER , customResourceReplaceFacade );
37
33
38
34
testCustomResource = getResource ();
39
35
40
36
when (resourceController .createOrUpdateResource (eq (testCustomResource ))).thenReturn (Optional .of (testCustomResource ));
41
37
when (resourceController .deleteResource (eq (testCustomResource ))).thenReturn (true );
42
- when (resourceOperation . lockResourceVersion (any ())).thenReturn (mock ( Replaceable . class ) );
38
+ when (customResourceReplaceFacade . replaceWithLock (any ())).thenReturn (null );
43
39
}
44
40
45
41
@ Test
@@ -92,7 +88,7 @@ void removesDefaultFinalizerOnDelete() {
92
88
eventDispatcher .handleEvent (Watcher .Action .MODIFIED , testCustomResource );
93
89
94
90
assertEquals (0 , testCustomResource .getMetadata ().getFinalizers ().size ());
95
- verify (resourceOperation , times (1 )).lockResourceVersion (any ());
91
+ verify (customResourceReplaceFacade , times (1 )).replaceWithLock (any ());
96
92
}
97
93
98
94
@ Test
@@ -104,7 +100,7 @@ void doesNotRemovesTheFinalizerIfTheDeleteMethodRemovesFalse() {
104
100
eventDispatcher .handleEvent (Watcher .Action .MODIFIED , testCustomResource );
105
101
106
102
assertEquals (1 , testCustomResource .getMetadata ().getFinalizers ().size ());
107
- verify (resourceOperation , never ()).lockResourceVersion (any ());
103
+ verify (customResourceReplaceFacade , never ()).replaceWithLock (any ());
108
104
}
109
105
110
106
@ Test
@@ -113,8 +109,7 @@ void doesNotUpdateTheResourceIfEmptyOptionalReturned() {
113
109
when (resourceController .createOrUpdateResource (eq (testCustomResource ))).thenReturn (Optional .empty ());
114
110
115
111
eventDispatcher .handleEvent (Watcher .Action .MODIFIED , testCustomResource );
116
-
117
- verify (resourceOperation , never ()).lockResourceVersion (any ());
112
+ verify (customResourceReplaceFacade , never ()).replaceWithLock (any ());
118
113
}
119
114
120
115
@ Test
@@ -124,7 +119,7 @@ void addsFinalizerIfNotMarkedForDeletionAndEmptyCustomResourceReturned() {
124
119
eventDispatcher .handleEvent (Watcher .Action .MODIFIED , testCustomResource );
125
120
126
121
assertEquals (1 , testCustomResource .getMetadata ().getFinalizers ().size ());
127
- verify (resourceOperation , times (1 )).lockResourceVersion (any ());
122
+ verify (customResourceReplaceFacade , times (1 )).replaceWithLock (any ());
128
123
}
129
124
130
125
@ Test
@@ -135,7 +130,7 @@ void doesNotAddFinalizerIfOptionalIsReturnedButMarkedForDeletion() {
135
130
eventDispatcher .handleEvent (Watcher .Action .MODIFIED , testCustomResource );
136
131
137
132
assertEquals (0 , testCustomResource .getMetadata ().getFinalizers ().size ());
138
- verify (resourceOperation , never ()).lockResourceVersion (any ());
133
+ verify (customResourceReplaceFacade , never ()).replaceWithLock (any ());
139
134
}
140
135
141
136
private void markForDeletion (CustomResource customResource ) {
0 commit comments