1010import org .springframework .http .MediaType ;
1111import org .springframework .security .test .context .support .TestExecutionEvent ;
1212import org .springframework .security .test .context .support .WithUserDetails ;
13+ import org .springframework .test .annotation .DirtiesContext ;
1314import org .springframework .test .context .ActiveProfiles ;
14- import org .springframework .test .web . servlet . MockMvc ;
15+ import org .springframework .test .context . jdbc . Sql ;
1516import org .springframework .test .web .servlet .ResultActions ;
1617import org .springframework .transaction .annotation .Transactional ;
1718import org .springframework .transaction .support .TransactionTemplate ;
1819import org .tuna .zoopzoop .backend .domain .dashboard .entity .Graph ;
19- import org .tuna .zoopzoop .backend .domain .dashboard .repository .DashboardRepository ;
20- import org .tuna .zoopzoop .backend .domain .dashboard .repository .GraphRepository ;
2120import org .tuna .zoopzoop .backend .domain .member .enums .Provider ;
21+ import org .tuna .zoopzoop .backend .domain .member .repository .MemberRepository ;
2222import org .tuna .zoopzoop .backend .domain .member .service .MemberService ;
2323import org .tuna .zoopzoop .backend .domain .space .membership .enums .Authority ;
24+ import org .tuna .zoopzoop .backend .domain .space .membership .repository .MembershipRepository ;
2425import org .tuna .zoopzoop .backend .domain .space .membership .service .MembershipService ;
2526import org .tuna .zoopzoop .backend .domain .space .space .entity .Space ;
27+ import org .tuna .zoopzoop .backend .domain .space .space .repository .SpaceRepository ;
2628import org .tuna .zoopzoop .backend .domain .space .space .service .SpaceService ;
2729import org .tuna .zoopzoop .backend .testSupport .ControllerTestSupport ;
2830
3537
3638import static org .assertj .core .api .AssertionsForInterfaceTypes .assertThat ;
3739import static org .awaitility .Awaitility .await ;
38- import static org .hamcrest .Matchers .hasSize ;
39- import static org .junit .jupiter .api .Assertions .assertEquals ;
4040import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
4141import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
42- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
4342
4443@ SpringBootTest
4544@ AutoConfigureMockMvc
4847@ Transactional
4948@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
5049class DashboardControllerTest extends ControllerTestSupport {
51- @ Autowired
52- private SpaceService spaceService ;
50+ @ Autowired private SpaceService spaceService ;
51+ @ Autowired private MemberService memberService ;
52+ @ Autowired private MembershipService membershipService ;
5353
54- @ Autowired
55- private MemberService memberService ;
54+ @ Autowired SpaceRepository spaceRepository ;
55+ @ Autowired MemberRepository memberRepository ;
56+ @ Autowired MembershipRepository membershipRepository ;
5657
57- @ Autowired
58- private MembershipService membershipService ;
58+ @ Autowired private TransactionTemplate transactionTemplate ;
5959
60- @ Autowired
61- private DashboardRepository dashboardRepository ;
62-
63- @ Autowired
64- private TransactionTemplate transactionTemplate ;
65-
66- private Integer authorizedDashboardId ;
6760 private Integer unauthorizedDashboardId ;
61+ private Integer authorizedDashboardId ;
62+
63+ private String authorizedSpaceName = "TestSpace1_forDashboardControllerTest" ;
64+ private String unauthorizedSpaceName = "TestSpace2_forDashboardControllerTest" ;
6865
6966 @ Value ("${liveblocks.secret-key}" )
7067 private String testSecretKey ;
@@ -76,8 +73,8 @@ void setUp() {
7673 memberService .createMember ("tester2_forDashboardControllerTest" , "url" , "dc2222" , Provider .KAKAO );
7774
7875 // 2. 스페이스 생성 (생성과 동시에 대시보드도 생성됨)
79- Space space1 = spaceService .createSpace ("TestSpace1_forDashboardControllerTest" , "thumb1" );
80- Space space2 = spaceService .createSpace ("TestSpace2_forDashboardControllerTest" , "thumb2" );
76+ Space space1 = spaceService .createSpace (authorizedSpaceName , "thumb1" );
77+ Space space2 = spaceService .createSpace (unauthorizedSpaceName , "thumb2" );
8178
8279 // 테스트에서 사용할 대시보드 ID 저장
8380 this .authorizedDashboardId = space1 .getDashboard ().getId ();
@@ -98,6 +95,14 @@ void setUp() {
9895 );
9996 }
10097
98+ @ AfterAll
99+ void tearDown () {
100+ // 멤버십, 스페이스, 멤버 모두 삭제
101+ membershipRepository .deleteAll ();
102+ spaceRepository .deleteAll ();
103+ memberRepository .deleteAll ();
104+ }
105+
101106 // ============================= GET GRAPH ============================= //
102107
103108 @ Test
@@ -180,7 +185,8 @@ void updateGraph_Success() throws Exception {
180185 await ().atMost (5 , TimeUnit .SECONDS ).untilAsserted (() -> {
181186 // [수정] transactionTemplate을 사용하여 트랜잭션 내에서 검증 로직을 실행
182187 transactionTemplate .execute (status -> {
183- Graph updatedGraph = dashboardRepository .findById (authorizedDashboardId ).get ().getGraph ();
188+ Space space = spaceService .findByName (authorizedSpaceName );
189+ Graph updatedGraph = space .getDashboard ().getGraph ();
184190 assertThat (updatedGraph .getNodes ()).hasSize (2 );
185191 assertThat (updatedGraph .getEdges ()).hasSize (1 );
186192 assertThat (updatedGraph .getNodes ().get (0 ).getData ().get ("title" )).isEqualTo ("노드1" );
0 commit comments