Source Code Cross Referenced for TestFileSystemCollection.java in  » Search-Engine » zilverline » org » zilverline » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Search Engine » zilverline » org.zilverline.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2003-2004 Michael Franken, Zilverline.
003:         *
004:         * The contents of this file, or the files included with this file, are subject to
005:         * the current version of ZILVERLINE Collaborative Source License for the
006:         * Zilverline Search Engine (the "License"); You may not use this file except in
007:         * compliance with the License.
008:         *
009:         * You may obtain a copy of the License at
010:         *
011:         *     http://www.zilverline.org.
012:         *
013:         * See the License for the rights, obligations and
014:         * limitations governing use of the contents of the file.
015:         *
016:         * The Original and Upgraded Code is the Zilverline Search Engine. The developer of
017:         * the Original and Upgraded Code is Michael Franken. Michael Franken owns the
018:         * copyrights in the portions it created. All Rights Reserved.
019:         *
020:         */
021:
022:        package org.zilverline.core;
023:
024:        import java.io.File;
025:        import java.util.Iterator;
026:        import java.util.List;
027:        import java.util.ListIterator;
028:
029:        import org.apache.commons.logging.Log;
030:        import org.apache.commons.logging.LogFactory;
031:
032:        import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
033:        import org.springframework.util.StringUtils;
034:
035:        import org.zilverline.service.CollectionManager;
036:
037:        /**
038:         * Test class for Collection, self documenting.
039:         * 
040:         * @author Michael Franken
041:         * 
042:         * @see org.zilverline.core.FileSystemCollection
043:         */
044:        public class TestFileSystemCollection extends
045:                AbstractDependencyInjectionSpringContextTests {
046:            /** logger for Commons logging. */
047:            private static Log log = LogFactory
048:                    .getLog(TestFileSystemCollection.class);
049:
050:            protected String[] getConfigLocations() {
051:                return new String[] { "applicationContext.xml" };
052:            }
053:
054:            public void testName() {
055:                FileSystemCollection col = new FileSystemCollection();
056:                assertEquals("", col.getName());
057:                col.setName("test");
058:                assertEquals("test", col.getName());
059:            }
060:
061:            public void testNoURL() {
062:                FileSystemCollection col = new FileSystemCollection();
063:                assertNull(col.getUrlDefault());
064:                col
065:                        .setContentDir(new File(System
066:                                .getProperty("java.io.tmpdir")));
067:                col.setUrl(null);
068:                assertTrue(new File(System.getProperty("java.io.tmpdir"))
069:                        .exists());
070:                assertTrue("need a URL", StringUtils.hasLength(col
071:                        .getUrlDefault()));
072:                assertTrue(col.getUrlDefault().endsWith("/"));
073:            }
074:
075:            public void testURL() {
076:                FileSystemCollection col = new FileSystemCollection();
077:                assertNull(col.getUrlDefault());
078:                String testString = "http://localhost/books";
079:                col.setUrl(testString);
080:                assertEquals("http://localhost/books/", col.getUrlDefault());
081:                assertTrue(col.getUrlDefault().endsWith("/"));
082:            }
083:
084:            public void testNoCacheURL() {
085:                FileSystemCollection col = new FileSystemCollection();
086:                assertNotNull(col.getCacheDirWithManagerDefaults());
087:                assertNotNull(col.getCacheUrlWithManagerDefaults());
088:                col.setCacheDir(new File(System.getProperty("java.io.tmpdir")));
089:                col.setCacheUrl(null);
090:                assertTrue(new File(System.getProperty("java.io.tmpdir"))
091:                        .exists());
092:                assertTrue("need a URL", StringUtils.hasLength(col
093:                        .getCacheUrlWithManagerDefaults()));
094:                assertTrue(col.getCacheUrlWithManagerDefaults().endsWith("/"));
095:            }
096:
097:            public void testCacheURL() {
098:                FileSystemCollection col = new FileSystemCollection();
099:                assertNull(col.getUrlDefault());
100:                String testString = "http://localhost/cachedBooks";
101:                col.setCacheUrl(testString);
102:                assertEquals("http://localhost/cachedBooks/", col
103:                        .getCacheUrlWithManagerDefaults());
104:                assertTrue(col.getCacheUrlWithManagerDefaults().endsWith("/"));
105:            }
106:
107:            public final void testContentDir() {
108:                try {
109:                    CollectionManager colMan = (CollectionManager) applicationContext
110:                            .getBean("collectionMan");
111:                    List collections = colMan.getCollections();
112:
113:                    for (Iterator iter = collections.iterator(); iter.hasNext();) {
114:                        DocumentCollection col = (DocumentCollection) iter
115:                                .next();
116:
117:                        assertTrue(col.getName() + " does not exist", col
118:                                .isIndexValid());
119:                        assertTrue(
120:                                col.getName() + " with url: '"
121:                                        + col.getUrlDefault()
122:                                        + "' does not end with /", col
123:                                        .getUrlDefault().endsWith("/"));
124:                    }
125:                } catch (Exception e) {
126:                    fail("Should not happen, Exception: " + e.getMessage());
127:                }
128:            }
129:
130:            public final void testCollectionAddToManager() {
131:                try {
132:                    CollectionManager colMan = (CollectionManager) applicationContext
133:                            .getBean("collectionMan");
134:                    int size = colMan.getCollections().size();
135:
136:                    FileSystemCollection col1 = new FileSystemCollection();
137:                    col1.setName("collection1");
138:                    colMan.addCollection(col1);
139:                    log.debug("New collection has got Id: " + col1.getId());
140:                    assertEquals(size + 1, colMan.getCollections().size());
141:
142:                    FileSystemCollection col2 = new FileSystemCollection();
143:                    col2.setName("collection2");
144:                    // give the new Collection an existing ID, then add it, it should replace instead of being added
145:                    col2.setId(col1.getId());
146:                    // test overridden equals method
147:                    assertTrue(col1.equals(col2));
148:                    colMan.addCollection(col2);
149:                    assertEquals(size + 1, colMan.getCollections().size());
150:                    colMan.deleteCollection(col1);
151:                    colMan.deleteCollection(col2);
152:                } catch (Exception e) {
153:                    fail("Should not happen, Exception: " + e.getMessage());
154:                }
155:            }
156:
157:            public final void testCacheDir() {
158:                CollectionManager colMan = (CollectionManager) applicationContext
159:                        .getBean("collectionMan");
160:                List collections = colMan.getCollections();
161:
162:                for (Iterator iter = collections.iterator(); iter.hasNext();) {
163:                    DocumentCollection col = (DocumentCollection) iter.next();
164:                    // the following assertion should hold if the cacheDir exists, and is a Directory
165:                    if (col.getCacheDirWithManagerDefaults().exists()) {
166:                        assertTrue(col.getCacheUrlWithManagerDefaults(), col
167:                                .getCacheUrlWithManagerDefaults().endsWith("/"));
168:                    }
169:                }
170:            }
171:
172:            public void testAllCollections() throws Exception {
173:                CollectionManager c = (CollectionManager) applicationContext
174:                        .getBean("collectionMan");
175:                assertNotNull(c);
176:
177:                ListIterator li = c.getCollections().listIterator();
178:                while (li.hasNext()) {
179:                    DocumentCollection col = (DocumentCollection) li.next();
180:                    log.debug("Collection " + col.getName());
181:                    if (col instanceof  FileSystemCollection) {
182:                        assertTrue(col.getName(), ((FileSystemCollection) col)
183:                                .getContentDir().isDirectory());
184:                        log.debug(((FileSystemCollection) col).getContentDir()
185:                                + ", " + col.getIndexDirWithManagerDefaults()
186:                                + ", " + col.getCacheDirWithManagerDefaults());
187:                        log.debug(((FileSystemCollection) col).getContentDir()
188:                                .getAbsoluteFile());
189:                    }
190:                    log.debug(col.getName() + " has %%% "
191:                            + col.getNumberOfDocs() + " documents.");
192:                }
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.