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 import static org.hamcrest.Matchers.nullValue;
22
23 import java.lang.reflect.Method;
24 import java.util.Arrays;
25
26 import org.junit.Test;
27
28 import de.smartics.projectdoc.annotations.DocCategory;
29 import de.smartics.projectdoc.annotations.DocParent;
30 import de.smartics.projectdoc.annotations.DocTag;
31 import de.smartics.projectdoc.annotations.Document;
32 import de.smartics.properties.api.core.domain.DocumentMetaData;
33 import de.smartics.properties.api.core.domain.PropertyDescriptor;
34 import de.smartics.properties.spi.core.metadata.PropertyMetaDataParser;
35 import de.smartics.testdoc.annotations.Uut;
36
37
38
39
40
41 @Uut(type = PropertyMetaDataParser.class)
42 public class PropertyMetaDataParserDocumentAnnotationsTest extends
43 AbstractPropertyMetaDataParserTestBase
44 {
45
46
47
48
49 public static final String PARENT_NAME = "Parent Name";
50
51 public static final String PARENT_TITLE = "Parent Title";
52
53 public static final String PARENT_PARENT_DOCUMENT = "Parent Parent Document";
54
55 public static final String PARENT_SPACE = "Parent Space";
56
57 public static final String PARENT_AUDIENCE_1 = "Parent Audience 1";
58
59 public static final String PARENT_AUDIENCE_2 = "Parent Audience 2";
60
61 public static final String PARENT_CATEGORY = "parentCategory";
62
63 public static final String PARENT_TAG = "parentTag";
64
65
66
67
68
69 @DocParent({ PARENT_PARENT_DOCUMENT })
70 @Document(name = PARENT_NAME, shortDescription = "Parent Short Description.",
71 notes = { "Parent Note 1", "Parent Note 2" }, space = PARENT_SPACE,
72 title = "Parent Title", sortKey = "Parent Sort Key",
73 summary = "Parent Summary", audience = { PARENT_AUDIENCE_1,
74 PARENT_AUDIENCE_2 })
75 @DocCategory({ PARENT_CATEGORY })
76 @DocTag(PARENT_TAG)
77 public interface TestProperties
78 {
79 String inheritAll();
80
81 @DocParent({ "Child 1 Parent" })
82 @Document(name = "Child Name 1",
83 shortDescription = "Child 1 Short Description.",
84 notes = { "Child 1 Notes" }, space = "Child 1 Space",
85 title = "Child 1 Title", sortKey = "Child 1 Sort Key",
86 summary = "Child 1 Summary", audience = "Child 1 Audience")
87 @DocCategory({ "Child 1 Category" })
88 @DocTag({ "Child 1 Tag" })
89 String oneValue();
90
91 @DocParent({ "Child 2 Parent 1", "Child 2 Parent 2" })
92 @Document(audience = { "Child 2 Audience 1", "Child 2 Audience 2" })
93 @DocCategory({ "Child 2 Category 1", "Child 2 Category 2" })
94 @DocTag({ "Child 2 Tag 1", "Child 2 Tag 2" })
95 String multipleValues();
96 }
97
98
99
100
101
102
103
104 private DocumentMetaData runTest(final String methodNameAndPropertyName)
105 {
106 final Method method =
107 fetchMethod(TestProperties.class, methodNameAndPropertyName);
108 final PropertyDescriptor descriptor = uut.readDescriptor(method);
109 final DocumentMetaData metaData = descriptor.getDocumentMetaData();
110 return metaData;
111 }
112
113
114
115 @Test
116 public void propertyMetaDataAnnotationIsNotRequired()
117 {
118 final DocumentMetaData metaData = runTest("inheritAll");
119
120 assertThat(metaData.getParents().isEmpty(), is(true));
121 assertThat(metaData.getName(), is(PARENT_NAME + ".inheritAll"));
122 assertThat(metaData.getShortDescription(), is(nullValue()));
123 assertThat(metaData.getNotes().isEmpty(), is(true));
124 assertThat(metaData.getSpace(), is(equalTo(PARENT_SPACE)));
125 assertThat(metaData.getTitle(), is(PARENT_TITLE + ".inheritAll"));
126 assertThat(metaData.getSortKey(), is(nullValue()));
127 assertThat(metaData.getSummary(), is(nullValue()));
128 assertThat(metaData.getAudience(),
129 is(equalTo(Arrays.asList(PARENT_AUDIENCE_1, PARENT_AUDIENCE_2))));
130 assertThat(metaData.getCategories(),
131 is(equalTo(Arrays.asList(PARENT_CATEGORY))));
132 assertThat(metaData.getTags(), is(equalTo(Arrays.asList(PARENT_TAG))));
133 }
134
135 @Test
136 public void propertyMetaDataAnnotationProvidesDefaults()
137 {
138 final DocumentMetaData metaData = runTest("oneValue");
139
140 assertThat(metaData.getParents(),
141 is(equalTo(Arrays.asList("Child 1 Parent"))));
142 assertThat(metaData.getName(), is(equalTo("Child Name 1")));
143 assertThat(metaData.getShortDescription(),
144 is(equalTo("Child 1 Short Description.")));
145 assertThat(metaData.getNotes(), is(equalTo(Arrays.asList("Child 1 Notes"))));
146 assertThat(metaData.getSpace(), is(equalTo("Child 1 Space")));
147 assertThat(metaData.getTitle(), is(equalTo("Child 1 Title")));
148 assertThat(metaData.getSortKey(), is(equalTo("Child 1 Sort Key")));
149 assertThat(metaData.getSummary(), is(equalTo("Child 1 Summary")));
150 assertThat(metaData.getAudience(), is(equalTo(Arrays.asList(
151 PARENT_AUDIENCE_1, PARENT_AUDIENCE_2, "Child 1 Audience"))));
152 assertThat(metaData.getCategories(),
153 is(equalTo(Arrays.asList(PARENT_CATEGORY, "Child 1 Category"))));
154 assertThat(metaData.getTags(),
155 is(equalTo(Arrays.asList(PARENT_TAG, "Child 1 Tag"))));
156 }
157
158 @Test
159 public void propertyMetaDataAnnotationAllowsMultipleValues()
160 {
161 final DocumentMetaData metaData = runTest("multipleValues");
162
163 assertThat(metaData.getParents(),
164 is(equalTo(Arrays.asList("Child 2 Parent 1", "Child 2 Parent 2"))));
165 assertThat(metaData.getName(), is(PARENT_NAME + ".multipleValues"));
166 assertThat(metaData.getShortDescription(), is(nullValue()));
167 assertThat(metaData.getNotes().isEmpty(), is(true));
168 assertThat(metaData.getSpace(), is(equalTo(PARENT_SPACE)));
169 assertThat(metaData.getTitle(), is(PARENT_TITLE + ".multipleValues"));
170 assertThat(metaData.getSortKey(), is(nullValue()));
171 assertThat(metaData.getSummary(), is(nullValue()));
172 assertThat(metaData.getAudience(), is(equalTo(Arrays.asList(
173 PARENT_AUDIENCE_1, PARENT_AUDIENCE_2, "Child 2 Audience 1",
174 "Child 2 Audience 2"))));
175 assertThat(metaData.getCategories(), is(equalTo(Arrays.asList(
176 PARENT_CATEGORY, "Child 2 Category 1", "Child 2 Category 2"))));
177 assertThat(
178 metaData.getTags(),
179 is(equalTo(Arrays.asList(PARENT_TAG, "Child 2 Tag 1", "Child 2 Tag 2"))));
180 }
181 }