Back to Repositories

Testing XxlJobLogGlue DAO Operations in XXL-JOB

This test suite validates the data access operations for job glue logs in XXL-JOB’s admin module. It encompasses CRUD operations for the XxlJobLogGlue entity, ensuring proper persistence and retrieval of glue-related job execution data.

Test Coverage Overview

The test suite provides comprehensive coverage of XxlJobLogGlueDao operations.

Key functionality tested includes:
  • Saving new glue log entries
  • Retrieving glue logs by job ID
  • Removing old glue log entries
  • Deleting glue logs by job ID
The test verifies both positive scenarios and data manipulation operations.

Implementation Analysis

The testing approach utilizes Spring Boot’s test framework with JUnit Jupiter. The implementation follows a straightforward unit test pattern with direct DAO injection.

Technical patterns include:
  • Spring Boot test context configuration
  • Resource injection for DAO access
  • Sequential operation verification
  • Date handling for timestamps

Technical Details

Testing infrastructure includes:
  • JUnit Jupiter test framework
  • Spring Boot Test context with random port configuration
  • Jakarta Annotation for resource injection
  • XxlJobLogGlueDao for data access operations
  • In-memory database for test execution

Best Practices Demonstrated

The test demonstrates several testing best practices for DAO layer validation.

Notable practices include:
  • Isolated test context using Spring Boot test configuration
  • Complete CRUD cycle testing
  • Proper resource management and injection
  • Clear test method organization
  • Comprehensive entity attribute coverage

xuxueli/xxl-job

xxl-job-admin/src/test/java/com/xxl/job/admin/dao/XxlJobLogGlueDaoTest.java

            
package com.xxl.job.admin.dao;

import com.xxl.job.admin.core.model.XxlJobLogGlue;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Date;
import java.util.List;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class XxlJobLogGlueDaoTest {

    @Resource
    private XxlJobLogGlueDao xxlJobLogGlueDao;

    @Test
    public void test(){
        XxlJobLogGlue logGlue = new XxlJobLogGlue();
        logGlue.setJobId(1);
        logGlue.setGlueType("1");
        logGlue.setGlueSource("1");
        logGlue.setGlueRemark("1");

        logGlue.setAddTime(new Date());
        logGlue.setUpdateTime(new Date());
        int ret = xxlJobLogGlueDao.save(logGlue);

        List<XxlJobLogGlue> list = xxlJobLogGlueDao.findByJobId(1);

        int ret2 = xxlJobLogGlueDao.removeOld(1, 1);

        int ret3 =xxlJobLogGlueDao.deleteByJobId(1);
    }

}