/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed 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.
 * </p>
 */

package io.shardingsphere.orchestration.internal;

import io.shardingsphere.orchestration.config.OrchestrationConfiguration;
import io.shardingsphere.orchestration.reg.api.RegistryCenter;
import io.shardingsphere.orchestration.reg.api.RegistryCenterConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import java.lang.reflect.Field;
import java.util.Arrays;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public final class OrchestrationFacadeTest {
    
    private OrchestrationFacade orchestrationFacade;
    
    @Mock
    private RegistryCenter regCenter;
    
    @Before
    public void setUp() throws ReflectiveOperationException {
        orchestrationFacade = new OrchestrationFacade(getOrchestrationConfiguration(), Arrays.asList("sharding_db", "masterslave_db"));
        setRegistryForOrchestrationFacade();
    }
    
    private void setRegistryForOrchestrationFacade() throws ReflectiveOperationException {
        Field field = orchestrationFacade.getClass().getDeclaredField("regCenter");
        field.setAccessible(true);
        field.set(orchestrationFacade, regCenter);
    }
    
    private OrchestrationConfiguration getOrchestrationConfiguration() {
        return new OrchestrationConfiguration("test", new RegistryCenterConfiguration(), true);
    }
    
    @Test
    public void assertInitWithParameters() {
    }
    
    @Test
    public void assertInitWithoutParameters() {
        orchestrationFacade.init();
        verify(regCenter).persistEphemeral(anyString(), anyString());
    }
    
    @Test
    public void testClose() {
    }
}

@@ -873,24 +873,91 @@
 figuration;%0A
+import io.shardingsphere.orchestration.reg.listener.EventListener;%0A
 import org.j
@@ -1154,16 +1154,64 @@
 rrays;%0A%0A
+import static org.mockito.ArgumentMatchers.any;%0A
 import s
@@ -1256,16 +1256,63 @@
 String;%0A
+import static org.mockito.ArgumentMatchers.eq;%0A
 import s
@@ -1763,36 +1763,34 @@
      setRegistry
-ForO
+(o
 rchestrationFaca
@@ -1791,17 +1791,16 @@
 onFacade
-(
 );%0A    %7D
@@ -1837,31 +1837,28 @@
 stry
-ForOrchestrationFacade(
+(final Object target
 ) th
@@ -1915,35 +1915,22 @@
 field = 
-orchestrationFacade
+target
 .getClas
@@ -2017,35 +2017,22 @@
 eld.set(
-orchestrationFacade
+target
 , regCen
@@ -2454,24 +2454,570 @@
 yString());%0A
+        verify(regCenter).persist(%22/test/state/datasources%22, %22%22);%0A        verify(regCenter).watch(eq(%22/test/config/authentication%22), any(EventListener.class));%0A        verify(regCenter).watch(eq(%22/test/config/configmap%22), any(EventListener.class));%0A        verify(regCenter).watch(eq(%22/test/config/schema/sharding_db/datasource%22), any(EventListener.class));%0A        verify(regCenter).watch(eq(%22/test/config/props%22), any(EventListener.class));%0A        verify(regCenter).watch(eq(%22/test/config/schema/sharding_db/rule%22), any(EventListener.class));%0A
     %7D%0A    %0A 

add setRegistry()