Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12048] Add integration tests for FeedbackResponsesDb #12856

Merged
Merged
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
e1955b6
Migrate SessionResultsData
xenosf Feb 12, 2024
8f0f835
Add default entities
xenosf Feb 12, 2024
d40f2fb
Add helper methods to assist migrated logic
xenosf Feb 12, 2024
da63d4a
Migrate buildCompleteGiverRecipientMap
xenosf Feb 12, 2024
cc8ff7a
Migrate checkSpecificAccessControl
xenosf Feb 1, 2024
a046670
Add default team instance for instructor
xenosf Feb 4, 2024
9b4945b
Migrate session results data logic
xenosf Feb 4, 2024
fb5a808
Use default team entity for instructor instead of const
xenosf Feb 12, 2024
cd64a4c
Migrate non-db logic
xenosf Feb 14, 2024
a78bf65
Merge branch 'v9-migration' into v9-migration-GetSessionResultsAction
xenosf Feb 14, 2024
97ae4b5
Refactor Datastore and SQL action logic out to separate methods
xenosf Feb 15, 2024
51f738f
Fix checkstyle errors
xenosf Feb 15, 2024
6573955
Migrate DB logic
xenosf Feb 16, 2024
13191fe
Merge branch 'v9-migration' into v9-migration-GetSessionResultsAction
xenosf Feb 19, 2024
80d651e
Fix checkstyle errors
xenosf Feb 19, 2024
7e960f7
Move default instructor team entity to const
xenosf Feb 19, 2024
901307a
Add test for SqlSessionResultsBundle
xenosf Feb 19, 2024
29900bd
Fix SQL results bundle test
xenosf Feb 20, 2024
ab20259
Add IT for GetSessionResultsAction
xenosf Feb 20, 2024
06c6b61
Fix action logic
xenosf Feb 20, 2024
0ad3b56
Fix checkstyle errors
xenosf Feb 20, 2024
a23545d
Remove unused method parameters
xenosf Feb 20, 2024
1aa00a8
Merge branch 'v9-migration' into v9-migration-GetSessionResultsAction
xenosf Feb 20, 2024
56a9d93
Fix persistence issues in test cases
xenosf Feb 20, 2024
a5de57d
Remove question getter for comment
xenosf Feb 23, 2024
6e62b70
Rename boolean methods to start with verb
xenosf Feb 23, 2024
fa89559
Reword comment to clarify question ID
xenosf Feb 23, 2024
273032b
Refactor getting question UUID from param value
xenosf Feb 23, 2024
8627c3f
Remove unneeded getters
xenosf Feb 23, 2024
7f7b81b
Remove entities from Const
xenosf Feb 23, 2024
b6d4b0f
Revert changes to SqlCourseRoster
xenosf Feb 23, 2024
bd67d3c
Create and use missing response class
xenosf Feb 23, 2024
092a08b
Merge branch 'v9-migration' into v9-migration-GetSessionResultsAction
xenosf Feb 23, 2024
0668931
Refactor no response text to const
xenosf Feb 24, 2024
82eeeb8
Merge branch 'v9-migration' into v9-migration-GetSessionResultsAction
xenosf Feb 24, 2024
f850787
Merge branch 'v9-migration' into v9-migration-GetSessionResultsAction
xenosf Feb 24, 2024
a012ad2
Migrate preview-related functionality
xenosf Feb 24, 2024
4401890
Merge branch 'v9-migration' into v9-migration-GetSessionResultsAction
xenosf Feb 24, 2024
2504ead
Migrate preview functionality for question output
xenosf Feb 24, 2024
3811154
Fix recipient section filter
xenosf Feb 26, 2024
08ca697
Merge branch 'master' into v9-migration-GetSessionResultsAction
xenosf Feb 26, 2024
f8c18b8
Update test cases to handle question preview
xenosf Feb 26, 2024
4a75f0e
Merge duplicate methods
xenosf Feb 26, 2024
27ca58d
Fix checkstyle errors
xenosf Feb 26, 2024
79fae78
Add missing questions with non-visible preview responses
xenosf Feb 26, 2024
809b006
Merge branch 'master' into v9-migration-GetSessionResultsAction
xenosf Feb 26, 2024
5d8bf95
Remove outdated test
xenosf Feb 26, 2024
e10e4ba
Edit for style and readability
xenosf Feb 26, 2024
343bd0e
Fix missing join
xenosf Feb 26, 2024
36eb927
Fix section filtering logic
xenosf Feb 26, 2024
f762d0e
Fix checkstyle errors
xenosf Feb 26, 2024
d34caa1
Merge branch 'master' into v9-migration-GetSessionResultsAction
xenosf Feb 27, 2024
4f7cc3a
Merge branch 'master' into v9-migration-add-tests-FeedbackResponsesDb
xenosf Feb 27, 2024
ae72f5f
Add integration tests
xenosf Feb 28, 2024
454c74b
Merge branch 'master' into v9-migration-add-tests-FeedbackResponsesDb
xenosf Feb 28, 2024
2c6447f
Update and use typical bundle
xenosf Mar 1, 2024
4d61c98
Update test cases for updated bundle
xenosf Mar 4, 2024
66cff71
Merge branch 'master' into v9-migration-add-tests-FeedbackResponsesDb
xenosf Mar 12, 2024
6e691a0
Revert typical data bundle
xenosf Mar 12, 2024
74cd952
Use separate data bundle for feedback responses test
xenosf Mar 12, 2024
2b6218b
Revert unrelated tests
xenosf Mar 12, 2024
eed82da
Fix json formatting
xenosf Mar 12, 2024
50b857a
Merge branch 'master' into v9-migration-add-tests-FeedbackResponsesDb
xenosf Mar 13, 2024
23a9e99
Merge branch 'master' into v9-migration-add-tests-FeedbackResponsesDb
cedricongjh Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 215 additions & 19 deletions src/it/java/teammates/it/storage/sqlapi/FeedbackResponsesDbIT.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package teammates.it.storage.sqlapi;

import java.util.HashSet;
import java.util.List;
import java.util.UUID;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import teammates.common.datatransfer.FeedbackResultFetchType;
import teammates.common.datatransfer.SqlDataBundle;
import teammates.common.datatransfer.questions.FeedbackResponseDetails;
import teammates.common.datatransfer.questions.FeedbackTextResponseDetails;
Expand All @@ -29,31 +32,33 @@ public class FeedbackResponsesDbIT extends BaseTestCaseWithSqlDatabaseAccess {
private final FeedbackResponsesDb frDb = FeedbackResponsesDb.inst();
private final FeedbackResponseCommentsDb frcDb = FeedbackResponseCommentsDb.inst();

private SqlDataBundle typicalDataBundle;
private SqlDataBundle testDataBundle;

@Override
@BeforeClass
public void setupClass() {
super.setupClass();
typicalDataBundle = getTypicalSqlDataBundle();
testDataBundle = loadSqlDataBundle("/FeedbackResponsesITBundle.json");
}

@Override
@BeforeMethod
protected void setUp() throws Exception {
super.setUp();
persistDataBundle(typicalDataBundle);
persistDataBundle(testDataBundle);
HibernateUtil.flushSession();
HibernateUtil.clearSession();
}

@Test
public void testGetFeedbackResponsesFromGiverForQuestion() {
______TS("success: typical case");
FeedbackQuestion fq = typicalDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
FeedbackResponse fr = typicalDataBundle.feedbackResponses.get("response1ForQ1");
FeedbackQuestion fq = testDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");

List<FeedbackResponse> expectedQuestions = List.of(fr);
List<FeedbackResponse> expectedQuestions = List.of(
testDataBundle.feedbackResponses.get("response1ForQ1"),
testDataBundle.feedbackResponses.get("response3ForQ1")
);

List<FeedbackResponse> actualQuestions =
frDb.getFeedbackResponsesFromGiverForQuestion(fq.getId(), "[email protected]");
Expand All @@ -65,10 +70,10 @@ public void testGetFeedbackResponsesFromGiverForQuestion() {
@Test
public void testDeleteFeedbackResponsesForQuestionCascade() {
______TS("success: typical case");
FeedbackQuestion fq = typicalDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
FeedbackResponse fr1 = typicalDataBundle.feedbackResponses.get("response1ForQ1");
FeedbackResponse fr2 = typicalDataBundle.feedbackResponses.get("response2ForQ1");
FeedbackResponseComment frc1 = typicalDataBundle.feedbackResponseComments.get("comment1ToResponse1ForQ1");
FeedbackQuestion fq = testDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
FeedbackResponse fr1 = testDataBundle.feedbackResponses.get("response1ForQ1");
FeedbackResponse fr2 = testDataBundle.feedbackResponses.get("response2ForQ1");
FeedbackResponseComment frc1 = testDataBundle.feedbackResponseComments.get("comment1ToResponse1ForQ1");

frDb.deleteFeedbackResponsesForQuestionCascade(fq.getId());

Expand All @@ -80,7 +85,7 @@ public void testDeleteFeedbackResponsesForQuestionCascade() {
@Test
public void testDeleteFeedback() {
______TS("success: typical case");
FeedbackResponse fr1 = typicalDataBundle.feedbackResponses.get("response1ForQ1");
FeedbackResponse fr1 = testDataBundle.feedbackResponses.get("response1ForQ1");

frDb.deleteFeedbackResponse(fr1);

Expand All @@ -90,8 +95,8 @@ public void testDeleteFeedback() {
@Test
public void testHasResponsesFromGiverInSession() {
______TS("success: typical case");
Course course = typicalDataBundle.courses.get("course1");
FeedbackSession fs = typicalDataBundle.feedbackSessions.get("session1InCourse1");
Course course = testDataBundle.courses.get("course1");
FeedbackSession fs = testDataBundle.feedbackSessions.get("session1InCourse1");

boolean actualHasReponses1 =
frDb.hasResponsesFromGiverInSession("[email protected]", fs.getName(), course.getId());
Expand All @@ -108,15 +113,15 @@ public void testHasResponsesFromGiverInSession() {
@Test
public void testAreThereResponsesForQuestion() {
______TS("success: typical case");
FeedbackQuestion fq1 = typicalDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
FeedbackQuestion fq1 = testDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");

boolean actualResponse1 =
frDb.areThereResponsesForQuestion(fq1.getId());

assertTrue(actualResponse1);

______TS("feedback question with no responses");
FeedbackQuestion fq2 = typicalDataBundle.feedbackQuestions.get("qn6InSession1InCourse1NoResponses");
FeedbackQuestion fq2 = testDataBundle.feedbackQuestions.get("qn6InSession1InCourse1NoResponses");

boolean actualResponse2 =
frDb.areThereResponsesForQuestion(fq2.getId());
Expand All @@ -127,7 +132,7 @@ public void testAreThereResponsesForQuestion() {
@Test
public void testHasResponsesForCourse() {
______TS("success: typical case");
Course course = typicalDataBundle.courses.get("course1");
Course course = testDataBundle.courses.get("course1");

boolean actual =
frDb.hasResponsesForCourse(course.getId());
Expand All @@ -136,7 +141,7 @@ public void testHasResponsesForCourse() {
}

private FeedbackResponse prepareSqlInjectionTest() {
FeedbackResponse fr = typicalDataBundle.feedbackResponses.get("response1ForQ1");
FeedbackResponse fr = testDataBundle.feedbackResponses.get("response1ForQ1");
assertNotNull(frDb.getFeedbackResponse(fr.getId()));

return fr;
Expand Down Expand Up @@ -207,8 +212,8 @@ public void testSqlInjectionInHasResponsesForCourse() {
public void testSqlInjectionInCreateFeedbackResponse() throws Exception {
FeedbackResponse fr = prepareSqlInjectionTest();

FeedbackQuestion fq = typicalDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
Section s = typicalDataBundle.sections.get("section1InCourse1");
FeedbackQuestion fq = testDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
Section s = testDataBundle.sections.get("section1InCourse1");
String dummyUuid = "00000000-0000-4000-8000-000000000001";
FeedbackResponseDetails frd = new FeedbackTextResponseDetails();

Expand All @@ -230,4 +235,195 @@ public void testSqlInjectionInCpdateFeedbackResponse() throws Exception {

checkSqliFailed(fr);
}

@Test
public void testGetFeedbackResponsesForRecipientForQuestion_matchNotFound_shouldReturnEmptyList() {
______TS("Question not found");
String recipient = "[email protected]";
UUID nonexistentQuestionId = UUID.fromString("11110000-0000-0000-0000-000000000000");
List<FeedbackResponse> results = frDb.getFeedbackResponsesForRecipientForQuestion(nonexistentQuestionId, recipient);
assertEquals(0, results.size());

______TS("No matching responses exist");
FeedbackQuestion questionWithNoResponses = testDataBundle.feedbackQuestions.get("qn4InSession1InCourse1");
results = frDb.getFeedbackResponsesForRecipientForQuestion(questionWithNoResponses.getId(), recipient);
assertEquals(0, results.size());

}

@Test
public void testGetFeedbackResponsesForRecipientForQuestion_matchFound_success() {
______TS("Matching responses exist");
String recipient = "[email protected]";
FeedbackQuestion question = testDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
List<FeedbackResponse> expected = List.of(
testDataBundle.feedbackResponses.get("response2ForQ1")
);
List<FeedbackResponse> actual = frDb.getFeedbackResponsesForRecipientForQuestion(question.getId(), recipient);
assertListResponsesEqual(expected, actual);

}

@Test
public void testGetFeedbackResponsesForSessionInSection_matchNotFound_shouldReturnEmptyList() {
String section3 = testDataBundle.sections.get("section3InCourse1").getName();
FeedbackSession session = testDataBundle.feedbackSessions.get("session1InCourse1");
String courseId = session.getCourse().getId();

______TS("No matching responses exist for giver section");
FeedbackResultFetchType fetchType = FeedbackResultFetchType.GIVER;
List<FeedbackResponse> results = frDb.getFeedbackResponsesForSessionInSection(
session, courseId, section3, fetchType);
assertEquals(0, results.size());

______TS("No matching responses exist for recipient section");
fetchType = FeedbackResultFetchType.RECEIVER;
results = frDb.getFeedbackResponsesForSessionInSection(session, courseId, section3, fetchType);
assertEquals(0, results.size());

______TS("No matching responses exist for both giver and recipient section");
fetchType = FeedbackResultFetchType.BOTH;
results = frDb.getFeedbackResponsesForSessionInSection(session, courseId, section3, fetchType);
assertEquals(0, results.size());
}

@Test
public void testGetFeedbackResponsesForSessionInSection_matchFound_success() {
Course course = testDataBundle.courses.get("course1");
FeedbackSession session1 = testDataBundle.feedbackSessions.get("session1InCourse1");
Section section1 = testDataBundle.sections.get("section1InCourse1");
Section section2 = testDataBundle.sections.get("section2InCourse1");

______TS("Match giver section 1 in session 1");
FeedbackResultFetchType fetchType = FeedbackResultFetchType.GIVER;
List<FeedbackResponse> expected = List.of(
testDataBundle.feedbackResponses.get("response1ForQ1"),
testDataBundle.feedbackResponses.get("response2ForQ1"),
testDataBundle.feedbackResponses.get("response1ForQ2"),
testDataBundle.feedbackResponses.get("response2ForQ2"),
testDataBundle.feedbackResponses.get("response1ForQ3"),
testDataBundle.feedbackResponses.get("response3ForQ1"),
testDataBundle.feedbackResponses.get("response3ForQ2")
);
List<FeedbackResponse> actual = frDb.getFeedbackResponsesForSessionInSection(
session1, course.getId(), section1.getName(), fetchType);
assertListResponsesEqual(expected, actual);

______TS("Match recipient section 2 in session 1");
fetchType = FeedbackResultFetchType.RECEIVER;
expected = List.of(
testDataBundle.feedbackResponses.get("response3ForQ1"),
testDataBundle.feedbackResponses.get("response3ForQ2"),
testDataBundle.feedbackResponses.get("response4ForQ1")
);
actual = frDb.getFeedbackResponsesForSessionInSection(session1, course.getId(),
section2.getName(), fetchType);
assertListResponsesEqual(expected, actual);

______TS("Match both giver and recipient section 2 in session 1");
fetchType = FeedbackResultFetchType.BOTH;
expected = List.of(
testDataBundle.feedbackResponses.get("response4ForQ1")
);
actual = frDb.getFeedbackResponsesForSessionInSection(session1, course.getId(),
section2.getName(), fetchType);
assertListResponsesEqual(expected, actual);
}

@Test
public void testGetFeedbackResponsesForQuestionInSection_matchNotFound_shouldReturnEmptyList() {
String section1 = testDataBundle.sections.get("section1InCourse1").getName();
String section3 = testDataBundle.sections.get("section3InCourse1").getName();

______TS("Question not found");
UUID nonexistentQuestionId = UUID.fromString("11110000-0000-0000-0000-000000000000");
FeedbackResultFetchType fetchType = FeedbackResultFetchType.BOTH;
List<FeedbackResponse> results = frDb.getFeedbackResponsesForQuestionInSection(nonexistentQuestionId,
section1, fetchType);
assertEquals(0, results.size());

______TS("No matching responses exist for giver section");
UUID questionId = testDataBundle.feedbackQuestions.get("qn1InSession1InCourse1").getId();
fetchType = FeedbackResultFetchType.GIVER;
results = frDb.getFeedbackResponsesForQuestionInSection(questionId, section3, fetchType);
assertEquals(0, results.size());

______TS("No matching responses exist for recipient section");
fetchType = FeedbackResultFetchType.RECEIVER;
results = frDb.getFeedbackResponsesForQuestionInSection(questionId, section3, fetchType);
assertEquals(0, results.size());

______TS("No matching responses exist for both giver and recipient section");
fetchType = FeedbackResultFetchType.BOTH;
results = frDb.getFeedbackResponsesForQuestionInSection(questionId, section3, fetchType);
assertEquals(0, results.size());
}

@Test
public void testGetFeedbackResponsesForQuestionInSection_matchFound_success() {
Section section1 = testDataBundle.sections.get("section1InCourse1");
Section section2 = testDataBundle.sections.get("section2InCourse1");
FeedbackQuestion question1 = testDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");

______TS("Match giver section 1 for Q1");
FeedbackResultFetchType fetchType = FeedbackResultFetchType.GIVER;
List<FeedbackResponse> expected = List.of(
testDataBundle.feedbackResponses.get("response1ForQ1"),
testDataBundle.feedbackResponses.get("response2ForQ1"),
testDataBundle.feedbackResponses.get("response3ForQ1")
);
List<FeedbackResponse> actual = frDb.getFeedbackResponsesForQuestionInSection(question1.getId(),
section1.getName(), fetchType);
assertListResponsesEqual(expected, actual);

______TS("Match recipient section 2 for Q1");
fetchType = FeedbackResultFetchType.RECEIVER;
expected = List.of(
testDataBundle.feedbackResponses.get("response3ForQ1"),
testDataBundle.feedbackResponses.get("response4ForQ1")
);
actual = frDb.getFeedbackResponsesForQuestionInSection(question1.getId(), section2.getName(), fetchType);
assertListResponsesEqual(expected, actual);

______TS("Match both giver and recipient section 2 for Q1");
fetchType = FeedbackResultFetchType.BOTH;
expected = List.of(
testDataBundle.feedbackResponses.get("response4ForQ1")
);
actual = frDb.getFeedbackResponsesForQuestionInSection(question1.getId(), section2.getName(), fetchType);
assertListResponsesEqual(expected, actual);
}

@Test
public void testGetFeedbackResponsesForSession() {
______TS("Session has responses");
FeedbackSession sessionWithResponses = testDataBundle.feedbackSessions.get("session1InCourse1");
List<FeedbackResponse> expected = List.of(
testDataBundle.feedbackResponses.get("response1ForQ1"),
testDataBundle.feedbackResponses.get("response2ForQ1"),
testDataBundle.feedbackResponses.get("response1ForQ2"),
testDataBundle.feedbackResponses.get("response2ForQ2"),
testDataBundle.feedbackResponses.get("response1ForQ3"),
testDataBundle.feedbackResponses.get("response3ForQ1"),
testDataBundle.feedbackResponses.get("response3ForQ2"),
testDataBundle.feedbackResponses.get("response4ForQ1")
);
List<FeedbackResponse> actual = frDb.getFeedbackResponsesForSession(sessionWithResponses,
sessionWithResponses.getCourse().getId());
assertListResponsesEqual(expected, actual);

______TS("Session has no responses");
FeedbackSession sessionWithoutResponses = testDataBundle.feedbackSessions.get(
"unpublishedSession1InTypicalCourse");
actual = frDb.getFeedbackResponsesForSession(sessionWithoutResponses, sessionWithResponses.getCourse().getId());
assertEquals(0, actual.size());
}

private void assertListResponsesEqual(List<FeedbackResponse> expected, List<FeedbackResponse> actual) {
assertEquals("List size not equal.", expected.size(), actual.size());
assertTrue(
String.format("List contents are not equal.%nExpected: %s,%nActual: %s",
expected.toString(), actual.toString()),
new HashSet<>(expected).equals(new HashSet<>(actual)));
}
}
Loading