Skip to content

Commit 1625d18

Browse files
Adicionado Novo cacert
1 parent 3f3c3c2 commit 1625d18

23 files changed

+2609
-4
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package br.com.swconsultoria.nfe;
2+
3+
import br.com.swconsultoria.nfe.dom.ConfiguracoesNfe;
4+
import br.com.swconsultoria.nfe.dom.Evento;
5+
import br.com.swconsultoria.nfe.dom.enuns.AmbienteEnum;
6+
import br.com.swconsultoria.nfe.dom.enuns.AssinaturaEnum;
7+
import br.com.swconsultoria.nfe.dom.enuns.DocumentoEnum;
8+
import br.com.swconsultoria.nfe.dom.enuns.EstadosEnum;
9+
import br.com.swconsultoria.nfe.exception.NfeException;
10+
import br.com.swconsultoria.nfe.schema.envEventoCancNFe.TEnvEvento;
11+
import br.com.swconsultoria.nfe.schema.envEventoCancNFe.TRetEnvEvento;
12+
import br.com.swconsultoria.nfe.util.CancelamentoUtil;
13+
import br.com.swconsultoria.nfe.util.StubUtil;
14+
import br.com.swconsultoria.nfe.wsdl.NFeRecepcaoEvento.NFeRecepcaoEvento4Stub;
15+
import mockit.Mock;
16+
import mockit.MockUp;
17+
import org.apache.axiom.om.util.AXIOMUtil;
18+
import org.junit.jupiter.api.BeforeEach;
19+
import org.junit.jupiter.api.Test;
20+
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
24+
class CancelarTest {
25+
26+
private static final String RET_EVENTO_XML =
27+
"<retEnvEvento versao=\"1.00\" xmlns=\"http://www.portalfiscal.inf.br/nfe\">" +
28+
"<idLote>1</idLote><tpAmb>2</tpAmb><verAplic>TESTE</verAplic>" +
29+
"<cOrgao>91</cOrgao><cStat>128</cStat>" +
30+
"<xMotivo>Lote de Evento Processado</xMotivo>" +
31+
"</retEnvEvento>";
32+
33+
private ConfiguracoesNfe config;
34+
private TEnvEvento enviEvento;
35+
36+
@BeforeEach
37+
void setUp() throws NfeException {
38+
config = new ConfiguracoesNfe();
39+
config.setEstado(EstadosEnum.SP);
40+
config.setAmbiente(AmbienteEnum.HOMOLOGACAO);
41+
config.setEncode("UTF-8");
42+
43+
config.setZoneId(java.time.ZoneId.of("America/Sao_Paulo"));
44+
45+
Evento evento = new Evento();
46+
evento.setChave("52230309158456000159550010000731791567812345");
47+
evento.setCnpj("09158456000159");
48+
evento.setProtocolo("352230000123456");
49+
evento.setMotivo("Cancelamento por erro na emissao do documento fiscal");
50+
evento.setDataEvento(java.time.LocalDateTime.of(2024, 1, 15, 10, 0, 0));
51+
enviEvento = CancelamentoUtil.montaCancelamento(evento, config);
52+
}
53+
54+
private void mockStubUtil() {
55+
new MockUp<StubUtil>() {
56+
@Mock
57+
public void configuraHttpClient(org.apache.axis2.client.Stub stub,
58+
ConfiguracoesNfe cfg, String url) { }
59+
};
60+
}
61+
62+
private void mockAssinar() {
63+
new MockUp<Assinar>() {
64+
@Mock
65+
public String assinaNfe(ConfiguracoesNfe cfg, String xml,
66+
AssinaturaEnum tipo) throws NfeException {
67+
return xml;
68+
}
69+
};
70+
}
71+
72+
private void mockEventosStub() {
73+
new MockUp<NFeRecepcaoEvento4Stub>() {
74+
@Mock
75+
public void $init(String endpoint) { }
76+
77+
@Mock
78+
public NFeRecepcaoEvento4Stub.NfeResultMsg nfeRecepcaoEvento(
79+
NFeRecepcaoEvento4Stub.NfeDadosMsg data) throws Exception {
80+
NFeRecepcaoEvento4Stub.NfeResultMsg result = new NFeRecepcaoEvento4Stub.NfeResultMsg();
81+
result.setExtraElement(AXIOMUtil.stringToOM(RET_EVENTO_XML));
82+
return result;
83+
}
84+
};
85+
}
86+
87+
@Test
88+
void eventoCancelamento_semValidacao_retornaEvento() throws NfeException {
89+
mockStubUtil();
90+
mockAssinar();
91+
mockEventosStub();
92+
93+
TRetEnvEvento ret = Cancelar.eventoCancelamento(config, enviEvento, false, DocumentoEnum.NFE);
94+
95+
assertNotNull(ret);
96+
assertEquals("128", ret.getCStat());
97+
}
98+
99+
@Test
100+
void eventoCancelamento_retornaLoteProcessado() throws NfeException {
101+
mockStubUtil();
102+
mockAssinar();
103+
mockEventosStub();
104+
105+
TRetEnvEvento ret = Cancelar.eventoCancelamento(config, enviEvento, false, DocumentoEnum.NFE);
106+
107+
assertEquals("Lote de Evento Processado", ret.getXMotivo());
108+
}
109+
110+
@Test
111+
void eventoCancelamento_retornaAmbienteHomologacao() throws NfeException {
112+
mockStubUtil();
113+
mockAssinar();
114+
mockEventosStub();
115+
116+
TRetEnvEvento ret = Cancelar.eventoCancelamento(config, enviEvento, false, DocumentoEnum.NFE);
117+
118+
assertEquals("2", ret.getTpAmb());
119+
}
120+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package br.com.swconsultoria.nfe;
2+
3+
import br.com.swconsultoria.nfe.dom.ConfiguracoesNfe;
4+
import br.com.swconsultoria.nfe.dom.Evento;
5+
import br.com.swconsultoria.nfe.dom.enuns.AmbienteEnum;
6+
import br.com.swconsultoria.nfe.dom.enuns.AssinaturaEnum;
7+
import br.com.swconsultoria.nfe.dom.enuns.EstadosEnum;
8+
import br.com.swconsultoria.nfe.exception.NfeException;
9+
import br.com.swconsultoria.nfe.schema.envcce.TEnvEvento;
10+
import br.com.swconsultoria.nfe.schema.envcce.TRetEnvEvento;
11+
import br.com.swconsultoria.nfe.util.CartaCorrecaoUtil;
12+
import br.com.swconsultoria.nfe.util.StubUtil;
13+
import br.com.swconsultoria.nfe.wsdl.NFeRecepcaoEvento.NFeRecepcaoEvento4Stub;
14+
import mockit.Mock;
15+
import mockit.MockUp;
16+
import org.apache.axiom.om.util.AXIOMUtil;
17+
import org.junit.jupiter.api.BeforeEach;
18+
import org.junit.jupiter.api.Test;
19+
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
23+
class CartaCorrecaoTest {
24+
25+
private static final String RET_EVENTO_XML =
26+
"<retEnvEvento versao=\"1.00\" xmlns=\"http://www.portalfiscal.inf.br/nfe\">" +
27+
"<idLote>1</idLote><tpAmb>2</tpAmb><verAplic>TESTE</verAplic>" +
28+
"<cOrgao>91</cOrgao><cStat>128</cStat>" +
29+
"<xMotivo>Lote de Evento Processado</xMotivo>" +
30+
"</retEnvEvento>";
31+
32+
private ConfiguracoesNfe config;
33+
private TEnvEvento enviEvento;
34+
35+
@BeforeEach
36+
void setUp() throws NfeException {
37+
config = new ConfiguracoesNfe();
38+
config.setEstado(EstadosEnum.SP);
39+
config.setAmbiente(AmbienteEnum.HOMOLOGACAO);
40+
config.setEncode("UTF-8");
41+
42+
config.setZoneId(java.time.ZoneId.of("America/Sao_Paulo"));
43+
44+
Evento evento = new Evento();
45+
evento.setChave("52230309158456000159550010000731791567812345");
46+
evento.setCnpj("09158456000159");
47+
evento.setMotivo("Correcao no campo de endereco do destinatario da nota fiscal");
48+
evento.setSequencia(1);
49+
evento.setDataEvento(java.time.LocalDateTime.of(2024, 3, 10, 9, 0, 0));
50+
enviEvento = CartaCorrecaoUtil.montaCCe(evento, config);
51+
}
52+
53+
private void mockStubUtil() {
54+
new MockUp<StubUtil>() {
55+
@Mock
56+
public void configuraHttpClient(org.apache.axis2.client.Stub stub,
57+
ConfiguracoesNfe cfg, String url) { }
58+
};
59+
}
60+
61+
private void mockAssinar() {
62+
new MockUp<Assinar>() {
63+
@Mock
64+
public String assinaNfe(ConfiguracoesNfe cfg, String xml,
65+
AssinaturaEnum tipo) throws NfeException {
66+
return xml;
67+
}
68+
};
69+
}
70+
71+
private void mockEventosStub() {
72+
new MockUp<NFeRecepcaoEvento4Stub>() {
73+
@Mock
74+
public void $init(String endpoint) { }
75+
76+
@Mock
77+
public NFeRecepcaoEvento4Stub.NfeResultMsg nfeRecepcaoEvento(
78+
NFeRecepcaoEvento4Stub.NfeDadosMsg data) throws Exception {
79+
NFeRecepcaoEvento4Stub.NfeResultMsg result = new NFeRecepcaoEvento4Stub.NfeResultMsg();
80+
result.setExtraElement(AXIOMUtil.stringToOM(RET_EVENTO_XML));
81+
return result;
82+
}
83+
};
84+
}
85+
86+
@Test
87+
void eventoCCe_semValidacao_retornaEvento() throws NfeException {
88+
mockStubUtil();
89+
mockAssinar();
90+
mockEventosStub();
91+
92+
TRetEnvEvento ret = CartaCorrecao.eventoCCe(config, enviEvento, false);
93+
94+
assertNotNull(ret);
95+
assertEquals("128", ret.getCStat());
96+
}
97+
98+
@Test
99+
void eventoCCe_retornaLoteProcessado() throws NfeException {
100+
mockStubUtil();
101+
mockAssinar();
102+
mockEventosStub();
103+
104+
TRetEnvEvento ret = CartaCorrecao.eventoCCe(config, enviEvento, false);
105+
106+
assertEquals("Lote de Evento Processado", ret.getXMotivo());
107+
}
108+
109+
@Test
110+
void eventoCCe_retornaAmbienteHomologacao() throws NfeException {
111+
mockStubUtil();
112+
mockAssinar();
113+
mockEventosStub();
114+
115+
TRetEnvEvento ret = CartaCorrecao.eventoCCe(config, enviEvento, false);
116+
117+
assertEquals("2", ret.getTpAmb());
118+
}
119+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package br.com.swconsultoria.nfe;
2+
3+
import br.com.swconsultoria.nfe.dom.ConfiguracoesNfe;
4+
import br.com.swconsultoria.nfe.dom.enuns.AmbienteEnum;
5+
import br.com.swconsultoria.nfe.dom.enuns.DocumentoEnum;
6+
import br.com.swconsultoria.nfe.dom.enuns.EstadosEnum;
7+
import br.com.swconsultoria.nfe.exception.NfeException;
8+
import br.com.swconsultoria.nfe.schema_4.consReciNFe.TRetConsReciNFe;
9+
import br.com.swconsultoria.nfe.util.StubUtil;
10+
import br.com.swconsultoria.nfe.wsdl.NFeRetAutorizacao.NFeRetAutorizacao4Stub;
11+
import mockit.Mock;
12+
import mockit.MockUp;
13+
import org.apache.axiom.om.util.AXIOMUtil;
14+
import org.junit.jupiter.api.BeforeEach;
15+
import org.junit.jupiter.api.Test;
16+
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
20+
class ConsultaReciboTest {
21+
22+
private static final String RET_RECIBO_XML =
23+
"<retConsReciNFe versao=\"4.00\" xmlns=\"http://www.portalfiscal.inf.br/nfe\">" +
24+
"<tpAmb>2</tpAmb><cStat>104</cStat><xMotivo>Lote processado</xMotivo>" +
25+
"<cUF>35</cUF>" +
26+
"</retConsReciNFe>";
27+
28+
private ConfiguracoesNfe config;
29+
30+
@BeforeEach
31+
void setUp() {
32+
config = new ConfiguracoesNfe();
33+
config.setEstado(EstadosEnum.SP);
34+
config.setAmbiente(AmbienteEnum.HOMOLOGACAO);
35+
config.setEncode("UTF-8");
36+
}
37+
38+
private void mockStubUtil() {
39+
new MockUp<StubUtil>() {
40+
@Mock
41+
public void configuraHttpClient(org.apache.axis2.client.Stub stub,
42+
ConfiguracoesNfe cfg, String url) { }
43+
};
44+
}
45+
46+
private void mockReciboStub() {
47+
new MockUp<NFeRetAutorizacao4Stub>() {
48+
@Mock
49+
public void $init(String endpoint) { }
50+
51+
@Mock
52+
public NFeRetAutorizacao4Stub.NfeResultMsg nfeRetAutorizacaoLote(
53+
NFeRetAutorizacao4Stub.NfeDadosMsg data) throws Exception {
54+
NFeRetAutorizacao4Stub.NfeResultMsg result = new NFeRetAutorizacao4Stub.NfeResultMsg();
55+
result.setExtraElement(AXIOMUtil.stringToOM(RET_RECIBO_XML));
56+
return result;
57+
}
58+
};
59+
}
60+
61+
@Test
62+
void reciboNfe_reciboValido_retornaLoteProcessado() throws NfeException {
63+
mockStubUtil();
64+
mockReciboStub();
65+
66+
TRetConsReciNFe ret = ConsultaRecibo.reciboNfe(config, "135240000000001", DocumentoEnum.NFE);
67+
68+
assertNotNull(ret);
69+
assertEquals("104", ret.getCStat());
70+
}
71+
72+
@Test
73+
void reciboNfe_retornaMotivo() throws NfeException {
74+
mockStubUtil();
75+
mockReciboStub();
76+
77+
TRetConsReciNFe ret = ConsultaRecibo.reciboNfe(config, "135240000000001", DocumentoEnum.NFE);
78+
79+
assertEquals("Lote processado", ret.getXMotivo());
80+
}
81+
82+
@Test
83+
void reciboNfe_nfce_retornaResultado() throws NfeException {
84+
mockStubUtil();
85+
mockReciboStub();
86+
87+
TRetConsReciNFe ret = ConsultaRecibo.reciboNfe(config, "135240000000001", DocumentoEnum.NFCE);
88+
89+
assertNotNull(ret);
90+
assertEquals("104", ret.getCStat());
91+
}
92+
}

0 commit comments

Comments
 (0)