Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Selvakumar Kamatchinathan
amp-t2d-property-registry
Commits
c82623ad
Commit
c82623ad
authored
Nov 28, 2018
by
Selvakumar Kamatchinathan
Browse files
changes suggested by zl
parent
71953b1d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
116 additions
and
7 deletions
+116
-7
src/main/java/uk/ac/ebi/ampt2d/registry/exceptionhandling/ExceptionHandlers.java
.../ampt2d/registry/exceptionhandling/ExceptionHandlers.java
+44
-0
src/main/java/uk/ac/ebi/ampt2d/registry/service/mail/MailService.java
...a/uk/ac/ebi/ampt2d/registry/service/mail/MailService.java
+11
-6
src/test/java/uk/ac/ebi/ampt2d/registry/RegistryUpdateNotificationFailure.java
...bi/ampt2d/registry/RegistryUpdateNotificationFailure.java
+48
-0
src/test/java/uk/ac/ebi/ampt2d/registry/RegistryUpdateNotificationTest.java
...c/ebi/ampt2d/registry/RegistryUpdateNotificationTest.java
+3
-0
src/test/resources/application.properties
src/test/resources/application.properties
+10
-1
No files found.
src/main/java/uk/ac/ebi/ampt2d/registry/exceptionhandling/ExceptionHandlers.java
0 → 100644
View file @
c82623ad
/*
*
* Copyright 2018 EMBL - European Bioinformatics Institute
*
* 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
uk.ac.ebi.ampt2d.registry.exceptionhandling
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.mail.MailSendException
;
import
org.springframework.transaction.TransactionSystemException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
@ControllerAdvice
public
class
ExceptionHandlers
{
private
static
final
Logger
exceptionLogger
=
Logger
.
getLogger
(
ExceptionHandlers
.
class
.
getSimpleName
());
@ExceptionHandler
(
value
=
TransactionSystemException
.
class
)
public
ResponseEntity
<
String
>
handleMailSendException
(
TransactionSystemException
ex
)
{
if
(
ex
.
getOriginalException
().
getCause
().
getClass
().
equals
(
MailSendException
.
class
))
{
exceptionLogger
.
log
(
Level
.
SEVERE
,
ex
.
getOriginalException
().
getCause
().
getMessage
());
return
new
ResponseEntity
(
"Mail send exception, please contact amp-dev@ebi.ac.uk"
,
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
throw
ex
;
}
}
src/main/java/uk/ac/ebi/ampt2d/registry/service/mail/MailService.java
View file @
c82623ad
...
...
@@ -29,6 +29,9 @@ public class MailService {
@Autowired
private
JavaMailSender
javaMailSender
;
@Value
(
"${mail.notify:false}"
)
private
Boolean
nofify
;
@Value
(
"${mail.to}"
)
private
String
to
;
...
...
@@ -39,6 +42,7 @@ public class MailService {
private
String
subject
;
public
void
send
(
String
text
)
{
if
(
nofify
==
true
)
{
SimpleMailMessage
message
=
new
SimpleMailMessage
();
message
.
setTo
(
to
);
message
.
setFrom
(
from
);
...
...
@@ -46,4 +50,5 @@ public class MailService {
message
.
setText
(
text
);
javaMailSender
.
send
(
message
);
}
}
}
\ No newline at end of file
src/test/java/uk/ac/ebi/ampt2d/registry/RegistryUpdateNotificationFailure.java
0 → 100644
View file @
c82623ad
/*
*
* Copyright 2018 EMBL - European Bioinformatics Institute
*
* 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
uk.ac.ebi.ampt2d.registry
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.servlet.MockMvc
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
properties
=
{
"mail.notify=true"
,
"spring.mail.host=invalid_host"
})
@AutoConfigureMockMvc
public
class
RegistryUpdateNotificationFailure
{
@Autowired
private
MockMvc
mockMvc
;
@Test
public
void
testPhenotypeEvent
()
throws
Exception
{
String
phenotypeContent
=
"{\"id\":\"BMI\","
+
"\"phenotypeGroup\":\"ANTHROPOMETRIC\"}"
;
mockMvc
.
perform
(
post
(
"/phenotypes"
).
content
(
phenotypeContent
))
.
andExpect
(
status
().
isInternalServerError
())
.
andExpect
(
content
().
string
(
"Mail send exception, please contact amp-dev@ebi.ac.uk"
));
}
}
src/test/java/uk/ac/ebi/ampt2d/registry/RegistryUpdateNotificationTest.java
View file @
c82623ad
...
...
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.web.servlet.MockMvc
;
import
uk.ac.ebi.ampt2d.registry.service.mail.MailService
;
...
...
@@ -32,6 +33,7 @@ import static org.mockito.Matchers.anyString;
import
static
org
.
mockito
.
Mockito
.
doNothing
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
springframework
.
test
.
annotation
.
DirtiesContext
.
ClassMode
.
BEFORE_CLASS
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
delete
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
patch
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
...
...
@@ -40,6 +42,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
@AutoConfigureMockMvc
@DirtiesContext
(
classMode
=
BEFORE_CLASS
)
public
class
RegistryUpdateNotificationTest
{
@Autowired
...
...
src/test/resources/application.properties
View file @
c82623ad
...
...
@@ -12,3 +12,12 @@ endpoints.health.sensitive=false
registry.protocols
=
http
spring.jpa.hibernate.ddl-auto
=
none
spring.mail.port
=
587
spring.mail.test-connection
=
false
spring.mail.properties.mail.smtp.auth
=
false
spring.mail.properties.mail.smtp.ssl.enable
=
false
mail.from
=
amp-dev@ebi.ac.uk
mail.to
=
amp-dev@ebi.ac.uk
mail.subject
=
AMP-T2D Registry Update
\ No newline at end of file
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