/**
* This file is part of JSurveyLib.
*
* JSurveyLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JSurveyLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JSurveyLib. If not, see <http://www.gnu.org/licenses/>.
**/
package org.jsurveylib.io;
import static org.junit.Assert.*;
import org.junit.Test;
import org.jsurveylib.model.i18n.Strings;
import java.io.File;
/**
* Copyright (c)2007, Daniel Kaplan
*
* @author Daniel Kaplan
* @since 7.10.4
*/
public class XMLSurveyReaderTest {
@Test(expected = org.xml.sax.SAXParseException.class)
public void uniqueQuestionIds() throws Exception {
new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\io\\xmlsurveyreaderfiles\\uniquequestionids.xml"));
}
@Test
public void getpages() throws Exception {
XMLSurveyReader reader = new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\io\\xmlsurveyreaderfiles\\getpages.xml"));
assertEquals(8, reader.getPages().size());
assertTrue(reader.getPages().get(0).getQuestions().size() > 0); //there are questions
}
@Test
public void initScript() throws Exception {
XMLSurveyReader reader = new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\io\\xmlsurveyreaderfiles\\initscript.xml"));
assertEquals("x = 0;", reader.getInitScript());
}
@Test
public void defaultI18NStrings() throws Exception {
XMLSurveyReader reader = new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\io\\xmlsurveyreaderfiles\\defaulti18nstrings.xml"));
Strings strings = reader.getStrings();
assertEquals("Next", strings.getNextString());
assertEquals("Previous", strings.getPreviousString());
assertEquals("Finish", strings.getFinishString());
assertEquals("Page", strings.getPageString());
assertEquals("of", strings.getOfString());
assertEquals("Browse", strings.getBrowseString());
assertEquals("File", strings.getFileString());
assertEquals("View", strings.getViewString());
assertEquals("First Page", strings.getFirstPageString());
assertEquals("Previous Page", strings.getPreviousPageString());
assertEquals("Next Page", strings.getNextPageString());
assertEquals("Last Page", strings.getLastPageString());
assertEquals("Open...", strings.getOpenString());
assertEquals("Save", strings.getSaveString());
assertEquals("Save As...", strings.getSaveAsString());
assertEquals("Unsaved Changes", strings.getUnsavedChangesString());
assertEquals("This survey has unsaved changes. Choose OK to save these changes to\n", strings.getSaveToWorkingFileNotificationString());
assertEquals("This survey has unsaved changes. Choose OK to save these changes.", strings.getSaveToNewFileNotificationString());
}
@Test
public void i18NStringsDeprecated() throws Exception {
XMLSurveyReader reader = new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\io\\xmlsurveyreaderfiles\\i18nstringsdeprecated.xml"));
Strings strings = reader.getStrings();
assertEquals("1", strings.getNextString());
assertEquals("2", strings.getPreviousString());
assertEquals("3", strings.getFinishString());
assertEquals("4", strings.getPageString());
assertEquals("5", strings.getOfString());
}
@Test
public void i18NStrings() throws Exception {
XMLSurveyReader reader = new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\io\\xmlsurveyreaderfiles\\i18nstrings.xml"));
Strings strings = reader.getStrings();
assertEquals("1", strings.getNextString());
assertEquals("2", strings.getPreviousString());
assertEquals("3", strings.getFinishString());
assertEquals("4", strings.getPageString());
assertEquals("5", strings.getOfString());
assertEquals("6", strings.getBrowseString());
assertEquals("7", strings.getFileString());
assertEquals("8", strings.getViewString());
assertEquals("9", strings.getFirstPageString());
assertEquals("10", strings.getPreviousPageString());
assertEquals("11", strings.getNextPageString());
assertEquals("12", strings.getLastPageString());
assertEquals("13", strings.getOpenString());
assertEquals("14", strings.getSaveString());
assertEquals("15", strings.getSaveAsString());
assertEquals("16", strings.getUnsavedChangesString());
assertEquals("17", strings.getSaveToWorkingFileNotificationString());
assertEquals("18", strings.getSaveToNewFileNotificationString());
}
@Test
public void saveToFileOnFinish() throws Exception {
XMLSurveyReader reader = new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\io\\xmlsurveyreaderfiles\\savetofileonfinish.xml"));
assertTrue(reader.saveToFileOnFinish());
//this is the default:
reader = new XMLSurveyReader(new File("src\\test\\org\\jsurveylib\\io\\xmlsurveyreaderfiles\\i18nstrings.xml"));
assertFalse(reader.saveToFileOnFinish());
}
}