// Path: src/test/java/se/kth/csc/config/WebSecurityConfigurationAware.java
// public abstract class WebSecurityConfigurationAware extends WebAppConfigurationAware {
// 
//     @Inject
//     private FilterChainProxy springSecurityFilterChain;
// 
//     @Before
//     public void before() {
//         this.mockMvc = webAppContextSetup(this.wac)
//                 .addFilters(this.springSecurityFilterChain).build();
//     }
// 
//     public MockHttpSession signInAs(final String principalName, final String... roles) {
//         MockHttpSession session = new MockHttpSession();
// 
//         final List<GrantedAuthority> authorities = Lists.newArrayList();
// 
//         for (String role : roles) {
//             authorities.add(new SimpleGrantedAuthority(role));
//         }
// 
//         session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
//                 new MockSecurityContext(new AbstractAuthenticationToken(authorities) {
//                     @Override
//                     public Object getCredentials() {
//                         return null;
//                     }
// 
//                     @Override
//                     public Object getPrincipal() {
//                         return principalName;
//                     }
//                 })
//         );
// 
//         return session;
//     }
// 
//     public class MockSecurityContext implements SecurityContext {
//         private Authentication authentication;
// 
//         public MockSecurityContext(Authentication authentication) {
//             this.authentication = authentication;
//         }
// 
//         @Override
//         public Authentication getAuthentication() {
//             return authentication;
//         }
// 
//         @Override
//         public void setAuthentication(Authentication authentication) {
//             this.authentication = authentication;
//         }
//     }
// }


import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.annotation.DirtiesContext;
import se.kth.csc.config.WebSecurityConfigurationAware;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
        MockHttpSession session2 = signInAs("u1testUser2", "admin");
        mockMvc.perform(get("/api/user/u1testUser").session(session1))
                .andExpect(status().isOk())
                .andExpect(jsonPath("name", is("u1testUser")))
                .andExpect(jsonPath("admin", is(false)));
        mockMvc.perform(get("/api/user/u1testUser2").session(session2))
                .andExpect(status().isOk())
                .andExpect(jsonPath("name", is("u1testUser2")))
                .andExpect(jsonPath("admin", is(true)));

        mockMvc.perform(put("/api/user/u1testUser2/role/admin").session(session1).contentType(MediaType.APPLICATION_JSON).content("false"))
                .andExpect(status().isForbidden());
        mockMvc.perform(get("/api/user/u1testUser").session(session1))
                .andExpect(status().isOk())
                .andExpect(jsonPath("name", is("u1testUser")))
                .andExpect(jsonPath("admin", is(false)));
        mockMvc.perform(get("/api/user/u1testUser2").session(session2))
                .andExpect(status().isOk())
                .andExpect(jsonPath("name", is("u1testUser2")))
                .andExpect(jsonPath("admin", is(true)));
    }

    @Test
    public void testAddQueue() throws Exception {
        MockHttpSession session = signInAs("u1testUser", "admin");
        mockMvc.perform(put("/api/queue/abc123").contentType(MediaType.APPLICATION_JSON).session(session).content("{\"title\":\"Test queue\"}"))
                .andExpect(status().isOk());
        mockMvc.perform(put("/api/queue/abc123/owner/u1testUser").session(session))
                .andExpect(status().isOk());
        mockMvc.perform(get("/api/queue/abc123").session(session))
// Path: src/test/java/se/kth/csc/config/WebSecurityConfigurationAware.java
// public abstract class WebSecurityConfigurationAware extends WebAppConfigurationAware {
// 
//     @Inject
//     private FilterChainProxy springSecurityFilterChain;
// 
//     @Before
//     public void before() {
//         this.mockMvc = webAppContextSetup(this.wac)
//                 .addFilters(this.springSecurityFilterChain).build();
//     }
// 
//     public MockHttpSession signInAs(final String principalName, final String... roles) {
//         MockHttpSession session = new MockHttpSession();
// 
//         final List<GrantedAuthority> authorities = Lists.newArrayList();
// 
//         for (String role : roles) {
//             authorities.add(new SimpleGrantedAuthority(role));
//         }
// 
//         session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
//                 new MockSecurityContext(new AbstractAuthenticationToken(authorities) {
//                     @Override
//                     public Object getCredentials() {
//                         return null;
//                     }
// 
//                     @Override
//                     public Object getPrincipal() {
//                         return principalName;
//                     }
//                 })
//         );
// 
//         return session;
//     }
// 
//     public class MockSecurityContext implements SecurityContext {
//         private Authentication authentication;
// 
//         public MockSecurityContext(Authentication authentication) {
//             this.authentication = authentication;
//         }
// 
//         @Override
//         public Authentication getAuthentication() {
//             return authentication;
//         }
// 
//         @Override
//         public void setAuthentication(Authentication authentication) {
//             this.authentication = authentication;
//         }
//     }
// }


// Path: src/test/java/se/kth/csc/controller/ApiControllerIT.java
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.annotation.DirtiesContext;
import se.kth.csc.config.WebSecurityConfigurationAware;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;

        MockHttpSession session2 = signInAs("u1testUser2", "admin");
        mockMvc.perform(get("/api/user/u1testUser").session(session1))
                .andExpect(status().isOk())
                .andExpect(jsonPath("name", is("u1testUser")))
                .andExpect(jsonPath("admin", is(false)));
        mockMvc.perform(get("/api/user/u1testUser2").session(session2))
                .andExpect(status().isOk())
                .andExpect(jsonPath("name", is("u1testUser2")))
                .andExpect(jsonPath("admin", is(true)));

        mockMvc.perform(put("/api/user/u1testUser2/role/admin").session(session1).contentType(MediaType.APPLICATION_JSON).content("false"))
                .andExpect(status().isForbidden());
        mockMvc.perform(get("/api/user/u1testUser").session(session1))
                .andExpect(status().isOk())
                .andExpect(jsonPath("name", is("u1testUser")))
                .andExpect(jsonPath("admin", is(false)));
        mockMvc.perform(get("/api/user/u1testUser2").session(session2))
                .andExpect(status().isOk())
                .andExpect(jsonPath("name", is("u1testUser2")))
                .andExpect(jsonPath("admin", is(true)));
    }

    @Test
    public void testAddQueue() throws Exception {
        MockHttpSession session = signInAs("u1testUser", "admin");
        mockMvc.perform(put("/api/queue/abc123").contentType(MediaType.APPLICATION_JSON).session(session).content("{\"title\":\"Test queue\"}"))
                .andExpect(status().isOk());
        mockMvc.perform(put("/api/queue/abc123/owner/u1testUser").session(session))
                .andExpect(status().isOk());
        mockMvc.perform(get("/api/queue/abc123").session(session))
                .andExpect(status().isOk())