1 package org.tigris.scarab.om; 2 3 48 49 import java.io.File ; 50 51 import org.apache.commons.fileupload.DefaultFileItemFactory; 52 import org.apache.commons.fileupload.FileItem; 53 import org.apache.commons.fileupload.FileItemFactory; 54 import org.apache.torque.om.NumberKey; 55 import org.tigris.scarab.test.BaseScarabTestCase; 56 57 58 64 public class AttachmentTest2 extends BaseScarabTestCase 65 { 66 private Attachment comment = null; 67 private Attachment fileAttachment = null; 68 private Issue issue = null; 69 70 public void setUp()throws Exception { 71 super.setUp(); 72 comment = AttachmentManager.getInstance(); 73 fileAttachment = AttachmentManager.getInstance(); 74 issue = IssueManager.getInstance(new NumberKey("1")); 75 76 } 77 78 79 public void saveFile() throws Exception 80 { 81 FileItemFactory factory = new DefaultFileItemFactory(6480, null); 83 String textFieldName = "textField"; 84 85 FileItem fileItem = factory.createItem( 86 textFieldName, 87 "image/jpeg", 88 true, 89 "logo.gif" 90 ); 91 fileAttachment.setFile(fileItem); 92 fileAttachment.setName(fileItem.getName()); 93 fileAttachment.setMimeType("image/jpeg"); 94 fileAttachment.setCreatedBy(getUser1().getUserId()); 95 issue.addFile(fileAttachment, getUser1()); 96 issue.save(); 97 issue.doSaveFileAttachments(getUser1()); 99 System.out.println("filename=" + fileAttachment.getFileName()); 100 } 101 102 public void testGetRepositoryDirectory() throws Exception 103 { 104 105 String control = new String ("WEB-INF" + File.separator + "attachments"); 109 File testPath = new File (Attachment.getRepositoryDirectory()); 110 assertTrue("testpath was:" + testPath.getPath(),testPath.getPath().endsWith(control)); 111 } 112 113 public void OFFtestGetRelativePath() throws Exception 114 { 115 saveFile(); 116 File control = new File ("mod" + issue.getModuleId().toString() 117 + "/" + issue.getIdCount()/1000 + "/" 118 + issue.getUniqueId() + "_" 119 + fileAttachment.getQueryKey() 120 + "_" + fileAttachment.getFileName()); 121 File testPath = new File (fileAttachment.getRelativePath()); 122 assertEquals(control.getPath(), testPath.getPath()); 123 } 124 125 public void OFFtestGetFullPath() throws Exception 126 { 127 saveFile(); 128 File control = new File (fileAttachment.getFullPath()); 129 File testPath = new File (Attachment.getRepositoryDirectory(), 130 fileAttachment.getRelativePath()); 131 assertEquals(control.getPath(), testPath.getPath()); 132 } 133 } 134 | Popular Tags |