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