View Javadoc
1   package wjhk.jupload2.gui.filepanel.treeview;
2   
3   import static org.junit.Assert.*;
4   
5   import java.io.File;
6   
7   import org.junit.Before;
8   import org.junit.Test;
9   
10  import wjhk.jupload2.JUploadDaemon;
11  import wjhk.jupload2.exception.JUploadException;
12  import wjhk.jupload2.filedata.DefaultFileData;
13  import wjhk.jupload2.filedata.FileData;
14  import wjhk.jupload2.testhelpers.FilePanelTestHelper;
15  import wjhk.jupload2.testhelpers.JUploadPanelTestHelper;
16  import wjhk.jupload2.testhelpers.UploadPolicyTestHelper;
17  import wjhk.jupload2.upload.AbstractJUploadTestHelper;
18  
19  public class FileDataNodeTest extends AbstractJUploadTestHelper {
20  
21      File file = null;
22  
23      File root = new File(".");
24  
25      FileData fileData = null;
26  
27      FileDataNode fileDataNode = null;
28  
29      @Before
30      public void setUp() throws Exception {
31          // Set the postURL for the current unit test, according to the local network access.
32          setPostURL();
33  
34          this.juploadDaemon = new JUploadDaemon();
35          this.filePanel = new FilePanelTestHelper(this.filesToUpload);
36          this.juploadPanel = new JUploadPanelTestHelper(this.filePanel);
37          this.uploadPolicy = new UploadPolicyTestHelper(this.juploadPanel);
38  
39          file = AbstractJUploadTestHelper.getTestFile(File.separator + "files" + File.separator + "1.txt");
40          fileData = new DefaultFileData(file, uploadPolicy);
41          fileDataNode = new FileDataNode(fileData);
42      }
43  
44      @Test
45      public void testFileDataNode() {
46          assertNotNull("not null", fileDataNode);
47          assertEquals("getChildren", 0, fileDataNode.getChildren().size());
48          assertEquals("getFileName", "1.txt", fileDataNode.getFileName());
49          assertEquals("getFileExtension", "txt", fileDataNode.getFileExtension());
50          assertEquals("getFileLength", 3, fileDataNode.getFileLength());
51          assertEquals("getLastModified", fileData.getLastModified(), fileDataNode.getLastModified());
52          assertEquals("getDirectory", file.getAbsoluteFile().getParent(), fileDataNode.getDirectory());
53          assertEquals("canRead", true, fileDataNode.canRead());
54          // assertEquals("getFile", file, fileDataNode.getFile()); Now raises an error
55          assertEquals("isPreparedForUpload", false, fileDataNode.isPreparedForUpload());
56          assertEquals("getChildCount", 0, fileDataNode.getChildCount());
57          assertNull("getChild", fileDataNode.getChild(24));
58          assertNull("getChild", fileDataNode.getChild("24"));
59          assertEquals("isLeaf", true, fileDataNode.isLeaf());
60          assertEquals("parent", null, fileDataNode.getParent());
61          assertEquals("model", null, fileDataNode.treeModel);
62  
63          assertEquals("FileData link", fileDataNode, fileData.getTreeFileDataNode());
64      }
65  
66      @Test
67      public void testSetGetUploadFlag() {
68          assertEquals("getUploadFlag (true)", true, fileDataNode.getUploadFlag());
69          fileDataNode.setUploadFlag(false);
70          assertEquals("getUploadFlag (false)", false, fileDataNode.getUploadFlag());
71      }
72  
73      @Test(expected = IllegalStateException.class)
74      public void testGetUploadLength_NotPrepared() {
75          assertEquals("getUploadLength", 3, fileDataNode.getUploadLength());
76      }
77  
78      public void testGetUploadLength_Prepared() throws JUploadException {
79          fileDataNode.beforeUpload(null);
80          assertEquals("getUploadLength", 3, fileDataNode.getUploadLength());
81      }
82  
83  }