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