1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
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 p3j.pppm.readerwriter.database;
17  
18  import james.core.data.DBConnectionData;
19  import james.core.util.misc.Pair;
20  
21  import java.net.URI;
22  import java.net.URISyntaxException;
23  
24  import junit.framework.TestCase;
25  
26  /**
27   * So far only tests {@link PPPMDatabaseReader}.
28   * 
29   * @author Christina Bohk
30   * @author Roland Ewald
31   * 
32   */
33  public class TestDBReaderWriter extends TestCase {
34  
35    /**
36     * Tests how the {@link PPPMDatabaseReader} interprets the delivered
37     * {@link URI}.
38     * 
39     * @throws URISyntaxException
40     *           if test URI has a wrong syntax
41     */
42    public void testURIInterpretation() throws URISyntaxException {
43      String dbUser = "root";
44      String dbPasswd = "pass";
45      Pair<DBConnectionData, Integer> modelReaderInfo = PPPMDatabaseReader
46          .resolveModelDBURI(new URI("db-p3m://" + dbUser + ":" + dbPasswd
47              + "@localhost/pppm_db?12"));
48      assertEquals(12, modelReaderInfo.getSecondValue().intValue());
49      DBConnectionData dbConn = modelReaderInfo.getFirstValue();
50      assertEquals(dbUser, dbConn.getUser());
51      assertEquals(dbPasswd, dbConn.getPassword());
52      assertEquals("jdbc:mysql://localhost/pppm_db", dbConn.getUrl());
53    }
54  }