CacheServiceIT.java 1.42 KB
package pwc.taxtech.atms.service.impl;

import static org.assertj.core.api.Assertions.*;

import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import pwc.taxtech.atms.CommonIT;
import pwc.taxtech.atms.common.CommonUtils;
import pwc.taxtech.atms.entitiy.Cache;
import pwc.taxtech.atms.service.CacheService;

public class CacheServiceIT extends CommonIT {

    @Autowired
    private CacheService cacheService;

    @Before
    public void setUp() {
        cacheMapper.deleteByExample(null);
    }

    @Test
    public void getAllCache() {
        insertData();
        // see assertj document
        // http://joel-costigliola.github.io/assertj/assertj-core-quick-start.html
        assertThat(cacheService.getAllCache()).isNotEmpty().filteredOn(x -> x.getCacheKey().equals("cachekey1"))
                .isNotEmpty().extracting("lastModifyTime").contains("2017-10-18T14:11:01.840+08:00");

    }

    @Test
    public void shoudWork() {
        insertData();
        assertThat(cacheService.getCacheByKey("cachekey1")).isNotNull().extracting("lastModifyTime")
                .contains("2017-10-18T14:11:01.840+08:00");
    }

    private void insertData() {
        Cache record = new Cache();
        record.setID(CommonUtils.getUUID());
        record.setCacheKey("cachekey1");
        record.setLastModifyTime("2017-10-18T14:11:01.840+08:00");
        cacheMapper.insert(record);
    }
}