1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jdtaus.banking.dtaus.it;
22
23 import java.io.File;
24 import junit.framework.Assert;
25 import junit.framework.TestCase;
26 import org.jdtaus.banking.dtaus.PhysicalFile;
27 import org.jdtaus.banking.dtaus.PhysicalFileException;
28 import org.jdtaus.banking.dtaus.PhysicalFileFactory;
29 import org.jdtaus.core.io.FileOperations;
30 import org.jdtaus.core.io.util.MemoryFileOperations;
31
32
33
34
35
36
37
38 public class PhysicalFileFactoryTest extends TestCase
39 {
40
41
42 private PhysicalFileFactory factory;
43
44
45
46
47
48
49 public PhysicalFileFactory getPhysicalFileFactory()
50 {
51 return this.factory;
52 }
53
54
55
56
57
58
59 public final void setPhysicalFileFactory( final PhysicalFileFactory value )
60 {
61 this.factory = value;
62 }
63
64
65
66
67
68 public void testCreateIllegalArguments() throws Exception
69 {
70 assert this.getPhysicalFileFactory() != null;
71
72 try
73 {
74 this.getPhysicalFileFactory().createPhysicalFile( (FileOperations) null, PhysicalFileFactory.FORMAT_DISK );
75 throw new AssertionError();
76 }
77 catch ( NullPointerException e )
78 {
79 Assert.assertNotNull( e.getMessage() );
80 System.out.println( e.toString() );
81 }
82
83 try
84 {
85 this.getPhysicalFileFactory().createPhysicalFile( (File) null, PhysicalFileFactory.FORMAT_DISK );
86 throw new AssertionError();
87 }
88 catch ( NullPointerException e )
89 {
90 Assert.assertNotNull( e.getMessage() );
91 System.out.println( e.toString() );
92 }
93
94 try
95 {
96 this.getPhysicalFileFactory().createPhysicalFile( new MemoryFileOperations(), Integer.MIN_VALUE );
97 throw new AssertionError();
98 }
99 catch ( IllegalArgumentException e )
100 {
101 Assert.assertNotNull( e.getMessage() );
102 System.out.println( e.toString() );
103 }
104
105
106 }
107
108
109
110
111
112 public void testCreate() throws Exception
113 {
114 assert this.getPhysicalFileFactory() != null;
115
116 final FileOperations diskOps = new MemoryFileOperations();
117 final FileOperations tapeOps = new MemoryFileOperations();
118
119 final PhysicalFile diskFile =
120 this.getPhysicalFileFactory().createPhysicalFile( diskOps, PhysicalFileFactory.FORMAT_DISK );
121
122 final PhysicalFile tapeFile =
123 this.getPhysicalFileFactory().createPhysicalFile( tapeOps, PhysicalFileFactory.FORMAT_TAPE );
124
125 Assert.assertNotNull( diskFile );
126 Assert.assertNotNull( tapeFile );
127
128 Assert.assertTrue( diskFile.getLogicalFileCount() == 0 );
129 Assert.assertTrue( tapeFile.getLogicalFileCount() == 0 );
130 }
131
132
133
134
135
136 public void testGetPhysicalFileNull() throws Exception
137 {
138 assert this.getPhysicalFileFactory() != null;
139
140 try
141 {
142 this.getPhysicalFileFactory().getPhysicalFile( (FileOperations) null );
143 throw new AssertionError();
144 }
145 catch ( NullPointerException e )
146 {
147 Assert.assertNotNull( e.getMessage() );
148 System.out.println( e.toString() );
149 }
150
151 try
152 {
153 this.getPhysicalFileFactory().getPhysicalFile( (File) null );
154 throw new AssertionError();
155 }
156 catch ( NullPointerException e )
157 {
158 Assert.assertNotNull( e.getMessage() );
159 System.out.println( e.toString() );
160 }
161 }
162
163
164
165
166
167 public void testGetPhysicalFileNoLength() throws Exception
168 {
169 assert this.getPhysicalFileFactory() != null;
170
171 final PhysicalFile pFile = this.getPhysicalFileFactory().getPhysicalFile( new MemoryFileOperations() );
172 Assert.assertNotNull( pFile );
173 Assert.assertTrue( pFile.getLogicalFileCount() == 0 );
174 }
175
176
177
178
179 public void testAnalyseNull() throws Exception
180 {
181 assert this.getPhysicalFileFactory() != null;
182
183 try
184 {
185 this.getPhysicalFileFactory().analyse( (FileOperations) null );
186 throw new AssertionError();
187 }
188 catch ( NullPointerException e )
189 {
190 Assert.assertNotNull( e.getMessage() );
191 System.out.println( e.toString() );
192 }
193
194 try
195 {
196 this.getPhysicalFileFactory().analyse( (File) null );
197 throw new AssertionError();
198 }
199 catch ( NullPointerException e )
200 {
201 Assert.assertNotNull( e.getMessage() );
202 System.out.println( e.toString() );
203 }
204 }
205
206
207
208
209
210 public void testAnalyseNoLength() throws Exception
211 {
212 assert this.getPhysicalFileFactory() != null;
213
214 try
215 {
216 this.getPhysicalFileFactory().analyse( new MemoryFileOperations() );
217 throw new AssertionError();
218 }
219 catch ( PhysicalFileException e )
220 {
221 Assert.assertNotNull( e.getMessage() );
222 System.out.println( e.toString() );
223 }
224
225 }
226
227 }