Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
6f3ad2c9
Commit
6f3ad2c9
authored
Apr 15, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix UT file resource issue
parent
5ebe366e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
33 deletions
+42
-33
ConfigIntegrationTest.java
...a/com/ctrip/apollo/integration/ConfigIntegrationTest.java
+42
-33
No files found.
apollo-client/src/test/java/com/ctrip/apollo/integration/ConfigIntegrationTest.java
View file @
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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment