View Javadoc

1   /*
2    * Copyright 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.security.esapi;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.equalTo;
20  import static org.hamcrest.Matchers.is;
21  import help.de.smartics.properties.core.PropertyDescriptorBuilder;
22  
23  import org.junit.Before;
24  import org.junit.Test;
25  
26  import de.smartics.properties.api.core.domain.PropertyDescriptor;
27  import de.smartics.properties.security.esapi.EsapiPropertyValueSecurity;
28  import de.smartics.testdoc.annotations.Uut;
29  
30  /**
31   * Tests {@link EsapiPropertyValueSecurity}.
32   */
33  public class EsapiPropertyValueSecurityTest
34  {
35    // ********************************* Fields *********************************
36  
37    // --- constants ------------------------------------------------------------
38  
39    // --- members --------------------------------------------------------------
40  
41    @Uut
42    private EsapiPropertyValueSecurity uut;
43  
44    // ****************************** Inner Classes *****************************
45  
46    // ********************************* Methods ********************************
47  
48    // --- prepare --------------------------------------------------------------
49  
50    @Before
51    public void setUp()
52    {
53      uut = new EsapiPropertyValueSecurity();
54    }
55  
56    // --- helper ---------------------------------------------------------------
57  
58    // --- tests ----------------------------------------------------------------
59  
60    @Test
61    public void allowsToEncryptAndDecrypt()
62    {
63      final PropertyDescriptor descriptor =
64          PropertyDescriptorBuilder.defaultPropertyDescriptor();
65      final String value = "plain";
66      final String encrypted = uut.encrypt(descriptor, value);
67      final String decrypted = uut.decrypt(descriptor, encrypted);
68      assertThat(decrypted, is(equalTo(value)));
69    }
70  }