package org.bench4q.master.integrated;

import static org.junit.Assert.assertTrue;

import org.bench4q.master.domain.entity.Monitor;
import org.bench4q.master.domain.valueobject.datastatistics.TestMonitorSampler;
import org.bench4q.share.models.monitor.MonitorMain;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:service-test-context.xml" })
public class Test_TestMonitorSampler {

	private TestMonitorSampler testMonitorSampler;
	private Monitor monitor;

	public TestMonitorSampler getTestMonitorSampler() {
		return testMonitorSampler;
	}

	@Autowired
	public void setTestMonitorSampler(TestMonitorSampler testMonitorSampler) {
		this.testMonitorSampler = testMonitorSampler;
	}

	@Before
	public void setUp() {
		this.monitor = new Monitor();
		monitor.setHostName("127.0.0.1");
		monitor.setPort(5556);
	}

	@Test
	public void testDoSaveResult() {
		assertTrue(this.monitor.getHostName().equals("127.0.0.1"));
		assertTrue(this.monitor.getPort() == 5556);
		MonitorMain monitorMain = this.testMonitorSampler.getMonitorResult(
				monitor.getHostName(), monitor.getPort());
		Assert.assertNotNull(monitorMain);
	}

	@After
	public void clean() {
	}

}
