001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.http.commons.session; 019 020import static org.fcrepo.http.commons.test.util.TestHelpers.setField; 021import static org.junit.Assert.assertNotNull; 022import static org.mockito.Mockito.when; 023 024import javax.servlet.http.HttpServletRequest; 025 026import org.fcrepo.kernel.api.FedoraSession; 027import org.junit.Before; 028import org.junit.Test; 029import org.junit.runner.RunWith; 030import org.mockito.Mock; 031import org.mockito.runners.MockitoJUnitRunner; 032 033/** 034 * <p>SessionProviderTest class.</p> 035 * 036 * @author awoods 037 */ 038@RunWith(MockitoJUnitRunner.class) 039public class SessionProviderTest { 040 041 SessionProvider testObj; 042 043 @Mock 044 private HttpSession mockSession; 045 046 @Mock 047 private FedoraSession mockFedoraSession; 048 049 @Mock 050 private SessionFactory mockSessionFactory; 051 052 @Mock 053 private HttpServletRequest mockHttpServletRequest; 054 055 @Before 056 public void setUp() { 057 when(mockSessionFactory.getInternalSession()).thenReturn(mockFedoraSession); 058 when(mockSessionFactory.getSession(mockHttpServletRequest)).thenReturn(mockSession); 059 testObj = new SessionProvider(mockHttpServletRequest); 060 setField(testObj, "sessionFactory", mockSessionFactory); 061 setField(testObj, "request", mockHttpServletRequest); 062 063 } 064 065 @Test 066 public void testProvide() { 067 final HttpSession inj = testObj.provide(); 068 assertNotNull("Didn't get a session", inj); 069 } 070}