Commit cb7fd9c5 authored by 贷前—徐菲's avatar 贷前—徐菲

单元测试

parent 2e676c4e
......@@ -17,9 +17,9 @@ public interface IQuantgroupCaptchaService {
/**
* 校验QG验证码
* @param key
* @param code
* @param captchaId
* @param captchaValue
* @return
*/
boolean validQuantgroupCaptcha(String key, String code);
boolean validQuantgroupCaptcha(String captchaId, String captchaValue);
}
......@@ -53,14 +53,14 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService {
}
@Override
public boolean validQuantgroupCaptcha(String key, String code) {
public boolean validQuantgroupCaptcha(String captchaId, String captchaValue) {
boolean validCaptcha = false;
if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(code)) {
if (StringUtils.isNotBlank(captchaId) && StringUtils.isNotBlank(captchaValue)) {
// 验证码校验(忽略用户输入的大小写)
try {
validCaptcha = Boolean.valueOf(imageCaptchaService.validateResponseForID(Constants.IMAGE_CAPTCHA_KEY + key, code.toLowerCase()));
validCaptcha = imageCaptchaService.validateResponseForID(Constants.IMAGE_CAPTCHA_KEY + captchaId, captchaValue.toLowerCase());
} catch (CaptchaServiceException e) {
log.error("校验QG图形验证码:key:{}, code:{}", key, code, e);
log.error("校验QG图形验证码:key:{}, code:{}", captchaId, captchaValue, e);
}
}
return validCaptcha;
......
package demo;
import cn.quantgroup.xyqb.Bootstrap;
import cn.quantgroup.xyqb.model.ClientType;
import cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService;
import cn.quantgroup.xyqb.util.PasswordUtil;
import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Bootstrap.class)
@ContextConfiguration(initializers = ApolloPropertySourceInitializer.class)
public class GeetestCaptchaServiceTest {
@Resource
private IGeetestCaptchaService geetestCaptchaService;
@Test
public void testFetchGeetestCaptcha(){
Assert.assertNotEquals(null,geetestCaptchaService.fetchGeetestCaptcha(PasswordUtil.MD5("18010043006"),"127.0.0.1", ClientType.APP));
}
@Test
public void testValidGeetestCaptcha(){
String challenge = "d6e965e06b187c0a01276834d2ff00e6";
String validate = "validate";
String seccode = "seccode";
Assert.assertEquals(true,
geetestCaptchaService.validGeetestCaptcha(ClientType.APP,"127.0.0.1", PasswordUtil.MD5("18010043006"),challenge,validate,seccode));
}
}
package demo;
import cn.quantgroup.xyqb.Bootstrap;
import cn.quantgroup.xyqb.service.captcha.IQuantgroupCaptchaService;
import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.Locale;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Bootstrap.class)
@ContextConfiguration(initializers = ApolloPropertySourceInitializer.class)
public class QuantgroupCaptchaServiceTest {
@Resource
private IQuantgroupCaptchaService quantgroupCaptchaService;
@Test
public void testFetchQuantgroupCaptcha(){
Locale locale = Locale.US;
Assert.assertEquals(null,quantgroupCaptchaService.fetchQuantgroupCaptcha(locale));
}
@Test
public void testValidQuantgroupCaptcha(){
String captchaId="captchaId";
String captchaValue="captchaValue";
Assert.assertEquals(true,quantgroupCaptchaService.validQuantgroupCaptcha(captchaId,captchaValue));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment