1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.reboot;
12
13 import java.io.BufferedReader;
14 import java.io.ByteArrayInputStream;
15 import java.io.ByteArrayOutputStream;
16 import java.io.File;
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.io.InputStreamReader;
20 import java.net.URL;
21
22 import org.junit.Before;
23 import org.junit.Test;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 public class MuleContainerBootstrapUtilsTestCase
31 {
32
33 @Before
34 public void setUp()
35 {
36 System.setProperty("mule.home", "foo");
37 }
38
39
40
41
42 @Test
43 public void testIsStandaloneTrue()
44 {
45 assertTrue(MuleContainerBootstrapUtils.isStandalone());
46 }
47
48
49
50
51 @Test
52 public void testGetMuleHomeFile()
53 {
54 File muleHome = MuleContainerBootstrapUtils.getMuleHome();
55 assertNotNull(muleHome.getAbsolutePath());
56 }
57
58
59
60
61 @Test
62 public void testGetMuleAppsFile()
63 {
64 File muleApps = MuleContainerBootstrapUtils.getMuleAppsDir();
65 assertNotNull(muleApps.getAbsolutePath());
66 }
67
68
69
70
71 @Test
72 public void testGetMuleLibDir()
73 { File muleLib = MuleContainerBootstrapUtils.getMuleLibDir();
74 assertNotNull(muleLib.getAbsolutePath());
75 }
76
77
78
79
80 @Test
81 public void testGetMuleLocalJarFile()
82 { File muleLocalJar = MuleContainerBootstrapUtils.getMuleLocalJarFile();
83 assertNotNull(muleLocalJar.getAbsolutePath());
84 }
85
86
87
88
89
90 @Test
91 public void testGetResource() throws IOException
92 {
93 URL resource = MuleContainerBootstrapUtils.getResource("test-resource.txt", this.getClass());
94 assertNotNull(resource);
95 Object content = resource.getContent();
96 assertTrue(content instanceof InputStream);
97 BufferedReader in = new BufferedReader(new InputStreamReader((InputStream)content));
98 assertEquals("msg=Hello World", in.readLine());
99 }
100
101
102
103
104
105 @Test
106 public void testRenameFile() throws IOException
107 {
108 File source = File.createTempFile("foo", ".tmp");
109 File dest = new File(source.getParent() + File.separatorChar + "dest" + System.currentTimeMillis() + ".tmp");
110 assertFalse(dest.exists());
111 MuleContainerBootstrapUtils.renameFile(source, dest);
112 assertTrue(dest.exists());
113 assertFalse(source.exists());
114 source.delete();
115 dest.delete();
116 }
117
118
119
120
121
122 @Test
123 public void testRenameFileHard() throws IOException
124 {
125 File source = File.createTempFile("foo2", ".tmp");
126 File dest = new File(source.getParent() + File.separatorChar + "dest2" + System.currentTimeMillis() + ".tmp");
127 assertFalse(dest.exists());
128 MuleContainerBootstrapUtils.renameFileHard(source, dest);
129 assertTrue(dest.exists());
130 assertFalse(source.exists());
131 source.delete();
132 dest.delete();
133 }
134
135
136
137
138
139 @Test
140 public void testCopy() throws IOException
141 {
142 byte[] b = {0,1,2};
143 ByteArrayInputStream input = new ByteArrayInputStream(b, 0, Integer.MAX_VALUE);
144 ByteArrayOutputStream output = new ByteArrayOutputStream();
145 int i = MuleContainerBootstrapUtils.copy(input, output);
146 assertEquals(b.length, i);
147 }
148
149
150
151
152
153 @Test
154 public void testCopyLarge() throws IOException
155 {
156 byte[] b = {0,1,2};
157 ByteArrayInputStream input = new ByteArrayInputStream(b, 0, Integer.MAX_VALUE);
158 ByteArrayOutputStream output = new ByteArrayOutputStream();
159 long i = MuleContainerBootstrapUtils.copyLarge(input, output);
160 assertEquals(b.length, i);
161 }
162 }
163
164