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
92ae3e27
Commit
92ae3e27
authored
Apr 12, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Isolate SpringBootAplication from integration test
parent
5bb2aaf1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
AdminServiceTestConfiguration.java
.../java/com/ctrip/apollo/AdminServiceTestConfiguration.java
+9
-4
AppControllerTest.java
...rip/apollo/adminservice/controller/AppControllerTest.java
+14
-6
No files found.
apollo-adminservice/src/test/java/com/ctrip/apollo/AdminServiceTestConfiguration.java
View file @
92ae3e27
package
com
.
ctrip
.
apollo
;
package
com
.
ctrip
.
apollo
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.FilterType
;
@SpringBootApplication
(
exclude
=
{
SampleAdminServiceApplication
.
class
,
@Configuration
EurekaClientAutoConfiguration
.
class
})
@ComponentScan
(
excludeFilters
=
{
@Filter
(
type
=
FilterType
.
ASSIGNABLE_TYPE
,
value
=
{
SampleAdminServiceApplication
.
class
,
AdminServiceApplication
.
class
})})
@EnableAutoConfiguration
public
class
AdminServiceTestConfiguration
{
public
class
AdminServiceTestConfiguration
{
}
}
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/AppControllerTest.java
View file @
92ae3e27
...
@@ -4,6 +4,7 @@ import org.junit.Assert;
...
@@ -4,6 +4,7 @@ import org.junit.Assert;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.boot.test.WebIntegrationTest
;
...
@@ -20,7 +21,7 @@ import com.ctrip.apollo.core.dto.AppDTO;
...
@@ -20,7 +21,7 @@ import com.ctrip.apollo.core.dto.AppDTO;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
AdminServiceTestConfiguration
.
class
)
@SpringApplicationConfiguration
(
classes
=
AdminServiceTestConfiguration
.
class
)
@WebIntegrationTest
@WebIntegrationTest
(
randomPort
=
true
)
public
class
AppControllerTest
{
public
class
AppControllerTest
{
RestTemplate
restTemplate
=
new
TestRestTemplate
();
RestTemplate
restTemplate
=
new
TestRestTemplate
();
...
@@ -28,11 +29,18 @@ public class AppControllerTest {
...
@@ -28,11 +29,18 @@ public class AppControllerTest {
@Autowired
@Autowired
AppRepository
appRepository
;
AppRepository
appRepository
;
@Value
(
"${local.server.port}"
)
private
int
port
;
private
String
getBaseAppUrl
(){
return
"http://localhost:"
+
port
+
"/apps/"
;
}
@Test
@Test
public
void
testCreate
()
{
public
void
testCreate
()
{
AppDTO
dto
=
generateSampleDTOData
();
AppDTO
dto
=
generateSampleDTOData
();
ResponseEntity
<
AppDTO
>
response
=
ResponseEntity
<
AppDTO
>
response
=
restTemplate
.
postForEntity
(
"http://localhost:8090/apps/"
,
dto
,
AppDTO
.
class
);
restTemplate
.
postForEntity
(
getBaseAppUrl
()
,
dto
,
AppDTO
.
class
);
AppDTO
result
=
response
.
getBody
();
AppDTO
result
=
response
.
getBody
();
Assert
.
assertEquals
(
HttpStatus
.
CREATED
,
response
.
getStatusCode
());
Assert
.
assertEquals
(
HttpStatus
.
CREATED
,
response
.
getStatusCode
());
Assert
.
assertEquals
(
dto
.
getAppId
(),
result
.
getAppId
());
Assert
.
assertEquals
(
dto
.
getAppId
(),
result
.
getAppId
());
...
@@ -52,7 +60,7 @@ public class AppControllerTest {
...
@@ -52,7 +60,7 @@ public class AppControllerTest {
app
=
appRepository
.
save
(
app
);
app
=
appRepository
.
save
(
app
);
AppDTO
result
=
AppDTO
result
=
restTemplate
.
getForObject
(
"http://localhost:8090/apps/"
+
dto
.
getAppId
(),
AppDTO
.
class
);
restTemplate
.
getForObject
(
getBaseAppUrl
()
+
dto
.
getAppId
(),
AppDTO
.
class
);
Assert
.
assertEquals
(
dto
.
getAppId
(),
result
.
getAppId
());
Assert
.
assertEquals
(
dto
.
getAppId
(),
result
.
getAppId
());
Assert
.
assertEquals
(
dto
.
getName
(),
result
.
getName
());
Assert
.
assertEquals
(
dto
.
getName
(),
result
.
getName
());
...
@@ -62,7 +70,7 @@ public class AppControllerTest {
...
@@ -62,7 +70,7 @@ public class AppControllerTest {
@Test
@Test
public
void
testFindNotExist
()
{
public
void
testFindNotExist
()
{
ResponseEntity
<
AppDTO
>
result
=
ResponseEntity
<
AppDTO
>
result
=
restTemplate
.
getForEntity
(
"http://localhost:8090/apps/"
+
"notExists"
,
AppDTO
.
class
);
restTemplate
.
getForEntity
(
getBaseAppUrl
()
+
"notExists"
,
AppDTO
.
class
);
Assert
.
assertEquals
(
HttpStatus
.
NOT_FOUND
,
result
.
getStatusCode
());
Assert
.
assertEquals
(
HttpStatus
.
NOT_FOUND
,
result
.
getStatusCode
());
}
}
...
@@ -72,7 +80,7 @@ public class AppControllerTest {
...
@@ -72,7 +80,7 @@ public class AppControllerTest {
App
app
=
BeanUtils
.
transfrom
(
App
.
class
,
dto
);
App
app
=
BeanUtils
.
transfrom
(
App
.
class
,
dto
);
app
=
appRepository
.
save
(
app
);
app
=
appRepository
.
save
(
app
);
restTemplate
.
delete
(
"http://localhost:8090/apps/"
+
dto
.
getAppId
());
restTemplate
.
delete
(
getBaseAppUrl
()
+
dto
.
getAppId
());
App
deletedApp
=
appRepository
.
findOne
(
app
.
getId
());
App
deletedApp
=
appRepository
.
findOne
(
app
.
getId
());
Assert
.
assertNull
(
deletedApp
);
Assert
.
assertNull
(
deletedApp
);
...
@@ -85,7 +93,7 @@ public class AppControllerTest {
...
@@ -85,7 +93,7 @@ public class AppControllerTest {
app
=
appRepository
.
save
(
app
);
app
=
appRepository
.
save
(
app
);
dto
.
setName
(
"newName"
);
dto
.
setName
(
"newName"
);
restTemplate
.
put
(
"http://localhost:8090/apps/"
+
dto
.
getAppId
(),
dto
);
restTemplate
.
put
(
getBaseAppUrl
()
+
dto
.
getAppId
(),
dto
);
App
updatedApp
=
appRepository
.
findOne
(
app
.
getId
());
App
updatedApp
=
appRepository
.
findOne
(
app
.
getId
());
Assert
.
assertEquals
(
dto
.
getName
(),
updatedApp
.
getName
());
Assert
.
assertEquals
(
dto
.
getName
(),
updatedApp
.
getName
());
...
...
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