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;
import
org.springframework.expression.Expression
;
import
org.springframework.expression.ParserContext
;
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
de.codecentric.boot.admin.event.ClientApplicationEvent
;
...
...
@@ -78,13 +81,17 @@ public class HipchatNotifier extends AbstractStatusChangeNotifier {
authToken
);
}
protected
Map
<
String
,
Object
>
createHipChatNotification
(
ClientApplicationEvent
event
)
{
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
result
.
put
(
"color"
,
getColor
(
event
));
result
.
put
(
"message"
,
getMessage
(
event
));
result
.
put
(
"notify"
,
getNotify
());
result
.
put
(
"message_format"
,
"html"
);
return
result
;
protected
HttpEntity
<
Map
<
String
,
Object
>>
createHipChatNotification
(
ClientApplicationEvent
event
)
{
Map
<
String
,
Object
>
body
=
new
HashMap
<>();
body
.
put
(
"color"
,
getColor
(
event
));
body
.
put
(
"message"
,
getMessage
(
event
));
body
.
put
(
"notify"
,
getNotify
());
body
.
put
(
"message_format"
,
"html"
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
return
new
HttpEntity
<>(
body
,
headers
);
}
protected
boolean
getNotify
()
{
...
...
@@ -97,7 +104,8 @@ public class HipchatNotifier extends AbstractStatusChangeNotifier {
protected
String
getColor
(
ClientApplicationEvent
event
)
{
if
(
event
instanceof
ClientApplicationStatusChangedEvent
)
{
return
"UP"
.
equals
(((
ClientApplicationStatusChangedEvent
)
event
).
getTo
().
getStatus
())
?
"green"
:
"red"
;
return
"UP"
.
equals
(((
ClientApplicationStatusChangedEvent
)
event
).
getTo
().
getStatus
())
?
"green"
:
"red"
;
}
else
{
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
;
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
.
isA
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.net.URI
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.junit.Before
;
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
de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent
;
...
...
@@ -40,17 +44,27 @@ public class HipchatNotifierTest {
StatusInfo
infoDown
=
StatusInfo
.
ofDown
();
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
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
infoDown
,
infoUp
));
Map
<
String
,
Object
>
expected
=
new
HashMap
<
String
,
Object
>();
expected
.
put
(
"color"
,
"green"
);
expected
.
put
(
"message"
,
"<strong>App</strong>/-id- is <strong>UP</strong>"
);
expected
.
put
(
"notify"
,
Boolean
.
TRUE
);
expected
.
put
(
"message_format"
,
"html"
);
assertThat
(
httpRequest
.
getValue
().
getHeaders
()).
containsEntry
(
"Content-Type"
,
asList
(
"application/json"
));
Map
<
String
,
Object
>
body
=
httpRequest
.
getValue
().
getBody
();
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
...
...
@@ -58,16 +72,25 @@ public class HipchatNotifierTest {
StatusInfo
infoDown
=
StatusInfo
.
ofDown
();
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
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
infoUp
,
infoDown
));
Map
<
String
,
Object
>
expected
=
new
HashMap
<
String
,
Object
>();
expected
.
put
(
"color"
,
"red"
);
expected
.
put
(
"message"
,
"<strong>App</strong>/-id- is <strong>DOWN</strong>"
);
expected
.
put
(
"notify"
,
Boolean
.
TRUE
);
expected
.
put
(
"message_format"
,
"html"
);
assertThat
(
httpRequest
.
getValue
().
getHeaders
()).
containsEntry
(
"Content-Type"
,
asList
(
"application/json"
));
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