package pl.java.scalatech.test;

import static org.junit.Assert.assertEquals;

import org.junit.After;
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.context.ApplicationContext;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import pl.java.scalatech.config.MongoDBConfig;
import pl.java.scalatech.config.MongoRepositoryConfig;
import pl.java.scalatech.config.SecurityBasicConfig;
import pl.java.scalatech.config.ServiceConfig;
import pl.java.scalatech.service.MyService;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { SecurityBasicConfig.class, MongoRepositoryConfig.class, MongoDBConfig.class, ServiceConfig.class })
public class SampleSecureApplicationTests {
    @Autowired
    private MyService service;
    @Autowired
    private ApplicationContext context;
    private Authentication authentication;
    

    @Before
    public void init() {
        AuthenticationManager authenticationManager = this.context.getBean(AuthenticationManager.class);
        this.authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken("user", "slawek"));
    }

    @After
    public void close() {
        SecurityContextHolder.clearContext();
    }

    @Test
    public void shouldSecure() throws Exception {
        SecurityContextHolder.getContext().setAuthentication(this.authentication);
        assertEquals(this.service.secure(), MyService.RESULT);

    }

    @Test
    public void shouldAuthenticated() throws Exception {
        SecurityContextHolder.getContext().setAuthentication(this.authentication);
        assertEquals(this.service.secure(), MyService.RESULT);
    }

    @Test
    public void shouldPreauth() throws Exception {
        SecurityContextHolder.getContext().setAuthentication(this.authentication);
        assertEquals(this.service.authorized(), MyService.RESULT);
    }

    @Test(expected = AccessDeniedException.class)
    public void shouldDenied() throws Exception {

        SecurityContextHolder.getContext().setAuthentication(this.authentication);
        assertEquals(this.service.denied(), MyService.RESULT);
    }

}
@@ -48,35 +48,131 @@
 org.
-junit.Assert.assertEquals;%0A
+fest.assertions.Assertions.assertThat;%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport org.fest.assertions.Assertions;
 %0Aimp
@@ -1225,29 +1225,45 @@
 = %7B Security
-Basic
+Config.class, MongoDB
 Config.class
@@ -1292,37 +1292,16 @@
 g.class,
- MongoDBConfig.class,
  Service
@@ -1503,21 +1503,16 @@
 ication;
-%0A    
 %0A%0A    @B
@@ -1538,24 +1538,25 @@
 id init() %7B%0A
+%0A
         Auth
@@ -1758,27 +1758,286 @@
 en(%22
-user%22, %22slawek%22)
+przodownik%22, %22test%22));%0A%0A    %7D%0A%0A    @Test%0A    public void shouldRoleSetWork() %7B%0A%0A        assertThat(authentication.getAuthorities()).hasSize(1);%0A        assertThat(authentication.getName()).isEqualTo(%22przodownik%22);%0A        assertThat(authentication.isAuthenticated()).isTrue(
 );%0A
+%0A
     
@@ -2338,229 +2338,8 @@
 LT);
-%0A%0A    %7D%0A%0A    @Test%0A    public void shouldAuthenticated() throws Exception %7B%0A        SecurityContextHolder.getContext().setAuthentication(this.authentication);%0A        assertEquals(this.service.secure(), MyService.RESULT);
 %0A   
@@ -2660,17 +2660,16 @@
 ption %7B%0A
-%0A
         
@@ -2732,32 +2732,394 @@
 s.authentication
+);%0A        assertEquals(this.service.denied(), MyService.RESULT);%0A    %7D%0A%0A    @Test(expected = AccessDeniedException.class)%0A    public void shouldAuthenticated() throws Exception %7B%0A        SecurityContextHolder.getContext().setAuthentication(this.authentication);%0A        System.err.println(SecurityContextHolder.getContext().getAuthentication().isAuthenticated()
 );%0A        asser
@@ -3131,38 +3131,37 @@
 ls(this.service.
-denied
+other
 (), MyService.RE

change test