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
5c90f473
Commit
5c90f473
authored
Jan 11, 2017
by
earthmonkey0
Committed by
Johannes Edmeier
Jan 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add content-type header to hipchat request
fixes #382
parent
21aac376
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
23 deletions
+54
-23
HipchatNotifier.java
...ava/de/codecentric/boot/admin/notify/HipchatNotifier.java
+16
-8
HipchatNotifierTest.java
...de/codecentric/boot/admin/notify/HipchatNotifierTest.java
+38
-15
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/notify/HipchatNotifier.java
View file @
5c90f473
...
@@ -22,6 +22,9 @@ import java.util.Map;
...
@@ -22,6 +22,9 @@ import java.util.Map;
import
org.springframework.expression.Expression
;
import
org.springframework.expression.Expression
;
import
org.springframework.expression.ParserContext
;
import
org.springframework.expression.ParserContext
;
import
org.springframework.expression.spel.standard.SpelExpressionParser
;
import
org.springframework.expression.spel.standard.SpelExpressionParser
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
de.codecentric.boot.admin.event.ClientApplicationEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationEvent
;
...
@@ -78,13 +81,17 @@ public class HipchatNotifier extends AbstractStatusChangeNotifier {
...
@@ -78,13 +81,17 @@ public class HipchatNotifier extends AbstractStatusChangeNotifier {
authToken
);
authToken
);
}
}
protected
Map
<
String
,
Object
>
createHipChatNotification
(
ClientApplicationEvent
event
)
{
protected
HttpEntity
<
Map
<
String
,
Object
>>
createHipChatNotification
(
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
ClientApplicationEvent
event
)
{
result
.
put
(
"color"
,
getColor
(
event
));
Map
<
String
,
Object
>
body
=
new
HashMap
<>();
result
.
put
(
"message"
,
getMessage
(
event
));
body
.
put
(
"color"
,
getColor
(
event
));
result
.
put
(
"notify"
,
getNotify
());
body
.
put
(
"message"
,
getMessage
(
event
));
result
.
put
(
"message_format"
,
"html"
);
body
.
put
(
"notify"
,
getNotify
());
return
result
;
body
.
put
(
"message_format"
,
"html"
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
return
new
HttpEntity
<>(
body
,
headers
);
}
}
protected
boolean
getNotify
()
{
protected
boolean
getNotify
()
{
...
@@ -97,7 +104,8 @@ public class HipchatNotifier extends AbstractStatusChangeNotifier {
...
@@ -97,7 +104,8 @@ public class HipchatNotifier extends AbstractStatusChangeNotifier {
protected
String
getColor
(
ClientApplicationEvent
event
)
{
protected
String
getColor
(
ClientApplicationEvent
event
)
{
if
(
event
instanceof
ClientApplicationStatusChangedEvent
)
{
if
(
event
instanceof
ClientApplicationStatusChangedEvent
)
{
return
"UP"
.
equals
(((
ClientApplicationStatusChangedEvent
)
event
).
getTo
().
getStatus
())
?
"green"
:
"red"
;
return
"UP"
.
equals
(((
ClientApplicationStatusChangedEvent
)
event
).
getTo
().
getStatus
())
?
"green"
:
"red"
;
}
else
{
}
else
{
return
"gray"
;
return
"gray"
;
}
}
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/notify/HipchatNotifierTest.java
View file @
5c90f473
package
de
.
codecentric
.
boot
.
admin
.
notify
;
package
de
.
codecentric
.
boot
.
admin
.
notify
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
java
.
util
.
Arrays
.
asList
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Matchers
.
isA
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.net.URI
;
import
java.net.URI
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.mockito.ArgumentCaptor
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent
;
...
@@ -40,17 +44,27 @@ public class HipchatNotifierTest {
...
@@ -40,17 +44,27 @@ public class HipchatNotifierTest {
StatusInfo
infoDown
=
StatusInfo
.
ofDown
();
StatusInfo
infoDown
=
StatusInfo
.
ofDown
();
StatusInfo
infoUp
=
StatusInfo
.
ofUp
();
StatusInfo
infoUp
=
StatusInfo
.
ofUp
();
@SuppressWarnings
(
"unchecked"
)
ArgumentCaptor
<
HttpEntity
<
Map
<
String
,
Object
>>>
httpRequest
=
ArgumentCaptor
.
forClass
((
Class
<
HttpEntity
<
Map
<
String
,
Object
>>>)
(
Class
<?>)
HttpEntity
.
class
);
when
(
restTemplate
.
postForEntity
(
isA
(
String
.
class
),
httpRequest
.
capture
(),
eq
(
Void
.
class
)))
.
thenReturn
(
ResponseEntity
.
ok
((
Void
)
null
));
notifier
.
notify
(
new
ClientApplicationStatusChangedEvent
(
notifier
.
notify
(
new
ClientApplicationStatusChangedEvent
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
infoDown
,
infoUp
));
infoDown
,
infoUp
));
Map
<
String
,
Object
>
expected
=
new
HashMap
<
String
,
Object
>();
assertThat
(
httpRequest
.
getValue
().
getHeaders
()).
containsEntry
(
"Content-Type"
,
expected
.
put
(
"color"
,
"green"
);
asList
(
"application/json"
));
expected
.
put
(
"message"
,
"<strong>App</strong>/-id- is <strong>UP</strong>"
);
expected
.
put
(
"notify"
,
Boolean
.
TRUE
);
Map
<
String
,
Object
>
body
=
httpRequest
.
getValue
().
getBody
();
expected
.
put
(
"message_format"
,
"html"
);
assertThat
(
body
).
containsEntry
(
"color"
,
"green"
);
assertThat
(
body
).
containsEntry
(
"message"
,
"<strong>App</strong>/-id- is <strong>UP</strong>"
);
assertThat
(
body
).
containsEntry
(
"notify"
,
Boolean
.
TRUE
);
assertThat
(
body
).
containsEntry
(
"message_format"
,
"html"
);
verify
(
restTemplate
).
postForEntity
(
any
(
String
.
class
),
eq
(
expected
),
eq
(
Void
.
class
));
}
}
@Test
@Test
...
@@ -58,16 +72,25 @@ public class HipchatNotifierTest {
...
@@ -58,16 +72,25 @@ public class HipchatNotifierTest {
StatusInfo
infoDown
=
StatusInfo
.
ofDown
();
StatusInfo
infoDown
=
StatusInfo
.
ofDown
();
StatusInfo
infoUp
=
StatusInfo
.
ofUp
();
StatusInfo
infoUp
=
StatusInfo
.
ofUp
();
@SuppressWarnings
(
"unchecked"
)
ArgumentCaptor
<
HttpEntity
<
Map
<
String
,
Object
>>>
httpRequest
=
ArgumentCaptor
.
forClass
((
Class
<
HttpEntity
<
Map
<
String
,
Object
>>>)
(
Class
<?>)
HttpEntity
.
class
);
when
(
restTemplate
.
postForEntity
(
isA
(
String
.
class
),
httpRequest
.
capture
(),
eq
(
Void
.
class
)))
.
thenReturn
(
ResponseEntity
.
ok
((
Void
)
null
));
notifier
.
notify
(
new
ClientApplicationStatusChangedEvent
(
notifier
.
notify
(
new
ClientApplicationStatusChangedEvent
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
infoUp
,
infoDown
));
infoUp
,
infoDown
));
Map
<
String
,
Object
>
expected
=
new
HashMap
<
String
,
Object
>();
assertThat
(
httpRequest
.
getValue
().
getHeaders
()).
containsEntry
(
"Content-Type"
,
expected
.
put
(
"color"
,
"red"
);
asList
(
"application/json"
));
expected
.
put
(
"message"
,
"<strong>App</strong>/-id- is <strong>DOWN</strong>"
);
expected
.
put
(
"notify"
,
Boolean
.
TRUE
);
expected
.
put
(
"message_format"
,
"html"
);
verify
(
restTemplate
).
postForEntity
(
any
(
String
.
class
),
eq
(
expected
),
eq
(
Void
.
class
));
Map
<
String
,
Object
>
body
=
httpRequest
.
getValue
().
getBody
();
assertThat
(
body
).
containsEntry
(
"color"
,
"red"
);
assertThat
(
body
).
containsEntry
(
"message"
,
"<strong>App</strong>/-id- is <strong>DOWN</strong>"
);
assertThat
(
body
).
containsEntry
(
"notify"
,
Boolean
.
TRUE
);
assertThat
(
body
).
containsEntry
(
"message_format"
,
"html"
);
}
}
}
}
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