Skip to content

Commit

Permalink
Merge pull request #37 from fincatto/dev
Browse files Browse the repository at this point in the history
Adicionado parser para nota processada
  • Loading branch information
jefperito committed May 11, 2015
2 parents 6bc910a + 1ef8af4 commit 89e24d4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/main/java/com/fincatto/nfe310/parsers/NotaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.simpleframework.xml.core.Persister;

import com.fincatto.nfe310.classes.nota.NFNota;
import com.fincatto.nfe310.classes.nota.NFNotaProcessada;
import com.fincatto.nfe310.transformers.NFRegistryMatcher;
import com.fincatto.nfe310.validadores.xsd.XMLValidador;

Expand All @@ -15,18 +16,17 @@ public NotaParser() {
this.persister = new Persister(new NFRegistryMatcher());
}

public NFNota paraObjeto(final File xml) {
public NFNota notaParaObjeto(final File xml) {
try {
final NFNota nota = this.persister.read(NFNota.class, xml);
XMLValidador.validaNota(nota.toString());
return nota;
} catch (final Exception e) {
throw new IllegalArgumentException(String.format("Nao foi possivel parsear o xml: %s", e.getMessage()));
}

}

public NFNota paraObjeto(final String xml) {
public NFNota notaParaObjeto(final String xml) {
try {
final NFNota nota = this.persister.read(NFNota.class, xml);
XMLValidador.validaNota(nota.toString());
Expand All @@ -35,4 +35,20 @@ public NFNota paraObjeto(final String xml) {
throw new IllegalArgumentException(String.format("Nao foi possivel parsear o xml: %s", e.getMessage()));
}
}

public NFNotaProcessada notaProcessadaParaObjeto(final String xml) {
try {
return this.persister.read(NFNotaProcessada.class, xml);
} catch (final Exception e) {
throw new IllegalArgumentException(String.format("Nao foi possivel parsear o xml: %s", e.getMessage()));
}
}

public NFNotaProcessada notaProcessadaParaObjeto(final File xml) {
try {
return this.persister.read(NFNotaProcessada.class, xml);
} catch (final Exception e) {
throw new IllegalArgumentException(String.format("Nao foi possivel parsear o xml: %s", e.getMessage()));
}
}
}
9 changes: 9 additions & 0 deletions src/test/java/com/fincatto/nfe310/FabricaDeObjetosFake.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
import com.fincatto.nfe310.classes.nota.NFNotaInfoTransporte;
import com.fincatto.nfe310.classes.nota.NFNotaInfoVeiculo;
import com.fincatto.nfe310.classes.nota.NFNotaInfoVolume;
import com.fincatto.nfe310.classes.nota.NFNotaProcessada;
import com.fincatto.nfe310.classes.nota.NFOperacaoConsumidorFinal;
import com.fincatto.nfe310.classes.nota.NFOperadoraCartao;
import com.fincatto.nfe310.classes.nota.NFPessoaAutorizadaDownloadNFe;
Expand Down Expand Up @@ -373,6 +374,14 @@ public static NFNota getNFNota() {
return nota;
}

public static NFNotaProcessada getNFNotaProcessada() {
final NFNotaProcessada notaProcessada = new NFNotaProcessada();
notaProcessada.setNota(FabricaDeObjetosFake.getNFNota1());
notaProcessada.setProtocolo(FabricaDeObjetosFake.getNFProtocolo());
notaProcessada.setVersao(new BigDecimal("3.10"));
return notaProcessada;
}

public static NFLoteEnvioRetornoRecebimentoInfo getNFLoteEnvioRetornoRecebimentoInfo() {
final NFLoteEnvioRetornoRecebimentoInfo recebimentoInfo = new NFLoteEnvioRetornoRecebimentoInfo();
recebimentoInfo.setRecibo("845e40545");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void deveValidarXMLContraXSD() throws Throwable {
@Ignore
public void validaArquivos() throws Throwable {
for (final File notaXML : TesteUtil.getArquivosParaTestes(new File(ValidacaoXML.DIRETORIO_XML_NOTAS))) {
Assert.assertEquals(TesteUtil.filepathToString(notaXML.getAbsolutePath()), new NotaParser().paraObjeto(notaXML).toString());
Assert.assertEquals(TesteUtil.filepathToString(notaXML.getAbsolutePath()), new NotaParser().notaParaObjeto(notaXML).toString());
}
}
}
21 changes: 21 additions & 0 deletions src/test/java/com/fincatto/nfe310/parsers/NotaParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.fincatto.nfe310.parsers;

import org.junit.Assert;
import org.junit.Test;

import com.fincatto.nfe310.FabricaDeObjetosFake;

public class NotaParserTest {

@Test
public void deveParsearCorretamenteUmXMLDaNota310() {
final String xmlNota = FabricaDeObjetosFake.getNFNota().toString();
Assert.assertNotNull(new NotaParser().notaParaObjeto(xmlNota));
}

@Test
public void deveParsearCorretamenteUmXMLDaNotaProcessada310() {
final String xmlNota = FabricaDeObjetosFake.getNFNotaProcessada().toString();
Assert.assertNotNull(new NotaParser().notaProcessadaParaObjeto(xmlNota));
}
}

0 comments on commit 89e24d4

Please sign in to comment.