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.GlobalUconnectExtAuth;
import com.fca.uconnect.global.GlobalUconnectExtProvision;
import com.fca.uconnect.global.SDPExampleForAuthorization;
import com.fca.uconnect.global.TBMExampleForAuthorization;



public class AuthTest {
	static SDPExampleForAuthorization referenceService = new SDPExampleForAuthorization();
	static TBMExampleForAuthorization referenceClient =new TBMExampleForAuthorization();

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

	 
	@Test
	public void testLoginSuccess() throws Exception{
		    List<UconnectAny> messages = referenceClient.process();
		    for(UconnectAny message:messages){
	 			if(message.hasExtension(GlobalUconnectExtAuth.loginResponse)) {	
	 				GlobalUconnectExtAuth.LoginResponse.ResponseEnum responseForLogin = message.getExtension(GlobalUconnectExtAuth.loginResponse).getResponse();
					if(responseForLogin!=null && responseForLogin.equals( GlobalUconnectExtAuth.LoginResponse.ResponseEnum.SUCCESS)){
						assertEquals(GlobalUconnectExtAuth.LoginResponse.ResponseEnum.SUCCESS,responseForLogin);
					}
	 			}else if(message.hasExtension(GlobalUconnectExtProvision.provisioningPush)){
	 				GlobalUconnectExtProvision.ProvisioningPush provPush = message.getExtension(GlobalUconnectExtProvision.provisioningPush);
	 				//assertEquals(provPush.getServiceSubscriptionInfo().getServicesCount(),2);
//	 				assertTrue(receivedList.get(0).equals(ServiceDescription.newBuilder()
//	 						.setExpireTime(1234567890)
//	 						.setServiceType(ServiceTypeEnum.ECALL)
//	 						.build()));
	 			}
	 			
		    }
	   }
	@AfterClass
	public  static  void disconnectClass(){
		try {
			referenceService.disconnect();
			referenceClient.disconnect();
		} catch (Exception e) {
			e.printStackTrace();
		}				
	}
	
}
