X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthorization%2Fhibernate%2FPersistentAuthorizationServiceTest.java;h=f0ed95f0ef3d9ba87b1b86d1507407c458a4ce32;hb=17775e14ecfb286e59f67117e5cee7e21e95ab1f;hp=b1a369347032d6122a01145543659a5afb5ab6ab;hpb=0d8d8f24656e585ee75558cfd6a4c661f8f14985;p=utils diff --git a/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java b/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java index b1a36934..f0ed95f0 100644 --- a/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java +++ b/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 the original author or authors. + * Copyright 2005-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,22 +12,26 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ - + */ package org.wamblee.security.authorization.hibernate; -import java.sql.SQLException; - import org.apache.log4j.Logger; + import org.hibernate.cfg.Configuration; + import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.dialect.MySQL5InnoDBDialect; + import org.hibernate.tool.hbm2ddl.SchemaExport; + import org.springframework.orm.hibernate3.HibernateTemplate; + import org.wamblee.general.BeanKernel; + import org.wamblee.security.authorization.AuthorizationService; import org.wamblee.security.authorization.AuthorizationServiceTest; import org.wamblee.security.authorization.TestUserAccessor; + import org.wamblee.system.adapters.ClassConfiguration; import org.wamblee.system.adapters.ClassConfigurationTest; import org.wamblee.system.adapters.DefaultContainer; @@ -36,60 +40,71 @@ import org.wamblee.system.components.DatabaseComponentFactory; import org.wamblee.system.core.Scope; import org.wamblee.system.spring.component.DatabaseTesterComponent; import org.wamblee.system.spring.component.DatasourceComponent; + import org.wamblee.usermgt.UserAccessor; import org.wamblee.usermgt.hibernate.AuthorizationComponent; import org.wamblee.usermgt.hibernate.HibernateUserAdministrationTest; import org.wamblee.usermgt.hibernate.UserAdministrationComponent; +import java.sql.SQLException; + /** * Unit test for the persistent authorization service. * * @author Erik Brakkee */ public class PersistentAuthorizationServiceTest extends - AuthorizationServiceTest { - + AuthorizationServiceTest { private static final Logger LOGGER = Logger - .getLogger(PersistentAuthorizationServiceTest.class); + .getLogger(PersistentAuthorizationServiceTest.class); private static final String SERVICE_TABLE = "AUTHORIZATION_SERVICE"; + private static final String RULES_TABLE = "AUTHORIZATION_RULES"; + private static final String SERVICE_RULES_TABLE = "AUTHORIZATION_SERVICE_RULES"; + private static final String OPERATIONCOND_TABLE = "OPERATION_CONDITIONS"; + private static final String PATHCOND_TABLE = "PATH_CONDITIONS"; + private static final String USERCOND_TABLE = "USER_CONDITIONS"; private DefaultContainer container; + private Scope scope; private DatabaseTesterComponent databaseTester; + private UserAccessor userAccessor; + private HibernateTemplate hibernateTemplate; + private AuthorizationService authorizationService; @Override protected void setUp() throws Exception { - container = new DefaultContainer("top"); DatabaseComponentFactory.addDatabaseConfig(container); container.addComponent(new DatasourceComponent("datasource")); + ClassConfiguration useraccessorConfig = new ClassConfiguration( - TestUserAccessor.class); + TestUserAccessor.class); useraccessorConfig.getObjectConfig().getSetterConfig().initAllSetters(); container.addComponent("userAccessor", useraccessorConfig); - container.addComponent(new AuthorizationComponent("authorization", - true)); + container + .addComponent(new AuthorizationComponent("authorization", true)); ClassConfiguration dbtesterConfig = new ClassConfiguration( - DatabaseTesterComponent.class); + DatabaseTesterComponent.class); dbtesterConfig.getObjectConfig().getSetterConfig().initAllSetters(); container.addComponent("databaseTester", dbtesterConfig); ObjectConfiguration config = new ObjectConfiguration( - PersistentAuthorizationServiceTest.class); + PersistentAuthorizationServiceTest.class); config.getSetterConfig().clear().add("setUserAccessor").add( - "setDatabaseTester").add("setHibernateTemplate").add( - "setAuthorizationService"); + "setDatabaseTester").add("setHibernateTemplate").add( + "setAuthorizationService"); container.addComponent("testcase", this, config); scope = container.start(); @@ -112,7 +127,7 @@ public class PersistentAuthorizationServiceTest extends } public void setAuthorizationService( - AuthorizationService aAuthorizationService) { + AuthorizationService aAuthorizationService) { authorizationService = aAuthorizationService; } @@ -126,7 +141,8 @@ public class PersistentAuthorizationServiceTest extends @Override protected AuthorizationService createService() { PersistentAuthorizationService service = new PersistentAuthorizationService( - "DEFAULT", hibernateTemplate, createUserAccessor(), 10000); + "DEFAULT", hibernateTemplate, createUserAccessor(), 10000); + return service; } @@ -143,34 +159,37 @@ public class PersistentAuthorizationServiceTest extends assertEquals(1, databaseTester.getTableSize(SERVICE_TABLE)); assertEquals(aCount, databaseTester.getTableSize(RULES_TABLE)); assertEquals(aCount, databaseTester - .getTableSize(SERVICE_RULES_TABLE)); + .getTableSize(SERVICE_RULES_TABLE)); assertEquals(aCount, databaseTester.getTableSize(USERCOND_TABLE)); assertEquals(aCount, databaseTester.getTableSize(PATHCOND_TABLE)); assertEquals(aCount, databaseTester - .getTableSize(OPERATIONCOND_TABLE)); + .getTableSize(OPERATIONCOND_TABLE)); } catch (SQLException e) { throw new RuntimeException(e); } - } - public void testSchemaExport() { + public void testSchemaExport() { Configuration config = new Configuration(); - for (String mappingFile: new AuthorizationMappingFiles()) { - config.addResource(mappingFile); + + for (String mappingFile : new AuthorizationMappingFiles()) { + config.addResource(mappingFile); } - config.setProperty("hibernate.dialect", MySQL5InnoDBDialect.class.getName()); + + config.setProperty("hibernate.dialect", MySQL5InnoDBDialect.class + .getName()); + SchemaExport exporter = new SchemaExport(config); exporter.setOutputFile("target/mysql5.schema.sql"); - exporter.create(true,false); + exporter.create(true, false); } public void testPerformance() { - PersistentAuthorizationService service = (PersistentAuthorizationService) getService(); int n = 1000; long time = System.currentTimeMillis(); + for (int i = 0; i < n; i++) { testFirstRuleGrants(); resetTestRules(); @@ -180,8 +199,9 @@ public class PersistentAuthorizationServiceTest extends resetTestRules(); testNoRulesSupportResource(); } - LOGGER.info("Executed " + 4 * n + " authorization checks in " - + (float) (System.currentTimeMillis() - time) / (float) 1000 - + " seconds."); + + LOGGER.info("Executed " + (4 * n) + " authorization checks in " + + ((float) (System.currentTimeMillis() - time) / (float) 1000) + + " seconds."); } }