Commits

Anonymous committed 59c625c

New Survey and Poll Test Cases.

git-svn-id: http://svn.encuesta.me/trunk/encuestame@100239e2479b-dd58-4041-9f67-69c9b71f0610

Comments (0)

Files changed (8)

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/IPoll.java

       * @return
       */
      List<Poll> getPollsByPollFolderId(final Long userId, final PollFolder folder);
+
+     /**
+      * Get PollFolder By User.
+      * @param pollFolderId
+      * @param userId
+      * @return
+      */
+     PollFolder getPollFolderByIdandUser(final Long pollFolderId, final Long userId);
+
+     /**
+      * Get Poll by User.
+      * @param pollId
+      * @param userId
+      * @return
+      */
+     Poll getPollByIdandUserId(final Long pollId, Long userId);
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/ISurvey.java

        * @return
        */
       Survey getSurveyByIdandUserId(final Long surveyId, final Long userId);
+
+      /**
+       * Retrieve Surveys by Folder.
+       * @param userId
+       * @param folderId
+       * @return
+       */
+      List<Survey> retrieveSurveyByFolder(final Long userId, final Long folderId);
+
+      /**
+       * Retrieve All Folders.
+       * @param userId
+       * @return
+       */
+      List<SurveyFolder> retrieveAllFolders(final Long userId);
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/imp/PollDao.java

 @Repository("pollDao")
 public class PollDao extends AbstractHibernateDaoSupport implements IPoll {
 
-	@Autowired
-	public PollDao(SessionFactory sessionFactory) {
-	 		setSessionFactory(sessionFactory);
+    @Autowired
+    public PollDao(SessionFactory sessionFactory) {
+             setSessionFactory(sessionFactory);
     }
-	
+
     /**
      * Find All Polls.
      *
      */
     @SuppressWarnings("unchecked")
     public List<Poll> findAll() throws HibernateException {
-         return getHibernateTemplate().find("FROM poll");
+         return getHibernateTemplate().find("FROM Poll");
     }
 
     /**

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/imp/SurveyDaoImp.java

 import java.util.List;
 
 import org.encuestame.persistence.dao.ISurvey;
+import org.encuestame.persistence.domain.survey.Survey;
 import org.encuestame.persistence.domain.survey.SurveyFolder;
 import org.encuestame.persistence.domain.survey.SurveyFormat;
 import org.encuestame.persistence.domain.survey.SurveyPagination;
 import org.encuestame.persistence.domain.survey.SurveySection;
-import org.encuestame.persistence.domain.survey.Survey;
 import org.hibernate.HibernateException;
 import org.hibernate.SessionFactory;
 import org.hibernate.criterion.DetachedCriteria;
 @Repository("surveyDaoImp")
 public class SurveyDaoImp extends AbstractHibernateDaoSupport implements ISurvey {
 
-	@Autowired
-	public SurveyDaoImp(SessionFactory sessionFactory) {
-	 		setSessionFactory(sessionFactory);
+    @Autowired
+    public SurveyDaoImp(SessionFactory sessionFactory) {
+             setSessionFactory(sessionFactory);
     }
-	
+
     /**
      * Search survey by name.
      * @param searchString search string
      * @return
      */
     @SuppressWarnings("unchecked")
-    public List<SurveyFolder> retrieveSurveysByFolder(final Long userId, final Long folderId){
-        return getHibernateTemplate().findByNamedParam("FROM SurveyFolder where surveyFolderId:folderId","folderId", folderId);
-    }
+    public List<Survey> retrieveSurveyByFolder(final Long userId, final Long folderId){
+        final DetachedCriteria criteria = DetachedCriteria.forClass(Survey.class);
+        criteria.add(Restrictions.eq("secUsers.uid", userId));
+        criteria.add(Restrictions.eq("surveysfolder.id", folderId));
+        return getHibernateTemplate().findByCriteria(criteria);
+   }
 
     /**
      * Retrieve All Folders
          criteria.add(Restrictions.eq("sid", surveyId));
          return (Survey) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));
     }
+
 }
 

encuestame-persistence/src/test/java/org/encuestame/test/config/AbstractBase.java

 import java.util.Date;
 import java.util.Properties;
 
-import junit.framework.Assert;
-
 import org.apache.commons.lang.RandomStringUtils;
+import org.encuestame.persistence.dao.IAccountDao;
+import org.encuestame.persistence.dao.IClientDao;
 import org.encuestame.persistence.dao.IEmail;
 import org.encuestame.persistence.dao.IGeoPoint;
 import org.encuestame.persistence.dao.IGeoPointTypeDao;
-import org.encuestame.persistence.dao.IClientDao;
+import org.encuestame.persistence.dao.IGroupDao;
 import org.encuestame.persistence.dao.INotification;
+import org.encuestame.persistence.dao.IPermissionDao;
 import org.encuestame.persistence.dao.IPoll;
 import org.encuestame.persistence.dao.IProjectDao;
 import org.encuestame.persistence.dao.IQuestionDao;
-import org.encuestame.persistence.dao.IGroupDao;
-import org.encuestame.persistence.dao.IPermissionDao;
-import org.encuestame.persistence.dao.IAccountDao;
 import org.encuestame.persistence.dao.ISocialProviderDao;
 import org.encuestame.persistence.dao.ISurvey;
 import org.encuestame.persistence.dao.ISurveyFormatDao;
 import org.encuestame.persistence.dao.ITweetPoll;
-import org.encuestame.persistence.dao.imp.EmailDao;
 import org.encuestame.persistence.dao.imp.ClientDao;
+import org.encuestame.persistence.dao.imp.EmailDao;
 import org.encuestame.persistence.dao.imp.PollDao;
 import org.encuestame.persistence.dao.imp.TweetPollDao;
-import org.encuestame.persistence.domain.GeoPointType;
 import org.encuestame.persistence.domain.Client;
-import org.encuestame.persistence.domain.EmailList;
 import org.encuestame.persistence.domain.Email;
+import org.encuestame.persistence.domain.EmailList;
 import org.encuestame.persistence.domain.EnMePermission;
-import org.encuestame.persistence.domain.GeoPointFolder;
 import org.encuestame.persistence.domain.GeoPoint;
+import org.encuestame.persistence.domain.GeoPointFolder;
 import org.encuestame.persistence.domain.GeoPointFolderType;
+import org.encuestame.persistence.domain.GeoPointType;
 import org.encuestame.persistence.domain.Project;
 import org.encuestame.persistence.domain.Question;
 import org.encuestame.persistence.domain.Status;
 import org.encuestame.persistence.domain.survey.Poll;
 import org.encuestame.persistence.domain.survey.PollFolder;
 import org.encuestame.persistence.domain.survey.PollResult;
+import org.encuestame.persistence.domain.survey.QuestionAnswer;
 import org.encuestame.persistence.domain.survey.QuestionColettion;
 import org.encuestame.persistence.domain.survey.QuestionPattern;
-import org.encuestame.persistence.domain.survey.QuestionAnswer;
+import org.encuestame.persistence.domain.survey.Survey;
 import org.encuestame.persistence.domain.survey.SurveyFolder;
 import org.encuestame.persistence.domain.survey.SurveyFormat;
 import org.encuestame.persistence.domain.survey.SurveyGroup;
 import org.encuestame.persistence.domain.survey.SurveyPagination;
 import org.encuestame.persistence.domain.survey.SurveySection;
-import org.encuestame.persistence.domain.survey.Survey;
 import org.encuestame.persistence.domain.survey.TweetPoll;
 import org.encuestame.persistence.domain.survey.TweetPollFolder;
 import org.encuestame.persistence.domain.survey.TweetPollResult;
     }
 
     /**
+     * Add Survey To Folder.
+     * @param folderId
+     * @param userId
+     * @param surveyId
+     * @return
+     * @throws EnMeDomainNotFoundException
+     */
+    public Survey addSurveyToFolder(final Long folderId, final Long userId, final Long surveyId) throws EnMeDomainNotFoundException{
+        final SurveyFolder sfolder = getSurveyDaoImp().getSurveyFolderById(folderId);
+        final Survey survey = getSurveyDaoImp().getSurveyByIdandUserId(surveyId, userId);
+        survey.setSurveysfolder(sfolder);
+        getSurveyDaoImp().saveOrUpdate(survey);
+        return survey;
+    }
+
+    /**
+     * Add Poll to Folder.
+     * @param folderId
+     * @param userId
+     * @param pollId
+     * @return
+     * @throws EnMeDomainNotFoundException
+     */
+    public Poll addPollToFolder(final Long folderId, final Long userId, final Long pollId) throws EnMeDomainNotFoundException{
+        final PollFolder pfolder = getiPoll().getPollFolderById(folderId);
+        final Poll poll = getiPoll().getPollByIdandUserId(pollId, userId);
+        poll.setPollFolder(pfolder);
+        getiPoll().saveOrUpdate(poll);
+        return poll;
+    }
+
+    /**
      * @return the activateNotifications
      */
     public Boolean getActivateNotifications() {

encuestame-persistence/src/test/java/org/encuestame/test/persistence/dao/TestPollDao.java

 import java.util.Iterator;
 import java.util.List;
 
+import org.encuestame.persistence.dao.IPoll;
 import org.encuestame.persistence.domain.Question;
 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.domain.survey.Poll;
+import org.encuestame.persistence.domain.survey.PollFolder;
 import org.encuestame.persistence.domain.survey.PollResult;
-import org.encuestame.persistence.domain.survey.QuestionPattern;
 import org.encuestame.persistence.domain.survey.QuestionAnswer;
-import org.encuestame.persistence.dao.IPoll;
+import org.encuestame.persistence.domain.survey.QuestionPattern;
+import org.encuestame.persistence.exception.EnMeDomainNotFoundException;
 import org.encuestame.test.config.AbstractBase;
 import org.junit.Before;
 import org.junit.Test;
     /** {@link QuestionPattern} **/
     private QuestionPattern questionPattern;
 
+    private PollFolder pollFolder;
+
      /**
      * Before.
      */
         this.question = createQuestion("Why the roses are red?","html");
         this.questionPattern = createQuestionPattern("html");
         this.poll = createPoll(new Date(), this.question, "FDK125", this.user, Boolean.TRUE, Boolean.TRUE);
+        this.pollFolder = createPollFolder("My First Poll Folder", this.user);
 
     }
 
       **/
     @Test
     public void testFindAllPollByUserId(){
-       this.secUserSecondary = createSecondaryUser("diana", this.user);
+        this.secUserSecondary = createSecondaryUser("diana", this.user);
         System.out.println("UID-->"+this.secUserSecondary.getUid());
         final List<Poll> pollList = getiPoll().findAllPollByUserId(this.user.getUid(),5,0);
         assertEquals("Should be equals", 1, pollList.size());
 
     /**
      * Test retrieve Poll By Id.
-     **/
-   @Test
-   public void testGetPollById(){
-       final Poll getpoll = getiPoll().getPollById(this.poll.getPollId());
-       assertNotNull(getpoll);
-   }
-
-   /**
+    **/
+    @Test
+    public void testGetPollById(){
+        final Poll getpoll = getiPoll().getPollById(this.poll.getPollId());
+        assertNotNull(getpoll);
+    }
+
+    /**
     * Test retrieve Results Poll By PollId.
     **/
-  @Test
-  public void testRetrievePollResultsById(){
-      final Question quest = createQuestion("Do you like futboll", "Yes/No");
+    @Test
+    public void testRetrievePollResultsById(){
+        final Question quest = createQuestion("Do you like futboll", "Yes/No");
+        final QuestionAnswer qansw = createQuestionAnswer("Yes", quest, "2020");
+        final QuestionAnswer qansw2 = createQuestionAnswer("No", quest, "2020");
+        final PollResult pollResult =createPollResults(qansw, this.poll);
+        final PollResult pollResult2 =createPollResults(qansw, this.poll);
+        final List<Object[]> polli = getiPoll().retrieveResultPolls(this.poll.getPollId(),qansw.getQuestionAnswerId());
+        final Iterator<Object[]> iterator = polli.iterator();
+        while (iterator.hasNext()) {
+            final Object[] objects = iterator.next();
+         }
+        assertEquals("Should be equals", 1, polli.size());
+    }
 
-      final QuestionAnswer qansw = createQuestionAnswer("Yes", quest, "2020");
-      final QuestionAnswer qansw2 = createQuestionAnswer("No", quest, "2020");
-      final PollResult pollResult =createPollResults(qansw, this.poll);
-      final PollResult pollResult2 =createPollResults(qansw, this.poll);
-      final List<Object[]> polli = getiPoll().retrieveResultPolls(this.poll.getPollId(),qansw.getQuestionAnswerId());
-     final Iterator<Object[]> iterator = polli.iterator();
+    /**
+     * Test Get Poll Folder by User.
+     */
+    @Test
+    public void testGetPollFolderByIdandUser(){
+        assertNotNull(pollFolder);
+        final PollFolder pfolder = getiPoll().getPollFolderByIdandUser(this.pollFolder.getId(), this.user.getUid());
+        assertEquals("Should be equals", this.pollFolder.getId(), pfolder.getId());
+     }
 
-      while (iterator.hasNext()) {
-          final Object[] objects = iterator.next();
-       }
-      assertEquals("Should be equals", 1, polli.size());
+    /**
+     * Test Get Poll By User
+     */
+    @Test
+    public void testGetPollByIdandUserId(){
+        assertNotNull(this.poll);
+        final Poll poll = getiPoll().getPollByIdandUserId(this.poll.getPollId(), this.user.getUid());
+        assertNotNull(poll);
+        assertEquals("Should be equals", this.poll.getPollId(), poll.getPollId());
+    }
+
+    /**
+     * Test Get Polls By Question Keyword.
+     */
+    @Test
+    public void testGetPollsByQuestionKeyword(){
+        assertNotNull(this.poll);
+        final String keywordQuestion = "roses";
+        final List<Poll> listPoll = getiPoll().getPollsByQuestionKeyword(keywordQuestion, this.user.getUid(), 5, 0);
+        assertEquals("Should be equals", 1, listPoll.size());
+    }
 
-  }
+    @Test
+    public void testGetPollFolderById(){
+        assertNotNull(this.pollFolder);
+        final PollFolder pollFolder = getiPoll().getPollFolderById(this.pollFolder.getId());
+        assertEquals("Should be equals", this.pollFolder.getId(), pollFolder.getId());
+    }
 
+    /**
+     * Test Get Polls By PollFolderId.
+     * @throws EnMeDomainNotFoundException
+     */
+    @Test
+    public void testGetPollsByPollFolderId() throws EnMeDomainNotFoundException{
+         assertNotNull(this.pollFolder);
+         assertNotNull(poll);
+         final Poll addPoll = addPollToFolder(this.pollFolder.getId(), this.user.getUid(), this.poll.getPollId());
+         assertNotNull(addPoll);
+         final List<Poll> pfolder = getiPoll().getPollsByPollFolderId(this.user.getUid(), this.pollFolder);
+         assertEquals("Should be equals", 1, pfolder.size());
+    }
 
+    @Test
+    public void testFindAllPoll(){
+        assertNotNull(this.poll);
+        final List<Poll> allPoll = getiPoll().findAll();
+        assertEquals("Should be equals", 1, allPoll.size());
 
+    }
 }

encuestame-persistence/src/test/java/org/encuestame/test/persistence/dao/TestSocialAccountDao.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2009
+ * encuestame Development Team.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.encuestame.test.persistence.dao;
+
+import org.encuestame.persistence.domain.security.SocialAccount;
+import org.encuestame.persistence.domain.security.SocialAccountProvider;
+import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.test.config.AbstractBase;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test {@link SocialAccount}..
+ * @author Morales, Diana Paola paola AT encuestame.org
+ * @since December 27, 2010
+ * @version $Id: $
+ */
+public class TestSocialAccountDao extends AbstractBase{
+
+    /** {@link UserAccount}. **/
+    private SocialAccount socialAccount;
+
+    /**
+     * Before.
+     */
+   // @Before
+    public void initData(){
+        //this.socialAccount =
+
+    }
+
+    @Test
+    public void testGetSocialAccountProviderId(){
+        //final SocialAccountProvider socialAccount = getProviderDao().getSocialAccountProviderId(this.socialAccount.getId());
+        System.out.println("TEST");
+    }
+
+}

encuestame-persistence/src/test/java/org/encuestame/test/persistence/dao/TestSurveyDao.java

 package org.encuestame.test.persistence.dao;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.util.List;
 
 import org.encuestame.persistence.domain.security.Account;
 import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.domain.survey.Survey;
 import org.encuestame.persistence.domain.survey.SurveyFolder;
 import org.encuestame.persistence.domain.survey.SurveyPagination;
 import org.encuestame.persistence.domain.survey.SurveySection;
-import org.encuestame.persistence.domain.survey.Survey;
+import org.encuestame.persistence.exception.EnMeDomainNotFoundException;
 import org.encuestame.test.config.AbstractBase;
 import org.junit.Before;
 import org.junit.Test;
          assertEquals("Should be equals", 2, sectionsByPage.size());
     }
 
+    /**
+     * Test Get Survey by User.
+     */
+    @Test
+    public void testGetSurveyByIdandUserId(){
+        assertNotNull(this.survey);
+        assertNotNull(this.user);
+        final Survey mySurvey = getSurveyDaoImp().getSurveyByIdandUserId(this.survey.getSid(), this.user.getUid());
+        assertNotNull(mySurvey.getSid());
+        assertEquals("Should be equals", this.survey.getSid(), mySurvey.getSid());
+    }
+
+    /**
+     * Test Get Survey Folder
+     */
+    @Test
+    public void testGetSurveyFolderByIdandUser(){
+        assertNotNull(this.surveyFolder);
+        assertNotNull(this.user);
+        final SurveyFolder folder = getSurveyDaoImp().getSurveyFolderByIdandUser(this.surveyFolder.getId(), this.user.getUid());
+        assertNotNull(folder.getId());
+        assertEquals("Should be equals", this.surveyFolder.getId(), surveyFolder.getId());
+    }
+
+    /**
+     * Test Get Survey by Id.
+     */
+    @Test
+    public void testGetSurveyFolderById(){
+        assertNotNull(this.surveyFolder);
+        final SurveyFolder folder = getSurveyDaoImp().getSurveyFolderById(this.surveyFolder.getId());
+        assertNotNull(folder.getId());
+        System.out.println("SURVEY FOLDER ID--->"+ this.surveyFolder.getId());
+        System.out.println("MY SURVEY FOLDER--->"+ surveyFolder.getId());
+        assertEquals("Should be equals", this.surveyFolder.getId(), surveyFolder.getId());
+    }
+
+    /**
+     * Test Retrieve Survey by Folder.
+     * @throws EnMeDomainNotFoundException
+     */
+    @Test
+    public void testRetrieveSurveysByFolder() throws EnMeDomainNotFoundException{
+        assertNotNull(surveyFolder);
+        assertNotNull(survey);
+        final Survey addSurvey = addSurveyToFolder(this.surveyFolder.getId(), this.user.getUid(), this.survey.getSid());
+        assertNotNull(addSurvey);
+        final List<Survey> sfolder = getSurveyDaoImp().retrieveSurveyByFolder(this.user.getUid(), this.surveyFolder.getId());
+        assertEquals("Should be equals", 1, sfolder.size());
+    }
+
+    @Test
+    public void testRetrieveAllFolders(){
+         assertNotNull(surveyFolder);
+         final List<SurveyFolder> allSurveyFolder = getSurveyDaoImp().retrieveAllFolders(this.user.getUid());
+         assertEquals("Should be equals", 1, allSurveyFolder.size());
+    }
+
+
 }