1 package org.apache.turbine.services.crypto;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.fulcrum.crypto.CryptoAlgorithm;
23 import org.apache.fulcrum.crypto.CryptoService;
24 import org.apache.turbine.services.ServiceManager;
25 import org.apache.turbine.services.TurbineServices;
26 import org.apache.turbine.test.BaseTestCase;
27 import org.apache.turbine.util.TurbineConfig;
28
29
30
31
32
33
34
35
36
37 public class FulcrumCryptoServiceTest extends BaseTestCase
38 {
39 private static final String preDefinedInput = "Oeltanks";
40 private static TurbineConfig tc = null;
41 private CryptoService cryptoService;
42
43 public FulcrumCryptoServiceTest(String name) throws Exception
44 {
45 super(name);
46 }
47
48 public void testMd5()
49 {
50 String preDefinedResult = "XSop0mncK19Ii2r2CUe29w==";
51
52 try
53 {
54 CryptoAlgorithm ca =cryptoService.getCryptoAlgorithm("default");
55 ca.setCipher("MD5");
56 String output = ca.encrypt(preDefinedInput);
57 assertEquals("MD5 Encryption failed ", preDefinedResult, output);
58 }
59 catch (Exception e)
60 {
61 e.printStackTrace();
62 fail();
63 }
64 }
65
66 public void testSha1()
67 {
68 String preDefinedResult = "uVDiJHaavRYX8oWt5ctkaa7j1cw=";
69
70 try
71 {
72 CryptoAlgorithm ca = cryptoService.getCryptoAlgorithm("default");
73 ca.setCipher("SHA1");
74 String output = ca.encrypt(preDefinedInput);
75 assertEquals("SHA1 Encryption failed ", preDefinedResult, output);
76 }
77 catch (Exception e)
78 {
79 e.printStackTrace();
80 fail();
81 }
82 }
83
84 public void setUp() throws Exception
85 {
86 tc = new TurbineConfig(".", "/conf/test/TestFulcrumComponents.properties");
87 tc.initialize();
88 ServiceManager serviceManager = TurbineServices.getInstance();
89 cryptoService = (CryptoService) serviceManager.getService(CryptoService.ROLE);
90 }
91
92 public void tearDown() throws Exception
93 {
94 if (tc != null)
95 {
96 tc.dispose();
97 }
98 }
99 }