use of org.springframework.test.annotation.Rollback in project spring-data-document-examples by spring-projects.
the class CustomerRepositoryTests method testInsertOneEntity.
@Transactional
@Rollback(false)
@Test
public void testInsertOneEntity() {
Customer c = new Customer();
c.setFirstName("Sven");
c.setLastName("Olafsen");
SurveyInfo surveyInfo = new SurveyInfo();
Map<String, String> qAndA = new HashMap<String, String>();
qAndA.put("age", "22");
qAndA.put("married", "Yes");
qAndA.put("citizenship", "Norwegian");
surveyInfo.setQuestionsAndAnswers(qAndA);
c.setSurveyInfo(surveyInfo);
customerRepository.save(c);
Assert.assertNotNull(c.getId());
idUsed = c.getId();
}
use of org.springframework.test.annotation.Rollback in project spring-data-document-examples by spring-projects.
the class CustomerRepositoryTests method testDeleteOneEntity.
@Transactional
@Rollback(false)
@Test
public void testDeleteOneEntity() {
Customer c = customerRepository.findOne(idUsed);
customerRepository.delete(c);
}
use of org.springframework.test.annotation.Rollback in project spring-data-document-examples by spring-projects.
the class CustomerRepositoryTests method testCheckOneEntityIsGone.
@Transactional
@Rollback(false)
@Test
public void testCheckOneEntityIsGone() {
Customer c = customerRepository.findOne(idUsed);
Assert.assertNull(c);
}
use of org.springframework.test.annotation.Rollback in project spring-data-document-examples by spring-projects.
the class CustomerRepositoryTests method testUpdateOneEntity.
@Transactional
@Rollback(false)
@Test
public void testUpdateOneEntity() {
Customer c = customerRepository.findOne(idUsed);
Assert.assertNotNull(c);
c.setLastName("Nilsson");
}
use of org.springframework.test.annotation.Rollback in project spring-framework by spring-projects.
the class TransactionalTestExecutionListener method isDefaultRollback.
/**
* Determine whether or not to rollback transactions by default for the
* supplied {@linkplain TestContext test context}.
* <p>Supports {@link Rollback @Rollback} or {@link Commit @Commit} at the
* class-level.
* @param testContext the test context for which the default rollback flag
* should be retrieved
* @return the <em>default rollback</em> flag for the supplied test context
* @throws Exception if an error occurs while determining the default rollback flag
*/
protected final boolean isDefaultRollback(TestContext testContext) throws Exception {
Class<?> testClass = testContext.getTestClass();
Rollback rollback = AnnotatedElementUtils.findMergedAnnotation(testClass, Rollback.class);
boolean rollbackPresent = (rollback != null);
if (rollbackPresent) {
boolean defaultRollback = rollback.value();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Retrieved default @Rollback(%s) for test class [%s].", defaultRollback, testClass.getName()));
}
return defaultRollback;
}
// else
return true;
}
Aggregations