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
865d8edc
Commit
865d8edc
authored
May 02, 2017
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix deprecation warnings
parent
4b0b99d1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
315 additions
and
332 deletions
+315
-332
TurbineAutoConfigurationTest.java
...ot/admin/turbine/config/TurbineAutoConfigurationTest.java
+46
-46
TurbineRouteLocatorTest.java
...t/admin/turbine/zuul/filters/TurbineRouteLocatorTest.java
+47
-50
DiscoveryClientConfiguration.java
...ntric/boot/admin/config/DiscoveryClientConfiguration.java
+36
-39
AdminServerWebConfigurationTest.java
...ic/boot/admin/config/AdminServerWebConfigurationTest.java
+103
-112
DiscoveryClientConfigurationTest.java
...c/boot/admin/config/DiscoveryClientConfigurationTest.java
+83
-85
No files found.
spring-boot-admin-server-ui-turbine/src/test/java/spring/boot/admin/turbine/config/TurbineAutoConfigurationTest.java
View file @
865d8edc
package
spring
.
boot
.
admin
.
turbine
.
config
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
empty
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
de.codecentric.boot.admin.config.AdminServerCoreConfiguration
;
import
de.codecentric.boot.admin.config.AdminServerWebConfiguration
;
import
de.codecentric.boot.admin.config.RevereseZuulProxyConfiguration
;
import
spring.boot.admin.turbine.web.TurbineController
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.
context.
PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.RestTemplateConfiguration
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.cloud.client.discovery.
noop.Noop
DiscoveryClientAutoConfiguration
;
import
org.springframework.cloud.client.discovery.
simple.Simple
DiscoveryClientAutoConfiguration
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
de.codecentric.boot.admin.config.AdminServerCoreConfiguration
;
import
de.codecentric.boot.admin.config.AdminServerWebConfiguration
;
import
de.codecentric.boot.admin.config.RevereseZuulProxyConfiguration
;
import
spring.boot.admin.turbine.web.TurbineController
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
Matchers
.
empty
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TurbineAutoConfigurationTest
{
private
AnnotationConfigWebApplicationContext
context
;
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
test_disabled
()
{
load
(
"spring.boot.admin.turbine.enabled:false"
,
"spring.boot.admin.turbine.url:http://turbine.server:8989/turbine.stream"
);
assertThat
(
context
.
getBeansOfType
(
TurbineController
.
class
).
values
(),
empty
());
}
@Test
public
void
test_enabled
()
{
load
(
"spring.boot.admin.turbine.url:http://turbine.server:8989/turbine.stream"
);
assertThat
(
context
.
getBean
(
TurbineController
.
class
),
instanceOf
(
TurbineController
.
class
));
}
private
void
load
(
String
...
environment
)
{
AnnotationConfigWebApplicationContext
applicationContext
=
new
AnnotationConfigWebApplicationContext
();
applicationContext
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
Noop
DiscoveryClientAutoConfiguration
.
class
);
applicationContext
.
register
(
AdminServerCoreConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
applicationContext
.
register
(
RevereseZuulProxyConfiguration
.
class
);
applicationContext
.
register
(
TurbineAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
applicationContext
,
environment
);
applicationContext
.
refresh
();
this
.
context
=
applicationContext
;
}
private
AnnotationConfigWebApplicationContext
context
;
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
test_disabled
()
{
load
(
"spring.boot.admin.turbine.enabled:false"
,
"spring.boot.admin.turbine.url:http://turbine.server:8989/turbine.stream"
);
assertThat
(
context
.
getBeansOfType
(
TurbineController
.
class
).
values
(),
empty
());
}
@Test
public
void
test_enabled
()
{
load
(
"spring.boot.admin.turbine.url:http://turbine.server:8989/turbine.stream"
);
assertThat
(
context
.
getBean
(
TurbineController
.
class
),
instanceOf
(
TurbineController
.
class
));
}
private
void
load
(
String
...
environment
)
{
AnnotationConfigWebApplicationContext
applicationContext
=
new
AnnotationConfigWebApplicationContext
();
applicationContext
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
Simple
DiscoveryClientAutoConfiguration
.
class
);
applicationContext
.
register
(
AdminServerCoreConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
applicationContext
.
register
(
RevereseZuulProxyConfiguration
.
class
);
applicationContext
.
register
(
TurbineAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
applicationContext
,
environment
);
applicationContext
.
refresh
();
this
.
context
=
applicationContext
;
}
}
spring-boot-admin-server-ui-turbine/src/test/java/spring/boot/admin/turbine/zuul/filters/TurbineRouteLocatorTest.java
View file @
865d8edc
package
spring
.
boot
.
admin
.
turbine
.
zuul
.
filters
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.util.Arrays
;
import
org.junit.Test
;
import
org.springframework.cloud.client.DefaultServiceInstance
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.client.discovery.noop.NoopDiscoveryClient
;
import
org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClient
;
import
org.springframework.cloud.client.discovery.simple.SimpleDiscoveryProperties
;
import
org.springframework.cloud.netflix.zuul.filters.Route
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute
;
public
class
TurbineRouteLocatorTest
{
@Test
public
void
test_route_http_location
()
{
ZuulRoute
route
=
new
ZuulRoute
(
"/path/**"
,
"http://example.com/target"
);
TurbineRouteLocator
locator
=
new
TurbineRouteLocator
(
route
,
""
,
new
ZuulProperties
(),
null
);
assertThat
(
locator
.
getRoutes
().
size
(),
is
(
1
)
);
assertThat
(
locator
.
getRoutes
().
get
(
0
).
getPath
(),
is
(
"/**"
));
assertThat
(
locator
.
getRoutes
().
get
(
0
).
getPrefix
(),
is
(
"/path"
));
assertThat
(
locator
.
getRoutes
().
get
(
0
).
getLocation
(),
is
(
"http://example.com/target"
));
Route
matchingRoute
=
locator
.
getMatchingRoute
(
"/path/foo"
);
assertThat
(
matchingRoute
.
getLocation
(),
is
(
"http://example.com/target"
));
assertThat
(
matchingRoute
.
getPath
(),
is
(
"/foo/turbine.stream"
));
assertThat
(
locator
.
getMatchingRoute
(
"/404/foo"
),
nullValue
());
}
@Test
public
void
test_route_service_location
()
{
ZuulRoute
route
=
new
ZuulRoute
(
"/path/**"
,
"turbine"
);
DiscoveryClient
discovery
=
mock
(
DiscoveryClient
.
class
);
when
(
discovery
.
getInstances
(
"turbine"
)).
thenReturn
(
Arrays
.<
ServiceInstance
>
asList
(
new
DefaultServiceInstance
(
"turbine"
,
"example.com"
,
80
,
false
)));
TurbineRouteLocator
locator
=
new
TurbineRouteLocator
(
route
,
""
,
new
ZuulProperties
(),
discovery
);
Route
matchingRoute
=
locator
.
getMatchingRoute
(
"/path/foo"
);
assertThat
(
matchingRoute
.
getLocation
(),
is
(
"http://example.com:80"
));
assertThat
(
matchingRoute
.
getPath
(),
is
(
"/foo/turbine.stream"
));
}
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
test_route_noservice
()
{
ZuulRoute
route
=
new
ZuulRoute
(
"/path/**"
,
"turbine"
);
DiscoveryClient
discovery
=
new
NoopDiscoveryClient
(
null
);
TurbineRouteLocator
locator
=
new
TurbineRouteLocator
(
route
,
""
,
new
ZuulProperties
(),
discovery
);
public
class
TurbineRouteLocatorTest
{
locator
.
getMatchingRoute
(
"/path/foo"
);
}
@Test
public
void
test_route_http_location
()
{
ZuulRoute
route
=
new
ZuulRoute
(
"/path/**"
,
"http://example.com/target"
);
TurbineRouteLocator
locator
=
new
TurbineRouteLocator
(
route
,
""
,
new
ZuulProperties
(),
null
);
assertThat
(
locator
.
getRoutes
().
size
(),
is
(
1
));
assertThat
(
locator
.
getRoutes
().
get
(
0
).
getPath
(),
is
(
"/**"
));
assertThat
(
locator
.
getRoutes
().
get
(
0
).
getPrefix
(),
is
(
"/path"
));
assertThat
(
locator
.
getRoutes
().
get
(
0
).
getLocation
(),
is
(
"http://example.com/target"
));
Route
matchingRoute
=
locator
.
getMatchingRoute
(
"/path/foo"
);
assertThat
(
matchingRoute
.
getLocation
(),
is
(
"http://example.com/target"
));
assertThat
(
matchingRoute
.
getPath
(),
is
(
"/foo/turbine.stream"
));
assertThat
(
locator
.
getMatchingRoute
(
"/404/foo"
),
nullValue
());
}
@Test
public
void
test_route_service_location
()
{
ZuulRoute
route
=
new
ZuulRoute
(
"/path/**"
,
"turbine"
);
DiscoveryClient
discovery
=
mock
(
DiscoveryClient
.
class
);
when
(
discovery
.
getInstances
(
"turbine"
)).
thenReturn
(
Arrays
.<
ServiceInstance
>
asList
(
new
DefaultServiceInstance
(
"turbine"
,
"example.com"
,
80
,
false
)));
TurbineRouteLocator
locator
=
new
TurbineRouteLocator
(
route
,
""
,
new
ZuulProperties
(),
discovery
);
Route
matchingRoute
=
locator
.
getMatchingRoute
(
"/path/foo"
);
assertThat
(
matchingRoute
.
getLocation
(),
is
(
"http://example.com:80"
));
assertThat
(
matchingRoute
.
getPath
(),
is
(
"/foo/turbine.stream"
));
}
@Test
(
expected
=
IllegalStateException
.
class
)
public
void
test_route_noservice
()
{
ZuulRoute
route
=
new
ZuulRoute
(
"/path/**"
,
"turbine"
);
DiscoveryClient
discovery
=
new
SimpleDiscoveryClient
(
new
SimpleDiscoveryProperties
());
TurbineRouteLocator
locator
=
new
TurbineRouteLocator
(
route
,
""
,
new
ZuulProperties
(),
discovery
);
locator
.
getMatchingRoute
(
"/path/foo"
);
}
}
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/DiscoveryClientConfiguration.java
View file @
865d8edc
...
...
@@ -15,6 +15,12 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
config
;
import
de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener
;
import
de.codecentric.boot.admin.discovery.DefaultServiceInstanceConverter
;
import
de.codecentric.boot.admin.discovery.EurekaServiceInstanceConverter
;
import
de.codecentric.boot.admin.discovery.ServiceInstanceConverter
;
import
de.codecentric.boot.admin.registry.ApplicationRegistry
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
...
...
@@ -23,56 +29,47 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.client.discovery.
noop.Noop
DiscoveryClientAutoConfiguration
;
import
org.springframework.cloud.client.discovery.
simple.Simple
DiscoveryClientAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
com.netflix.discovery.EurekaClient
;
import
de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener
;
import
de.codecentric.boot.admin.discovery.DefaultServiceInstanceConverter
;
import
de.codecentric.boot.admin.discovery.EurekaServiceInstanceConverter
;
import
de.codecentric.boot.admin.discovery.ServiceInstanceConverter
;
import
de.codecentric.boot.admin.registry.ApplicationRegistry
;
@Configuration
@ConditionalOnSingleCandidate
(
DiscoveryClient
.
class
)
@ConditionalOnProperty
(
prefix
=
"spring.boot.admin.discovery"
,
name
=
"enabled"
,
matchIfMissing
=
true
)
@AutoConfigureAfter
({
NoopDiscoveryClientAutoConfiguration
.
class
})
@AutoConfigureAfter
({
SimpleDiscoveryClientAutoConfiguration
.
class
})
public
class
DiscoveryClientConfiguration
{
@Autowired
private
DiscoveryClient
discoveryClient
;
@Autowired
private
DiscoveryClient
discoveryClient
;
@Autowired
private
ApplicationRegistry
registry
;
@Autowired
private
ApplicationRegistry
registry
;
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties
(
prefix
=
"spring.boot.admin.discovery"
)
public
ApplicationDiscoveryListener
applicationDiscoveryListener
(
ServiceInstanceConverter
serviceInstanceConverter
)
{
ApplicationDiscoveryListener
listener
=
new
ApplicationDiscoveryListener
(
discoveryClient
,
registry
);
listener
.
setConverter
(
serviceInstanceConverter
);
return
listener
;
}
@Bean
@ConditionalOnMissingBean
@ConfigurationProperties
(
prefix
=
"spring.boot.admin.discovery"
)
public
ApplicationDiscoveryListener
applicationDiscoveryListener
(
ServiceInstanceConverter
serviceInstanceConverter
)
{
ApplicationDiscoveryListener
listener
=
new
ApplicationDiscoveryListener
(
discoveryClient
,
registry
);
listener
.
setConverter
(
serviceInstanceConverter
);
return
listener
;
}
@Configuration
@ConditionalOnBean
(
EurekaClient
.
class
)
public
static
class
EurekaConverterConfiguration
{
@Bean
@ConditionalOnMissingBean
({
ServiceInstanceConverter
.
class
})
@ConfigurationProperties
(
prefix
=
"spring.boot.admin.discovery.converter"
)
public
EurekaServiceInstanceConverter
serviceInstanceConverter
()
{
return
new
EurekaServiceInstanceConverter
();
}
}
@Configuration
@ConditionalOnBean
(
EurekaClient
.
class
)
public
static
class
EurekaConverterConfiguration
{
@Bean
@ConditionalOnMissingBean
({
ServiceInstanceConverter
.
class
})
@ConfigurationProperties
(
prefix
=
"spring.boot.admin.discovery.converter"
)
public
EurekaServiceInstanceConverter
serviceInstanceConverter
()
{
return
new
EurekaServiceInstanceConverter
();
}
}
@Bean
@ConditionalOnMissingBean
({
ServiceInstanceConverter
.
class
})
@ConfigurationProperties
(
prefix
=
"spring.boot.admin.discovery.converter"
)
public
DefaultServiceInstanceConverter
serviceInstanceConverter
()
{
return
new
DefaultServiceInstanceConverter
();
}
@Bean
@ConditionalOnMissingBean
({
ServiceInstanceConverter
.
class
})
@ConfigurationProperties
(
prefix
=
"spring.boot.admin.discovery.converter"
)
public
DefaultServiceInstanceConverter
serviceInstanceConverter
()
{
return
new
DefaultServiceInstanceConverter
();
}
}
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/config/AdminServerWebConfigurationTest.java
View file @
865d8edc
...
...
@@ -15,135 +15,126 @@
*/
package
de
.
codecentric
.
boot
.
admin
.
config
;
import
static
org
.
hamcrest
.
CoreMatchers
.
hasItem
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
isA
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener
;
import
de.codecentric.boot.admin.journal.store.HazelcastJournaledEventStore
;
import
de.codecentric.boot.admin.journal.store.JournaledEventStore
;
import
de.codecentric.boot.admin.journal.store.SimpleJournaledEventStore
;
import
de.codecentric.boot.admin.notify.MailNotifier
;
import
de.codecentric.boot.admin.registry.store.ApplicationStore
;
import
de.codecentric.boot.admin.registry.store.HazelcastApplicationStore
;
import
de.codecentric.boot.admin.registry.store.SimpleApplicationStore
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.
context.
PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.RestTemplateConfiguration
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.cloud.client.discovery.
noop.Noop
DiscoveryClientAutoConfiguration
;
import
org.springframework.cloud.client.discovery.
simple.Simple
DiscoveryClientAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
com.hazelcast.config.Config
;
import
de.codecentric.boot.admin.discovery.ApplicationDiscoveryListener
;
import
de.codecentric.boot.admin.journal.store.HazelcastJournaledEventStore
;
import
de.codecentric.boot.admin.journal.store.JournaledEventStore
;
import
de.codecentric.boot.admin.journal.store.SimpleJournaledEventStore
;
import
de.codecentric.boot.admin.notify.MailNotifier
;
import
de.codecentric.boot.admin.registry.store.ApplicationStore
;
import
de.codecentric.boot.admin.registry.store.HazelcastApplicationStore
;
import
de.codecentric.boot.admin.registry.store.SimpleApplicationStore
;
import
static
org
.
hamcrest
.
CoreMatchers
.
hasItem
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
isA
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
AdminServerWebConfigurationTest
{
private
AnnotationConfigWebApplicationContext
context
;
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
jacksonMapperPresentFromDefault
()
{
AdminServerWebConfiguration
config
=
new
AdminServerWebConfiguration
(
null
,
null
,
null
,
null
);
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<>();
converters
.
add
(
new
MappingJackson2HttpMessageConverter
());
config
.
extendMessageConverters
(
converters
);
assertThat
(
converters
,
hasItem
(
isA
(
MappingJackson2HttpMessageConverter
.
class
)));
assertThat
(
converters
.
size
(),
is
(
1
));
}
@Test
public
void
jacksonMapperPresentNeedExtend
()
{
AdminServerWebConfiguration
config
=
new
AdminServerWebConfiguration
(
null
,
null
,
null
,
null
);
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<>();
config
.
extendMessageConverters
(
converters
);
assertThat
(
converters
,
hasItem
(
isA
(
MappingJackson2HttpMessageConverter
.
class
)));
assertThat
(
converters
.
size
(),
is
(
1
));
}
@Test
public
void
simpleConfig
()
{
load
();
assertThat
(
context
.
getBean
(
ApplicationStore
.
class
),
is
(
instanceOf
(
SimpleApplicationStore
.
class
)));
assertTrue
(
context
.
getBeansOfType
(
ApplicationDiscoveryListener
.
class
).
isEmpty
());
assertTrue
(
context
.
getBeansOfType
(
MailNotifier
.
class
).
isEmpty
());
assertThat
(
context
.
getBean
(
JournaledEventStore
.
class
),
is
(
instanceOf
(
SimpleJournaledEventStore
.
class
)));
}
@Test
public
void
hazelcastConfig
()
{
load
(
TestHazelcastConfig
.
class
);
assertThat
(
context
.
getBean
(
ApplicationStore
.
class
),
is
(
instanceOf
(
HazelcastApplicationStore
.
class
)));
assertThat
(
context
.
getBean
(
JournaledEventStore
.
class
),
is
(
instanceOf
(
HazelcastJournaledEventStore
.
class
)));
assertTrue
(
context
.
getBeansOfType
(
ApplicationDiscoveryListener
.
class
).
isEmpty
());
}
@Test
public
void
discoveryConfig
()
{
load
(
NoopDiscoveryClientAutoConfiguration
.
class
);
assertThat
(
context
.
getBean
(
ApplicationStore
.
class
),
is
(
instanceOf
(
SimpleApplicationStore
.
class
)));
context
.
getBean
(
ApplicationDiscoveryListener
.
class
);
}
@Configuration
static
class
TestHazelcastConfig
{
@Bean
public
Config
config
()
{
return
new
Config
();
}
}
private
void
load
(
String
...
environment
)
{
load
(
null
,
environment
);
}
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
AnnotationConfigWebApplicationContext
applicationContext
=
new
AnnotationConfigWebApplicationContext
();
if
(
config
!=
null
)
{
applicationContext
.
register
(
config
);
}
applicationContext
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
HazelcastAutoConfiguration
.
class
);
applicationContext
.
register
(
HazelcastStoreConfiguration
.
class
);
applicationContext
.
register
(
DiscoveryClientConfiguration
.
class
);
applicationContext
.
register
(
AdminServerCoreConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
applicationContext
,
environment
);
applicationContext
.
refresh
();
this
.
context
=
applicationContext
;
}
private
AnnotationConfigWebApplicationContext
context
;
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
jacksonMapperPresentFromDefault
()
{
AdminServerWebConfiguration
config
=
new
AdminServerWebConfiguration
(
null
,
null
,
null
,
null
);
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<>();
converters
.
add
(
new
MappingJackson2HttpMessageConverter
());
config
.
extendMessageConverters
(
converters
);
assertThat
(
converters
,
hasItem
(
isA
(
MappingJackson2HttpMessageConverter
.
class
)));
assertThat
(
converters
.
size
(),
is
(
1
));
}
@Test
public
void
jacksonMapperPresentNeedExtend
()
{
AdminServerWebConfiguration
config
=
new
AdminServerWebConfiguration
(
null
,
null
,
null
,
null
);
List
<
HttpMessageConverter
<?>>
converters
=
new
ArrayList
<>();
config
.
extendMessageConverters
(
converters
);
assertThat
(
converters
,
hasItem
(
isA
(
MappingJackson2HttpMessageConverter
.
class
)));
assertThat
(
converters
.
size
(),
is
(
1
));
}
@Test
public
void
simpleConfig
()
{
load
();
assertThat
(
context
.
getBean
(
ApplicationStore
.
class
),
is
(
instanceOf
(
SimpleApplicationStore
.
class
)));
assertTrue
(
context
.
getBeansOfType
(
ApplicationDiscoveryListener
.
class
).
isEmpty
());
assertTrue
(
context
.
getBeansOfType
(
MailNotifier
.
class
).
isEmpty
());
assertThat
(
context
.
getBean
(
JournaledEventStore
.
class
),
is
(
instanceOf
(
SimpleJournaledEventStore
.
class
)));
}
@Test
public
void
hazelcastConfig
()
{
load
(
TestHazelcastConfig
.
class
);
assertThat
(
context
.
getBean
(
ApplicationStore
.
class
),
is
(
instanceOf
(
HazelcastApplicationStore
.
class
)));
assertThat
(
context
.
getBean
(
JournaledEventStore
.
class
),
is
(
instanceOf
(
HazelcastJournaledEventStore
.
class
)));
assertTrue
(
context
.
getBeansOfType
(
ApplicationDiscoveryListener
.
class
).
isEmpty
());
}
@Test
public
void
discoveryConfig
()
{
load
(
SimpleDiscoveryClientAutoConfiguration
.
class
);
assertThat
(
context
.
getBean
(
ApplicationStore
.
class
),
is
(
instanceOf
(
SimpleApplicationStore
.
class
)));
context
.
getBean
(
ApplicationDiscoveryListener
.
class
);
}
@Configuration
static
class
TestHazelcastConfig
{
@Bean
public
Config
config
()
{
return
new
Config
();
}
}
private
void
load
(
String
...
environment
)
{
load
(
null
,
environment
);
}
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
AnnotationConfigWebApplicationContext
applicationContext
=
new
AnnotationConfigWebApplicationContext
();
if
(
config
!=
null
)
{
applicationContext
.
register
(
config
);
}
applicationContext
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
HazelcastAutoConfiguration
.
class
);
applicationContext
.
register
(
HazelcastStoreConfiguration
.
class
);
applicationContext
.
register
(
DiscoveryClientConfiguration
.
class
);
applicationContext
.
register
(
AdminServerCoreConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
applicationContext
,
environment
);
applicationContext
.
refresh
();
this
.
context
=
applicationContext
;
}
}
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/config/DiscoveryClientConfigurationTest.java
View file @
865d8edc
package
de
.
codecentric
.
boot
.
admin
.
config
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
de.codecentric.boot.admin.discovery.DefaultServiceInstanceConverter
;
import
de.codecentric.boot.admin.discovery.EurekaServiceInstanceConverter
;
import
de.codecentric.boot.admin.discovery.ServiceInstanceConverter
;
import
de.codecentric.boot.admin.model.Application
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.
context.
PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration.RestTemplateConfiguration
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.client.discovery.
noop.Noop
DiscoveryClientAutoConfiguration
;
import
org.springframework.cloud.client.discovery.
simple.Simple
DiscoveryClientAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
com.netflix.discovery.EurekaClient
;
import
de.codecentric.boot.admin.discovery.DefaultServiceInstanceConverter
;
import
de.codecentric.boot.admin.discovery.EurekaServiceInstanceConverter
;
import
de.codecentric.boot.admin.discovery.ServiceInstanceConverter
;
import
de.codecentric.boot.admin.model.Application
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
DiscoveryClientConfigurationTest
{
private
AnnotationConfigWebApplicationContext
context
;
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
defaultServiceInstanceConverter
()
{
load
(
NoopDiscoveryClientAutoConfiguration
.
class
);
assertThat
(
context
.
getBean
(
ServiceInstanceConverter
.
class
),
is
(
instanceOf
(
DefaultServiceInstanceConverter
.
class
)));
}
@Test
public
void
eurekaServiceInstanceConverter
()
{
load
(
EurekaClientConfig
.
class
);
assertThat
(
context
.
getBean
(
ServiceInstanceConverter
.
class
),
is
(
instanceOf
(
EurekaServiceInstanceConverter
.
class
)));
}
@Test
public
void
customServiceInstanceConverter
()
{
load
(
NoopDiscoveryClientAutoConfiguration
.
class
,
TestCustomServiceInstanceConverterConfig
.
class
);
assertThat
(
context
.
getBean
(
ServiceInstanceConverter
.
class
),
is
(
instanceOf
(
CustomServiceInstanceConverter
.
class
)));
}
@Configuration
static
class
TestCustomServiceInstanceConverterConfig
{
@Bean
public
CustomServiceInstanceConverter
converter
()
{
return
new
CustomServiceInstanceConverter
();
}
}
static
class
CustomServiceInstanceConverter
implements
ServiceInstanceConverter
{
@Override
public
Application
convert
(
ServiceInstance
instance
)
{
return
null
;
}
}
@Configuration
protected
static
class
EurekaClientConfig
{
@Bean
public
EurekaClient
eurekaClient
()
{
return
Mockito
.
mock
(
EurekaClient
.
class
);
}
@Bean
public
DiscoveryClient
discoveryClient
()
{
return
Mockito
.
mock
(
DiscoveryClient
.
class
);
}
}
private
void
load
(
Class
<?>...
configs
)
{
AnnotationConfigWebApplicationContext
applicationContext
=
new
AnnotationConfigWebApplicationContext
();
for
(
Class
<?>
config
:
configs
)
{
applicationContext
.
register
(
config
);
}
applicationContext
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
AdminServerCoreConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
applicationContext
.
register
(
DiscoveryClientConfiguration
.
class
);
applicationContext
.
refresh
();
this
.
context
=
applicationContext
;
}
private
AnnotationConfigWebApplicationContext
context
;
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
defaultServiceInstanceConverter
()
{
load
(
SimpleDiscoveryClientAutoConfiguration
.
class
);
assertThat
(
context
.
getBean
(
ServiceInstanceConverter
.
class
),
is
(
instanceOf
(
DefaultServiceInstanceConverter
.
class
)));
}
@Test
public
void
eurekaServiceInstanceConverter
()
{
load
(
EurekaClientConfig
.
class
);
assertThat
(
context
.
getBean
(
ServiceInstanceConverter
.
class
),
is
(
instanceOf
(
EurekaServiceInstanceConverter
.
class
)));
}
@Test
public
void
customServiceInstanceConverter
()
{
load
(
SimpleDiscoveryClientAutoConfiguration
.
class
,
TestCustomServiceInstanceConverterConfig
.
class
);
assertThat
(
context
.
getBean
(
ServiceInstanceConverter
.
class
),
is
(
instanceOf
(
CustomServiceInstanceConverter
.
class
)));
}
@Configuration
static
class
TestCustomServiceInstanceConverterConfig
{
@Bean
public
CustomServiceInstanceConverter
converter
()
{
return
new
CustomServiceInstanceConverter
();
}
}
static
class
CustomServiceInstanceConverter
implements
ServiceInstanceConverter
{
@Override
public
Application
convert
(
ServiceInstance
instance
)
{
return
null
;
}
}
@Configuration
protected
static
class
EurekaClientConfig
{
@Bean
public
EurekaClient
eurekaClient
()
{
return
Mockito
.
mock
(
EurekaClient
.
class
);
}
@Bean
public
DiscoveryClient
discoveryClient
()
{
return
Mockito
.
mock
(
DiscoveryClient
.
class
);
}
}
private
void
load
(
Class
<?>...
configs
)
{
AnnotationConfigWebApplicationContext
applicationContext
=
new
AnnotationConfigWebApplicationContext
();
for
(
Class
<?>
config
:
configs
)
{
applicationContext
.
register
(
config
);
}
applicationContext
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
);
applicationContext
.
register
(
RestTemplateConfiguration
.
class
);
applicationContext
.
register
(
ServerPropertiesAutoConfiguration
.
class
);
applicationContext
.
register
(
AdminServerCoreConfiguration
.
class
);
applicationContext
.
register
(
AdminServerWebConfiguration
.
class
);
applicationContext
.
register
(
DiscoveryClientConfiguration
.
class
);
applicationContext
.
refresh
();
this
.
context
=
applicationContext
;
}
}
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