by Adobe

adobe_logo

Created

3 May 2011

 

Test server-side code

 
 

Code

No code is written in this tutorial.
 

Tutorial

In the previous two modules, you built Flex applications that retrieve, display, and modify data from a database. In this module you test and debug your code.
 
In this tutorial, you use the Flash Builder Test Operation to test your server-side code—even before writing any Flex code. This is useful to make sure your server-side operations are all working before you call them in your application.
 

 
Step 1: Test a service operation that returns data.

Right-click the getEmployees()operation in the Data/Services view and select Test Operation. Click the Test button in the Test Operation view.
 
You will see all the return data displayed in the TestOperation view (see Figure 1).
 
Test the getEmployees() service operation.
Figure 1. Test the getEmployees() service operation.
Java developers: You will get an employee object that is an array of Employee objects.
 

 
Step 2: Test a service operation that requires an input parameter.

Select the getEmployeesById() operation from the drop-down in the Test Operation view. Enter a value for the argument and click Test (see Figure 2).
 
The getEmployeesById() operation is invoked with the value you specified and the return data is displayed in the Test Operation view.
 
Test the getEmployeesById() service operation.
Figure 2. Test the getEmployeesById() service operation.

 
Step 3: Test a service operation that requires a complex input parameter.

Select the createEmployee() operation in the Test Operation view. Click in the Enter Value field and click the Ellipses button. You should get a pop-up window to enter input data (see Figure 3). Close this window.
 
You will be asked for an input object when testing the createEmployee() operation.
Figure 3. You will be asked for an input object when testing the createEmployee() operation.
Java developers: Your Input Argument window will look different because your method already knows it needs an Employee object. You can skip Steps 4 and 5 below and just enter test values here as shown in Figure 5 and then test the operation. Be sure to enter integers for id and departmentid and only two characters for state. It doesn't matter what id you specify, it will not be used; a value will be generated automatically for it by the database when the data is inserted.
 

 
Step 4: Configure the createEmployee() operation return type.

Return to the Data/Services view, right-click createEmployee() and select Configure Return Type. In the dialog box, auto-detect from sample data, change the type from Object to Employee, and then click in the Enter Value field (see Figure 4). Click the Ellipses button that appears and enter values for each Employee field (see Figure 5). Be sure to enter integers for departmentid and id and only two characters for state.
 
It does not matter what id you specify, it will not be used; a value will be automatically generated for it by the database when the data is inserted.
 
Specify data type when configuring the createEmployee() return type.
Figure 4. Specify data type when configuring the createEmployee() return type.
 Specify input arguments when configuring the createEmployee() return type.
Figure 5. Specify input arguments when configuring the createEmployee() return type.
You should now see parameter and return types (Employee and int, respectively) specified for the createEmployee()operation in the Data/Services panel.
 

 
Step 5: Test the createEmployee() operation again.

Right-click createEmployees() in the Data/Services view and select Test Operation. Click the Test button in the Test Operation view.
 
This time you will see the test values you specified while configuring the return type already entered in the Enter Value field.
 
After you test the operation, you should see an integer displayed as the response value (see Figure 6). A new employee was successfully added to the database. If you run your application again, you will see this new employee in the DataGrid.
 
Test the createEmployee() service operation.
Figure 6. Test the createEmployee() service operation.
In this tutorial, you tested your server-side operations even before writing any code. In the next tutorial, you will monitor the traffic between your application and the server after you use service calls in your code.
 

 
Learn more

Refer to the following resources to learn more about this topic:
 
 
Documentation: Accessing data with Flex