1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.dbunit.testutil;
23
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.FileNotFoundException;
27 import java.io.FileReader;
28
29 import org.apache.commons.io.FilenameUtils;
30 import org.dbunit.DatabaseEnvironment;
31
32
33
34
35
36 public class TestUtils
37 {
38 private static String getProfileName() throws Exception
39 {
40 return DatabaseEnvironment.getInstance().getProfile().getActiveProfile();
41 }
42
43 public static String getFileName(String fileName)
44 {
45 return "src/test/resources/" + fileName;
46 }
47
48 public static File getFile(String fileName)
49 {
50 return new File(getFileName(fileName));
51 }
52
53 public static File getFileForDatabaseEnvironment(String originalFileName) throws Exception
54 {
55 String fullPath = FilenameUtils.getFullPath(originalFileName);
56 String baseName = FilenameUtils.getBaseName(originalFileName);
57 String extension = FilenameUtils.getExtension(originalFileName);
58 File profileFile = new File(fullPath + baseName + "-" + getProfileName() + "." + extension);
59 if (profileFile.exists())
60 {
61 return profileFile;
62 }
63 else
64 {
65 return new File(originalFileName);
66 }
67 }
68
69 public static FileReader getFileReader(String fileName) throws FileNotFoundException
70 {
71 return new FileReader(getFileName(fileName));
72 }
73
74 public static FileInputStream getFileInputStream(String fileName) throws FileNotFoundException
75 {
76 return new FileInputStream(getFileName(fileName));
77 }
78
79 }