From d86b8a186bc6bd79ce4b5776ed52e8e67fde3f11 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 29 Mar 2022 15:26:31 +0200 Subject: [PATCH] Finished exam test --- .../gui/integration/FinishedExamTest.java | 48 +++++++++++++++++++ .../integration/UseCasesIntegrationTest.java | 8 +++- .../api/exam/SebConnectionTest.java | 9 +++- .../api/exam/SebVdiConnectionTest.java | 7 ++- src/test/resources/data-test-additional.sql | 12 ++++- 5 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 src/test/java/ch/ethz/seb/sebserver/gui/integration/FinishedExamTest.java diff --git a/src/test/java/ch/ethz/seb/sebserver/gui/integration/FinishedExamTest.java b/src/test/java/ch/ethz/seb/sebserver/gui/integration/FinishedExamTest.java new file mode 100644 index 00000000..b4ba156d --- /dev/null +++ b/src/test/java/ch/ethz/seb/sebserver/gui/integration/FinishedExamTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.gui.integration; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.junit.Test; +import org.springframework.test.context.jdbc.Sql; + +import ch.ethz.seb.sebserver.gbl.model.Page; +import ch.ethz.seb.sebserver.gbl.model.exam.Exam; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestServiceImpl; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetFinishedExamClientConnection; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetFinishedExamClientConnectionPage; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetFinishedExamPage; + +@Sql(scripts = { "classpath:schema-test.sql", "classpath:data-test.sql", "classpath:data-test-additional.sql" }) +public class FinishedExamTest extends GuiIntegrationTest { + + @Test + public void finishedExamsTest() throws IOException { + final RestServiceImpl restService = createRestServiceForUser( + "admin", + "admin", + new GetFinishedExamPage(), + new GetFinishedExamClientConnectionPage(), + new GetFinishedExamClientConnection()); + + // get finished exams page: + final Page finishedExams = restService + .getBuilder(GetFinishedExamPage.class) + .call() + .getOrThrow(); + + assertNotNull(finishedExams); + assertFalse(finishedExams.content.isEmpty()); + } + +} diff --git a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java index 96042974..a0251bbb 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java @@ -218,6 +218,9 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.DisableCl import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetClientConnection; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetClientConnectionDataList; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetClientConnectionPage; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetFinishedExamClientConnection; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetFinishedExamClientConnectionPage; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetFinishedExamPage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetMonitoringFullPageData; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetPendingClientNotifications; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.session.GetRunningExamPage; @@ -2127,7 +2130,10 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { new PropagateInstruction(), new GetClientConnectionPage(), new GetPendingClientNotifications(), - new ConfirmPendingClientNotification()); + new ConfirmPendingClientNotification(), + new GetFinishedExamPage(), + new GetFinishedExamClientConnectionPage(), + new GetFinishedExamClientConnection()); final RestServiceImpl adminRestService = createRestServiceForUser( "TestInstAdmin", diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebConnectionTest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebConnectionTest.java index 17eda66e..4cc9ebb8 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebConnectionTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebConnectionTest.java @@ -30,6 +30,7 @@ import ch.ethz.seb.sebserver.gbl.api.APIMessage.ErrorMessage; import ch.ethz.seb.sebserver.gbl.api.JSONMapper; import ch.ethz.seb.sebserver.gbl.model.session.ClientEvent.EventType; import ch.ethz.seb.sebserver.gbl.model.session.IndicatorValue; +import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientConnectionRecordDynamicSqlSupport; import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientConnectionRecordMapper; import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientEventRecordDynamicSqlSupport; import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientEventRecordMapper; @@ -71,6 +72,7 @@ public class SebConnectionTest extends ExamAPIIntegrationTester { // check correct stored final List records = this.clientConnectionRecordMapper .selectByExample() + .where(ClientConnectionRecordDynamicSqlSupport.examId, SqlBuilder.isEqualTo(2L)) .build() .execute(); @@ -120,6 +122,7 @@ public class SebConnectionTest extends ExamAPIIntegrationTester { // check correct stored final List records = this.clientConnectionRecordMapper .selectByExample() + .where(ClientConnectionRecordDynamicSqlSupport.examId, SqlBuilder.isEqualTo(2L)) .build() .execute(); @@ -209,6 +212,7 @@ public class SebConnectionTest extends ExamAPIIntegrationTester { // check correct stored final List records = this.clientConnectionRecordMapper .selectByExample() + .where(ClientConnectionRecordDynamicSqlSupport.examId, SqlBuilder.isEqualTo(2L)) .build() .execute(); @@ -289,6 +293,7 @@ public class SebConnectionTest extends ExamAPIIntegrationTester { // check correct stored final List records = this.clientConnectionRecordMapper .selectByExample() + .where(ClientConnectionRecordDynamicSqlSupport.examId, SqlBuilder.isEqualTo(2L)) .build() .execute(); @@ -316,7 +321,7 @@ public class SebConnectionTest extends ExamAPIIntegrationTester { final String accessToken = super.obtainAccessToken("test", "test", "SEBClient"); assertNotNull(accessToken); - final MockHttpServletResponse createConnection = super.createConnection(accessToken, 1L, null); + final MockHttpServletResponse createConnection = super.createConnection(accessToken, 1L, 2L); assertNotNull(createConnection); final String connectionToken = createConnection.getHeader(API.EXAM_API_SEB_CONNECTION_TOKEN); @@ -351,6 +356,7 @@ public class SebConnectionTest extends ExamAPIIntegrationTester { // check correct stored (no changes) final List records = this.clientConnectionRecordMapper .selectByExample() + .where(ClientConnectionRecordDynamicSqlSupport.examId, SqlBuilder.isEqualTo(2L)) .build() .execute(); @@ -413,6 +419,7 @@ public class SebConnectionTest extends ExamAPIIntegrationTester { // check correct stored (no changes) final List records = this.clientConnectionRecordMapper .selectByExample() + .where(ClientConnectionRecordDynamicSqlSupport.examId, SqlBuilder.isEqualTo(2L)) .build() .execute(); diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebVdiConnectionTest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebVdiConnectionTest.java index a63c9b91..5e722f06 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebVdiConnectionTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebVdiConnectionTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.*; import java.util.List; import org.junit.Test; +import org.mybatis.dynamic.sql.SqlBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; import org.springframework.cache.Cache.ValueWrapper; @@ -22,6 +23,7 @@ import org.springframework.test.context.jdbc.Sql; import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.api.JSONMapper; +import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientConnectionRecordDynamicSqlSupport; import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientConnectionRecordMapper; import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientEventRecordMapper; import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ClientConnectionRecord; @@ -43,7 +45,7 @@ public class SebVdiConnectionTest extends ExamAPIIntegrationTester { final String accessToken = super.obtainAccessToken("testVDI", "testVDI", "read write"); assertNotNull(accessToken); - final MockHttpServletResponse createConnection = super.createConnection(accessToken, 1L, null); + final MockHttpServletResponse createConnection = super.createConnection(accessToken, 1L, 2L); assertNotNull(createConnection); // check correct response @@ -60,13 +62,14 @@ public class SebVdiConnectionTest extends ExamAPIIntegrationTester { // check correct stored final List records = this.clientConnectionRecordMapper .selectByExample() + .where(ClientConnectionRecordDynamicSqlSupport.examId, SqlBuilder.isEqualTo(2L)) .build() .execute(); assertTrue(records.size() == 1); final ClientConnectionRecord clientConnectionRecord = records.get(0); assertEquals("1", String.valueOf(clientConnectionRecord.getInstitutionId())); - assertNull(clientConnectionRecord.getExamId()); + assertEquals("2", clientConnectionRecord.getExamId().toString()); assertEquals("CONNECTION_REQUESTED", String.valueOf(clientConnectionRecord.getStatus())); assertEquals(connectionToken, clientConnectionRecord.getConnectionToken()); assertNotNull(clientConnectionRecord.getClientAddress()); diff --git a/src/test/resources/data-test-additional.sql b/src/test/resources/data-test-additional.sql index c23236b2..9fb96552 100644 --- a/src/test/resources/data-test-additional.sql +++ b/src/test/resources/data-test-additional.sql @@ -13,8 +13,9 @@ INSERT IGNORE INTO additional_attributes VALUES ; INSERT IGNORE INTO exam VALUES - (1, 1, 1, 'quiz1', 'super-admin', 'super-admin', 'MANAGED', null, null, 'UP_COMING', 1, 0, null, 1, null, null), - (2, 1, 1, 'quiz6', 'super-admin', 'super-admin', 'MANAGED', null, null, 'RUNNING', 1, 0, null, 1, null, null) + (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) ; INSERT IGNORE INTO indicator VALUES @@ -874,3 +875,10 @@ INSERT IGNORE INTO exam_configuration_map VALUES (1, 1, 2, 1, null, null) ; +INSERT IGNORE INTO client_connection VALUES + (1,1,3,'CLOSED','62c4bbdc-e8a5-42bc-8161-c3d187360184','-- (connection_080)','127.0.0.1',NULL,0,NULL,1647960776988,1647960797388,NULL,NULL,'machineName','osName','versionXY'), + (2,1,3,'CLOSED','e3abf4e5-ee5c-4cf1-a13a-1ff8fd23718a','-- (connection_063)','127.0.0.1',NULL,0,NULL,1647960776989,1647960797482,NULL,NULL,'machineName','osName','versionXY'), + (3,1,3,'DISABLED','3120f91e-76a9-4810-8628-f25f4099c47b','-- (connection_043)','127.0.0.1',NULL,0,NULL,1647960814460,1648130312083,NULL,NULL,'machineName','osName','versionXY'), + (4,1,3,'ACTIVE','6b901e7f-65fb-425f-a303-25e9d6fcbdf2','-- (connection_003)','127.0.0.1',NULL,0,NULL,1648134709401,1648542395328,NULL,NULL,'machineName','osName','versionXY'), + (5,1,3,'ACTIVE','2a2013a6-1664-4798-8f1d-362e9ec0a4e4','-- (connection_038)','127.0.0.1',NULL,0,NULL,1648135999634,1648542400438,NULL,NULL,'machineName','osName','versionXY'); +