HHH-7311 - Fix and test

This commit is contained in:
Lukasz Antoniak 2012-06-12 07:22:49 +02:00
parent 1f78c9685e
commit 41bac11115
2 changed files with 32 additions and 2 deletions

View File

@ -34,6 +34,7 @@
import org.hibernate.service.jdbc.connections.spi.DataSourceBasedMultiTenantConnectionProviderImpl;
import org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider;
import org.hibernate.service.spi.BasicServiceInitiator;
import org.hibernate.service.spi.ServiceException;
import org.hibernate.service.spi.ServiceRegistryImplementor;
/**
@ -84,7 +85,7 @@ public MultiTenantConnectionProvider initiateService(Map configurationValues, Se
}
catch (ClassLoadingException cle) {
log.warn( "Unable to locate specified class [" + className + "]", cle );
return null;
throw new ServiceException( "Unable to locate specified multi-tenant connection provider [" + className + "]" );
}
}
@ -93,7 +94,7 @@ public MultiTenantConnectionProvider initiateService(Map configurationValues, Se
}
catch (Exception e) {
log.warn( "Unable to instantiate specified class [" + implClass.getName() + "]", e );
return null;
throw new ServiceException( "Unable to instantiate specified multi-tenant connection provider [" + implClass.getName() + "]" );
}
}
}

View File

@ -0,0 +1,29 @@
package org.hibernate.test.multitenancy;
import org.junit.Test;
import org.hibernate.MultiTenancyStrategy;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.spi.ServiceException;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@TestForIssue(jiraKey = "HHH-7311")
public class ConfigurationValidationTest extends BaseUnitTestCase {
@Test(expected = ServiceException.class)
public void testInvalidConnectionProvider() {
Configuration cfg = new Configuration();
cfg.getProperties().put( Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA );
cfg.setProperty( Environment.MULTI_TENANT_CONNECTION_PROVIDER, "class.not.present.in.classpath" );
cfg.buildMappings();
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new ServiceRegistryBuilder()
.applySettings( cfg.getProperties() ).buildServiceRegistry();
cfg.buildSessionFactory( serviceRegistry );
}
}