场景:
SpringBoot执行器:
@SpringBootApplication
@EntityScan(basePackages = "io.sciro.leaderdata.domain")
@ComponentScan(basePackages = {"io.sciro.leaderdata.config", "io.sciro.leaderdata.repo", "io.sciro.leaderdata.domain", "io.sciro.leaderdata.controller"})
public class LeaderDataApp {
public static void main(String[] args) {
SpringApplication.run(LeaderDataApp.class, args);
}
}
实体:
@Data
@NodeEntity(label = "match")
@JsonIdentityInfo(generator = JSOGGenerator.class, property = "id")
public class Match implements IdStrategy {
@Id
@GeneratedValue
private Long id;
private String codeName;
private Long round;
private String me;
private String pc;
private Character result;
@JsonFormat(pattern = "MMM dd, yyyy, HH:mm:ss a")
private Date timestamp;
@JsonFormat(pattern = "MMM dd, yyyy, HH:mm:ss a")
@LastModifiedDate
private Date lastUpdated;
@JsonFormat(pattern = "MMM dd, yyyy, HH:mm:ss a")
@CreatedDate
private Date created;
@Override
public String toString() {
return "Match{" +
"id=" + id +
", codeName='" + codeName + '\'' +
", round=" + round +
", me='" + me + '\'' +
", pc='" + pc + '\'' +
", result=" + result +
", timestamp=" + timestamp +
", lastUpdated=" + lastUpdated +
", created=" + created +
'}';
}
/**
* Generates new id for given entity
*
* @param entity saved entity
* @return identifier of the entity
*/
@Override
public Object generateId(Object entity) {
return null;
}
}
回购:
@RepositoryRestResource(path = "matches", collectionResourceRel = "matches")
public interface MatchRepo extends Neo4jRepository<Match, Long> {
Collection<Match> findAllByCodeName(@Param("codeName") String codeName);
}
配置类。一个用于Live,另一个用于Dev / Test。
@Profile("dev")
@Configuration
@EnableNeo4jRepositories(basePackages = "io.sciro.leaderdata.repo")
@EntityScan(basePackages = "io.sciro.leaderdata.domain")
@EnableTransactionManagement
public class DevConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(DevConfig.class);
//Values Injected in the Live-Config: @Value("${spring.data.neo4j.uri}")
private final String uri = "bolt://localhost:7687";
private final String username = "neo4j";
private final String password = "password";
@Bean
public SessionFactory sessionFactory() {
// with domain entity base package(s)
return new SessionFactory(configuration(), "io.db.accountservice.domain");
}
@Bean
public org.neo4j.ogm.config.Configuration configuration() {
LOGGER.debug("URI: \n\n\nuri: {}\n\n\n", uri);
return new org.neo4j.ogm.config.Configuration
.Builder()
.uri(uri)
.credentials(username, password)
.build();
}
@Bean
public Neo4jTransactionManager transactionManager() {
return new Neo4jTransactionManager(sessionFactory());
}
}
在执行SpringBoot应用程序时,我会卷曲,得到积极的回应:
通过unix-terminal发布:
curl -i -X POST -H "Content-Type:application/json" -d '{"codeName":"Test-CodeName-1","round":1,"me":"ROCK","pc":"ROCK","result":"D","lastUpdated":"Nov 19, 2018, 9:44:11 PM","created":"Nov 19, 2018, 9:44:11 PM"}' http://localhost:8003/spring-data/api/v1/matches
响应:
HTTP/1.1 201
Last-Modified: Mon, 19 Nov 2018 09:44:11 GMT
Location: http://localhost:8003/spring-data/api/v1/matches/2
Content-Type: application/hal+json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 20 Nov 2018 08:52:52 GMT
{
"id" : "1",
"codeName" : "Test-CodeName-1",
"round" : 1,
"me" : "ROCK",
"pc" : "ROCK",
"result" : "D",
"timestamp" : null,
"lastUpdated" : "Nov 19, 2018, 09:44:11 AM",
"created" : "Nov 19, 2018, 09:44:11 AM",
"_links" : {
"self" : {
"href" : "http://localhost:8003/spring-data/api/v1/matches/2"
},
"match" : {
"href" : "http://localhost:8003/spring-data/api/v1/matches/2"
}
}
}%
通过UNIX终端获取:
curl -i -X GET http://localhost:8003/spring-data/api/v1/matches/2
响应:
HTTP/1.1 200
Last-Modified: Mon, 19 Nov 2018 09:44:11 GMT
Content-Type: application/hal+json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 20 Nov 2018 11:19:14 GMT
{
"id" : "1",
"codeName" : "Test-CodeName-1",
"round" : 1,
"me" : "ROCK",
"pc" : "ROCK",
"result" : "D",
"timestamp" : null,
"lastUpdated" : "Nov 19, 2018, 09:44:11 AM",
"created" : "Nov 19, 2018, 09:44:11 AM",
"_links" : {
"self" : {
"href" : "http://localhost:8003/spring-data/api/v1/matches/2"
},
"match" : {
"href" : "http://localhost:8003/spring-data/api/v1/matches/2"
}
}
}%
测试用例:
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@WebAppConfiguration(value = "classpath:bootstrap.yml")
@SpringBootTest(classes = LeaderDataApp.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@ExtendWith(SpringExtension.class)
@ActiveProfiles("dev")
public class MatchRepoTest {
private static final Logger LOGGER = LoggerFactory.getLogger(MatchRepoTest.class);
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
private static final String TEST_NAME = "Test-CodeName-1";
@BeforeAll
public static void setup(){
LOGGER.info("Testing MatchRepo...");
}
@AfterAll
public static void teardown(){
LOGGER.info("Completed MatchRepo tests...");
}
@BeforeEach
public void setUp() {
this.mockMvc = webAppContextSetup(wac).build();
}
@Test
public void matchRepoTest_1_saveNewMatch() throws Exception {
final Date date = new Date();
final Gson gson = new Gson();
final Match match = new Match();
match.setCodeName(TEST_NAME);
match.setCreated(date);
match.setLastUpdated(date);
match.setMe("ROCK");
match.setPc("ROCK");
match.setResult('D');
match.setRound(1L);
final String payload = gson.toJson(match);
LOGGER.debug("Match: "+ payload);
// {"codeName":"Test-CodeName-1","round":1,"me":"ROCK","pc":"ROCK","result":"D","lastUpdated":"Nov 19, 2018, 9:44:11 PM","created":"Nov 19, 2018, 9:44:11 PM"}
mockMvc.perform(post(APP_BASE_URL+"/matches")
.content(payload)
.contentType(MediaType.APPLICATION_JSON)).andDo(print())
.andExpect(status().isCreated());
}
@Test
public void matchRepoTest_2_findById() throws Exception {
mockMvc.perform(get(APP_BASE_URL+"/matches/20")
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect((ResultMatcher) jsonPath("$.codeName", is(TEST_NAME)));
}
}
现在,当我尝试使用Jupiter执行集成测试时,挑战就来了。我的测试失败,出现了奇怪的stacktrace,这对我来说意义不大。错误消息:
"Class class io.sciro.leaderdata.domain.Match is not a valid entity class. Please check the entity mapping."
没什么意思。其他人知道这意味着什么吗?
2018-11-20 02:48:36.377 INFO 18036 --- [ main] o.s.b.t.m.w.SpringBootMockServletContext : Initializing Spring TestDispatcherServlet ''
2018-11-20 02:48:36.377 INFO 18036 --- [ main] o.s.t.web.servlet.TestDispatcherServlet : Initializing Servlet ''
2018-11-20 02:48:36.393 INFO 18036 --- [ main] o.s.t.web.servlet.TestDispatcherServlet : Completed initialization in 16 ms
2018-11-20 02:48:36.599 INFO 18036 --- [ main] Driver : Driver instance org.neo4j.driver.internal.InternalDriver@620992a8 created
2018-11-20 02:48:36.972 ERROR 18036 --- [ main] o.s.d.r.w.RepositoryRestExceptionHandler : Class class io.sciro.leaderdata.domain.Match is not a valid entity class. Please check the entity mapping.
java.lang.IllegalArgumentException: Class class io.sciro.leaderdata.domain.Match is not a valid entity class. Please check the entity mapping.
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:97) ~[neo4j-ogm-core-3.1.3.jar:3.1.3]
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:46) ~[neo4j-ogm-core-3.1.3.jar:3.1.3]
at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:463) ~[neo4j-ogm-core-3.1.3.jar:3.1.3]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.data.neo4j.transaction.SharedSessionCreator$SharedSessionInvocationHandler.invoke(SharedSessionCreator.java:122) ~[spring-data-neo4j-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at com.sun.proxy.$Proxy134.save(Unknown Source) ~[na:na]
at org.springframework.data.neo4j.repository.support.SimpleNeo4jRepository.save(SimpleNeo4jRepository.java:72) ~[spring-data-neo4j-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359) ~[spring-data-commons-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) ~[spring-data-commons-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644) ~[spring-data-commons-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608) ~[spring-data-commons-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-tx-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at com.sun.proxy.$Proxy144.save(Unknown Source) ~[na:na]
at org.springframework.data.repository.support.CrudRepositoryInvoker.invokeSave(CrudRepositoryInvoker.java:101) ~[spring-data-commons-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory$UnwrappingRepositoryInvoker.invokeSave(UnwrappingRepositoryInvokerFactory.java:176) ~[spring-data-rest-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.data.rest.webmvc.RepositoryEntityController.createAndReturn(RepositoryEntityController.java:480) ~[spring-data-rest-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.data.rest.webmvc.RepositoryEntityController.postCollectionResource(RepositoryEntityController.java:272) ~[spring-data-rest-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:207) ~[spring-web-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800) ~[spring-webmvc-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) ~[spring-webmvc-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998) [spring-webmvc-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:901) [spring-webmvc-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875) [spring-webmvc-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:71) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.12.jar:9.0.12]
at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:166) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:133) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:182) [spring-test-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at io.sciro.leaderdata.repo.MatchRepoTest.matchRepoTest_1_saveNewMatch(MatchRepoTest.java:101) [classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:515) [junit-platform-commons-1.3.1.jar:1.3.1]
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115) [junit-jupiter-engine-5.3.1.jar:5.3.1]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:171) [junit-jupiter-engine-5.3.1.jar:5.3.1]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:167) [junit-jupiter-engine-5.3.1.jar:5.3.1]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:114) [junit-jupiter-engine-5.3.1.jar:5.3.1]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:59) [junit-jupiter-engine-5.3.1.jar:5.3.1]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:105) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:95) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:71) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1378) ~[na:na]
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:110) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:95) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:71) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1378) ~[na:na]
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:110) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:95) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:71) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) ~[junit-platform-engine-1.3.1.jar:1.3.1]
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220) ~[junit-platform-launcher-1.3.1.jar:1.3.1]
at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188) ~[junit-platform-launcher-1.3.1.jar:1.3.1]
at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202) ~[junit-platform-launcher-1.3.1.jar:1.3.1]
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181) ~[junit-platform-launcher-1.3.1.jar:1.3.1]
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128) ~[junit-platform-launcher-1.3.1.jar:1.3.1]
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:74) ~[junit5-rt.jar:na]
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) ~[junit-rt.jar:na]
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) ~[junit-rt.jar:na]
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) ~[junit-rt.jar:na]
2018-11-20 02:48:36.987 WARN 18036 --- [ main] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [java.lang.IllegalArgumentException: Class class io.sciro.leaderdata.domain.Match is not a valid entity class. Please check the entity mapping.]
MockHttpServletRequest:
HTTP Method = POST
Request URI = /spring-data/api/v1/matches
Parameters = {}
Headers = {Content-Type=[application/json]}
Body = <no character encoding set>
Session Attrs = {}
Handler:
Type = org.springframework.data.rest.webmvc.RepositoryEntityController
Method = public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryEntityController.postCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.PersistentEntityResource,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler,java.lang.String) throws org.springframework.web.HttpRequestMethodNotSupportedException
Async:
Async started = false
Async result = null
Resolved Exception:
Type = java.lang.IllegalArgumentException
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 500
Error message = null
Headers = {Content-Type=[application/json;charset=UTF-8]}
Content type = application/json;charset=UTF-8
Body = {"cause":null,"message":"Class class io.sciro.leaderdata.domain.Match is not a valid entity class. Please check the entity mapping."}
Forwarded URL = null
Redirected URL = null
Cookies = []
java.lang.AssertionError: Status expected:<201> but was:<500>
Expected :201
Actual :500
<Click to see difference>
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:55)
at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:82)
at org.springframework.test.web.servlet.result.StatusResultMatchers.lambda$matcher$9(StatusResultMatchers.java:619)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:195)
at io.sciro.leaderdata.repo.MatchRepoTest.matchRepoTest_1_saveNewMatch(MatchRepoTest.java:104)
答案 0 :(得分:0)
我发现了问题。在我的配置类中,SessionFactory参数中的第二个参数不正确:
@Bean
public SessionFactory sessionFactory() {
// with domain entity base package(s)
return new SessionFactory(configuration(), "io.db.accountservice.domain");
}
应该是:
@Bean
public SessionFactory sessionFactory() {
// with domain entity base package(s)
return new SessionFactory(configuration(), "io.sciro.leaderdata.domain");
}