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.transform;
017
018import org.fcrepo.transform.transformations.LDPathTransform;
019import org.fcrepo.transform.transformations.SparqlQueryTransform;
020import org.junit.Before;
021import org.junit.Test;
022import org.mockito.Mock;
023
024import javax.ws.rs.core.MediaType;
025
026import java.io.InputStream;
027import java.util.Collection;
028import java.util.Map;
029
030import static org.apache.jena.riot.WebContent.contentTypeSPARQLQuery;
031import static org.fcrepo.transform.transformations.LDPathTransform.APPLICATION_RDF_LDPATH;
032import static org.junit.Assert.assertEquals;
033import static org.mockito.MockitoAnnotations.initMocks;
034
035/**
036 * <p>TransformationFactoryTest class.</p>
037 *
038 * @author cbeer
039 */
040public class TransformationFactoryTest {
041
042    @Mock
043    InputStream mockInputStream;
044
045    TransformationFactory transformationFactory;
046
047    @Before
048    public void setUp() {
049        initMocks(this);
050        transformationFactory = new TransformationFactory();
051    }
052
053    @Test
054    public void testLDPathCreation() {
055
056        final Transformation<Map<String, Collection<Object>>> transform =
057            transformationFactory.getTransform(MediaType.valueOf(APPLICATION_RDF_LDPATH), mockInputStream);
058
059        assertEquals(new LDPathTransform(mockInputStream), transform);
060
061    }
062
063    @Test
064    public void testSparqlCreation() {
065
066        final Transformation<Map<String, Collection<Object>>> transform =
067            transformationFactory.getTransform(MediaType.valueOf(contentTypeSPARQLQuery), mockInputStream);
068        assertEquals(new SparqlQueryTransform(mockInputStream), transform);
069
070    }
071
072
073    @Test(expected = UnsupportedOperationException.class)
074    public void testOtherCreation() {
075
076        transformationFactory.getTransform(MediaType.valueOf("some/mime-type"), mockInputStream);
077
078    }
079}