Fornax-Platform
Forum

Configuration/running Unit Tests

View: New views
6 Messages — Rating Filter:   Alert me  

Configuration/running Unit Tests

by deepshar027 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey Guys,

I have been working diligently to run a unit test after code generation from sculptor(version 1.6).Havent been there yet.

few queries.

1) I see there is difference in config files generated for main and test with regards to EntityManagerFactory.xml specifically.
for e.g Test file has a datasource specified while main file doesnt.
Also following bean is specified in test EntitymanagerFactory.xml but not in main.

<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="defaultDataSource" ref="hsqldbDataSource"/>  
    <property name="persistenceXmlLocations">
      <list>
        <value>classpath:META-INF/persistence-test.xml</value>
      </list>
    </property>
  </bean>

I want to have my main EntitymanagerFactory.xml file have same stuff its there in test file.Not sure why there is discrepency.

2) The tests file uses hsqldb by default.Is there a way I can override that to use oracle for tests as well?

3) When I run my tests I get an error
   14:20:29,984  INFO UserServiceTest:162 - Custom transaction definition [PROPAGAT
   ION_REQUIRED,ISOLATION_DEFAULT] for test method [testCreateAccount].
   14:20:29,984  INFO UserServiceTest:175 - ApplicationContext has not been configu
   red for test [com.bookonz.account.serviceapi.UserServiceTest]: dependency inject
   ion will NOT be performed.


I think this is becoz I need to define the test bean(UserServiceTest) in applicationContext.xml and configure transaction params.
Do you guys have any working example of this?

I really want to get past configuring spring/hibernate/jpa stuff and be able to run a few tests.

Thanks,
Deepak

Re: Configuration/running Unit Tests

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

By default we use hsqldb inmemory database with dbunit for unit testing.

To use same configuration for test as for production you can add the following annotation to your unit test class (which is extending AbstractDbUnitJpaTests)

@ContextConfiguration(locations={"classpath:applicationContext.xml"}, inheritLocations=false)

I doubt that using real oracle for junit test is a good approach, but maybe a few integration tests using a real database is reasonable.

All 3 samples (library, DDDSample, and helloworld) have junit test examples, using the default approach with hsqldb.

/Patrik

PS. I will soon write something about how to use Mockito together with Spring/Sculptor.

deepshar027 wrote:
Hey Guys,

I have been working diligently to run a unit test after code generation from sculptor(version 1.6).Havent been there yet.

few queries.

1) I see there is difference in config files generated for main and test with regards to EntityManagerFactory.xml specifically.
for e.g Test file has a datasource specified while main file doesnt.
Also following bean is specified in test EntitymanagerFactory.xml but not in main.

<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="defaultDataSource" ref="hsqldbDataSource"/>  
    <property name="persistenceXmlLocations">
      <list>
        <value>classpath:META-INF/persistence-test.xml</value>
      </list>
    </property>
  </bean>

I want to have my main EntitymanagerFactory.xml file have same stuff its there in test file.Not sure why there is discrepency.

2) The tests file uses hsqldb by default.Is there a way I can override that to use oracle for tests as well?

3) When I run my tests I get an error
   14:20:29,984  INFO UserServiceTest:162 - Custom transaction definition [PROPAGAT
   ION_REQUIRED,ISOLATION_DEFAULT] for test method [testCreateAccount].
   14:20:29,984  INFO UserServiceTest:175 - ApplicationContext has not been configu
   red for test [com.bookonz.account.serviceapi.UserServiceTest]: dependency inject
   ion will NOT be performed.


I think this is becoz I need to define the test bean(UserServiceTest) in applicationContext.xml and configure transaction params.
Do you guys have any working example of this?

I really want to get past configuring spring/hibernate/jpa stuff and be able to run a few tests.

Thanks,
Deepak

Re: Configuration/running Unit Tests

by deepshar027 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Patrik,
I dont think any of the examples DDDSample etc have been migrated to sculptor version 1.6.
I am looking for a JPA sample running successfully with all tests.

Do you have any plans for that?

Thanks,
Deepak.


By default we use hsqldb inmemory database with dbunit for unit testing.

To use same configuration for test as for production you can add the following annotation to your unit test class (which is extending AbstractDbUnitJpaTests)

@ContextConfiguration(locations={"classpath:applicationContext.xml"}, inheritLocations=false)

I doubt that using real oracle for junit test is a good approach, but maybe a few integration tests using a real database is reasonable.

All 3 samples (library, DDDSample, and helloworld) have junit test examples, using the default approach with hsqldb.

/Patrik

PS. I will soon write something about how to use Mockito together with Spring/Sculptor.

deepshar027 wrote:
Hey Guys,

I have been working diligently to run a unit test after code generation from sculptor(version 1.6).Havent been there yet.

few queries.

1) I see there is difference in config files generated for main and test with regards to EntityManagerFactory.xml specifically.
for e.g Test file has a datasource specified while main file doesnt.
Also following bean is specified in test EntitymanagerFactory.xml but not in main.

<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="defaultDataSource" ref="hsqldbDataSource"/>  
    <property name="persistenceXmlLocations">
      <list>
        <value>classpath:META-INF/persistence-test.xml</value>
      </list>
    </property>
  </bean>

I want to have my main EntitymanagerFactory.xml file have same stuff its there in test file.Not sure why there is discrepency.

2) The tests file uses hsqldb by default.Is there a way I can override that to use oracle for tests as well?

3) When I run my tests I get an error
   14:20:29,984  INFO UserServiceTest:162 - Custom transaction definition [PROPAGAT
   ION_REQUIRED,ISOLATION_DEFAULT] for test method [testCreateAccount].
   14:20:29,984  INFO UserServiceTest:175 - ApplicationContext has not been configu
   red for test [com.bookonz.account.serviceapi.UserServiceTest]: dependency inject
   ion will NOT be performed.


I think this is becoz I need to define the test bean(UserServiceTest) in applicationContext.xml and configure transaction params.
Do you guys have any working example of this?

I really want to get past configuring spring/hibernate/jpa stuff and be able to run a few tests.

Thanks,
Deepak


Re: Configuration/running Unit Tests

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

All samples use 1.6.0-SNAPSHOT, with JPA. We run those in our continuous build server all the time.  What failures/problems do you see?

Checkout latest DDDSample from subversion:
https://fornax.svn.sourceforge.net/svnroot/fornax/trunk/cartridges/sculptor/DDDSample/
Thereafter run mvn clean install. What is the result?

/Patrik

deepshar027 wrote:
Patrik,
I dont think any of the examples DDDSample etc have been migrated to sculptor version 1.6.
I am looking for a JPA sample running successfully with all tests.

Do you have any plans for that?

Thanks,
Deepak.

Re: Configuration/running Unit Tests

by deepshar027 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Patrik,

Its my bad.I have multiple versions of code on my machine and I was looking at the wrong place.
I downloaded the code again and mvn install works great.

Thanks,
Deepak.


All samples use 1.6.0-SNAPSHOT, with JPA. We run those in our continuous build server all the time.  What failures/problems do you see?

Checkout latest DDDSample from subversion:
https://fornax.svn.sourceforge.net/svnroot/fornax/trunk/cartridges/sculptor/DDDSample/
Thereafter run mvn clean install. What is the result?

/Patrik

deepshar027 wrote:
Patrik,
I dont think any of the examples DDDSample etc have been migrated to sculptor version 1.6.
I am looking for a JPA sample running successfully with all tests.

Do you have any plans for that?

Thanks,
Deepak.


Re: Configuration/running Unit Tests

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That is good. Please continue to ask if you need some further help or clarification.
/Patrik