TS 71 JavaBeans

Beans support test specification

Author: Jiri Prox
Version:7.1
Last update:2011/09/27
Introduction: This is test specification for beans support in NetBeans. It describes generating getters and setters and generating event firing support, support in navigator and bean info editor

Contents

Test suite: Beans property

Purpose: ""

Setup: "Open empty java class in editor"

  1. Adding property
    1. Put caret inside class body
    2. Press Alt-insert and select "Add property"
    3. Change Name, default value (at the same line as Name, behind '=') and Type text field to "prop","1","int"
    4. Keep other options as default and press OK
    • EXPECTED RESULT: New field and its getter and setter are generated.
  2. Access modifier
    1. Open Add property dialog
    2. Try to change access modifier
    3. Try selecting "static" and "final" checkbox
    4. Confirm dialog
    • EXPECTED RESULT: The field has expected modifier, getter & setter are always public. When final is selected, only getter can be generated. When static is selected, event firing support cannot be generated
  3. Getter/Setter
    1. Open Add property dialog
    2. Try generate only setter or getter
    • EXPECTED RESULT: Getter or setter is generated according to specified values
  4. Indexed
    1. Open Add property dialog
    2. Check "indexed" checkbox
    3. Enter property name, type and default value
    • EXPECTED RESULT:
   private String[] indexed_prop = {"a", "b", "c"};
   /**
    * Get the value of indexed_prop
    *
    * @return the value of indexed_prop
    */
   public String[] getIndexed_prop() {
       return this.indexed_prop;
   }
   /**
    * Set the value of indexed_prop
    *
    * @param newindexed_prop new value of indexed_prop
    */
   public void setIndexed_prop(String[] newindexed_prop) {
       this.indexed_prop = newindexed_prop;
   }
   /**
    * Get the value of indexed_prop at specified index
    *
    * @param index
    * @return the value of indexed_prop at specified index
    */
   public String getIndexed_prop(int index) {
       return this.indexed_prop[Index];
   }
   /**
    * Set the value of indexed_prop at specified index.
    *
    * @param index
    * @param newindexed_prop new value of indexed_prop at specified index
    */
   public void setIndexed_prop(int index, String newindexed_prop) {
       this.indexed_prop[Index] = newindexed_prop;
   }
  1. Javadoc
    1. Try any from the previous usecase
    2. Check the javadoc is correct in preview and in generated code
    3. Unselect javadoc checkbox
    4. Confirm dialog
    • EXPECTED RESULT: All method has javadoc stub. After unselecting the checkbox no javadoc is present in preview and generated code

Test suite: Firing events support

  1. Property change support
    1. Open Add property dialog
    2. Enter any property name and type
    3. Check "Generate Property Change Support"
    • EXPECTED RESULT: The firing event support is added in preview and into generated code. For property change this code is added:
   private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
   /**
    * Add PropertyChangeListener.
    *
    * @param listener
    */
   public void addPropertyChangeListener(PropertyChangeListener listener) {
       propertyChangeSupport.addPropertyChangeListener(listener);
   }
   /**
    * Remove PropertyChangeListener.
    *
    * @param listener
    */
   public void removePropertyChangeListener(PropertyChangeListener listener) {
       propertyChangeSupport.removePropertyChangeListener(listener);
   }        
  1. Property vetoable change support
    1. Open Add property dialog
    2. Enter any property name and type
    3. Check "Generate Vetoable Change Support"
    • EXPECTED RESULT: This code is added for vetoable change
   private VetoableChangeSupport vetoableChangeSupport = new VetoableChangeSupport(this);
   /**
    * Add VetoableChangeListener.
    *
    * @param listener
    */
   public void addVetoableChangeListener(VetoableChangeListener listener) {
       vetoableChangeSupport.addVetoableChangeListener(listener);
   }
   /**
    * Remove VetoableChangeListener.
    *
    * @param listener
    */
   public void removeVetoableChangeListener(VetoableChangeListener listener) {
       vetoableChangeSupport.removeVetoableChangeListener(listener);
   }
  1. Bound property
    1. Open Add property dialog
    2. Enter name and type
    3. Select Bound checkbox, and specify its name
    • EXPECTED RESULT: Besides the property itself another filed is added and setter is changed as in following code:
          
      
   public static final String PROP_PROP = "prop";
   public void setProp(String newprop) {
       String oldprop = prop;
       this.prop = newprop;
       propertyChangeSupport.firePropertyChange(PROP_PROP, oldprop, newprop);
   }
  1. Vetoable property
    1. Open Add property dialog
    2. Enter name and type
    3. Select Bound checkbox, specify its name and select Vetoable checkbox
    • EXPECTED RESULT: Besides the property itself another filed is added and setter is changed as in following code:
   public void setProp(String newprop) throws java.beans.PropertyVetoException {
       String oldprop = prop;
       vetoableChangeSupport.fireVetoableChange(PROP_PROP, oldprop, newprop);
       this.prop = newprop;
       propertyChangeSupport.firePropertyChange(PROP_PROP, oldprop, newprop);
   }
  1. Javadoc
    1. Check javadoc for all method of event firing support
    • EXPECTED RESULT: All javadoc stubs are present
  2. Indexed bound property
    1. Add new indexed vetoable bound property
    • EXPECTED RESULT: The both setters are changed to
   public void setString(String[] newstring) throws java.beans.PropertyVetoException {
       String[] oldstring = string;
       vetoableChangeSupport.fireVetoableChange(PROP_STRING, oldstring, newstring);
       this.string = newstring;
       propertyChangeSupport.firePropertyChange(PROP_STRING, oldstring, newstring);
   }
   public void setString(int index, String newstring) throws java.beans.PropertyVetoException {
       String oldstring = string[Index];
       vetoableChangeSupport.fireVetoableChange(PROP_STRING, oldstring, newstring);
       this.string[Index] = newstring;
       propertyChangeSupport.fireIndexedPropertyChange(PROP_STRING, index, oldstring, newstring);
   }

Test suite: Beans patterns recognition

  1. Single property
    1. Open empty class and select Beans Patterns in the combo-box in the Navigator window
    2. Manually add public getter method
    3. Manually add public setter method
    4. Modify getter/setter name, return type, visibility etc...
    • EXPECTED RESULT: The beans pattern is recognized in the Navigator, the type and name of property is correctly derived from methods name. The icon indicates if the property is read only, write only or read/write
  2. indexed property
    1. Open empty class and select Beans Patterns in navigator
    2. Manually add getter method for indexed property (e.g. method public <TYPE> get<NAME>(int index) )
    3. Manually add setter method for indexed property (e.g. method public void set<NAME>(<TYPE> value,int index) )
    4. Change names, return types, visibility and argument types
    5. Add getter/setter method for single property (public <TYPE> get<NAME>() and public void set<NAME>(<TYPE> value) )
    • EXPECTED RESULT: The index property is recognized properly, only indexed property is shown in navigator when both types of getter/setter are present
  3. Change support
    1. Manually add methods for even firing support (public void addPropertyChangeListener(PropertyChangeListener listener) and public void removePropertyChangeListener(PropertyChangeListener listener) )
    2. Manually add support for vetoable change (public void addVetoableChangeListener(VetoableChangeListener listener) and public void removeVetoableChangeListener(VetoableChangeListener listener) )
    • EXPECTED RESULT: Event firing support is recognized and proper node is added to navigator.

Test suite: Miscellaneous

  1. Duplicate names
    1. Open Add property dialog
    2. Try to add property which match already existing field
    3. Specify bound name to value which is already added
    • EXPECTED RESULT: The property generation cannot continue, there is clear message in the dialog
  2. Type selection
    1. Open Add property dialog
    2. Check all primitive types + String is in type combobox
    3. Try use Browse button to select the type
    • EXPECTED RESULT: All primitive types are present, Browse button opens the dialog for selecting class name, the correct class name is inserted in the code when dialog is confirmed
  3. Duplicate change support
    1. Open class where is present support for firing events
    2. Open Add property dialog
    • EXPECTED RESULT: Appropriate checkbox is disabled, so the support cannot be generated twice
  4. Inner classes
    1. Call Add Property within inner class
    • EXPECTED RESULT: The getter/setter are added to proper class
  5. Generate inside method
    1. Put caret inside method body
    2. Call Add property
    • EXPECTED RESULT: Getter/Setter are added to correct position (e.g. in class body, not in method body)
  6. Availability
    1. Create a new annotation type, enum and interface inside the existing class
    2. Try to call Add Property from bodies of enum, interface and annotation type
    3. Create a new files: Java Annotation Type, Java Enum and Java Interface (File > New File, select the Java category)
    4. Try to call Add Property from Insert Code menu in each file
    • EXPECTED RESULT: Add Property is NOT available INSIDE the interface and the annotation type, but it is available in the enum.

Test suite: Bean info editor

  1. Generating beaninfo
    1. Open attached file Bean_TS_67_Beans.java and add it to some project
    2. Right click on its node in project view and select 'Beaninfo editor'
    3. Press Yes in confirmation dialog
    • EXPECTED RESULT: The file BeanBeanInfo.java is created containing subclass of SimpleBeanInfo
  2. BeanInfo designer
    1. Open BeanBeanInfo.java
    2. Try switching between Source and Design view
    3. In design vidw select some node
    • EXPECTED RESULT: There is editor with 2 view (as for form file), when node is selected in designer view, the right part of designer is populated with properties related to the selected node
  3. BeanInfo node
    1. In designer select BeanInfo node
    2. Copy several icons to the current project
    3. Click on ... for setting icon
    4. In opened dialog select 'classpath' and type in or select the path to the icon
    5. Confirm the dialog
    6. Type 1 for Default Property Index and Default Event Index
    7. Check 'Use Super class'
    8. Switch to source view
    • EXPECTED RESULT: The fileds iconName??? are initialized with FQN of the selected icons, fields defaultPropertyIndex and defaultEventIndex are set to 1 and the method getAdditionalBeanInfo is present in the code

public BeanInfo[] getAdditionalBeanInfo() {

       Class superclass = javaapplication127.Bean.class.getSuperclass();
       BeanInfo sbi = null;
       try {
           sbi = Introspector.getBeanInfo(superclass);
   // Here you can add code for customizing the Superclass BeanInfo.
       } catch(IntrospectionException ex) { }
       return new BeanInfo[] { sbi }; 

}

  1. Bean node
    1. Check 'Get from introspection' and check how code was changed
    2. Uncheck 'Get from introspection' and check 'Use Lazy Initialization'
    3. Switch to code
    • EXPECTED RESULT: When 'Get from introspection' is selected, the whole branch 'Bean' in designer is gray and does have any effect (although the properties of the subnode are active). The body of private static BeanDescriptor getBdescriptor() is empty. Is lazy initialization is used the getBdescriptor() returns object which is created only when method is called. Otherwise the BeanDescriptor object is created when initializing field beanDescriptor.
  2. Bean subnode
    1. Select Bean's subnode - there should be only one named as class with the original bean
    2. Select options 'Expert', 'Hidden', 'Preferred', enter sting value "text" to Display Name Code and Short Description Code
    3. add String.class to Customizer Name Code
    4. see the impact on the code
    • EXPECTED RESULT: The following code is inserted to source
       beanDescriptor.setExpert ( true );
       beanDescriptor.setHidden ( true );
       beanDescriptor.setPreferred ( true );
       beanDescriptor.setDisplayName ( "text" );
       beanDescriptor.setShortDescription ( "text" );
and 'String.class' is added as parameter of BeanDescriptor constructor. It depends on type of initialization if this code in static initializer or getBdescriptor method
  1. Properties node
    1. Select Properties node
    2. In Properties node select 'Get From Introspection'
    3. See changes in code
    4. In Properties node unselect 'Get From Introspection' and select 'Use Lazy Initialization'
    5. See changes in code
    • EXPECTED RESULT: When Get from Introspection is on the method getPdescriptor is empty, there is only return statement and whole branch is gray in designer. The 'Use Lazy initialization controls where the object returned by getPdescriptor is initialized. If it's on, the initialization is done directly in getPdescriptor method. If it's off the initialization is done in static initializer block
  2. Property
    1. Select the node of 'string' property
    2. Select all checkboxes, type in "text" to Display Name and Short Description, fill in 'String.class' as Property Editor Class, select one of the 3 possible Modes
    3. See changes in code
    • EXPECTED RESULT: The following code was added
           properties[PROPERTY_string] = new PropertyDescriptor ( "string", javaapplication127.Bean.class, "getString", "setString" ); // NOI18N
           properties[PROPERTY_string].setExpert ( true );
           properties[PROPERTY_string].setHidden ( true );
           properties[PROPERTY_string].setPreferred ( true );
           properties[PROPERTY_string].setDisplayName ( "text" );
           properties[PROPERTY_string].setShortDescription ( "text" );
           properties[PROPERTY_string].setBound ( true );
           properties[PROPERTY_string].setConstrained ( true );
           properties[PROPERTY_string].setPropertyEditorClass ( String.class );
, the 'getString' or 'setString' can be replaced with null depending on selected mode.
  1. Event Sources
    1. Select EventSources node
    2. In Properties node select 'Get From Introspection'
    3. See changes in code
    4. In Properties node unselect 'Get From Introspection' and select 'Use Lazy Initialization'
    5. See changes in code
    • EXPECTED RESULT: When Get from Introspection is on the method getEdescriptor is empty, there is only return statement and whole branch is gray in designer. The 'Use Lazy initialization controls where the object returned by getEdescriptor is initialized. If it's on, the initialization is done directly in getEdescriptor method. If it's off the initialization is done in static initializer block
  2. Event source
    1. Select 'propertyChangeListener' node
    2. Select all checkboxes, fill in string in values as in previous test cases .
    3. See the code
    • EXPECTED RESULT: The following code was added
           eventSets[EVENT_propertyChangeListener].setExpert ( true );
           eventSets[EVENT_propertyChangeListener].setHidden ( true );
           eventSets[EVENT_propertyChangeListener].setPreferred ( true );
           eventSets[EVENT_propertyChangeListener].setDisplayName ( "text" );
           eventSets[EVENT_propertyChangeListener].setShortDescription ( "text" );
, again the place where the code was added depends on style of initialization.
  1. Methods
    1. Select Methods node
    2. In Properties node select 'Get From Introspection'
    3. See changes in code
    4. In Properties node unselect 'Get From Introspection' and select 'Use Lazy Initialization'
    5. See changes in code
    • EXPECTED RESULT: When Get from Introspection is on the method getMdescriptor is empty, there is only return statement and whole branch is gray in designer. The 'Use Lazy initialization' controls where the object returned by getMdescriptor is initialized. If it's on, the initialization is done directly in getMdescriptor method. If it's off the initialization is done in static initializer block
  2. Method
    1. Select the node of method 'number'
    2. Fill in all values as in previous cases
    3. See the code
    • EXPECTED RESULT: The following code was added
           methods[METHOD_number0].setExpert ( true );
           methods[METHOD_number0].setHidden ( true );
           methods[METHOD_number0].setPreferred ( true );
           methods[METHOD_number0].setDisplayName ( "text" );
           methods[METHOD_number0].setShortDescription ( "text" );
on proper place
  1. Saving
    1. Do some change in source view and save file
    2. Do some change in design view and save file
    3. Do some change in design view, switch to source view and save file
    4. Do some change in source view, switch to design view and save file
    • EXPECTED RESULT: In all cases the modification is indicated by '*' by the of the editor tab, and after saving the file is correctly written to disk
  2. Adding new items
    1. Add new property or method in Bean_TS_67_Beans.java
    2. Switch to design view of file BeanBeanInfo.java
    3. Include the new feature by selecting 'Include in BeanInfo' selected
    • EXPECTED RESULT: The new node is added at the proper place in designer view, but is has red icon. After including it in benainfo the icon it green and the code is updated.
  3. Regenerating beaninfo
    1. Right click on Bean_TS_67_Beans.java
    2. Select Beaninfo Editor form the popup menu
    • EXPECTED RESULT: The BeanBeanInfo.java is opened in editor, w/o any change
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