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

Java tutorial

Introduction

Here is the source code for org.homiefund.test.dao.InvitationDAOTest.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.InvitationDAO;
import org.homiefund.api.dao.domain.Home;
import org.homiefund.api.dao.domain.Invitation;
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 InvitationDAOTest extends AbstractDAOTest {
    @BeforeClass
    public static void setUp() {
        checkMethods(InvitationDAOTest.class, InvitationDAO.class);
    }

    @Test
    public void create() {
        Home home = homeDAO.getById(1L);
        Invitation invitation = new Invitation();
        invitation.setHash("randomhash");
        invitation.setValid(true);
        invitation.setHome(home);

        invitationDAO.create(invitation);

        Assert.assertNotNull(message(CREATE, Invitation.class), invitation.getId());
    }

    @Test
    public void update() {
        Invitation invitation = invitationDAO.getById(4L);
        invitation.setValid(false);
        invitationDAO.update(invitation);

        Assert.assertFalse(invitationDAO.getById(4L).getValid());
    }

    @Test
    public void delete() {
        invitationDAO.delete(3L);

        Assert.assertNull(invitationDAO.getById(3L));
    }

    @Test
    public void getById() {
        Assert.assertEquals(Long.valueOf(1L), invitationDAO.getById(1L).getId());
    }

    @Test
    public void getAll() {
        Assert.assertEquals(4, invitationDAO.getAll().size());
    }

    @Test
    public void getByHash() {
        Assert.assertEquals("355a78ab58b698b7b16d7f2f38e666b0",
                invitationDAO.getByHash("355a78ab58b698b7b16d7f2f38e666b0").get().getHash());
        Assert.assertFalse(invitationDAO.getByHash("huehuehuehue60").isPresent());
    }

    @Test
    public void getClassType() {
        Assert.assertEquals(Invitation.class, invitationDAO.getClassType());
    }
}