Package org.silverpeas.core.test
Class WarBuilder<T extends WarBuilder<T>>
- java.lang.Object
-
- org.silverpeas.core.test.WarBuilder<T>
-
- All Implemented Interfaces:
Builder<org.jboss.shrinkwrap.api.spec.WebArchive>
,CommonArchive<CommonWebArchive<T>>
,CommonWebArchive<T>
- Direct Known Subclasses:
BasicWarBuilder
public abstract class WarBuilder<T extends WarBuilder<T>> extends Object implements Builder<org.jboss.shrinkwrap.api.spec.WebArchive>, CommonWebArchive<T>
This class permits to setup an integration test- Author:
- Yohann Chastagnier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
WarBuilder.TestFocus<T extends WarBuilder<T>>
In order to highlight the specification of tested classes, packages or resources.-
Nested classes/interfaces inherited from interface org.silverpeas.core.test.CommonArchive
CommonArchive.OnShrinkWrapWar
-
-
Field Summary
Fields Modifier and Type Field Description protected Collection<String>
jarLibForPersistence
protected Collection<String>
mavenDependencies
protected Collection<String>
mavenDependenciesWithoutTransitivity
protected Collection<String>
webParts
-
Constructor Summary
Constructors Modifier Constructor Description protected
WarBuilder(Class<U> classOfTest)
Constructs a war builder for the specified test class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WarBuilder<T>
addAsResource(String resourceName)
Adds the resource as a resource to the container, returning the container itself.WarBuilder<T>
addAsResource(String resourceName, String target)
Adds the resource as a resource to the container, returning the container itself.WarBuilder<T>
addAsWebInfResource(String resourceName, String target)
Adds the resource as a WEB-INF resource to the container, returning the container itself.WarBuilder<T>
addAsWebInfResource(org.jboss.shrinkwrap.api.asset.Asset resource, String target)
Adds theAsset
as a WEB-INF resource to the container, returning the container itself.WarBuilder<T>
addClasses(Class<?>... classes)
WarBuilder<T>
addMavenDependencies(String... mavenDependencies)
Adds the specified maven dependencies with their transitive dependencies that are defined in the pom.xml of the project.WarBuilder<T>
addMavenDependenciesWithoutTransitivity(String... mavenDependencies)
Adds the specified maven dependencies without their transitive dependencies that are defined in the pom.xml of the project.WarBuilder<T>
addMavenDependenciesWithPersistence(String... mavenDependencies)
Adds the specified maven dependencies with their transitive dependencies that are defined in the pom.xml of the project.WarBuilder<T>
addPackages(boolean recursive, String... packages)
Adds all classes in the specifiedPackage
s to theArchive
.WarBuilder<T>
addWebListener(Class<? extends EventListener> webListenerClass)
Adds the specified web servlet listener.WarBuilder<T>
applyManually(CommonArchive.OnShrinkWrapWar onShrinkWrapWar)
Applies a configuration by using directly theWebArchive
instance provided by the ShrinkWrap API.org.jboss.shrinkwrap.api.spec.WebArchive
build()
Builds the final WAR archive.boolean
contains(Class<?> aClass)
Denotes whether this archive contains a classboolean
contains(String path)
Denotes whether this archive contains a resource at the specified pathWarBuilder<T>
createMavenDependencies(String... mavenDependencies)
Creates a maven dependencies (when not declared in the pom.xml of the current project).WarBuilder<T>
createMavenDependenciesWithPersistence(String... mavenDependencies)
Creates a maven dependencies (when not declared in the pom.xml of the current project).WarBuilder<T>
deleteClasses(Class<?>... classes)
Deletes theClass
es in theArchive
.WarBuilder<T>
initJcrSchema()
The test implied code that uses the JCR.protected Predicate<File>
onLibsToInclude()
Gets a predicate on libraries (represented each of them by a file) to indicate if a library is accepted or not to be included among the dependencies of a WAR to build for integration tests ran by Arquillian.WarBuilder<T>
testFocusedOn(WarBuilder.TestFocus<T> testFocus)
Applies the configuration that the test is focused on.
-
-
-
Field Detail
-
mavenDependencies
protected Collection<String> mavenDependencies
-
mavenDependenciesWithoutTransitivity
protected Collection<String> mavenDependenciesWithoutTransitivity
-
jarLibForPersistence
protected Collection<String> jarLibForPersistence
-
webParts
protected Collection<String> webParts
-
-
Constructor Detail
-
WarBuilder
protected WarBuilder(Class<U> classOfTest)
Constructs a war builder for the specified test class. It will load all the resources in the same packages of the specified test class.- Type Parameters:
U
- the type of the test.- Parameters:
classOfTest
- the class of the test for which a war archive will be build.
-
-
Method Detail
-
createMavenDependencies
public WarBuilder<T> createMavenDependencies(String... mavenDependencies)
Creates a maven dependencies (when not declared in the pom.xml of the current project). Each of the specified dependencies must be expressed in the canonical form
If the version isn't specified, then it is figured out from the<groupId>:<artifactId>[:<version>]
maven.properties
file. A property<artifactId>.version
is first looked for and if not found, the silverpeas version is then used.- Parameters:
mavenDependencies
- the canonical maven dependencies to add.- Returns:
- the instance of the configurator.
-
createMavenDependenciesWithPersistence
public WarBuilder<T> createMavenDependenciesWithPersistence(String... mavenDependencies)
Creates a maven dependencies (when not declared in the pom.xml of the current project). Each of the specified dependencies must be expressed in the canonical form
If the version isn't specified, then it is figured out from the<groupId>:<artifactId>[:<version>]
maven.properties
file. A property<artifactId>.version
is first looked for and if not found, the silverpeas version is then used. The artifacts are then referenced in the persistence descriptor so that the entities and repositories are taken in charge by the persistence layer.- Parameters:
mavenDependencies
- the canonical maven dependencies to add.- Returns:
- the instance of the configurator.
- Throws:
IllegalArgumentException
- if no version if found for one of the specified Maven dependencies.
-
addMavenDependencies
public WarBuilder<T> addMavenDependencies(String... mavenDependencies)
Adds the specified maven dependencies with their transitive dependencies that are defined in the pom.xml of the project. Each of the specified dependencies must be expressed in the canonical form<groupId>:<artifactId>[:<version>]
- Parameters:
mavenDependencies
- the canonical maven dependencies to add.- Returns:
- the instance of the configurator.
-
addMavenDependenciesWithPersistence
public WarBuilder<T> addMavenDependenciesWithPersistence(String... mavenDependencies)
Adds the specified maven dependencies with their transitive dependencies that are defined in the pom.xml of the project. Each of the specified dependencies must be expressed in the canonical form
. The artifacts are then referenced in the persistence descriptor so that the entities and repositories are taken in charge by the persistence layer. For doing, in the case the version isn't specified in the canonical form of the dependency, it is figured out from the<groupId>:<artifactId>[:<version>]
maven.properties
file. A property<artifactId>.version
is first looked for and if not found, the silverpeas version is then used.- Parameters:
mavenDependencies
- the canonical maven dependencies to add.- Returns:
- the instance of the configurator.
-
addMavenDependenciesWithoutTransitivity
public WarBuilder<T> addMavenDependenciesWithoutTransitivity(String... mavenDependencies)
Adds the specified maven dependencies without their transitive dependencies that are defined in the pom.xml of the project. Each of the specified dependencies must be expressed in the canonical form<groupId>:<artifactId>[:<version>]
- Parameters:
mavenDependencies
- the canonical maven dependencies to add.- Returns:
- the instance of the configurator.
-
addWebListener
public WarBuilder<T> addWebListener(Class<? extends EventListener> webListenerClass)
Adds the specified web servlet listener.- Parameters:
webListenerClass
- the class of the web listener to add.- Returns:
- the instance of the configurator.
-
contains
public boolean contains(Class<?> aClass) throws IllegalArgumentException
Description copied from interface:CommonArchive
Denotes whether this archive contains a class- Specified by:
contains
in interfaceCommonArchive<T extends WarBuilder<T>>
- Parameters:
aClass
- a class- Returns:
- true if the archive contains the class, false otherwise.
- Throws:
IllegalArgumentException
- If the path is not specified
-
contains
public boolean contains(String path) throws IllegalArgumentException
Description copied from interface:CommonArchive
Denotes whether this archive contains a resource at the specified path- Specified by:
contains
in interfaceCommonArchive<T extends WarBuilder<T>>
- Parameters:
path
- the path of the resource- Returns:
- true if the archive contains the resource, false otherwise
- Throws:
IllegalArgumentException
- If the path is not specified
-
deleteClasses
public WarBuilder<T> deleteClasses(Class<?>... classes)
Description copied from interface:CommonArchive
Deletes theClass
es in theArchive
.- Specified by:
deleteClasses
in interfaceCommonArchive<T extends WarBuilder<T>>
- Parameters:
classes
- the classes to delete in the archive.- Returns:
- this archive.
-
addClasses
public WarBuilder<T> addClasses(Class<?>... classes) throws IllegalArgumentException
Description copied from interface:CommonArchive
- Specified by:
addClasses
in interfaceCommonArchive<T extends WarBuilder<T>>
- Parameters:
classes
- The classes to add to the Archive- Returns:
- This archive
- Throws:
IllegalArgumentException
- If no classes were specified
-
addPackages
public WarBuilder<T> addPackages(boolean recursive, String... packages) throws IllegalArgumentException
Description copied from interface:CommonArchive
Adds all classes in the specifiedPackage
s to theArchive
.- Specified by:
addPackages
in interfaceCommonArchive<T extends WarBuilder<T>>
- Parameters:
recursive
- Should the sub packages be addedpackages
- All the packages to add represented by a String ("my/package")- Returns:
- This virtual archive
- Throws:
IllegalArgumentException
- If no packages were specified- See Also:
ClassContainer.addPackages(boolean, Filter, Package...)
-
addAsResource
public WarBuilder<T> addAsResource(String resourceName) throws IllegalArgumentException
Description copied from interface:CommonArchive
Adds the resource as a resource to the container, returning the container itself.
The resource will be placed into the Container Resource path under the same context from which it was retrieved.
TheClassLoader
used to obtain the resource is up to the implementation.- Specified by:
addAsResource
in interfaceCommonArchive<T extends WarBuilder<T>>
- Parameters:
resourceName
- resource to add- Returns:
- This virtual archive
- Throws:
IllegalArgumentException
- If the resourceName is null- See Also:
ResourceContainer.addAsResource(Asset, ArchivePath)
-
addAsResource
public WarBuilder<T> addAsResource(String resourceName, String target) throws IllegalArgumentException
Description copied from interface:CommonArchive
Adds the resource as a resource to the container, returning the container itself.
TheClassLoader
used to obtain the resource is up to the implementation.- Specified by:
addAsResource
in interfaceCommonArchive<T extends WarBuilder<T>>
- Parameters:
resourceName
- resource to addtarget
- The target path within the archive in which to add the resource, relative to theArchive
s resource path.- Returns:
- This virtual archive
- Throws:
IllegalArgumentException
- if resourceName is null or if target is null- See Also:
ResourceContainer.addAsResource(Asset, ArchivePath)
-
addAsWebInfResource
public WarBuilder<T> addAsWebInfResource(String resourceName, String target) throws IllegalArgumentException
Description copied from interface:CommonWebArchive
Adds the resource as a WEB-INF resource to the container, returning the container itself.
TheClassLoader
used to obtain the resource is up to the implementation.- Specified by:
addAsWebInfResource
in interfaceCommonWebArchive<T extends WarBuilder<T>>
- Parameters:
resourceName
- resource to addtarget
- The target path within the archive in which to add the resource, relative to theArchive
s WEB-INF path.- Returns:
- This
Archive
- Throws:
IllegalArgumentException
- if resourceName or target is not specified
-
addAsWebInfResource
public WarBuilder<T> addAsWebInfResource(org.jboss.shrinkwrap.api.asset.Asset resource, String target) throws IllegalArgumentException
Description copied from interface:CommonWebArchive
Adds theAsset
as a WEB-INF resource to the container, returning the container itself.- Specified by:
addAsWebInfResource
in interfaceCommonWebArchive<T extends WarBuilder<T>>
- Parameters:
resource
-Asset
resource to addtarget
- The target path within the archive in which to add the resource, relative to theArchive
s WEB-INF path.- Returns:
- This
Archive
- Throws:
IllegalArgumentException
- If the resource or target is not specified
-
initJcrSchema
public WarBuilder<T> initJcrSchema()
The test implied code that uses the JCR. So initialize the JCR schema of Silverpeas.- Returns:
- itself.
-
build
public final org.jboss.shrinkwrap.api.spec.WebArchive build()
Builds the final WAR archive. The following stuffs are automatically added:- The beans.xml descriptor in order to activate CDI,
- The META-INF/services/org.silverpeas.core.util.BeanContainer service file to load the CDI-based bean container,
- Specified by:
build
in interfaceBuilder<T extends WarBuilder<T>>
- Returns:
- the built WAR archive.
-
onLibsToInclude
protected Predicate<File> onLibsToInclude()
Gets a predicate on libraries (represented each of them by a file) to indicate if a library is accepted or not to be included among the dependencies of a WAR to build for integration tests ran by Arquillian.- Returns:
- a predicate on a file (a given library)
-
testFocusedOn
public final WarBuilder<T> testFocusedOn(WarBuilder.TestFocus<T> testFocus)
Applies the configuration that the test is focused on.- Parameters:
testFocus
- the instance of an anonymous implementation ofWarBuilder.TestFocus
interface.- Returns:
- the instance of the war builder.
-
applyManually
public final WarBuilder<T> applyManually(CommonArchive.OnShrinkWrapWar onShrinkWrapWar)
Applies a configuration by using directly theWebArchive
instance provided by the ShrinkWrap API.- Specified by:
applyManually
in interfaceCommonArchive<T extends WarBuilder<T>>
- Parameters:
onShrinkWrapWar
- the instance of an anonymous implementation ofCommonArchive.OnShrinkWrapWar
interface.- Returns:
- the instance of the war builder.
-
-