概述
package com.zhqt;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.htsc.ocrm.core.service.CustService;
import com.htsc.ocrm.core.service.IHallServReqService;
import com.htsc.ocrm.core.service.cust.dto.AddMktgServeRecordDTO;
import com.htsc.custserv.ihall.app.core.dto.CustServReqDTO;
import com.zhqt.consumer.dao.CustomerMessageMapper;
import com.zhqt.consumer.domain.CustomerMessage;
import com.zhqt.controller.CustomerController;
import com.zhqt.consumer.domain.SingleResponse;
import com.zhqt.provider.service.impl.CameraServiceImpl;
import com.zhqt.provider.service.impl.InternalServiceImpl;
import com.zhqt.provider.service.impl.RobotServiceImpl;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class CustomerControllerTest {
@Autowired
private CustomerController customerController;
@Mock
private RestTemplate restTemplate;
@Mock
private IHallServReqService iHallServReqService;
@Mock
private CustomerMessageMapper customerMessageMapper;
@Mock
private CustService custService;
@InjectMocks
@Autowired
private RobotServiceImpl robotService;
@InjectMocks
@Autowired
private InternalServiceImpl internalService;
@InjectMocks
@Autowired
private CameraServiceImpl cameraService;
@Value("${camera.url}")
private String cameraUrl;
@Value("${ihall.url}")
private String ihallUrl;
@Value("${cust.url}")
private String custUrl;
//初始化Mock
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
iniMapper();
}
//模拟Mapper结果
public void iniMapper(){
CustomerMessage a = new CustomerMessage();
a.setCustomer_name_ori("王海啸");
a.setCustomer_name("王");
a.setAssset(1.2);
a.setBuss_hall_est_id("1");
a.setBuss_hall_est_name("2");
a.setBuss_hall_svr_Id("1");
a.setBuss_hall_svr_name("1");
a.setCustomer_gender(1);
a.setCustomer_id("1");
a.setUpdate_time(new Date());
CustomerMessage b = new CustomerMessage();
b.setCustomer_name_ori("公孙海啸");
b.setCustomer_name("公孙");
List<CustomerMessage> customerMessages = new ArrayList<>();
customerMessages.add(a);
customerMessages.add(b);
List<String> dfn = new ArrayList<>();
dfn.add("王");
dfn.add("公孙");
Mockito.when( customerMessageMapper.getDoubleFamilyName()).thenReturn(dfn);
Mockito.when(customerMessageMapper.getCustomerNameOri()).thenReturn(customerMessages);
}
//获取大图base64
public String getBigPicture() throws Exception {
String path = new File(".").getAbsolutePath();
path = path.replace(".","")+"src/test/base64.txt";
FileReader fr = null;
BufferedReader br = null;
StringBuffer sb = new StringBuffer();
try{
fr = new FileReader(path);
br = new BufferedReader(fr);
String data = null;
while((data=br.readLine())!=null){
sb.append(data);
}
}catch (IOException e){
e.getMessage();
}finally {
fr.close();
br.close();
}
return sb.toString();
}
@Test()
public void testGetCustomerPhotoException() throws Exception {
//4004 parameter error 模拟入参
JSONObject jsonParameter = new JSONObject() {{
put("faceId",null);
}};
SingleResponse singleRs = customerController.getCustomerPhoto(jsonParameter);
Assert.assertEquals("4004",singleRs.getErrCode());
}
@Test()
public void testIsVipException() throws Exception {
//4003 access denied 模拟入参
String fakeToken ="34a5382e";
JSONObject jsonParameter = new JSONObject() {{
put("token", fakeToken);
}};
SingleResponse singleRs = customerController.isVip(jsonParameter);
Assert.assertEquals("4003",singleRs.getErrCode());
//4002 bad picture type 模拟入参
String badPicture = "data:image/gif;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";
String token ="34a5382e-0e7e-4d5a-842d-e2162cd85e7c";
jsonParameter = new JSONObject() {{
put("picture", badPicture);
put("token", token);
}};
singleRs = customerController.isVip(jsonParameter);
Assert.assertEquals("4002",singleRs.getErrCode());
//4001 picture over size 模拟入参
String bigPicture = getBigPicture();
String pictureName = "picName";
float similarityMin = 1.5f;
String businessId = "bussId";
Integer customerType = 1;
jsonParameter = new JSONObject() {{
put("picture",bigPicture);
put("pictureName", pictureName);
put("similarityMin", similarityMin);
put("businessId",businessId);
put("customerType", customerType);
put("token", token);
}};
singleRs = customerController.isVip(jsonParameter);
Assert.assertEquals("4001",singleRs.getErrCode());
//4004 parameter error 模拟入参
String picture = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";
jsonParameter = new JSONObject() {{
put("picture",picture);
put("pictureName", pictureName);
put("similarityMin", similarityMin);
put("businessId",businessId);
put("customerType", customerType);
put("token", token);
}};
singleRs = customerController.isVip(jsonParameter);
Assert.assertEquals("4004",singleRs.getErrCode());
}
@Test()
public void testTimeoutWarnException() throws Exception {
//4003 access denied 模拟入参
String fakeToken ="34a5382e";
JSONObject jsonParameter = new JSONObject() {{
put("token", fakeToken);
}};
SingleResponse singleRs = customerController.timeoutWarn(jsonParameter);
Assert.assertEquals("4003",singleRs.getErrCode());
//4002 bad picture type 模拟入参
String badPicture = "data:image/gif;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";
String token ="34a5382e-0e7e-4d5a-842d-e2162cd85e7c";
jsonParameter = new JSONObject() {{
put("picture", badPicture);
put("token", token);
}};
singleRs = customerController.timeoutWarn(jsonParameter);
Assert.assertEquals("4002",singleRs.getErrCode());
//4001 picture over size 模拟入参
String bigPicture = getBigPicture();
jsonParameter = new JSONObject() {{
put("picture",bigPicture);
put("token", token);
}};
singleRs = customerController.timeoutWarn(jsonParameter);
Assert.assertEquals("4001",singleRs.getErrCode());
//4004 parameter error 模拟入参
String picture = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";
jsonParameter = new JSONObject() {{
put("picture",picture);
put("token", token);
}};
singleRs = customerController.timeoutWarn(jsonParameter);
Assert.assertEquals("4004",singleRs.getErrCode());
//5000 throw exception 模拟入参
String deviceBussHallId = "ZZ010000"; // 营业厅ID
String robotId = "02"; // 机器人ID
String serviceTime = "20180918"; // 服务时间
String pushTime = "20180918"; // 推送时间
String responseString ="";
Mockito.when(restTemplate.postForObject(Mockito.eq(ihallUrl), Mockito.any(CustServReqDTO.class), Mockito.eq(String.class))).thenReturn(responseString);
jsonParameter = new JSONObject() {{
put("picture",picture);
put("deviceBussHallId", deviceBussHallId);
put("robotId", robotId);
put("serviceTime",serviceTime);
put("pushTime", pushTime);
put("token", token);
}};
//验证结果
singleRs = customerController.timeoutWarn(jsonParameter);
Assert.assertEquals("5000",singleRs.getErrCode());
}
@Test()
public void testInfoPushException() throws Exception {
//4003 access denied 模拟入参
String fakeToken ="34a5382e";
JSONObject jsonParameter = new JSONObject() {{
put("token", fakeToken);
}};
SingleResponse singleRs = customerController.infoPush(jsonParameter);
Assert.assertEquals("4003",singleRs.getErrCode());
//4002 bad picture type 模拟入参
String badPicture = "data:image/gif;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";
String token ="34a5382e-0e7e-4d5a-842d-e2162cd85e7c";
jsonParameter = new JSONObject() {{
put("picture", badPicture);
put("token", token);
}};
singleRs = customerController.infoPush(jsonParameter);
Assert.assertEquals("4002",singleRs.getErrCode());
//4001 picture over size 模拟入参
String bigPicture = getBigPicture();
jsonParameter = new JSONObject() {{
put("picture",bigPicture);
put("pictureOri",bigPicture);
put("token", token);
}};
singleRs = customerController.infoPush(jsonParameter);
Assert.assertEquals("4001",singleRs.getErrCode());
//4004 parameter error 模拟入参
String picture = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";
jsonParameter = new JSONObject() {{
put("picture",picture);
put("pictureOri",picture);
put("token", token);
}};
singleRs = customerController.infoPush(jsonParameter);
Assert.assertEquals("4004",singleRs.getErrCode());
//4005 error interface 模拟入
String pictureOri = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7"; // 人脸库底图
Integer customerType = 2; // 客户类型
String faceId = "1"; // 人脸ID
String customerNo = ""; // 客户号(8个或12个数字)
String deviceBussHallId = "ZZ010000"; // 营业厅ID
Integer visits = 2; // 到访次数
String visitTime = "2018-09-18 10:22:11"; // 到访时间
String responseString1 = "";
String responseString2 = "response2";
Mockito.when(restTemplate.postForObject(Mockito.eq(ihallUrl), Mockito.any(CustServReqDTO.class),Mockito.eq(String.class))).thenReturn(responseString1);
Mockito.when(restTemplate.postForObject(Mockito.eq(custUrl), Mockito.any(AddMktgServeRecordDTO.class), Mockito.eq(String.class))).thenReturn(responseString2);
jsonParameter = new JSONObject() {{
put("picture",picture);
put("pictureOri",pictureOri);
put("customerType",customerType);
put("faceId",faceId);
put("customerNo", customerNo);
put("deviceBussHallId", deviceBussHallId);
put("visits",visits);
put("visitTime", visitTime);
put("token", token);
}};
//验证结果
singleRs = customerController.infoPush(jsonParameter);
Assert.assertEquals("4005",singleRs.getErrCode());
}
@Test()
public void testGetSimilarityException() throws Exception {
//4002 bad picture type 模拟入参
String badPicture = "data:image/gif;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";
String token ="34a5382e-0e7e-4d5a-842d-e2162cd85e7c";
JSONObject jsonParameter = new JSONObject() {{
put("picture1", badPicture);
put("picture2", badPicture);
}};
SingleResponse singleRs = customerController.getSimilarity(jsonParameter);
Assert.assertEquals("4002",singleRs.getErrCode());
//4001 picture over size 模拟入参
String bigPicture = getBigPicture();
jsonParameter = new JSONObject() {{
put("picture1",bigPicture);
put("picture2",bigPicture);
}};
singleRs = customerController.getSimilarity(jsonParameter);
Assert.assertEquals("4001",singleRs.getErrCode());
//4004 parameter error 模拟入参
String picture = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";
jsonParameter = new JSONObject() {{
put("picture1",picture);
put("picture2",picture);
}};
singleRs = customerController.getSimilarity(jsonParameter);
Assert.assertEquals("4004",singleRs.getErrCode());
}
/**
* 根据人脸id或客户号查询客户在人脸库的照片
* 入参:人脸id,客户号,照片类型(大,小)像素
* 出参:照片base64*/
@Test
public void testGetCustomerPhoto() throws Exception {
JSONObject data = new JSONObject() {{
put("baseFaceUrl", "face.com");
put("baseFacePicture", "face.com");
put("newestFaceUrl", "face.com");
put("newestFacePicture", "face.com");
}};
//模拟结果数据
String dataRs = data.toJSONString();
Map<String, Object> requestParam = new HashMap<>();
requestParam.put("customerNo", "12345678");
Mockito.when(restTemplate.postForObject(cameraUrl + "/vip/face/query", requestParam,
String.class
)).thenReturn(dataRs);
Map<String, Object> requestParam1 = new HashMap<>();
requestParam1.put("faceId", "1");
Mockito.when(restTemplate.postForObject(cameraUrl + "/vip/face/query", requestParam1,
String.class
)).thenReturn(dataRs);
//模拟入参
String faceId = "1";
int type = 1;
JSONObject jsonParameter = new JSONObject() {{
put("faceId",faceId);
put("type", type);
}};
//验证结果
SingleResponse singleRs = customerController.getCustomerPhoto(jsonParameter);
JSONObject json = (JSONObject)singleRs.getData();
Assert.assertEquals("face.com",json.getString("baseFaceUrl"));
Assert.assertEquals("face.com",json.getString("baseFacePicture"));
Assert.assertEquals("face.com",json.getString("newestFaceUrl"));
Assert.assertEquals("face.com",json.getString("newestFacePicture"));
//模拟入参
String customerNo = "12345678";
JSONObject jsonParameter1 = new JSONObject() {{
put("faceId",faceId);
put("customerNo", customerNo);
put("type", type);
}};
// String jsonParameter1 = json1.toJSONString();
//验证结果
SingleResponse singleRs1 = customerController.getCustomerPhoto(jsonParameter1);
json = (JSONObject)singleRs1.getData();
Assert.assertEquals("face.com",json.getString("baseFaceUrl"));
Assert.assertEquals("face.com",json.getString("baseFacePicture"));
Assert.assertEquals("face.com",json.getString("newestFaceUrl"));
Assert.assertEquals("face.com",json.getString("newestFacePicture"));
}
/**
* 为机器人提供识别高端客户能力
* 入参:照片
* 出参:客户实体*/
@Test
public void testIsVip() throws Exception {
String picture = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";
//模拟isVip结果数据
JSONObject json = new JSONObject();
JSONObject dataObj = new JSONObject();
JSONArray ja = new JSONArray();
ja.add(new JSONObject() {{
put("name", "王海啸");
}});
ja.add(new JSONObject() {{
put("name", "公孙海啸");
}});
dataObj.put("data", ja);
dataObj.put("total",2);
json.put("searchResult", dataObj);
String jsonRs = json.toJSONString();
Mockito.when( restTemplate.postForObject(cameraUrl + "/vip/image/analysis/searchhuman", new HashMap() {{
put("picture", picture);
put("pictureName", "picName");
put("similarityMin", 0.5f);
put("businessId", "bussId");
put("customerType", 1);
}},
String.class
)).thenReturn(jsonRs);
//模拟入参
String pictureName = "picName";
float similarityMin = 0.5f;
String businessId = "bussId";
Integer customerType = 1;
String token ="34a5382e-0e7e-4d5a-842d-e2162cd85e7c";
JSONObject jsonParameter = new JSONObject() {{
put("picture",picture);
put("pictureName", pictureName);
put("similarityMin", similarityMin);
put("businessId",businessId);
put("customerType", customerType);
put("token", token);
}};
//验证结果
SingleResponse singleRs = customerController.isVip(jsonParameter);
String jsonStr = (String)singleRs.getData();
JSONArray jsonArr = JSONArray.parseArray(jsonStr);
Assert.assertEquals("王",""+jsonArr.getJSONObject(0).getString("name"));
Assert.assertEquals("公孙",""+jsonArr.getJSONObject(1).getString("name"));
}
/**
* 当机器人服务超时后,调用该接口
* 入参:营业厅ID,机器人ID,客户号,人脸ID,推送时间,服务时间
* 出参:ACK*/
@Test
public void testTimeoutWarn() throws Exception {
String picture = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";; // 客户照片
String deviceBussHallId = "ZZ010000"; // 营业厅ID
String robotId = "02"; // 机器人ID
String serviceTime = "20180918"; // 服务时间
String pushTime = "20180918"; // 推送时间
String token = "34a5382e-0e7e-4d5a-842d-e2162cd85e7c"; // 校验码
String responseString ="链接超时";
Mockito.when(restTemplate.postForObject(Mockito.eq(ihallUrl), Mockito.any(CustServReqDTO.class),Mockito.eq(String.class))).thenReturn(responseString);
JSONObject jsonParameter = new JSONObject() {{
put("picture",picture);
put("deviceBussHallId", deviceBussHallId);
put("robotId", robotId);
put("serviceTime",serviceTime);
put("pushTime", pushTime);
put("token", token);
}};
//验证结果
SingleResponse singleRs = customerController.timeoutWarn(jsonParameter);
Assert.assertEquals("1",singleRs.getErrCode());
}
/**
* 将高端客户与再访客户的来访推送给PAD
* 入参:现场实时照片,客户号,人脸ID,客户类型,营业厅ID,到访次数
* 出参:ACK*/
@Test
public void testInfoPush() throws Exception {
//模拟入参
String picture = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7"; // 客户照片
String pictureOri = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7"; // 人脸库底图
Integer customerType = 1; // 客户类型
String faceId = "1"; // 人脸ID
String customerNo = "12345678"; // 客户号(8个或12个数字)
String deviceBussHallId = "ZZ010000"; // 营业厅ID
Integer visits = 2; // 到访次数
String visitTime = "2018-09-18 10:22:11"; // 到访时间
String token = "34a5382e-0e7e-4d5a-842d-e2162cd85e7c"; // 校验码
String responseString1 = "response1";
String responseString2 = "response2";
Mockito.when(restTemplate.postForObject(Mockito.eq(ihallUrl), Mockito.any(CustServReqDTO.class),Mockito.eq(String.class))).thenReturn(responseString1);
Mockito.when(restTemplate.postForObject(Mockito.eq(custUrl), Mockito.any(AddMktgServeRecordDTO.class), Mockito.eq(String.class))).thenReturn(responseString2);
JSONObject jsonParameter = new JSONObject() {{
put("picture",picture);
put("pictureOri",pictureOri);
put("customerType",customerType);
put("faceId",faceId);
put("customerNo", customerNo);
put("deviceBussHallId", deviceBussHallId);
put("visits",visits);
put("visitTime", visitTime);
put("token", token);
}};
//验证结果
SingleResponse singleRs = customerController.infoPush(jsonParameter);
String jsonStr = (String)singleRs.getData();
Assert.assertEquals("1",singleRs.getErrCode());
}
/**
* 得到照片特征值
* 入参:照片
* 出参:特征值*/
@Test
public void testGetSimilarity() throws Exception {
//模拟入参
String picture1 = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7"; // 比对图1
String picture2 = "data:image/png;base64,R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7"; // 客户照片; // 比对图2
String pictureName1 = "gjw1"; // 比对图名称1
String pictureName2 = "gjw2"; // 比对图名称2
//模拟 getSimilarity结果数据
JSONObject json = new JSONObject() {{
put("similarity","1");
put("errorCode", "001");
put("errorMsg", "error");
}};
String jsonRs = json.toJSONString();
Mockito.when( restTemplate.postForObject(cameraUrl + "/vip/image/analysis/compare", new HashMap() {{
put("srcImage",picture1);
put("srcImageName", pictureName1);
put("destImage", picture2);
put("destImageName", pictureName2);
}},
String.class
)).thenReturn(jsonRs);
JSONObject jsonParameter = new JSONObject() {{
put("picture1",picture1);
put("picture2",picture2);
put("pictureName1",pictureName1);
put("pictureName2",pictureName2);
}};
//验证结果
SingleResponse singleRs = customerController.getSimilarity(jsonParameter);
JSONObject rs = (JSONObject )singleRs.getData();
Assert.assertEquals("1",rs.getString("similarity"));
}
@Test
public void testQAability() throws Exception {
new Expectations() {
{
robotService.QAability("read","123","java");
returns("answer","answer","answer");
}
};
String question = "read";
String userId = "123";
String platform = "java";
String QAability = robotService.QAability(question,userId,platform);
Assert.assertEquals("answer",QAability);
}
//
@Test
public void testPictureTranscoding() throws Exception {
Customer customer = new Customer();
String path = new File(".").getAbsolutePath();
path = path.replace(".","")+"src/test/test.gif";
String base64 = cameraService1.PictureTranscoding(path);
base64 = base64.replaceAll("r|n", "");
System.out.print(base64);
String rs ="R0lGODlhdQAmAKIAAOYyL+rU4llg6Jmd8e92dCky4eEGAv///yH5BAAAAAAALAAAAAB1ACYAAAP/eLrc/jC2IEoZMATJu/9gyFVWIUyksIls677LUJbrEcxWDe98f+CWk4I0w/iOSNANKJQBC8mo9LEEDp8F3XR7rOIU2Cx3jHwKsUKyWqRhEEvGN3xN91BoCq8l9tTW/244Rk4mOkBGgIl8VjF+d4V5A5KKf3IWiCCEOZRraGxPnGqeIZpzoVyjDBptDpYmp1yumI9BWq5QUQS6fn+lm3lYmLdSBsW8xcjJBgAABLwfAMhXRQt6ODWuJ8rb3AYK0d3h4OHIBC7jC0TCYb/ZB+Th3/Dc4/PmLOgSvkwK+xjMAAEmCwhQnrc8rFSxGkiwnoFnEnTp0mdqlJw0DgIggwgu/08xABM+KkhGJdm9JJqMhGkyQIAATA3HxVwATuO8jyQfECiXJyYzZwzyOSilcqWEmzkP1ES6LGmDcStshjspNJAgMOwwNmBajGZXGyJVhU22quxOaR7hrahqQ52DC1jh/nj1AG0Eux3BLgu59x3SkxHO9mVLhJfcirUc2IWA96vUbvf+QkNbldCgIGCKHi6h1e/Bu1+VOiYHYAVTwBHyCfWyocoZzZovbf3ok1njzx/IltUg+GG13twMfta0gdDruLH3MOD6uaPDcI8hCAZp4/k24elmtOacGXlcPAuYe/VmnVt0ncioTyeYU+ibQRWOHyCRXEz40BDyivYWYBzQAIbTbeBUNTIZRF1QlNlVimGdfffLSPg9oJ9+vVV4H23smWSgFqrZZc0AWiTWACMXcjAhfgAqgxpXKwDXDXbZsSPjVcth6NNtZj3nzCpM1dDfPDACM+OQ9l2I1HiPlfNceentMoGLygQp5Eq3aKfYaUgOdBIB9RyYSEsmvASiFgG0RMRLEK2RAAA7";
Assert.assertTrue("a",base64.equals(rs));
}
//
//
@Test
//
public void testCustomerEntity() throws Exception {
//
Customer customer = new Customer();
//
customer.setCustomerType(1);
//
customer.setPicture("1");
//
customer.setBussinessId("1");
//
customer.setName("1");
//
customer.setFeatures("1");
//
customer.setBussHallSvrId("1");
//
customer.setBussHallSvrCity("1");
//
customer.setFaceId("1");
//
customer.setType(1);
//
customer.setCustomerNo("1");
//
customer.setCustomerId("1");
//
customer.setGender(1);
//
customer.getBussHallSvrCity();
//
customer.getBussHallSvrId();
//
customer.getBussinessId();
//
customer.getCustomerId();
//
customer.getCustomerNo();
//
customer.getCustomerType();
//
customer.getFaceId();
//
customer.getFeatures();
//
customer.getName();
//
customer.getType();
//
customer.getGender();
//
customer.getPicture();
//
}
}
最后
以上就是老实楼房为你收集整理的Mockito跨层Mock的全部内容,希望文章能够帮你解决Mockito跨层Mock所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复