throwing complexity over the wall: rapid development for enterprise java (javaone 2010)

Post on 08-Jul-2015

1.246 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

For many, development of enterprise Java has long been an arduous undertaking. We're of the opinion that application programmers should be free to focus on their business logic only. In this session, we'll cover: • What makes us most productive? • What tasks should we be programming; more importantly, what shouldn't we? • What is a component model, and what does it buy us? • How is this stuff usable in the real world? We'll discuss how testing relates to the features of the Java EE 6 stack. By the end, we'll have introduced a pair of simple and powerful frameworks that render the testing of real enterprise components as natural as calling "add" on a CS101 Calculator.java.

TRANSCRIPT

Throwing Complexity Over the Wall:Throwing Complexity Over the Wall: Rapid Development for Enterprise JavaRapid Development for Enterprise Java

Dan AllenDan AllenJBoss, by Red HatJBoss, by Red Hat mojavelinuxmojavelinux

Andrew RubingerAndrew RubingerJBoss, by Red HatJBoss, by Red Hat ALRubingerALRubinger

2

Agenda

● Enterprise software development challenges

● Component models as a solution

● Tools that help you develop & test with confidence● ShrinkWrap - Skip the build● Arquillian - Test in-container

● Demo, demo, demo

● Arquillian's interchangeable parts

● Q & A (or more demos)

#arquillian

3

General categorization of software

● Core concerns

● Cross-cutting concerns

● Plumbing

4

What should you code?

● Core concerns● Business logic● Domain-specific

● Why?● Nothing can do this for you● It's what you are paid to do● It's a good investment of time● You get to 100% done sooner

5

What should you avoid?

● “Conceptual weight”● Cross-cutting concerns● Plumbing

● Unnecessary LOC● Write less = maintain less● Improve signal-to-noise ratio

6

Components models as a solution

● Component● Follows standard programming model● Encapsulates business logic● Packaged in deployable archive

● Container● Host process for deployed applications● Provides services and a runtime for components● Gives you powerful mechanisms for free

7

So what is Java EE, really?

A standards-based platform that allows us to write business logic as components

8

What's been from Java EE?missing

^

9

for your testsfor your testsA component model

10

Unit tests vs integration tests

Unit

● Attributes● Fine-grained● Simple● Single API call

● Perception● Fast, fast, fast● Easily run in an IDE

Integration

● Attributes● Coarse-grained● Complex● Component interactions

● Perception● Sloooooooow● Run in an IDE? How?

11

No tests #fail

12

Common integration testing challenges

● Bootstrap a container environment

● Run a build to create/deploy application archive

● Mock dependent components

● Configure application to use test data source(s)

● Deal with (lack of) classpath isolation

● URLs, host names and ports, oh my!

13

The testing “bandgap”

Unit Tests Integration Tests System Tests

Functionality

Setup & configuration

Com

ple x

ity (

Men

tal E

ffort

)

14

What if integration testing could be...?

● as easy as writing a unit test

● run in the IDE (incremental builds, debugging, etc)

● ramped up in phases

● portable

15

An in-container approach to integration testing

1. Start or connect to a container

2. Package and deploy test case to container

3. Run test in-container

4. Capture and report results

5. Undeploy test archive

Bring your test to the runtime...

...instead of managing the runtime from your test.

16

Reducing enterprise testing to child's play

Unit Tests Integration Tests System Tests

Functionality

Setup & configuration

Arquillian's test continuum

Com

ple x

ity (

Men

tal E

ffort

)

17

How do we get there?

18

Test in-container!Test in-container!Skip the build!

19

Step 1: Liberate your tests from the build!

● Builds are laborious● Add overhead● Slow down test execution● Coarse-grained packaging

● Keep it manageable!● Well-defined “unit”● Classpath control

20

n. a fluent API for creating archives such as JARs, WARs andEARs in Java

Project lead: Andrew Lee Rubinger

http://jboss.org/shrinkwrap

21

Benefits of ShrinkWrap

● Incremental IDE compilation● Save and re-run● Skip the build!

● Simple, fluent API

● Container deployment adapters

● Micro deployments

● Export and debugging

22

Fluent archive creation

final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "slsb.jar") .addClasses(Greeter.class, GreeterBean.class);System.out.println(archive.toString(true));

slsb.jar:/com//com/acme//com/acme/app//com/acme/app/ejb3//com/acme/app/ejb3/Greeter.class/com/acme/app/ejb3/GreeterBean.class

Yields output:

23

Micro deployments

● Deploy components in isolation

● Test one functional unit at a time

● Don't need to wait for full application build/startup

● Incremental integration● Hand pick components & resources● No “big bang” integration

24

Build, what build?

@Deploymentpublic static Archive<?> createDeployment() { return ShrinkWrap.create(JavaArchive.class) .addClasses(Greeter.class, GreeterBean.class);}

25

Skip the build!

@Deploymentpublic static Archive<?> createDeployment() { return ShrinkWrap.create(JavaArchive.class) .addPackage(TemperatureConverter.class.getPackage()) .addManifestResource(EmptyAsset.INSTANCE, "beans.xml");}

26

Step 2: Gut the plumbing!

● Start/connect to container

● Package & deploy archive

● Inject resources

● Test logic

● Cleanup resources

● Undeploy archive

● Stop/disconnect from container

27

n. a container-oriented testing framework that enablesdevelopers to create portable integration tests for enterpriseapplications; manages the lifecycle of a container and enriches,deploys and runs tests against it

Project lead: Aslak Knutsen

http://jboss.org/arquillian

28

Make integration testing a breeze!

Arquillian project mission

29

Prove it.

@RunWith(Arquillian.class)public class GreeterTestCase {

@Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(JavaArchive.class) .addClasses(Greeter.class, GreeterBean.class); } @EJB private Greeter greeter; @Test public void shouldBeAbleToInvokeEJB() throws Exception { assertEquals("Hello, Earthlings", greeter.greet("Earthlings")); }}

30

Prove it.

@RunWith(Arquillian.class)public class GreeterTestCase {

@Deployment public static Archive<?> createDeployment() { return ShrinkWrap.create(JavaArchive.class).addClass(Greeter.class) .addManifestResource(EmptyAsset.INSTANCE, "beans.xml"); } @Inject Greeter greeter; @Test public void shouldBeAbleToInvokeManagedBean() throws Exception { assertEquals("Hello, Earthlings", greeter.greet("Earthlings")); }}

31

DEMO!

32

Benefits of Arquillian

● Write less (test) code

● As much or as little “integration” as you need

● Looks like a unit test, but you're in a real environment!● Easily lookup component to test● No hesitation when you need a resource

● Run same test in multiple containers

● It's a learning environment

33

34

Supported unit testing frameworks

JUnit TestNG>= 4.6 >= 5.10

35

Test run modes

● In-container● Test bundled with @Deployment archive● Archive deployed to container● Test runs inside container alongside application code● Invoke application code directly (same JVM)

● As client● @Deployment archive is test archive (unmodified)● Archive deployed to the container● Test stays back, runs in original test runner● Interact as a remote client (e.g., HTTP client)

36

Container modes

● Embedded● Same JVM as test runner● Test protocol either local or remote● Lifecycle controlled by Arquillian

● Remote● Separate JVM from test runner● Arquillian connects to running container● Tests executed over remote protocol

● Managed● Remote with lifecycle management

37

Supported containers

● JBoss AS 5.0 & 5.1 – Managed and remote

● JBoss AS 6 – Managed, remote and embedded

● JBoss JCA – Embedded

● GlassFish 3 – Remote and embedded

● Weld – SE embedded and EE mock embedded

● OpenWebBeans – embedded

● OpenEJB 3.1 – embedded

● OSGi – embedded

● Tomcat 6, Jetty 6.1 and Jetty 7 – embedded

● More on the way...

38

Container SPI, not just for Java EE

public interface DeployableContainer {

void setup(Context context, Configuration configuration);

void start(Context context) throws LifecycleException;

ContainerMethodExecutor deploy(Context context, Archive<?> archive) throws DeploymentException;

void undeploy(Context context, Archive<?> archive) throws DeploymentException;

void stop(Context context) throws LifecycleException;

}

39

Power tools: test framework integration

● Test frameworks are services too!

● Extends test component model

● Examples:● JSFUnit*● Cobertura*● Spock*● Selenium*● HTTPUnit● DBUnit

* available

40

Arquillian...

● is a container-oriented testing framework

● provides a component model for tests

● handles test infrastructure & plumbing

● ships with a set of container implementations

● provides a little bit of magic ;)

41

We're in print!

Enterprise JavaBeans 3.1, Sixth EditionO’Reilly - Andrew Lee Rubinger, et al

http://community.jboss.org/groups/oreillyejb6th

LOOK INSIDE!

42

Get involved!

● Download us!● ShrinkWrap - http://jboss.org/shrinkwap● Arquillian - http://jboss.org/arquillian

● Participate with us!● Community Space

● Fork us!

● Meet us!● #jbosstesting channel on irc.freenode.net

● Write for us!● Share your stories – Blog! Tweet! #arquillian● Document how it works

43

Emotional Ike

Now available as a Hudson build plugin!http://github.com/arquillian/arquillian-extensions

Q & A (or more demos)Q & A (or more demos)

http://jboss.org/arquillianhttp://jboss.org/arquillianhttp://jboss.org/shrinkwraphttp://jboss.org/shrinkwrap

45

46

47

top related