KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > api > metadata > view > service > impl > ContentRepositoryTest


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.api.metadata.view.service.impl;
22
23 import java.util.Properties JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.FileNotFoundException JavaDoc;
27 import java.io.BufferedInputStream JavaDoc;
28 import java.io.FileInputStream JavaDoc;
29 import java.io.InputStream JavaDoc;
30
31 import junit.framework.TestCase;
32 import org.springframework.context.support.ClassPathXmlApplicationContext;
33 import com.jaspersoft.jasperserver.api.metadata.common.domain.Folder;
34 import com.jaspersoft.jasperserver.api.metadata.common.domain.ContentResource;
35 import com.jaspersoft.jasperserver.api.metadata.common.domain.client.FolderImpl;
36 import com.jaspersoft.jasperserver.api.metadata.common.domain.client.ContentResourceImpl;
37 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService;
38
39 public class ContentRepositoryTest extends TestCase
40 {
41     private Properties JavaDoc jdbcProps;
42     private RepositoryService repo;
43
44     protected void setUp() throws Exception JavaDoc {
45         loadJdbcProps();
46         ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
47                 new String JavaDoc[] {"hibernateConfig.xml", "viewService.xml"});
48
49         repo = (RepositoryService) appContext.getBean("repoService");
50     }
51
52     protected Properties JavaDoc loadJdbcProps() throws IOException JavaDoc, FileNotFoundException JavaDoc {
53         jdbcProps = new Properties JavaDoc();
54         String JavaDoc jdbcPropFile = System.getProperty("test.hibernate.jdbc.properties");
55         BufferedInputStream JavaDoc is = new BufferedInputStream JavaDoc(new FileInputStream JavaDoc(jdbcPropFile));
56         jdbcProps.load(is);
57         is.close();
58         return jdbcProps;
59     }
60
61     public void testFolder()
62     {
63         Folder dsFolder = new FolderImpl();
64         dsFolder.setName("ContentFiles");
65         dsFolder.setLabel("Content files");
66         dsFolder.setDescription("Content files generated by reports");
67         repo.saveFolder(null, dsFolder);
68
69         Folder newFolder = new FolderImpl();
70         newFolder.setParentFolder(dsFolder);
71         newFolder.setName("html");
72         newFolder.setLabel("html");
73         repo.saveFolder(null, newFolder);
74
75         newFolder = new FolderImpl();
76         newFolder.setParentFolder(dsFolder);
77         newFolder.setName("pdf");
78         newFolder.setLabel("pdf");
79         repo.saveFolder(null, newFolder);
80
81         newFolder = new FolderImpl();
82         newFolder.setParentFolder(dsFolder);
83         newFolder.setName("xls");
84         newFolder.setLabel("xls");
85         repo.saveFolder(null, newFolder);
86
87     }
88
89     public void testFiles()
90     {
91         ContentResource fileResource = new ContentResourceImpl();
92         fileResource.setName("PdfTestFile");
93         fileResource.setLabel("Pdf test file");
94         fileResource.setParentFolder("/ContentFiles/pdf");
95         InputStream JavaDoc file = getClass().getResourceAsStream("/FontsReport.pdf");
96         fileResource.readData(file);
97         fileResource.setFileType(ContentResource.TYPE_PDF);
98         repo.saveResource(null, fileResource);
99
100
101         ContentResource htmlFile = new ContentResourceImpl();
102         htmlFile.setName("HtmlTestFile");
103         htmlFile.setLabel("HTML test file with images");
104         htmlFile.setParentFolder("/ContentFiles/html");
105         file = getClass().getResourceAsStream("/FirstJasper.html");
106         htmlFile.readData(file);
107         htmlFile.setFileType(ContentResource.TYPE_HTML);
108
109         ArrayList JavaDoc images = new ArrayList JavaDoc();
110
111         ContentResource image = new ContentResourceImpl();
112         image.setName("img_0_0_1");
113         image.setLabel("img_0_0_1");
114         file = getClass().getResourceAsStream("/FirstJasper.html_files/img_0_0_1");
115         image.readData(file);
116         image.setFileType(ContentResource.TYPE_HTML);
117         images.add(image);
118
119         image = new ContentResourceImpl();
120         image.setName("img_0_7_125");
121         image.setLabel("img_0_7_125");
122         file = getClass().getResourceAsStream("/FirstJasper.html_files/img_0_7_125");
123         image.readData(file);
124         image.setFileType(ContentResource.TYPE_HTML);
125         images.add(image);
126
127         image = new ContentResourceImpl();
128         image.setName("px");
129         image.setLabel("px");
130         file = getClass().getResourceAsStream("/FirstJasper.html_files/px");
131         image.readData(file);
132         image.setFileType(ContentResource.TYPE_HTML);
133         images.add(image);
134
135         htmlFile.setResources(images);
136         repo.saveResource(null, htmlFile);
137
138
139         htmlFile = new ContentResourceImpl();
140         htmlFile.setName("Test");
141         htmlFile.setLabel("HTML test file with one image");
142         htmlFile.setParentFolder("/ContentFiles/html");
143         file = getClass().getResourceAsStream("/Test.html");
144         htmlFile.readData(file);
145         htmlFile.setFileType(ContentResource.TYPE_HTML);
146
147         image = new ContentResourceImpl();
148         image.setName("image0");
149         image.setLabel("image0");
150         file = getClass().getResourceAsStream("/Test.html_files/image0");
151         image.readData(file);
152         image.setFileType(ContentResource.TYPE_HTML);
153         images = new ArrayList JavaDoc();
154         images.add(image);
155
156         htmlFile.setResources(images);
157         repo.saveResource(null, htmlFile);
158     }
159 }
160
Popular Tags