PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/server/endpoint/file/FileManagerTest.java

http://sigma-h.googlecode.com/
Java | 65 lines | 42 code | 23 blank | 0 comment | 0 complexity | bcbba24d2caac00cb461baeb92db8cb9 MD5 | raw file
 1package org.sigmah.server.endpoint.file;
 2
 3import static org.hamcrest.CoreMatchers.equalTo;
 4import static org.junit.Assert.assertThat;
 5
 6import java.io.BufferedReader;
 7import java.io.IOException;
 8import java.io.InputStreamReader;
 9import java.util.HashMap;
10import java.util.Map;
11
12import org.junit.Test;
13import org.junit.runner.RunWith;
14import org.sigmah.server.dao.OnDataSet;
15import org.sigmah.server.endpoint.file.FileManager.DownloadableFile;
16import org.sigmah.shared.dto.value.FileUploadUtils;
17import org.sigmah.test.InjectionSupport;
18import org.sigmah.test.MockHibernateModule;
19import org.sigmah.test.Modules;
20
21import com.google.inject.Inject;
22
23
24@RunWith(InjectionSupport.class)
25@Modules({
26        MockHibernateModule.class,
27        FileManagerTestConfigModule.class
28})
29@OnDataSet("/dbunit/projects.db.xml")
30public class FileManagerTest {
31	
32	
33	private static final int AUTHOR_ID = 1;
34	
35
36	@Inject
37	private FileManagerImpl fileManager;
38	
39	@Inject
40	private FileStorageProvider storageProvider;
41		
42
43	
44	@Test
45	public void testLocalFileSystem() throws IOException {
46		
47		Map<String, String> fileProperties = new HashMap<String, String>();
48		fileProperties.put(FileUploadUtils.DOCUMENT_NAME, "/home/alex/test.doc");
49		fileProperties.put(FileUploadUtils.DOCUMENT_FLEXIBLE_ELEMENT, "1");
50				
51		String fileId = fileManager.saveNewFile(fileProperties, "Hello World".getBytes() , AUTHOR_ID);
52		
53		assertThat( contents( fileManager.getFile(fileId, null) ), equalTo("Hello World"));		
54	}
55	
56	
57	
58	private String contents(DownloadableFile item) throws IOException {
59		BufferedReader reader = new BufferedReader(new InputStreamReader( storageProvider.open(item.getStorageId())));
60		return reader.readLine();
61	
62	}
63	
64}
65