- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试对domains类使用模拟,但是在findBy中不起作用,请表明该类为null。
最后一次给出此错误:
"C:\Program Files\Java\jdk1.8.0_144\bin\java" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Users\pedro.borborema-nub\AppData\Roaming\JetBrains\IntelliJ IDEA 2017.2.5\lib\idea_rt.jar=50871:C:\Users\pedro.borborema-nub\AppData\Roaming\JetBrains\IntelliJ IDEA 2017.2.5\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Administrador\AppData\Local\Temp\classpath2.jar com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 "colaborar.pagamentos.PagamentoServiceSpec,teste taxa"
2018-01-10 14:36:15 [main] ERROR g.a.s.c.pagamentos.PagamentoService - Erro ao gerar documentoInfo: java.lang.IllegalStateException: Either class [colaborar.domains.financeiro.CrParcela] is not a domain class or GORM has not been initialized correctly or has already been shutdown. If you are unit testing your entities using the mocking APIs
at org.grails.datastore.gorm.GormEnhancer.stateException(GormEnhancer.groovy:159)
at org.grails.datastore.gorm.GormEnhancer.findStaticApi(GormEnhancer.groovy:153)
at org.grails.datastore.gorm.GormEnhancer.findStaticApi(GormEnhancer.groovy)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.currentGormStaticApi(GormEntity.groovy:1315)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:91)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at colaborar.domains.financeiro.CrParcela.currentGormStaticApi(CrParcela.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:91)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:58)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.staticMethodMissing(GormEntity.groovy:734)
at org.grails.datastore.gorm.GormEntity$Trait$Helper$staticMethodMissing$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)
at colaborar.domains.financeiro.CrParcela.staticMethodMissing(CrParcela.groovy)
at colaborar.domains.financeiro.CrParcela$staticMethodMissing.callStatic(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:214)
at colaborar.domains.financeiro.CrParcela.$static_methodMissing(CrParcela.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1496)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1484)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at colaborar.pagamentos.PagamentoService.getDocumentoInfo(PagamentoService.groovy:62)
at colaborar.pagamentos.PagamentoService$getDocumentoInfo.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at colaborar.pagamentos.PagamentoServiceSpec.$spock_feature_0_6(PagamentoServiceSpec.groovy:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:153)
at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:84)
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:480)
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:463)
at org.spockframework.runtime.BaseSpecRunner.runFeatureMethod(BaseSpecRunner.java:405)
at org.spockframework.runtime.BaseSpecRunner.doRunIteration(BaseSpecRunner.java:324)
at org.spockframework.runtime.BaseSpecRunner$6.invoke(BaseSpecRunner.java:309)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:233)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at grails.test.runtime.TestRuntimeJunitAdapter$1$2.evaluate(TestRuntimeJunitAdapter.groovy:46)
at org.spockframework.runtime.extension.builtin.TestRuleInterceptor.intercept(TestRuleInterceptor.java:38)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:471)
at org.spockframework.runtime.BaseSpecRunner.runIteration(BaseSpecRunner.java:288)
at org.spockframework.runtime.BaseSpecRunner.initializeAndRunIteration(BaseSpecRunner.java:278)
at org.spockframework.runtime.BaseSpecRunner.runSimpleFeature(BaseSpecRunner.java:269)
at org.spockframework.runtime.BaseSpecRunner.doRunFeature(BaseSpecRunner.java:263)
at org.spockframework.runtime.BaseSpecRunner$5.invoke(BaseSpecRunner.java:246)
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:480)
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:463)
at org.spockframework.runtime.BaseSpecRunner.runFeature(BaseSpecRunner.java:238)
at org.spockframework.runtime.BaseSpecRunner.runFeatures(BaseSpecRunner.java:188)
at org.spockframework.runtime.BaseSpecRunner.doRunSpec(BaseSpecRunner.java:98)
at org.spockframework.runtime.BaseSpecRunner$1.invoke(BaseSpecRunner.java:84)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:233)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at grails.test.runtime.TestRuntimeJunitAdapter$3$4.evaluate(TestRuntimeJunitAdapter.groovy:73)
at org.spockframework.runtime.extension.builtin.ClassRuleInterceptor.intercept(ClassRuleInterceptor.java:38)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:471)
at org.spockframework.runtime.BaseSpecRunner.runSpec(BaseSpecRunner.java:76)
at org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:67)
at org.spockframework.runtime.Sputnik.run(Sputnik.java:63)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
def getDocumentoInfo(CrDocumento documento) {
try {
def vbr = ViewBoletoRegistro.findById(documento?.id)
def crTaxa = CrTaxa.findByCrDocumento(documento)
if (crTaxa) {
return getTaxa(crTaxa, documento, vbr)
}
} catch (Exception ex) {
log.error("Erro ao gerar documentoInfo: " + ExceptionUtils.getFullStackTrace(ex))
return [:]
}
}
def getTaxa(CrTaxa crTaxa, documento, ViewBoletoRegistro vbr) {
def vencimento = (crTaxa.dataVencimento <= new Date()) ? calculaDiasUteis(new Date(), 0) : crTaxa?.dataVencimento
def tipoCursoId = crTaxa?.solicitacaoServico?.matricula?.ofertaPoloTurma?.ofertaPolo?.oferta?.modulo?.matriz?.curso?.tipoCurso?.id
def desconto = crTaxa.valorDesconto == null ? 0 : crTaxa.valorDesconto
def juros = 0
if (((tipoCursoId == '03' || tipoCursoId == '14' || tipoCursoId == '20' && crTaxa.numeroParcela != '01') || tipoCursoId == '23') && crTaxa.dataVencimento <= new Date() && !crTaxa.dataPrimeiroRecebimento) {
juros = calculaMultaNodia(documento.id, vencimento)
} else {
juros = crTaxa.valorJuros == null ? 0 : crTaxa.valorJuros
}
def maxParcelaCartao = ServicoPrecoItem.findByServico(crTaxa.solicitacaoServico.servico).parcelas
def documentoInfo = [:]
documentoInfo.id = documento.id
documentoInfo.pessoa = crTaxa?.solicitacaoServico?.matricula?.aluno?.pessoa
documentoInfo.nome = crTaxa?.solicitacaoServico?.matricula?.aluno?.nome + (crTaxa?.solicitacaoServico?.matricula ? " (${crTaxa?.solicitacaoServico?.matricula?.id})" : "")
documentoInfo.email = crTaxa?.solicitacaoServico?.matricula?.aluno?.email
documentoInfo.descricao = "Taxa"
documentoInfo.valor = toBigDecimal(crTaxa.valor).add(toBigDecimal(juros))
documentoInfo.valorTitulo = vbr?.valorNominalTitulo
documentoInfo.data = vencimento
documentoInfo.situacao = crTaxa.situacaoFaturamento.id
documentoInfo.boleto = true
documentoInfo.cartao = (maxParcelaCartao >= 1 ? true : crTaxa.numeroParcela == '01' ? true : false) && Colaborar.getBoolean('pagamento.cielo.parcela.enabled', true)
documentoInfo.minParcelas = 1
documentoInfo.maxParcelas = maxParcelaCartao >= 1 ? maxParcelaCartao : tipoCursoId == '14' ? 1 : tipoCursoId == '20' ? 1 : 3
documentoInfo.conta = crTaxa.conta
documentoInfo.apenasCartao = crTaxa.solicitacaoServico.cartao
documentoInfo
}
void 'teste taxa'(){
setup:
GroovySpy(CrTaxa, global:true)
GroovySpy(ViewBoletoRegistro, global:true)
when:
def documento=CrDocumento.findOrSaveById(123)
def documentoInfo=service.getDocumentoInfo(documento)
then:
1 * ViewBoletoRegistro.findById("123")
1 * CrTaxa.findByCrDocumento(CrDocumento.findOrSaveById(123))
documentoInfo.descricao=="Taxa"
}
最佳答案
对于grails> = 3.3.0,您可以使用新的单元测试框架功能模拟域类。实现 DataTest 和 getDomainClassesToMock():
class YourSpec extends Specification implements DataTest {
Class[] getDomainClassesToMock() {
[CrParcela, CrTaxa, ViewBoletoRegistro, CrDocumento]
}
// your tests ...
}
@Mock([CrParcela, CrTaxa, ViewBoletoRegistro, CrDocumento])
class YourSpec extends Specification {
// your tests ...
}
关于grails - 如何在Spock中使用Mock在Grails中进行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48193391/
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
我们正在尝试使用 https://grails.org/plugin/jms用于 jms 集成。但我们无法解决它。 环顾四周,我能够验证它是否存在于这个 repo 中: http://repo.gra
我有许多集成测试在grails 3中失败(而在grails 2中通过),因为它无法解析导入: grails.test.MockUtils grails.test.Grails模拟 我找不到有关应如何迁
有没有办法在 Grails 站点上发生 Grails 错误时向自己发送详细信息? 设置它的最佳方法是什么?在一个地方? (试图保持干燥) 我想包括产生错误的 URL。 最佳答案 . 如果您打算捕获项目
我有一个 grails 应用程序,其中包含一些被序列化为 JSON 的域对象。在另一个 java/groovy 项目中,我想使用这些域对象。如果我发布一个插件,看起来只有其他 grails 应用程序可
我正在尝试为 Grails 编写一个插件,该插件将根据我们在遗留数据库中设计的特殊 View 自动生成我的域类。我基本上只是想节省一些时间手动编写使域类工作所需的所有映射内容。 我是否可以从自定义 A
我正在尝试编写一个可以在多个 Grails 应用程序中重用的插件。该插件基本上应该是 spring security core 的包装器和 ldap 插件。 这意味着它应该包含: 用户/角色的域类 S
我有一个应用程序,我在其中使用 Spring Security 和 grails 旋律。我计划在生产环境中运行 grails melody,但不希望访问者访问它。我应该如何做到这一点?我尝试在 gra
我只是继承了一个现有的应用程序,而我注意到的第一件事是我必须在每个“grails run-app”之前进行“grails clean”操作,否则会出错。创建该项目的人说,他们还有其他几个具有类似设置的
我有一个自定义 toString我的枚举中的方法: enum TaxRate implements Serializable { RATE23(23.0), ... priva
我正在创建一个 Grails 插件作为复杂产品的包装器。该产品对其他产品(如 hibernate)有很多依赖性。问题是,grails 有一些相同的依赖项,但版本不同。 例如。 Grails -> 休眠
当我掉进 grails 服务的兔子洞时,我目前正在将业务逻辑从 Controller 方法转移到服务。我的服务中有以下方法: Job closeJobOpportunity(Job op, Emplo
我只收到默认验证器消息。我究竟做错了什么? class Questao { static hasMany = [alternativas:Alternativa] static constraints
Closed. This question needs to be more focused 。它目前不接受答案。 想改善这个问题吗?更新问题,使其仅通过 editing this post 关注一个
特定版本的 Grails 支持多长时间?一般的 VMWare 支持策略似乎是支持当前版本和一个版本。我无法找到任何关于支持多长时间版本的 Grails 特定信息,通用 VMWare 策略是否适用? 最
我有一个通过 grails 交互模式运行的 grails 应用程序。此应用程序包含服务、tagLibs、gsps 等,但最重要的是它包含 src/groovy 文件夹中的 groovy 文件。 这些
LinkedIn 的人们一直在以一种有趣的方式使用 Play 来处理需要由许多不同组件组成的页面:http://engineering.linkedin.com/play/composable-and
我在 Grails 应用程序中使用 Servlet 3.0 异步渲染。我收到以下错误。 | Error 2014-04-29 11:10:24,125 [Actor Thread 28] ERROR
我看了Controller.groovy源代码,看起来 CRUD 操作不是事务性的(至少是明确的)。 如果我是对的,这是否意味着不应该在生产中按原样使用动态脚手架?有没有办法使它具有事务性(即我可以修
我如何基本上对字符串数据类型字段执行唯一约束。 class User{ String username String Email static hasMany = [roles:Roles
我是一名优秀的程序员,十分优秀!