From 81f6f7af8a2ef75980598b982ef0358dc1a2d356 Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:04:22 +0100 Subject: [PATCH 01/15] add feature --- .../integration/DeleteEventIntegrationTest.kt | 16 ++++++++++++++++ .../bssweb/event/entity/DetailedEventEntity.kt | 2 +- .../bssweb/video/entity/DetailedVideoEntity.kt | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/integration/src/intTest/kotlin/hu/bsstudio/bssweb/event/integration/DeleteEventIntegrationTest.kt b/integration/src/intTest/kotlin/hu/bsstudio/bssweb/event/integration/DeleteEventIntegrationTest.kt index a4b42616..dbf2d3c7 100644 --- a/integration/src/intTest/kotlin/hu/bsstudio/bssweb/event/integration/DeleteEventIntegrationTest.kt +++ b/integration/src/intTest/kotlin/hu/bsstudio/bssweb/event/integration/DeleteEventIntegrationTest.kt @@ -3,7 +3,10 @@ package hu.bsstudio.bssweb.event.integration import hu.bsstudio.bssweb.IntegrationTest import hu.bsstudio.bssweb.event.client.EventClient import hu.bsstudio.bssweb.event.entity.DetailedEventEntity +import hu.bsstudio.bssweb.eventvideo.entity.EventVideoEntity +import hu.bsstudio.bssweb.video.entity.DetailedVideoEntity import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.longs.shouldBeZero import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.HttpStatusCode @@ -28,4 +31,17 @@ class DeleteEventIntegrationTest( actual.statusCode shouldBeEqual HttpStatusCode.valueOf(204) } + + @Test + fun `it should return 204 when event has video attached`() { + val eventEntity = eventRepository.save(DetailedEventEntity(url = "url", title = "title")) + val videoEntity = videoRepository.save(DetailedVideoEntity(url = "url", title = "title")) + eventVideoRepository.save(EventVideoEntity(eventId = eventEntity.id, videoId = videoEntity.id)) + + val actual = client.deleteEvent(eventEntity.id) + + actual.statusCode shouldBeEqual HttpStatusCode.valueOf(204) + videoRepository.count().shouldBeEqual(1) + eventVideoRepository.count().shouldBeZero() + } } diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt index d51b3219..bfe610a9 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt @@ -25,7 +25,7 @@ data class DetailedEventEntity( @GeneratedValue override lateinit var id: UUID - @OneToMany + @OneToMany(orphanRemoval = true) @JoinTable( name = "event_video", joinColumns = [JoinColumn(name = "event_id")], diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt index 06b1b777..cd17f20f 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt @@ -24,7 +24,7 @@ data class DetailedVideoEntity( @GeneratedValue override lateinit var id: UUID - @OneToMany + @OneToMany(orphanRemoval = true) @JoinColumn(name = "video_id") lateinit var videoCrew: List From 32d313183c4c44d99a9b7e75d918a14216d0048a Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:53:19 +0100 Subject: [PATCH 02/15] wip --- docker-compose.ci.yml | 24 +++++++++++++++ docker-compose.yml | 29 +------------------ server/build.gradle.kts | 1 + .../event/entity/DetailedEventEntity.kt | 3 +- .../video/entity/DetailedVideoEntity.kt | 3 +- .../entity/DetailedVideoCrewEntity.kt | 7 +++-- .../repository/DetailedEventRepositoryTest.kt | 17 +++++++++-- .../event/repository/EventRepositoryTest.kt | 6 +++- .../member/repository/MemberRepositoryTest.kt | 6 +++- .../repository/DetailedVideoRepositoryTest.kt | 29 ++++++++++--------- server/src/main/resources/application.yml | 5 ++++ 11 files changed, 79 insertions(+), 51 deletions(-) diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 990d03db..53387340 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -1,8 +1,32 @@ version: "3.9" services: app: + build: + context: "./" ports: - "8080" + healthcheck: + test: "wget --tries=1 --no-verbose -qO- http://localhost:8080/actuator/health | grep -q UP" + interval: 10s + timeout: 5s + retries: 5 + start_period: 20s + depends_on: + - postgres + - influx + environment: + bss.file-api.url: "http://mock-file-api:8080" + spring.security.user.password: "password" + spring.datasource.url: "jdbc:postgresql://db:5432/postgres?currentSchema=bss_web" + spring.datasource.username: "postgres" + spring.datasource.password: "postgres" + spring.flyway.default-schema: "bss_web" + management.influx.metrics.export.uri: "http://influx:8086" + management.influx.metrics.export.token: "token" + management.influx.metrics.export.org: "org" + management.influx.metrics.export.user-name: "user" + management.influx.metrics.export.password: "password" + management.influx.metrics.export.bucket: "bucket" db: ports: - "5432" diff --git a/docker-compose.yml b/docker-compose.yml index 7198a413..a54f605b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,33 +1,6 @@ version: "3.9" services: - app: - build: - context: "./" - ports: - - "127.0.0.1:8080:8080" - healthcheck: - test: "wget --tries=1 --no-verbose -qO- http://localhost:8080/actuator/health | grep -q UP" - interval: 10s - timeout: 5s - retries: 5 - start_period: 20s - depends_on: - - db - - influx - environment: - bss.file-api.url: "http://mock-file-api:8080" - spring.security.user.password: "password" - spring.datasource.url: "jdbc:postgresql://db:5432/postgres?currentSchema=bss_web" - spring.datasource.username: "postgres" - spring.datasource.password: "postgres" - spring.flyway.default-schema: "bss_web" - management.influx.metrics.export.uri: "http://influx:8086" - management.influx.metrics.export.token: "token" - management.influx.metrics.export.org: "org" - management.influx.metrics.export.user-name: "user" - management.influx.metrics.export.password: "password" - management.influx.metrics.export.bucket: "bucket" - db: + postgres: image: "postgres:16.0-alpine3.18" environment: POSTGRES_PASSWORD: "postgres" diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 1cee90ae..d1dee2ce 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -6,4 +6,5 @@ plugins { dependencies { api(project(":server:web")) runtimeOnly("io.micrometer:micrometer-registry-influx") + developmentOnly("org.springframework.boot:spring-boot-docker-compose") } diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt index bfe610a9..51a88d0c 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt @@ -1,6 +1,7 @@ package hu.bsstudio.bssweb.event.entity import hu.bsstudio.bssweb.video.entity.SimpleVideoEntity +import jakarta.persistence.CascadeType import jakarta.persistence.Entity import jakarta.persistence.GeneratedValue import jakarta.persistence.Id @@ -25,7 +26,7 @@ data class DetailedEventEntity( @GeneratedValue override lateinit var id: UUID - @OneToMany(orphanRemoval = true) + @OneToMany // (cascade = [CascadeType.DETACH]) @JoinTable( name = "event_video", joinColumns = [JoinColumn(name = "event_id")], diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt index cd17f20f..6bfdf913 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt @@ -1,6 +1,7 @@ package hu.bsstudio.bssweb.video.entity import hu.bsstudio.bssweb.videocrew.entity.DetailedVideoCrewEntity +import jakarta.persistence.CascadeType import jakarta.persistence.Entity import jakarta.persistence.GeneratedValue import jakarta.persistence.Id @@ -24,7 +25,7 @@ data class DetailedVideoEntity( @GeneratedValue override lateinit var id: UUID - @OneToMany(orphanRemoval = true) + @OneToMany(cascade = [CascadeType.REMOVE]) @JoinColumn(name = "video_id") lateinit var videoCrew: List diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt index 7624c743..f383aaf4 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt @@ -1,6 +1,7 @@ package hu.bsstudio.bssweb.videocrew.entity import hu.bsstudio.bssweb.member.entity.SimpleMemberEntity +import jakarta.persistence.CascadeType import jakarta.persistence.EmbeddedId import jakarta.persistence.Entity import jakarta.persistence.JoinColumn @@ -13,10 +14,12 @@ import org.hibernate.Hibernate data class DetailedVideoCrewEntity( @EmbeddedId var id: VideoCrewEntityId, +) { + @ManyToOne @JoinColumn(insertable = false, updatable = false) - var member: SimpleMemberEntity -) { + lateinit var member: SimpleMemberEntity + override fun equals(other: Any?): Boolean { if (this === other) return true if (other == null || Hibernate.getClass(this) != Hibernate.getClass(other)) return false diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt index 31438d5e..ba39f5f3 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt @@ -11,6 +11,7 @@ import io.kotest.matchers.longs.shouldBeZero import io.kotest.matchers.optional.shouldBeEmpty import io.kotest.matchers.optional.shouldBePresent import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase @@ -28,6 +29,12 @@ class DetailedEventRepositoryTest( @Autowired private val eventVideoRepository: EventVideoRepository, @Autowired private val entityManager: TestEntityManager ) { + + @AfterEach + fun tearDown() { + entityManager.flush() + } + @Test internal fun `create read delete`() { underTest.count().shouldBeZero() @@ -40,6 +47,8 @@ class DetailedEventRepositoryTest( underTest.findById(id) shouldBePresent { it shouldBeEqualToComparingFields expected } underTest.deleteById(id) + entityManager.flush() + underTest.findById(id).shouldBeEmpty() } @@ -51,13 +60,15 @@ class DetailedEventRepositoryTest( eventVideoRepository.save(EventVideoEntity(eventId = eventId, videoId = video.id)) entityManager.run { flush(); clear() } - val actual = underTest.findById(eventId).orElseThrow() + val actual = underTest.findById(eventId) val expected = createExpected(eventId, listOf(video)) - actual.shouldBeEqualToComparingFields(expected) + actual shouldBePresent { it shouldBeEqualToComparingFields expected } underTest.deleteById(eventId) + entityManager.flush() + underTest.findById(eventId).shouldBeEmpty() - simpleVideoRepository.count().shouldBe(1L) + simpleVideoRepository.findById(video.id).shouldBePresent() } private fun createExpected(id: UUID, videos: List = emptyList()) = diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/EventRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/EventRepositoryTest.kt index 0a9df681..7e12ec31 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/EventRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/EventRepositoryTest.kt @@ -9,12 +9,14 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager import java.time.LocalDate @DataJpaTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) class EventRepositoryTest( - @Autowired private val underTest: SimpleEventRepository + @Autowired private val underTest: SimpleEventRepository, + @Autowired private val entityManager: TestEntityManager ) { @Test @@ -36,6 +38,8 @@ class EventRepositoryTest( } underTest.deleteById(id) + entityManager.flush() + underTest.findById(id).shouldBeEmpty() } diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/member/repository/MemberRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/member/repository/MemberRepositoryTest.kt index b569eb36..e5fab874 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/member/repository/MemberRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/member/repository/MemberRepositoryTest.kt @@ -10,12 +10,14 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager import java.time.LocalDate @DataJpaTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) class MemberRepositoryTest( - @Autowired private val underTest: MemberRepository + @Autowired private val underTest: MemberRepository, + @Autowired private val entityManager: TestEntityManager ) { @Test fun `create read delete`() { @@ -40,6 +42,8 @@ class MemberRepositoryTest( } underTest.deleteById(id) + entityManager.flush() + underTest.findById(id).shouldBeEmpty() } diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt index dd75c053..7351e6d6 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt @@ -1,7 +1,6 @@ package hu.bsstudio.bssweb.video.repository import hu.bsstudio.bssweb.member.entity.DetailedMemberEntity -import hu.bsstudio.bssweb.member.entity.SimpleMemberEntity import hu.bsstudio.bssweb.member.repository.MemberRepository import hu.bsstudio.bssweb.video.entity.DetailedVideoEntity import hu.bsstudio.bssweb.video.entity.SimpleVideoEntity @@ -18,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager +import org.testcontainers.shaded.org.bouncycastle.asn1.x500.style.RFC4519Style.member import java.time.LocalDate import java.util.UUID @@ -26,7 +26,6 @@ import java.util.UUID class DetailedVideoRepositoryTest( @Autowired private val underTest: DetailedVideoRepository, @Autowired private val memberRepository: MemberRepository, - @Autowired private val simpleVideoRepository: SimpleVideoRepository, @Autowired private val videoCrewRepository: VideoCrewRepository, @Autowired private val entityManager: TestEntityManager ) { @@ -42,25 +41,27 @@ class DetailedVideoRepositoryTest( underTest.findById(id) shouldBePresent { it shouldBeEqualToComparingFields expected } underTest.deleteById(id) + entityManager.flush() + underTest.findById(id).shouldBeEmpty() } @Test internal fun `create read delete with crew`() { - val memberId = DetailedMemberEntity(name = MEMBER_NAME, url = MEMBER_URL, nickname = MEMBER_NICKNAME) - .let { this.memberRepository.save(it) } - .id + val member = DetailedMemberEntity(name = MEMBER_NAME, url = MEMBER_URL, nickname = MEMBER_NICKNAME) + .let { this.entityManager.persist(it) } val videoId = SimpleVideoEntity(url = URL, title = TITLE) - .let { this.simpleVideoRepository.save(it) } - .id - val videoCrewId = VideoCrewEntityId(videoId, "cameraman", memberId) - this.videoCrewRepository.save(VideoCrewEntity(videoCrewId)) - entityManager.run { flush(); clear() } + .let { this.entityManager.persistAndGetId(it, UUID::class.java) } + this.entityManager.persist(VideoCrewEntity(VideoCrewEntityId(videoId, "cameraman", member.id))) + this.entityManager.flush() + + val video = underTest.findById(videoId).shouldBePresent() + + underTest.deleteById(video.id) + // todo entityManager.flush() - val expected = createExpected(videoId, listOf(DetailedVideoCrewEntity(videoCrewId, SimpleMemberEntity(MEMBER_NAME, MEMBER_NICKNAME).apply { id = memberId }))) - underTest.findById(videoId) - .shouldBePresent() - .shouldBeEqualToComparingFields(expected) + underTest.findById(videoId).shouldBeEmpty() + memberRepository.findById(member.id).shouldBePresent() } private fun createExpected(id: UUID, videoCrew: List = emptyList()) = diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 4e0a5087..bcd67364 100644 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -3,6 +3,11 @@ spring: name: BSS Web admin API jpa: open-in-view: false + cloud: + discovery: + client: + composite-indicator: + enabled: false springdoc: swagger-ui: url: /open-api.yaml From c6c36a72da8d099a1edfcd7d41677d7a622dfcf9 Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Thu, 19 Oct 2023 07:45:40 +0100 Subject: [PATCH 03/15] wip --- .../event/entity/DetailedEventEntity.kt | 2 +- .../video/entity/DetailedVideoEntity.kt | 3 +- .../entity/DetailedVideoCrewEntity.kt | 1 - .../repository/DetailedEventRepositoryTest.kt | 17 +++------- .../repository/EventVideoRepositoryTest.kt | 16 ++++++---- .../repository/DetailedVideoRepositoryTest.kt | 32 +------------------ .../repository/SimpleVideoRepositoryTest.kt | 6 +++- .../repository/VideoCrewRepositoryTest.kt | 19 +++++++---- .../videocrew/mapper/VideoCrewMapper.kt | 6 +++- .../videocrew/mapper/VideoCrewMapperTest.kt | 4 +-- 10 files changed, 42 insertions(+), 64 deletions(-) diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt index 51a88d0c..2570fd1b 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt @@ -26,7 +26,7 @@ data class DetailedEventEntity( @GeneratedValue override lateinit var id: UUID - @OneToMany // (cascade = [CascadeType.DETACH]) + @OneToMany @JoinTable( name = "event_video", joinColumns = [JoinColumn(name = "event_id")], diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt index 6bfdf913..ba9c27bc 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt @@ -3,6 +3,7 @@ package hu.bsstudio.bssweb.video.entity import hu.bsstudio.bssweb.videocrew.entity.DetailedVideoCrewEntity import jakarta.persistence.CascadeType import jakarta.persistence.Entity +import jakarta.persistence.ForeignKey import jakarta.persistence.GeneratedValue import jakarta.persistence.Id import jakarta.persistence.JoinColumn @@ -25,7 +26,7 @@ data class DetailedVideoEntity( @GeneratedValue override lateinit var id: UUID - @OneToMany(cascade = [CascadeType.REMOVE]) + @OneToMany @JoinColumn(name = "video_id") lateinit var videoCrew: List diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt index f383aaf4..c6950de7 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt @@ -1,7 +1,6 @@ package hu.bsstudio.bssweb.videocrew.entity import hu.bsstudio.bssweb.member.entity.SimpleMemberEntity -import jakarta.persistence.CascadeType import jakarta.persistence.EmbeddedId import jakarta.persistence.Entity import jakarta.persistence.JoinColumn diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt index ba39f5f3..233618c1 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt @@ -3,14 +3,12 @@ package hu.bsstudio.bssweb.event.repository import hu.bsstudio.bssweb.event.entity.DetailedEventEntity import hu.bsstudio.bssweb.event.entity.SimpleEventEntity import hu.bsstudio.bssweb.eventvideo.entity.EventVideoEntity -import hu.bsstudio.bssweb.eventvideo.repository.EventVideoRepository import hu.bsstudio.bssweb.video.entity.SimpleVideoEntity -import hu.bsstudio.bssweb.video.repository.SimpleVideoRepository import io.kotest.matchers.equality.shouldBeEqualToComparingFields import io.kotest.matchers.longs.shouldBeZero +import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.optional.shouldBeEmpty import io.kotest.matchers.optional.shouldBePresent -import io.kotest.matchers.shouldBe import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired @@ -24,9 +22,6 @@ import java.util.UUID @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) class DetailedEventRepositoryTest( @Autowired private val underTest: DetailedEventRepository, - @Autowired private val simpleEventRepository: SimpleEventRepository, - @Autowired private val simpleVideoRepository: SimpleVideoRepository, - @Autowired private val eventVideoRepository: EventVideoRepository, @Autowired private val entityManager: TestEntityManager ) { @@ -54,11 +49,9 @@ class DetailedEventRepositoryTest( @Test internal fun `create read delete with video`() { - val eventId = simpleEventRepository.save(SimpleEventEntity(url = URL, title = TITLE)).id - val video = simpleVideoRepository.save(SimpleVideoEntity(url = "url", title = "title")) - - eventVideoRepository.save(EventVideoEntity(eventId = eventId, videoId = video.id)) - entityManager.run { flush(); clear() } + val eventId = entityManager.persistAndGetId(SimpleEventEntity(url = URL, title = TITLE), UUID::class.java) + val video = entityManager.persist(SimpleVideoEntity(url = "url", title = "title")) + entityManager.persistAndFlush(EventVideoEntity(eventId = eventId, videoId = video.id)) val actual = underTest.findById(eventId) val expected = createExpected(eventId, listOf(video)) @@ -68,7 +61,7 @@ class DetailedEventRepositoryTest( entityManager.flush() underTest.findById(eventId).shouldBeEmpty() - simpleVideoRepository.findById(video.id).shouldBePresent() + entityManager.find(SimpleVideoEntity::class.java, video.id).shouldNotBeNull() } private fun createExpected(id: UUID, videos: List = emptyList()) = diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/eventvideo/repository/EventVideoRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/eventvideo/repository/EventVideoRepositoryTest.kt index 0cdc4745..89d87e62 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/eventvideo/repository/EventVideoRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/eventvideo/repository/EventVideoRepositoryTest.kt @@ -6,6 +6,7 @@ import hu.bsstudio.bssweb.eventvideo.entity.EventVideoEntity import hu.bsstudio.bssweb.video.entity.SimpleVideoEntity import hu.bsstudio.bssweb.video.repository.SimpleVideoRepository import io.kotest.matchers.equality.shouldBeEqualToComparingFields +import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.optional.shouldBeEmpty import io.kotest.matchers.optional.shouldBePresent import io.kotest.matchers.shouldBe @@ -13,19 +14,20 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager +import java.util.UUID @DataJpaTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) class EventVideoRepositoryTest( - @Autowired private val eventRepository: SimpleEventRepository, - @Autowired private val videoRepository: SimpleVideoRepository, - @Autowired private val underTest: EventVideoRepository + @Autowired private val underTest: EventVideoRepository, + @Autowired private val entityManager: TestEntityManager ) { @Test fun `create read delete`() { - val videoId = videoRepository.save(SimpleVideoEntity(url = "url", title = "title")).id - val eventId = eventRepository.save(SimpleEventEntity(url = "url", title = "title")).id + val videoId = entityManager.persistAndGetId(SimpleVideoEntity(url = "url", title = "title"), UUID::class.java) + val eventId = entityManager.persistAndGetId(SimpleEventEntity(url = "url", title = "title"), UUID::class.java) val entity = EventVideoEntity(eventId, videoId) underTest.save(entity) @@ -34,7 +36,7 @@ class EventVideoRepositoryTest( underTest.deleteById(entity) underTest.findById(entity).shouldBeEmpty() - videoRepository.count().shouldBe(1L) - eventRepository.count().shouldBe(1L) + entityManager.find(SimpleVideoEntity::class.java, videoId).shouldNotBeNull() + entityManager.find(SimpleEventEntity::class.java, eventId).shouldNotBeNull() } } diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt index 7351e6d6..11a7b179 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt @@ -1,13 +1,7 @@ package hu.bsstudio.bssweb.video.repository -import hu.bsstudio.bssweb.member.entity.DetailedMemberEntity -import hu.bsstudio.bssweb.member.repository.MemberRepository import hu.bsstudio.bssweb.video.entity.DetailedVideoEntity -import hu.bsstudio.bssweb.video.entity.SimpleVideoEntity import hu.bsstudio.bssweb.videocrew.entity.DetailedVideoCrewEntity -import hu.bsstudio.bssweb.videocrew.entity.VideoCrewEntity -import hu.bsstudio.bssweb.videocrew.entity.VideoCrewEntityId -import hu.bsstudio.bssweb.videocrew.repository.VideoCrewRepository import io.kotest.matchers.equality.shouldBeEqualToComparingFields import io.kotest.matchers.longs.shouldBeZero import io.kotest.matchers.optional.shouldBeEmpty @@ -17,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager -import org.testcontainers.shaded.org.bouncycastle.asn1.x500.style.RFC4519Style.member import java.time.LocalDate import java.util.UUID @@ -25,8 +18,6 @@ import java.util.UUID @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) class DetailedVideoRepositoryTest( @Autowired private val underTest: DetailedVideoRepository, - @Autowired private val memberRepository: MemberRepository, - @Autowired private val videoCrewRepository: VideoCrewRepository, @Autowired private val entityManager: TestEntityManager ) { @Test @@ -35,7 +26,7 @@ class DetailedVideoRepositoryTest( val entity = DetailedVideoEntity(url = URL, title = TITLE) val id = underTest.save(entity).id - entityManager.run { flush(); clear() } + // entityManager.run { flush(); clear() } val expected = createExpected(id) underTest.findById(id) shouldBePresent { it shouldBeEqualToComparingFields expected } @@ -46,24 +37,6 @@ class DetailedVideoRepositoryTest( underTest.findById(id).shouldBeEmpty() } - @Test - internal fun `create read delete with crew`() { - val member = DetailedMemberEntity(name = MEMBER_NAME, url = MEMBER_URL, nickname = MEMBER_NICKNAME) - .let { this.entityManager.persist(it) } - val videoId = SimpleVideoEntity(url = URL, title = TITLE) - .let { this.entityManager.persistAndGetId(it, UUID::class.java) } - this.entityManager.persist(VideoCrewEntity(VideoCrewEntityId(videoId, "cameraman", member.id))) - this.entityManager.flush() - - val video = underTest.findById(videoId).shouldBePresent() - - underTest.deleteById(video.id) - // todo entityManager.flush() - - underTest.findById(videoId).shouldBeEmpty() - memberRepository.findById(member.id).shouldBePresent() - } - private fun createExpected(id: UUID, videoCrew: List = emptyList()) = DetailedVideoEntity( url = URL, @@ -79,8 +52,5 @@ class DetailedVideoRepositoryTest( private companion object { private const val URL = "szobakommando" private const val TITLE = "Szobakommando" - private const val MEMBER_NAME = "Bence Csik" - private const val MEMBER_URL = "bcsik" - private const val MEMBER_NICKNAME = "CséBé" } } diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/SimpleVideoRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/SimpleVideoRepositoryTest.kt index 7c184522..8de69d8e 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/SimpleVideoRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/SimpleVideoRepositoryTest.kt @@ -9,12 +9,14 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager import java.time.LocalDate @DataJpaTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) class SimpleVideoRepositoryTest( - @Autowired private val underTest: SimpleVideoRepository + @Autowired private val underTest: SimpleVideoRepository, + @Autowired private val entityManager: TestEntityManager ) { @Test @@ -36,6 +38,8 @@ class SimpleVideoRepositoryTest( } underTest.deleteById(id) + entityManager.flush() + underTest.findById(id).shouldBeEmpty() } diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/videocrew/repository/VideoCrewRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/videocrew/repository/VideoCrewRepositoryTest.kt index 142ce86c..82f8d162 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/videocrew/repository/VideoCrewRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/videocrew/repository/VideoCrewRepositoryTest.kt @@ -7,6 +7,7 @@ import hu.bsstudio.bssweb.video.repository.SimpleVideoRepository import hu.bsstudio.bssweb.videocrew.entity.VideoCrewEntity import hu.bsstudio.bssweb.videocrew.entity.VideoCrewEntityId import io.kotest.matchers.equality.shouldBeEqualToComparingFields +import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.optional.shouldBeEmpty import io.kotest.matchers.optional.shouldBePresent import io.kotest.matchers.shouldBe @@ -14,28 +15,32 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager +import org.springframework.data.jpa.domain.AbstractPersistable_.id +import java.util.UUID @DataJpaTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) class VideoCrewRepositoryTest( @Autowired private val underTest: VideoCrewRepository, - @Autowired private val memberRepository: MemberRepository, - @Autowired private val videoRepository: SimpleVideoRepository + @Autowired private val entityManager: TestEntityManager ) { @Test fun `create read delete`() { - val memberId = memberRepository.save(DetailedMemberEntity(url = "url", name = "name")).id - val videoId = videoRepository.save(SimpleVideoEntity(url = "url", title = "title")).id + val memberId = entityManager.persistAndGetId(DetailedMemberEntity(url = "url", name = "name"), UUID::class.java) + val videoId = entityManager.persistAndGetId(SimpleVideoEntity(url = "url", title = "title"), UUID::class.java) + val entity = VideoCrewEntity(VideoCrewEntityId(videoId, "cameraMan", memberId)) val id = VideoCrewEntityId(videoId, "cameraMan", memberId) - val entity = VideoCrewEntity(id) underTest.save(entity) underTest.findById(id) shouldBePresent { it shouldBeEqualToComparingFields entity } underTest.deleteById(id) + entityManager.flush() + underTest.findById(id).shouldBeEmpty() - memberRepository.count().shouldBe(1L) - videoRepository.count().shouldBe(1L) + entityManager.find(DetailedMemberEntity::class.java, memberId).shouldNotBeNull() + entityManager.find(SimpleVideoEntity::class.java, videoId).shouldNotBeNull() } } diff --git a/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt b/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt index 8f40a440..666041e3 100644 --- a/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt +++ b/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt @@ -18,7 +18,11 @@ class VideoCrewMapper(private val memberMapper: MemberMapper) { } fun modelToEntity(model: VideoCrewRequest): VideoCrewEntity { - return VideoCrewEntity(id = this.modelToId(model)) + return VideoCrewEntity( + videoId = model.videoId, + position = model.position, + memberId = model.memberId + ) } fun entityToModel(entity: DetailedVideoCrewEntity): VideoCrew { diff --git a/server/service/src/test/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapperTest.kt b/server/service/src/test/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapperTest.kt index 92d57baa..6ea69d4f 100644 --- a/server/service/src/test/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapperTest.kt +++ b/server/service/src/test/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapperTest.kt @@ -57,8 +57,8 @@ internal class VideoCrewMapperTest( private val VIDEO_CREW = VideoCrew(VIDEO_ID, POSITION, MEMBER) private val VIDEO_CREW_REQUEST = VideoCrewRequest(VIDEO_ID, POSITION, MEMBER_ID) private val VIDEO_CREW_ENTITY_ID = VideoCrewEntityId(VIDEO_ID, POSITION, MEMBER_ID) - private val VIDEO_CREW_ENTITY = VideoCrewEntity(VIDEO_CREW_ENTITY_ID) + private val VIDEO_CREW_ENTITY = VideoCrewEntity(VIDEO_ID, POSITION, MEMBER_ID) private val MEMBER_ENTITY = SimpleMemberEntity("name", "nickname").apply { id = MEMBER_ID } - private val DETAILED_VIDEO_CREW_ENTITY = DetailedVideoCrewEntity(id = VIDEO_CREW_ENTITY_ID, member = MEMBER_ENTITY) + private val DETAILED_VIDEO_CREW_ENTITY = DetailedVideoCrewEntity(id = VIDEO_CREW_ENTITY_ID).apply { member = MEMBER_ENTITY } } } From 222055a749574690fa62a47e5856ab7dc114c236 Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:26:11 +0100 Subject: [PATCH 04/15] WIP --- docker-compose.ci.yml | 24 ------------------------ docker-compose.yml | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 53387340..990d03db 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -1,32 +1,8 @@ version: "3.9" services: app: - build: - context: "./" ports: - "8080" - healthcheck: - test: "wget --tries=1 --no-verbose -qO- http://localhost:8080/actuator/health | grep -q UP" - interval: 10s - timeout: 5s - retries: 5 - start_period: 20s - depends_on: - - postgres - - influx - environment: - bss.file-api.url: "http://mock-file-api:8080" - spring.security.user.password: "password" - spring.datasource.url: "jdbc:postgresql://db:5432/postgres?currentSchema=bss_web" - spring.datasource.username: "postgres" - spring.datasource.password: "postgres" - spring.flyway.default-schema: "bss_web" - management.influx.metrics.export.uri: "http://influx:8086" - management.influx.metrics.export.token: "token" - management.influx.metrics.export.org: "org" - management.influx.metrics.export.user-name: "user" - management.influx.metrics.export.password: "password" - management.influx.metrics.export.bucket: "bucket" db: ports: - "5432" diff --git a/docker-compose.yml b/docker-compose.yml index a54f605b..7f4d1dee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,32 @@ version: "3.9" services: + app: + build: + context: "./" + ports: + - "8080" + healthcheck: + test: "wget --tries=1 --no-verbose -qO- http://localhost:8080/actuator/health | grep -q UP" + interval: 10s + timeout: 5s + retries: 5 + start_period: 20s + depends_on: + - postgres + - influx + environment: + bss.file-api.url: "http://mock-file-api:8080" + spring.security.user.password: "password" + spring.datasource.url: "jdbc:postgresql://db:5432/postgres?currentSchema=bss_web" + spring.datasource.username: "postgres" + spring.datasource.password: "postgres" + spring.flyway.default-schema: "bss_web" + management.influx.metrics.export.uri: "http://influx:8086" + management.influx.metrics.export.token: "token" + management.influx.metrics.export.org: "org" + management.influx.metrics.export.user-name: "user" + management.influx.metrics.export.password: "password" + management.influx.metrics.export.bucket: "bucket" postgres: image: "postgres:16.0-alpine3.18" environment: From c78442a84e54cb176e192159772a48b8c8ed28ac Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:28:42 +0100 Subject: [PATCH 05/15] WIP --- server/build.gradle.kts | 1 - .../hu/bsstudio/bssweb/TestEntityManagerDsl.kt | 15 +++++++++++++++ .../repository/DetailedEventRepositoryTest.kt | 11 ++++------- .../repository/VideoCrewRepositoryTest.kt | 14 ++++++-------- 4 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 server/data/src/test/kotlin/hu/bsstudio/bssweb/TestEntityManagerDsl.kt diff --git a/server/build.gradle.kts b/server/build.gradle.kts index d1dee2ce..1cee90ae 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -6,5 +6,4 @@ plugins { dependencies { api(project(":server:web")) runtimeOnly("io.micrometer:micrometer-registry-influx") - developmentOnly("org.springframework.boot:spring-boot-docker-compose") } diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/TestEntityManagerDsl.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/TestEntityManagerDsl.kt new file mode 100644 index 00000000..6c175c67 --- /dev/null +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/TestEntityManagerDsl.kt @@ -0,0 +1,15 @@ +package hu.bsstudio.bssweb + +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager + +inline fun TestEntityManager.find(primaryKey: Any?): T { + return this.find(T::class.java, primaryKey) +} + +inline fun TestEntityManager.persistAndGetId(entity: Any): T { + return this.persistAndGetId(entity, T::class.java) +} + +inline fun TestEntityManager.getId(entity: Any): T { + return this.getId(entity, T::class.java) +} diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt index 233618c1..b8ad6809 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt @@ -3,6 +3,8 @@ package hu.bsstudio.bssweb.event.repository import hu.bsstudio.bssweb.event.entity.DetailedEventEntity import hu.bsstudio.bssweb.event.entity.SimpleEventEntity import hu.bsstudio.bssweb.eventvideo.entity.EventVideoEntity +import hu.bsstudio.bssweb.find +import hu.bsstudio.bssweb.persistAndGetId import hu.bsstudio.bssweb.video.entity.SimpleVideoEntity import io.kotest.matchers.equality.shouldBeEqualToComparingFields import io.kotest.matchers.longs.shouldBeZero @@ -25,11 +27,6 @@ class DetailedEventRepositoryTest( @Autowired private val entityManager: TestEntityManager ) { - @AfterEach - fun tearDown() { - entityManager.flush() - } - @Test internal fun `create read delete`() { underTest.count().shouldBeZero() @@ -49,7 +46,7 @@ class DetailedEventRepositoryTest( @Test internal fun `create read delete with video`() { - val eventId = entityManager.persistAndGetId(SimpleEventEntity(url = URL, title = TITLE), UUID::class.java) + val eventId = entityManager.persistAndGetId(SimpleEventEntity(url = URL, title = TITLE)) val video = entityManager.persist(SimpleVideoEntity(url = "url", title = "title")) entityManager.persistAndFlush(EventVideoEntity(eventId = eventId, videoId = video.id)) @@ -61,7 +58,7 @@ class DetailedEventRepositoryTest( entityManager.flush() underTest.findById(eventId).shouldBeEmpty() - entityManager.find(SimpleVideoEntity::class.java, video.id).shouldNotBeNull() + entityManager.find(video.id).shouldNotBeNull() } private fun createExpected(id: UUID, videos: List = emptyList()) = diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/videocrew/repository/VideoCrewRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/videocrew/repository/VideoCrewRepositoryTest.kt index 82f8d162..d1bf2238 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/videocrew/repository/VideoCrewRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/videocrew/repository/VideoCrewRepositoryTest.kt @@ -1,22 +1,20 @@ package hu.bsstudio.bssweb.videocrew.repository +import hu.bsstudio.bssweb.find import hu.bsstudio.bssweb.member.entity.DetailedMemberEntity -import hu.bsstudio.bssweb.member.repository.MemberRepository +import hu.bsstudio.bssweb.persistAndGetId import hu.bsstudio.bssweb.video.entity.SimpleVideoEntity -import hu.bsstudio.bssweb.video.repository.SimpleVideoRepository import hu.bsstudio.bssweb.videocrew.entity.VideoCrewEntity import hu.bsstudio.bssweb.videocrew.entity.VideoCrewEntityId import io.kotest.matchers.equality.shouldBeEqualToComparingFields import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.optional.shouldBeEmpty import io.kotest.matchers.optional.shouldBePresent -import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager -import org.springframework.data.jpa.domain.AbstractPersistable_.id import java.util.UUID @DataJpaTest @@ -28,8 +26,8 @@ class VideoCrewRepositoryTest( @Test fun `create read delete`() { - val memberId = entityManager.persistAndGetId(DetailedMemberEntity(url = "url", name = "name"), UUID::class.java) - val videoId = entityManager.persistAndGetId(SimpleVideoEntity(url = "url", title = "title"), UUID::class.java) + val memberId = entityManager.persistAndGetId(DetailedMemberEntity(url = "url", name = "name")) + val videoId = entityManager.persistAndGetId(SimpleVideoEntity(url = "url", title = "title")) val entity = VideoCrewEntity(VideoCrewEntityId(videoId, "cameraMan", memberId)) val id = VideoCrewEntityId(videoId, "cameraMan", memberId) @@ -40,7 +38,7 @@ class VideoCrewRepositoryTest( entityManager.flush() underTest.findById(id).shouldBeEmpty() - entityManager.find(DetailedMemberEntity::class.java, memberId).shouldNotBeNull() - entityManager.find(SimpleVideoEntity::class.java, videoId).shouldNotBeNull() + entityManager.find(memberId).shouldNotBeNull() + entityManager.find(videoId).shouldNotBeNull() } } From 5554a6861b8592799c6332a448aef0b62c64fe71 Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:30:08 +0100 Subject: [PATCH 06/15] Update server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt --- .../hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt index 2570fd1b..d51b3219 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/event/entity/DetailedEventEntity.kt @@ -1,7 +1,6 @@ package hu.bsstudio.bssweb.event.entity import hu.bsstudio.bssweb.video.entity.SimpleVideoEntity -import jakarta.persistence.CascadeType import jakarta.persistence.Entity import jakarta.persistence.GeneratedValue import jakarta.persistence.Id From 874e94f4f51530603fc77fcac30a54e1e7e2b663 Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:30:24 +0100 Subject: [PATCH 07/15] Update server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt --- .../hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt index ba9c27bc..c2391b66 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt @@ -1,7 +1,6 @@ package hu.bsstudio.bssweb.video.entity import hu.bsstudio.bssweb.videocrew.entity.DetailedVideoCrewEntity -import jakarta.persistence.CascadeType import jakarta.persistence.Entity import jakarta.persistence.ForeignKey import jakarta.persistence.GeneratedValue From 07b9a4531164df70e6921ed7b1279dbb057e3bb8 Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:30:37 +0100 Subject: [PATCH 08/15] Update server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt --- .../hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt index c2391b66..06b1b777 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/video/entity/DetailedVideoEntity.kt @@ -2,7 +2,6 @@ package hu.bsstudio.bssweb.video.entity import hu.bsstudio.bssweb.videocrew.entity.DetailedVideoCrewEntity import jakarta.persistence.Entity -import jakarta.persistence.ForeignKey import jakarta.persistence.GeneratedValue import jakarta.persistence.Id import jakarta.persistence.JoinColumn From 4fa1997981f168df5bf7ef0830227a61b8dd774a Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:32:31 +0100 Subject: [PATCH 09/15] WIP --- .../hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt b/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt index 666041e3..ea6d3db3 100644 --- a/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt +++ b/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt @@ -18,11 +18,7 @@ class VideoCrewMapper(private val memberMapper: MemberMapper) { } fun modelToEntity(model: VideoCrewRequest): VideoCrewEntity { - return VideoCrewEntity( - videoId = model.videoId, - position = model.position, - memberId = model.memberId - ) + return VideoCrewEntity(this.modelToId(model)) } fun entityToModel(entity: DetailedVideoCrewEntity): VideoCrew { From 6aa9bd1f285233dc6e5422af4e793993d159f89a Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:38:42 +0100 Subject: [PATCH 10/15] WIP --- docker-compose.ci.yml | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 990d03db..9fd30fa1 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -3,7 +3,7 @@ services: app: ports: - "8080" - db: + postgres: ports: - "5432" influx: diff --git a/docker-compose.yml b/docker-compose.yml index 7f4d1dee..6c1d75dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: build: context: "./" ports: - - "8080" + - "127.0.0.1:8080:8080" healthcheck: test: "wget --tries=1 --no-verbose -qO- http://localhost:8080/actuator/health | grep -q UP" interval: 10s From 25ef87a1cb990e8d63cb0115235d28de44926781 Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:40:45 +0100 Subject: [PATCH 11/15] WIP --- .../repository/EventVideoRepositoryTest.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/eventvideo/repository/EventVideoRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/eventvideo/repository/EventVideoRepositoryTest.kt index 89d87e62..86fc7283 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/eventvideo/repository/EventVideoRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/eventvideo/repository/EventVideoRepositoryTest.kt @@ -1,15 +1,14 @@ package hu.bsstudio.bssweb.eventvideo.repository import hu.bsstudio.bssweb.event.entity.SimpleEventEntity -import hu.bsstudio.bssweb.event.repository.SimpleEventRepository import hu.bsstudio.bssweb.eventvideo.entity.EventVideoEntity +import hu.bsstudio.bssweb.find +import hu.bsstudio.bssweb.persistAndGetId import hu.bsstudio.bssweb.video.entity.SimpleVideoEntity -import hu.bsstudio.bssweb.video.repository.SimpleVideoRepository import io.kotest.matchers.equality.shouldBeEqualToComparingFields import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.optional.shouldBeEmpty import io.kotest.matchers.optional.shouldBePresent -import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase @@ -26,8 +25,8 @@ class EventVideoRepositoryTest( @Test fun `create read delete`() { - val videoId = entityManager.persistAndGetId(SimpleVideoEntity(url = "url", title = "title"), UUID::class.java) - val eventId = entityManager.persistAndGetId(SimpleEventEntity(url = "url", title = "title"), UUID::class.java) + val videoId = entityManager.persistAndGetId(SimpleVideoEntity(url = "url", title = "title")) + val eventId = entityManager.persistAndGetId(SimpleEventEntity(url = "url", title = "title")) val entity = EventVideoEntity(eventId, videoId) underTest.save(entity) @@ -35,8 +34,10 @@ class EventVideoRepositoryTest( underTest.findById(entity) shouldBePresent { it shouldBeEqualToComparingFields entity } underTest.deleteById(entity) + entityManager.flush() + underTest.findById(entity).shouldBeEmpty() - entityManager.find(SimpleVideoEntity::class.java, videoId).shouldNotBeNull() - entityManager.find(SimpleEventEntity::class.java, eventId).shouldNotBeNull() + entityManager.find(videoId).shouldNotBeNull() + entityManager.find(eventId).shouldNotBeNull() } } From 4ecaff40803df498a3ae761890b2f69c7111a795 Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:08:00 +0100 Subject: [PATCH 12/15] WIP --- .../bssweb/video/repository/DetailedVideoRepositoryTest.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt index 11a7b179..02a2632a 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/video/repository/DetailedVideoRepositoryTest.kt @@ -1,7 +1,6 @@ package hu.bsstudio.bssweb.video.repository import hu.bsstudio.bssweb.video.entity.DetailedVideoEntity -import hu.bsstudio.bssweb.videocrew.entity.DetailedVideoCrewEntity import io.kotest.matchers.equality.shouldBeEqualToComparingFields import io.kotest.matchers.longs.shouldBeZero import io.kotest.matchers.optional.shouldBeEmpty @@ -26,7 +25,7 @@ class DetailedVideoRepositoryTest( val entity = DetailedVideoEntity(url = URL, title = TITLE) val id = underTest.save(entity).id - // entityManager.run { flush(); clear() } + entityManager.run { flush(); clear() } val expected = createExpected(id) underTest.findById(id) shouldBePresent { it shouldBeEqualToComparingFields expected } @@ -37,7 +36,7 @@ class DetailedVideoRepositoryTest( underTest.findById(id).shouldBeEmpty() } - private fun createExpected(id: UUID, videoCrew: List = emptyList()) = + private fun createExpected(id: UUID) = DetailedVideoEntity( url = URL, title = TITLE, @@ -46,7 +45,7 @@ class DetailedVideoRepositoryTest( visible = false ).apply { this.id = id - this.videoCrew = videoCrew + this.videoCrew = emptyList() } private companion object { From c44ddc55ece016f5d548daaa69caf42e3fa5ed92 Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:16:14 +0100 Subject: [PATCH 13/15] WIP --- .../bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt | 2 +- .../bssweb/event/repository/DetailedEventRepositoryTest.kt | 1 - .../hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapperTest.kt | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt b/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt index c6950de7..8b09a3cc 100644 --- a/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt +++ b/server/data/src/main/kotlin/hu/bsstudio/bssweb/videocrew/entity/DetailedVideoCrewEntity.kt @@ -12,7 +12,7 @@ import org.hibernate.Hibernate @Table(name = "crew") data class DetailedVideoCrewEntity( @EmbeddedId - var id: VideoCrewEntityId, + var id: VideoCrewEntityId ) { @ManyToOne diff --git a/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt b/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt index b8ad6809..85c9bee9 100644 --- a/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt +++ b/server/data/src/test/kotlin/hu/bsstudio/bssweb/event/repository/DetailedEventRepositoryTest.kt @@ -11,7 +11,6 @@ import io.kotest.matchers.longs.shouldBeZero import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.optional.shouldBeEmpty import io.kotest.matchers.optional.shouldBePresent -import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase diff --git a/server/service/src/test/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapperTest.kt b/server/service/src/test/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapperTest.kt index 6ea69d4f..88d53875 100644 --- a/server/service/src/test/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapperTest.kt +++ b/server/service/src/test/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapperTest.kt @@ -57,7 +57,7 @@ internal class VideoCrewMapperTest( private val VIDEO_CREW = VideoCrew(VIDEO_ID, POSITION, MEMBER) private val VIDEO_CREW_REQUEST = VideoCrewRequest(VIDEO_ID, POSITION, MEMBER_ID) private val VIDEO_CREW_ENTITY_ID = VideoCrewEntityId(VIDEO_ID, POSITION, MEMBER_ID) - private val VIDEO_CREW_ENTITY = VideoCrewEntity(VIDEO_ID, POSITION, MEMBER_ID) + private val VIDEO_CREW_ENTITY = VideoCrewEntity(VIDEO_CREW_ENTITY_ID) private val MEMBER_ENTITY = SimpleMemberEntity("name", "nickname").apply { id = MEMBER_ID } private val DETAILED_VIDEO_CREW_ENTITY = DetailedVideoCrewEntity(id = VIDEO_CREW_ENTITY_ID).apply { member = MEMBER_ENTITY } } From 286cf77570e627a3e9e200793949f54f55c5d90d Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:41:19 +0100 Subject: [PATCH 14/15] Update server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt --- .../hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt b/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt index ea6d3db3..8f40a440 100644 --- a/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt +++ b/server/service/src/main/kotlin/hu/bsstudio/bssweb/videocrew/mapper/VideoCrewMapper.kt @@ -18,7 +18,7 @@ class VideoCrewMapper(private val memberMapper: MemberMapper) { } fun modelToEntity(model: VideoCrewRequest): VideoCrewEntity { - return VideoCrewEntity(this.modelToId(model)) + return VideoCrewEntity(id = this.modelToId(model)) } fun entityToModel(entity: DetailedVideoCrewEntity): VideoCrew { From 0bbecbf9256df36d2c9607c9f6f5d93b68f55e59 Mon Sep 17 00:00:00 2001 From: Bence Csik <22349790+csikb@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:42:24 +0100 Subject: [PATCH 15/15] WIP --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8930ab90..150dfb8f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: environment: bss.file-api.url: "http://mock-file-api:8080" spring.security.user.password: "password" - spring.datasource.url: "jdbc:postgresql://db:5432/postgres?currentSchema=bss_web" + spring.datasource.url: "jdbc:postgresql://postgres:5432/postgres?currentSchema=bss_web" spring.datasource.username: "postgres" spring.datasource.password: "postgres" spring.flyway.default-schema: "bss_web"