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