Skip to content

Commit

Permalink
fix spring boot test
Browse files Browse the repository at this point in the history
  • Loading branch information
elguardian committed Nov 3, 2023
1 parent b7c30d5 commit 11bd73c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,66 @@
*/
package org.kie.kogito.app.audit.springboot;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan
@Configuration(proxyBeanMethods = false)
public class SpringBootAuditDataConfiguration {

@Bean
@Primary
public JpaProperties primaryJpaDataAuditProperties() {
return new JpaProperties();
}

@Bean(name = "JPADataAuditProperties")
@Qualifier("JPADataAuditProperties")
@ConfigurationProperties(prefix = "data-audit.spring.jpa")
public JpaProperties jpaDataAuditProperties() {
return new JpaProperties();
}

@Bean
public LocalContainerEntityManagerFactoryBean jpaDataAuditEntityManagerFactory(
DataSource dataSource,
@Autowired @Qualifier("JPADataAuditProperties") JpaProperties jpaProperties) {
EntityManagerFactoryBuilder builder = createEntityManagerFactoryBuilder(jpaProperties);
return builder
.dataSource(dataSource)
.mappingResources(jpaProperties.getMappingResources().toArray(String[]::new))
.properties(jpaProperties.getProperties())
.persistenceUnit("DataAuditPU")
.build();
}

private EntityManagerFactoryBuilder createEntityManagerFactoryBuilder(JpaProperties jpaProperties) {
JpaVendorAdapter jpaVendorAdapter = createJpaVendorAdapter(jpaProperties);
return new EntityManagerFactoryBuilder(jpaVendorAdapter, jpaProperties.getProperties(), null);
}

private JpaVendorAdapter createJpaVendorAdapter(JpaProperties jpaProperties) {
HibernateJpaVendorAdapter hibernate = new HibernateJpaVendorAdapter();
hibernate.setDatabase(jpaProperties.getDatabase());
hibernate.setGenerateDdl(jpaProperties.isGenerateDdl());
hibernate.setShowSql(jpaProperties.isShowSql());
hibernate.setDatabasePlatform(jpaProperties.getDatabasePlatform());
return hibernate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class SpringBootJPADataAuditEventPublisher implements DataAuditEventPubli
private DataAuditStoreProxyService proxy;

@Autowired
@Qualifier("DataAuditPU")
@Qualifier("jpaDataAuditEntityManagerFactory")
EntityManager entityManager;

public SpringBootJPADataAuditEventPublisher() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# configure jpa
data-audit.spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
data-audit.spring.jpa.mapping-resources=META-INF/entity-orm.xml,META-INF/job-orm.xml,META-INF/process-orm.xml,META-INF/usertask-orm.xml
data-audit.spring.jpa.show-sql=false
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
spring.datasource.jdbc-url=jdbc:h2:mem:test
spring.datasource.driver-class-name=org.h2.Driver

# configure jpa
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.mapping-resources=META-INF/entity-orm.xml,META-INF/job-orm.xml,META-INF/process-orm.xml,META-INF/usertask-orm.xml
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=false


spring.kafka.consumer.bootstrap-servers: localhost:9092
spring.kafka.consumer.auto-offset-reset: earliest

spring.jpa.show-sql=false

data-audit.spring.jpa.database=H2
data-audit.spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
data-audit.spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
data-audit.spring.jpa.properties.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
data-audit.spring.jpa.mapping-resources=META-INF/entity-orm.xml,META-INF/job-orm.xml,META-INF/process-orm.xml,META-INF/usertask-orm.xml
data-audit.spring.jpa.show-sql=true

0 comments on commit 11bd73c

Please sign in to comment.