Separating security into a part that depends only on the JPA and into a
[utils] / security / src / test / java / org / wamblee / security / authorization / hibernate / PersistentAuthorizationServiceTest.java
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
deleted file mode 100644 (file)
index f0ed95f..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * 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.
- * 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 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;
-import org.wamblee.system.adapters.ObjectConfiguration;
-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 {
-    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";
-
-    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);
-        useraccessorConfig.getObjectConfig().getSetterConfig().initAllSetters();
-        container.addComponent("userAccessor", useraccessorConfig);
-        container
-            .addComponent(new AuthorizationComponent("authorization", true));
-
-        ClassConfiguration dbtesterConfig = new ClassConfiguration(
-            DatabaseTesterComponent.class);
-        dbtesterConfig.getObjectConfig().getSetterConfig().initAllSetters();
-        container.addComponent("databaseTester", dbtesterConfig);
-
-        ObjectConfiguration config = new ObjectConfiguration(
-            PersistentAuthorizationServiceTest.class);
-        config.getSetterConfig().clear().add("setUserAccessor").add(
-            "setDatabaseTester").add("setHibernateTemplate").add(
-            "setAuthorizationService");
-        container.addComponent("testcase", this, config);
-
-        scope = container.start();
-
-        databaseTester.cleanDatabase();
-
-        super.setUp();
-    }
-
-    public void setDatabaseTester(DatabaseTesterComponent aDatabaseTester) {
-        databaseTester = aDatabaseTester;
-    }
-
-    public void setUserAccessor(UserAccessor aUserAccessor) {
-        userAccessor = aUserAccessor;
-    }
-
-    public void setHibernateTemplate(HibernateTemplate aHibernateTemplate) {
-        hibernateTemplate = aHibernateTemplate;
-    }
-
-    public void setAuthorizationService(
-        AuthorizationService aAuthorizationService) {
-        authorizationService = aAuthorizationService;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.wamblee.security.authorization.AuthorizationServiceTest#createService
-     * ()
-     */
-    @Override
-    protected AuthorizationService createService() {
-        PersistentAuthorizationService service = new PersistentAuthorizationService(
-            "DEFAULT", hibernateTemplate, createUserAccessor(), 10000);
-
-        return service;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount
-     * (int)
-     */
-    @Override
-    protected void checkRuleCount(int aCount) {
-        try {
-            assertEquals(1, databaseTester.getTableSize(SERVICE_TABLE));
-            assertEquals(aCount, databaseTester.getTableSize(RULES_TABLE));
-            assertEquals(aCount, databaseTester
-                .getTableSize(SERVICE_RULES_TABLE));
-            assertEquals(aCount, databaseTester.getTableSize(USERCOND_TABLE));
-            assertEquals(aCount, databaseTester.getTableSize(PATHCOND_TABLE));
-            assertEquals(aCount, databaseTester
-                .getTableSize(OPERATIONCOND_TABLE));
-        } catch (SQLException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    public void testSchemaExport() {
-        Configuration config = new Configuration();
-
-        for (String mappingFile : new AuthorizationMappingFiles()) {
-            config.addResource(mappingFile);
-        }
-
-        config.setProperty("hibernate.dialect", MySQL5InnoDBDialect.class
-            .getName());
-
-        SchemaExport exporter = new SchemaExport(config);
-        exporter.setOutputFile("target/mysql5.schema.sql");
-        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();
-            testSecondRuleDenies();
-            resetTestRules();
-            testThirdRuleGrants();
-            resetTestRules();
-            testNoRulesSupportResource();
-        }
-
-        LOGGER.info("Executed " + (4 * n) + " authorization checks in " +
-            ((float) (System.currentTimeMillis() - time) / (float) 1000) +
-            " seconds.");
-    }
-}