Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
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
spring-cloud-netflix
Commits
51a03b30
Commit
51a03b30
authored
Jun 21, 2017
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidate stub tests into one place
parent
561f3b2f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
82 deletions
+29
-82
AbstractDocumentationTests.java
...netflix/eureka/server/doc/AbstractDocumentationTests.java
+14
-0
AppRegistrationTests.java
...cloud/netflix/eureka/server/doc/AppRegistrationTests.java
+15
-2
RegisteredAppsTests.java
.../cloud/netflix/eureka/server/doc/RegisteredAppsTests.java
+0
-80
No files found.
spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/doc/AbstractDocumentationTests.java
View file @
51a03b30
...
...
@@ -20,10 +20,13 @@ import com.jayway.restassured.RestAssured;
import
com.jayway.restassured.builder.RequestSpecBuilder
;
import
com.jayway.restassured.filter.Filter
;
import
com.jayway.restassured.specification.RequestSpecification
;
import
com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl
;
import
org.junit.After
;
import
org.junit.Rule
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.context.embedded.LocalServerPort
;
...
...
@@ -38,6 +41,7 @@ import org.springframework.restdocs.restassured.RestAssuredRestDocumentation;
import
org.springframework.restdocs.restassured.RestDocumentationFilter
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
springframework
.
restdocs
.
operation
.
preprocess
.
Preprocessors
.
preprocessRequest
;
import
static
org
.
springframework
.
restdocs
.
operation
.
preprocess
.
Preprocessors
.
preprocessResponse
;
...
...
@@ -54,10 +58,20 @@ public abstract class AbstractDocumentationTests {
@LocalServerPort
private
int
port
=
0
;
@Autowired
private
PeerAwareInstanceRegistryImpl
registry
;
@Rule
public
JUnitRestDocumentation
restDocumentation
=
new
JUnitRestDocumentation
(
"target/generated-snippets"
);
@After
public
void
init
()
{
registry
.
clearRegistry
();
ReflectionTestUtils
.
setField
(
registry
,
"responseCache"
,
null
);
registry
.
initializedResponseCache
();
}
private
RestDocumentationFilter
filter
(
String
name
)
{
return
RestAssuredRestDocumentation
.
document
(
name
,
preprocessRequest
(
modifyUris
().
host
(
"eureka.example.com"
).
removePort
(),
...
...
spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/doc/
EmptyApps
Tests.java
→
spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/doc/
AppRegistration
Tests.java
View file @
51a03b30
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
cloud
.
netflix
.
eureka
.
server
.
doc
;
import
java.util.UUID
;
import
com.github.tomakehurst.wiremock.client.WireMock
;
import
com.netflix.appinfo.ApplicationInfoManager
;
...
...
@@ -26,12 +28,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
emptyIterable
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
springframework
.
cloud
.
netflix
.
eureka
.
server
.
doc
.
RequestVerifierFilter
.
verify
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
public
class
EmptyApps
Tests
extends
AbstractDocumentationTests
{
public
class
AppRegistration
Tests
extends
AbstractDocumentationTests
{
@Autowired
private
EurekaInstanceConfigBean
instanceConfig
;
...
...
@@ -41,7 +45,7 @@ public class EmptyAppsTests extends AbstractDocumentationTests {
@Test
public
void
addApp
()
throws
Exception
{
instanceConfig
.
setAppname
(
"foo"
);
instanceConfig
.
setInstanceId
(
"unique-id"
);
instanceConfig
.
setInstanceId
(
UUID
.
randomUUID
().
toString
()
);
instanceConfig
.
setHostname
(
"foo.example.com"
);
applicationInfoManager
.
initComponent
(
instanceConfig
);
assure
(
"add-app"
,
applicationInfoManager
.
getInfo
())
...
...
@@ -50,6 +54,12 @@ public class EmptyAppsTests extends AbstractDocumentationTests {
.
json
(
"$.instance.instanceId"
)
.
json
(
"$.instance.dataCenterInfo.name"
))
.
when
().
post
(
"/eureka/apps/FOO"
).
then
().
assertThat
().
statusCode
(
is
(
204
));
assure
(
"starting-app"
).
accept
(
"application/json"
).
when
().
get
(
"/eureka/apps"
)
.
then
().
assertThat
()
.
body
(
"applications.application"
,
hasSize
(
1
),
"applications.application[0].instance[0].status"
,
equalTo
(
"STARTING"
))
.
statusCode
(
is
(
200
));
assure
(
"up-app"
)
.
filter
(
verify
(
WireMock
.
put
(
WireMock
.
urlPathMatching
(
"/eureka/apps/FOO/.*"
))
...
...
@@ -58,6 +68,9 @@ public class EmptyAppsTests extends AbstractDocumentationTests {
.
put
(
"/eureka/apps/FOO/{id}/status?value={value}"
,
applicationInfoManager
.
getInfo
().
getInstanceId
(),
"UP"
)
.
then
().
assertThat
().
statusCode
(
is
(
200
));
assure
(
"one-app"
).
accept
(
"application/json"
).
when
().
get
(
"/eureka/apps"
).
then
()
.
assertThat
().
body
(
"applications.application"
,
hasSize
(
1
))
.
statusCode
(
is
(
200
));
assure
(
"delete-app"
).
when
()
.
delete
(
"/eureka/apps/FOO/{id}"
,
applicationInfoManager
.
getInfo
().
getInstanceId
())
...
...
spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/doc/RegisteredAppsTests.java
deleted
100644 → 0
View file @
561f3b2f
/*
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
cloud
.
netflix
.
eureka
.
server
.
doc
;
import
com.netflix.appinfo.ApplicationInfoManager
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.netflix.eureka.CloudEurekaClient
;
import
org.springframework.cloud.netflix.eureka.EurekaClientConfigBean
;
import
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
public
class
RegisteredAppsTests
extends
AbstractDocumentationTests
{
@Autowired
private
EurekaInstanceConfigBean
instanceConfig
;
@Autowired
private
EurekaClientConfigBean
clientConfig
;
@Autowired
private
ApplicationInfoManager
applicationInfoManager
;
@Autowired
private
ApplicationEventPublisher
publisher
;
private
static
CloudEurekaClient
client
;
@Before
public
void
setUp
()
throws
Exception
{
if
(
client
==
null
)
{
instanceConfig
.
setAppname
(
"foo"
);
instanceConfig
.
setLeaseRenewalIntervalInSeconds
(
1
);
applicationInfoManager
.
initComponent
(
instanceConfig
);
clientConfig
.
setInitialInstanceInfoReplicationIntervalSeconds
(
0
);
clientConfig
.
setRegisterWithEureka
(
true
);
client
=
new
CloudEurekaClient
(
applicationInfoManager
,
clientConfig
,
publisher
);
// Give registration a chance to work
while
(
client
.
getLastSuccessfulHeartbeatTimePeriod
()
<
0
)
{
Thread
.
sleep
(
100L
);
}
}
}
@AfterClass
public
static
void
cleanUp
()
{
if
(
client
!=
null
)
{
client
.
shutdown
();
}
}
@Test
public
void
registeredApps
()
throws
Exception
{
assure
().
accept
(
"application/json"
).
when
().
get
(
"/eureka/apps"
).
then
().
assertThat
()
.
body
(
"applications.application"
,
hasSize
(
1
)).
statusCode
(
is
(
200
));
}
}
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