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.Before;
26
27 import de.smartics.properties.api.core.domain.PropertyConstraint;
28 import de.smartics.properties.api.core.domain.PropertyDescriptor;
29 import de.smartics.properties.api.core.domain.PropertyExpression;
30 import de.smartics.properties.api.core.domain.PropertyKey;
31 import de.smartics.properties.api.core.domain.PropertyType;
32 import de.smartics.properties.api.core.domain.PropertyValueRange;
33 import de.smartics.properties.spi.core.metadata.PropertyMetaDataParser;
34 import de.smartics.testdoc.annotations.Uut;
35
36
37
38
39 @Uut(type = PropertyMetaDataParser.class)
40 public abstract class AbstractPropertyMetaDataParserTestBase
41 {
42
43
44
45
46
47
48 protected PropertyMetaDataParser uut;
49
50
51
52
53
54
55
56 @Before
57 public void setUp()
58 {
59 uut = PropertyMetaDataParser.createWithoutContextAccess();
60 }
61
62
63
64 protected static final Method fetchMethod(final Class<?> type,
65 final String methodName)
66 {
67 try
68 {
69 return type.getDeclaredMethod(methodName, new Class<?>[0]);
70 }
71 catch (final Exception e)
72 {
73 throw new IllegalStateException(String.format(
74 "No method named '%s' found in type '%s'.", methodName,
75 type.getName()));
76 }
77 }
78
79
80 @SuppressWarnings("rawtypes")
81 protected static final void checkThat(
82
83 final PropertyDescriptor descriptor, final PropertyKey expectedKey,
84 final PropertyType expectedType,
85 final PropertyExpression expectedExpression,
86 final PropertyValueRange expectedRange, final List expectedConstraints)
87 {
88
89 checkThat(descriptor, expectedKey, expectedType, false, expectedExpression,
90 expectedRange, expectedConstraints);
91 }
92
93
94 @SuppressWarnings("rawtypes")
95 protected static final void checkThat(
96
97 final PropertyDescriptor descriptor, final PropertyKey expectedKey,
98 final PropertyType expectedType, final boolean mandatory,
99 final PropertyExpression expectedExpression,
100 final PropertyValueRange expectedRange, final List expectedConstraints)
101 {
102
103 assertThat(descriptor.getKey(), is(equalTo(expectedKey)));
104 assertThat(descriptor.getType(), is(equalTo(expectedType)));
105 assertThat(descriptor.isMandatory(), is(equalTo(mandatory)));
106 assertThat(descriptor.getDefaultExpression().getExpression(),
107 is(equalTo(expectedExpression.getExpression())));
108 assertThat(descriptor.getValueRange(), is(equalTo(expectedRange)));
109
110 final List<? extends PropertyConstraint<?>> actualConstraints =
111 descriptor.getConstraints();
112 assertThat(actualConstraints.size(),
113 is(equalTo(expectedConstraints.size())));
114 for (int i = actualConstraints.size() - 1; i >= 0; i--)
115 {
116 final PropertyConstraint actual = actualConstraints.get(i);
117 final PropertyConstraint expected =
118 (PropertyConstraint) expectedConstraints.get(i);
119 assertThat(actual.toString(), is(equalTo(expected.toString())));
120 }
121 }
122
123
124
125 }