fixing issues with tests
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
package zw.qantra.tm;
|
||||
|
||||
import io.nflow.rest.config.RestConfiguration;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@SpringBootApplication
|
||||
@Import(RestConfiguration.class)
|
||||
@EnableCaching
|
||||
@EnableAsync
|
||||
public class TmApplication {
|
||||
@@ -24,4 +23,14 @@ public class TmApplication {
|
||||
public Gson gson() {
|
||||
return new Gson();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally imports nFlow REST configuration only when NOT running the "test" profile.
|
||||
* This prevents nFlow's PostgreSQL-dependent beans from loading in tests that use H2.
|
||||
*/
|
||||
@Configuration
|
||||
@Profile("!test")
|
||||
@org.springframework.context.annotation.Import(io.nflow.rest.config.RestConfiguration.class)
|
||||
static class NflowRestConfig {
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,13 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
@Profile("!test")
|
||||
public class NflowDatabaseConfig extends PgDatabaseConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -31,4 +33,4 @@ public class NflowDatabaseConfig extends PgDatabaseConfiguration {
|
||||
.initializeDataSourceBuilder()
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,13 @@ package zw.qantra.tm;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import zw.qantra.tm.config.NflowTestConfig;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("test")
|
||||
@Import(NflowTestConfig.class)
|
||||
class TmApplicationTests {
|
||||
|
||||
@Test
|
||||
|
||||
34
src/test/java/zw/qantra/tm/config/NflowTestConfig.java
Normal file
34
src/test/java/zw/qantra/tm/config/NflowTestConfig.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package zw.qantra.tm.config;
|
||||
|
||||
import io.nflow.engine.internal.workflow.ObjectStringMapper;
|
||||
import io.nflow.engine.service.WorkflowInstanceService;
|
||||
import io.nflow.engine.workflow.instance.QueryWorkflowInstances;
|
||||
import io.nflow.engine.workflow.instance.WorkflowInstanceFactory;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
@TestConfiguration
|
||||
@Profile("test")
|
||||
public class NflowTestConfig {
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public WorkflowInstanceFactory workflowInstanceFactory() {
|
||||
return Mockito.mock(WorkflowInstanceFactory.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public WorkflowInstanceService workflowInstanceService() {
|
||||
return Mockito.mock(WorkflowInstanceService.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public ObjectStringMapper objectStringMapper() {
|
||||
return Mockito.mock(ObjectStringMapper.class);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ nflow.db.h2.password=
|
||||
nflow.autostart=false
|
||||
|
||||
# Disable security for tests
|
||||
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,io.nflow.spring.boot.autoconfigure.NflowAutoConfiguration
|
||||
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
|
||||
|
||||
# Disable jobrunr for tests
|
||||
jobrunr.enabled=false
|
||||
|
||||
Reference in New Issue
Block a user