Example #1
0
 @Test
 public void test_poll_allowCom_false_noCampaign() {
   // GIVEN WHEN
   Poll sond = new Poll();
   // THEN
   assertEquals(sond.isAllowComment(), false);
 }
  @RequestMapping(value = "/edit-vote.jsp", method = RequestMethod.GET)
  public ModelAndView showForm(HttpServletRequest request, @RequestParam("msgid") int msgid)
      throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isModeratorSession()) {
      throw new AccessViolationException("Not authorized");
    }

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("msgid", msgid);

    Connection db = null;

    try {
      db = LorDataSource.getConnection();

      Poll poll = Poll.getPollByTopic(db, msgid);
      params.put("poll", poll);

      List<PollVariant> variants = poll.getPollVariants(db, Poll.ORDER_ID);
      params.put("variants", variants);

      return new ModelAndView("edit-vote", params);
    } finally {
      if (db != null) {
        db.close();
      }
    }
  }
Example #3
0
 @Test
 public void test_poll_removeKey_Campaign() {
   // GIVEN
   Poll sond = new Poll();
   String key1 = "test";
   String key2 = "test2";
   List<String> keys = new ArrayList<String>();
   keys.add(key1);
   keys.add(key2);
   sond.setKeywords(keys);
   // WHEN
   Campaign c = new Campaign();
   c.setStartingAt(new Timestamp(new Date().getTime()));
   c.setEndingAt(new Timestamp(new Date().getTime() + 10000));
   List<Campaign> lcamps = new ArrayList<Campaign>();
   lcamps.add(c);
   sond.setCampaigns(lcamps);
   // THEN
   try {
     sond.removeKeyword("test");
     fail("A campaign is processing.");
   } catch (IllegalArgumentException expected) {
     assertEquals("A campaign is processing.", expected.getMessage());
   }
 }
Example #4
0
 @Test
 public void test_poll_setCampaign_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   List<Campaign> campList = new ArrayList<Campaign>();
   // WHEN
   sond.setCampaigns(campList);
   // THEN
   assertEquals(sond.getCampaigns(), campList);
 }
Example #5
0
 @Test
 public void test_poll_setQuestions_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   List<Question> questList = new ArrayList<Question>();
   // WHEN
   sond.setQuestions(questList);
   // THEN
   assertEquals(sond.getQuestions(), questList);
 }
Example #6
0
 @Test
 public void test_poll_setClassification_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   ClassificationCategory cc = ClassificationCategory.MUSIC;
   // WHEN
   sond.setClassification(cc);
   // THEN
   assertEquals(sond.getClassification(), cc);
 }
Example #7
0
 @Test
 public void test_poll_setCreate_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   long actualTime = new Date().getTime();
   // WHEN
   sond.setCreatedAt(new Timestamp(actualTime));
   // THEN
   assertEquals(sond.getCreatedAt(), new Timestamp(actualTime));
 }
Example #8
0
 @Test
 public void test_poll_allowCom_true_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   boolean com = true;
   // WHEN
   sond.setAllowComment(com);
   // THEN
   assertEquals(sond.isAllowComment(), com);
 }
Example #9
0
 @Test
 public void test_poll_setMedia_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   Media m = new Media();
   // WHEN
   sond.setMedia(m);
   // THEN
   assertEquals(sond.getMedia(), m);
 }
Example #10
0
 @Test
 public void test_poll_setComments_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   List<Comment> commentList = new ArrayList<Comment>();
   // WHEN
   sond.setComments(commentList);
   // THEN
   assertEquals(sond.getComments(), commentList);
 }
Example #11
0
 @Test
 public void test_poll_setDesc_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   String newDesc = "Des";
   // WHEN
   sond.setDescription(newDesc);
   boolean processingCampaign = sond.hasProcessingCampaign();
   // THEN
   assertEquals(sond.getDescription(), newDesc);
 }
Example #12
0
 public static String serialize(Poll... polls) {
   StringBuilder sb = new StringBuilder();
   sb.append("PollTitle;PollDescription");
   sb.append("\r\n");
   for (Poll poll : polls) {
     sb.append(convert(poll.getTitle()));
     sb.append('"').append(poll.getDescription()).append('"');
     sb.append("\r\n");
   }
   return sb.toString();
 }
Example #13
0
 @Test
 public void test_poll_setTitle_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   String newTitle = "Tests";
   // WHEN
   sond.setTitle(newTitle);
   boolean processingCampaign = sond.hasProcessingCampaign();
   // THEN
   assertEquals(sond.getTitle(), newTitle);
 }
Example #14
0
 @Test
 public void test_poll_setID_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   long newID = 42;
   // WHEN
   sond.setId(newID);
   boolean processingCampaign = sond.hasProcessingCampaign();
   // THEN
   assertEquals(sond.getId(), newID);
 }
Example #15
0
 @Test
 public void test_poll_construct_empty() {
   // GIVEN WHEN
   Poll sond = new Poll();
   String titre = "";
   String desc = "";
   // THEN
   assertEquals(sond.getDescription(), desc);
   assertEquals(sond.getTitle(), titre);
   assertNotNull(sond.getCreatedAt());
   assertNotNull(sond.getUpdatedAt());
 }
Example #16
0
 @Test
 public void test_poll_visible_poll() {
   // GIVEN
   Poll sond = new Poll();
   Campaign c = new Campaign();
   c.setVisibility(CampaignVisibility.PUBLIC);
   List<Campaign> camps = new ArrayList<Campaign>();
   camps.add(c);
   // WHEN
   sond.setCampaigns(camps);
   // THEN
   assertEquals(sond.getCampaigns().get(0).getVisibility(), CampaignVisibility.PUBLIC);
 }
Example #17
0
  @Test
  public void test_poll_setID_noCampaign_negative() {
    // GIVEN
    Poll sond = new Poll();
    long newID = -54;

    try {
      // WHEN
      sond.setId(newID);
      fail("Id can not be negative or 0");
    } catch (IllegalArgumentException exc) {
      // THEN
      assertEquals(exc.getMessage(), "Id can not be negative or 0");
    }
  }
Example #18
0
 @Override
 public void trim(int height) {
   super.trim(height);
   try (Connection con = Db.db.getConnection();
       DbIterator<Poll> polls = Poll.getPollsFinishingAtOrBefore(height);
       PreparedStatement pstmt =
           con.prepareStatement("DELETE FROM vote WHERE poll_id = ?")) {
     for (Poll poll : polls) {
       pstmt.setLong(1, poll.getId());
       pstmt.executeUpdate();
     }
   } catch (SQLException e) {
     throw new RuntimeException(e.toString(), e);
   }
 }
Example #19
0
  @Test
  public void test_poll_setWebsite_exception_noCampaign() {
    // GIVEN
    Poll sond = new Poll();
    String url = "Blajefe.monsite.fr";
    // WHEN

    // THEN
    try {
      sond.setWebsite(url);
      fail("Website URL should be correct to the pattern.");
    } catch (IllegalArgumentException expected) {
      assertEquals("Website URL should be correct to the pattern.", expected.getMessage());
    }
  }
Example #20
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);
 }
Example #21
0
 @Test
 public void test_poll_removeKey_noCampaign() {
   // GIVEN
   Poll sond = new Poll();
   String key1 = "test";
   String key2 = "test2";
   List<String> keys = new ArrayList<String>();
   keys.add(key1);
   keys.add(key2);
   sond.setKeywords(keys);
   // WHEN
   sond.removeKeyword("test");
   // THEN
   assertEquals(keys.get(0), key2);
   assertEquals(keys.size(), 1);
 }
Example #22
0
 @Test
 public void test_poll_setWebsite_noCampaign3() {
   // GIVEN
   Poll sond = new Poll();
   String url = "https://www.google.fr/search?client=ubuntu";
   // WHEN
   sond.setWebsite(url);
   // THEN
   assertEquals(sond.getWebsite(), url);
   /*try {
       sond.setWebsite(url);
       fail("Website URL should be correct to the pattern.");
   } catch (IllegalArgumentException expected) {
       assertEquals("Website URL should be correct to the pattern.", expected.getMessage());
   }*/
 }
Example #23
0
 @Test
 public void test_poll_setWebsite_noCampaign2() {
   // GIVEN
   Poll sond = new Poll();
   String url = "http://aaaaaaaaaa";
   // WHEN
   // sond.setWebsite(url);
   // THEN
   // assertEquals(sond.getWebsite(), url);
   try {
     sond.setWebsite(url);
     fail("Website URL should be correct to the pattern.");
   } catch (IllegalArgumentException expected) {
     assertEquals("Website URL should be correct to the pattern.", expected.getMessage());
   }
 }
Example #24
0
  @Test
  public void test_poll_setWebsite_noCampaign4() {
    // GIVEN
    Poll sond = new Poll();
    String url = "http://communaute-universitaire.univ-rouen.fr/";
    // WHEN
    sond.setWebsite(url);
    // THEN
    assertEquals(sond.getWebsite(), url);
    /*try {
        sond.setWebsite(url);
        fail("Website URL should be correct to the pattern.");
    } catch (IllegalArgumentException expected) {
        assertEquals("Website URL should be correct to the pattern.", expected.getMessage());
    }*/

  }
 /* (non-Javadoc)
  * @see org.fosstrak.ale.wsdl.ale.epcglobal.ALEServicePortType#poll(org.fosstrak.ale.wsdl.ale.epcglobal.Poll  parms )*
  */
 public org.fosstrak.ale.xsd.ale.epcglobal.ECReports poll(Poll parms)
     throws ImplementationExceptionResponse, SecurityExceptionResponse,
         NoSuchNameExceptionResponse {
   log.debug("poll");
   try {
     return ale.poll(parms.getSpecName());
   } catch (org.fosstrak.ale.exception.NoSuchNameException e) {
     throw new NoSuchNameExceptionResponse(e.getMessage(), e);
   }
 }
Example #26
0
 /* Tests CDR */
 @Test
 public void test_poll_with_ordo_questions() {
   // GIVEN
   Poll sond = new Poll();
   Question q1 = new Question();
   q1.setId(1);
   q1.setOrderNumber(1);
   Question q2 = new Question();
   q2.setId(2);
   q2.setOrderNumber(2);
   List<Question> quests = new ArrayList<Question>();
   quests.add(q1);
   quests.add(q2);
   // WHEN
   sond.setQuestions(quests);
   // THEN
   assertEquals(sond.getQuestions().get(0).getOrderNumber(), 1);
   assertEquals(sond.getQuestions().get(1).getOrderNumber(), 2);
 }
Example #27
0
 @Test
 public void test_poll_setClassification_Campaign() {
   // GIVEN
   Poll sond = new Poll();
   ClassificationCategory cc = ClassificationCategory.MUSIC;
   // WHEN
   Campaign c = new Campaign();
   c.setStartingAt(new Timestamp(new Date().getTime()));
   c.setEndingAt(new Timestamp(new Date().getTime() + 10000));
   List<Campaign> lcamps = new ArrayList<Campaign>();
   lcamps.add(c);
   sond.setCampaigns(lcamps);
   // THEN
   try {
     sond.setClassification(cc);
     fail("A campaign is processing.");
   } catch (IllegalArgumentException expected) {
     assertEquals("A campaign is processing.", expected.getMessage());
   }
 }
Example #28
0
 @Test
 public void test_poll_allowCom_true_Campaign() {
   // GIVEN
   Poll sond = new Poll();
   boolean com = true;
   // WHEN
   Campaign c = new Campaign();
   c.setStartingAt(new Timestamp(new Date().getTime()));
   c.setEndingAt(new Timestamp(new Date().getTime() + 10000));
   List<Campaign> lcamps = new ArrayList<Campaign>();
   lcamps.add(c);
   sond.setCampaigns(lcamps);
   // THEN
   try {
     sond.setAllowComment(com);
     fail("A campaign is processing.");
   } catch (IllegalArgumentException expected) {
     assertEquals("A campaign is processing.", expected.getMessage());
   }
 }
Example #29
0
 @Test
 public void test_poll_setWebsite_exception_Campaign() {
   // GIVEN
   Poll sond = new Poll();
   String url = "Blajefe.monsite.fr";
   // WHEN
   Campaign c = new Campaign();
   c.setStartingAt(new Timestamp(new Date().getTime()));
   c.setEndingAt(new Timestamp(new Date().getTime() + 10000));
   List<Campaign> lcamps = new ArrayList<Campaign>();
   lcamps.add(c);
   sond.setCampaigns(lcamps);
   // THEN
   try {
     sond.setWebsite(url);
     fail("A campaign is processing.");
   } catch (IllegalArgumentException expected) {
     assertEquals("A campaign is processing.", expected.getMessage());
   }
 }
Example #30
0
 @Test
 public void test_poll_setQuestions_checkIDs() {
   // GIVEN
   Poll sond = new Poll();
   Question q1 = new Question();
   q1.setId(1);
   Question q2 = new Question();
   q2.setId(2);
   Question q3 = new Question();
   q3.setId(3);
   List<Question> lqs = new ArrayList<Question>();
   lqs.add(q1);
   lqs.add(q2);
   lqs.add(q3);
   // WHEN
   sond.setQuestions(lqs);
   // THEN
   assertEquals(sond.getQuestions().get(0).getId(), 1);
   assertEquals(sond.getQuestions().get(1).getId(), 2);
   assertEquals(sond.getQuestions().get(2).getId(), 3);
 }