I'm trying to write a test case that checks whether a document was pushed into the SOLR index. The problem is, the assertion is failing because the transaction hasn't been committed. The database assertions are fine, they respond with the right rowcounts before the rollback. But I'm getting 0 count on the documents in SOLR, I presume because when I query the index, the previous document wouldn't have been committed into the index yet.
All conditions pass in this test, except the last one, which returns 0 count.
Can anyone suggest how I can implement this test to take into account transaction boundary management with SOLR and rollback requirements?
@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());
}