This project has retired. For details please refer to its Attic page.
AES128CryptorTest xref
View Javadoc
1   /*
2    * Copyright 2014 The Apache Software Foundation.
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  
17  package org.apache.juddi.v3.client.cryptor;
18  
19  import java.security.InvalidKeyException;
20  import java.security.NoSuchAlgorithmException;
21  import java.security.spec.InvalidKeySpecException;
22  import java.util.logging.Level;
23  import java.util.logging.Logger;
24  import javax.crypto.NoSuchPaddingException;
25  import org.junit.Test;
26  import static org.junit.Assert.*;
27  
28  /**
29   *
30   * @author Alex O'Ree
31   */
32  public class AES128CryptorTest {
33          
34          public AES128CryptorTest() {
35          }
36  
37          /**
38           * Test of getKey method, of class AES128Cryptor.
39           */
40          @Test
41          public void testGetKey() {
42                  try {
43                          System.out.println("getKey");
44                          AES128Cryptor instance = new AES128Cryptor();
45                          String result = instance.getKey();
46                          assertNotNull(result);
47                  } catch (NoSuchAlgorithmException ex) {
48                          Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
49                  } catch (InvalidKeySpecException ex) {
50                          Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
51                  } catch (NoSuchPaddingException ex) {
52                          Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
53                  } catch (InvalidKeyException ex) {
54                          Logger.getLogger(AES128CryptorTest.class.getName()).log(Level.SEVERE, null, ex);
55                  }
56          }
57  
58          /**
59           * Test of encrypt method, of class AES128Cryptor.
60           */
61          @Test
62          public void testEncrypt() throws Exception {
63                  System.out.println("encrypt");
64                  String str = "test";
65                  AES128Cryptor instance = new AES128Cryptor();
66                  String result = instance.encrypt(str);
67                  assertNotEquals(str, result);
68          }
69  
70          /**
71           * Test of decrypt method, of class AES128Cryptor. EXTERNAL KEY
72           */
73          @Test
74          public void testExternalKey() throws Exception {
75                  System.out.println("testExternalKey");
76                  AES128Cryptor instance = new AES128Cryptor();
77                  String result = instance.getKey();
78                  System.getProperties().put("juddi.encryptionKeyFile.AES128Cryptor", "./src/test/resources/JUDDI-808/aes128.key");
79                  String expResult = instance.getKey();
80                  System.getProperties().remove("juddi.encryptionKeyFile.AES128Cryptor");
81                  assertNotEquals("loading of external key failed", expResult, result);
82                  String enc = instance.decrypt(instance.encrypt("test"));
83                  assertEquals(enc, "test");
84          }
85          
86          /**
87           * Test of decrypt method, of class AES128Cryptor. 
88           */
89          @Test
90          public void testDecrypt() throws Exception {
91                  System.out.println("testDecrypt");
92                  String str = "test";
93                  AES128Cryptor instance = new AES128Cryptor();
94                  String expResult = "test";
95                  String result = instance.decrypt(instance.encrypt(str));
96                  assertEquals(expResult, result);
97          }
98  
99          /**
100          * Test of newKey method, of class AES128Cryptor.
101          */
102         @Test
103         public void testNewKey() throws Exception{
104                 System.out.println("newKey");
105                 AES128Cryptor instance = new AES128Cryptor();
106                 String result = instance.newKey();
107                 assertNotNull(result);
108         }
109         
110 }