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.resolve;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.is;
20  
21  import org.junit.Before;
22  import org.junit.Test;
23  
24  import de.smartics.projectdoc.annotations.DocCategory;
25  import de.smartics.projectdoc.annotations.Document;
26  import de.smartics.projectdoc.annotations.topic.DocChapter;
27  import de.smartics.properties.api.config.domain.ConfigurationProperties;
28  import de.smartics.properties.api.core.domain.PropertyValueResolveException;
29  import de.smartics.properties.impl.config.classpath.ClasspathConfigurationProperties;
30  import de.smartics.properties.impl.config.classpath.ClasspathConfigurationPropertiesFactory;
31  
32  /**
33   * This tutorial provides information about resolving .
34   */
35  @Document(title = "Resolve Properties", sortKey = "basics0200")
36  @DocCategory({ "basics" })
37  // @DocTopic(path="basics", step="200")
38  public class PropertyResolveTutorial
39  {
40    private ConfigurationProperties config; // NOPMD
41  
42    private ResolveProperties properties;
43  
44    @Before
45    public void setUp()
46    {
47      config = createConfiguration();
48      properties = config.getProperties(ResolveProperties.class);
49    }
50  
51    private static ConfigurationProperties createConfiguration()
52    {
53      final ClasspathConfigurationPropertiesFactory factory =
54          new ClasspathConfigurationPropertiesFactory();
55      final ClasspathConfigurationProperties config = factory.create();
56      config.addClassPathProperties(ResolveProperties.class);
57      return config;
58    }
59  
60    @DocChapter
61    @Test
62    public void transitiveReferences()
63    {
64      final String property = properties.property();
65  
66      assertThat(property, is("referenced transitive"));
67    }
68  
69    @DocChapter
70    @Test(expected=PropertyValueResolveException.class)
71    public void illegalBackReference()
72    {
73      properties.backProperty();
74    }
75  
76    @DocChapter
77    @Test(expected=PropertyValueResolveException.class)
78    public void referenceToAPropertyWithANullValue()
79    {
80      properties.nullProperty();
81    }
82  
83    @DocChapter
84    @Test(expected=PropertyValueResolveException.class)
85    public void illegalUnknownReference()
86    {
87      properties.illegalUnknownReference();
88    }
89  }