package com.fca.uconnect.global.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

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.GlobalUconnectExtWIFIHotSpot;
import com.fca.uconnect.global.SDPExampleForWifiHotSpot;
import com.fca.uconnect.global.TBMExampleForWifiHotSpot;

public class WifiHotSpotTest {
	static SDPExampleForWifiHotSpot referenceService = new SDPExampleForWifiHotSpot();
	static TBMExampleForWifiHotSpot referenceClient =new TBMExampleForWifiHotSpot();
	

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

	 
	@Test
	public void testWIFISuccess() throws Exception{
		    List<UconnectAny> messages = referenceClient.process();
		    for(UconnectAny message:messages){
	 			if(message.hasExtension(GlobalUconnectExtWIFIHotSpot.dataPackageStatusResponse)) {	
	 				GlobalUconnectExtWIFIHotSpot.DataPackageStatusResponse.ResponseEnum responseForWIFIHotSpot = message.getExtension(GlobalUconnectExtWIFIHotSpot.dataPackageStatusResponse).getResponseEnum();
					if(responseForWIFIHotSpot!=null && responseForWIFIHotSpot.equals( GlobalUconnectExtWIFIHotSpot.DataPackageStatusResponse.ResponseEnum.SUCCESS)){
						assertEquals(GlobalUconnectExtWIFIHotSpot.DataPackageStatusResponse.ResponseEnum.SUCCESS,responseForWIFIHotSpot);
					}
	 			}else if(message.hasExtension(GlobalUconnectExtWIFIHotSpot.wifiPackageDataStatus)){
	 				GlobalUconnectExtWIFIHotSpot.WifiPackageDataStatus wifiPush = message.getExtension(GlobalUconnectExtWIFIHotSpot.wifiPackageDataStatus);
	 				assertTrue(wifiPush.getIsLowAlertFlag());
	 			}
	 			
		    }
	}
	@AfterClass
	public  static  void disconnectClass(){
		try {
			referenceService.disconnect();
			referenceClient.disconnect();
		} catch (Exception e) {
			e.printStackTrace();
		}				
	}
}
