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 FeedbackResponseCommentsDb #12849

Merged
Changes from 58 commits
Commits
Show all changes
62 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
fc290a1
Add integration tests
xenosf Feb 26, 2024
3f7949b
Refactor tests for readability
xenosf Feb 27, 2024
16a2275
Merge branch 'master' into v9-migration-add-tests-FeedbackResponseCom…
xenosf Feb 27, 2024
3d13901
Fix broken test cases
xenosf Feb 28, 2024
b1bc6ee
Rename test section key
xenosf Feb 28, 2024
7ec93f2
Merge branch 'master' into v9-migration-add-tests-FeedbackResponseCom…
xenosf Feb 28, 2024
4271cc4
Merge branch 'master' into v9-migration-add-tests-FeedbackResponseCom…
xenosf Mar 12, 2024
41a43a7
Use separate json bundle for test data
xenosf Mar 12, 2024
d4b9c04
Clear session when set up
xenosf Mar 12, 2024
134aa93
Merge branch 'master' into v9-migration-add-tests-FeedbackResponseCom…
cedricongjh Mar 12, 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
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
package teammates.it.storage.sqlapi;

import java.util.ArrayList;
import java.util.Arrays;
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.FeedbackParticipantType;
import teammates.common.datatransfer.SqlDataBundle;
import teammates.common.datatransfer.questions.FeedbackTextResponseDetails;
import teammates.common.exception.EntityAlreadyExistsException;
import teammates.common.exception.InvalidParametersException;
import teammates.common.util.HibernateUtil;
import teammates.it.test.BaseTestCaseWithSqlDatabaseAccess;
import teammates.storage.sqlapi.FeedbackResponseCommentsDb;
import teammates.storage.sqlentity.Course;
import teammates.storage.sqlentity.FeedbackQuestion;
import teammates.storage.sqlentity.FeedbackResponse;
import teammates.storage.sqlentity.FeedbackResponseComment;
import teammates.storage.sqlentity.FeedbackSession;
import teammates.storage.sqlentity.Section;
import teammates.storage.sqlentity.responses.FeedbackTextResponse;

/**
* SUT: {@link FeedbackResponseCommentsDb}.
Expand Down Expand Up @@ -45,4 +60,256 @@ public void testGetFeedbackResponseCommentForResponseFromParticipant() {

assertEquals(expectedComment, actualComment);
}

@Test
public void testGetFeedbackResponseCommentsForSession_matchFound_success() {
Course course = typicalDataBundle.courses.get("course1");

______TS("Session with comments");
FeedbackSession sessionWithComments = typicalDataBundle.feedbackSessions.get("session1InCourse1");
List<FeedbackResponseComment> expected = List.of(
typicalDataBundle.feedbackResponseComments.get("comment1ToResponse1ForQ1"),
typicalDataBundle.feedbackResponseComments.get("comment2ToResponse1ForQ1"),
typicalDataBundle.feedbackResponseComments.get("comment2ToResponse2ForQ1"),
typicalDataBundle.feedbackResponseComments.get("comment1ToResponse1ForQ2s"),
typicalDataBundle.feedbackResponseComments.get("comment1ToResponse1ForQ3")
);
List<FeedbackResponseComment> results = frcDb.getFeedbackResponseCommentsForSession(
course.getId(), sessionWithComments.getName());
assertListCommentsEqual(expected, results);
}

@Test
public void testGetFeedbackResponseCommentsForSession_matchNotFound_shouldReturnEmptyList() {
Course course = typicalDataBundle.courses.get("course1");
FeedbackSession session = typicalDataBundle.feedbackSessions.get("session1InCourse1");

______TS("Course not found");
List<FeedbackResponseComment> results = frcDb.getFeedbackResponseCommentsForSession("not_exist", session.getName());
assertEquals(0, results.size());

______TS("Session not found");
results = frcDb.getFeedbackResponseCommentsForSession(course.getId(), "Nonexistent session");
assertEquals(0, results.size());

______TS("Session without comments");
FeedbackSession sessionWithoutComments = typicalDataBundle.feedbackSessions.get("session2InTypicalCourse");
results = frcDb.getFeedbackResponseCommentsForSession(course.getId(), sessionWithoutComments.getName());
assertEquals(0, results.size());
}

@Test
public void testGetFeedbackResponseCommentsForQuestion_matchFound_success() {
______TS("Question with comments");
FeedbackQuestion questionWithComments = typicalDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
List<FeedbackResponseComment> expectedComments = Arrays.asList(
typicalDataBundle.feedbackResponseComments.get("comment1ToResponse1ForQ1"),
typicalDataBundle.feedbackResponseComments.get("comment2ToResponse1ForQ1"),
typicalDataBundle.feedbackResponseComments.get("comment2ToResponse2ForQ1"));
List<FeedbackResponseComment> results = frcDb.getFeedbackResponseCommentsForQuestion(questionWithComments.getId());
assertListCommentsEqual(expectedComments, results);
}

@Test
public void testGetFeedbackResponseCommentsForQuestion_matchNotFound_shouldReturnEmptyList() {
______TS("Question not found");
UUID nonexistentQuestionId = UUID.fromString("11110000-0000-0000-0000-000000000000");
List<FeedbackResponseComment> results = frcDb.getFeedbackResponseCommentsForQuestion(nonexistentQuestionId);
assertEquals(0, results.size());

______TS("Question without comments");
FeedbackQuestion questionWithoutComments = typicalDataBundle.feedbackQuestions.get("qn5InSession1InCourse1");
results = frcDb.getFeedbackResponseCommentsForQuestion(questionWithoutComments.getId());
assertEquals(0, results.size());
}

@Test
public void testGetFeedbackResponseCommentsForSessionInSection_matchFound_success()
throws EntityAlreadyExistsException, InvalidParametersException {
SqlDataBundle additionalTestData = getAdditionalTestData();
Section section1 = additionalTestData.sections.get("section1aInCourse1");
Section section2 = additionalTestData.sections.get("section2aInCourse1");
Course course = additionalTestData.courses.get("course1");
FeedbackSession session = additionalTestData.feedbackSessions.get("session1InCourse1");

______TS("Section 1A match");
List<FeedbackResponseComment> expected = List.of(
additionalTestData.feedbackResponseComments.get("commentForQ1FromS1aToS1a"),
additionalTestData.feedbackResponseComments.get("commentForQ1FromS1aToS2a"),
additionalTestData.feedbackResponseComments.get("commentForQ2FromS1aToS2a")
);
List<FeedbackResponseComment> results = frcDb.getFeedbackResponseCommentsForSessionInSection(
course.getId(), session.getName(), section1.getName());
assertListCommentsEqual(expected, results);

______TS("Section 2A match");
expected = List.of(
additionalTestData.feedbackResponseComments.get("commentForQ1FromS1aToS2a"),
additionalTestData.feedbackResponseComments.get("commentForQ1FromS2aToS2a"),
additionalTestData.feedbackResponseComments.get("commentForQ2FromS1aToS2a")
);
results = frcDb.getFeedbackResponseCommentsForSessionInSection(
course.getId(), session.getName(), section2.getName());
assertListCommentsEqual(expected, results);
}

@Test
public void testGetFeedbackResponseCommentsForSessionInSection_matchNotFound_shouldReturnEmptyList() {
Course course = typicalDataBundle.courses.get("course1");
FeedbackSession session1 = typicalDataBundle.feedbackSessions.get("session1InCourse1");
FeedbackSession session2 = typicalDataBundle.feedbackSessions.get("session2InTypicalCourse");
Section section = typicalDataBundle.sections.get("section1InCourse1");

______TS("Course not found");
List<FeedbackResponseComment> results = frcDb.getFeedbackResponseCommentsForSessionInSection(
"not_exist", session1.getName(), section.getName());
assertEquals(0, results.size());

______TS("Session not found");
results = frcDb.getFeedbackResponseCommentsForSessionInSection(
course.getId(), "Nonexistent session", section.getName());
assertEquals(0, results.size());

______TS("Section not found");
results = frcDb.getFeedbackResponseCommentsForSessionInSection(
course.getId(), session1.getName(), "Nonexistent section");
assertEquals(0, results.size());

______TS("No matching comments exist");
results = frcDb.getFeedbackResponseCommentsForSessionInSection(
course.getId(), session2.getName(), section.getName());
assertEquals(0, results.size());
}

@Test
public void testGetFeedbackResponseCommentsForQuestionInSection_matchFound_success() {
SqlDataBundle additionalTestData = getAdditionalTestData();
Section section1 = additionalTestData.sections.get("section1aInCourse1");
Section section2 = additionalTestData.sections.get("section2aInCourse1");
FeedbackQuestion question1 = typicalDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
FeedbackQuestion question2 = typicalDataBundle.feedbackQuestions.get("qn2InSession1InCourse1");

______TS("Section 1A Question 1 match");
List<FeedbackResponseComment> expected = List.of(
additionalTestData.feedbackResponseComments.get("commentForQ1FromS1aToS1a"),
additionalTestData.feedbackResponseComments.get("commentForQ1FromS1aToS2a")
);
List<FeedbackResponseComment> results = frcDb.getFeedbackResponseCommentsForQuestionInSection(
question1.getId(), section1.getName());
assertListCommentsEqual(expected, results);

______TS("Section 2A Question 1 match");
expected = List.of(
additionalTestData.feedbackResponseComments.get("commentForQ1FromS1aToS2a"),
additionalTestData.feedbackResponseComments.get("commentForQ1FromS2aToS2a")
);
results = frcDb.getFeedbackResponseCommentsForQuestionInSection(
question1.getId(), section2.getName());
assertListCommentsEqual(expected, results);

______TS("Section 1 Question 2 match");
expected = List.of(
additionalTestData.feedbackResponseComments.get("commentForQ2FromS1aToS2a")
);
results = frcDb.getFeedbackResponseCommentsForQuestionInSection(
question2.getId(), section1.getName());
assertListCommentsEqual(expected, results);
}

@Test
public void testGetFeedbackResponseCommentsForQuestionInSection_matchNotFound_shouldReturnEmptyList() {
Section section = typicalDataBundle.sections.get("section1InCourse1");
FeedbackQuestion question1 = typicalDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
FeedbackQuestion question2 = typicalDataBundle.feedbackQuestions.get("qn1InSession2InCourse1");

______TS("Question not found");
UUID nonexistentQuestionId = UUID.fromString("11110000-0000-0000-0000-000000000000");
List<FeedbackResponseComment> results = frcDb.getFeedbackResponseCommentsForQuestionInSection(
nonexistentQuestionId, section.getName());
assertEquals(0, results.size());

______TS("Section not found");
results = frcDb.getFeedbackResponseCommentsForQuestionInSection(question1.getId(), "Nonexistent section");
assertEquals(0, results.size());

______TS("No matching comments exist");
results = frcDb.getFeedbackResponseCommentsForQuestionInSection(question2.getId(), section.getName());
assertEquals(0, results.size());
}

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

/**
* Generate extra test comments not included in typical bundle.
*/
private SqlDataBundle getAdditionalTestData() {
xenosf marked this conversation as resolved.
Show resolved Hide resolved
SqlDataBundle bundle = new SqlDataBundle();

Course course = typicalDataBundle.courses.get("course1");
FeedbackQuestion question1 = typicalDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
FeedbackQuestion question2 = typicalDataBundle.feedbackQuestions.get("qn2InSession1InCourse1");
FeedbackSession session = typicalDataBundle.feedbackSessions.get("session1InCourse1");
Section section1a = new Section(course, "Section 1A");
Section section2a = new Section(course, "Section 2A");
FeedbackResponse frG1R1Q1 = new FeedbackTextResponse(question1, "", section1a, "", section1a,
new FeedbackTextResponseDetails("Response Q1 S1 to S1"));
FeedbackResponse frG1R2Q1 = new FeedbackTextResponse(question1, "", section1a, "", section2a,
new FeedbackTextResponseDetails("Response Q1 S1 to S2"));
FeedbackResponse frG1R2Q2 = new FeedbackTextResponse(question2, "", section1a, "", section2a,
new FeedbackTextResponseDetails("Response Q2 S1 to S2"));
FeedbackResponse frG2R2Q1 = new FeedbackTextResponse(question1, "", section2a, "", section2a,
new FeedbackTextResponseDetails("Response Q1 S2 to S2"));
FeedbackResponseComment frcG1R1Q1 = new FeedbackResponseComment(
frG1R1Q1, "", FeedbackParticipantType.STUDENTS, section1a, section1a,
"Comment Q1 S1 to S1", true, true, new ArrayList<>(), new ArrayList<>(), ""
);
FeedbackResponseComment frcG1R2Q1 = new FeedbackResponseComment(
frG1R2Q1, "", FeedbackParticipantType.STUDENTS, section1a, section2a,
"Comment Q1 S1 to S2", true, true, new ArrayList<>(), new ArrayList<>(), ""
);
FeedbackResponseComment frcG1R2Q2 = new FeedbackResponseComment(
frG1R2Q2, "", FeedbackParticipantType.STUDENTS, section1a, section2a,
"Comment Q2 S1 to S2", true, true, new ArrayList<>(), new ArrayList<>(), ""
);
FeedbackResponseComment frcG2R2Q1 = new FeedbackResponseComment(
frG2R2Q1, "", FeedbackParticipantType.STUDENTS, section2a, section2a,
"Comment Q1 S2 to S2", true, true, new ArrayList<>(), new ArrayList<>(), ""
);

HibernateUtil.persist(section1a);
HibernateUtil.persist(section2a);
course.addSection(section1a);
course.addSection(section2a);
HibernateUtil.merge(session);
HibernateUtil.merge(course);
HibernateUtil.persist(frG1R1Q1);
HibernateUtil.persist(frG1R2Q2);
HibernateUtil.persist(frG1R2Q1);
HibernateUtil.persist(frG2R2Q1);
HibernateUtil.persist(frcG1R1Q1);
HibernateUtil.persist(frcG1R2Q2);
HibernateUtil.persist(frcG1R2Q1);
HibernateUtil.persist(frcG2R2Q1);

bundle.courses.put("course1", course);
bundle.feedbackSessions.put("session1InCourse1", session);
bundle.sections.put("section1aInCourse1", section1a);
bundle.sections.put("section2aInCourse1", section2a);
bundle.feedbackResponses.put("responseForQ1FromS1aToS1a", frG1R1Q1);
bundle.feedbackResponses.put("responseForQ1FromS1aToS2a", frG1R2Q1);
bundle.feedbackResponses.put("responseForQ2FromS1aToS2a", frG1R2Q2);
bundle.feedbackResponses.put("responseForQ1FromS2aToS2a", frG2R2Q1);
bundle.feedbackResponseComments.put("commentForQ1FromS1aToS1a", frcG1R1Q1);
bundle.feedbackResponseComments.put("commentForQ1FromS1aToS2a", frcG1R2Q1);
bundle.feedbackResponseComments.put("commentForQ2FromS1aToS2a", frcG1R2Q2);
bundle.feedbackResponseComments.put("commentForQ1FromS2aToS2a", frcG2R2Q1);

return bundle;
}
}
Loading