package com.nokia.service;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import com.nokia.pojo.User;
import com.nokia.pojo.UserRoleCity;

@SpringBootTest
public class UserServiceTest {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Test
    void testRedisTemplate() {
        Object value = redisTemplate.opsForValue().get("test_token_hengshui");
        System.out.println(value);
        Boolean delete = redisTemplate.delete("test_token_hengshui");
        System.out.println(delete);
        value = redisTemplate.opsForValue().get("test_token_hengshui");
        System.out.println(value);
    }

    @Test
    void testGetByLoginName() {
        User user = userService.getByLoginName("test_abc");
        System.out.println(user);
    }

    @Test
    void testAddUserRoleCity() throws FileNotFoundException, IOException {
        try (BufferedReader reader = new BufferedReader(
                new FileReader("D:\\code\\acl_tousu_all\\acl_tousu\\ignored\\abc.txt"))) {
            String line = null;
            while ((line = reader.readLine()) != null) {
                String[] strs = line.split("\t");
                UserRoleCity userRoleCity = new UserRoleCity();
                userRoleCity.setUserId(Integer.parseInt(strs[0]));
                userRoleCity.setRoleId(Integer.parseInt(strs[1]));
                userRoleCity.setCityId(Integer.parseInt(strs[2]));
                userService.addUserRoleCity(userRoleCity);
            }
        }
    }

}
