Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.test.builder; |
| 2 | |||
| 3 | import java.text.ParseException; |
||
| 4 | import java.text.SimpleDateFormat; |
||
| 5 | import java.util.Date; |
||
| 6 | |||
| 7 | import br.gov.al.saude.scg.model.view.PessoaFisicaView; |
||
| 8 | import br.gov.al.saude.scs.model.view.ServidorView; |
||
| 9 | import br.gov.al.saude.test.unidade.generic.builder.AbstractEntidadeBuilder; |
||
| 10 | |||
| 11 | |||
| 12 | public class ServidorViewBuilder extends AbstractEntidadeBuilder<ServidorView> { |
||
| 13 | |||
| 14 | public ServidorViewBuilder comSequencial(String codigo) { |
||
| 15 | PessoaFisicaView pessoa = new PessoaFisicaView(); |
||
| 16 | pessoa.setSequencialPessoa(parseLong(codigo)); |
||
| 17 | entidade.setPessoa(pessoa); |
||
| 18 | return this; |
||
| 19 | } |
||
| 20 | |||
| 21 | public ServidorViewBuilder comPessoaFisica(PessoaFisicaView pessoaFisica) { |
||
| 22 | entidade.setPessoa(pessoaFisica); |
||
| 23 | return this; |
||
| 24 | } |
||
| 25 | |||
| 26 | public ServidorViewBuilder comDataNascimento(String dataNascimento) { |
||
| 27 | entidade.setDataNascimento(parseDate(dataNascimento, "dd/MM/yyyy")); |
||
| 28 | return this; |
||
| 29 | } |
||
| 30 | |||
| 31 | public ServidorViewBuilder comNacionalidade(String nacionalidade) { |
||
| 32 | entidade.setNacionalidade(nacionalidade); |
||
| 33 | return this; |
||
| 34 | } |
||
| 35 | |||
| 36 | public ServidorViewBuilder comNome(String nome) { |
||
| 37 | entidade.setNome(nome); |
||
| 38 | return this; |
||
| 39 | } |
||
| 40 | |||
| 41 | public ServidorViewBuilder comSexo(String sexo) { |
||
| 42 | entidade.setSexo(sexo); |
||
| 43 | return this; |
||
| 44 | } |
||
| 45 | |||
| 46 | @Override |
||
| 47 | protected void inicializarDadosDefault() { |
||
| 48 | entidade = new ServidorView(); |
||
| 49 | } |
||
| 50 | |||
| 51 | private Date parseDate(String dataString, String pattern) { |
||
| 52 | SimpleDateFormat format = new SimpleDateFormat(pattern); |
||
| 53 | try { |
||
| 54 | return format.parse(dataString); |
||
| 55 | } catch (ParseException e) { |
||
| 56 | throw new RuntimeException("Não foi possível converter a data."); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | } |