KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > testsupport > AbstractDaisyTestCase


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.repository.testsupport;
17
18 import junit.framework.TestCase;
19
20 import java.io.File JavaDoc;
21
22 import org.outerj.daisy.repository.RepositoryManager;
23 import org.outerj.daisy.repository.Credentials;
24 import org.outerj.daisy.repository.clientimpl.RemoteRepositoryManager;
25 import org.outerj.daisy.emailnotifier.clientimpl.RemoteEmailSubscriptionManagerProvider;
26 import org.outerj.daisy.navigation.clientimpl.RemoteNavigationManagerProvider;
27 import org.outerj.daisy.jms.JmsClient;
28 import org.outerj.daisy.doctaskrunner.clientimpl.RemoteDocumentTaskManagerProvider;
29 import org.apache.avalon.framework.logger.Logger;
30
31 public abstract class AbstractDaisyTestCase extends TestCase {
32
33     protected MyMerlin merlin;
34     private TestSupportConfig config;
35
36     protected void setUp() throws Exception JavaDoc {
37         super.setUp();
38
39         config = new TestSupportConfig();
40
41         if (resetDataStores()) {
42
43             System.out.println("Reinstalling database...");
44             DatabaseHelper dbHelper = new DatabaseHelper(config);
45             dbHelper.resetDatabase("testuser", "testuser");
46
47             String JavaDoc blobstore = config.getRequiredProperty("testsupport.blobstore");
48             String JavaDoc indexstore = config.getRequiredProperty("testsupport.fulltextindexstore");
49
50             File JavaDoc blobstoreFile = new File JavaDoc(blobstore);
51             if (!blobstoreFile.exists() && blobstoreFile.isDirectory())
52                 throw new Exception JavaDoc("Blobstore directory does not exist or is not a directory: " + blobstoreFile.getAbsolutePath());
53             System.out.println("Deleting contents of blobstore directory (" + blobstoreFile.getAbsolutePath() + ")...");
54             emptyDir(blobstoreFile);
55
56             File JavaDoc indexstoreFile = new File JavaDoc(indexstore);
57             if (!indexstoreFile.exists() && indexstoreFile.isDirectory())
58                 throw new Exception JavaDoc("Indexstore directory does not exist or is not a directory: " + indexstoreFile.getAbsolutePath());
59             System.out.println("Deleting contents of indexstore directory (" + indexstoreFile.getAbsolutePath() + ")...");
60             emptyDir(indexstoreFile);
61         }
62
63         merlin = new MyMerlin(config);
64
65         merlin.startMerlin();
66     }
67
68     private void emptyDir(File JavaDoc dir) {
69         File JavaDoc[] files = dir.listFiles();
70         for (int i = 0; i < files.length; i++) {
71             if (files[i].isDirectory())
72                 emptyDir(files[i]);
73             files[i].delete();
74         }
75     }
76
77     protected void tearDown() throws Exception JavaDoc {
78         super.tearDown();
79         merlin.stopMerlin();
80     }
81
82     protected abstract boolean resetDataStores();
83
84     protected Object JavaDoc getComponent(String JavaDoc path) throws Exception JavaDoc {
85         return merlin.resolve(path);
86     }
87
88     protected RepositoryManager getRemoteRepositoryManager() throws Exception JavaDoc {
89         JmsClient jmsClient = (JmsClient)getComponent("/daisy/jmsclient/jmsclient");
90         RemoteRepositoryManager repositoryManager = new RemoteRepositoryManager("http://localhost:9263", new Credentials("testuser", "testuser"), jmsClient, config.getRequiredProperty("testsupport.jmstopic"), new DummyLogger());
91         repositoryManager.registerExtension("EmailSubscriptionManager", new RemoteEmailSubscriptionManagerProvider());
92         repositoryManager.registerExtension("NavigationManager", new RemoteNavigationManagerProvider());
93         repositoryManager.registerExtension("DocumentTaskManager", new RemoteDocumentTaskManagerProvider());
94         return repositoryManager;
95     }
96
97     protected RepositoryManager getLocalRepositoryManager() throws Exception JavaDoc {
98         return (RepositoryManager)getComponent("/daisy/repository/repository-manager");
99     }
100
101     private class DummyLogger implements Logger {
102         public void debug(String JavaDoc s) {
103             System.out.println(s);
104         }
105
106         public void debug(String JavaDoc s, Throwable JavaDoc throwable) {
107             System.out.println(s);
108         }
109
110         public boolean isDebugEnabled() {
111             return true;
112         }
113
114         public void info(String JavaDoc s) {
115             System.out.println(s);
116         }
117
118         public void info(String JavaDoc s, Throwable JavaDoc throwable) {
119             System.out.println(s);
120         }
121
122         public boolean isInfoEnabled() {
123             return true;
124         }
125
126         public void warn(String JavaDoc s) {
127             System.out.println(s);
128         }
129
130         public void warn(String JavaDoc s, Throwable JavaDoc throwable) {
131             System.out.println(s);
132         }
133
134         public boolean isWarnEnabled() {
135             return true;
136         }
137
138         public void error(String JavaDoc s) {
139             System.out.println(s);
140         }
141
142         public void error(String JavaDoc s, Throwable JavaDoc throwable) {
143             System.out.println(s);
144         }
145
146         public boolean isErrorEnabled() {
147             return false;
148         }
149
150         public void fatalError(String JavaDoc s) {
151             System.out.println(s);
152         }
153
154         public void fatalError(String JavaDoc s, Throwable JavaDoc throwable) {
155             System.out.println(s);
156         }
157
158         public boolean isFatalErrorEnabled() {
159             return true;
160         }
161
162         public Logger getChildLogger(String JavaDoc s) {
163             return new DummyLogger();
164         }
165     }
166 }
167
Popular Tags