我想为Jhipster中的duplicatingRow()
方法编写测试。
Customer1已经在表中如果我需要复制它,则所有属性都应具有相同的值,但id
除外。 id是在此处自动生成的。
我的方法是
@PostMapping("/duplicatingRow")
@Timed
public ResponseEntity<Customer> duplicatingRow(@RequestBody Customer customer) throws URISyntaxException {
Optional<Customer> duplicatecustomer = customerRepository.findById(customer.getId());
Customer custom = duplicatecustomer.get();
custom.setId(null);
Customer result = customerRepository.save(custom);
return ResponseEntity.ok().build();
我的测试用例是
@Test
@Transactional
public void duplicateCustomer() throws Exception {
// Initialize the database
customerRepository.saveAndFlush(customer);
int databaseSizeBeforeUpdate = customerRepository.findAll().size();
restCustomerMockMvc.perform(post("/api/duplicatecustomers")
.contentType(TestUtil.APPLICATION_JSON_UTF8)
.content(TestUtil.convertObjectToJsonBytes(customer)))
.andExpect(status().isOk()).andDo(print());
// Validate the Customer in the database
List<Customer> customerList = customerRepository.findAll();
assertThat(customerList).hasSize(databaseSizeBeforeUpdate +1);
Customer testCustomer1 = customerList.get(customerList.size() -1);
System.out.print("test pro is"+testCustomer1);
}
但是,如果我运行测试用例时遇到错误,它将使原始客户ID变为NULL。我不知道要不要如何在不影响原始行的情况下创建新的重复行?