/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shardingsphere.orchestration.core.common.listener;

import org.apache.shardingsphere.orchestration.center.CenterRepository;
import org.apache.shardingsphere.orchestration.center.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.event.ShardingOrchestrationEvent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Arrays;
import java.util.Collections;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public final class PostShardingCenterRepositoryEventListenerTest {
    
    @Mock
    private CenterRepository centerRepository;
    
    @Test
    public void assertWatch() {
        PostShardingCenterRepositoryEventListener postShardingCenterRepositoryEventListener = new PostShardingCenterRepositoryEventListener(centerRepository, Collections.singletonList("test")) {
            
            @Override
            protected ShardingOrchestrationEvent createShardingOrchestrationEvent(final DataChangedEvent event) {
                return mock(ShardingOrchestrationEvent.class);
            }
        };
        postShardingCenterRepositoryEventListener.watch();
        verify(centerRepository).watch(eq("test"), ArgumentMatchers.any());
    }
    
    @Test
    public void assertWatchMultipleKey() {
        PostShardingCenterRepositoryEventListener postShardingCenterRepositoryEventListener = new PostShardingCenterRepositoryEventListener(centerRepository, Arrays.asList("test", "dev")) {
            
            @Override
            protected ShardingOrchestrationEvent createShardingOrchestrationEvent(final DataChangedEvent event) {
                return mock(ShardingOrchestrationEvent.class);
            }
        };
        postShardingCenterRepositoryEventListener.watch();
        verify(centerRepository).watch(eq("test"), ArgumentMatchers.any());
        verify(centerRepository).watch(eq("dev"), ArgumentMatchers.any());
    }
}

@@ -1016,24 +1016,113 @@
 angedEvent;%0A
+import org.apache.shardingsphere.orchestration.center.listener.DataChangedEventListener;%0A
 import org.a
@@ -1465,18 +1465,155 @@
 atchers.
-eq
+any;%0Aimport static org.mockito.ArgumentMatchers.eq;%0Aimport static org.mockito.Mockito.anyString;%0Aimport static org.mockito.Mockito.doAnswer
 ;%0Aimport
@@ -2324,32 +2324,438 @@
    %7D%0A        %7D;%0A
+        doAnswer(invocationOnMock -%3E %7B%0A            DataChangedEventListener listener = (DataChangedEventListener) invocationOnMock.getArguments()%5B1%5D;%0A            listener.onChange(new DataChangedEvent(%22test%22, %22value%22, DataChangedEvent.ChangedType.UPDATED));%0A            return mock(DataChangedEventListener.class);%0A        %7D).when(centerRepository).watch(anyString(), any(DataChangedEventListener.class));%0A
         postShar
@@ -2786,32 +2786,68 @@
 tListener.watch(
+DataChangedEvent.ChangedType.UPDATED
 );%0A        verif
@@ -3412,56 +3412,536 @@
     
-postShardingCenterRepositoryEventListener.watch(
+doAnswer(invocationOnMock -%3E %7B%0A            DataChangedEventListener listener = (DataChangedEventListener) invocationOnMock.getArguments()%5B1%5D;%0A            listener.onChange(new DataChangedEvent(%22test%22, %22value%22, DataChangedEvent.ChangedType.UPDATED));%0A            return mock(DataChangedEventListener.class);%0A        %7D).when(centerRepository).watch(anyString(), any(DataChangedEventListener.class));%0A        postShardingCenterRepositoryEventListener.watch(DataChangedEvent.ChangedType.UPDATED, DataChangedEvent.ChangedType.DELETED
 );%0A 

Add call back test case in orchestration module.