X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthorization%2Fhibernate%2FPersistentAuthorizationServiceTest.java;fp=security%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthorization%2Fhibernate%2FPersistentAuthorizationServiceTest.java;h=93758b1239cc8ba87e478d690fd7ea5cfe113530;hb=162af365e45e54e5e8d656be276914df2005eaec;hp=0000000000000000000000000000000000000000;hpb=cf25a3646c663c5aadbd2de8c23840550b18125b;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 new file mode 100644 index 00000000..93758b12 --- /dev/null +++ b/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java @@ -0,0 +1,91 @@ +/* + * Copyright 2005 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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.springframework.orm.hibernate3.HibernateTemplate; +import org.wamblee.general.BeanKernel; +import org.wamblee.security.authorization.AuthorizationService; +import org.wamblee.security.authorization.AuthorizationServiceTest; + +/** + * Unit test for the persistent authorization service. + */ +public class PersistentAuthorizationServiceTest extends AuthorizationServiceTest { + + private static final Logger LOGGER = Logger.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"; + + + public PersistentAuthorizationServiceTest() { + super(AuthorizationSpringConfigFiles.class, AuthorizationMappingFiles.class); + } + + /* (non-Javadoc) + * @see org.wamblee.security.authorization.AuthorizationServiceTest#createService() + */ + @Override + protected AuthorizationService createService() { + PersistentAuthorizationService service = new PersistentAuthorizationService("DEFAULT", + BeanKernel.getBeanFactory().find(HibernateTemplate.class), createUserAccessor(), 10000); + return service; + } + + /* (non-Javadoc) + * @see org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount(int) + */ + @Override + protected void checkRuleCount(int aCount) { + try { + assertEquals(1, getTableSize(SERVICE_TABLE)); + assertEquals(aCount, getTableSize(RULES_TABLE)); + assertEquals(aCount, getTableSize(SERVICE_RULES_TABLE)); + assertEquals(aCount, getTableSize(USERCOND_TABLE)); + assertEquals(aCount, getTableSize(PATHCOND_TABLE)); + assertEquals(aCount, getTableSize(OPERATIONCOND_TABLE)); + } catch (SQLException e) { + throw new RuntimeException(e); + } + + } + + public void testPerformance() { + + PersistentAuthorizationService service = (PersistentAuthorizationService)getService(); + + int n = 1000; + long time = System.currentTimeMillis(); + for (int i = 0; i < n; i++) { + testFirstRuleGrants(); + resetTestRules(); + testSecondRuleDenies(); + resetTestRules(); + testThirdRuleGrants(); + resetTestRules(); + testNoRulesSupportResource(); + } + LOGGER.info("Executed " + 4*n + " authorization checks in " + (float)(System.currentTimeMillis()-time)/(float)1000 + " seconds."); + } +}