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
Hide 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;
import
com.netflix.discovery.DiscoveryClient
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
/**
* @author Dave Syer
...
...
@@ -61,8 +62,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
@Test
public
void
onWhenRequested
()
throws
Exception
{
Mockito
.
when
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
))
.
thenReturn
(
this
.
info
);
given
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
)).
willReturn
(
this
.
info
);
setup
(
"spring.cloud.config.discovery.enabled=true"
);
assertEquals
(
1
,
...
...
@@ -77,8 +78,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
@Test
public
void
setsPasssword
()
throws
Exception
{
this
.
info
.
getMetadata
().
put
(
"password"
,
"bar"
);
Mockito
.
when
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
))
.
thenReturn
(
this
.
info
);
given
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
)).
willReturn
(
this
.
info
);
setup
(
"spring.cloud.config.discovery.enabled=true"
);
ConfigClientProperties
locator
=
this
.
context
.
getBean
(
ConfigClientProperties
.
class
);
...
...
@@ -90,8 +91,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
@Test
public
void
setsPath
()
throws
Exception
{
this
.
info
.
getMetadata
().
put
(
"configPath"
,
"/bar"
);
Mockito
.
when
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
))
.
thenReturn
(
this
.
info
);
given
(
this
.
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
)).
willReturn
(
this
.
info
);
setup
(
"spring.cloud.config.discovery.enabled=true"
);
ConfigClientProperties
locator
=
this
.
context
.
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;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
isA
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
* @author Spencer Gibb
...
...
@@ -66,16 +66,13 @@ public class RibbonInterceptorTests {
public
void
testIntercept
()
throws
Exception
{
RibbonServer
server
=
new
RibbonServer
(
"myservice"
,
new
Server
(
"myhost"
,
8080
));
RibbonInterceptor
interceptor
=
new
RibbonInterceptor
(
new
MyClient
(
server
));
when
(
this
.
request
.
getURI
()).
thenReturn
(
new
URL
(
"http://myservice"
).
toURI
());
when
(
this
.
execution
.
execute
(
isA
(
HttpRequest
.
class
),
isA
(
byte
[].
class
)))
.
thenReturn
(
this
.
response
);
given
(
this
.
request
.
getURI
()).
willReturn
(
new
URL
(
"http://myservice"
).
toURI
());
given
(
this
.
execution
.
execute
(
isA
(
HttpRequest
.
class
),
isA
(
byte
[].
class
)))
.
willReturn
(
this
.
response
);
ArgumentCaptor
<
HttpRequestWrapper
>
argument
=
ArgumentCaptor
.
forClass
(
HttpRequestWrapper
.
class
);
ClientHttpResponse
response
=
interceptor
.
intercept
(
this
.
request
,
new
byte
[
0
],
this
.
execution
);
assertNotNull
(
"response was null"
,
response
);
verify
(
this
.
execution
).
execute
(
argument
.
capture
(),
isA
(
byte
[].
class
));
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;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerRequest
;
...
...
@@ -36,10 +35,10 @@ import com.netflix.loadbalancer.ServerStats;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
anyDouble
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
* @author Spencer Gibb
...
...
@@ -61,7 +60,7 @@ public class RibbonLoadBalancerClientTests {
@Before
public
void
init
()
{
MockitoAnnotations
.
initMocks
(
this
);
Mockito
.
when
(
this
.
clientFactory
.
getLoadBalancerContext
(
anyString
())).
then
Return
(
given
(
this
.
clientFactory
.
getLoadBalancerContext
(
anyString
())).
will
Return
(
new
RibbonLoadBalancerContext
(
this
.
loadBalancer
));
}
...
...
@@ -144,13 +143,15 @@ public class RibbonLoadBalancerClientTests {
protected
RibbonLoadBalancerClient
getRibbonLoadBalancerClient
(
RibbonServer
ribbonServer
)
{
when
(
this
.
loadBalancer
.
getName
()).
thenReturn
(
ribbonServer
.
getServiceId
());
when
(
this
.
loadBalancer
.
chooseServer
(
anyString
())).
thenReturn
(
ribbonServer
.
server
);
when
(
this
.
loadBalancer
.
getLoadBalancerStats
()).
thenReturn
(
this
.
loadBalancerStats
);
when
(
this
.
loadBalancerStats
.
getSingleServerStat
(
ribbonServer
.
server
)).
thenReturn
(
this
.
serverStats
);
when
(
this
.
clientFactory
.
getLoadBalancer
(
this
.
loadBalancer
.
getName
())).
thenReturn
(
this
.
loadBalancer
);
given
(
this
.
loadBalancer
.
getName
()).
willReturn
(
ribbonServer
.
getServiceId
());
given
(
this
.
loadBalancer
.
chooseServer
(
anyString
()))
.
willReturn
(
ribbonServer
.
server
);
given
(
this
.
loadBalancer
.
getLoadBalancerStats
())
.
willReturn
(
this
.
loadBalancerStats
);
given
(
this
.
loadBalancerStats
.
getSingleServerStat
(
ribbonServer
.
server
))
.
willReturn
(
this
.
serverStats
);
given
(
this
.
clientFactory
.
getLoadBalancer
(
this
.
loadBalancer
.
getName
()))
.
willReturn
(
this
.
loadBalancer
);
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;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
* @author Spencer Gibb
...
...
@@ -102,15 +102,15 @@ public class DomainExtractingServerListTests {
@SuppressWarnings
(
"unchecked"
)
ServerList
<
Server
>
originalServerList
=
mock
(
ServerList
.
class
);
InstanceInfo
instanceInfo
=
mock
(
InstanceInfo
.
class
);
when
(
server
.
getInstanceInfo
()).
then
Return
(
instanceInfo
);
when
(
server
.
getHost
()).
then
Return
(
HOST_NAME
);
when
(
instanceInfo
.
getMetadata
()).
then
Return
(
given
(
server
.
getInstanceInfo
()).
will
Return
(
instanceInfo
);
given
(
server
.
getHost
()).
will
Return
(
HOST_NAME
);
given
(
instanceInfo
.
getMetadata
()).
will
Return
(
ImmutableMap
.<
String
,
String
>
builder
().
put
(
"instanceId"
,
INSTANCE_ID
)
.
build
());
when
(
instanceInfo
.
getHostName
()).
then
Return
(
HOST_NAME
);
when
(
instanceInfo
.
getIPAddr
()).
then
Return
(
IP_ADDR
);
when
(
instanceInfo
.
getPort
()).
then
Return
(
PORT
);
when
(
originalServerList
.
getInitialListOfServers
()).
then
Return
(
given
(
instanceInfo
.
getHostName
()).
will
Return
(
HOST_NAME
);
given
(
instanceInfo
.
getIPAddr
()).
will
Return
(
IP_ADDR
);
given
(
instanceInfo
.
getPort
()).
will
Return
(
PORT
);
given
(
originalServerList
.
getInitialListOfServers
()).
will
Return
(
Arrays
.<
Server
>
asList
(
server
));
return
new
DomainExtractingServerList
(
originalServerList
,
config
,
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;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
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
;
/**
...
...
@@ -203,9 +203,8 @@ public class ProxyRouteLocatorTests {
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
this
.
discovery
,
this
.
properties
);
this
.
properties
.
setIgnoredServices
(
Lists
.
newArrayList
(
IGNOREDSERVICE
));
when
(
this
.
discovery
.
getServices
()).
thenReturn
(
Lists
.
newArrayList
(
IGNOREDSERVICE
));
given
(
this
.
discovery
.
getServices
())
.
willReturn
(
Lists
.
newArrayList
(
IGNOREDSERVICE
));
Map
<
String
,
String
>
routesMap
=
routeLocator
.
getRoutes
();
String
serviceId
=
routesMap
.
get
(
getMapping
(
IGNOREDSERVICE
));
assertNull
(
"routes did not ignore "
+
IGNOREDSERVICE
,
serviceId
);
...
...
@@ -215,7 +214,7 @@ public class ProxyRouteLocatorTests {
public
void
testAutoRoutes
()
{
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
this
.
discovery
,
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
();
assertNotNull
(
"routesMap was null"
,
routesMap
);
assertFalse
(
"routesMap was empty"
,
routesMap
.
isEmpty
());
...
...
@@ -229,7 +228,7 @@ public class ProxyRouteLocatorTests {
this
.
properties
.
getRoutes
().
put
(
MYSERVICE
,
route
);
ProxyRouteLocator
routeLocator
=
new
ProxyRouteLocator
(
this
.
discovery
,
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
();
assertNotNull
(
"routesMap was null"
,
routesMap
);
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