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

Java tutorial

Introduction

Here is the source code for cz.muni.fi.editor.database.test.CmisDAOTest.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.
*/
package cz.muni.fi.editor.database.test;

import cz.muni.fi.editor.database.dao.CmisObjectDAO;
import cz.muni.fi.editor.database.domain.CmisObjectDB;
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;

/**
 * Created by Dominik Szalai - emptulik at gmail.com on 10/24/16.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@DAOTest
@Log4j2
public class CmisDAOTest extends AbstractDAOTest {
    @BeforeClass
    public static void setupClass() {
        checkMethods(CmisDAOTest.class, CmisObjectDAO.class);
    }

    @Test
    public void create() {
        CmisObjectDB cmis = new CmisObjectDB();
        cmis.setObjectID("L3Jvb3Qvc2VjcmV0L2hvZG9yLw==");

        cmisObjectDAO.create(cmis);

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

    @Test
    public void update() {
        CmisObjectDB cmis = cmisObjectDAO.getById(2L);
        cmis.setObjectID("1234");

        cmisObjectDAO.update(cmis);

        Assert.assertEquals("1234", cmisObjectDAO.getById(2L).getObjectID());
    }

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

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

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

    @Test
    public void getAll() {
        Assert.assertEquals(6, cmisObjectDAO.getAll().size());
    }

    @Test
    public void getByCmisID() {
        CmisObjectDB cmisObjectDB = cmisObjectDAO.getByCmisID("68545bea2e2fca1bc091f1161722a43d").get();

        Assert.assertEquals("68545bea2e2fca1bc091f1161722a43d", cmisObjectDB.getObjectID());
        Assert.assertEquals(Long.valueOf(2L), cmisObjectDB.getId());

        Assert.assertFalse(cmisObjectDAO.getByCmisID("hodor").isPresent());
    }

    @Test
    public void deleteByCmisID() {
        cmisObjectDAO.deleteByCmisID("f6d482fdf1799a11ee1c2b3e1c55f9dc");

        Assert.assertFalse(cmisObjectDAO.getByCmisID("f6d482fdf1799a11ee1c2b3e1c55f9dc").isPresent());

        //for covareage
        cmisObjectDAO.deleteByCmisID("f6d482fdf1799a11ee1c2b3e1c55f9dc");
    }

    @Test
    public void getClassType() {
        Assert.assertEquals(CmisObjectDB.class, cmisObjectDAO.getClassType());
    }
}