1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.report;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.equalTo;
20 import static org.hamcrest.Matchers.hasItems;
21 import static org.hamcrest.Matchers.is;
22 import static org.hamcrest.Matchers.nullValue;
23
24 import java.io.File;
25 import java.util.List;
26
27 import org.junit.Test;
28
29 import de.smartics.properties.api.core.domain.DocumentMetaData;
30 import de.smartics.properties.report.ReportBuilder;
31 import de.smartics.properties.report.ReportConfiguration;
32 import de.smartics.properties.report.data.PropertyReportItem;
33 import de.smartics.properties.report.data.PropertyReportSet;
34 import de.smartics.properties.reports.InMemoryPropertyReport;
35 import de.smartics.testdoc.annotations.Uut;
36 import de.smartics.util.test.io.FileTestUtils;
37
38
39
40
41 @Uut(type = ReportBuilder.class)
42 public class ReportBuilderSimpleTest
43 {
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 protected final ReportConfiguration createConfiguration(
59 final String projectName)
60 {
61 final File sourceTree = resolveSourceTree(projectName);
62 final ReportConfiguration conf = new ReportConfiguration();
63 conf.addSourceTree(sourceTree);
64 conf.setProjectClassLoader(Thread.currentThread().getContextClassLoader());
65 return conf;
66 }
67
68 protected final File resolveSourceTree(final String projectName)
69 {
70 final String resource = "projects/" + projectName;
71 final File sourceTree =
72 FileTestUtils.getFileFromRelativeResource(getClass(), resource);
73 return sourceTree;
74 }
75
76
77
78 @Test
79 public void reportOnPlain()
80 {
81 final ReportConfiguration configuration = createConfiguration("plain");
82 final ReportBuilder uut = ReportBuilder.create(configuration);
83 final InMemoryPropertyReport report = new InMemoryPropertyReport();
84 uut.reportTo(report);
85
86 final List<PropertyReportItem> items = report.getItems();
87 assertThat(items.isEmpty(), is(equalTo(false)));
88 }
89
90 @Test
91 public void reportOnAnnotations()
92 {
93 final ReportConfiguration configuration = createConfiguration("projectdoc");
94 final ReportBuilder uut = ReportBuilder.create(configuration);
95 final InMemoryPropertyReport report = new InMemoryPropertyReport();
96 uut.reportTo(report);
97 checkReportSets(report);
98 checkReportItems(report);
99 }
100
101 private void checkReportSets(final InMemoryPropertyReport report)
102 {
103 final List<PropertyReportSet> reportSets = report.getSets();
104 assertThat(reportSets.size(), is(equalTo(1)));
105
106 final PropertyReportSet reportSet = reportSets.get(0);
107 assertThat(reportSet.getComment(),
108 is(equalTo("Class that implements the property descriptor interface.")));
109
110 final DocumentMetaData metadata = reportSet.getMetaData();
111 assertThat(metadata.getCategories(), hasItems("parentCategory"));
112 assertThat(metadata.getTags(), hasItems("parentTag"));
113 assertThat(metadata.getParents(), hasItems("P1"));
114 assertThat(metadata.getName(), is(equalTo("P")));
115 assertThat(metadata.getShortDescription(), is(equalTo("S.")));
116 assertThat(metadata.getNotes(), hasItems("P1", "P2"));
117 assertThat(metadata.getSpace(), is("SpaceP"));
118 assertThat(metadata.getTitle(), is("Title P"));
119 assertThat(metadata.getSortKey(), is("skp"));
120 assertThat(metadata.getSummary(), is("Parent Summary"));
121 assertThat(metadata.getAudience(), hasItems("pm1", "pm2"));
122 }
123
124 private void checkReportItems(final InMemoryPropertyReport report)
125 {
126 final List<PropertyReportItem> items = report.getItems();
127 assertThat(items.size(), is(equalTo(2)));
128
129 final PropertyReportItem reportItem1 = items.get(0);
130 assertThat(reportItem1.getComment(),
131 is(equalTo("The name 1 of a property.")));
132 final DocumentMetaData metadata1 = reportItem1.getMetaData();
133 assertThat(metadata1.getCategories(),
134 hasItems("parentCategory", "C1Category1"));
135 assertThat(metadata1.getTags(), hasItems("parentTag", "C1Tag1"));
136 assertThat(metadata1.getParents(), hasItems("C1"));
137 assertThat(metadata1.getName(), is(equalTo("C1")));
138 assertThat(metadata1.getShortDescription(), is(equalTo("S1.")));
139 assertThat(metadata1.getNotes(), hasItems("C1"));
140 assertThat(metadata1.getSpace(), is("SC1"));
141 assertThat(metadata1.getTitle(), is("Title C1"));
142 assertThat(metadata1.getSortKey(), is("c1"));
143 assertThat(metadata1.getSummary(), is("Child 1 Summary"));
144 assertThat(metadata1.getAudience(), hasItems("pm1", "pm2", "cm1"));
145
146 final PropertyReportItem reportItem2 = items.get(1);
147 assertThat(reportItem2.getComment(),
148 is(equalTo("The name 2 of a property.")));
149 final DocumentMetaData metadata2 = reportItem2.getMetaData();
150 assertThat(metadata2.getCategories(),
151 hasItems("parentCategory", "C2Category1", "C2Category2"));
152 assertThat(metadata2.getTags(), hasItems("parentTag", "C2Tag1", "C2Tag2"));
153 assertThat(metadata2.getParents(), hasItems("C2-1", "C2-2"));
154 assertThat(metadata2.getName(), is("P.name2"));
155 assertThat(metadata2.getShortDescription(), is(nullValue()));
156 assertThat(metadata2.getNotes().isEmpty(), is(true));
157 assertThat(metadata2.getSpace(), is("SpaceP"));
158 assertThat(metadata2.getTitle(), is("Title P.name2"));
159 assertThat(metadata2.getSortKey(), is(nullValue()));
160 assertThat(metadata2.getSummary(), is(nullValue()));
161 assertThat(metadata2.getAudience(), hasItems("pm1", "pm2"));
162 }
163 }