spring-test

Using annotation @Sql, is it possible to execute scripts in Class level before Method level?

流过昼夜 提交于 2021-02-20 13:31:12
问题 I want to execute two scripts before every test method, but i also want to define some scripts to execute before specific methods. Using Spring framework and @Sql annotations, is it possible? @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/WEB-INF/application-context.xml") @DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD) @Sql({ "/database/drop_schema.sql", "/database/create_schema.sql" }) public class CentralServiceTestCase { // I want to run "drop_schema.sql",

When should I use TypeExcludeFilters in Spring?

纵饮孤独 提交于 2021-02-19 03:36:30
问题 Recently, Spring Boot added TypeExcludeFilters. One prominent use case is the SpringBootApplication annotation. Before Spring Boot 1.4: // ... @ComponentScan public @interface SpringBootApplication { // ... Since Spring Boot 1.4: // ... @ComponentScan(excludeFilters = @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class)) public @interface SpringBootApplication { // ... The main motivation seems to improve testing support in Spring, but I fail to get an intuitive understanding

When should I use TypeExcludeFilters in Spring?

家住魔仙堡 提交于 2021-02-19 03:36:03
问题 Recently, Spring Boot added TypeExcludeFilters. One prominent use case is the SpringBootApplication annotation. Before Spring Boot 1.4: // ... @ComponentScan public @interface SpringBootApplication { // ... Since Spring Boot 1.4: // ... @ComponentScan(excludeFilters = @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class)) public @interface SpringBootApplication { // ... The main motivation seems to improve testing support in Spring, but I fail to get an intuitive understanding

how to run/turn off selective tests based on profiles in spring boot

痴心易碎 提交于 2021-02-17 05:16:12
问题 I have a spring-boot application for which I am writing IT tests. The data for the tests comes from application-dev.properties when I activate dev profile Here is what I have for tests: @RunWith(SpringRunner.class) @SpringBootTest @WebAppConfiguration public class ApplicationTests { @Autowired Environment env; @Test public void contextLoads() { System.out.println(Arrays.toString((env.getActiveProfiles()))); } } ServiceITTest public class ServiceITTest extends ApplicationTests { @value String

how to run/turn off selective tests based on profiles in spring boot

走远了吗. 提交于 2021-02-17 05:16:06
问题 I have a spring-boot application for which I am writing IT tests. The data for the tests comes from application-dev.properties when I activate dev profile Here is what I have for tests: @RunWith(SpringRunner.class) @SpringBootTest @WebAppConfiguration public class ApplicationTests { @Autowired Environment env; @Test public void contextLoads() { System.out.println(Arrays.toString((env.getActiveProfiles()))); } } ServiceITTest public class ServiceITTest extends ApplicationTests { @value String

Testing an Apache Kafka Integration within a Spring Boot Application with JUnit 5 and EmbeddedKafkaBroker

五迷三道 提交于 2021-02-11 13:01:49
问题 I have a simple producer class defined as follows: @Configuration public class MyKafkaProducer { private final static Logger log = LoggerFactory.getLogger(MyKafkaProducer.class); @Value("${my.kafka.producer.topic}") private String topic; @Autowired KafkaTemplate<String, String> kafkaTemplate; public void sendDataToKafka(@RequestParam String data) { ListenableFuture<SendResult<String, String>> listenableFuture = kafkaTemplate.send(topic, data); listenableFuture.addCallback(new

Test Spring batch with @JpaDataTest

∥☆過路亽.° 提交于 2021-02-11 12:32:33
问题 I'm using spring batch 4.0 and i'm trying to test my batch. I would use embedded database h2 with @JpaDataTest but it doesn't work. When i add this annotation i got error java.lang.IllegalStateException: Existing transaction detected in JobRepository. Please fix this and try again (e.g. remove @Transactional annotations from client). @Transaction(propagation=Propagation.NEW_REQUIRED) on the @Test dosen't work. I tried to copy every annotations from @JpaDataTest and remove @Transaction

Writing a JUnit test for a “Step” scoped bean - No scope registered for scope name “step” (Spring Batch 3.0.10)

蹲街弑〆低调 提交于 2021-02-11 08:09:09
问题 I want to write a JUnit test case for a Spring managed bean which has the scope as "step". This bean is refereed by a Spring Batch Tasklet. Bean defintion for configDAO ConfigDAOImpl class <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:batch="http://www.springframework.org/schema

Writing a JUnit test for a “Step” scoped bean - No scope registered for scope name “step” (Spring Batch 3.0.10)

走远了吗. 提交于 2021-02-11 08:06:03
问题 I want to write a JUnit test case for a Spring managed bean which has the scope as "step". This bean is refereed by a Spring Batch Tasklet. Bean defintion for configDAO ConfigDAOImpl class <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:batch="http://www.springframework.org/schema

Writing a JUnit test for a “Step” scoped bean - No scope registered for scope name “step” (Spring Batch 3.0.10)

一曲冷凌霜 提交于 2021-02-11 08:05:50
问题 I want to write a JUnit test case for a Spring managed bean which has the scope as "step". This bean is refereed by a Spring Batch Tasklet. Bean defintion for configDAO ConfigDAOImpl class <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:batch="http://www.springframework.org/schema