package com.sengled.rest.data.dynamodb.test;

import com.sengled.rest.data.dynamodb.domain.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.sengled.rest.data.dynamodb.repository.UserRepository;
import com.sengled.rest.data.dynamodb.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * @version 1.0
 * @Description
 * @Author：andy
 * @CreateDate：2016/5/17
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringDataDynamoDemoConfig.class)
public class UserRepositoryIntegrationTest  {

    @Autowired UserRepository userRepository;

    @Test
    public void sampleTestCase() {
        List<User> result = userRepository.findByAccount("test1@sengled.com");
        System.out.println(result.get(0));
    }

    @Test
    public void sampleTest1Case() {
        List<User> result = userRepository.queryById(1);
        System.out.println(result.get(0));
    }

    @Test
    public void save(){
        String s="{\n" +
                "  \"id\" : 101,\n" +
                "  \"account\" : \"test101@sengled.com\",\n" +
                "  \"properties\" : {\n" +
                "    \"sex\" : \"m\",\n" +
                "    \"password\" : \"1010101\",\n" +
                "    \"telphone\" : \"644453071\"\n" +
                "  },\n" +
                "  \"friends\" : [ \"3\", \"2\", \"1\", \"0\", \"7\", \"6\", \"5\", \"4\" ]\n" +
                "}";
        User user= JsonUtil.getInstance().fromJson(s,User.class);
        userRepository.save(user);
    }
}
