Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
6f3ad2c9
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6f3ad2c9
编写于
4月 15, 2016
作者:
Y
Yiming Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix UT file resource issue
上级
5ebe366e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
33 deletion
+42
-33
apollo-client/src/test/java/com/ctrip/apollo/integration/ConfigIntegrationTest.java
...a/com/ctrip/apollo/integration/ConfigIntegrationTest.java
+42
-33
未找到文件。
apollo-client/src/test/java/com/ctrip/apollo/integration/ConfigIntegrationTest.java
浏览文件 @
6f3ad2c9
package
com.ctrip.apollo.integration
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.ctrip.apollo.Config
;
import
com.ctrip.apollo.ConfigChangeListener
;
import
com.ctrip.apollo.ConfigService
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.utils.ClassLoaderUtil
;
import
com.ctrip.apollo.model.ConfigChangeEvent
;
import
org.eclipse.jetty.server.Request
;
import
org.eclipse.jetty.server.handler.AbstractHandler
;
import
org.eclipse.jetty.server.handler.ContextHandler
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
core
.
IsEqual
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
...
...
@@ -31,9 +17,23 @@ import javax.servlet.ServletException;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
static
org
.
hamcrest
.
core
.
IsEqual
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
org.eclipse.jetty.server.Request
;
import
org.eclipse.jetty.server.handler.AbstractHandler
;
import
org.eclipse.jetty.server.handler.ContextHandler
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
com.ctrip.apollo.Config
;
import
com.ctrip.apollo.ConfigChangeListener
;
import
com.ctrip.apollo.ConfigService
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.utils.ClassLoaderUtil
;
import
com.ctrip.apollo.model.ConfigChangeEvent
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
/**
* @author Jason Song(song_s@ctrip.com)
...
...
@@ -56,8 +56,8 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
@Override
@After
public
void
tearDown
()
throws
Exception
{
super
.
tearDown
();
recursiveDelete
(
configDir
);
super
.
tearDown
();
}
private
void
recursiveDelete
(
File
file
)
{
...
...
@@ -69,7 +69,12 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
recursiveDelete
(
f
);
}
}
file
.
delete
();
try
{
Files
.
deleteIfExists
(
file
.
toPath
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Test
...
...
@@ -108,8 +113,7 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
@Test
public
void
testGetConfigWithNoLocalFileAndRemoteConfigError
()
throws
Exception
{
ContextHandler
handler
=
ContextHandler
handler
=
mockConfigServerHandler
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
,
null
);
startServerWithHandlers
(
handler
);
...
...
@@ -129,13 +133,11 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
properties
.
put
(
someKey
,
someValue
);
createLocalCachePropertyFile
(
properties
);
ContextHandler
handler
=
ContextHandler
handler
=
mockConfigServerHandler
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
,
null
);
startServerWithHandlers
(
handler
);
Config
config
=
ConfigService
.
getConfig
();
assertEquals
(
someValue
,
config
.
getProperty
(
someKey
,
null
));
}
...
...
@@ -166,7 +168,7 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
assertEquals
(
1
,
changeEvent
.
getChanges
().
size
());
assertEquals
(
someValue
,
changeEvent
.
getChange
(
someKey
).
getOldValue
());
assertEquals
(
anotherValue
,
changeEvent
.
getChange
(
someKey
).
getNewValue
());
//if there is any assertion failed above, this line won't be executed
//
if there is any assertion failed above, this line won't be executed
changeEvents
.
add
(
changeEvent
);
}
});
...
...
@@ -186,7 +188,7 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
context
.
setHandler
(
new
AbstractHandler
()
{
@Override
public
void
handle
(
String
target
,
Request
baseRequest
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
,
ServletException
{
HttpServletResponse
response
)
throws
IOException
,
ServletException
{
response
.
setContentType
(
"application/json;charset=UTF-8"
);
response
.
setStatus
(
statusCode
);
...
...
@@ -210,12 +212,19 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
private
File
createLocalCachePropertyFile
(
Properties
properties
)
throws
IOException
{
File
file
=
new
File
(
configDir
,
assembleLocalCacheFileName
());
properties
.
store
(
new
FileOutputStream
(
file
),
"Persisted by ConfigIntegrationTest"
);
FileOutputStream
in
=
null
;
try
{
in
=
new
FileOutputStream
(
file
);
properties
.
store
(
in
,
"Persisted by ConfigIntegrationTest"
);
}
finally
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
return
file
;
}
private
String
assembleLocalCacheFileName
()
{
return
String
.
format
(
"%s-%s-%s.properties"
,
someAppId
,
someClusterName
,
someNamespace
);
return
String
.
format
(
"%s-%s-%s.properties"
,
someAppId
,
someClusterName
,
someNamespace
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录