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