cz.muni.fi.editor.database.test.RequestDAOTest.java Source code

Java tutorial

Introduction

Here is the source code for cz.muni.fi.editor.database.test.RequestDAOTest.java

Source

/*
*Copyright  2016 Dominik Szalai (emptulik@gmail.com)
*
*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.
*/
/*
 * Copyright  2016 Dominik Szalai (emptulik@gmail.com)
 *
 * 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 cz.muni.fi.editor.database.test;

import cz.muni.fi.editor.database.dao.RequestDAO;
import cz.muni.fi.editor.database.domain.requests.Request;
import cz.muni.fi.editor.database.domain.requests.RequestState;
import cz.muni.fi.editor.database.test.helpers.AbstractDAOTest;
import cz.muni.fi.editor.database.test.helpers.DAOTest;
import lombok.extern.log4j.Log4j2;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.time.LocalDateTime;

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

    @Test
    public void create() {
        Request request = new Request();
        request.setRequestDate(LocalDateTime.now());
        request.setRequestor(userDAO.getById(8L));
        request.setAction("create");
        request.setClazz("cz.muni.fi.editor.api.dto.OrganizationDTO");
        request.setTargetId(6L);
        request.setState(RequestState.PENDING);

        requestDAO.create(request);

        Assert.assertNotNull(request.getId());
    }

    @Test
    public void update() {
        Request request = requestDAO.getById(5L);
        request.setApprover(userDAO.getById(1L));
        request.setState(RequestState.ACCEPTED);

        requestDAO.update(request);

        Request update = requestDAO.getById(5L);
        Assert.assertEquals(request.getApprover(), update.getApprover());
        Assert.assertEquals(RequestState.ACCEPTED, update.getState());
    }

    @Test
    public void delete() {
        requestDAO.delete(6L);

        Assert.assertNull(requestDAO.getById(6L));
    }

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

    @Test
    public void getAll() {
        Assert.assertEquals(8, requestDAO.getAll().size());
    }

    @Test
    public void getUnApproved() {
        Assert.assertEquals(4, requestDAO.getUnApproved().size());
    }

    @Test
    public void getClassType() {
        Assert.assertEquals(Request.class, requestDAO.getClassType());
    }
}