Detailed information about defect clone:

24-C1.H0.M0.L0_T_S_06.war

 

Nickname of the defect

addition-displayed-but-not-in-DB

Brief desctiption

The button Participate in the column Teach this subject in Others' Subjects deletes this subject from table at the screen but does NOT add it into the database .

How to activate the defect

 

Visibility of the defect

Expected Actual

Parts

StudentService TeacherService DateUtility GradeDAO UserDAO
BaseStudentService E06TeacherService BaseDateUtility GradeTypeDaoCriteria UserDaoCriteria

URL to the defect source code

https://gitlab.kiv.zcu.cz/herout/TbUIS-UIS/blob/master/src/main/java/cz/zcu/kiv/matyasj/dp/service/users/error/E06TeacherService.java

Source code with the injected defect

/** * DELIBERATE ERROR * * This error method does not add subject to taught subject, but * pretends it does. * * @param teacher Subject will be set for this teacher object. * @param subjectId The subject with this database id will be set for this teacher. * @return true if operation will be successfully completed, false otherwise */ @Override @ErrorMethod(errorMessage = "This error method does not add subject to taught subjects in database or in view.") public boolean setMySubject(Teacher teacher, Long subjectId) { if (teacher == null) { log.error("Setting of subject failed."); return false; } log.info("Setting subject with id " + subjectId + " to teacher with id " + teacher.getId() + "."); Teacher tmpTeacher = (Teacher) userDao.findOne(teacher.getId()); Subject tmpSubject = subjectDao.findOne(subjectId); if (tmpTeacher == null) { log.error("Setting of subject failed."); return false; } if (tmpSubject == null) { log.warn("Setting of subject failed"); return false; } // Check max subject count for teacher int maxSubjectsNumber = Integer.parseInt(propertyLoader.getProperty("teacherMaxSubjects")); if (tmpTeacher.getListOfTaughtSubjects().size() >= maxSubjectsNumber) { log.warn("Teacher " + tmpTeacher.getFirstName() + " " + tmpTeacher.getLastName() + " is trying to register more than max subject count(" + maxSubjectsNumber + ")!"); return false; } // Check max teacher count for subject int maxTeachersNumber = Integer.parseInt(propertyLoader.getProperty("subjectMaxTeachers")); if (tmpSubject.getTeachers().size() >= maxTeachersNumber) { log.warn("Subject " + tmpSubject.getName() + " is trying to register more than max teachers count(" + maxTeachersNumber + ")!"); return false; } // Test if teacher already teaches this subject. for (Subject subject : tmpTeacher.getListOfTaughtSubjects()) { if (subject.getId().longValue() == subjectId.longValue()) { // Teacher already teaches this subject. return false; } } if (!tmpTeacher.getListOfTaughtSubjects().contains(tmpSubject)) { taughtSubjects.add(tmpSubject); log.error(propertyLoader.getProperty("log.E06TeacherService.setMySubject")); return true; } log.error("Setting of subject failed."); return false; }

URL to the correct source code

https://gitlab.kiv.zcu.cz/herout/TbUIS-UIS/blob/master/src/main/java/cz/zcu/kiv/matyasj/dp/service/users/correct/BaseTeacherService.java

Correct source code

/** * Set the subject to a teacher. * * @param teacher Subject will be set for this teacher object. * @param subjectId The subject with this database id will be set for this teacher. * @return true if operation will be successfully completed, false otherwise */ @Override public boolean setMySubject(Teacher teacher, Long subjectId) { if (teacher == null) { log.error("Setting of subject failed."); return false; } log.info("Setting subject with id " + subjectId + " to teacher with id " + teacher.getId() + "."); Teacher tmpTeacher = (Teacher) userDao.findOne(teacher.getId()); Subject tmpSubject = subjectDao.findOne(subjectId); if (tmpTeacher == null) { log.error("Setting of subject failed."); return false; } if (tmpSubject == null) { log.warn("Setting of subject failed"); return false; } // Check max subject count for teacher int maxSubjectsNumber = Integer.parseInt(propertyLoader.getProperty("teacherMaxSubjects")); if (tmpTeacher.getListOfTaughtSubjects().size() >= maxSubjectsNumber) { log.warn("Teacher " + tmpTeacher.getFirstName() + " " + tmpTeacher.getLastName() + " is trying to register more than max subject count(" + maxSubjectsNumber + ")!"); return false; } // Check max teacher count for subject int maxTeachersNumber = Integer.parseInt(propertyLoader.getProperty("subjectMaxTeachers")); if (tmpSubject.getTeachers().size() >= maxTeachersNumber) { log.warn("Subject " + tmpSubject.getName() + " is trying to register more than max teachers count(" + maxTeachersNumber + ")!"); return false; } // Test if teacher already teaches this subject. for (Subject subject : tmpTeacher.getListOfTaughtSubjects()) { if (subject.getId().longValue() == subjectId.longValue()) { // Teacher already teaches this subject. return false; } } if (tmpSubject != null) { if (!tmpTeacher.getListOfTaughtSubjects().contains(tmpSubject)) { tmpTeacher.getListOfTaughtSubjects().add(tmpSubject); tmpTeacher = (Teacher) userDao.save(tmpTeacher); if (tmpTeacher != null) { return true; } } } log.error("Setting of subject failed."); return false; }

Logged information up to failure

2019-10-14 11:25:07.091 -- INFO LogHelper:31 - HHH000204: Processing PersistenceUnitInfo [name: cz.zcu.kiv.matyasj.dp] 2019-10-14 11:25:07.312 -- INFO Version:46 - HHH000412: Hibernate Core {5.4.1.Final} 2019-10-14 11:25:07.749 -- INFO Version:49 - HCANN000001: Hibernate Commons Annotations {5.1.0.Final} 2019-10-14 11:25:08.171 -- INFO C3P0ConnectionProvider:116 - HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/uis-web-db 2019-10-14 11:25:08.171 -- INFO C3P0ConnectionProvider:117 - HHH10001001: Connection properties: {password=****, useUnicode=true, handling_mode=DELAYED_ACQUISITION_AND_HOLD, characterEncoding=UTF-8, user=uis-web} 2019-10-14 11:25:08.187 -- INFO C3P0ConnectionProvider:120 - HHH10001003: Autocommit mode: false 2019-10-14 11:25:08.390 -- INFO C3P0ConnectionProvider:200 - HHH10001007: JDBC isolation level: <unknown> 2019-10-14 11:25:08.812 -- INFO Dialect:158 - HHH000400: Using dialect: org.hibernate.dialect.MySQL55Dialect 2019-10-14 11:25:10.749 -- INFO access:47 - HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@7b2c8390] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode. 2019-10-14 11:25:13.598 -- INFO access:47 - HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@34a2e10c] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode. 2019-10-14 11:25:27.801 -- INFO JtaPlatformInitiator:52 - HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] 2019-10-14 11:25:28.035 -- INFO SecurityConfig:75 - SECURITY JDBC authentication process is running 2019-10-14 11:25:30.304 -- INFO SecurityConfig:93 - Authorization configuration process is running 2019-10-14 11:25:30.601 -- INFO BaseInitializer:97 - Initializing ... 2019-10-14 11:25:37.852 -- INFO BaseInitializer:463 - Initialized! 2019-10-14 11:25:38.008 -- INFO BaseInitializer:97 - Initializing ... 2019-10-14 11:28:20.598 -- INFO LoginController:30 - Request for login view 2019-10-14 11:28:26.522 -- INFO UserDaoCriteria:74 - User with username strict found. 2019-10-14 11:28:26.584 -- INFO SecurityConfig:121 - Success login - strict 2019-10-14 11:28:26.584 -- INFO SecurityConfig:125 - User login role: ROLE_TEACHER 2019-10-14 11:28:26.600 -- INFO UserDaoCriteria:74 - User with username strict found. 2019-10-14 11:28:26.631 -- INFO OverviewController:53 - Request for overview of teacher with id 32 for view. 2019-10-14 11:28:28.787 -- INFO ListOfNotTaughtSubjectController:45 - Request for retrieving list of not taught subjects view. 2019-10-14 11:28:28.787 -- INFO UserDaoCriteria:74 - User with username strict found. 2019-10-14 11:28:28.803 -- INFO E06TeacherService:60 - Getting list of not taught subjects for teacher with id 32. 2019-10-14 11:28:28.865 -- INFO SubjectDaoCriteria:93 - Returning list of 10 subjects. 2019-10-14 11:29:15.869 -- INFO UserDaoCriteria:74 - User with username strict found. 2019-10-14 11:29:15.884 -- INFO ListOfNotTaughtSubjectController:66 - Request for setting new taught subject(id[6]) for teacher (id[32]). 2019-10-14 11:29:15.884 -- INFO UserDaoCriteria:74 - User with username strict found. 2019-10-14 11:29:15.900 -- INFO E06TeacherService:91 - Setting subject with id 6 to teacher with id 32. 2019-10-14 11:29:15.915 -- ERROR E06TeacherService:130 - INJECTED_ERROR: E06TeacherService_setMySubject_does_not_add_subject_to_taught_subjects_in_db_or_view 2019-10-14 11:29:15.915 -- INFO ListOfNotTaughtSubjectController:70 - Request for setting new taught subject(id[6]) for teacher (id[32]) was successful. 2019-10-14 11:29:15.915 -- INFO ListOfNotTaughtSubjectController:45 - Request for retrieving list of not taught subjects view. 2019-10-14 11:29:15.931 -- INFO UserDaoCriteria:74 - User with username strict found. 2019-10-14 11:29:15.947 -- INFO E06TeacherService:60 - Getting list of not taught subjects for teacher with id 32. 2019-10-14 11:29:15.978 -- INFO SubjectDaoCriteria:93 - Returning list of 9 subjects. 2019-10-14 11:30:32.534 -- INFO ListOfTaughtSubjectController:45 - Request for retrieving list of taught subjects for view. 2019-10-14 11:30:32.534 -- INFO UserDaoCriteria:74 - User with username strict found. 2019-10-14 11:30:32.550 -- INFO BaseTeacherService:92 - Getting list of taught subjects for teacher with id 32.

Overview of functional tests full log

Overview of acceptance tests full report