TS 71 CDI

Context and Dependency Injection Test Specification

Author: Jiri Skrivanek
Version: NetBeans 7.1
Default IZ component(s): javaee/CDI
Last update: 30-th September 2011
Introduction: This test specification is focused on testing of context and dependency injection in NetBeans. Description of existing features can be found in new and noteworthy and CDI functional specification. General information about CDI are in Java EE 6 tutorial or NetBeans tutorials.

Contents


Test suite: CDI

  1. Create CDI Types from Template
    1. Create new Java web application and during creation choose Java EE 6 version and check "Enable Context and Dependency Injection"
    2. Open new file wizard
    3. Select "Context and Dependency Injection|Qualifier Type" and finish the wizard
    4. Select "Context and Dependency Injection|Stereotype" and finish the wizard
    5. Select "Context and Dependency Injection|Interceptor Binding Type" and click Next
    6. Change class name to NewInterceptorBinding and finish the wizard
    7. Select "Context and Dependency Injection|Scope Type" and finish the wizard
    • EXPECTED RESULT: All operations are successful.
  2. Generate Interceptor
    1. Open NewInterceptorBinding.java
    2. Right-click in editor and choose "Insert Code...|Generate Interceptor"
    3. Confirm dialog with class name and check that created class contains code like this:
        @Interceptor
        @NewInterceptorBinding
        public class NewInterceptor {
    
        }
    1. Put cursor inside class definition and press Ctrl+Alt+C or use right-click and then "Navigate|Inspect CDI"
    2. Check the dialog "Interceptors for chosen "NewInterceptor" element is opened
    3. Click NewInterceptor in left pane and check right pane is populated with class javadoc
    • EXPECTED RESULT: All operations are successful.
  1. Hints and Annotations
    1. Create a new java class from template
    2. Add injection like this
        public class NewClass {

            @Inject
            @NewQualifier
            private int qualifier;
        }
    1. Check there is a hint "Unsatisfied dependency: no bean matches the injection point"
    2. Add producer to the class
            @Produces
            @NewQualifier
            @NewStereotype
            @NewScope
            int getQualifier() {
                return 0;
            }
    1. Check warning hint disappeared and only blue I (Injection Point) editor hint stays there
    2. Click Injection Point hint and cursor should jump before @Produces annotation
    3. Put cursor at qualifier field and press Ctrl+Alt+J or right-click and then use "Navigate|Go to Injectable"
    4. Check cursor jumped again before @Produces annotation
    5. Put cursor at qualifier field and press Ctrl+Alt+C or right-click and then use "Navigate|Inspect CDI"
    6. Check dialog for qualifier injection point is opened
    7. If you select getQualifier() method in left pane, you should see method's javadoc in the right pane and @NewQualifier, @NewScope and @NewStereotype in bottom fields
    8. Add event injection
            @Inject @Any Event event;
    1. Check blue E (CDI Event) editor hint appers
    2. Click CDI Event hint (bug 202895)
    3. Add observer
            void observer(@Observes Event event) {
            }
    1. Check blue O (CDI Observer) editor hint appears
    2. Click CDI Observer hint and check dialog for observer method appears
    3. Put cursor at observer method and press Ctrl+Alt+C or right-click and then use "Navigate|Inspect CDI"
    4. Check dialog for observer method appears
    • EXPECTED RESULT: All operations are successful.
  1. Decorator
    1. Create a new java class and name it NewDecorator
    2. Add @Decorator annotation to this class
    3. Check error hint "A decorator must have exactly one delegate injection point" appears
    4. Insert delegate injection point
            @Inject
            @Delegate
            @NewQualifier
            private int qualifier1;
    1. Check blue D (Delegate injection point) editor hint appears
    2. Click Delegate injection point hint and cursor should jump before @Produces annotation in NewClass.java
    3. Put cursor at qualifier1 field and press Ctrl+Alt+J or right-click and then use "Navigate|Go to Injectable"
    4. Check cursor jumped again before @Produces annotation
    5. Put cursor at qualifier1 field and press Ctrl+Alt+C or right-click and then use "Navigate|Inspect CDI"
    6. Check dialog for qualifier1 injection point is opened
    • EXPECTED RESULT: All operations are successful.


Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo