1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.brabenetz.lib.securedproperties.snippets;
21
22 import net.brabenetz.lib.securedproperties.SecuredProperties;
23 import net.brabenetz.lib.securedproperties.SecuredPropertiesConfig;
24 import org.junit.Test;
25 import org.settings4j.Settings4j;
26 import org.settings4j.connector.PropertyFileConnector;
27 import org.settings4j.connector.SystemPropertyConnector;
28
29 import java.io.File;
30
31 import static org.hamcrest.MatcherAssert.assertThat;
32 import static org.hamcrest.Matchers.is;
33 import static org.settings4j.ConnectorPositions.afterLast;
34
35
36
37
38 public class Settings4jExampleTest {
39
40 @Test
41 public void testSettings4jConfiguration() throws Exception {
42
43
44
45 File secretKey = new File("src/test/data/secretFileExample.key");
46 File propertiesFile = new File("src/test/data/TestProperties-Valid.properties");
47
48
49 SecuredPropertiesConfig config = new SecuredPropertiesConfig().withSecretFile(secretKey).initDefault();
50
51 SecuredProperties.encryptNonEncryptedValues(
52 config, propertiesFile, "mySecretPassword");
53
54 String myPassword = SecuredProperties.getSecretValue(
55 config, propertiesFile, "mySecretPassword");
56
57 System.setProperty("mySecretPassword", myPassword);
58
59
60 PropertyFileConnector myConnector = new PropertyFileConnector();
61 myConnector.setName("myCustomConfig");
62 myConnector.setPropertyFromPath(propertiesFile.toURI().toString());
63 Settings4j.getSettingsRepository().getSettings().addConnector(myConnector, afterLast(SystemPropertyConnector.class));
64
65
66 assertThat(Settings4j.getString("myTitle"), is("My Test"));
67 assertThat(Settings4j.getString("mySecretPassword"), is("test"));
68
69
70 }
71 }