2

次の統合テストがあります。基本的に、1 対多の関係で 3 つの SdkApplication オブジェクトに制限されている「アカウント」オブジェクトをデータベースに保存します。統合テストを実行して、これがコントローラーで正しく適用されていることをテストしたいと思います。唯一の問題は、コントローラーによって異なる結果がレンダリングされたにもかかわらず、sac.response.json の最後の行が毎回同じものを返すことです。

統合テストで grails コントローラーの呼び出しの間に呼び出す必要がある応答の明確なメソッドはありますか?

void testAddTooManySdkApplicationBackOfficeUserFails() {
    doTestLoginJasonBackofficeUser(sac)
    def account = ObjectMother.account("TestCo")
    account.maxAuthorized3rdPartyApps = 3
    account.company.save(flush: true)
    account.save(flush: true, failOnError: true)

    3.times {
        setJSONRequest([name: "Amazing Application", accountId: account.id], sac)
        sac.addSdkApplication()
        assertSDKAddedCorrectly(sac.response.json as JSONObject)
    }

    setJSONRequest([name: "Amazing Application", accountId: account.id], sac)
    sac.addSdkApplication()
    def resp = sac.response.json as JSONObject
    assertFalse("Should have failed to add an SDKApplication as the limit was reached", resp.success)
}
4

1 に答える 1

2

yourController.reset() または response.reset() を呼び出してみてください

于 2013-07-10T20:14:34.030 に答える