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
5bc9e65c
Commit
5bc9e65c
authored
Jun 22, 2017
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for server metadata
parent
d6a60405
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
29 deletions
+112
-29
AbstractDocumentationTests.java
...netflix/eureka/server/doc/AbstractDocumentationTests.java
+19
-4
AppRegistrationTests.java
...cloud/netflix/eureka/server/doc/AppRegistrationTests.java
+47
-24
EurekaServerTests.java
...rk/cloud/netflix/eureka/server/doc/EurekaServerTests.java
+45
-0
application.properties
...x-eureka-server/src/test/resources/application.properties
+1
-1
No files found.
spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/doc/AbstractDocumentationTests.java
View file @
5bc9e65c
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
cloud
.
netflix
.
eureka
.
server
.
doc
;
import
java.util.UUID
;
import
com.jayway.restassured.RestAssured
;
import
com.jayway.restassured.builder.RequestSpecBuilder
;
import
com.jayway.restassured.filter.Filter
;
...
...
@@ -53,7 +55,7 @@ import static org.springframework.restdocs.restassured.RestAssuredRestDocumentat
import
static
org
.
springframework
.
restdocs
.
restassured
.
operation
.
preprocess
.
RestAssuredPreprocessors
.
modifyUris
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
Application
.
class
,
webEnvironment
=
WebEnvironment
.
DEFINED
_PORT
,
value
=
{
@SpringBootTest
(
classes
=
Application
.
class
,
webEnvironment
=
WebEnvironment
.
RANDOM
_PORT
,
value
=
{
"spring.jmx.enabled=true"
,
"management.security.enabled=false"
})
@DirtiesContext
public
abstract
class
AbstractDocumentationTests
{
...
...
@@ -81,11 +83,20 @@ public abstract class AbstractDocumentationTests {
registry
.
initializedResponseCache
();
}
protected
void
register
(
String
name
,
String
id
)
{
registry
.
register
(
getInstance
(
name
,
id
),
false
);
protected
InstanceInfo
register
(
String
name
)
{
return
register
(
name
,
UUID
.
randomUUID
().
toString
());
}
protected
InstanceInfo
register
(
String
name
,
String
id
)
{
registry
.
register
(
instance
(
name
,
id
),
false
);
return
instance
();
}
protected
InstanceInfo
instance
(
String
name
)
{
return
instance
(
name
,
UUID
.
randomUUID
().
toString
());
}
protected
InstanceInfo
getI
nstance
(
String
name
,
String
id
)
{
protected
InstanceInfo
i
nstance
(
String
name
,
String
id
)
{
instanceConfig
.
setAppname
(
name
);
instanceConfig
.
setInstanceId
(
id
);
instanceConfig
.
setHostname
(
"foo.example.com"
);
...
...
@@ -93,6 +104,10 @@ public abstract class AbstractDocumentationTests {
return
applicationInfoManager
.
getInfo
();
}
protected
InstanceInfo
instance
()
{
return
applicationInfoManager
.
getInfo
();
}
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/AppRegistrationTests.java
View file @
5bc9e65c
...
...
@@ -18,13 +18,17 @@ package org.springframework.cloud.netflix.eureka.server.doc;
import
java.util.UUID
;
import
com.github.tomakehurst.wiremock.client.WireMock
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
delete
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
get
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
matching
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
put
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
urlPathMatching
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
hamcrest
.
CoreMatchers
.
equalTo
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
emptyIterable
;
...
...
@@ -36,7 +40,7 @@ public class AppRegistrationTests extends AbstractDocumentationTests {
@Test
public
void
startingApp
()
throws
Exception
{
register
(
"foo"
,
UUID
.
randomUUID
().
toString
()
);
register
(
"foo"
);
document
().
accept
(
"application/json"
).
when
().
get
(
"/eureka/apps"
).
then
()
.
assertThat
()
.
body
(
"applications.application"
,
hasSize
(
1
),
...
...
@@ -47,7 +51,7 @@ public class AppRegistrationTests extends AbstractDocumentationTests {
@Test
public
void
addInstance
()
throws
Exception
{
document
(
getInstance
(
"foo"
,
UUID
.
randomUUID
().
toString
()
))
document
(
instance
(
"foo"
))
.
filter
(
verify
(
"$.instance.app"
).
json
(
"$.instance.hostName"
)
.
json
(
"$.instance[?(@.status=='STARTING')]"
)
.
json
(
"$.instance.instanceId"
)
...
...
@@ -57,54 +61,73 @@ public class AppRegistrationTests extends AbstractDocumentationTests {
@Test
public
void
setStatus
()
throws
Exception
{
String
id
=
UUID
.
randomUUID
().
toString
();
register
(
"foo"
,
id
);
String
id
=
register
(
"foo"
).
getInstanceId
();
document
()
.
filter
(
verify
(
WireMock
.
put
(
WireMock
.
urlPathMatching
(
"/eureka/apps/FOO/.*"
))
.
withQueryParam
(
"value"
,
WireMock
.
matching
(
"UP"
))))
.
filter
(
verify
(
put
(
urlPathMatching
(
"/eureka/apps/FOO/.*/status"
))
.
withQueryParam
(
"value"
,
matching
(
"UP"
))))
.
when
().
put
(
"/eureka/apps/FOO/{id}/status?value={value}"
,
id
,
"UP"
).
then
()
.
assertThat
().
statusCode
(
is
(
200
));
}
@Test
public
void
allApps
()
throws
Exception
{
register
(
"foo"
,
UUID
.
randomUUID
().
toString
()
);
register
(
"foo"
);
document
().
accept
(
"application/json"
).
when
().
get
(
"/eureka/apps"
).
then
()
.
assertThat
().
body
(
"applications.application"
,
hasSize
(
1
))
.
statusCode
(
is
(
200
));
}
@Test
public
void
delta
()
throws
Exception
{
register
(
"foo"
);
document
().
accept
(
"application/json"
).
when
().
get
(
"/eureka/apps/delta"
).
then
()
.
assertThat
().
body
(
"applications.application"
,
hasSize
(
1
))
.
statusCode
(
is
(
200
));
}
@Test
public
void
oneInstance
()
throws
Exception
{
String
id
=
UUID
.
randomUUID
().
toString
();
register
(
"foo"
,
id
);
document
()
.
filter
(
verify
(
WireMock
.
get
(
WireMock
.
urlPathMatching
(
"/eureka/apps/FOO/.*"
))))
document
().
filter
(
verify
(
get
(
urlPathMatching
(
"/eureka/apps/FOO/.*"
))))
.
accept
(
"application/json"
).
when
().
get
(
"/eureka/apps/FOO/{id}"
,
id
).
then
()
.
assertThat
().
body
(
"instance.app"
,
equalTo
(
"FOO"
)).
statusCode
(
is
(
200
));
}
@Test
public
void
lookupInstance
()
throws
Exception
{
String
id
=
register
(
"foo"
).
getInstanceId
();
document
().
filter
(
verify
(
get
(
urlPathMatching
(
"/eureka/instances/.*"
))))
.
accept
(
"application/json"
).
when
().
get
(
"/eureka/instances/{id}"
,
id
)
.
then
().
assertThat
().
body
(
"instance.app"
,
equalTo
(
"FOO"
))
.
statusCode
(
is
(
200
));
}
@Test
public
void
renew
()
throws
Exception
{
String
id
=
UUID
.
randomUUID
().
toString
();
register
(
"foo"
,
id
);
document
()
.
filter
(
verify
(
WireMock
.
put
(
WireMock
.
urlPathMatching
(
"/eureka/apps/FOO/.*"
))))
String
id
=
register
(
"foo"
).
getInstanceId
();
document
().
filter
(
verify
(
put
(
urlPathMatching
(
"/eureka/apps/FOO/.*"
))))
.
accept
(
"application/json"
).
when
().
put
(
"/eureka/apps/FOO/{id}"
,
id
).
then
()
.
assertThat
().
statusCode
(
is
(
200
));
}
@Test
public
void
deleteInstance
()
throws
Exception
{
String
id
=
UUID
.
randomUUID
().
toString
();
register
(
"foo"
,
id
);
public
void
updateMetadata
()
throws
Exception
{
String
id
=
register
(
"foo"
).
getInstanceId
();
document
()
.
filter
(
verify
(
WireMock
.
delete
(
WireMock
.
urlPathMatching
(
"/eureka/apps/FOO/.*"
))))
.
when
().
delete
(
"/eureka/apps/FOO/{id}"
,
id
).
then
().
assertThat
()
.
filter
(
verify
(
put
(
urlPathMatching
(
"/eureka/apps/FOO/.*/metadata"
))
.
withQueryParam
(
"key"
,
matching
(
".*"
))))
.
accept
(
"application/json"
).
when
()
.
put
(
"/eureka/apps/FOO/{id}/metadata?key=value"
,
id
).
then
().
assertThat
()
.
statusCode
(
is
(
200
));
assertThat
(
instance
().
getMetadata
()).
containsEntry
(
"key"
,
"value"
);
}
@Test
public
void
deleteInstance
()
throws
Exception
{
String
id
=
register
(
"foo"
).
getInstanceId
();
document
().
filter
(
verify
(
delete
(
urlPathMatching
(
"/eureka/apps/FOO/.*"
)))).
when
()
.
delete
(
"/eureka/apps/FOO/{id}"
,
id
).
then
().
assertThat
()
.
statusCode
(
is
(
200
));
}
...
...
spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/doc/EurekaServerTests.java
0 → 100644
View file @
5bc9e65c
/*
* 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
java.util.UUID
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.test.context.TestPropertySource
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
// TODO: maybe this should be the default (the test fails without it because the JSON is
// invalid)
@TestPropertySource
(
properties
=
"eureka.server.minAvailableInstancesForPeerReplication=0"
)
public
class
EurekaServerTests
extends
AbstractDocumentationTests
{
@Test
public
void
serverStatus
()
throws
Exception
{
register
(
"foo"
,
UUID
.
randomUUID
().
toString
());
document
().
accept
(
"application/json"
).
when
().
get
(
"/eureka/status"
).
then
()
.
assertThat
().
body
(
"generalStats"
,
notNullValue
(),
"applicationStats"
,
notNullValue
(),
"instanceInfo"
,
notNullValue
())
.
statusCode
(
is
(
200
));
}
}
spring-cloud-netflix-eureka-server/src/test/resources/application.properties
View file @
5bc9e65c
server.port
=
${local.server.port:8761}
server.port
=
8761
spring.application.name
=
eureka
eureka.client.registerWithEureka
=
false
eureka.client.fetchRegistry
=
false
...
...
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