fr.mael.microrss.dao.UserDaoTest.java Source code

Java tutorial

Introduction

Here is the source code for fr.mael.microrss.dao.UserDaoTest.java

Source

/*
   Copyright  2013 Mael Le Guvel
   This work is free. You can redistribute it and/or modify it under the
   terms of the Do What The Fuck You Want To Public License, Version 2,
   as published by Sam Hocevar. See the COPYING file for more details.
*/
package fr.mael.microrss.dao;

import java.util.List;

import org.junit.Assert;
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.springframework.transaction.annotation.Transactional;

import fr.mael.microrss.domain.User;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/fr/mael/microrss/conf/application-context-test.xml" })
@Transactional
public class UserDaoTest {

    @Autowired
    private UserDao userDao;

    @Autowired
    private ArticleDao articleDao;

    @Autowired
    private CategoryDao categoryDao;

    @Autowired
    private FeedDao feedDao;

    @Autowired
    private UserArticleDao userArticleDao;

    @Test
    public void testLoadByUsername() {
        User user = userDao.loadByUsername("admin");
        Assert.assertEquals(new Integer(17), user.getId());
    }

    @Test
    public void testUserHasArticle() {
        Assert.assertTrue(userDao.userHasArticle(userDao.get(17), articleDao.get(3)));
        Assert.assertFalse(userDao.userHasArticle(userDao.get(18), articleDao.get(3)));
    }

    @Test
    public void testUserHasCategory() {
        Assert.assertTrue(userDao.userHasCategory(userDao.get(17), categoryDao.get(1)));
        Assert.assertFalse(userDao.userHasCategory(userDao.get(18), categoryDao.get(1)));

        Assert.assertTrue(userDao.userHasCategory(userDao.get(18), categoryDao.get(6)));
        Assert.assertFalse(userDao.userHasCategory(userDao.get(17), categoryDao.get(6)));
    }

    @Test
    public void testUserHasFeed() {
        Assert.assertTrue(userDao.userHasFeed(userDao.get(17), feedDao.get(2)));
        Assert.assertFalse(userDao.userHasFeed(userDao.get(18), feedDao.get(2)));
    }

    @Test
    public void testUsersForFeed() {
        List<User> users = userDao.usersForFeed(feedDao.get(3));
        Assert.assertEquals(new Integer(2), new Integer(users.size()));
    }

    @Test
    public void testUserHasUserArticle() {
        Assert.assertTrue(userDao.userHasUserArticle(userDao.get(17), 3));
        Assert.assertFalse(userDao.userHasUserArticle(userDao.get(18), 3));
    }

}