1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.spring;
17
18 import java.io.File;
19 import java.io.FileInputStream;
20 import java.io.FileOutputStream;
21 import java.io.IOException;
22 import java.io.ObjectInputStream;
23 import java.io.ObjectOutputStream;
24
25 import org.apache.commons.io.FileUtils;
26 import org.junit.Assert;
27 import org.kuali.student.r2.common.messages.service.MessageService;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31
32
33
34
35
36 public final class SpringProxyTestUtils {
37 private static final Logger log = LoggerFactory
38 .getLogger(SpringProxyTestUtils.class);
39
40
41
42
43 private SpringProxyTestUtils() {
44
45 }
46
47 public static Object testBeanSerialization(Object bean, long expectedSize) throws IOException, ClassNotFoundException {
48
49 File tempFile = File.createTempFile("proxy", "dat");
50
51 ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(tempFile));
52
53 oos.writeObject(bean);
54 oos.flush();
55 oos.close();
56
57
58
59 long serializedSizeInBytes = FileUtils.sizeOf(tempFile);
60
61 Assert.assertEquals(expectedSize, serializedSizeInBytes);
62
63 ObjectInputStream iis = new ObjectInputStream(new FileInputStream(tempFile));
64
65 Object deserialized = iis.readObject();
66
67 iis.close();
68
69 return deserialized;
70
71 }
72
73 public static Object testBeanSerialization(Object bean, String expectedToStringValue, long expectedSize) throws IOException, ClassNotFoundException {
74
75 File tempFile = File.createTempFile("proxy", "dat");
76
77 ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(tempFile));
78
79 oos.writeObject(bean);
80 oos.flush();
81 oos.close();
82
83
84
85 long serializedSizeInBytes = FileUtils.sizeOf(tempFile);
86
87 Assert.assertEquals(expectedSize, serializedSizeInBytes);
88
89 ObjectInputStream iis = new ObjectInputStream(new FileInputStream(tempFile));
90
91 Object generated = iis.readObject();
92
93 iis.close();
94
95 Assert.assertEquals(expectedToStringValue, generated.toString());
96
97 return generated;
98 }
99 }