Case Study – Testing Our Controller Code

·

·Case Study
·Scenario & Setup
·Model Part 1
·View Part 1
·Controller Part 1
·Model Part 2
·Controller Part 2
·View Part 2
·Testing & Wrap Up

 
Controller TestingHomepage  « Case Study « Controller Testing
In this lesson we do some visual checks to ensure the controller code is working and end-to-end testing to show that the disparate parts of our system function together correctly.
We have already used controller code for some end-to-end testing without maybe being aware of it by getting a local/remote connection to the StockImpl singleton, for registering our services with the ServicesImpl singleton locally and via a RemoteServicesImpl instance remotely, or by populating our custom ManufacturerTableModel table model on initial entry.
In this lesson we test the stocking and unstocking functionality both locally and remotely. We can only order stock once, so if the amount entered is wrong the goods will have to be unstocked and the correct stock order reentered. What this means for us as programmers and the way we have coded these buttons in the GUI is that when stock is ordered, the Unstock button is activated and the Stock button is deactivated. When no stock has been ordered, the Stock button is activated and the Unstock button is deactivated.
Localized Stocking/Unstocking Top
To test localized stocking and unstocking we will have to run in “Non-Networked” client mode. This mode involves running the client on the same machine as the Manufacturer file location and so doesn’t require a network connection to a remote Manufacturer file location to be started. In “Non-Networked” client mode a user is only ever able to stock or unstock a product, as the Stock and Unstock buttons will never be active at the same time. Click on rows in the manufacturer information panel and you can see how the Stock and Unstock buttons are activated/deactivated dependant upon the Stock Ordered field being populated or not.
To start in this mode we need to run the ManufacturerApplicationStartup class with an argument of ‘client’.
Change to directory  cd c:_Case_Studyclasses
Run the ManufacturerApplicationStartup class from the classes directory using our package as well
    java client.ManufacturerApplicationStartup client
Press the ‘Connect’ button and the manufacturer window is displayed as shown below.

Click on the first row of Manufacturer Information – Fine Fancy Foods, Birmingham and then click the Stock button. Order an amount of 39.
Click on the third row of Manufacturer Information – Fine Fancy Foods, Swindon and then click the Unstock button.
The Stock Level and Stock Ordered fields of these rows should have been updated as shown below:

Remote Stocking/Unstocking Top
To test remote stocking and unstocking we will first have to start a server be started for a network connection to the remote Manufacturer file location.
To start in this mode we need to run the ManufacturerApplicationStartup class with an argument of ‘server’.
Change to directory  cd c:_Case_Studyclasses
Run the ManufacturerApplicationStartup class from the classes directory using our package as well
    java client.ManufacturerApplicationStartup server
Make sure you keep the server running in its own JVM, as we need the server connection up and running for networked client mode, which we will run in a new JVM next.
To run in “Networked” client mode we need to run the ManufacturerApplicationStartup class with no arguments in a new command prompt window.
Change to directory  cd c:_Case_Studyclasses
Run the ManufacturerApplicationStartup class from the classes directory using our package as well
    java client.ManufacturerApplicationStartup
Press the ‘Connect’ button and the manufacturer window is displayed and should like the following screenshot, post changes from local run above.

Click on the first row of Manufacturer Information – Car Parts Ltd, Swindon and then click the Stock button. Order an amount of 5.
Click on the third row of Manufacturer Information – Smart Clothes Incorporated, Birmingham and then click the Unstock button.
The Stock Level and Stock Ordered fields of these rows should have been updated as shown below:

There are lots of other tests that we can do such as opening two remote clients to create a StockingException exception where multiple users are trying to order stock concurrently. This can be simulated by pressing the Stock button on both remote clients and then entering an amount of stock to order on one client and then the other. Feel free to test this and other parts of the application as you wish 🙂
Related Java6 Tutorials
Swing – Swing Containers
Swing – Swing Components
Swing – Layout Managers
Swing – Event Handling
Swing – Dialogs
Swing – RMI

What’s Next?
In the next lesson we finish the case study by creating documentation using the javadoc tool on the packages we have coded. We then wrap all our files up neatly in a jar file so we can easily distribute them.
<<  View Testing             Javadocs & Jar File  >>
 Homepage  Top
All the Testing & Wrap Up lessons are listed below. Click a link to go to that lesson.

Testing & Wrap Up
Model Testing
View Testing
Controller Testing
Localized Stocking/Unstocking
Remote Stocking/Unstocking
Javadocs & Jar File
 

 

Read More Post