|
26 | 26 | import java.util.List;
|
27 | 27 | import java.util.stream.Collectors;
|
28 | 28 |
|
29 |
| -import org.junit.Before; |
| 29 | +import org.junit.BeforeClass; |
30 | 30 | import org.junit.Test;
|
31 | 31 |
|
32 | 32 | import spoon.Launcher;
|
|
38 | 38 |
|
39 | 39 | public class ModelStreamerTest {
|
40 | 40 |
|
41 |
| - private final String filename = "./src/test/resources/serialization/factory.ser"; |
| 41 | + private static final String SOURCE_DIRECTORY = "./src/main/java/spoon/reflect/declaration"; |
| 42 | + private final static String OUTPUT_FILENAME = "./src/test/resources/serialization/factory.ser"; |
| 43 | + private static File outputFile; |
| 44 | + private static Factory factory; |
42 | 45 |
|
43 |
| - private Factory factory; |
44 |
| - |
45 |
| - private File file; |
46 |
| - |
47 |
| - @Before |
48 |
| - public void setUp() { |
| 46 | + @BeforeClass |
| 47 | + public static void setUp() { |
| 48 | + System.out.println("Testing factory serialization with different " |
| 49 | + + "compressors with source folder: " + SOURCE_DIRECTORY); |
49 | 50 | Launcher launcher = new Launcher();
|
50 |
| - launcher.addInputResource("./src/main/java/spoon/reflect/declaration"); |
| 51 | + launcher.addInputResource(SOURCE_DIRECTORY); |
51 | 52 | launcher.buildModel();
|
52 |
| - this.factory = launcher.getFactory(); |
53 |
| - file = new File(filename); |
54 |
| - file.deleteOnExit(); |
| 53 | + factory = launcher.getFactory(); |
| 54 | + outputFile = new File(OUTPUT_FILENAME); |
| 55 | + outputFile.deleteOnExit(); |
55 | 56 | }
|
56 | 57 |
|
57 | 58 | @Test
|
58 | 59 | public void testDefaultCompressionType() throws IOException {
|
59 |
| - new SerializationModelStreamer().save(factory, new FileOutputStream(file)); |
60 |
| - Factory factoryFromFile = new SerializationModelStreamer().load(new FileInputStream(file)); |
| 60 | + new SerializationModelStreamer().save(factory, new FileOutputStream(outputFile)); |
| 61 | + FileInputStream in = new FileInputStream(outputFile); |
| 62 | + System.out.println(in.getChannel().size() + " bytes for default"); |
| 63 | + Factory factoryFromFile = new SerializationModelStreamer().load(in); |
61 | 64 | compareFactoryModels(factory, factoryFromFile);
|
62 | 65 | }
|
63 |
| - |
| 66 | + |
64 | 67 | @Test
|
65 | 68 | public void testGZipCompressionType() throws IOException {
|
66 | 69 | factory.getEnvironment().setCompressionType(CompressionType.GZIP);
|
67 |
| - new SerializationModelStreamer().save(factory, new FileOutputStream(file)); |
68 |
| - Factory factoryFromFile = new SerializationModelStreamer().load(new FileInputStream(file)); |
| 70 | + new SerializationModelStreamer().save(factory, new FileOutputStream(outputFile)); |
| 71 | + FileInputStream in = new FileInputStream(outputFile); |
| 72 | + System.out.println(in.getChannel().size() + " bytes for " + CompressionType.GZIP); |
| 73 | + Factory factoryFromFile = new SerializationModelStreamer().load(in); |
| 74 | + compareFactoryModels(factory, factoryFromFile); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void testBZip2CompressionType() throws IOException { |
| 79 | + factory.getEnvironment().setCompressionType(CompressionType.BZIP2); |
| 80 | + new SerializationModelStreamer().save(factory, new FileOutputStream(outputFile)); |
| 81 | + FileInputStream in = new FileInputStream(outputFile); |
| 82 | + System.out.println(in.getChannel().size() + " bytes for " + CompressionType.BZIP2); |
| 83 | + Factory factoryFromFile = new SerializationModelStreamer().load(in); |
69 | 84 | compareFactoryModels(factory, factoryFromFile);
|
70 | 85 | }
|
71 | 86 |
|
72 | 87 | @Test
|
73 | 88 | public void testNoneCompressionType() throws IOException {
|
74 | 89 | factory.getEnvironment().setCompressionType(CompressionType.NONE);
|
75 |
| - new SerializationModelStreamer().save(factory, new FileOutputStream(file)); |
76 |
| - Factory factoryFromFile = new SerializationModelStreamer().load(new FileInputStream(file)); |
| 90 | + new SerializationModelStreamer().save(factory, new FileOutputStream(outputFile)); |
| 91 | + FileInputStream in = new FileInputStream(outputFile); |
| 92 | + System.out.println(in.getChannel().size() + " bytes for " + CompressionType.NONE); |
| 93 | + Factory factoryFromFile = new SerializationModelStreamer().load(in); |
| 94 | + compareFactoryModels(factory, factoryFromFile); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void testLZMACompressionType() throws IOException { |
| 99 | + factory.getEnvironment().setCompressionType(CompressionType.LZMA); |
| 100 | + new SerializationModelStreamer().save(factory, new FileOutputStream(outputFile)); |
| 101 | + FileInputStream in = new FileInputStream(outputFile); |
| 102 | + System.out.println(in.getChannel().size() + " bytes for " + CompressionType.LZMA); |
| 103 | + Factory factoryFromFile = new SerializationModelStreamer().load(in); |
77 | 104 | compareFactoryModels(factory, factoryFromFile);
|
78 | 105 | }
|
79 | 106 |
|
|
0 commit comments