001/* 002 * Copyright 2019 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.handlers.ocfl; 018 019import edu.wisc.library.ocfl.api.MutableOcflRepository; 020import edu.wisc.library.ocfl.core.OcflRepositoryBuilder; 021import edu.wisc.library.ocfl.core.extension.storage.layout.config.HashedNTupleLayoutConfig; 022import edu.wisc.library.ocfl.core.path.mapper.LogicalPathMappers; 023import edu.wisc.library.ocfl.core.storage.filesystem.FileSystemOcflStorage; 024import org.apache.commons.lang3.SystemUtils; 025import org.fcrepo.storage.ocfl.OcflObjectSessionFactory; 026import org.junit.Before; 027import org.junit.Rule; 028import org.junit.Test; 029import org.junit.rules.TemporaryFolder; 030 031import java.io.IOException; 032import java.nio.file.Path; 033 034import static org.junit.Assert.assertNotEquals; 035 036/** 037 * @author pwinckles 038 */ 039public class PlainOcflObjectSessionFactoryTest { 040 041 @Rule 042 public TemporaryFolder tempDir = new TemporaryFolder(); 043 044 private Path ocflRoot; 045 private Path staging; 046 047 private MutableOcflRepository ocflRepo; 048 private OcflObjectSessionFactory sessionFactory; 049 050 @Before 051 public void setup() throws IOException { 052 ocflRoot = tempDir.newFolder("ocfl").toPath(); 053 staging = tempDir.newFolder("staging").toPath(); 054 055 final var logicalPathMapper = SystemUtils.IS_OS_WINDOWS ? 056 LogicalPathMappers.percentEncodingWindowsMapper() : LogicalPathMappers.percentEncodingLinuxMapper(); 057 058 ocflRepo = new OcflRepositoryBuilder() 059 .defaultLayoutConfig(new HashedNTupleLayoutConfig()) 060 .logicalPathMapper(logicalPathMapper) 061 .storage(FileSystemOcflStorage.builder().repositoryRoot(ocflRoot).build()) 062 .workDir(staging) 063 .buildMutable(); 064 065 sessionFactory = new PlainOcflObjectSessionFactory(ocflRepo, staging, 066 "testing", "fedoraAdmin", "info:fedora/fedoraAdmin", false); 067 } 068 069 @Test 070 public void returnDifferentSessionsForTheSameObject() { 071 final var session1 = sessionFactory.newSession("obj1"); 072 final var session2 = sessionFactory.newSession("obj1"); 073 074 assertNotEquals(session1.sessionId(), session2.sessionId()); 075 } 076 077}