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 */
016
017package org.fcrepo.migration;
018
019import org.apache.commons.io.FileUtils;
020import org.junit.After;
021import org.junit.Test;
022import org.springframework.context.ConfigurableApplicationContext;
023import org.springframework.context.support.ClassPathXmlApplicationContext;
024import org.fcrepo.storage.ocfl.OcflObjectSessionFactory;
025
026import java.nio.file.Files;
027import java.nio.file.Paths;
028
029import static org.junit.Assert.assertTrue;
030
031/**
032 * @author Dan Field
033 */
034public class DisabledDigestIT {
035
036    private ConfigurableApplicationContext context;
037    private Migrator migrator;
038    private OcflObjectSessionFactory sessionFactory;
039
040    @After
041    public void tearDown() {
042        if (context != null) {
043            context.close();
044        }
045    }
046
047    private void setup(final String name) throws Exception {
048        final var storage = Paths.get(String.format("target/test/ocfl/%s/storage", name));
049        final var staging = Paths.get(String.format("target/test/ocfl/%s/staging", name));
050
051        if (Files.exists(storage)) {
052            FileUtils.forceDelete(storage.toFile());
053        }
054        if (Files.exists(staging)) {
055            FileUtils.forceDelete(staging.toFile());
056        }
057
058        Files.createDirectories(storage);
059        Files.createDirectories(staging);
060
061        context = new ClassPathXmlApplicationContext(String.format("spring/%s-setup.xml", name));
062        migrator = (Migrator) context.getBean("migrator");
063        sessionFactory = (OcflObjectSessionFactory) context.getBean("ocflSessionFactory");
064    }
065
066    @Test
067    public void testMigrateObjectWithExternalDatastreamAndDisabledDigest() throws Exception {
068        setup("inline-disabled-it");
069        migrator.run();
070        final var session = sessionFactory.newSession("info:fedora/llgc-id:1591190");
071        assertTrue(session.containsResource("info:fedora/llgc-id:1591190/POLICY"));
072    }
073
074}