1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.tutorial.property.constraints;
17
18 import static org.junit.Assert.fail;
19
20 import javax.validation.groups.Default;
21
22 import org.junit.Before;
23 import org.junit.Test;
24
25 import de.smartics.projectdoc.annotations.DocCategory;
26 import de.smartics.projectdoc.annotations.Document;
27 import de.smartics.projectdoc.annotations.topic.DocSection;
28 import de.smartics.properties.api.config.domain.ConfigurationValidationException;
29 import de.smartics.properties.impl.config.classpath.ClasspathConfigurationProperties;
30 import de.smartics.properties.impl.config.classpath.ClasspathConfigurationPropertiesFactory;
31 import de.smartics.testdoc.categories.type.Integration;
32 import de.smartics.validation.constraints.groups.Startup;
33
34
35
36
37
38
39
40
41
42
43 @Document(title = "Property Constraints With Groups", sortKey = "basics0060")
44 @DocCategory({ "basics" })
45
46 public class PropertyConstraintsWithGroupsTutorial
47 {
48 private ClasspathConfigurationProperties config;
49
50 private static final Class<GroupConstraintsProperties> TYPE =
51 GroupConstraintsProperties.class;
52
53 private GroupConstraintsProperties properties;
54
55 @Before
56 public void setUp()
57 {
58 config = createConfiguration();
59 properties = config.getProperties(TYPE);
60 }
61
62 private static ClasspathConfigurationProperties createConfiguration()
63 {
64 final ClasspathConfigurationPropertiesFactory factory =
65 new ClasspathConfigurationPropertiesFactory();
66 final ClasspathConfigurationProperties config = factory.create();
67 config.addClassPathProperties(TYPE);
68 return config;
69 }
70
71
72
73
74
75
76
77
78
79
80
81 @Test(expected = ConfigurationValidationException.class)
82 @DocSection
83 public void invalidInStartupGroup()
84 {
85 config.setProperty(properties.startupGroupPropertyKey(), "11");
86
87 try
88 {
89 config.validate();
90 }
91 catch (final ConfigurationValidationException e)
92 {
93 fail("Validation exception not expected since Startup group not activated.");
94 }
95
96 config.validate(Startup.class);
97 }
98
99
100
101
102
103
104
105 @Test(expected = ConfigurationValidationException.class)
106 @DocSection
107 public void declaredDefaultGroup()
108 {
109 config.setProperty(properties.defaultGroupPropertyKey(), "11");
110 config.validate();
111 }
112
113
114
115
116
117
118 @Test(expected = ConfigurationValidationException.class)
119 @DocSection
120 public void declaredDefaultGroupExplictCallWithDefaultGroup()
121 {
122 config.setProperty(properties.defaultGroupPropertyKey(), "2");
123 config.validate(Default.class);
124 }
125
126
127
128
129
130
131 @Test
132 @DocSection
133 public void calledWithUnknownGroup()
134 {
135 config.setProperty(properties.startupGroupPropertyKey(), "11");
136 config.validate(Integration.class);
137 }
138 }