package org.bench4q.master.unitTest.factory;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.Set;

import org.bench4q.master.domain.entity.plugin.BehaviorInfo;
import org.bench4q.master.domain.entity.plugin.PluginUI;
import org.bench4q.master.domain.factory.PluginDomainFactory;
import org.bench4q.master.unitTest.testHelper.Test_PluginHelper;
import org.bench4q.share.models.master.plugin.PluginUIModel;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.model.InitializationError;
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_PluginDomainFactory extends Test_PluginHelper {
	private PluginDomainFactory pluginDomainFactory;
	private PluginUI pluginUI;

	public PluginDomainFactory getPluginDomainFactory() {
		return pluginDomainFactory;
	}

	@Autowired
	public void setPluginDomainFactory(PluginDomainFactory pluginDomainFactory) {
		this.pluginDomainFactory = pluginDomainFactory;
	}

	@Before
	public void setUp() throws InitializationError, IOException {
		pluginUI = Test_PluginHelper.createPluginUI("hbase.xml");
	}

	@After
	public void clear() {

	}

	@Test
	public void test_createPluginUIModel() throws IOException {

		PluginUIModel pluginUIModel = this.getPluginDomainFactory()
				.createPluginUIModelwithOutBehaviors(pluginUI);
		assertNotNull(pluginUIModel);
		assertNull(pluginUIModel.getBehaviorInfos());
		assertEquals(3, pluginUIModel.getPluginInfoModel().getGroupModels()
				.size());

	}

	@Test
	public void test_CreateBehaviorModels() {
		Set<BehaviorInfo> behaviorInfos = this.pluginUI.getBehaviorInfos();
		assertNotNull(behaviorInfos);
		assertTrue(behaviorInfos.size() > 0);
	}

}
