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 */
006package org.fcrepo.kernel.api.utils;
007
008import static java.net.URI.create;
009import static org.fcrepo.config.DigestAlgorithm.SHA1;
010import static org.fcrepo.kernel.api.utils.ContentDigest.asURI;
011import static org.fcrepo.kernel.api.utils.ContentDigest.getAlgorithm;
012import static org.junit.Assert.assertEquals;
013
014import org.fcrepo.config.DigestAlgorithm;
015
016import org.junit.Test;
017
018/**
019 * <p>ContentDigestTest class.</p>
020 *
021 * @author ksclarke
022 */
023public class ContentDigestTest {
024
025    @Test
026    public void testSHA_1() {
027        assertEquals("Failed to produce a proper content digest URI!",
028                create("urn:sha1:fake"), asURI(SHA1.getAlgorithm(), "fake"));
029    }
030
031    @Test
032    public void testSHA1() {
033        assertEquals("Failed to produce a proper content digest URI!",
034                create("urn:sha1:fake"), asURI("SHA", "fake"));
035    }
036
037    @Test
038    public void testGetAlgorithm() {
039        assertEquals("Failed to produce a proper digest algorithm!", SHA1.getAlgorithm(),
040                getAlgorithm(asURI(SHA1.getAlgorithm(), "fake")));
041    }
042
043    @Test
044    public void testSHA256() {
045        assertEquals("Failed to produce a proper content digest URI!",
046                create("urn:sha-256:fake"), asURI("SHA-256", "fake"));
047    }
048
049    @Test
050    public void testMissingAlgorithm() {
051        assertEquals("Failed to produce a proper content digest URI!",
052                create("missing:fake"), asURI("SHA-819", "fake"));
053    }
054
055    @Test
056    public void testFromAlgorithm() {
057        assertEquals(DigestAlgorithm.SHA1, DigestAlgorithm.fromAlgorithm("SHA"));
058        assertEquals(DigestAlgorithm.SHA1, DigestAlgorithm.fromAlgorithm("sha-1"));
059    }
060
061    @Test
062    public void testFromAlgorithmMissing() {
063        assertEquals(DigestAlgorithm.MISSING, DigestAlgorithm.fromAlgorithm("what"));
064    }
065}