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
8ef1319c
Commit
8ef1319c
authored
Nov 09, 2015
by
Johannes Edmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests and missing license-headers
parent
01fbf73d
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
279 additions
and
21 deletions
+279
-21
ClientApplicationEvent.java
.../codecentric/boot/admin/event/ClientApplicationEvent.java
+26
-0
MailNotifier.java
...n/java/de/codecentric/boot/admin/notify/MailNotifier.java
+1
-6
AdminServerWebConfigurationTest.java
...ic/boot/admin/config/AdminServerWebConfigurationTest.java
+15
-0
ClientApplicationEventTest.java
...ecentric/boot/admin/event/ClientApplicationEventTest.java
+73
-0
HazelcastJournaledEventStoreTest.java
...admin/journal/store/HazelcastJournaledEventStoreTest.java
+67
-0
AbstractNotifierTest.java
...e/codecentric/boot/admin/notify/AbstractNotifierTest.java
+32
-1
MailNotifierTest.java
...va/de/codecentric/boot/admin/notify/MailNotifierTest.java
+17
-1
PagerdutyNotifierTest.java
.../codecentric/boot/admin/notify/PagerdutyNotifierTest.java
+15
-0
StatusUpdaterTest.java
...de/codecentric/boot/admin/registry/StatusUpdaterTest.java
+33
-13
No files found.
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/event/ClientApplicationEvent.java
View file @
8ef1319c
...
...
@@ -17,6 +17,9 @@ package de.codecentric.boot.admin.event;
import
java.io.Serializable
;
import
org.apache.commons.lang.builder.EqualsBuilder
;
import
org.apache.commons.lang.builder.HashCodeBuilder
;
import
de.codecentric.boot.admin.model.Application
;
/**
...
...
@@ -55,4 +58,27 @@ public abstract class ClientApplicationEvent implements Serializable {
*/
public
abstract
String
getType
();
@Override
public
int
hashCode
()
{
return
new
HashCodeBuilder
().
append
(
application
).
append
(
timestamp
).
append
(
getType
())
.
toHashCode
();
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
==
null
)
{
return
false
;
}
if
(
getClass
()
!=
obj
.
getClass
())
{
return
false
;
}
ClientApplicationEvent
other
=
(
ClientApplicationEvent
)
obj
;
return
new
EqualsBuilder
().
append
(
this
.
application
,
other
.
application
)
.
append
(
this
.
timestamp
,
other
.
timestamp
).
append
(
this
.
getType
(),
other
.
getType
())
.
isEquals
();
}
}
spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/notify/MailNotifier.java
View file @
8ef1319c
...
...
@@ -24,7 +24,6 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
import
org.springframework.expression.spel.support.StandardEvaluationContext
;
import
org.springframework.mail.MailSender
;
import
org.springframework.mail.SimpleMailMessage
;
import
org.springframework.mail.javamail.JavaMailSender
;
import
de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent
;
...
...
@@ -33,7 +32,7 @@ public class MailNotifier extends AbstractNotifier {
private
final
static
String
DEFAULT_TEXT
=
"#{application.name} (#{application.id})\nstatus changed from #{from.status} to #{to.status}\n\n#{application.healthUrl}"
;
private
final
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
private
MailSender
sender
;
private
final
MailSender
sender
;
/**
* recipients of the mail
...
...
@@ -80,10 +79,6 @@ public class MailNotifier extends AbstractNotifier {
sender
.
send
(
message
);
}
public
void
setSender
(
JavaMailSender
sender
)
{
this
.
sender
=
sender
;
}
public
void
setTo
(
String
[]
to
)
{
this
.
to
=
Arrays
.
copyOf
(
to
,
to
.
length
);
}
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/config/AdminServerWebConfigurationTest.java
View file @
8ef1319c
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
config
;
import
static
org
.
hamcrest
.
CoreMatchers
.
hasItem
;
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/event/ClientApplicationEventTest.java
0 → 100644
View file @
8ef1319c
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
event
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.io.Serializable
;
import
org.apache.commons.io.output.ByteArrayOutputStream
;
import
org.junit.Test
;
import
de.codecentric.boot.admin.model.Application
;
public
class
ClientApplicationEventTest
{
@Test
public
void
hashCode_equals
()
throws
Exception
{
ClientApplicationEvent
event1
=
new
ClientApplicationRegisteredEvent
(
Application
.
create
(
"test"
).
build
());
ClientApplicationEvent
event2
=
cloneBySerialization
(
event1
);
assertThat
(
event1
.
hashCode
(),
is
(
event2
.
hashCode
()));
assertThat
(
event1
,
is
(
event2
));
}
@Test
public
void
equals
()
throws
Exception
{
ClientApplicationEvent
event1
=
new
ClientApplicationRegisteredEvent
(
Application
.
create
(
"test"
).
build
());
ClientApplicationEvent
event2
=
new
ClientApplicationDeregisteredEvent
(
Application
.
create
(
"test"
).
build
());
assertThat
(
event1
,
not
(
is
(
event2
)));
}
@SuppressWarnings
(
"unchecked"
)
/**
* yeah nasty but we need exact the same timestamp
*/
private
<
T
extends
Serializable
>
T
cloneBySerialization
(
T
obj
)
throws
IOException
,
ClassNotFoundException
{
try
(
ByteArrayOutputStream
buf
=
new
ByteArrayOutputStream
())
{
try
(
ObjectOutputStream
oos
=
new
ObjectOutputStream
(
buf
))
{
oos
.
writeObject
(
obj
);
}
try
(
ObjectInputStream
ois
=
new
ObjectInputStream
(
new
ByteArrayInputStream
(
buf
.
toByteArray
())))
{
return
(
T
)
ois
.
readObject
();
}
}
}
}
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/journal/store/HazelcastJournaledEventStoreTest.java
0 → 100644
View file @
8ef1319c
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
journal
.
store
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Test
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.core.HazelcastInstance
;
import
com.hazelcast.instance.HazelcastInstanceFactory
;
import
de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationEvent
;
import
de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent
;
import
de.codecentric.boot.admin.model.Application
;
public
class
HazelcastJournaledEventStoreTest
{
private
HazelcastJournaledEventStore
store
;
@Before
public
void
setup
()
{
HazelcastInstance
hazelcast
=
HazelcastInstanceFactory
.
newHazelcastInstance
(
new
Config
());
store
=
new
HazelcastJournaledEventStore
(
hazelcast
.<
ClientApplicationEvent
>
getList
(
"testList"
));
}
@Test
public
void
test_store
()
{
Application
application
=
Application
.
create
(
"foo"
).
withId
(
"bar"
).
build
();
List
<
ClientApplicationEvent
>
events
=
Arrays
.
asList
(
new
ClientApplicationRegisteredEvent
(
application
),
new
ClientApplicationDeregisteredEvent
(
application
));
for
(
ClientApplicationEvent
event
:
events
)
{
store
.
store
(
event
);
}
// Items are stored in reverse order
List
<
ClientApplicationEvent
>
reversed
=
new
ArrayList
<>(
events
);
Collections
.
reverse
(
reversed
);
assertThat
(
store
.
findAll
(),
is
((
Collection
<
ClientApplicationEvent
>)
reversed
));
}
}
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/notify/AbstractNotifierTest.java
View file @
8ef1319c
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
notify
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
...
...
@@ -10,10 +25,10 @@ import de.codecentric.boot.admin.model.Application;
import
de.codecentric.boot.admin.model.StatusInfo
;
public
class
AbstractNotifierTest
{
private
TestableNotifier
notifier
=
new
TestableNotifier
();
@Test
public
void
test_onApplicationEvent
()
{
TestableNotifier
notifier
=
new
TestableNotifier
();
notifier
.
onClientApplicationStatusChanged
(
new
ClientApplicationStatusChangedEvent
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
StatusInfo
.
ofDown
(),
StatusInfo
.
ofUp
()));
...
...
@@ -22,6 +37,7 @@ public class AbstractNotifierTest {
@Test
public
void
test_onApplicationEvent_disbaled
()
{
TestableNotifier
notifier
=
new
TestableNotifier
();
notifier
.
setEnabled
(
false
);
notifier
.
onClientApplicationStatusChanged
(
new
ClientApplicationStatusChangedEvent
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
...
...
@@ -31,6 +47,7 @@ public class AbstractNotifierTest {
@Test
public
void
test_onApplicationEvent_noSend
()
{
TestableNotifier
notifier
=
new
TestableNotifier
();
notifier
.
onClientApplicationStatusChanged
(
new
ClientApplicationStatusChangedEvent
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
StatusInfo
.
ofUnknown
(),
StatusInfo
.
ofUp
()));
...
...
@@ -40,6 +57,7 @@ public class AbstractNotifierTest {
@Test
public
void
test_onApplicationEvent_noSend_wildcard
()
{
TestableNotifier
notifier
=
new
TestableNotifier
();
notifier
.
setIgnoreChanges
(
new
String
[]
{
"*:UP"
});
notifier
.
onClientApplicationStatusChanged
(
new
ClientApplicationStatusChangedEvent
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
...
...
@@ -48,6 +66,19 @@ public class AbstractNotifierTest {
assertFalse
(
notifier
.
hasNotified
);
}
@Test
public
void
test_onApplicationEvent_throw_doesnt_propagate
()
{
AbstractNotifier
notifier
=
new
AbstractNotifier
()
{
@Override
protected
void
notify
(
ClientApplicationStatusChangedEvent
event
)
throws
Exception
{
throw
new
RuntimeException
();
}
};
notifier
.
onClientApplicationStatusChanged
(
new
ClientApplicationStatusChangedEvent
(
Application
.
create
(
"App"
).
withId
(
"-id-"
).
withHealthUrl
(
"http://health"
).
build
(),
StatusInfo
.
ofOffline
(),
StatusInfo
.
ofUp
()));
}
private
static
class
TestableNotifier
extends
AbstractNotifier
{
private
boolean
hasNotified
;
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/notify/MailNotifierTest.java
View file @
8ef1319c
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
notify
;
import
static
org
.
mockito
.
Matchers
.
eq
;
...
...
@@ -26,6 +41,7 @@ public class MailNotifierTest {
notifier
.
setTo
(
new
String
[]
{
"foo@bar.com"
});
notifier
.
setCc
(
new
String
[]
{
"bar@foo.com"
});
notifier
.
setFrom
(
"SBA <no-reply@example.com>"
);
notifier
.
setSubject
(
"#{application.id} is #{to.status}"
);
}
@Test
...
...
@@ -39,7 +55,7 @@ public class MailNotifierTest {
expected
.
setCc
(
new
String
[]
{
"bar@foo.com"
});
expected
.
setFrom
(
"SBA <no-reply@example.com>"
);
expected
.
setText
(
"App (-id-)\nstatus changed from DOWN to UP\n\nhttp://health"
);
expected
.
setSubject
(
"
App (-id-)
is UP"
);
expected
.
setSubject
(
"
-id-
is UP"
);
verify
(
sender
).
send
(
eq
(
expected
));
}
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/notify/PagerdutyNotifierTest.java
View file @
8ef1319c
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
notify
;
import
static
org
.
mockito
.
Matchers
.
eq
;
...
...
spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/registry/StatusUpdaterTest.java
View file @
8ef1319c
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
de
.
codecentric
.
boot
.
admin
.
registry
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
...
...
@@ -45,7 +60,8 @@ public class StatusUpdaterTest {
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
)).
thenReturn
(
ResponseEntity
.
ok
().
body
((
Map
)
Collections
.
singletonMap
(
"status"
,
"UP"
)));
updater
.
updateStatus
(
Application
.
create
(
"foo"
).
withId
(
"id"
).
withHealthUrl
(
"health"
).
build
());
updater
.
updateStatus
(
Application
.
create
(
"foo"
).
withId
(
"id"
).
withHealthUrl
(
"health"
).
build
());
Application
app
=
store
.
find
(
"id"
);
...
...
@@ -55,13 +71,14 @@ public class StatusUpdaterTest {
@Test
public
void
test_update_statusUnchanged
()
{
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
))
.
thenReturn
(
ResponseEntity
.
ok
((
Map
)
Collections
.
singletonMap
(
"status"
,
"UNKNOWN"
)));
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
))
.
thenReturn
(
ResponseEntity
.
ok
((
Map
)
Collections
.
singletonMap
(
"status"
,
"UNKNOWN"
)));
updater
.
updateStatus
(
Application
.
create
(
"foo"
).
withId
(
"id"
).
withHealthUrl
(
"health"
).
build
());
updater
.
updateStatus
(
Application
.
create
(
"foo"
).
withId
(
"id"
).
withHealthUrl
(
"health"
).
build
());
verify
(
publisher
,
never
())
.
publishEvent
(
argThat
(
isA
(
ClientApplicationStatusChangedEvent
.
class
)));
verify
(
publisher
,
never
())
.
publishEvent
(
argThat
(
isA
(
ClientApplicationStatusChangedEvent
.
class
)));
}
@Test
...
...
@@ -69,25 +86,28 @@ public class StatusUpdaterTest {
// HTTP 200 - UP
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
)).
thenReturn
(
ResponseEntity
.
ok
((
Map
)
null
));
updater
.
updateStatus
(
Application
.
create
(
"foo"
).
withId
(
"id"
).
withHealthUrl
(
"health"
).
build
());
updater
.
updateStatus
(
Application
.
create
(
"foo"
).
withId
(
"id"
).
withHealthUrl
(
"health"
).
build
());
assertThat
(
store
.
find
(
"id"
).
getStatusInfo
().
getStatus
(),
is
(
"UP"
));
// HTTP != 200 - DOWN
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
))
.
thenReturn
(
ResponseEntity
.
status
(
503
).
body
((
Map
)
null
));
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
))
.
thenReturn
(
ResponseEntity
.
status
(
503
).
body
((
Map
)
null
));
updater
.
updateStatus
(
Application
.
create
(
"foo"
).
withId
(
"id"
).
withHealthUrl
(
"health"
).
build
());
updater
.
updateStatus
(
Application
.
create
(
"foo"
).
withId
(
"id"
).
withHealthUrl
(
"health"
).
build
());
assertThat
(
store
.
find
(
"id"
).
getStatusInfo
().
getStatus
(),
is
(
"DOWN"
));
}
@Test
public
void
test_update_offline
()
{
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
))
.
thenThrow
(
new
ResourceAccessException
(
"error"
));
when
(
template
.
getForEntity
(
"health"
,
Map
.
class
))
.
thenThrow
(
new
ResourceAccessException
(
"error"
));
updater
.
updateStatus
(
Application
.
create
(
"foo"
).
withId
(
"id"
).
withHealthUrl
(
"health"
).
build
());
updater
.
updateStatus
(
Application
.
create
(
"foo"
).
withId
(
"id"
).
withHealthUrl
(
"health"
).
build
());
assertThat
(
store
.
find
(
"id"
).
getStatusInfo
().
getStatus
(),
is
(
"OFFLINE"
));
}
...
...
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