Spaces:
Build error
Build error
| package com.dalab.discovery.sd.config; | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| import javax.sql.DataSource; | |
| import org.springframework.beans.factory.annotation.Qualifier; | |
| import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | |
| import org.springframework.boot.test.context.TestConfiguration; | |
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.context.annotation.Primary; | |
| 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; | |
| /** | |
| * Provides the EntityManagerFactory and TransactionManager for tests, | |
| * relying on application-test.yml for DataSource and most JPA properties. | |
| */ | |
| public class TestDatabaseConfiguration { | |
| public LocalContainerEntityManagerFactoryBean entityManagerFactory( | |
| EntityManagerFactoryBuilder builder, | |
| DataSource dataSource) { | |
| Map<String, Object> jpaProperties = new HashMap<>(); | |
| // Explicitly set H2 dialect for this EntityManagerFactory | |
| jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); | |
| // ddl-auto should be picked from application-test.yml (create-drop) | |
| // Other properties like show-sql, format_sql also from application-test.yml | |
| return builder | |
| .dataSource(dataSource) | |
| .packages( | |
| "com.dalab.discovery.common.model.entity", | |
| "com.dalab.discovery.common.model", | |
| "com.dalab.discovery.catalog.model", | |
| "com.dalab.discovery.config.model", | |
| "com.dalab.discovery.sd.model", | |
| "com.dalab.discovery.sd.repository", | |
| "com.dalab.discovery.crawler.model", | |
| "com.dalab.discovery.domain.model", | |
| "com.dalab.discovery.log.service.gcp.persistence.entity" | |
| ) | |
| .persistenceUnit("testPU") | |
| .properties(jpaProperties) // Set explicit properties | |
| .build(); | |
| } | |
| public PlatformTransactionManager transactionManager( | |
| LocalContainerEntityManagerFactoryBean entityManagerFactory) { | |
| return new JpaTransactionManager(entityManagerFactory.getObject()); | |
| } | |
| } |