@@ -0,0 +1,3476 @@
+/**%0A%0ACopyright 2010 OpenEngSB Division, Vienna University of Technology%0A%0ALicensed under the Apache License, Version 2.0 (the %22License%22);%0Ayou may not use this file except in compliance with the License.%0AYou may obtain a copy of the License at%0A%0Ahttp://www.apache.org/licenses/LICENSE-2.0%0A%0AUnless required by applicable law or agreed to in writing, software%0Adistributed under the License is distributed on an %22AS IS%22 BASIS,%0AWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0ASee the License for the specific language governing permissions and%0Alimitations under the License.%0A%0A */%0Apackage org.openengsb.ui.web;%0A%0Aimport static org.hamcrest.Matchers.is;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport java.util.Arrays;%0A%0Aimport org.apache.wicket.Page;%0Aimport org.apache.wicket.Request;%0Aimport org.apache.wicket.Response;%0Aimport org.apache.wicket.Session;%0Aimport org.apache.wicket.markup.html.form.DropDownChoice;%0Aimport org.apache.wicket.protocol.http.WebApplication;%0Aimport org.apache.wicket.spring.injection.annot.SpringComponentInjector;%0Aimport org.apache.wicket.spring.injection.annot.test.AnnotApplicationContextMock;%0Aimport org.apache.wicket.util.tester.WicketTester;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.openengsb.core.common.context.ContextCurrentService;%0A%0Apublic class BasePageTest %7B%0A%0A    private WicketTester tester;%0A    private ContextCurrentService contextService;%0A%0A    @Before%0A    public void setup() %7B%0A        tester = new WicketTester(new WebApplication() %7B%0A            @Override%0A            public Class%3C? extends Page%3E getHomePage() %7B%0A                return Index.class;%0A            %7D%0A%0A            @Override%0A            public Session newSession(Request request, Response response) %7B%0A                return new WicketSession(request);%0A            %7D%0A        %7D);%0A        contextService = mock(ContextCurrentService.class);%0A        AnnotApplicationContextMock appContext = new AnnotApplicationContextMock();%0A        appContext.putBean(contextService);%0A        tester.getApplication().addComponentInstantiationListener(%0A                new SpringComponentInjector(tester.getApplication(), appContext, false));%0A        when(contextService.getAvailableContexts()).thenReturn(Arrays.asList(new String%5B%5D %7B %22foo%22, %22bar%22 %7D));%0A        tester.startPage(new BasePage());%0A    %7D%0A%0A    @Test%0A    public void test_default_context_initialization() %7B%0A        tester.assertComponent(%22projectChoice%22, DropDownChoice.class);%0A        assertThat(%22foo%22, is(WicketSession.get().getThreadContextId()));%0A    %7D%0A%0A    @Test%0A    public void test_context_change() %7B%0A        tester.assertComponent(%22projectChoice%22, DropDownChoice.class);%0A        assertThat(%22foo%22, is(WicketSession.get().getThreadContextId()));%0A%0A        verify(contextService).setThreadLocalContext(%22foo%22);%0A%0A        @SuppressWarnings(%22unchecked%22)%0A        DropDownChoice%3CString%3E choice = (DropDownChoice%3CString%3E) tester%0A                .getComponentFromLastRenderedPage(%22projectChoice%22);%0A%0A        choice.setModelObject(%22bar%22);%0A        assertThat(%22bar%22, is(WicketSession.get().getThreadContextId()));%0A%0A        // this is a hack to simulate a reload and should be replaced when the%0A        // page is automatically reloaded on current thread context changes%0A        tester.startPage(new BasePage());%0A        verify(contextService).setThreadLocalContext(%22bar%22);%0A    %7D%0A%7D%0A

Add test for context choice.