- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 RepositoryRestController
为一些持久实体公开资源。
我的 Controller 上有一个方法需要一个 PersistentEntityResourceAssembler
帮我自动生成资源。
@RepositoryRestController
@ExposesResourceFor(Customer.class)
@RequestMapping("/api/customers")
public class CustomerController {
@Autowired
private CustomerService service;
@RequestMapping(method = GET, value="current")
public ResponseEntity getCurrent(Principal principal Long id, PersistentEntityResourceAssembler assembler) {
return ResponseEntity.ok(assembler.toResource(service.getForPrincipal(principal)));
}
}
(人为的例子,但它节省了我的用例的不相关细节的过多细节)
我想为我的 Controller 编写一个测试(我的真实用例实际上值得测试),并计划使用@WebMvcTest。
所以我有以下测试类:
@RunWith(SpringRunner.class)
@WebMvcTest(CustomerController.class)
@AutoConfigureMockMvc(secure=false)
public class CustomerControllerTest {
@Autowired
private MockMvc client;
@MockBean
private CustomerService service;
@Test
public void testSomething() {
// test stuff in here
}
@Configuration
@Import(CustomerController.class)
static class Config {
}
}
但是我得到一个异常说 java.lang.NoSuchMethodException: org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.<init>()
大概是这里没有正确配置,因为我缺少整个数据层。有没有办法模拟 PersistentEntityResourceAssembler
?或者我可以在这里使用的另一种方法?
最佳答案
我现在结束了:
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
它的缺点是测试将启动完整的 Spring 应用程序上下文(但没有服务器)。
关于java - 测试使用 PersistentEntityResourceAssembler 的自定义 RepositoryRestController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46658333/
我正在使用 spring 框架,在下面的代码中我想获取用户的 session ,但是当我调用 API 时,它给了我一个错误,详细信息如下 Controller @Controller() public
我有一个 RepositoryRestController为一些持久实体公开资源。 我的 Controller 上有一个方法需要一个 PersistentEntityResourceAssembler
我正在使用 Spring Boot 2.1、Spring Data REST、Spring HATEOAS、Hibernate 5。 我正在寻找一种方法来过滤 REST 调用中的字段。我将使用http
你能帮我一下吗? 我尝试使用参数 PersistentEntityResourceAssembler 为 Restcontroller 实现 JUnit-Test。 这是我的 RestControll
我正在尝试向 RepositoryRestResource 自动生成的端点添加一些额外的业务逻辑。请看下面的代码: 资源: @RepositoryRestResource(collectionReso
我是一名优秀的程序员,十分优秀!