1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.reports;
17
18 import static org.junit.Assert.assertEquals;
19
20 import java.io.UnsupportedEncodingException;
21 import java.lang.reflect.Method;
22
23 import org.junit.Before;
24 import org.junit.Test;
25
26 import de.smartics.properties.api.core.domain.DocumentMetaData;
27 import de.smartics.properties.api.core.domain.PropertyDescriptor;
28 import de.smartics.properties.report.data.PropertyReportItem;
29 import de.smartics.properties.report.data.PropertyReportSet;
30 import de.smartics.properties.report.data.SourceInfo;
31 import de.smartics.properties.report.data.ValueComment;
32 import de.smartics.properties.reports.XmlPropertyReport;
33 import de.smartics.properties.spi.core.metadata.PropertyMetaDataParser;
34 import de.smartics.properties.spi.core.metadata.projectdoc.ProjectdocMetaData;
35 import de.smartics.testdoc.annotations.Uut;
36 import de.smartics.util.io.MemoryStreamHandler;
37 import de.smartics.util.lang.StringFunction;
38
39
40
41
42 public class XmlPropertyReportTest
43 {
44
45
46
47
48
49
50 @Uut
51 private XmlPropertyReport uut;
52
53 private MemoryStreamHandler setReportsRoot;
54
55 private MemoryStreamHandler propertyReportsRoot;
56
57
58
59
60
61
62
63 @Before
64 public void setUp()
65 {
66 setReportsRoot = new MemoryStreamHandler();
67 propertyReportsRoot = new MemoryStreamHandler();
68
69 uut = new XmlPropertyReport(setReportsRoot, propertyReportsRoot);
70 }
71
72
73
74
75
76
77 @Test
78 public void generatesPropertySetReport() throws UnsupportedEncodingException
79 {
80 final PropertyReportSet.Builder builder = new PropertyReportSet.Builder();
81 final String name = "name";
82 final DocumentMetaData metaData = createMetaData(name);
83 builder.with(metaData);
84 final String type = "type";
85 builder.withType(type);
86 final String comment = "comment";
87 builder.withComment(comment);
88 final PropertyReportSet reportData = builder.build();
89 uut.handle(reportData);
90
91 final byte[] data = setReportsRoot.getData(name + ".xml");
92 final String xml = StringFunction.strip(new String(data, "UTF-8"));
93 assertEquals(
94 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
95 + " <property-set "
96 + "xmlns=\"http://www.smartics.de/schema/projectdoc/doctype/property-set/1\""
97 + " name=\"name\"><identification><space>space</space><title>title</title></identification>"
98 + "<filing><parents><parent>parent1</parent><parent>parent2</parent>"
99 + "</parents><categories><category>category1</category>"
100 + "<category>category2</category></categories><tags>"
101 + "<tag>tag1</tag><tag>tag2</tag></tags>"
102 + "<sortKey>sortKey1</sortKey></filing><description><audience>"
103 + "<member>audience1</member><member>audience2</member></audience>"
104 + "<shortDescription>shortDescription</shortDescription>"
105 + "<summary>summary</summary><notes><ol "
106 + "xmlns=\"http://www.w3.org/1999/xhtml\"><li>Note 1</li>"
107 + "<li>Note 2</li></ol></notes></description>"
108 + "<specification>comment</specification></property-set>", xml);
109 }
110
111
112 @Test
113 public void generatesPropertyReport() throws Exception
114 {
115 final PropertyReportItem.Builder builder = new PropertyReportItem.Builder();
116
117 final ValueComment valueComment = new ValueComment("Value summary");
118 valueComment.addValueComment(EnumValue.ONE, "1");
119 valueComment.addValueComment(EnumValue.TWO, "2");
120 valueComment.addValueComment(EnumValue.THREE, "3");
121 builder.with(valueComment);
122
123 final PropertyMetaDataParser parser =
124 PropertyMetaDataParser.createWithoutContextAccess();
125 final Method method =
126 TestProperty.class.getDeclaredMethod("enumProperty", new Class<?>[0]);
127 final PropertyDescriptor desc = parser.readDescriptor(method);
128 builder.with(desc);
129
130 final String comment = "comment";
131 builder.withComment(comment);
132
133 builder.with(new SourceInfo("de.smartics.test.Test", "ELEMENT", 42));
134
135 final PropertyReportItem reportData = builder.build();
136 uut.handle(reportData);
137
138 final byte[] data = propertyReportsRoot.getData("name.xml");
139 final String xml = StringFunction.strip(new String(data, "UTF-8"));
140 assertEquals(
141 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
142 + " <property xmlns=\"http://www.smartics.de/schema/projectdoc/doctype/property/1\""
143 + " name=\"name\"><identification><space>space</space>"
144 + "<title>title</title></identification><filing><parents><parent>"
145 + "parent1</parent><parent>parent2</parent></parents><categories>"
146 + "<category>category1</category><category>category2</category>"
147 + "</categories><tags><tag>tag1</tag><tag>tag2</tag></tags>"
148 + "<sortKey>sortKey1</sortKey></filing><description><audience>"
149 + "<member>audience1</member><member>audience2</member>"
150 + "</audience><shortDescription>shortDescription</shortDescription>"
151 + "<summary>summary</summary><notes><ol "
152 + "xmlns=\"http://www.w3.org/1999/xhtml\"><li>Note 1</li>"
153 + "<li>Note 2</li></ol></notes></description>"
154 + "<propertySet>test.de.smartics.properties.reports.TestProperty</propertySet><name>"
155 + "test.de.smartics.properties.reports.TestProperty.enumProperty"
156 + "</name><type>test.de.smartics.properties.reports.EnumValue"
157 + "</type><specification>comment</specification><valueRange>"
158 + "<summary>Value summary</summary><element><value>one</value>"
159 + "<description>1</description></element><element><value>two"
160 + "</value><description>2</description></element><element>"
161 + "<value>three</value><description>3</description></element>"
162 + "</valueRange><valueConstraints><constraint><type>"
163 + "de.smartics.properties.spi.core.constraints.PropertyRangeConstraint"
164 + "</type><description>Select one of the following values: one, "
165 + "two, three</description></constraint></valueConstraints>"
166 + "<implementation><type>de.smartics.test.Test</type><field>"
167 + "ELEMENT</field><lineNumber>42</lineNumber></implementation>"
168 + "</property>", xml);
169 }
170
171 private DocumentMetaData createMetaData(final String name)
172 {
173 final ProjectdocMetaData metadata = new ProjectdocMetaData();
174 metadata.setName(name);
175
176 metadata.addAudience("audience1");
177 metadata.addAudience("audience2");
178 metadata.addCategory("category1");
179 metadata.addCategory("category2");
180 metadata.addNote("Note 1");
181 metadata.addNote("Note 2");
182 metadata.addParent("parent1");
183 metadata.addParent("parent2");
184 metadata.setSortKey("sortKey1");
185 metadata.setSpace("space");
186 metadata.addTag("tag1");
187 metadata.addTag("tag2");
188
189 metadata.setShortDescription("shortDescription");
190 metadata.setSummary("summary");
191 metadata.setTitle("title");
192 return metadata;
193 }
194 }