@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(); } } }
@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()); } }
@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); }
@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); }
@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); }
@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)); }
@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); }
@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); }
@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); }
@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); }
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(); }
@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); }
@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); }
@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()); }
@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); }
@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"); } }
@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); } }
@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()); } }
@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); }
@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); }
@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()); }*/ }
@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()); } }
@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); } }
/* 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); }
@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()); } }
@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()); } }
@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()); } }
@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); }