View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.tutorial.config.doc;
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.io.Serializable;
23  import java.util.List;
24  
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  import de.smartics.projectdoc.annotations.DocCategory;
29  import de.smartics.projectdoc.annotations.Document;
30  import de.smartics.projectdoc.annotations.topic.DocChapter;
31  import de.smartics.properties.api.config.app.ConfigurationPropertiesFactory;
32  import de.smartics.properties.api.config.app.ConfigurationPropertiesFactoryFactory;
33  import de.smartics.properties.api.config.domain.ConfigurationPropertiesManagement;
34  import de.smartics.properties.api.config.domain.key.ApplicationId;
35  import de.smartics.properties.api.config.domain.key.ConfigurationKey;
36  import de.smartics.properties.api.config.domain.key.EnvironmentId;
37  import de.smartics.properties.api.core.domain.PropertyComment;
38  import de.smartics.properties.api.core.domain.PropertyDescriptor;
39  import de.smartics.properties.api.core.domain.PropertyType;
40  import de.smartics.properties.api.core.domain.PropertyValueComment;
41  import de.smartics.properties.impl.config.domain.key.rtaware.TenantUserConfigurationKey;
42  import de.smartics.sandbox.agile.Priority;
43  import de.smartics.sandbox.agile.UserStoryProperties;
44  
45  /**
46   * This tutorial shows how documentation information is provided at runtime.
47   */
48  @Document(title = "Providing Configuration Keys", sortKey = "basics1100")
49  @DocCategory({ "basics" })
50  // @DocTopic(path="basics", step="1100")
51  public class PropertyDocumentationTutorial
52  {
53    private UserStoryProperties properties;
54  
55    @Before
56    public void setUp()
57    {
58      final ConfigurationPropertiesFactory factory =
59          ConfigurationPropertiesFactoryFactory.createDefaultFactory();
60  
61      final ConfigurationKey<?> key =
62          new TenantUserConfigurationKey(new EnvironmentId("test"), new ApplicationId(
63              "de.smartics.sandbox", "test-application", "0.1.0"));
64      final ConfigurationPropertiesManagement config =
65          factory.createManagement(key);
66      properties = config.getProperties(UserStoryProperties.class);
67    }
68  
69    /**
70     * <p>
71     * To access the Javadoc comment of a property, the properties definition
72     * bundle requires metadata information in it's <code>META-INF</code> folder.
73     * This is automatically provided by the <a
74     * href="http://www.smartics.eu/smartics-properties-maven-plugin/"
75     * >smartics-properties-maven-plugin</a>. Please refer to the documentation of
76     * this plugin for information about how to configure a properties definition
77     * project to make use of this plugin (or have a look at the <a
78     * href="http://www.smartics.eu/test-module-agile/">test-module-agile</a>
79     * project).
80     * </p>
81     * <p>
82     * For this example we assume that the properties definition have been
83     * successfully provided.
84     * </p>
85     * {@insertCode}
86     * <p>
87     * The comment is provided via the {@link PropertyDescriptor} ({@$1}). At
88     * {@$2} the comment is read and it shows the text provided by the
89     * developer in the Javadoc comment. This is a simple example since there are
90     * no constraints.
91     * </p>
92     */
93    @DocChapter
94    @Test
95    public void accessJavadocComment()
96    {
97      final PropertyDescriptor desc = properties.namePropertyDescriptor(); // {1}
98  
99      // {2}
100     final PropertyComment comment = desc.getComment();
101     assertThat(comment.getText(), is("The name of a user story."));
102   }
103 
104   /**
105    * <p>
106    * </p>
107    */
108   @DocChapter
109   @Test
110   public void accessPropertyRangeComment()
111   {
112     final PropertyDescriptor desc = properties.storyPointPropertyDescriptor();
113 
114     // {1}
115     final PropertyComment comment = desc.getComment();
116     assertThat(
117         comment.getText(),
118         is("The story point stating the estimated work to implement the story."));
119     assertThat(desc.getDefaultExpression().getExpression(), is("8"));
120   }
121 
122   /**
123    * <p>
124    * If the value comment is an enumeration type, the comments of the elements
125    * is also accessible.
126    * </p>
127    * {@insertCode}
128    * <p>
129    * At {@$1} we again access the Javadoc comment of the property. In this
130    * case the type of the property {@link Priority} which is an enumeration type
131    * ({@$2}). Therefore the comment of the enumeration type and the
132    * comments from the enumeration elements are also accessible. At {@$3}
133    * the comment of the enumeration type is accessed, at {@$4} the
134    * individual comments of the enumeration type.
135    * </p>
136    */
137   @DocChapter
138   @Test
139   public void accessValueComment()
140   {
141     final PropertyDescriptor desc =
142         properties.businessPriorityPropertyDescriptor();
143 
144     // {1}
145     final PropertyComment comment = desc.getComment();
146     assertThat(comment.getText(),
147         is("The business priority of the user story."));
148 
149     // {2}
150     final PropertyType type = desc.getType();
151     assertThat(type.getType().getName(), is(equalTo(Priority.class.getName())));
152 
153     // {3}
154     final PropertyValueComment valueComment = comment.getValueComment();
155     assertThat(valueComment.getSummary(),
156         is("The valid priority values for user stories."
157            + " <p> Only {@link #REQUIRED required},"
158            + " {@link #VERY_IMPORTANT very important} are items that are"
159            + " necessary to be implemented. </p>"));
160 
161     // {4}
162     final List<Serializable> values = valueComment.getValues();
163     assertThat(
164         valueComment.getValueComment(values.get(0)),
165         is("The story is required for the final product."
166            + " <p> This and {@link #VERY_IMPORTANT} are items necessary to be implemented. </p>"));
167     assertThat(
168         valueComment.getValueComment(values.get(1)),
169         is("The story is very important for the final product."
170            + " <p> This and {@link #REQUIRED} are items necessary to be implemented. </p>"));
171     assertThat(valueComment.getValueComment(values.get(2)),
172         is("The story is a nice-to-have for the final product,"
173            + " but not relevant for the release."));
174     assertThat(valueComment.getValueComment(values.get(3)),
175         is("The story would add to the user experience of the user,"
176            + " but is not relevant for the release."));
177     assertThat(valueComment.getValueComment(values.get(4)),
178         is("The story is not necessary to be part of the release, but may"
179            + " be included if resources are available. If the product backlog"
180            + " contains only dispensable stores, the development is likely to"
181            + " come to an end. <p> The priority is available to keep stories"
182            + " in the product backlog for further references. </p>"));
183 
184   }
185 }