[英]Gosu system table query failing in Gunits
I have a Guidewire Gunit for a transformer in gosu which queries the system table to get a description for a result code which is working fine when run on the server but Gunit fails for the same. 我有一个针对gosu中的变换器的Guidewire Gunit,它查询系统表以获得结果代码的描述,该代码在服务器上运行时工作正常,但Gunit也失败了。 I have tried the annotation @ServerTest for Gunit but that is failing as well. 我已经为Gunit尝试了注释@ServerTest,但这也失败了。 The same code works fine in Gosu scratchpad. 相同的代码在Gosu暂存器中工作正常。 PFA the code snippet as follows: PFA代码段如下:
var resultCodes = Query.make(SystemTable).select().where(\elt -> elt.ResultCode == "AS01")
var description = "" var description =“”
if(resultCodes != null && !resultCodes.isEmpty())
{
description = resultCodes.get(0).getFullDescription()
}
I'm getting the exception as follows : 我得到的例外情况如下:
java.lang.IllegalStateException: TableMetadataFactory cannot be used before it is started java.lang.IllegalStateException:TableMetadataFactory在启动之前无法使用
Thanks, Deepti 谢谢,Deepti
(Suggestion : )If your requirement is just to query based on some values. (建议:)如果您的要求只是基于某些值进行查询。 Better dont use that .where()
condition. 最好不要使用.where()
条件。
This is like SELECT * FROM <TABLE>
and after getting all the data you are picking out your required result. 这就像SELECT * FROM <TABLE>
,在获取所有数据后,您将获取所需的结果。
The best and the actual way is to use like 最好的和实际的方式是使用喜欢
Query.make(TABLE_NAME).compare(TABLE_NAME#FIELD_NAME,Relop.Equals,"value_to_compare").select();
Query will be like 查询就像
SELECT * FROM <TABLE_NAME> WHERE FIELD_NAME = FIELD_VALUE_TO_COMPARE;
After inserting data into SystemTable (either using builder classes or bundles) run the below code. 将数据插入SystemTable(使用构建器类或包)后,运行以下代码。
var resultCodes = Query.make(SystemTable).compare(SystemTable#ResultCode ,Relop.Equals,"AS01").select()
foreach(result in resultCodes){
description = result.FullDescription
print("Output : "+description);
}
This happens when your RunLevel is set too low. 当RunLevel设置得太低时会发生这种情况。 Run levels below "NO_DAEMONS" will not load system tables. 运行“NO_DAEMONS”以下的级别将不会加载系统表。 The default should be "NO_DAEMONS" so if you have an annotation on your test like this: 默认值应为“NO_DAEMONS”,因此如果您的测试中有注释,请执行以下操作:
@RunLevel(gw.api.system.server.Runlevel.NONE)
either remove it or increase the level. 要么删除它,要么提高水平。
You can refactor your code like this: 您可以像这样重构代码:
uses gw.testharness.RunLevel
uses gw.api.database.Query
uses org.mockito.Mockito
uses gw.api.database.IQueryBeanResult
@RunLevel(NONE)
class StackOverflowTest {
function testDoQuery() {
var rs = Mockito.mock(IQueryBeanResult<SystemTable>)
var query = Mockito.mock(Query<SystemTable>)
Mockito.when(query.select()).thenReturn(rs)
var stackOverflow = Mockito.spy(new StackOverflow())
Mockito.doReturn(query).when(stackOverflow).getSystemTableQuery()
stackOverflow.doQuery()
Mockito.verify(stackOverflow, Mockito.times(1)).getSystemTableQuery()
Mockito.verify(query, Mockito.times(1)).select()
Mockito.verify(rs, Mockito.times(1)).iterator()
}
class StackOverflow {
function doQuery() {
var resultCodes = getSystemTableQuery().select().where(\elt -> elt.ResultCode == "AS01")
}
protected function getSystemTableQuery(): Query<SystemTable> {
return Query.make(SystemTable)
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.