Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] 테스트 코드 환경 설정 #131

Merged
merged 17 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions .github/tt.yml

This file was deleted.

55 changes: 0 additions & 55 deletions .github/workflows/main.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
.vscode
/.idea/
1 change: 1 addition & 0 deletions main/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bin/

### IntelliJ IDEA ###
.idea
.idea/
*.iws
*.iml
*.ipr
Expand Down
73 changes: 72 additions & 1 deletion main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
id 'jacoco'
}

group = 'org.sopt.makers.crew'
Expand All @@ -24,7 +25,6 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
// https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui
implementation 'io.hypersistence:hypersistence-utils-hibernate-62:3.6.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
implementation 'org.springframework.boot:spring-boot-starter-webflux:3.1.5'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
Expand All @@ -36,16 +36,47 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.6.0'

// jsonb 타입 핸들링 위함
implementation 'io.hypersistence:hypersistence-utils-hibernate-62:3.6.0'

implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5'
implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5'
implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5'
implementation 'com.auth0:java-jwt:4.4.0'

// h2
runtimeOnly 'com.h2database:h2'

// mac m1 setting
implementation 'io.netty:netty-resolver-dns-native-macos:4.1.68.Final:osx-aarch_64'

implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.0.3'

// test container
testImplementation 'org.testcontainers:testcontainers:1.17.3' // TC 의존성
testImplementation 'org.testcontainers:junit-jupiter:1.16.2' // TC 의존성
testImplementation 'org.testcontainers:postgresql:1.17.3' // PostgreSQL 컨테이너 사용
testImplementation 'org.testcontainers:jdbc' // DB와의 JDBC connection
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.14.0'


}

tasks.named('test') {
useJUnitPlatform()

finalizedBy jacocoTestCoverageVerification

jacoco {
excludes += [
"org/crew/main/MainApplication.class",
"**/response/*",
"**/config/*",
"**/dto/*",
"**/vo/*",
"**/exception/*",
]
}
}

ext {
Expand All @@ -58,4 +89,44 @@ dependencyManagement {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}

}

jacocoTestReport {
reports {
xml.required.set(true)
csv.required.set(true)
html.required.set(true)
}

afterEvaluate {
classDirectories.setFrom(
files(classDirectories.files.collect {
fileTree(dir: it, excludes: [
"org/crew/main/MainApplication.class",
"**/response/*",
"**/config/*",
"org/crew/**/*Dto.*",
"**/dto/*",
"**/vo/*",
"**/exception/*",
])
})
)
}
}

jacocoTestCoverageVerification {
violationRules {
rule {
// ...

excludes = [
'*.*Application',
'*.*Exception',
'*.Dto',
'*.response'
// ...
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.makers.crew.main.common.config;

import java.util.Arrays;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import org.sopt.makers.crew.main.common.config.jwt.JwtAuthenticationEntryPoint;
import org.sopt.makers.crew.main.common.config.jwt.JwtAuthenticationFilter;
Expand All @@ -14,6 +15,7 @@
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
Expand All @@ -39,7 +41,7 @@ public class SecurityConfig {

private static final String[] AUTH_WHITELIST = {
"/health",
"meeting/v2/org-user/**"
"/meeting/v2/org-user/**"
};

@Bean
Expand All @@ -51,8 +53,14 @@ SecurityFilterChain devSecurityFilterChain(HttpSecurity http) throws Exception {
(sessionManagement) -> sessionManagement.sessionCreationPolicy(
SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(
authorize -> authorize.requestMatchers(AUTH_WHITELIST).permitAll()
.requestMatchers(SWAGGER_URL).permitAll()
authorize -> authorize.requestMatchers(Stream
.of(SWAGGER_URL)
.map(AntPathRequestMatcher::antMatcher)
.toArray(AntPathRequestMatcher[]::new)).permitAll()
.requestMatchers(Stream
.of(AUTH_WHITELIST)
.map(AntPathRequestMatcher::antMatcher)
.toArray(AntPathRequestMatcher[]::new)).permitAll()
.anyRequest().authenticated())
.addFilterBefore(
new JwtAuthenticationFilter(this.jwtTokenProvider, this.jwtAuthenticationEntryPoint),
Expand All @@ -62,6 +70,32 @@ SecurityFilterChain devSecurityFilterChain(HttpSecurity http) throws Exception {
return http.build();
}

@Bean
@Profile("test")
SecurityFilterChain testSecurityFilterChain(HttpSecurity http) throws Exception {
http.csrf((csrfConfig) -> csrfConfig.disable())
.cors(Customizer.withDefaults())
.sessionManagement(
(sessionManagement) -> sessionManagement.sessionCreationPolicy(
SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(
authorize -> authorize.requestMatchers(Stream
.of(SWAGGER_URL)
.map(AntPathRequestMatcher::antMatcher)
.toArray(AntPathRequestMatcher[]::new)).permitAll()
.requestMatchers(Stream
.of(AUTH_WHITELIST)
.map(AntPathRequestMatcher::antMatcher)
.toArray(AntPathRequestMatcher[]::new)).permitAll()
.anyRequest().authenticated())
.addFilterBefore(
new JwtAuthenticationFilter(this.jwtTokenProvider, this.jwtAuthenticationEntryPoint),
UsernamePasswordAuthenticationFilter.class)
.exceptionHandling(exceptionHandling -> exceptionHandling
.authenticationEntryPoint(this.jwtAuthenticationEntryPoint));
return http.build();
}

@Bean
@Profile("prod")
SecurityFilterChain prodSecurityFilterChain(HttpSecurity http) throws Exception {
Expand All @@ -71,9 +105,15 @@ SecurityFilterChain prodSecurityFilterChain(HttpSecurity http) throws Exception
(sessionManagement) -> sessionManagement.sessionCreationPolicy(
SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(
authorize -> authorize.requestMatchers(AUTH_WHITELIST).permitAll()
.requestMatchers(SWAGGER_URL).permitAll()
.anyRequest().authenticated())
authorize -> authorize.requestMatchers(Stream
.of(SWAGGER_URL)
.map(AntPathRequestMatcher::antMatcher)
.toArray(AntPathRequestMatcher[]::new)).permitAll()
.requestMatchers(Stream
.of(AUTH_WHITELIST)
.map(AntPathRequestMatcher::antMatcher)
.toArray(AntPathRequestMatcher[]::new)).permitAll()
.anyRequest().authenticated())
.addFilterBefore(
new JwtAuthenticationFilter(this.jwtTokenProvider, this.jwtAuthenticationEntryPoint),
UsernamePasswordAuthenticationFilter.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.type.SqlTypes;
import org.sopt.makers.crew.main.entity.apply.Apply;
import org.sopt.makers.crew.main.entity.meeting.converter.MeetingCategoryConverter;
import org.sopt.makers.crew.main.entity.meeting.enums.EnMeetingStatus;
Expand Down Expand Up @@ -80,8 +82,9 @@ public class Meeting {
/**
* 이미지
*/
@Column(name = "imageURL")
@Column(name = "imageURL",columnDefinition = "jsonb")
@Type(JsonBinaryType.class)
//@JdbcTypeCode(SqlTypes.JSON)
private List<ImageUrlVO> imageURL;

/**
Expand Down Expand Up @@ -184,14 +187,15 @@ public class Meeting {
private List<Post> posts;

@Builder
public Meeting(User user, Integer userId, String title, MeetingCategory category,
public Meeting(User user, Integer userId, List<Apply> appliedInfo, String title, MeetingCategory category,
List<ImageUrlVO> imageURL, LocalDateTime startDate, LocalDateTime endDate, Integer capacity,
String desc, String processDesc, LocalDateTime mStartDate, LocalDateTime mEndDate,
String leaderDesc, String targetDesc, String note, Boolean isMentorNeeded,
Boolean canJoinOnlyActiveGeneration, Integer createdGeneration,
Integer targetActiveGeneration, MeetingJoinablePart[] joinableParts) {
this.user = user;
this.userId = userId;
this.appliedInfo = appliedInfo;
this.title = title;
this.category = category;
this.imageURL = imageURL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@Getter
@RequiredArgsConstructor
public class ImageUrlVO {

private Integer id;
private String url;
}
private final Integer id;
private final String url;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class User {
/**
* 활동 목록
*/
@Column(name = "activities")
@Column(name = "activities",columnDefinition = "jsonb")
@Type(JsonBinaryType.class)
private List<UserActivityVO> activities;

Expand Down Expand Up @@ -125,4 +125,6 @@ public void addLike(Like like) {
public void addReport(Report report) {
this.reports.add(report);
}

public void setUserIdForTest(Integer userId){ this.id = userId;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@ToString
public class UserActivityVO {

private String part;
private int generation;
private final String part;
private final int generation;

}
Loading