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 java.net.URI;
19  import java.net.URISyntaxException;
20  
21  import junit.framework.TestCase;
22  
23  import org.jamesii.core.data.DBConnectionData;
24  import org.jamesii.core.util.misc.Pair;
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 Exception {
43  
44      String dbUser = "root";
45      String dbPasswd = "pass";
46      String dbURL = "jdbc:mysql://localhost/pppm_db";
47      String dbDrv = "some.Driver";
48      int projectionID = 12;
49  
50      Pair<DBConnectionData, Integer> modelReaderInfo = PPPModelDatabaseReaderFactory
51          .retrieveReaderParams((PPPModelDatabaseReaderFactory
52              .createReaderParams(new DBConnectionData(dbURL, dbUser, dbPasswd,
53                  dbDrv), projectionID)));
54  
55      DBConnectionData dbConn = modelReaderInfo.getFirstValue();
56      assertEquals(dbUser, dbConn.getUser());
57      assertEquals(dbPasswd, dbConn.getPassword());
58      assertEquals(dbURL, dbConn.getURL());
59      assertEquals(dbDrv, dbConn.getDriver());
60  
61      assertEquals(projectionID, modelReaderInfo.getSecondValue().intValue());
62    }
63  }