66import mx .com .sw .services .stamp .responses .StampResponseV2 ;
77import mx .com .sw .services .stamp .responses .StampResponseV3 ;
88import mx .com .sw .services .stamp .responses .StampResponseV4 ;
9+
10+ import java .util .Arrays ;
11+ import java .util .Collections ;
12+ import java .util .List ;
13+ import java .util .UUID ;
14+ import java .util .stream .Collectors ;
15+
916import org .junit .jupiter .api .Assertions ;
1017import org .junit .jupiter .api .Test ;
1118
@@ -190,7 +197,129 @@ public void testV4StampV1() {
190197 IssueJsonV4 stamp = new IssueJsonV4 (settings .getUrlSW (), settings .getUserSW (), settings .getPasswordSW (),
191198 null , 0 );
192199 String json = settings .getJsonCFDI ();
193- StampResponseV1 response = stamp .timbrarV1 (json , settings .getEmail ());
200+ StampResponseV1 response = stamp .timbrarV1 (json , settings .getEmail (), null , false );
201+ Assertions .assertNotNull (response );
202+ Assertions .assertNotNull (response .getData ());
203+ Assertions .assertNotNull (response .getStatus ());
204+ Assertions .assertNotNull (response .getData ().getTFD ());
205+ Assertions .assertTrue ("success" .equalsIgnoreCase (response .getStatus ()));
206+ } catch (ServicesException ex ) {
207+ Assertions .assertNotNull (ex );
208+ }
209+ }
210+
211+ /**
212+ * Método de UT timbrado versión 1 (con usuario y password y envio de email erroneo).
213+ */
214+ @ Test
215+ public void testV4StampV1_errorEmail () {
216+ try {
217+ IssueJsonV4 stamp = new IssueJsonV4 (settings .getUrlSW (), settings .getUserSW (), settings .getPasswordSW (),
218+ null , 0 );
219+ String json = settings .getJsonCFDI ();
220+ StampResponseV1 response = stamp .timbrarV1 (json , "correotest.com.mx" , null , false );
221+ String messageExpect = "El listado de correos no contiene un formato válido o alguno de los correos es inválido." ;
222+ Assertions .assertNotNull (response );
223+ Assertions .assertTrue ("error" .equalsIgnoreCase (response .getStatus ()));
224+ Assertions .assertTrue (messageExpect .equalsIgnoreCase (response .getMessage ()));
225+ } catch (ServicesException ex ) {
226+ Assertions .assertNotNull (ex );
227+ }
228+ }
229+
230+ /**
231+ * Método de UT timbrado versión 1 (con usuario y password y envio de 6 emails).
232+ */
233+ @ Test
234+ public void testV4StampV1_maxEmail () {
235+ try {
236+ IssueJsonV4 stamp = new IssueJsonV4 (settings .getUrlSW (), settings .getUserSW (), settings .getPasswordSW (),
237+ null , 0 );
238+ String json = settings .getJsonCFDI ();
239+ String emails = "correo@test.com.mx, correo@test2.com.mx, correo@test3.com.mx, correo@test4.com.mx, correo@test5.com.mx, correo@test6.com.mx" ;
240+ StampResponseV1 response = stamp .timbrarV1 (json , emails , null , false );
241+ String messageExpect = "El listado de correos está vacío o contiene más de 5 correos." ;
242+ Assertions .assertNotNull (response );
243+ Assertions .assertTrue ("error" .equalsIgnoreCase (response .getStatus ()));
244+ Assertions .assertTrue (messageExpect .equalsIgnoreCase (response .getMessage ()));
245+ } catch (ServicesException ex ) {
246+ Assertions .assertNotNull (ex );
247+ }
248+ }
249+
250+ /**
251+ * Método de UT timbrado versión 1 (con usuario y password y envio de CustomId).
252+ */
253+ @ Test
254+ public void testV4StampV1_customId () {
255+ try {
256+ IssueJsonV4 stamp = new IssueJsonV4 (settings .getUrlSW (), settings .getUserSW (), settings .getPasswordSW (),
257+ null , 0 );
258+ String json = settings .getJsonCFDI ();
259+ String customId = UUID .randomUUID ().toString ();
260+ StampResponseV1 response = stamp .timbrarV1 (json , null , customId , false );
261+ Assertions .assertNotNull (response );
262+ Assertions .assertNotNull (response .getData ());
263+ Assertions .assertNotNull (response .getStatus ());
264+ Assertions .assertNotNull (response .getData ().getTFD ());
265+ Assertions .assertTrue ("success" .equalsIgnoreCase (response .getStatus ()));
266+ } catch (ServicesException ex ) {
267+ Assertions .assertNotNull (ex );
268+ }
269+ }
270+
271+ /**
272+ * Método de UT timbrado versión 1 (con usuario y password y envio de CustomId duplicado).
273+ */
274+ @ Test
275+ public void testV4StampV1_duplicateCustomId () {
276+ try {
277+ IssueJsonV4 stamp = new IssueJsonV4 (settings .getUrlSW (), settings .getUserSW (), settings .getPasswordSW (),
278+ null , 0 );
279+ String json = settings .getJsonCFDI ();
280+ String customId = UUID .randomUUID ().toString ();
281+ StampResponseV1 response = stamp .timbrarV1 (json , null , customId , false );
282+ Assertions .assertNotNull (response );
283+ Assertions .assertTrue ("success" .equalsIgnoreCase (response .getStatus ()));
284+ response = stamp .timbrarV1 (json , null , customId , false );
285+ Assertions .assertTrue ("error" .equalsIgnoreCase (response .getStatus ()));
286+ Assertions .assertTrue ("307. El comprobante contiene un timbre previo." .equalsIgnoreCase (response .getMessage ()));
287+ } catch (ServicesException ex ) {
288+ Assertions .assertNotNull (ex );
289+ }
290+ }
291+
292+ /**
293+ * Método de UT timbrado versión 1 (con usuario y password y envio de CustomId invalido).
294+ */
295+ @ Test
296+ public void testV4StampV1_invalidCustomId () {
297+ try {
298+ IssueJsonV4 stamp = new IssueJsonV4 (settings .getUrlSW (), settings .getUserSW (), settings .getPasswordSW (),
299+ null , 0 );
300+ String json = settings .getJsonCFDI ();
301+ String customId = UUID .randomUUID ().toString ();
302+ customId = Collections .nCopies (10 , customId ).stream ().collect (Collectors .joining ());
303+ StampResponseV1 response = stamp .timbrarV1 (json , null , customId , false );
304+ String messageExpect = "El CustomId no es válido o viene vacío." ;
305+ Assertions .assertNotNull (response );
306+ Assertions .assertTrue ("error" .equalsIgnoreCase (response .getStatus ()));
307+ Assertions .assertTrue (messageExpect .equalsIgnoreCase (response .getMessage ()));
308+ } catch (ServicesException ex ) {
309+ Assertions .assertNotNull (ex );
310+ }
311+ }
312+
313+ /**
314+ * Método de UT timbrado versión 1 (con usuario y password y envio de parametro extra para crear PDF).
315+ */
316+ @ Test
317+ public void testV4StampV1_pdf () {
318+ try {
319+ IssueJsonV4 stamp = new IssueJsonV4 (settings .getUrlSW (), settings .getUserSW (), settings .getPasswordSW (),
320+ null , 0 );
321+ String json = settings .getJsonCFDI ();
322+ StampResponseV1 response = stamp .timbrarV1 (json , null , null , true );
194323 Assertions .assertNotNull (response );
195324 Assertions .assertNotNull (response .getData ());
196325 Assertions .assertNotNull (response .getStatus ());
@@ -210,7 +339,7 @@ public void testV4StampV2() {
210339 IssueJsonV4 stamp = new IssueJsonV4 (settings .getUrlSW (), settings .getUserSW (), settings .getPasswordSW (),
211340 null , 0 );
212341 String json = settings .getJsonCFDI ();
213- StampResponseV2 response = stamp .timbrarV2 (json , settings .getEmail ());
342+ StampResponseV2 response = stamp .timbrarV2 (json , settings .getEmail (), null , false );
214343 Assertions .assertNotNull (response );
215344 Assertions .assertNotNull (response .getData ());
216345 Assertions .assertNotNull (response .getStatus ());
@@ -229,7 +358,7 @@ public void testV4StampV3() {
229358 try {
230359 IssueJsonV4 stamp = new IssueJsonV4 (settings .getUrlSW (), settings .getTokenSW (), null , 0 );
231360 String json = settings .getJsonCFDI ();
232- StampResponseV3 response = stamp .timbrarV3 (json , settings .getEmail ());
361+ StampResponseV3 response = stamp .timbrarV3 (json , settings .getEmail (), null , false );
233362 Assertions .assertNotNull (response );
234363 Assertions .assertNotNull (response .getData ());
235364 Assertions .assertNotNull (response .getStatus ());
@@ -248,7 +377,7 @@ public void testV4StampV4() {
248377 try {
249378 IssueJsonV4 stamp = new IssueJsonV4 (settings .getUrlSW (), settings .getTokenSW (), null , 0 );
250379 String json = settings .getJsonCFDI ();
251- StampResponseV4 response = stamp .timbrarV4 (json , settings .getEmail ());
380+ StampResponseV4 response = stamp .timbrarV4 (json , settings .getEmail (), null , false );
252381 Assertions .assertNotNull (response );
253382 Assertions .assertNotNull (response .getData ());
254383 Assertions .assertNotNull (response .getStatus ());
0 commit comments