1 21 package com.jaspersoft.jasperserver.api.metadata.view.service.impl; 22 23 import java.util.Properties ; 24 import java.util.ArrayList ; 25 import java.io.IOException ; 26 import java.io.FileNotFoundException ; 27 import java.io.BufferedInputStream ; 28 import java.io.FileInputStream ; 29 import java.io.InputStream ; 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 jdbcProps; 42 private RepositoryService repo; 43 44 protected void setUp() throws Exception { 45 loadJdbcProps(); 46 ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( 47 new String [] {"hibernateConfig.xml", "viewService.xml"}); 48 49 repo = (RepositoryService) appContext.getBean("repoService"); 50 } 51 52 protected Properties loadJdbcProps() throws IOException , FileNotFoundException { 53 jdbcProps = new Properties (); 54 String jdbcPropFile = System.getProperty("test.hibernate.jdbc.properties"); 55 BufferedInputStream is = new BufferedInputStream (new FileInputStream (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 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 images = new ArrayList (); 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 (); 154 images.add(image); 155 156 htmlFile.setResources(images); 157 repo.saveResource(null, htmlFile); 158 } 159 } 160 | Popular Tags |