-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: 로그 레벨, 데이터 컬럼명 변경 - CreateLogRequest - logLevel -> level - logData -> data - CreateLogServiceRequest - logLevel -> level - logData -> data - Log - logData -> data - 필드 변경에 따른 테스트 코드 수정 * feat: UUID와 byte 배열 변환을 위한 UUIDUtil 클래스 추가 UUID 문자열과 byte 배열 간의 변환을 위한 UUIDUtil 클래스를 구현했습니다. - uuidStringToBytes: UUID 문자열을 byte 배열로 변환 - bytesToUuidString: byte 배열을 UUID 문자열로 변환 * test: UUID 변환을 검증하는 UUIDUtilTest 클래스 추가 UUID 변환을 검증하기 위한 UUIDUtilTest 클래스 생성: - uuidToBytes_ShouldConvertUUIDStringToByteArray: UUID 문자열을 byte 배열로 변환하는 것을 검증 - bytesToUUIDString_ShouldConvertByteArrayToUUIDString: byte 배열을 UUID 문자열로 변환하는 것을 검증 * refactor: application_id를 appKey로 변경 - CreateLogServiceRequest applicationId -> appKey로 변경 - Log 도메인 객체에서 applicationId -> appKey - LogController app-id -> appKey로 변경, Validation NotBlank로 변경 - LogSerivce에서 applicationId -> appKey로 변경 - 관련 테스트 변경 * refactor: UUIDUtil final 클래스로 변경, 기본 생성자 Private 추가 * feat: LogController 201 반환하도록 변경 * chore: bb -> byteBuffer로 변경 * test: Displayname 추가 * test: created로 response가 변경됨에 따라 테스트코드 변경 * test: 여러 개의 assertThat을 assertAll로 묶음 * refactor: Response 상태 코드를 어노테이션으로 처리 후 리턴 타입으로 void로 수정
- Loading branch information
Showing
12 changed files
with
192 additions
and
82 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
logbat/src/main/java/info/logbat/common/util/UUIDUtil.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,28 @@ | ||
package info.logbat.common.util; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.UUID; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class UUIDUtil { | ||
|
||
private static final int UUID_BYTE_LENGTH = 16; | ||
|
||
public static byte[] uuidStringToBytes(String uuidStr) { | ||
UUID uuid = UUID.fromString(uuidStr); | ||
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[UUID_BYTE_LENGTH]); | ||
byteBuffer.putLong(uuid.getMostSignificantBits()); | ||
byteBuffer.putLong(uuid.getLeastSignificantBits()); | ||
return byteBuffer.array(); | ||
} | ||
|
||
public static String bytesToUuidString(byte[] bytes) { | ||
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); | ||
long high = byteBuffer.getLong(); | ||
long low = byteBuffer.getLong(); | ||
UUID uuid = new UUID(high, low); | ||
return uuid.toString(); | ||
} | ||
} |
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
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
51 changes: 51 additions & 0 deletions
51
logbat/src/test/java/info/logbat/common/util/UUIDUtilTest.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,51 @@ | ||
package info.logbat.common.util; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
@DisplayName("UUIDUtil에서 ") | ||
public class UUIDUtilTest { | ||
|
||
@ParameterizedTest | ||
@DisplayName("UUID 문자열은 byte 배열로 변환할 수 있다.") | ||
@MethodSource("validUUIDProvider") | ||
void uuidToBytes_ShouldConvertUUIDStringToByteArray(String uuidStr, byte[] expectedBytes) { | ||
// when | ||
byte[] bytes = UUIDUtil.uuidStringToBytes(uuidStr); | ||
|
||
assertAll( | ||
() -> assertThat(bytes).isNotNull(), | ||
() -> assertThat(bytes.length).isEqualTo(16), | ||
() -> assertThat(bytes).isEqualTo(expectedBytes) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@DisplayName("bytesToUUIDString은 byte 배열을 UUID 문자열로 정확하게 변환해야 한다.") | ||
@MethodSource("validUUIDProvider") | ||
void bytesToUUIDString_ShouldConvertByteArrayToUUIDString(String expectedUUIDStr, byte[] bytes) { | ||
// when | ||
String resultUUIDStr = UUIDUtil.bytesToUuidString(bytes); | ||
|
||
// then | ||
assertThat(resultUUIDStr).isEqualTo(expectedUUIDStr); | ||
} | ||
|
||
|
||
private static Stream<Arguments> validUUIDProvider() { | ||
return Stream.of( | ||
Arguments.of("550e8400-e29b-41d4-a716-446655440000", | ||
new byte[]{85, 14, -124, 0, -30, -101, 65, -44, -89, 22, 68, 102, 85, 68, 0, 0}), | ||
Arguments.of("123e4567-e89b-12d3-a456-426614174000", | ||
new byte[]{18, 62, 69, 103, -24, -101, 18, -45, -92, 86, 66, 102, 20, 23, 64, 0}), | ||
Arguments.of("00000000-0000-0000-0000-000000000000", | ||
new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) | ||
); | ||
} | ||
} |
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
Oops, something went wrong.