spring-test

Hibernate OnDelete cascade in test doesn't work

一笑奈何 提交于 2020-08-26 08:47:05
问题 I have one-directional related entities: @Entity public class Book { private String isbn; } @Entity private class Recommentation { @ManyToOne(optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "book_id", nullable = false) @OnDelete(action = OnDeleteAction.CASCADE) private Book book; } And the following test: @RunWith(SpringRunner.class) @DataJpaTest public class BookRepositoryTest { @Autowired private TestEntityManager testEntityManager; @Autowired private BookRepository

JDK 9: JUnit 5 test compile with SpringExtension produces java.lang.NoClassDefFoundError: org/w3c/dom/ls/DocumentLS

爷,独闯天下 提交于 2020-07-28 19:05:29
问题 I believe this problem not to be related to module exclusions in JDK 9 (as with java.se.ee), but rather with the fact that JDK 9 includes a newer version of org.w3c.dom.ls in the java.xml module that does not have the DocumentLS class. The important bit of the stack trace is this: Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [spring-test/test-container.xml]; nested exception is java.lang

org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/json;charset=UTF-8' not supported

旧街凉风 提交于 2020-07-18 04:45:43
问题 The error show up when My code like this: @Test public void getTemplateByIdTest() throws Exception { client.get().uri("/template/getTemplate/7") .exchange() .expectStatus().isOk() .expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8) .expectBody(VtTemplateVO.class) .returnResult(); } When I change my code like this,it's ok! @Test public void getTemplateByIdTest() throws Exception { client.get().uri("/template/getTemplate/7") .exchange() .expectStatus().isOk() .expectHeader()

Spring Boot DataJpaTest fail with java.lang.IllegalStateException:Caused by: Given type must be an interface

你说的曾经没有我的故事 提交于 2020-06-22 04:26:36
问题 To be precise depends on what error I have. If I go with Intellij Maven Install, I get this exception (which is strange because I have this dependency and it should be by default in spring-starter-test if I am not wrong): Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.turbo.TurboFilter But if I start test directly in problematic test class I get this exception: o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework

Why does my flapdoodle Embedded MongoDB test fail to run? (creating 'embeddedMongoServer' could not start process EOF)

陌路散爱 提交于 2020-05-26 12:10:34
问题 I'm having trouble getting my brand new project to build. I used https://start.spring.io/ to generate a fresh new Spring 2.0 MongoDB Maven project, and I want to have an embedded MongoDB database for my integration tests. The spring initializer added a dependency for de.flapdoodle.embed.mongo to that end. But every time I try to run a "mvn clean package", I get the following error during my test: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name

How do I set up a Spring Data Neo4j integration test with JUnit 5 (in Kotlin)?

雨燕双飞 提交于 2020-03-16 08:10:13
问题 Most examples around the Web for doing Spring integration tests with Neo4j are still on JUnit 4, and use the Neo4jRule. How do we create a setup for Neo4j + Spring + JUnit 5? 回答1: If you are testing on embedded, please use the Test Harness with a simple Spring Configuration. Here are some examples: https://medium.com/neo4j/testing-your-neo4j-based-java-application-34bef487cc3c https://github.com/michael-simons/neo4j-sdn-ogm-tips/tree/master/examples/using-the-test-harness https://github.com

How do I set up a Spring Data Neo4j integration test with JUnit 5 (in Kotlin)?

让人想犯罪 __ 提交于 2020-03-16 08:08:10
问题 Most examples around the Web for doing Spring integration tests with Neo4j are still on JUnit 4, and use the Neo4jRule. How do we create a setup for Neo4j + Spring + JUnit 5? 回答1: If you are testing on embedded, please use the Test Harness with a simple Spring Configuration. Here are some examples: https://medium.com/neo4j/testing-your-neo4j-based-java-application-34bef487cc3c https://github.com/michael-simons/neo4j-sdn-ogm-tips/tree/master/examples/using-the-test-harness https://github.com

Spring Testing: How to enable auto-scan of beans

烈酒焚心 提交于 2020-02-20 06:41:05
问题 For example, now in each test class I have to do @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader=AnnotationConfigContextLoader.class) I want to get rid of @ContextConfiguration(loader=AnnotationConfigContextLoader.class) and want Spring to scan all the beans in my project. How can I do that? 回答1: If you have your spring configuration in an xml file you would use something like: @ContextConfiguration(locations="classpath:applicationContext.xml") If you use Java Config then