:imagesdir: images
= The Simplest "Micro" Deployment (ArqTip #2)
The second Arquillian tip is the simplest “micro” deployment. Its a Arquillian deployment that uses the hole project as deployment with no need for adding individual classes, packages or libraries:
image::simplest-deployment.png[]
[source,java,linenumbers]
----
@RunWith(Arquillian.class)
public class SimplestDeployment {
@Deployment
public static Archive> createDeployment() {
WebArchive war = ShrinkWrap.create(ZipImporter.class, "cdi-crud.war").
importFrom(new File("target/cdi-crud.war")).as(WebArchive.class);
war.addAsResource("persistence.xml", "META-INF/persistence.xml");//replace with test persistence
return war;
}
@Inject
CarService carService;
@Test
@UsingDataSet("car.yml")
public void shouldCountCars() {
assertNotNull(carService);
assertEquals(carService.crud().count(), 4);
}
}
----
This basically uses a previously builded project as deployment and just replaces its persistence.xml to use a https://github.com/rmpestano/cdi-crud/blob/cdi-crud-universe/src/test/resources/persistence.xml[test database^].
Compare it with a https://github.com/rmpestano/cdi-crud/blob/cdi-crud-universe/src/test/java/com/cdi/crud/util/Deployments.java#L27[traditional deployment here^].
Of course that this simplicity comes with a price:
. Its not a true micro deployment because it uses the hole application. If your application is big the deployment can take considerable time(seconds);
. You need to build the application before running the test. Here you lose a big advantage of Arquillian which is to *not build the application if a test (even functional tests) has failed*.
To overcome problem #2 you can execute the tests in surefire *integration-tests phase*:
[source,xml]
----
simple-deployment
maven-surefire-plugin
2.16
after-package
integration-test
test
false
**/*SimplestDeployment.java
----
There is an issue from 2012 in Arquillian issue tracker which address this feature of a “simplest deployment” using a single annotation, https://issues.jboss.org/browse/ARQ-74[see the issue here^].
Source code of this post can be found here: https://github.com/rmpestano/cdi-crud/blob/cdi-crud-universe/src/test/java/com/cdi/crud/it/SimplestDeployment.java
For any feedback and comments, see the original post: https://rpestano.wordpress.com/2015/11/12/the-simplest-micro-deployment-arqtip-2/.