package com.fca.uconnect.global.test;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
import com.fca.uconnect.global.GlobalUconnectExtProvision;
import com.fca.uconnect.global.SDPExampleForProvisioning;
import com.fca.uconnect.global.TBMExampleForProvisioning;



public class ProvisioningTest {
	static SDPExampleForProvisioning referenceService = new SDPExampleForProvisioning();
	static TBMExampleForProvisioning referenceClient =new TBMExampleForProvisioning();

	@BeforeClass
	public  static  void setUpClass(){
		try {
			
			  referenceService.process();
			  Thread.sleep(1000);
			  //referenceClient.process();
		} catch (Exception e) {
			e.printStackTrace();
		}				
	}	 

	 
	@Test
	public void testProvisioningSuccess() throws Exception{
		    List<UconnectAny> messages = referenceClient.process();
		    for(UconnectAny message:messages){
	 			if(message.hasExtension(GlobalUconnectExtProvision.provisioningResponse)) {	
	 				GlobalUconnectExtProvision.ProvisioningResponse.ResponseEnum responseForProvisioning = message.getExtension(GlobalUconnectExtProvision.provisioningResponse).getResponseEnum();
					if(responseForProvisioning!=null && responseForProvisioning.equals( GlobalUconnectExtProvision.ProvisioningResponse.ResponseEnum.SUCCESS)){
						assertEquals(GlobalUconnectExtProvision.ProvisioningResponse.ResponseEnum.SUCCESS,responseForProvisioning);
					}
	 			}else if(message.hasExtension(GlobalUconnectExtProvision.provisioningPush)){
	 				GlobalUconnectExtProvision.ProvisioningPush provPush = message.getExtension(GlobalUconnectExtProvision.provisioningPush);
	 				//assertEquals(provPush.getServiceSubscriptionInfo().getServicesCount(),2);
	 			}
	 			
		    }
	}
	@AfterClass
	public  static  void disconnectClass(){
		try {
			referenceService.disconnect();
			referenceClient.disconnect();
		} catch (Exception e) {
			e.printStackTrace();
		}				
	}
}
