GrailsV3。3.9和jsonView 1.2.10
我有一个域类查询,在运行与类my domain class Device的集成测试时失败,该类扩展了ManagedEntity(abstract),它扩展了RootEntity(也是abstract)。该设备有两个静态withCriteria查询来执行即时抓取。
域类设备。groovy:
Device extends ManagedEntity {
OrgRoleInstance org
Site site
Location location
NetworkDomain domain //can only be in one domain or zero
ProviderNetwork vfNetwork //can be part of one CSP network domain
//simpler option than deviceRoles - not an entity in this case but a join table
Collection<Resource.ResourceRoleType> roles = [] // creates device_roles table no versioning */
Collection<FlexAttribute> attributes = []
Collection<Equipment> buildConfiguration = []
Collection<Interface> interfaces = []
Collection<Alias> aliasNames = []
boolean freeStanding = false
boolean testDevice = false
Product product //ref to portfolio offering if exists
String deviceStatus = "Operational" //or Ceased or ...
String licenceType //e.g. for cisco 903 would be one of "metro servcices", or "metro Ip services", "metro aggregation services"
String licence = "none"
String memory
String storage
String numberOfCpu
Software runtimeOS
boolean isTestEntity () {
testDevice
}
boolean isFreeStanding () {
freeStanding
}
static hasMany = [deviceRoles: Resource, roles: Resource.ResourceRoleType, attributes:FlexAttribute, buildConfiguration: Equipment, interfaces:Interface, aliasNames:Alias]
static belongsTo = [org:OrgRoleInstance] //dont at providerNetwork as belongs to as we dont want cascade delete
static constraints = {
org nullable:true
site nullable:true
location nullable:true
roles nullable:true
domain nullable:true , validator : {NetworkDomain domain, Device dev ->
//assumes org has been set
if (domain == null)
return true
if (dev.org == null)
log.debug "org was null, trying to validate domain is in orgs.domains list - so org must be set first"
NetworkDomain[] validDomains = dev?.org?.domains ?: []
boolean test = validDomains.contains(domain)
test
}
vfNetwork nullable:true , validator : {ProviderNetwork vfNetwork, Device dev ->
if (vfNetwork == null) return true
OrgRoleInstance vf = OrgRoleInstance.findByNameAndRole ("Vodafone", OrgRoleInstance.OrgRoleType.ServiceProvider)
ProviderNetwork[] networks = vf?.providerNetworks ?: []
boolean test = networks.contains (vfNetwork)
if (test == false)
log.debug "Vodafone provider does not yet have any ProviderNetworks to validate to, please create and save any provider networks before assigning to device, then save "
test
}//ensure its in vf's list of provider networks }*/
product nullable:true
deviceStatus nullable:true
licenceType nullable:true
licence nullable:true
memory nullable:true
storage nullable:true
numberOfCpu nullable:true
runtimeOS nullable:true
attributes nullable:true
buildConfiguration nullable:true
interfaces nullable:true
aliasNames nullable:true
}
String toString () {
"Device (manHostname:$manHostName, opState:$opStatus)[id:$id]"
}
//Queries
static Device getFullDeviceById (Serializable id) {
Device.withCriteria (uniqueResult:true) {
join 'domain'
join 'providerNetwork'
join 'site'
join 'location'
join 'runtimeOS'
fetchMode 'product', FetchMode.SELECT
fetchMode 'interfaces', FetchMode.SELECT
fetchMode 'attributes', FetchMode.SELECT
fetchMode 'aliasNames', FetchMode.SELECT
fetchMode 'buildConfiguration', FetchMode.SELECT
idEq (id as Long)
}
}
//Queries
static List<Device> getFullDeviceBySite (Serializable sid) {
Device.withCriteria (uniqueResult:true) {
join 'domain'
join 'providerNetwork'
join 'site'
join 'location'
join 'runtimeOS'
fetchMode 'product', FetchMode.SELECT
fetchMode 'interfaces', FetchMode.SELECT
fetchMode 'attributes', FetchMode.SELECT
fetchMode 'aliasNames', FetchMode.SELECT
fetchMode 'buildConfiguration', FetchMode.SELECT
site {idEq (sid as Long)}
}
}
}
我的测试集成测试失败了(从测试报告中可以看出)
<testcase time="0.0" name="build relationship between two CI " classname="com.softwood.domain.DeviceIntegSpecSpec">
<failure type="org.springframework.beans.factory.UnsatisfiedDependencyException" message="org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.softwood.controller.JsonApiRestfulController': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.Class<?>' available: expected at least 1 bean which qualifies as autowire candidate.
我的缩减测试如下所示,它只调用静态查询(数据在引导中加载):
设备集成测试规范
在两个CI之间建立关系(){
given:
Device pe = Device.getFullDeviceById(2)
assert pe
when : "build a ce and relate the CE and PE "
then:
true
}
这似乎是对我的控制器类(我没有测试)的反对,当我运行应用程序时,它实际上运行良好(启动时没有错误)。
我怎样才能解决这个问题?我不确定这是否相关:
某人的插件中也存在类似的问题
如果我启动Groovy控制台并像这样运行查询:
import com.softwood.domain.Device
Device pe = Device.getFullDeviceById(2)
println pe
这运行得很好,没有错误——因此这与启动集成测试框架有关,而不是加载所有控制器。我想写一些集成测试,但不能,因为这是一个拦截器。
您有一个没有no-arg构造函数的控制器。构造函数需要一个Class
参数。Spring无法知道要在那里传递什么Class
,因此这被认为是无效的。您可能希望该控制器是一个抽象的父类。
编辑:
https://github.com/jeffbrown/williamwoodmanconstructor的项目简化了你的情况,消除了大部分不相关的东西。https://github.com/jeffbrown/williamwoodmanconstructor/blob/cb799545dfa76f78e8203e68cfadb09aed604544/grails-app/controllers/williamwoodmanconstructor/JsonApiRestfulController.groovy就是问题所在。
package williamwoodmanconstructor
import grails.rest.RestfulController
class JsonApiRestfulController<T> extends RestfulController<T> {
JsonApiRestfulController(Class<T> c) {
super(c, false)
}
}
这是无效的。您可以通过运行应用程序并向发送请求来验证这一点http://localhost:8080/jsonApiRestful/index.
在一个使用jwt的Spring Boot应用程序中,在我的spring-cloud-gateway中,我有以下代码。 [main]onfigReactiveWebServerApplicationContext:上下文初始化过程中遇到异常-取消刷新尝试:org.springframework.beans.factory.unsatisfiedDependencyException:创建文件[/ho
我正在尝试使用spring Boot连接到aws。但是,我无法启动我的应用程序。以下是错误消息: 我的pom.xml有以下内容:
我在使用Spring4.1.6.Release时出现了一个错误。 我不知道这个错误是从哪里来的。Autowire注释应该为我创建bean。我还遗漏了什么注释? 说明服务器遇到一个内部错误,使其无法满足此请求。 例外 servletException:servlet.init()servlet appServlet抛出异常he.coyote.abstractProtocol$abstractConn
运行项目时,出现错误: UnsatisfiedDependencyException:创建文件SQLServerQueryDaoImpl.class中定义的名为“SQL ServerQueryDaoImpl”的bean时出错:未满足的依赖关系通过构造函数参数0表示;嵌套异常是org.springframework.beans.factory.NosuchBeanDefinitionExceptio
我在所有集成测试中不断收到异常,而单元测试运行良好。所有异常如下所示: 我正在使用Jupiter进行测试。我的观点的上述例外指向data.sql脚本,我必须填充一些数据。对我来说,语法似乎没问题,也运行良好,这意味着如果使用邮递员进行测试,会生成记录: 还考虑了Spring Boot可能存在的配置问题,所以我在gradle中添加了jdbc-starter依赖项。但它似乎仍然失败。 以下是测试的一部
尝试使用异常消息导航到“客户”时出现异常