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 test.de.smartics.properties.spi.core.metadata;
17  
18  import java.lang.reflect.Method;
19  import java.util.Collections;
20  import java.util.List;
21  
22  import org.junit.Test;
23  
24  import de.smartics.properties.api.core.domain.PropertyConstraint;
25  import de.smartics.properties.api.core.domain.PropertyDescriptor;
26  import de.smartics.properties.api.core.domain.PropertyExpression;
27  import de.smartics.properties.api.core.domain.PropertyKey;
28  import de.smartics.properties.api.core.domain.PropertyType;
29  import de.smartics.properties.spi.core.metadata.PropertyMetaDataParser;
30  import de.smartics.testdoc.annotations.Uut;
31  
32  /**
33   * Tests {@link de.smartics.properties.spi.core.metadata.PropertyMetaDataParser} with and
34   * without property key annotations.
35   */
36  @Uut(type = PropertyMetaDataParser.class)
37  public class PropertyMetaDataParserPropertyKeyAnnotationsTest extends
38      AbstractPropertyMetaDataParserTestBase
39  { // NOPMD
40    // ********************************* Fields *********************************
41  
42    // --- constants ------------------------------------------------------------
43  
44    // --- members --------------------------------------------------------------
45  
46    // ****************************** Inner Classes *****************************
47  
48    public interface TestProperties
49    {
50      String property1();
51  
52      @de.smartics.properties.api.core.annotations.PropertyKeyName("some.key")
53      String property2();
54    }
55  
56    // ********************************* Methods ********************************
57  
58    // --- prepare --------------------------------------------------------------
59  
60    // --- helper ---------------------------------------------------------------
61  
62    private void runTest(final String methodName, final String propertyName)
63    {
64      final Method method = fetchMethod(TestProperties.class, methodName);
65      final PropertyDescriptor descriptor = uut.readDescriptor(method);
66  
67      final PropertyKey expectedKey =
68          new PropertyKey(TestProperties.class.getName(), propertyName);
69      final PropertyType expectedType = new PropertyType(String.class);
70      final List<PropertyConstraint<?>> expectedConstraints =
71          Collections.emptyList();
72  
73      checkThat(descriptor, expectedKey, expectedType,
74          PropertyExpression.NO_EXPRESSION, null, expectedConstraints);
75    }
76  
77    // --- tests ----------------------------------------------------------------
78  
79    @Test
80    public void parsesPropertySetOnType()
81    {
82      runTest("property1", "property1");
83    }
84  
85    @Test
86    public void favoursPropertySetOnMethodName()
87    {
88      runTest("property2", "some.key");
89    }
90  }