1616
1717import com .meterware .httpunit .Base64 ;
1818import com .meterware .simplestub .Memento ;
19- import io .kubernetes .client .openapi .models .V1ObjectMeta ;
2019import io .kubernetes .client .openapi .models .V1Service ;
21- import io .kubernetes .client .openapi .models .V1ServiceSpec ;
20+ import io .kubernetes .client .openapi .models .V1ServiceBuilder ;
2221import oracle .kubernetes .operator .DomainProcessorTestSetup ;
2322import oracle .kubernetes .operator .helpers .DomainPresenceInfo ;
2423import oracle .kubernetes .operator .helpers .KubernetesTestSupport ;
@@ -76,10 +75,6 @@ class ReadHealthStepTest {
7675 private static final String DYNAMIC_MANAGED_SERVER2 = "dyn-managed-server2" ;
7776
7877 private static final ClassCastException CLASSCAST_EXCEPTION = new ClassCastException ("" );
79- static final String MS1_URL = "http://127.0.0.1:7001" ;
80- private final V1Service service = createStub (V1ServiceStub .class );
81- private final V1Service headlessService = createStub (V1HeadlessServiceStub .class );
82- private final V1Service headlessMSService = createStub (V1HeadlessMSServiceStub .class );
8378 private final List <LogRecord > logRecords = new ArrayList <>();
8479 private final List <Memento > mementos = new ArrayList <>();
8580 private final KubernetesTestSupport testSupport = new KubernetesTestSupport ();
@@ -123,22 +118,15 @@ private int getRemainingServersToRead(Packet packet) {
123118 return ((AtomicInteger ) packet .get (REMAINING_SERVERS_HEALTH_TO_READ )).get ();
124119 }
125120
126- private void selectServer (String serverName ) {
127- selectServer ( serverName , false );
121+ private V1Service createService (String serverName ) {
122+ return new V1ServiceBuilder (). withNewMetadata (). withName ( serverName ). withNamespace ( "Test" ). endMetadata (). build ( );
128123 }
129124
130- private void selectServer (String serverName , V1Service service ) {
125+ private V1Service selectServer (String serverName ) {
126+ V1Service service = createService (serverName );
131127 testSupport .addToPacket (SERVER_NAME , serverName );
132128 info .setServerService (serverName , service );
133- }
134-
135- private void selectServer (String serverName , boolean headless ) {
136- testSupport .addToPacket (SERVER_NAME , serverName );
137- if (headless ) {
138- info .setServerService (serverName , headlessService );
139- } else {
140- info .setServerService (serverName , service );
141- }
129+ return service ;
142130 }
143131
144132 @ AfterEach
@@ -149,7 +137,7 @@ public void tearDown() {
149137 @ Test
150138 void whenReadAdminServerHealth_decrementRemainingServers () {
151139 selectServer (ADMIN_NAME );
152- defineResponse (200 , OK_RESPONSE , "http://127.0.0.1 :3456" );
140+ defineResponse (200 , OK_RESPONSE , "http://" + ADMIN_NAME + ".Test :3456" );
153141
154142 Packet packet = testSupport .runSteps (readHealthStep );
155143
@@ -165,9 +153,9 @@ private void defineResponse(int status, String body, @Nonnull String url) {
165153
166154 @ Test
167155 void whenReadConfiguredManagedServerHealth_decrementRemainingServers () {
168- selectServer (CONFIGURED_MANAGED_SERVER1 );
169- configureServiceWithClusterName (CONFIGURED_CLUSTER_NAME );
170- defineResponse (200 , OK_RESPONSE , MS1_URL );
156+ V1Service service = selectServer (CONFIGURED_MANAGED_SERVER1 );
157+ configureServiceWithClusterName (CONFIGURED_CLUSTER_NAME , service );
158+ defineResponse (200 , OK_RESPONSE , "http://" + CONFIGURED_MANAGED_SERVER1 + ".Test:7001" );
171159
172160 Packet packet = testSupport .runSteps (readHealthStep );
173161
@@ -179,9 +167,9 @@ void whenReadConfiguredManagedServerHealth_decrementRemainingServers() {
179167
180168 @ Test
181169 void whenReadDynamicManagedServerHealth_decrementRemainingServers () {
182- selectServer (DYNAMIC_MANAGED_SERVER1 );
183- configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME );
184- defineResponse (200 , OK_RESPONSE , MS1_URL );
170+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER1 );
171+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
172+ defineResponse (200 , OK_RESPONSE , "http://" + DYNAMIC_MANAGED_SERVER1 + ".Test:7001" );
185173
186174 Packet packet = testSupport .runSteps (readHealthStep );
187175
@@ -192,7 +180,7 @@ void whenReadDynamicManagedServerHealth_decrementRemainingServers() {
192180 void whenServerRunning_verifyServerHealth () {
193181 selectServer (MANAGED_SERVER1 );
194182
195- defineResponse (200 , OK_RESPONSE , "http://127.0.0.1 :8001" );
183+ defineResponse (200 , OK_RESPONSE , "http://" + MANAGED_SERVER1 + ".Test :8001" );
196184
197185 Packet packet = testSupport .runSteps (readHealthStep );
198186
@@ -210,7 +198,7 @@ private Map<String, String> getServerStateMap(Packet packet) {
210198
211199 @ Test
212200 void whenAdminPodIPNull_verifyServerHealth () {
213- selectServer (ADMIN_NAME , true );
201+ selectServer (ADMIN_NAME );
214202 defineResponse (200 , OK_RESPONSE , "http://admin-server.Test:3456" );
215203
216204 Packet packet = testSupport .runSteps (readHealthStep );
@@ -220,7 +208,7 @@ void whenAdminPodIPNull_verifyServerHealth() {
220208
221209 @ Test
222210 void whenAdminPodIPNull_requestSendWithCredentials () {
223- selectServer (ADMIN_NAME , true );
211+ selectServer (ADMIN_NAME );
224212 defineResponse (200 , OK_RESPONSE , "http://admin-server.Test:3456" );
225213
226214 testSupport .runSteps (readHealthStep );
@@ -244,7 +232,7 @@ private String expectedAuthorizationHeader() {
244232 void whenServerOverloaded_verifyServerHealth () {
245233 selectServer (MANAGED_SERVER1 );
246234
247- defineResponse (500 , "" , "http://127.0.0.1 :8001" );
235+ defineResponse (500 , "" , "http://" + MANAGED_SERVER1 + ".Test :8001" );
248236
249237 Packet packet = testSupport .runSteps (readHealthStep );
250238
@@ -257,7 +245,7 @@ void whenServerOverloaded_verifyServerHealth() {
257245 void whenUnableToReadHealth_verifyNotAvailable () {
258246 selectServer (MANAGED_SERVER1 );
259247
260- defineResponse (404 , "" , MS1_URL );
248+ defineResponse (404 , "" , "http://" + MANAGED_SERVER1 + ".Test:8001" );
261249
262250 Packet packet = testSupport .runSteps (readHealthStep );
263251
@@ -268,7 +256,8 @@ void whenUnableToReadHealth_verifyNotAvailable() {
268256
269257 @ Test
270258 void whenServerConfiguredWithServerListenPortOnly_readHealthUsingServerListenPort () {
271- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
259+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
260+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
272261 WlsServerConfig server = getDynamicClusterServer2 ();
273262 server .setListenPort (8001 );
274263 defineExpectedURLInResponse ("http" , 8001 );
@@ -280,7 +269,8 @@ void whenServerConfiguredWithServerListenPortOnly_readHealthUsingServerListenPor
280269
281270 @ Test
282271 void whenServerConfiguredWithSSLPortOnly_readHealthUsingSSLPort () {
283- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
272+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
273+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
284274 WlsServerConfig server = getDynamicClusterServer2 ();
285275 server .setSslListenPort (7002 );
286276 defineExpectedURLInResponse ("https" , 7002 );
@@ -292,7 +282,8 @@ void whenServerConfiguredWithSSLPortOnly_readHealthUsingSSLPort() {
292282
293283 @ Test
294284 void whenServerConfiguredWithServerListenPortAndSSLPort_readHealthUsingSSLPort () {
295- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
285+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
286+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
296287 WlsServerConfig server = getDynamicClusterServer2 ();
297288 server .setListenPort (8001 );
298289 server .setSslListenPort (7002 );
@@ -305,7 +296,8 @@ void whenServerConfiguredWithServerListenPortAndSSLPort_readHealthUsingSSLPort()
305296
306297 @ Test
307298 void whenServerConfiguredWithServerListenPortAndNonAdminNAP_readHealthUsingServerListenPort () {
308- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
299+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
300+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
309301 WlsServerConfig server = getDynamicClusterServer2 ();
310302 server .setListenPort (8001 );
311303 server .addNetworkAccessPoint (new NetworkAccessPoint ("nap1" , "t3" , 9001 , 9001 ));
@@ -318,7 +310,8 @@ void whenServerConfiguredWithServerListenPortAndNonAdminNAP_readHealthUsingServe
318310
319311 @ Test
320312 void whenServerConfiguredWithServerSSLPortAndNonAdminNAP_readHealthUsingSSLPort () {
321- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
313+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
314+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
322315 WlsServerConfig server = getDynamicClusterServer2 ();
323316 server .setSslListenPort (7002 );
324317 server .addNetworkAccessPoint (new NetworkAccessPoint ("nap1" , "t3" , 9001 , 9001 ));
@@ -331,7 +324,8 @@ void whenServerConfiguredWithServerSSLPortAndNonAdminNAP_readHealthUsingSSLPort(
331324
332325 @ Test
333326 void whenServerConfiguredWithSSLPortAndAdminNAP_readHealthUsingAdminNAPPort () {
334- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
327+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
328+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
335329 WlsServerConfig server = getDynamicClusterServer2 ();
336330 server .setSslListenPort (7002 );
337331 server .addNetworkAccessPoint (new NetworkAccessPoint ("admin" , "admin" , 8888 , 8888 ));
@@ -344,7 +338,8 @@ void whenServerConfiguredWithSSLPortAndAdminNAP_readHealthUsingAdminNAPPort() {
344338
345339 @ Test
346340 void whenServerConfiguredWithServerListenPortAndAdminNAP_readHealthUsingAdminNAPPort () {
347- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
341+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
342+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
348343 WlsServerConfig server = getDynamicClusterServer2 ();
349344 server .setListenPort (8001 );
350345 server .setListenPort (null );
@@ -358,7 +353,8 @@ void whenServerConfiguredWithServerListenPortAndAdminNAP_readHealthUsingAdminNAP
358353
359354 @ Test
360355 void whenServerConfiguredWithNonAdminNAPOnly_readHealthFailed () {
361- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
356+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
357+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
362358 WlsServerConfig server = getDynamicClusterServer2 ();
363359 server .addNetworkAccessPoint (new NetworkAccessPoint ("nap1" , "t3" , 9001 , 9001 ));
364360 defineExpectedURLInResponse ("http" , 9001 );
@@ -398,7 +394,7 @@ void whenAuthorizedToReadHealthAndThenWait_verifySecretCleared() {
398394 void whenNotAuthorizedToReadHealth_verifySecretCleared () {
399395 selectServer (MANAGED_SERVER1 );
400396
401- defineResponse (403 , "" , "http://127.0.0.1 :8001" );
397+ defineResponse (403 , "" , "http://" + MANAGED_SERVER1 + ".Test :8001" );
402398
403399 testSupport .runSteps (readHealthStep );
404400
@@ -418,37 +414,8 @@ private WlsServerConfig getDynamicClusterServer2() {
418414 return wlsDomainConfig .getClusterConfig (DYNAMIC_CLUSTER_NAME ).getServerConfigs ().get (1 );
419415 }
420416
421- public abstract static class V1ServiceStub extends V1Service {
422-
423- @ Override
424- public V1ServiceSpec getSpec () {
425- return new V1ServiceSpec ().clusterIP ("127.0.0.1" );
426- }
427- }
428-
429- public abstract static class V1HeadlessServiceStub extends V1Service {
430-
431- @ Override
432- public V1ObjectMeta getMetadata () {
433- return new V1ObjectMeta ().name (ADMIN_NAME ).namespace ("Test" );
434- }
435-
436- @ Override
437- public V1ServiceSpec getSpec () {
438- return new V1ServiceSpec ().clusterIP ("None" );
439- }
440- }
441-
442- public abstract static class V1HeadlessMSServiceStub extends V1Service {
443- @ Override
444- public V1ObjectMeta getMetadata () {
445- return new V1ObjectMeta ().name (DYNAMIC_MANAGED_SERVER2 ).namespace ("Test" )
446- .putLabelsItem (CLUSTERNAME_LABEL , DYNAMIC_CLUSTER_NAME );
447- }
448- }
449-
450- private void configureServiceWithClusterName (String clusterName ) {
451- service .setMetadata (new V1ObjectMeta ().putLabelsItem (CLUSTERNAME_LABEL , clusterName ));
417+ private void configureServiceWithClusterName (String clusterName , V1Service service ) {
418+ service .getMetadata ().putLabelsItem (CLUSTERNAME_LABEL , clusterName );
452419 }
453420
454421}
0 commit comments