1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.tutorial.config.key;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is;
20
21 import org.junit.Before;
22 import org.junit.Test;
23
24 import de.smartics.projectdoc.annotations.DocCategory;
25 import de.smartics.projectdoc.annotations.Document;
26 import de.smartics.projectdoc.annotations.topic.DocChapter;
27 import de.smartics.projectdoc.annotations.topic.DocSection;
28 import de.smartics.properties.api.config.app.ConfigurationPropertiesFactory;
29 import de.smartics.properties.api.config.app.ConfigurationPropertiesFactoryFactory;
30 import de.smartics.properties.api.config.domain.ConfigurationPropertiesManagement;
31 import de.smartics.properties.api.config.domain.key.ApplicationId;
32 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
33 import de.smartics.properties.api.config.domain.key.EnvironmentId;
34 import de.smartics.properties.impl.config.domain.key.rtaware.TenantUserConfigurationKey;
35 import de.smartics.sandbox.mail.AnnouncementProperties;
36 import de.smartics.sandbox.mail.MailProperties;
37
38
39
40
41
42
43
44
45 @Document(title = "Multiple Nodes", sortKey = "basics1010")
46 @DocCategory({ "basics" })
47
48
49 public class MultiConfigurationKeyTutorial
50 {
51 private ConfigurationPropertiesFactory factory;
52
53 @Before
54 public void setUp()
55 {
56 factory = ConfigurationPropertiesFactoryFactory.createDefaultFactory();
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 @DocChapter
96 public void accessConfigurationByHardcodedKey()
97 {
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111 @DocSection
112 @Test
113 public void theMailServerConfiguration()
114 {
115 final ConfigurationKey<?> key =
116 new TenantUserConfigurationKey(new EnvironmentId("test", "mail"),
117 new ApplicationId("de.smartics.sandbox", "mail-server", "1.0"));
118
119 final ConfigurationPropertiesManagement config =
120 factory.createManagement(key);
121
122 final MailProperties properties =
123 config.getProperties(MailProperties.class);
124
125 final int mailsPerPage = properties.mailsPerPage();
126 assertThat(mailsPerPage, is(10));
127 }
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142 @DocSection
143 @Test
144 public void theMainServerConfiguration()
145 {
146 final ConfigurationKey<?> key =
147 new TenantUserConfigurationKey(new EnvironmentId("test", "main"),
148 new ApplicationId("de.smartics.sandbox", "app-server", "1.0"));
149 final ConfigurationPropertiesManagement config =
150 factory.createManagement(key);
151
152 final AnnouncementProperties properties =
153 config.getProperties(AnnouncementProperties.class);
154
155 final int lookup = properties.lookupIntervalMs();
156 assertThat(lookup, is(0));
157 }
158 }