-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotation Service tests are implemented and the some code moved to D…
…toConverter to increse readability (#676) Good. Thanks.
- Loading branch information
Showing
5 changed files
with
405 additions
and
138 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
143 changes: 71 additions & 72 deletions
143
app/annotation-service/src/main/kotlin/com/group6/annotationservice/Utils/DtoConverter.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
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
112 changes: 112 additions & 0 deletions
112
...otation-service/src/test/kotlin/com/group6/annotationservice/AnnotationControllerTests.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,112 @@ | ||
package com.group6.annotationservice | ||
|
||
import com.group6.annotationservice.controller.AnnotationController | ||
import com.group6.annotationservice.dtos.AnnotationDto | ||
import com.group6.annotationservice.dtos.BodyDto | ||
import com.group6.annotationservice.dtos.FragmentSelectorDto | ||
import com.group6.annotationservice.dtos.TargetDto | ||
import com.group6.annotationservice.entity.* | ||
import com.group6.annotationservice.entity.Annotation | ||
import com.group6.annotationservice.entity.Target | ||
import com.group6.annotationservice.service.AnnotationService | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.Mockito.`when` | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.springframework.http.HttpStatus | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class AnnotationControllerTests { | ||
|
||
@Mock | ||
private lateinit var annotationService: AnnotationService | ||
|
||
@InjectMocks | ||
private lateinit var annotationController: AnnotationController | ||
|
||
|
||
@Test | ||
fun `createAnnotation should return created status with converted DTO`() { | ||
val inputDto = AnnotationDto( | ||
context = "http://www.w3.org/ns/anno.jsonld", | ||
id = "1", | ||
type = "Annotation", | ||
motivation = listOf("editing"), | ||
creator = "test_creator", | ||
body = listOf( | ||
BodyDto(id = "1", type = "TextualBody", value = "Example text") | ||
), | ||
target = TargetDto( | ||
id = "1", | ||
format = "text/plain", | ||
selector = FragmentSelectorDto( | ||
type = "FragmentSelector", | ||
value = "Example selector" | ||
) | ||
) | ||
) | ||
|
||
|
||
val createdAnnotation = Annotation( | ||
context = "http://www.w3.org/ns/anno.jsonld", | ||
id = "1", | ||
type = "Annotation", | ||
motivation = listOf(Motivation(value = "editing")), | ||
creator = "test_creator", | ||
body = listOf( | ||
Body(id = "1", type = "TextualBody", value = "Example text") | ||
), | ||
target = Target( | ||
id = "1", | ||
format = "text/plain", | ||
), | ||
selector = FragmentSelector( | ||
type = "FragmentSelector", | ||
value = "Example selector" | ||
) | ||
) | ||
|
||
val convertedDto = AnnotationDto( | ||
context = "http://www.w3.org/ns/anno.jsonld", | ||
id = "1", | ||
type = "Annotation", | ||
motivation = listOf("editing"), | ||
creator = "test_creator", | ||
created = createdAnnotation.created, | ||
body = listOf( | ||
BodyDto(id = "1", type = "TextualBody", value = "Example text") | ||
), | ||
target = TargetDto( | ||
id = "1", | ||
format = "text/plain", | ||
selector = FragmentSelectorDto( | ||
type = "FragmentSelector", | ||
value = "Example selector" | ||
) | ||
) | ||
) | ||
|
||
|
||
`when`(annotationService.createAnnotation(inputDto)).thenReturn(createdAnnotation) | ||
//`when`(DtoConverter.convertAnnotationToAnnotationDto(createdAnnotation)).thenReturn(convertedDto) | ||
|
||
val response = annotationController.createAnnotation(inputDto) | ||
|
||
assertEquals(HttpStatus.CREATED, response.statusCode) | ||
assertEquals(convertedDto.id, response.body!!.id) | ||
assertEquals(convertedDto.type, response.body!!.type) | ||
assertEquals(convertedDto.motivation, response.body!!.motivation) | ||
assertEquals(convertedDto.creator, response.body!!.creator) | ||
assertEquals(convertedDto.created, response.body!!.created) | ||
assertEquals(convertedDto.body, response.body!!.body) | ||
assertEquals(convertedDto.target.id, response.body!!.target.id) | ||
assertEquals(convertedDto.target.format, response.body!!.target.format) | ||
assertEquals(convertedDto.target.language, response.body!!.target.language) | ||
assertEquals(convertedDto.target.selector, response.body!!.target.selector) | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.