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 */
016package org.fcrepo.client.impl;
017
018import static org.junit.Assert.assertFalse;
019import static org.mockito.Matchers.anyString;
020import static org.mockito.Mockito.doThrow;
021import static org.mockito.Mockito.mock;
022import static org.mockito.Mockito.spy;
023
024import java.io.IOException;
025
026import org.fcrepo.client.NotFoundException;
027
028import org.fcrepo.client.FedoraException;
029import org.fcrepo.client.ReadOnlyException;
030
031import org.junit.Before;
032import org.junit.Test;
033
034
035/**
036 * Read-only repository impl -- read operations should work, but write operations
037 * should throw a ReadOnlyException.
038 *
039 * @author escowles
040**/
041public class ReadOnlyFedoraRepositoryImplTest extends FedoraRepositoryImplTest {
042
043    ReadOnlyFedoraRepositoryImpl fedoraRepository;
044
045    @Before
046    public void setUp() throws IOException {
047        super.setUp();
048        super.fedoraRepository = new ReadOnlyFedoraRepositoryImpl(testRepositoryUrl, mockClient);
049    }
050
051    @Test
052    public void testGetObject() throws IOException, FedoraException {
053        super.testGetObject();
054    }
055
056    @Test
057    public void testGetRepositoryUrl() {
058        super.testGetRepositoryUrl();
059    }
060
061    @Test
062    public void testExists() throws IOException, FedoraException {
063        super.testExists();
064    }
065
066    @Test
067    public void testExistsNonExistent() throws IOException, FedoraException {
068        super.testExistsNonExistent();
069    }
070
071    @Test (expected = ReadOnlyException.class)
072    public void testCreateObject() throws IOException, FedoraException {
073        super.testCreateObject();
074    }
075
076    @Test
077    public void testFindOrCreateObject() throws FedoraException {
078        super.testFindOrCreateObject();
079    }
080
081    @Test (expected = ReadOnlyException.class)
082    public void testFindOrCreateObjectNonExistent() throws FedoraException {
083        final ReadOnlyFedoraRepositoryImpl spy = spy( new ReadOnlyFedoraRepositoryImpl(testRepositoryUrl, mockClient) );
084        final NotFoundException mockException = mock(NotFoundException.class);
085        doThrow(mockException).when(spy).getObject(anyString());
086        spy.findOrCreateObject("/foo");
087    }
088
089    @Test
090    public void testWritable() {
091        System.out.println("ReadOnlyFedoraRepositoryImpl.isWritable()" + fedoraRepository);
092        assertFalse( super.fedoraRepository.isWritable() );
093    }
094}