단위 테스트 reCAPTCHA를 플러그인을 사용하여 컨트롤러의 방법 :Grails를 - 내가 단위 다음과 같은 방법을 테스트 할 것
def handleEmailSharing = { EmailSharingCommand esc ->
if (params.send) {
def recaptchaOK = true
if (!recaptchaService.verifyAnswer(session, request.getRemoteAddr(), params)) {
recaptchaOK = false
}
}
...
이 내가 그것을 위해 노력하고있는 방법입니다 :
import com.megatome.grails.RecaptchaService
class EmailSharerControllerTests extends ControllerUnitTestCase {
protected void setUp() {
controller.recaptchaService = new RecaptchaService()
}
void testHandleEmailSharingSendAndSuccess() {
mockCommandObject(EmailSharingCommand)
def emailSharingCommand = new EmailSharingCommand(from: "[email protected]",
to: " [email protected] , [email protected] ",
cc: "",
bcc:"[email protected]",
trimmedListOfToRecipients: ["[email protected]", "[email protected]"])
emailSharingCommand.validate()
}
controller.handleEmailSharing(emailSharingCommand)
그러나 나는 다음과 같은 오류가 발생합니다 : 그것은 기본적으로 내 org.codehaus.groovy.grails.commons.ConfigurationHolder
를 n이라고 말했다 있기 때문에, 이상하다
Cannot get property 'recaptcha' on null object
java.lang.NullPointerException: Cannot get property 'recaptcha' on null object
at com.megatome.grails.RecaptchaService.getRecaptchaConfig(RecaptchaService.groovy:33)
at com.megatome.grails.RecaptchaService.this$2$getRecaptchaConfig(RecaptchaService.groovy)
at com.megatome.grails.RecaptchaService$this$2$getRecaptchaConfig.callCurrent(Unknown Source)
at com.megatome.grails.RecaptchaService.isEnabled(RecaptchaService.groovy:100)
at com.megatome.grails.RecaptchaService$isEnabled.callCurrent(Unknown Source)
at com.megatome.grails.RecaptchaService.verifyAnswer(RecaptchaService.groovy:81)
at com.megatome.grails.RecaptchaService$verifyAnswer.call(Unknown Source)
at bankemist.personalcreditcomparator.EmailSharerController$_closure2.doCall(EmailSharerController.groovy:49)
at bankemist.personalcreditcomparator.EmailSharerControllerTests.testHandleEmailSharingSendButtonButMissingFromAndTo(EmailSharerControllerTests.groovy:49)
ull 또는 포함 된 recaptcha
개체
if (ConfigurationHolder.config.recaptcha) {...}
또는 (마지막 :))이 내 RecaptchaConfig.groovy 설정 방법 : RecaptchaService.groovy
의 전화 라인 (33)은 내가이 문제를 해결하기 위해 관리하지 않는
recaptcha {
// These keys are generated by the ReCaptcha service
publicKey = "xxx"
privateKey = "xxx"
// Include the noscript tags in the generated captcha
includeNoScript = true
}
mailhide {
// Generated by the Mailhide service
publicKey = ""
privateKey = ""
}
environments {
development {
recaptcha {
// Set to false to disable the display of captcha
enabled = true
// Communicate using HTTPS
useSecureAPI = false
}
}
test {
recaptcha {
// Set to false to disable the display of captcha
enabled = true
// Communicate using HTTPS
useSecureAPI = false
}
}
. configHolder를 테스트 파일로 가져 오려고했지만 아무 것도 변경하지 않았습니다. 어떤 도움이라도 대단히 감사합니다.
감사합니다. 지금은 매우 명확합니다. –