/** Test of getTaskAnswer(documentId) method, of class TaskAnswerResourceFacadeImp. */ @Test public void testGetTaskAnswerByDocumentId() { taskAnswer.setAnswer("test_sample_answer2"); entityManager.getTransaction().begin(); taskAnswerResourceFacadeImp.insertTaskAnswer(taskAnswer); entityManager.getTransaction().commit(); List<TaskAnswerDTO> taskAnswer = taskAnswerResourceFacadeImp.getTaskAnswer(documentDTO.getDocumentID()); assertTrue(taskAnswer.size() >= 1); }
/** Test of getTaskAnswer(documentId, userId) method, of class TaskAnswerResourceFacadeImp. */ @Test public void testinsertTaskAnswerByDocumentIdAndUserId() { taskAnswer.setAnswer("test_sample_answer3"); entityManager.getTransaction().begin(); taskAnswerResourceFacadeImp.insertTaskAnswer(taskAnswer); entityManager.getTransaction().commit(); TaskAnswerDTO taskAnswer = taskAnswerResourceFacadeImp.getTaskAnswer(documentDTO.getDocumentID(), user.getUserID()); assertEquals(documentDTO.getDocumentID(), taskAnswer.getDocumentID()); }
@BeforeClass public static void setUpClass() { entityManager = Persistence.createEntityManagerFactory("ProjectDBManagerTest-ejbPU").createEntityManager(); taskAnswerResourceFacadeImp = new TaskAnswerResourceFacadeImp(); taskAnswerResourceFacadeImp.setEntityManager(entityManager); documentResourceFacadeImp = new DocumentResourceFacadeImp(); crisisResourceFacadeImp = new CollectionResourceFacadeImp(); crisisTypeResourceFacadeImp = new CrisisTypeResourceFacadeImp(); userResourceFacadeImp = new UsersResourceFacadeImp(); documentResourceFacadeImp.setEntityManager(entityManager); crisisResourceFacadeImp.setEntityManager(entityManager); crisisTypeResourceFacadeImp.setEntityManager(entityManager); userResourceFacadeImp.setEntityManager(entityManager); }
@After public void tearDown() { if (taskAnswer != null) { entityManager.getTransaction().begin(); taskAnswerResourceFacadeImp.undoTaskAnswer(documentDTO.getDocumentID(), user.getUserID()); entityManager.getTransaction().commit(); } if (documentDTO != null) { entityManager.getTransaction().begin(); documentResourceFacadeImp.deleteDocument(documentDTO); entityManager.getTransaction().commit(); } if (crisis != null) { try { entityManager.getTransaction().begin(); crisisResourceFacadeImp.deleteCrisis(crisis); entityManager.getTransaction().commit(); CollectionDTO result = crisisResourceFacadeImp.getCrisisByCode(crisis.getCode()); assertNull(result); } catch (PropertyNotSetException e) { logger.error("PropertyNotSetException while deleting crisis " + e.getMessage()); } } try { if (user != null) { entityManager.getTransaction().begin(); userResourceFacadeImp.deleteUser(user.getUserID()); entityManager.getTransaction().commit(); UsersDTO result = userResourceFacadeImp.getUserByName(user.getName()); assertNull(result); } } catch (PropertyNotSetException ex) { logger.error("PropertyNotSetException while deleting user " + ex.getMessage()); } }
@AfterClass public static void shutDown() throws Exception { taskAnswerResourceFacadeImp.getEntityManager().close(); }