/**
  * Test the createMaintenance(Maintenance) method : the DAO must have an additionnal entity after
  * the creation
  */
 @Test
 public void testCreateMaintenance() {
   int count = (int) maintenanceDAO.count();
   Maintenance m = Maintenance.getMaintenance(Maintenance.TEST);
   maintenanceDAO.createMaintenance(m);
   assertEquals(count + 1, maintenanceDAO.count());
 }
 @Override
 public void bootstrap() {
   if (maintenanceDAO.count() == 0) {
     maintenanceDAO.createMaintenance(Maintenance.getMaintenance(Maintenance.FULL));
     maintenanceDAO.createMaintenance(Maintenance.getMaintenance(Maintenance.TEST));
     maintenanceDAO.createMaintenance(Maintenance.getMaintenance(Maintenance.NONE));
   }
 }
  /**
   * Set up the context
   *
   * @throws Exception
   */
  @Before
  public void setUp() throws Exception {
    fullMaintenance = Maintenance.getMaintenance(Maintenance.FULL);
    maintenanceDAO.createMaintenance(fullMaintenance);
    fullMaintenanceId = fullMaintenance.getId();

    noneMaintenance = Maintenance.getMaintenance(Maintenance.NONE);
    maintenanceDAO.createMaintenance(noneMaintenance);
    noneMaintenanceId = noneMaintenance.getId();
  }
 /**
  * Test if the findAll() method return a correct and complete list of all maintenances. The
  * following conditions are checked :<br>
  *
  * <ul>
  *   <li>2 maintenances are in the list
  *   <li>The list contains the maintenance "Full"
  *   <li>The list contains the maintenance "None"
  * </ul>
  */
 @Test
 public void testFindAll() {
   List<Maintenance> maintenances = maintenanceDAO.findAll();
   assertEquals(2, maintenances.size());
   assertTrue(maintenances.contains(fullMaintenance));
   assertTrue(maintenances.contains(noneMaintenance));
 }
  /**
   * Test some {@link Maintenance} {@link Query}. First, we create a {@link Query} without filters.
   * Then, after each execution of this query, we add a filter. The following scenario is executed :
   * <br>
   *
   * <ul>
   *   <li>0 filters : 2 maintenances found
   *   <li>Filter () added : 1 maintenance found
   *   <li>Filter () added : no maintenance found
   * </ul>
   */
  @Test
  public void testFilter() {
    List<Maintenance> maintenances;
    Query<Maintenance> query = new Query<Maintenance>(Maintenance.class);

    maintenances = maintenanceDAO.filter(query);
    assertEquals(2, maintenances.size());

    // TODO test some filters
  }
  /**
   * Create and persist an {@link Client} object
   *
   * @throws Exception
   */
  @Before
  public void setUp() throws Exception {
    maintenance = Maintenance.getMaintenance(Maintenance.TEST);
    maintenanceDAO.createMaintenance(maintenance);

    client = new Client();
    client.setName("client");
    clientDAO.createClient(client);

    clientId = client.getId();
  }
예제 #7
0
 /** {@inheritDoc} */
 @Override
 public void setAsText(String text) {
   setValue((text == null) ? null : maintenanceDAO.findById(Long.parseLong(text)));
 }
 /** Test if an {@link Maintenance} can be found by his ID */
 @Test
 public void testFindById() {
   assertEquals(fullMaintenance, maintenanceDAO.findById(fullMaintenanceId));
 }
 /** Test if the maintenance with the specified name is found. */
 @Test
 public void testFindByName() {
   Maintenance maintenance = maintenanceDAO.findByName("Full");
   assertEquals(fullMaintenance, maintenance);
 }
 /**
  * Clear the context
  *
  * @throws Exception
  */
 @After
 public void tearDown() throws Exception {
   maintenanceDAO.deleteAll();
   fullMaintenance = null;
   noneMaintenance = null;
 }
 /**
  * Test the deletion of an {@link Maintenance}. We check that the deleted {@link Maintenance}
  * can't be found.
  */
 @Test
 public void testDeleteMaintenance() {
   maintenanceDAO.deleteMaintenance(noneMaintenance);
   assertNull(maintenanceDAO.findById(noneMaintenanceId));
 }
 /** Test the count() method */
 @Test
 public void testCount() {
   assertEquals(2, maintenanceDAO.count());
 }
 /**
  * Test if the updateMaintenance(Maintenance) method throws an {@link
  * InvalidDataAccessApiUsageException} if the given argument is <code>null</code>
  */
 @Test(expected = InvalidDataAccessApiUsageException.class)
 public void testUpdateNullMaintenance() {
   maintenanceDAO.updateMaintenance(null);
 }
 /** Test if the modification of an entity has been correctly done */
 @Test
 public void testUpdateMaintenance() {
   noneMaintenance.setName("Very full");
   maintenanceDAO.updateMaintenance(noneMaintenance);
   assertEquals("Very full", maintenanceDAO.findById(noneMaintenanceId).getName());
 }
 /**
  * Clear the entity manager and the {@link Client} object
  *
  * @throws Exception
  */
 @After
 public void tearDown() throws Exception {
   clientDAO.deleteAll();
   maintenanceDAO.deleteAll();
   client = null;
 }
 /**
  * Test if the DAO have no more {@link Maintenance} entities after the call of deleteAll() method
  */
 @Test
 public void testDeleteAll() {
   maintenanceDAO.deleteAll();
   assertEquals(0, maintenanceDAO.count());
 }
 /**
  * Test if a {@link NullPointerException} is thrown by trying to delete a <code>null</code> {@link
  * Maintenance}
  */
 @Test(expected = NullPointerException.class)
 public void testDeleteNullMaintenance() {
   maintenanceDAO.deleteMaintenance(null);
 }