org.jboss.cdi.tck.shrinkwrap
Class ArchiveBuilder<T extends ArchiveBuilder<T,A>,A extends org.jboss.shrinkwrap.api.Archive<A>>

java.lang.Object
  extended by org.jboss.cdi.tck.shrinkwrap.ArchiveBuilder<T,A>
Type Parameters:
T - Self type to enable abstract builder pattern
A - Final shrinkwrap archive
Direct Known Subclasses:
EnterpriseArchiveBuilder, WebArchiveBuilder

public abstract class ArchiveBuilder<T extends ArchiveBuilder<T,A>,A extends org.jboss.shrinkwrap.api.Archive<A>>
extends Object

Abstract shrinkwrap archive builder for JSR299 TCK arquillian test.

This is a base class for builders that try to solve most JBoss Test Harness to Arquillian migration issues. The main goal was to use CDI TCK 1.0 tests with minimum code changes.

Note that all arquillian tests running in as-client mode (including tests using ShouldThrowException) cannot contain testing related stuff like test class itself while arquillian is not repackaging test archive. That's why isAsClientMode has to be properly set.

In case of isTestArchive set to false this archive may not include any testing related stuff as it is probably part of another test archive.

Author:
Martin Kouba

Nested Class Summary
protected  class ArchiveBuilder.LibraryDescriptor
          Internal library descriptor.
protected  class ArchiveBuilder.ResourceDescriptor
          Internal resource descriptor.
protected  class ArchiveBuilder.ServiceProviderDescriptor
          Internal service provider descriptor.
 
Field Summary
protected  org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor
           
protected  ArchiveBuilder.ResourceDescriptor beansXml
           
protected  List<String> classes
           
protected  List<String> excludedClasses
           
protected  List<ArchiveBuilder.LibraryDescriptor> libraries
           
protected  List<ArchiveBuilder.ResourceDescriptor> manifestResources
           
protected  List<String> packages
           
protected  org.jboss.shrinkwrap.descriptor.api.persistence20.PersistenceDescriptor persistenceDescriptor
           
protected  List<ArchiveBuilder.ResourceDescriptor> resources
           
protected  List<ArchiveBuilder.ServiceProviderDescriptor> serviceProviders
           
protected  List<ArchiveBuilder.ResourceDescriptor> webResources
           
protected  ArchiveBuilder.ResourceDescriptor webXml
           
protected  org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor webXmlDescriptor
           
 
Constructor Summary
ArchiveBuilder()
           
 
Method Summary
 A build()
           
protected abstract  A buildInternal()
           
 String getName()
           
protected  boolean isAsClientMode()
           
 boolean isTestArchive()
           
 T notTestArchive()
          Mark this archive as non-testing.
protected  void processClasses(org.jboss.shrinkwrap.api.container.ClassContainer<?> archive)
          Process classes.
protected  void processLibraries(org.jboss.shrinkwrap.api.container.LibraryContainer<?> archive)
          Process libraries.
protected  void processManifestResources(org.jboss.shrinkwrap.api.container.ManifestContainer<?> archive)
          Process manifest resources.
protected  void processPackages(org.jboss.shrinkwrap.api.container.ClassContainer<?> archive)
          Process packages.
protected  void processResources(org.jboss.shrinkwrap.api.container.ResourceContainer<?> archive)
          Process resources.
abstract  T self()
           
 T withBeanLibrary(org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor, Class<?>... beanClasses)
          Add bean library that consists of defined bean classes; automatically include empty beans.xml and if any of defined classes implements Extension add corresponding service provider.
 T withBeanLibrary(Class<?>... beanClasses)
          Add bean library that consists of defined bean classes; automatically include empty beans.xml and if any of defined classes implements Extension add corresponding service provider.
 T withBeanLibrary(String name, org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor, Class<?>... beanClasses)
          Add bean library that consists of defined bean classes; automatically include empty beans.xml and if any of defined classes implements Extension add corresponding service provider.
 T withBeanLibrary(String name, Class<?>... beanClasses)
          Add bean library that consists of defined bean classes; automatically include empty beans.xml and if any of defined classes implements Extension add corresponding service provider.
 T withBeansXml(org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor)
          Add beans.xml descriptor created with shrinkwrap-descriptors.
 T withBeansXml(String beansXml)
          Add beans.xml located in src/main/resource/{testPackagePath}.
 T withClass(Class<?> clazz)
          Add class to archive.
 T withClasses(Class<?>... classes)
          Add classes to archive.
 T withDefaultPersistenceXml()
          Add default persistence.xml.
 T withEjbJarXml(String ejbJarXml)
          Add ejb-jar.xml located in src/main/resource/{testPackagePath} to META-INF/ejb-jar.xml.
 T withExcludedClass(String clazz)
          Specified class must be excluded from final archive unless also added via withClass(Class) or withClasses(Class...).
 T withExcludedClasses(String... classes)
          Specified classes must be excluded from final archive unless also added via withClass(Class) or withClasses(Class...).
 T withExtension(Class<? extends javax.enterprise.inject.spi.Extension> extensionClass)
          Add CDI extension.
 T withExtension(String extension)
          Add CDI extension located in src/main/resource/{testPackagePath} to META-INF/services/javax.enterprise.inject.spi.Extension.
 T withExtensions(Class<? extends javax.enterprise.inject.spi.Extension>... extensionClasses)
          Add CDI extensions.
 T withLibrary(org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor, boolean includeEmptyBeanXml, Class<?>... classes)
          Add library that consists of defined classes.
 T withLibrary(Class<?>... classes)
          Add library that consists of defined classes.
 T withLibrary(File library)
          Add library.
 T withLibrary(String name, org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor, boolean includeEmptyBeanXml, Class<?>... classes)
          Add library that consists of defined classes.
 T withManifestResource(String source)
          Add resource to META-INF.
 T withManifestResource(String source, boolean useTestPackageToLocateSource)
          Add resource to META-INF.
 T withManifestResource(String source, String target, boolean useTestPackageToLocateSource)
          Add resource to META-INF.
 T withName(String name)
          Change default archive name.
 T withPersistenceXml(org.jboss.shrinkwrap.descriptor.api.persistence20.PersistenceDescriptor persistenceDescriptor)
          Add persistence.xml descriptor created with shrinkwrap-descriptors.
 T withResource(String source)
          Add resource.
 T withResource(String source, boolean useTestPackageToLocateSource)
          Add resource.
 T withResource(String source, String target, boolean useTestPackageToLocateSource)
          Add resource.
 T withServiceProvider(ArchiveBuilder.ServiceProviderDescriptor serviceProvider)
          Add service provider.
 T withTestClass(Class<?> testClazz)
          Add test class to archive and set test class definition for configuration purpose.
 T withTestClassDefinition(Class<?> testClazz)
          Set test class definition for configuration purpose.
 T withTestClassPackage(Class<?> testClazz)
          Add all classes in the test class package to archive and set test class definition for configuration purpose.
 T withWebResource(String source)
          Add web resource.
 T withWebResource(String source, boolean useTestPackageToLocateSource)
          Add web resource.
 T withWebResource(String source, String target)
          Add web resource.
 T withWebResource(String source, String target, boolean useTestPackageToLocateSource)
          Add web resource.
 T withWebXml(String webXml)
          Add web.xml located in src/main/resource/{testPackagePath}.
 T withWebXml(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor webXml)
          Add web.xml descriptor created with shrinkwrap-descriptors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

beansXml

protected ArchiveBuilder.ResourceDescriptor beansXml

beansDescriptor

protected org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor

webXml

protected ArchiveBuilder.ResourceDescriptor webXml

webXmlDescriptor

protected org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor webXmlDescriptor

persistenceDescriptor

protected org.jboss.shrinkwrap.descriptor.api.persistence20.PersistenceDescriptor persistenceDescriptor

manifestResources

protected List<ArchiveBuilder.ResourceDescriptor> manifestResources

resources

protected List<ArchiveBuilder.ResourceDescriptor> resources

webResources

protected List<ArchiveBuilder.ResourceDescriptor> webResources

packages

protected List<String> packages

classes

protected List<String> classes

excludedClasses

protected List<String> excludedClasses

libraries

protected List<ArchiveBuilder.LibraryDescriptor> libraries

serviceProviders

protected List<ArchiveBuilder.ServiceProviderDescriptor> serviceProviders
Constructor Detail

ArchiveBuilder

public ArchiveBuilder()
Method Detail

withName

public T withName(String name)
Change default archive name.

Parameters:
name -
Returns:

withBeansXml

public T withBeansXml(String beansXml)
Add beans.xml located in src/main/resource/{testPackagePath}.

Do not use this in new tests - use withBeansXml(BeansDescriptor) instead.

Parameters:
beansXml -
Returns:
self

withBeansXml

public T withBeansXml(org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor)
Add beans.xml descriptor created with shrinkwrap-descriptors.

Parameters:
beansDescriptor -
Returns:
self

withExtension

public T withExtension(String extension)
Add CDI extension located in src/main/resource/{testPackagePath} to META-INF/services/javax.enterprise.inject.spi.Extension.

Do not use this in new tests - use withExtension(Class) instead.

Parameters:
extension -
Returns:
self

withExtension

public T withExtension(Class<? extends javax.enterprise.inject.spi.Extension> extensionClass)
Add CDI extension. This method does not add the specified extension class to the archive.

Parameters:
extensionClass -
Returns:
self

withExtensions

public T withExtensions(Class<? extends javax.enterprise.inject.spi.Extension>... extensionClasses)
Add CDI extensions. This method does not add the specified extension classes to the archive.

Parameters:
extensionClasses -
Returns:
self

withServiceProvider

public T withServiceProvider(ArchiveBuilder.ServiceProviderDescriptor serviceProvider)
Add service provider.

Parameters:
serviceProvider -
Returns:

withClass

public T withClass(Class<?> clazz)
Add class to archive.

Parameters:
clazz -
Returns:
self

withClasses

public T withClasses(Class<?>... classes)
Add classes to archive.

Parameters:
classes -
Returns:
self

withExcludedClass

public T withExcludedClass(String clazz)
Specified class must be excluded from final archive unless also added via withClass(Class) or withClasses(Class...). Useful for exluding some classes from package added via withPackage(Package).

Parameters:
clazz - Fully qualified class name
Returns:
self

withExcludedClasses

public T withExcludedClasses(String... classes)
Specified classes must be excluded from final archive unless also added via withClass(Class) or withClasses(Class...). Useful for exluding some classes from package added via withPackage(Package).

Parameters:
classes - Fully qualified class names
Returns:
self

withTestClassPackage

public T withTestClassPackage(Class<?> testClazz)
Add all classes in the test class package to archive and set test class definition for configuration purpose.

Parameters:
testClazz -
Returns:
self

withTestClass

public T withTestClass(Class<?> testClazz)
Add test class to archive and set test class definition for configuration purpose.

Parameters:
testClazz -
Returns:
self

withTestClassDefinition

public T withTestClassDefinition(Class<?> testClazz)
Set test class definition for configuration purpose. Do not add it to final archive.

Parameters:
test -
Returns:
self

withManifestResource

public T withManifestResource(String source)
Add resource to META-INF.

Parameters:
source -
Returns:
self

withManifestResource

public T withManifestResource(String source,
                              boolean useTestPackageToLocateSource)
Add resource to META-INF.

Parameters:
source -
useTestPackageToLocateSource -
Returns:
self

withManifestResource

public T withManifestResource(String source,
                              String target,
                              boolean useTestPackageToLocateSource)
Add resource to META-INF.

Parameters:
source -
target -
useTestPackageToLocateSource -
Returns:
self

withResource

public T withResource(String source)
Add resource.

Parameters:
source -
Returns:
self

withResource

public T withResource(String source,
                      boolean useTestPackageToLocateSource)
Add resource.

Parameters:
source -
useTestPackageToLocateSource -
Returns:
self

withResource

public T withResource(String source,
                      String target,
                      boolean useTestPackageToLocateSource)
Add resource.

Parameters:
source -
target -
useTestPackageToLocateSource -
Returns:
self

withWebResource

public T withWebResource(String source)
Add web resource.

Parameters:
source -
Returns:
self

withWebResource

public T withWebResource(String source,
                         String target)
Add web resource.

Parameters:
source -
target -
Returns:
self

withWebResource

public T withWebResource(String source,
                         boolean useTestPackageToLocateSource)
Add web resource.

Parameters:
source -
useTestPackageToLocateSource -
Returns:
self

withWebResource

public T withWebResource(String source,
                         String target,
                         boolean useTestPackageToLocateSource)
Add web resource.

Parameters:
source -
Returns:

withEjbJarXml

public T withEjbJarXml(String ejbJarXml)
Add ejb-jar.xml located in src/main/resource/{testPackagePath} to META-INF/ejb-jar.xml.

Parameters:
ejbJarXml -
Returns:

withWebXml

public T withWebXml(String webXml)
Add web.xml located in src/main/resource/{testPackagePath}.

Do not use this in new tests - use withWebXml(WebAppDescriptor) instead.

Parameters:
webXml -
Returns:

withWebXml

public T withWebXml(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor webXml)
Add web.xml descriptor created with shrinkwrap-descriptors.

Parameters:
webXml -
Returns:

withDefaultPersistenceXml

public T withDefaultPersistenceXml()
Add default persistence.xml.

Returns:
self

withPersistenceXml

public T withPersistenceXml(org.jboss.shrinkwrap.descriptor.api.persistence20.PersistenceDescriptor persistenceDescriptor)
Add persistence.xml descriptor created with shrinkwrap-descriptors.

Parameters:
persistenceXml -
Returns:
self

withLibrary

public T withLibrary(File library)
Add library.

Parameters:
library -
Returns:
self

withBeanLibrary

public T withBeanLibrary(Class<?>... beanClasses)
Add bean library that consists of defined bean classes; automatically include empty beans.xml and if any of defined classes implements Extension add corresponding service provider.

Parameters:
beanClasses -
Returns:
self

withBeanLibrary

public T withBeanLibrary(org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor,
                         Class<?>... beanClasses)
Add bean library that consists of defined bean classes; automatically include empty beans.xml and if any of defined classes implements Extension add corresponding service provider.

Parameters:
beanClasses -
Returns:
self

withBeanLibrary

public T withBeanLibrary(String name,
                         Class<?>... beanClasses)
Add bean library that consists of defined bean classes; automatically include empty beans.xml and if any of defined classes implements Extension add corresponding service provider.

Parameters:
beanClasses -
Returns:
self

withBeanLibrary

public T withBeanLibrary(String name,
                         org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor,
                         Class<?>... beanClasses)
Add bean library that consists of defined bean classes; automatically include empty beans.xml and if any of defined classes implements Extension add corresponding service provider.

Parameters:
beanClasses -
Returns:
self

withLibrary

public T withLibrary(Class<?>... classes)
Add library that consists of defined classes.

Parameters:
classes -
Returns:
self

withLibrary

public T withLibrary(org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor,
                     boolean includeEmptyBeanXml,
                     Class<?>... classes)
Add library that consists of defined classes. Include empty beans.xml if necessary.

Parameters:
serviceProvider -
omitBeansXml -
classes -
Returns:

withLibrary

public T withLibrary(String name,
                     org.jboss.shrinkwrap.descriptor.api.beans10.BeansDescriptor beansDescriptor,
                     boolean includeEmptyBeanXml,
                     Class<?>... classes)
Add library that consists of defined classes. Include empty beans.xml if necessary.

Parameters:
serviceProvider -
omitBeansXml -
classes -
Returns:

self

public abstract T self()
Returns:
self to enable generic builder

build

public A build()
Returns:
shrinkwrap archive

buildInternal

protected abstract A buildInternal()
Returns:
concrete shrinkwrap archive

processPackages

protected void processPackages(org.jboss.shrinkwrap.api.container.ClassContainer<?> archive)
Process packages. Exclude classes specified via #withExcludedClass(Class). If in as-client mode, filter test class.

Parameters:
archive -

processClasses

protected void processClasses(org.jboss.shrinkwrap.api.container.ClassContainer<?> archive)
Process classes.

Parameters:
archive -

processLibraries

protected void processLibraries(org.jboss.shrinkwrap.api.container.LibraryContainer<?> archive)
Process libraries.

Parameters:
archive -

processResources

protected void processResources(org.jboss.shrinkwrap.api.container.ResourceContainer<?> archive)
Process resources.

Parameters:
archive -

processManifestResources

protected void processManifestResources(org.jboss.shrinkwrap.api.container.ManifestContainer<?> archive)
Process manifest resources.

Parameters:
archive -

isAsClientMode

protected boolean isAsClientMode()
Returns:
true if building as-client mode archive (no test infrastructure), false otherwise

isTestArchive

public boolean isTestArchive()
Returns:
true in case of archive should

notTestArchive

public T notTestArchive()
Mark this archive as non-testing.


getName

public String getName()
Returns:
name of final archive


Copyright © 2008-2012 Seam Framework. All Rights Reserved.