示例#1
0
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   *     <p>Creates the question and registers it within the database then depending on what the
   *     user clicks, sends them to the finish quiz page or to create another question
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    HttpSession session = request.getSession();
    Quiz qz = (Quiz) session.getAttribute("newQuiz");
    DBConnection dbCon = (DBConnection) session.getAttribute("connection");
    int qzID = qz.getID();
    Question newQn;
    String question = request.getParameter("question");
    String answer = request.getParameter("answer");
    int type = Integer.parseInt(request.getParameter("type"));
    String MC = null;
    switch (type) {
      case 1:
        newQn = new QResponse(question, answer);
        newQn.setType(type);
        break;
      case 2:
        newQn = new FillIn(question, answer);
        newQn.setType(type);
        break;
      case 3:
        newQn = new MultiChoice(question, answer);
        MC = request.getParameter("choices");
        ((MultiChoice) newQn).addMCOptions(MC);
        newQn.setType(type);
        break;
      case 4:
        newQn = new PictureResponse(question, answer);
        newQn.setType(type);
        break;
      default:
        newQn = null;
        break;
    }
    newQn.printString();
    if (!newQn.equals(null)) qz.addQuestion(newQn);
    Question.registerQuestion(qzID, type, question, answer, MC, dbCon);

    // send the user on forward through the quiz creation
    String action = request.getParameter("action");
    if (action.equals("Create & Continue")) {
      RequestDispatcher dispatch = request.getRequestDispatcher("chooseQuestionType.jsp");
      dispatch.forward(request, response);
    } else if (action.equals("Create & Finish Quiz")) {
      RequestDispatcher dispatch = request.getRequestDispatcher("finishCreationQuiz.jsp");
      dispatch.forward(request, response);
    }
  }
示例#2
0
  /** Create a user, create a state and make him answer a few questions. */
  @Before
  public void setup() {

    // setup user
    expectedUser = new User("xuser");
    expectedUser.setId(1234);

    // setup level
    expectedLevel = QuestionLevel.LEVEL_1;

    // setup question
    expectedQuestion = new Question();
    expectedQuestion.setAnswer("xanswer");
    expectedQuestion.setType(QuestionType.TEXT);
    expectedQuestion.setCategory(QuestionCategory.SHAPES);
    List<String> choices = new ArrayList();
    choices.add("apple");
    choices.add("orange");
    choices.add("banana");
    choices.add("cherry");
    expectedQuestion.setChoices(choices);
    expectedQuestion.setLevel(expectedLevel);
    expectedQuestion.setQuestion("xquestion");
    expectedQuestion.setExplaination("xplanation");

    // set current question and level for user
    expectedUser.setCurrentQuestion(expectedQuestion);
    expectedUser.endState();
    fileUserManager.addUser(expectedUser);
  }
示例#3
0
 @Test
 public void test_question_setType() {
   // GIVEN
   Question q = new Question();
   QuestionType qt = QuestionType.SIMPLE_CHOICE;
   // WHEN
   q.setType(qt);
   // THEN
   assertEquals(q.getType(), qt);
 }
示例#4
0
 @Test
 public void test_question_questionMultiChoice() {
   // GIVEN
   Poll sond = new Poll();
   Question q = new Question();
   q.setType(QuestionType.MULTIPLE_CHOICE);
   List<Question> lq = new ArrayList<Question>();
   lq.add(q);
   // WHEN
   sond.setQuestions(lq);
   // THEN
   assertNotNull(sond.getQuestions());
   assertNotNull(sond.getQuestions().get(0));
   assertEquals(sond.getQuestions().get(0).getType(), QuestionType.MULTIPLE_CHOICE);
 }