TS 60 BeanBinding

Beans Binding Test Specification

Author: Jiri Vagner
Version: 6.0
Lastupdate: 2007/06/11
Introduction:

Contents

Test suite: Basic test

Purpose: Tests basic beans binding functionality.
Setup: Create new Java Application project, add new jFrame form and add two jLabel components into that form. Renamed labels to sourceLabel and targetLabel and change text value of labels to "source" and "target"

  1. Bind text property of JLabel components
    1. Invoke popup menu for targetLabel component node in Inspector window
    2. Click "Bind -> text" menu item
    3. In Bind dialog in Binding source select sourceLabel component
    4. In Bind Expression tree combo list doubleclik on "text java.lang.String" node and press OK
    • EXPECTED RESULT: Now "text" property of two jlabels are binded. Binding works also in desing time, targetLabel now contains value from binded sourceLabel component.
  2. Check the generated code
    1. In form designer press Source button and expand initComponents() method body
    • EXPECTED RESULT: Binding dialog added there binding code, check the lines which starts with "bindingContext...". There should be initialization of binding context object, binding of our two labels and start of binding process.


Test suite: Advanced test

Setup: Use the form with two binded jlabels from the previous test case.

  1. Creating special buttons
    1. Add two jbutton components into form, change their names to sourceButton and targetButton and change their text to "Change source" and "Change target"
    2. Invoke popup menu for sourceButton and click item "Events -> Action -> actionPerformed"
    3. Into generated event handler paste: sourceLabel.setText(sourceLabel.getText() + "+");
    4. Do the steps 2 and 3 for button targetButton
    • EXPECTED RESULT: On the form there are two buttons for changing target and source property values.
  2. Update modes - Always sync
    1. Execute form (SHIFT + F6) and press sourceButton and targetButton
    • EXPECTED RESULT: Beans binding propagates changes of source text property value to target value and changes of target value to source value. This "Always sync (read/write)" update mode is default. Check the Advancec tab in Bind dialog.
  3. Update modes - Only read from source
    1. Invoke popup menu for targetLabel component node in Inspector window
    2. Click "Bind -> text" menu item
    3. In Bind dialog select Advanced tab
    4. In Update mode listbox select "Only read from source (read-only)" item and press OK
    5. Execute form (SHIFT + F6) and press sourceButton and targetButton
    • EXPECTED RESULT: Binding library will propagate only changes of source text property value. Changes of target text property are not propagated.
  4. Update modes - Read from source once
    1. Invoke popup menu for targetLabel component node in Inspector window
    2. Click "Bind -> text" menu item
    3. In Bind dialog select Advanced tab
    4. In Update mode listbox select "Read from source once (read once)" item and press OK
    5. Execute form (SHIFT + F6) and press sourceButton and targetButton
    • EXPECTED RESULT: Binding library will propagate changes of source text property value only after frame start.
  5. Alternate Values - Null value
    • Comments: If the binding source is null, you can set your own value for target property.
    1. Add new jLabel component and rename it to "nullLabel"
    2. Invoke bind dialog for text property of nullLabel
    3. In Bind dialog in Binding source select Form
    4. In Bind Expression select iconImage property (this property is null in this new test form)
    5. Go to Advanced tab and check "Null value" checkbox
    6. Click "..." button for Null value property and in popup dialog type text "item is null" and press OK
    7. Press OK button and check the form
    • EXPECTED RESULT: Binding will change the text property of nullLabel to "item is null". It will use null value alternate, because binding source is null.
  6. Alternate Values - Incomplete path value
    • Comments: If the binding source path is incomplete, you can set your own value for target property. For example if you will bind your component value to some custom User object to its property user.address.zipcode and user object will containt empty or null address component.
    1. Add new jLabel component and rename it to "incompletePathLabel"
    2. Invoke bind dialog for text property of incompletePathLabel
    3. In Bind dialog in Binding source select Form
    4. In Bind Expression select iconImage->accelerationPriority property (iconImage property is null, path is incomplete)
    5. Go to Advanced tab and check "Incomplete Path Value" checkbox
    6. Click "..." button for Incomplete Path Value property and in popup dialog type text "path is incomplete" and press OK
    • EXPECTED RESULT: Binding will change the text property of incompletePathLabel to "path is incomplete". It will use alternate value, because binding source expression path is evaluated as incomplete path.
  7. Convertors
    • Setup: Create empty form, add two JLabel components and rename them to "sourceLabel" and "targetLabel"
    1. Copy file TestConverter_TS_60_BeanBinding.java file into your project and change package name.
    2. Set the text property of sourceLabel component to "happy"
    3. Invoke popup menu for targetLabel component node in Inspector window
    4. Click "Bind -> text" menu item
    5. In Bind dialog in Binding source select sourceLabel component
    6. In Bind Expression tree combo list doubleclik on "text java.lang.String" node and press OK
    7. Go to Advanced tab and click the "..." button for Convertor property
    8. Set converter property using Custom Code editor, in property code textfield fill "TestConverter.MoodToFaceString" and press OK button
    9. Close Bind dialog using OK button and run form (SHIFT + F6)
    • EXPECTED RESULT: In runtime, string "happy" is converted to ":)". Change the text property of sourceLabel component to "sad" and run form again. For more info check the methods sourceToTarget() and targetToSource() inside MoodToFaceStringConverter class in TestConverter_TS_60_BeanBinding.java file.
  8. Validators
    • Setup: Create empty form, add two JLabel components and rename them to "sourceLabel" and "targetLabel"
    1. Copy file LoginValidator_TS_60_BeanBinding.java file into your project and change package name.
    2. Build validator file and drag it from Pproject tree and drop it into form
    3. Add JButton component, rename it to "changeTarget" and set text "Change target"
    4. Invoke popup menu for targetButton and click item "Events -> Action -> actionPerformed"
    5. Into generated event handler paste: targetLabel.setText(targetLabel.getText() + "+");
    6. Invoke popup menu for targetLabel component node in Inspector window
    7. Click "Bind -> text" menu item
    8. In Bind dialog in Binding source select sourceLabel component
    9. In Bind Expression tree combo list doubleclik on "text java.lang.String" node and press OK
    10. Go to Advanced tab and in Validator section select loginValidator component
    11. Close Bind dialog using OK button and run form (SHIFT + F6)
    12. Click button several times to increase "login" length
    • EXPECTED RESULT: After few clicks login validator will stop writing of warning msgs into console output. For more details check the content of a method TestValidator.LoginValidator.validate(). In real app programmer should implement BindingListener and use it instead of ugly console println(). :)

}}
}}

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