package com.offcn.api.nwn.process;

import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Random;

import org.json.simple.JSONArray;

import com.offcn.TestUnti.Log;
import com.offcn.TestUnti.MapUtil;
import com.offcn.TestUnti.ReadProperties;
import com.offcn.TestUnti.RequestDataUtils;
import com.offcn.TestUnti.StringUtils;
import com.offcn.interfaces.API;
import com.offcn.process.NWN;
import com.offcn.process.XYZB;

import net.sf.json.JSONObject;



/**
 *获取PHPSESSID
 * 
 * @author puhui
 *
 */
public class code extends NWN implements API {
	
	@Override
	public void initialize(HashMap<String, Object> data) {
	}

	@Override
	public HashMap<String, Object> handleInput(HashMap<String, Object> data) {
		return data;
	}

	@Override
	public Response SendRequest(HashMap<String, Object> data, String Url,
			String Request) {
//		Response re = RequestDataUtils.Get_two_cookie(data, nwn_url,"admin_login_ssid",admin_login_ssid,"PHPSESSID",PHPSESSID);
		return null;
	}

	@Override
	public String handleOutput(Response re, HashMap<String, Object> data) {
		
		String body=re.asString();
		boolean result = true;  
		String failReason = "";  
		
		if(body.contains("<title>")){
			int Alength="<title>".length();
			int start=body.indexOf("<title>");
			int end=body.indexOf("</title>")+1;
			body=body.substring(start+Alength, end-1);
		}
			
		if(data.get("custom") != null && body!=null){
			if(!(body.equals(data.get("custom")))){
				result = result && false;
				failReason = failReason + "custom is expected "
						+ data.get("custom").toString() + " but actually "
						+ body + ".";
			}else{
				MapUtil.showMap_String(re.getCookies());
				admin_login_ssid=re.getCookie("admin_login_ssid");
				admin_31_encode=re.getCookie("admin_31_encode");
			}
		}
			
			
			
		
		
		if (result)
			return "Pass";
		else
			return "Fail:" + failReason;
	}

}
