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.kernel.impl.operations;
019
020import static org.junit.Assert.assertEquals;
021import static org.mockito.Mockito.when;
022
023import org.apache.commons.io.IOUtils;
024
025import org.fcrepo.kernel.api.Transaction;
026import org.fcrepo.kernel.api.identifiers.FedoraId;
027import org.fcrepo.kernel.api.operations.NonRdfSourceOperationBuilder;
028import org.fcrepo.kernel.api.operations.NonRdfSourceOperationFactory;
029import org.junit.Before;
030import org.junit.Test;
031import org.junit.runner.RunWith;
032import org.mockito.Mock;
033import org.mockito.junit.MockitoJUnitRunner;
034
035import java.io.InputStream;
036import java.net.URI;
037import java.util.UUID;
038
039/**
040 * @author bseeger
041 */
042@RunWith(MockitoJUnitRunner.Silent.class)
043public class NonRdfSourceOperationFactoryImplTest {
044
045    private NonRdfSourceOperationFactory factory;
046
047    private FedoraId randomId;
048
049    @Mock
050    private Transaction transaction;
051
052    @Before
053    public void setUp() throws Exception {
054        when(transaction.getId()).thenReturn("tx-123");
055        factory = new NonRdfSourceOperationFactoryImpl();
056        randomId = FedoraId.create(UUID.randomUUID().toString());
057    }
058
059    @Test
060    public void testCreateInternalBuilder() throws Exception {
061        final InputStream stream = IOUtils.toInputStream("This is some test data", "UTF-8");
062        final NonRdfSourceOperationBuilder builder = factory.createInternalBinaryBuilder(transaction, randomId, stream);
063        assertEquals(CreateNonRdfSourceOperationBuilderImpl.class, builder.getClass());
064    }
065
066    @Test
067    public void testCreateExternalBuilder() {
068        final URI externalURI = URI.create("http://example.com/some/location");
069        final NonRdfSourceOperationBuilder builder = factory.createExternalBinaryBuilder(transaction, randomId,
070                "PROXY", externalURI);
071        assertEquals(CreateNonRdfSourceOperationBuilderImpl.class, builder.getClass());
072    }
073}