/* 
 * Copyright (c) 2008-2010, Hazel Ltd. All Rights Reserved.
 * 
 * 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 com.hazelcast.spring;

import static com.hazelcast.client.HazelcastClientMapTest.getAllThreads;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hazelcast.core.HazelcastInstance;

public class TestApplicationContext {

    private Thread[] initialThreads;

    @Before
    public void before(){
        this.initialThreads = getAllThreads();
    }
    
    @After
    public void after(){
        List<Thread> listOfThreads = new ArrayList<Thread>(Arrays.asList(getAllThreads()));
        for (Thread thread : initialThreads) {
            listOfThreads.remove(thread);
        }
        for (final Thread thread : listOfThreads) {
            assertFalse(thread.getName().startsWith("hz."));
        }
    }
    
    @Test
    public void testNodeContext() throws Exception {
        final ClassPathXmlApplicationContext context = 
            new ClassPathXmlApplicationContext("classpath:/com/hazelcast/spring/fullcacheconfig-applicationContext-hazelcast.xml");
        final HazelcastInstance instance = (HazelcastInstance) context.getBean("instance");
        assertNotNull(instance);
        context.destroy();
    }
    
    @Test
    public void testNodeClientContext() throws Exception {
        final ClassPathXmlApplicationContext context = 
            new ClassPathXmlApplicationContext("classpath:/com/hazelcast/spring/node-client-applicationContext-hazelcast.xml");
        final HazelcastInstance instance = (HazelcastInstance) context.getBean("instance");
        assertNotNull(instance);
        
        final HazelcastInstance client = (HazelcastInstance) context.getBean("client");
        assertNotNull(client);
        context.destroy();
    }
}

@@ -671,101 +671,117 @@
 tic 
-com.hazelcast.client.HazelcastCli
+org.junit.Assert.*;%0A%0Aimport java.lang.managem
 ent
+.
 Ma
-pTest.getAllThreads;%0Aimport static org.junit.Assert.*;%0A
+nagementFactory;%0Aimport java.lang.management.ThreadMXBean;
 %0Aimp
@@ -2535,10 +2535,831 @@
 ;%0A    %7D%0A
+    %0A    static ThreadGroup rootThreadGroup = null;%0A%0A    public static ThreadGroup getRootThreadGroup() %7B%0A        if (rootThreadGroup != null)%0A            return rootThreadGroup;%0A        ThreadGroup tg = Thread.currentThread().getThreadGroup();%0A        ThreadGroup ptg;%0A        while ((ptg = tg.getParent()) != null)%0A            tg = ptg;%0A        return tg;%0A    %7D%0A    %0A    public static Thread%5B%5D getAllThreads() %7B%0A        final ThreadGroup root = getRootThreadGroup();%0A        final ThreadMXBean thbean = ManagementFactory.getThreadMXBean();%0A        int nAlloc = thbean.getThreadCount();%0A        int n = 0;%0A        Thread%5B%5D threads;%0A        do %7B%0A            nAlloc *= 2;%0A            threads = new Thread%5BnAlloc%5D;%0A            n = root.enumerate(threads, true);%0A        %7D while (n == nAlloc);%0A        return threads;%0A    %7D%0A
 %7D%0A

fix getAllThreads