Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-boot-admin
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-boot-admin
Commits
5b2d8f73
Commit
5b2d8f73
authored
Jul 18, 2017
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add wiremock test to client
parent
d665d083
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
103 additions
and
46 deletions
+103
-46
AdminServerWebConfigurationTest.java
.../admin/server/config/AdminServerWebConfigurationTest.java
+1
-3
pom.xml
spring-boot-admin-starter-client/pom.xml
+6
-0
ApplicationRegistrator.java
...oot/admin/client/registration/ApplicationRegistrator.java
+1
-2
ClientApplicationTest.java
...ntric/boot/admin/client/config/ClientApplicationTest.java
+0
-34
ClientServletApplicationTest.java
...oot/admin/client/config/ClientServletApplicationTest.java
+95
-0
logback-test.xml
...-admin-starter-client/src/test/resources/logback-test.xml
+0
-7
No files found.
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/config/AdminServerWebConfigurationTest.java
View file @
5b2d8f73
...
@@ -28,10 +28,8 @@ import org.junit.After;
...
@@ -28,10 +28,8 @@ import org.junit.After;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration
;
import
org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration
;
import
org.springframework.cloud.commons.util.UtilAutoConfiguration
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.cloud.commons.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.HttpMessageConverter
;
...
...
spring-boot-admin-starter-client/pom.xml
View file @
5b2d8f73
...
@@ -69,5 +69,11 @@
...
@@ -69,5 +69,11 @@
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
com.github.tomakehurst
</groupId>
<artifactId>
wiremock-standalone
</artifactId>
<version>
2.5.1
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/client/registration/ApplicationRegistrator.java
View file @
5b2d8f73
...
@@ -25,7 +25,6 @@ import org.slf4j.Logger;
...
@@ -25,7 +25,6 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
...
@@ -70,7 +69,7 @@ public class ApplicationRegistrator {
...
@@ -70,7 +69,7 @@ public class ApplicationRegistrator {
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
response
=
template
.
postForEntity
(
adminUrl
,
@SuppressWarnings
(
"rawtypes"
)
ResponseEntity
<
Map
>
response
=
template
.
postForEntity
(
adminUrl
,
new
HttpEntity
<>(
self
,
HTTP_HEADERS
),
Map
.
class
);
new
HttpEntity
<>(
self
,
HTTP_HEADERS
),
Map
.
class
);
if
(
response
.
getStatusCode
().
equals
(
HttpStatus
.
CREATED
))
{
if
(
response
.
getStatusCode
().
is2xxSuccessful
(
))
{
if
(
registeredId
.
compareAndSet
(
null
,
response
.
getBody
().
get
(
"id"
).
toString
()))
{
if
(
registeredId
.
compareAndSet
(
null
,
response
.
getBody
().
get
(
"id"
).
toString
()))
{
LOGGER
.
info
(
"Application registered itself as {}"
,
response
.
getBody
());
LOGGER
.
info
(
"Application registered itself as {}"
,
response
.
getBody
());
}
else
{
}
else
{
...
...
spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/client/config/ClientApplicationTest.java
deleted
100644 → 0
View file @
d665d083
package
de
.
codecentric
.
boot
.
admin
.
client
.
config
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
TestClientApplication
.
class
,
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
,
properties
=
{
"management.port=0"
,
"spring.boot.admin.client.url=http://example.com"
})
public
class
ClientApplicationTest
{
@Autowired
private
ClientProperties
properties
;
@Test
public
void
test_context
()
{
assertThat
(
properties
).
isNotNull
();
}
}
@Configuration
@EnableAutoConfiguration
class
TestClientApplication
{
}
spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/client/config/ClientServletApplicationTest.java
0 → 100644
View file @
5b2d8f73
/*
* Copyright 2014-2017 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
de
.
codecentric
.
boot
.
admin
.
client
.
config
;
import
wiremock.org.apache.http.HttpStatus
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringBootConfiguration
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
com.github.tomakehurst.wiremock.WireMockServer
;
import
com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder
;
import
com.github.tomakehurst.wiremock.matching.RequestPatternBuilder
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
aResponse
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
configureFor
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
equalTo
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
equalToJson
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
moreThanOrExactly
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
post
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
postRequestedFor
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
stubFor
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
urlEqualTo
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
client
.
WireMock
.
verify
;
import
static
com
.
github
.
tomakehurst
.
wiremock
.
core
.
WireMockConfiguration
.
wireMockConfig
;
public
class
ClientServletApplicationTest
{
private
ConfigurableApplicationContext
instance
;
private
WireMockServer
wiremock
;
@Before
public
void
setUp
()
throws
Exception
{
wiremock
=
new
WireMockServer
(
wireMockConfig
().
dynamicPort
());
wiremock
.
start
();
configureFor
(
wiremock
.
port
());
ResponseDefinitionBuilder
response
=
aResponse
().
withStatus
(
HttpStatus
.
SC_CREATED
)
.
withHeader
(
"Content-Type"
,
"application/json"
)
.
withHeader
(
"Location"
,
"http://localhost:"
+
wiremock
.
port
()
+
"/api/applications/abcdef"
)
.
withBody
(
"{ \"id\" : \"abcdef\" }"
);
stubFor
(
post
(
urlEqualTo
(
"/api/applications"
)).
willReturn
(
response
));
instance
=
SpringApplication
.
run
(
TestClientApplication
.
class
,
"--spring.main.web-application-type=servlet"
,
"--spring.application.name=Test-Client"
,
"--server.port=0"
,
"--management.port=0"
,
"--management.context-path=/mgmt"
,
"--spring.boot.admin.client.url=http://localhost:"
+
wiremock
.
port
());
}
@Test
public
void
test_context
()
throws
InterruptedException
{
Thread
.
sleep
(
1000L
);
String
serviceHost
=
"http://localhost:"
+
instance
.
getEnvironment
().
getProperty
(
"local.server.port"
);
String
managementHost
=
"http://localhost:"
+
instance
.
getEnvironment
().
getProperty
(
"local.management.port"
);
String
body
=
"{ \"name\" : \"Test-Client\","
+
//
" \"managementUrl\" : \""
+
managementHost
+
"/mgmt/\","
+
//
" \"healthUrl\" : \""
+
managementHost
+
"/mgmt/health/\","
+
//
" \"serviceUrl\" : \""
+
serviceHost
+
"/\", "
+
//
" \"metadata\" : {} }"
;
RequestPatternBuilder
request
=
postRequestedFor
(
urlEqualTo
(
"/api/applications"
)).
withHeader
(
"Content-Type"
,
equalTo
(
"application/json"
)).
withRequestBody
(
equalToJson
(
body
));
verify
(
moreThanOrExactly
(
1
),
request
);
}
@After
public
void
shutdown
()
{
instance
.
close
();
wiremock
.
stop
();
}
@SpringBootConfiguration
@EnableAutoConfiguration
public
static
class
TestClientApplication
{
}
}
spring-boot-admin-starter-client/src/test/resources/logback-test.xml
deleted
100644 → 0
View file @
d665d083
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include
resource=
"org/springframework/boot/logging/logback/base.xml"
/>
<root
level=
"INFO"
>
<appender-ref
ref=
"CONSOLE"
/>
</root>
</configuration>
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