Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.j256.ormlite.db;
  
  import static org.easymock.EasyMock.createMock;
  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.assertTrue;
 
 import java.util.List;
 
 import org.junit.Test;
 
 
 
 	protected void setDatabaseParams() throws SQLException {
 		 = "jdbc:postgresql:ormlitepostgres";
 	}
 
 	protected boolean isDriverClassExpected() {
 		return false;
 	}
 
 	@Test
 	public void testEscapedEntityName() {
 		String word = "word";
 		assertEquals("\"" + word + "\"", TestUtils.appendEscapedEntityName(word));
 	}
 
 	@Test
 	public void testEscapedEntityNameSchema() {
 		String schema = "schema";
 		String table = "table";
 		String word = schema + "." + table;
 		assertEquals("\"" + schema + "\".\"" + table + "\"", TestUtils.appendEscapedEntityName(word));
 	}
 
 	@Test(expected = IllegalStateException.class)
 	public void testBadGeneratedId() throws Exception {
 		if ( == null) {
 			throw new IllegalStateException("Simulate a failure");
 		}
 		Field field = GeneratedId.class.getField("id");
 		DatabaseType mockDb = createMock(DatabaseType.class);
 		replay(mockDb);
 		try {
 			FieldType fieldType = FieldType.createFieldType("foo"fieldGeneratedId.class);
 			verify(mockDb);
 			StringBuilder sb = new StringBuilder();
 			List<StringstatementsBefore = new ArrayList<String>();
 			.appendColumnArg(nullsbfieldTypenullstatementsBeforenullnull);
 		} finally {
 		}
 	}
 
 	@Test
 	public void testDropSequence() throws Exception {
 		if ( == null) {
 			return;
 		}
 		Field field = GeneratedId.class.getField("id");
 		FieldType fieldType = FieldType.createFieldType("foo"fieldGeneratedId.class);
 		List<StringstatementsBefore = new ArrayList<String>();
 		List<StringstatementsAfter = new ArrayList<String>();
 		.dropColumnArg(fieldTypestatementsBeforestatementsAfter);
 		assertEquals(0, statementsBefore.size());
 		assertEquals(1, statementsAfter.size());
 		assertTrue(statementsAfter.get(0).contains("DROP SEQUENCE "));
 	}
 
 	@Test
 	public void testGeneratedIdSequence() throws Exception {
 		if ( == null) {
 			return;
 		}
 		assertEquals(2, tableInfo.getFieldTypes().length);
		List<StringadditionalArgs = new ArrayList<String>();
		List<StringstatementsBefore = new ArrayList<String>();
		List<StringqueriesAfter = new ArrayList<String>();
		.appendColumnArg(nullsbtableInfo.getFieldTypes()[0], additionalArgsstatementsBeforenull,
				queriesAfter);
		.addPrimaryKeySql(tableInfo.getFieldTypes(), additionalArgsstatementsBeforenullqueriesAfter);
		assertTrue(sb.toString().contains(" DEFAULT NEXTVAL('\"" +  + "\"')"));
		assertEquals(1, statementsBefore.size());
		assertTrue(statementsBefore.get(0).contains());
		assertEquals(1, additionalArgs.size());
		assertTrue(additionalArgs.get(0).contains("PRIMARY KEY"));
		assertEquals(0, queriesAfter.size());
	}
	public void testGeneratedIdSequenceAutoName() throws Exception {
		if ( == null) {
			return;
		}
		assertEquals(2, tableInfo.getFieldTypes().length);
		FieldType idField = tableInfo.getFieldTypes()[0];
		List<StringadditionalArgs = new ArrayList<String>();
		List<StringstatementsBefore = new ArrayList<String>();
		List<StringqueriesAfter = new ArrayList<String>();
		.appendColumnArg(nullsbidFieldadditionalArgsstatementsBeforenullqueriesAfter);
		.addPrimaryKeySql(new FieldType[] { idField }, additionalArgsstatementsBeforenullqueriesAfter);
		String seqName =
						idField);
		assertTrue(sb.toString().contains(" DEFAULT NEXTVAL('\"" + seqName + "\"')"));
		assertEquals(1, statementsBefore.size());
		assertTrue(statementsBefore.get(0).contains(seqName));
		assertEquals(1, additionalArgs.size());
		assertTrue(additionalArgs.get(0).contains("PRIMARY KEY"));
		assertEquals(0, queriesAfter.size());
	}
	public void testBoolean() throws Exception {
		if ( == null) {
			return;
		}
		TableInfo<AllTypesIntegertableInfo =
		assertEquals(9, tableInfo.getFieldTypes().length);
		FieldType booleanField = tableInfo.getFieldTypes()[1];
		assertEquals("booleanField"booleanField.getColumnName());
		List<StringadditionalArgs = new ArrayList<String>();
		List<StringstatementsBefore = new ArrayList<String>();
		.appendColumnArg(nullsbbooleanFieldadditionalArgsstatementsBeforenullnull);
		assertTrue(sb.toString().contains("BOOLEAN"));
	}
	public void testByte() throws Exception {
		if ( == null) {
			return;
		}
		TableInfo<AllTypesIntegertableInfo =
		assertEquals(9, tableInfo.getFieldTypes().length);
		FieldType byteField = tableInfo.getFieldTypes()[3];
		assertEquals("byteField"byteField.getColumnName());
		List<StringadditionalArgs = new ArrayList<String>();
		List<StringstatementsBefore = new ArrayList<String>();
		.appendColumnArg(nullsbbyteFieldadditionalArgsstatementsBeforenullnull);
		assertTrue(sb.toString().contains("SMALLINT"));
	}
New to GrepCode? Check out our FAQ X