私はセッションと統合テストに問題があります。ここで私が試したことがあります。 私はShoppingCartWebshopServiceと呼ばれるサービスを持っていて、メソッド "createNewShoppableItem"を持っています。このメソッドはPriceServiceから2つのメソッドを呼び出し、問題があります。 PriceServiceのGrails統合テストとセッションインジェクション
パート:ShoppingCartWebshopServiceの
def sessionFactory_lookup
def getActionResult(){
final session = sessionFactory_lookup.currentSession.connection()
def conn = new Sql(session)
{query and rest of the code}
}
パート:
def customerPriceDetails = priceService.getActionResult()
私の統合テスト:
class ShoppingCartWebshopServiceIntegrationSpec extends IntegrationSpec {
def shoppingCartWebshopService
def priceService
def sessionFactory
void "test something"() {
when:
//First version of session injection:
// ApplicationContext context = (ApplicationContext) ServletContextHolder.getServletContext().getAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT);
// SessionFactory sf = context.getBean('sessionFactory')
// Session session = sf.getCurrentSession()
shoppingCartWebshopService.priceService = priceService
shoppingCartWebshopService.priceService.getActionResult("003-65607758", "19")
//Second version of session injection:
def session = sessionFactory.getCurrentSession()
//
shoppingCartWebshopService.priceService.sessionFactory_lookup = session
def artikl = shoppingCartWebshopService.createNewShoppableItem("003-65607758", "19")
then:
artikl.size() > 0
}
}
私はここで見つかりましたが、それは動作しません最初のバージョン。最初のバージョンでGrails integration test and sessionFactory.currentSession
私は彼のエラーを取得:「groovy.lang.MissingPropertyException:いいえ、そのようなプロパティ:クラスのcurrentSession:org.hibernate.impl.SessionImpl」
番目のバージョンでは、私はこの取得:java.langでの.NullPointerException: "私はSQLクエリの実行のためのセッションを呼び出すPriceServiceの部分でnullのオブジェクトのcurrentSession 'プロパティを取得できません。
私はもう何を試していいのかわからないので、誰かに助言を与えることができますか? ありがとうございます。
SessionFactory_lookupはresources.groovyや他の場所には存在しません。私はGoogleで検索しましたが、多くの情報はありません。それは奇妙に聞こえるかもしれませんが、そのBeanの定義はありません。 IntelliJを使用していて、 "def sessionFactory_lookup"の隣にBeanアイコンがありません。それにもかかわらず、それはSQLプロシージャを実行するために正常に動作します。 – pep
この記事は、sessionFactory_lookupが記述されているところでのみ見つかりました。 http://totalprogus.blogspot.hr/2015/03/upgrade-grails-244-to-250.html Grailsをより高いバージョンにアップグレードすることです。 – pep
PriceServiceのdef sessionFactory_lookupをsessionFactoryに変更してみてください。 –