Cannot run integration test because of IllegalStateException in grails-3.0.1 plugin application -


context: i've created new grails plugin named "sampleplugin". has 1 domain class person , integration test personspec. now, when run grails test-app, test fails below exception:

java.lang.illegalstateexception: method on class [sampleplugin.person] used outside of grails application. if running in context of test using mocking api or bootstrap grails correctly.     @ org.grails.datastore.gorm.gormentity$trait$helper.currentgorminstanceapi(gormentity.groovy:52)     @ org.grails.datastore.gorm.gormentity$trait$helper.save(gormentity.groovy:165)     @ sampleplugin.personspec.$tt__$spock_feature_0_1(personspec.groovy:25)     @ sampleplugin.personspec.test save_closure2(personspec.groovy)     @ groovy.lang.closure.call(closure.java:423)     @ groovy.lang.closure.call(closure.java:439)     @ grails.transaction.grailstransactiontemplate$1.dointransaction(grailstransactiontemplate.groovy:67)     @ org.springframework.transaction.support.transactiontemplate.execute(transactiontemplate.java:133)     @ grails.transaction.grailstransactiontemplate.executeandrollback(grailstransactiontemplate.groovy:64)     @ sampleplugin.personspec.test save(personspec.groovy) 

class person.groovy is:

package sampleplugin  class person {     string name } 

class personspec.groovy is:

package sampleplugin  import grails.test.mixin.integration.integration import grails.transaction.* import spock.lang.*  @integration @rollback class personspec extends specification {    void "canary test"() {       expect:           true == true   }    void "test save"() {     when:       new person(name: "john doe").save flush:true     then:       1 == person.count()   } } 

here github link sample grails3 plugin https://github.com/puneetbehl/sampleplugin.git

i able resolve issue adding compile "org.grails.plugins:hibernate" under dependencies in build.gradle. seems grails plugin application doesn't have default. below build.gradle file:

buildscript {     ext {         grailsversion = project.grailsversion     }     repositories {         mavenlocal()         maven { url "https://repo.grails.org/grails/core" }     }     dependencies {         classpath "org.grails:grails-gradle-plugin:$grailsversion"     } }  plugins {     id "io.spring.dependency-management" version "0.4.0.release"     id "com.jfrog.bintray" version "1.1" }  version "0.1-snapshot" group "org.grails.plugins"  apply plugin: 'maven-publish' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: "spring-boot" apply plugin: "org.grails.grails-plugin" apply plugin: "org.grails.grails-gsp" // used publishing central repository, remove if not needed apply from:'https://raw.githubusercontent.com/grails/grails-profile-repository/master/profiles/plugin/templates/grailscentralpublishing.gradle' apply from:'https://raw.githubusercontent.com/grails/grails-profile-repository/master/profiles/plugin/templates/bintraypublishing.gradle'  ext {     grailsversion = project.grailsversion     gradlewrapperversion = project.gradlewrapperversion }  sourcecompatibility = 1.7 targetcompatibility = 1.7   repositories {     mavenlocal()     mavencentral()     maven { url "https://repo.grails.org/grails/core" } }  dependencymanagement {     imports {         mavenbom "org.grails:grails-bom:$grailsversion"     }     applymavenexclusions false }  dependencies {     provided 'org.springframework.boot:spring-boot-starter-logging'     provided "org.springframework.boot:spring-boot-starter-actuator"     provided "org.springframework.boot:spring-boot-autoconfigure"     provided "org.springframework.boot:spring-boot-starter-tomcat"      provided "org.grails:grails-web-boot"     provided "org.grails:grails-dependencies"     provided 'javax.servlet:javax.servlet-api:3.1.0'      compile "org.grails.plugins:hibernate"      testcompile "org.grails:grails-plugin-testing"      console "org.grails:grails-console" }  task wrapper(type: wrapper) {     gradleversion = gradlewrapperversion } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -