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.property.metadata;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.empty;
20  import static org.hamcrest.Matchers.is;
21  import static org.hamcrest.Matchers.nullValue;
22  
23  import org.junit.Before;
24  import org.junit.Test;
25  
26  import de.smartics.projectdoc.annotations.DocCategory;
27  import de.smartics.projectdoc.annotations.Document;
28  import de.smartics.projectdoc.annotations.topic.DocChapter;
29  import de.smartics.properties.api.config.domain.ConfigurationProperties;
30  import de.smartics.properties.api.core.domain.DocumentMetaData;
31  import de.smartics.properties.api.core.domain.PropertyDescriptor;
32  import de.smartics.properties.impl.config.classpath.ClasspathConfigurationProperties;
33  import de.smartics.properties.impl.config.classpath.ClasspathConfigurationPropertiesFactory;
34  
35  /**
36   * This tutorial introduces to the document meta data that allows to integrate
37   * the documentation of properties into a project documentation.
38   */
39  @Document(title = "Property Metadata", sortKey = "basics0040")
40  @DocCategory({ "basics" })
41  // @DocTopic(path="basics", step="40")
42  public class PropertyMetaDataTutorial
43  {
44    private ConfigurationProperties config; // NOPMD
45  
46    private MetaDataProperties properties;
47  
48    @Before
49    public void setUp()
50    {
51      config = createConfiguration();
52      properties = config.getProperties(MetaDataProperties.class);
53    }
54  
55    private static ConfigurationProperties createConfiguration()
56    {
57      final ClasspathConfigurationPropertiesFactory factory =
58          new ClasspathConfigurationPropertiesFactory();
59      final ClasspathConfigurationProperties config = factory.create();
60      config.addClassPathProperties(MetaDataProperties.class);
61      return config;
62    }
63  
64    /**
65     * If no further metadata is attached to a properties set, the following
66     * metadata is created per default.
67     * <ol>
68     * <li>Title of the document: defaults to the fully qualified name of the
69     * property</li>
70     * <li>The space within which the title is unique: defaults to the type that
71     * declares the property</li>
72     * <li>The unique name of the document: defaults to the fully qualified name
73     * of the property, too</li>
74     * </ol>
75     * {@insertCode}
76     */
77    @DocChapter
78    @Test
79    public void defaultMetaData()
80    {
81      final PropertyDescriptor descriptor = properties.hostPropertyDescriptor();
82  
83      final DocumentMetaData metaData = descriptor.getDocumentMetaData();
84      assertThat(metaData.getCategories(), is(empty()));
85      assertThat(metaData.getTags(), is(empty()));
86      assertThat(metaData.getParents(), is(empty()));
87      assertThat(metaData.getAudience(), is(empty()));
88  
89      assertThat(metaData.getNotes(), is(empty()));
90      assertThat(metaData.getShortDescription(), is(nullValue()));
91      assertThat(metaData.getSummary(), is(nullValue()));
92      assertThat(metaData.getTitle(), is("tutorial.property.metadata.host"));
93      assertThat(metaData.getSortKey(), is(nullValue()));
94  
95      assertThat(
96          metaData.getSpace(),
97          is("property:de.smartics.properties.tutorial.property.metadata.MetaDataProperties"));
98      assertThat(metaData.getName(), is("tutorial.property.metadata.host"));
99    }
100 
101   /**
102    * PENDING: Show how to add documentation metadata.
103    */
104   @DocChapter
105   @Test
106   public void documentationMetaData()
107   {
108   }
109 }