private void insertData() { viajero = factory.manufacturePojo(ViajeroEntity.class); em.persist(viajero); for (int i = 0; i < 3; i++) { ItinerarioEntity entity = factory.manufacturePojo(ItinerarioEntity.class); entity.setViajero(viajero); em.persist(entity); data.add(entity); } for (int i = 0; i < 3; i++) { FotoEntity fotos = factory.manufacturePojo(FotoEntity.class); DiaEntity dias = factory.manufacturePojo(DiaEntity.class); fotos.setItinerario(data.get(0)); dias.setItinerario(data.get(0)); em.persist(dias); diaData.add(dias); em.persist(fotos); fotoData.add(fotos); } }
@Test public void addDaysTest() throws BusinessLogicException { ItinerarioEntity entity = data.get(0); DiaEntity diaEntity = factory.manufacturePojo(DiaEntity.class); DiaEntity response = itinerarioLogic.addDay(viajero.getId(), entity.getId(), diaEntity); Assert.assertNotNull(response); Assert.assertEquals(diaEntity.getId(), response.getId()); }
@Test public void replaceDaysTest() { try { ItinerarioEntity entity = data.get(0); List<DiaEntity> list = diaData.subList(1, 3); for (DiaEntity dia : list) { logger.info( "parte 1: " + dia.getDate() + " " + dia.getName() + " " + dia.getCiudad() + dia.getPais() + dia.getId()); } itinerarioLogic.replaceDays(list, viajero.getId(), entity.getId()); entity = itinerarioLogic.getItinerario(viajero.getId(), entity.getId()); for (DiaEntity dia : entity.getDias()) { logger.info( "parte 2: " + dia.getDate() + " " + dia.getName() + " " + dia.getCiudad() + dia.getPais() + dia.getId()); } Assert.assertFalse(entity.getDias().contains(diaData.get(0))); Assert.assertTrue(entity.getDias().contains(list.get(0))); Assert.assertTrue(entity.getDias().contains(list.get(1))); } catch (BusinessLogicException ex) { Assert.fail(ex.getLocalizedMessage()); } }
@Test public void getDayTest() { ItinerarioEntity entity = data.get(0); DiaEntity diaEntity = diaData.get(0); DiaEntity response = itinerarioLogic.getDay(viajero.getId(), entity.getId(), diaEntity.getId()); Assert.assertEquals(diaEntity.getId(), response.getId()); Assert.assertEquals(diaEntity.getName(), response.getName()); Assert.assertEquals(diaEntity.getDate(), response.getDate()); Assert.assertEquals(diaEntity.getCiudad(), response.getCiudad()); }