PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Having problems creating an H2 database for testing-VBForums
Results 1 to 1 of 1

Thread: Having problems creating an H2 database for testing

  1. #1

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,453

    Having problems creating an H2 database for testing

    Trying to add some groovy test cases to a project I'm working on. It's a Spring Boot Java project. I'm at the point where I need a database to do some interactions. We're using the @TestPropertySource to set the db properties for the spring.liquibase.change-log ... which when encountered should run the noted script that builds the schema within the database. For some reason it isn't. Later, in the test, when I go to load the dataset of sample data needed, it throws an exception that it can't insert the data because the table doesn't exist... I'm able to persist the database to file and inspect it... sure enough, there's no tables in it, other than the default ones that get created in a blank db.

    I've been banging my head on this for two days now and it's ticking me off. I'm comparing configurations and code and pom files between my project and two others that do work... and as far as I can tell, it's all right.

    Here's the base class: (names changed)
    java Code:
    1. package g.v.myapp.myclass.junk
    2.  
    3. import org.springframework.boot.autoconfigure.ImportAutoConfiguration
    4. import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
    5. import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
    6. import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
    7. import org.springframework.test.context.ContextConfiguration
    8. import org.springframework.test.context.TestPropertySource
    9. import org.unitils.database.annotations.Transactional
    10. import org.unitils.database.util.TransactionMode
    11. import spock.lang.Specification
    12.  
    13. @ContextConfiguration(classes = [MyClassTestConfiguration])
    14. @DataJpaTest
    15. @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
    16. @ImportAutoConfiguration([LiquibaseAutoConfiguration])
    17. @TestPropertySource(properties = [
    18.         'debug=true',
    19.         'spring.liquibase.change-log=classpath:liquibase/schema.xml',
    20.         'spring.liquibase.contexts=!partitioned',
    21.         'spring.datasource.url=jdbc:h2:file:/Users/me/dev/github/c/myapp/mymodule/src/test/data:sampletest;DB_CLOSE_DELAY=-1;MODE=PostgreSQL;DB_CLOSE_ON_EXIT=FALSE'])
    22. @Transactional(TransactionMode.DISABLED)
    23. class MyClassTestBase extends Specification {
    24.  
    25. }

    And here's the implementing test class:
    java Code:
    1. package g.v.myapp.myclass.junk
    2.  
    3. import org.junit.Test
    4. import org.springframework.beans.factory.annotation.Autowired
    5. import org.springframework.boot.CommandLineRunner
    6. import org.unitils.dbunit.annotation.DataSet
    7. import org.unitils.dbunit.datasetloadstrategy.impl.CleanInsertLoadStrategy
    8. import spock.lang.Unroll
    9. import spock.unitils.UnitilsSupport
    10.  
    11. @UnitilsSupport
    12. @DataSet(
    13.         value = ['dbunit/..../repository/SampleData.xml'],
    14.         loadStrategy = CleanInsertLoadStrategy
    15. )
    16. class MyClassTestCaseTest extends MyClassTestBase {
    When it loads the dataset (SampleData.xml) that's when I get the errors... For what ever reason, it looks like it isn't using the properties set in the base class to create the schema structure that I'm expecting.

    I feel like I've missed something stupid simple & obvious, but I can't figure it out.
    Last edited by techgnome; Jul 25th, 2019 at 11:37 AM.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width