我正在尝试编写一个测试用例来检查文档是否被推送到 SOLR 索引中。问题是,断言失败是因为事务尚未提交。数据库断言很好,它们在回滚之前以正确的行数响应。但是我在 SOLR 中的文档计数为 0,我想是因为当我查询索引时,以前的文档还没有提交到索引中。
所有条件都通过了这个测试,除了最后一个,它返回 0 个计数。
谁能建议我如何实施此测试以考虑具有 SOLR 和回滚要求的事务边界管理?
@Test
@Sql(scripts = {"classpath:test/sql/customers/delete_customer.sql"})
@Rollback
public void testSubmitSubscriberRegistration() throws Exception{
logger.entry();
final String email="Billy.Evans@mailinator.com";
int orig = JdbcTestUtils.countRowsInTable(jdbcTemplate, "customers");
MvcResult result = this.mockMvc.perform(post("/ajax/customers/register")
.param("firstName", "Bill")
.param("lastName", "Evans")
.param("preferredName", "Billy")
.param("email", email)
.param("subscriber", "true")
)
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.object.id", Matchers.notNullValue()))
.andReturn();
logger.debug(result.getResponse().getContentAsString());
Assert.assertEquals(JdbcTestUtils.countRowsInTable(jdbcTemplate, "customers"), orig+1);
Assert.assertEquals(JdbcTestUtils.countRowsInTable(jdbcTemplate, "customer_roles"), orig+1);
Mockito.verify(mockCustomerNotifier, Mockito.times(1)).sendRegistrationConfirmation(Mockito.any(Customer.class), Mockito.anyString());
// now we do a quick confirmation of the state of the user.
Customer customer = customerAccountService.findByEmail(email);
Assert.assertNotNull(customer);
Assert.assertTrue(customer.isSubscriber());
Assert.assertEquals(customer.getFirstName(), "Bill");
Assert.assertEquals(customer.getLastName(), "Evans");
Assert.assertEquals(customer.getEmail(), email);
boolean found = false;
for (Role role: customer.getRoles())
{
if (role.getCode().equals("REGISTERED_CUSTOMER")){
found = true;
}
}
Assert.assertTrue(found);
// now we have to verify the search indexes were updated with the customer details.
Assert.assertNotNull(customerDocumentRepository);
List<CustomerDocument> customerDocuments = customerDocumentRepository.findByEmail(email);
Assert.assertEquals(1, customerDocuments.size());
}