spring-test

javax.validation.ValidationException: HV000183: Unable to initialize 'javax.el.ExpressionFactory' when using WebTestClient

佐手、 提交于 2019-12-11 17:56:31
问题 I am trying to write an integration test with WebTestClient that will only standup the controller I'm testing with a WebTestClient to make the requests. On starting a test, I get this in the console: 14:33:50.435 [main] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.9.Final 14:33:50.442 [main] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2

Correctly define path to test properties using @TestPropertySource (Spring Boot 2)

半腔热情 提交于 2019-12-11 17:35:18
问题 I have a following hierarchy in my Spring Boot 2 test folder test/ java/ package.name/ SpringBootTest.java resources/ test.properties SpringBootTest has a code like @RunWith (SpringRunner.class) @TestPropertySource(locations = {"/resources/test.properties"}) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"management.port=0"}) public class SwaggerExtractorTest { ... } I also tried to use locations = {"test.properties"} with the file located just next

Why is my Spring JUnit Test Rule not running?

扶醉桌前 提交于 2019-12-11 10:23:48
问题 I've been struggling to find an obvious solution to why the linked code will not run JUnit TestRules. I've created a success case where TestRules execute, and a failure case that shows a situation where TestRules fail. Is anybody able to see why the TestRules are not being picked up? It's not just Spring's TestRule not being picked up. It seems to be all TestRules, as demonstrated by MyTestRule.java in the source code. Running mvn clean install on the success case, will see all tests passing.

Define spring property values in Java

雨燕双飞 提交于 2019-12-11 08:59:47
问题 I have some spring beans which wire in property values using the @Value annotation. e.g. @Value("${my.property}") private String myField; Usually the values are sourced from property files. The test I am currently writing uses a fully annotation based configuration. e.g. @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader=AnnotationConfigContextLoader.class) public class AcceptanceTest implements ApplicationContextInitializer<ConfigurableApplicationContext> { @Configuration

How to mock BindingResult in Spring Boot Test

不想你离开。 提交于 2019-12-11 07:58:12
问题 I have the following controller: @RestController @RequestMapping(value = ROOT_MAPPING) public class GatewayController { @Autowired private RequestValidator requestValidator; @InitBinder protected void initBinder(WebDataBinder binder) { binder.addValidators(requestValidator); } @PostMapping(value = REDIRECT_MAPPING) public ResponseEntity<ResponseDTO> redirectEndpoint(@Validated @RequestBody RequestDTO requestDTO, BindingResult result) { if (result.hasErrors()) { // Handle validation errors

Spring doesn't autowire fields when runner invokes '@Before' method

不问归期 提交于 2019-12-11 07:33:28
问题 I have following test: @RunWith(Parameterized.class) @SpringBootTest @ContextConfiguration(classes = MyConfig.class) public class OrderPlacementCancelTest { @Autowired private TestSessionsHolderPerf sessionsHolder; @ClassRule public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule(); @Rule public final SpringMethodRule springMethodRule = new SpringMethodRule(); private CommonCredentialSetter commonCredentialSetter; @Before public void login() throws InterruptedException {

MockMvc to test SpringMVC Rest Web Service using JUnit, Mockito, and Hamcrest

有些话、适合烂在心里 提交于 2019-12-11 05:49:51
问题 Am using Spring MVC to create Restful Web Services... Here's my pom.xml: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.0.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.0.3.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.0.3.RELEASE</version> <

@TestPropertySource not working?

雨燕双飞 提交于 2019-12-11 03:38:14
问题 I am trying to test my Spring Configuration. Here is my config class @Configuration @PropertySource("/etc/my.properties") @ComponentScan("my.package") public class SpringConfig { @Bean ..... } And when I tried to test it thru my test as @RunWith(SpringJUnit4ClassRunner.class) @TestPropertySource(locations = "classpath:test.properties") @ContextConfiguration(classes = {SpringConfigIntTest.class, SpringConfig.class}) public class SpringConfigIntTest { ....... } I keep getting the failure saying

How to use MockRestServiceServer with multiple URLs?

那年仲夏 提交于 2019-12-11 03:25:08
问题 I need to configure multiple expectations on an instance of MockRestServiceServer. The expectations are for two different URLs: Call URL #1 Call URL #1 (for a second time) Call URL #2 The same URL is called twice, then a 3rd call is made to the same URL with different request params. I have one instance of a load-balanced RestTemplate available to inject into my test, and I pass this to MockRestServiceServer.createServer(). I've tried to inline these 3 expectations to my MockRestServiceServer

HSQLDB Trigger Statement ERROR when using SimpleJdbcTestUtils.executeSqlScript()

夙愿已清 提交于 2019-12-11 00:06:25
问题 I'm currently trying to load a sql script to create a HSQL database. This is done by using the following code: Resource resource = new ClassPathResource("/create-table.sql"); SimpleJdbcTestUtils.executeSqlScript(template, resource, Boolean.FALSE); The script contains the create statement of a trigger: CREATE TRIGGER t BEFORE UPDATE ON SUBJECTS REFERENCING NEW AS newrow OLD AS oldrow FOR EACH ROW BEGIN ATOMIC SET newrow.VERSION = oldrow.VERSION + 1; END; When running the tests using this code,