Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.j256.ormlite.jdbc;
  
  import static org.easymock.EasyMock.createMock;
  import static org.easymock.EasyMock.eq;
  import static org.easymock.EasyMock.expect;
  import static org.easymock.EasyMock.isA;
  import static org.easymock.EasyMock.replay;
  import static org.easymock.EasyMock.verify;
  import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 
 import org.junit.Test;
 
 
 public class JdbcConnectionSourceTest extends BaseCoreTest {
 
 	@Test
 	public void testSimpleDataSource() {
 		String url = "foo:bar:baz";
 		sds.setUrl(url);
 		assertEquals(urlsds.getUrl());
 	}
 
 	@Test
 	public void testSimpleDataSourceString() throws Exception {
 		String url = "jdbc:h2:mem:baz";
 		assertEquals(urlsds.getUrl());
 	}
 
 	@Test
 		String username = "user";
 		String password = "_secret";
 		String url = "jdbc:h2:mem:ormlite-up;USER=" + username + ";PASSWORD=" + password;
 		JdbcConnectionSource sds = new JdbcConnectionSource(urlusernamepassword);
 	}
 
 	@Test
 	public void testGetConnection() throws Exception {
 		Connection conn = createMock(Connection.class);
 		Driver driver = createMock(Driver.class);
 		String url = "jdbc:bar:mem:baz";
 		expect(driver.acceptsURL(url)).andReturn(true);
 		expect(driver.connect(isA(String.class), isA(Properties.class))).andReturn(conn);
 		replay(driver);
 		DriverManager.registerDriver(driver);
 		try {
 			verify(driver);
 		} finally {
 			DriverManager.deregisterDriver(driver);
 		}
 	}
 
 	@Test
 	public void testGetConnectionUserPassSetters() throws Exception {
 		String username = "user";
 		String password = "_secret";
 		String url = "jdbc:h2:mem:ormlite-up;USER=" + username + ";PASSWORD=" + password;
 		sds.setUsername(username);
 		sds.setPassword(password);
 	}
 
 	@Test(expected = SQLException.class)
 	public void testGetConnectionNull() throws Exception {
 		Driver driver = createMock(Driver.class);
 		Properties props = new Properties();
 		String url = "jdbc:bar:baz";
 		expect(driver.acceptsURL(url)).andReturn(true);
 		expect(driver.connect(eq(url), eq(props))).andReturn(null);
 		replay(driver);
 		DriverManager.registerDriver(driver);
 		try {
 		} finally {
 			DriverManager.deregisterDriver(driver);
 		}
 	}
 
	public void testClose() throws Exception {
		conn.close();
		Driver driver = createMock(Driver.class);
		String url = "jdbc:bar:baz";
		expect(driver.acceptsURL(url)).andReturn(true);
		expect(driver.connect(isA(String.class), isA(Properties.class))).andReturn(conn);
		replay(driverconn);
		DriverManager.registerDriver(driver);
		try {
			sds.close();
			verify(driverconn);
finally {
			DriverManager.deregisterDriver(driver);
		}
	}
	@Test(expected = SQLException.class)
	public void testInitNoUrl() throws Exception {
	}
	@Test(expected = SQLException.class)
	public void testConnectionClosed() throws Exception {
		expect(conn.isClosed()).andReturn(true);
		Driver driver = createMock(Driver.class);
		String url = "jdbc:bar:baz";
		expect(driver.acceptsURL(url)).andReturn(true);
		expect(driver.connect(isA(String.class), isA(Properties.class))).andReturn(conn);
		replay(driverconn);
		DriverManager.registerDriver(driver);
		try {
			fail("Should not get here");
finally {
			DriverManager.deregisterDriver(driver);
		}
	}
	public void testSpringWiring() throws Exception {
		String url = "jdbc:h2:mem:baz";
		sds.setUrl(url);
	}
	@Test(expected = SQLException.class)
	public void testCloseBeforeInitialize() throws Exception {
		sds.close();
	}
	@Test(expected = SQLException.class)
	}
	@Test(expected = SQLException.class)
	}
	@Test(expected = SQLException.class)
	}
	@Test(expected = IllegalStateException.class)
	}
	public void testDoubleInit() throws Exception {
		JdbcConnectionSource sds = new JdbcConnectionSource("jdbc:h2:mem:baz");
	}
	public void testSaveAndClear() throws Exception {
		JdbcConnectionSource sds = new JdbcConnectionSource("jdbc:h2:mem:baz");
		assertSame(conn1conn2);
	}
	public void testSetDatabaseType() throws Exception {
		sds.setUrl("jdbc:h2:mem:baz");
	}
	public void testIsOpen() throws Exception {
		JdbcConnectionSource sds = new JdbcConnectionSource("jdbc:h2:mem:baz");
		// no get connection yet
		sds.close();
	}
New to GrepCode? Check out our FAQ X