From 6bf24ccd34abded8f45d305037084f9f44b4f585 Mon Sep 17 00:00:00 2001 From: Nelson Date: Thu, 15 Oct 2020 23:41:10 -0300 Subject: [PATCH 1/3] =?UTF-8?q?Inclusion=20of=20support=20for=20Brazil=20?= =?UTF-8?q?=C2=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/devskiller/jfairy/BrFairyModule.java | 36 +++++++ .../br/BrVATIdentificationNumberProvider.java | 98 +++++++++++++++++ .../producer/person/locale/br/BrAddress.java | 27 +++++ .../person/locale/br/BrAddressProvider.java | 26 +++++ .../BrNationalIdentityCardNumberProvider.java | 100 ++++++++++++++++++ .../locale/br/BrPassportNumberProvider.java | 17 +++ .../jfairy/producer/util/LanguageCode.java | 3 +- src/main/resources/jfairy_br.yml | 28 +++++ ...VATIdentificationNumberProviderSpec.groovy | 36 +++++++ ...ionalIdentityCardNumberProviderSpec.groovy | 55 ++++++++++ .../br/BrPassportNumberProviderSpec.groovy | 38 +++++++ 11 files changed, 463 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/devskiller/jfairy/BrFairyModule.java create mode 100644 src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java create mode 100644 src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrAddress.java create mode 100644 src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrAddressProvider.java create mode 100644 src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrNationalIdentityCardNumberProvider.java create mode 100644 src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrPassportNumberProvider.java create mode 100644 src/main/resources/jfairy_br.yml create mode 100644 src/test/groovy/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProviderSpec.groovy create mode 100644 src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrNationalIdentityCardNumberProviderSpec.groovy create mode 100644 src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrPassportNumberProviderSpec.groovy diff --git a/src/main/java/com/devskiller/jfairy/BrFairyModule.java b/src/main/java/com/devskiller/jfairy/BrFairyModule.java new file mode 100644 index 00000000..b19fd635 --- /dev/null +++ b/src/main/java/com/devskiller/jfairy/BrFairyModule.java @@ -0,0 +1,36 @@ +package com.devskiller.jfairy; + +import com.devskiller.jfairy.data.DataMaster; +import com.devskiller.jfairy.producer.RandomGenerator; +import com.devskiller.jfairy.producer.VATIdentificationNumberProvider; +import com.devskiller.jfairy.producer.company.locale.br.BrVATIdentificationNumberProvider; +import com.devskiller.jfairy.producer.person.AddressProvider; +import com.devskiller.jfairy.producer.person.NationalIdentificationNumberFactory; +import com.devskiller.jfairy.producer.person.NationalIdentityCardNumberProvider; +import com.devskiller.jfairy.producer.person.PassportNumberProvider; +import com.devskiller.jfairy.producer.person.locale.NoNationalIdentificationNumberFactory; +import com.devskiller.jfairy.producer.person.locale.br.BrAddressProvider; +import com.devskiller.jfairy.producer.person.locale.br.BrNationalIdentityCardNumberProvider; +import com.devskiller.jfairy.producer.person.locale.br.BrPassportNumberProvider; + +/** + * @author Nelson Rodrigues da Silva Júnior + * @since 15.10.2020 + */ +public class BrFairyModule extends FairyModule { + + public BrFairyModule(DataMaster dataMaster, RandomGenerator randomGenerator) { + super(dataMaster, randomGenerator); + } + + @Override + protected void configure() { + super.configure(); + bind(NationalIdentificationNumberFactory.class).to(NoNationalIdentificationNumberFactory.class); + bind(NationalIdentityCardNumberProvider.class).to(BrNationalIdentityCardNumberProvider.class); + bind(VATIdentificationNumberProvider.class).to(BrVATIdentificationNumberProvider.class); + bind(AddressProvider.class).to(BrAddressProvider.class); + bind(PassportNumberProvider.class).to(BrPassportNumberProvider.class); + } + +} diff --git a/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java b/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java new file mode 100644 index 00000000..3698436c --- /dev/null +++ b/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java @@ -0,0 +1,98 @@ +package com.devskiller.jfairy.producer.company.locale.br; + +import java.util.Set; + +import com.google.common.collect.Sets; +import com.google.inject.Inject; + +import com.devskiller.jfairy.producer.BaseProducer; +import com.devskiller.jfairy.producer.VATIdentificationNumberProvider; + +import static java.lang.String.valueOf; +import static java.lang.System.arraycopy; +import static org.apache.commons.lang3.StringUtils.leftPad; + +/** + * Brazilian VAT Identification Number (known as the National Register of Legal Entities or CNPJ in Brazil) + * + * @author Nelson Rodrigues da Silva Júnior + * @since 15.10.2020 + */ +public class BrVATIdentificationNumberProvider implements VATIdentificationNumberProvider { + + private static final int EIN_LENGTH = 14; + private static final int[] pesoCNPJ = {6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2}; + + private BaseProducer baseProducer; + + @Inject + public BrVATIdentificationNumberProvider(BaseProducer baseProducer) { + this.baseProducer = baseProducer; + } + + @Override + public String get() { + char[] ein = new char[EIN_LENGTH]; + + return valueOf(ein); + } + + private int randomiza(int n) { + int ranNum = (int) (Math.random() * n); + return ranNum; + } + + private int mod(int dividendo, int divisor) { + return (int) Math.round(dividendo - (Math.floor(dividendo / divisor) * divisor)); + } + + public String cnpj() { + int n = 9; + int n1 = randomiza(n); + int n2 = randomiza(n); + int n3 = randomiza(n); + int n4 = randomiza(n); + int n5 = randomiza(n); + int n6 = randomiza(n); + int n7 = randomiza(n); + int n8 = randomiza(n); + int n9 = 0; //randomiza(n); + int n10 = 0; //randomiza(n); + int n11 = 0; //randomiza(n); + int n12 = 1; //randomiza(n); + int d1 = n12 * 2 + n11 * 3 + n10 * 4 + n9 * 5 + n8 * 6 + n7 * 7 + n6 * 8 + n5 * 9 + n4 * 2 + n3 * 3 + n2 * 4 + n1 * 5; + + d1 = 11 - (mod(d1, 11)); + + if (d1 >= 10) + d1 = 0; + + int d2 = d1 * 2 + n12 * 3 + n11 * 4 + n10 * 5 + n9 * 6 + n8 * 7 + n7 * 8 + n6 * 9 + n5 * 2 + n4 * 3 + n3 * 4 + n2 * 5 + n1 * 6; + + d2 = 11 - (mod(d2, 11)); + + if (d2 >= 10) + d2 = 0; + + return "" + n1 + n2 + "." + n3 + n4 + n5 + "." + n6 + n7 + n8 + "/" + n9 + n10 + n11 + n12 + "-" + d1 + d2; + } + + public boolean isValid(String cnpj) { + cnpj = cnpj.trim().replace(".", "").replace("-", ""); + if ((cnpj==null)||(cnpj.length()!=14)) return false; + + Integer digito1 = calcularDigito(cnpj.substring(0,12), pesoCNPJ); + Integer digito2 = calcularDigito(cnpj.substring(0,12) + digito1, pesoCNPJ); + return cnpj.equals(cnpj.substring(0,12) + digito1.toString() + digito2.toString()); + } + + private static int calcularDigito(String str, int[] peso) { + int soma = 0; + for (int indice=str.length()-1, digito; indice >= 0; indice-- ) { + digito = Integer.parseInt(str.substring(indice,indice+1)); + soma += digito*peso[peso.length-str.length()+indice]; + } + soma = 11 - soma % 11; + return soma > 9 ? 0 : soma; + } +} diff --git a/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrAddress.java b/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrAddress.java new file mode 100644 index 00000000..0bd4d7e4 --- /dev/null +++ b/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrAddress.java @@ -0,0 +1,27 @@ +package com.devskiller.jfairy.producer.person.locale.br; + +import com.devskiller.jfairy.producer.person.locale.AbstractAddress; + +import static org.apache.commons.lang3.StringUtils.isNotBlank; + +/** + * @author Nelson Rodrigues da Silva Júnior + * @since 15.10.2020 + */ +public class BrAddress extends AbstractAddress { + + public BrAddress(String streetNumber, String street, String apartmentNumber, String city, String postalCode) { + super(street, streetNumber, apartmentNumber, postalCode, city); + } + + @Override + public String getAddressLine1() { + return street + ", " + streetNumber + + (isNotBlank(apartmentNumber) ? " APT " + apartmentNumber : ""); + } + + @Override + public String getAddressLine2() { + return postalCode + " " + city; + } +} diff --git a/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrAddressProvider.java b/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrAddressProvider.java new file mode 100644 index 00000000..7694c6cb --- /dev/null +++ b/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrAddressProvider.java @@ -0,0 +1,26 @@ +package com.devskiller.jfairy.producer.person.locale.br; + +import javax.inject.Inject; + +import com.devskiller.jfairy.data.DataMaster; +import com.devskiller.jfairy.producer.BaseProducer; +import com.devskiller.jfairy.producer.person.AbstractAddressProvider; + +/** + * @author Nelson Rodrigues da Silva Júnior + * @since 15.10.2020 + */ +public class BrAddressProvider extends AbstractAddressProvider { + + @Inject + public BrAddressProvider(DataMaster dataMaster, BaseProducer baseProducer) { + super(dataMaster, baseProducer); + } + + @Override + public BrAddress get() { + return new BrAddress(getStreetNumber(), getStreet(), getApartmentNumber(), + getCity(), getPostalCode()); + } + +} diff --git a/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrNationalIdentityCardNumberProvider.java b/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrNationalIdentityCardNumberProvider.java new file mode 100644 index 00000000..1bc8765b --- /dev/null +++ b/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrNationalIdentityCardNumberProvider.java @@ -0,0 +1,100 @@ +package com.devskiller.jfairy.producer.person.locale.br; + +import java.util.List; + +import com.google.common.collect.Lists; +import com.google.inject.Inject; + +import com.devskiller.jfairy.producer.BaseProducer; +import com.devskiller.jfairy.producer.person.NationalIdentityCardNumberProvider; + +import static java.lang.String.valueOf; +import static java.lang.System.arraycopy; +import static org.apache.commons.lang3.StringUtils.leftPad; + +/** + * Brazilian National Identity Card Number (known as the Individual Taxpayer Register or CPF in Brazil) + * + * @author Nelson Rodrigues da Silva Júnior + * @since 15.10.2020 + */ +public class BrNationalIdentityCardNumberProvider implements NationalIdentityCardNumberProvider { + + private final BaseProducer baseProducer; + private static final int[] pesoCPF = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2}; + + @Inject + public BrNationalIdentityCardNumberProvider(BaseProducer baseProducer) { + this.baseProducer = baseProducer; + } + + @Override + public String get() { + return cpf(); + } + + private int randomiza(int n) { + int ranNum = (int) (Math.random() * n); + return ranNum; + } + + private int mod(int dividendo, int divisor) { + return (int) Math.round(dividendo - (Math.floor(dividendo / divisor) * divisor)); + } + + private String cpf() { + int n = 9; + int n1 = randomiza(n); + int n2 = randomiza(n); + int n3 = randomiza(n); + int n4 = randomiza(n); + int n5 = randomiza(n); + int n6 = randomiza(n); + int n7 = randomiza(n); + int n8 = randomiza(n); + int n9 = randomiza(n); + int d1 = n9 * 2 + n8 * 3 + n7 * 4 + n6 * 5 + n5 * 6 + n4 * 7 + n3 * 8 + n2 * 9 + n1 * 10; + + d1 = 11 - (mod(d1, 11)); + + if (d1 >= 10) + d1 = 0; + + int d2 = d1 * 2 + n9 * 3 + n8 * 4 + n7 * 5 + n6 * 6 + n5 * 7 + n4 * 8 + n3 * 9 + n2 * 10 + n1 * 11; + + d2 = 11 - (mod(d2, 11)); + + if (d2 >= 10) + d2 = 0; + + return "" + n1 + n2 + n3 + '.' + n4 + n5 + n6 + '.' + n7 + n8 + n9 + '-' + d1 + d2; + } + + public boolean isValid(String cpf) { + cpf = cpf.trim().replace(".", "").replace("-", ""); + if ((cpf==null) || (cpf.length()!=11)) return false; + + for (int j = 0; j < 10; j++) + if (padLeft(Integer.toString(j), Character.forDigit(j, 10)).equals(cpf)) + return false; + + Integer digito1 = calcularDigito(cpf.substring(0,9), pesoCPF); + Integer digito2 = calcularDigito(cpf.substring(0,9) + digito1, pesoCPF); + return cpf.equals(cpf.substring(0,9) + digito1.toString() + digito2.toString()); + } + + private static int calcularDigito(String str, int[] peso) { + int soma = 0; + for (int indice=str.length()-1, digito; indice >= 0; indice-- ) { + digito = Integer.parseInt(str.substring(indice,indice+1)); + soma += digito*peso[peso.length-str.length()+indice]; + } + soma = 11 - soma % 11; + return soma > 9 ? 0 : soma; + } + + private static String padLeft(String text, char character) { + return String.format("%11s", text).replace(' ', character); + } +} + diff --git a/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrPassportNumberProvider.java b/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrPassportNumberProvider.java new file mode 100644 index 00000000..612be196 --- /dev/null +++ b/src/main/java/com/devskiller/jfairy/producer/person/locale/br/BrPassportNumberProvider.java @@ -0,0 +1,17 @@ +package com.devskiller.jfairy.producer.person.locale.br; + +import org.apache.commons.lang3.RandomStringUtils; + +import com.devskiller.jfairy.producer.person.PassportNumberProvider; + +/** + * @author Nelson Rodrigues da Silva Júnior + * @since 15.10.2020 + */ +public class BrPassportNumberProvider implements PassportNumberProvider { + + @Override + public String get() { + return RandomStringUtils.randomAlphanumeric(9); + } +} diff --git a/src/main/java/com/devskiller/jfairy/producer/util/LanguageCode.java b/src/main/java/com/devskiller/jfairy/producer/util/LanguageCode.java index eb23de81..6a235fd5 100644 --- a/src/main/java/com/devskiller/jfairy/producer/util/LanguageCode.java +++ b/src/main/java/com/devskiller/jfairy/producer/util/LanguageCode.java @@ -13,5 +13,6 @@ public enum LanguageCode { IT, DE, SV, - ZH + ZH, + BR } diff --git a/src/main/resources/jfairy_br.yml b/src/main/resources/jfairy_br.yml new file mode 100644 index 00000000..b4bba876 --- /dev/null +++ b/src/main/resources/jfairy_br.yml @@ -0,0 +1,28 @@ +alphabet: abcdefghijklmnopqrstuvwxyz +domains: [ com.br, br, app.br, blog, net.br ] +firstNames: { + male: [ José, João, Antônio, Francisco, Carlos, Paulo, Pedro, Lucas, Luiz, Marcos, Luis, Gabriel, Rafael, Daniel, Marcelo, Bruno, Eduardo, Felipe, Raimundo, Rodrigo, Nelson, Manoel, Geraldo, Roberto, Mario, Joaquim, Jorge, Sebastião, Diego, Guilherme, Fernando, Davi, Rafael, Andre, Anderson, Márcio, Gustavo, Fábio, Júlio, Renato, Alex, Igor, Douglas, Vínicios, Ricardo, Leonardo, Robson, Wilson, Mauro, Jonas, Vicente, Nicolas, Osmar, Artur, Moises, Wagner, Pablo, Willian, Ivan, Celso, Breno, Junior, Sidnei, Jaime, Alisson, Ronaldo, Romário, Neymar, Nilton, Nilson, Murilo, Sandro, Isaias, Raul, Alcides, Gean, Bernado, Arlindo, Rodolfo, Armando, Lucio, Clovis, Itamar, Magno, Vilson, Dirceu, Jonata, Enzo, Afonso, Romulo, Airton, Weliton, Ednaldo, Vilmar, Rivaldo, Juan, Abel, Tite, Savio, Roni ], + female: [ Maria, Juraci, Lucimar, Ana, Jaci, Alcione, Ivanir, Nadir, Edir, Leoni, Edi, Valdete, Reni, Eurides, Rosimar, Clair, Antonia, Francisca, Iraci, Irani, Iris, Luzimar, Geneci, Erli, Sirlei, Fernanda, Nelci, Rosinei, Gabriela, Bruna, Taina, Adria, Darli, Derci, Silva, Joseli, Juracy, Delci, Joceli, Evanir, Elis, Adriana, Rafaela, Raimunda, Edenir, Vitoria, Gabriele, Rosemar, Solimar, Ivani, Juliana, Marlei, Marley, Daniele, Gessi, Vanir, Doraci, Aline, Marcia, Irismar, Josefa, Elci, Jessica, Amanda, Renata, Raquel, Nerci, Julia, Elionai, Camila, Luana, Jacy, Eduarda, Denir, Leonor, Luciana, Gerci, Patricia, Mariana, Leticia, Erci, Iva, Jane, Cristiane, Conceicao, Aquila, Elienai, Cleidimar, Guiomar, Michele, Paula, Sirley, Silvani, Rosario, Dagmar, Daniela, Fabiana, Beatriz, Santana, Alessandra, Carla, Edy, Vanessa, Larissa, Claudia, Eroni, Luz, Lori, Joseni, Edione, Laureci, Dalci, Jaqueline ] +} +lastNames: { + male: [ Agostinho, Aguiar, Albuquerque, Alegria, Alencastro, Almada, Almeida, Alves, Alves, Alvim, Amorim, Andrade, Antunes, Aparício, Apolinário, Aragão, Araújo, Araújo, Arruda, Assis, Assunção, Ávila, Azambuja, Baptista, Barbosa, Barreto, Barros, Barros, Beira-Mar, Belchior, Belém, Bernardes, Bittencourt, Boaventura, Bonfim, Botelho, Brites, Brito, Caetano, Caldeira, Calixto, Camacho, Camilo, Campos, Capelo, Cardoso, Cardoso, Carvalho, Carvalho, Castro, Castro, Cavalcante, Cavalcanti, Chaves, Conceição, Córdoba, Corte Real, Cortês, Costa, Coutinho, Crespo, Cunha, Curado, Custódio, D’Ávila, da Conceição, da Costa, da Cruz, da Cunha, da Luz, da Mata, da Mota, da Paz, da Rocha, da Rosa, Damásio, Dantas, das Neves, Dias, Dias, Dinís, Domingues, Dorneles, dos Reis, Drumond, Duarte, Escobar, Espinosa, Esteves, Evangelista, Farias, Farias, Félix, Fernandes, Fernandes, Ferrari, Ferreira, Figueiredo, Figueiroa, Flores, Fogaça, Fogaça, Freitas, Freitas, Frutuoso, Furtado, Galvão, Garcia, Gaspar, Gentil, Geraldes, Gil, Godinho, Góis, Gomes, Gomes, Gomes, Gonçalves, Gonzaga, Goulart, Gouveia, Guedes, Guimarães, Guterres, Hernandes, Hilário, Hipólito, Ibrahim, Ilha, Infante, Jaques, Jesus, Jesus, Jordão, Lacerda, Lancastre, Leiria, Lessa, Lima, Lopes, Machado, Maciel, Magalhães, Maia, Maldonado, Marinho, Marques, Martins, Martins, Martins, Medeiros, Meireles, Mello, Melo, Mendes, Mendes, Mendes, Menezes, Mesquita, Modesto, Monteiro, Monteiro, Moraes, Morais, Moreira, Moreira, Morgado, Moura, Moura, Muniz, Nascimento, Neves, Nóbrega, Nogueira, Nogueira, Novaes, Novais, Nunes, Oliveira, Oliveira, Ornélas, Ourique, Pacheco, Padilha, Paiva, Paraíso, Paris, Peixoto, Peixoto, Peralta, Pereira, Pereira, Peres, Pilar, Pimenta, Pinheiro, Pinto, Pires, Portela, Porto, Quaresma, Quarteira, Queiroz, Ramires, Ramos, Ramos, Rebelo, Resende, Rezende, Ribeiro, Ribeiro, Ribeiro, Rocha, Rodrigues, Rodrigues, Salazar, Sales, Sales, Salgado, Salgueiro, Sampaio, Sanches, Santana, Santos, Silva, Silveira, Siqueira, Soares, Souza, Subtil, Tavares, Taveira, Teixeira, Teixeira, Teles, Torres, Trindade, Varela, Vargas, Vasconcelos, Vasques, Veiga, Veloso, Viana, Vidal, Vieira, Vieira, Vilela, Xavier, Ximenes, Xisco, Zagalo, Zaganelli, Zanette ], + female: [ Agostinho, Aguiar, Albuquerque, Alegria, Alencastro, Almada, Almeida, Alves, Alves, Alvim, Amorim, Andrade, Antunes, Aparício, Apolinário, Aragão, Araújo, Araújo, Arruda, Assis, Assunção, Ávila, Azambuja, Baptista, Barbosa, Barreto, Barros, Barros, Beira-Mar, Belchior, Belém, Bernardes, Bittencourt, Boaventura, Bonfim, Botelho, Brites, Brito, Caetano, Caldeira, Calixto, Camacho, Camilo, Campos, Capelo, Cardoso, Cardoso, Carvalho, Carvalho, Castro, Castro, Cavalcante, Cavalcanti, Chaves, Conceição, Córdoba, Corte Real, Cortês, Costa, Coutinho, Crespo, Cunha, Curado, Custódio, D’Ávila, da Conceição, da Costa, da Cruz, da Cunha, da Luz, da Mata, da Mota, da Paz, da Rocha, da Rosa, Damásio, Dantas, das Neves, Dias, Dias, Dinís, Domingues, Dorneles, dos Reis, Drumond, Duarte, Escobar, Espinosa, Esteves, Evangelista, Farias, Farias, Félix, Fernandes, Fernandes, Ferrari, Ferreira, Figueiredo, Figueiroa, Flores, Fogaça, Fogaça, Freitas, Freitas, Frutuoso, Furtado, Galvão, Garcia, Gaspar, Gentil, Geraldes, Gil, Godinho, Góis, Gomes, Gomes, Gomes, Gonçalves, Gonzaga, Goulart, Gouveia, Guedes, Guimarães, Guterres, Hernandes, Hilário, Hipólito, Ibrahim, Ilha, Infante, Jaques, Jesus, Jesus, Jordão, Lacerda, Lancastre, Leiria, Lessa, Lima, Lopes, Machado, Maciel, Magalhães, Maia, Maldonado, Marinho, Marques, Martins, Martins, Martins, Medeiros, Meireles, Mello, Melo, Mendes, Mendes, Mendes, Menezes, Mesquita, Modesto, Monteiro, Monteiro, Moraes, Morais, Moreira, Moreira, Morgado, Moura, Moura, Muniz, Nascimento, Neves, Nóbrega, Nogueira, Nogueira, Novaes, Novais, Nunes, Oliveira, Oliveira, Ornélas, Ourique, Pacheco, Padilha, Paiva, Paraíso, Paris, Peixoto, Peixoto, Peralta, Pereira, Pereira, Peres, Pilar, Pimenta, Pinheiro, Pinto, Pires, Portela, Porto, Quaresma, Quarteira, Queiroz, Ramires, Ramos, Ramos, Rebelo, Resende, Rezende, Ribeiro, Ribeiro, Ribeiro, Rocha, Rodrigues, Rodrigues, Salazar, Sales, Sales, Salgado, Salgueiro, Sampaio, Sanches, Santana, Santos, Silva, Silveira, Siqueira, Soares, Souza, Subtil, Tavares, Taveira, Teixeira, Teixeira, Teles, Torres, Trindade, Varela, Vargas, Vasconcelos, Vasques, Veiga, Veloso, Viana, Vidal, Vieira, Vieira, Vilela, Xavier, Ximenes, Xisco, Zagalo, Zaganelli, Zanette ] +} +personalEmails: [ gmail.com, hotmail.com, yahoo.com.br, uol.com.br ] +companyNames: [ Bar, Sapataria, Mercado, Padaria, Supermercado, Farmácia, Drogaria, Loja de Conveniência, Posto de Gasolina, Açougue, Mercearia, Restaurante, Perfumaria, Loja de Roupas, Mercado Central, Lanchonete, Loja de 1.99, Atacado, Mecânica, Autopeças, Basar, Açaí, Academia, Ótica, Brinquedoteca, FastFood, Boate, Boteco ] +companySuffixes: [ LTDA, Loja, Consultoria, Inc., Industria] +companyEmails: [ info, contato, escritorio, faleconosco ] + +text: Este hipertexto, isto é, matriz de textos potencializados em um duplo-devir virtualizante, visa proporcionar uma combinatória proto-semântica de um discurso proposicional a partir de um universo de possíveis. Sua instauração epistemológica é traçada a posteriori pela necessidade de construir-se um conhecimento teórico escamoteado em uma base glossofônica da interioridade da razão, em conssonância com a tex-tualidade apofântica sinteticamente determinável em sua exterioridade do Ser. + +telephone_number_formats: [ '##-####-####' ] + +postal_code: [ '#####-###' ] + +city: [ São Paulo, Rio de Janeiro, Salvador, Brasília, Fortaleza, Belo Horizonte, Manaus, Curitiba, Recife, Porto Alegre, Unaí ] + +street: [ Rua Gonçalo de Carvalho, Rua das Pedras, Vieira Souto, Avenida Paulista, Rua XV de Novembro, Avenida Pedro Basso, Rua Marcelino Champagnat, Avenida Júlio Castilhos, Rua Bento Gonçalves, Rua da Aurora, Rua Portugal, Avenida Silvio Carlos Viana, Avenida Dante Michelini, Avenida Getúlio Vargas, Rua do Mucugê ] + +country: [ 'Brasil' ] + +language: 'BR' diff --git a/src/test/groovy/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProviderSpec.groovy b/src/test/groovy/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProviderSpec.groovy new file mode 100644 index 00000000..4530579b --- /dev/null +++ b/src/test/groovy/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProviderSpec.groovy @@ -0,0 +1,36 @@ +package com.devskiller.jfairy.producer.company.locale.br + +import com.devskiller.jfairy.producer.company.locale.es.EsVATIdentificationNumberProvider +import spock.lang.Specification +import spock.lang.Unroll + +/** + * @author Nelson Rodrigues da Silva Júnior + * @since 15.10.2020 + */ +class BrVATIdentificationNumberProviderSpec extends Specification { + + private BrVATIdentificationNumberProvider generator = new BrVATIdentificationNumberProvider() + + @Unroll + def "Should validate #vatIdentificationNumber as #valid"() { + + expect: + generator.isValid(vatIdentificationNumber) == valid + + where: + vatIdentificationNumber | valid + "03.061.384/0001-40" | true + "03.232.334/0001-40" | false + "95.659.509/0001-57" | true + "67.706.334/0001-10" | false + } + + def "Should always generate proper nip"() { + expect: + generator.isValid(generator.get()) + where: + i << (1..100) + } + +} diff --git a/src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrNationalIdentityCardNumberProviderSpec.groovy b/src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrNationalIdentityCardNumberProviderSpec.groovy new file mode 100644 index 00000000..75efa7bd --- /dev/null +++ b/src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrNationalIdentityCardNumberProviderSpec.groovy @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2013 Codearte and authors + */ + +package com.devskiller.jfairy.producer.person.locale.br + +import com.devskiller.jfairy.Fairy +import com.devskiller.jfairy.producer.company.locale.br.BrVATIdentificationNumberProvider +import spock.lang.Specification +import spock.lang.Unroll + +/** + * @author Nelson Rodrigues da Silva Júnior + * @since 15.10.2020 + */ +class BrNationalIdentityCardNumberProviderSpec extends Specification { + + private Fairy fairy; + private String brNationalIdentityCardNumber + private final int dniLength = 14 + private BrNationalIdentityCardNumberProvider generator = new BrNationalIdentityCardNumberProvider() + + def setup() { + fairy = Fairy.create(Locale.forLanguageTag("br")) + brNationalIdentityCardNumber = fairy.person().nationalIdentityCardNumber + } + + def "should generate number with 14 characters"() { + expect: + brNationalIdentityCardNumber.length() == dniLength + } + + @Unroll + def "Should validate #vatIdentificationNumber as #valid"() { + + expect: + generator.isValid(vatIdentificationNumber) == valid + + where: + vatIdentificationNumber | valid + "982.970.740-72" | true + "984.350.400-33" | false + "723.083.860-61" | true + "136.214.190-80" | false + } + + def "Should always generate proper nip"() { + expect: + generator.isValid(generator.get()) + where: + i << (1..100) + } + + +} diff --git a/src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrPassportNumberProviderSpec.groovy b/src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrPassportNumberProviderSpec.groovy new file mode 100644 index 00000000..06987104 --- /dev/null +++ b/src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrPassportNumberProviderSpec.groovy @@ -0,0 +1,38 @@ +package com.devskiller.jfairy.producer.person.locale.br; + + +import spock.lang.Specification + +import com.devskiller.jfairy.Fairy + +/** + * @author Nelson Rodrigues da Silva Júnior + * @since 15.10.2020 + */ +class BrPassportNumberProviderSpec extends Specification { + + private Fairy fairy; + private String passportNumber + + def setup() { + fairy = Fairy.create(Locale.forLanguageTag("br")) + passportNumber = fairy.person().passportNumber + } + + def "should generate number with nine characters"() + + { + expect: + passportNumber.length() == 9 + } + + def "should contain only digits and letters"() + + { + for (Character character : passportNumber) { + expect: + character.isDigit() || character.isLetter() + } + } + +} From 1a2bc995060884926bc6461c113a82322a36c332 Mon Sep 17 00:00:00 2001 From: Nelson Date: Fri, 16 Oct 2020 00:14:08 -0300 Subject: [PATCH 2/3] Include locate BR into Bootstrap --- .../java/com/devskiller/jfairy/Bootstrap.java | 2 + .../br/BrVATIdentificationNumberProvider.java | 2 +- .../person/locale/br/BrAddressSpec.groovy | 58 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrAddressSpec.groovy diff --git a/src/main/java/com/devskiller/jfairy/Bootstrap.java b/src/main/java/com/devskiller/jfairy/Bootstrap.java index 451d2b5c..c1b08398 100644 --- a/src/main/java/com/devskiller/jfairy/Bootstrap.java +++ b/src/main/java/com/devskiller/jfairy/Bootstrap.java @@ -145,6 +145,8 @@ private static FairyModule getFairyModuleForLocale(DataMaster dataMaster, Locale return new DeFairyModule(dataMaster, randomGenerator); case KA: return new KaFairyModule(dataMaster, randomGenerator); + case BR: + return new BrFairyModule(dataMaster, randomGenerator); default: LOG.info("No data for your language - using EN"); return new EnFairyModule(dataMaster, randomGenerator); diff --git a/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java b/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java index 3698436c..e33a10fb 100644 --- a/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java +++ b/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java @@ -78,7 +78,7 @@ public String cnpj() { } public boolean isValid(String cnpj) { - cnpj = cnpj.trim().replace(".", "").replace("-", ""); + cnpj = cnpj.trim().replace(".", "").replace("/", "").replace("-", ""); if ((cnpj==null)||(cnpj.length()!=14)) return false; Integer digito1 = calcularDigito(cnpj.substring(0,12), pesoCNPJ); diff --git a/src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrAddressSpec.groovy b/src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrAddressSpec.groovy new file mode 100644 index 00000000..7f0b0353 --- /dev/null +++ b/src/test/groovy/com/devskiller/jfairy/producer/person/locale/br/BrAddressSpec.groovy @@ -0,0 +1,58 @@ +package com.devskiller.jfairy.producer.person.locale.br + +import com.devskiller.jfairy.Fairy +import com.devskiller.jfairy.producer.person.Address +import spock.lang.Specification + +class BrAddressSpec extends Specification { + + private final int SEED = 5 + private Fairy fairy; + private Address address + + def setup() { + fairy = Fairy.builder().withRandomSeed(SEED).withLocale(Locale.forLanguageTag("br")).build() + address = fairy.person().address + } + + def "should generate random street"() { + expect: + address.street == "Rua das Pedras" + } + + def "should generate random streetNumber"() { + expect: + address.streetNumber == "138" + } + + def "should generate random apartmentNumber"() { + expect: + address.apartmentNumber == "" + } + + def "should generate random postalCode"() { + expect: + address.postalCode == "75092-797" + } + + def "should generate random city"() { + expect: + address.city == "Fortaleza" + } + + def "should return addressLine1 in es locale format"() { + expect: + address.addressLine1 == "Rua das Pedras, 138" + } + + def "should return addressLine2 in es locale format"() { + expect: + address.addressLine2 == "75092-797 Fortaleza" + } + + def "should return address in es locale format"() { + expect: + address.toString() == "Rua das Pedras, 138" + System.lineSeparator() + "75092-797 Fortaleza" + } + +} From fdd2cdb1d3af1f6a0c5796504670518eca90167d Mon Sep 17 00:00:00 2001 From: Nelson Date: Fri, 16 Oct 2020 00:21:05 -0300 Subject: [PATCH 3/3] Fix error when generating VAT Identification Number --- .../locale/br/BrVATIdentificationNumberProvider.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java b/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java index e33a10fb..77142c57 100644 --- a/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java +++ b/src/main/java/com/devskiller/jfairy/producer/company/locale/br/BrVATIdentificationNumberProvider.java @@ -32,9 +32,7 @@ public BrVATIdentificationNumberProvider(BaseProducer baseProducer) { @Override public String get() { - char[] ein = new char[EIN_LENGTH]; - - return valueOf(ein); + return cnpj(); } private int randomiza(int n) { @@ -46,7 +44,7 @@ private int mod(int dividendo, int divisor) { return (int) Math.round(dividendo - (Math.floor(dividendo / divisor) * divisor)); } - public String cnpj() { + private String cnpj() { int n = 9; int n1 = randomiza(n); int n2 = randomiza(n);