私はこの方法をテストしようとしています
def save() {
def activityArtifactInstance = new ActivityArtifact(params)
def activityInstance = Activity.get(params.activity.id)
def uploadedFile = request.getFile('myFile')
if (!uploadedFile.empty) {
def userDir = new File(ConfigurationHolder.config.getProperty("userfiles").toString(), "/files")
userDir.mkdirs()
uploadedFile.transferTo(new File(userDir, uploadedFile.originalFilename))
activityArtifactInstance.fileName = uploadedFile.originalFilename
}
if (!activityArtifactInstance.save(flush: true)) {
render(view: "create", model: [activityArtifactInstance: activityArtifactInstance, activityInstance: activityInstance])
return
}
flash.message = message(code: 'default.created.message', args: [message(code: 'activityArtifact.label', default: 'ActivityArtifact'), activityArtifactInstance.id])
redirect(controller: "activity", action: "show", id: activityInstance.id, params: [phaseId:activityInstance.phase.id])
}
これは私のテストコードです:-
def 'save action: valid activity artifact'() {
setup:
mockDomain(ActivityArtifact)
mockI18N(ActivityArtifactController)
controller.params.name = "Activity Artiface"
when:
controller.save()
then:
redirectArgs.action == "show"
controller.flash.message != null
}
そして、このエラーが発生します:-
java.lang.NullPointerException:nullオブジェクトのプロパティ'id'を取得できません
アクティビティオブジェクトのIDを呼び出すにはどうすればよいですか