| 1 |
|
package org.itracker; |
| 2 |
|
|
| 3 |
|
import com.sun.tools.internal.ws.processor.model.java.JavaArrayType; |
| 4 |
|
import org.apache.log4j.Logger; |
| 5 |
|
import org.dbunit.database.DatabaseConfig; |
| 6 |
|
import org.dbunit.database.DatabaseConnection; |
| 7 |
|
import org.dbunit.dataset.CompositeDataSet; |
| 8 |
|
import org.dbunit.dataset.IDataSet; |
| 9 |
|
import org.dbunit.dataset.xml.XmlDataSet; |
| 10 |
|
import org.dbunit.ext.hsqldb.HsqldbDataTypeFactory; |
| 11 |
|
import org.dbunit.operation.DatabaseOperation; |
| 12 |
|
import org.hibernate.Session; |
| 13 |
|
import org.hibernate.SessionFactory; |
| 14 |
|
import org.itracker.services.ConfigurationService; |
| 15 |
|
import org.itracker.services.util.SystemConfigurationUtilities; |
| 16 |
|
import org.junit.After; |
| 17 |
|
import org.junit.Before; |
| 18 |
|
import org.junit.internal.runners.JUnit4ClassRunner; |
| 19 |
|
import org.junit.runner.RunWith; |
| 20 |
|
import org.springframework.mail.MailSender; |
| 21 |
|
import org.springframework.mail.javamail.JavaMailSender; |
| 22 |
|
import org.springframework.mail.javamail.JavaMailSenderImpl; |
| 23 |
|
import org.springframework.orm.hibernate3.LocalSessionFactoryBean; |
| 24 |
|
import org.springframework.orm.hibernate3.SessionHolder; |
| 25 |
|
import org.springframework.test.AbstractDependencyInjectionSpringContextTests; |
| 26 |
|
import org.springframework.transaction.support.TransactionSynchronizationManager; |
| 27 |
|
|
| 28 |
|
import javax.naming.InitialContext; |
| 29 |
|
import javax.sql.DataSource; |
| 30 |
|
import java.sql.SQLException; |
| 31 |
|
import java.util.Properties; |
| 32 |
|
|
| 33 |
|
@RunWith(JUnit4ClassRunner.class) |
|
|
|
| 19.5% |
Uncovered Elements: 62 (77) |
Complexity: 22 |
Complexity Density: 0.42 |
|
| 34 |
|
public abstract class AbstractDependencyInjectionTest extends |
| 35 |
|
AbstractDependencyInjectionSpringContextTests { |
| 36 |
|
|
| 37 |
|
private static final Logger log = Logger |
| 38 |
|
.getLogger(AbstractDependencyInjectionSpringContextTests.class); |
| 39 |
|
private DataSource dataSource; |
| 40 |
|
private LocalSessionFactoryBean sessionFactoryBean; |
| 41 |
|
public ClassLoader classLoader; |
| 42 |
|
public IDataSet dataSet; |
| 43 |
|
private SessionFactory sessionFactory; |
| 44 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 45 |
331
|
protected AbstractDependencyInjectionTest() {... |
| 46 |
331
|
classLoader = getClass().getClassLoader(); |
| 47 |
|
} |
| 48 |
|
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 6 |
Complexity Density: 0.3 |
|
| 49 |
0
|
@Override... |
| 50 |
|
public void onSetUp() throws Exception { |
| 51 |
0
|
super.onSetUp(); |
| 52 |
0
|
sessionFactory = (SessionFactory) applicationContext |
| 53 |
|
.getBean("sessionFactory"); |
| 54 |
0
|
Session session = sessionFactory.openSession(); |
| 55 |
0
|
TransactionSynchronizationManager.bindResource(sessionFactory, |
| 56 |
|
new SessionHolder(session)); |
| 57 |
|
|
| 58 |
0
|
dataSet = getDataSet(); |
| 59 |
0
|
DatabaseConnection dbConnection = null; |
| 60 |
0
|
try { |
| 61 |
|
|
| 62 |
0
|
resetConfiguration(); |
| 63 |
|
|
| 64 |
0
|
dbConnection = new DatabaseConnection(getDataSource().getConnection()); |
| 65 |
0
|
dbConnection.getConfig().setProperty( |
| 66 |
|
DatabaseConfig.PROPERTY_DATATYPE_FACTORY, |
| 67 |
|
new HsqldbDataTypeFactory()); |
| 68 |
|
|
| 69 |
0
|
if (dataSet != null) { |
| 70 |
0
|
DatabaseOperation.CLEAN_INSERT.execute(dbConnection, dataSet); |
| 71 |
|
} |
| 72 |
|
|
| 73 |
0
|
if (!dbConnection.getConnection().getAutoCommit()) { |
| 74 |
0
|
dbConnection.getConnection().commit(); |
| 75 |
|
} |
| 76 |
|
} catch (Exception e) { |
| 77 |
0
|
log.error("onSetUp: failed to set up datasets", e); |
| 78 |
0
|
throw e; |
| 79 |
|
} finally { |
| 80 |
0
|
if (null != dbConnection) { |
| 81 |
0
|
try { |
| 82 |
0
|
dbConnection.close(); |
| 83 |
|
} catch (SQLException e) { |
| 84 |
0
|
log.warn("onSetUp: failed to close connection", e); |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
|
|
|
|
| 27.3% |
Uncovered Elements: 16 (22) |
Complexity: 6 |
Complexity Density: 0.38 |
|
| 90 |
329
|
@Override... |
| 91 |
|
public void onTearDown() throws Exception { |
| 92 |
329
|
DatabaseConnection dbConnection = null; |
| 93 |
329
|
try { |
| 94 |
329
|
dbConnection = new DatabaseConnection(getDataSource() |
| 95 |
|
.getConnection()); |
| 96 |
|
|
| 97 |
0
|
if (dataSet != null) { |
| 98 |
0
|
DatabaseOperation.DELETE_ALL.execute(dbConnection, dataSet); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
0
|
if (!dbConnection.getConnection().getAutoCommit()) { |
| 102 |
0
|
dbConnection.getConnection().commit(); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
} catch (Exception e) { |
| 106 |
329
|
log.error("onTearDown: failed to tear down datasets", e); |
| 107 |
329
|
throw e; |
| 108 |
|
} finally { |
| 109 |
329
|
TransactionSynchronizationManager.unbindResource(sessionFactory); |
| 110 |
0
|
sessionFactoryBean.destroy(); |
| 111 |
|
|
| 112 |
|
|
| 113 |
0
|
if (null != dbConnection) { |
| 114 |
0
|
try { |
| 115 |
0
|
dbConnection.close(); |
| 116 |
|
} catch (SQLException e) { |
| 117 |
0
|
log.warn("onTearDown: failed to close connection", e); |
| 118 |
|
} |
| 119 |
|
} |
| 120 |
0
|
super.onTearDown(); |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 124 |
0
|
final protected void resetConfiguration() {... |
| 125 |
0
|
ConfigurationService configurationService = (ConfigurationService) applicationContext |
| 126 |
|
.getBean("configurationService"); |
| 127 |
|
|
| 128 |
0
|
SystemConfigurationUtilities.initializeAllLanguages(configurationService, true); |
| 129 |
0
|
configurationService.initializeConfiguration(); |
| 130 |
|
|
| 131 |
0
|
configurationService.resetConfigurationCache(); |
| 132 |
|
} |
| 133 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 134 |
0
|
private IDataSet getDataSet() throws Exception {... |
| 135 |
0
|
final String[] aDataSet = getDataSetFiles(); |
| 136 |
0
|
final IDataSet[] dataSets = new IDataSet[aDataSet.length]; |
| 137 |
|
|
| 138 |
0
|
for (int i = 0; i < aDataSet.length; i++) { |
| 139 |
0
|
dataSets[i] = new XmlDataSet(classLoader |
| 140 |
|
.getResourceAsStream(aDataSet[i])); |
| 141 |
|
} |
| 142 |
0
|
return new CompositeDataSet(dataSets); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
@return |
| 150 |
|
|
| 151 |
|
protected abstract String[] getDataSetFiles(); |
| 152 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 153 |
0
|
public LocalSessionFactoryBean getSessionFactoryBean() {... |
| 154 |
0
|
return sessionFactoryBean; |
| 155 |
|
} |
| 156 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 157 |
0
|
public void setSessionFactoryBean(LocalSessionFactoryBean sessionFactoryBean) {... |
| 158 |
0
|
this.sessionFactoryBean = sessionFactoryBean; |
| 159 |
|
} |
| 160 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 161 |
329
|
public DataSource getDataSource() {... |
| 162 |
329
|
return dataSource; |
| 163 |
|
} |
| 164 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 165 |
0
|
public void setDataSource(DataSource dataSource) {... |
| 166 |
0
|
this.dataSource = dataSource; |
| 167 |
|
} |
| 168 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 169 |
329
|
@Before... |
| 170 |
|
public final void callSetup() throws Exception { |
| 171 |
329
|
super.setUp(); |
| 172 |
|
} |
| 173 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 174 |
329
|
@After... |
| 175 |
|
public final void callTeardown() throws Exception { |
| 176 |
329
|
super.tearDown(); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
} |