Search in sources :

Example 1 with Owner

use of org.springframework.samples.petclinic.owner.Owner in project spring-petclinic by spring-projects.

the class ClinicServiceTests method shouldUpdateOwner.

@Test
@Transactional
public void shouldUpdateOwner() {
    Owner owner = this.owners.findById(1);
    String oldLastName = owner.getLastName();
    String newLastName = oldLastName + "X";
    owner.setLastName(newLastName);
    this.owners.save(owner);
    // retrieving new name from database
    owner = this.owners.findById(1);
    assertThat(owner.getLastName()).isEqualTo(newLastName);
}
Also used : Owner(org.springframework.samples.petclinic.owner.Owner) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Owner

use of org.springframework.samples.petclinic.owner.Owner in project spring-petclinic by spring-projects.

the class ClinicServiceTests method shouldFindSingleOwnerWithPet.

@Test
public void shouldFindSingleOwnerWithPet() {
    Owner owner = this.owners.findById(1);
    assertThat(owner.getLastName()).startsWith("Franklin");
    assertThat(owner.getPets().size()).isEqualTo(1);
    assertThat(owner.getPets().get(0).getType()).isNotNull();
    assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat");
}
Also used : Owner(org.springframework.samples.petclinic.owner.Owner) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 3 with Owner

use of org.springframework.samples.petclinic.owner.Owner in project spring-petclinic by spring-projects.

the class ClinicServiceTests method shouldInsertOwner.

@Test
@Transactional
public void shouldInsertOwner() {
    Collection<Owner> owners = this.owners.findByLastName("Schultz");
    int found = owners.size();
    Owner owner = new Owner();
    owner.setFirstName("Sam");
    owner.setLastName("Schultz");
    owner.setAddress("4, Evans Street");
    owner.setCity("Wollongong");
    owner.setTelephone("4444444444");
    this.owners.save(owner);
    assertThat(owner.getId().longValue()).isNotEqualTo(0);
    owners = this.owners.findByLastName("Schultz");
    assertThat(owners.size()).isEqualTo(found + 1);
}
Also used : Owner(org.springframework.samples.petclinic.owner.Owner) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Owner

use of org.springframework.samples.petclinic.owner.Owner in project spring-petclinic by spring-projects.

the class OwnerControllerTests method setup.

@Before
public void setup() {
    george = new Owner();
    george.setId(TEST_OWNER_ID);
    george.setFirstName("George");
    george.setLastName("Franklin");
    george.setAddress("110 W. Liberty St.");
    george.setCity("Madison");
    george.setTelephone("6085551023");
    given(this.owners.findById(TEST_OWNER_ID)).willReturn(george);
}
Also used : Owner(org.springframework.samples.petclinic.owner.Owner) Before(org.junit.Before)

Example 5 with Owner

use of org.springframework.samples.petclinic.owner.Owner in project spring-petclinic by spring-projects.

the class PetControllerTests method setup.

@Before
public void setup() {
    PetType cat = new PetType();
    cat.setId(3);
    cat.setName("hamster");
    given(this.pets.findPetTypes()).willReturn(Lists.newArrayList(cat));
    given(this.owners.findById(TEST_OWNER_ID)).willReturn(new Owner());
    given(this.pets.findById(TEST_PET_ID)).willReturn(new Pet());
}
Also used : Owner(org.springframework.samples.petclinic.owner.Owner) Pet(org.springframework.samples.petclinic.owner.Pet) PetType(org.springframework.samples.petclinic.owner.PetType) Before(org.junit.Before)

Aggregations

Owner (org.springframework.samples.petclinic.owner.Owner)6 Test (org.junit.Test)4 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)4 Transactional (org.springframework.transaction.annotation.Transactional)3 Before (org.junit.Before)2 Pet (org.springframework.samples.petclinic.owner.Pet)2 PetType (org.springframework.samples.petclinic.owner.PetType)2 Date (java.util.Date)1