PageRenderTime 1034ms CodeModel.GetById 150ms app.highlight 90ms RepoModel.GetById 656ms app.codeStats 0ms

/src/test/java/com/google/ie/business/dao/impl/TagDaoImplTest.java

http://thoughtsite.googlecode.com/
Java | 136 lines | 93 code | 26 blank | 17 comment | 2 complexity | 9d121712bed4be87b58ebc64558989a7 MD5 | raw file
  1// Copyright 2009 Google Inc. All Rights Reserved.
  2/**
  3 * 
  4 */
  5package com.google.ie.business.dao.impl;
  6
  7import static org.junit.Assert.assertEquals;
  8import static org.junit.Assert.assertNotNull;
  9import static org.junit.Assert.assertTrue;
 10
 11import com.google.ie.business.domain.Tag;
 12import com.google.ie.dto.RetrievalInfo;
 13import com.google.ie.test.DatastoreTest;
 14
 15import org.junit.Before;
 16import org.junit.Test;
 17
 18import java.util.ArrayList;
 19import java.util.Collection;
 20import java.util.List;
 21
 22/**
 23 * Test cases for TagDaoImpl class.
 24 * 
 25 * @author Charanjeet singh
 26 * 
 27 */
 28public class TagDaoImplTest extends DatastoreTest {
 29    TagDaoImpl tagDaoImpl = null;
 30
 31    /**
 32     */
 33    @Before
 34    public void setUp() {
 35        super.setUp();
 36        if (tagDaoImpl == null) {
 37            tagDaoImpl = new TagDaoImpl();
 38            tagDaoImpl.setPersistenceManagerFactory(pmf);
 39        }
 40
 41    }
 42
 43    /**
 44     * Test method for
 45     * {@link com.google.ie.business.dao.impl.TagDaoImpl#saveTag(com.google.ie.business.domain.Tag)}
 46     * .
 47     */
 48    @Test
 49    public final void saveTag() {
 50        Tag expactedTag = new Tag();
 51        expactedTag.setTitle("TestTag");
 52        Tag actualTag = tagDaoImpl.saveTag(expactedTag);
 53
 54        assertNotNull(actualTag);
 55        assertEquals(expactedTag.getTitle(), actualTag.getTitle());
 56    }
 57
 58    @Test
 59    public final void getAllTags() {
 60        Tag expectedTag1 = new Tag();
 61        expectedTag1.setTitle("TestTag1");
 62        tagDaoImpl.saveTag(expectedTag1);
 63        Tag expectedTag2 = new Tag();
 64        expectedTag2.setTitle("TestTag2");
 65        tagDaoImpl.saveTag(expectedTag2);
 66
 67        assertEquals(2, tagDaoImpl.getAllTags().size());
 68    }
 69
 70    @Test
 71    public final void getTagsByKeys() {
 72        Tag tag = new Tag();
 73        tag.setTitle("testTag");
 74
 75        Tag tag1 = new Tag();
 76        tag1.setTitle("testTag1");
 77
 78        tag = tagDaoImpl.saveTag(tag);
 79        tag1 = tagDaoImpl.saveTag(tag1);
 80
 81        Collection<String> keys = new ArrayList<String>();
 82        keys.add(tag.getKey());
 83        keys.add(tag1.getKey());
 84
 85        assertNotNull(tagDaoImpl.getTagsByKeys(keys));
 86        assertEquals(tag.getKey(),
 87                        tagDaoImpl.getTagsByKeys(keys).get(0).getKey());
 88        assertEquals(2,
 89                        tagDaoImpl.getTagsByKeys(keys).size());
 90    }
 91
 92    @Test
 93    public void getTagsForTagCloud() {
 94        Tag tag = new Tag();
 95        tag.setTitle("finance");
 96        tagDaoImpl.saveTag(tag);
 97        RetrievalInfo info = new RetrievalInfo();
 98        info.setNoOfRecords(10);
 99        List<Tag> tagList = tagDaoImpl.getTagsForTagCloud(info);
100        assertNotNull(tagList);
101    }
102
103    @Test
104    public void getTagsWithSpecificStartString() {
105        String expectedString = "ab";
106
107        Tag tag = new Tag();
108        tag.setTitle("abstract");
109        tagDaoImpl.saveTag(tag);
110
111        Tag tag2 = new Tag();
112        tag2.setTitle("bargain");
113        tagDaoImpl.saveTag(tag2);
114
115        Tag tag3 = new Tag();
116        tag3.setTitle("science");
117        tagDaoImpl.saveTag(tag3);
118
119        Tag tag4 = new Tag();
120        tag4.setTitle("agriculture");
121        tagDaoImpl.saveTag(tag4);
122
123        RetrievalInfo info = new RetrievalInfo();
124        info.setOrderType("asc");
125        info.setOrderBy("title");
126        info.setNoOfRecords(10);
127        List<Tag> listOfTags = tagDaoImpl.getTagsWithSpecificStartString(expectedString, info
128                        );
129
130        assertNotNull(listOfTags);
131
132        String actualString = listOfTags.get(0).getTitle();
133        assertTrue(actualString.startsWith(expectedString));
134    }
135
136}