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
8b6307e7
Commit
8b6307e7
authored
Jan 14, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use BDD Mockito
parent
3ea0f8d2
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
37 deletions
+35
-37
DiscoveryClientConfigServiceBootstrapConfigurationTests.java
...coveryClientConfigServiceBootstrapConfigurationTests.java
+7
-6
RibbonInterceptorTests.java
...ramework/cloud/netflix/ribbon/RibbonInterceptorTests.java
+4
-7
RibbonLoadBalancerClientTests.java
...k/cloud/netflix/ribbon/RibbonLoadBalancerClientTests.java
+11
-10
DomainExtractingServerListTests.java
...etflix/ribbon/eureka/DomainExtractingServerListTests.java
+8
-8
ProxyRouteLocatorTests.java
...gframework/cloud/netflix/zuul/ProxyRouteLocatorTests.java
+5
-6
No files found.
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/config/DiscoveryClientConfigServiceBootstrapConfigurationTests.java
View file @
8b6307e7
...
@@ -28,6 +28,7 @@ import com.netflix.appinfo.InstanceInfo;
...
@@ -28,6 +28,7 @@ import com.netflix.appinfo.InstanceInfo;
import
com.netflix.discovery.DiscoveryClient
;
import
com.netflix.discovery.DiscoveryClient
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
/**
/**
* @author Dave Syer
* @author Dave Syer
...
@@ -61,8 +62,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
...
@@ -61,8 +62,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
@Test
@Test
public
void
onWhenRequested
()
throws
Exception
{
public
void
onWhenRequested
()
throws
Exception
{
Mockito
.
when
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
))
given
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
)).
willReturn
(
.
thenReturn
(
this
.
info
);
this
.
info
);
setup
(
"spring.cloud.config.discovery.enabled=true"
);
setup
(
"spring.cloud.config.discovery.enabled=true"
);
assertEquals
(
assertEquals
(
1
,
1
,
...
@@ -77,8 +78,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
...
@@ -77,8 +78,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
@Test
@Test
public
void
setsPasssword
()
throws
Exception
{
public
void
setsPasssword
()
throws
Exception
{
this
.
info
.
getMetadata
().
put
(
"password"
,
"bar"
);
this
.
info
.
getMetadata
().
put
(
"password"
,
"bar"
);
Mockito
.
when
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
))
given
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
)).
willReturn
(
.
thenReturn
(
this
.
info
);
this
.
info
);
setup
(
"spring.cloud.config.discovery.enabled=true"
);
setup
(
"spring.cloud.config.discovery.enabled=true"
);
ConfigClientProperties
locator
=
this
.
context
ConfigClientProperties
locator
=
this
.
context
.
getBean
(
ConfigClientProperties
.
class
);
.
getBean
(
ConfigClientProperties
.
class
);
...
@@ -90,8 +91,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
...
@@ -90,8 +91,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
@Test
@Test
public
void
setsPath
()
throws
Exception
{
public
void
setsPath
()
throws
Exception
{
this
.
info
.
getMetadata
().
put
(
"configPath"
,
"/bar"
);
this
.
info
.
getMetadata
().
put
(
"configPath"
,
"/bar"
);
Mockito
.
when
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
))
given
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
)).
willReturn
(
.
thenReturn
(
this
.
info
);
this
.
info
);
setup
(
"spring.cloud.config.discovery.enabled=true"
);
setup
(
"spring.cloud.config.discovery.enabled=true"
);
ConfigClientProperties
locator
=
this
.
context
ConfigClientProperties
locator
=
this
.
context
.
getBean
(
ConfigClientProperties
.
class
);
.
getBean
(
ConfigClientProperties
.
class
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonInterceptorTests.java
View file @
8b6307e7
...
@@ -39,9 +39,9 @@ import com.netflix.loadbalancer.Server;
...
@@ -39,9 +39,9 @@ import com.netflix.loadbalancer.Server;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
isA
;
import
static
org
.
mockito
.
Matchers
.
isA
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
/**
* @author Spencer Gibb
* @author Spencer Gibb
...
@@ -66,16 +66,13 @@ public class RibbonInterceptorTests {
...
@@ -66,16 +66,13 @@ public class RibbonInterceptorTests {
public
void
testIntercept
()
throws
Exception
{
public
void
testIntercept
()
throws
Exception
{
RibbonServer
server
=
new
RibbonServer
(
"myservice"
,
new
Server
(
"myhost"
,
8080
));
RibbonServer
server
=
new
RibbonServer
(
"myservice"
,
new
Server
(
"myhost"
,
8080
));
RibbonInterceptor
interceptor
=
new
RibbonInterceptor
(
new
MyClient
(
server
));
RibbonInterceptor
interceptor
=
new
RibbonInterceptor
(
new
MyClient
(
server
));
given
(
this
.
request
.
getURI
()).
willReturn
(
new
URL
(
"http://myservice"
).
toURI
());
when
(
this
.
request
.
getURI
()).
thenReturn
(
new
URL
(
"http://myservice"
).
toURI
());
given
(
this
.
execution
.
execute
(
isA
(
HttpRequest
.
class
),
isA
(
byte
[].
class
)))
when
(
this
.
execution
.
execute
(
isA
(
HttpRequest
.
class
),
isA
(
byte
[].
class
)))
.
willReturn
(
this
.
response
);
.
thenReturn
(
this
.
response
);
ArgumentCaptor
<
HttpRequestWrapper
>
argument
=
ArgumentCaptor
ArgumentCaptor
<
HttpRequestWrapper
>
argument
=
ArgumentCaptor
.
forClass
(
HttpRequestWrapper
.
class
);
.
forClass
(
HttpRequestWrapper
.
class
);
ClientHttpResponse
response
=
interceptor
.
intercept
(
this
.
request
,
new
byte
[
0
],
ClientHttpResponse
response
=
interceptor
.
intercept
(
this
.
request
,
new
byte
[
0
],
this
.
execution
);
this
.
execution
);
assertNotNull
(
"response was null"
,
response
);
assertNotNull
(
"response was null"
,
response
);
verify
(
this
.
execution
).
execute
(
argument
.
capture
(),
isA
(
byte
[].
class
));
verify
(
this
.
execution
).
execute
(
argument
.
capture
(),
isA
(
byte
[].
class
));
HttpRequestWrapper
wrapper
=
argument
.
getValue
();
HttpRequestWrapper
wrapper
=
argument
.
getValue
();
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClientTests.java
View file @
8b6307e7
...
@@ -22,7 +22,6 @@ import java.net.URL;
...
@@ -22,7 +22,6 @@ import java.net.URL;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.MockitoAnnotations
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerRequest
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerRequest
;
...
@@ -36,10 +35,10 @@ import com.netflix.loadbalancer.ServerStats;
...
@@ -36,10 +35,10 @@ import com.netflix.loadbalancer.ServerStats;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
anyDouble
;
import
static
org
.
mockito
.
Matchers
.
anyDouble
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
/**
* @author Spencer Gibb
* @author Spencer Gibb
...
@@ -61,7 +60,7 @@ public class RibbonLoadBalancerClientTests {
...
@@ -61,7 +60,7 @@ public class RibbonLoadBalancerClientTests {
@Before
@Before
public
void
init
()
{
public
void
init
()
{
MockitoAnnotations
.
initMocks
(
this
);
MockitoAnnotations
.
initMocks
(
this
);
Mockito
.
when
(
this
.
clientFactory
.
getLoadBalancerContext
(
anyString
())).
then
Return
(
given
(
this
.
clientFactory
.
getLoadBalancerContext
(
anyString
())).
will
Return
(
new
RibbonLoadBalancerContext
(
this
.
loadBalancer
));
new
RibbonLoadBalancerContext
(
this
.
loadBalancer
));
}
}
...
@@ -144,13 +143,15 @@ public class RibbonLoadBalancerClientTests {
...
@@ -144,13 +143,15 @@ public class RibbonLoadBalancerClientTests {
protected
RibbonLoadBalancerClient
getRibbonLoadBalancerClient
(
protected
RibbonLoadBalancerClient
getRibbonLoadBalancerClient
(
RibbonServer
ribbonServer
)
{
RibbonServer
ribbonServer
)
{
when
(
this
.
loadBalancer
.
getName
()).
thenReturn
(
ribbonServer
.
getServiceId
());
given
(
this
.
loadBalancer
.
getName
()).
willReturn
(
ribbonServer
.
getServiceId
());
when
(
this
.
loadBalancer
.
chooseServer
(
anyString
())).
thenReturn
(
ribbonServer
.
server
);
given
(
this
.
loadBalancer
.
chooseServer
(
anyString
()))
when
(
this
.
loadBalancer
.
getLoadBalancerStats
()).
thenReturn
(
this
.
loadBalancerStats
);
.
willReturn
(
ribbonServer
.
server
);
when
(
this
.
loadBalancerStats
.
getSingleServerStat
(
ribbonServer
.
server
)).
thenReturn
(
given
(
this
.
loadBalancer
.
getLoadBalancerStats
())
this
.
serverStats
);
.
willReturn
(
this
.
loadBalancerStats
);
when
(
this
.
clientFactory
.
getLoadBalancer
(
this
.
loadBalancer
.
getName
())).
thenReturn
(
given
(
this
.
loadBalancerStats
.
getSingleServerStat
(
ribbonServer
.
server
))
this
.
loadBalancer
);
.
willReturn
(
this
.
serverStats
);
given
(
this
.
clientFactory
.
getLoadBalancer
(
this
.
loadBalancer
.
getName
()))
.
willReturn
(
this
.
loadBalancer
);
return
new
RibbonLoadBalancerClient
(
this
.
clientFactory
);
return
new
RibbonLoadBalancerClient
(
this
.
clientFactory
);
}
}
}
}
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/eureka/DomainExtractingServerListTests.java
View file @
8b6307e7
...
@@ -32,8 +32,8 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
...
@@ -32,8 +32,8 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
/**
* @author Spencer Gibb
* @author Spencer Gibb
...
@@ -102,15 +102,15 @@ public class DomainExtractingServerListTests {
...
@@ -102,15 +102,15 @@ public class DomainExtractingServerListTests {
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
ServerList
<
Server
>
originalServerList
=
mock
(
ServerList
.
class
);
ServerList
<
Server
>
originalServerList
=
mock
(
ServerList
.
class
);
InstanceInfo
instanceInfo
=
mock
(
InstanceInfo
.
class
);
InstanceInfo
instanceInfo
=
mock
(
InstanceInfo
.
class
);
when
(
server
.
getInstanceInfo
()).
then
Return
(
instanceInfo
);
given
(
server
.
getInstanceInfo
()).
will
Return
(
instanceInfo
);
when
(
server
.
getHost
()).
then
Return
(
HOST_NAME
);
given
(
server
.
getHost
()).
will
Return
(
HOST_NAME
);
when
(
instanceInfo
.
getMetadata
()).
then
Return
(
given
(
instanceInfo
.
getMetadata
()).
will
Return
(
ImmutableMap
.<
String
,
String
>
builder
().
put
(
"instanceId"
,
INSTANCE_ID
)
ImmutableMap
.<
String
,
String
>
builder
().
put
(
"instanceId"
,
INSTANCE_ID
)
.
build
());
.
build
());
when
(
instanceInfo
.
getHostName
()).
then
Return
(
HOST_NAME
);
given
(
instanceInfo
.
getHostName
()).
will
Return
(
HOST_NAME
);
when
(
instanceInfo
.
getIPAddr
()).
then
Return
(
IP_ADDR
);
given
(
instanceInfo
.
getIPAddr
()).
will
Return
(
IP_ADDR
);
when
(
instanceInfo
.
getPort
()).
then
Return
(
PORT
);
given
(
instanceInfo
.
getPort
()).
will
Return
(
PORT
);
when
(
originalServerList
.
getInitialListOfServers
()).
then
Return
(
given
(
originalServerList
.
getInitialListOfServers
()).
will
Return
(
Arrays
.<
Server
>
asList
(
server
));
Arrays
.<
Server
>
asList
(
server
));
return
new
DomainExtractingServerList
(
originalServerList
,
config
,
return
new
DomainExtractingServerList
(
originalServerList
,
config
,
approximateZoneFromHostname
);
approximateZoneFromHostname
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/ProxyRouteLocatorTests.java
View file @
8b6307e7
...
@@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
...
@@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
mockito
.
Mockito
.
wh
en
;
import
static
org
.
mockito
.
BDDMockito
.
giv
en
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
/**
/**
...
@@ -203,9 +203,8 @@ public class ProxyRouteLocatorTests {
...
@@ -203,9 +203,8 @@ public class ProxyRouteLocatorTests {
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
this
.
discovery
,
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
this
.
discovery
,
this
.
properties
);
this
.
properties
);
this
.
properties
.
setIgnoredServices
(
Lists
.
newArrayList
(
IGNOREDSERVICE
));
this
.
properties
.
setIgnoredServices
(
Lists
.
newArrayList
(
IGNOREDSERVICE
));
given
(
this
.
discovery
.
getServices
())
when
(
this
.
discovery
.
getServices
()).
thenReturn
(
Lists
.
newArrayList
(
IGNOREDSERVICE
));
.
willReturn
(
Lists
.
newArrayList
(
IGNOREDSERVICE
));
Map
<
String
,
String
>
routesMap
=
routeLocator
.
getRoutes
();
Map
<
String
,
String
>
routesMap
=
routeLocator
.
getRoutes
();
String
serviceId
=
routesMap
.
get
(
getMapping
(
IGNOREDSERVICE
));
String
serviceId
=
routesMap
.
get
(
getMapping
(
IGNOREDSERVICE
));
assertNull
(
"routes did not ignore "
+
IGNOREDSERVICE
,
serviceId
);
assertNull
(
"routes did not ignore "
+
IGNOREDSERVICE
,
serviceId
);
...
@@ -215,7 +214,7 @@ public class ProxyRouteLocatorTests {
...
@@ -215,7 +214,7 @@ public class ProxyRouteLocatorTests {
public
void
testAutoRoutes
()
{
public
void
testAutoRoutes
()
{
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
this
.
discovery
,
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
this
.
discovery
,
this
.
properties
);
this
.
properties
);
when
(
this
.
discovery
.
getServices
()).
then
Return
(
Lists
.
newArrayList
(
MYSERVICE
));
given
(
this
.
discovery
.
getServices
()).
will
Return
(
Lists
.
newArrayList
(
MYSERVICE
));
Map
<
String
,
String
>
routesMap
=
routeLocator
.
getRoutes
();
Map
<
String
,
String
>
routesMap
=
routeLocator
.
getRoutes
();
assertNotNull
(
"routesMap was null"
,
routesMap
);
assertNotNull
(
"routesMap was null"
,
routesMap
);
assertFalse
(
"routesMap was empty"
,
routesMap
.
isEmpty
());
assertFalse
(
"routesMap was empty"
,
routesMap
.
isEmpty
());
...
@@ -229,7 +228,7 @@ public class ProxyRouteLocatorTests {
...
@@ -229,7 +228,7 @@ public class ProxyRouteLocatorTests {
this
.
properties
.
getRoutes
().
put
(
MYSERVICE
,
route
);
this
.
properties
.
getRoutes
().
put
(
MYSERVICE
,
route
);
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
this
.
discovery
,
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
this
.
discovery
,
this
.
properties
);
this
.
properties
);
when
(
this
.
discovery
.
getServices
()).
then
Return
(
Lists
.
newArrayList
(
MYSERVICE
));
given
(
this
.
discovery
.
getServices
()).
will
Return
(
Lists
.
newArrayList
(
MYSERVICE
));
Map
<
String
,
String
>
routesMap
=
routeLocator
.
getRoutes
();
Map
<
String
,
String
>
routesMap
=
routeLocator
.
getRoutes
();
assertNotNull
(
"routesMap was null"
,
routesMap
);
assertNotNull
(
"routesMap was null"
,
routesMap
);
assertFalse
(
"routesMap was empty"
,
routesMap
.
isEmpty
());
assertFalse
(
"routesMap was empty"
,
routesMap
.
isEmpty
());
...
...
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