View Javadoc
1   package wjhk.jupload2.gui.filepanel.treeview;
2   
3   import static org.junit.Assert.*;
4   
5   import java.io.File;
6   import java.io.IOException;
7   import java.util.Date;
8   
9   import javax.swing.tree.TreePath;
10  
11  import org.junit.Before;
12  import org.junit.Test;
13  
14  import wjhk.jupload2.exception.JUploadExceptionStopAddingFiles;
15  import wjhk.jupload2.filedata.DefaultFileData;
16  import wjhk.jupload2.gui.filepanel.FilePanel;
17  import wjhk.jupload2.policies.UploadPolicy;
18  import wjhk.jupload2.upload.AbstractJUploadTestHelper;
19  
20  public class FileDataTreeViewModelTest extends AbstractJUploadTestHelper {
21  
22      @Before
23      public void setUp() throws Exception {
24          fileDataTreeViewModel = new FileDataTreeViewModel(uploadPolicy, this.filePanelFlatDataModel2);
25      }
26  
27      @Test
28      public void testFileDataTreeViewModel() {
29          assertEquals("uploadPolicy", uploadPolicy, fileDataTreeViewModel.uploadPolicy);
30      }
31  
32      @Test
33      public void testGetColumnCount() {
34          assertEquals(5, fileDataTreeViewModel.getColumnCount());
35      }
36  
37      @Test
38      public void testGetColumnName() {
39          // The mock UploadPolicy doesn't translate strings. We just get the property for the localized strings
40          assertEquals("Name", "colName", fileDataTreeViewModel.getColumnName(0));
41          assertEquals("Size", "colSize", fileDataTreeViewModel.getColumnName(1));
42          assertEquals("Directory", "colDirectory", fileDataTreeViewModel.getColumnName(2));
43          assertEquals("Modified", "colModified", fileDataTreeViewModel.getColumnName(3));
44          assertEquals("Checked", "", fileDataTreeViewModel.getColumnName(4));
45      }
46  
47      @Test
48      public void testGetColumnSizePercentage() {
49          assertEquals(
50                  "100%",
51                  100,
52                  fileDataTreeViewModel.getColumnSizePercentage(0) + fileDataTreeViewModel.getColumnSizePercentage(1)
53                          + fileDataTreeViewModel.getColumnSizePercentage(2)
54                          + fileDataTreeViewModel.getColumnSizePercentage(3)
55                          + fileDataTreeViewModel.getColumnSizePercentage(4));
56      }
57  
58      @Test
59      public void testGetColumnClass() {
60          assertEquals("Name", MyTreeTableModel.class, fileDataTreeViewModel.getColumnClass(0));
61          assertEquals("Size", Long.class, fileDataTreeViewModel.getColumnClass(1));
62          assertEquals("Directory", String.class, fileDataTreeViewModel.getColumnClass(2));
63          assertEquals("Modified", Date.class, fileDataTreeViewModel.getColumnClass(3));
64          assertEquals("Checked", Boolean.class, fileDataTreeViewModel.getColumnClass(4));
65      }
66  
67      @Test
68      public void testGetValueAtTreeFileDataNodeInt() {
69          // Test with real Node
70          FileDataNode fd = new FileDataNode(new DefaultFileData(getTestFile("3.txt"), uploadPolicy));
71          fd.setUploadFlag(false);
72          checkNodeValue(fd, fd, "");
73  
74          // Test with null Node
75          assertNull("node null", fileDataTreeViewModel.getValueAt(null, 1));
76      }
77  
78      /**
79       * @param fd
80       */
81      private void checkNodeValue(FileDataNode fdExpected, FileDataNode fdToBeChecked, String testMsg) {
82          assertEquals("filename (" + testMsg + ")", fdExpected.getFileName(),
83                  fileDataTreeViewModel.getValueAt(fdToBeChecked, 0));
84          assertEquals("size (" + testMsg + ")", fdExpected.getFileLength(),
85                  fileDataTreeViewModel.getValueAt(fdToBeChecked, 1));
86          assertEquals("directory (" + testMsg + ")", fdExpected.getDirectory(),
87                  fileDataTreeViewModel.getValueAt(fdToBeChecked, 2));
88          assertEquals("modified (" + testMsg + ")", fdExpected.getLastModified(),
89                  fileDataTreeViewModel.getValueAt(fdToBeChecked, 3));
90          assertEquals("checked (" + testMsg + ")", fdExpected.getUploadFlag(),
91                  (Boolean) fileDataTreeViewModel.getValueAt(fdToBeChecked, 4));
92      }
93  
94      @Test
95      public void testIsCellEditable() {
96          assertTrue("Name", fileDataTreeViewModel.isCellEditable(null, 0));
97          assertFalse("Size", fileDataTreeViewModel.isCellEditable(null, 1));
98          assertFalse("Directory", fileDataTreeViewModel.isCellEditable(null, 2));
99          assertFalse("Modified", fileDataTreeViewModel.isCellEditable(null, 3));
100         assertTrue("Checked", fileDataTreeViewModel.isCellEditable(null, 4));
101     }
102 
103     @Test
104     public void testSetValueAt() {
105         // Test with real Node
106         FileDataNode fdCheck = new FileDataNode(new DefaultFileData(getTestFile("1.txt"), uploadPolicy));
107         FileDataNode fdToUpdate = new FileDataNode(new DefaultFileData(getTestFile("1.txt"), uploadPolicy));
108         fdCheck.setUploadFlag(false);
109         fdToUpdate.setUploadFlag(false);
110 
111         // Should not generate a change
112         fileDataTreeViewModel.setValueAt("new name", fdToUpdate, 0);
113         checkNodeValue(fdCheck, fdToUpdate, "0");
114 
115         // Should not generate a change
116         fileDataTreeViewModel.setValueAt(10000, fdToUpdate, 1);
117         checkNodeValue(fdCheck, fdToUpdate, "1");
118 
119         // Should not generate a change
120         fileDataTreeViewModel.setValueAt("new directory", fdToUpdate, 2);
121         checkNodeValue(fdCheck, fdToUpdate, "2");
122 
123         // Should not generate a change
124         fileDataTreeViewModel.setValueAt(12314, fdToUpdate, 3);
125         checkNodeValue(fdCheck, fdToUpdate, "3");
126 
127         // Should GENERATE a change
128         assertFalse("Checked", fdToUpdate.getUploadFlag());
129         fdCheck.setUploadFlag(true);
130         fileDataTreeViewModel.setValueAt(true, fdToUpdate, 4);
131         checkNodeValue(fdCheck, fdToUpdate, "4");
132         assertTrue("Checked", fdToUpdate.getUploadFlag());
133     }
134 
135     @Test(expected = NullPointerException.class)
136     public void testSetValueAt_NullNode() {
137         fileDataTreeViewModel.setValueAt(true, null, 4);
138     }
139 
140     @Test
141     public void testGetTreePathFromFile_createDescendant_false() throws IOException, JUploadExceptionStopAddingFiles {
142         // Check for the FS root
143         TreePath rootTreePath = fileDataTreeViewModel.getTreePathFromFile(getRootPath(), false);
144         assertNull("No path for current FS root, as called with false", rootTreePath);
145 
146         // Check for the current folder
147         String currentPath = new File(".").getCanonicalPath();
148         TreePath folderTreePath = fileDataTreeViewModel.getTreePathFromFile(new File(currentPath), false);
149         assertNull("No path for folder, as called with false", folderTreePath);
150 
151         // Check for a file.
152         File f2 = getTestFile("files/level1/level2");
153         TreePath fileTreePath = fileDataTreeViewModel.getTreePathFromFile(f2, false);
154         assertNull("No path for file, as called with false", fileTreePath);
155     }
156 
157     @Test(expected = IllegalStateException.class)
158     public void testGetTreePathFromFile_independantTreeView() throws JUploadExceptionStopAddingFiles {
159 
160         // Preparation
161         String oldValue = System.getProperty(UploadPolicy.PROP_FILE_LIST_VIEW_MODE);
162         System.setProperty(UploadPolicy.PROP_FILE_LIST_VIEW_MODE,
163                 FilePanel.FileListViewMode.INDEPENDENT_TREE_VIEW.toString());
164 
165         // go, go, go
166         try {
167             fileDataTreeViewModel.getTreePathFromFile(new File("."), true);
168         } finally {
169             // Cleaning
170             if (oldValue == null) {
171                 System.clearProperty(UploadPolicy.PROP_FILE_LIST_VIEW_MODE);
172             } else {
173                 System.setProperty(UploadPolicy.PROP_FILE_LIST_VIEW_MODE, oldValue);
174             }
175         }
176     }
177 
178     @Test
179     public void testGetTreePathFromFile_createDescendant_true() throws JUploadExceptionStopAddingFiles {
180         // Check for the FS root
181         assertEquals("Empty tree", 0, getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
182         TreePath rootTreePath = fileDataTreeViewModel.getTreePathFromFile(getRootPath(), true);
183         assertEquals("rootTreePath - nb items", 2, rootTreePath.getPathCount());
184         assertEquals("rootTreePath - root", "", ((FolderNode) rootTreePath.getPathComponent(0)).getFileName());
185 
186         // go, go, go (null file)
187         TreePath treePathNull = fileDataTreeViewModel.getTreePathFromFile(null, true);
188 
189         // Verification
190         assertEquals("With a null file, it should return the root", fileDataTreeViewModel.getAbsoluteRoot(),
191                 treePathNull.getLastPathComponent());
192         assertEquals("null file, last component", fileDataTreeViewModel.absoluteRoot,
193                 treePathNull.getLastPathComponent());
194         assertEquals("null file, nb path", 1, treePathNull.getPath().length);
195 
196         // go, go, go (Real file)
197         TreePath treePath = fileDataTreeViewModel.getTreePathFromFile(new File(getTestFilesRootPath()), true);
198         FolderNode folderNode = (FolderNode) treePath.getLastPathComponent();
199 
200         // Verification
201         assertEquals("Real file", nbSubfoldersForSrcTestResourcesFiles,
202                 getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
203         assertEquals("folderNode", "files", folderNode.getFileName());
204     }
205 
206     /** Get the root of the current FS. e.g.: /, C:, \\myserver.com\ ... */
207     private File getRootPath() {
208         String fCurrentPath = new File(".").getAbsolutePath();
209         // fCurrentPath can start by "/" (unix, mac) or by a drive letter (windows, e.g.: C:, D:...) or by network path
210         File fsRoot = null;
211         if (fCurrentPath.startsWith("/")) {
212             // Unix or Mac FS
213             fsRoot = new File("/");
214         } else if (fCurrentPath.substring(1, 2).equals(":")) {
215             // Windows FS
216             fsRoot = new File(fCurrentPath.substring(0, 2) + "\\");
217         } else if (fCurrentPath.substring(0, 2).equals("\\\\")) {
218             // It's a netbios FS. It starts by \\servername\). Let's find the end of the servername :
219             int iEndServerName = fCurrentPath.indexOf('\\', 2);
220             fsRoot = new File(fCurrentPath.substring(0, iEndServerName + 1));
221         } else {
222             fail("Unknown File Absolute Path: " + fCurrentPath);
223         }
224         return fsRoot;
225     }
226 
227     /*
228      * @Test public void testGetFolderNodeForNewFileFile() throws JUploadExceptionStopAddingFiles { // Preparation
229      * assertEquals("Empty tree", 0, fileDataTreeViewModel.getAbsoluteRoot().getChildCount()); // Null file
230      * assertEquals("With a null file, it should return the root", fileDataTreeViewModel.getAbsoluteRoot(),
231      * fileDataTreeViewModel.getFolderNodeForNewFile(null)); // Real file FolderNode folderNode =
232      * fileDataTreeViewModel.getFolderNodeForNewFile(new File(getTestFilesRootPath())); assertEquals("Real file",
233      * nbSubfoldersForSrcTestResourcesFiles, fileDataTreeViewModel.getAbsoluteRoot() .getChildCount());
234      * assertEquals("folderNode", "files", folderNode.getFileName()); }
235      */
236     /**
237      * Actually the same test as testGetFolderNodeForNewFileFile, but with an additional null as a parameter to
238      * getFolderNodeForNewFile
239      * 
240      * @throws JUploadExceptionStopAddingFiles
241      */
242     /*
243      * @Test public void testGetFolderNodeForNewFileFileFolderNode_parentNode_null() throws
244      * JUploadExceptionStopAddingFiles { // Preparation assertEquals("Empty tree", 0,
245      * fileDataTreeViewModel.getAbsoluteRoot().getChildCount()); // Null file
246      * assertEquals("With a null file, it should return the root", fileDataTreeViewModel.getAbsoluteRoot(),
247      * fileDataTreeViewModel.getFolderNodeForNewFile(null, null)); // Real file FolderNode folderNode =
248      * fileDataTreeViewModel.getFolderNodeForNewFile(new File(getTestFilesRootPath()), null); assertEquals("Real file",
249      * nbSubfoldersForSrcTestResourcesFiles, fileDataTreeViewModel.getAbsoluteRoot() .getChildCount());
250      * assertEquals("folderNode", "files", folderNode.getFileName()); }
251      * @Test public void testGetFolderNodeForNewFileFileFolderNode() throws JUploadExceptionStopAddingFiles { //
252      * Preparation // Let's create a first folder, with all its hierarchy. It's tested here above. FolderNode
253      * parentFolderNode = fileDataTreeViewModel.getFolderNodeForNewFile(new File(getTestFilesRootPath()), null); File
254      * subfolderLevel1 = new File(getTestFilesRootPath(), "level1"); File subsubfolderLevel2 = new File(subfolderLevel1,
255      * "level2"); // go, go, go FolderNode folderNode =
256      * fileDataTreeViewModel.getFolderNodeForNewFile(subsubfolderLevel2, parentFolderNode); // Verification
257      * assertEquals("Real file", nbSubfoldersForSrcTestResourcesFiles + 2, fileDataTreeViewModel.getAbsoluteRoot()
258      * .getChildCount()); assertEquals("folderNode", "level2", folderNode.getFileName()); }
259      */
260 
261     @Test(expected = IllegalArgumentException.class)
262     public void testAttachObject_BadType() throws IllegalArgumentException, JUploadExceptionStopAddingFiles {
263         fileDataTreeViewModel.attachObject(this);
264     }
265 
266     @Test
267     public void testAttachObject() throws IllegalArgumentException, JUploadExceptionStopAddingFiles {
268         // Preparation
269         File file = new File(getTestFilesRootPath());
270         assertEquals("Tree is empty", 0, fileDataTreeViewModel.getAbsoluteRoot().getChildCount());
271 
272         // Go, go, go
273         int nbAttachedObjects = fileDataTreeViewModel.attachObject(file);
274 
275         // Verification
276         assertEquals("nbAttachedObjects", 18, nbAttachedObjects);
277         assertEquals("Real file", 1, fileDataTreeViewModel.getAbsoluteRoot().getChildCount());
278         assertEquals("Real file", nbSubfoldersForSrcTestResourcesFiles + 25,
279                 getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
280     }
281 
282     private int getNbDescendants(TreeFileDataNode node) {
283         int nbDescendant = 0;
284         for (MyTreeNode child : node.getChildren()) {
285             nbDescendant += 1; // The child
286             nbDescendant += getNbDescendants((TreeFileDataNode) child); // The children's child
287         }// for
288         return nbDescendant;
289     }
290 
291     @Test(expected = IllegalArgumentException.class)
292     public void testGetTreePathForObject_badType() {
293         fileDataTreeViewModel.getTreePathForObject(this);
294     }
295 
296     @Test
297     public void testGetTreePathForObject_notCreated() throws IllegalArgumentException, JUploadExceptionStopAddingFiles {
298         // No preparation
299         File file = new File(getTestFilesRootPath());
300 
301         // go, go, go
302         TreePath treePath = fileDataTreeViewModel.getTreePathForObject(file);
303 
304         // Verification
305         assertNull(treePath);
306     }
307 
308     @Test
309     public void testGetTreePathForObject() throws IllegalArgumentException, JUploadExceptionStopAddingFiles {
310         // Preparation
311         File file = new File(getTestFilesRootPath());
312         fileDataTreeViewModel.attachObject(file);
313 
314         // go, go, go
315         TreePath treePath = fileDataTreeViewModel.getTreePathForObject(file);
316 
317         // Verification
318         assertTrue("folderNode", treePath.getLastPathComponent() instanceof FolderNode);
319         assertEquals("filename", "files", ((FolderNode) treePath.getLastPathComponent()).getFileName());
320     }
321 
322     @Test
323     public void testMyAbstractTreeTableModel() {
324         assertEquals("uploadPolicy", uploadPolicy, fileDataTreeViewModel.uploadPolicy);
325 
326         assertNotNull("absoluteRoot", fileDataTreeViewModel.absoluteRoot);
327         assertTrue("absoluteRoot RootNode", fileDataTreeViewModel.absoluteRoot instanceof RootNode);
328         assertEquals("absoluteRoot TreeModel", fileDataTreeViewModel,
329                 ((RootNode) fileDataTreeViewModel.absoluteRoot).treeModel);
330         assertNotNull("absoluteRoot FlatModel", ((RootNode) fileDataTreeViewModel.absoluteRoot).flatModel);
331 
332         assertNotNull("visibleRoot", fileDataTreeViewModel.visibleRoot);
333         assertTrue("visibleRoot RootNode", fileDataTreeViewModel.visibleRoot instanceof RootNode);
334         assertNotNull("absoluteRoot flatModel", ((RootNode) fileDataTreeViewModel.visibleRoot).flatModel);
335     }
336 
337     @Test
338     public void testGetSetTree() {
339         // Start
340         assertEquals(fileDataTreeViewModel.tree, fileDataTreeViewModel.getTree());
341 
342         // Update
343         fileDataTreeViewModel.setTree(null);
344         assertNull("null", fileDataTreeViewModel.getTree());
345     }
346 
347     @Test
348     public void testGetAbsoluteRoot() {
349         assertEquals(fileDataTreeViewModel.absoluteRoot, fileDataTreeViewModel.getAbsoluteRoot());
350     }
351 
352     @Test
353     public void testGetSetRoot() {
354         // Start (absoluteRoot = visibleRoot
355         assertEquals("absoluteRoot", fileDataTreeViewModel.absoluteRoot, fileDataTreeViewModel.getRoot());
356         assertNotNull("not null", fileDataTreeViewModel.getRoot());
357 
358         // Update
359         RootNode newRoot = new RootNode(uploadPolicy, fileDataTreeViewModel, filePanelFlatDataModel2);
360         fileDataTreeViewModel.setRoot(newRoot);
361         assertEquals("newRoot", newRoot, fileDataTreeViewModel.getRoot());
362     }
363 
364     @Test
365     public void testRemove() throws IllegalArgumentException, JUploadExceptionStopAddingFiles {
366         // Preparation
367         File file = new File(getTestFilesRootPath());
368         fileDataTreeViewModel.attachObject(file);
369         assertEquals("Start", nbSubfoldersForSrcTestResourcesFiles + 25,
370                 getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
371         TreeFileDataNode tfdnATextFile3 = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(
372                 getTestFile("files/level1/level2/level3/ATestFile3.txt"), false).getLastPathComponent();
373         TreeFileDataNode tfdnATextFile33 = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(
374                 getTestFile("files/level1/level2/level33/ATestFile33.txt"), false).getLastPathComponent();
375         TreeFileDataNode tfdnATextFolder1 = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(
376                 getTestFile("files/level1"), false).getLastPathComponent();
377 
378         // go, go, go (and check)
379         fileDataTreeViewModel.remove(tfdnATextFile3);
380         assertEquals("tfdnATextFile3", nbSubfoldersForSrcTestResourcesFiles + 24,
381                 getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
382 
383         // go, go, go (and check)
384         fileDataTreeViewModel.remove(tfdnATextFile33);
385         assertEquals("tfdnATextFile33", nbSubfoldersForSrcTestResourcesFiles + 23,
386                 getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
387 
388         // go, go, go (and check)
389         fileDataTreeViewModel.remove(tfdnATextFolder1);
390         assertEquals("tfdnATextFolder1", nbSubfoldersForSrcTestResourcesFiles + 16,
391                 getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
392     }
393 
394     @Test
395     public void testGetTreePath() throws JUploadExceptionStopAddingFiles {
396         // Preparation
397         File file = new File(getTestFilesRootPath());
398         TreePath treePathCheck = fileDataTreeViewModel.getTreePathFromFile(file, true);
399 
400         // go, go, go
401         TreePath treePathExec = fileDataTreeViewModel.getTreePath((TreeFileDataNode) treePathCheck
402                 .getLastPathComponent());
403 
404         // Verification
405         assertEquals("Nb levels", treePathCheck.getPathCount(), treePathExec.getPathCount());
406         for (int i = 0; i < treePathExec.getPathCount(); i += 1) {
407             assertEquals("filename " + i, treePathCheck.getPath()[i].toString(), treePathExec.getPath()[i].toString());
408         }// for
409     }
410 
411     @Test
412     public void testCleanHierarchy() throws JUploadExceptionStopAddingFiles {
413         // Preparation
414         File file = new File(getTestFilesRootPath());
415         fileDataTreeViewModel.attachObject(file);
416         assertEquals("Real file", nbSubfoldersForSrcTestResourcesFiles + 25,
417                 getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
418         TreeFileDataNode tfdnATextFile3 = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(
419                 getTestFile("files/level1/level2/level3/ATestFile3.txt"), false).getLastPathComponent();
420         TreeFileDataNode tfdnATextFile33 = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(
421                 getTestFile("files/level1/level2/level33/ATestFile33.txt"), false).getLastPathComponent();
422         TreeFileDataNode tfdnATextFile22 = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(
423                 getTestFile("files/level1/level22/ATestFile22.txt"), false).getLastPathComponent();
424         fileDataTreeViewModel.remove(tfdnATextFile3);
425         fileDataTreeViewModel.remove(tfdnATextFile33);
426         fileDataTreeViewModel.remove(tfdnATextFile22);
427 
428         // go, go, go
429         fileDataTreeViewModel.cleanHierarchy();
430 
431         // Verification
432         assertEquals("Tree has been cleaned", nbSubfoldersForSrcTestResourcesFiles + 18,
433                 getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
434     }
435 
436     @Test
437     public void testCleanHierarchyT() throws JUploadExceptionStopAddingFiles {
438         // Preparation
439         File file = new File(getTestFilesRootPath());
440         fileDataTreeViewModel.attachObject(file);
441         assertEquals("Real file", nbSubfoldersForSrcTestResourcesFiles + 25,
442                 getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
443         TreeFileDataNode tfdnATextFile3 = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(
444                 getTestFile("files/level1/level2/level3/ATestFile3.txt"), false).getLastPathComponent();
445         TreeFileDataNode tfdnATextFile33 = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(
446                 getTestFile("files/level1/level2/level33/ATestFile33.txt"), false).getLastPathComponent();
447         TreeFileDataNode tfdnATextFile22 = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(
448                 getTestFile("files/level1/level22/ATestFile22.txt"), false).getLastPathComponent();
449         fileDataTreeViewModel.remove(tfdnATextFile3); // Behind level2
450         fileDataTreeViewModel.remove(tfdnATextFile33); // Behind level2
451         fileDataTreeViewModel.remove(tfdnATextFile22);// No behind level2 (level22 is a "no children" folder, but should
452                                                       // not be cleared
453         TreeFileDataNode tfdnFolder2 = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(
454                 getTestFile("files/level1/level2"), false).getLastPathComponent();
455 
456         // go, go, go
457         boolean ret = fileDataTreeViewModel.cleanHierarchy(tfdnFolder2);
458 
459         // Verification
460         assertTrue("Return", ret);
461         assertEquals("Tree has been cleaned", nbSubfoldersForSrcTestResourcesFiles + 20,
462                 getNbDescendants(fileDataTreeViewModel.getAbsoluteRoot()));
463     }
464 
465     @Test
466     public void testGetChild() throws JUploadExceptionStopAddingFiles {
467         // Preparation
468         File file = new File(getTestFilesRootPath());
469         fileDataTreeViewModel.attachObject(file);
470         TreeFileDataNode tfdn = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(file, false)
471                 .getLastPathComponent();
472 
473         // go, go, go
474         TreeFileDataNode tfdnChild = fileDataTreeViewModel.getChild(tfdn, 3);
475 
476         // Verification
477         assertEquals("child index 3", "3.txt", tfdnChild.toString());
478     }
479 
480     @Test
481     public void testGetChildCount() throws JUploadExceptionStopAddingFiles {
482         // Preparation
483         File file = new File(getTestFilesRootPath());
484         fileDataTreeViewModel.attachObject(file);
485         TreeFileDataNode tfdn = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(file, false)
486                 .getLastPathComponent();
487 
488         // go, go, go
489         int childCount = fileDataTreeViewModel.getChildCount(tfdn);
490 
491         // Verification
492         assertEquals("child index 3", 14, childCount);
493     }
494 
495     @Test
496     public void testIsLeaf() throws JUploadExceptionStopAddingFiles {
497         // Preparation
498         File file = new File(getTestFilesRootPath());
499         fileDataTreeViewModel.attachObject(file);
500         TreeFileDataNode tfdn = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(file, false)
501                 .getLastPathComponent();
502         TreeFileDataNode tfdnChild = fileDataTreeViewModel.getChild(tfdn, 3);
503 
504         // Verification
505         assertFalse("folder", fileDataTreeViewModel.isLeaf(tfdn));
506         assertTrue("file", fileDataTreeViewModel.isLeaf(tfdnChild));
507     }
508 
509     @Test
510     public void testGetIndexOfChild() throws JUploadExceptionStopAddingFiles {
511         // Preparation
512         File file = new File(getTestFilesRootPath());
513         fileDataTreeViewModel.attachObject(file);
514         TreeFileDataNode tfdn = (TreeFileDataNode) fileDataTreeViewModel.getTreePathFromFile(file, false)
515                 .getLastPathComponent();
516         TreeFileDataNode tfdnChild = fileDataTreeViewModel.getChild(tfdn, 3);
517 
518         // Verification
519         assertEquals(3, fileDataTreeViewModel.getIndexOfChild(tfdn, tfdnChild));
520     }
521 
522 }