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.IOException;
26 import java.io.InputStream;
27 import java.io.Reader;
28 import java.nio.charset.StandardCharsets;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32
33 import org.dbunit.DatabaseEnvironment;
34
35
36
37
38
39 public class TestUtils
40 {
41 private static String getProfileName() throws Exception
42 {
43 return DatabaseEnvironment.getInstance().getProfile()
44 .getActiveProfile();
45 }
46
47 public static String getFileName(String fileName)
48 {
49 return "src/test/resources/" + fileName;
50 }
51
52 public static File getFile(String fileName)
53 {
54 final Path path = Paths.get(getFileName(fileName));
55 return path.toFile();
56 }
57
58 public static File getFileForDatabaseEnvironment(String originalFileName)
59 throws Exception
60 {
61 String profilePath =
62 originalFileName.replace(".", "-" + getProfileName() + ".");
63 File profileFile = Paths.get(profilePath).toFile();
64 if (profileFile.exists())
65 {
66 return profileFile;
67 } else
68 {
69 final Path path = Paths.get(originalFileName);
70 return path.toFile();
71 }
72 }
73
74 public static Reader getFileReader(String fileName) throws IOException
75 {
76 final Path path = Paths.get(getFileName(fileName));
77 return Files.newBufferedReader(path, StandardCharsets.UTF_8);
78 }
79
80 public static InputStream getFileInputStream(String fileName)
81 throws IOException
82 {
83 final Path path = Paths.get(getFileName(fileName));
84 return Files.newInputStream(path);
85 }
86
87 }