Examples of PersonDTO


Examples of net.petrikainulainen.spring.datajpa.dto.PersonDTO

   
    @Test
    public void submitEmptyCreatePersonForm() {
        MockHttpServletRequest mockRequest = new MockHttpServletRequest("/person/create", "POST");
       
        PersonDTO created = new PersonDTO();
       
        RedirectAttributes attributes = new RedirectAttributesModelMap();
        BindingResult result = bindAndValidate(mockRequest, created);
       
        String view = controller.submitCreatePersonForm(created, result, attributes);
View Full Code Here

Examples of net.petrikainulainen.spring.datajpa.dto.PersonDTO

    @Test
    public void submitCreatePersonFormWithEmptyFirstName() {
        MockHttpServletRequest mockRequest = new MockHttpServletRequest("/person/create", "POST");

        PersonDTO created = PersonTestUtil.createDTO(null, null, LAST_NAME);

        RedirectAttributes attributes = new RedirectAttributesModelMap();
        BindingResult result = bindAndValidate(mockRequest, created);

        String view = controller.submitCreatePersonForm(created, result, attributes);
View Full Code Here

Examples of net.petrikainulainen.spring.datajpa.dto.PersonDTO

    @Test
    public void submitCreatePersonFormWithEmptyLastName() {
        MockHttpServletRequest mockRequest = new MockHttpServletRequest("/person/create", "POST");

        PersonDTO created = PersonTestUtil.createDTO(null, FIRST_NAME, null);

        RedirectAttributes attributes = new RedirectAttributesModelMap();
        BindingResult result = bindAndValidate(mockRequest, created);

        String view = controller.submitCreatePersonForm(created, result, attributes);
View Full Code Here

Examples of net.petrikainulainen.spring.datajpa.dto.PersonDTO

        verify(personServiceMock, times(1)).findById(PERSON_ID);
        verifyNoMoreInteractions(personServiceMock);
       
        assertEquals(PersonController.PERSON_EDIT_FORM_VIEW, view);
       
        PersonDTO formObject = (PersonDTO) model.asMap().get(PersonController.MODEL_ATTIRUTE_PERSON);

        assertNotNull(formObject);
        assertEquals(person.getId(), formObject.getId());
        assertEquals(person.getFirstName(), formObject.getFirstName());
        assertEquals(person.getLastName(), formObject.getLastName());
    }
View Full Code Here

Examples of net.petrikainulainen.spring.datajpa.dto.PersonDTO

    }
   
    @Test
    public void submitEditPersonForm() throws PersonNotFoundException {
        MockHttpServletRequest mockRequest = new MockHttpServletRequest("/person/edit", "POST");
        PersonDTO updated = PersonTestUtil.createDTO(PERSON_ID, FIRST_NAME_UPDATED, LAST_NAME_UPDATED);
        Person person = PersonTestUtil.createModelObject(PERSON_ID, FIRST_NAME_UPDATED, LAST_NAME_UPDATED);
       
        when(personServiceMock.update(updated)).thenReturn(person);
       
        initMessageSourceForFeedbackMessage(PersonController.FEEDBACK_MESSAGE_KEY_PERSON_EDITED);
       
        BindingResult bindingResult = bindAndValidate(mockRequest, updated);
        RedirectAttributes attributes = new RedirectAttributesModelMap();
       
        String view = controller.submitEditPersonForm(updated, bindingResult, attributes);
       
        verify(personServiceMock, times(1)).update(updated);
        verifyNoMoreInteractions(personServiceMock);
       
        String expectedView = createExpectedRedirectViewPath(PersonController.REQUEST_MAPPING_LIST);
        assertEquals(expectedView, view);

        assertFeedbackMessage(attributes, PersonController.FEEDBACK_MESSAGE_KEY_PERSON_EDITED);
       
        assertEquals(updated.getFirstName(), person.getFirstName());
        assertEquals(updated.getLastName(), person.getLastName());
    }
View Full Code Here

Examples of net.petrikainulainen.spring.datajpa.dto.PersonDTO

    }
   
    @Test
    public void submitEditPersonFormWhenPersonIsNotFound() throws PersonNotFoundException {
        MockHttpServletRequest mockRequest = new MockHttpServletRequest("/person/edit", "POST");
        PersonDTO updated = PersonTestUtil.createDTO(PERSON_ID, FIRST_NAME_UPDATED, LAST_NAME_UPDATED);
       
        when(personServiceMock.update(updated)).thenThrow(new PersonNotFoundException());
        initMessageSourceForErrorMessage(PersonController.ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND);
       
        BindingResult bindingResult = bindAndValidate(mockRequest, updated);
View Full Code Here

Examples of org.company.recordshop.service.dto.PersonDto

    PersonExample example = personDtoTranslator.exampleFromDto(filter);
    found = customerServiceModelDomainService.findPersonByExample(example);

    for (Person object : found) {
      PersonDto item = personDtoTranslator.toDto(object);
      result.add(item);
    }
    return result;
  }
View Full Code Here

Examples of org.company.recordshop.service.dto.PersonDto

        .findPersonByExampleCount(example, firstResult, maxResults,
            sortProperty, isAscending);
    List<PersonDto> result = new ArrayList<PersonDto>();

    for (Person object : range) {
      PersonDto item = personDtoTranslator.toDto(object);
      result.add(item);
    }
    return result;
  }
View Full Code Here

Examples of org.company.recordshop.service.dto.PersonDto

  PersonDto toDto(final Person source, final Map<Object, Object> translated) {
    if (translated.containsKey((source))) {
      return (PersonDto) translated.get(source);
    }
    Assert.notNull(source, "argument [source] may not be null");
    PersonDto result = new PersonDto(source.getId(), source.getVersion());
    result.setFirstName(source.getFirstName());
    result.setLastName(source.getLastName());
    result.setBirthDate(source.getBirthDate());

    translated.put(source, result);

    for (Relation element : source.getRelationsFrom()) {
      result.addToRelationsFrom(relationDtoTranslator.toDto(element,
          translated));
    }

    for (Relation element : source.getRelationsTo()) {
      result.addToRelationsTo(relationDtoTranslator.toDto(element,
          translated));
    }

    return result;
  }
View Full Code Here

Examples of org.company.recordshop.service.dto.PersonDto

    private CustomerServiceModelLocalService customerServiceModelService;

    @Test
    public void testCreateCrossRelations() {

        PersonDto manDto = new PersonDto();
        manDto.setLastName("Johnson");
        manDto.setFirstName("John");
        manDto.setBirthDate(new DateTime());
        Long manId = customerServiceModelService.createPerson(manDto);

        PersonDto womanDto = new PersonDto();
        womanDto.setLastName("Butterfly");
        womanDto.setFirstName("Susan");
        womanDto.setBirthDate(new DateTime());
        Long womanId = customerServiceModelService.createPerson(womanDto);
        flush();

        /* Husband: Relation from man to woman */
        RelationDto husbandDto = new RelationDto();
        husbandDto.setName("Husband");
        husbandDto.setPersonFrom(customerServiceModelService.readPersonAsPersonDto(manId));
        husbandDto.setPersonTo(customerServiceModelService.readPersonAsPersonDto(womanId));
        Long husbandId = customerServiceModelService.createRelation(husbandDto);
        flush();
        husbandDto = customerServiceModelService.readRelationAsRelationDto(husbandId);

        Assert.assertTrue(husbandId > 0);
        Assert.assertEquals(0, husbandDto.getVersion().intValue());
        Assert.assertEquals(1, husbandDto.getPersonFrom().getVersion().intValue());
        Assert.assertEquals(1, husbandDto.getPersonTo().getVersion().intValue());

        /*
         * Within the create service the opposite of a bi-directional association is updated, so we
         * always need to get the latest version of the associated object after the transaction has
         * finished. Here it's not sufficient to do: manDto = husbandRelationDto.getPersonFrom();
         * Because the man Person object is flushed at the end of the transaction and a new version
         * is born. So in these situations you'll need to use the read serivce method to get the
         * latest version from the store. If you forget to do this you will run into a
         * ConcurrentUpdateException.
         */
        manDto = customerServiceModelService.readPersonAsPersonDto(manId);
        womanDto = customerServiceModelService.readPersonAsPersonDto(womanId);
        Assert.assertEquals(1, manDto.getVersion().intValue());
        Assert.assertEquals(1, womanDto.getVersion().intValue());

        /* Wife: Relation form woman to man */
        RelationDto wifeDto = new RelationDto();
        wifeDto.setName("Wife");
        wifeDto.setPersonFrom(husbandDto.getPersonTo());
        wifeDto.setPersonTo(husbandDto.getPersonFrom());
        Long wifeRelationId = customerServiceModelService.createRelation(wifeDto);
        flush();

        wifeDto = customerServiceModelService.readRelationAsRelationDto(wifeRelationId);

        Assert.assertEquals(womanId, wifeDto.getPersonFrom().getId());
        Assert.assertEquals(manId, wifeDto.getPersonTo().getId());

        manDto = customerServiceModelService.readPersonAsPersonDto(manDto.getId());
        womanDto = customerServiceModelService.readPersonAsPersonDto(womanDto.getId());
        Assert.assertEquals(2, manDto.getVersion().intValue());
        Assert.assertEquals(2, womanDto.getVersion().intValue());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.