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