1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.tutorial.property.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.properties.api.core.domain.PropertyKey;
28 import de.smartics.properties.impl.config.classpath.ClasspathConfigurationProperties;
29 import de.smartics.properties.impl.config.classpath.ClasspathConfigurationPropertiesFactory;
30
31
32
33
34
35 @Document(title = "Accessing Property Keys", sortKey = "basics0070")
36 @DocCategory({ "basics" })
37
38 public class PropertyKeyAccessTutorial
39 {
40 private ClasspathConfigurationProperties config;
41
42 private DescriptorAndKeyProperties properties;
43
44 @Before
45 public void setUp()
46 {
47 config = createConfiguration();
48 properties = config.getProperties(DescriptorAndKeyProperties.class);
49 }
50
51 private static ClasspathConfigurationProperties createConfiguration()
52 {
53 final ClasspathConfigurationPropertiesFactory factory =
54 new ClasspathConfigurationPropertiesFactory();
55 final ClasspathConfigurationProperties config = factory.create();
56 config.addClassPathProperties(DescriptorAndKeyProperties.class);
57 return config;
58 }
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 @DocChapter
78 @Test
79 public void declarationOfAProperty()
80 {
81 final PropertyKey key = properties.hostPropertyKey();
82
83 assertThat(key.getPropertySet(), is("tutorial.property.key"));
84 assertThat(key.getName(), is("host"));
85 }
86 }