/**
 * Core4BPEL - SOA Tools Platform.
 * Copyright (c) 2008 EBM Websourcing, http://www.ebmwebsourcing.com/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * -------------------------------------------------------------------------
 * $id.java
 * -------------------------------------------------------------------------
 */
package usecase.prosodie.deliveredService;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.xml.namespace.QName;

import org.jdom.JDOMException;
import org.junit.Test;

import com.ebmwebsourcing.easybpel.model.bpel.api.BPELException;
import com.ebmwebsourcing.easybpel.model.bpel.api.message.BPELExternalMessage;
import com.ebmwebsourcing.easybpel.model.bpel.impl.BPELFactoryImpl;
import com.ebmwebsourcing.easybpel.model.bpel.impl.exception.UserDefinedException;
import com.ebmwebsourcing.easybpel.model.bpel.impl.message.BPELExternalMessageImpl;
import com.ebmwebsourcing.easybpel.model.bpel.impl.message.DefaultBPELMessageConverter;
import com.ebmwebsourcing.easyviper.core.api.Core;
import com.ebmwebsourcing.easyviper.core.api.CoreException;
import com.ebmwebsourcing.easyviper.core.api.soa.message.ExternalMessage;
import com.ebmwebsourcing.easyviper.core.impl.model.registry.ProcessContextDefinitionImpl;
import com.ebmwebsourcing.easyviper.environment.test.BpelParentTest;
import com.ebmwebsourcing.easyviper.environment.test.env.ExecutionEnvironmentTestFactory;
import com.ebmwebsourcing.easyviper.environment.test.env.TestSenderImpl;
import com.ebmwebsourcing.easyviper.environment.test.env.api.ClientEndpoint;
import com.ebmwebsourcing.easyviper.environment.test.env.api.ExecutionEnvironmentTest;
import com.ebmwebsourcing.easyviper.environment.test.env.api.ProviderEndpoint;
import com.ebmwebsourcing.easyviper.tools.MemoryReceiverImpl;

/**
 * @author Nicolas Salatge - eBM WebSourcing
 */
public class TestDeliveredServiceServiceProcess extends BpelParentTest {

	/**
	 * @param name
	 */
	public TestDeliveredServiceServiceProcess(final String name) {
		super(name);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see junit.framework.TestCase#setUp()
	 */
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		System
		.setProperty("javax.xml.transform.TransformerFactory",
		"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see junit.framework.TestCase#tearDown()
	 */
	@Override
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	private ExecutionEnvironmentTest createAllEnvironment(final boolean explorer)
	throws CoreException, BPELException, URISyntaxException {
		// create execution environment
		ExecutionEnvironmentTest env = ExecutionEnvironmentTestFactory
		.newInstance().newEnvironment("TestEnvironnement", explorer);

		// // create core
		final Core core = BPELFactoryImpl.getInstance().newBPELEngine(
				DefaultBPELMessageConverter.get(), 1, MemoryReceiverImpl.class,
				1, TestSenderImpl.class);
		env.setCore(core);

		// // create providers
		ProviderEndpoint RefSDServiceProvider = env.createProviderEndpoint(
				"DeliveredServiceSOAP", RefSDService.class);
		
		ProviderEndpoint AliasServiceProvider = env.createProviderEndpoint("AliasServiceSOAP", AliasService.class);

		// store the definition
		core.getModel().getRegistry().storeProcessDefinition(
				new URI("./src/test/resources/deliverdServiceProcess.bpel"),
				new ProcessContextDefinitionImpl());
		return env;
	}

	/*
	@Test
	public void testGetClientOperations() throws CoreException, URISyntaxException,
	BPELException, InterruptedException, JDOMException, IOException {
		final boolean explorer = false;
		ExecutionEnvironmentTest env = createAllEnvironment(explorer);

		// // create client
		ClientEndpoint client = env.createClientEndpoint("client");

		ExternalMessage response = null;

		// send client message
		BPELExternalMessage message = new BPELExternalMessageImpl();
		message.setService(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"DeliveredServiceService"));
		message.setEndpoint("deliveredServiceSOAP");
		message.setQName(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"getClientOperationsRequest"));
		message
		.setMessage("<ns:getClientOperations xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:ns1=\"http://document.prosodie.com/ClientOperation/1/\" xmlns:ns2=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:ns3=\"http://document.prosodie.com/Sensitivity/1/\" xmlns:ns4=\"http://document.prosodie.com/Business/1/\" xmlns:ns5=\"http://document.prosodie.com/Resource/1/\">\r\n" + 
				"         <clientOperation>\r\n" + 
				"            <ns1:code>33333</ns1:code>\r\n" + 
				"         </clientOperation>\r\n" + 
				"      </ns:getClientOperations>\r\n" + 
		"");


		response = client.sendSync(message);



		BPELExternalMessage expectedResponse = new BPELExternalMessageImpl();
		expectedResponse.setMessage("<tns:getClientOperationsResponse xmlns:tns=\"http://contract.prosodie.com/DeliveredServiceService/1/\">" +
				"<clientOperations xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"tns:clientOperations\">" +
				"    <clientOperation>" +
				"      <ns:code xmlns:ns=\"http://document.prosodie.com/ClientOperation/1/\">33333</ns:code>" +
				"    </clientOperation>" +
				"  </clientOperations>" +
				"</tns:getClientOperationsResponse>" +
		"");
		assertEquals(expectedResponse.toString(), response.toString());

		if (explorer) {
			Thread.sleep(10000000);
		}

	}
	
	@Test
	public void testSaveClientOperations() throws CoreException, URISyntaxException,
	BPELException, InterruptedException, JDOMException, IOException {
		final boolean explorer = false;
		ExecutionEnvironmentTest env = createAllEnvironment(explorer);

		// // create client
		ClientEndpoint client = env.createClientEndpoint("client");

		ExternalMessage response = null;

		// send client message
		BPELExternalMessage message = new BPELExternalMessageImpl();
		message.setService(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"DeliveredServiceService"));
		message.setEndpoint("deliveredServiceSOAP");
		message.setQName(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"saveClientOperationRequest"));
		message
		.setMessage("<ns:saveClientOperation xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:ns1=\"http://document.prosodie.com/ClientOperation/1/\" xmlns:ns2=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:ns3=\"http://document.prosodie.com/Sensitivity/1/\" xmlns:ns4=\"http://document.prosodie.com/Business/1/\" xmlns:ns5=\"http://document.prosodie.com/Resource/1/\" xmlns:ns6=\"http://document.prosodie.com/MainAffair/1/\" xmlns:ns7=\"http://document.prosodie.com/Client/1/\">\r\n" + 
				"         <clientOperation>\r\n" + 
				"            <ns1:code>2233</ns1:code>\r\n" + 
				"         </clientOperation>\r\n" + 
				"      </ns:saveClientOperation>\r\n" + 
				"");


		response = client.sendSync(message);



		BPELExternalMessage expectedResponse = new BPELExternalMessageImpl();
		expectedResponse.setMessage("<tns:saveClientOperationResponse xmlns:tns=\"http://contract.prosodie.com/DeliveredServiceService/1/\">\r\n" + 
				"  <clientOperation xmlns:oc=\"http://document.prosodie.com/ClientOperation/1/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"oc:ClientOperation\">\r\n" + 
				"    <ns1:code xmlns:ns1=\"http://document.prosodie.com/ClientOperation/1/\">2233</ns1:code>\r\n" + 
				"  </clientOperation>\r\n" + 
				"</tns:saveClientOperationResponse>");
		assertEquals(expectedResponse.toString(), response.toString());

		if (explorer) {
			Thread.sleep(10000000);
		}

	}

	@Test
	public void testRemoveClientOperation() throws CoreException, URISyntaxException,
	BPELException, InterruptedException, JDOMException, IOException {
		final boolean explorer = false;
		ExecutionEnvironmentTest env = createAllEnvironment(explorer);

		// // create client
		ClientEndpoint client = env.createClientEndpoint("client");

		ExternalMessage response = null;

		// send client message
		BPELExternalMessage message = new BPELExternalMessageImpl();
		message.setService(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"DeliveredServiceService"));
		message.setEndpoint("deliveredServiceSOAP");
		message.setQName(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"removeClientOperationRequest"));
		message
		.setMessage("<ns:removeClientOperation xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:ns1=\"http://document.prosodie.com/ClientOperation/1/\" xmlns:ns2=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:ns3=\"http://document.prosodie.com/Sensitivity/1/\" xmlns:ns4=\"http://document.prosodie.com/Business/1/\" xmlns:ns5=\"http://document.prosodie.com/Resource/1/\" xmlns:ns6=\"http://document.prosodie.com/MainAffair/1/\" xmlns:ns7=\"http://document.prosodie.com/Client/1/\">\r\n" + 
				"         <clientOperation>\r\n" + 
				"            <ns1:deliveredService>\r\n" + 
				"               <ns2:uuid>NNDDRRFG</ns2:uuid>\r\n" + 
				"            </ns1:deliveredService>\r\n" + 
				"\r\n" + 
				"            <ns1:code>4455</ns1:code>\r\n" + 
				"\r\n" + 
				"         </clientOperation>\r\n" + 
				"      </ns:removeClientOperation>\r\n" + 
				"");


		response = client.sendSync(message);



		BPELExternalMessage expectedResponse = new BPELExternalMessageImpl();
		expectedResponse.setMessage("<ns:removeClientOperationResponse xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" />");
		assertEquals(expectedResponse.toString(), response.toString());

		if (explorer) {
			Thread.sleep(10000000);
		}

	}
	
	@Test
	public void testRemoveDeliveredService() throws CoreException, URISyntaxException,
	BPELException, InterruptedException, JDOMException, IOException {
		final boolean explorer = false;
		ExecutionEnvironmentTest env = createAllEnvironment(explorer);

		// // create client
		ClientEndpoint client = env.createClientEndpoint("client");

		ExternalMessage response = null;

		// send client message
		BPELExternalMessage message = new BPELExternalMessageImpl();
		message.setService(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"DeliveredServiceService"));
		message.setEndpoint("deliveredServiceSOAP");
		message.setQName(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"removeDeliveredServiceRequest"));
		message
		.setMessage("<ns:removeDeliveredService xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:ns2=\"http://document.prosodie.com/Sensitivity/1/\" xmlns:ns3=\"http://document.prosodie.com/Business/1/\" xmlns:ns4=\"http://document.prosodie.com/Resource/1/\" xmlns:ns5=\"http://document.prosodie.com/MainAffair/1/\" xmlns:ns6=\"http://document.prosodie.com/Client/1/\">\r\n" + 
				"         <deliveredService>\r\n" + 
				"            <ns1:uuid>SS-DD</ns1:uuid>\r\n" + 
				"         </deliveredService>\r\n" + 
				"      </ns:removeDeliveredService>\r\n" + 
				"");


		response = client.sendSync(message);



		BPELExternalMessage expectedResponse = new BPELExternalMessageImpl();
		expectedResponse.setMessage("<tns:removeDeliveredServiceResponse xmlns:tns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" />");
		assertEquals(expectedResponse.toString(), response.toString());

		if (explorer) {
			Thread.sleep(10000000);
		}

	}
	
	@Test
	public void testSaveDeliveredService() throws CoreException, URISyntaxException,
	BPELException, InterruptedException, JDOMException, IOException {
		final boolean explorer = false;
		ExecutionEnvironmentTest env = createAllEnvironment(explorer);

		// // create client
		ClientEndpoint client = env.createClientEndpoint("client");

		ExternalMessage response = null;

		// send client message
		BPELExternalMessage message = new BPELExternalMessageImpl();
		message.setService(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"DeliveredServiceService"));
		message.setEndpoint("deliveredServiceSOAP");
		message.setQName(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"saveDeliveredServiceRequest"));
		message
		.setMessage("<ns:saveDeliveredService xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:ns2=\"http://document.prosodie.com/Sensitivity/1/\" xmlns:ns3=\"http://document.prosodie.com/Business/1/\" xmlns:ns4=\"http://document.prosodie.com/Resource/1/\" xmlns:ns5=\"http://document.prosodie.com/MainAffair/1/\" xmlns:ns6=\"http://document.prosodie.com/Client/1/\">\r\n" + 
				"         <deliveredService>\r\n" + 
				"            <ns1:code>556699</ns1:code>\r\n" + 
				"            <ns1:name>TEST</ns1:name>\r\n" + 
				"            <ns1:enabled>1</ns1:enabled>\r\n" + 
				"         </deliveredService>\r\n" + 
				"      </ns:saveDeliveredService>\r\n" + 
				"");


		response = client.sendSync(message);



		BPELExternalMessage expectedResponse = new BPELExternalMessageImpl();
		expectedResponse.setMessage("<tns:saveDeliveredServiceResponse xmlns:tns=\"http://contract.prosodie.com/DeliveredServiceService/1/\">\r\n" + 
				"  <deliveredService xmlns:sd=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"sd:DeliveredService\">\r\n" + 
				"    <ns1:uuid xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\">SN 12 36 54</ns1:uuid>\r\n" + 
				"    <ns1:code xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\">556699</ns1:code>\r\n" + 
				"    <ns1:name xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\">TEST</ns1:name>\r\n" + 
				"    <ns1:enabled xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\">1</ns1:enabled>\r\n" + 
				"  </deliveredService>\r\n" + 
				"</tns:saveDeliveredServiceResponse>");
		assertEquals(expectedResponse.toString(), response.toString());

		if (explorer) {
			Thread.sleep(10000000);
		}

	}
	
	@Test
	public void testGetDeliveredServices() throws CoreException, URISyntaxException,
	BPELException, InterruptedException, JDOMException, IOException {
		final boolean explorer = false;
		ExecutionEnvironmentTest env = createAllEnvironment(explorer);

		// // create client
		ClientEndpoint client = env.createClientEndpoint("client");

		ExternalMessage response = null;

		// send client message
		BPELExternalMessage message = new BPELExternalMessageImpl();
		message.setService(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"DeliveredServiceService"));
		message.setEndpoint("deliveredServiceSOAP");
		message.setQName(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"getDeliveredServicesRequest"));
		message
		.setMessage("<ns:getDeliveredServices xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:ns2=\"http://document.prosodie.com/Sensitivity/1/\" xmlns:ns3=\"http://document.prosodie.com/Business/1/\" xmlns:ns4=\"http://document.prosodie.com/Resource/1/\" xmlns:ns5=\"http://document.prosodie.com/MainAffair/1/\" xmlns:ns6=\"http://document.prosodie.com/Client/1/\">\r\n" + 
				"         <deliveredService>\r\n" + 
				"            <ns1:mainAffair>\r\n" + 
				"               <ns5:uuid>AP1254</ns5:uuid>\r\n" + 
				"            </ns1:mainAffair>\r\n" + 
				"         </deliveredService>\r\n" + 
				"      </ns:getDeliveredServices>\r\n" + 
				"");


		response = client.sendSync(message);



		BPELExternalMessage expectedResponse = new BPELExternalMessageImpl();
		expectedResponse.setMessage("<ns:getDeliveredServicesResponse xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\">\r\n" + 
				"  <getDeliveredServicesResponse>\r\n" + 
				"    <deliveredServices xmlns:tns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"tns:deliveredServices\">\r\n" + 
				"      <deliveredService>\r\n" + 
				"        <ns1:uuid xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\">SN1</ns1:uuid>\r\n" + 
				"        <aliases xmlns=\"http://document.prosodie.com/DeliveredService/1/\">\r\n" + 
				"          <alias xmlns=\"\">test@service.com</alias>\r\n" + 
				"        </aliases>\r\n" + 
				"        <ns1:mainAffair xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\">\r\n" + 
				"          <ns5:uuid xmlns:ns5=\"http://document.prosodie.com/MainAffair/1/\">AP1254</ns5:uuid>\r\n" + 
				"        </ns1:mainAffair>\r\n" + 
				"      </deliveredService>\r\n" + 
				"      <deliveredService>\r\n" + 
				"        <ns1:uuid xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\">SN2</ns1:uuid>\r\n" + 
				"        <aliases xmlns=\"http://document.prosodie.com/DeliveredService/1/\">\r\n" + 
				"          <alias xmlns=\"\">test2@service.com</alias>\r\n" + 
				"          <alias xmlns=\"\">test3@service.com</alias>\r\n" + 
				"        </aliases>\r\n" + 
				"        <ns1:mainAffair xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\">\r\n" + 
				"          <ns5:uuid xmlns:ns5=\"http://document.prosodie.com/MainAffair/1/\">AP1254</ns5:uuid>\r\n" + 
				"        </ns1:mainAffair>\r\n" + 
				"      </deliveredService>\r\n" + 
				"    </deliveredServices>\r\n" + 
				"  </getDeliveredServicesResponse>\r\n" + 
				"</ns:getDeliveredServicesResponse>");
		assertEquals(expectedResponse.toString(), response.toString());

		if (explorer) {
			Thread.sleep(10000000);
		}

	}
	
	@Test
	public void testGetDeliveredServicesIllegalArgumentFault() throws CoreException, URISyntaxException,
	BPELException, InterruptedException, JDOMException, IOException {
		final boolean explorer = false;
		ExecutionEnvironmentTest env = createAllEnvironment(explorer);

		// // create client
		ClientEndpoint client = env.createClientEndpoint("client");

		ExternalMessage response = null;

		// send client message
		BPELExternalMessage message = new BPELExternalMessageImpl();
		message.setService(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"DeliveredServiceService"));
		message.setEndpoint("deliveredServiceSOAP");
		message.setQName(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"getDeliveredServicesRequest"));
		message
		.setMessage("<ns:getDeliveredServices xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:ns2=\"http://document.prosodie.com/Sensitivity/1/\" xmlns:ns3=\"http://document.prosodie.com/Business/1/\" xmlns:ns4=\"http://document.prosodie.com/Resource/1/\" xmlns:ns5=\"http://document.prosodie.com/MainAffair/1/\" xmlns:ns6=\"http://document.prosodie.com/Client/1/\">\r\n" + 
				"         <deliveredService>\r\n" + 
				"            <ns1:mainAffair>\r\n" + 
				"               <ns5:uuid>AP6598</ns5:uuid>\r\n" + 
				"            </ns1:mainAffair>\r\n" + 
				"         </deliveredService>\r\n" + 
				"      </ns:getDeliveredServices>\r\n" + 
				"");


		try {
			response = client.sendSync(message);
			fail();
		} catch (Exception e) {
			assertEquals(UserDefinedException.class, e.getClass());
			assertEquals("L'exception en correspond pas.",
					((UserDefinedException) e).getFaultName()
					.getLocalPart(), "getDeliveredServicesIllegalArgumentFault");
		}


		if (explorer) {
			Thread.sleep(10000000);
		}
	}
	
	
	@Test
	public void testGetDeliveredServicesTechnicalFault() throws CoreException, URISyntaxException,
	BPELException, InterruptedException, JDOMException, IOException {
		final boolean explorer = false;
		ExecutionEnvironmentTest env = createAllEnvironment(explorer);

		// // create client
		ClientEndpoint client = env.createClientEndpoint("client");

		ExternalMessage response = null;

		// send client message
		BPELExternalMessage message = new BPELExternalMessageImpl();
		message.setService(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"DeliveredServiceService"));
		message.setEndpoint("deliveredServiceSOAP");
		message.setQName(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"getDeliveredServicesRequest"));
		message
		.setMessage("<ns:getDeliveredServices xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:ns2=\"http://document.prosodie.com/Sensitivity/1/\" xmlns:ns3=\"http://document.prosodie.com/Business/1/\" xmlns:ns4=\"http://document.prosodie.com/Resource/1/\" xmlns:ns5=\"http://document.prosodie.com/MainAffair/1/\" xmlns:ns6=\"http://document.prosodie.com/Client/1/\">\r\n" + 
				"         <deliveredService>\r\n" + 
				"            <ns1:mainAffair>\r\n" + 
				"               <ns5:uuid>AP7000</ns5:uuid>\r\n" + 
				"            </ns1:mainAffair>\r\n" + 
				"         </deliveredService>\r\n" + 
				"      </ns:getDeliveredServices>\r\n" + 
				"");


		try {
			response = client.sendSync(message);
			fail();
		} catch (Exception e) {
			assertEquals(UserDefinedException.class, e.getClass());
			assertEquals("L'exception en correspond pas.",
					((UserDefinedException) e).getFaultName()
					.getLocalPart(), "getDeliveredServicesTechnicalFault");
		}


		if (explorer) {
			Thread.sleep(10000000);
		}

	}
	*/
	
	
	@Test
	public void testGetDeliveredServicesAliasTechnicalFault() throws CoreException, URISyntaxException,
	BPELException, InterruptedException, JDOMException, IOException {
		final boolean explorer = false;
		ExecutionEnvironmentTest env = createAllEnvironment(explorer);

		// // create client
		ClientEndpoint client = env.createClientEndpoint("client");

		ExternalMessage response = null;

		// send client message
		BPELExternalMessage message = new BPELExternalMessageImpl();
		message.setService(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"DeliveredServiceService"));
		message.setEndpoint("deliveredServiceSOAP");
		message.setQName(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"getDeliveredServicesRequest"));
		message
		.setMessage("<ns:getDeliveredServices xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:ns2=\"http://document.prosodie.com/Sensitivity/1/\" xmlns:ns3=\"http://document.prosodie.com/Business/1/\" xmlns:ns4=\"http://document.prosodie.com/Resource/1/\" xmlns:ns5=\"http://document.prosodie.com/MainAffair/1/\" xmlns:ns6=\"http://document.prosodie.com/Client/1/\">\r\n" + 
				"         <deliveredService>\r\n" + 
				"            <ns1:mainAffair>\r\n" + 
				"               <ns5:uuid>AP9001</ns5:uuid>\r\n" + 
				"            </ns1:mainAffair>\r\n" + 
				"         </deliveredService>\r\n" + 
				"      </ns:getDeliveredServices>\r\n" + 
				"");


		try {
			response = client.sendSync(message);
			fail();
		} catch (Exception e) {
			assertEquals(UserDefinedException.class, e.getClass());
			assertEquals("L'exception en correspond pas.",
					((UserDefinedException) e).getFaultName()
					.getLocalPart(), "getDeliveredServicesTechnicalFault");
		}


		if (explorer) {
			Thread.sleep(10000000);
		}

	}
	
	
	/*
	@Test
	public void testGetDeliveredServicesAliasIllegalArgumentFault() throws CoreException, URISyntaxException,
	BPELException, InterruptedException, JDOMException, IOException {
		final boolean explorer = false;
		ExecutionEnvironmentTest env = createAllEnvironment(explorer);

		// // create client
		ClientEndpoint client = env.createClientEndpoint("client");

		ExternalMessage response = null;

		// send client message
		BPELExternalMessage message = new BPELExternalMessageImpl();
		message.setService(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"DeliveredServiceService"));
		message.setEndpoint("deliveredServiceSOAP");
		message.setQName(new QName(
				"http://contract.prosodie.com/DeliveredServiceService/1/",
		"getDeliveredServicesRequest"));
		message
		.setMessage("<ns:getDeliveredServices xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://contract.prosodie.com/DeliveredServiceService/1/\" xmlns:ns1=\"http://document.prosodie.com/DeliveredService/1/\" xmlns:ns2=\"http://document.prosodie.com/Sensitivity/1/\" xmlns:ns3=\"http://document.prosodie.com/Business/1/\" xmlns:ns4=\"http://document.prosodie.com/Resource/1/\" xmlns:ns5=\"http://document.prosodie.com/MainAffair/1/\" xmlns:ns6=\"http://document.prosodie.com/Client/1/\">\r\n" + 
				"         <deliveredService>\r\n" + 
				"            <ns1:mainAffair>\r\n" + 
				"               <ns5:uuid>AP9000</ns5:uuid>\r\n" + 
				"            </ns1:mainAffair>\r\n" + 
				"         </deliveredService>\r\n" + 
				"      </ns:getDeliveredServices>\r\n" + 
				"");


		try {
			response = client.sendSync(message);
			fail();
		} catch (Exception e) {
			assertEquals(UserDefinedException.class, e.getClass());
			assertEquals("L'exception en correspond pas.",
					((UserDefinedException) e).getFaultName()
					.getLocalPart(), "getDeliveredServicesIllegalArgumentFault");
		}


		if (explorer) {
			Thread.sleep(10000000);
		}

	}
	*/
}
