Commit c4d17fa9 authored by Administrator's avatar Administrator

Allows both application execution and deployment with Maven

The previous Maven configuration included a WildFly Maven plugin
configuration in the H2 and MySQL profiles that allowed the application
execution directly from Maven (with the mvn wildfly:start wildfly:deploy
command). As this configuration included a custom WildFly deployment
configuration (that modified the standalone.xml of the WildFly where the
application will be deployed), the mvn wildfly:deploy couldn't be used
to deploy the application in a local WildFly instance.

This commit adds a new profile (wildfly-mysql-run) that can be used to
execute the application directly from Maven (with the mvn install
command). The custom WildFly plugin configuration has been removed from
the other profiles, allowing users to normally deploy the application in
a running WildFly instances.

Instructions on how to use the profiles for application execution and
deployment can be found in the README.md file.
parent 667186e4
...@@ -3,46 +3,47 @@ ...@@ -3,46 +3,47 @@
This repository contains the code base of a sample project that will be used in This repository contains the code base of a sample project that will be used in
the XCS subject inside the DGSS itinerary. the XCS subject inside the DGSS itinerary.
## Deployment Environment ## 1. Deployment Environment
The environment is based on Java 8, Maven 3.3+, Git 1.9+, MySQL 5.5+,
WildFly 8.2.1 and Eclipse Neon for JavaEE.
The environment is based on Maven 3, MySQL 5.5, WildFly 8.2.1 and Eclipse Neon ### 1.1. Java JDK 8
for JavaEE.
### Java JDK 8
Download and install Java JDK 8, preferably the Oracle version (the commands Download and install Java JDK 8, preferably the Oracle version (the commands
`java` and `javac` must be available). `java` and `javac` must be available).
### Maven You can test your Java installation with the commands:
```bash
java -version
javac -version
```
### 1.2. Maven 3.3+
Install Maven 3 in your system, if it was not installed (the `mvn` command must Install Maven 3 in your system, if it was not installed (the `mvn` command must
be available). If you are in a Debian-based OS, install the `maven` package be available). If you are in a Debian-based OS, install the `maven` package
(**don't install `maven2` package!!**). (**don't install `maven2` package!!**).
### Git You can test your Maven installation with the command:
```bash
mvn --version
```
### 1.3. Git 1.9+
First, install Git in your system if it was not installed (the `git` command First, install Git in your system if it was not installed (the `git` command
must be available). We will work with Git to get updates of these sample. must be available). We will work with Git to get updates of these sample.
Concretely, we will work with a Git repository inside Concretely, we will work with a Git repository inside
[our Gitlab server](http://sing.ei.uvigo.es/dt/gitlab). [our Gitlab server](http://sing.ei.uvigo.es/dt/gitlab).
Once Git is installed in your system, clone the project: You can tests your Git installation with the command:
```bash ```bash
git clone http://sing.ei.uvigo.es/dt/gitlab/dgss-1617/xcs-sample.git git --version
``` ```
### Eclipse Once Git is installed in your system, clone the project:
```bash
Open Eclipse Neon for Java EE and import your Maven project with git clone http://sing.ei.uvigo.es/dt/gitlab/dgss-1617/xcs-sample.git
`File -> Import -> Maven -> Existing Maven Projects` ```
Select your source code folder (where the `pom.xml` should be placed).
Eclipse should then import a parent project (`xcs-sample`) and 6 child projects
(`tests`, `domain`, `service`, `rest`, `jsf` and `ear`).
If you want, you can use any other IDE, such as IntelliJ IDEA or NetBeans, as
long as they are compatible with Maven projects, but we recommend using Eclipse
Neon for Java EE.
### MySQL ### 1.4. MySQL 5.5+
In order to run the tests with the `wildfly-embedded-mysql` profile (more about In order to run the tests with the `wildfly-embedded-mysql` profile (more about
this in the **Sample 2** section) and to run the application, we need a MySQL this in the **Sample 2** section) and to run the application, we need a MySQL
server. server.
...@@ -51,8 +52,9 @@ The server can be installed as usual, but it must contain two databases: ...@@ -51,8 +52,9 @@ The server can be installed as usual, but it must contain two databases:
* The `xcs` database for running the application. * The `xcs` database for running the application.
* The `xcssampletest` database for testing the appliaction. * The `xcssampletest` database for testing the appliaction.
In both cases, the user `xcs` identified by `xcs` should have all privileges on In both cases, the user `xcs` identified by `xcs` password should have all
this database. You can do this by executing the following commands: privileges on this database. You can do this by executing the following
commands:
```sql ```sql
CREATE DATABASE xcs; CREATE DATABASE xcs;
...@@ -65,121 +67,141 @@ FLUSH PRIVILEGES; ...@@ -65,121 +67,141 @@ FLUSH PRIVILEGES;
``` ```
If you want to add some data to the `xcs` database to run the application (data If you want to add some data to the `xcs` database to run the application (data
will be automatically inseted to the `xcssampletest` database during the tests), will be automatically inserted to the `xcssampletest` database during the
you can also execute: tests) you can also execute:
```sql ```sql
DROP TABLE IF EXISTS `User`; DROP TABLE IF EXISTS `User`;
CREATE TABLE `User` ( CREATE TABLE `User` (
`role` varchar(5) NOT NULL, `role` varchar(5) NOT NULL,
`login` varchar(100) NOT NULL, `login` varchar(100) NOT NULL,
`password` varchar(32) NOT NULL, `password` varchar(32) NOT NULL,
PRIMARY KEY (`login`) PRIMARY KEY (`login`)
); );
DROP TABLE IF EXISTS `Pet`; DROP TABLE IF EXISTS `Pet`;
CREATE TABLE `Pet` ( CREATE TABLE `Pet` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`animal` varchar(4) NOT NULL, `animal` varchar(4) NOT NULL,
`birth` datetime NOT NULL, `birth` datetime NOT NULL,
`name` varchar(100) NOT NULL, `name` varchar(100) NOT NULL,
`owner` varchar(100) NOT NULL, `owner` varchar(100) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `FK_6mfctqh1tpytabbk1u4bk1pym` (`owner`), KEY `FK_6mfctqh1tpytabbk1u4bk1pym` (`owner`),
CONSTRAINT `FK_6mfctqh1tpytabbk1u4bk1pym` FOREIGN KEY (`owner`) REFERENCES `User` (`login`) CONSTRAINT `FK_6mfctqh1tpytabbk1u4bk1pym` FOREIGN KEY (`owner`) REFERENCES `User` (`login`)
); );
-- All the passwords are "<login>pass". -- All the passwords are "<login>pass".
INSERT INTO `User` INSERT INTO `User`
VALUES ('ADMIN','jose','A3F6F4B40B24E2FD61F08923ED452F34'), VALUES ('ADMIN','jose','A3F6F4B40B24E2FD61F08923ED452F34'),
('OWNER','pepe','B43B4D046860B2BD945BCA2597BF9F07'), ('OWNER','pepe','B43B4D046860B2BD945BCA2597BF9F07'),
('OWNER','juan','B4FBB95580592697DC71488A1F19277E'), ('OWNER','juan','B4FBB95580592697DC71488A1F19277E'),
('OWNER','ana','22BEEAE33E9B2657F9610621502CD7A4'), ('OWNER','ana','22BEEAE33E9B2657F9610621502CD7A4'),
('OWNER','lorena','05009E420932C21E5A68F5EF1AADD530'); ('OWNER','lorena','05009E420932C21E5A68F5EF1AADD530');
INSERT INTO `Pet` (animal, birth, name, owner) INSERT INTO `Pet` (animal, birth, name, owner)
VALUES ('CAT','2000-01-01 01:01:01','Pepecat','pepe'), VALUES ('CAT','2000-01-01 01:01:01','Pepecat','pepe'),
('CAT','2000-01-01 01:01:01','Max','juan'), ('CAT','2000-01-01 01:01:01','Max','juan'),
('DOG','2000-01-01 01:01:01','Juandog','juan'), ('DOG','2000-01-01 01:01:01','Juandog','juan'),
('CAT','2000-01-01 01:01:01','Anacat','ana'), ('CAT','2000-01-01 01:01:01','Anacat','ana'),
('DOG','2000-01-01 01:01:01','Max','ana'), ('DOG','2000-01-01 01:01:01','Max','ana'),
('BIRD','2000-01-01 01:01:01','Anabird','ana'); ('BIRD','2000-01-01 01:01:01','Anabird','ana');
``` ```
You can find the `xcs-sample-mysql.sql` and `xcs-sample-test-mysql.sql` scripts You can find the `xcs-sample-mysql.sql` and `xcs-sample-test-mysql.sql` scripts
with these queries stored in the `additional-material/db` project folder. with these queries stored in the `additional-material/db` project folder.
### Wildfly 8 ### 1.5. Eclipse Neon for Java EE
Before we can run the project, we need to configure a WildFly server to include Open Eclipse Neon for Java EE and import your Maven project with
the datasource used by the application and the security configuration. `File -> Import -> Maven -> Existing Maven Projects`. In the dialog opened you
have to select as `Root directory` the directory of the project that you have
just cloned (it should contain a `pom.xml` file).
Eclipse should then import a parent project (`xcs-sample`) and 6 child projects
(`tests`, `domain`, `service`, `rest`, `jsf` and `ear`). If any project is
disabled for import it is probably because you already have another project in
your workspace with the same name. To avoid this problem you can open the
advanced settings of the dialog and use a custom `Name template` (for example,
`xcs-sample-[artifactId]`).
If you want, you can use any other IDE, such as IntelliJ IDEA or NetBeans, as
long as they are compatible with Maven projects, but we recommend using Eclipse
Neon for Java EE.
### 1.6 WildFly 8.2.1
If you want to run the project you need a Java EE server. In this section you
can find how to configure a local WildFly server to execute the project.
Basically, we need to configure the WildFly server to include the datasource and
the security configuration needed by the application.
In the following sections you can find an explanation of how you can configure In the following sections you can find an explanation of how you can configure
the WildFly server by editing the `standalone.xml`. However, the the WildFly server by editing the `standalone.xml`. However, the
`additional-material/wildfly` folder includes a `standalone.xml` ready to be `additional-material/wildfly` directory of the project includes a
used that you can just copy to your WildFly server (replacing the original `standalone.xml` ready to be used that you can just copy to your WildFly server
`standalone/configuration/standalone.xml` file). (replacing the original `standalone/configuration/standalone.xml` file).
#### Datasource #### 1.6.1. Datasource configuration
There are several ways to add a datasource to a WildFly server. We are going to There are several ways to add a datasource to a WildFly server. We are going to
add a new datasource to the `standalone/configuration/standalone.xml` add it by editing the `standalone/configuration/standalone.xml` configuration
configuration file of the server. To do so, you have to edit this file and add file of the server. To do so, you have to edit this file and add the following
the following content to the `<datasources>` element: content to the `<datasources>` element:
```xml ```xml
<datasource jndi-name="java:jboss/datasources/xcs" pool-name="MySQLPool"> <datasource jndi-name="java:jboss/datasources/xcs" pool-name="MySQLPool">
<connection-url>jdbc:mysql://localhost:3306/xcs</connection-url> <connection-url>jdbc:mysql://localhost:3306/xcs</connection-url>
<driver>mysql-connector-java-5.1.21.jar</driver> <driver>mysql-connector-java-5.1.21.jar</driver>
<pool> <pool>
<max-pool-size>30</max-pool-size> <max-pool-size>30</max-pool-size>
</pool> </pool>
<security> <security>
<user-name>xcs</user-name> <user-name>xcs</user-name>
<password>xcs</password> <password>xcs</password>
</security> </security>
</datasource> </datasource>
``` ```
In addition, you also have to add the MySQL driver to the deployments folder In addition, you also have to add the MySQL driver to the deployments folder
(`standalone/deployments`). You can download it form [here](http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.21/mysql-connector-java-5.1.21.jar) (`standalone/deployments`). You can download it form [here](http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.21/mysql-connector-java-5.1.21.jar)
to the deployments folder and Wildfly will automatically deploy it. to the deployments (`standalone/deployments`) directory and WildFly will
automatically deploy it on startup.
#### Security configuration #### 1.6.2. Security configuration
All the WildFly security configuration is done in the All the WildFly security configuration is done in the
`standalone/configuration/standalone.xml` file of the server. `standalone/configuration/standalone.xml` file of the server.
Inside the `<security-reamls>` element you have to add: Inside the `<security-reamls>` element you have to add a new security realm:
```xml ```xml
<security-realm name="RemotingRealm"> <security-realm name="RemotingRealm">
<authentication> <authentication>
<jaas name="AppRealmLoopThrough"/> <jaas name="AppRealmLoopThrough"/>
</authentication> </authentication>
</security-realm> </security-realm>
``` ```
And inside the `<security-domains>` element you have to add: Then, inside the `<security-domains>` element you have to add the following
security domains:
```xml ```xml
<security-domain name="AppRealmLoopThrough" cache-type="default"> <security-domain name="AppRealmLoopThrough" cache-type="default">
<authentication> <authentication>
<login-module code="Client" flag="required"> <login-module code="Client" flag="required">
<module-option name="multi-threaded" value="true"/> <module-option name="multi-threaded" value="true"/>
</login-module> </login-module>
</authentication> </authentication>
</security-domain> </security-domain>
<security-domain name="xcs-sample-security-domain"> <security-domain name="xcs-sample-security-domain">
<authentication> <authentication>
<login-module code="Database" flag="required"> <login-module code="Database" flag="required">
<module-option name="dsJndiName" value="java:jboss/datasources/xcs"/> <module-option name="dsJndiName" value="java:jboss/datasources/xcs"/>
<module-option name="principalsQuery" value="SELECT password FROM User WHERE login=?"/> <module-option name="principalsQuery" value="SELECT password FROM User WHERE login=?"/>
<module-option name="rolesQuery" value="SELECT role, 'Roles' FROM User WHERE login=?"/> <module-option name="rolesQuery" value="SELECT role, 'Roles' FROM User WHERE login=?"/>
<module-option name="hashAlgorithm" value="MD5"/> <module-option name="hashAlgorithm" value="MD5"/>
<module-option name="hashEncoding" value="hex"/> <module-option name="hashEncoding" value="hex"/>
<module-option name="ignorePasswordCase" value="true"/> <module-option name="ignorePasswordCase" value="true"/>
</login-module> </login-module>
</authentication> </authentication>
</security-domain> </security-domain>
``` ```
#### Deploying the application #### 1.6.3. Deploying the application manually
When the `package` goal is run in the `xcs-sample` project, an EAR file is When the `package` goal is run in the `xcs-sample` project, an EAR file is
generated inside the `target` folder of the `ear` project. generated inside the `target` folder of the `ear` project.
...@@ -190,80 +212,104 @@ the entire application. To do so, you can copy this file to the ...@@ -190,80 +212,104 @@ the entire application. To do so, you can copy this file to the
Once this is done, you can run the WildFly server executing the Once this is done, you can run the WildFly server executing the
`bin/standalone.sh` script. The application should be running in `bin/standalone.sh` script. The application should be running in
`http://localhost:8080/`. http://localhost:8080/xcs-sample. If you want to access through the web
interface, you can open the http://localhost:8080/xcs-sample/jsf URL.
#### Running the application #### 1.6.4 Deploying the application from Maven
Maven configuration is prepared to deploy the generated EAR file to a running
WildFly. Doing so is as easy as launching the `wildfly:deploy` goal:
```bash
mvn wildfly:deploy
```
This will launch the construction of the project and, at the end, the EAR will
be deployed. Remember that, if you want a fast deployment, you can avoid the
test execution with the parameter `-DskipTests=true`.
#### 1.7. Running the application from Maven
This project includes the Maven WildFly plugin, which allows the execution of This project includes the Maven WildFly plugin, which allows the execution of
the project without needing an external WildFly server. To run the application the application without needing an external WildFly server. To run the
with the running MySQL database (`xcs`) you just have to go to the `ear` module application with the running MySQL database (`xcs`) you just have execute the
and execute the following command: following command:
```bash ```bash
mvn wildfly:start wildfly:deploy -P wildfly-embedded-mysql,-wildfly-embedded-h2 mvn install -P wildfly-mysql-run,-wildfly-embedded-h2
``` ```
This will launch the complete construction cycle (remember that you can skip
test execution adding the `-DskipTests=true` parameter), start a WildFly server
and deploy the application. Once the application is running you can access it
in the URL http://localhost:8080/xcs-sample/jsf.
Once the application is running you can access it in the URL `http://localhost:8080/xcs-sample/jsf`. **Important**: You shouldn't have a local WildFly instance running or Maven will
not be able to start its own WildFly and will try to deploy the application in
the running instance. This will cause changes to the WildFly configuration that
may leave it in an unstable state.
To stop the WildFly lauched you can execute the following command: To stop the WildFly lauched you can execute the following command:
```bash ```bash
mvn wildfly:shutdown mvn wildfly:shutdown
``` ```
## Sample 1: Testing entities ## 2. Samples
## 2.1. Sample 1: Testing entities
Using JUnit and Hamcrest, we will see how to test JPA entities or any other Using JUnit and Hamcrest, we will see how to test JPA entities or any other
Java class. This libraries are the base for every test done in the application. Java class. This libraries are the base for every test done in the application.
## Sample 2: Testing EJBs ## 2.2. Sample 2: Testing EJBs
Using Arquillian and Arquillian Persistence, the EJBs are tested. We wouldn't do Using Arquillian and Arquillian Persistence, the EJBs are tested. We wouldn't do
unit testing in this layer, as we don't want to mock the `EntityManager`. unit testing in this layer, as we don't want to mock the `EntityManager`.
In this layer we will use some workarounds to set the desired role and principal In this layer we will use some workarounds to set the desired role and principal
in the tests. in the tests.
### How to run tests with Arquillian? ### 2.2.1. How to run tests with Arquillian?
This project is configured to use two Maven profiles: This project is configured to use two Maven profiles:
* `wildfly-embedded-h2`: This profile uses Wildfly in embedded mode with the H2 * `wildfly-embedded-h2`: this profile uses WildFly in embedded mode with a H2
`ExampleDS` database that is included by default in this Java EE server (it has database, whose driver is included by default in WilFly.
the JNDI name `java:jboss/datasources/ExampleDS`). * `wildfly-embedded-mysql`: same as before, but it uses a MySQL database.
* `wildfly-embedded-mysql`: Same as before, but it uses a MySQL datasource with
the JNDI name `java:jboss/datasources/xcs`.
In both profiles, the Wildfly server is downloaded automatically using the In both profiles, the WildFly server is automatically downloaded using the
`maven-dependency-plugin`, that extracts it in the `target/wildfly-<version>` `maven-dependency-plugin`, that extracts it in the `target/wildfly-<version>`
folder (`target/wildfly-8.2.1.Final` currently). In the MySQL profile, the MySQL folder (`target/wildfly-8.2.1.Final` currently). In the MySQL profile, the MySQL
driver is also downloaded using this plugin and added to the driver is also downloaded using this plugin and added to the
`target/wildfly-<version>/standalone/deployments` folder, to make it available `target/wildfly-<version>/standalone/deployments` folder, to make it available
in the Wildfly server. in the WildFly server.
For each profile, Maven is configured to use the files stored in For each profile, Maven is configured to use the files stored in
`src/test/resources-<profile name>` as resources when running tests, in addition `src/test/resources-<profile name>` as resources when running tests, in addition
to the stored in the `src/test/resources` folder, as usual. Inside this folder, to the stored in the `src/test/resources` folder, as usual. Inside this folder,
the projects using Arquillian must include a `standalone.xml` file, that will be the projects using Arquillian must include a `standalone.xml` file, that will be
replace the default `standalone.xml` file of the Wildfly server. This is replace the default `standalone.xml` file of the WildFly server. This is
specially useful to configure the security constraints. The MySQL resources specially useful to configure the security constraints and datasources.
folder must also include a `mysql-ds.xml` file, with the MySQL datasource
configuration that will be added to the Wildfly server. In order to avoid port collising with other WildFly instances, the WildFly used
by the test have a port offset of 10000. This means that the HTTP port is
displaced from the default 8080 port to the 18080 port, and the management port
is displaced from the default 9990 port to the 19990 port.
Therefore, when running Maven tests (e.g. `mvn test`), they will run without any Therefore, when running Maven tests (e.g. `mvn test`), they will run without any
external requirement. external requirement.
#### Arquillian tests in Eclipse #### 2.2.1.1 Arquillian tests in Eclipse
To run Arquillian tests in Eclipse (or in any non-Maven enviroment) a further To run Arquillian tests in Eclipse (or in any non-Maven enviroment) a further
step is needed. You must configure the following system properties: step is needed. You must configure the following system properties:
* `java.util.logging.manager`: The logger to be used by the standard Java * `java.util.logging.manager`: the logger to be used by the standard Java
logger. Commonly, the value `org.jboss.logmanager.LogManager` is used. logger. Commonly, the value `org.jboss.logmanager.LogManager` is used.
* `wildfly.version`: The version of the Wildfly server stored in `target`. * `wildfly.version`: the version of the WildFly server stored in `target`.
The current version is `8.2.1.Final`. The current version is `8.2.1.Final`.
In Eclipse, this system properties can be added to the run configuration in the In Eclipse, this system properties can be added to the run configuration in the
`VM arguments` field of the `Arguments` tab. For example, the following `VM arguments` field of the `Arguments` tab. For example, the following
configuration will work for the current configuration: configuration will work for the current configuration:
``` ```
-Dwildfly.version=8.2.1.Final -Dwildfly.version=8.2.1.Final
-Djava.util.logging.manager=org.jboss.logmanager.LogManager -Djava.util.logging.manager=org.jboss.logmanager.LogManager
``` ```
This configuration will run with the **h2** database. If you wish to run the
This configuration will run with the **H2** database. If you wish to run the
tests with the **MySQL** database, you have to add to additional system tests with the **MySQL** database, you have to add to additional system
configuration: configuration:
* `mysql.version`: The version of the MySQL driver (currently, `5.1.21`). This * `mysql.version`: The version of the MySQL driver (currently, `5.1.21`). This
...@@ -273,6 +319,7 @@ by Arquillian. It should be `wildfly-embedded-mysql` to use the MySQL profile. ...@@ -273,6 +319,7 @@ by Arquillian. It should be `wildfly-embedded-mysql` to use the MySQL profile.
Therefore, the `VM arguments` configuration for running the tests in Eclipse Therefore, the `VM arguments` configuration for running the tests in Eclipse
using the MySQL database is: using the MySQL database is:
``` ```
-Dwildfly.version=8.2.1.Final -Dwildfly.version=8.2.1.Final
-Djava.util.logging.manager=org.jboss.logmanager.LogManager -Djava.util.logging.manager=org.jboss.logmanager.LogManager
...@@ -280,30 +327,30 @@ using the MySQL database is: ...@@ -280,30 +327,30 @@ using the MySQL database is:
-Darquillian.launch=wildfly-embedded-mysql -Darquillian.launch=wildfly-embedded-mysql
``` ```
## Sample 3: Testing with test doubles ## 2.3. Sample 3: Testing with test doubles
Using EasyMock, we will mock the EJBs to test the REST classes isolated from the Using EasyMock, we will mock the EJBs to test the REST classes isolated from the
underlying layer. underlying layer.
## Sample 4: Testing JAX-RS ## 2.4. Sample 4: Testing JAX-RS
Using Arquillian REST Client, we will test the REST API accessing it as real Using Arquillian REST Client, we will test the REST API accessing it as real
HTTP clients. HTTP clients.
Tests can be run using the same configuration as explained in *Sample 2*. Tests can be run using the same configuration as explained in *Sample 2*.
When executed, the REST resources can be found in: When executed, the REST resources can be found in:
* Owners: `http://localhost:8080/rest/api/owner` * Owners: http://localhost:8080/xcs-sample/rest/api/owner
* Pets: `http://localhost:8080/rest/api/pet` * Pets: http://localhost:8080/xcs-sample/rest/api/pet
## Sample 5: Testing JSF ## 2.5. Sample 5: Testing JSF
Using Arquillian Drone, Arquillian Graphene and Selenium, we will test the JSF Using Arquillian Drone, Arquillian Graphene and Selenium, we will test the JSF
web interface accessing it as real Web clients. web interface accessing it as real Web clients.
Tests can be run using the same configuration as explained in *Sample 2*. Tests can be run using the same configuration as explained in *Sample 2*.
When executed, the REST resources can be found in When executed, the REST resources can be found in
`http://localhost:8080/jsf/faces/index.html`. http://localhost:8080/xcs-sample/jsf/faces/index.html.
## Sample 6: Additional Testing Tools ## 2.6. Sample 6: Additional Testing Tools
### Test coverage with JaCoCo ### Test coverage with JaCoCo
Test coverage is a very useful tool that shows the parts of the source code that Test coverage is a very useful tool that shows the parts of the source code that
are covered by the tests. The coverage analysis is done during the tests are covered by the tests. The coverage analysis is done during the tests
......
...@@ -399,7 +399,7 @@ ...@@ -399,7 +399,7 @@
</interface> </interface>
</interfaces> </interfaces>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="0"> <socket-binding-group name="standard-sockets" default-interface="public" port-offset="10000">
<socket-binding name="management-http" interface="management" port="9990"/> <socket-binding name="management-http" interface="management" port="9990"/>
<socket-binding name="management-https" interface="management" port="9993"/> <socket-binding name="management-https" interface="management" port="9993"/>
<socket-binding name="ajp" port="8009"/> <socket-binding name="ajp" port="8009"/>
......
...@@ -408,7 +408,7 @@ ...@@ -408,7 +408,7 @@
</interface> </interface>
</interfaces> </interfaces>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="0"> <socket-binding-group name="standard-sockets" default-interface="public" port-offset="10000">
<socket-binding name="management-http" interface="management" port="9990"/> <socket-binding name="management-http" interface="management" port="9990"/>
<socket-binding name="management-https" interface="management" port="9993"/> <socket-binding name="management-https" interface="management" port="9993"/>
<socket-binding name="ajp" port="8009"/> <socket-binding name="ajp" port="8009"/>
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
<configuration> <configuration>
<property name="jbossHome">target/wildfly-${wildfly.version}</property> <property name="jbossHome">target/wildfly-${wildfly.version}</property>
<property name="modulePath">target/wildfly-${wildfly.version}/modules</property> <property name="modulePath">target/wildfly-${wildfly.version}/modules</property>
<property name="managementPort">19990</property>
</configuration> </configuration>
<protocol type="Servlet 3.0">
<property name="port">18080</property>
</protocol>
</container> </container>
</arquillian> </arquillian>
\ No newline at end of file
...@@ -474,58 +474,153 @@ ...@@ -474,58 +474,153 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<before-deployment>
<batch/>
<commands>
<command>data-source add --jndi-name=java:jboss/datasources/xcs --name=xcs-sample --jta=true --use-ccm=true --connection-url=jdbc:h2:mem:xcs;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE --driver-name=h2 --user-name=xcs --password=xcs</command>
<command>/core-service=management/security-realm=RemotingRealm:add</command>
<command>/core-service=management/security-realm=RemotingRealm/authentication=jaas:add(name="AppRealmLoopThrough")</command>
<command>/subsystem=remoting/http-connector=http-remoting-connector:write-attribute(name="security-realm", value="RemotingRealm")</command>
<command>/subsystem=security/security-domain=AppRealmLoopThrough:add(cache-type=default)</command>
<command>/subsystem=security/security-domain=AppRealmLoopThrough/authentication=classic:add(login-modules=[{"code"=>"Client", "flag" => "required", "module-options" => [("multi-threaded" => "true")]}])</command>
<command>/subsystem=security/security-domain=xcs-sample-security-domain:add</command>
<command>/subsystem=security/security-domain=xcs-sample-security-domain/authentication=classic:add(login-modules=[{"code"=>"Database", "flag" => "required", "module-options" => [("dsJndiName" => "java:jboss/datasources/xcs"),("principalsQuery" => "SELECT password FROM User WHERE login=?"),("rolesQuery" => "SELECT role, 'Roles' FROM User WHERE login=?"),("hashAlgorithm" => "MD5"),("hashEncoding" => "hex"),("ignorePasswordCase" => "true")]}])</command>
</commands>
</before-deployment>
<after-deployment>
<commands>
<command>:reload</command>
</commands>
</after-deployment>
<add-user>
<users>
<user>
<username>wildfly-admin</username>
<password>xcsadmin</password>
<applicationUser>false</applicationUser>
</user>
<user>
<username>admin</username>
<password>adminpass</password>
<applicationUser>true</applicationUser>
<groups>ADMIN</groups>
</user>
<user>
<username>owner</username>
<password>ownerpass</password>
<applicationUser>true</applicationUser>
<groups>OWNER</groups>
</user>
</users>
</add-user>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</profile> </profile>
<profile> <profile>
<id>wildfly-embedded-mysql</id> <id>wildfly-embedded-mysql</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-embedded</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-embedded</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/resources-wildfly-embedded-mysql</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<mysql.version>${mysql.connector.java.version}</mysql.version>
<wildfly.version>${wildfly.version}</wildfly.version>
<arquillian.launch>wildfly-embedded</arquillian.launch>
</systemPropertyVariables>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>${wildfly.version}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>copy-mysql</id>
<phase>process-test-classes</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/wildfly-${wildfly.version}/standalone/deployments</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>copy-mysql-for-execution</id>
<phase>process-test-classes</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>mysql-connector-java-${mysql.connector.java.version}.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
<!-- This JAR will be used for executing the Wildfly server -->
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-wildfly-resources</id>
<phase>process-test-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/wildfly-${wildfly.version}/standalone/configuration</outputDirectory>
<resources>
<resource>
<directory>src/test/resources-wildfly-embedded-mysql</directory>
<include>standalone.xml</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>wildfly-mysql-run</id>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.wildfly</groupId> <groupId>org.wildfly</groupId>
...@@ -692,6 +787,16 @@ ...@@ -692,6 +787,16 @@
</users> </users>
</add-user> </add-user>
</configuration> </configuration>
<executions>
<execution>
<id>start-wildfly</id>
<phase>install</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
......
...@@ -399,7 +399,7 @@ ...@@ -399,7 +399,7 @@
</interface> </interface>
</interfaces> </interfaces>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="0"> <socket-binding-group name="standard-sockets" default-interface="public" port-offset="10000">
<socket-binding name="management-http" interface="management" port="9990"/> <socket-binding name="management-http" interface="management" port="9990"/>
<socket-binding name="management-https" interface="management" port="9993"/> <socket-binding name="management-https" interface="management" port="9993"/>
<socket-binding name="ajp" port="8009"/> <socket-binding name="ajp" port="8009"/>
......
...@@ -408,7 +408,7 @@ ...@@ -408,7 +408,7 @@
</interface> </interface>
</interfaces> </interfaces>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="0"> <socket-binding-group name="standard-sockets" default-interface="public" port-offset="10000">
<socket-binding name="management-http" interface="management" port="9990"/> <socket-binding name="management-http" interface="management" port="9990"/>
<socket-binding name="management-https" interface="management" port="9993"/> <socket-binding name="management-https" interface="management" port="9993"/>
<socket-binding name="ajp" port="8009"/> <socket-binding name="ajp" port="8009"/>
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
<configuration> <configuration>
<property name="jbossHome">target/wildfly-${wildfly.version}</property> <property name="jbossHome">target/wildfly-${wildfly.version}</property>
<property name="modulePath">target/wildfly-${wildfly.version}/modules</property> <property name="modulePath">target/wildfly-${wildfly.version}/modules</property>
<property name="managementPort">19990</property>
</configuration> </configuration>
<protocol type="Servlet 3.0">
<property name="port">18080</property>
</protocol>
</container> </container>
</arquillian> </arquillian>
\ No newline at end of file
...@@ -399,7 +399,7 @@ ...@@ -399,7 +399,7 @@
</interface> </interface>
</interfaces> </interfaces>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="0"> <socket-binding-group name="standard-sockets" default-interface="public" port-offset="10000">
<socket-binding name="management-http" interface="management" port="9990"/> <socket-binding name="management-http" interface="management" port="9990"/>
<socket-binding name="management-https" interface="management" port="9993"/> <socket-binding name="management-https" interface="management" port="9993"/>
<socket-binding name="ajp" port="8009"/> <socket-binding name="ajp" port="8009"/>
......
...@@ -408,7 +408,7 @@ ...@@ -408,7 +408,7 @@
</interface> </interface>
</interfaces> </interfaces>
<socket-binding-group name="standard-sockets" default-interface="public" port-offset="0"> <socket-binding-group name="standard-sockets" default-interface="public" port-offset="10000">
<socket-binding name="management-http" interface="management" port="9990"/> <socket-binding name="management-http" interface="management" port="9990"/>
<socket-binding name="management-https" interface="management" port="9993"/> <socket-binding name="management-https" interface="management" port="9993"/>
<socket-binding name="ajp" port="8009"/> <socket-binding name="ajp" port="8009"/>
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
<configuration> <configuration>
<property name="jbossHome">target/wildfly-${wildfly.version}</property> <property name="jbossHome">target/wildfly-${wildfly.version}</property>
<property name="modulePath">target/wildfly-${wildfly.version}/modules</property> <property name="modulePath">target/wildfly-${wildfly.version}/modules</property>
<property name="managementPort">19990</property>
</configuration> </configuration>
<protocol type="Servlet 3.0">
<property name="port">18080</property>
</protocol>
</container> </container>
</arquillian> </arquillian>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment