001 package com.khubla.pragmatach.dbtestsuite;
002
003 import java.util.Set;
004
005 import org.testng.Assert;
006 import org.testng.annotations.BeforeClass;
007 import org.testng.annotations.Test;
008
009 import com.khubla.pragmatach.dbtestsuite.pojo.ExamplePOJO;
010 import com.khubla.pragmatach.framework.api.Configuration;
011 import com.khubla.pragmatach.framework.application.Application;
012 import com.khubla.pragmatach.framework.dao.DAO;
013 import com.khubla.pragmatach.framework.scanner.AnnotationScanner;
014
015 /**
016 * @author tome
017 */
018 public abstract class AbstractPersistenceTest {
019 /**
020 * get the configs
021 */
022 public abstract Set<Configuration> getConfigurations();
023
024 /**
025 * get the DAO implementation
026 */
027 public abstract DAO<ExamplePOJO, Long> getDAO();
028
029 /**
030 * for the class
031 */
032 @BeforeClass
033 public void setupClass() {
034 /*
035 * run the scanner
036 */
037 try {
038 AnnotationScanner.scan(null);
039 } catch (final Exception e) {
040 e.printStackTrace();
041 Assert.fail();
042 }
043 }
044
045 @Test
046 public void testAllDatabaseConfigurations() {
047 try {
048 /*
049 * config
050 */
051 final Set<Configuration> configurations = getConfigurations();
052 if ((null != configurations) && (configurations.size() > 0)) {
053 /*
054 * set an initial config
055 */
056 Application.setConfiguration(configurations.iterator().next());
057 /*
058 * the dao
059 */
060 final DAO<ExamplePOJO, Long> dao = getDAO();
061 /*
062 * walk the config
063 */
064 for (final Configuration configuration : configurations) {
065 /*
066 * dump the config
067 */
068 for (String key : configuration.getAll().keySet()) {
069 System.out.println(key + " : " + configuration.getParameter(key));
070 }
071 /*
072 * set the application config
073 */
074 Application.setConfiguration(configuration);
075 /*
076 * force a session factory reload
077 */
078 dao.reloadConfig();
079 /*
080 * run test
081 */
082 BasicTests.testBasicFunctionality(dao);
083 }
084 }
085 } catch (final Exception e) {
086 e.printStackTrace();
087 Assert.fail();
088 }
089 }
090 }