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 */
016
017package org.fcrepo.client;
018
019import static java.net.URI.create;
020import static org.fcrepo.client.TestUtils.baseUrl;
021import static org.junit.Assert.assertFalse;
022import static org.mockito.Matchers.any;
023import static org.mockito.Matchers.eq;
024import static org.mockito.Mockito.verify;
025import static org.mockito.Mockito.when;
026
027import java.net.URI;
028
029import org.apache.http.client.methods.HttpRequestBase;
030import org.junit.Before;
031import org.junit.Test;
032import org.junit.runner.RunWith;
033import org.mockito.ArgumentCaptor;
034import org.mockito.Mock;
035import org.mockito.runners.MockitoJUnitRunner;
036
037/**
038 * @author escowles
039 */
040@RunWith(MockitoJUnitRunner.class)
041public class HeadBuilderTest {
042
043    @Mock
044    private FcrepoClient client;
045
046    @Mock
047    private FcrepoResponse fcrepoResponse;
048
049    private HeadBuilder testBuilder;
050
051    private URI uri;
052
053    @Before
054    public void setUp() throws Exception {
055        when(client.executeRequest(any(URI.class), any(HttpRequestBase.class)))
056                .thenReturn(fcrepoResponse);
057
058        uri = create(baseUrl);
059        testBuilder = new HeadBuilder(uri, client);
060    }
061
062    @Test
063    public void testHead() throws Exception {
064        testBuilder.perform();
065        final ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);
066        verify(client).executeRequest(eq(uri), requestCaptor.capture());
067    }
068
069    @Test
070    public void testDisableRedirects() throws Exception {
071        testBuilder.disableRedirects();
072        assertFalse(testBuilder.request.getConfig().isRedirectsEnabled());
073    }
074}