Java tutorial
/** * Copyright 2015 DuraSpace, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.fcrepo.client; import static java.net.URI.create; import static org.fcrepo.client.FedoraHeaderConstants.DESTINATION; import static org.fcrepo.client.TestUtils.baseUrl; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.net.URI; import org.apache.http.client.methods.HttpRequestBase; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; /** * @author bbpennel */ @RunWith(MockitoJUnitRunner.class) public class MoveBuilderTest { @Mock private FcrepoClient client; @Mock private FcrepoResponse fcrepoResponse; private MoveBuilder testBuilder; private URI uri; private URI destUri; public static final String destUrl = "http://localhost:8080/rest/dest/foo"; @Before public void setUp() throws Exception { when(client.executeRequest(any(URI.class), any(HttpRequestBase.class))).thenReturn(fcrepoResponse); uri = create(baseUrl); destUri = create(destUrl); testBuilder = new MoveBuilder(uri, destUri, client); } @Test public void testMove() throws Exception { testBuilder.perform(); final ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class); verify(client).executeRequest(eq(uri), requestCaptor.capture()); final HttpRequestBase request = requestCaptor.getValue(); assertEquals("MOVE", request.getMethod()); assertEquals(destUrl, request.getFirstHeader(DESTINATION).getValue()); } }