Newer
Older
newfiber-termite / newfiber-termites-business / newfiber-termites-biz-package / src / test / java / ServiceTest.java
@xiongkai xiongkai 14 hours ago 1 KB OTA升级
import com.newfiber.termite.NewfiberTermiteBusinessApplication;
import com.newfiber.termite.domain.DeviceInfo;
import com.newfiber.termite.domain.request.deviceInfo.DeviceInfoQueryRequest;
import com.newfiber.termite.service.IDeviceInfoService;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@Slf4j
@SpringBootTest(classes = NewfiberTermiteBusinessApplication.class)
@RunWith(SpringRunner.class)
public class ServiceTest {

    @Resource
    private MongoTemplate mongoTemplate;

    @Resource
    private IDeviceInfoService deviceInfoService;

    @Test
    public void mongoDelete(){
        Set<String> collections = mongoTemplate.getCollectionNames();
        List<DeviceInfo> deviceInfoList = deviceInfoService.selectList(new DeviceInfoQueryRequest());

        Set<String> snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toSet());
        for(String collection : collections){
            if(!snList.contains(collection)){
                log.info("集合【{}】不存在", collection);
//                mongoTemplate.dropCollection(collection);
            }
        }
    }
}