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

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.util.pid.Ad74aPIDws;
import com.ejie.ad74a.ws.client.dokusi.gestDocumental.T65BFsdJaxbInterface;

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

	@Autowired
	private T65BFsdJaxbInterface t65BFsdJaxbInterface;

	@Autowired
	private Ad74aPIDws pidWS;

	@Test
	@Transactional(propagation = Propagation.SUPPORTS)
	@Rollback(false)
	public void testPut() {

		try {

//			// subimos documento a pif
//			String basePath = "D:/taadmin/trunk/datos/ad74a/file/pif/";
//			String nombre = "file_test.xml";
//
//			File file = new File(basePath + nombre);
//			InputStream inputStream = null;
//			int i = 0;
//			try {
//				inputStream = new FileInputStream(file);
//				while ((i = inputStream.read()) != -1) {
//					System.out.print((char) i + "");
//				}
//			} catch (FileNotFoundException e) {
//				e.printStackTrace();
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//
//			Ad74aPIFws pifService = Ad74aPIFws.getInstance();
//			pifService.uploadDocument(inputStream, "/ad74a/test/" + nombre, true);

			String nombreFichero = "file_test.xml";
			String usuarioAlta = "AD74A";
			String rutaPif = "/ad74a/test/file_test.xml";
			String aplic = "AD74A";
			String rutaPid = pidWS.put(aplic, nombreFichero, rutaPif, usuarioAlta);
			System.out.println(rutaPid);

		} catch (Throwable e) {
			e.printStackTrace();
			Assert.fail("Error al procesar el message");
		}
		// Assert.assertTrue("Se ha encontrado un registro que no existe", true);
	}

	@Test
	@Transactional(propagation = Propagation.SUPPORTS)
	@Rollback(false)
	public void testGet() {

		Ad74aPIDws pidWS = new Ad74aPIDws();
		try {

			String nombreFichero = "prueba.pdf";
			String usuarioAlta = "AD74A";
			String rutaPif = "/ad74a/test/";
			String aplic = "AD74A";
			// pidWS.get("", "");

		} catch (Throwable e) {
			e.printStackTrace();
			Assert.fail("Error al procesar el message");
		}
		// Assert.assertTrue("Se ha encontrado un registro que no existe", true);
	}

}
