spring-boot-test

Spring boot: @ConfigurationProperties not satisfied on test

心已入冬 提交于 2020-01-13 07:11:14
问题 I'm getting this exception on my test excution: UnsatisfiedDependencyException: Error creating bean with name 'net.gencat.transversal.espaidoc.mongo.GridFSTest': Unsatisfied dependency expressed through field 'resourceProperties'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'net.gencat.transversal.espaidoc.ResourcesConfigProperties' available: expected at least 1 bean which qualifies as autowire candidate. So, I think message

Use spring.profiles.active=@profileActive@ in property file of test/resource folder

有些话、适合烂在心里 提交于 2020-01-06 05:30:20
问题 In my application I have three different profiles and their own property files. In my application.properties file the correct active profile will be set by the profile of my maven build: spring.profiles.active=@profileActive@ The maven profiles are dev , test and prod . The maven command looks like that: mvn clean install -Pdev for example. After the build, my active profile is set to dev . Now, I added also some property files to my test/resource folder to use @TestPropertySource for my

How can I combine @DataJpaTest @SpringBootTest in one MVC application for testing every layer?

泄露秘密 提交于 2020-01-05 05:30:27
问题 Here https://stackoverflow.com/a/52968130/10894456 is well explained why @DataJpaTest @SpringBootTest shouldn't be mixed in one application. But barely explained the case when anyway need to test every layer of MVC SpringBoot application (from my point it's natural to test not only one or only another layer but both and even all layers, isn't it?) So there was suggested a solution to use @AutoConfigureTestDatabase rather than @DataJpaTest but didn't finish the job ((( So my question is: is

@WithUserDetails does not seem to work

你离开我真会死。 提交于 2020-01-02 08:39:10
问题 I have an application in which I use Spring Social Security for authentication and authorization. Unfortunately I am having some problems with mocking Spring Security. It seems that it does not work at all. I have a REST controller that returns 404 Not Found if the identifier of the entity it should return is not available. If the user is not logged in then any page redirects to the social login page of my app. I have read here that the @WithUserDetails annotation would suit me the best. So

@DataJpaTest does't work with @GenericGenerator

蓝咒 提交于 2019-12-25 01:26:38
问题 I tried to test my repository with the @DataJpaTest annotation but something strange appears. When I use a classic @GeneratedValue every thing is OK, my test succeed. But when I use the generator bellow my test failed. The test createCountry_should_succeed succeed but the others don't because no exceptions on Valitation on constraint are throw. @GeneratedValue(generator = "UUID") @GenericGenerator(name = "UUID", strategy = "com.example.demojpa.CustomIdentifierGenerator") For exemple here one

Springboot and maven: how to launch unit tests automatically with two profiles

匆匆过客 提交于 2019-12-25 01:09:41
问题 This question is the continuation of question "SpringBoot: how to run tests twice, with two different config files". I use to compile my project using mvn clean install . Doing that, maven also launches my unit tests and I immediately knows whether my development is correct. I am actually working on a module that embeds a JMS connection. my module supports two JMS buses: EMS and AMQ. The bus to be used is specified in the configuration of my module As a consequence, I need to create two

Spring boot test - No qualifying bean of type 'com.example.MyService' available

南笙酒味 提交于 2019-12-24 16:23:22
问题 There are a number of similar questions on stackoverflow, but I found none to be my case. In my integration test with Spring boot 2.0.2.RELEASE , I created a separate @Configuration class for the test where I did define the bean com.example.MyService . This bean happens to be used by some other bean in com.example.OtherBean . Here is the code: Test class: @RunWith(SpringRunner.class) @SpringBootTest(classes = {MyIntegrationTestConfig.class}, webEnvironment = SpringBootTest.WebEnvironment.MOCK

Can you get Spring Boot JUnit tests to use the same server?

一世执手 提交于 2019-12-24 07:16:09
问题 I have some Spring Boot JUnit tests that require a somewhat lengthy server start up (I'm loading a complex domain in JPA). I've put them into a test suite, but each test kicks off a new server start up. Is it possible to set them up in such a way that the server is only started once and each test is loaded onto it and run as if the server were started by the test itself? 回答1: Okay, so the solution here is actually built in to Spring testing. That is, it caches ApplicationContexts for tests,

Exclude ApplicationStartup Event listener when testing

北城余情 提交于 2019-12-24 06:46:19
问题 I recently added an ApplicationStartup class to my SpringBoot project @Component public class ApplicationStartup implements ApplicationListener<ApplicationReadyEvent> { ... It implements ApplicationListener. Now when I run my old JUNit tests that have nothing to do with that class, The testrunner tries to Run my StartupListener, which is neither necessary not appropriate in these cases. How do I skip the ApplicationListener when my tests initialize? @RunWith(SpringRunner.class)

Attribute ServerContainer not found in ServletContext

假如想象 提交于 2019-12-23 04:43:43
问题 In my Spring boot application i use also websockets. Everything works fine, as expected in production. Now i started to create UnitTests with Spring-Boot-Test. Every time i start a @SpringBootTest , i get following exception (shortened): java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createWebSocketContainer' defined in class path resource [com/package/spring/ws