Commits

Paola Morales  committed dade536

New Test Cases and Helper for TweetPoll and HashTag Dao

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

  • Participants
  • Parent commits 59c625c

Comments (0)

Files changed (5)

File encuestame-persistence/src/main/java/org/encuestame/persistence/dao/ITweetPoll.java

 
 package org.encuestame.persistence.dao;
 
+import java.util.Date;
 import java.util.List;
 
 import org.encuestame.persistence.dao.imp.TweetPollDao;
        */
      Long getTotalVotesByTweetPollId(final Long tweetPollId);
 
+     /**
+      * Retrieve TweetPoll by Date
+      * @param userId
+      * @param initDate
+      * @param maxResults
+      * @param start
+      * @return
+      */
+     List<TweetPoll> retrieveTweetPollByDate(final Long userId, final Date initDate, final Integer maxResults,
+             final Integer start);
 }

File encuestame-persistence/src/main/java/org/encuestame/persistence/dao/imp/TweetPollDao.java

      * @return
      */
     @SuppressWarnings("unchecked")
-    private List<TweetPoll> retrieveTweetPollByDate(
+    public List<TweetPoll> retrieveTweetPollByDate(
             final Long userId,
             final Date initDate,
             final Integer maxResults,
         criteria.createAlias("tweetOwner","tweetOwner");
         criteria.add(Restrictions.eq("scheduleTweetPoll", Boolean.TRUE));
         criteria.add(Restrictions.isNotNull("scheduleDate"));
-        criteria.add(Restrictions.eq("tweetOwner.id", userId));
+        criteria.add(Restrictions.eq("tweetOwner.uid", userId));
         return (List<TweetPoll>) filterByMaxorStart(criteria, maxResults, start);
     }
 

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

 import org.encuestame.persistence.dao.IGeoPoint;
 import org.encuestame.persistence.dao.IGeoPointTypeDao;
 import org.encuestame.persistence.dao.IGroupDao;
+import org.encuestame.persistence.dao.IHashTagDao;
 import org.encuestame.persistence.dao.INotification;
 import org.encuestame.persistence.dao.IPermissionDao;
 import org.encuestame.persistence.dao.IPoll;
 import org.encuestame.persistence.dao.ITweetPoll;
 import org.encuestame.persistence.dao.imp.ClientDao;
 import org.encuestame.persistence.dao.imp.EmailDao;
+import org.encuestame.persistence.dao.imp.HashTagDao;
 import org.encuestame.persistence.dao.imp.PollDao;
 import org.encuestame.persistence.dao.imp.TweetPollDao;
 import org.encuestame.persistence.domain.Client;
 import org.encuestame.persistence.domain.GeoPointFolder;
 import org.encuestame.persistence.domain.GeoPointFolderType;
 import org.encuestame.persistence.domain.GeoPointType;
+import org.encuestame.persistence.domain.HashTag;
 import org.encuestame.persistence.domain.Project;
 import org.encuestame.persistence.domain.Question;
 import org.encuestame.persistence.domain.Status;
     @Autowired
     private ISocialProviderDao providerDao;
 
+    /** {@link HashTagDao} **/
+    @Autowired
+    private IHashTagDao hashTagDao;
+
     /**
      * Get Property.
      * @param property
         tweetPoll.setQuestion(question);
         tweetPoll.setScheduleDate(scheduleDate);
         tweetPoll.setScheduleTweetPoll(scheduleTweetPoll);
-        //tweetPoll.setTweetId(tweetId);
+        tweetPoll.setCreateDate(publicationDateTweet);
+        tweetPoll.setFavourites(Boolean.TRUE);
         tweetPoll.setTweetOwner(tweetOwner);
         getTweetPoll().saveOrUpdate(tweetPoll);
         return tweetPoll;
      * @return {@link TweetPoll}
      */
     public TweetPoll createPublishedTweetPoll(final Account tweetOwner, final Question question){
-       return createTweetPoll(12345L, false, false, false, true, false, new Date(), new Date(), false, tweetOwner, question);
+       return createTweetPoll(12345L, false, false, false, true, true, new Date(), new Date(), false, tweetOwner, question);
     }
 
     /**
     }
 
     /**
+     * Create Hash Tag.
+     * @param hashTagName
+     * @return
+     */
+    public HashTag createHashTag(final String hashTagName){
+        final HashTag hashTag = new HashTag();
+        hashTag.setHashTag(hashTagName);
+        getHashTagDao().saveOrUpdate(hashTag);
+        return hashTag;
+    }
+    /**
      * @return the notification
      */
     public INotification getNotification() {
         this.providerDao = providerDao;
     }
 
+    /**
+     * @return the hashTagDao
+     */
+    public IHashTagDao getHashTagDao() {
+        return hashTagDao;
+    }
+
+    /**
+     * @param hashTagDao the hashTagDao to set
+     */
+    public void setHashTagDao(IHashTagDao hashTagDao) {
+        this.hashTagDao = hashTagDao;
+    }
 }

File encuestame-persistence/src/test/java/org/encuestame/test/persistence/dao/TestHashTagDao.java

+/*
+ ************************************************************************************
+ * Copyright (C) 2001-2010 encuestame: system online surveys Copyright (C) 2010
+ * 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 static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.encuestame.persistence.dao.imp.HashTagDao;
+import org.encuestame.persistence.domain.HashTag;
+import org.encuestame.test.config.AbstractBase;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test {@link HashTagDao}..
+ * @author Morales Urbina, Diana paola AT encuestame.org
+ * @since January 06, 2011
+ * @version $Id: $
+ */
+public class TestHashTagDao  extends AbstractBase{
+
+    /** {@link HashTag} **/
+    private HashTag hashTag;
+
+    @Before
+    public void initData(){
+        this.hashTag = createHashTag("software");
+    }
+
+    /**
+     * Test Get HashTag by Name.
+     */
+    @Test
+    public void testGetHashTagByName(){
+        final HashTag ht = getHashTagDao().getHashTagByName(this.hashTag.getHashTag());
+        assertEquals("Should be equals", this.hashTag.getHashTag(), ht.getHashTag());
+    }
+
+    /**
+     * Test Get List HashTags by Keyword.
+     */
+
+    public void testGetListHashTagsByKeyword(){
+        this.hashTag = createHashTag("software");
+        final String keyword = "software";
+        final List<HashTag> hashTagList = getHashTagDao().getListHashTagsByKeyword(keyword, 5);
+        assertEquals("Should be equals", 2, hashTagList.size());
+    }
+
+}

File encuestame-persistence/src/test/java/org/encuestame/test/persistence/dao/TestTweetPollDao.java

 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import java.util.Date;
 import java.util.List;
 
+import org.encuestame.persistence.dao.imp.TweetPollDao;
 import org.encuestame.persistence.domain.Question;
 import org.encuestame.persistence.domain.security.UserAccount;
 import org.encuestame.persistence.domain.survey.QuestionAnswer;
         final List<TweetPoll> tpfolder = getTweetPoll().retrieveTweetPollByFolder(user, this.tweetPollFolder.getId());
         assertEquals("Should be equals", 1, tpfolder.size());
     }
+
+    /**
+     * Test Retrieve Tweets By User.
+     */
+    @Test
+    public void testRetrieveTweetsByUserId(){
+        assertNotNull(this.secondary);
+        assertNotNull(tweetPoll);
+        final Long userId = this.secondary.getSecUser().getUid();
+        final List<TweetPoll> tweets = getTweetPoll().retrieveTweetsByUserId(userId, 5, 0);
+        assertEquals("Should be equals", 1, tweets.size());
+    }
+
+    /**
+     * Test Retrieve Tweets by
+     */
+    @Test
+    public void testRetrieveTweetsByQuestionName(){
+        assertNotNull(this.secondary);
+        assertNotNull(tweetPoll);
+        final Long userId = this.secondary.getSecUser().getUid();
+        final String keyword = "Who";
+        final List<TweetPoll> tweets = getTweetPoll().retrieveTweetsByQuestionName(keyword, userId, 5, 0);
+        assertEquals("Should be equals", 1, tweets.size());
+    }
+
+    /**
+     * Test Retrieve TweetPoll Today.
+     */
+    @Test
+    public void testRetrieveTweetPollToday(){
+        assertNotNull(this.secondary);
+        assertNotNull(tweetPoll);
+        final Long userId = this.secondary.getSecUser().getUid();
+        final List<TweetPoll> tweetsToday = getTweetPoll().retrieveTweetPollToday(userId, 5, 0);
+        assertEquals("Should be equals", 1, tweetsToday.size());
+    }
+
+    @Test
+    public void testRetrieveTweetPollByDate(){
+        assertNotNull(this.secondary);
+        assertNotNull(tweetPoll);
+        final Long userId = this.secondary.getSecUser().getUid();
+        final Date initDate = new Date();
+        final List<TweetPoll> tweetsByDate = getTweetPoll().retrieveTweetPollByDate(userId, initDate, 5, 0);
+        assertEquals("Should be equals", 1, tweetsByDate.size());
+    }
+
+    /**
+     * Test Retrieve TweetPoll Last Week
+     */
+    @Test
+    public void testRetrieveFavouritesTweetPoll(){
+        assertNotNull(this.secondary);
+        assertNotNull(tweetPoll);
+        final Long userId = this.secondary.getSecUser().getUid();
+        final List<TweetPoll> favouritesTweets = getTweetPoll().retrieveFavouritesTweetPoll(userId, 5, 0);
+        assertEquals("Should be equals", 1, favouritesTweets.size());
+    }
+
+    @Test
+    public void testRetrieveScheduledTweetPoll(){
+        assertNotNull(this.secondary);
+        assertNotNull(tweetPoll);
+        final Long userId = this.secondary.getSecUser().getUid();
+        final List<TweetPoll> scheduledTweets = getTweetPoll().retrieveScheduledTweetPoll(userId, 5, 0);
+        assertEquals("Should be equals", 1, scheduledTweets.size());
+    }
 }