spring-boot-test

Spring boot with WebFlux always throw 403 status in tests

妖精的绣舞 提交于 2020-12-05 11:48:25
问题 Great thx for viewing my question) I have some strange subject: my spring boot tests don't work. They start successfully but always throwing 403 HTTP status when making the requests to any controller I have some project with next dependencies: buildscript { ext.kotlin_version = '1.3.71' dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.71" classpath "org.springframework.boot:spring-boot-gradle-plugin:2.2.1.RELEASE" classpath "com.google.cloud.tools.jib:com.google.cloud

Spring boot @DataJpaTest exclude filter doesn't work

有些话、适合烂在心里 提交于 2020-08-08 05:24:47
问题 I Have this test: @RunWith(SpringRunner.class) @DataJpaTest(excludeFilters = @Filter(type = FilterType.REGEX, pattern = "io\\.rainrobot\\.adwisdom\\.repository\\.es\\..*")) public class AskTest { that should not scan repositories in this packege: io.rainrobot.adwisdom.repository.ex.* - but when i run the test i get this error: Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract org.springframework.data.domain.Page io.rainrobot.adwisdom.repository

Unit Test For Websocket Returns Null

旧巷老猫 提交于 2020-07-22 06:27:11
问题 I am trying to implement unit test for a Websocket in Springboot with JUnit . I am following this link and it runs fine but gets null in the result, when i test my websocket with a browser it sends the desire results. let me show my test class @ExtendWith(SpringExtension.class) @SpringBootTest(classes =Main.class) @WebAppConfiguration public class WebSocketTest { static final String WEBSOCKET_URI = "http://localhost:8080/api/realtimedata"; static final String WEBSOCKET_TOPIC = "/realtimedata"

Spring Cloud Contract - is it Consumer Driven?

泪湿孤枕 提交于 2020-07-18 20:46:34
问题 I'm just starting with Consumer-Driven Contracts for our microservice setup, and as they are mainly Spring Boot apps natural choice is Spring Cloud Contract. But then comes the confusion. In all examples in docs contracts are defined on the producer side, and consumer retrieves them from maven repo. How it is consumer-driven if the producer defines them? My understanding was that conceptually consumer defines them as its expectation from the producer for part of the API it uses. In addition

Spring Cloud Contract - is it Consumer Driven?

六月ゝ 毕业季﹏ 提交于 2020-07-18 20:43:34
问题 I'm just starting with Consumer-Driven Contracts for our microservice setup, and as they are mainly Spring Boot apps natural choice is Spring Cloud Contract. But then comes the confusion. In all examples in docs contracts are defined on the producer side, and consumer retrieves them from maven repo. How it is consumer-driven if the producer defines them? My understanding was that conceptually consumer defines them as its expectation from the producer for part of the API it uses. In addition

How to enable JPA auditing with SpringBootTest?

蓝咒 提交于 2020-07-10 07:58:23
问题 I want to write integration tests for my RestAPI endpoints, and I'm struggling with @EnableJpaAuditing. I want some of my entities to be audited by Spring, so I've created the following configuration class: @Configuration @EnableJpaAuditing public class PersistenceAuditConfiguration { } Which I import into my main application config: @ServletComponentScan @SpringBootApplication @Import(PersistenceAuditConfiguration.class) public class TMTWebApplication { public static void main(String[] args)

Difference between webEnvironment = RANDOM_PORT and webEnvironment = MOCK

半城伤御伤魂 提交于 2020-07-07 05:40:45
问题 I wrote spring boot integration test and it is working. Here is the test config: @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @AutoConfigureMockMvc @Transactional public class SomeTest { @Autowired private MockMvc mvc; @Test public void insertEventTest(){ ...testing something... } } I understand that when setting webEnvironment = RANDOM_PORT spring will initialize an embedded web server and run this test against that web server. I take a look at logs when running

Unable to start ReactiveWebApplicationContext due to missing ReactiveWebServerFactory bean

♀尐吖头ヾ 提交于 2020-07-06 06:11:31
问题 I have a new springboot application I am attempting to get started. The error I receive is org.springframework.context.ApplicationContextException: Unable to start reactive web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ReactiveWebApplicationContext due to missing ReactiveWebServerFactory bean. at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:76) ~

Is there a way to pass docker flags in GenericContainer from test containers

梦想的初衷 提交于 2020-06-29 04:31:25
问题 Is there a way to pass those flags from this command in GenericContainer object from test-containers lib ? docker container run \ --publish 9092:9082 \ --detach \ --name h2 \ nemerosa/h2 @ClassRule public static GenericContainer h2db = new GenericContainer("nemerosa/h2") .withStartupTimeout(Duration.ofSeconds(Constants.TIMEOUT_DURATION)); 回答1: For exposing ports, Testcontainers offers a method on the GenericContainer : @ClassRule public static GenericContainer h2db = new GenericContainer(