package ch.difty.sipamato;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.util.tester.WicketTester;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SipamatoApplication.class)
@WebAppConfiguration
@DirtiesContext
public class SipamatoHomePageTest {

    private WicketTester tester;

    @Autowired
    private SipamatoApplication application;

    @Before
    public void setUp() {
        tester = new WicketTester(application);
    }

    @Test
    public void testRenderMyPage() {
        tester.startPage(SipamatoHomePage.class);
        tester.assertRenderedPage(SipamatoHomePage.class);
        tester.assertComponent("message", Label.class);
    }
}
@@ -71,16 +71,181 @@
 .Label;%0A
+import org.apache.wicket.protocol.http.WebApplication;%0Aimport org.apache.wicket.spring.test.ApplicationContextMock;%0Aimport org.apache.wicket.util.tester.FormTester;%0A
 import o
@@ -496,24 +496,300 @@
 figuration;%0A
+import org.springframework.security.authentication.AuthenticationManager;%0Aimport org.springframework.security.authentication.TestingAuthenticationToken;%0Aimport org.springframework.security.core.Authentication;%0Aimport org.springframework.security.core.AuthenticationException;%0A
 import org.s
@@ -971,16 +971,189 @@
 uration;
+%0Aimport org.springframework.test.util.ReflectionTestUtils;%0A%0Aimport com.giffing.wicket.spring.boot.starter.configuration.extensions.external.spring.security.SecureWebSession;
 %0A%0A@RunWi
@@ -1345,175 +1345,1684 @@
 ate 
-WicketTester tester;%0A%0A    @Autowired%0A    private SipamatoApplication application;%0A%0A    @Before%0A    public void setUp() %7B%0A        tester = new WicketTester(application)
+static final String USERNAME = %22admin%22;%0A    private static final String PASSWORD = %22admin%22;%0A%0A    private WicketTester tester;%0A%0A    @Autowired%0A    private SipamatoApplication application;%0A%0A    private ApplicationContextMock applicationContextMock;%0A%0A    @Before%0A    public void setUp() %7B%0A        applicationContextMock = new ApplicationContextMock();%0A        applicationContextMock.putBean(%22authenticationManager%22, new AuthenticationManager() %7B%0A%0A            @Override%0A            public Authentication authenticate(Authentication arg0) throws AuthenticationException %7B%0A                return new TestingAuthenticationToken(USERNAME, PASSWORD, %22USER%22, %22ADMIN%22);%0A            %7D%0A        %7D);%0A        ReflectionTestUtils.setField(application, %22applicationContext%22, applicationContextMock);%0A        tester = new WicketTester(application);%0A        login(USERNAME, PASSWORD);%0A        tester = new WicketTester(application);%0A    %7D%0A%0A    private void login(String username, String password) %7B%0A        SecureWebSession session = (SecureWebSession) tester.getSession();%0A        session.signOut();%0A        tester.startPage(LoginPage.class);%0A        FormTester formTester = tester.newFormTester(%22loginForm%22);%0A        formTester.setValue(%22username%22, username);%0A        formTester.setValue(%22password%22, password);%0A        formTester.submit();%0A        tester.assertNoErrorMessage();%0A        tester.assertRenderedPage(SipamatoHomePage.class);%0A    %7D%0A%0A    public WicketTester getTester() %7B%0A        return tester;%0A    %7D%0A%0A    public WebApplication getApplication() %7B%0A        return application;%0A    %7D%0A%0A    public ApplicationContextMock getApplicationContextMock() %7B%0A        return applicationContextMock
 ;%0A  

fix security test