Skip to content

Commit

Permalink
Feat: Member, Profile Entity, MemberRepository 추가
Browse files Browse the repository at this point in the history
+ MemberRepositoryTest 추가

Related to: KakaoTech-BootCamp-Team-2#1
  • Loading branch information
Taejin1221 committed Aug 19, 2024
1 parent 51b5daf commit 0f1e1eb
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 20 deletions.
41 changes: 21 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.2'
id 'io.spring.dependency-management' version '1.1.6'
id 'java'
id 'org.springframework.boot' version '3.3.2'
id 'io.spring.dependency-management' version '1.1.6'
}

group = 'kaboo'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testRuntimeOnly 'com.h2database:h2'
}

tasks.named('test') {
useJUnitPlatform()
useJUnitPlatform()
}
40 changes: 40 additions & 0 deletions src/main/java/kaboo/kaboo_auth/domain/entity/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package kaboo.kaboo_auth.domain.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@NoArgsConstructor
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_id")
private Long id;

@Setter
private String username;

@Setter
private String nickname;

@Setter
private String password;

@Setter
private String info;

@Builder
public Member(String username, String nickname, String password) {
this.username = username;
this.nickname = nickname;
this.password = password;
}
}
34 changes: 34 additions & 0 deletions src/main/java/kaboo/kaboo_auth/domain/entity/ProfileImage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package kaboo.kaboo_auth.domain.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@NoArgsConstructor
public class ProfileImage {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne
@JoinColumn(name = "member_id")
private Member member;

@Setter
@Column(name = "image_name")
private String imageName;

public ProfileImage(Member member, String imageName) {
this.member = member;
this.imageName = imageName;
}
}
11 changes: 11 additions & 0 deletions src/main/java/kaboo/kaboo_auth/repository/MemberRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kaboo.kaboo_auth.repository;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

import kaboo.kaboo_auth.domain.entity.Member;

public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByUsername(String username);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kaboo.kaboo_auth.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import kaboo.kaboo_auth.domain.entity.ProfileImage;

public interface ProfileImageRepository extends JpaRepository<ProfileImage, Long> {
}
6 changes: 6 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
spring.application.name=kaboo-auth
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.datasource.url=${DB_URL}
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package kaboo.kaboo_auth.repository;

import static org.junit.jupiter.api.Assertions.*;

import java.util.Optional;

import org.junit.jupiter.api.DisplayName;
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.transaction.annotation.Transactional;

import kaboo.kaboo_auth.domain.entity.Member;

@DataJpaTest
@Transactional
@DisplayName("Member Repository Test")
class MemberRepositoryTest {
@Autowired
MemberRepository memberRepository;

@Test
@DisplayName("DB 저장 Test")
void saveMemberTest() {
// Given
Member member = Member.builder().username("Alice").nickname("Alice").password("1234").build();
memberRepository.save(member);

// When
Member result = memberRepository.findById(member.getId()).get();

// Then
assertEquals(result, member);
}

@Test
@DisplayName("Username으로 찾기 성공 Test")
void findByUsername_Success() {
// Given
Member member1 = Member.builder().username("Alice").nickname("Alice").password("1234").build();
memberRepository.save(member1);

// When
Member result = memberRepository.findByUsername("Alice").get();

// Then
assertEquals(result, member1);
}

@Test
@DisplayName("Username 존재하지 않을 때 Test")
void findByUsername_Failure() {
// Given

// When
Optional<Member> result = memberRepository.findByUsername("Alice");

// Then
assertEquals(result, Optional.empty());
}
}
18 changes: 18 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
spring:
datasource:
url: jdbc:h2:mem:test;MODE=MariaDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
driverClassName: org.h2.Driver
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: true
h2:
console:
enabled: true
path: /h2-console

0 comments on commit 0f1e1eb

Please sign in to comment.