-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
245 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
backend/src/main/java/shook/shook/song/domain/ArtistSynonym.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package shook.shook.song.domain; | ||
|
||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.ForeignKey; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import java.util.Objects; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@Table(name = "artist_synonym") | ||
@Entity | ||
public class ArtistSynonym { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "artist_id", foreignKey = @ForeignKey(name = "none"), updatable = false, nullable = false) | ||
private Artist artist; | ||
|
||
@Embedded | ||
private Synonym synonym; | ||
|
||
public String getArtistName() { | ||
return artist.getArtistName(); | ||
} | ||
|
||
public String getSynonym() { | ||
return synonym.getValue(); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final ArtistSynonym artistSynonym = (ArtistSynonym) o; | ||
if (Objects.isNull(artistSynonym.id) || Objects.isNull(this.id)) { | ||
return false; | ||
} | ||
return Objects.equals(id, artistSynonym.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
backend/src/main/java/shook/shook/song/domain/Synonym.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package shook.shook.song.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import java.util.Map; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import shook.shook.song.exception.ArtistException; | ||
import shook.shook.util.StringChecker; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@EqualsAndHashCode | ||
@Embeddable | ||
public class Synonym { | ||
|
||
private static final int MAXIMUM_LENGTH = 255; | ||
|
||
@Column(name = "synonym", nullable = false) | ||
private String value; | ||
|
||
public Synonym(final String value) { | ||
validate(value); | ||
this.value = value; | ||
} | ||
|
||
private void validate(final String value) { | ||
if (StringChecker.isNullOrBlank(value)) { | ||
throw new ArtistException.NullOrEmptySynonymException(); | ||
} | ||
if (value.length() > MAXIMUM_LENGTH) { | ||
throw new ArtistException.TooLongSynonymException( | ||
Map.of("ArtistSynonym", value) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
backend/src/test/java/shook/shook/song/domain/ProfileImageUrlTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package shook.shook.song.domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import shook.shook.song.exception.ArtistException; | ||
|
||
class ProfileImageUrlTest { | ||
|
||
@DisplayName("ProfileImageUrl 을 생성한다.") | ||
@Test | ||
void create_success() { | ||
// given | ||
// when, then | ||
assertDoesNotThrow(() -> new ProfileImageUrl("image")); | ||
} | ||
|
||
@DisplayName("이미지 URL이 비어있으면 예외를 던진다.") | ||
@NullSource | ||
@ParameterizedTest(name = "이미지 URL이 \"{0}\" 일 때") | ||
@ValueSource(strings = {"", " "}) | ||
void create_fail_lessThanOne(final String value) { | ||
//given | ||
//when | ||
//then | ||
assertThatThrownBy(() -> new ProfileImageUrl(value)) | ||
.isInstanceOf(ArtistException.NullOrEmptyProfileUrlException.class); | ||
} | ||
|
||
@DisplayName("이미지 URL의 길이가 65_536을 넘을 경우 예외를 던진다.") | ||
@Test | ||
void create_fail_lengthOver65_536() { | ||
//given | ||
final String name = ".".repeat(65_537); | ||
|
||
//when | ||
//then | ||
assertThatThrownBy(() -> new ProfileImageUrl(name)) | ||
.isInstanceOf(ArtistException.TooLongProfileUrlException.class); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
backend/src/test/java/shook/shook/song/domain/SynonymTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package shook.shook.song.domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import shook.shook.song.exception.ArtistException; | ||
|
||
class SynonymTest { | ||
|
||
@DisplayName("가수 이름 동의어를 뜻하는 객체를 생성한다.") | ||
@Test | ||
void create_success() { | ||
//given | ||
//when | ||
//then | ||
Assertions.assertDoesNotThrow(() -> new Synonym("동의어")); | ||
} | ||
|
||
@DisplayName("가수 이름 동의어가 유효하지 않으면 예외를 던진다.") | ||
@NullSource | ||
@ParameterizedTest(name = "동의어가 \"{0}\" 일 때") | ||
@ValueSource(strings = {"", " "}) | ||
void create_fail_lessThanOne(final String synonym) { | ||
//given | ||
//when | ||
//then | ||
assertThatThrownBy(() -> new Synonym(synonym)) | ||
.isInstanceOf(ArtistException.NullOrEmptySynonymException.class); | ||
} | ||
|
||
@DisplayName("가수 이름 동의어의 길이가 255를 넘을 경우 예외를 던진다.") | ||
@Test | ||
void create_fail_lengthOver255() { | ||
//given | ||
final String synonym = ".".repeat(256); | ||
|
||
//when | ||
//then | ||
assertThatThrownBy(() -> new Synonym(synonym)) | ||
.isInstanceOf(ArtistException.TooLongSynonymException.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters