From c5ae6032c9f80e55c647898cab7bf437102e9aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20M=C3=BCller?= Date: Thu, 23 Jul 2026 13:41:43 +0200 Subject: [PATCH] feat(community): add findAllWithDetails query to MembershipRepository Add @Query with JOIN FETCH on meteringPoint and energyCommunity, no WHERE clause to return all memberships regardless of status. Includes reflection-based unit test verifying method existence and annotation correctness. --- .../repository/MembershipRepository.java | 3 ++ .../repository/MembershipRepositoryTest.java | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 eeg_backend/src/test/java/at/mueller/eeg/backend/community/repository/MembershipRepositoryTest.java diff --git a/eeg_backend/src/main/java/at/mueller/eeg/backend/community/repository/MembershipRepository.java b/eeg_backend/src/main/java/at/mueller/eeg/backend/community/repository/MembershipRepository.java index b0afec0..0a14401 100644 --- a/eeg_backend/src/main/java/at/mueller/eeg/backend/community/repository/MembershipRepository.java +++ b/eeg_backend/src/main/java/at/mueller/eeg/backend/community/repository/MembershipRepository.java @@ -37,6 +37,9 @@ public interface MembershipRepository extends JpaRepository { @Query("SELECT m FROM Membership m JOIN FETCH m.meteringPoint mp JOIN FETCH m.energyCommunity ec WHERE m.status = 'PENDING'") List findPendingWithDetails(); + @Query("SELECT m FROM Membership m JOIN FETCH m.meteringPoint mp JOIN FETCH m.energyCommunity ec") + List findAllWithDetails(); + @Query("SELECT mp.userId FROM Membership m JOIN m.meteringPoint mp WHERE m.energyCommunity.id = :communityId AND m.status != 'INACTIVE'") List findActiveMemberUserIdsByCommunityId(@Param("communityId") UUID communityId); diff --git a/eeg_backend/src/test/java/at/mueller/eeg/backend/community/repository/MembershipRepositoryTest.java b/eeg_backend/src/test/java/at/mueller/eeg/backend/community/repository/MembershipRepositoryTest.java new file mode 100644 index 0000000..26cf2e9 --- /dev/null +++ b/eeg_backend/src/test/java/at/mueller/eeg/backend/community/repository/MembershipRepositoryTest.java @@ -0,0 +1,41 @@ +package at.mueller.eeg.backend.community.repository; + +import at.mueller.eeg.backend.community.domain.Membership; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Method; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class MembershipRepositoryTest { + + @Test + void findAllWithDetails_methodExists() throws NoSuchMethodException { + Method method = MembershipRepository.class.getMethod("findAllWithDetails"); + assertNotNull(method); + assertEquals(List.class, method.getReturnType()); + } + + @Test + void findAllWithDetails_hasQueryAnnotation() { + Method method = null; + try { + method = MembershipRepository.class.getMethod("findAllWithDetails"); + } catch (NoSuchMethodException e) { + fail("findAllWithDetails method not found on MembershipRepository"); + } + + org.springframework.data.jpa.repository.Query queryAnnotation = + method.getAnnotation(org.springframework.data.jpa.repository.Query.class); + assertNotNull(queryAnnotation, "findAllWithDetails should have @Query annotation"); + + String queryValue = queryAnnotation.value(); + assertTrue(queryValue.contains("JOIN FETCH m.meteringPoint"), + "Query should JOIN FETCH meteringPoint"); + assertTrue(queryValue.contains("JOIN FETCH m.energyCommunity"), + "Query should JOIN FETCH energyCommunity"); + assertFalse(queryValue.contains("WHERE"), + "Query should not have WHERE clause (returns all statuses)"); + } +}