Little helper for ShrinkWrap using Groovy
Branch: master
Clone or download
Pull request Compare This branch is even with ALRubinger:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
Readme.md
pom.xml

Readme.md

Shrinkwrap Groovy DSL

Helper for describing ShrinkWrap archives using Groovy closures. This will allow to reuse Archive and Descriptors descriptions, augment and compose them.

For example:

class ExampleDeploy {
	
	def static ear = ShrinkWrapGroovy.createClosureForArchive(EnterpriseArchive.class)
	def static war = ShrinkWrapGroovy.createClosureForArchive(WebArchive.class)
	def static jar = ShrinkWrapGroovy.createClosureForArchive(JavaArchive.class)
	
	def static beans = ShrinkWrapGroovy.createClosureForDescriptor(BeansDescriptor.class)
	def static webXml = ShrinkWrapGroovy.createClosureForDescriptor(WebAppDescriptor.class)
	def static application = ShrinkWrapGroovy.createClosureForDescriptor(ApplicationDescriptor.class)
	
	def otherClasses = {
		classes Double.class, Float.class
	}
	
	def webAppDesc = webXml {
				version "3.0"
				sessionConfig {
					sessionTimeout 30
				}
			}
	
	def warDesc = war {
		
		asLibrary jar ('myjar.jar') {
			classes String.class, Integer.class
		}
		
		include otherClasses
		
		asResource beans {
			alternatives {
				clazz StringBuilder.class.name
			}
		}, "META-INF/beans.xml"
		
		asWebInfResource webAppDesc, "web.xml"
	}
	
	def earDesc = ear {
		asModule warDesc
		setApplicationXML application {
			module {
				web {
					webUri "aUri"
					contextRoot "aContextRoot"
				}
			}
		} 
	}
	
	def build() {
		earDesc.build()
	}
	
}

This would be a description for a base deployment. Then you can use this from your test:

@RunWith(Arquillian.class)
public class Example {

    @Deployment public static Archive<?> getDeployment() {
        new ExampleDeploy().with {
            warDesc << { classes MyServlet.class }
            webAppDesc << { 
				servlet {
					servletClass MyServlet.class.name
					servletName "My Servlet"			
				}
			}
	    build()
        }
    }
}