fixed tests

This commit is contained in:
anhefti 2022-05-17 09:06:34 +02:00
parent 2f20313883
commit 0390e004a6
5 changed files with 48 additions and 6 deletions

View file

@ -195,7 +195,7 @@ public interface ExamDAO extends ActivatableEntityDAO<Exam, Exam>, BulkActionSup
* @return Result refer to the given QuizData or to an error when happened */
@CacheEvict(
cacheNames = ExamSessionCacheService.CACHE_NAME_RUNNING_EXAM,
key = "examId")
key = "#examId")
Result<QuizData> updateQuizData(Long examId, QuizData quizData, String updateId);
/** This is used by the internal update process to mark exams for which the LMS related data is

View file

@ -12,6 +12,7 @@ import static org.junit.Assert.*;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Order;
import org.springframework.beans.factory.annotation.Autowired;
@ -24,7 +25,10 @@ import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection;
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection.ConnectionStatus;
import ch.ethz.seb.sebserver.gbl.util.Result;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ClientConnectionDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamAdminService;
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPIService;
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPITemplate;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamProctoringRoomService;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamSessionService;
@ -42,6 +46,16 @@ public class ExamProctoringRoomServiceTest extends AdministrationAPIIntegrationT
private ExamAdminService examAdminService;
@Autowired
private ClientConnectionDAO clientConnectionDAO;
@Autowired
private ExamDAO examDAO;
@Autowired
private LmsAPIService lmsAPIService;
@Before
public void init() {
final LmsAPITemplate lmsAPITemplate = this.lmsAPIService.getLmsAPITemplate(1L).getOrThrow();
this.examDAO.updateQuizData(2L, lmsAPITemplate.getQuiz("quiz6").getOrThrow(), "testUpdate");
}
@Test
@Order(1)

View file

@ -13,6 +13,7 @@ import static org.junit.Assert.*;
import java.util.Collection;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.springframework.beans.factory.annotation.Autowired;
@ -36,6 +37,9 @@ import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientEventRecord
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientEventRecordMapper;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ClientConnectionRecord;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ClientEventRecord;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPIService;
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPITemplate;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.impl.ClientConnectionDataInternal;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.impl.ExamSessionCacheService;
@ -48,6 +52,16 @@ public class SebConnectionTest extends ExamAPIIntegrationTester {
private ClientEventRecordMapper clientEventRecordMapper;
@Autowired
private JSONMapper jsonMapper;
@Autowired
private ExamDAO examDAO;
@Autowired
private LmsAPIService lmsAPIService;
@Before
public void init() {
final LmsAPITemplate lmsAPITemplate = this.lmsAPIService.getLmsAPITemplate(1L).getOrThrow();
this.examDAO.updateQuizData(2L, lmsAPITemplate.getQuiz("quiz6").getOrThrow(), "testUpdate");
}
@Test
@Sql(scripts = { "classpath:schema-test.sql", "classpath:data-test.sql", "classpath:data-test-additional.sql" })
@ -102,6 +116,7 @@ public class SebConnectionTest extends ExamAPIIntegrationTester {
@Test
@Sql(scripts = { "classpath:schema-test.sql", "classpath:data-test.sql", "classpath:data-test-additional.sql" })
public void testCreateConnectionWithExamId() throws Exception {
final String accessToken = super.obtainAccessToken("test", "test", "SEBClient");
assertNotNull(accessToken);

View file

@ -12,12 +12,17 @@ import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.junit.Test;
import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
import ch.ethz.seb.sebserver.gbl.util.Tuple;
import ch.ethz.seb.sebserver.gbl.util.Utils;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ClientConnectionRecord;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ClientEventRecord;
@ -107,12 +112,16 @@ public class SEBClientEventCSVExporterTest {
@Test
public void streamDataTestWithExam() {
final Map<String, String> attrs = Stream.of(new Tuple<>(QuizData.QUIZ_ATTR_DESCRIPTION, "description"))
.collect(Collectors.toMap(t -> t._1, t -> t._2));
final SEBClientEventCSVExporter exporter = new SEBClientEventCSVExporter();
final ClientEventRecord event = new ClientEventRecord(0L, 1L, 2, 3L, 4L, new BigDecimal(5), "text");
final Exam exam = new Exam(0L, 1L, 3L, "externalid", true, "name", new DateTime(1L),
new DateTime(1L),
Exam.ExamType.BYOD, "owner", new ArrayList<>(), Exam.ExamStatus.RUNNING, false, "bek", true,
"lastUpdate", 4L, null, null);
"lastUpdate", 4L, null, attrs);
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
final BufferedOutputStream output = new BufferedOutputStream(stream);
@ -128,6 +137,10 @@ public class SEBClientEventCSVExporterTest {
@Test
public void streamDataTestWithConnectionAndExam() {
final Map<String, String> attrs = Stream.of(new Tuple<>(QuizData.QUIZ_ATTR_DESCRIPTION, "description"))
.collect(Collectors.toMap(t -> t._1, t -> t._2));
final ClientConnectionRecord connection = new ClientConnectionRecord(0L, 1L, 2L, "status", "token", "sessionid",
"clientaddress", "virtualaddress", 3, "vdi", 4L, 5L, 6L, 7,
"seb_os_name", "seb_machine_name", "seb_version");
@ -136,7 +149,7 @@ public class SEBClientEventCSVExporterTest {
final Exam exam = new Exam(0L, 1L, 3L, "externalid", true, "name", new DateTime(1L),
new DateTime(1L),
Exam.ExamType.BYOD, "owner", new ArrayList<>(), Exam.ExamStatus.RUNNING, false, "bek", true,
"lastUpdate", 4L, null, null);
"lastUpdate", 4L, null, attrs);
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
final BufferedOutputStream output = new BufferedOutputStream(stream);

View file

@ -13,9 +13,9 @@ INSERT IGNORE INTO additional_attributes VALUES
;
INSERT IGNORE INTO exam VALUES
(1, 1, 1, 'quiz1', 'admin', 'admin', 'MANAGED', null, null, 'UP_COMING', 1, 0, null, 1, null, null),
(2, 1, 1, 'quiz6', 'admin', 'admin', 'MANAGED', null, null, 'RUNNING', 1, 0, null, 1, null, null),
(3, 1, 1, 'quiz3', 'admin', 'admin', 'MANAGED', null, null, 'FINISHED', 1, 0, null, 1, null, null)
(1, 1, 1, 'quiz1', 'admin', 'admin', 'MANAGED', null, null, 'UP_COMING', 1, 0, null, 1, null, null, null, null, null, null),
(2, 1, 1, 'quiz6', 'admin', 'admin', 'MANAGED', null, null, 'RUNNING', 1, 0, null, 1, null, null, null, null, null, null),
(3, 1, 1, 'quiz3', 'admin', 'admin', 'MANAGED', null, null, 'FINISHED', 1, 0, null, 1, null, null, null, null, null, null)
;
INSERT IGNORE INTO indicator VALUES