Your SlideShare is downloading. ×
Apache DeltaSpike
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Apache DeltaSpike

2,535

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,535
On Slideshare
0
From Embeds
0
Number of Embeds
47
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. THE SOFTWARE EXPERTS Apache DeltaSpike ... closes the gaps!
  • 2. THE SOFTWARE EXPERTS Agenda • History • DeltaSpike is… • DeltaSpike by Example  Core  JSF Module  Test-Control Module • Portability • Module Overview • Bonus
  • 3. THE SOFTWARE EXPERTS History Java EE without CDI Spring Framework Seam2 MyFaces Orchestra MyFaces CODI Java EE with CDI Seam3 + CDI implementation DeltaSpike Other Extensions
  • 4. THE SOFTWARE EXPERTS DeltaSpike is... • Portable CDI-Extension (for Apache OpenWebBeans and JBoss Weld) • Possible base for own CDI-Extensions • Source of proper usages of CDI (API and SPI) • Collection of the best concepts of  Apache MyFaces CODI  JBoss Seam3  ...
  • 5. THE SOFTWARE EXPERTS Parts of DS • Core (v0.1+) • Container-Control (v0.2+) • Modules
  • 6. THE SOFTWARE EXPERTS DS by Example
  • 7. THE SOFTWARE EXPERTS DS Core
  • 8. THE SOFTWARE EXPERTS Deactivate Beans • Disable CDI-Bean unconditionally @Exclude public class MockMailService implements MailService { /*...*/ } • Enable CDI-Bean only for Unit-Tests @Exclude(exceptIfProjectStage = ProjectStage.UnitTest.class) @Alternative public class TestMailService implements MailService { /*...*/ }
  • 9. THE SOFTWARE EXPERTS Window-Scope - Overview • Based on the CDI Session-Scope • A HTTP-Session is optional  Allows logical windows (for batches,...)  Simple/r to test • Needs to get de-/activated explicitly (autom. handling with the JSF-Module) • Base for  Grouped-Conversation-Scope  View-Access-Scope
  • 10. THE SOFTWARE EXPERTS Window-Scope - Usage • Bean-Definition @WindowScoped public class UserHolder implements Serializable { private User user; public void setCurrentUser(User user) { this.user = user; } //... } • Usage @Inject private UserHolder holder; //... holder.setCurrentUser(authenticatedUser);
  • 11. THE SOFTWARE EXPERTS Highlights (DS Core) • Scopes  Window-Scope  Grouped-Conversation-Scope  View-Access-Scope • @Exclude • Type-safe Project-Stages • Builders for CDI-Metadata • Exception-Control • JMX integration • Utilities
  • 12. THE SOFTWARE EXPERTS DS JSF-Module
  • 13. THE SOFTWARE EXPERTS Window-Scope with JSF • Like a session per browser window/tab • Pluggable ClientWindow (+ optional adapter for JSF 2.2+) • Requires ds:windowId Tag in the page(-template) (Namespace: http://deltaspike.apache.org/jsf)
  • 14. THE SOFTWARE EXPERTS Type-safe View-Config - Overview • Type-safe configuration  Re-usable for JSF-Navigation  Parameters (static or dynamic) • Highly customizable/extensible  Custom naming conventions,…  Custom Metadata,… • Std. Java  Std. IDE Support  Autocomplete  Usages / Code-Navigation  Refactoring  Show inheritance hierarchy
  • 15. THE SOFTWARE EXPERTS View-Config - Minimal Example • Definition public class MyPage implements ViewConfig {} • Usage public Class<? extends ViewConfig> toNextPage() { return MyPage.class; } /myPage.xhtml
  • 16. THE SOFTWARE EXPERTS View-Config with Metadata - 1 • Definition @View(navigation = REDIRECT) public interface Pages extends ViewConfig { interface Admin extends Pages { class Overview implements Admin {} } } • Usage public Class<? extends Pages> toNextPage() { return Pages.Admin.Overview.class; } /pages/admin/overview.xhtml?faces-redirect=true
  • 17. THE SOFTWARE EXPERTS View-Config with Metadata - 2 • Definition @Secured(MyAccessDecisionVoter.class) public interface SecuredPages {} @View(navigation = REDIRECT) public interface Pages extends ViewConfig { interface Admin extends Pages,SecuredPages { @ViewControllerRef(AdminPage.class) class Overview implements Admin { } } }
  • 18. THE SOFTWARE EXPERTS Custom Metadata • Definition @ViewMetaData @interface InfoPage { /*...*/ } • Usage @Inject private ViewConfigResolver vcr; //... ViewConfigDescriptor vcd = vcr.getViewConfigDescriptor( /*[Class|String]*/); List<InfoPage> metaDataList = vcd.getMetaData(InfoPage.class);
  • 19. THE SOFTWARE EXPERTS Highlights (JSF Module) • Type-safe View-Config • View-Controller concept • Double-Submit prevention • Injection for converters and validators • JSF Scope- and Event-Bridge • Special integration of other parts provided by DS (e.g. Security-adapter, Scopes, I18n,...) • Optional JSF 2.2+ integration/support
  • 20. THE SOFTWARE EXPERTS DS Test-Control
  • 21. THE SOFTWARE EXPERTS Testing CDI Applications with DS • Available options  Manual usage of DS-Core and Container-Control  JUnit Runner of DS-Test-Control • Mainly for CDI-Beans  No full Java EE tests like with Arquillian  Optional support of EJBs with Apache TomEE (embedded)  Optional integration with Apache MyFaces-Test (e.g. to test JSF Page-Beans manually)
  • 22. THE SOFTWARE EXPERTS Inject CDI-Beans in Tests - Setup • Add OpenWebBeans or Weld • Add DeltaSpike (at least Core) • Add the test-dependencies  JUnit  DeltaSpike Container-Control  DeltaSpike Test-Control
  • 23. THE SOFTWARE EXPERTS Inject CDI-Beans in Tests - Usage • Use the Test-Runner to write a test @RunWith(CdiTestRunner.class) public class SimpleTest { @Inject private QuestionOfLifeBean bean; @Test public void ultimateAnswer() { assertEquals(42, bean.getAnswer()); } }
  • 24. THE SOFTWARE EXPERTS Page-Bean Tests - Setup • Add MyFaces-Core and MyFaces-Test • Add one of the adapters to the configuration (META-INFservicesorg.apache.deltaspike.testcontrol.spi.ExternalContainer)
  • 25. THE SOFTWARE EXPERTS Page-Bean Tests - Usage • Use the JSF-API in a test @Test public void registerUser() { FacesContext fc = FacesContext.getCurrentInstance(); assertTrue( fc.getMessageList().isEmpty()); //... assertEquals(Pages.User.Login.class, this.registrationPage.register()); assertFalse( fc.getMessageList().isEmpty()); //... }
  • 26. THE SOFTWARE EXPERTS Tests with Context-Control • No additional Setup • Inject ContextControl • Control scopes specified by the CDI specification
  • 27. THE SOFTWARE EXPERTS Tests with Scope-Control - Usage • Simulate multiple Requests/... per Test-Method @Test public void registerUser() { //... assertFalse( fc.getMessageList().isEmpty()); this.contextControl.stopContexts(); this.contextControl.startContexts(); assertTrue( fc.getMessageList().isEmpty()); //... }
  • 28. THE SOFTWARE EXPERTS Tests with DeltaSpike Scopes • No additional Setup • Context-implementations provide Management-API • Examples  @WindowScoped  WindowContext  @GroupedConversationScoped  GroupedConversationManager
  • 29. THE SOFTWARE EXPERTS Window Aware Tests - Usage • Control the Window @Test public void registerUserAndLogin() { this.windowContext.activateWindow("w1"); //... this.registrationPage.register(); //... this.contextControl.stopContexts(); this.contextControl.startContexts(); this.windowContext.activateWindow("w1"); //... this.registrationPage.login(); //... }
  • 30. THE SOFTWARE EXPERTS Tests with Mocks for CDI-Beans • Only needed if a single Test-Bean isn’t possible/useful (via @Specializes or @Alternative) • Mocking framework is optional ( additional Setup depends on it) • Register custom (mock-)instances  Inject ApplicationMockManager for application scoped mocks  Inject DynamicMockManager for mocks per request ( Test-Method per default)
  • 31. THE SOFTWARE EXPERTS Tests with Mocks - Usage • Register mock-instance created via Mockito @Test public void registerUserWithMockedBean() { UserRepository mocked = mock(UserRepository.class); when(mockedRepository.findUser("gp")) .thenReturn(new User(/*...*/)); this.dynamicMockManager.addMock(mocked); //... this.registrationPage.register(); assertEquals("gp", this.userRepository.findUser("gp") .getUserName()); }
  • 32. THE SOFTWARE EXPERTS Advantages of DS Test-Control • Easy to use and fast (no additional container-/deployment-configurations) • Testing the whole application (no "Micro-Deployments" like with Arquillian) • Integration with DS Project-Stages (see the optional @TestControl Annotation) • Allows to (re-)use mocks (and mocking frameworks like Mockito)
  • 33. THE SOFTWARE EXPERTS Disadvantages of DS Test-Control • No deployment to the Target-EE-Server • Mainly for CDI • EJB-Support just with TomEE embedded (@Transactional of DeltaSpike might be easier for tests)
  • 34. THE SOFTWARE EXPERTS Tested Portability
  • 35. THE SOFTWARE EXPERTS Tested Portability - 1 • CDI-Implementations  Apache OpenWebBeans (>= 1.1.5)  JBoss Weld (>= 1.1.9) • EE6+ Servers  Apache TomEE 1.6.0+  JBoss AS7 und WildFly8  Oracle WebLogic 12.1.3+  IBM WebSphere 8+
  • 36. THE SOFTWARE EXPERTS Tested Portability - 2
  • 37. THE SOFTWARE EXPERTS DS Module Overview
  • 38. THE SOFTWARE EXPERTS DS Modules • Security (since v0.2+) • JPA (Transaction) (since v0.3+) • JSF (since v0.4+) • Partial-Bean (since v0.4+) • Bean-Validation (since v0.5+) • Data (Query) (since v0.5+) • Servlet (since v0.5+) • Scheduler (since v0.6+) • Test-Control (since v0.6+)
  • 39. THE SOFTWARE EXPERTS Bonus - Advanced CDI
  • 40. THE SOFTWARE EXPERTS Customize CDI-Beans • CDI-Bootstrapping-Process provides several useful events • Creating custom Bean-Metadata manually can be tricky
  • 41. THE SOFTWARE EXPERTS DS helps with Builders for Metadata • Dynamically change the existing metadata AnnotatedType<T> annotatedType = processAnnotatedType.getAnnotatedType(); processAnnotatedType.setAnnotatedType( new AnnotatedTypeBuilder<T>() .readFromType(annotatedType) .addToClass( new MyAnnotationLiteral()) .create());
  • 42. THE SOFTWARE EXPERTS Q&A!?!
  • 43. THE SOFTWARE EXPERTS Links • Apache DeltaSpike http://deltaspike.apache.org • Add-ons, Project-Templates,… https://github.com/os890 • CDI@Work http://cdiatwork.irian.at • Professional Support http://www.irian.at

×