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

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.TextMessage;

import org.junit.Assert;
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.jms.service.PlateaJMSService;
import com.ejie.ad74a.ws.client.platea.regRepresentantes.IsValidRepresentation;
import com.ejie.ad74a.ws.client.platea.regRepresentantes.X43AWebService;
import com.ejie.ad74a.ws.client.platea.service.PlateaService;

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

	@Autowired
	private PlateaService plateaService;

	@Test
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	@Rollback(false)
	public void validarRrepresentacionAceptada() {
		String idTitular = "20040201W";
		String idRepresentante = "20040200R";
		boolean resultado = false;
		try {
			resultado = this.plateaService.validateRepresentative(idTitular, idRepresentante);
		} catch (Throwable e) {
			e.printStackTrace();
			Assert.fail("Error al procesar el message");
		}
		Assert.assertTrue("No se ha validado correctamente la representacion", resultado);
	}

	@Test
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	@Rollback(false)
	public void validarRrepresentacionRechazada() {
		String idTitular = "11111111H";
		String idRepresentante = "16271790A";
		boolean resultado = false;
		try {
			resultado = this.plateaService.validateRepresentative(idTitular, idRepresentante);
		} catch (Throwable e) {
			e.printStackTrace();
			Assert.fail("Error al procesar el message");
		}
		Assert.assertTrue("No se ha validado correctamente la representacion", !resultado);
	}

}
