Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grails Specification test unable identify Domain in in-place plugin as Domain object #53

Open
dtsushant opened this issue May 1, 2019 · 0 comments

Comments

@dtsushant
Copy link

I am trying to build a plugin with multitenency feature that carries all the domain object so that it can be shared across multiple grails based web-application, but on writing a simple unit-test I am seeing that the Unit-test denies to identify the Domain class in the plugin as a domain at all.
If I run the same test by linking it with the Domain object in the project itself instead of Plugin, everything works fine, I cannot have the test placed in plugin itself as the heavy implementation will be on the specific service end, any idea on it, below is the code snippet, where Benefit is the domain obect that lies inside the inplace plugin:-

package test

import com.common.domain.Benefit
import grails.test.hibernate.HibernateSpec
import grails.testing.services.ServiceUnitTest
import org.grails.datastore.mapping.config.Settings
import org.grails.datastore.mapping.multitenancy.resolvers.SystemPropertyTenantResolver

class TestServiceSpec extends HibernateSpec implements ServiceUnitTest<TestService>{

    Class<?>[] getDomainClassesToMock(){
        return [Benefit] as  Class[]
    }

    @Override
    Map getConfiguration() {
        [(Settings.SETTING_MULTI_TENANT_RESOLVER_CLASS): SystemPropertyTenantResolver]
    }

    def setup() {
        System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, 'vendor1') //
    }


    def cleanup() {
        System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, '')
    }

    void "test something"() {
        expect:"fix me"
            service.serviceMethod()
            true == true
    }
}

here is the service

.
.
import com.common.domain.Benefit

@Transactional
@CurrentTenant
@CompileStatic
class TestService {

    def serviceMethod() {
       def something = Benefit.findAll()
        println something
        return something

    }
}

Following is the error I am gettin on the end of the unit test

Either class [com.common.domain.Benefit] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
java.lang.IllegalStateException: Either class [com.common.domain.Benefit] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
	at org.grails.datastore.gorm.GormEnhancer.stateException(GormEnhancer.groovy:472)
	at org.grails.datastore.gorm.GormEnhancer.findDatastore(GormEnhancer.groovy:354)
	at org.grails.datastore.gorm.GormEnhancer.findTenantId(GormEnhancer.groovy:268)
	at org.grails.datastore.gorm.GormEnhancer.findStaticApi(GormEnhancer.groovy:299)
	at org.grails.datastore.gorm.GormEntity$Trait$Helper.currentGormStaticApi(GormEntity.groovy:1368)
	at org.grails.datastore.gorm.GormEntity$Trait$Helper.findAll(GormEntity.groovy:689)
	at org.grails.datastore.gorm.GormEntity$Trait$Helper.findAll(GormEntity.groovy:688)
	at test.TestService.$tt__serviceMethod(TestService.groovy:15)
	at test.TestService._mt__serviceMethod_closure3(TestService.groovy)
	at groovy.lang.Closure.call(Closure.java:418)
	at groovy.lang.Closure.call(Closure.java:434)
	at grails.gorm.transactions.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:94)
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
	at grails.gorm.transactions.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:91)
	at test.TestService.serviceMethod_closure1(TestService.groovy)
	at groovy.lang.Closure.call(Closure.java:418)
	at groovy.lang.Closure.call(Closure.java:434)
	at grails.gorm.multitenancy.Tenants.withId_closure2$_closure6(Tenants.groovy:265)
	at org.grails.orm.hibernate.GrailsHibernateTemplate$1.doInHibernate(GrailsHibernateTemplate.java:153)
	at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:299)
	at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:243)
	at org.grails.orm.hibernate.GrailsHibernateTemplate.executeWithNewSession(GrailsHibernateTemplate.java:150)
	at org.grails.orm.hibernate.GrailsHibernateTemplate.executeWithExistingOrCreateNewSession(GrailsHibernateTemplate.java:209)
	at org.grails.orm.hibernate.AbstractHibernateDatastore.withNewSession(AbstractHibernateDatastore.java:369)
	at grails.gorm.multitenancy.Tenants.withId_closure2(Tenants.groovy:258)
	at grails.gorm.multitenancy.Tenants$CurrentTenant.withTenant(Tenants.groovy:358)
	at grails.gorm.multitenancy.Tenants.withId(Tenants.groovy:236)
	at org.grails.datastore.gorm.services.DefaultTenantService.withCurrent(DefaultTenantService.groovy:71)
	at test.TestServiceSpec.test something somethng(TestServiceSpec.groovy:38)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant