package com;

import com.sv.entity.Member;
import com.sv.entity.MemberFaceInfo;
import com.sv.mapper.MemberMapper;
import com.sv.service.api.MemberService;
import com.sv.service.common.FaceService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.NONE)
public class FaceServiceTest {

    @Resource
    private FaceService faceService;

    @Resource
    private MemberService memberService;

    @Resource
    private MemberMapper memberMapper;


    @Test
    public void test(){
        try {
            faceService.login();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void addFace() {
        try {
            faceService.login();
            faceService.show("7","","");
            faceService.show2();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void addMember() throws IOException {
        String faceUrl = "faceUrl";
        faceService.login();
        Member member = memberService.findById(521);
        Integer memberId = member.getId();
        Integer subjectId = faceService.addSubject(130,member);
        MemberFaceInfo memberFaceInfo = memberMapper.findMemberFaceInfo(memberId);
        if (memberFaceInfo == null) {
            memberFaceInfo = new MemberFaceInfo();
            memberFaceInfo.setMemberId(memberId);
            memberFaceInfo.setPlatformId(1);
        }
        memberFaceInfo.setFaceId(subjectId);
        memberFaceInfo.setFaceUrl(faceUrl);
        memberFaceInfo.setModifiedTime(new Date());
        if (memberFaceInfo.getId() == null) {
            memberMapper.insertMemberFaceInfo(memberFaceInfo);
        } else {
            memberMapper.updateMemberFaceInfo(memberFaceInfo);
        }
    }

}
