FileDocCategorySizeDatePackage
ControllerTest.javaAPI DocExample1897Sun Apr 24 18:24:30 BST 2005None

ControllerTest

public class ControllerTest extends TestCase

Fields Summary
private org.springframework.context.ApplicationContext
ctx
Constructors Summary
Methods Summary
public voidsetUp()

      ctx = new FileSystemXmlApplicationContext("war/WEB-INF/rentaBikeApp-servlet.xml");
   
public voidtestBikeValidator()

      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 voidtestBikesController()

      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 voidtestJDBC()

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