forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAK-42403 MessageBundleManager turned on by default (sakaiproject#7294)
- Loading branch information
1 parent
4eae5bd
commit eeaa91b
Showing
9 changed files
with
175 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...rc/test/java/org/sakaiproject/messagebundle/impl/test/MessageBundleTestConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package org.sakaiproject.messagebundle.impl.test; | ||
|
||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
import javax.sql.DataSource; | ||
import javax.transaction.TransactionManager; | ||
|
||
import org.hibernate.SessionFactory; | ||
import org.hibernate.dialect.HSQLDialect; | ||
import org.hsqldb.jdbcDriver; | ||
import org.sakaiproject.component.api.ServerConfigurationService; | ||
import org.sakaiproject.hibernate.AssignableUUIDGenerator; | ||
import org.sakaiproject.messagebundle.api.MessageBundleProperty; | ||
import org.sakaiproject.messagebundle.api.MessageBundleService; | ||
import org.sakaiproject.messagebundle.impl.MessageBundleServiceImpl; | ||
import org.sakaiproject.springframework.orm.hibernate.AdditionalHibernateMappings; | ||
import org.sakaiproject.springframework.orm.hibernate.impl.AdditionalHibernateMappingsImpl; | ||
import org.sakaiproject.tool.api.Session; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.jdbc.datasource.DriverManagerDataSource; | ||
import org.springframework.orm.hibernate4.HibernateTransactionManager; | ||
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
import org.springframework.transaction.support.TransactionTemplate; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@PropertySource("classpath:/hibernate.properties") | ||
public class MessageBundleTestConfiguration { | ||
@Autowired | ||
private Environment environment; | ||
|
||
@Bean(name = "org.sakaiproject.springframework.orm.hibernate.impl.AdditionalHibernateMappings.messagebundle") | ||
public AdditionalHibernateMappings hibernateMappings() { | ||
Class[] annotatedClasses = new Class[] {MessageBundleProperty.class}; | ||
AdditionalHibernateMappings mappings = new AdditionalHibernateMappingsImpl(); | ||
mappings.setAnnotatedClasses(annotatedClasses); | ||
return mappings; | ||
} | ||
|
||
@Bean(name = "org.sakaiproject.springframework.orm.hibernate.GlobalSessionFactory") | ||
public SessionFactory sessionFactory(Properties hibernateProperties, AdditionalHibernateMappings mappings) { | ||
LocalSessionFactoryBuilder sfb = new LocalSessionFactoryBuilder(dataSource()); | ||
try { | ||
mappings.processAdditionalMappings(sfb); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
sfb.addProperties(hibernateProperties); | ||
sfb.getIdentifierGeneratorFactory().register("uuid2", AssignableUUIDGenerator.class); | ||
return sfb.buildSessionFactory(); | ||
} | ||
|
||
@Bean(name = "javax.sql.DataSource") | ||
public DataSource dataSource() { | ||
DriverManagerDataSource db = new DriverManagerDataSource(); | ||
db.setDriverClassName(environment.getProperty(org.hibernate.cfg.Environment.DRIVER, jdbcDriver.class.getName())); | ||
db.setUrl(environment.getProperty(org.hibernate.cfg.Environment.URL, "jdbc:hsqldb:mem:test")); | ||
db.setUsername(environment.getProperty(org.hibernate.cfg.Environment.USER, "sa")); | ||
db.setPassword(environment.getProperty(org.hibernate.cfg.Environment.PASS, "")); | ||
return db; | ||
} | ||
|
||
@Bean | ||
public Properties hibernateProperties() { | ||
return new Properties() { | ||
{ | ||
setProperty(org.hibernate.cfg.Environment.DIALECT, environment.getProperty(org.hibernate.cfg.Environment.DIALECT, HSQLDialect.class.getName())); | ||
setProperty(org.hibernate.cfg.Environment.HBM2DDL_AUTO, environment.getProperty(org.hibernate.cfg.Environment.HBM2DDL_AUTO)); | ||
setProperty(org.hibernate.cfg.Environment.ENABLE_LAZY_LOAD_NO_TRANS, environment.getProperty(org.hibernate.cfg.Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true")); | ||
setProperty(org.hibernate.cfg.Environment.CACHE_REGION_FACTORY, environment.getProperty(org.hibernate.cfg.Environment.CACHE_REGION_FACTORY)); | ||
} | ||
}; | ||
} | ||
|
||
@Bean(name = "org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager") | ||
public PlatformTransactionManager transactionManager(SessionFactory sessionFactory) { | ||
HibernateTransactionManager txManager = new HibernateTransactionManager(); | ||
txManager.setSessionFactory(sessionFactory); | ||
return txManager; | ||
} | ||
|
||
@Bean(name = "org.sakaiproject.component.api.ServerConfigurationService") | ||
public ServerConfigurationService serverConfigurationService() { | ||
ServerConfigurationService scs = mock(ServerConfigurationService.class); | ||
when(scs.getBoolean(eq("load.bundles.from.db"), eq(true))).thenReturn(true); | ||
return scs; | ||
} | ||
|
||
@Bean(name = "org.sakaiproject.messagebundle.api.MessageBundleService") | ||
public MessageBundleService messageBundleService(ServerConfigurationService serverConfigurationService, SessionFactory sessionFactory, PlatformTransactionManager transactionManager) { | ||
MessageBundleServiceImpl messageBundleService = new MessageBundleServiceImpl(); | ||
messageBundleService.setServerConfigurationService(serverConfigurationService); | ||
messageBundleService.setSessionFactory(sessionFactory); | ||
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); | ||
messageBundleService.setTransactionTemplate(transactionTemplate); | ||
messageBundleService.setScheduleSaves(false); | ||
messageBundleService.init(); | ||
return messageBundleService; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.