KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > store > jdbc > JdbcStoreTest


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

17 package org.apache.servicemix.store.jdbc;
18
19 import java.sql.Connection JavaDoc;
20
21 import javax.sql.DataSource JavaDoc;
22
23 import junit.framework.TestCase;
24
25 import org.apache.servicemix.store.Store;
26 import org.apache.servicemix.store.StoreFactory;
27 import org.hsqldb.jdbc.jdbcDataSource;
28
29 public class JdbcStoreTest extends TestCase {
30
31     private DataSource JavaDoc dataSource;
32     private Connection JavaDoc connection;
33     private StoreFactory factory;
34
35     protected void setUp() throws Exception JavaDoc {
36         jdbcDataSource ds = new jdbcDataSource();
37         ds.setDatabase("jdbc:hsqldb:mem:aname");
38         ds.setUser("sa");
39         dataSource = ds;
40         connection = dataSource.getConnection();
41         JdbcStoreFactory f = new JdbcStoreFactory();
42         f.setDataSource(dataSource);
43         factory = f;
44     }
45     
46     protected void tearDown() throws Exception JavaDoc {
47         if (connection != null) {
48             connection.close();
49         }
50     }
51
52     public void testStoreLoad() throws Exception JavaDoc {
53         Store store = factory.open("store");
54         String JavaDoc id = store.store(new Integer JavaDoc(10));
55         Integer JavaDoc i = (Integer JavaDoc) store.load(id);
56         assertEquals(10, i.intValue());
57         assertNull(store.load("a"));
58     }
59 }
60
Popular Tags