Skip to content

Commit e8360cc

Browse files
author
Nadim Ritter
committed
SEBSP-171 improve test data and integration tests
1 parent f201701 commit e8360cc

File tree

3 files changed

+144
-146
lines changed

3 files changed

+144
-146
lines changed

src/test/java/ch/ethz/seb/sps/integrationtests/proctoring/ProctoringServiceTest.java

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33
import ch.ethz.seb.sps.domain.api.API;
44
import ch.ethz.seb.sps.domain.model.Page;
55
import ch.ethz.seb.sps.domain.model.PageSortOrder;
6+
import ch.ethz.seb.sps.domain.model.service.DistinctMetadataWindowForExam;
67
import ch.ethz.seb.sps.domain.model.service.Exam;
78
import ch.ethz.seb.sps.domain.model.service.GroupViewData;
89
import ch.ethz.seb.sps.domain.model.service.ScreenshotSearchResult;
910
import ch.ethz.seb.sps.domain.model.service.ScreenshotViewData;
1011
import ch.ethz.seb.sps.domain.model.service.ScreenshotsInGroupData;
1112
import ch.ethz.seb.sps.domain.model.service.SessionSearchResult;
1213
import ch.ethz.seb.sps.domain.model.service.TimelineViewData;
13-
import ch.ethz.seb.sps.server.datalayer.dao.ClientAccessDAO;
14-
import ch.ethz.seb.sps.server.datalayer.dao.ScreenshotDataDAO;
15-
import ch.ethz.seb.sps.server.datalayer.dao.UserDAO;
16-
import ch.ethz.seb.sps.server.weblayer.AdminProctorController;
14+
import ch.ethz.seb.sps.domain.model.service.UserListForApplicationSearch;
1715
import com.fasterxml.jackson.core.type.TypeReference;
1816
import org.junit.Test;
19-
import org.springframework.beans.factory.annotation.Autowired;
2017
import org.springframework.http.HttpMethod;
2118

2219
import java.sql.Date;
23-
import java.util.ArrayList;
2420
import java.util.Arrays;
2521
import java.util.HashMap;
2622
import java.util.List;
@@ -42,8 +38,8 @@ public void testFullUseCaseSuccess() throws Exception {
4238
final int expectedAmountOfScreenshots = 2;
4339
final String expectedGroupUuid = "3cfb99c0-34a5-4ffd-a11c-6d9790b3f24c";
4440
final String expectedSessionUuid = "9cfb99c0-34a5-4ffd-a11c-4d9790b3f24c";
45-
final String expectedGroupingKey = "Google Homepage";
46-
final int expectedLengthOfGroupedScreenshotData = 10;
41+
final String expectedGroupingKey = "Stackoverflow";
42+
final int expectedLengthOfGroupedScreenshotData = 1;
4743
final List<Long> expectedScreenshotTimestamps = Arrays.asList(1721743482182l, 1721743483215l, 1721743484222l, 1721743485226l, 1721743486247l);
4844
final List<Date> expectedUniqueDays = Arrays.asList(Date.valueOf("2024-07-23"), Date.valueOf("2024-07-11"));
4945
final List<String> expectedSessionSearchUuids = Arrays.asList("9cfb99c0-34a5-4ffd-a11c-4d9790b3f24c", "4461dec0-5579-4fef-a86f-0ec7b252c779", "c8ebdedc-1105-4ecb-bd04-c20ba2e221a5");
@@ -183,9 +179,9 @@ public void testFullUseCaseSuccess() throws Exception {
183179
@Test
184180
public void testApplicationSearch() throws Exception {
185181
//GIVEN
186-
Long expectedExamId = 1l;
187-
List<Long> expectedGroupIds = Arrays.asList(1l, 2l);
188-
// List<String> expectedMetadataApp = Arrays.asList("")
182+
int expectedAmountOfDistinctMetadataApp = 3;
183+
int expectedAmountOfDistinctMetadataWindow = 2;
184+
int expectedAmountOfUsers = 4;
189185

190186
//WHEN
191187
//1. get exams in the given time frame
@@ -199,29 +195,53 @@ public void testApplicationSearch() throws Exception {
199195
//2. get groupIds for given exam
200196
//endpoint: /search/applications/groupdIds/<examId>
201197
List<Long> groupIds = createMockApiCall(
202-
API.APPLICATION_SEARCH_ENDPOINT + "/groupIds/" + 1L,
198+
API.APPLICATION_SEARCH_ENDPOINT + "/groupIds/" + exams.get(0).getId(),
203199
HttpMethod.GET,
204200
new TypeReference<List<Long>>(){},
205201
new HashMap<>());
206202

207-
//2. get metadata application for given groupIds
203+
//3. get metadata application for given groupIds
208204
//endpoint: /search/applications/metadata/app
209-
Map<String, String> groupIdsAttributes = new HashMap<>();
210-
groupIdsAttributes.put("groupIds", "1,2");
211-
//
212-
// List<String> metadataAppList = createMockApiCall(
213-
// API.APPLICATION_SEARCH_METADATA_APP_ENDPOINT,
214-
// HttpMethod.GET,
215-
// new TypeReference<List<String>>(){},
216-
// groupIdsAttributes);
217-
//
218-
// System.out.println(exams);
205+
//set groupIds attributes (same for all calls)
206+
Map<String, String> metadataAppAttributes = new HashMap<>();
207+
metadataAppAttributes.put("groupIds", groupIds.get(0) + "," + groupIds.get(1));
219208

209+
List<String> metadataAppList = createMockApiCall(
210+
API.APPLICATION_SEARCH_METADATA_APP_ENDPOINT,
211+
HttpMethod.GET,
212+
new TypeReference<List<String>>(){},
213+
metadataAppAttributes);
220214

215+
//4. get metadata window titles for given groupIds
216+
//endpoint: /search/applications/metadata/window
217+
Map<String, String> metadataWindowAttributes = new HashMap<>();
218+
metadataWindowAttributes.put("groupIds", groupIds.get(0) + "," + groupIds.get(1));
219+
metadataWindowAttributes.put("screenProctoringMetadataApplication", metadataAppList.get(0));
220+
221+
DistinctMetadataWindowForExam metadataWindowList = createMockApiCall(
222+
API.APPLICATION_SEARCH_METADATA_WINDOW_ENDPOINT,
223+
HttpMethod.GET,
224+
new TypeReference<DistinctMetadataWindowForExam>(){},
225+
metadataWindowAttributes);
221226

222-
//THEN
223227

228+
//5. get a list of users who match the metadata search
229+
//endpoint: /search/applications/users
230+
Map<String, String> usersAttributes = new HashMap<>();
231+
usersAttributes.put("groupIds", groupIds.get(0) + "," + groupIds.get(1));
232+
usersAttributes.put("screenProctoringMetadataApplication", metadataAppList.get(0));
233+
usersAttributes.put("screenProctoringMetadataWindowTitle", metadataWindowList.distinctWindowTitles().stream().toList().get(0));
224234

235+
List<UserListForApplicationSearch> userList = createMockApiCall(
236+
API.APPLICATION_SEARCH_USER_LIST_ENDPOINT,
237+
HttpMethod.GET,
238+
new TypeReference<List<UserListForApplicationSearch>>(){},
239+
usersAttributes);
240+
241+
//THEN
242+
assertEquals(expectedAmountOfDistinctMetadataApp, metadataAppList.size());
243+
assertEquals(expectedAmountOfDistinctMetadataWindow, metadataWindowList.distinctWindowTitles().size());
244+
assertEquals(expectedAmountOfUsers, userList.size());
225245
}
226246

227247

src/test/java/ch/ethz/seb/sps/integrationtests/proctoring/ServiceTest_PROCTORING.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
package ch.ethz.seb.sps.integrationtests.proctoring;
22

3-
import ch.ethz.seb.sps.domain.Domain;
4-
import ch.ethz.seb.sps.domain.api.API;
53
import ch.ethz.seb.sps.domain.api.JSONMapper;
6-
import ch.ethz.seb.sps.domain.model.service.ScreenshotData;
7-
import ch.ethz.seb.sps.domain.model.service.Session;
8-
import ch.ethz.seb.sps.domain.model.user.ServerUser;
9-
import ch.ethz.seb.sps.domain.model.user.UserInfo;
10-
import ch.ethz.seb.sps.server.datalayer.dao.ScreenshotDataDAO;
11-
import ch.ethz.seb.sps.server.datalayer.dao.UserDAO;
12-
import com.fasterxml.jackson.annotation.JsonProperty;
134
import com.fasterxml.jackson.core.type.TypeReference;
14-
import org.flywaydb.core.internal.jdbc.JdbcTemplate;
15-
import org.joda.time.DateTimeZone;
165
import org.junit.Before;
17-
import org.junit.Test;
186
import org.junit.runner.RunWith;
197
import org.springframework.beans.factory.annotation.Autowired;
208
import org.springframework.beans.factory.annotation.Value;
@@ -24,8 +12,6 @@
2412
import org.springframework.http.HttpMethod;
2513
import org.springframework.http.HttpStatus;
2614
import org.springframework.http.MediaType;
27-
import org.springframework.mock.web.MockServletContext;
28-
import org.springframework.security.core.userdetails.User;
2915
import org.springframework.security.web.FilterChainProxy;
3016
import org.springframework.test.context.ActiveProfiles;
3117
import org.springframework.test.context.jdbc.Sql;
@@ -41,16 +27,9 @@
4127
import org.springframework.util.MultiValueMap;
4228
import org.springframework.web.context.WebApplicationContext;
4329

44-
import jakarta.servlet.ServletContext;
4530
import java.util.HashMap;
46-
import java.util.HashSet;
47-
import java.util.List;
48-
import java.util.Locale;
4931
import java.util.Map;
50-
import java.util.Set;
5132

52-
import static org.junit.Assert.assertNotNull;
53-
import static org.junit.Assert.assertTrue;
5433
import static org.springframework.http.HttpMethod.*;
5534
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
5635
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
@@ -61,7 +40,6 @@
6140
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
6241
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
6342
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
64-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
6543

6644
@RunWith(SpringRunner.class)
6745
@SpringBootTest(

0 commit comments

Comments
 (0)