├── src ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── guru │ │ └── springframework │ │ └── sfgpetclinic │ │ ├── repositories │ │ ├── Repository.java │ │ ├── PetRepository.java │ │ ├── VetRepository.java │ │ ├── VisitRepository.java │ │ ├── PetTypeRepository.java │ │ ├── SpecialtyRepository.java │ │ ├── OwnerRepository.java │ │ └── CrudRepository.java │ │ ├── fauxspring │ │ ├── WebDataBinder.java │ │ ├── Model.java │ │ ├── ModelMap.java │ │ ├── BindingResult.java │ │ ├── ModelAndView.java │ │ └── Formatter.java │ │ ├── services │ │ ├── VetService.java │ │ ├── VisitService.java │ │ ├── PetTypeService.java │ │ ├── SpecialtyService.java │ │ ├── PetService.java │ │ ├── CrudService.java │ │ ├── OwnerService.java │ │ ├── map │ │ │ ├── PetMapService.java │ │ │ ├── PetTypeMapService.java │ │ │ ├── SpecialityMapService.java │ │ │ ├── VisitMapService.java │ │ │ ├── AbstractMapService.java │ │ │ ├── VetMapService.java │ │ │ └── OwnerMapService.java │ │ └── springdatajpa │ │ │ ├── VetSDJpaService.java │ │ │ ├── PetSDJpaService.java │ │ │ ├── VisitSDJpaService.java │ │ │ ├── PetTypeSDJpaService.java │ │ │ ├── SpecialitySDJpaService.java │ │ │ └── OwnerSDJpaService.java │ │ ├── controllers │ │ ├── IndexController.java │ │ ├── VetController.java │ │ ├── VisitController.java │ │ ├── PetController.java │ │ └── OwnerController.java │ │ ├── model │ │ ├── BaseEntity.java │ │ ├── PetType.java │ │ ├── Speciality.java │ │ ├── Vet.java │ │ ├── Person.java │ │ ├── Visit.java │ │ ├── Pet.java │ │ └── Owner.java │ │ └── formatters │ │ └── PetTypeFormatter.java └── test │ └── java │ └── guru │ └── springframework │ └── package-info.java ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── .gitignore ├── pom.xml ├── mvnw.cmd ├── mvnw └── LICENSE /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/java/guru/springframework/package-info.java: -------------------------------------------------------------------------------- 1 | package guru.springframework; -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/springframeworkguru/testing-java-junit5/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/repositories/Repository.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.repositories; 2 | 3 | 4 | public interface Repository { 5 | 6 | } -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/fauxspring/WebDataBinder.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.fauxspring; 2 | 3 | public interface WebDataBinder { 4 | void setDisallowedFields(String id); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/fauxspring/Model.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.fauxspring; 2 | 3 | public interface Model { 4 | 5 | void addAttribute(String key, Object o); 6 | 7 | void addAttribute(Object o); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/VetService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services; 2 | 3 | import guru.springframework.sfgpetclinic.model.Vet; 4 | 5 | public interface VetService extends CrudService{ 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/VisitService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services; 2 | 3 | import guru.springframework.sfgpetclinic.model.Visit; 4 | 5 | public interface VisitService extends CrudService { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/fauxspring/ModelMap.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.fauxspring; 2 | 3 | import guru.springframework.sfgpetclinic.model.Pet; 4 | 5 | public interface ModelMap { 6 | void put(String pet, Pet pet1); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/repositories/PetRepository.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.repositories; 2 | 3 | import guru.springframework.sfgpetclinic.model.Pet; 4 | 5 | public interface PetRepository extends CrudRepository { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/repositories/VetRepository.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.repositories; 2 | 3 | import guru.springframework.sfgpetclinic.model.Vet; 4 | 5 | public interface VetRepository extends CrudRepository { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/PetTypeService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services; 2 | 3 | import guru.springframework.sfgpetclinic.model.PetType; 4 | 5 | public interface PetTypeService extends CrudService { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/repositories/VisitRepository.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.repositories; 2 | 3 | import guru.springframework.sfgpetclinic.model.Visit; 4 | 5 | public interface VisitRepository extends CrudRepository { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/SpecialtyService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services; 2 | 3 | import guru.springframework.sfgpetclinic.model.Speciality; 4 | 5 | public interface SpecialtyService extends CrudService { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/repositories/PetTypeRepository.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.repositories; 2 | 3 | import guru.springframework.sfgpetclinic.model.PetType; 4 | 5 | public interface PetTypeRepository extends CrudRepository { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/fauxspring/BindingResult.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.fauxspring; 2 | 3 | 4 | public interface BindingResult { 5 | void rejectValue(String lastName, String notFound, String not_found); 6 | 7 | boolean hasErrors(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/repositories/SpecialtyRepository.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.repositories; 2 | 3 | import guru.springframework.sfgpetclinic.model.Speciality; 4 | 5 | public interface SpecialtyRepository extends CrudRepository { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/PetService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services; 2 | 3 | import guru.springframework.sfgpetclinic.model.Pet; 4 | 5 | /** 6 | * Created by jt on 7/18/18. 7 | */ 8 | public interface PetService extends CrudService { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/fauxspring/ModelAndView.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.fauxspring; 2 | 3 | 4 | public class ModelAndView { 5 | 6 | public ModelAndView() { 7 | } 8 | 9 | public ModelAndView(String view) { 10 | } 11 | 12 | public void addObject(Object o){} 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/controllers/IndexController.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.controllers; 2 | 3 | public class IndexController { 4 | 5 | public String index(){ 6 | 7 | return "index"; 8 | } 9 | 10 | public String oupsHandler(){ 11 | return "notimplemented"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/CrudService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services; 2 | 3 | import java.util.Set; 4 | 5 | public interface CrudService { 6 | 7 | Set findAll(); 8 | 9 | T findById(ID id); 10 | 11 | T save(T object); 12 | 13 | void delete(T object); 14 | 15 | void deleteById(ID id); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/OwnerService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services; 2 | 3 | import guru.springframework.sfgpetclinic.model.Owner; 4 | 5 | import java.util.List; 6 | 7 | public interface OwnerService extends CrudService { 8 | 9 | Owner findByLastName(String lastName); 10 | 11 | List findAllByLastNameLike(String lastName); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/repositories/OwnerRepository.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.repositories; 2 | 3 | 4 | import guru.springframework.sfgpetclinic.model.Owner; 5 | 6 | import java.util.List; 7 | 8 | public interface OwnerRepository extends CrudRepository { 9 | 10 | Owner findByLastName(String lastName); 11 | 12 | List findAllByLastNameLike(String lastName); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/fauxspring/Formatter.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.fauxspring; 2 | 3 | import guru.springframework.sfgpetclinic.model.PetType; 4 | 5 | import java.text.ParseException; 6 | import java.util.Locale; 7 | 8 | 9 | public interface Formatter { 10 | 11 | String print(PetType petType, Locale locale); 12 | 13 | PetType parse(String text, Locale locale) throws ParseException; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/model/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.model; 2 | 3 | import java.io.Serializable; 4 | 5 | 6 | public class BaseEntity implements Serializable { 7 | 8 | private Long id; 9 | 10 | public boolean isNew() { 11 | return this.id == null; 12 | } 13 | 14 | public BaseEntity() { 15 | } 16 | 17 | public BaseEntity(Long id) { 18 | this.id = id; 19 | } 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Long id) { 26 | this.id = id; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/controllers/VetController.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.controllers; 2 | 3 | import guru.springframework.sfgpetclinic.fauxspring.Model; 4 | import guru.springframework.sfgpetclinic.services.VetService; 5 | 6 | public class VetController { 7 | 8 | private final VetService vetService; 9 | 10 | public VetController(VetService vetService) { 11 | this.vetService = vetService; 12 | } 13 | 14 | public String listVets(Model model){ 15 | 16 | model.addAttribute("vets", vetService.findAll()); 17 | 18 | return "vets/index"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction to JUnit 5 with Maven 2 | 3 | All source code examples in the repository are for my [Online Course - Testing Spring Beginner to Guru](https://www.udemy.com/testing-spring-boot-beginner-to-guru/?couponCode=GITHUB_REPO) 4 | 5 | This source code repository contains JUnit 5 test examples with Maven. 6 | 7 | ## Setup 8 | ### Requirements 9 | * Should use Java 11 or higher. Previous versions of Java are un-tested. 10 | * Use Maven 3.5.2 or higher 11 | 12 | ## Support 13 | For questions and help: 14 | * Please post in course 15 | * Or post in the Slack Community exclusive to the course. 16 | 17 | GitHub Issues will not be addressed. 18 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/model/PetType.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.model; 2 | 3 | 4 | public class PetType extends BaseEntity { 5 | 6 | private String name; 7 | 8 | @Override 9 | public String toString() { 10 | return name; 11 | } 12 | 13 | public PetType() { 14 | } 15 | 16 | public PetType(String name) { 17 | this.name = name; 18 | } 19 | 20 | public PetType(Long id, String name) { 21 | super(id); 22 | this.name = name; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/model/Speciality.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.model; 2 | 3 | public class Speciality extends BaseEntity { 4 | private String description; 5 | 6 | public Speciality() { 7 | } 8 | 9 | public Speciality(String description) { 10 | this.description = description; 11 | } 12 | 13 | public Speciality(Long id, String description) { 14 | super(id); 15 | this.description = description; 16 | } 17 | 18 | public String getDescription() { 19 | return description; 20 | } 21 | 22 | public void setDescription(String description) { 23 | this.description = description; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/model/Vet.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.model; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | 7 | public class Vet extends Person { 8 | 9 | private Set specialities = new HashSet<>(); 10 | 11 | public Vet(Long id, String firstName, String lastName, Set specialities) { 12 | super(id, firstName, lastName); 13 | this.specialities = specialities; 14 | } 15 | 16 | public Set getSpecialities() { 17 | return specialities; 18 | } 19 | 20 | public void setSpecialities(Set specialities) { 21 | this.specialities = specialities; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/model/Person.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.model; 2 | 3 | public class Person extends BaseEntity { 4 | 5 | public Person(Long id, String firstName, String lastName) { 6 | super(id); 7 | this.firstName = firstName; 8 | this.lastName = lastName; 9 | } 10 | 11 | private String firstName; 12 | private String lastName; 13 | 14 | public String getFirstName() { 15 | return firstName; 16 | } 17 | 18 | public void setFirstName(String firstName) { 19 | this.firstName = firstName; 20 | } 21 | 22 | public String getLastName() { 23 | return lastName; 24 | } 25 | 26 | public void setLastName(String lastName) { 27 | this.lastName = lastName; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/map/PetMapService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.map; 2 | 3 | import guru.springframework.sfgpetclinic.model.Pet; 4 | import guru.springframework.sfgpetclinic.services.PetService; 5 | 6 | import java.util.Set; 7 | 8 | 9 | public class PetMapService extends AbstractMapService implements PetService { 10 | @Override 11 | public Set findAll() { 12 | return super.findAll(); 13 | } 14 | 15 | @Override 16 | public Pet findById(Long id) { 17 | return super.findById(id); 18 | } 19 | 20 | @Override 21 | public Pet save(Pet object) { 22 | return super.save(object); 23 | } 24 | 25 | @Override 26 | public void delete(Pet object) { 27 | super.delete(object); 28 | } 29 | 30 | @Override 31 | public void deleteById(Long id) { 32 | super.deleteById(id); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/map/PetTypeMapService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.map; 2 | 3 | import guru.springframework.sfgpetclinic.model.PetType; 4 | import guru.springframework.sfgpetclinic.services.PetTypeService; 5 | 6 | import java.util.Set; 7 | 8 | public class PetTypeMapService extends AbstractMapService implements PetTypeService { 9 | 10 | @Override 11 | public Set findAll() { 12 | return super.findAll(); 13 | } 14 | 15 | @Override 16 | public PetType findById(Long id) { 17 | return super.findById(id); 18 | } 19 | 20 | @Override 21 | public PetType save(PetType object) { 22 | return super.save(object); 23 | } 24 | 25 | @Override 26 | public void delete(PetType object) { 27 | super.delete(object); 28 | } 29 | 30 | @Override 31 | public void deleteById(Long id) { 32 | super.deleteById(id); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/map/SpecialityMapService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.map; 2 | 3 | import guru.springframework.sfgpetclinic.model.Speciality; 4 | import guru.springframework.sfgpetclinic.services.SpecialtyService; 5 | 6 | import java.util.Set; 7 | 8 | public class SpecialityMapService extends AbstractMapService implements SpecialtyService { 9 | 10 | @Override 11 | public Set findAll() { 12 | return super.findAll(); 13 | } 14 | 15 | @Override 16 | public Speciality findById(Long id) { 17 | return super.findById(id); 18 | } 19 | 20 | @Override 21 | public Speciality save(Speciality object) { 22 | return super.save(object); 23 | } 24 | 25 | @Override 26 | public void delete(Speciality object) { 27 | super.delete(object); 28 | } 29 | 30 | @Override 31 | public void deleteById(Long id) { 32 | super.deleteById(id); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/model/Visit.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.model; 2 | 3 | import java.time.LocalDate; 4 | 5 | public class Visit extends BaseEntity { 6 | 7 | private LocalDate date; 8 | private String description; 9 | private Pet pet; 10 | 11 | public Visit() { 12 | super(null); 13 | } 14 | 15 | public Visit(Long id) { 16 | super(id); 17 | } 18 | 19 | public Visit(Long id, LocalDate date) { 20 | super(id); 21 | this.date = date; 22 | } 23 | 24 | public LocalDate getDate() { 25 | return date; 26 | } 27 | 28 | public void setDate(LocalDate date) { 29 | this.date = date; 30 | } 31 | 32 | public String getDescription() { 33 | return description; 34 | } 35 | 36 | public void setDescription(String description) { 37 | this.description = description; 38 | } 39 | 40 | public Pet getPet() { 41 | return pet; 42 | } 43 | 44 | public void setPet(Pet pet) { 45 | this.pet = pet; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/map/VisitMapService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.map; 2 | 3 | import guru.springframework.sfgpetclinic.model.Visit; 4 | import guru.springframework.sfgpetclinic.services.VisitService; 5 | 6 | import java.util.Set; 7 | 8 | public class VisitMapService extends AbstractMapService implements VisitService { 9 | 10 | @Override 11 | public Set findAll() { 12 | return super.findAll(); 13 | } 14 | 15 | @Override 16 | public Visit findById(Long id) { 17 | return super.findById(id); 18 | } 19 | 20 | @Override 21 | public Visit save(Visit visit) { 22 | 23 | if(visit.getPet() == null || visit.getPet().getOwner() == null || visit.getPet().getId() == null 24 | || visit.getPet().getOwner().getId() == null){ 25 | throw new RuntimeException("Invalid Visit"); 26 | } 27 | 28 | return super.save(visit); 29 | } 30 | 31 | @Override 32 | public void delete(Visit object) { 33 | super.delete(object); 34 | } 35 | 36 | @Override 37 | public void deleteById(Long id) { 38 | super.deleteById(id); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/formatters/PetTypeFormatter.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.formatters; 2 | 3 | import guru.springframework.sfgpetclinic.fauxspring.Formatter; 4 | import guru.springframework.sfgpetclinic.model.PetType; 5 | import guru.springframework.sfgpetclinic.services.PetTypeService; 6 | 7 | import java.text.ParseException; 8 | import java.util.Collection; 9 | import java.util.Locale; 10 | 11 | 12 | public class PetTypeFormatter implements Formatter { 13 | 14 | private final PetTypeService petTypeService; 15 | 16 | public PetTypeFormatter(PetTypeService petTypeService) { 17 | this.petTypeService = petTypeService; 18 | } 19 | 20 | @Override 21 | public String print(PetType petType, Locale locale) { 22 | return petType.getName(); 23 | } 24 | 25 | @Override 26 | public PetType parse(String text, Locale locale) throws ParseException { 27 | Collection findPetTypes = petTypeService.findAll(); 28 | 29 | for (PetType type : findPetTypes) { 30 | if (type.getName().equals(text)) { 31 | return type; 32 | } 33 | } 34 | 35 | throw new ParseException("type not found: " + text, 0); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/springdatajpa/VetSDJpaService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.springdatajpa; 2 | 3 | import guru.springframework.sfgpetclinic.model.Vet; 4 | import guru.springframework.sfgpetclinic.repositories.VetRepository; 5 | import guru.springframework.sfgpetclinic.services.VetService; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | public class VetSDJpaService implements VetService { 11 | 12 | private final VetRepository vetRepository; 13 | 14 | public VetSDJpaService(VetRepository vetRepository) { 15 | this.vetRepository = vetRepository; 16 | } 17 | 18 | @Override 19 | public Set findAll() { 20 | Set vets = new HashSet<>(); 21 | vetRepository.findAll().forEach(vets::add); 22 | return vets; 23 | } 24 | 25 | @Override 26 | public Vet findById(Long aLong) { 27 | return vetRepository.findById(aLong).orElse(null); 28 | } 29 | 30 | @Override 31 | public Vet save(Vet object) { 32 | return vetRepository.save(object); 33 | } 34 | 35 | @Override 36 | public void delete(Vet object) { 37 | vetRepository.delete(object); 38 | } 39 | 40 | @Override 41 | public void deleteById(Long aLong) { 42 | vetRepository.deleteById(aLong); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/springdatajpa/PetSDJpaService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.springdatajpa; 2 | 3 | import guru.springframework.sfgpetclinic.model.Pet; 4 | import guru.springframework.sfgpetclinic.repositories.PetRepository; 5 | import guru.springframework.sfgpetclinic.services.PetService; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | 11 | public class PetSDJpaService implements PetService { 12 | 13 | private final PetRepository petRepository; 14 | 15 | public PetSDJpaService(PetRepository petRepository) { 16 | this.petRepository = petRepository; 17 | } 18 | 19 | @Override 20 | public Set findAll() { 21 | Set pets = new HashSet<>(); 22 | petRepository.findAll().forEach(pets::add); 23 | return pets; 24 | } 25 | 26 | @Override 27 | public Pet findById(Long aLong) { 28 | return petRepository.findById(aLong).orElse(null); 29 | } 30 | 31 | @Override 32 | public Pet save(Pet object) { 33 | return petRepository.save(object); 34 | } 35 | 36 | @Override 37 | public void delete(Pet object) { 38 | petRepository.delete(object); 39 | } 40 | 41 | @Override 42 | public void deleteById(Long aLong) { 43 | petRepository.deleteById(aLong); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/springdatajpa/VisitSDJpaService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.springdatajpa; 2 | 3 | import guru.springframework.sfgpetclinic.model.Visit; 4 | import guru.springframework.sfgpetclinic.repositories.VisitRepository; 5 | import guru.springframework.sfgpetclinic.services.VisitService; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | public class VisitSDJpaService implements VisitService { 11 | 12 | private final VisitRepository visitRepository; 13 | 14 | public VisitSDJpaService(VisitRepository visitRepository) { 15 | this.visitRepository = visitRepository; 16 | } 17 | 18 | @Override 19 | public Set findAll() { 20 | Set visits = new HashSet<>(); 21 | visitRepository.findAll().forEach(visits::add); 22 | return visits; 23 | } 24 | 25 | @Override 26 | public Visit findById(Long aLong) { 27 | return visitRepository.findById(aLong).orElse(null); 28 | } 29 | 30 | @Override 31 | public Visit save(Visit object) { 32 | return visitRepository.save(object); 33 | } 34 | 35 | @Override 36 | public void delete(Visit object) { 37 | visitRepository.delete(object); 38 | } 39 | 40 | @Override 41 | public void deleteById(Long aLong) { 42 | visitRepository.deleteById(aLong); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/map/AbstractMapService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.map; 2 | 3 | import guru.springframework.sfgpetclinic.model.BaseEntity; 4 | 5 | import java.util.*; 6 | 7 | 8 | public abstract class AbstractMapService { 9 | 10 | protected Map map = new HashMap<>(); 11 | 12 | Set findAll(){ 13 | return new HashSet<>(map.values()); 14 | } 15 | 16 | T findById(ID id) { 17 | return map.get(id); 18 | } 19 | 20 | T save(T object){ 21 | 22 | if(object != null) { 23 | if(object.getId() == null){ 24 | object.setId(getNextId()); 25 | } 26 | 27 | map.put(object.getId(), object); 28 | } else { 29 | throw new RuntimeException("Object cannot be null"); 30 | } 31 | 32 | return object; 33 | } 34 | 35 | void deleteById(ID id){ 36 | map.remove(id); 37 | } 38 | 39 | void delete(T object){ 40 | map.entrySet().removeIf(entry -> entry.getValue().equals(object)); 41 | } 42 | 43 | private Long getNextId(){ 44 | 45 | Long nextId = null; 46 | 47 | try { 48 | nextId = Collections.max(map.keySet()) + 1; 49 | } catch (NoSuchElementException e) { 50 | nextId = 1L; 51 | } 52 | 53 | return nextId; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/model/Pet.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.model; 2 | 3 | import java.time.LocalDate; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | 8 | public class Pet extends BaseEntity{ 9 | 10 | private String name; 11 | private PetType petType; 12 | private Owner owner; 13 | private LocalDate birthDate; 14 | private Set visits = new HashSet<>(); 15 | 16 | public Pet() { 17 | } 18 | 19 | public Pet(Long id) { 20 | super(id); 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | 31 | public PetType getPetType() { 32 | return petType; 33 | } 34 | 35 | public void setPetType(PetType petType) { 36 | this.petType = petType; 37 | } 38 | 39 | public Owner getOwner() { 40 | return owner; 41 | } 42 | 43 | public void setOwner(Owner owner) { 44 | this.owner = owner; 45 | } 46 | 47 | public LocalDate getBirthDate() { 48 | return birthDate; 49 | } 50 | 51 | public void setBirthDate(LocalDate birthDate) { 52 | this.birthDate = birthDate; 53 | } 54 | 55 | public Set getVisits() { 56 | return visits; 57 | } 58 | 59 | public void setVisits(Set visits) { 60 | this.visits = visits; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/springdatajpa/PetTypeSDJpaService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.springdatajpa; 2 | 3 | import guru.springframework.sfgpetclinic.model.PetType; 4 | import guru.springframework.sfgpetclinic.repositories.PetTypeRepository; 5 | import guru.springframework.sfgpetclinic.services.PetTypeService; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | 11 | public class PetTypeSDJpaService implements PetTypeService { 12 | 13 | private final PetTypeRepository petTypeRepository; 14 | 15 | public PetTypeSDJpaService(PetTypeRepository petTypeRepository) { 16 | this.petTypeRepository = petTypeRepository; 17 | } 18 | 19 | @Override 20 | public Set findAll() { 21 | Set petTypes = new HashSet<>(); 22 | petTypeRepository.findAll().forEach(petTypes::add); 23 | return petTypes; 24 | } 25 | 26 | @Override 27 | public PetType findById(Long aLong) { 28 | return petTypeRepository.findById(aLong).orElse(null); 29 | } 30 | 31 | @Override 32 | public PetType save(PetType object) { 33 | return petTypeRepository.save(object); 34 | } 35 | 36 | @Override 37 | public void delete(PetType object) { 38 | petTypeRepository.delete(object); 39 | } 40 | 41 | @Override 42 | public void deleteById(Long aLong) { 43 | petTypeRepository.deleteById(aLong); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/springdatajpa/SpecialitySDJpaService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.springdatajpa; 2 | 3 | import guru.springframework.sfgpetclinic.model.Speciality; 4 | import guru.springframework.sfgpetclinic.repositories.SpecialtyRepository; 5 | import guru.springframework.sfgpetclinic.services.SpecialtyService; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | 11 | public class SpecialitySDJpaService implements SpecialtyService { 12 | 13 | private final SpecialtyRepository specialtyRepository; 14 | 15 | public SpecialitySDJpaService(SpecialtyRepository specialtyRepository) { 16 | this.specialtyRepository = specialtyRepository; 17 | } 18 | 19 | @Override 20 | public Set findAll() { 21 | Set specialities = new HashSet<>(); 22 | specialtyRepository.findAll().forEach(specialities::add); 23 | return specialities; 24 | } 25 | 26 | @Override 27 | public Speciality findById(Long aLong) { 28 | return specialtyRepository.findById(aLong).orElse(null); 29 | } 30 | 31 | @Override 32 | public Speciality save(Speciality object) { 33 | return specialtyRepository.save(object); 34 | } 35 | 36 | @Override 37 | public void delete(Speciality object) { 38 | specialtyRepository.delete(object); 39 | } 40 | 41 | @Override 42 | public void deleteById(Long aLong) { 43 | specialtyRepository.deleteById(aLong); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/map/VetMapService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.map; 2 | 3 | import guru.springframework.sfgpetclinic.model.Speciality; 4 | import guru.springframework.sfgpetclinic.model.Vet; 5 | import guru.springframework.sfgpetclinic.services.SpecialtyService; 6 | import guru.springframework.sfgpetclinic.services.VetService; 7 | 8 | import java.util.Set; 9 | 10 | public class VetMapService extends AbstractMapService implements VetService { 11 | 12 | private final SpecialtyService specialtyService; 13 | 14 | public VetMapService(SpecialtyService specialtyService) { 15 | this.specialtyService = specialtyService; 16 | } 17 | 18 | @Override 19 | public Set findAll() { 20 | return super.findAll(); 21 | } 22 | 23 | @Override 24 | public Vet findById(Long id) { 25 | return super.findById(id); 26 | } 27 | 28 | @Override 29 | public Vet save(Vet object) { 30 | 31 | if (object.getSpecialities().size() > 0){ 32 | object.getSpecialities().forEach(speciality -> { 33 | if(speciality.getId() == null){ 34 | Speciality savedSpecialty = specialtyService.save(speciality); 35 | speciality.setId(savedSpecialty.getId()); 36 | } 37 | }); 38 | } 39 | 40 | return super.save(object); 41 | } 42 | 43 | @Override 44 | public void delete(Vet object) { 45 | super.delete(object); 46 | } 47 | 48 | @Override 49 | public void deleteById(Long id) { 50 | super.deleteById(id); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/controllers/VisitController.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.controllers; 2 | 3 | import guru.springframework.sfgpetclinic.fauxspring.BindingResult; 4 | import guru.springframework.sfgpetclinic.fauxspring.WebDataBinder; 5 | import guru.springframework.sfgpetclinic.model.Pet; 6 | import guru.springframework.sfgpetclinic.model.Visit; 7 | import guru.springframework.sfgpetclinic.services.PetService; 8 | import guru.springframework.sfgpetclinic.services.VisitService; 9 | 10 | import javax.validation.Valid; 11 | import java.util.Map; 12 | 13 | 14 | public class VisitController { 15 | 16 | private final VisitService visitService; 17 | private final PetService petService; 18 | 19 | public VisitController(VisitService visitService, PetService petService) { 20 | this.visitService = visitService; 21 | this.petService = petService; 22 | } 23 | 24 | public void setAllowedFields(WebDataBinder dataBinder) { 25 | dataBinder.setDisallowedFields("id"); 26 | } 27 | 28 | public Visit loadPetWithVisit(Long petId, Map model) { 29 | Pet pet = petService.findById(petId); 30 | model.put("pet", pet); 31 | Visit visit = new Visit(); 32 | pet.getVisits().add(visit); 33 | visit.setPet(pet); 34 | return visit; 35 | } 36 | 37 | public String initNewVisitForm(Long petId, Map model) { 38 | return "pets/createOrUpdateVisitForm"; 39 | } 40 | 41 | public String processNewVisitForm(@Valid Visit visit, BindingResult result) { 42 | if (result.hasErrors()) { 43 | return "pets/createOrUpdateVisitForm"; 44 | } else { 45 | visitService.save(visit); 46 | 47 | return "redirect:/owners/{ownerId}"; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/model/Owner.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.model; 2 | 3 | 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | public class Owner extends Person { 8 | 9 | private String address; 10 | private String city; 11 | private String telephone; 12 | private Set pets = new HashSet<>(); 13 | 14 | public Owner(Long id, String firstName, String lastName) { 15 | super(id, firstName, lastName); 16 | } 17 | 18 | public Pet getPet(String name) { 19 | return getPet(name, false); 20 | } 21 | 22 | /** 23 | * Return the Pet with the given name, or null if none found for this Owner. 24 | * 25 | * @param name to test 26 | * @return true if pet name is already in use 27 | */ 28 | public Pet getPet(String name, boolean ignoreNew) { 29 | name = name.toLowerCase(); 30 | for (Pet pet : pets) { 31 | if (!ignoreNew || !pet.isNew()) { 32 | String compName = pet.getName(); 33 | compName = compName.toLowerCase(); 34 | if (compName.equals(name)) { 35 | return pet; 36 | } 37 | } 38 | } 39 | return null; 40 | } 41 | 42 | public String getAddress() { 43 | return address; 44 | } 45 | 46 | public void setAddress(String address) { 47 | this.address = address; 48 | } 49 | 50 | public String getCity() { 51 | return city; 52 | } 53 | 54 | public void setCity(String city) { 55 | this.city = city; 56 | } 57 | 58 | public String getTelephone() { 59 | return telephone; 60 | } 61 | 62 | public void setTelephone(String telephone) { 63 | this.telephone = telephone; 64 | } 65 | 66 | public Set getPets() { 67 | return pets; 68 | } 69 | 70 | public void setPets(Set pets) { 71 | this.pets = pets; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/springdatajpa/OwnerSDJpaService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.springdatajpa; 2 | 3 | import guru.springframework.sfgpetclinic.model.Owner; 4 | import guru.springframework.sfgpetclinic.repositories.OwnerRepository; 5 | import guru.springframework.sfgpetclinic.repositories.PetRepository; 6 | import guru.springframework.sfgpetclinic.repositories.PetTypeRepository; 7 | import guru.springframework.sfgpetclinic.services.OwnerService; 8 | 9 | import java.util.HashSet; 10 | import java.util.List; 11 | import java.util.Set; 12 | 13 | public class OwnerSDJpaService implements OwnerService { 14 | 15 | private final OwnerRepository ownerRepository; 16 | private final PetRepository petRepository; 17 | private final PetTypeRepository petTypeRepository; 18 | 19 | public OwnerSDJpaService(OwnerRepository ownerRepository, PetRepository petRepository, 20 | PetTypeRepository petTypeRepository) { 21 | this.ownerRepository = ownerRepository; 22 | this.petRepository = petRepository; 23 | this.petTypeRepository = petTypeRepository; 24 | } 25 | 26 | @Override 27 | public Owner findByLastName(String lastName) { 28 | return ownerRepository.findByLastName(lastName); 29 | } 30 | 31 | @Override 32 | public List findAllByLastNameLike(String lastName) { 33 | return ownerRepository.findAllByLastNameLike(lastName); 34 | } 35 | 36 | @Override 37 | public Set findAll() { 38 | Set owners = new HashSet<>(); 39 | ownerRepository.findAll().forEach(owners::add); 40 | return owners; 41 | } 42 | 43 | @Override 44 | public Owner findById(Long aLong) { 45 | return ownerRepository.findById(aLong).orElse(null); 46 | } 47 | 48 | @Override 49 | public Owner save(Owner object) { 50 | return ownerRepository.save(object); 51 | } 52 | 53 | @Override 54 | public void delete(Owner object) { 55 | ownerRepository.delete(object); 56 | } 57 | 58 | @Override 59 | public void deleteById(Long aLong) { 60 | ownerRepository.deleteById(aLong); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ###################### 2 | # Project Specific 3 | ###################### 4 | /build/www/** 5 | /src/test/javascript/coverage/ 6 | /src/test/javascript/PhantomJS*/ 7 | 8 | ###################### 9 | # Node 10 | ###################### 11 | /node/ 12 | node_tmp/ 13 | node_modules/ 14 | npm-debug.log.* 15 | 16 | ###################### 17 | # SASS 18 | ###################### 19 | .sass-cache/ 20 | 21 | ###################### 22 | # Eclipse 23 | ###################### 24 | *.pydevproject 25 | .project 26 | .metadata 27 | tmp/ 28 | tmp/**/* 29 | *.tmp 30 | *.bak 31 | *.swp 32 | *~.nib 33 | local.properties 34 | .classpath 35 | .settings/ 36 | .loadpath 37 | .factorypath 38 | /src/main/resources/rebel.xml 39 | 40 | # External tool builders 41 | .externalToolBuilders/** 42 | 43 | # Locally stored "Eclipse launch configurations" 44 | *.launch 45 | 46 | # CDT-specific 47 | .cproject 48 | 49 | # PDT-specific 50 | .buildpath 51 | 52 | ###################### 53 | # Intellij 54 | ###################### 55 | .idea/ 56 | *.iml 57 | *.iws 58 | *.ipr 59 | *.ids 60 | *.orig 61 | 62 | ###################### 63 | # Visual Studio Code 64 | ###################### 65 | .vscode/ 66 | 67 | ###################### 68 | # Maven 69 | ###################### 70 | /log/ 71 | /target/ 72 | 73 | ###################### 74 | # Gradle 75 | ###################### 76 | .gradle/ 77 | /build/ 78 | 79 | ###################### 80 | # Package Files 81 | ###################### 82 | *.jar 83 | *.war 84 | *.ear 85 | *.db 86 | 87 | ###################### 88 | # Windows 89 | ###################### 90 | # Windows image file caches 91 | Thumbs.db 92 | 93 | # Folder config file 94 | Desktop.ini 95 | 96 | ###################### 97 | # Mac OSX 98 | ###################### 99 | .DS_Store 100 | .svn 101 | 102 | # Thumbnails 103 | ._* 104 | 105 | # Files that might appear on external disk 106 | .Spotlight-V100 107 | .Trashes 108 | 109 | ###################### 110 | # Directories 111 | ###################### 112 | /bin/ 113 | /deploy/ 114 | 115 | ###################### 116 | # Logs 117 | ###################### 118 | *.log 119 | 120 | ###################### 121 | # Others 122 | ###################### 123 | *.class 124 | *.*~ 125 | *~ 126 | .merge_file* 127 | 128 | ###################### 129 | # Gradle Wrapper 130 | ###################### 131 | !gradle/wrapper/gradle-wrapper.jar 132 | 133 | ###################### 134 | # Maven Wrapper 135 | ###################### 136 | !.mvn/wrapper/maven-wrapper.jar 137 | 138 | ###################### 139 | # ESLint 140 | ###################### 141 | .eslintcache 142 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/services/map/OwnerMapService.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.services.map; 2 | 3 | import guru.springframework.sfgpetclinic.model.Owner; 4 | import guru.springframework.sfgpetclinic.model.Pet; 5 | import guru.springframework.sfgpetclinic.services.OwnerService; 6 | import guru.springframework.sfgpetclinic.services.PetService; 7 | import guru.springframework.sfgpetclinic.services.PetTypeService; 8 | 9 | import java.util.List; 10 | import java.util.Set; 11 | 12 | public class OwnerMapService extends AbstractMapService implements OwnerService { 13 | 14 | private final PetTypeService petTypeService; 15 | private final PetService petService; 16 | 17 | public OwnerMapService(PetTypeService petTypeService, PetService petService) { 18 | this.petTypeService = petTypeService; 19 | this.petService = petService; 20 | } 21 | 22 | @Override 23 | public Set findAll() { 24 | return super.findAll(); 25 | } 26 | 27 | @Override 28 | public Owner findById(Long id) { 29 | return super.findById(id); 30 | } 31 | 32 | @Override 33 | public Owner save(Owner object) { 34 | 35 | if(object != null){ 36 | if (object.getPets() != null) { 37 | object.getPets().forEach(pet -> { 38 | if (pet.getPetType() != null){ 39 | if(pet.getPetType().getId() == null){ 40 | pet.setPetType(petTypeService.save(pet.getPetType())); 41 | } 42 | } else { 43 | throw new RuntimeException("Pet Type is required"); 44 | } 45 | 46 | if(pet.getId() == null){ 47 | Pet savedPet = petService.save(pet); 48 | pet.setId(savedPet.getId()); 49 | } 50 | }); 51 | } 52 | 53 | return super.save(object); 54 | 55 | } else { 56 | return null; 57 | } 58 | } 59 | 60 | @Override 61 | public void delete(Owner object) { 62 | super.delete(object); 63 | } 64 | 65 | @Override 66 | public void deleteById(Long id) { 67 | super.deleteById(id); 68 | } 69 | 70 | @Override 71 | public Owner findByLastName(String lastName) { 72 | return this.findAll() 73 | .stream() 74 | .filter(owner -> owner.getLastName().equalsIgnoreCase(lastName)) 75 | .findFirst() 76 | .orElse(null); 77 | } 78 | 79 | @Override 80 | public List findAllByLastNameLike(String lastName) { 81 | 82 | //todo - impl 83 | return null; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/repositories/CrudRepository.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.repositories; 2 | 3 | import java.util.Optional; 4 | 5 | public interface CrudRepository extends Repository { 6 | 7 | /** 8 | * Saves a given entity. Use the returned instance for further operations as the save operation might have changed the 9 | * entity instance completely. 10 | * 11 | * @param entity must not be {@literal null}. 12 | * @return the saved entity will never be {@literal null}. 13 | */ 14 | S save(S entity); 15 | 16 | /** 17 | * Saves all given entities. 18 | * 19 | * @param entities must not be {@literal null}. 20 | * @return the saved entities will never be {@literal null}. 21 | * @throws IllegalArgumentException in case the given entity is {@literal null}. 22 | */ 23 | Iterable saveAll(Iterable entities); 24 | 25 | /** 26 | * Retrieves an entity by its id. 27 | * 28 | * @param id must not be {@literal null}. 29 | * @return the entity with the given id or {@literal Optional#empty()} if none found 30 | * @throws IllegalArgumentException if {@code id} is {@literal null}. 31 | */ 32 | Optional findById(ID id); 33 | 34 | /** 35 | * Returns whether an entity with the given id exists. 36 | * 37 | * @param id must not be {@literal null}. 38 | * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise. 39 | * @throws IllegalArgumentException if {@code id} is {@literal null}. 40 | */ 41 | boolean existsById(ID id); 42 | 43 | /** 44 | * Returns all instances of the type. 45 | * 46 | * @return all entities 47 | */ 48 | Iterable findAll(); 49 | 50 | /** 51 | * Returns all instances of the type with the given IDs. 52 | * 53 | * @param ids 54 | * @return 55 | */ 56 | Iterable findAllById(Iterable ids); 57 | 58 | /** 59 | * Returns the number of entities available. 60 | * 61 | * @return the number of entities 62 | */ 63 | long count(); 64 | 65 | /** 66 | * Deletes the entity with the given id. 67 | * 68 | * @param id must not be {@literal null}. 69 | * @throws IllegalArgumentException in case the given {@code id} is {@literal null} 70 | */ 71 | void deleteById(ID id); 72 | 73 | /** 74 | * Deletes a given entity. 75 | * 76 | * @param entity 77 | * @throws IllegalArgumentException in case the given entity is {@literal null}. 78 | */ 79 | void delete(T entity); 80 | 81 | /** 82 | * Deletes the given entities. 83 | * 84 | * @param entities 85 | * @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}. 86 | */ 87 | void deleteAll(Iterable entities); 88 | 89 | /** 90 | * Deletes all entities managed by the repository. 91 | */ 92 | void deleteAll(); 93 | } -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/controllers/PetController.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.controllers; 2 | 3 | import guru.springframework.sfgpetclinic.fauxspring.BindingResult; 4 | import guru.springframework.sfgpetclinic.fauxspring.Model; 5 | import guru.springframework.sfgpetclinic.fauxspring.ModelMap; 6 | import guru.springframework.sfgpetclinic.fauxspring.WebDataBinder; 7 | import guru.springframework.sfgpetclinic.model.Owner; 8 | import guru.springframework.sfgpetclinic.model.Pet; 9 | import guru.springframework.sfgpetclinic.model.PetType; 10 | import guru.springframework.sfgpetclinic.services.OwnerService; 11 | import guru.springframework.sfgpetclinic.services.PetService; 12 | import guru.springframework.sfgpetclinic.services.PetTypeService; 13 | import org.apache.commons.lang3.StringUtils; 14 | 15 | import javax.validation.Valid; 16 | import java.util.Collection; 17 | 18 | public class PetController { 19 | 20 | private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm"; 21 | 22 | private final PetService petService; 23 | private final OwnerService ownerService; 24 | private final PetTypeService petTypeService; 25 | 26 | public PetController(PetService petService, OwnerService ownerService, PetTypeService petTypeService) { 27 | this.petService = petService; 28 | this.ownerService = ownerService; 29 | this.petTypeService = petTypeService; 30 | } 31 | 32 | public Collection populatePetTypes() { 33 | return petTypeService.findAll(); 34 | } 35 | 36 | public Owner findOwner(Long ownerId) { 37 | return ownerService.findById(ownerId); 38 | } 39 | 40 | public void initOwnerBinder(WebDataBinder dataBinder) { 41 | dataBinder.setDisallowedFields("id"); 42 | } 43 | 44 | public String initCreationForm(Owner owner, Model model) { 45 | Pet pet = new Pet(); 46 | owner.getPets().add(pet); 47 | pet.setOwner(owner); 48 | model.addAttribute("pet", pet); 49 | return VIEWS_PETS_CREATE_OR_UPDATE_FORM; 50 | } 51 | 52 | public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model) { 53 | if (StringUtils.length(pet.getName()) > 0 && pet.isNew() && owner.getPet(pet.getName(), true) != null){ 54 | result.rejectValue("name", "duplicate", "already exists"); 55 | } 56 | owner.getPets().add(pet); 57 | if (result.hasErrors()) { 58 | model.put("pet", pet); 59 | return VIEWS_PETS_CREATE_OR_UPDATE_FORM; 60 | } else { 61 | petService.save(pet); 62 | 63 | return "redirect:/owners/" + owner.getId(); 64 | } 65 | } 66 | 67 | public String initUpdateForm(Long petId, Model model) { 68 | model.addAttribute("pet", petService.findById(petId)); 69 | return VIEWS_PETS_CREATE_OR_UPDATE_FORM; 70 | } 71 | 72 | public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owner, Model model) { 73 | if (result.hasErrors()) { 74 | pet.setOwner(owner); 75 | model.addAttribute("pet", pet); 76 | return VIEWS_PETS_CREATE_OR_UPDATE_FORM; 77 | } else { 78 | owner.getPets().add(pet); 79 | petService.save(pet); 80 | return "redirect:/owners/" + owner.getId(); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/guru/springframework/sfgpetclinic/controllers/OwnerController.java: -------------------------------------------------------------------------------- 1 | package guru.springframework.sfgpetclinic.controllers; 2 | 3 | import guru.springframework.sfgpetclinic.fauxspring.BindingResult; 4 | import guru.springframework.sfgpetclinic.fauxspring.Model; 5 | import guru.springframework.sfgpetclinic.fauxspring.ModelAndView; 6 | import guru.springframework.sfgpetclinic.fauxspring.WebDataBinder; 7 | import guru.springframework.sfgpetclinic.model.Owner; 8 | import guru.springframework.sfgpetclinic.services.OwnerService; 9 | 10 | import javax.validation.Valid; 11 | import java.util.List; 12 | 13 | 14 | public class OwnerController { 15 | private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; 16 | 17 | private final OwnerService ownerService; 18 | 19 | public OwnerController(OwnerService ownerService) { 20 | this.ownerService = ownerService; 21 | } 22 | 23 | public void setAllowedFields(WebDataBinder dataBinder) { 24 | dataBinder.setDisallowedFields("id"); 25 | } 26 | 27 | public String findOwners(Model model){ 28 | model.addAttribute("owner", new Owner(null, null, null)); 29 | return "owners/findOwners"; 30 | } 31 | 32 | public String processFindForm(Owner owner, BindingResult result, Model model){ 33 | // allow parameterless GET request for /owners to return all records 34 | if (owner.getLastName() == null) { 35 | owner.setLastName(""); // empty string signifies broadest possible search 36 | } 37 | 38 | // find owners by last name 39 | List results = ownerService.findAllByLastNameLike("%"+ owner.getLastName() + "%"); 40 | 41 | if (results.isEmpty()) { 42 | // no owners found 43 | result.rejectValue("lastName", "notFound", "not found"); 44 | return "owners/findOwners"; 45 | } else if (results.size() == 1) { 46 | // 1 owner found 47 | owner = results.get(0); 48 | return "redirect:/owners/" + owner.getId(); 49 | } else { 50 | // multiple owners found 51 | model.addAttribute("selections", results); 52 | return "owners/ownersList"; 53 | } 54 | } 55 | 56 | public ModelAndView showOwner(Long ownerId) { 57 | ModelAndView mav = new ModelAndView("owners/ownerDetails"); 58 | mav.addObject(ownerService.findById(ownerId)); 59 | return mav; 60 | } 61 | 62 | public String initCreationForm(Model model) { 63 | model.addAttribute("owner", new Owner(null, null, null)); 64 | return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; 65 | } 66 | 67 | public String processCreationForm(@Valid Owner owner, BindingResult result) { 68 | if (result.hasErrors()) { 69 | return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; 70 | } else { 71 | Owner savedOwner = ownerService.save(owner); 72 | return "redirect:/owners/" + savedOwner.getId(); 73 | } 74 | } 75 | 76 | public String initUpdateOwnerForm(Long ownerId, Model model) { 77 | model.addAttribute(ownerService.findById(ownerId)); 78 | return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; 79 | } 80 | 81 | public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, Long ownerId) { 82 | if (result.hasErrors()) { 83 | return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; 84 | } else { 85 | owner.setId(ownerId); 86 | Owner savedOwner = ownerService.save(owner); 87 | return "redirect:/owners/" + savedOwner.getId(); 88 | } 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | guru.springframework 8 | testing-java-junit5 9 | 1.0-SNAPSHOT 10 | 11 | testing-java-junit5 12 | Testing Java with JUnit 5 13 | 14 | 15 | Spring Framework Guru 16 | https://springframework.guru/ 17 | 18 | 19 | 20 | 21 | jt 22 | John Thompson 23 | john@springframework.guru 24 | 25 | 26 | 27 | 2018 28 | 29 | 30 | 31 | The Apache License, Version 2.0 32 | http://www.apache.org/licenses/LICENSE-2.0.txt 33 | 34 | 35 | 36 | 37 | UTF-8 38 | UTF-8 39 | 11 40 | ${java.version} 41 | ${java.version} 42 | 5.3.1 43 | 44 | 45 | 46 | 47 | javax.validation 48 | validation-api 49 | 2.0.1.Final 50 | 51 | 52 | org.apache.commons 53 | commons-lang3 54 | 3.8.1 55 | 56 | 57 | org.junit.jupiter 58 | junit-jupiter-api 59 | ${junit-platform.version} 60 | test 61 | 62 | 63 | org.junit.jupiter 64 | junit-jupiter-engine 65 | ${junit-platform.version} 66 | test 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.apache.maven.plugins 74 | maven-compiler-plugin 75 | 3.8.0 76 | 77 | 78 | org.apache.maven.plugins 79 | maven-surefire-plugin 80 | 2.22.0 81 | 82 | 83 | --illegal-access=permit 84 | 85 | 86 | 87 | 88 | org.apache.maven.plugins 89 | maven-failsafe-plugin 90 | 2.22.0 91 | 92 | 93 | --illegal-access=permit 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------