Methods Summary |
---|
public static void | main(java.lang.String[] args)
setupFilenames( args );
StoreDataAccess.makeNew();
// If errors occur, then let them occur here
new CheckinCheckoutTests();
junit.textui.TestRunner.run( suite() );
|
protected void | setUp()Sets up the fixture, for example, open a network connection.
theRentalOperations = RentalOperations.getInstance();
theMaintenanceOperations =
MaintenanceOperations.getInstance();
theTestOnlyOperations = TestOnlyOperations.getInstance();
theTestOnlyOperations.collectionsClear();
theMaintenanceOperations.collectionsInitialize(
CUSTOMER_FILENAME,
CDDISC_FILENAME,
CDRELEASE_FILENAME );
|
private static void | setupFilenames(java.lang.String[] args)
if ( args.length == 0 )
{
return;
}
if ( args.length < 3 )
{
System.out.println( "You must specify 3 filenames" +
"- CDRelease, CDDisc, Customer" );
return;
}
CDRELEASE_FILENAME = args[0];
CDDISC_FILENAME = args[1];
CUSTOMER_FILENAME = args[2];
|
public static junit.framework.Test | suite()
TestSuite suite = new TestSuite();
suite.addTest( new CheckinCheckoutTests( "testNormalOperation" ) );
suite.addTest( new CheckinCheckoutTests( "testLateReturn" ) );
suite.addTest( new CheckinCheckoutTests( "testBadPhysicalID" ) );
suite.addTest( new CheckinCheckoutTests( "testBadCustomerID" ) );
suite.addTest( new CheckinCheckoutTests( "testAlreadyRented" ) );
suite.addTest( new CheckinCheckoutTests( "testNonExistentPhysicalID" ) );
suite.addTest( new CheckinCheckoutTests( "testReturnNotRented" ) );
TestResult testResult = new TestResult();
suite.run( testResult );
return suite;
|
protected void | tearDown()Tears down the fixture, for example, close a network connection.
theRentalOperations.dispose();
|
public void | testAlreadyRented()
try
{
PhysicalID aPhysicalID = new PhysicalID( "1234567890" );
CustomerID aCustomerID = new CustomerID( "ABCDEFGHIJ" );
try
{
theRentalOperations.checkoutCDDisc( aPhysicalID, aCustomerID );
}
catch ( CheckOutDeviation e )
{
fail( "Checkout failed " + e.getMessage() );
}
boolean flag = theRentalOperations.isCDDiscRented( aPhysicalID );
assertTrue( "CDDisc not rented", flag );
CustomerID anotherCustomerID = new CustomerID( "DEFGHIJKLM" );
theRentalOperations.checkoutCDDisc( aPhysicalID, anotherCustomerID );
fail( "Checkout was supposed to fail" );
}
catch ( PhysicalIDFormatDeviation e )
{
fail(
"Physical id failed " + e.getMessage() );
}
catch ( CustomerIDFormatDeviation e )
{
fail( "Customer id failed " + e.getMessage() );
}
catch ( CheckOutDeviation e )
{
;
}
|
public void | testBadCustomerID()
try
{
new CustomerID( "ABCDEFG" );
fail( "Customer id supposed to fail" );
}
catch ( CustomerIDFormatDeviation e )
{
;
}
|
public void | testBadPhysicalID()
try
{
new PhysicalID( "123456" );
fail( "Physical id supposed to fail" );
}
catch ( PhysicalIDFormatDeviation e )
{
;
}
|
public void | testLateReturn()
PhysicalID aPhysicalID = null;
CustomerID aCustomerID = null;
try
{
aPhysicalID = new PhysicalID( "1234567890" );
aCustomerID = new CustomerID( "ABCDEFGHIJ" );
theRentalOperations.checkoutCDDisc( aPhysicalID, aCustomerID );
boolean flag = theRentalOperations.isCDDiscRented( aPhysicalID );
assertTrue( "CDDisc not rented", flag );
// What do I do - wait for two days and then test?
// I really want to perform this test at the command level
// Because Sam wants a dialog box put up.
theTestOnlyOperations.setStartTimeForRentalBackSomeDays(
aPhysicalID, 3 );
theRentalOperations.checkinCDDisc(
aPhysicalID );
fail( "Rental supposed to be overdue" );
}
catch ( PhysicalIDFormatDeviation e )
{
fail(
"Physical id failed " + e.getMessage() );
}
catch ( CustomerIDFormatDeviation e )
{
fail( "Customer id failed " + e.getMessage() );
}
catch ( CheckOutDeviation e )
{
fail( "Checkout failed " + e.getMessage() );
}
catch ( CheckInDeviation e )
{
fail( "Checkin failed " + e.getMessage() );
}
catch ( LateReturnDeviation e )
{
// Check the contents of the DTO
OverdueRentalDTO ordto = e.getOverdueRentalDTO();
Timestamp today = new Timestamp();
Timestamp start = today.addDays( -3 );
assertEquals( "Start date incorrect", start,
ordto.theRentalStartTime );
Timestamp due_date = start.addDays( 2 );
assertEquals( "Due date incorrect", due_date,
ordto.theRentalDueTime );
Timestamp end_date = today;
assertEquals( "End date incoorect", end_date,
ordto.theRentalEndTime );
assertEquals( " Customer name incorrect", new Name( "Sammy" ),
ordto.theCustomerName );
assertEquals( "Title incorrect", new Name( "Really Good Title" ),
ordto.theCDReleaseTitle );
assertEquals( "Customer id incorrect", aCustomerID,
ordto.theCustomerID );
assertEquals( "Physical id incorrect", aPhysicalID,
ordto.theCDDiscPhysicalID );
;
}
|
public void | testNonExistentCustomerID()
try
{
PhysicalID aPhysicalID = new PhysicalID( "1234567890" );
CustomerID aCustomerID = new CustomerID( "ABCDEQQQQQ" );
theRentalOperations.checkoutCDDisc( aPhysicalID,
aCustomerID );
fail( "Checkout should fail" );
}
catch ( PhysicalIDFormatDeviation e )
{
fail(
"Physical id failed " + e.getMessage() );
}
catch ( CustomerIDFormatDeviation e )
{
fail( "Customer id failed " + e.getMessage() );
}
catch ( CheckOutDeviation e )
{
;
}
|
public void | testNonExistentPhysicalID()
try
{
PhysicalID aPhysicalID = new PhysicalID( "1234567000" );
CustomerID aCustomerID = new CustomerID( "ABCDEFGHIJ" );
theRentalOperations.checkoutCDDisc( aPhysicalID,
aCustomerID );
fail( "Checkout should fail" );
}
catch ( PhysicalIDFormatDeviation e )
{
fail(
"Physical id failed " + e.getMessage() );
}
catch ( CustomerIDFormatDeviation e )
{
fail( "Customer id failed " + e.getMessage() );
}
catch ( CheckOutDeviation e )
{
;
}
|
public void | testNormalOperation()runNormalOperationTest
try
{
PhysicalID aPhysicalID = new PhysicalID( "1234567890" );
CustomerID aCustomerID = new CustomerID( "ABCDEFGHIJ" );
RentalContractDTO rcdto = theRentalOperations.
checkoutCDDisc( aPhysicalID, aCustomerID );
// Check DTO values
assertEquals( "Rental fee incorrect", new Dollar( 3.0 ),
rcdto.theRentalFee );
assertEquals( "Physical ID DTO incorrect", aPhysicalID,
rcdto.theCDDiscPhysicalID );
Timestamp today = new Timestamp();
assertEquals( " Start date incorrect", today,
rcdto.theRentalStartTime );
Timestamp due_date = today.addDays( 2 );
assertEquals( " End date incorrect ", due_date,
rcdto.theRentalDueTime );
assertEquals( " Customer name incorrect", new Name( "Sammy" ),
rcdto.theCustomerName );
assertEquals( "Title incorrect", new Name( "Really Good Title" ),
rcdto.theCDReleaseTitle );
boolean flag = theRentalOperations.isCDDiscRented( aPhysicalID );
assertTrue( "CDDisc not rented", flag );
theRentalOperations.checkinCDDisc( aPhysicalID );
}
catch ( PhysicalIDFormatDeviation e )
{
fail(
"Physical id failed " + e.getMessage() );
}
catch ( CustomerIDFormatDeviation e )
{
fail( "Customer id failed " + e.getMessage() );
}
catch ( CheckOutDeviation e )
{
fail( "Checkout failed " + e.getMessage() );
}
catch ( CheckInDeviation e )
{
fail( "Checkin failed " + e.getMessage() );
}
catch ( LateReturnDeviation e )
{
fail( "Should not be late return " );
}
|
public void | testReturnNotRented()
try
{
PhysicalID aPhysicalID = new PhysicalID( "1234567890" );
theRentalOperations.checkinCDDisc(
aPhysicalID );
fail( "Checkin suppose to fail" );
}
catch ( PhysicalIDFormatDeviation e )
{
fail(
"Physical id failed " + e.getMessage() );
}
catch ( CheckInDeviation e )
{
;
}
|