01: package com.sun.portal.app.filesharing.repo;
02:
03: import junit.framework.TestCase;
04:
05: /**
06: * @author Alejandro Abdelnur
07: */
08: public class RepoItemTest extends TestCase {
09:
10: public void testRoot() throws Exception {
11: assertEquals(RepoItem.ROOT, RepoItem.ROOT);
12: assertEquals(RepoItem.ROOT.getPath(), "/");
13: assertEquals(RepoItem.ROOT.getName(), "/");
14: assertEquals(RepoItem.ROOT.getParent(), null);
15: assertEquals(RepoItem.ROOT.getCreator(), "ROOT");
16:
17: assertEquals(RepoItem.ROOT, new RepoItem("/", "ROOT"));
18:
19: RepoItem item = new RepoItem(RepoItem.ROOT, "a", "owner");
20: assertEquals(item.getParent(), RepoItem.ROOT);
21: }
22:
23: public void testPathConstructor() throws Exception {
24: try {
25: new RepoItem(null, "owner");
26: assertTrue("path cannot be null", false);
27: } catch (Exception ex) {
28: }
29: try {
30: new RepoItem("", "owner");
31: assertTrue("path cannot be empty", false);
32: } catch (Exception ex) {
33: }
34: try {
35: new RepoItem("a", "owner");
36: assertTrue("path must start with /", false);
37: } catch (Exception ex) {
38: }
39: try {
40: new RepoItem("//a", "owner");
41: assertTrue("path must not have //", false);
42: } catch (Exception ex) {
43: }
44:
45: RepoItem item = new RepoItem("/a/", "owner");
46: assertEquals(RepoItem.ROOT, item.getParent());
47: assertEquals("/a", item.getPath());
48: assertEquals("a", item.getName());
49: }
50:
51: public void testParentNameConstructor() throws Exception {
52: try {
53: new RepoItem(null, "a", "owner");
54: assertTrue("parent cannot be null", false);
55: } catch (Exception ex) {
56: }
57: try {
58: new RepoItem(RepoItem.ROOT, null, "owner");
59: assertTrue("name cannot be null", false);
60: } catch (Exception ex) {
61: }
62: try {
63: new RepoItem(RepoItem.ROOT, "a", null);
64: assertTrue("creator cannot be null", false);
65: } catch (Exception ex) {
66: }
67: try {
68: new RepoItem(RepoItem.ROOT, "a/a", null);
69: assertTrue("creator cannot container a /", false);
70: } catch (Exception ex) {
71: }
72: }
73:
74: public void testPath() throws Exception {
75: RepoItem item1 = new RepoItem(RepoItem.ROOT, "a", "owner");
76: RepoItem item2 = new RepoItem(item1, "b", "owner");
77: assertEquals("/a", item1.getPath());
78: assertEquals("/a/b", item2.getPath());
79: }
80:
81: }
|