package org.bench4q.master.unitTest.controller;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.JAXBException;

import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
import org.junit.Before;
import org.junit.Test;

public class ScriptControllerTest extends TestBase {

	private String controllerUrl = BASE_URL + "/RecordScript";

	@Before
	public void prepare() {
		this.setAccessTocken(this.login());
	}

	@Test
	public void loadScriptsTest() throws IOException, JAXBException {
		String url = this.controllerUrl + "/loadScriptList";
		HttpResponse httpResponse = this.httpRequester.sendGet(url, null,
				this.makeAccessTockenMap(this.login()));
		OperateScriptServerResponseModel ret = (OperateScriptServerResponseModel) MarshalHelper
				.unmarshal(OperateScriptServerResponseModel.class,
						httpResponse.getContent());
		assertTrue(ret.getScriptModels().size() > 0);
	}

	@Test
	public void deleteScript(int scriptId) throws IOException {
		Map<String, String> params = new HashMap<String, String>();
		params.put("scriptId", scriptId + "");
		Map<String, String> properties = new HashMap<String, String>();
		properties.put(this.AUTH_HEADER_PROPERTY, this.ACCES_TOCKEN_STARTER
				+ this.accessTocken);
		HttpResponse httpResponse = this.httpRequester.sendPost(
				this.controllerUrl + "/deleteScript", params, properties);
		System.out.println(httpResponse.getContent());
	}
}
