org.homiefund.test.dao.HomeDAOTest.java Source code

Java tutorial

Introduction

Here is the source code for org.homiefund.test.dao.HomeDAOTest.java

Source

/**
 * Copyright  2016 REPLACE ME OWNER (REPLACE ME YEAR)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 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.homiefund.test.dao;

import lombok.extern.log4j.Log4j2;
import org.homiefund.api.dao.HomeDAO;
import org.homiefund.api.dao.domain.Home;
import org.homiefund.api.dao.domain.User;
import org.homiefund.test.config.AbstractDAOTest;
import org.homiefund.test.config.DAOTest;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by Dominik Szalai - emptulik at gmail.com on 22.9.2016.
 */
@DAOTest
@Log4j2
@RunWith(SpringJUnit4ClassRunner.class)
public class HomeDAOTest extends AbstractDAOTest {
    @BeforeClass
    public static void setUp() {
        checkMethods(HomeDAOTest.class, HomeDAO.class);
    }

    @Test
    public void create() {
        User user = userDAO.getById(1L);
        Home h = new Home();
        h.setName("pokus");
        h.setOwner(user);
        h.setMembers(toList(user));

        homeDAO.create(h);
        Assert.assertNotNull(message(CREATE, Home.class), h.getId());
    }

    @Test
    public void update() {
        Home h = homeDAO.getById(2L);
        h.setName("test");
        homeDAO.update(h);

        Assert.assertEquals("name not changed", "test", homeDAO.getById(2L).getName());
    }

    @Test
    public void getById() {
        Assert.assertEquals("wrong id", Long.valueOf(2L), homeDAO.getById(2L).getId());
    }

    @Test
    public void delete() {
        homeDAO.delete(1L);

        Assert.assertNull(message(DELETE, Home.class), homeDAO.getById(1L));
    }

    @Test
    public void getAll() {
        Assert.assertEquals("Wrong number of homes", 4, homeDAO.getAll().size());
    }

    @Test
    public void getClassType() {
        Assert.assertEquals("Wrong class type", Home.class, homeDAO.getClassType());
    }

    @Test
    public void getHomes() {
        Assert.assertEquals(3, homeDAO.getHomes(userDAO.getById(2L)).size());
    }
}