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.pidlist;
017
018import org.junit.Assert;
019import org.junit.Before;
020import org.junit.Test;
021
022import java.io.BufferedWriter;
023import java.io.File;
024import java.io.FileWriter;
025import java.util.Arrays;
026import java.util.List;
027
028
029/**
030 * Unit test class for UserProvidedPidListManager
031 *
032 * @author awoods
033 * @since 2019-11-08
034 */
035public class UserProvidedPidListManagerTest {
036
037    private UserProvidedPidListManager manager;
038
039    private List<String> pidList;
040
041    private File pidListFile;
042
043    @Before
044    public void setUp() throws Exception {
045        // Test PIDs
046        pidList = Arrays.asList("pid:1", "pid:2", "pid:3", "pid:4");
047
048        // Create file in which to place test PIDs
049        final String testDir = System.getProperty("test.output.dir");
050        final StringBuilder tmpList = new StringBuilder();
051        pidList.forEach(pid -> tmpList.append(pid).append("\n"));
052
053        pidListFile = new File(testDir, "pid-list.txt");
054
055        final BufferedWriter writer = new BufferedWriter(new FileWriter(pidListFile));
056        writer.write(tmpList.toString());
057        writer.close();
058
059        // Class under test
060        manager = new UserProvidedPidListManager(pidListFile);
061    }
062
063    @Test
064    public void accept() {
065        pidList.forEach(pid -> Assert.assertTrue(pid + " should be accepted", manager.accept(pid)));
066    }
067
068    @Test
069    public void acceptAll() {
070        manager = new UserProvidedPidListManager(null);
071        pidList.forEach(pid -> Assert.assertTrue(pid + " should be accepted", manager.accept(pid)));
072    }
073
074
075    @Test
076    public void acceptNotFound() {
077        Assert.assertFalse("'bad' should NOT be accepted", manager.accept("bad"));
078        Assert.assertFalse("'junk' should NOT be accepted", manager.accept("junk"));
079    }
080}