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.foxml; 017 018import static org.junit.Assert.assertEquals; 019 020import org.apache.commons.io.FileUtils; 021import org.junit.After; 022import org.junit.Before; 023import org.junit.Test; 024 025import java.io.File; 026import java.io.IOException; 027import java.io.UnsupportedEncodingException; 028 029/** 030 * @author mikedurbin 031 */ 032public class AkubraFSIDResolverTest { 033 034 private AkubraFSIDResolver idResolver; 035 036 private File tempDir; 037 038 @Before 039 public void setup() throws IOException { 040 tempDir = File.createTempFile("tempfile", "basedir"); 041 tempDir.delete(); 042 tempDir.mkdir(); 043 idResolver = new AkubraFSIDResolver(tempDir); 044 } 045 046 @Test 047 public void testIDMapping() throws UnsupportedEncodingException { 048 assertEquals("example:1+DS2+DS2.0", 049 idResolver.getInternalIdForFile(new File("info%3Afedora%2Fexample%3A1%2FDS2%2FDS2.0"))); 050 } 051 052 @Test (expected = IllegalArgumentException.class) 053 public void testBadFileIDMapping() throws UnsupportedEncodingException { 054 idResolver.getInternalIdForFile(new File("example%3A1%2FDS2%2FDS2.0")); 055 } 056 057 058 @After 059 public void cleanup() throws IOException { 060 FileUtils.deleteDirectory(tempDir); 061 } 062}