mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-22 19:27:13 +10:00
[강운덕] [PROFILER-17] loader를 통해 test를 간접실행하도록 수정.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@3683 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.nhn.pinpoint.profiler.modifier.orm.ibatis;
|
||||
|
||||
import com.nhn.pinpoint.bootstrap.ContextClassLoaderExecuteTemplate;
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.profiler.DefaultAgent;
|
||||
import com.nhn.pinpoint.profiler.DummyInstrumentation;
|
||||
import com.nhn.pinpoint.profiler.logging.Slf4jLoggerBinder;
|
||||
import com.nhn.pinpoint.profiler.util.MockAgent;
|
||||
import com.nhn.pinpoint.profiler.util.TestClassLoader;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class SqlClientImplTest {
|
||||
|
||||
private static TestClassLoader LOADER;
|
||||
private static ContextClassLoaderExecuteTemplate TEMPLATE;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.setProperty("catalina.home", "test");
|
||||
PLoggerFactory.initialize(new Slf4jLoggerBinder());
|
||||
|
||||
ProfilerConfig profilerConfig = new ProfilerConfig();
|
||||
|
||||
String path = ProfilerConfig.class.getClassLoader().getResource("pinpoint.config").getPath();
|
||||
profilerConfig.readConfigFile(path);
|
||||
|
||||
profilerConfig.setApplicationServerType(ServiceType.STAND_ALONE);
|
||||
DefaultAgent agent = new MockAgent("", new DummyInstrumentation(), profilerConfig);
|
||||
LOADER = new TestClassLoader(agent);
|
||||
|
||||
TEMPLATE = new ContextClassLoaderExecuteTemplate<Callable>(LOADER);
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModify() throws Throwable {
|
||||
|
||||
TEMPLATE.execute(new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
try {
|
||||
LOADER.runTest("com.nhn.pinpoint.profiler.modifier.orm.ibatis.SqlMapClientImplModifierTest", "testModify");
|
||||
} catch (Throwable th) {
|
||||
throw new RuntimeException(th.getMessage(), th);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
+8
-32
@@ -4,26 +4,14 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ibatis.common.resources.Resources;
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
|
||||
import com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate;
|
||||
import com.nhn.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.nhn.pinpoint.common.ServiceType;
|
||||
import com.nhn.pinpoint.profiler.DefaultAgent;
|
||||
import com.nhn.pinpoint.profiler.DummyInstrumentation;
|
||||
import com.nhn.pinpoint.profiler.logging.Slf4jLoggerBinder;
|
||||
import com.nhn.pinpoint.profiler.util.MockAgent;
|
||||
import com.nhn.pinpoint.profiler.util.TestClassLoader;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -33,35 +21,23 @@ public class SqlMapClientImplModifierTest {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(SqlMapClientImplModifierTest.class);
|
||||
|
||||
private static TestClassLoader loader;
|
||||
|
||||
@Mock
|
||||
private SqlMapExecutorDelegate mockSqlMapExecutorDelegate;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.setProperty("catalina.home", "test");
|
||||
PLoggerFactory.initialize(new Slf4jLoggerBinder());
|
||||
|
||||
ProfilerConfig profilerConfig = new ProfilerConfig();
|
||||
|
||||
String path = ProfilerConfig.class.getClassLoader().getResource("pinpoint.config").getPath();
|
||||
profilerConfig.readConfigFile(path);
|
||||
|
||||
profilerConfig.setApplicationServerType(ServiceType.STAND_ALONE);
|
||||
DefaultAgent agent = new MockAgent("", new DummyInstrumentation(), profilerConfig);
|
||||
loader = new TestClassLoader(agent);
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModify() throws Exception {
|
||||
final String className = SqlMapClientImplModifier.TARGET_CLASS_NAME.replace('/', '.');
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<SqlMapClientImpl> sqlMapClientClazz = (Class<SqlMapClientImpl>)loader.loadClass(className);
|
||||
|
||||
Constructor<?>[] constructors = sqlMapClientClazz.getConstructors();
|
||||
SqlMapClient sqlMapClient = (SqlMapClient)constructors[0].newInstance(mockSqlMapExecutorDelegate);
|
||||
|
||||
// Class<SqlMapClientImpl> sqlMapClientClazz = (Class<SqlMapClientImpl>)loader.loadClass(className);
|
||||
// Class<SqlMapClientImpl> sqlMapClientClazz = (Class<SqlMapClientImpl>)loader.loadClass(className);
|
||||
//
|
||||
// Constructor<?>[] constructors = sqlMapClientClazz.getConstructors();
|
||||
// SqlMapClient sqlMapClient = (SqlMapClient)constructors[0].newInstance(mockSqlMapExecutorDelegate);
|
||||
|
||||
SqlMapClient sqlMapClient = new SqlMapClientImpl(mockSqlMapExecutorDelegate);
|
||||
// SqlMapClient sqlMapClient = sqlMapClientClazz.getDeclaredConstructor(SqlMapExecutorDelegate.class).newInstance(mockSqlMapExecutorDelegate);
|
||||
sqlMapClient.queryForList("abc");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user