Testing - ControllerS2C Home « Testing - Controller

In this last part of testing 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 part of the 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_Study\classes

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.

Non network manufacturer window

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:

Non network stock

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_Study\classes

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_Study\classes

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.

Network manufacturer window2

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:

Network stock

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 :)

This completes the testing for the Manufacturer application.

Lesson 20 Complete

In this lesson we tested the Controller elements of the MVC pattern.

Related Java Tutorials

Beginning Java - Primitive Variables
Beginning Java - Conditional Statements
Beginning Java - Loop Statements
Objects & Classes - Arrays
Objects & Classes - Class Structure and Syntax
Objects & Classes - Reference Variables
Objects & Classes - Methods
Objects & Classes - Instance Variables & Scope
Objects & Classes - Constructors
Objects & Classes - Static Members
Objects & Classes - Enumerations
OO Concepts - Encapsulation
OO Concepts - Inheritance Concepts - Using the super keyword
OO Concepts - Interfaces
Exceptions - Handling Exceptions
API Contents - Inheritance - Using the package keyword
API Contents - Inheritance - Using the import keyword
API Contents - Java I/O Overview - The java.io.File Class
Concurrency - Thread Basics
Concurrency - The Runnable Interface
Swing - Swing Containers
Swing - Swing Components
Swing - Layout Managers
Swing - Event Handling
Swing - Dialogs
Swing - RMI

What's Next?

In the next lesson we create documentation by using the javadoc tool on the packages we have coded.