
examples.GreetingConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of example-junit-spring-integrationtest Show documentation
Show all versions of example-junit-spring-integrationtest Show documentation
Creates a new quickstart project to integration test Spring modules and services with Testify, JUnit4, Mockito, and AssertJ.
The newest version!
/*
* Copyright 2016-2017 Testify Project.
*
* 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 examples;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.postgresql.ds.PGSimpleDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* Greeting Module Spring Java Config class.
*
* @author saden
*/
@ComponentScan
@Configuration
@EnableJpaRepositories
@EnableTransactionManagement
public class GreetingConfig {
/**
* An in-memory H2 database data source.
*
* @return the data source
*/
@Bean
DataSource productionDataSource() {
PGSimpleDataSource dataSource = new PGSimpleDataSource();
dataSource.setServerName("production.acme.com");
dataSource.setPortNumber(5432);
dataSource.setDatabaseName("postgres");
dataSource.setUser("postgres");
dataSource.setPassword("mysecretpassword");
return dataSource;
}
@Bean
LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
LocalContainerEntityManagerFactoryBean bean =
new LocalContainerEntityManagerFactoryBean();
bean.setDataSource(dataSource);
bean.setPersistenceUnitName("example.greetings");
return bean;
}
/**
* Provides JPA based Spring transaction manager.
*
* @param entityManagerFactory the entity manager factory
* @return jpa transaction manager
*/
@Bean
PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
JpaTransactionManager transactionManager =
new JpaTransactionManager(entityManagerFactory);
return transactionManager;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy