Package org.jsurveylib

Examples of org.jsurveylib.Survey


public class PageTest {


    @Test
    public void label() throws Exception {
        Survey m = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\pagefiles\\label.xml")));
        Page page = m.getCurrentPage();
        assertEquals("My Page", page.getLabel());
    }
View Full Code Here


        assertEquals("My Page", page.getLabel());
    }

    @Test
    public void elementsAndQuestions() throws Exception {
        Survey m = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\pagefiles\\elementsandquestions.xml")));
        Page page = m.getCurrentPage();
        assertEquals(3, page.countElements());
        Question q1 = (Question) page.getSurveyElements().get(0);
        assertEquals("Y", q1.getId());
        Label label = (Label) page.getSurveyElements().get(1);
        assertEquals("I Am a question too!!!", label.getText());
View Full Code Here

        assertEquals(3, page.getSurveyElements().size());
    }

    @Test
    public void isRequiredQuestionsAnswered() throws Exception {
        Survey m = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\pagefiles\\allmandatoryanswered.xml")));
        Page firstPage = m.getCurrentPage();
        assertFalse(firstPage.areRequirementsMet());
        firstPage.getQuestions().get(0).setAnswer("yes");
        assertFalse(firstPage.areRequirementsMet());
        m.getQuestionByID("Z").setAnswer("yes");    //this will make a mandatory question on page 0 become visible
        assertTrue(m.getQuestionByID("X").isVisible());
        assertFalse(firstPage.areRequirementsMet());
        m.getQuestionByID("X").setAnswer("yes");
        assertTrue(firstPage.areRequirementsMet());
        m.goToNextPage();
        Page secondPage = m.getCurrentPage();
        assertFalse(secondPage.areRequirementsMet());   //page 0's "Y" must be set to "no" for question "B" to be valid
        assertFalse(m.getQuestionByID("B").isValid());

        m.getQuestionByID("Y").setAnswer("no");
        assertTrue(secondPage.areRequirementsMet());   //page 0's "Y" must be set to "no" for question "B" to be valid
        assertTrue(m.getQuestionByID("B").isValid());
    }
View Full Code Here

        assertTrue(m.getQuestionByID("B").isValid());
    }

    @Test
    public void insertQuestionCorrectly() throws Exception {
        Survey survey = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\pagefiles\\insertquestioncorrectly.xml")));
        Page p = survey.getPages().get(0);
        Question z = survey.getQuestionByID("Y").populateTemplate("Z", null, false, "");
        p.insertQuestion(z, 2);
        assertEquals(z, p.getQuestions().get(2));
        assertEquals(survey.getQuestionByID("X"), p.getQuestions().get(1));

        Question a = z.populateTemplate("A", null, false, "");
        p.insertQuestion(a, 0);
        assertEquals(a, p.getQuestions().get(0));
        assertEquals(survey.getQuestionByID("Y"), p.getQuestions().get(1));

        Question m = z.populateTemplate("A", null, false, "");
        p.insertQuestion(m, 1);
        assertEquals(m, p.getQuestions().get(1));
        assertEquals(a, p.getQuestions().get(0));
        assertEquals(survey.getQuestionByID("Y"), p.getQuestions().get(2));
    }
View Full Code Here

        assertEquals(survey.getQuestionByID("Y"), p.getQuestions().get(2));
    }

    @Test(expected = IllegalArgumentException.class)
    public void insertQuestionTooHigh() throws Exception {
        Survey survey = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\pagefiles\\insertquestiontoohigh.xml")));
        survey.getPages().get(0).insertQuestion(survey.getQuestionByID("Y").populateTemplate("Z", null, false, ""), 3);
    }
View Full Code Here

        survey.getPages().get(0).insertQuestion(survey.getQuestionByID("Y").populateTemplate("Z", null, false, ""), 3);
    }

    @Test(expected = IllegalArgumentException.class)
    public void insertQuestionTooLow() throws Exception {
        Survey survey = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\pagefiles\\insertquestiontoolow.xml")));
        survey.getPages().get(0).insertQuestion(survey.getQuestionByID("Y").populateTemplate("Z", null, false, ""), -1);
    }
View Full Code Here

        survey.getPages().get(0).insertQuestion(survey.getQuestionByID("Y").populateTemplate("Z", null, false, ""), -1);
    }

    @Test
    public void rowOf() throws Exception {
        Survey survey = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\pagefiles\\rowof.xml")));
        Page page = survey.getPages().get(0);
        assertEquals(0, page.rowOf("X"));
        assertEquals(1, page.rowOf("Y"));
        assertEquals(2, page.rowOf("Z"));
        assertTrue(page.rowOf("NONE") < 0);
    }
View Full Code Here

        assertTrue(page.rowOf("NONE") < 0);
    }

    @Test
    public void skipped() throws Exception {
        Survey survey = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\pagefiles\\skipped.xml")));
        assertFalse(survey.getPages().get(0).isSkipped());
        assertTrue(survey.getPages().get(1).isSkipped());
        assertEquals(3, survey.getPages().size());
        assertEquals(2, survey.getTotalPagesExcludingSkipped());

        assertEquals(0, survey.getCurrentPageNumber());
        assertEquals(0, survey.getCurrentPageNumberExcludingSkipped());
        survey.goToNextPage();
        assertEquals(2, survey.getCurrentPageNumber()); //we skipped a page
        assertEquals(1, survey.getCurrentPageNumberExcludingSkipped());
        assertTrue(survey.isLastPageAndComplete());
        survey.goToPreviousPage();
        assertEquals(0, survey.getCurrentPageNumber());
        assertEquals(0, survey.getCurrentPageNumberExcludingSkipped());
        assertFalse(survey.isLastPageAndComplete());

        //we have mandatory / invalid questions on a skipped page but we should still be allowed to finish
        Question mandatory = survey.getQuestionByID("mandatory");
        assertTrue(mandatory.isMandatory() && !mandatory.isAnswered());
        Question invalid = survey.getQuestionByID("invalid");
        assertFalse(invalid.isValid());
        assertTrue(survey.getPages().get(1).areRequirementsMet());

        survey.goToNextPage()//last page
        assertTrue(survey.isLastPageAndComplete());               
    }
View Full Code Here

        assertTrue(survey.isLastPageAndComplete());               
    }

    @Test(expected = IllegalArgumentException.class)
    public void visitSkippedPage() throws Exception {
        Survey survey = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\pagefiles\\visitskippedpage.xml")));
        survey.goToPage(1); //goto a skipped page
    }
View Full Code Here

        survey.goToPage(1); //goto a skipped page
    }

    @Test
    public void firstPagesSkipped() throws Exception {
        Survey survey = new Survey(new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\model\\pagefiles\\firstpageskipped.xml")));
        assertEquals(2, survey.getCurrentPageNumber());
        assertEquals(0, survey.getCurrentPageNumberExcludingSkipped());
        assertEquals(1, survey.getTotalPagesExcludingSkipped());
        assertEquals(3, survey.getPages().size());
        assertFalse(survey.isPreviousPageAvailable());
        assertTrue(survey.isLastPageAndComplete());
    }
View Full Code Here

TOP

Related Classes of org.jsurveylib.Survey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.