@@ -0,0 +1,3011 @@
+/**%0A * Copyright 2010 OpenEngSB Division, Vienna University of Technology%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.openengsb.core.common.internal;%0A%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.mockito.Mockito.mock;%0A%0Aimport java.util.concurrent.Callable;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.Future;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.springframework.security.core.Authentication;%0Aimport org.springframework.security.core.context.SecurityContextHolder;%0A%0Apublic class ThreadLocalUT %7B%0A%0A    private ThreadLocal%3CString%3E local = new InheritableThreadLocal%3CString%3E();%0A    private ExecutorService pool = Executors.newSingleThreadExecutor();%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);%0A    %7D%0A%0A    @Test%0A    public void testPools() throws Exception %7B%0A        local.set(%22a%22);%0A        Authentication authentication = mock(Authentication.class);%0A        SecurityContextHolder.getContext().setAuthentication(authentication);%0A%0A        Callable%3CString%3E localCall = new Callable%3CString%3E() %7B%0A            @Override%0A            public String call() throws Exception %7B%0A                System.out.println(Thread.currentThread().getId());%0A                return local.get();%0A            %7D%0A        %7D;%0A        Callable%3CAuthentication%3E contextCall = new Callable%3CAuthentication%3E() %7B%0A            @Override%0A            public Authentication call() throws Exception %7B%0A                System.out.println(Thread.currentThread().getId());%0A                return SecurityContextHolder.getContext().getAuthentication();%0A            %7D%0A        %7D;%0A        Future%3CString%3E local1 = pool.submit(localCall);%0A        Future%3CAuthentication%3E auth1 = pool.submit(contextCall);%0A%0A        assertThat(local1.get(), is(local.get()));%0A        assertThat(auth1.get(), is(SecurityContextHolder.getContext().getAuthentication()));%0A%0A        local.set(%22a%22);%0A        authentication = mock(Authentication.class);%0A        SecurityContextHolder.getContext().setAuthentication(authentication);%0A%0A        Future%3CString%3E local2 = pool.submit(localCall);%0A        Future%3CAuthentication%3E auth2 = pool.submit(contextCall);%0A%0A        assertThat(local2.get(), is(local.get()));%0A        assertThat(auth2.get(), is(SecurityContextHolder.getContext().getAuthentication()));%0A    %7D%0A%0A%7D%0A

add Threadlocal-usetest