@Test public void shouldAddPhone() { OutsiderTeacher teacher = scenarioHelper.createEmptyOutsiderTeacher(); Phone phone = PhoneTest.createOne(scenarioHelper.createPhoneType()); assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getPhones()) .isEmpty(); Phone saved = outsiderTeacherManager.addPhone(teacher.getId(), phone); assertThat(phoneRepository.findAll()).hasSize(1); assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getPhones()) .hasSize(1); assertThat(saved.getId()).isNotNull(); }
@Test public void shouldAddEmail() { OutsiderTeacher teacher = scenarioHelper.createEmptyOutsiderTeacher(); Email email = EmailTest.createOne(scenarioHelper.createEmailType()); assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getEmails()) .isEmpty(); Email saved = outsiderTeacherManager.addEmail(teacher.getId(), email); assertThat(emailRepository.findAll()).hasSize(1); assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getEmails()) .hasSize(1); assertThat(saved.getId()).isNotNull(); }
@Test public void shouldAddAddress() { OutsiderTeacher teacher = scenarioHelper.createEmptyOutsiderTeacher(); Address address = AddressTest.createOne(scenarioHelper.createAddressType()); assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getAddresses()) .isEmpty(); Address saved = outsiderTeacherManager.addAddress(teacher.getId(), address); assertThat(addressRepository.findAll()).hasSize(1); assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getAddresses()) .hasSize(1); assertThat(saved.getId()).isNotNull(); }
@Test public void shouldFindOneById() { OutsiderTeacher model = OutsiderTeacherTest.createOne(); scenarioHelper.createOutsiderTeacher(model); OutsiderTeacher fetched = outsiderTeacherManager.findOneById(model.getId()); assertThat(fetched).isNotNull(); }
@Test public void shouldCreate() { OutsiderTeacher model = OutsiderTeacherTest.createOneEmpty(); OutsiderTeacher saved = outsiderTeacherManager.create(model); OutsiderTeacher fetched = outsiderTeacherManager.findOneById(model.getId()); assertThat(model.getId()).isNotNull(); assertThat(saved.getId()).isNotNull(); assertThat(fetched.getName()).isEqualTo(model.getName()); assertThat(fetched.getContact()).isEqualTo(model.getContact()); }
@Test public void shouldRemovePhone() { OutsiderTeacher teacher = scenarioHelper.createOutsiderTeacher(); assertThat(teacher.getContact().getPhones()).isNotEmpty(); for (Phone phone : teacher.getContact().getPhones()) { outsiderTeacherManager.removePhone(phone.getId()); } assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getPhones()) .isEmpty(); assertThat(phoneRepository.findAll()).isEmpty(); }
@Test public void shouldRemoveEmail() { OutsiderTeacher teacher = scenarioHelper.createOutsiderTeacher(); assertThat(teacher.getContact().getEmails()).isNotEmpty(); for (Email email : teacher.getContact().getEmails()) { outsiderTeacherManager.removeEmail(email.getId()); } assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getEmails()) .isEmpty(); assertThat(emailRepository.findAll()).isEmpty(); }
@Test public void shouldRemoveAddress() { OutsiderTeacher teacher = scenarioHelper.createOutsiderTeacher(); assertThat(teacher.getContact().getAddresses()).isNotEmpty(); for (Address address : teacher.getContact().getAddresses()) { outsiderTeacherManager.removeAddress(address.getId()); } assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getAddresses()) .isEmpty(); assertThat(addressRepository.findAll()).isEmpty(); }
@Test public void shouldCreateAddressAndEmailAndPhoneOnCascade() { OutsiderTeacher model = OutsiderTeacherTest.createOne(); scenarioHelper.createOutsiderTeacher(model); OutsiderTeacher fetched = outsiderTeacherManager.findOneById(model.getId()); assertThat(addressRepository.findAll()).hasSameSizeAs(model.getContact().getAddresses()); assertThat(emailRepository.findAll()).hasSameSizeAs(model.getContact().getEmails()); assertThat(phoneRepository.findAll()).hasSameSizeAs(model.getContact().getPhones()); assertThat(fetched.getContact().getAddresses()) .hasSameSizeAs(model.getContact().getAddresses()); assertThat(fetched.getContact().getEmails()).hasSameSizeAs(model.getContact().getEmails()); assertThat(fetched.getContact().getPhones()).hasSameSizeAs(model.getContact().getPhones()); }
@Test(expected = TeacherResourceNotFoundException.class) public void shouldFailFindOneByIdWithNonExisting() { outsiderTeacherManager.findOneById(156L); }
@Test(expected = IllegalArgumentException.class) public void shouldFailFindOneByIdWithNull() { outsiderTeacherManager.findOneById(null); }