You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by jimpo <ja...@gofore.com> on 2007/10/26 13:36:52 UTC

How to use different databases for tests and the actual application?

I am using Maven2 to build my war packet. Base maven configuration is created
with Appfuse http://appfuse.org/display/APF/Home.

When I do a mvn install (or mvn cargo:deploy), first a test phase executes,
and then the final war is built and installed in the repository (or deployed
to my app server).

I want to run the tests against a different db than which the final package
uses. So far I have not figured out how to do this. Test phase uses the same
database as the final application.

I figured out how to use profiles to switch between different databases. I
can switch to test profile with, say, mvn test -Ptestdatabase. I could of
course use mvn test -Ptestdatabase to test and then separate command mvn
install -Dmaven.test.skip -Prealdatabase for creating the packet (and
skipping tests), but that's not very nice. I want to be able to issue one
command which does both phases, tests and packaging.

I am guessing maybe the solution would be something like activating profile
X for the tests phase, and then activating a different profile Y for the
actual build. How could I accomplish this?

-- 
View this message in context: http://www.nabble.com/How-to-use-different-databases-for-tests-and-the-actual-application--tf4696771s177.html#a13425450
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to use different databases for tests and the actual application?

Posted by Wayne Fay <wa...@gmail.com>.
Perhaps not ideal, but this would work:
mvn -Pdev clean test => for your unit tests
mvn -Dmaven.test.skip=true clean install (or cargo:deploy) => for real
install/deployment

And of course you'll need to specify a special dev/test config file
directory in the dev profile.

Wayne

On 10/26/07, jimpo <ja...@gofore.com> wrote:
>
> Using application server -specified datasources is out of the question right
> now unfortunately. Database connection details are configured inside the web
> application.
>
> It surprises me if Maven would not make it easy to use a different database
> configuration for the tests and a different one for the created application.
> This would basically make the dbUnit plugin pretty pointless, wouldn't it?
> If you are creating a release of your application, you want the release to
> point to a production db, but you still want the unit tests to be done
> against a unit test db populated with dbUnit.
>
> (not getting into whether such unit tests are really true "unit" tests...I
> need them regardless of the term)
>
>
> Arnaud Bailly wrote:
> >
> > jimpo <ja...@gofore.com> writes:
> >
> >> I am using Maven2 to build my war packet. Base maven configuration is
> >> created
> >> with Appfuse http://appfuse.org/display/APF/Home.
> >>
> >> When I do a mvn install (or mvn cargo:deploy), first a test phase
> >> executes,
> >> and then the final war is built and installed in the repository (or
> >> deployed
> >> to my app server).
> >>
> >> I want to run the tests against a different db than which the final
> >> package
> >> uses. So far I have not figured out how to do this. Test phase uses the
> >> same
> >> database as the final application.
> >>
> >> I figured out how to use profiles to switch between different databases.
> >> I
> >> can switch to test profile with, say, mvn test -Ptestdatabase. I could of
> >> course use mvn test -Ptestdatabase to test and then separate command mvn
> >> install -Dmaven.test.skip -Prealdatabase for creating the packet (and
> >> skipping tests), but that's not very nice. I want to be able to issue one
> >> command which does both phases, tests and packaging.
> >>
> >> I am guessing maybe the solution would be something like activating
> >> profile
> >> X for the tests phase, and then activating a different profile Y for the
> >> actual build. How could I accomplish this?
> >>
> >
> > Hello,
> > I do not think possible right now to activate different profiles for
> > different phases in the same run.  And I do not think this is
> > desirable. Maybe, if you are in a J2EE Container, you could use
> > different data sources parameters in test and production ? AFAIK, data
> > source configuration is independent of the applicaiont and configured
> > in the container, so you could use a test configuration, say with
> > hsqldb or derby in test, and another configuration in productoin. In
> > your webapp, data source reference will stay the same.
> >
> > HTH
> > --
> > OQube < software engineering \ génie logiciel >
> > Arnaud Bailly, Dr.
> > \web> http://www.oqube.com
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/How-to-use-different-databases-for-tests-and-the-actual-application--tf4696771s177.html#a13426113
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to use different databases for tests and the actual application?

Posted by Marco Mistroni <mm...@gmail.com>.
hi,
Not sure about that..

maven creates only 1 war, and tha ti ste result of you building app

i m using spring, using 2 different datasources for test and deploy
if u r not using spring, i'd go for 2 separate config files, but not knowing
your app
i won't comment further....

hth
 marco

On 10/29/07, jimpo <janne

.mattila@gofore.com> wrote:
>
>
> Hi,
>
> yes, this is something I have actually started to use as a basic
> principle.
>
> In src/main/resources and src/test/resources there is a config file
> jdbc.properties which defines the connection details. It has properties
> such
> as
>
> jdbc.username=${jdbc.username}
> jdbc.password=${jdbc.password}
>
> Now, instead of trying to make Maven put different values to
> ${jdbc.username} based on the build phase, I created additional properties
> such as ${jdbc.test.username} and used them in the src/test/*. I'm still
> in
> the middle of configuring the whole thing, but it seems like a valid
> approach.
>
> To get things clear, maven creates one .war during the test phase (with
> files based on src/test/resources/) and then creates another .war (using
> files from src/main/resources) when it creates the final installation
> packet? When I run
>
> > mvn install
>
> and Maven first goes through the test phase and then installs war in the
> repository, two different wars are created? Correct?
>
>
>
>
> Victor Cardona wrote:
> >
> > jimpo wrote:
> >> Using application server -specified datasources is out of the question
> >> right
> >> now unfortunately. Database connection details are configured inside
> the
> >> web
> >> application.
> >>
> >> It surprises me if Maven would not make it easy to use a different
> >> database
> >> configuration for the tests and a different one for the created
> >> application.
> >> This would basically make the dbUnit plugin pretty pointless, wouldn't
> >> it?
> >> If you are creating a release of your application, you want the release
> >> to
> >> point to a production db, but you still want the unit tests to be done
> >> against a unit test db populated with dbUnit.
> >>
> >> (not getting into whether such unit tests are really true "unit"
> >> tests...I
> >> need them regardless of the term)
> >>
> >>
> >> Arnaud Bailly wrote:
> >>> jimpo <ja...@gofore.com> writes:
> >>>
> >>>> I am using Maven2 to build my war packet. Base maven configuration is
> >>>> created
> >>>> with Appfuse http://appfuse.org/display/APF/Home.
> >>>>
> >>>> When I do a mvn install (or mvn cargo:deploy), first a test phase
> >>>> executes,
> >>>> and then the final war is built and installed in the repository (or
> >>>> deployed
> >>>> to my app server).
> >>>>
> >>>> I want to run the tests against a different db than which the final
> >>>> package
> >>>> uses. So far I have not figured out how to do this. Test phase uses
> the
> >>>> same
> >>>> database as the final application.
> >>>>
> >>>> I figured out how to use profiles to switch between different
> >>>> databases.
> >>>> I
> >>>> can switch to test profile with, say, mvn test -Ptestdatabase. I
> could
> >>>> of
> >>>> course use mvn test -Ptestdatabase to test and then separate command
> >>>> mvn
> >>>> install -Dmaven.test.skip -Prealdatabase for creating the packet (and
> >>>> skipping tests), but that's not very nice. I want to be able to issue
> >>>> one
> >>>> command which does both phases, tests and packaging.
> >>>>
> >>>> I am guessing maybe the solution would be something like activating
> >>>> profile
> >>>> X for the tests phase, and then activating a different profile Y for
> >>>> the
> >>>> actual build. How could I accomplish this?
> >>>>
> >>> Hello,
> >>> I do not think possible right now to activate different profiles for
> >>> different phases in the same run.  And I do not think this is
> >>> desirable. Maybe, if you are in a J2EE Container, you could use
> >>> different data sources parameters in test and production ? AFAIK, data
> >>> source configuration is independent of the applicaiont and configured
> >>> in the container, so you could use a test configuration, say with
> >>> hsqldb or derby in test, and another configuration in productoin. In
> >>> your webapp, data source reference will stay the same.
> >>>
> >>> HTH
> >>> --
> >>> OQube < software engineering \ génie logiciel >
> >>> Arnaud Bailly, Dr.
> >>> \web> http://www.oqube.com
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >>> For additional commands, e-mail: users-help@maven.apache.org
> >>>
> >>>
> >>>
> >>
> >
> > I'm not familiar with Appfuse, so excuse my uninformed question.  How
> > are you configuring your datasource in your webapp?  I'm guessing that
> > you have the connection properties in a file somewhere similar to
> > tomcat's context.xml.  If so, can't you just add a similar file to your
> > testing resources directory that would then configure the application
> > with the test database information?
> >
> > Victor
> >
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/How-to-use-different-databases-for-tests-and-the-actual-application--tf4696771s177.html#a13469803
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: How to use different databases for tests and the actual application?

Posted by Victor Cardona <v....@sbcglobal.net>.
jimpo wrote:
> Hi,
> 
> yes, this is something I have actually started to use as a basic principle. 
> 
> In src/main/resources and src/test/resources there is a config file
> jdbc.properties which defines the connection details. It has properties such
> as 
> 
> jdbc.username=${jdbc.username}
> jdbc.password=${jdbc.password}
> 
> Now, instead of trying to make Maven put different values to
> ${jdbc.username} based on the build phase, I created additional properties
> such as ${jdbc.test.username} and used them in the src/test/*. I'm still in
> the middle of configuring the whole thing, but it seems like a valid
> approach.
> 
> To get things clear, maven creates one .war during the test phase (with
> files based on src/test/resources/) and then creates another .war (using
> files from src/main/resources) when it creates the final installation
> packet? When I run
> 
>> mvn install
> 
> and Maven first goes through the test phase and then installs war in the
> repository, two different wars are created? Correct?
> 
> 
> 
> 
> Victor Cardona wrote:
>> jimpo wrote:
>>> Using application server -specified datasources is out of the question
>>> right
>>> now unfortunately. Database connection details are configured inside the
>>> web
>>> application.
>>>
>>> It surprises me if Maven would not make it easy to use a different
>>> database
>>> configuration for the tests and a different one for the created
>>> application.
>>> This would basically make the dbUnit plugin pretty pointless, wouldn't
>>> it?
>>> If you are creating a release of your application, you want the release
>>> to
>>> point to a production db, but you still want the unit tests to be done
>>> against a unit test db populated with dbUnit.
>>>
>>> (not getting into whether such unit tests are really true "unit"
>>> tests...I
>>> need them regardless of the term)
>>>
>>>
>>> Arnaud Bailly wrote:
>>>> jimpo <ja...@gofore.com> writes:
>>>>
>>>>> I am using Maven2 to build my war packet. Base maven configuration is
>>>>> created
>>>>> with Appfuse http://appfuse.org/display/APF/Home.
>>>>>
>>>>> When I do a mvn install (or mvn cargo:deploy), first a test phase
>>>>> executes,
>>>>> and then the final war is built and installed in the repository (or
>>>>> deployed
>>>>> to my app server).
>>>>>
>>>>> I want to run the tests against a different db than which the final
>>>>> package
>>>>> uses. So far I have not figured out how to do this. Test phase uses the
>>>>> same
>>>>> database as the final application.
>>>>>
>>>>> I figured out how to use profiles to switch between different
>>>>> databases.
>>>>> I
>>>>> can switch to test profile with, say, mvn test -Ptestdatabase. I could
>>>>> of
>>>>> course use mvn test -Ptestdatabase to test and then separate command
>>>>> mvn
>>>>> install -Dmaven.test.skip -Prealdatabase for creating the packet (and
>>>>> skipping tests), but that's not very nice. I want to be able to issue
>>>>> one
>>>>> command which does both phases, tests and packaging.
>>>>>
>>>>> I am guessing maybe the solution would be something like activating
>>>>> profile
>>>>> X for the tests phase, and then activating a different profile Y for
>>>>> the
>>>>> actual build. How could I accomplish this?
>>>>>
>>>> Hello,
>>>> I do not think possible right now to activate different profiles for
>>>> different phases in the same run.  And I do not think this is
>>>> desirable. Maybe, if you are in a J2EE Container, you could use
>>>> different data sources parameters in test and production ? AFAIK, data
>>>> source configuration is independent of the applicaiont and configured
>>>> in the container, so you could use a test configuration, say with
>>>> hsqldb or derby in test, and another configuration in productoin. In
>>>> your webapp, data source reference will stay the same.
>>>>
>>>> HTH
>>>> -- 
>>>> OQube < software engineering \ génie logiciel >
>>>> Arnaud Bailly, Dr.
>>>> \web> http://www.oqube.com
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>
>>>>
>>>>
>> I'm not familiar with Appfuse, so excuse my uninformed question.  How
>> are you configuring your datasource in your webapp?  I'm guessing that
>> you have the connection properties in a file somewhere similar to
>> tomcat's context.xml.  If so, can't you just add a similar file to your
>> testing resources directory that would then configure the application
>> with the test database information?
>>
>> Victor
>>
>>
>>  
>>
> 

Well I can't really offer anymore advise at present.  I have never
actually tried to do a lot of integration testing with Maven before.  My
only suggestion is for you to google "maven" and "integration testing
web applications"  and see what you come up with.  Perhaps someone else
on the list can help you further.

Victor


Re: How to use different databases for tests and the actual application?

Posted by jimpo <ja...@gofore.com>.
Hi,

yes, this is something I have actually started to use as a basic principle. 

In src/main/resources and src/test/resources there is a config file
jdbc.properties which defines the connection details. It has properties such
as 

jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}

Now, instead of trying to make Maven put different values to
${jdbc.username} based on the build phase, I created additional properties
such as ${jdbc.test.username} and used them in the src/test/*. I'm still in
the middle of configuring the whole thing, but it seems like a valid
approach.

To get things clear, maven creates one .war during the test phase (with
files based on src/test/resources/) and then creates another .war (using
files from src/main/resources) when it creates the final installation
packet? When I run

> mvn install

and Maven first goes through the test phase and then installs war in the
repository, two different wars are created? Correct?




Victor Cardona wrote:
> 
> jimpo wrote:
>> Using application server -specified datasources is out of the question
>> right
>> now unfortunately. Database connection details are configured inside the
>> web
>> application.
>> 
>> It surprises me if Maven would not make it easy to use a different
>> database
>> configuration for the tests and a different one for the created
>> application.
>> This would basically make the dbUnit plugin pretty pointless, wouldn't
>> it?
>> If you are creating a release of your application, you want the release
>> to
>> point to a production db, but you still want the unit tests to be done
>> against a unit test db populated with dbUnit.
>> 
>> (not getting into whether such unit tests are really true "unit"
>> tests...I
>> need them regardless of the term)
>> 
>> 
>> Arnaud Bailly wrote:
>>> jimpo <ja...@gofore.com> writes:
>>>
>>>> I am using Maven2 to build my war packet. Base maven configuration is
>>>> created
>>>> with Appfuse http://appfuse.org/display/APF/Home.
>>>>
>>>> When I do a mvn install (or mvn cargo:deploy), first a test phase
>>>> executes,
>>>> and then the final war is built and installed in the repository (or
>>>> deployed
>>>> to my app server).
>>>>
>>>> I want to run the tests against a different db than which the final
>>>> package
>>>> uses. So far I have not figured out how to do this. Test phase uses the
>>>> same
>>>> database as the final application.
>>>>
>>>> I figured out how to use profiles to switch between different
>>>> databases.
>>>> I
>>>> can switch to test profile with, say, mvn test -Ptestdatabase. I could
>>>> of
>>>> course use mvn test -Ptestdatabase to test and then separate command
>>>> mvn
>>>> install -Dmaven.test.skip -Prealdatabase for creating the packet (and
>>>> skipping tests), but that's not very nice. I want to be able to issue
>>>> one
>>>> command which does both phases, tests and packaging.
>>>>
>>>> I am guessing maybe the solution would be something like activating
>>>> profile
>>>> X for the tests phase, and then activating a different profile Y for
>>>> the
>>>> actual build. How could I accomplish this?
>>>>
>>> Hello,
>>> I do not think possible right now to activate different profiles for
>>> different phases in the same run.  And I do not think this is
>>> desirable. Maybe, if you are in a J2EE Container, you could use
>>> different data sources parameters in test and production ? AFAIK, data
>>> source configuration is independent of the applicaiont and configured
>>> in the container, so you could use a test configuration, say with
>>> hsqldb or derby in test, and another configuration in productoin. In
>>> your webapp, data source reference will stay the same.
>>>
>>> HTH
>>> -- 
>>> OQube < software engineering \ génie logiciel >
>>> Arnaud Bailly, Dr.
>>> \web> http://www.oqube.com
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>>
>> 
> 
> I'm not familiar with Appfuse, so excuse my uninformed question.  How
> are you configuring your datasource in your webapp?  I'm guessing that
> you have the connection properties in a file somewhere similar to
> tomcat's context.xml.  If so, can't you just add a similar file to your
> testing resources directory that would then configure the application
> with the test database information?
> 
> Victor
> 
> 
>  
> 

-- 
View this message in context: http://www.nabble.com/How-to-use-different-databases-for-tests-and-the-actual-application--tf4696771s177.html#a13469803
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to use different databases for tests and the actual application?

Posted by Marco Mistroni <mm...@gmail.com>.
Hi,
  didnt follow whole thread i m afraid
my understanding is that you want to use 2 diffeerent datasources for your
app
r u using Spring at all?
coul dyou not configure a datasource for production and a datasource for
test?

hth
 marco

On 10/27/07, Victor Cardona <v....@sbcglobal.net> wrote:
>
> jimpo wrote:
> > Using application server -specified datasources is out of the question
> right
> > now unfortunately. Database connection details are configured inside the
> web
> > application.
> >
> > It surprises me if Maven would not make it easy to use a different
> database
> > configuration for the tests and a different one for the created
> application.
> > This would basically make the dbUnit plugin pretty pointless, wouldn't
> it?
> > If you are creating a release of your application, you want the release
> to
> > point to a production db, but you still want the unit tests to be done
> > against a unit test db populated with dbUnit.
> >
> > (not getting into whether such unit tests are really true "unit"
> tests...I
> > need them regardless of the term)
> >
> >
> > Arnaud Bailly wrote:
> >> jimpo <ja...@gofore.com> writes:
> >>
> >>> I am using Maven2 to build my war packet. Base maven configuration is
> >>> created
> >>> with Appfuse http://appfuse.org/display/APF/Home.
> >>>
> >>> When I do a mvn install (or mvn cargo:deploy), first a test phase
> >>> executes,
> >>> and then the final war is built and installed in the repository (or
> >>> deployed
> >>> to my app server).
> >>>
> >>> I want to run the tests against a different db than which the final
> >>> package
> >>> uses. So far I have not figured out how to do this. Test phase uses
> the
> >>> same
> >>> database as the final application.
> >>>
> >>> I figured out how to use profiles to switch between different
> databases.
> >>> I
> >>> can switch to test profile with, say, mvn test -Ptestdatabase. I could
> of
> >>> course use mvn test -Ptestdatabase to test and then separate command
> mvn
> >>> install -Dmaven.test.skip -Prealdatabase for creating the packet (and
> >>> skipping tests), but that's not very nice. I want to be able to issue
> one
> >>> command which does both phases, tests and packaging.
> >>>
> >>> I am guessing maybe the solution would be something like activating
> >>> profile
> >>> X for the tests phase, and then activating a different profile Y for
> the
> >>> actual build. How could I accomplish this?
> >>>
> >> Hello,
> >> I do not think possible right now to activate different profiles for
> >> different phases in the same run.  And I do not think this is
> >> desirable. Maybe, if you are in a J2EE Container, you could use
> >> different data sources parameters in test and production ? AFAIK, data
> >> source configuration is independent of the applicaiont and configured
> >> in the container, so you could use a test configuration, say with
> >> hsqldb or derby in test, and another configuration in productoin. In
> >> your webapp, data source reference will stay the same.
> >>
> >> HTH
> >> --
> >> OQube < software engineering \ génie logiciel >
> >> Arnaud Bailly, Dr.
> >> \web> http://www.oqube.com
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: users-help@maven.apache.org
> >>
> >>
> >>
> >
>
> I'm not familiar with Appfuse, so excuse my uninformed question.  How
> are you configuring your datasource in your webapp?  I'm guessing that
> you have the connection properties in a file somewhere similar to
> tomcat's context.xml.  If so, can't you just add a similar file to your
> testing resources directory that would then configure the application
> with the test database information?
>
> Victor
>
>
>

Re: How to use different databases for tests and the actual application?

Posted by Victor Cardona <v....@sbcglobal.net>.
jimpo wrote:
> Using application server -specified datasources is out of the question right
> now unfortunately. Database connection details are configured inside the web
> application.
> 
> It surprises me if Maven would not make it easy to use a different database
> configuration for the tests and a different one for the created application.
> This would basically make the dbUnit plugin pretty pointless, wouldn't it?
> If you are creating a release of your application, you want the release to
> point to a production db, but you still want the unit tests to be done
> against a unit test db populated with dbUnit.
> 
> (not getting into whether such unit tests are really true "unit" tests...I
> need them regardless of the term)
> 
> 
> Arnaud Bailly wrote:
>> jimpo <ja...@gofore.com> writes:
>>
>>> I am using Maven2 to build my war packet. Base maven configuration is
>>> created
>>> with Appfuse http://appfuse.org/display/APF/Home.
>>>
>>> When I do a mvn install (or mvn cargo:deploy), first a test phase
>>> executes,
>>> and then the final war is built and installed in the repository (or
>>> deployed
>>> to my app server).
>>>
>>> I want to run the tests against a different db than which the final
>>> package
>>> uses. So far I have not figured out how to do this. Test phase uses the
>>> same
>>> database as the final application.
>>>
>>> I figured out how to use profiles to switch between different databases.
>>> I
>>> can switch to test profile with, say, mvn test -Ptestdatabase. I could of
>>> course use mvn test -Ptestdatabase to test and then separate command mvn
>>> install -Dmaven.test.skip -Prealdatabase for creating the packet (and
>>> skipping tests), but that's not very nice. I want to be able to issue one
>>> command which does both phases, tests and packaging.
>>>
>>> I am guessing maybe the solution would be something like activating
>>> profile
>>> X for the tests phase, and then activating a different profile Y for the
>>> actual build. How could I accomplish this?
>>>
>> Hello,
>> I do not think possible right now to activate different profiles for
>> different phases in the same run.  And I do not think this is
>> desirable. Maybe, if you are in a J2EE Container, you could use
>> different data sources parameters in test and production ? AFAIK, data
>> source configuration is independent of the applicaiont and configured
>> in the container, so you could use a test configuration, say with
>> hsqldb or derby in test, and another configuration in productoin. In
>> your webapp, data source reference will stay the same.
>>
>> HTH
>> -- 
>> OQube < software engineering \ génie logiciel >
>> Arnaud Bailly, Dr.
>> \web> http://www.oqube.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>>
> 

I'm not familiar with Appfuse, so excuse my uninformed question.  How
are you configuring your datasource in your webapp?  I'm guessing that
you have the connection properties in a file somewhere similar to
tomcat's context.xml.  If so, can't you just add a similar file to your
testing resources directory that would then configure the application
with the test database information?

Victor


Re: How to use different databases for tests and the actual application?

Posted by jimpo <ja...@gofore.com>.
Using application server -specified datasources is out of the question right
now unfortunately. Database connection details are configured inside the web
application.

It surprises me if Maven would not make it easy to use a different database
configuration for the tests and a different one for the created application.
This would basically make the dbUnit plugin pretty pointless, wouldn't it?
If you are creating a release of your application, you want the release to
point to a production db, but you still want the unit tests to be done
against a unit test db populated with dbUnit.

(not getting into whether such unit tests are really true "unit" tests...I
need them regardless of the term)


Arnaud Bailly wrote:
> 
> jimpo <ja...@gofore.com> writes:
> 
>> I am using Maven2 to build my war packet. Base maven configuration is
>> created
>> with Appfuse http://appfuse.org/display/APF/Home.
>>
>> When I do a mvn install (or mvn cargo:deploy), first a test phase
>> executes,
>> and then the final war is built and installed in the repository (or
>> deployed
>> to my app server).
>>
>> I want to run the tests against a different db than which the final
>> package
>> uses. So far I have not figured out how to do this. Test phase uses the
>> same
>> database as the final application.
>>
>> I figured out how to use profiles to switch between different databases.
>> I
>> can switch to test profile with, say, mvn test -Ptestdatabase. I could of
>> course use mvn test -Ptestdatabase to test and then separate command mvn
>> install -Dmaven.test.skip -Prealdatabase for creating the packet (and
>> skipping tests), but that's not very nice. I want to be able to issue one
>> command which does both phases, tests and packaging.
>>
>> I am guessing maybe the solution would be something like activating
>> profile
>> X for the tests phase, and then activating a different profile Y for the
>> actual build. How could I accomplish this?
>>
> 
> Hello,
> I do not think possible right now to activate different profiles for
> different phases in the same run.  And I do not think this is
> desirable. Maybe, if you are in a J2EE Container, you could use
> different data sources parameters in test and production ? AFAIK, data
> source configuration is independent of the applicaiont and configured
> in the container, so you could use a test configuration, say with
> hsqldb or derby in test, and another configuration in productoin. In
> your webapp, data source reference will stay the same.
> 
> HTH
> -- 
> OQube < software engineering \ génie logiciel >
> Arnaud Bailly, Dr.
> \web> http://www.oqube.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-use-different-databases-for-tests-and-the-actual-application--tf4696771s177.html#a13426113
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to use different databases for tests and the actual application?

Posted by Insitu <ab...@oqube.com>.
jimpo <ja...@gofore.com> writes:

> I am using Maven2 to build my war packet. Base maven configuration is created
> with Appfuse http://appfuse.org/display/APF/Home.
>
> When I do a mvn install (or mvn cargo:deploy), first a test phase executes,
> and then the final war is built and installed in the repository (or deployed
> to my app server).
>
> I want to run the tests against a different db than which the final package
> uses. So far I have not figured out how to do this. Test phase uses the same
> database as the final application.
>
> I figured out how to use profiles to switch between different databases. I
> can switch to test profile with, say, mvn test -Ptestdatabase. I could of
> course use mvn test -Ptestdatabase to test and then separate command mvn
> install -Dmaven.test.skip -Prealdatabase for creating the packet (and
> skipping tests), but that's not very nice. I want to be able to issue one
> command which does both phases, tests and packaging.
>
> I am guessing maybe the solution would be something like activating profile
> X for the tests phase, and then activating a different profile Y for the
> actual build. How could I accomplish this?
>

Hello,
I do not think possible right now to activate different profiles for
different phases in the same run.  And I do not think this is
desirable. Maybe, if you are in a J2EE Container, you could use
different data sources parameters in test and production ? AFAIK, data
source configuration is independent of the applicaiont and configured
in the container, so you could use a test configuration, say with
hsqldb or derby in test, and another configuration in productoin. In
your webapp, data source reference will stay the same.

HTH
-- 
OQube < software engineering \ génie logiciel >
Arnaud Bailly, Dr.
\web> http://www.oqube.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org