You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Wa...@emc.com on 2007/05/09 20:15:13 UTC
How do I pass a username/password to a Junit test
I've seen this question asked a few places before, but the only
responses that I've seen have been either dead links or links to
reference material that doesn't actually explain the "how" of it.
I have a unit test that connects to a database using a username and
password in a system property as described in the junit docs:
http://junit.sourceforge.net/doc/faq/faq.htm#running_7. I have a line of
code in my test setup that does:
dbusr = System.getProperty("dbusr");
It does the same for the db password and url.
We are using several IDE's and each test runner allows me to define this
property on the command line:
-Ddbusr=foo
However using this switch on the "mvn" command line does not set the
system property when the test is run.
Now I have been able to make this work by specifying the
<systemProperties> element in the pom.xml under the surefire plugin's
configuration. This will pass the hardcoded values from the pom.xml to
the unit test. However, I have not figured out a way to parameterize the
build so that users can supply this information themselves. To date I
have tried the following:
1) Specifying maven.junit.jvmargs=-D... on the command line (in quotes)
as well as in a project.properties file and hardcoded in the pom.xml
itself. This property seems to have no affect regardless of what I do
with it.
2) Specifying the properties themselves on the maven command line, in a
project.properties file.
3) Doing number (2) in conjunction with the maven.junit.sysproperties
set to the names of the properties on the command line, in a
project.properties file.
4) Setting maven.junit.sysproperties hardcoded in the pom.xml as a
system property to the surefire configuration and then setting the
properties themselves as in (2).
None of the 4 approaches above have worked. Has anyone been able to
accomplish this? If so could you describe your approach.
Thank you,
-- Les Walker
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Site generation at one with Multimodule project
Posted by Roland Asmann <Ro...@cfc.at>.
If your project is set up correctly, calling site:deploy will upload the sites
to one location on a remote server. You must have that location configured in
your POM of course!
Just call mvn site:deploy from the root of the project.
On Wednesday 09 May 2007 22:27, Jaish.Singh@wellsfargo.com wrote:
> Hello,
>
> I need to generate the site with multimodule project. Requirement is to
> create site project at one place and deploy it to weblogic server.
>
> As of now each module is creating the site at it's target folder. Can we
> combine all the module and deploy it one place?
>
> Thanks
> Jaish
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
--
Roland Asmann
CFC Informationssysteme Entwicklungsgesellschaft m.b.H
Bäckerstrasse 1/2/7
A-1010 Wien
FN 266155f, Handelsgericht Wien
Tel.: +43/1/513 88 77 - 27
Fax.: +43/1/513 88 62
Email: Roland.Asmann@cfc.at
Web: www.cfc.at
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Site generation at one with Multimodule project
Posted by Ja...@wellsfargo.com.
Hello,
I need to generate the site with multimodule project. Requirement is to
create site project at one place and deploy it to weblogic server.
As of now each module is creating the site at it's target folder. Can we
combine all the module and deploy it one place?
Thanks
Jaish
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
[SOLVED] RE: How do I pass a username/password to a Junit test
Posted by Wa...@emc.com.
That did it. I thought that I had tried that, but without knowing which
approach to take it's difficult to spend time debugging any one
approach.
Junit code:
@BeforeClass
public static void initClass() {
dbusr = System.getProperty("dbusr");
dbpwd = System.getProperty("dbpwd");
dburl = System.getProperty("dburl");
if ((dbusr == null) || (dbpwd == null) || (dburl == null)) {
throw new RuntimeException("Invalid configuration. Make sure
to set dbusr, dbpwd, and dburl!");
}
}
POM.XML:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>dbusr</name>
<value>${dbusr}</value>
</property>
<property>
<name>dbpwd</name>
<value>${dbpwd}</value>
</property>
<property>
<name>dburl</name>
<value>${dburl}</value>
</property>
</systemProperties>
</configuration>
</plugin>
and the command line:
mvn -D dbusr=lester -D dbpwd=youwish -D
dburl=jdbc:oracle:thin:@//localhost:1521/xe test
Thanks for the help.
-- Les Walker
-----Original Message-----
From: Wayne Fay [mailto:waynefay@gmail.com]
Sent: Wednesday, May 09, 2007 3:04 PM
To: Maven Users List
Subject: Re: How do I pass a username/password to a Junit test
This happens because Surefire by default forks "once" which means all
tests run in their own JVM.
If your tests will run with no forking, you can set
<forkMode>never</forkMode> and all properties passed on the mvn
command line will go straight through to the tests. Most people will
not choose this option.
So the next option is to pass the CLI values into variables in the
pom, and then pass them into the tests as system Properties, ie:
In test source code:
String dbusr = System.getProperty("dbusr");
System.out.println("dbusr is: " + dbusr);
In pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>dbusr</name>
<value>${foo}</value>
</property>
</systemProperties>
</configuration>
</plugin>
On command line:
C:\temp\blah>mvn test -Dfoo=blah
Running myTest
dbusr is: blah
Wayne
On 5/9/07, Walker_Les@emc.com <Wa...@emc.com> wrote:
> I've seen this question asked a few places before, but the only
> responses that I've seen have been either dead links or links to
> reference material that doesn't actually explain the "how" of it.
>
> I have a unit test that connects to a database using a username and
> password in a system property as described in the junit docs:
> http://junit.sourceforge.net/doc/faq/faq.htm#running_7. I have a line
of
> code in my test setup that does:
>
> dbusr = System.getProperty("dbusr");
>
> It does the same for the db password and url.
>
> We are using several IDE's and each test runner allows me to define
this
> property on the command line:
>
> -Ddbusr=foo
>
> However using this switch on the "mvn" command line does not set the
> system property when the test is run.
>
> Now I have been able to make this work by specifying the
> <systemProperties> element in the pom.xml under the surefire plugin's
> configuration. This will pass the hardcoded values from the pom.xml to
> the unit test. However, I have not figured out a way to parameterize
the
> build so that users can supply this information themselves. To date I
> have tried the following:
>
> 1) Specifying maven.junit.jvmargs=-D... on the command line (in
quotes)
> as well as in a project.properties file and hardcoded in the pom.xml
> itself. This property seems to have no affect regardless of what I do
> with it.
> 2) Specifying the properties themselves on the maven command line, in
a
> project.properties file.
> 3) Doing number (2) in conjunction with the maven.junit.sysproperties
> set to the names of the properties on the command line, in a
> project.properties file.
> 4) Setting maven.junit.sysproperties hardcoded in the pom.xml as a
> system property to the surefire configuration and then setting the
> properties themselves as in (2).
>
> None of the 4 approaches above have worked. Has anyone been able to
> accomplish this? If so could you describe your approach.
>
> Thank you,
>
> -- Les Walker
>
>
> ---------------------------------------------------------------------
> 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
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: How do I pass a username/password to a Junit test
Posted by Wayne Fay <wa...@gmail.com>.
This happens because Surefire by default forks "once" which means all
tests run in their own JVM.
If your tests will run with no forking, you can set
<forkMode>never</forkMode> and all properties passed on the mvn
command line will go straight through to the tests. Most people will
not choose this option.
So the next option is to pass the CLI values into variables in the
pom, and then pass them into the tests as system Properties, ie:
In test source code:
String dbusr = System.getProperty("dbusr");
System.out.println("dbusr is: " + dbusr);
In pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>dbusr</name>
<value>${foo}</value>
</property>
</systemProperties>
</configuration>
</plugin>
On command line:
C:\temp\blah>mvn test -Dfoo=blah
Running myTest
dbusr is: blah
Wayne
On 5/9/07, Walker_Les@emc.com <Wa...@emc.com> wrote:
> I've seen this question asked a few places before, but the only
> responses that I've seen have been either dead links or links to
> reference material that doesn't actually explain the "how" of it.
>
> I have a unit test that connects to a database using a username and
> password in a system property as described in the junit docs:
> http://junit.sourceforge.net/doc/faq/faq.htm#running_7. I have a line of
> code in my test setup that does:
>
> dbusr = System.getProperty("dbusr");
>
> It does the same for the db password and url.
>
> We are using several IDE's and each test runner allows me to define this
> property on the command line:
>
> -Ddbusr=foo
>
> However using this switch on the "mvn" command line does not set the
> system property when the test is run.
>
> Now I have been able to make this work by specifying the
> <systemProperties> element in the pom.xml under the surefire plugin's
> configuration. This will pass the hardcoded values from the pom.xml to
> the unit test. However, I have not figured out a way to parameterize the
> build so that users can supply this information themselves. To date I
> have tried the following:
>
> 1) Specifying maven.junit.jvmargs=-D... on the command line (in quotes)
> as well as in a project.properties file and hardcoded in the pom.xml
> itself. This property seems to have no affect regardless of what I do
> with it.
> 2) Specifying the properties themselves on the maven command line, in a
> project.properties file.
> 3) Doing number (2) in conjunction with the maven.junit.sysproperties
> set to the names of the properties on the command line, in a
> project.properties file.
> 4) Setting maven.junit.sysproperties hardcoded in the pom.xml as a
> system property to the surefire configuration and then setting the
> properties themselves as in (2).
>
> None of the 4 approaches above have worked. Has anyone been able to
> accomplish this? If so could you describe your approach.
>
> Thank you,
>
> -- Les Walker
>
>
> ---------------------------------------------------------------------
> 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