Skip to content

Commit 83438ec

Browse files
author
Rupert Westenthaler
committed
MORE-Platform#393: added cleanup to the test
1 parent 9f608cb commit 83438ec

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

studymanager-services/src/main/java/io/redlink/more/studymanager/repository/goals/GoalConfigurationRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ INSERT INTO goal_adherence_checks(study_id, check_id, title, time)
6666
private static final String DELETE_ADHERENCE_CHECKS = "DELETE FROM goal_adherence_checks WHERE study_id = ?";
6767
private static final String UPDATE_ADHERENCE_CHECK = "UPDATE goal_adherence_checks SET title = :title, time = :time WHERE study_id = :study_id AND check_id = :check_id";
6868

69+
private static final String DELETE_ALL = "DELETE FROM study_goal_config";
70+
71+
6972
private final JdbcTemplate template;
7073
private final NamedParameterJdbcTemplate namedTemplate;
7174

@@ -196,6 +199,10 @@ public void deleteCheck(Long studyId, Integer checkId) {
196199
}
197200
}
198201

202+
public void clear() {
203+
template.execute(DELETE_ALL);
204+
}
205+
199206
private MapSqlParameterSource toParams(StudyGoalConfig config) {
200207
return new MapSqlParameterSource()
201208
.addValue("study_id", config.getStudyId())

studymanager-services/src/test/java/io/redlink/more/studymanager/repository/goals/GoalRepositoryTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,23 @@ class GoalRepositoryTest {
4747
@Autowired
4848
private ParticipantRepository participantRepository;
4949

50+
Long studyId = null;
51+
5052
@BeforeEach
5153
void deleteAll() {
5254
goalRepository.clear();
55+
participantRepository.clear();
56+
goalTemplateRepository.clear();
57+
goalConfigurationRepository.clear();
58+
if(studyId != null) {
59+
studyRepository.deleteById(studyId);
60+
studyId = null;
61+
}
5362
}
5463

5564
@Test
5665
public void testInsertListUpdateDeleteAndFlexibleQueries() {
57-
Long studyId = studyRepository.insert(new Study().setContact(new Contact().setPerson("test").setEmail("test"))).getStudyId();
66+
studyId = studyRepository.insert(new Study().setContact(new Contact().setPerson("test").setEmail("test"))).getStudyId();
5867
Integer participantId = participantRepository.insert(new Participant().setStudyId(studyId).setRegistrationToken("t")).getParticipantId();
5968
Integer templateId = goalTemplateRepository.insert(new GoalTemplate().setStudyId(studyId).setType("test")).getTemplateId();
6069

@@ -86,7 +95,7 @@ public void testInsertListUpdateDeleteAndFlexibleQueries() {
8695
@Test
8796
public void testFlexibleListQueriesWithMultipleGoalsPerParticipantAndTemplate() {
8897
// === Setup ===
89-
Long studyId = studyRepository.insert(new Study().setContact(new Contact().setPerson("test").setEmail("test"))).getStudyId();
98+
studyId = studyRepository.insert(new Study().setContact(new Contact().setPerson("test").setEmail("test"))).getStudyId();
9099

91100
Integer p1 = participantRepository.insert(new Participant().setStudyId(studyId).setRegistrationToken("p1")).getParticipantId();
92101
Integer p2 = participantRepository.insert(new Participant().setStudyId(studyId).setRegistrationToken("p2")).getParticipantId();
@@ -189,7 +198,7 @@ public void testFlexibleListQueriesWithMultipleGoalsPerParticipantAndTemplate()
189198
@Test
190199
@DisplayName("Goal adherence checks are correctly saved, loaded and updated")
191200
void testGoalAdherenceChecksMapping() {
192-
Long studyId = studyRepository.insert(new Study().setContact(new Contact().setPerson("test").setEmail("test"))).getStudyId();
201+
studyId = studyRepository.insert(new Study().setContact(new Contact().setPerson("test").setEmail("test"))).getStudyId();
193202
Integer participantId = participantRepository.insert(new Participant().setStudyId(studyId).setRegistrationToken("t")).getParticipantId();
194203
Integer templateId = goalTemplateRepository.insert(new GoalTemplate().setStudyId(studyId).setType("test")).getTemplateId();
195204

0 commit comments

Comments
 (0)