KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > mailrepository > JDBCMailRepositoryTest


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20
21 package org.apache.james.mailrepository;
22
23 import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
24 import org.apache.avalon.cornerstone.services.store.Store;
25 import org.apache.avalon.framework.configuration.ConfigurationException;
26 import org.apache.avalon.framework.configuration.DefaultConfiguration;
27 import org.apache.avalon.framework.service.DefaultServiceManager;
28 import org.apache.avalon.framework.service.ServiceException;
29 import org.apache.james.mailrepository.filepair.File_Persistent_Stream_Repository;
30 import org.apache.james.services.FileSystem;
31 import org.apache.james.services.MailRepository;
32 import org.apache.james.test.mock.avalon.MockLogger;
33 import org.apache.james.test.mock.avalon.MockStore;
34 import org.apache.james.test.mock.james.MockFileSystem;
35 import org.apache.james.test.mock.util.AttrValConfiguration;
36 import org.apache.james.test.util.Util;
37
38 public class JDBCMailRepositoryTest extends AbstractMailRepositoryTest {
39
40     /**
41      * @return
42      * @throws ServiceException
43      * @throws ConfigurationException
44      * @throws Exception
45      */

46     protected MailRepository getMailRepository() throws ServiceException, ConfigurationException, Exception JavaDoc {
47         DefaultServiceManager serviceManager = new DefaultServiceManager();
48         serviceManager.put(FileSystem.ROLE, new MockFileSystem());
49         serviceManager.put(DataSourceSelector.ROLE, Util.getDataSourceSelector());
50         JDBCMailRepository mr = new JDBCMailRepository();
51         
52         // only used for dbfile
53
MockStore mockStore = new MockStore();
54         File_Persistent_Stream_Repository file_Persistent_Stream_Repository = new File_Persistent_Stream_Repository();
55         file_Persistent_Stream_Repository.service(serviceManager);
56         file_Persistent_Stream_Repository.enableLogging(new MockLogger());
57         DefaultConfiguration defaultConfiguration2 = new DefaultConfiguration("conf");
58         defaultConfiguration2.setAttribute("destinationURL", "file://target/var/mr/testrepo");
59         file_Persistent_Stream_Repository.configure(defaultConfiguration2);
60         file_Persistent_Stream_Repository.initialize();
61         mockStore.add("STREAM.mr", file_Persistent_Stream_Repository);
62         serviceManager.put(Store.ROLE,mockStore);
63
64         mr.enableLogging(new MockLogger());
65         DefaultConfiguration defaultConfiguration = new DefaultConfiguration("ReposConf");
66         defaultConfiguration.setAttribute("destinationURL","db://maildb/mr/testrepo");
67         defaultConfiguration.addChild(new AttrValConfiguration("sqlFile","file://conf/sqlResources.xml"));
68         defaultConfiguration.setAttribute("type","MAIL");
69         mr.service(serviceManager);
70         mr.configure(defaultConfiguration);
71         mr.initialize();
72         return mr;
73     }
74     
75     protected String JavaDoc getType() {
76         return "db";
77     }
78
79 }
80
81
Popular Tags