001/**
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 *
006 */
007package org.fcrepo.migration.foxml;
008
009import static org.junit.Assert.assertEquals;
010
011import org.apache.commons.io.FileUtils;
012import org.junit.After;
013import org.junit.Before;
014import org.junit.Test;
015
016import java.io.File;
017import java.io.IOException;
018import java.io.UnsupportedEncodingException;
019
020/**
021 * @author mikedurbin
022 */
023public class AkubraFSIDResolverTest {
024
025    private AkubraFSIDResolver idResolver;
026
027    private File tempDir;
028
029    @Before
030    public void setup() throws IOException {
031        tempDir = File.createTempFile("tempfile", "basedir");
032        tempDir.delete();
033        tempDir.mkdir();
034        idResolver = new AkubraFSIDResolver(tempDir);
035    }
036
037    @Test
038    public void testIDMapping() throws UnsupportedEncodingException {
039        assertEquals("example:1+DS2+DS2.0",
040                idResolver.getInternalIdForFile(new File("info%3Afedora%2Fexample%3A1%2FDS2%2FDS2.0")));
041    }
042
043    @Test (expected = IllegalArgumentException.class)
044    public void testBadFileIDMapping() throws UnsupportedEncodingException {
045        idResolver.getInternalIdForFile(new File("example%3A1%2FDS2%2FDS2.0"));
046    }
047
048
049    @After
050    public void cleanup() throws IOException {
051        FileUtils.deleteDirectory(tempDir);
052    }
053}