Search in sources :

Example 51 with FeedbackQuestionAttributes

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

the class FeedbackSessionsLogicTest method testCreateAndDeleteFeedbackSession.

private void testCreateAndDeleteFeedbackSession() throws InvalidParametersException, EntityAlreadyExistsException {
    ______TS("test create");
    FeedbackSessionAttributes fs = getNewFeedbackSession();
    fsLogic.createFeedbackSession(fs);
    verifyPresentInDatastore(fs);
    ______TS("test create with invalid session name");
    fs.setFeedbackSessionName("test & test");
    try {
        fsLogic.createFeedbackSession(fs);
        signalFailureToDetectException();
    } catch (Exception e) {
        assertEquals("The provided feedback session name is not acceptable to TEAMMATES " + "as it cannot contain the following special html characters in brackets: " + "(< > " / ' &)", e.getMessage());
    }
    fs.setFeedbackSessionName("test %| test");
    try {
        fsLogic.createFeedbackSession(fs);
        signalFailureToDetectException();
    } catch (Exception e) {
        assertEquals("\"test %| test\" is not acceptable to TEAMMATES as a/an feedback session name " + "because it contains invalid characters. A/An feedback session name " + "must start with an alphanumeric character, and cannot contain " + "any vertical bar (|) or percent sign (%).", e.getMessage());
    }
    ______TS("test delete");
    fs = getNewFeedbackSession();
    // Create a question under the session to test for cascading during delete.
    FeedbackQuestionAttributes fq = new FeedbackQuestionAttributes();
    fq.feedbackSessionName = fs.getFeedbackSessionName();
    fq.courseId = fs.getCourseId();
    fq.questionNumber = 1;
    fq.creatorEmail = fs.getCreatorEmail();
    fq.numberOfEntitiesToGiveFeedbackTo = Const.MAX_POSSIBLE_RECIPIENTS;
    fq.giverType = FeedbackParticipantType.STUDENTS;
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.questionMetaData = new Text("question to be deleted through cascade");
    fq.questionType = FeedbackQuestionType.TEXT;
    fq.showResponsesTo = new ArrayList<>();
    fq.showRecipientNameTo = new ArrayList<>();
    fq.showGiverNameTo = new ArrayList<>();
    fqLogic.createFeedbackQuestion(fq);
    fsLogic.deleteFeedbackSessionCascade(fs.getFeedbackSessionName(), fs.getCourseId());
    verifyAbsentInDatastore(fs);
    verifyAbsentInDatastore(fq);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Text(com.google.appengine.api.datastore.Text) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException)

Example 52 with FeedbackQuestionAttributes

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

the class FeedbackQuestionsDbTest method deleteFeedbackQuestions.

private void deleteFeedbackQuestions(int numToDelete) {
    FeedbackQuestionAttributes fqa = getNewFeedbackQuestionAttributes();
    for (int i = 1; i <= numToDelete; i++) {
        fqa.questionNumber = i;
        fqDb.deleteEntity(fqa);
    }
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Example 53 with FeedbackQuestionAttributes

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

the class FeedbackQuestionsDbTest method createNewQuestionsForDifferentRecipientTypes.

private int[] createNewQuestionsForDifferentRecipientTypes() throws Exception {
    int[] numberOfQuestionsToCreate = new int[] { 2, 3, 1, 2 };
    FeedbackQuestionAttributes fqa;
    for (int i = 1; i <= numberOfQuestionsToCreate[0]; i++) {
        fqa = getNewFeedbackQuestionAttributes();
        fqa.questionNumber = i;
        fqa.giverType = FeedbackParticipantType.INSTRUCTORS;
        fqDb.createEntity(fqa);
    }
    for (int i = 1; i <= numberOfQuestionsToCreate[1]; i++) {
        fqa = getNewFeedbackQuestionAttributes();
        fqa.questionNumber = numberOfQuestionsToCreate[0] + i;
        fqa.giverType = FeedbackParticipantType.STUDENTS;
        fqDb.createEntity(fqa);
    }
    for (int i = 1; i <= numberOfQuestionsToCreate[2]; i++) {
        fqa = getNewFeedbackQuestionAttributes();
        fqa.giverType = FeedbackParticipantType.SELF;
        fqa.questionNumber = numberOfQuestionsToCreate[0] + numberOfQuestionsToCreate[1] + i;
        fqDb.createEntity(fqa);
    }
    for (int i = 1; i <= numberOfQuestionsToCreate[3]; i++) {
        fqa = getNewFeedbackQuestionAttributes();
        fqa.giverType = FeedbackParticipantType.TEAMS;
        fqa.questionNumber = numberOfQuestionsToCreate[0] + numberOfQuestionsToCreate[1] + numberOfQuestionsToCreate[2] + i;
        fqDb.createEntity(fqa);
    }
    return numberOfQuestionsToCreate;
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Example 54 with FeedbackQuestionAttributes

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

the class FeedbackQuestionsDbTest method getNewFeedbackQuestionAttributes.

private FeedbackQuestionAttributes getNewFeedbackQuestionAttributes() {
    FeedbackQuestionAttributes fqa = new FeedbackQuestionAttributes();
    fqa.courseId = "testCourse";
    fqa.creatorEmail = "instructor@email.com";
    fqa.feedbackSessionName = "testFeedbackSession";
    fqa.giverType = FeedbackParticipantType.INSTRUCTORS;
    fqa.recipientType = FeedbackParticipantType.SELF;
    fqa.numberOfEntitiesToGiveFeedbackTo = 1;
    fqa.questionNumber = 1;
    FeedbackTextQuestionDetails questionDetails = new FeedbackTextQuestionDetails("Question text.");
    fqa.questionType = FeedbackQuestionType.TEXT;
    fqa.setQuestionDetails(questionDetails);
    fqa.showGiverNameTo = new ArrayList<>();
    fqa.showRecipientNameTo = new ArrayList<>();
    fqa.showResponsesTo = new ArrayList<>();
    return fqa;
}
Also used : FeedbackTextQuestionDetails(teammates.common.datatransfer.questions.FeedbackTextQuestionDetails) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Example 55 with FeedbackQuestionAttributes

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

the class FeedbackQuestionsDbTest method testGetFeedbackQuestions.

@Test
public void testGetFeedbackQuestions() throws Exception {
    FeedbackQuestionAttributes expected = getNewFeedbackQuestionAttributes();
    // remove possibly conflicting entity from the database
    fqDb.deleteEntity(expected);
    fqDb.createEntity(expected);
    ______TS("standard success case");
    FeedbackQuestionAttributes actual = fqDb.getFeedbackQuestion(expected.feedbackSessionName, expected.courseId, expected.questionNumber);
    assertEquals(expected.toString(), actual.toString());
    ______TS("non-existant question");
    assertNull(fqDb.getFeedbackQuestion("Non-existant feedback session", "non-existent-course", 1));
    ______TS("null fsName");
    try {
        fqDb.getFeedbackQuestion(null, expected.courseId, 1);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
    }
    ______TS("null courseId");
    try {
        fqDb.getFeedbackQuestion(expected.feedbackSessionName, null, 1);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
    }
    ______TS("get by id");
    assertEquals(expected.toString(), actual.toString());
    ______TS("get non-existent question by id");
    actual = fqDb.getFeedbackQuestion("non-existent id");
    assertNull(actual);
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Test(org.testng.annotations.Test)

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