Package org.uned.agonzalo16.bitacora.dao

Source Code of org.uned.agonzalo16.bitacora.dao.BlogDaoTest

package org.uned.agonzalo16.bitacora.dao;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.util.Date;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.uned.agonzalo16.bitacora.BaseDataStoreTest;
import org.uned.agonzalo16.bitacora.domain.Blog;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext-test.xml")
public class BlogDaoTest extends BaseDataStoreTest {

  @Autowired
  private BlogDao blogDao;

  @Test
  public void testList() {
    for (int i = 0; i < 100; i++) {
      Blog blog = new Blog();
      blog.setName("blog " + i);
      blog.setCreationDate(new Date());
      blog.setDescription("description " + i);

      blogDao.merge(blog);
    }

    List<Blog> allBlogs = blogDao.findAll();

    assertEquals("100 blogs in datastore", allBlogs.size(), 100);
  }

  @Test
  public void testSave() {
    Blog blog = new Blog();
    blog.setName("blog 1");
    blog.setCreationDate(new Date());
    blog.setDescription("description 1");

    Blog newBlog = blogDao.merge(blog);

    assertEquals("Id must be the same", blog.getId(), newBlog.getId());
  }

  @Test
  public void testDelete() {
    Blog blog = new Blog();
    blog.setName("blog 1");
    blog.setCreationDate(new Date());
    blog.setDescription("description 1");

    Blog newBlog = blogDao.merge(blog);

    blogDao.delete(newBlog.getId());

    assertNull("The entity has been deleted", blogDao.get(newBlog.getId()));
  }

}
TOP

Related Classes of org.uned.agonzalo16.bitacora.dao.BlogDaoTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.