|
20 | 20 |
|
21 | 21 | class ConfigurationFiles { |
22 | 22 |
|
23 | | - public static void createRoleMappingFile(File destination) { |
24 | | - String resource = "roles_mapping.yml"; |
25 | | - copyResourceToFile(resource, destination); |
26 | | - } |
| 23 | + public static void createRoleMappingFile(File destination) { |
| 24 | + String resource = "roles_mapping.yml"; |
| 25 | + copyResourceToFile(resource, destination); |
| 26 | + } |
27 | 27 |
|
28 | | - public static void createConfigFile(File destination) { |
29 | | - String resource = "config.yml"; |
30 | | - copyResourceToFile(resource, destination); |
31 | | - } |
| 28 | + public static Path createConfigurationDirectory() { |
| 29 | + try { |
| 30 | + Path tempDirectory = Files.createTempDirectory("test-security-config"); |
| 31 | + String[] configurationFiles = { |
| 32 | + "config.yml", |
| 33 | + "action_groups.yml", |
| 34 | + "config.yml", |
| 35 | + "internal_users.yml", |
| 36 | + "roles.yml", |
| 37 | + "roles_mapping.yml", |
| 38 | + "security_tenants.yml", |
| 39 | + "tenants.yml" }; |
| 40 | + for (String fileName : configurationFiles) { |
| 41 | + Path configFileDestination = tempDirectory.resolve(fileName); |
| 42 | + copyResourceToFile(fileName, configFileDestination.toFile()); |
| 43 | + } |
| 44 | + return tempDirectory.toAbsolutePath(); |
| 45 | + } catch (IOException ex) { |
| 46 | + throw new RuntimeException("Cannot create directory with security plugin configuration.", ex); |
| 47 | + } |
| 48 | + } |
32 | 49 |
|
33 | | - public static Path createConfigurationDirectory() { |
34 | | - try { |
35 | | - Path tempDirectory = Files.createTempDirectory("test-security-config"); |
36 | | - String[] configurationFiles = { |
37 | | - "config.yml", |
38 | | - "action_groups.yml", |
39 | | - "config.yml", |
40 | | - "internal_users.yml", |
41 | | - "roles.yml", |
42 | | - "roles_mapping.yml", |
43 | | - "security_tenants.yml", |
44 | | - "tenants.yml" |
45 | | - }; |
46 | | - for (String fileName : configurationFiles) { |
47 | | - Path configFileDestination = tempDirectory.resolve(fileName); |
48 | | - copyResourceToFile(fileName, configFileDestination.toFile()); |
49 | | - } |
50 | | - return tempDirectory.toAbsolutePath(); |
51 | | - } catch (IOException ex) { |
52 | | - throw new RuntimeException("Cannot create directory with security plugin configuration.", ex); |
53 | | - } |
54 | | - } |
55 | | - |
56 | | - private static void copyResourceToFile(String resource, File destination) { |
57 | | - try(InputStream input = ConfigurationFiles.class.getClassLoader().getResourceAsStream(resource)) { |
58 | | - Objects.requireNonNull(input, "Cannot find source resource " + resource); |
59 | | - try(OutputStream output = new FileOutputStream(destination)) { |
60 | | - input.transferTo(output); |
61 | | - } |
62 | | - } catch (IOException e) { |
63 | | - throw new RuntimeException("Cannot create file with security plugin configuration", e); |
64 | | - } |
65 | | - } |
| 50 | + private static void copyResourceToFile(String resource, File destination) { |
| 51 | + try (InputStream input = ConfigurationFiles.class.getClassLoader().getResourceAsStream(resource)) { |
| 52 | + Objects.requireNonNull(input, "Cannot find source resource " + resource); |
| 53 | + try (OutputStream output = new FileOutputStream(destination)) { |
| 54 | + input.transferTo(output); |
| 55 | + } |
| 56 | + } catch (IOException e) { |
| 57 | + throw new RuntimeException("Cannot create file with security plugin configuration", e); |
| 58 | + } |
| 59 | + } |
66 | 60 | } |
0 commit comments