-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pivotal ID # 172817960: Resubmit Notfication (#253)
* Pivotal ID # 172817960: Resubmit Notfication - Create an extended user endpoint - Use the endpoint to get the user information in the notifications side
- Loading branch information
1 parent
ad95fb8
commit f130dba
Showing
14 changed files
with
235 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...mission-webapp/src/main/kotlin/ac/uk/ebi/biostd/security/domain/service/ExtUserService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ac.uk.ebi.biostd.security.domain.service | ||
|
||
import ac.uk.ebi.biostd.persistence.model.DbUser | ||
import ac.uk.ebi.biostd.persistence.repositories.UserDataRepository | ||
import ebi.ac.uk.extended.model.ExtUser | ||
import ebi.ac.uk.security.integration.exception.UserNotFoundByEmailException | ||
|
||
class ExtUserService(private val userDataRepository: UserDataRepository) { | ||
fun getExtUser(email: String): ExtUser = | ||
toExtUser(userDataRepository | ||
.findByEmail(email) | ||
.orElseThrow { UserNotFoundByEmailException(email) }) | ||
|
||
private fun toExtUser(user: DbUser) = ExtUser( | ||
email = user.email, | ||
fullName = user.fullName, | ||
login = user.login, | ||
notificationsEnabled = user.notificationsEnabled) | ||
} |
23 changes: 23 additions & 0 deletions
23
...ission/submission-webapp/src/main/kotlin/ac/uk/ebi/biostd/security/web/ExtUserResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ac.uk.ebi.biostd.security.web | ||
|
||
import ac.uk.ebi.biostd.security.domain.service.ExtUserService | ||
import ebi.ac.uk.extended.model.ExtUser | ||
import io.swagger.annotations.Api | ||
import io.swagger.annotations.ApiOperation | ||
import io.swagger.annotations.ApiParam | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/security/users/extended") | ||
@Api(tags = ["Extended User"]) | ||
class ExtUserResource(private val extUserService: ExtUserService) { | ||
@GetMapping("/{email:.*}") | ||
@ApiOperation("Get the extended information for a user") | ||
fun getExtUser( | ||
@ApiParam(name = "email", value = "The user email") | ||
@PathVariable email: String | ||
): ExtUser = extUserService.getExtUser(email) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
submission/submission-webapp/src/test/kotlin/ac/uk/ebi/biostd/events/EventsServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ac.uk.ebi.biostd.events | ||
|
||
import ac.uk.ebi.biostd.common.property.ApplicationProperties | ||
import ebi.ac.uk.extended.events.SubmissionSubmitted | ||
import ebi.ac.uk.extended.model.ExtSubmission | ||
import ebi.ac.uk.security.integration.model.api.SecurityUser | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.slot | ||
import io.mockk.verify | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate | ||
|
||
@ExtendWith(MockKExtension::class) | ||
class EventsServiceTest( | ||
@MockK private val rabbitTemplate: RabbitTemplate, | ||
@MockK private val properties: ApplicationProperties | ||
) { | ||
private val testInstance = EventsService(rabbitTemplate, properties) | ||
|
||
@Test | ||
fun submissionSubmitted( | ||
@MockK user: SecurityUser, | ||
@MockK submission: ExtSubmission | ||
) { | ||
val notificationSlot = slot<SubmissionSubmitted>() | ||
|
||
every { user.email } returns "test@ebi.ac.uk" | ||
every { submission.accNo } returns "S-BSST0" | ||
every { properties.instanceBaseUrl } returns "http://biostudies:8788" | ||
every { | ||
rabbitTemplate.convertAndSend(BIOSTUDIES_EXCHANGE, SUBMISSIONS_ROUTING_KEY, capture(notificationSlot)) | ||
} answers { nothing } | ||
|
||
testInstance.submissionSubmitted(submission, user) | ||
|
||
val notification = notificationSlot.captured | ||
assertThat(notification.accNo).isEqualTo("S-BSST0") | ||
assertThat(notification.uiUrl).isEqualTo("http://biostudies:8788") | ||
assertThat(notification.pagetabUrl).isEqualTo("http://biostudies:8788/submissions/S-BSST0.json") | ||
assertThat(notification.extTabUrl).isEqualTo("http://biostudies:8788/submissions/extended/S-BSST0") | ||
assertThat(notification.extUserUrl).isEqualTo("http://biostudies:8788/security/users/extended/test@ebi.ac.uk") | ||
|
||
verify { rabbitTemplate.convertAndSend(BIOSTUDIES_EXCHANGE, SUBMISSIONS_ROUTING_KEY, notification) } | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ion-webapp/src/test/kotlin/ac/uk/ebi/biostd/security/domain/service/ExtUserServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ac.uk.ebi.biostd.security.domain.service | ||
|
||
import ac.uk.ebi.biostd.persistence.model.DbUser | ||
import ac.uk.ebi.biostd.persistence.repositories.UserDataRepository | ||
import ebi.ac.uk.security.integration.exception.UserNotFoundByEmailException | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.mockk | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import java.util.Optional | ||
|
||
@ExtendWith(MockKExtension::class) | ||
class ExtUserServiceTest(@MockK private val userDataRepository: UserDataRepository) { | ||
private val testInstance = ExtUserService(userDataRepository) | ||
|
||
@Test | ||
fun getExtUser() { | ||
val user = mockUser() | ||
every { userDataRepository.findByEmail("test@ebi.ac.uk") } returns Optional.of(user) | ||
|
||
val extUser = testInstance.getExtUser("test@ebi.ac.uk") | ||
assertThat(extUser.login).isEqualTo("test") | ||
assertThat(extUser.fullName).isEqualTo("Test User") | ||
assertThat(extUser.email).isEqualTo("test@ebi.ac.uk") | ||
assertThat(extUser.notificationsEnabled).isTrue() | ||
} | ||
|
||
@Test | ||
fun `non existing user`() { | ||
every { userDataRepository.findByEmail("test@ebi.ac.uk") } returns Optional.empty() | ||
|
||
val exception = assertThrows<UserNotFoundByEmailException> { testInstance.getExtUser("test@ebi.ac.uk") } | ||
assertThat(exception.message).isEqualTo("Could not find user with the provided email 'test@ebi.ac.uk'.") | ||
} | ||
|
||
private fun mockUser(): DbUser { | ||
val user = mockk<DbUser>() | ||
every { user.login } returns "test" | ||
every { user.fullName } returns "Test User" | ||
every { user.email } returns "test@ebi.ac.uk" | ||
every { user.notificationsEnabled } returns true | ||
|
||
return user | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...n-webapp/src/test/kotlin/ac/uk/ebi/biostd/submission/web/resources/ExtUserResourceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ac.uk.ebi.biostd.submission.web.resources | ||
|
||
import ac.uk.ebi.biostd.security.web.ExtUserResource | ||
import ac.uk.ebi.biostd.security.domain.service.ExtUserService | ||
import ebi.ac.uk.dsl.json.jsonObj | ||
import ebi.ac.uk.extended.model.ExtUser | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.verify | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.http.MediaType.APPLICATION_JSON | ||
import org.springframework.test.web.servlet.get | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders | ||
|
||
@ExtendWith(MockKExtension::class) | ||
class ExtUserResourceTest(@MockK private val extUserService: ExtUserService) { | ||
private val mvc = MockMvcBuilders | ||
.standaloneSetup(ExtUserResource(extUserService)) | ||
.build() | ||
|
||
@Test | ||
fun `get ext user`() { | ||
val expectedJson = jsonObj { | ||
"login" to "test_user" | ||
"fullName" to "Test User" | ||
"email" to "test@ebi.ac.uk" | ||
"notificationsEnabled" to true | ||
}.toString() | ||
|
||
every { extUserService.getExtUser("test@ebi.ac.uk") } returns testUser() | ||
|
||
mvc.get("/security/users/extended/test@ebi.ac.uk") { | ||
accept = APPLICATION_JSON | ||
}.andExpect { | ||
status { isOk } | ||
content { json(expectedJson) } | ||
} | ||
|
||
verify { extUserService.getExtUser("test@ebi.ac.uk") } | ||
} | ||
|
||
private fun testUser() = ExtUser( | ||
login = "test_user", | ||
fullName = "Test User", | ||
email = "test@ebi.ac.uk", | ||
notificationsEnabled = true | ||
) | ||
} |