Hi all.

I have many integ. tests with use “wrap” to invoke actions or setters, 
simulating end-user behavior.

In current implementation, if the Isis Security Add-On is on the classpath, it 
setups the 
org.isisaddons.module.security.facets.TenantedAuthorizationFacetFactory, which 
requires the User to be associated with a Tenant.

As for integ. tests the domainObjectContainer is initialized with a default 
user name that it’s “tester”, it needs to be instantiated on the Isis Security 
Add-On and associated with an ApplicationTenancy.

Right not, what I’ve made is create a JUnit @Before method on my 
IntegrationTestAbstract descendant, like this one:

public class AbstractTellmeGenIntegTest extends IntegrationTestAbstract {

…

    @Before
    public void setUpSecurity() {

        final String testerUserName = 
this.domainObjectContainer.getUser().getName();
        ApplicationUser applicationUser = 
this.applicationUsers.findUserByUsername(testerUserName);
        if (applicationUser == null) {
            applicationUser = 
this.applicationUsers.newLocalUser(testerUserName, new 
Password(testerUserName), new Password(testerUserName), null, true, 
"[email protected]");
            final ApplicationTenancy applicationTenancy = 
this.applicationTenancies.findTenancyByPath("/");
            applicationTenancy.addUser(applicationUser);

            this.domainObjectContainer.flush();
        }

    }
}


Should it be the way to proceed? Perhaps a better way instead is available?

Thanks,

Oscar

Reply via email to