org.springframework.samples.petclinic.model.PetType Java Examples
The following examples show how to use
org.springframework.samples.petclinic.model.PetType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractClinicServiceTests.java From DevOps-for-Web-Development with MIT License | 6 votes |
@Test @Transactional public void shouldInsertPetIntoDatabaseAndGenerateId() { Owner owner6 = this.clinicService.findOwnerById(6); int found = owner6.getPets().size(); Pet pet = new Pet(); pet.setName("bowser"); Collection<PetType> types = this.clinicService.findPetTypes(); pet.setType(EntityUtils.getById(types, PetType.class, 2)); pet.setBirthDate(new Date()); owner6.addPet(pet); assertThat(owner6.getPets().size()).isEqualTo(found + 1); this.clinicService.savePet(pet); this.clinicService.saveOwner(owner6); owner6 = this.clinicService.findOwnerById(6); assertThat(owner6.getPets().size()).isEqualTo(found + 1); // checks that id has been generated assertThat(pet.getId()).isNotNull(); }
Example #2
Source File: JdbcPetRepositoryImpl.java From audit4j-demo with Apache License 2.0 | 6 votes |
@Override public Pet findById(int id) throws DataAccessException { JdbcPet pet; try { Map<String, Object> params = new HashMap<String, Object>(); params.put("id", id); pet = this.namedParameterJdbcTemplate.queryForObject( "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id", params, new JdbcPetRowMapper()); } catch (EmptyResultDataAccessException ex) { throw new ObjectRetrievalFailureException(Pet.class, new Integer(id)); } Owner owner = this.ownerRepository.findById(pet.getOwnerId()); owner.addPet(pet); pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId())); List<Visit> visits = this.visitRepository.findByPetId(pet.getId()); for (Visit visit : visits) { pet.addVisit(visit); } return pet; }
Example #3
Source File: AbstractClinicServiceTests.java From audit4j-demo with Apache License 2.0 | 6 votes |
@Test @Transactional public void shouldInsertPetIntoDatabaseAndGenerateId() { Owner owner6 = this.clinicService.findOwnerById(6); int found = owner6.getPets().size(); Pet pet = new Pet(); pet.setName("bowser"); Collection<PetType> types = this.clinicService.findPetTypes(); pet.setType(EntityUtils.getById(types, PetType.class, 2)); pet.setBirthDate(new DateTime()); owner6.addPet(pet); assertThat(owner6.getPets().size()).isEqualTo(found + 1); this.clinicService.savePet(pet); this.clinicService.saveOwner(owner6); owner6 = this.clinicService.findOwnerById(6); assertThat(owner6.getPets().size()).isEqualTo(found + 1); // checks that id has been generated assertThat(pet.getId()).isNotNull(); }
Example #4
Source File: JdbcOwnerRepositoryImpl.java From audit4j-demo with Apache License 2.0 | 6 votes |
public void loadPetsAndVisits(final Owner owner) { Map<String, Object> params = new HashMap<String, Object>(); params.put("id", owner.getId().intValue()); final List<JdbcPet> pets = this.namedParameterJdbcTemplate.query( "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE owner_id=:id", params, new JdbcPetRowMapper() ); for (JdbcPet pet : pets) { owner.addPet(pet); pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId())); List<Visit> visits = this.visitRepository.findByPetId(pet.getId()); for (Visit visit : visits) { pet.addVisit(visit); } } }
Example #5
Source File: JdbcPetRepositoryImpl.java From DevOps-for-Web-Development with MIT License | 6 votes |
@Override public Pet findById(int id) throws DataAccessException { JdbcPet pet; try { Map<String, Object> params = new HashMap<>(); params.put("id", id); pet = this.namedParameterJdbcTemplate.queryForObject( "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id", params, new JdbcPetRowMapper()); } catch (EmptyResultDataAccessException ex) { throw new ObjectRetrievalFailureException(Pet.class, id); } Owner owner = this.ownerRepository.findById(pet.getOwnerId()); owner.addPet(pet); pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId())); List<Visit> visits = this.visitRepository.findByPetId(pet.getId()); for (Visit visit : visits) { pet.addVisit(visit); } return pet; }
Example #6
Source File: AbstractClinicServiceTests.java From DevOps-for-Web-Development with MIT License | 6 votes |
@Test @Transactional public void shouldInsertPetIntoDatabaseAndGenerateId() { Owner owner6 = this.clinicService.findOwnerById(6); int found = owner6.getPets().size(); Pet pet = new Pet(); pet.setName("bowser"); Collection<PetType> types = this.clinicService.findPetTypes(); pet.setType(EntityUtils.getById(types, PetType.class, 2)); pet.setBirthDate(new LocalDate()); owner6.addPet(pet); assertThat(owner6.getPets().size()).isEqualTo(found + 1); this.clinicService.savePet(pet); this.clinicService.saveOwner(owner6); owner6 = this.clinicService.findOwnerById(6); assertThat(owner6.getPets().size()).isEqualTo(found + 1); // checks that id has been generated assertThat(pet.getId()).isNotNull(); }
Example #7
Source File: AbstractClinicServiceTests.java From docker-workflow-plugin with MIT License | 6 votes |
@Test @Transactional public void shouldInsertPetIntoDatabaseAndGenerateId() { Owner owner6 = this.clinicService.findOwnerById(6); int found = owner6.getPets().size(); Pet pet = new Pet(); pet.setName("bowser"); Collection<PetType> types = this.clinicService.findPetTypes(); pet.setType(EntityUtils.getById(types, PetType.class, 2)); pet.setBirthDate(new DateTime()); owner6.addPet(pet); assertThat(owner6.getPets().size()).isEqualTo(found + 1); this.clinicService.savePet(pet); this.clinicService.saveOwner(owner6); owner6 = this.clinicService.findOwnerById(6); assertThat(owner6.getPets().size()).isEqualTo(found + 1); // checks that id has been generated assertThat(pet.getId()).isNotNull(); }
Example #8
Source File: JdbcPetRepositoryImpl.java From docker-workflow-plugin with MIT License | 6 votes |
@Override public Pet findById(int id) throws DataAccessException { JdbcPet pet; try { Map<String, Object> params = new HashMap<String, Object>(); params.put("id", id); pet = this.namedParameterJdbcTemplate.queryForObject( "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id", params, new JdbcPetRowMapper()); } catch (EmptyResultDataAccessException ex) { throw new ObjectRetrievalFailureException(Pet.class, new Integer(id)); } Owner owner = this.ownerRepository.findById(pet.getOwnerId()); owner.addPet(pet); pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId())); List<Visit> visits = this.visitRepository.findByPetId(pet.getId()); for (Visit visit : visits) { pet.addVisit(visit); } return pet; }
Example #9
Source File: JdbcOwnerRepositoryImpl.java From docker-workflow-plugin with MIT License | 6 votes |
public void loadPetsAndVisits(final Owner owner) { Map<String, Object> params = new HashMap<String, Object>(); params.put("id", owner.getId().intValue()); final List<JdbcPet> pets = this.namedParameterJdbcTemplate.query( "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE owner_id=:id", params, new JdbcPetRowMapper() ); for (JdbcPet pet : pets) { owner.addPet(pet); pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId())); List<Visit> visits = this.visitRepository.findByPetId(pet.getId()); for (Visit visit : visits) { pet.addVisit(visit); } } }
Example #10
Source File: AbstractClinicServiceTests.java From DevOps-for-Web-Development with MIT License | 5 votes |
@Test public void shouldFindAllPetTypes() { Collection<PetType> petTypes = this.clinicService.findPetTypes(); PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); assertThat(petType1.getName()).isEqualTo("cat"); PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4); assertThat(petType4.getName()).isEqualTo("snake"); }
Example #11
Source File: JdbcPetRepositoryImpl.java From audit4j-demo with Apache License 2.0 | 5 votes |
@Override public List<PetType> findPetTypes() throws DataAccessException { Map<String, Object> params = new HashMap<String, Object>(); return this.namedParameterJdbcTemplate.query( "SELECT id, name FROM types ORDER BY name", params, BeanPropertyRowMapper.newInstance(PetType.class)); }
Example #12
Source File: PetTypeFormatter.java From DevOps-for-Web-Development with MIT License | 5 votes |
@Override public PetType parse(String text, Locale locale) throws ParseException { Collection<PetType> findPetTypes = this.clinicService.findPetTypes(); for (PetType type : findPetTypes) { if (type.getName().equals(text)) { return type; } } throw new ParseException("type not found: " + text, 0); }
Example #13
Source File: PetTypeFormatter.java From audit4j-demo with Apache License 2.0 | 5 votes |
@Override public PetType parse(String text, Locale locale) throws ParseException { Collection<PetType> findPetTypes = this.clinicService.findPetTypes(); for (PetType type : findPetTypes) { if (type.getName().equals(text)) { return type; } } throw new ParseException("type not found: " + text, 0); }
Example #14
Source File: PetTypeFormatterTests.java From DevOps-for-Web-Development with MIT License | 5 votes |
@Test public void testPrint() { PetType petType = new PetType(); petType.setName("Hamster"); String petTypeName = petTypeFormatter.print(petType, Locale.ENGLISH); assertEquals("Hamster", petTypeName); }
Example #15
Source File: JdbcPetRepositoryImpl.java From DevOps-for-Web-Development with MIT License | 5 votes |
@Override public List<PetType> findPetTypes() throws DataAccessException { Map<String, Object> params = new HashMap<>(); return this.namedParameterJdbcTemplate.query( "SELECT id, name FROM types ORDER BY name", params, BeanPropertyRowMapper.newInstance(PetType.class)); }
Example #16
Source File: PetTypeFormatterTests.java From DevOps-for-Web-Development with MIT License | 5 votes |
/** * Helper method to produce some sample pet types just for test purpose * * @return {@link Collection} of {@link PetType} */ private Collection<PetType> makePetTypes() { Collection<PetType> petTypes = new ArrayList<>(); petTypes.add(new PetType(){ { setName("Dog"); } }); petTypes.add(new PetType(){ { setName("Bird"); } }); return petTypes; }
Example #17
Source File: PetTypeFormatter.java From DevOps-for-Web-Development with MIT License | 5 votes |
@Override public PetType parse(String text, Locale locale) throws ParseException { Collection<PetType> findPetTypes = this.clinicService.findPetTypes(); for (PetType type : findPetTypes) { if (type.getName().equals(text)) { return type; } } throw new ParseException("type not found: " + text, 0); }
Example #18
Source File: JdbcPetRepositoryImpl.java From docker-workflow-plugin with MIT License | 5 votes |
@Override public List<PetType> findPetTypes() throws DataAccessException { Map<String, Object> params = new HashMap<String, Object>(); return this.namedParameterJdbcTemplate.query( "SELECT id, name FROM types ORDER BY name", params, BeanPropertyRowMapper.newInstance(PetType.class)); }
Example #19
Source File: JdbcOwnerRepositoryImpl.java From DevOps-for-Web-Development with MIT License | 5 votes |
public void loadPetsAndVisits(final Owner owner) { Map<String, Object> params = new HashMap<>(); params.put("id", owner.getId()); final List<JdbcPet> pets = this.namedParameterJdbcTemplate.query( "SELECT pets.id, name, birth_date, type_id, owner_id, visits.id as visit_id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id", params, new JdbcPetVisitExtractor() ); Collection<PetType> petTypes = getPetTypes(); for (JdbcPet pet : pets) { pet.setType(EntityUtils.getById(petTypes, PetType.class, pet.getTypeId())); owner.addPet(pet); } }
Example #20
Source File: JdbcOwnerRepositoryImpl.java From DevOps-for-Web-Development with MIT License | 5 votes |
public void loadPetsAndVisits(final Owner owner) { Map<String, Object> params = new HashMap<>(); params.put("id", owner.getId()); final List<JdbcPet> pets = this.namedParameterJdbcTemplate.query( "SELECT pets.id, name, birth_date, type_id, owner_id, visits.id as visit_id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id", params, new JdbcPetVisitExtractor() ); Collection<PetType> petTypes = getPetTypes(); for (JdbcPet pet : pets) { pet.setType(EntityUtils.getById(petTypes, PetType.class, pet.getTypeId())); owner.addPet(pet); } }
Example #21
Source File: JdbcPetRepositoryImpl.java From DevOps-for-Web-Development with MIT License | 5 votes |
@Override public List<PetType> findPetTypes() throws DataAccessException { Map<String, Object> params = new HashMap<>(); return this.namedParameterJdbcTemplate.query( "SELECT id, name FROM types ORDER BY name", params, BeanPropertyRowMapper.newInstance(PetType.class)); }
Example #22
Source File: AbstractClinicServiceTests.java From audit4j-demo with Apache License 2.0 | 5 votes |
@Test public void shouldFindAllPetTypes() { Collection<PetType> petTypes = this.clinicService.findPetTypes(); PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); assertThat(petType1.getName()).isEqualTo("cat"); PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4); assertThat(petType4.getName()).isEqualTo("snake"); }
Example #23
Source File: PetTypeFormatterTests.java From DevOps-for-Web-Development with MIT License | 5 votes |
@Test public void testPrint() { PetType petType = new PetType(); petType.setName("Hamster"); String petTypeName = petTypeFormatter.print(petType, Locale.ENGLISH); assertEquals("Hamster", petTypeName); }
Example #24
Source File: PetTypeFormatterTests.java From DevOps-for-Web-Development with MIT License | 5 votes |
/** * Helper method to produce some sample pet types just for test purpose * * @return {@link Collection} of {@link PetType} */ private Collection<PetType> makePetTypes() { Collection<PetType> petTypes = new ArrayList<>(); petTypes.add(new PetType(){ { setName("Dog"); } }); petTypes.add(new PetType(){ { setName("Bird"); } }); return petTypes; }
Example #25
Source File: PetControllerTests.java From DevOps-for-Web-Development with MIT License | 5 votes |
@Before public void setup() { this.mockMvc = MockMvcBuilders .standaloneSetup(petController) .setConversionService(formattingConversionServiceFactoryBean.getObject()) .build(); PetType cat = new PetType(); cat.setId(3); cat.setName("hamster"); given(this.clinicService.findPetTypes()).willReturn(Lists.newArrayList(cat)); given(this.clinicService.findOwnerById(TEST_OWNER_ID)).willReturn(new Owner()); given(this.clinicService.findPetById(TEST_PET_ID)).willReturn(new Pet()); }
Example #26
Source File: AbstractClinicServiceTests.java From DevOps-for-Web-Development with MIT License | 5 votes |
@Test public void shouldFindAllPetTypes() { Collection<PetType> petTypes = this.clinicService.findPetTypes(); PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); assertThat(petType1.getName()).isEqualTo("cat"); PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4); assertThat(petType4.getName()).isEqualTo("snake"); }
Example #27
Source File: PetTypeFormatter.java From docker-workflow-plugin with MIT License | 5 votes |
@Override public PetType parse(String text, Locale locale) throws ParseException { Collection<PetType> findPetTypes = this.clinicService.findPetTypes(); for (PetType type : findPetTypes) { if (type.getName().equals(text)) { return type; } } throw new ParseException("type not found: " + text, 0); }
Example #28
Source File: AbstractClinicServiceTests.java From docker-workflow-plugin with MIT License | 5 votes |
@Test public void shouldFindAllPetTypes() { Collection<PetType> petTypes = this.clinicService.findPetTypes(); PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); assertThat(petType1.getName()).isEqualTo("cat"); PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4); assertThat(petType4.getName()).isEqualTo("snake"); }
Example #29
Source File: JpaPetRepositoryImpl.java From audit4j-demo with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public List<PetType> findPetTypes() { return this.em.createQuery("SELECT ptype FROM PetType ptype ORDER BY ptype.name").getResultList(); }
Example #30
Source File: PetController.java From audit4j-demo with Apache License 2.0 | 4 votes |
@ModelAttribute("types") public Collection<PetType> populatePetTypes() { return this.clinicService.findPetTypes(); }