Search in sources :

Example 1 with Rollback

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();
}
Also used : Customer(org.springframework.data.mongodb.examples.custsvc.domain.Customer) HashMap(java.util.HashMap) SurveyInfo(org.springframework.data.mongodb.examples.custsvc.domain.SurveyInfo) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Rollback

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);
}
Also used : Customer(org.springframework.data.mongodb.examples.custsvc.domain.Customer) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Rollback

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);
}
Also used : Customer(org.springframework.data.mongodb.examples.custsvc.domain.Customer) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Rollback

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");
}
Also used : Customer(org.springframework.data.mongodb.examples.custsvc.domain.Customer) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Rollback

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;
}
Also used : Rollback(org.springframework.test.annotation.Rollback)

Aggregations

Rollback (org.springframework.test.annotation.Rollback)107 Test (org.junit.Test)103 Transactional (org.springframework.transaction.annotation.Transactional)81 DBUnitTest (org.orcid.test.DBUnitTest)46 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)37 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)25 Date (java.util.Date)24 BaseTest (org.orcid.core.BaseTest)13 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)12 OrcidOauth2TokenDetail (org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail)12 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)11 HashSet (java.util.HashSet)10 ApprovalDate (org.orcid.jaxb.model.message.ApprovalDate)8 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)8 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)7 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)7 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)7 Claimed (org.orcid.jaxb.model.message.Claimed)6 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)6 ArrayList (java.util.ArrayList)5