
test.googlecode.genericdao.BaseTest Maven / Gradle / Ivy
The newest version!
/* Copyright 2013 David Wolverton
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package test.googlecode.genericdao;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import test.googlecode.genericdao.databaseinitializer.PersistableTestDataModel;
import test.googlecode.genericdao.model.Person;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:jUnit-applicationContext.xml" })
public abstract class BaseTest extends PersistableTestDataModel {
public T find(Class type, Serializable id) {
return persistenceHelper.find(type, id);
}
public T getProxy(Class type, Serializable id) {
return persistenceHelper.getProxy(type, id);
}
public void persist(Object entity) {
persistenceHelper.persist(entity);
}
public void flush() {
persistenceHelper.flush();
}
public void clear() {
persistenceHelper.clear();
}
protected boolean dbIgnoresCase;
@Autowired(required = true)
public void setDbIgnoresCase(Boolean dbIgnoresCase) {
this.dbIgnoresCase = dbIgnoresCase;
}
@Before
public void onSetUp() throws Exception {
resetModelObjects();
}
protected void initDB() {
persistModelToDatabase();
}
protected void assertListEqual(Person[] expected, List actual) {
Assert.assertEquals("The list did not have the expected length", expected.length, actual.size());
HashMap unmatched = new HashMap();
for (Person person : expected) {
unmatched.put(person.getId(), "");
}
for (Person person : actual) {
unmatched.remove(person.getId());
}
if (unmatched.size() != 0)
Assert.fail("The list did not match the expected results.");
}
protected void assertListEqual(List> actual, Object... expected) {
Assert.assertEquals("The list did not have the expected length", expected.length, actual.size());
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy