package com.github.phantomthief.zookeeper;

import static com.github.phantomthief.zookeeper.util.ZkUtils.removeFromZk;
import static org.apache.curator.framework.CuratorFrameworkFactory.newClient;

import java.io.IOException;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.retry.RetryForever;
import org.apache.curator.test.TestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

/**
 * @author w.vela
 * Created on 2017-08-25.
 */
public class BaseTest {

    protected static TestingServer testingServer;
    protected static CuratorFramework curatorFramework;
    private static String otherConnectionStr;

    @BeforeAll
    public static void init() throws Exception {
        if (otherConnectionStr == null) {
            testingServer = new TestingServer(true);
            curatorFramework = newClient(testingServer.getConnectString(), new RetryForever(1000));
        } else {
            curatorFramework = newClient(otherConnectionStr, new RetryForever(1000));
        }
        curatorFramework.start();
        removeFromZk(curatorFramework, "/test", true);
        curatorFramework.create().forPath("/test", "test1".getBytes());
        curatorFramework.create().forPath("/test/test1", "test1".getBytes());
        curatorFramework.create().forPath("/test/test2", "test2".getBytes());
        curatorFramework.create().forPath("/test/test3", "test3".getBytes());
        curatorFramework.create().forPath("/test/test3/test31", "test31".getBytes());
        curatorFramework.create().forPath("/test/test3/test32", "test32".getBytes());
        curatorFramework.create().forPath("/test/test3/test33", "test33".getBytes());
    }

    @AfterAll
    public static void destroy() throws IOException {
        curatorFramework.close();
        if (testingServer != null) {
            testingServer.close();
        }
    }
}

@@ -112,16 +112,92 @@
 FromZk;%0A
+import static org.apache.curator.framework.CuratorFrameworkFactory.builder;%0A
 import s
@@ -266,16 +266,16 @@
 Client;%0A
-
 %0Aimport 
@@ -750,16 +750,59 @@
 tionStr;
+%0A    private static boolean enableZk34Mode;
 %0A%0A    @B
@@ -1071,16 +1071,378 @@
  else %7B%0A
+            if (enableZk34Mode) %7B%0A                curatorFramework = builder()%0A                        .connectString(otherConnectionStr)%0A                        .zk34CompatibilityMode(true)%0A                        .dontUseContainerParents()%0A                        .retryPolicy(new RetryForever(1000))%0A                        .build();%0A            %7D else %7B%0A    
         
@@ -1511,32 +1511,46 @@
 Forever(1000));%0A
+            %7D%0A
         %7D%0A      

add zk34mode test switch.