You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@isis.apache.org by QUALITEC - Óscar Bou <ob...@qualitec.es> on 2015/05/06 16:58:08 UTC
Testing when Isis Security Module is on the classpath
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, "test@test.com");
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