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.services.functions;
007
008import static org.junit.Assert.assertEquals;
009import static org.springframework.test.util.ReflectionTestUtils.setField;
010import org.junit.Test;
011import org.junit.Before;
012import org.junit.runner.RunWith;
013import org.mockito.junit.MockitoJUnitRunner;
014import org.fcrepo.config.FedoraPropsConfig;;
015
016/**
017 * <p>
018 * ConfigurableHierarchicalSupplierTest class.
019 * </p>
020 *
021 * @author rdfloyd
022 */
023@RunWith(MockitoJUnitRunner.Silent.class)
024public class ConfigurableHierarchicalSupplierTest {
025
026    private final FedoraPropsConfig propsConfig = new FedoraPropsConfig();
027
028    private final UniqueValueSupplier defaultPidMinter = new ConfigurableHierarchicalSupplier();
029
030    @Before
031    public void setUp() {
032        // Need to set the defaults
033        propsConfig.setFcrepoPidMinterLength(0);
034        propsConfig.setFcrepoPidMinterCount(0);
035        setField(defaultPidMinter, "fedoraPropsConfig", propsConfig);
036    }
037
038    @Test
039    public void testGetIdNoPairtree() {
040        final String id = defaultPidMinter.get();
041        // With (desiredLength,desiredCount=0), check to see that id contains 1 part and no slashes
042        final int parts = (id.split("/").length);
043        assertEquals(1, parts);
044    }
045
046    @Test
047    public void testGetIdPairtreeParams() {
048        // Alter the settings for this test.
049        propsConfig.setFcrepoPidMinterLength(2);
050        propsConfig.setFcrepoPidMinterCount(4);
051        final String id = defaultPidMinter.get();
052        // With (desiredLength > 0 && desiredCount > 0) check to see that id contains (count + 1) parts
053        final int parts = (id.split("/").length);
054        assertEquals(5, parts);
055    }
056
057}