Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
9ed180a8
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9ed180a8
编写于
12月 16, 2008
作者:
C
Chris Beams
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
prepping .intstrument.classloading unit tests for move from .testsuite -> .context
上级
29526096
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
88 addition
and
76 deletion
+88
-76
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/InstrumentableClassLoaderTests.java
...strument/classloading/InstrumentableClassLoaderTests.java
+5
-2
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaverTests.java
...nstrument/classloading/ReflectiveLoadTimeWeaverTests.java
+20
-24
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/ResourceOverridingShadowingClassLoaderTests.java
...sloading/ResourceOverridingShadowingClassLoaderTests.java
+12
-3
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaverTests.java
.../classloading/glassfish/GlassFishLoadTimeWeaverTests.java
+21
-9
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/oc4j/OC4JClassPreprocessorAdapterTests.java
.../classloading/oc4j/OC4JClassPreprocessorAdapterTests.java
+22
-24
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/oc4j/OC4JLoadTimeWeaverTests.java
...instrument/classloading/oc4j/OC4JLoadTimeWeaverTests.java
+8
-14
未找到文件。
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/InstrumentableClassLoaderTests.java
浏览文件 @
9ed180a8
...
...
@@ -16,16 +16,19 @@
package
org.springframework.instrument.classloading
;
import
junit.framework.TestCas
e
;
import
static
org
.
junit
.
Assert
.
assertSam
e
;
import
org.junit.Test
;
import
org.springframework.util.ClassUtils
;
/**
* @author Costin Leau
* @author Juergen Hoeller
* @author Chris Beams
*/
public
class
InstrumentableClassLoaderTests
extends
TestCase
{
public
class
InstrumentableClassLoaderTests
{
@Test
public
void
testDefaultLoadTimeWeaver
()
{
ClassLoader
loader
=
new
SimpleInstrumentableClassLoader
(
ClassUtils
.
getDefaultClassLoader
());
ReflectiveLoadTimeWeaver
handler
=
new
ReflectiveLoadTimeWeaver
(
loader
);
...
...
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaverTests.java
浏览文件 @
9ed180a8
...
...
@@ -16,36 +16,33 @@
package
org.springframework.instrument.classloading
;
import
junit.framework.TestCase
;
import
org.springframework.test.AssertThrows
;
import
static
org
.
junit
.
Assert
.*;
import
java.lang.instrument.ClassFileTransformer
;
import
java.security.ProtectionDomain
;
import
org.junit.Test
;
/**
* Unit tests for the {@link ReflectiveLoadTimeWeaver} class.
*
* @author Rick Evans
* @author Chris Beams
*/
public
final
class
ReflectiveLoadTimeWeaverTests
extends
TestCase
{
public
final
class
ReflectiveLoadTimeWeaverTests
{
public
void
testCtorWithNullClassLoader
()
throws
Exception
{
new
AssertThrows
(
IllegalArgumentException
.
class
)
{
public
void
test
()
throws
Exception
{
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testCtorWithNullClassLoader
()
{
new
ReflectiveLoadTimeWeaver
(
null
);
}
}.
runTest
();
}
public
void
testCtorWithClassLoaderThatDoesNotExposeAnAddTransformerMethod
()
throws
Exception
{
new
AssertThrows
(
IllegalStateException
.
class
)
{
public
void
test
()
throws
Exception
{
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
testCtorWithClassLoaderThatDoesNotExposeAnAddTransformerMethod
()
{
new
ReflectiveLoadTimeWeaver
(
getClass
().
getClassLoader
());
}
}.
runTest
();
}
public
void
testCtorWithClassLoaderThatDoesNotExposeAGetThrowawayClassLoaderMethodIsOkay
()
throws
Exception
{
@Test
public
void
testCtorWithClassLoaderThatDoesNotExposeAGetThrowawayClassLoaderMethodIsOkay
()
{
JustAddTransformerClassLoader
classLoader
=
new
JustAddTransformerClassLoader
();
ReflectiveLoadTimeWeaver
weaver
=
new
ReflectiveLoadTimeWeaver
(
classLoader
);
weaver
.
addTransformer
(
new
ClassFileTransformer
()
{
...
...
@@ -56,21 +53,20 @@ public final class ReflectiveLoadTimeWeaverTests extends TestCase {
assertEquals
(
1
,
classLoader
.
getNumTimesGetThrowawayClassLoaderCalled
());
}
public
void
testAddTransformerWithNullTransformer
()
throws
Exception
{
new
AssertThrows
(
IllegalArgumentException
.
class
)
{
public
void
test
()
throws
Exception
{
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testAddTransformerWithNullTransformer
()
{
new
ReflectiveLoadTimeWeaver
(
new
JustAddTransformerClassLoader
()).
addTransformer
(
null
);
}
}.
runTest
();
}
public
void
testGetThrowawayClassLoaderWithClassLoaderThatDoesNotExposeAGetThrowawayClassLoaderMethodYieldsFallbackClassLoader
()
throws
Exception
{
@Test
public
void
testGetThrowawayClassLoaderWithClassLoaderThatDoesNotExposeAGetThrowawayClassLoaderMethodYieldsFallbackClassLoader
()
{
ReflectiveLoadTimeWeaver
weaver
=
new
ReflectiveLoadTimeWeaver
(
new
JustAddTransformerClassLoader
());
ClassLoader
throwawayClassLoader
=
weaver
.
getThrowawayClassLoader
();
assertNotNull
(
throwawayClassLoader
);
}
public
void
testGetThrowawayClassLoaderWithTotallyCompliantClassLoader
()
throws
Exception
{
@Test
public
void
testGetThrowawayClassLoaderWithTotallyCompliantClassLoader
()
{
TotallyCompliantClassLoader
classLoader
=
new
TotallyCompliantClassLoader
();
ReflectiveLoadTimeWeaver
weaver
=
new
ReflectiveLoadTimeWeaver
(
classLoader
);
ClassLoader
throwawayClassLoader
=
weaver
.
getThrowawayClassLoader
();
...
...
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/ResourceOverridingShadowingClassLoaderTests.java
浏览文件 @
9ed180a8
...
...
@@ -16,16 +16,19 @@
package
org.springframework.instrument.classloading
;
import
static
org
.
junit
.
Assert
.*;
import
java.io.IOException
;
import
java.util.Enumeration
;
import
junit.framework.TestCase
;
import
org.junit.Test
;
/**
* @author Rod Johnson
* @author Chris Beams
* @since 2.0
*/
public
class
ResourceOverridingShadowingClassLoaderTests
extends
TestCase
{
public
class
ResourceOverridingShadowingClassLoaderTests
{
private
static
final
String
EXISTING_RESOURCE
=
"org/springframework/instrument/classloading/testResource.xml"
;
...
...
@@ -34,41 +37,47 @@ public class ResourceOverridingShadowingClassLoaderTests extends TestCase {
private
ResourceOverridingShadowingClassLoader
overridingLoader
=
new
ResourceOverridingShadowingClassLoader
(
thisClassLoader
);
@Test
public
void
testFindsExistingResourceWithGetResourceAndNoOverrides
()
{
assertNotNull
(
thisClassLoader
.
getResource
(
EXISTING_RESOURCE
));
assertNotNull
(
overridingLoader
.
getResource
(
EXISTING_RESOURCE
));
}
@Test
public
void
testDoesNotFindExistingResourceWithGetResourceAndNullOverride
()
{
assertNotNull
(
thisClassLoader
.
getResource
(
EXISTING_RESOURCE
));
overridingLoader
.
override
(
EXISTING_RESOURCE
,
null
);
assertNull
(
overridingLoader
.
getResource
(
EXISTING_RESOURCE
));
}
@Test
public
void
testFindsExistingResourceWithGetResourceAsStreamAndNoOverrides
()
{
assertNotNull
(
thisClassLoader
.
getResourceAsStream
(
EXISTING_RESOURCE
));
assertNotNull
(
overridingLoader
.
getResourceAsStream
(
EXISTING_RESOURCE
));
}
@Test
public
void
testDoesNotFindExistingResourceWithGetResourceAsStreamAndNullOverride
()
{
assertNotNull
(
thisClassLoader
.
getResourceAsStream
(
EXISTING_RESOURCE
));
overridingLoader
.
override
(
EXISTING_RESOURCE
,
null
);
assertNull
(
overridingLoader
.
getResourceAsStream
(
EXISTING_RESOURCE
));
}
@Test
public
void
testFindsExistingResourceWithGetResourcesAndNoOverrides
()
throws
IOException
{
assertNotNull
(
thisClassLoader
.
getResources
(
EXISTING_RESOURCE
));
assertNotNull
(
overridingLoader
.
getResources
(
EXISTING_RESOURCE
));
assertEquals
(
1
,
countElements
(
overridingLoader
.
getResources
(
EXISTING_RESOURCE
)));
}
@Test
public
void
testDoesNotFindExistingResourceWithGetResourcesAndNullOverride
()
throws
IOException
{
assertNotNull
(
thisClassLoader
.
getResources
(
EXISTING_RESOURCE
));
overridingLoader
.
override
(
EXISTING_RESOURCE
,
null
);
assertEquals
(
0
,
countElements
(
overridingLoader
.
getResources
(
EXISTING_RESOURCE
)));
}
private
int
countElements
(
Enumeration
e
)
{
private
int
countElements
(
Enumeration
<?>
e
)
{
int
elts
=
0
;
while
(
e
.
hasMoreElements
())
{
e
.
nextElement
();
...
...
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaverTests.java
浏览文件 @
9ed180a8
...
...
@@ -16,6 +16,8 @@
package
org.springframework.instrument.classloading.glassfish
;
import
static
org
.
junit
.
Assert
.*;
import
java.lang.instrument.ClassFileTransformer
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
...
...
@@ -26,16 +28,20 @@ import java.util.List;
import
javax.persistence.spi.ClassTransformer
;
import
com.sun.enterprise.loader.InstrumentableClassLoader
;
import
junit.framework.TestCase
;
import
org.easymock.ArgumentsMatcher
;
import
org.easymock.MockControl
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.instrument.classloading.LoadTimeWeaver
;
public
class
GlassFishLoadTimeWeaverTests
extends
TestCase
{
import
com.sun.enterprise.loader.InstrumentableClassLoader
;
// converting away from old-style EasyMock APIs was problematic with this class
@SuppressWarnings
(
"deprecation"
)
public
class
GlassFishLoadTimeWeaverTests
{
private
MockControl
loaderCtrl
;
private
MockControl
<
InstrumentableClassLoader
>
loaderCtrl
;
private
InstrumentableClassLoader
loader
;
private
LoadTimeWeaver
ltw
;
...
...
@@ -60,9 +66,10 @@ public class GlassFishLoadTimeWeaverTests extends TestCase {
}
}
protected
void
setUp
()
throws
Exception
{
@Before
public
void
setUp
()
throws
Exception
{
loaderCtrl
=
MockControl
.
createControl
(
InstrumentableClassLoader
.
class
);
loader
=
(
InstrumentableClassLoader
)
loaderCtrl
.
getMock
();
loader
=
loaderCtrl
.
getMock
();
loaderCtrl
.
replay
();
ltw
=
new
GlassFishLoadTimeWeaver
()
{
...
...
@@ -73,11 +80,13 @@ public class GlassFishLoadTimeWeaverTests extends TestCase {
};
}
protected
void
tearDown
()
throws
Exception
{
@After
public
void
tearDown
()
throws
Exception
{
loaderCtrl
.
verify
();
ltw
=
null
;
}
@Test
public
void
testGlassFishLoadTimeWeaver
()
{
try
{
ltw
=
new
GlassFishLoadTimeWeaver
();
...
...
@@ -89,6 +98,7 @@ public class GlassFishLoadTimeWeaverTests extends TestCase {
}
@Test
public
void
testGlassFishLoadTimeWeaverClassLoader
()
{
try
{
ltw
=
new
GlassFishLoadTimeWeaver
(
null
);
...
...
@@ -115,8 +125,9 @@ public class GlassFishLoadTimeWeaverTests extends TestCase {
assertSame
(
cl4
,
ltw
.
getInstrumentableClassLoader
());
}
@Test
public
void
testAddTransformer
()
{
ClassFileTransformer
transformer
=
(
ClassFileTransformer
)
MockControl
.
createNiceControl
(
ClassFileTransformer
transformer
=
MockControl
.
createNiceControl
(
ClassFileTransformer
.
class
).
getMock
();
loaderCtrl
.
reset
();
loader
.
addTransformer
(
new
ClassTransformerAdapter
(
transformer
));
...
...
@@ -141,6 +152,7 @@ public class GlassFishLoadTimeWeaverTests extends TestCase {
ltw
.
addTransformer
(
transformer
);
}
@Test
public
void
testGetThrowawayClassLoader
()
{
loaderCtrl
.
reset
();
ClassLoader
cl
=
new
URLClassLoader
(
new
URL
[
0
]);
...
...
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/oc4j/OC4JClassPreprocessorAdapterTests.java
浏览文件 @
9ed180a8
...
...
@@ -16,50 +16,48 @@
package
org.springframework.instrument.classloading.oc4j
;
import
junit.framework.TestCase
;
import
org.easymock.AbstractMatcher
;
import
org.easymock.MockControl
;
import
org.springframework.test.AssertThrows
;
import
static
org
.
easymock
.
EasyMock
.*;
import
static
org
.
easymock
.
EasyMock
.
createMock
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
java.lang.instrument.ClassFileTransformer
;
import
java.lang.instrument.IllegalClassFormatException
;
import
java.security.ProtectionDomain
;
import
org.easymock.AbstractMatcher
;
import
org.easymock.MockControl
;
import
org.junit.Test
;
/**
* Unit tests for the {@link OC4JClassPreprocessorAdapter} class.
*
* @author Rick Evans
* @author Chris Beams
*/
public
final
class
OC4JClassPreprocessorAdapterTests
extends
TestCase
{
public
final
class
OC4JClassPreprocessorAdapterTests
{
public
void
testClassNameIsUnMangledPriorToTransformation
()
throws
Exception
{
@Test
public
void
testClassNameIsUnMangledPriorToTransformation
()
throws
IllegalClassFormatException
{
final
byte
[]
classBytes
=
"CAFEBABE"
.
getBytes
();
final
ClassLoader
classLoader
=
getClass
().
getClassLoader
();
MockControl
mockTransformer
=
MockControl
.
createControl
(
ClassFileTransformer
.
class
);
ClassFileTransformer
transformer
=
(
ClassFileTransformer
)
mockTransformer
.
getMock
();
transformer
.
transform
(
classLoader
,
"com/foo/Bar"
,
null
,
null
,
classBytes
);
mockTransformer
.
setMatcher
(
new
AbstractMatcher
()
{
public
boolean
matches
(
Object
[]
expected
,
Object
[]
actual
)
{
return
expected
[
1
].
equals
(
actual
[
1
]);
}
});
mockTransformer
.
setReturnValue
(
classBytes
);
ClassFileTransformer
transformer
=
createMock
(
ClassFileTransformer
.
class
);
mockTransformer
.
replay
();
expect
(
transformer
.
transform
(
eq
(
classLoader
),
eq
(
"com/foo/Bar"
),
(
Class
<?>)
isNull
(),
(
ProtectionDomain
)
isNull
(),
isA
(
byte
[].
class
))
).
andReturn
(
classBytes
);
replay
(
transformer
);
OC4JClassPreprocessorAdapter
processor
=
new
OC4JClassPreprocessorAdapter
(
transformer
);
byte
[]
bytes
=
processor
.
processClass
(
"com.foo.Bar"
,
classBytes
,
0
,
0
,
null
,
classLoader
);
assertNotNull
(
bytes
);
mockTransformer
.
verify
(
);
verify
(
transformer
);
}
public
void
testCtorWithNullClassFileTransformer
()
throws
Exception
{
new
AssertThrows
(
IllegalArgumentException
.
class
)
{
public
void
test
()
throws
Exception
{
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testCtorWithNullClassFileTransformer
()
{
new
OC4JClassPreprocessorAdapter
(
null
);
}
}.
runTest
();
}
}
org.springframework.testsuite/src/test/java/org/springframework/instrument/classloading/oc4j/OC4JLoadTimeWeaverTests.java
浏览文件 @
9ed180a8
...
...
@@ -16,30 +16,24 @@
package
org.springframework.instrument.classloading.oc4j
;
import
junit.framework.TestCase
;
import
org.springframework.test.AssertThrows
;
import
org.junit.Test
;
/**
* Unit tests for the {@link OC4JLoadTimeWeaver} class.
*
* @author Rick Evans
* @author Chris Beams
*/
public
final
class
OC4JLoadTimeWeaverTests
extends
TestCase
{
public
final
class
OC4JLoadTimeWeaverTests
{
public
void
testCtorWithNullClassLoader
()
throws
Exception
{
new
AssertThrows
(
IllegalArgumentException
.
class
)
{
public
void
test
()
throws
Exception
{
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testCtorWithNullClassLoader
()
{
new
OC4JLoadTimeWeaver
(
null
);
}
}.
runTest
();
}
public
void
testAddTransformerWithNullTransformer
()
throws
Exception
{
new
AssertThrows
(
IllegalArgumentException
.
class
)
{
public
void
test
()
throws
Exception
{
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testAddTransformerWithNullTransformer
()
{
new
OC4JLoadTimeWeaver
().
addTransformer
(
null
);
}
}.
runTest
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录