Search in sources :

Example 1 with Person

use of org.springframework.test.context.junit4.orm.domain.Person in project spring-framework-debug by Joker-5.

the class HibernateSessionFlushingTests method findSam.

@Test
public void findSam() {
    Person sam = personService.findByName(SAM);
    assertThat(sam).as("Should be able to find Sam").isNotNull();
    DriversLicense driversLicense = sam.getDriversLicense();
    assertThat(driversLicense).as("Sam's driver's license should not be null").isNotNull();
    assertThat(driversLicense.getNumber()).as("Verifying Sam's driver's license number").isEqualTo(Long.valueOf(1234));
}
Also used : DriversLicense(org.springframework.test.context.junit4.orm.domain.DriversLicense) Person(org.springframework.test.context.junit4.orm.domain.Person) Test(org.junit.Test)

Example 2 with Person

use of org.springframework.test.context.junit4.orm.domain.Person in project spring-framework-debug by Joker-5.

the class HibernateSessionFlushingTests method updateSamWithNullDriversLicense.

private void updateSamWithNullDriversLicense() {
    Person sam = personService.findByName(SAM);
    assertThat(sam).as("Should be able to find Sam").isNotNull();
    sam.setDriversLicense(null);
    personService.save(sam);
}
Also used : Person(org.springframework.test.context.junit4.orm.domain.Person)

Example 3 with Person

use of org.springframework.test.context.junit4.orm.domain.Person in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.

the class HibernateSessionFlushingTests method findSamWithReadOnlySession.

// SPR-16956
@Test
@Transactional(readOnly = true)
public void findSamWithReadOnlySession() {
    Person sam = personService.findByName(SAM);
    sam.setName("Vlad");
    // By setting setDefaultReadOnly(true), the user can no longer modify any entity...
    Session session = sessionFactory.getCurrentSession();
    session.flush();
    session.refresh(sam);
    assertThat(sam.getName()).isEqualTo("Sam");
}
Also used : Person(org.springframework.test.context.junit4.orm.domain.Person) Session(org.hibernate.Session) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Person

use of org.springframework.test.context.junit4.orm.domain.Person in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.

the class HibernateSessionFlushingTests method findSam.

@Test
public void findSam() {
    Person sam = personService.findByName(SAM);
    assertThat(sam).as("Should be able to find Sam").isNotNull();
    DriversLicense driversLicense = sam.getDriversLicense();
    assertThat(driversLicense).as("Sam's driver's license should not be null").isNotNull();
    assertThat(driversLicense.getNumber()).as("Verifying Sam's driver's license number").isEqualTo(Long.valueOf(1234));
}
Also used : DriversLicense(org.springframework.test.context.junit4.orm.domain.DriversLicense) Person(org.springframework.test.context.junit4.orm.domain.Person) Test(org.junit.Test)

Example 5 with Person

use of org.springframework.test.context.junit4.orm.domain.Person in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.

the class HibernateSessionFlushingTests method updateSamWithNullDriversLicense.

private void updateSamWithNullDriversLicense() {
    Person sam = personService.findByName(SAM);
    assertThat(sam).as("Should be able to find Sam").isNotNull();
    sam.setDriversLicense(null);
    personService.save(sam);
}
Also used : Person(org.springframework.test.context.junit4.orm.domain.Person)

Aggregations

Test (org.junit.Test)29 Person (org.springframework.test.context.junit4.orm.domain.Person)16 Before (org.junit.Before)11 RunWith (org.junit.runner.RunWith)11 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Person (cn.taketoday.test.context.junit4.orm.domain.Person)8 SpringRunner (org.springframework.test.context.junit4.SpringRunner)8 DriversLicense (org.springframework.test.context.junit4.orm.domain.DriversLicense)8 Transactional (org.springframework.transaction.annotation.Transactional)8 Session (org.hibernate.Session)6 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Mock (org.mockito.Mock)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 DriversLicense (cn.taketoday.test.context.junit4.orm.domain.DriversLicense)3 Date (java.util.Date)3 After (org.junit.After)3 Configuration (org.springframework.context.annotation.Configuration)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3