1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.tutorial.resolve;
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.config.domain.ConfigurationProperties;
28 import de.smartics.properties.api.core.domain.PropertyValueResolveException;
29 import de.smartics.properties.impl.config.classpath.ClasspathConfigurationProperties;
30 import de.smartics.properties.impl.config.classpath.ClasspathConfigurationPropertiesFactory;
31
32
33
34
35 @Document(title = "Resolve Properties", sortKey = "basics0200")
36 @DocCategory({ "basics" })
37
38 public class PropertyResolveTutorial
39 {
40 private ConfigurationProperties config;
41
42 private ResolveProperties properties;
43
44 @Before
45 public void setUp()
46 {
47 config = createConfiguration();
48 properties = config.getProperties(ResolveProperties.class);
49 }
50
51 private static ConfigurationProperties createConfiguration()
52 {
53 final ClasspathConfigurationPropertiesFactory factory =
54 new ClasspathConfigurationPropertiesFactory();
55 final ClasspathConfigurationProperties config = factory.create();
56 config.addClassPathProperties(ResolveProperties.class);
57 return config;
58 }
59
60 @DocChapter
61 @Test
62 public void transitiveReferences()
63 {
64 final String property = properties.property();
65
66 assertThat(property, is("referenced transitive"));
67 }
68
69 @DocChapter
70 @Test(expected=PropertyValueResolveException.class)
71 public void illegalBackReference()
72 {
73 properties.backProperty();
74 }
75
76 @DocChapter
77 @Test(expected=PropertyValueResolveException.class)
78 public void referenceToAPropertyWithANullValue()
79 {
80 properties.nullProperty();
81 }
82
83 @DocChapter
84 @Test(expected=PropertyValueResolveException.class)
85 public void illegalUnknownReference()
86 {
87 properties.illegalUnknownReference();
88 }
89 }