package com.ejie.ad74a.service.test.platea;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ejie.ad74a.ws.client.platea.expedienteElectronico.TAuthorizationTraceType;
import com.ejie.ad74a.ws.client.platea.expedienteElectronico.TPersonIDName;
import com.ejie.ad74a.service.interoperabilidad.InteroperabilidadService;
import com.ejie.ad74a.service.interoperabilidad.RemesasService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:test/application-context.xml")
public class TestInteroperabilidadService {

	@Autowired
	private InteroperabilidadService interoperabilidadService;

	@Autowired
	private RemesasService remesasService;

	@Test
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	@Rollback(false)
	public void testGetAuthorizationTrace() {
		String authorizationID = "";
		String iopTraceID = "x53ji00378F9D00123148";

		String documentPath = "/ad74a/" + iopTraceID + ".html";
		TPersonIDName senderID = new TPersonIDName();
		senderID.setID("AD74A");

		this.interoperabilidadService.getAuthorizationTrace(authorizationID, iopTraceID, documentPath,
				TAuthorizationTraceType.NISAE, senderID);
	}

	@Test
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	@Rollback(false)
	public void testValidarCodigoPostalCorrecto() {
		String codigoPostal = "01012";

		boolean valido = this.remesasService.validarCodigoPostal(codigoPostal);

		assertTrue("No se ha validado correctamente el codigo postaL correcto", valido);

	}

	@Test
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	@Rollback(false)
	public void testValidarCodigoPostalInCorrecto() {
		String codigoPostal = "6666";

		boolean valido = this.remesasService.validarCodigoPostal(codigoPostal);

		assertTrue("No se ha validado correctamente el codigo postal incorrecto", !valido);

	}

}
