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.migration;
017
018import java.io.IOException;
019
020import javax.xml.stream.XMLStreamException;
021
022import org.junit.Before;
023import org.junit.Test;
024import org.springframework.context.ConfigurableApplicationContext;
025import org.springframework.context.support.ClassPathXmlApplicationContext;
026
027/**
028 * A series of tests that cover all the features used in processing
029 * FOXML exported using the context=archive option.
030 * @author mdurbin
031 */
032public class ExportedArchiveFoxmlMigratorTest extends Example1TestSuite {
033
034    private static DummyHandler result;
035
036    private static DummyURLFetcher fetcher;
037
038    @Before
039    public synchronized void processFoxml() throws XMLStreamException, IOException {
040        if (getResult() == null) {
041            final ConfigurableApplicationContext context =
042                    new ClassPathXmlApplicationContext("spring/exported-foxml.xml");
043            this.result = (DummyHandler) context.getBean("dummyHandler");
044            this.fetcher = (DummyURLFetcher) context.getBean("dummyFetcher");
045            final Migrator m = (Migrator) context.getBean("migrator");
046            m.run();
047            context.close();
048        }
049    }
050
051    @Override
052    protected DummyHandler getResult() {
053        return result;
054    }
055
056    @Override
057    protected DummyURLFetcher getFetcher() {
058        return fetcher;
059    }
060
061    @Test (expected = IllegalStateException.class)
062    public void testTempFileRemoval() throws IOException {
063        getResult().dsVersions.get(4).getContent();
064    }
065}