KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > CreatedModifiedFilesTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project;
21
22 import java.io.BufferedReader JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.FileInputStream JavaDoc;
25 import java.io.FileNotFoundException JavaDoc;
26 import java.io.FileOutputStream JavaDoc;
27 import java.io.FileReader JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.io.InputStreamReader JavaDoc;
31 import java.io.OutputStream JavaDoc;
32 import java.io.PrintWriter JavaDoc;
33 import java.net.URL JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Arrays JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.List JavaDoc;
38 import java.util.Map JavaDoc;
39 import java.util.Set JavaDoc;
40 import java.util.SortedSet JavaDoc;
41 import java.util.zip.ZipEntry JavaDoc;
42 import java.util.zip.ZipOutputStream JavaDoc;
43 import junit.framework.TestCase;
44 import org.netbeans.api.project.ProjectInformation;
45 import org.netbeans.api.project.ProjectUtils;
46 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles.Operation;
47 import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
48 import org.netbeans.modules.apisupport.project.ui.customizer.ModuleDependency;
49 import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo;
50 import org.netbeans.spi.project.support.ant.EditableProperties;
51 import org.openide.filesystems.FileLock;
52 import org.openide.filesystems.FileObject;
53 import org.openide.filesystems.FileUtil;
54 import org.openide.modules.SpecificationVersion;
55
56 /**
57  * Tests {@link CreatedModifiedFiles}.
58  * @author Martin Krauskopf
59  */

60 public class CreatedModifiedFilesTest extends LayerTestBase {
61
62     private static final String JavaDoc[] HTML_CONTENT = new String JavaDoc[] {
63         "<html>",
64         "<em>i am some template</em>",
65         "</html>"
66     };
67     
68     private static final Map JavaDoc TOKENS_MAP = new HashMap JavaDoc(2);
69     
70     static {
71         TOKENS_MAP.put("some", "a\\ nonsense");
72         TOKENS_MAP.put("\\<(\\/{0,1})em\\>", "<$1strong>");
73     }
74     
75     private static final String JavaDoc[] HTML_CONTENT_TOKENIZED = new String JavaDoc[] {
76         "<html>",
77         "<strong>i am a nonsense template</strong>",
78         "</html>"
79     };
80     
81     public CreatedModifiedFilesTest(String JavaDoc name) {
82         super(name);
83     }
84     
85     protected void setUp() throws Exception JavaDoc {
86         super.setUp();
87         TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
88     }
89     
90     public void testCreatedModifiedFiles() throws Exception JavaDoc {
91         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
92         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
93         cmf.add(cmf.bundleKeyDefaultBundle(LocalizedBundleInfo.NAME, "Much Better Name"));
94         cmf.add(cmf.bundleKey("src/custom.properties", "some.property", "some value"));
95         cmf.add(cmf.addLoaderSection("org/example/module1/MyExtLoader", null));
96         cmf.add(cmf.createFile("src/org/example/module1/resources/template.html", createFile(HTML_CONTENT)));
97         cmf.add(cmf.addLookupRegistration(
98                 "org.example.spi.somemodule.ProvideMe",
99                 "org.example.module1.ProvideMeImpl", false));
100         
101         assertRelativePaths(
102                 new String JavaDoc[] {"src/META-INF/services/org.example.spi.somemodule.ProvideMe", "src/custom.properties", "src/org/example/module1/resources/template.html"},
103                 cmf.getCreatedPaths());
104         assertRelativePaths(
105                 new String JavaDoc[] {"manifest.mf", "src/org/example/module1/resources/Bundle.properties"},
106                 cmf.getModifiedPaths());
107
108         cmf.run();
109     }
110     
111     public void testBundleKeyDefaultBundle() throws Exception JavaDoc {
112         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
113         ProjectInformation pi = ProjectUtils.getInformation(project);
114         assertEquals("display name before from bundle", "Testing Module", pi.getDisplayName());
115         assertEquals("display name before from project", "Testing Module", project.getBundleInfo().getDisplayName());
116         
117         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
118         Operation op = cmf.bundleKeyDefaultBundle(LocalizedBundleInfo.NAME, "Much Better Name");
119         assertRelativePath("src/org/example/module1/resources/Bundle.properties",
120                 op.getModifiedPaths());
121         op.run();
122         
123         pi = ProjectUtils.getInformation(project);
124         assertEquals("display name after from bundle", "Much Better Name", pi.getDisplayName());
125         assertEquals("display name after from project", "Much Better Name", project.getBundleInfo().getDisplayName());
126     }
127     
128     public void testBundleKey() throws Exception JavaDoc {
129         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
130         
131         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
132         Operation op = cmf.bundleKey("src/custom.properties", "some.property", "some value");
133         
134         assertRelativePath("src/custom.properties", op.getCreatedPaths());
135         
136         cmf.add(op);
137         cmf.run();
138         
139         EditableProperties ep = Util.loadProperties(FileUtil.toFileObject(TestBase.file(getWorkDir(), "module1/src/custom.properties")));
140         assertEquals("property created", "some value", ep.getProperty("some.property"));
141     }
142     
143     public void testAddLoaderSection() throws Exception JavaDoc {
144         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
145         
146         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
147         Operation op = cmf.addLoaderSection("org/example/module1/MyExtLoader", null);
148         
149         assertRelativePath("manifest.mf", op.getModifiedPaths());
150         
151         op.run();
152         
153         EditableManifest em = Util.loadManifest(FileUtil.toFileObject(TestBase.file(getWorkDir(), "module1/manifest.mf")));
154         assertEquals("loader section was added", "Loader", em.getAttribute("OpenIDE-Module-Class", "org/example/module1/MyExtLoader.class"));
155     }
156     
157     public void testAddLookupRegistration() throws Exception JavaDoc {
158         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
159         
160         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
161         cmf.add(cmf.addLookupRegistration(
162                 "org.example.spi.somemodule.ProvideMe",
163                 "org.example.module1.ProvideMeImpl1", false));
164         cmf.add(cmf.addLookupRegistration(
165                 "org.example.spi.somemodule.ProvideMe",
166                 "org.example.module1.ProvideMeImpl2", false));
167         cmf.add(cmf.addLookupRegistration(
168                 "org.example.spi.somemodule.ProvideMe",
169                 "org.example.module1.ProvideMeImpl1", true));
170
171         String JavaDoc[] paths = {
172             "src/META-INF/services/org.example.spi.somemodule.ProvideMe",
173             "test/unit/src/META-INF/services/org.example.spi.somemodule.ProvideMe",
174         };
175         assertRelativePaths(paths, cmf.getCreatedPaths());
176         
177         cmf.run();
178
179         FileObject registry = project.getProjectDirectory().getFileObject(paths[0]);
180         assertNotNull(registry);
181         InputStream JavaDoc is = registry.getInputStream();
182         try {
183             BufferedReader JavaDoc r = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(is, "UTF-8"));
184             assertEquals("org.example.module1.ProvideMeImpl1", r.readLine());
185             assertEquals("org.example.module1.ProvideMeImpl2", r.readLine());
186             assertEquals(null, r.readLine());
187         } finally {
188             is.close();
189         }
190         registry = project.getProjectDirectory().getFileObject(paths[1]);
191         assertNotNull(registry);
192         is = registry.getInputStream();
193         try {
194             BufferedReader JavaDoc r = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(is, "UTF-8"));
195             assertEquals("org.example.module1.ProvideMeImpl1", r.readLine());
196             assertEquals(null, r.readLine());
197         } finally {
198             is.close();
199         }
200     }
201     
202     public void testCreateFile() throws Exception JavaDoc {
203         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
204         
205         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
206         
207         String JavaDoc templatePath = "src/org/example/module1/resources/template.html";
208         Operation op = cmf.createFile(templatePath, createFile(HTML_CONTENT));
209         
210         assertRelativePath(templatePath, op.getCreatedPaths());
211         
212         cmf.add(op);
213         cmf.run();
214         
215         assertFileContent(HTML_CONTENT, new File JavaDoc(getWorkDir(), "module1/" + templatePath));
216     }
217     
218     public void testCreateBinaryFile() throws Exception JavaDoc {
219         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
220         
221         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
222         
223         String JavaDoc templatePath = "src/org/example/module1/resources/binarytemplate.zip";
224         
225         File JavaDoc binaryFile = createBinaryFile(HTML_CONTENT);
226         
227         Operation op = cmf.createFile(templatePath, binaryFile.toURI().toURL());
228         
229         assertRelativePath(templatePath, op.getCreatedPaths());
230         
231         cmf.add(op);
232         cmf.run();
233         
234         assertFileContent(binaryFile, new File JavaDoc(getWorkDir(), "module1/" + templatePath));
235     }
236     
237     public void testCreateFileWithSubstitutions() throws Exception JavaDoc {
238         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
239         
240         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
241         
242         String JavaDoc templatePath = "src/org/example/module1/resources/template.html";
243         Operation op = cmf.createFileWithSubstitutions(templatePath, createFile(HTML_CONTENT), TOKENS_MAP);
244         
245         assertRelativePath(templatePath, op.getCreatedPaths());
246         
247         cmf.add(op);
248         cmf.run();
249         
250         assertFileContent(HTML_CONTENT_TOKENIZED, new File JavaDoc(getWorkDir(), "module1/" + templatePath));
251     }
252     
253     public void testAddModuleDependency() throws Exception JavaDoc {
254         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
255         
256         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
257         
258         Operation op = cmf.addModuleDependency("org.apache.tools.ant.module", "3",
259                 new SpecificationVersion("3.9"), true);
260         
261         assertRelativePath("nbproject/project.xml", op.getModifiedPaths());
262         
263         cmf.add(op);
264         cmf.run();
265         
266         ProjectXMLManager pxm = new ProjectXMLManager(project);
267         Set JavaDoc deps = pxm.getDirectDependencies();
268         assertEquals("one dependency", 1, deps.size());
269         ModuleDependency antDep = (ModuleDependency) deps.toArray()[0];
270         assertEquals("cnb", "org.apache.tools.ant.module", antDep.getModuleEntry().getCodeNameBase());
271         assertEquals("release version", "3", antDep.getReleaseVersion());
272         assertEquals("specification version", "3.9", antDep.getSpecificationVersion());
273         assertTrue("compile dependeny", antDep.hasCompileDependency());
274         assertFalse("implementation dependeny", antDep.hasImplementationDepedendency());
275     }
276     
277     public void testTheSameModuleDependencyTwice() throws Exception JavaDoc {
278         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
279         
280         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
281         
282         Operation op = cmf.addModuleDependency("org.apache.tools.ant.module",null,null,false);
283         
284         assertRelativePath("nbproject/project.xml", op.getModifiedPaths());
285         
286         cmf.add(op);
287         cmf.add(op);
288         cmf.run();
289         
290         ProjectXMLManager pxm = new ProjectXMLManager(project);
291         Set JavaDoc deps = pxm.getDirectDependencies();
292         assertEquals("one dependency", 1, deps.size());
293         ModuleDependency antDep = (ModuleDependency) deps.toArray()[0];
294         assertEquals("cnb", "org.apache.tools.ant.module", antDep.getModuleEntry().getCodeNameBase());
295     }
296     
297     public void testOrderLayerEntry() throws Exception JavaDoc {
298         // also tested in testCreateLayerEntry where is also tested generated content
299
NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
300         
301         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
302         
303         Operation op = cmf.orderLayerEntry("Loaders/text/x-java/Actions",
304                 "IAmSecond.instance", "IAmThird.instance");
305         
306         assertRelativePath("src/org/example/module1/resources/layer.xml", op.getModifiedPaths());
307         
308         cmf.add(op);
309         cmf.run();
310     }
311     
312     public void testCreateLayerEntry() throws Exception JavaDoc {
313         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
314         
315         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
316         Operation layerOp = cmf.createLayerEntry(
317                 "Menu/Tools/org-example-module1-BeepAction.instance",
318                 null,
319                 null,
320                 null,
321                 null);
322         layerOp.run();
323         
324         layerOp = cmf.createLayerEntry(
325                 "Services/org-example-module1-Module1UI.settings",
326                 null,
327                 null,
328                 null,
329                 null);
330         cmf.add(layerOp);
331         assertRelativePath("src/org/example/module1/resources/layer.xml", layerOp.getModifiedPaths());
332         
333         layerOp = cmf.orderLayerEntry("Menu/Tools",
334                 "org-example-module1-BeepAction.instance",
335                 "org-example-module1-BlareAction.instance");
336         cmf.add(layerOp);
337         
338         layerOp = cmf.createLayerEntry(
339                 "Menu/Tools/org-example-module1-BlareAction.instance",
340                 null,
341                 null,
342                 null,
343                 null);
344         cmf.add(layerOp);
345         
346         layerOp = cmf.createLayerEntry(
347                 "Services/org-example-module1-Other.settings",
348                 createFile(HTML_CONTENT),
349                 null,
350                 null,
351                 null);
352         cmf.add(layerOp);
353
354         layerOp = cmf.createLayerEntry(
355                 "Services/org-example-module1-Tokenized.settings",
356                 createFile(HTML_CONTENT),
357                 TOKENS_MAP,
358                 null,
359                 null);
360         cmf.add(layerOp);
361
362         layerOp = cmf.createLayerEntry(
363                 "Services/org-example-module1-LocalizedAndTokened.settings",
364                 createFile(HTML_CONTENT),
365                 TOKENS_MAP,
366                 "Some Settings",
367                 null);
368         cmf.add(layerOp);
369
370         assertRelativePaths(
371                 new String JavaDoc[] {"src/org/example/module1/resources/Bundle.properties", "src/org/example/module1/resources/layer.xml"},
372                 cmf.getModifiedPaths());
373         assertRelativePaths(
374                 new String JavaDoc[] {
375                     "src/org/example/module1/resources/org-example-module1-LocalizedAndTokenedSettings.xml",
376                     "src/org/example/module1/resources/org-example-module1-OtherSettings.xml",
377                     "src/org/example/module1/resources/org-example-module1-TokenizedSettings.xml"
378                 },
379                 cmf.getCreatedPaths());
380         cmf.run();
381
382         assertFileContent(HTML_CONTENT_TOKENIZED, new File JavaDoc(getWorkDir(), "module1/src/org/example/module1/resources/org-example-module1-TokenizedSettings.xml"));
383
384         // check layer content
385
String JavaDoc[] supposedContent = new String JavaDoc[] {
386             "<filesystem>",
387                     "<folder name=\"Menu\">",
388                     "<folder name=\"Tools\">",
389                     "<file name=\"org-example-module1-BeepAction.instance\"/>",
390                     "<attr name=\"org-example-module1-BeepAction.instance/org-example-module1-BlareAction.instance\" boolvalue=\"true\"/>",
391                     "<file name=\"org-example-module1-BlareAction.instance\"/>",
392                     "</folder>",
393                     "</folder>",
394                     "<folder name=\"Services\">",
395                     "<file name=\"org-example-module1-LocalizedAndTokened.settings\" url=\"org-example-module1-LocalizedAndTokenedSettings.xml\">",
396                     "<attr name=\"SystemFileSystem.localizingBundle\" stringvalue=\"org.example.module1.resources.Bundle\"/>",
397                     "</file>",
398                     "<file name=\"org-example-module1-Module1UI.settings\"/>",
399                     "<file name=\"org-example-module1-Other.settings\" url=\"org-example-module1-OtherSettings.xml\"/>",
400                     "<file name=\"org-example-module1-Tokenized.settings\" url=\"org-example-module1-TokenizedSettings.xml\"/>",
401                     "</folder>",
402                     "</filesystem>"
403         };
404         assertLayerContent(supposedContent,
405                 new File JavaDoc(getWorkDir(), "module1/src/org/example/module1/resources/layer.xml"));
406         
407         // check bundle content
408
EditableProperties ep = Util.loadProperties(FileUtil.toFileObject(
409                 TestBase.file(getWorkDir(), "module1/src/org/example/module1/resources/Bundle.properties")));
410         assertEquals("localized name property", "Some Settings",
411                 ep.getProperty("Services/org-example-module1-LocalizedAndTokened.settings"));
412         assertEquals("module name", "Testing Module", ep.getProperty("OpenIDE-Module-Name"));
413     }
414     
415     public void testCreateLayerAttribute() throws Exception JavaDoc {
416         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
417         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
418         String JavaDoc fqClassName = "org.example.module1.BeepAction";
419         String JavaDoc dashedFqClassName = fqClassName.replace('.', '-');
420         String JavaDoc layerPath = "Actions/Tools/" + dashedFqClassName + ".instance";
421         
422         Operation op = cmf.createLayerEntry(layerPath, null, null, null, null);
423         cmf.add(op);
424         
425         op = cmf.createLayerAttribute(
426                 layerPath, "instanceClass", fqClassName);
427         assertRelativePath("src/org/example/module1/resources/layer.xml", op.getModifiedPaths());
428         
429         cmf.add(op);
430         cmf.run();
431         
432         String JavaDoc[] supposedContent = new String JavaDoc[] {
433             "<filesystem>",
434                     "<folder name=\"Actions\">",
435                     "<folder name=\"Tools\">",
436                     "<file name=\"org-example-module1-BeepAction.instance\">",
437                     "<attr name=\"instanceClass\" stringvalue=\"org.example.module1.BeepAction\"/>",
438                     "</file>",
439                     "</folder>",
440                     "</folder>",
441                     "</filesystem>"
442         };
443         assertLayerContent(supposedContent,
444                 new File JavaDoc(getWorkDir(), "module1/src/org/example/module1/resources/layer.xml"));
445     }
446
447     /** @see "#64273" */
448     public void testCreateLayerEntryWithoutLocalizingBundle() throws Exception JavaDoc {
449         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module");
450         project.getProjectDirectory().getFileObject("src/org/example/module/resources/Bundle.properties").delete();
451         FileObject mf = project.getProjectDirectory().getFileObject("manifest.mf");
452         EditableManifest m;
453         InputStream JavaDoc is = mf.getInputStream();
454         try {
455             m = new EditableManifest(is);
456         } finally {
457             is.close();
458         }
459         m.removeAttribute("OpenIDE-Module-Localizing-Bundle", null);
460         FileLock lock = mf.lock();
461         try {
462             OutputStream JavaDoc os = mf.getOutputStream(lock);
463             try {
464                 m.write(os);
465             } finally {
466                 os.close();
467             }
468         } finally {
469             lock.releaseLock();
470         }
471         CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
472         Operation op = cmf.createLayerEntry("f", null, null, "F!", null);
473         cmf.add(op);
474         cmf.run();
475         String JavaDoc[] supposedContent = new String JavaDoc[] {
476             "<filesystem>",
477             "<file name=\"f\"/>",
478             "</filesystem>"
479         };
480         assertLayerContent(supposedContent,
481                 new File JavaDoc(getWorkDir(), "module/src/org/example/module/resources/layer.xml"));
482     }
483     
484     public static void assertRelativePath(String JavaDoc expectedPath, String JavaDoc[] paths) {
485         TestCase.assertEquals("one path", 1, paths.length);
486         TestCase.assertEquals("created, modified paths", expectedPath, paths[0]);
487     }
488     
489     public static void assertRelativePath(String JavaDoc expectedPath, SortedSet JavaDoc paths) {
490         String JavaDoc[] s = new String JavaDoc[paths.size()];
491         assertRelativePath(expectedPath, (String JavaDoc[]) paths.toArray(s));
492     }
493     
494     public static void assertRelativePaths(String JavaDoc[] expectedPaths, String JavaDoc[] paths) {
495         TestCase.assertEquals("created, modified paths", Arrays.asList(expectedPaths), Arrays.asList(paths));
496     }
497     
498     private URL JavaDoc createFile(String JavaDoc[] content) throws IOException JavaDoc {
499         File JavaDoc myTemplate = new File JavaDoc(getWorkDir(), "myTemplate.html");
500         OutputStream JavaDoc myTemplateOS = new FileOutputStream JavaDoc(myTemplate);
501         PrintWriter JavaDoc pw = new PrintWriter JavaDoc(myTemplateOS);
502         try {
503             for (int i = 0; i < content.length; i++) {
504                 pw.println(content[i]);
505             }
506         } finally {
507             pw.close();
508         }
509         return myTemplate.toURI().toURL();
510     }
511     
512     private File JavaDoc createBinaryFile(String JavaDoc[] content) throws IOException JavaDoc {
513         File JavaDoc myTemplate = new File JavaDoc(getWorkDir(), "myTemplate.zip");
514         ZipOutputStream JavaDoc zos = new ZipOutputStream JavaDoc(new FileOutputStream JavaDoc(myTemplate));
515         ZipEntry JavaDoc entry = new ZipEntry JavaDoc("a/b/c/d.txt");
516         zos.putNextEntry(entry);
517         
518         try {
519             for (int i = 0; i < content.length; i++) {
520                 zos.write(content[i].getBytes());
521             }
522             
523         } finally {
524             zos.close();
525         }
526         return myTemplate;
527     }
528     
529     private void assertFileContent(String JavaDoc[] content, File JavaDoc file) throws IOException JavaDoc {
530         assertTrue("file exist and is a regular file", file.isFile());
531         BufferedReader JavaDoc br = new BufferedReader JavaDoc(new FileReader JavaDoc(file));
532         try {
533             for (int i = 0; i < content.length; i++) {
534                 assertEquals("file content", content[i], br.readLine());
535             }
536             assertNull(br.readLine());
537         } finally {
538             br.close();
539         }
540     }
541     
542     private void assertFileContent(File JavaDoc f1, File JavaDoc f2) throws IOException JavaDoc {
543         InputStream JavaDoc is = new FileInputStream JavaDoc(f1);
544         InputStream JavaDoc is2 = new FileInputStream JavaDoc(f2);
545         
546         try {
547             byte[] content = new byte[is.available()];
548             is.read(content);
549             
550             byte[] content2 = new byte[is2.available()];
551             is2.read(content2);
552             
553             for (int i = 0; i < content.length; i++) {
554                 assertEquals("file content", content[i], content2[i]);
555             }
556         } finally {
557             is.close();
558             is2.close();
559         }
560     }
561     
562     public static void assertLayerContent(final String JavaDoc[] supposedContent,
563             final File JavaDoc layerF) throws IOException JavaDoc, FileNotFoundException JavaDoc {
564         BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new FileReader JavaDoc(layerF));
565         List JavaDoc actualContent = new ArrayList JavaDoc();
566         boolean fsElementReached = false;
567         String JavaDoc line;
568         
569         try {
570             while ((line = reader.readLine()) != null) {
571                 line = line.trim();
572                 if (!fsElementReached && line.equals(supposedContent[0])) {
573                     fsElementReached = true;
574                     actualContent.add(line);
575                     continue;
576                 }
577                 if (fsElementReached) {
578                     actualContent.add(line);
579                 }
580             }
581         } finally {
582             reader.close();
583         }
584         
585         assertEquals("content of layer", Arrays.asList(supposedContent).toString(), actualContent.toString());
586     }
587     
588 }
589
590
Popular Tags