From c8e525ab3d7327a2de8159bca4920230f5fdc3fe Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Fri, 21 Jul 2017 20:31:01 +0200
Subject: [PATCH] OO-2636: add unit tests for lecture module

---
 .../modules/lecture/LectureBlockAuditLog.java |   2 +
 .../model/LectureBlockAuditLogImpl.java       |  10 +
 .../manager/LectureBlockAuditLogDAOTest.java  |  74 +++++-
 .../lecture/manager/LectureBlockDAOTest.java  | 155 ++++++++++++-
 .../manager/LectureBlockReminderDAOTest.java  |  32 ++-
 .../manager/LectureBlockRollCallDAOTest.java  | 213 +++++++++++++++++-
 .../lecture/manager/ReasonDAOTest.java        |  20 ++
 ...itoryEntryLectureConfigurationDAOTest.java |  66 +++++-
 8 files changed, 561 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/olat/modules/lecture/LectureBlockAuditLog.java b/src/main/java/org/olat/modules/lecture/LectureBlockAuditLog.java
index 5134cb36277..26621e9898f 100644
--- a/src/main/java/org/olat/modules/lecture/LectureBlockAuditLog.java
+++ b/src/main/java/org/olat/modules/lecture/LectureBlockAuditLog.java
@@ -37,6 +37,8 @@ public interface LectureBlockAuditLog {
 
 	public String getAfter();
 	
+	public String getMessage();
+	
 	public Long getLectureBlockKey();
 	
 	public Long getRollCallKey();
diff --git a/src/main/java/org/olat/modules/lecture/model/LectureBlockAuditLogImpl.java b/src/main/java/org/olat/modules/lecture/model/LectureBlockAuditLogImpl.java
index 9f977dda306..7b322b2db84 100644
--- a/src/main/java/org/olat/modules/lecture/model/LectureBlockAuditLogImpl.java
+++ b/src/main/java/org/olat/modules/lecture/model/LectureBlockAuditLogImpl.java
@@ -80,6 +80,7 @@ public class LectureBlockAuditLogImpl implements LectureBlockAuditLog, Persistab
 		return key;
 	}
 
+	@Override
 	public Date getCreationDate() {
 		return creationDate;
 	}
@@ -88,6 +89,7 @@ public class LectureBlockAuditLogImpl implements LectureBlockAuditLog, Persistab
 		this.creationDate = creationDate;
 	}
 
+	@Override
 	public String getAction() {
 		return action;
 	}
@@ -96,6 +98,7 @@ public class LectureBlockAuditLogImpl implements LectureBlockAuditLog, Persistab
 		this.action = action;
 	}
 
+	@Override
 	public String getBefore() {
 		return before;
 	}
@@ -104,6 +107,7 @@ public class LectureBlockAuditLogImpl implements LectureBlockAuditLog, Persistab
 		this.before = before;
 	}
 
+	@Override
 	public String getAfter() {
 		return after;
 	}
@@ -112,6 +116,7 @@ public class LectureBlockAuditLogImpl implements LectureBlockAuditLog, Persistab
 		this.after = after;
 	}
 
+	@Override
 	public String getMessage() {
 		return message;
 	}
@@ -120,6 +125,7 @@ public class LectureBlockAuditLogImpl implements LectureBlockAuditLog, Persistab
 		this.message = message;
 	}
 
+	@Override
 	public Long getLectureBlockKey() {
 		return lectureBlockKey;
 	}
@@ -128,6 +134,7 @@ public class LectureBlockAuditLogImpl implements LectureBlockAuditLog, Persistab
 		this.lectureBlockKey = lectureBlockKey;
 	}
 
+	@Override
 	public Long getRollCallKey() {
 		return rollCallKey;
 	}
@@ -136,6 +143,7 @@ public class LectureBlockAuditLogImpl implements LectureBlockAuditLog, Persistab
 		this.rollCallKey = rollCallKey;
 	}
 
+	@Override
 	public Long getEntryKey() {
 		return entryKey;
 	}
@@ -144,6 +152,7 @@ public class LectureBlockAuditLogImpl implements LectureBlockAuditLog, Persistab
 		this.entryKey = entryKey;
 	}
 
+	@Override
 	public Long getIdentityKey() {
 		return identityKey;
 	}
@@ -152,6 +161,7 @@ public class LectureBlockAuditLogImpl implements LectureBlockAuditLog, Persistab
 		this.identityKey = identityKey;
 	}
 
+	@Override
 	public Long getAuthorKey() {
 		return authorKey;
 	}
diff --git a/src/test/java/org/olat/modules/lecture/manager/LectureBlockAuditLogDAOTest.java b/src/test/java/org/olat/modules/lecture/manager/LectureBlockAuditLogDAOTest.java
index fd07e49197c..4b56dfb5517 100644
--- a/src/test/java/org/olat/modules/lecture/manager/LectureBlockAuditLogDAOTest.java
+++ b/src/test/java/org/olat/modules/lecture/manager/LectureBlockAuditLogDAOTest.java
@@ -20,7 +20,9 @@
 package org.olat.modules.lecture.manager;
 
 import java.util.Date;
+import java.util.List;
 
+import org.junit.Assert;
 import org.junit.Test;
 import org.olat.core.commons.persistence.DB;
 import org.olat.core.id.Identity;
@@ -55,6 +57,74 @@ public class LectureBlockAuditLogDAOTest extends OlatTestCase {
 		dbInstance.commitAndCloseSession();
 	}
 	
+	@Test
+	public void getAuditLog_byIdentity() {
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
+		Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("audit-2-");
+		Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("audit-3-");
+		lectureBlockAuditLogDao.auditLog(LectureBlockAuditLog.Action.createLectureBlock, "3", "4", "Update absence", null, null,entry, identity, author);
+		dbInstance.commitAndCloseSession();
+		
+		//load the audit log
+		List<LectureBlockAuditLog> auditLog = lectureBlockAuditLogDao.getAuditLog(identity);
+		Assert.assertNotNull(auditLog);
+		Assert.assertEquals(1, auditLog.size());
+		//check the entry
+		LectureBlockAuditLog logEntry = auditLog.get(0);
+		Assert.assertEquals(identity.getKey(), logEntry.getIdentityKey());
+		Assert.assertEquals(author.getKey(), logEntry.getAuthorKey());
+		Assert.assertEquals(entry.getKey(), logEntry.getEntryKey());
+		Assert.assertEquals("3", logEntry.getBefore());
+		Assert.assertEquals("4", logEntry.getAfter());
+		Assert.assertEquals(LectureBlockAuditLog.Action.createLectureBlock.name(), logEntry.getAction());
+	}
+	
+	@Test
+	public void getAuditLog_byRepositoryEntry() {
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
+		Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("audit-4-");
+		Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("audit-5-");
+		lectureBlockAuditLogDao.auditLog(LectureBlockAuditLog.Action.updateAuthorizedAbsence, "Before", "After", "Update absence of course", null, null,entry, identity, author);
+		dbInstance.commitAndCloseSession();
+		
+		//load the audit log
+		List<LectureBlockAuditLog> auditLog = lectureBlockAuditLogDao.getAuditLog(entry);
+		Assert.assertNotNull(auditLog);
+		Assert.assertEquals(1, auditLog.size());
+		//check the entry
+		LectureBlockAuditLog logEntry = auditLog.get(0);
+		Assert.assertEquals(identity.getKey(), logEntry.getIdentityKey());
+		Assert.assertEquals(author.getKey(), logEntry.getAuthorKey());
+		Assert.assertEquals(entry.getKey(), logEntry.getEntryKey());
+		Assert.assertEquals("Before", logEntry.getBefore());
+		Assert.assertEquals("After", logEntry.getAfter());
+		Assert.assertEquals("Update absence of course", logEntry.getMessage());
+		Assert.assertEquals(LectureBlockAuditLog.Action.updateAuthorizedAbsence.name(), logEntry.getAction());
+	}
+	
+	@Test
+	public void getAuditLog_byLectureBlock() {
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
+		LectureBlock lectureBlock = lectureBlockDao.createLectureBlock(entry);
+		lectureBlock.setStartDate(new Date());
+		lectureBlock.setEndDate(new Date());
+		lectureBlock.setTitle("I will be loged");
+		lectureBlock = lectureBlockDao.update(lectureBlock);
+		lectureBlockAuditLogDao.auditLog(LectureBlockAuditLog.Action.autoclose, "Before", "After", "Close the absence of course", lectureBlock, null,entry, null, null);
+		dbInstance.commitAndCloseSession();
+		
+		//load the audit log
+		List<LectureBlockAuditLog> auditLog = lectureBlockAuditLogDao.getAuditLog(lectureBlock);
+		Assert.assertNotNull(auditLog);
+		Assert.assertEquals(1, auditLog.size());
+		//check the entry
+		LectureBlockAuditLog logEntry = auditLog.get(0);
+		Assert.assertEquals(entry.getKey(), logEntry.getEntryKey());
+		Assert.assertEquals("Before", logEntry.getBefore());
+		Assert.assertEquals("After", logEntry.getAfter());
+		Assert.assertEquals("Close the absence of course", logEntry.getMessage());
+		Assert.assertEquals(LectureBlockAuditLog.Action.autoclose.name(), logEntry.getAction());
+	}
 	
 	@Test
 	public void xmlAuditLog() {
@@ -67,8 +137,6 @@ public class LectureBlockAuditLogDAOTest extends OlatTestCase {
 		dbInstance.commitAndCloseSession();
 		
 		String xml = lectureBlockAuditLogDao.toXml(lectureBlock);
-		System.out.println(xml);
-		
+		Assert.assertNotNull(xml);
 	}
-
 }
diff --git a/src/test/java/org/olat/modules/lecture/manager/LectureBlockDAOTest.java b/src/test/java/org/olat/modules/lecture/manager/LectureBlockDAOTest.java
index e1f636cc59e..dd2cb0e26cd 100644
--- a/src/test/java/org/olat/modules/lecture/manager/LectureBlockDAOTest.java
+++ b/src/test/java/org/olat/modules/lecture/manager/LectureBlockDAOTest.java
@@ -42,6 +42,7 @@ import org.olat.modules.lecture.LectureService;
 import org.olat.modules.lecture.RepositoryEntryLectureConfiguration;
 import org.olat.modules.lecture.model.LectureBlockImpl;
 import org.olat.modules.lecture.model.LectureBlockToGroupImpl;
+import org.olat.modules.lecture.model.LecturesBlockSearchParameters;
 import org.olat.repository.RepositoryEntry;
 import org.olat.repository.RepositoryService;
 import org.olat.repository.manager.RepositoryEntryRelationDAO;
@@ -130,7 +131,7 @@ public class LectureBlockDAOTest extends OlatTestCase {
 	}
 	
 	@Test
-	public void getLectureBlocks() {
+	public void getLectureBlocks_entry() {
 		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
 		LectureBlock lectureBlock = lectureBlockDao.createLectureBlock(entry);
 		lectureBlock.setStartDate(new Date());
@@ -146,6 +147,157 @@ public class LectureBlockDAOTest extends OlatTestCase {
 		Assert.assertEquals(lectureBlock, loadedBlock);
 	}
 	
+	@Test
+	public void getLectureBlocks_all() {
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
+		LectureBlock lectureBlock = lectureBlockDao.createLectureBlock(entry);
+		lectureBlock.setStartDate(new Date());
+		lectureBlock.setEndDate(new Date());
+		lectureBlock.setTitle("Get them all");
+		lectureBlock = lectureBlockDao.update(lectureBlock);
+		dbInstance.commitAndCloseSession();
+		
+		List<LectureBlock> blocks = lectureBlockDao.getLectureBlocks();
+		Assert.assertNotNull(blocks);
+		Assert.assertTrue(blocks.size() >= 1);
+		Assert.assertTrue(blocks.contains(lectureBlock));
+	}
+	
+	@Test
+	public void loadByTeachers() {
+		Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-1");
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
+		LectureBlock lectureBlock = createMinimalLectureBlock(entry);
+		dbInstance.commitAndCloseSession();
+
+		lectureService.addTeacher(lectureBlock, teacher);
+		dbInstance.commitAndCloseSession();
+		
+		//search all
+		LecturesBlockSearchParameters searchParams = new LecturesBlockSearchParameters();
+		List<LectureBlock> blocks = lectureBlockDao.loadByTeacher(teacher, searchParams);
+		Assert.assertNotNull(blocks);
+		Assert.assertEquals(1, blocks.size());
+		Assert.assertEquals(lectureBlock, blocks.get(0));
+	}
+	
+	@Test
+	public void loadByTeachers_searchString() {
+		Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-1");
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
+		LectureBlock lectureBlock = createMinimalLectureBlock(entry);
+		dbInstance.commitAndCloseSession();
+
+		lectureService.addTeacher(lectureBlock, teacher);
+		dbInstance.commitAndCloseSession();
+		
+		//search lectures with the string
+		LecturesBlockSearchParameters searchParams = new LecturesBlockSearchParameters();
+		searchParams.setSearchString("lecturers");
+		List<LectureBlock> blocks = lectureBlockDao.loadByTeacher(teacher, searchParams);
+		Assert.assertNotNull(blocks);
+		Assert.assertEquals(1, blocks.size());
+		Assert.assertEquals(lectureBlock, blocks.get(0));
+		
+		//search lectures with a string which is not available to this teacher
+		LecturesBlockSearchParameters searchNegativeParams = new LecturesBlockSearchParameters();
+		searchNegativeParams.setSearchString("goodbye");
+		List<LectureBlock> negativeBlocks = lectureBlockDao.loadByTeacher(teacher, searchNegativeParams);
+		Assert.assertNotNull(negativeBlocks);
+		Assert.assertEquals(0, negativeBlocks.size());
+	}
+	
+	@Test
+	public void loadByTeachers_startEndDates() {
+		Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-1");
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
+		LectureBlock lectureBlock = createMinimalLectureBlock(entry);
+		dbInstance.commitAndCloseSession();
+
+		lectureService.addTeacher(lectureBlock, teacher);
+		dbInstance.commitAndCloseSession();
+		
+		//search lectures with the string
+		LecturesBlockSearchParameters searchNowParams = new LecturesBlockSearchParameters();
+		Calendar now = Calendar.getInstance();
+		now.add(Calendar.DATE, -1);
+		searchNowParams.setStartDate(now.getTime());
+		now.add(Calendar.DATE, 2);
+		searchNowParams.setEndDate(now.getTime());
+		List<LectureBlock> blocks = lectureBlockDao.loadByTeacher(teacher, searchNowParams);
+		Assert.assertNotNull(blocks);
+		Assert.assertEquals(1, blocks.size());
+		Assert.assertEquals(lectureBlock, blocks.get(0));
+		
+		//search in future
+		LecturesBlockSearchParameters searchFutureParams = new LecturesBlockSearchParameters();
+		now.add(Calendar.DATE, 2);
+		searchFutureParams.setStartDate(now.getTime());
+		now.add(Calendar.DATE, 2);
+		searchFutureParams.setEndDate(now.getTime());
+		List<LectureBlock> futureBlocks = lectureBlockDao.loadByTeacher(teacher, searchFutureParams);
+		Assert.assertNotNull(futureBlocks);
+		Assert.assertEquals(0, futureBlocks.size());
+	}
+	
+	@Test
+	public void loadByTeachers_startDate() {
+		Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-3");
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
+		LectureBlock lectureBlock = createMinimalLectureBlock(entry);
+		dbInstance.commitAndCloseSession();
+
+		lectureService.addTeacher(lectureBlock, teacher);
+		dbInstance.commitAndCloseSession();
+		
+		//search lectures with the string
+		LecturesBlockSearchParameters searchNowParams = new LecturesBlockSearchParameters();
+		Calendar now = Calendar.getInstance();
+		now.add(Calendar.DATE, -1);
+		searchNowParams.setStartDate(now.getTime());
+		List<LectureBlock> blocks = lectureBlockDao.loadByTeacher(teacher, searchNowParams);
+		Assert.assertNotNull(blocks);
+		Assert.assertEquals(1, blocks.size());
+		Assert.assertEquals(lectureBlock, blocks.get(0));
+		
+		//search in future
+		LecturesBlockSearchParameters searchFutureParams = new LecturesBlockSearchParameters();
+		now.add(Calendar.DATE, 2);
+		searchFutureParams.setStartDate(now.getTime());
+		List<LectureBlock> futureBlocks = lectureBlockDao.loadByTeacher(teacher, searchFutureParams);
+		Assert.assertNotNull(futureBlocks);
+		Assert.assertEquals(0, futureBlocks.size());
+	}
+	
+	@Test
+	public void loadByTeachers_endDate() {
+		Identity teacher = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-3");
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
+		LectureBlock lectureBlock = createMinimalLectureBlock(entry);
+		dbInstance.commitAndCloseSession();
+
+		lectureService.addTeacher(lectureBlock, teacher);
+		dbInstance.commitAndCloseSession();
+		
+		//search lectures with the string
+		LecturesBlockSearchParameters searchNowParams = new LecturesBlockSearchParameters();
+		Calendar now = Calendar.getInstance();
+		now.add(Calendar.DATE, -1);
+		searchNowParams.setEndDate(now.getTime());
+		List<LectureBlock> blocks = lectureBlockDao.loadByTeacher(teacher, searchNowParams);
+		Assert.assertNotNull(blocks);
+		Assert.assertEquals(0, blocks.size());
+		
+		//search in future
+		LecturesBlockSearchParameters searchFutureParams = new LecturesBlockSearchParameters();
+		now.add(Calendar.DATE, 2);
+		searchFutureParams.setEndDate(now.getTime());
+		List<LectureBlock> futureBlocks = lectureBlockDao.loadByTeacher(teacher, searchFutureParams);
+		Assert.assertNotNull(futureBlocks);
+		Assert.assertEquals(1, futureBlocks.size());
+		Assert.assertEquals(lectureBlock, futureBlocks.get(0));
+	}
+	
 	@Test
 	public void addGroup() {
 		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
@@ -365,6 +517,7 @@ public class LectureBlockDAOTest extends OlatTestCase {
 		Assert.assertEquals(1, rollcalls.size());
 		Assert.assertEquals(lectureBlock, rollcalls.get(0));
 	}
+
 	
 	@Test
 	public void deleteLectureBlock() {
diff --git a/src/test/java/org/olat/modules/lecture/manager/LectureBlockReminderDAOTest.java b/src/test/java/org/olat/modules/lecture/manager/LectureBlockReminderDAOTest.java
index 4b46eb80c93..96eacadbb25 100644
--- a/src/test/java/org/olat/modules/lecture/manager/LectureBlockReminderDAOTest.java
+++ b/src/test/java/org/olat/modules/lecture/manager/LectureBlockReminderDAOTest.java
@@ -101,6 +101,35 @@ public class LectureBlockReminderDAOTest extends OlatTestCase {
 		Assert.assertFalse(hasTeacher1);
 	}
 	
+	@Test
+	public void deleteReminder() {
+		//create a reminder
+		Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("reminder-to-delete-1");
+		LectureBlock lectureBlock = createMinimalLectureBlock(2);
+		LectureBlockReminderImpl reminder = lectureBlockReminderDao.createReminder(lectureBlock, id, "Delete it");
+		dbInstance.commitAndCloseSession();
+		Assert.assertNotNull(reminder);
+		
+		//delete the reminders
+		int deletedRows = lectureBlockReminderDao.deleteReminders(id);
+		Assert.assertEquals(1, deletedRows);
+		dbInstance.commitAndCloseSession();
+		
+		Calendar cal = Calendar.getInstance();
+		cal.add(Calendar.DATE, -3);
+		List<LectureBlockToTeacher> toRemind = lectureBlockReminderDao.getLectureBlockTeachersToReminder(cal.getTime());
+		
+		boolean hasId = false;
+		for(LectureBlockToTeacher remind:toRemind) {
+			if(remind.getLectureBlock().equals(lectureBlock)) {
+				if(remind.getTeacher().equals(id)) {
+					hasId = true;
+				}
+			}
+		}
+		
+		Assert.assertFalse(hasId);
+	}
 	
 	private LectureBlock createMinimalLectureBlock(int dayInThePast) {
 		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
@@ -114,5 +143,4 @@ public class LectureBlockReminderDAOTest extends OlatTestCase {
 		lectureBlock.setTitle("Hello lecturers");
 		return lectureBlockDao.update(lectureBlock);
 	}
-
-}
+}
\ No newline at end of file
diff --git a/src/test/java/org/olat/modules/lecture/manager/LectureBlockRollCallDAOTest.java b/src/test/java/org/olat/modules/lecture/manager/LectureBlockRollCallDAOTest.java
index af0b01b8d54..9530b950271 100644
--- a/src/test/java/org/olat/modules/lecture/manager/LectureBlockRollCallDAOTest.java
+++ b/src/test/java/org/olat/modules/lecture/manager/LectureBlockRollCallDAOTest.java
@@ -19,7 +19,10 @@
  */
 package org.olat.modules.lecture.manager;
 
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.Date;
+import java.util.List;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -49,7 +52,7 @@ public class LectureBlockRollCallDAOTest extends OlatTestCase {
 	
 	@Test
 	public void createAndPersistRollCall() {
-		LectureBlock lectureBlock = createMinimalLectureBlock();
+		LectureBlock lectureBlock = createMinimalLectureBlock(2);
 		Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
 		dbInstance.commitAndCloseSession();
 		
@@ -66,7 +69,7 @@ public class LectureBlockRollCallDAOTest extends OlatTestCase {
 	
 	@Test
 	public void createAndLoadRollCall() {
-		LectureBlock lectureBlock = createMinimalLectureBlock();
+		LectureBlock lectureBlock = createMinimalLectureBlock(2);
 		Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
 		dbInstance.commitAndCloseSession();
 		
@@ -83,14 +86,216 @@ public class LectureBlockRollCallDAOTest extends OlatTestCase {
 		Assert.assertEquals(lectureBlock, reloadRollCall.getLectureBlock());
 		Assert.assertEquals(id, reloadRollCall.getIdentity());	
 	}
+	
+	@Test
+	public void createRollCall_absences() {
+		LectureBlock lectureBlock = createMinimalLectureBlock(3);
+		Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
+		dbInstance.commitAndCloseSession();
+		
+		List<Integer> absences = Collections.singletonList(2);
+		LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, absences);
+		dbInstance.commitAndCloseSession();
+		
+		LectureBlockRollCall reloadRollCall = lectureBlockRollCallDao.loadByKey(rollCall.getKey());
+		Assert.assertNotNull(reloadRollCall);
+		Assert.assertEquals(rollCall, reloadRollCall);
+		
+		//check absence
+		Assert.assertEquals(1, reloadRollCall.getLecturesAbsentNumber());
+		List<Integer> absenceList = reloadRollCall.getLecturesAbsentList();
+		Assert.assertNotNull(absenceList);
+		Assert.assertEquals(1, absenceList.size());
+		Assert.assertEquals(2, absenceList.get(0).intValue());
+		
+		//check attendee
+		Assert.assertEquals(2, reloadRollCall.getLecturesAttendedNumber());
+		List<Integer> attendeeList = reloadRollCall.getLecturesAttendedList();
+		Assert.assertNotNull(attendeeList);
+		Assert.assertEquals(2, attendeeList.size());
+		Assert.assertEquals(0, attendeeList.get(0).intValue());
+		Assert.assertEquals(1, attendeeList.get(1).intValue());
+	}
+	
+	@Test
+	public void addLectures() {
+		LectureBlock lectureBlock = createMinimalLectureBlock(4);
+		Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
+		dbInstance.commitAndCloseSession();
+		
+		List<Integer> absences = Arrays.asList(0);
+		LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, absences);
+		dbInstance.commitAndCloseSession();
+		
+		LectureBlockRollCall reloadRollCall = lectureBlockRollCallDao.loadByKey(rollCall.getKey());
+		Assert.assertNotNull(reloadRollCall);
+		Assert.assertEquals(1, reloadRollCall.getLecturesAbsentNumber());
+		
+		List<Integer> additionalAbsences = Arrays.asList(1, 2);
+		lectureBlockRollCallDao.addLecture(lectureBlock, reloadRollCall, additionalAbsences);
+		dbInstance.commitAndCloseSession();
+		
+		//check absence
+		Assert.assertEquals(3, reloadRollCall.getLecturesAbsentNumber());
+		List<Integer> absenceList = reloadRollCall.getLecturesAbsentList();
+		Assert.assertNotNull(absenceList);
+		Assert.assertEquals(3, absenceList.size());
+		Assert.assertEquals(0, absenceList.get(0).intValue());
+		Assert.assertEquals(1, absenceList.get(1).intValue());
+		Assert.assertEquals(2, absenceList.get(2).intValue());
+		
+		//check attendee
+		Assert.assertEquals(1, reloadRollCall.getLecturesAttendedNumber());
+		List<Integer> attendeeList = reloadRollCall.getLecturesAttendedList();
+		Assert.assertNotNull(attendeeList);
+		Assert.assertEquals(1, attendeeList.size());
+		Assert.assertEquals(3, attendeeList.get(0).intValue());
+	}
+	
+	@Test
+	public void removeLectures() {
+		LectureBlock lectureBlock = createMinimalLectureBlock(4);
+		Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
+		dbInstance.commitAndCloseSession();
+		
+		List<Integer> absences = Arrays.asList(0, 1, 2, 3);
+		LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, absences);
+		dbInstance.commitAndCloseSession();
+		
+		LectureBlockRollCall reloadRollCall = lectureBlockRollCallDao.loadByKey(rollCall.getKey());
+		Assert.assertNotNull(reloadRollCall);
+		Assert.assertEquals(4, reloadRollCall.getLecturesAbsentNumber());
+		
+		List<Integer> removedAbsences = Arrays.asList(1, 2);
+		lectureBlockRollCallDao.removeLecture(lectureBlock, reloadRollCall, removedAbsences);
+		dbInstance.commitAndCloseSession();
+		
+		//check absence
+		Assert.assertEquals(2, reloadRollCall.getLecturesAbsentNumber());
+		List<Integer> absenceList = reloadRollCall.getLecturesAbsentList();
+		Assert.assertNotNull(absenceList);
+		Assert.assertEquals(2, absenceList.size());
+		Assert.assertEquals(0, absenceList.get(0).intValue());
+		Assert.assertEquals(3, absenceList.get(1).intValue());
+		
+		//check attendee
+		Assert.assertEquals(2, reloadRollCall.getLecturesAttendedNumber());
+		List<Integer> attendeeList = reloadRollCall.getLecturesAttendedList();
+		Assert.assertNotNull(attendeeList);
+		Assert.assertEquals(2, attendeeList.size());
+		Assert.assertEquals(1, attendeeList.get(0).intValue());
+		Assert.assertEquals(2, attendeeList.get(1).intValue());
+	}
+	
+	@Test
+	public void adaptLectures_removeAbsences() {
+		LectureBlock lectureBlock = createMinimalLectureBlock(4);
+		Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
+		dbInstance.commitAndCloseSession();
+		
+		List<Integer> absences = Arrays.asList(0, 1, 2, 3);
+		LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, absences);
+		dbInstance.commitAndCloseSession();
+		
+		LectureBlockRollCall reloadRollCall = lectureBlockRollCallDao.loadByKey(rollCall.getKey());
+		Assert.assertNotNull(reloadRollCall);
+		Assert.assertEquals(4, reloadRollCall.getLecturesAbsentNumber());
+		
+		//adapt the number of lectures
+		LectureBlockRollCall adaptedCall = lectureBlockRollCallDao.adaptLecture(lectureBlock, reloadRollCall, 2, id);
+		dbInstance.commitAndCloseSession();
+		
+		//check absence
+		Assert.assertEquals(2, adaptedCall.getLecturesAbsentNumber());
+		List<Integer> absenceList = adaptedCall.getLecturesAbsentList();
+		Assert.assertNotNull(absenceList);
+		Assert.assertEquals(2, absenceList.size());
+		Assert.assertEquals(0, absenceList.get(0).intValue());
+		Assert.assertEquals(1, absenceList.get(1).intValue());
+		
+		//check attendee
+		Assert.assertEquals(0, reloadRollCall.getLecturesAttendedNumber());
+		List<Integer> attendeeList = reloadRollCall.getLecturesAttendedList();
+		Assert.assertNotNull(attendeeList);
+		Assert.assertEquals(0, attendeeList.size());
+	}
+	
+	@Test
+	public void adaptLectures_removeMixed() {
+		LectureBlock lectureBlock = createMinimalLectureBlock(4);
+		Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
+		dbInstance.commitAndCloseSession();
+		
+		List<Integer> absences = Arrays.asList(1, 2);
+		LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, absences);
+		dbInstance.commitAndCloseSession();
+		
+		LectureBlockRollCall reloadRollCall = lectureBlockRollCallDao.loadByKey(rollCall.getKey());
+		Assert.assertNotNull(reloadRollCall);
+		Assert.assertEquals(2, reloadRollCall.getLecturesAbsentNumber());
+		
+		//adapt the number of lectures
+		LectureBlockRollCall adaptedCall = lectureBlockRollCallDao.adaptLecture(lectureBlock, reloadRollCall, 2, id);
+		dbInstance.commitAndCloseSession();
+		
+		//check absence
+		Assert.assertEquals(1, adaptedCall.getLecturesAbsentNumber());
+		List<Integer> absenceList = adaptedCall.getLecturesAbsentList();
+		Assert.assertNotNull(absenceList);
+		Assert.assertEquals(1, absenceList.size());
+		Assert.assertEquals(1, absenceList.get(0).intValue());
+		
+		//check attendee
+		Assert.assertEquals(1, reloadRollCall.getLecturesAttendedNumber());
+		List<Integer> attendeeList = reloadRollCall.getLecturesAttendedList();
+		Assert.assertNotNull(attendeeList);
+		Assert.assertEquals(1, attendeeList.size());
+		Assert.assertEquals(0, attendeeList.get(0).intValue());
+	}
+	
+	@Test
+	public void adaptLectures_addMixed() {
+		LectureBlock lectureBlock = createMinimalLectureBlock(3);
+		Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
+		dbInstance.commitAndCloseSession();
+		
+		List<Integer> absences = Arrays.asList(1, 2);
+		LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, absences);
+		dbInstance.commitAndCloseSession();
+		
+		LectureBlockRollCall reloadRollCall = lectureBlockRollCallDao.loadByKey(rollCall.getKey());
+		Assert.assertNotNull(reloadRollCall);
+		Assert.assertEquals(2, reloadRollCall.getLecturesAbsentNumber());
+		
+		//adapt the number of lectures
+		LectureBlockRollCall adaptedCall = lectureBlockRollCallDao.adaptLecture(lectureBlock, reloadRollCall, 4, id);
+		dbInstance.commitAndCloseSession();
+		
+		//check absence
+		Assert.assertEquals(2, adaptedCall.getLecturesAbsentNumber());
+		List<Integer> absenceList = adaptedCall.getLecturesAbsentList();
+		Assert.assertNotNull(absenceList);
+		Assert.assertEquals(2, absenceList.size());
+		Assert.assertEquals(1, absenceList.get(0).intValue());
+		Assert.assertEquals(2, absenceList.get(1).intValue());
+		
+		//check attendee
+		Assert.assertEquals(2, reloadRollCall.getLecturesAttendedNumber());
+		List<Integer> attendeeList = reloadRollCall.getLecturesAttendedList();
+		Assert.assertNotNull(attendeeList);
+		Assert.assertEquals(2, attendeeList.size());
+		Assert.assertEquals(0, attendeeList.get(0).intValue());
+		Assert.assertEquals(3, attendeeList.get(1).intValue());
+	}
 
-
-	private LectureBlock createMinimalLectureBlock() {
+	private LectureBlock createMinimalLectureBlock(int numOfLectures) {
 		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
 		LectureBlock lectureBlock = lectureBlockDao.createLectureBlock(entry);
 		lectureBlock.setStartDate(new Date());
 		lectureBlock.setEndDate(new Date());
 		lectureBlock.setTitle("Hello lecturers");
+		lectureBlock.setPlannedLecturesNumber(numOfLectures);
+		lectureBlock.setEffectiveLecturesNumber(numOfLectures);
 		return lectureBlockDao.update(lectureBlock);
 	}
 }
diff --git a/src/test/java/org/olat/modules/lecture/manager/ReasonDAOTest.java b/src/test/java/org/olat/modules/lecture/manager/ReasonDAOTest.java
index 50200a41a6d..5f0bc0a721b 100644
--- a/src/test/java/org/olat/modules/lecture/manager/ReasonDAOTest.java
+++ b/src/test/java/org/olat/modules/lecture/manager/ReasonDAOTest.java
@@ -108,4 +108,24 @@ public class ReasonDAOTest extends OlatTestCase {
 		boolean inUse = reasonDao.isReasonInUse(reason);
 		Assert.assertFalse(inUse);
 	}
+	
+	@Test
+	public void deleteReasons() {
+		//create a reason
+		String title = "Forgotten reason";
+		String description = "Find a list";
+		Reason reason = reasonDao.createReason(title, description);
+		dbInstance.commitAndCloseSession();
+		//check it exists
+		List<Reason> reasons = reasonDao.getReasons();
+		Assert.assertTrue(reasons.contains(reason));
+		
+		//delete the reason
+		boolean deleted = reasonDao.delete(reason);
+		Assert.assertTrue(deleted);
+		
+		//check it exists
+		List<Reason> reloadedDasons = reasonDao.getReasons();
+		Assert.assertFalse(reloadedDasons.contains(reason));
+	}
 }
diff --git a/src/test/java/org/olat/modules/lecture/manager/RepositoryEntryLectureConfigurationDAOTest.java b/src/test/java/org/olat/modules/lecture/manager/RepositoryEntryLectureConfigurationDAOTest.java
index d9013bf9116..4ba99acd783 100644
--- a/src/test/java/org/olat/modules/lecture/manager/RepositoryEntryLectureConfigurationDAOTest.java
+++ b/src/test/java/org/olat/modules/lecture/manager/RepositoryEntryLectureConfigurationDAOTest.java
@@ -106,5 +106,69 @@ public class RepositoryEntryLectureConfigurationDAOTest extends OlatTestCase {
 		RepositoryEntryLectureConfiguration reloadedConfig = lectureConfigurationDao.getConfiguration(lectureBlock);
 		Assert.assertEquals(config, reloadedConfig);
 	}
-
+	
+	@Test
+	public void cloneConfigureLectureConfiguration() {
+		//create a configuration
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
+		RepositoryEntry cloneEntry = JunitTestHelper.createAndPersistRepositoryEntry();	
+		RepositoryEntryLectureConfiguration config = lectureConfigurationDao.createConfiguration(entry);
+		config.setLectureEnabled(true);
+		config.setOverrideModuleDefault(true);
+		config.setCalculateAttendanceRate(Boolean.TRUE);
+		config.setRequiredAttendanceRate(0.75d);
+		config.setParticipantCalendarSyncEnabled(Boolean.TRUE);
+		config.setTeacherCalendarSyncEnabled(Boolean.TRUE);
+		RepositoryEntryLectureConfiguration mergedConfig = lectureConfigurationDao.update(config);
+		dbInstance.commitAndCloseSession();
+		
+		//clone it
+		RepositoryEntryLectureConfiguration clonedConfig = lectureConfigurationDao.cloneConfiguration(mergedConfig, cloneEntry);
+		dbInstance.commitAndCloseSession();
+		Assert.assertNotNull(clonedConfig);
+		
+		
+		RepositoryEntryLectureConfiguration reloadedClonedConfig = lectureConfigurationDao.getConfiguration(cloneEntry);
+		Assert.assertEquals(clonedConfig, reloadedClonedConfig);
+		Assert.assertEquals(true, reloadedClonedConfig.isLectureEnabled());
+		Assert.assertEquals(true, reloadedClonedConfig.isOverrideModuleDefault());
+		Assert.assertEquals(Boolean.TRUE, reloadedClonedConfig.getCalculateAttendanceRate());
+		Assert.assertEquals(0.75d, reloadedClonedConfig.getRequiredAttendanceRate(), 0.0001);
+		Assert.assertEquals(Boolean.TRUE, reloadedClonedConfig.getParticipantCalendarSyncEnabled());
+		Assert.assertEquals(Boolean.TRUE, reloadedClonedConfig.getTeacherCalendarSyncEnabled());
+	}
+	
+	@Test
+	public void isConfigurationEnabledFor() {
+		//create a configuration
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();	
+		RepositoryEntryLectureConfiguration config = lectureConfigurationDao.createConfiguration(entry);
+		config.setLectureEnabled(true);
+		RepositoryEntryLectureConfiguration mergedConfig = lectureConfigurationDao.update(config);
+		dbInstance.commitAndCloseSession();
+		Assert.assertNotNull(mergedConfig);
+		
+		//check that the configuration enables the lectures feature
+		boolean enabled = lectureConfigurationDao.isConfigurationEnabledFor(entry);
+		Assert.assertTrue(enabled);
+	}
+	
+	@Test
+	public void deleteConfiguration_byRepositoryEntry() {
+		//create a configuration
+		RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();	
+		RepositoryEntryLectureConfiguration config = lectureConfigurationDao.createConfiguration(entry);
+		config.setLectureEnabled(true);
+		RepositoryEntryLectureConfiguration mergedConfig = lectureConfigurationDao.update(config);
+		dbInstance.commitAndCloseSession();
+		Assert.assertNotNull(mergedConfig);
+		
+		//delete the configuration
+		lectureConfigurationDao.deleteConfiguration(entry);
+		dbInstance.commitAndCloseSession();
+		
+		//check that the configuration is really deleted
+		RepositoryEntryLectureConfiguration deletedConfig = lectureConfigurationDao.getConfiguration(entry);
+		Assert.assertNull(deletedConfig);
+	}
 }
-- 
GitLab