Methods Summary |
---|
private int | getCurEventsCount()
SessionFactory factory = (SessionFactory)ctx.getBean("sessionFactory");
Session s = null;
int result = -1;
try {
s = factory.openSession();
result = s.find("from LogEvent").size();
} catch (Exception ex) {
return -1;
}
return result;
|
public void | setUp()
ctx = new FileSystemXmlApplicationContext("war/WEB-INF/rentaBikeApp-servlet.xml");
store = (RentABike)ctx.getBean("rentaBike");
|
public void | testBikeValidator()
BikeValidator v = (BikeValidator) ctx.getBean("bikeValidator");
Bike bike = new Bike("test", "test", 1, "test", 2.00, "test");
Errors errs = new BindException(bike, "bike");
v.validate(bike, errs);
assertFalse(errs.hasErrors());
bike = new Bike();
errs = new BindException(bike, "bike");
v.validate(bike, errs);
assertTrue(errs.hasErrors());
|
public void | testBikesController()
BikesController controller = (BikesController) ctx.getBean("bikesController");
ModelAndView mav = controller.handleRequest(null, null);
RentABike store = (RentABike)mav.getModel().get("rentaBike");
assertNotNull(store);
assertEquals(3, store.getBikes().size());
|
public void | testDeleteBike()
List bikes = store.getBikes();
assertEquals(3, bikes.size());
Bike bike = (Bike)bikes.get(0);
store.deleteBike(bike);
bikes = store.getBikes();
assertEquals(2, bikes.size());
|
public void | testGetBike()
Bike bike = store.getBike("11111");
assertNotNull(bike);
assertEquals("Shimano", bike.getManufacturer());
|
public void | testGetBikes()
List bikes = store.getBikes();
assertNotNull(bikes);
assertEquals(3, bikes.size());
|
public void | testGetName()
assertEquals("Bruce's Bikes", store.getStoreName());
|
public void | testJDBC()
try {
System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/bikestore");
} catch (Exception ex) {
assertTrue(ex.getMessage().indexOf("authorization") > 0);
}
assertTrue(true);
|
public void | testLocal()
LoggingBefore lb = new LoggingBefore();
SessionFactory factory = (SessionFactory)ctx.getBean("sessionFactory");
int initialCount = getCurEventsCount();
lb.setSessionFactory(factory);
try {
lb.before((Method)this.getClass().getMethods()[0], null, null);
} catch (Throwable t) {
fail(t.getMessage());
}
int afterCount = getCurEventsCount();
assertEquals("Should add one to count", initialCount, afterCount - 1);
|
public void | testRemoveNonExistentBike()
Bike b = new Bike(99, "me", "mine", 1, "1", 12.00, "good");
store.deleteBike(b);
|
public void | testSaveBike()
Bike bike = (Bike)store.getBikes().get(0);
assertFalse ("Royal".equals(bike.getManufacturer()));
bike.setManufacturer("Royal");
store.saveBike(bike);
Iterator iter = store.getBikes().iterator();
boolean found = false;
while(iter.hasNext()) {
Bike b = (Bike)iter.next();
if(b.getManufacturer().equals("Royal")) found = true;
}
assertTrue(found);
|