Writing Non-Component Locators: Understanding the Need for an NCL


Items that are directly contained by an AWT component do not require NCL's to be found. JavaStar can locate them. However, if those items themselves contain other sub-components, JavaStar needs more knowledge to determine what actual object is needed by the tester.

For example, let's consider a JTree, one of the Swing (soon to be JFC) components. As you saw in the last lesson, JavaStar could find the JTree without an NCL. However, it could not find a row, or node, of the tree. Without the NCL, testing could only be done on the tree as a whole.

Figure 11-1 is a screen shot of the tree we are going to work with for most of this lesson. It is from the SwingSet example distributed with Swing.

A JTree

Using JSNCLData

JSNCLData is the class that describes a non-component. Table 11-1 shows the definition of the class and the values for a single component, the Mozart line seen above.

Data members of JSNCLData

Variable Declaration Value for "Mozart"
Name public final String Name "4:Music##Classical##Mozart"
P public final Point P P.x: 40
P.y: 72
Ref public final Object Ref An instance of the DefaultMutableTreeNode class.

The Name is the unique identifier for that component within the JTree. It is created by the NCL. The name serves two purposes. First, it provides a means to locate the component itself. In this case the number 4 is the index into the JTree that will locate that row. Second, the name is a means to confirm that the component is the same as the one found at the original. The string "4:Music##Classical##Mozart" can be parsed. The string following the colon can be reconstructed into a path. This path must match the one found at index 4, or JavaStar will know that the component which was originally addressed no longer exists at that index.

The Point is the position of that sub-component within the containing component recognized by JavaStar. The containing component is the JTree. The upper-left location of the rectangle bounding the Mozart row is represented at that point. With this information, JavaStar can interpret any click on that component as relative to that point.

The Reference is the component itself or a means of locating the component. In the case of the JTree, it is the DefaultMutableTreeNode corresponding to the Mozart row. JavaStar can then inspect the available methods and data members of this component, and make them available for use in verification and synchronization.

Now that we've analyzed the JSNCLData, let's take a look at how one NCL, the Tree.java NCL, creates that data.

Using the JSNonComponentLocator

The purpose of a Non-Component Locator when recording is to interpret a click on a containing component, and provide its JSNCLData.

The purpose of a Non-Component Locator when playing back is to locate a component given its unique name, and return its current JSNCLData. If an entire tree is moved to a new location, JavaStar can still locate the proper component within that tree, as its bounds are relative to the tree. If the row is no longer at the 4th index position, however, JavaStar will not be able to find the component.




Send feedback to JavaStar-feedback@suntest.com
Copyright © 1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, CA 94303. All rights reserved.