KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > archive > OriginalDocumentGeneratorTest


1 package com.openedit.archive;
2
3 import java.io.ByteArrayOutputStream JavaDoc;
4 import java.io.File JavaDoc;
5
6 import com.openedit.OpenEditException;
7 import com.openedit.WebPageRequest;
8 import com.openedit.generators.Output;
9 import com.openedit.util.FileUtils;
10
11 public class OriginalDocumentGeneratorTest extends ArchiveTest
12 {
13     public OriginalDocumentGeneratorTest( String JavaDoc inName )
14     {
15         super( inName );
16     }
17     
18     public void testGenerate() throws OpenEditException
19     {
20         String JavaDoc path = "/testcatalog/downloads/originals/acfanvent01dottif1078102626/ACFanVent01.tif";
21         WebPageRequest request = getFixture().createPageRequest( path );
22         getFixture().getModuleManager().executePathActions( request.getPage(), request );
23         
24         Output out = new Output();
25         ByteArrayOutputStream JavaDoc baos = (ByteArrayOutputStream JavaDoc) request.getOutputStream();
26         out.setStream( baos );
27
28         request.getPage().generate( request , out );
29         byte[] bytes = baos.toByteArray();
30         assertTrue( "empty file", bytes.length > 1000 );
31         /*assertEquals( "First byte", '%', bytes[0] );
32         assertEquals( "Second byte", '!', bytes[1] );
33         assertEquals( "Third byte", 'P', bytes[2] );
34         assertEquals( "Fourth byte", 'S', bytes[3] );
35         */

36     }
37     /**
38     public void testZipCartDocuments() throws Exception
39     {
40         Cart cart = new Cart( getStore() );
41         Product product = getStore().getProduct( "acfanvent01dottif1078102626" );
42         CartItem item = new CartItem();
43         item.setProduct(product);
44         cart.addItem( item );
45         product = getStore().getProduct( "acrepairman01dottif1078102627" );
46         
47         CartItem newItem = new CartItem();
48         newItem.setProduct(product);
49         cart.addItem( newItem );
50
51         Page page = getFixture().getPageManager().getPage( "/archive/downloads/collection/originalzip/cart123.zip");
52
53         WebPageRequest req = getFixture().createPageRequest("/archive/downloads/collection/originalzip/cart123.zip");
54         req.putSessionValue("cart", cart);
55         getFixture().getModuleManager().executePathActions( req );
56
57         Output out = new Output();
58         ByteArrayOutputStream baos = (ByteArrayOutputStream) req.getOutputStream();
59         out.setStream( baos );
60
61         page.generate(req, out);
62         
63         byte[] data = baos.toByteArray();
64         ZipInputStream zis = new ZipInputStream( new ByteArrayInputStream(data) );
65         Set names = new HashSet();
66         ZipEntry entry = zis.getNextEntry();
67         while ( entry != null )
68         {
69             names.add( entry.getName() );
70             entry = zis.getNextEntry();
71         }
72         zis.close();
73         assertTrue( "TIFF should be in the zip file", names.contains( "ACFanVent01.tif" ) );
74         assertTrue( "ACRepairman01.tif should be in the zip file", names.contains( "ACRepairman01.tif" ) );
75         
76         assertTrue( "missing.txt should not be in the zip file", !names.contains( "missing.txt" ) );
77     }
78 */

79     protected void setUp() throws Exception JavaDoc
80     {
81         File JavaDoc etc = new File JavaDoc( getStore().getRootDirectory().getParentFile(),"etc");
82         //copy back the export file
83
File JavaDoc input = new File JavaDoc( etc, "archivefiles");
84         File JavaDoc output = new File JavaDoc( "/tmp/archivefiles");
85         FileUtils util = new FileUtils();
86         util.dirCopy(input,output);
87     }
88
89     
90 }
91
Popular Tags