Skip to content

Commit

Permalink
[#12048] Add tests for FeedbackQuestionsDbIT (#12781)
Browse files Browse the repository at this point in the history
* Add verification during feedback question creation

* Add tests for FeedbackQuestionsDb

* Fix missing javadocs

* Fix feedback question creation logic

* Add test

* Reuse error message

* Add tests for FeedbackQuestionsDbIT

---------

Co-authored-by: marquestye <[email protected]>
Co-authored-by: Wei Qing <[email protected]>
Co-authored-by: Cedric Ong <[email protected]>
  • Loading branch information
4 people authored Mar 12, 2024
1 parent e385eed commit 2ad2242
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/it/java/teammates/it/storage/sqlapi/FeedbackQuestionsDbIT.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package teammates.it.storage.sqlapi;

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.exception.EntityAlreadyExistsException;
import teammates.common.exception.InvalidParametersException;
import teammates.common.util.HibernateUtil;
import teammates.it.test.BaseTestCaseWithSqlDatabaseAccess;
import teammates.storage.sqlapi.FeedbackQuestionsDb;
Expand Down Expand Up @@ -39,6 +42,47 @@ protected void setUp() throws Exception {
HibernateUtil.flushSession();
}

@Test
public void testGetFeedbackQuestion() {
______TS("success: typical case");
FeedbackQuestion expectedFq = typicalDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");

FeedbackQuestion actualFq = fqDb.getFeedbackQuestion(expectedFq.getId());

assertEquals(expectedFq, actualFq);

______TS("failure: does not exist, returns null");
actualFq = fqDb.getFeedbackQuestion(UUID.randomUUID());
assertNull(actualFq);

______TS("failure: null parameter, assertion error");
assertThrows(AssertionError.class, () -> fqDb.getFeedbackQuestion(null));
}

@Test
public void testCreateFeedbackQuestion() throws EntityAlreadyExistsException, InvalidParametersException {
______TS("success: typical case");
FeedbackQuestion expectedFq = getTypicalFeedbackQuestionForSession(
getTypicalFeedbackSessionForCourse(getTypicalCourse()));

fqDb.createFeedbackQuestion(expectedFq);
verifyPresentInDatabase(expectedFq);

______TS("failure: duplicate question, throws error");
assertThrows(EntityAlreadyExistsException.class, () -> fqDb.createFeedbackQuestion(expectedFq));

______TS("failure: invalid question, throws error");
FeedbackQuestion invalidFq = getTypicalFeedbackQuestionForSession(
getTypicalFeedbackSessionForCourse(getTypicalCourse()));
invalidFq.setGiverType(FeedbackParticipantType.RECEIVER);

assertThrows(InvalidParametersException.class, () -> fqDb.createFeedbackQuestion(invalidFq));
assertNull(fqDb.getFeedbackQuestion(invalidFq.getId()));

______TS("failure: null parameter, assertion error");
assertThrows(AssertionError.class, () -> fqDb.createFeedbackQuestion(null));
}

@Test
public void testGetFeedbackQuestionsForSession() {
______TS("success: typical case");
Expand All @@ -56,6 +100,10 @@ public void testGetFeedbackQuestionsForSession() {

assertEquals(expectedQuestions.size(), actualQuestions.size());
assertTrue(expectedQuestions.containsAll(actualQuestions));

______TS("failure: session does not exist, returns no questions");
actualQuestions = fqDb.getFeedbackQuestionsForSession(UUID.randomUUID());
assertEquals(0, actualQuestions.size());
}

@Test
Expand All @@ -71,6 +119,24 @@ public void testGetFeedbackQuestionsForGiverType() {

assertEquals(expectedQuestions.size(), actualQuestions.size());
assertTrue(expectedQuestions.containsAll(actualQuestions));

______TS("failure: session does not exist, returns no questions");
fs = getTypicalFeedbackSessionForCourse(getTypicalCourse());
actualQuestions = fqDb.getFeedbackQuestionsForGiverType(fs, FeedbackParticipantType.STUDENTS);
assertEquals(0, actualQuestions.size());
}

@Test
public void testDeleteFeedbackQuestion() {
______TS("success: typical case");
FeedbackQuestion fq = typicalDataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
verifyPresentInDatabase(fq);

fqDb.deleteFeedbackQuestion(fq.getId());
assertNull(fqDb.getFeedbackQuestion(fq.getId()));

______TS("failure: null parameter, assertion error");
assertThrows(AssertionError.class, () -> fqDb.deleteFeedbackQuestion(null));
}

@Test
Expand All @@ -83,5 +149,9 @@ public void testHasFeedbackQuestionsForGiverType() {
fs.getName(), course.getId(), FeedbackParticipantType.STUDENTS);

assertTrue(actual);

______TS("failure: session/course does not exist, returns false");
actual = fqDb.hasFeedbackQuestionsForGiverType("session-name", "course-id", FeedbackParticipantType.STUDENTS);
assertFalse(actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ private BaseEntity getEntity(BaseEntity entity) {
return logic.getCourse(((Course) entity).getId());
} else if (entity instanceof FeedbackSession) {
return logic.getFeedbackSession(((FeedbackSession) entity).getId());
} else if (entity instanceof FeedbackQuestion) {
return logic.getFeedbackQuestion(((FeedbackQuestion) entity).getId());
} else if (entity instanceof Account) {
return logic.getAccount(((Account) entity).getId());
} else if (entity instanceof Notification) {
Expand Down

0 comments on commit 2ad2242

Please sign in to comment.