1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.spi.core.metadata;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.equalTo;
20 import static org.hamcrest.Matchers.is;
21
22 import java.lang.reflect.Method;
23 import java.util.List;
24
25 import org.junit.Test;
26
27 import de.smartics.properties.api.core.annotations.AccessType;
28 import de.smartics.properties.api.core.annotations.PropertyDefinitionTime;
29 import de.smartics.properties.api.core.annotations.PropertyLifecycle;
30 import de.smartics.properties.api.core.annotations.PropertySet;
31 import de.smartics.properties.api.core.domain.PropertyDescriptor;
32 import de.smartics.properties.spi.core.metadata.PropertyMetaDataParser;
33 import de.smartics.testdoc.annotations.Uut;
34
35
36
37
38
39 @Uut(type = PropertyMetaDataParser.class)
40 public class PropertyMetaDataParserMetaDataTest extends
41 AbstractPropertyMetaDataParserTestBase
42 {
43
44
45
46
47 private static final long SOME_MILLIS = 128L;
48
49
50
51
52
53 @PropertySet
54 public interface TestProperties
55 {
56 String noAnnotation();
57
58 @PropertyLifecycle
59 String defaultMetaData();
60
61 @PropertyLifecycle(definitionTime = PropertyDefinitionTime.RUN,
62 access = AccessType.READ_WRITE, updateInterval = SOME_MILLIS)
63 String allSpecifed();
64
65 String allSpecifiedPropertyKey();
66 }
67
68
69
70
71
72
73
74 private PropertyDescriptor runTest(final String methodNameAndPropertyName)
75 {
76 final Method method =
77 fetchMethod(TestProperties.class, methodNameAndPropertyName);
78 final PropertyDescriptor descriptor = uut.readDescriptor(method);
79 return descriptor;
80 }
81
82
83
84 @Test
85 public void propertyMetaDataAnnotationIsNotRequired()
86 {
87 final PropertyDescriptor descriptor = runTest("noAnnotation");
88
89 assertThat(descriptor.getConfigurationTime(),
90 is(equalTo(PropertyDefinitionTime.STARTUP)));
91 assertThat(descriptor.getUpdateIntervalInMs(), is(equalTo(-1L)));
92 assertThat(descriptor.isRuntimeMutable(), is(equalTo(false)));
93 }
94
95 @Test
96 public void propertyMetaDataAnnotationProvidesDefaults()
97 {
98 final PropertyDescriptor descriptor = runTest("defaultMetaData");
99
100 assertThat(descriptor.getConfigurationTime(),
101 is(equalTo(PropertyDefinitionTime.STARTUP)));
102 assertThat(descriptor.getUpdateIntervalInMs(), is(equalTo(-1L)));
103 assertThat(descriptor.isRuntimeMutable(), is(equalTo(false)));
104 }
105
106 @Test
107 public void propertyMetaDataAnnotationFromType()
108 {
109 final List<PropertyDescriptor> descriptors =
110 uut.readDescriptors(TestProperties.class);
111
112 assertThat(descriptors.size(), is(equalTo(3)));
113 }
114
115 @Test
116 public void propertyMetaDataAnnotationAllowsToProvideConfigurationTimeAndUpdateInterval()
117 {
118 final PropertyDescriptor descriptor = runTest("allSpecifed");
119
120 assertThat(descriptor.getConfigurationTime(),
121 is(equalTo(PropertyDefinitionTime.RUN)));
122 assertThat(descriptor.getUpdateIntervalInMs(), is(equalTo(SOME_MILLIS)));
123 assertThat(descriptor.isRuntimeMutable(), is(equalTo(true)));
124 }
125 }