Source Code Cross Referenced for OSIDUnitTestTool.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » tool » OSIDUnitTest » 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 » ERP CRM Financial » sakai » org.sakaiproject.tool.OSIDUnitTest 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: $
003:         * $Id:  $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.tool.OSIDUnitTest;
021:
022:        import java.io.IOException;
023:        import java.io.PrintWriter;
024:
025:        import javax.servlet.ServletConfig;
026:        import javax.servlet.ServletException;
027:        import javax.servlet.http.HttpServlet;
028:        import javax.servlet.http.HttpServletRequest;
029:        import javax.servlet.http.HttpServletResponse;
030:
031:        import org.sakaiproject.component.cover.ComponentManager;
032:
033:        /**
034:         * A set of unit tests to print out information for the Sakai OSID implementations.
035:         * @author Massachusetts Institute of Technology
036:         * @version $Id: PresenceTool.java 632 2005-07-14 21:22:50Z janderse@umich.edu $
037:         *
038:         */
039:        public class OSIDUnitTestTool extends HttpServlet {
040:
041:            /**
042:             * Access the Servlet's information display.
043:             *
044:             * @return servlet information.
045:             */
046:            public String getServletInfo() {
047:                return "Sakai Portal1";
048:            }
049:
050:            /**
051:             * Initialize the servlet.
052:             *
053:             * @param config
054:             *        The servlet config.
055:             * @throws ServletException
056:             */
057:            public void init(ServletConfig config) throws ServletException {
058:                super .init(config);
059:
060:            }
061:
062:            /**
063:             * Shutdown the servlet.
064:             */
065:            public void destroy() {
066:                super .destroy();
067:            }
068:
069:            private void testStart(PrintWriter out, String theString) {
070:                out.println("<tr><td>&nbsp;</td></tr>\r\n");
071:                out.println("<tr><td>Starting Test " + theString
072:                        + "</td></tr>\r\n");
073:            }
074:
075:            private void testStep(PrintWriter out, String theString) {
076:                out.println("<tr><td>" + theString + "</td></tr>\r\n");
077:            }
078:
079:            private void testPass(PrintWriter out, String theString) {
080:                out.println("<tr><td><font color=green>Passed: " + theString
081:                        + "</font></td></tr>\r\n");
082:            }
083:
084:            private void testFail(PrintWriter out, String theString) {
085:                out.println("<tr><td><font color=red>Failed: " + theString
086:                        + "</font></td></tr>\r\n");
087:            }
088:
089:            /**
090:             * Respond to navigation / access requests.
091:             *
092:             * @param req
093:             *        The servlet request.
094:             * @param res
095:             *        The servlet response.
096:             * @throws ServletException.
097:             * @throws IOException.
098:             *
099:             * Get an instance of the Sakai OSID RepositoryManager using the Component Manager.
100:             * Given the manager, get a list of registered repositories.
101:             */
102:            protected void doGet(HttpServletRequest req, HttpServletResponse res)
103:                    throws ServletException, IOException {
104:                // start the response
105:                res.setContentType("text/html; charset=UTF-8");
106:                PrintWriter out = res.getWriter();
107:
108:                out.println("<html>");
109:                out.println("<body>");
110:                out.println("<table>");
111:
112:                try {
113:                    testStart(out, "IdManager");
114:                    ComponentManager.getInstance();
115:                    Object o = ComponentManager.get("org.osid.id.IdManager");
116:                    if (o != null) {
117:                        org.osid.id.IdManager idManager = (org.osid.id.IdManager) o;
118:                        org.osid.shared.Id theId = idManager.createId();
119:                        testStep(out, "ID = " + theId.getIdString());
120:                        testPass(out, "IdManager");
121:                    } else {
122:                        testFail(out,
123:                                "ComponentManager could not find IdManager");
124:                    }
125:                } catch (Throwable t) {
126:                    testFail(out, "IdManager Exception " + t.toString());
127:                    // TODO: throw(t);
128:                }
129:
130:                try {
131:                    testStart(out, "LoggingManager");
132:                    ComponentManager.getInstance();
133:                    Object o = ComponentManager
134:                            .get("org.osid.logging.LoggingManager");
135:                    if (o != null) {
136:                        org.osid.logging.LoggingManager loggingManager = (org.osid.logging.LoggingManager) o;
137:                        org.osid.shared.StringIterator iter = loggingManager
138:                                .getLogNamesForWriting();
139:                        testStep(out, "Writable Logs " + iter);
140:                        org.osid.logging.WritableLog log = loggingManager
141:                                .getLogForWriting("info");
142:                        log.appendLog("This message should go to info log");
143:                        log = loggingManager.getLogForWriting("trace");
144:                        log.appendLog("This message should go to trace log");
145:                        log = loggingManager.getLogForWriting("fred");
146:                        log
147:                                .appendLog("This message should go to info log because if the log is unknown, info is assumed");
148:                        testPass(out, "LoggingManager");
149:                    } else {
150:                        testFail(out,
151:                                "ComponentManager could not find LoggingManager");
152:                    }
153:                } catch (Throwable t) {
154:                    testFail(out, "LoggingManager Exception " + t.toString());
155:                    // TODO: throw(t);
156:                }
157:
158:                try {
159:                    testStart(out, "RepositoryManager");
160:                    ComponentManager.getInstance();
161:                    Object o = ComponentManager
162:                            .get("org.osid.repository.RepositoryManager");
163:                    if (o != null) {
164:                        // have a place to store Repositories for later use in a search
165:                        java.util.Vector repositoryVector = new java.util.Vector();
166:
167:                        // initialize the repository manager and get its repositories
168:                        org.osid.repository.RepositoryManager repositoryManager = (org.osid.repository.RepositoryManager) o;
169:                        repositoryManager
170:                                .assignOsidContext(new org.osid.OsidContext());
171:                        repositoryManager
172:                                .assignConfiguration(new java.util.Properties());
173:                        org.osid.repository.RepositoryIterator repositoryIterator = repositoryManager
174:                                .getRepositories();
175:                        out
176:                                .println("<tr><td>List of OSID Repositories</td></tr>");
177:                        while (repositoryIterator.hasNextRepository()) {
178:                            // display each repository name in a line and store away the repository for a search
179:                            org.osid.repository.Repository nextRepository = repositoryIterator
180:                                    .nextRepository();
181:                            out.println("<tr><td>"
182:                                    + nextRepository.getDisplayName()
183:                                    + "</td></tr>");
184:                            repositoryVector.addElement(nextRepository);
185:                        }
186:
187:                        // perform a search if a criteria was passed
188:                        String criteria = req.getParameter("criteria");
189:                        org.osid.shared.Type thumbnailType = new Type(
190:                                "mit.edu", "partStructure", "thumbnail");
191:                        org.osid.shared.Type urlType = new Type("mit.edu",
192:                                "partStructure", "URL");
193:
194:                        if (criteria != null) {
195:                            // convert a vector of repositories to an array which the method call requires
196:                            int size = repositoryVector.size();
197:                            org.osid.repository.Repository repositories[] = new org.osid.repository.Repository[size];
198:                            for (int i = 0; i < size; i++) {
199:                                repositories[i] = (org.osid.repository.Repository) repositoryVector
200:                                        .elementAt(i);
201:                            }
202:
203:                            // perform the search
204:                            out
205:                                    .println("<tr><td>Results of searching all repositories for "
206:                                            + criteria + "</td></tr>");
207:                            org.osid.repository.AssetIterator assetIterator = repositoryManager
208:                                    .getAssetsBySearch(repositories, criteria,
209:                                            new Type("mit.edu", "search",
210:                                                    "keyword"), null);
211:                            while (assetIterator.hasNextAsset()) {
212:                                // show the name of the asset that was found
213:                                org.osid.repository.Asset asset = assetIterator
214:                                        .nextAsset();
215:                                out
216:                                        .println("<tr><td>Asset is "
217:                                                + asset.getDisplayName()
218:                                                + "</td></tr>");
219:
220:                                // look for a thumbnail or url part and show any
221:                                org.osid.repository.RecordIterator recordIterator = asset
222:                                        .getRecords();
223:                                while (recordIterator.hasNextRecord()) {
224:                                    org.osid.repository.PartIterator partIterator = recordIterator
225:                                            .nextRecord().getParts();
226:                                    while (partIterator.hasNextPart()) {
227:                                        org.osid.repository.Part part = partIterator
228:                                                .nextPart();
229:                                        org.osid.shared.Type partStructureType = part
230:                                                .getPartStructure().getType();
231:                                        if (partStructureType
232:                                                .isEqual(thumbnailType)) {
233:                                            out.println("<tr><td>Thumbnail is "
234:                                                    + part.getValue()
235:                                                    + "</td></tr>");
236:                                        } else if (partStructureType
237:                                                .isEqual(urlType)) {
238:                                            out.println("<tr><td>URL is "
239:                                                    + part.getValue()
240:                                                    + "</td></tr>");
241:                                        }
242:                                    }
243:                                }
244:                            }
245:                        }
246:
247:                    }
248:                } catch (Throwable t) {
249:                    t.printStackTrace();
250:                }
251:
252:                out.println("</table>");
253:                out.println("</body>");
254:                out.println("</html>");
255:            }
256:
257:            /**
258:             * Respond to data posting requests.
259:             *
260:             * @param req
261:             *        The servlet request.
262:             * @param res
263:             *        The servlet response.
264:             * @throws ServletException.
265:             * @throws IOException.
266:             */
267:            protected void doPost(HttpServletRequest req,
268:                    HttpServletResponse res) throws ServletException,
269:                    IOException {
270:                // start the response
271:                res.setContentType("text/html; charset=UTF-8");
272:                PrintWriter out = res.getWriter();
273:
274:                out.println("<h1>Test</h1>");
275:            }
276:
277:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.