Skip to content

Commit

Permalink
Tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
japarejo committed Feb 12, 2020
1 parent bed2364 commit c44003c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@

import java.time.LocalDate;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.dao.DataAccessException;
import org.springframework.samples.petclinic.model.Owner;
import org.springframework.samples.petclinic.model.Pet;
import org.springframework.samples.petclinic.model.PetType;
import org.springframework.samples.petclinic.model.Vet;
import org.springframework.samples.petclinic.model.Visit;
import org.springframework.samples.petclinic.model.User;
import org.springframework.samples.petclinic.model.Authorities;
import org.springframework.samples.petclinic.service.exceptions.DuplicatedPetNameException;
import org.springframework.samples.petclinic.util.EntityUtils;
import org.springframework.stereotype.Service;
import org.springframework.test.context.ContextConfiguration;
Expand Down Expand Up @@ -102,6 +108,12 @@ public void shouldInsertOwner() {
owner.setAddress("4, Evans Street");
owner.setCity("Wollongong");
owner.setTelephone("4444444444");
User user=new User();
user.setUsername("Sam");
user.setPassword("supersecretpassword");
user.setEnabled(true);
owner.setUser(user);

this.clinicService.saveOwner(owner);
assertThat(owner.getId().longValue()).isNotEqualTo(0);

Expand Down Expand Up @@ -156,7 +168,11 @@ public void shouldInsertPetIntoDatabaseAndGenerateId() {
owner6.addPet(pet);
assertThat(owner6.getPets().size()).isEqualTo(found + 1);

this.clinicService.savePet(pet);
try {
this.clinicService.savePet(pet);
} catch (DuplicatedPetNameException ex) {
Logger.getLogger(ClinicServiceTests.class.getName()).log(Level.SEVERE, null, ex);
}
this.clinicService.saveOwner(owner6);

owner6 = this.clinicService.findOwnerById(6);
Expand Down Expand Up @@ -199,7 +215,11 @@ public void shouldAddNewVisitForPet() {
pet7.addVisit(visit);
visit.setDescription("test");
this.clinicService.saveVisit(visit);
this.clinicService.savePet(pet7);
try {
this.clinicService.savePet(pet7);
} catch (DuplicatedPetNameException ex) {
Logger.getLogger(ClinicServiceTests.class.getName()).log(Level.SEVERE, null, ex);
}

pet7 = this.clinicService.findPetById(7);
assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.samples.petclinic.service.AuthoritiesService;
import org.springframework.samples.petclinic.service.UserService;
import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
import org.springframework.security.test.context.support.WithMockUser;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand All @@ -43,6 +45,12 @@ class OwnerControllerTests {

@MockBean
private ClinicService clinicService;

@MockBean
private UserService userService;

@MockBean
private AuthoritiesService authoritiesService;

@Autowired
private MockMvc mockMvc;
Expand Down

0 comments on commit c44003c

Please sign in to comment.