From 250bb1863d6e0cbf10a7b62dc03cc5daad568fac Mon Sep 17 00:00:00 2001 From: AvilaAndre Date: Fri, 29 Mar 2024 01:02:22 +0000 Subject: [PATCH] Fixing tests failing after changes --- .../pt/up/fe/ni/website/backend/model/Activity.kt | 2 +- .../service/activity/AbstractActivityService.kt | 7 ++++--- .../website/backend/controller/EventControllerTest.kt | 11 +++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/pt/up/fe/ni/website/backend/model/Activity.kt b/src/main/kotlin/pt/up/fe/ni/website/backend/model/Activity.kt index 5c616ea0..d7884b45 100644 --- a/src/main/kotlin/pt/up/fe/ni/website/backend/model/Activity.kt +++ b/src/main/kotlin/pt/up/fe/ni/website/backend/model/Activity.kt @@ -44,7 +44,7 @@ abstract class Activity( @field:NotBlank open var image: String, - @ElementCollection + @ElementCollection(fetch = FetchType.EAGER) open val gallery: MutableList = mutableListOf(), @Id diff --git a/src/main/kotlin/pt/up/fe/ni/website/backend/service/activity/AbstractActivityService.kt b/src/main/kotlin/pt/up/fe/ni/website/backend/service/activity/AbstractActivityService.kt index b2c802c3..5207b0ee 100644 --- a/src/main/kotlin/pt/up/fe/ni/website/backend/service/activity/AbstractActivityService.kt +++ b/src/main/kotlin/pt/up/fe/ni/website/backend/service/activity/AbstractActivityService.kt @@ -90,9 +90,10 @@ abstract class AbstractActivityService( var imageFolder = "activities" - when (activity::javaClass) { - Event::class -> imageFolder = EventService.IMAGE_FOLDER - Project::class -> imageFolder = ProjectService.IMAGE_FOLDER + if (activity is Event) { + imageFolder = EventService.IMAGE_FOLDER + } else if (activity is Project) { + imageFolder = ProjectService.IMAGE_FOLDER } val fileName = fileUploader.buildFileName(image, activity.title) diff --git a/src/test/kotlin/pt/up/fe/ni/website/backend/controller/EventControllerTest.kt b/src/test/kotlin/pt/up/fe/ni/website/backend/controller/EventControllerTest.kt index 726c48a1..67170474 100644 --- a/src/test/kotlin/pt/up/fe/ni/website/backend/controller/EventControllerTest.kt +++ b/src/test/kotlin/pt/up/fe/ni/website/backend/controller/EventControllerTest.kt @@ -837,7 +837,7 @@ internal class EventControllerTest @Autowired constructor( @Test fun `should add an image`() { - val expectedImagePath = "${uploadConfigProperties.staticServe}/gallery/${testEvent.title}-$uuid.jpeg" + val expectedImagePath = "${uploadConfigProperties.staticServe}/events/gallery/${testEvent.title}-$uuid.jpeg" mockMvc.multipartBuilder("/events/${testEvent.id}/gallery/addImage") .asPutMethod() @@ -898,11 +898,13 @@ internal class EventControllerTest @Autowired constructor( private val uuid: UUID = UUID.randomUUID() private val mockedSettings = Mockito.mockStatic(UUID::class.java) - private val mockImageUrl = "${uploadConfigProperties.staticServe}/gallery/${testEvent.title}-$uuid.jpeg" + private val mockImageUrl = "${uploadConfigProperties.staticServe}/events/gallery/${testEvent.title}-$uuid.jpeg" @BeforeAll fun setupMocks() { Mockito.`when`(UUID.randomUUID()).thenReturn(uuid) + + testEvent.gallery.add(mockImageUrl) } @AfterAll @@ -914,10 +916,7 @@ internal class EventControllerTest @Autowired constructor( fun addToRepositories() { accountRepository.save(testAccount) - val testEventClone = testEvent - - testEvent.gallery.add(mockImageUrl) - repository.save(testEventClone) + repository.save(testEvent) } @Test