在我的基于Java + Spring后端的项目中,我已经将权限属性列表提取到.properties file。如何在测试中验证属性文件中是否存在所请求的参数?
有没有办法在集成测试中集成此属性文件?
属性文件:
#Viewable Report Filter, Ordered list of states to be viewed in each step of the web-gui
TMSViewableReportFilter.allStates.verify=ONHOLD_HR,VERIFY,PREPARE,CONFIRM,CONFIRM_HR,CONFIRM_MGR,CONFIRM_RM,AGRESSO_IN_PROGRESS,CLOSED
TMSViewableReportFilter.allStates.manager=PREPARE,ONHOLD_FINANCE,ONHOLD_HR,AGRESSO_ERROR,CONFIRM,CONFIRM_HR,CONFIRM_MGR,CONFIRM_RM,AGRESSO_IN_PROGRESS,CLOSED
TMSViewableReportFilter.allStates.prepare=CONFIRM,CONFIRM_HR,CONFIRM_MGR,CONFIRM_RM,ONHOLD_FINANCE,CLOSED
TMSViewableReportFilter.allStates.confirm=CONFIRM_MGR,CONFIRM_HR,CONFIRM_RM,ONHOLD_HR,CLOSED
#Handleable Report Filter, Ordered list of states to be viewed in each step of the web-gui
TMSHandleableReportFilter.allStates.verify=APPROVE,ONHOLD_EMPLOYEE,ONHOLD_FINANCE,AGRESSO_ERROR
TMSHandleableReportFilter.allStates.manager=VERIFY
TMSHandleableReportFilter.allStates.prepare=PREPARE,ONHOLD_HR
TMSHandleableReportFilter.allStates.confirm.hr=CONFIRM_HR
TMSHandleableReportFilter.allStates.confirm.mgr=CONFIRM_MGR,CONFIRM_HR
TMSHandleableReportFilter.allStates.confirm.rm=CONFIRM_RM
以下是我访问这些值的方法:
@Autowired
public TMSHandleableReportService(
@Value("${TMSHandleableReportFilter.allStates.verify}") String[] verifyStringStates,
@Value("${TMSHandleableReportFilter.allStates.manager}") String[] managerStringStates,
@Value("${TMSHandleableReportFilter.allStates.prepare}") String[] prepareStringStates,
@Value("${TMSHandleableReportFilter.allStates.confirm.hr}") String[] confirmHRStringStates,
@Value("${TMSHandleableReportFilter.allStates.confirm.mgr}") String[] confirmMGRStringStates,
@Value("${TMSHandleableReportFilter.allStates.confirm.rm}") String[] confirmRMStringStates) {
handleStates = new HashMap<String, List<TMSState>>();
handleStates.put(
"verify",
loadTMSStateFromStringArray(verifyStringStates,
"TMSViewableReportFilter.allStates.verify"));
handleStates.put(
"manager",
loadTMSStateFromStringArray(managerStringStates,
"TMSViewableReportFilter.allStates.manager"));
handleStates.put(
"prepare",
loadTMSStateFromStringArray(prepareStringStates,
"TMSViewableReportFilter.allStates.prepare"));
handleStates.put(
"confirm.hr",
loadTMSStateFromStringArray(confirmHRStringStates,
"TMSViewableReportFilter.allStates.confirm.hr"));
handleStates.put(
"confirm.mgr",
loadTMSStateFromStringArray(confirmMGRStringStates,
"TMSViewableReportFilter.allStates.confirm.mgr"));
handleStates.put(
"confirm.rm",
loadTMSStateFromStringArray(confirmRMStringStates,
"TMSViewableReportFilter.allStates.confirm.rm"));
验证属性文件中是否存在密钥就足够了。即验证TMSHandleableReportFilter.allStates.verify,TMSHandleableReportFilter.allStates.prepare ...等的发生。
答案 0 :(得分:0)
&#34;在我基于Java + Spring后端的项目中,我已经将一个权限属性列表提取到.properties文件中。如何在测试中验证属性文件中是否存在所请求的参数?&#34; 我的回答是 - 你不需要这样做,一旦Spring无法从属性文件中自动赋值,服务器就不会启动(或任何其他集成te。没有必要验证。