1414import org .junit .Before ;
1515import org .junit .Test ;
1616
17+ import static oracle .kubernetes .operator .WebLogicConstants .SHUTDOWN_STATE ;
1718import static oracle .kubernetes .weblogic .domain .model .DomainConditionMatcher .hasCondition ;
1819import static oracle .kubernetes .weblogic .domain .model .DomainConditionType .Available ;
1920import static oracle .kubernetes .weblogic .domain .model .DomainConditionType .Failed ;
@@ -259,25 +260,86 @@ public void verifyThat_addServers_serverSortedInExpectedOrdering() {
259260 domainStatus .addServer (cluster1Server1 ).addServer (cluster2Server1 )
260261 .addServer (cluster1Server2 ).addServer (standAloneServerA ).addServer (adminServer );
261262
262- assertThat (domainStatus .servers ,
263+ assertThat (domainStatus .getServers () ,
263264 contains (adminServer , standAloneServerA , cluster1Server1 , cluster1Server2 , cluster2Server1 ));
264265 }
265266
266267 @ Test
267268 public void verifyThat_setServers_serverSortedInExpectedOrdering () {
268- ServerStatus cluster1Server1 = new ServerStatus ().withClusterName ("cluster-1" ).withServerName ("cluster1-server1" );
269- ServerStatus cluster1Server2 = new ServerStatus ().withClusterName ("cluster-1" ).withServerName ("cluster1-server2" );
270- ServerStatus cluster2Server1 = new ServerStatus ().withClusterName ("cluster-2" ).withServerName ("cluster2-server1" );
271- ServerStatus adminServer = new ServerStatus ().withServerName ("admin-server" ).withIsAdminServer (true );
272- ServerStatus standAloneServerA = new ServerStatus ().withServerName ("a" );
269+ ServerStatus cluster1Server1 = createStatus ().withClusterName ("cluster-1" ).withServerName ("cluster1-server1" );
270+ ServerStatus cluster1Server2 = createStatus ().withClusterName ("cluster-1" ).withServerName ("cluster1-server2" );
271+ ServerStatus cluster2Server1 = createStatus ().withClusterName ("cluster-2" ).withServerName ("cluster2-server1" );
272+ ServerStatus adminServer = createStatus ().withServerName ("admin-server" ).withIsAdminServer (true );
273+ ServerStatus standAloneServerA = createStatus ().withServerName ("a" );
273274
274275 domainStatus .setServers (Arrays .asList (cluster1Server1 ,
275276 cluster2Server1 , cluster1Server2 , standAloneServerA , adminServer ));
276277
277- assertThat (domainStatus .servers ,
278+ assertThat (domainStatus .getServers () ,
278279 contains (adminServer , standAloneServerA , cluster1Server1 , cluster1Server2 , cluster2Server1 ));
279280 }
280281
282+ private ServerStatus createStatus () {
283+ return new ServerStatus ().withState ("a" );
284+ }
285+
286+ @ Test
287+ public void whenMatchingServersExist_setServersUpdatesState () {
288+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ));
289+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ));
290+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("3" ).withState ("state1" ));
291+
292+ domainStatus .setServers (Arrays .asList (
293+ new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ),
294+ new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ),
295+ new ServerStatus ().withClusterName ("1" ).withServerName ("3" ).withState ("state2" )
296+ ));
297+
298+ assertThat (getServer ("1" , "1" ).getState (), equalTo ("state1" ));
299+ assertThat (getServer ("1" , "2" ).getState (), equalTo ("state1" ));
300+ assertThat (getServer ("1" , "3" ).getState (), equalTo ("state2" ));
301+ }
302+
303+ @ Test
304+ public void whenSetServerIncludesServerWithoutStateAndNoExistingState_defaultToSHUTDOWN () {
305+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ));
306+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ));
307+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("3" ).withState ("state1" ));
308+
309+ domainStatus .setServers (Arrays .asList (
310+ new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ),
311+ new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ),
312+ new ServerStatus ().withClusterName ("1" ).withServerName ("3" ).withState ("state2" ),
313+ new ServerStatus ().withClusterName ("2" ).withServerName ("1" )
314+ ));
315+
316+ assertThat (getServer ("2" , "1" ).getState (), equalTo (SHUTDOWN_STATE ));
317+ }
318+
319+ @ Test
320+ public void whenSetServerIncludesServerWithoutStateAndHasExistingState_preserveIt () {
321+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ));
322+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ));
323+ domainStatus .addServer (new ServerStatus ().withClusterName ("1" ).withServerName ("3" ).withState ("state1" ));
324+
325+ domainStatus .setServers (Arrays .asList (
326+ new ServerStatus ().withClusterName ("1" ).withServerName ("1" ).withState ("state1" ),
327+ new ServerStatus ().withClusterName ("1" ).withServerName ("2" ).withState ("state1" ),
328+ new ServerStatus ().withClusterName ("1" ).withServerName ("3" )
329+ ));
330+
331+ assertThat (getServer ("1" , "3" ).getState (), equalTo ("state1" ));
332+ }
333+
334+ private ServerStatus getServer (String clusterName , String serverName ) {
335+ return domainStatus .getServers ()
336+ .stream ()
337+ .filter (s -> s .getClusterName ().equals (clusterName ))
338+ .filter (s -> s .getServerName ().equals (serverName ))
339+ .findFirst ()
340+ .orElse (null );
341+ }
342+
281343 @ Test
282344 public void verifyThat_getServers_serverInExpectedOrdering () {
283345 ServerStatus cluster1Server1 = new ServerStatus ().withClusterName ("cluster-1" ).withServerName ("cluster1-server1" );
@@ -303,7 +365,7 @@ public void verifyThat_addClusters_clustersSortedInExpectedOrdering() {
303365
304366 domainStatus .addCluster (cluster10 ).addCluster (cluster1 ).addCluster (cluster2 );
305367
306- assertThat (domainStatus .clusters , contains (cluster1 , cluster2 , cluster10 ));
368+ assertThat (domainStatus .getClusters () , contains (cluster1 , cluster2 , cluster10 ));
307369 }
308370
309371 @ Test
@@ -314,9 +376,7 @@ public void verifyThat_setClusters_clustersSortedInExpectedOrdering() {
314376
315377 domainStatus .setClusters (Arrays .asList (cluster10 , cluster1 , cluster2 ));
316378
317- List <ClusterStatus > clusterStatuses = domainStatus .clusters ;
318-
319- assertThat (clusterStatuses , contains (cluster1 , cluster2 , cluster10 ));
379+ assertThat (domainStatus .getClusters (), contains (cluster1 , cluster2 , cluster10 ));
320380 }
321381
322382 @ Test
0 commit comments