@Test public void testRemove() throws Exception { // looking for student and delete Student student = studentDaoImpl.findById(1L); studentDaoImpl.remove(student); // get students table and counting rows // must be 4-1=3 IDataSet databaseDataSet = getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable("STUDENT"); Assert.assertEquals(actualTable.getRowCount(), 3); }
@Test public void testByUserId() throws Exception { // get students table IDataSet databaseDataSet = getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable("STUDENT"); // tacking student id with user id = 3 long studentId = (Long) actualTable.getValue(2, "id"); // get student by tested method and check result while (studentDaoImpl.findByUserId(3) == null) {} Student student = studentDaoImpl.findByUserId(3); Assert.assertEquals(studentId, student.getId()); }
@Test public void testUpdate() throws Exception { Student student = studentDaoImpl.findById(2L); Boolean actual = !student.isActive(); student.setActive(!student.isActive()); // upload user to DB studentDaoImpl.update(student); // getting from DB IDataSet databaseDataSet = getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable("STUDENT"); Boolean real = (Boolean) actualTable.getValue(1, "isActive"); Assert.assertEquals(real, actual); }
// STUDENT CONTROLLER CALL @Override public List<CourseDTO> allCoursesInDateRange4Student(Principal user, Date from, Date till) { // take courses form schedule // add to DTO base info long userId = Long.parseLong(user.getName()); Student student = studentDao.findByUserId(userId); List<Group> additionalGroups = student.getAdditionGroups(); Group mainGroup = student.getGroup(); List<Group> allGroups = new ArrayList<Group>(); allGroups.add(mainGroup); allGroups.addAll(additionalGroups); List<Course> allCoursesFromAllGroups = new ArrayList<Course>(); for (Group group : allGroups) { allCoursesFromAllGroups.addAll(getCourseForGroup(group, from, till)); } return fillCourseDTO(allCoursesFromAllGroups, from, till); }