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 expression annotations.
35   */
36  @Uut(type = PropertyMetaDataParser.class)
37  public class PropertyMetaDataParserPropertyExpressionAnnotationsTest 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.PropertyExpression("${test}expression")
53      String property2();
54    }
55  
56    // ********************************* Methods ********************************
57  
58    // --- prepare --------------------------------------------------------------
59  
60    // --- helper ---------------------------------------------------------------
61  
62    private void runTest(final String methodNameAndPropertyName,
63        final PropertyExpression expression)
64    {
65      final Method method =
66          fetchMethod(TestProperties.class, methodNameAndPropertyName);
67      final PropertyDescriptor descriptor = uut.readDescriptor(method);
68  
69      final PropertyKey expectedKey =
70          new PropertyKey(TestProperties.class.getName(),
71              methodNameAndPropertyName);
72      final PropertyType expectedType = new PropertyType(String.class);
73      final List<PropertyConstraint<?>> expectedConstraints =
74          Collections.emptyList();
75  
76      checkThat(descriptor, expectedKey, expectedType, expression, null,
77          expectedConstraints);
78    }
79  
80    // --- tests ----------------------------------------------------------------
81  
82    @Test
83    public void parsesPropertySetOnType()
84    {
85      runTest("property1", PropertyExpression.NO_EXPRESSION);
86    }
87  
88    @Test
89    public void favoursPropertySetOnMethodName()
90    {
91      runTest("property2", PropertyExpression.create("${test}expression"));
92    }
93  }