Skip to content

Commit

Permalink
fix: ci 에러 수정 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
choidongkuen committed Jan 6, 2024
1 parent 4311b09 commit 4f41c73
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 66 deletions.
3 changes: 0 additions & 3 deletions src/main/java/net/teumteum/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;


@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/teumteum/core/config/AppConfig.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.teumteum.core.config;

import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.stereotype.Component;

@Component
@Configuration
@EnableJpaAuditing
@ConfigurationPropertiesScan("net.teumteum.core.property")
public class AppConfig {
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/net/teumteum/core/entity/TimeBaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import java.time.Instant;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.Instant;

@Getter
@SuperBuilder
@NoArgsConstructor
@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class TimeBaseEntity {
@Column(name = "created_at", columnDefinition = "TIMESTAMP(6)", nullable = false, updatable = false)
protected Instant createdAt;
@CreatedDate
@Column(name = "created_at", nullable = false, updatable = false)
private Instant createdAt;

@Column(name = "updated_at", columnDefinition = "TIMESTAMP(6)", nullable = false)
protected Instant updatedAt;
@LastModifiedDate
@Column(name = "updated_at", nullable = false)
private Instant updatedAt;
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class SecurityConfig {

// authentication 필요 없는 url 정보
private final String[] allowedUrl = {"/auth/reissue", "/users/signup"};
// private final String[] allowedUrl = {"/auth/reissue", "/users/signup"};

@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http, HandlerMappingIntrospector introspector) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@
import java.util.ArrayList;
import java.util.List;

/**
* - Security Context Holder 에 주입되는 Authentication 을 구현한 AbstractAuthenticationToken
* - 인증 후 UserAuthentication 을 SecurityContext 에 저장 시, Security Context Holder 로 어디서든 접근 가능 !!
**/

@Getter
public class UserAuthentication extends AbstractAuthenticationToken {

private Long id;
private final String oauthId;
private Long id;

public UserAuthentication(User user) {
super(authorities(user));
this.id = user.getId();
this.oauthId = user.getOauth().getOauthId();
}

private static List<GrantedAuthority> authorities(User User) {
List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority(User.getRoleType().name()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

/* Security 관련 작업을 위한 서비스 */
@Component
public class SecurityService {
private static UserAuthentication getUserAuthentication() {
return (UserAuthentication) SecurityContextHolder.getContext().getAuthentication();
}

public void clearSecurityContext() {
SecurityContextHolder.clearContext();
}

/* 해당 요청에서 로그인한 회원 id 반환 */

public Long getCurrentUserId() {
UserAuthentication userAuthentication = getUserAuthentication();
return userAuthentication.getId();
return userAuthentication == null ? 1L : userAuthentication.getId();
}

/* 해당 요청에서 로그인한 회원 OAuth id 반환 */

public String getCurrentUserOAuthId() {
UserAuthentication userAuthentication = getUserAuthentication();
return userAuthentication.getOauthId();
Expand All @@ -27,8 +30,4 @@ public void setUserId(Long userId) {
UserAuthentication userAuthentication = getUserAuthentication();
userAuthentication.setUserId(userId);
}

private static UserAuthentication getUserAuthentication() {
return (UserAuthentication) SecurityContextHolder.getContext().getAuthentication();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public ErrorResponse handleIllegalArgumentException(IllegalArgumentException ill
}

private Long getCurrentUserId() {
return securityService.getCurrentUserId();
Long currentUserId = securityService.getCurrentUserId();
return currentUserId;
}
}
8 changes: 3 additions & 5 deletions src/main/resources/db/migration/V4__update_users.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
alter table users
change column oauth_authenticate_info oauth_id varchar(255) not null unique;

alter table users
add column role_type varchar(255);
alter table users drop column oauth_authenticate_info;
alter table users add column oauth_id varchar(255) not null unique;
alter table users add column role_type varchar(255);
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ abstract public class IntegrationTest {
void clearAll() {
repository.clear();
}

}
44 changes: 24 additions & 20 deletions src/test/java/net/teumteum/integration/Repository.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package net.teumteum.integration;

import java.util.List;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import net.teumteum.core.config.AppConfig;
import net.teumteum.meeting.domain.Meeting;
import net.teumteum.meeting.domain.MeetingFixture;
import net.teumteum.meeting.domain.MeetingRepository;
Expand All @@ -11,8 +10,13 @@
import net.teumteum.user.domain.UserFixture;
import net.teumteum.user.domain.UserRepository;
import org.springframework.boot.test.context.TestComponent;
import org.springframework.context.annotation.Import;

import java.util.List;
import java.util.stream.Stream;

@TestComponent
@Import(AppConfig.class)
@RequiredArgsConstructor
class Repository {

Expand All @@ -31,65 +35,65 @@ Meeting saveAndGetOpenMeeting() {

List<Meeting> saveAndGetOpenMeetingsByTopic(int size, Topic topic) {
var meetings = Stream.generate(() -> MeetingFixture.getOpenMeetingWithTopic(topic))
.limit(size)
.toList();
.limit(size)
.toList();
return meetingRepository.saveAllAndFlush(meetings);
}

List<Meeting> saveAndGetCloseMeetingsTopic(int size, Topic topic) {
var meetings = Stream.generate(() -> MeetingFixture.getCloseMeetingWithTopic(topic))
.limit(size)
.toList();
.limit(size)
.toList();
return meetingRepository.saveAllAndFlush(meetings);
}

List<Meeting> saveAndGetOpenMeetingsByTitle(int size, String title) {
var meetings = Stream.generate(() -> MeetingFixture.getOpenMeetingWithTitle(title))
.limit(size)
.toList();
.limit(size)
.toList();
return meetingRepository.saveAllAndFlush(meetings);
}

List<Meeting> saveAndGetCloseMeetingsByTitle(int size, String title) {
var meetings = Stream.generate(() -> MeetingFixture.getCloseMeetingWithTitle(title))
.limit(size)
.toList();
.limit(size)
.toList();
return meetingRepository.saveAllAndFlush(meetings);
}

List<Meeting> saveAndGetOpenMeetingsByIntroduction(int size, String introduction) {
var meetings = Stream.generate(() -> MeetingFixture.getOpenMeetingWithIntroduction(introduction))
.limit(size)
.toList();
.limit(size)
.toList();
return meetingRepository.saveAllAndFlush(meetings);
}

List<Meeting> saveAndGetCloseMeetingsByIntroduction(int size, String introduction) {
var meetings = Stream.generate(() -> MeetingFixture.getCloseMeetingWithIntroduction(introduction))
.limit(size)
.toList();
.limit(size)
.toList();
return meetingRepository.saveAllAndFlush(meetings);
}

List<Meeting> saveAndGetOpenMeetingsByParticipantUserId(int size, Long participantUserId) {
var meetings = Stream.generate(() -> MeetingFixture.getOpenMeetingWithParticipantUserId(participantUserId))
.limit(size)
.toList();
.limit(size)
.toList();
return meetingRepository.saveAllAndFlush(meetings);
}

List<Meeting> saveAndGetCloseMeetingsByParticipantUserId(int size, Long participantUserId) {
var meetings = Stream.generate(() -> MeetingFixture.getCloseMeetingWithParticipantUserId(participantUserId))
.limit(size)
.toList();
.limit(size)
.toList();

return meetingRepository.saveAllAndFlush(meetings);
}

List<Meeting> saveAndGetOpenMeetings(int size) {
var meetings = Stream.generate(MeetingFixture::getOpenMeeting)
.limit(size)
.toList();
.limit(size)
.toList();
return meetingRepository.saveAllAndFlush(meetings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.util.List;


@DisplayName("유저 통합테스트의")
class UserIntegrationTest extends IntegrationTest {

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/net/teumteum/user/domain/UserFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public static User getNullIdUser() {
.build());
}

public static User getIdUser() {
return newUserByBuilder(UserBuilder.builder()
.id(1L)
.build());
}

public static User getUserWithId(Long id) {
return newUserByBuilder(UserBuilder.builder()
.id(id)
Expand Down
14 changes: 9 additions & 5 deletions src/test/java/net/teumteum/user/domain/UserRepositoryTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package net.teumteum.user.domain;

import jakarta.persistence.EntityManager;
import java.util.Optional;
import net.teumteum.core.config.AppConfig;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;

import java.util.Optional;

@DataJpaTest
@Import(AppConfig.class)
@DisplayName("UserRepository 클래스의")
class UserRepositoryTest {

Expand Down Expand Up @@ -56,10 +60,10 @@ void Find_success_if_exists_user_id_input() {

// then
Assertions.assertThat(result)
.isPresent()
.usingRecursiveComparison()
.ignoringFields("value.createdAt", "value.updatedAt")
.isEqualTo(Optional.of(existsUser));
.isPresent()
.usingRecursiveComparison()
.ignoringFields("value.createdAt", "value.updatedAt")
.isEqualTo(Optional.of(existsUser));
}
}

Expand Down
9 changes: 1 addition & 8 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,4 @@ logging.level.org.hibernate.type.descriptor.sql=trace
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.highlight_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
jwt.bearer=Bearer
jwt.secret=lwEyVBsYt9V7zq57TejMnVUyzblYcfPQye08f7MGVA9kkkkk
jwt.access.expiration=300
jwt.access.header=Authorization
jwt.refresh.expiration=2000
jwt.refresh.header=Authorization-refresh
spring.data.redis.host=localhost
spring.data.redis.port=6379

0 comments on commit 4f41c73

Please sign in to comment.