Search in sources :

Example 86 with FeedbackQuestionAttributes

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes in project teammates by TEAMMATES.

the class FeedbackQuestionsDbTest method testCreateDeleteFeedbackQuestion.

@Test
public void testCreateDeleteFeedbackQuestion() throws InvalidParametersException, EntityAlreadyExistsException {
    ______TS("standard success case");
    FeedbackQuestionAttributes fqa = getNewFeedbackQuestionAttributes();
    // remove possibly conflicting entity from the database
    fqDb.deleteEntity(fqa);
    fqDb.createEntity(fqa);
    verifyPresentInDatastore(fqa);
    ______TS("duplicate - with same id.");
    try {
        fqDb.createEntity(fqa);
        signalFailureToDetectException();
    } catch (EntityAlreadyExistsException e) {
        AssertHelper.assertContains(String.format(FeedbackQuestionsDb.ERROR_CREATE_ENTITY_ALREADY_EXISTS, fqa.getEntityTypeAsString()) + fqa.getIdentificationString(), e.getMessage());
    }
    ______TS("delete - with id specified");
    fqDb.deleteEntity(fqa);
    verifyAbsentInDatastore(fqa);
    ______TS("null params");
    try {
        fqDb.createEntity(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
    }
    ______TS("invalid params");
    try {
        fqa.creatorEmail = "haha";
        fqDb.createEntity(fqa);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains("Invalid creator's email", e.getLocalizedMessage());
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) Test(org.testng.annotations.Test)

Example 87 with FeedbackQuestionAttributes

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes in project teammates by TEAMMATES.

the class FeedbackQuestionsDbTest method testUpdateFeedbackQuestion.

@Test
public void testUpdateFeedbackQuestion() throws Exception {
    ______TS("null params");
    try {
        fqDb.updateFeedbackQuestion(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
    }
    ______TS("invalid feedback question attributes");
    FeedbackQuestionAttributes invalidFqa = getNewFeedbackQuestionAttributes();
    fqDb.deleteEntity(invalidFqa);
    fqDb.createEntity(invalidFqa);
    invalidFqa.setId(fqDb.getFeedbackQuestion(invalidFqa.feedbackSessionName, invalidFqa.courseId, invalidFqa.questionNumber).getId());
    invalidFqa.creatorEmail = "haha";
    try {
        fqDb.updateFeedbackQuestion(invalidFqa);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains("Invalid creator's email", e.getLocalizedMessage());
    }
    ______TS("feedback session does not exist");
    FeedbackQuestionAttributes nonexistantFq = getNewFeedbackQuestionAttributes();
    nonexistantFq.setId("non-existent fq id");
    try {
        fqDb.updateFeedbackQuestion(nonexistantFq);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains(FeedbackQuestionsDb.ERROR_UPDATE_NON_EXISTENT, e.getLocalizedMessage());
    }
    ______TS("standard success case");
    FeedbackQuestionAttributes modifiedQuestion = getNewFeedbackQuestionAttributes();
    fqDb.deleteEntity(modifiedQuestion);
    fqDb.createEntity(modifiedQuestion);
    verifyPresentInDatastore(modifiedQuestion);
    modifiedQuestion = fqDb.getFeedbackQuestion(modifiedQuestion.feedbackSessionName, modifiedQuestion.courseId, modifiedQuestion.questionNumber);
    FeedbackQuestionDetails fqd = modifiedQuestion.getQuestionDetails();
    fqd.setQuestionText("New question text!");
    modifiedQuestion.setQuestionDetails(fqd);
    fqDb.updateFeedbackQuestion(modifiedQuestion);
    verifyPresentInDatastore(modifiedQuestion);
    modifiedQuestion = fqDb.getFeedbackQuestion(modifiedQuestion.feedbackSessionName, modifiedQuestion.courseId, modifiedQuestion.questionNumber);
    assertEquals("New question text!", modifiedQuestion.getQuestionDetails().getQuestionText());
    fqDb.deleteEntity(modifiedQuestion);
}
Also used : FeedbackQuestionDetails(teammates.common.datatransfer.questions.FeedbackQuestionDetails) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test)

Example 88 with FeedbackQuestionAttributes

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes in project teammates by TEAMMATES.

the class FeedbackQuestionsDbTest method testTimestamp.

@Test
public void testTimestamp() throws InvalidParametersException, EntityAlreadyExistsException, EntityDoesNotExistException {
    ______TS("success : created");
    FeedbackQuestionAttributes fq = getNewFeedbackQuestionAttributes();
    // remove possibly conflicting entity from the database
    fqDb.deleteEntity(fq);
    fqDb.createEntity(fq);
    verifyPresentInDatastore(fq);
    String feedbackSessionName = fq.feedbackSessionName;
    String courseId = fq.courseId;
    int questionNumber = fq.questionNumber;
    FeedbackQuestionAttributes feedbackQuestion = fqDb.getFeedbackQuestion(feedbackSessionName, courseId, questionNumber);
    // Assert dates are now.
    AssertHelper.assertInstantIsNow(feedbackQuestion.getCreatedAt());
    AssertHelper.assertInstantIsNow(feedbackQuestion.getUpdatedAt());
    ______TS("success : update lastUpdated");
    feedbackQuestion.questionNumber++;
    fqDb.updateFeedbackQuestion(feedbackQuestion);
    FeedbackQuestionAttributes updatedFq = fqDb.getFeedbackQuestion(feedbackSessionName, courseId, feedbackQuestion.questionNumber);
    // Assert lastUpdate has changed, and is now.
    assertFalse(feedbackQuestion.getUpdatedAt().equals(updatedFq.getUpdatedAt()));
    AssertHelper.assertInstantIsNow(updatedFq.getUpdatedAt());
    ______TS("success : keep lastUpdated");
    feedbackQuestion.questionNumber++;
    fqDb.updateFeedbackQuestion(feedbackQuestion, true);
    FeedbackQuestionAttributes updatedFqTwo = fqDb.getFeedbackQuestion(feedbackSessionName, courseId, feedbackQuestion.questionNumber);
    // Assert lastUpdate has NOT changed.
    assertEquals(updatedFq.getUpdatedAt(), updatedFqTwo.getUpdatedAt());
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Test(org.testng.annotations.Test)

Example 89 with FeedbackQuestionAttributes

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes in project teammates by TEAMMATES.

the class StudentFeedbackResultsPageDataTest method testAll.

@Test
public void testAll() throws EntityDoesNotExistException {
    ______TS("typical success case");
    AccountAttributes account = dataBundle.accounts.get("student1InCourse1");
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    assertNotNull(student);
    String dummyKey = "key123";
    student.key = dummyKey;
    Logic logic = new Logic();
    StudentFeedbackResultsPageData pageData = new StudentFeedbackResultsPageData(account, student, dummySessionToken);
    Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> questionsWithResponses = new LinkedHashMap<>();
    FeedbackQuestionAttributes question1 = dataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
    assertNotNull(question1);
    FeedbackQuestionAttributes question2 = dataBundle.feedbackQuestions.get("qn2InSession1InCourse1");
    assertNotNull(question2);
    List<FeedbackResponseAttributes> responsesForQ1 = new ArrayList<>();
    List<FeedbackResponseAttributes> responsesForQ2 = new ArrayList<>();
    /* Question 1 with responses */
    responsesForQ1.add(dataBundle.feedbackResponses.get("response1ForQ1S1C1"));
    questionsWithResponses.put(question1, responsesForQ1);
    /* Question 2 with responses */
    responsesForQ2.add(dataBundle.feedbackResponses.get("response1ForQ2S1C1"));
    responsesForQ2.add(dataBundle.feedbackResponses.get("response2ForQ2S1C1"));
    questionsWithResponses.put(question2, responsesForQ2);
    // need to obtain questionId and responseId as methods in FeedbackSessionResultsBundle require them
    questionsWithResponses = getActualQuestionsAndResponsesWithId(logic, questionsWithResponses);
    pageData.setBundle(logic.getFeedbackSessionResultsForStudent(question1.feedbackSessionName, question1.courseId, student.email));
    pageData.init(questionsWithResponses);
    StudentFeedbackResultsQuestionWithResponses questionBundle1 = pageData.getFeedbackResultsQuestionsWithResponses().get(0);
    StudentFeedbackResultsQuestionWithResponses questionBundle2 = pageData.getFeedbackResultsQuestionsWithResponses().get(1);
    assertNotNull(pageData.getFeedbackResultsQuestionsWithResponses());
    assertEquals(2, pageData.getFeedbackResultsQuestionsWithResponses().size());
    assertEquals("You are viewing feedback results as <span class='text-danger text-bold text-large'>" + "student1 In Course1</td></div>'\"</span>. You may submit feedback for sessions that are " + "currently open and view results without logging in. " + "To access other features you need <a href='/page/studentCourseJoinAuthentication?" + "key=" + StringHelper.encrypt(dummyKey) + "&studentemail=student1InCourse1%40gmail.tmt&courseid=idOfTypicalCourse1' class='link'>" + "to login using a Google account</a> (recommended).", pageData.getRegisterMessage());
    assertNotNull(questionBundle1.getQuestionDetails());
    assertNotNull(questionBundle2.getQuestionDetails());
    assertEquals("1", questionBundle1.getQuestionDetails().getQuestionIndex());
    assertEquals("2", questionBundle2.getQuestionDetails().getQuestionIndex());
    assertEquals("", questionBundle1.getQuestionDetails().getAdditionalInfo());
    assertEquals("", questionBundle2.getQuestionDetails().getAdditionalInfo());
    assertNotNull(questionBundle1.getResponseTables());
    assertNotNull(questionBundle2.getResponseTables());
    assertEquals("You", questionBundle1.getResponseTables().get(0).getRecipientName());
    assertNotNull(questionBundle1.getResponseTables().get(0).getResponses());
    assertEquals("You", questionBundle1.getResponseTables().get(0).getResponses().get(0).getGiverName());
    assertEquals("Student 1 self feedback.", questionBundle1.getResponseTables().get(0).getResponses().get(0).getAnswer());
    ______TS("student in unregistered course");
    student = dataBundle.students.get("student1InUnregisteredCourse");
    pageData = new StudentFeedbackResultsPageData(account, student, dummySessionToken);
    Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> questionsWithResponsesUnregistered = new LinkedHashMap<>();
    pageData.init(questionsWithResponsesUnregistered);
    assertTrue(pageData.getFeedbackResultsQuestionsWithResponses().isEmpty());
    assertEquals("regKeyForStuNotYetJoinCourse", student.key);
    assertEquals("idOfUnregisteredCourse", student.course);
    assertEquals("student1InUnregisteredCourse@gmail.tmt", student.email);
    assertEquals("You are viewing feedback results as " + "<span class='text-danger text-bold text-large'>student1 In " + "unregisteredCourse</span>. You may submit feedback for sessions that are currently open " + "and view results without logging in. To access other features you need " + "<a href='/page/studentCourseJoinAuthentication?key=" + StringHelper.encrypt("regKeyForStuNotYetJoinCourse") + "&studentemail=student1InUnregisteredCourse%40gmail.tmt&courseid=idOfUnregisteredCourse' " + "class='link'>to login using a Google account</a> (recommended).", pageData.getRegisterMessage());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ArrayList(java.util.ArrayList) StudentFeedbackResultsPageData(teammates.ui.pagedata.StudentFeedbackResultsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) LinkedHashMap(java.util.LinkedHashMap) StudentFeedbackResultsQuestionWithResponses(teammates.ui.template.StudentFeedbackResultsQuestionWithResponses) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) ArrayList(java.util.ArrayList) List(java.util.List) Logic(teammates.logic.api.Logic) Test(org.testng.annotations.Test)

Example 90 with FeedbackQuestionAttributes

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes in project teammates by TEAMMATES.

the class StudentFeedbackResultsPageDataTest method getActualQuestionsAndResponsesWithId.

private Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> getActualQuestionsAndResponsesWithId(Logic logic, Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> questionsWithResponses) {
    Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> actualQuestionsWithResponses = new LinkedHashMap<>();
    questionsWithResponses.forEach((dataBundleQuestion, dataBundleResponses) -> {
        FeedbackQuestionAttributes actualQuestion = logic.getFeedbackQuestion(dataBundleQuestion.feedbackSessionName, dataBundleQuestion.courseId, dataBundleQuestion.questionNumber);
        List<FeedbackResponseAttributes> actualResponses = new ArrayList<>();
        for (FeedbackResponseAttributes dataBundleResponse : dataBundleResponses) {
            FeedbackResponseAttributes actualResponse = logic.getFeedbackResponse(actualQuestion.getId(), dataBundleResponse.giver, dataBundleResponse.recipient);
            actualResponses.add(actualResponse);
        }
        actualQuestionsWithResponses.put(actualQuestion, actualResponses);
    });
    return actualQuestionsWithResponses;
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) ArrayList(java.util.ArrayList) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)154 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)64 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)48 ArrayList (java.util.ArrayList)47 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)38 Test (org.testng.annotations.Test)35 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)25 List (java.util.List)23 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)23 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)19 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)18 HashMap (java.util.HashMap)17 RedirectResult (teammates.ui.controller.RedirectResult)17 HashSet (java.util.HashSet)12 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)12 Text (com.google.appengine.api.datastore.Text)11 Map (java.util.Map)10 FeedbackQuestionDetails (teammates.common.datatransfer.questions.FeedbackQuestionDetails)10 LinkedHashMap (java.util.LinkedHashMap)9 DataBundle (teammates.common.datatransfer.DataBundle)9