Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.j256.ormlite.spring;
  
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.fail;
  
  import java.util.List;
  
 import org.junit.Test;
 
 
 public class TableCreatorTest extends BaseJdbcTest {
 
 	@Test
 	public void testInitialize() throws Exception {
 		Dao<FooObjectfooDao = createDao(Foo.classfalse);
 		try {
 			fooDao.create(new Foo());
 			fail("Should have thrown an exception");
 		} catch (SQLException e) {
 			// expected
 		}
 
 		TableCreator tableCreator = new TableCreator();
 
 		List<Dao<?, ?>> daoList = new ArrayList<Dao<?, ?>>();
 		daoList.add(fooDao);
 		tableCreator.setConfiguredDaos(daoList);
 		try {
 			tableCreator.initialize();
 		} finally {
 		}
 
 		assertEquals(1, fooDao.create(new Foo()));
 		// shouldn't do anything
 		tableCreator.destroy();
 		assertEquals(1, fooDao.create(new Foo()));
 
 		try {
 			tableCreator.destroy();
 			fooDao.create(new Foo());
 			fail("Should have thrown an exception");
 		} catch (SQLException e) {
 			// expected
 		} finally {
 		}
 	}
 
 	@Test
 	public void testAutoCreateNotSet() throws Exception {
 		TableCreator tableCreator = new TableCreator();
 		tableCreator.initialize();
 	}
 
 	@Test(expected = SQLException.class)
 	public void testNoConfiguredDaos() throws Exception {
 		TableCreator tableCreator = new TableCreator();
 
 		try {
 			tableCreator.initialize();
 			fail("should not get here");
 		} finally {
 		}
 	}
 
 	@Test
 	public void testNonSpring() throws Exception {
 		Dao<FooObjectfooDao = createDao(Foo.classfalse);
 		List<Dao<?, ?>> daoList = new ArrayList<Dao<?, ?>>();
 		daoList.add(fooDao);
 		TableCreator tableCreator = new TableCreator(daoList);
 		try {
 			tableCreator.maybeCreateTables();
 			tableCreator.maybeDropTables();
 		} finally {
 		}
 	}
 
 	@Test
 	public void testCreateAlreadyExists() throws Exception {
 		Dao<FooObjectfooDao = createDao(Foo.classtrue);
 		List<Dao<?, ?>> daoList = new ArrayList<Dao<?, ?>>();
		daoList.add(fooDao);
		TableCreator tableCreator = new TableCreator(daoList);
		try {
			tableCreator.maybeCreateTables();
finally {
		}
	}
	public void testDestroyDoesntExist() throws Exception {
		Dao<FooObjectfooDao = createDao(Foo.classfalse);
		List<Dao<?, ?>> daoList = new ArrayList<Dao<?, ?>>();
		daoList.add(fooDao);
		TableCreator tableCreator = new TableCreator(daoList);
		try {
			tableCreator.maybeCreateTables();
			TableUtils.dropTable(Foo.classtrue);
			tableCreator.maybeDropTables();
finally {
		}
	}
	protected static class Foo {
		@DatabaseField(generatedId = true)
		int id;
	}
New to GrepCode? Check out our FAQ X