001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.survey.test;
034:
035: import junit.framework.TestCase;
036: import junit.framework.TestSuite;
037:
038: import org.libresource.Libresource;
039:
040: import org.libresource.kernel.KernelConstants;
041: import org.libresource.kernel.interfaces.KernelService;
042:
043: import org.libresource.survey.Option;
044: import org.libresource.survey.SurveyConstants;
045: import org.libresource.survey.ejb.model.SurveyResourceValue;
046: import org.libresource.survey.interfaces.LibresourceSurveyService;
047:
048: import java.net.URI;
049:
050: import java.util.Iterator;
051: import java.util.Vector;
052:
053: import javax.security.auth.callback.CallbackHandler;
054: import javax.security.auth.login.LoginContext;
055:
056: /**
057: * LibreSource
058: * @author <a href="mailto:jouille@loria.fr">Florent Jouille </a>
059: */
060: public class SurveyTest extends TestCase {
061: LoginContext loginContext;
062: KernelService kernelService;
063: String rootNode;
064:
065: public SurveyTest(String arg0) {
066: super (arg0);
067: }
068:
069: protected void setUp() throws Exception {
070: //LibreSourceJAAS.loadDefaultJAASConfiguration("jonas");
071: CallbackHandler handler = org.libresource.Libresource
072: .buildCallBackHandler("user", "user");
073: loginContext = new LoginContext("libresource", handler);
074: loginContext.login();
075: kernelService = (KernelService) Libresource
076: .getService(KernelConstants.SERVICE);
077: rootNode = System.getProperty("rootNode");
078: }
079:
080: protected void tearDown() throws Exception {
081: loginContext.logout();
082: }
083:
084: public void testSurvey() throws Exception {
085: URI uri = new URI("/projects/test/survey");
086:
087: try {
088: //kernelService.deleteURI(uri);
089: } catch (Exception e) {
090: }
091:
092: //kernelService.createURI(uri);
093: LibresourceSurveyService surveyService = (LibresourceSurveyService) Libresource
094: .getService(SurveyConstants.SERVICE);
095:
096: //surveyService.createSurvey(uri, "Pourquoi ?", "", "TRUE", null, "HTML");
097: //printSurvey(surveyService.getSurvey(uri));
098: //surveyService.editSurvey(uri, "Comment ?", "PIE");
099: //printSurvey(surveyService.getSurvey(uri));
100: //surveyService.closeSurvey(uri);
101: //printSurvey(surveyService.getSurvey(uri));
102: //surveyService.openSurvey(uri);
103: //printSurvey(surveyService.getSurvey(uri));
104: //surveyService.addOptionInSurvey(uri, "choix 1", 0);
105: //printSurvey(surveyService.getSurvey(uri));
106: //surveyService.addOptionInSurvey(uri, "choix 2", 0);
107: printSurvey(surveyService.getSurvey(uri));
108:
109: //Option o = surveyService.getOptionInSurvey(uri, surveyService.getOptionsInSurvey(uri)[0].getId());
110: //surveyService.deleteOptionInSurvey(uri, o.getId());
111: //printSurvey(surveyService.getSurvey(uri));
112: surveyService.voteInSurvey(uri,
113: "ffa68b829851071200b551e4d7034fc8");
114: printSurvey(surveyService.getSurvey(uri));
115: System.out
116: .println(surveyService.getSurvey(uri).getVotersList());
117:
118: Vector v = surveyService.getResults(uri, surveyService
119: .getSurvey(uri).getVoters().length);
120:
121: for (Iterator i = v.iterator(); i.hasNext();) {
122: Object[] obj = (Object[]) i.next();
123:
124: for (int j = 0; j < obj.length; j++) {
125: System.out.println(obj[j]);
126: }
127: }
128: }
129:
130: public static TestSuite suite() {
131: TestSuite suite = new TestSuite();
132: suite.addTest(new SurveyTest("testSurvey"));
133:
134: return suite;
135: }
136:
137: private void printSurvey(SurveyResourceValue survey)
138: throws Exception {
139: System.out
140: .println("-----------------------------------------------");
141: System.out.println(">> SURVEY : " + survey.getUri());
142: System.out
143: .println(" - Question : " + survey.getQuestion());
144: System.out.println(" - DisplayMode : "
145: + survey.getDisplayMode());
146: System.out.println(" - CreationDate : "
147: + survey.getCreationDate());
148: System.out.println(" - Opening : " + survey.getState());
149: System.out.println(" - VotersList : "
150: + survey.getVotersList());
151:
152: LibresourceSurveyService surveyService = (LibresourceSurveyService) Libresource
153: .getService(SurveyConstants.SERVICE);
154: Vector options = surveyService.getOptionsInSurvey(survey
155: .getUri());
156:
157: for (Iterator i = options.iterator(); i.hasNext();) {
158: Option o = (Option) i.next();
159: System.out.println(" * Option : " + o.getId() + " \""
160: + o.getChoice() + "\" [" + o.getNbVote() + "]");
161: }
162: }
163: }
|