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.FedoraHeaderConstants.DESTINATION; 021import static org.fcrepo.client.TestUtils.baseUrl; 022import static org.junit.Assert.assertEquals; 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 bbpennel 040 */ 041@RunWith(MockitoJUnitRunner.class) 042public class MoveBuilderTest { 043 044 @Mock 045 private FcrepoClient client; 046 047 @Mock 048 private FcrepoResponse fcrepoResponse; 049 050 private MoveBuilder testBuilder; 051 052 private URI uri; 053 054 private URI destUri; 055 056 public static final String destUrl = "http://localhost:8080/rest/dest/foo"; 057 058 @Before 059 public void setUp() throws Exception { 060 when(client.executeRequest(any(URI.class), any(HttpRequestBase.class))) 061 .thenReturn(fcrepoResponse); 062 063 uri = create(baseUrl); 064 destUri = create(destUrl); 065 testBuilder = new MoveBuilder(uri, destUri, client); 066 } 067 068 @Test 069 public void testMove() throws Exception { 070 testBuilder.perform(); 071 072 final ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class); 073 verify(client).executeRequest(eq(uri), requestCaptor.capture()); 074 075 final HttpRequestBase request = requestCaptor.getValue(); 076 assertEquals("MOVE", request.getMethod()); 077 assertEquals(destUrl, request.getFirstHeader(DESTINATION).getValue()); 078 } 079}