1 package org.jastacry.layer;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.io.ByteArrayInputStream;
6 import java.io.ByteArrayOutputStream;
7 import java.io.InputStream;
8 import java.io.OutputStream;
9
10 import org.jastacry.JastacryException;
11 import org.junit.jupiter.api.AfterEach;
12 import org.junit.jupiter.api.BeforeEach;
13 import org.junit.jupiter.api.Test;
14
15
16
17
18
19
20
21 public class TestLayerMd5Des
22 {
23
24
25
26 private final String testdata = "The quick brown fox jumps over the lazy dog.";
27
28
29
30
31 private Md5DesLayer layerEncrypt = null;
32
33
34
35
36 private Md5DesLayer layerDecrypt = null;
37
38
39
40
41 private static final String INITVALUE = "Passwort123";
42
43
44
45
46
47
48
49 @BeforeEach
50 public void setUp() throws Exception
51 {
52 layerEncrypt = new Md5DesLayer();
53 layerEncrypt.init(INITVALUE);
54 layerDecrypt = new Md5DesLayer();
55 layerDecrypt.init(INITVALUE);
56 }
57
58
59
60
61
62
63
64 @AfterEach
65 public void tearDown() throws Exception
66 {
67 layerEncrypt = null;
68 layerDecrypt = null;
69 }
70
71
72
73
74
75
76
77 @Test
78
79 public void testEncDecStream() throws JastacryException
80 {
81
82
83 byte[] buf = testdata.getBytes();
84 final InputStream isEncode = new ByteArrayInputStream(buf);
85 final ByteArrayOutputStream osEncode = new ByteArrayOutputStream();
86 layerEncrypt.encStream(isEncode, osEncode);
87 buf = osEncode.toByteArray();
88
89 final InputStream isDecode = new ByteArrayInputStream(buf);
90 final OutputStream osDecode = new ByteArrayOutputStream();
91 layerDecrypt.decStream(isDecode, osDecode);
92 assertEquals("decoding differs", testdata, osDecode.toString());
93 }
94
95
96
97
98 @Test
99
100 public void testToString()
101 {
102 assertEquals("Layer name mismatch", Md5DesLayer.LAYERNAME, layerEncrypt.toString());
103 }
104
105
106
107
108 @Test
109 public void testEquals()
110 {
111 Md5DesLayer l1 = new Md5DesLayer();
112 Md5DesLayer l2 = new Md5DesLayer();
113 l1.init(INITVALUE);
114 l2.init(INITVALUE);
115 assertEquals("Layer object equal", l1, l2);
116 }
117
118
119
120
121 @Test
122 public void testEqualsSame()
123 {
124 Md5DesLayer l1 = new Md5DesLayer();
125 l1.init(INITVALUE);
126 assertEquals("Layer object same", l1, l1);
127 }
128
129
130
131
132 @Test
133 public void testNotEqualsNull()
134 {
135 Md5DesLayer l1 = new Md5DesLayer();
136 l1.init(INITVALUE);
137 Object o = null;
138 assertEquals("Layer object null unequal", l1.equals(o), false);
139 }
140
141
142
143
144 @Test
145 public void testNotEqualsWrongclass()
146 {
147 Md5DesLayer l1 = new Md5DesLayer();
148 l1.init(INITVALUE);
149 Object o = new Object();
150 assertEquals("Layer object wrong class unequal", l1.equals(o), false);
151 }
152
153
154
155
156 @Test
157 public void testHashcode()
158 {
159 Md5DesLayer l1 = new Md5DesLayer();
160 Md5DesLayer l2 = new Md5DesLayer();
161 l1.init(INITVALUE);
162 l2.init(INITVALUE);
163 assertEquals("Layer hash equal", l1.hashCode(), l2.hashCode());
164 }
165
166 }