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;
import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
import org.junit.Before;
import org.junit.Test;

public class Test_MonitorController extends TestBase {
	@Before
	public void prepare() {
		this.setAccessTocken(this.login());
	}

	@Test
	public void testMemoryInfo() throws IOException, JAXBException {
		Map<String, String> params = new HashMap<String, String>();
		params.put("testPlanRunId", "90293f23-581a-40a2-93e3-f47035c06242");
		params.put("hostName", "127.0.0.1");
		params.put("port", "5556");
		params.put("duationBegin", "0");
		HttpResponse httpResponse = this.httpRequester.sendGet(BASE_URL
				+ "/monitorController/memorySUTInfo", params,
				makeAccessTockenMap(this.getAccessTocken()));
		System.out.println(httpResponse.getContent());
		if (HttpRequester.isInvalidResponse(httpResponse)) {
			fail("not valid response!");
		}
		MonitorMemoryResponseModel memoryResponseModel = (MonitorMemoryResponseModel) MarshalHelper
				.unmarshal(MonitorMemoryResponseModel.class,
						httpResponse.getContent());
		assertEquals(3, memoryResponseModel.getMemoryModels().size());
	}
}
