package org.bench4q.agent.test.plugin;

import java.util.HashMap;
import java.util.UUID;

import org.bench4q.agent.helper.ClassHelper;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.PluginManager;
import org.bench4q.agent.plugin.TypeConverter;
import org.bench4q.agent.plugin.basic.http.HttpPlugin;
import org.junit.Test;

import static org.junit.Assert.*;

public class Test_PluginManager {
	@Test
	public void test_getInit() {
		PluginManager pluginManager = new PluginManager(new ClassHelper(),
				new TypeConverter());
		assertEquals(9, pluginManager.getPlugins().size());
		assertTrue(pluginManager.getPlugins().containsKey("Http"));
	}

	@Test
	public void test_InitializePlugin_IN_RightWay() {
		PluginManager pluginManager = new PluginManager(new ClassHelper(),
				new TypeConverter());
		HttpPlugin httpPlugin = (HttpPlugin) pluginManager.initializePlugin(
				pluginManager.getPlugins().get("Http"),
				new HashMap<String, String>(), new HashMap<String, String>() {
					private static final long serialVersionUID = 1L;
					{
						put("testId", UUID.randomUUID().toString());
					}
				});
		assertNotNull(httpPlugin);
	}

	@Test
	public void test_InitializePlugin_Without_Constructor_Annotation() {
		PluginManager pluginManager = new PluginManager(new ClassHelper(),
				new TypeConverter());
		pluginManager.getPlugins().put("WithoutConstructorAnnotation",
				WithoutConstructorAnnotationPlugin.class);
		WithoutConstructorAnnotationPlugin plugin = (WithoutConstructorAnnotationPlugin) pluginManager
				.initializePlugin(
						pluginManager.getPlugins().get(
								"WithoutConstructorAnnotation"), null, null);
		assertNull(plugin);
	}

	@Plugin("WithoutConstructorAnnotation")
	public static class WithoutConstructorAnnotationPlugin {

	}
}
