1 24 25 package org.objectweb.cjdbc.scenario.raidb1.driver; 26 27 import java.sql.Connection ; 28 import java.sql.ResultSet ; 29 import java.sql.SQLException ; 30 import java.sql.Statement ; 31 32 import org.objectweb.cjdbc.scenario.templates.SimpleRaidb1Template; 33 34 40 public class Raidb1ChangeCatalogScenario extends SimpleRaidb1Template 41 { 42 43 48 public void testChangeCatalog() throws Exception 49 { 50 Connection con = getCJDBCConnection("25322", "myDB1"); 51 con.setCatalog("myDB1"); 52 Statement statement = con.createStatement(); 53 ResultSet rs = statement.executeQuery("Select * from document"); 54 assertNotNull("ResultSet is null", rs); 55 statement.close(); 56 int count1 = controller.getVirtualDatabase("myDB1").getRequestManager() 57 .getScheduler().getNumberRead(); 58 con.setCatalog("myDB2"); 59 statement = con.createStatement(); 60 rs = statement.executeQuery("Select * from document"); 61 assertNotNull("ResultSet is null", rs); 62 statement.close(); 63 int count2 = controller.getVirtualDatabase("myDB2").getRequestManager() 64 .getScheduler().getNumberRead(); 65 assertTrue("Expected only one request on catalog myDB1,was:" + count1, 66 count1 == 1); 67 assertTrue("Expected only one request on catalog myDB2,was:" + count2, 68 count2 == 1); 69 assertTrue("Expected same number of requests on both catalogs", 70 count2 == count1); 71 } 72 73 78 public void testChangeCatalogWithWrongUser() throws Exception 79 { 80 Exception exception = null; 81 Connection con = null; 82 try 83 { 84 con = getCJDBCConnection("25322", "myDB1", "user2", ""); 85 } 86 catch (Exception e) 87 { 88 exception = e; 89 e.printStackTrace(); 90 } 91 assertNull("The user should be properly authenticated.", exception); 92 try 93 { 94 con.setCatalog("myDB2"); 95 } 96 catch (SQLException sql) 97 { 98 exception = sql; 100 } 101 assertNotNull("Changing of catalog should have thrown an exception", 102 exception); 103 } 104 105 108 protected void setUp() 109 { 110 super.setUp(); 111 try 112 { 113 cm.loadVirtualDatabases(controller, "myDB1", 114 "hsqldb-raidb1-with2virtualdatabases.xml"); 115 cm.loadVirtualDatabases(controller, "myDB2", 116 "hsqldb-raidb1-with2virtualdatabases.xml"); 117 mainVdb = controller.getVirtualDatabase("myDB1"); 118 mainVdb.enableAllBackends(); 119 mainVdb = controller.getVirtualDatabase("myDB2"); 120 mainVdb.enableAllBackends(); 121 } 122 catch(Exception e) 123 { 124 e.printStackTrace(); 125 } 126 } 127 } 128 | Popular Tags |