@@ -0,0 +1,3475 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one%0A * or more contributor license agreements.  See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership.  The ASF licenses this file%0A * to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance%0A * with the License.  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,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Apackage nl.surfnet.coin.teams.service.interceptor;%0A%0Aimport static junit.framework.Assert.assertFalse;%0Aimport static junit.framework.Assert.assertTrue;%0Aimport static junit.framework.Assert.fail;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport javax.servlet.ServletException;%0A%0Aimport nl.surfnet.coin.teams.interceptor.LoginInterceptor;%0Aimport nl.surfnet.coin.teams.service.TeamPersonService;%0Aimport nl.surfnet.coin.teams.util.TeamEnvironment;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.opensocial.models.Person;%0Aimport org.springframework.mock.web.MockHttpServletRequest;%0Aimport org.springframework.mock.web.MockHttpServletResponse;%0A%0A/**%0A * Test for %7B@link LoginInterceptor%7D%0A */%0Apublic class LoginInterceptorTest %7B%0A%0A  @Test%0A  public void testPreHandle() throws Exception %7B%0A    String remoteUser = %22urn:collab:person:surfnet.nl:hansz%22;%0A%0A    LoginInterceptor interceptor = new LoginInterceptor();%0A%0A    TeamPersonService personService = mock(TeamPersonService.class);%0A    Person person = new Person();%0A    person.setField(%22id%22, remoteUser);%0A    when(personService.getPerson(remoteUser)).thenReturn(person);%0A    interceptor.setPersonService(personService);%0A%0A    interceptor.setPersonService(personService);%0A    interceptor.setTeamEnvironment(new TeamEnvironment());%0A%0A    MockHttpServletRequest request = new MockHttpServletRequest();%0A    request.addHeader(%22REMOTE_USER%22, remoteUser);%0A    request.addHeader(%22coin-user-status%22, %22member%22);%0A    MockHttpServletResponse response = new MockHttpServletResponse();%0A    boolean loggedIn = interceptor.preHandle(request, response, null);%0A    assertTrue(loggedIn);%0A    Assert.assertNotNull(request.getSession().getAttribute(%22person%22));%0A  %7D%0A%0A  @Test%0A  public void testLoginFail() throws Exception %7B%0A    String remoteUser = %22urn:collab:person:surfnet.nl:hansz%22;%0A%0A    LoginInterceptor interceptor = new LoginInterceptor();%0A%0A    TeamPersonService personService = mock(TeamPersonService.class);%0A    when(personService.getPerson(remoteUser)).thenReturn(null);%0A    interceptor.setPersonService(personService);%0A%0A    interceptor.setPersonService(personService);%0A    interceptor.setTeamEnvironment(new TeamEnvironment());%0A%0A    MockHttpServletRequest request = new MockHttpServletRequest();%0A    request.addHeader(%22REMOTE_USER%22, remoteUser);%0A    request.addHeader(%22coin-user-status%22, %22member%22);%0A    MockHttpServletResponse response = new MockHttpServletResponse();%0A    boolean loggedIn = false;%0A    try %7B%0A      loggedIn = interceptor.preHandle(request, response, null);%0A      fail(%22Unknown user %22 + remoteUser);%0A    %7D catch (ServletException e) %7B%0A      assertFalse(loggedIn);%0A    %7D%0A  %7D%0A%7D%0A

Add LoginInterceptor tests