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 static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.is;
20  
21  import java.lang.reflect.Method;
22  
23  import org.junit.Test;
24  
25  import de.smartics.properties.api.core.annotations.PropertyValueSecured;
26  import de.smartics.properties.api.core.domain.PropertyDescriptor;
27  import de.smartics.properties.spi.core.metadata.PropertyMetaDataParser;
28  import de.smartics.testdoc.annotations.Uut;
29  
30  /**
31   * Tests {@link de.smartics.properties.spi.core.metadata.PropertyMetaDataParser}
32   * with secured properties.
33   */
34  @Uut(type = PropertyMetaDataParser.class)
35  public class PropertyMetaDataParserSecuredTest extends
36      AbstractPropertyMetaDataParserTestBase
37  { // NOPMD
38    // ********************************* Fields *********************************
39  
40    // --- constants ------------------------------------------------------------
41  
42    // --- members --------------------------------------------------------------
43  
44    // ****************************** Inner Classes *****************************
45  
46    public interface TestProperties
47    {
48      @PropertyValueSecured
49      String secured();
50  
51      @PropertyValueSecured(decrypt = true)
52      String explicitlySecured();
53  
54      @PropertyValueSecured(decrypt = false)
55      String noDecryption();
56  
57      String plain();
58    }
59  
60    // ********************************* Methods ********************************
61  
62    // --- prepare --------------------------------------------------------------
63  
64    // --- helper ---------------------------------------------------------------
65  
66    private void runTest(final String methodName, final boolean expected)
67    {
68      final Method method = fetchMethod(TestProperties.class, methodName);
69      final PropertyDescriptor descriptor = uut.readDescriptor(method);
70      assertThat(descriptor.isSecured(), is(expected));
71    }
72  
73    // --- tests ----------------------------------------------------------------
74  
75    @Test
76    public void recognizesSecuredProperties()
77    {
78      runTest("secured", true);
79    }
80  
81    @Test
82    public void recognizesExplicitlySecuredProperties()
83    {
84      runTest("explicitlySecured", true);
85    }
86  
87    @Test
88    public void recognizesNoDecryptedProperties()
89    {
90      runTest("noDecryption", false);
91    }
92  
93    @Test
94    public void recognizesNonSecuredProperties()
95    {
96      runTest("plain", false);
97    }
98  }