package quant.rich.emoney;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;
import quant.rich.emoney.service.postgre.StockStrategyService;

/**
 * 测试从本地读取包含 stock strategy 的 json, 转换为列表并更新到数据库中
 */
@SpringBootTest
@ContextConfiguration(classes = EmoneyAutoApplication.class)
@RunWith(SpringJUnit4ClassRunner.class)
@Slf4j
public class StockStrategyUpdateTest {
    
    @Autowired
    ObjectMapper objectMapper;
    
    @Autowired
    StockStrategyService stockStrategyService;

    @Test
    void test() throws IOException, InterruptedException, ExecutionException {
        
        // 首先从 tushare-data-service feign 客户端取数据
        
        
        String str = Files.readString(Path.of("C:\\Users\\Administrator\\Desktop\\stock_strategy.json"));
        JsonNode node = objectMapper.readTree(str);
        Future<Boolean> future = stockStrategyService.updateByQueryResponseAsync(node);
        future.get();
    }
}
