Skip to content

Commit e70e7ad

Browse files
Fix warnings (observaciones) (#15)
* Fix first set of warnings * Fix xml snapshot tests * Print warnings * Print warnings
1 parent 48f85c3 commit e70e7ad

34 files changed

+118
-143
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@
125125
</dependency>
126126
<dependency>
127127
<groupId>io.github.project-openubl</groupId>
128-
<artifactId>xml-sender-ws</artifactId>
129-
<version>2.1.1.Final</version>
128+
<artifactId>xsender</artifactId>
129+
<version>3.0.2.Final</version>
130130
<scope>test</scope>
131131
</dependency>
132132
</dependencies>

src/main/resources/io/github/project/openubl/xmlbuilderlib/templates/standard/common/document-line.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
<cac:TaxSubtotal>
7373
<cbc:TaxAmount currencyID="${moneda}">${item.impuestos.icb.importe}</cbc:TaxAmount>
7474
<cbc:BaseUnitMeasure unitCode="${item.unidadMedida}">${item.cantidad}</cbc:BaseUnitMeasure>
75-
<cbc:PerUnitAmount currencyID="${moneda}">${item.impuestos.icb.icbValor}</cbc:PerUnitAmount>
7675
<cac:TaxCategory>
76+
<cbc:PerUnitAmount currencyID="${moneda}">${item.impuestos.icb.icbValor}</cbc:PerUnitAmount>
7777
<cac:TaxScheme>
7878
<cbc:ID schemeAgencyName="PE:SUNAT" schemeID="UN/ECE 5153" schemeName="Codigo de tributos">${item.impuestos.icb.categoria.code}</cbc:ID>
7979
<cbc:Name>${item.impuestos.icb.categoria.nombre}</cbc:Name>

src/main/resources/io/github/project/openubl/xmlbuilderlib/templates/standard/common/note/invoice-reference.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<cac:DiscrepancyResponse>
22
<cbc:ReferenceID>${serieNumeroComprobanteAfectado}</cbc:ReferenceID>
3-
<cbc:ResponseCode listAgencyName="PE:SUNAT" listName="SUNAT: Identificador de tipo de nota de debito" listURI="urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo10">${tipoDocumentoComprobanteAfectado.code}</cbc:ResponseCode>
3+
<cbc:ResponseCode>${tipoDocumentoComprobanteAfectado.code}</cbc:ResponseCode>
44
<cbc:Description><![CDATA[${descripcionSustentoDeNota}]]></cbc:Description>
55
</cac:DiscrepancyResponse>
66
<#-- <#if orderCompra??>-->

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/AbstractUBLTest.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@
5252
import java.io.ByteArrayOutputStream;
5353
import java.io.IOException;
5454
import java.io.InputStream;
55-
import java.util.Calendar;
56-
import java.util.Set;
57-
import java.util.TimeZone;
55+
import java.util.*;
56+
import java.util.stream.Collectors;
5857

5958
import static org.junit.jupiter.api.Assertions.*;
6059

@@ -78,6 +77,7 @@ public abstract class AbstractUBLTest {
7877
protected TimeZone timeZone;
7978
protected SystemClock systemClock;
8079

80+
protected String PROVIDER_WITHOUT_ADDRESS_NOTE = "3030 - El XML no contiene el tag o no existe información del código de local anexo del emisor";
8181

8282
public AbstractUBLTest() throws Exception {
8383
xPath = XPathFactory.newInstance().newXPath();
@@ -132,19 +132,28 @@ public void assertSnapshot(String expected, String snapshotFile) {
132132
assertFalse(myDiff.hasDifferences(), expected + "\n" + myDiff.toString());
133133
}
134134

135-
public void assertSendSunat(String xmlWithoutSignature) throws Exception {
135+
public void assertSendSunat(String xmlWithoutSignature, String... allowedNotes) throws Exception {
136136
String skipSunat = System.getProperty("skipSunat", "false");
137137
if (skipSunat != null && skipSunat.equals("false")) {
138138
Document signedXML = XMLSigner.signXML(xmlWithoutSignature, SIGN_REFERENCE_ID, CERTIFICATE.getX509Certificate(), CERTIFICATE.getPrivateKey());
139-
sendFileToSunat(signedXML, xmlWithoutSignature);
139+
sendFileToSunat(signedXML, xmlWithoutSignature, allowedNotes);
140140
}
141141
}
142142

143-
private void sendFileToSunat(Document document, String xmlWithoutSignature) throws Exception {
143+
private void sendFileToSunat(Document document, String xmlWithoutSignature, String... allowedNotes) throws Exception {
144144
SmartBillServiceModel smartBillServiceModel = SmartBillServiceManager.send(XmlSignatureHelper.getBytesFromDocument(document), SUNAT_BETA_USERNAME, SUNAT_BETA_PASSWORD);
145145
XmlContentModel xmlContentModel = smartBillServiceModel.getXmlContentModel();
146146
BillServiceModel billServiceModel = smartBillServiceModel.getBillServiceModel();
147147

148+
if (billServiceModel.getNotes() != null) {
149+
List<String> allowedNotesList = Arrays.asList(allowedNotes);
150+
151+
List<String> notesToCheck = billServiceModel.getNotes().stream().filter(f -> allowedNotesList.stream().noneMatch(f::startsWith)).collect(Collectors.toList());
152+
notesToCheck.forEach(f -> System.out.println("WARNING:" + f));
153+
154+
// TODO Fix all warning messages and then apply this validation
155+
// assertTrue(notesToCheck.isEmpty(), "Notes fom SUNAT:\n" + String.join("\n", notesToCheck));
156+
}
148157

149158
// Check ticket
150159
if (!xmlContentModel.getDocumentType().equals(DocumentType.VOIDED_DOCUMENT.getType()) && !xmlContentModel.getDocumentType().equals(DocumentType.SUMMARY_DOCUMENT.getType())) {

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/ubl/SpecialCharactersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ void testVoidedDocument_Factura_MinData() throws Exception {
7474
// Then
7575
assertOutputHasNoConstraintViolations(validator, output);
7676
assertSnapshot(xml, "xml/invoice_specialCharacters.xml");
77-
assertSendSunat(xml);
77+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
7878
}
7979
}

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/ubl/creditnote/mindata/CreditNoteMinDataTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void testCreditNoteWithMinDataSent_customerWithRuc() throws Exception {
7676
// Then
7777
assertOutputHasNoConstraintViolations(validator, output);
7878
assertSnapshot(xml, "xml/creditnote/mindata/MinData_RUC.xml");
79-
assertSendSunat(xml);
79+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
8080
}
8181

8282
@Test
@@ -120,7 +120,7 @@ void testCreditNoteWithMinDataSent_customerWithDni() throws Exception {
120120
// Then
121121
assertOutputHasNoConstraintViolations(validator, output);
122122
assertSnapshot(xml, "xml/creditnote/mindata/MinData_DNI.xml");
123-
assertSendSunat(xml);
123+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
124124
}
125125

126126
@Test
@@ -164,7 +164,7 @@ void testCreditNoteWithMinDataSent_customerWithDocTribNoDomSinRuc() throws Excep
164164
// Then
165165
assertOutputHasNoConstraintViolations(validator, output);
166166
assertSnapshot(xml, "xml/creditnote/mindata/MinData_DocTribNoDomSinRuc.xml");
167-
assertSendSunat(xml);
167+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
168168
}
169169

170170
@Test
@@ -208,7 +208,7 @@ void testCreditNoteWithMinDataSent_customerWithExtranjeria() throws Exception {
208208
// Then
209209
assertOutputHasNoConstraintViolations(validator, output);
210210
assertSnapshot(xml, "xml/creditnote/mindata/MinData_Extranjeria.xml");
211-
assertSendSunat(xml);
211+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
212212
}
213213

214214
@Test
@@ -252,7 +252,7 @@ void testCreditNoteWithMinDataSent_customerWithPasaporte() throws Exception {
252252
// Then
253253
assertOutputHasNoConstraintViolations(validator, output);
254254
assertSnapshot(xml, "xml/creditnote/mindata/MinData_Pasaporte.xml");
255-
assertSendSunat(xml);
255+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
256256
}
257257

258258
@Test
@@ -296,7 +296,7 @@ void testCreditNoteWithMinDataSent_customerWithDecDiplomatica() throws Exception
296296
// Then
297297
assertOutputHasNoConstraintViolations(validator, output);
298298
assertSnapshot(xml, "xml/creditnote/mindata/MinData_DecDiplomatica.xml");
299-
assertSendSunat(xml);
299+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
300300
}
301301

302302
@Test
@@ -340,7 +340,7 @@ void testCreditNoteWithMinDataSent_usePrecioUnitario() throws Exception {
340340
// Then
341341
assertOutputHasNoConstraintViolations(validator, output);
342342
assertSnapshot(xml, "xml/creditnote/mindata/MinData_UsePrecioUnitarioOPrecioConIgv.xml");
343-
assertSendSunat(xml);
343+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
344344
}
345345

346346
@Test
@@ -384,7 +384,7 @@ void testCreditNoteWithMinDataSent_usePrecioConIgv() throws Exception {
384384
// Then
385385
assertOutputHasNoConstraintViolations(validator, output);
386386
assertSnapshot(xml, "xml/creditnote/mindata/MinData_UsePrecioUnitarioOPrecioConIgv.xml");
387-
assertSendSunat(xml);
387+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
388388
}
389389

390390
@Test
@@ -428,7 +428,7 @@ void testCreditNoteWithMinDataSent_usePrecioUnitarioAndCantidadThreeDecimals() t
428428
// Then
429429
assertOutputHasNoConstraintViolations(validator, output);
430430
assertSnapshot(xml, "xml/creditnote/mindata/MinData_UsePrecioUnitarioOPrecioConIgvAndCantidadThreeDecimals.xml");
431-
assertSendSunat(xml);
431+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
432432
}
433433

434434
@Test
@@ -472,6 +472,6 @@ void testCreditNoteWithMinDataSent_usePrecioConIgvAndCantidadThreeDecimals() thr
472472
// Then
473473
assertOutputHasNoConstraintViolations(validator, output);
474474
assertSnapshot(xml, "xml/creditnote/mindata/MinData_UsePrecioUnitarioOPrecioConIgvAndCantidadThreeDecimals.xml");
475-
assertSendSunat(xml);
475+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
476476
}
477477
}

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/ubl/creditnote/tiponota/CreditNoteTipoNotaTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void testCreditNoteTipoNota_GravadoOnerosa_precioUnitario() throws Exception {
8080
// Then
8181
assertOutputHasNoConstraintViolations(validator, output);
8282
assertSnapshot(xml, "xml/creditnote/tiponota/descuentoPorItem.xml");
83-
assertSendSunat(xml);
83+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
8484
}
8585

8686
}

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/ubl/debitnote/mindata/DebitNoteMinDataTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void testDebitNoteWithMinDataSent_customerWithRuc() throws Exception {
7676
// Then
7777
assertOutputHasNoConstraintViolations(validator, output);
7878
assertSnapshot(xml, "xml/debitnote/mindata/MinData_RUC.xml");
79-
assertSendSunat(xml);
79+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
8080
}
8181

8282
@Test
@@ -122,7 +122,7 @@ void testDebitNoteWithMinDataSent_customerWithDni() throws Exception {
122122
// Then
123123
assertOutputHasNoConstraintViolations(validator, output);
124124
assertSnapshot(xml, "xml/debitnote/mindata/MinData_DNI.xml");
125-
assertSendSunat(xml);
125+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
126126
}
127127

128128
@Test
@@ -166,7 +166,7 @@ void testDebitNoteWithMinDataSent_customerWithDocTribNoDomSinRuc() throws Except
166166
// Then
167167
assertOutputHasNoConstraintViolations(validator, output);
168168
assertSnapshot(xml, "xml/debitnote/mindata/MinData_DocTribNoDomSinRuc.xml");
169-
assertSendSunat(xml);
169+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
170170
}
171171

172172
@Test
@@ -212,7 +212,7 @@ void testDebitNoteWithMinDataSent_customerWithExtranjeria() throws Exception {
212212
// Then
213213
assertOutputHasNoConstraintViolations(validator, output);
214214
assertSnapshot(xml, "xml/debitnote/mindata/MinData_Extranjeria.xml");
215-
assertSendSunat(xml);
215+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
216216
}
217217

218218
@Test
@@ -258,7 +258,7 @@ void testDebitNoteWithMinDataSent_customerWithPasaporte() throws Exception {
258258
// Then
259259
assertOutputHasNoConstraintViolations(validator, output);
260260
assertSnapshot(xml, "xml/debitnote/mindata/MinData_Pasaporte.xml");
261-
assertSendSunat(xml);
261+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
262262
}
263263

264264
@Test
@@ -302,7 +302,7 @@ void testDebitNoteWithMinDataSent_customerWithDecDiplomatica() throws Exception
302302
// Then
303303
assertOutputHasNoConstraintViolations(validator, output);
304304
assertSnapshot(xml, "xml/debitnote/mindata/MinData_DecDiplomatica.xml");
305-
assertSendSunat(xml);
305+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
306306
}
307307

308308
@Test
@@ -346,7 +346,7 @@ void testDebitNoteWithMinDataSent_usePrecioUnitario() throws Exception {
346346
// Then
347347
assertOutputHasNoConstraintViolations(validator, output);
348348
assertSnapshot(xml, "xml/debitnote/mindata/MinData_UsePrecioUnitarioOPrecioConIgv.xml");
349-
assertSendSunat(xml);
349+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
350350
}
351351

352352
@Test
@@ -390,7 +390,7 @@ void testDebitNoteWithMinDataSent_usePrecioConIgv() throws Exception {
390390
// Then
391391
assertOutputHasNoConstraintViolations(validator, output);
392392
assertSnapshot(xml, "xml/debitnote/mindata/MinData_UsePrecioUnitarioOPrecioConIgv.xml");
393-
assertSendSunat(xml);
393+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
394394
}
395395

396396
@Test
@@ -434,7 +434,7 @@ void testDebitNoteWithMinDataSent_usePrecioUnitarioAndCantidadThreeDecimals() th
434434
// Then
435435
assertOutputHasNoConstraintViolations(validator, output);
436436
assertSnapshot(xml, "xml/debitnote/mindata/MinData_UsePrecioUnitarioOPrecioConIgvAndCantidadThreeDecimals.xml");
437-
assertSendSunat(xml);
437+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
438438
}
439439

440440
@Test
@@ -480,7 +480,7 @@ void testDebitNoteWithMinDataSent_usePrecioConIgvAndCantidadThreeDecimals() thro
480480
// Then
481481
assertOutputHasNoConstraintViolations(validator, output);
482482
assertSnapshot(xml, "xml/debitnote/mindata/MinData_UsePrecioUnitarioOPrecioConIgvAndCantidadThreeDecimals.xml");
483-
assertSendSunat(xml);
483+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
484484
}
485485

486486
}

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/ubl/debitnote/tiponota/DebitNoteTipoNotaTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void testDebitNoteTipoNota_GravadoOnerosa_precioUnitario() throws Exception {
7979
// Then
8080
assertOutputHasNoConstraintViolations(validator, output);
8181
assertSnapshot(xml, "xml/debitnote/tiponota/descuentoPorItem.xml");
82-
assertSendSunat(xml);
82+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
8383
}
8484

8585
}

src/test/java/io/github/project/openubl/xmlbuilderlib/integrationtest/ubl/invoice/InvoiceTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void testInvoiceWithCustomUnidadMedida() throws Exception {
7676
// Then
7777
assertOutputHasNoConstraintViolations(validator, output);
7878
assertSnapshot(xml, "xml/invoice/customUnidadMedida.xml");
79-
assertSendSunat(xml);
79+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
8080
}
8181

8282
@Test
@@ -123,7 +123,7 @@ void testInvoiceWithCustomFechaEmision() throws Exception {
123123
// Then
124124
assertOutputHasNoConstraintViolations(validator, output);
125125
assertSnapshot(xml, "xml/invoice/customFechaEmision.xml");
126-
assertSendSunat(xml);
126+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
127127
}
128128

129129
@Test
@@ -179,7 +179,7 @@ void testInvoiceWithCustomClienteDireccionAndContacto() throws Exception {
179179
// Then
180180
assertOutputHasNoConstraintViolations(validator, output);
181181
assertSnapshot(xml, "xml/invoice/customClienteDireccionAndContacto.xml");
182-
assertSendSunat(xml);
182+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
183183
}
184184

185185
@Test
@@ -200,7 +200,7 @@ void testInvoiceWithCustomProveedorDireccionAndContacto() throws Exception {
200200
.withDepartamento("Ayacucho")
201201
.withProvincia("Huamanga")
202202
.withDistrito("Jesus Nazareno")
203-
.withCodigoLocal("010101")
203+
.withCodigoLocal("0001")
204204
.withUrbanizacion("000000")
205205
.withDireccion("Jr. Las piedras 123")
206206
.withCodigoPais("PE")
@@ -284,7 +284,7 @@ void testInvoiceWithCustomFirmante() throws Exception {
284284
// Then
285285
assertOutputHasNoConstraintViolations(validator, output);
286286
assertSnapshot(xml, "xml/invoice/customFirmante.xml");
287-
assertSendSunat(xml);
287+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
288288
}
289289

290290
@Test
@@ -333,7 +333,7 @@ void testInvoiceWithICB_precioUnitario() throws Exception {
333333
// Then
334334
assertOutputHasNoConstraintViolations(validator, output);
335335
assertSnapshot(xml, "xml/invoice/icb.xml");
336-
assertSendSunat(xml);
336+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
337337
}
338338

339339
@Test
@@ -382,6 +382,6 @@ void testInvoiceWithICB_precioConIgv() throws Exception {
382382
// Then
383383
assertOutputHasNoConstraintViolations(validator, output);
384384
assertSnapshot(xml, "xml/invoice/icb.xml");
385-
assertSendSunat(xml);
385+
assertSendSunat(xml, PROVIDER_WITHOUT_ADDRESS_NOTE);
386386
}
387387
}

0 commit comments

Comments
 (0)