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 import org.junit.AfterClass;
29 import org.junit.Before;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32
33 import static org.junit.Assert.*;
34
35
36
37
38
39
40
41
42
43 public class FulcrumCryptoServiceTest extends BaseTestCase
44 {
45 private static final String preDefinedInput = "Oeltanks";
46 private static TurbineConfig tc = null;
47 private CryptoService cryptoService;
48
49
50
51 @Test public void testMd5()
52 {
53 String preDefinedResult = "XSop0mncK19Ii2r2CUe29w==";
54
55 try
56 {
57 CryptoAlgorithm ca =cryptoService.getCryptoAlgorithm("default");
58 ca.setCipher("MD5");
59 String output = ca.encrypt(preDefinedInput);
60 assertEquals("MD5 Encryption failed ", preDefinedResult, output);
61 }
62 catch (Exception e)
63 {
64 e.printStackTrace();
65 fail();
66 }
67 }
68
69 @Test public void testSha1()
70 {
71 String preDefinedResult = "uVDiJHaavRYX8oWt5ctkaa7j1cw=";
72
73 try
74 {
75 CryptoAlgorithm ca = cryptoService.getCryptoAlgorithm("default");
76 ca.setCipher("SHA1");
77 String output = ca.encrypt(preDefinedInput);
78 assertEquals("SHA1 Encryption failed ", preDefinedResult, output);
79 }
80 catch (Exception e)
81 {
82 e.printStackTrace();
83 fail();
84 }
85 }
86
87 @BeforeClass
88 public static void init() throws Exception
89 {
90 tc = new TurbineConfig(".", "/conf/test/TestFulcrumComponents.properties");
91 tc.initialize();
92
93 }
94
95 @Before
96 public void setUpBefore() throws Exception
97 {
98 ServiceManager serviceManager = TurbineServices.getInstance();
99 cryptoService = (CryptoService) serviceManager.getService(CryptoService.ROLE);
100 }
101
102 @AfterClass
103 public static void tearDown() throws Exception
104 {
105 if (tc != null)
106 {
107 tc.dispose();
108 }
109 }
110 }