/**
 * Copyright 2008 the original author or authors.
 *
 * 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.
 */
package net.sf.katta.node;

import static org.junit.Assert.assertEquals;

import java.util.List;

import net.sf.katta.coordinate.AddIndexCommandTest;
import net.sf.katta.coordinate.BalanceIndexCommandTest;
import net.sf.katta.testutil.PrintMethodNames;
import net.sf.katta.testutil.ZkTestSystem;

import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.ZkClient;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

public class NodeIntegrationTest {

  @Rule
  public ZkTestSystem _zk = ZkTestSystem.getInstance();
  @Rule
  public PrintMethodNames _printMethodNames = new PrintMethodNames();

  @Test
  public void testShutdown_shouldCleanupZkClientSubscriptions() {
    ZkClient zkClient = _zk.getZkClient();
    Node node = new Node(_zk.getInteractionProtocol(), new LuceneServer());
    node.start();

    zkClient.subscribeChildChanges("/", new IZkChildListener() {
      @Override
      public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
        // ignore
      }
    });

    node.shutdown();
    assertEquals(1, zkClient.numberOfListeners());
  }

  public static void main(String[] args) {
    Result result = org.junit.runner.JUnitCore.runClasses(AddIndexCommandTest.class, BalanceIndexCommandTest.class,
            NodeIntegrationTest.class);
    if (result.getFailureCount() > 0) {
      System.err.println("tests failed");
      List<Failure> failures = result.getFailures();
      for (Failure failure : failures) {
        System.out.println(failure.getMessage());
      }
    }
  }
}

@@ -707,116 +707,8 @@
 t;%0A%0A
-import net.sf.katta.coordinate.AddIndexCommandTest;%0Aimport net.sf.katta.coordinate.BalanceIndexCommandTest;%0A
 impo
@@ -750,16 +750,16 @@
 dNames;%0A
+
 import n
@@ -925,86 +925,8 @@
 est;
-%0Aimport org.junit.runner.Result;%0Aimport org.junit.runner.notification.Failure;
 %0A%0Apu
@@ -1613,449 +1613,6 @@
  %7D%0A%0A
-  public static void main(String%5B%5D args) %7B%0A    Result result = org.junit.runner.JUnitCore.runClasses(AddIndexCommandTest.class, BalanceIndexCommandTest.class,%0A            NodeIntegrationTest.class);%0A    if (result.getFailureCount() %3E 0) %7B%0A      System.err.println(%22tests failed%22);%0A      List%3CFailure%3E failures = result.getFailures();%0A      for (Failure failure : failures) %7B%0A        System.out.println(failure.getMessage());%0A      %7D%0A    %7D%0A  %7D%0A
 %7D%0A

fix compile error in test