I have some test cases that I use in a presentation I am giving that
were using liquibase 1.9.5.  I decided that I would try to update them
to the 2.0-rc6 code so that when I next give the presentation (in
January 2011) I will be using the most up-to-date version of liquibase.

I changed the Liquibase construction to use the ResourceAccessor
abstraction instead of the FileOpener abstractions, and made sure that
I'm using a JdbcConnection to talk to a mysql database running on my
workstation.

I am using Spring's Junit 4 integration to run a junit test that creates
some table structure in a @Before method using the liquibase.Liquibase
object, and then uses that same object in an @After method to rollback
the table structure created in the @Before.

When I run my test, the test does what is supposed to, and all of the
assertions pass.  Then in the @After method when the Liquibase object
attempts to rollback the changelist, we get a null pointer and blow up.
The NullPointer occurs in ChangeSet, line 308 where it is checking the
execType of the ranChangeSet to see if it has been EXECUTED or RERAN.
Unfortunately at this time, the execType is null, so the rollback blows
up.

I have attached my dao class, unit test class, as well as my spring
configuration file, and my liquibase change set for debugging purposes.
Here is the relevant stack trace from my test run.

Oct 29, 2010 12:11:46 PM liquibase.logging.jvm.JavaUtilLogger info
INFO: Successfully released change log lock
Oct 29, 2010 12:11:46 PM
org.springframework.test.context.transaction.TransactionalTestExecutionL
istener endTransaction
INFO: Rolled back transaction after test execution for test context
[[testcont...@19ea173 testClass =
PhoneBookDAOFreshStandAloneDBIntegrationTest, locations =
array<String>['classpath:/DatabaseTesting/PhoneBookDAOFreshStandAloneDBI
ntegrationTest-context.xml'], testInstance =
databasetesting.phonebookdaofreshstandalonedbintegrationt...@179a49f,
testMethod = test_get_h...@phonebookdaofreshstandalonedbintegrationtest,
testException = liquibase.exception.RollbackFailedException:
java.lang.NullPointerException]]

liquibase.exception.RollbackFailedException:
java.lang.NullPointerException
        at liquibase.changelog.ChangeSet.rolback(ChangeSet.java:340)
        at
liquibase.changelog.visitor.RollbackVisitor.visit(RollbackVisitor.java:2
3)
        at
liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58)
        at liquibase.Liquibase.rollback(Liquibase.java:249)
        at
DatabaseTesting.PhoneBookDAOFreshStandAloneDBIntegrationTest.drop_tables
(PhoneBookDAOFreshStandAloneDBIntegrationTest.java:44)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
        at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMet
hod.java:44)
        at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallab
le.java:15)
        at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMetho
d.java:41)
        at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
37)
        at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCal
lbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
        at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate
(SpringRepeat.java:72)
        at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild
(SpringJUnit4ClassRunner.java:240)
        at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner
.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCal
lbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
        at
org.springframework.test.context.junit4.statements.RunAfterTestClassCall
backs.evaluate(RunAfterTestClassCallbacks.java:70)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
        at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(Spri
ngJUnit4ClassRunner.java:180)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
        at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaT
estRunner.java:94)
        at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUni
tStarter.java:192)
        at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
        at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
Caused by: java.lang.NullPointerException
        at liquibase.changelog.ChangeSet.rolback(ChangeSet.java:310)
        ... 34 more



Also, on a very trivial sidenote, liquibase.changelog.ChangeSet.rolback
is misspelled.  It should have 2 Ls not one.


JB

"The best way to predict the future is to invent it."
- Alan Kay

Attachment: phonebook-initial-load.sql
Description: phonebook-initial-load.sql

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd";>
    <changeSet id="initialTableBuild" author="jb" failOnError="true">
        <comment>building the phonebook table.</comment>
        <createTable tableName="phone_book">
            <column autoIncrement="true" name="phone_num_id" type="INT">
                <constraints nullable="false" primaryKey="true"/>
            </column>
            <column name="last_name" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="first_name" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="phone_number" type="varchar(50)">
                <constraints nullable="false"/>
            </column>
            <column name="phone_num_type" type="INT" defaultValue="1">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <rollback>
            <dropTable tableName="phone_book"/>
        </rollback>
    </changeSet>
</databaseChangeLog>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans";
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd";>
    
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/database_testing_fresh"/>
        <property name="user" value="root"/>
        <property name="password" value="password"/>
    </bean>

    <bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean name="testJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean name="jdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
        <constructor-arg ref="testJdbcTemplate"/>
    </bean>

    <bean name="testDao" class="DatabaseTesting.PhoneBookDAO">
        <property name="template" ref="testJdbcTemplate"/>
    </bean>

    <bean name="testDataResource" class="org.springframework.core.io.ClassPathResource">
        <constructor-arg index="0" value="phonebook-initial-load.sql"/>
    </bean>

    <bean name="liquibase"  class="liquibase.Liquibase">
        <constructor-arg index="0" value="phonebook-create-changelog.xml"/>
        <constructor-arg index="1">
            <bean class="liquibase.resource.ClassLoaderResourceAccessor"/>
        </constructor-arg>
        <constructor-arg index="2">
            <bean class="liquibase.database.jvm.JdbcConnection">
                <constructor-arg index="0">
                    <bean id="dataSource.connection"
                    class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
                </constructor-arg>
            </bean>
        </constructor-arg>
    </bean>    
</beans>

Attachment: PhoneBookDAOFreshStandAloneDBIntegrationTest.java
Description: PhoneBookDAOFreshStandAloneDBIntegrationTest.java

Attachment: PhoneBookDAO.java
Description: PhoneBookDAO.java

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Liquibase-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/liquibase-user

Reply via email to