package com.yonge.log.test;

import java.util.HashMap;
import java.util.Map;

import org.junit.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.junit4.SpringRunner;

import com.yonge.log.AuditLogServerApplication;
import com.yonge.toolset.log.dal.model.AuditLog;
import com.yonge.toolset.log.service.AuditLogService;
import com.yonge.toolset.mongodb.QueryInfo;
import com.yonge.toolset.utils.json.JsonUtil;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = AuditLogServerApplication.class)
public class SpringBootMongodbApplicationTests {

	@Autowired
	private AuditLogService auditLogService;
	
	@Test
	public void add() {
		AuditLog auditLog = new AuditLog();
		auditLog.setId(1l);
		auditLog.setInputParams("{'signClassId':'','mixClassId':'','snapClassIds':'','highClassId':'','temporaryCourseFee':null,'studentRegistration':{'name':'上低08','gender':1,'birthdate':'2020-12-21','parentsName':'上低08家长','parentsPhone':'18881230038','currentGrade':'一年级','currentClass':'A','subjectId':2,'musicGroupId':'20123009470100001'},'studentPaymentOrderDetails':[]}");
		auditLog.setInterfaceUrl("api-web/studentRegistration/insertStudent");
		auditLog.setOperateName("进行中加学员");
		auditLog.setUserIp("127.0.0.1");
		auditLog.setUsername("xxx");
		auditLogService.insert(auditLog);
		
		System.out.println("*********insert*********");
		System.out.println(JsonUtil.toJSONString(auditLog));
		System.out.println("******************");
	}

	@Test
	public void query() {
		System.out.println("********query**********");
		System.out.println(JsonUtil.toJSONString(auditLogService.get("1")));
		System.out.println("******************");
	}

	@Test
	public void update() {
		AuditLog auditLog = auditLogService.get("1");
		auditLog.setInputParams("测试输入参数222");
		System.out.println("********update**********");
		System.out.println(JsonUtil.toJSONString(auditLogService.update("1", auditLog)));
		System.out.println("******************");
	}

	@Test
	public void delete() {
		System.out.println("********delete**********");
		System.out.println(JsonUtil.toJSONString(auditLogService.delete("1")));
		System.out.println("******************");
	}

	@Test
	public void findAll() {
		System.out.println("********findAll**********");
		System.out.println(JsonUtil.toJSONString(auditLogService.findAll(null)));
		System.out.println("******************");
	}

	@Test
	public void queryCount() {
		System.out.println("********queryCount**********");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", 1);
		System.out.println(JsonUtil.toJSONString(auditLogService.queryCount(params)));
		System.out.println("******************");
	}

	@Test
	public void queryPage() {
		System.out.println("********queryPage**********");
		QueryInfo queryInfo = new QueryInfo();
		System.out.println(JsonUtil.toJSONString(auditLogService.queryPage(queryInfo)));
		System.out.println("******************");
	}
}
