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

TimeStamp 생성 오류가 발생합니다. #1045

Closed
mintheon opened this issue Sep 5, 2024 · 2 comments
Closed

TimeStamp 생성 오류가 발생합니다. #1045

mintheon opened this issue Sep 5, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@mintheon
Copy link

mintheon commented Sep 5, 2024

Describe the bug

TimeStamp 필드를 가지고 있는 클래스를 givemeone메서드를 통해 생성시 오류가 발생합니다.

Your environment

  • version of Fixture Monkey: 1.0.14
  • version of Java/Kotlin: Java 21

Steps to reproduce

Tell us how to reproduce this issue.
Or provide us an example repository to check the bug
It would be very helpful if you could tell us the seed of the given test, which is provided in fixture-monkey-junit-jupiter module

픽스쳐 몽키는 아래와 같이 설정되어 있습니다.

FixtureMonkey.builder()
            .objectIntrospector(new FailoverIntrospector(
                    Arrays.asList(
                            FieldReflectionArbitraryIntrospector.INSTANCE,
                            BeanArbitraryIntrospector.INSTANCE,
                            BuilderArbitraryIntrospector.INSTANCE
                    )
            ))
            .defaultNotNull(true)
            .plugin(new JacksonPlugin())
            .plugin(new JakartaValidationPlugin())
            .plugin(new SimpleValueJqwikPlugin())
            .build();

문제가 되는 클래스입니다.

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class A {
    private LocalDateTime localDate;

    private Timestamp timeStamp;
}

실행 코드입니다.

fixtureMonkey.giveMeOne(A.class)

Expected behaviour

Tell us what should happen

Actual behaviour

Tell us what happens instead

아래와 같은 에러가 발생합니다.

Cannot deserialize value of type `java.sql.Timestamp` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: com.hello.db.model.dto.A["timeStamp"])

.plugin(new JacksonPlugin())

에러상 JacksonPlugin의 문제인듯하여 위 코드를 지웠는데 지우면 또 다른 에러가 발생하네요.

18:15:07.793 [Test worker] WARN com.navercorp.fixturemonkey.api.type.TypeCache -- Failed to create fields in type java.sql.Timestamp.
18:15:07.880 [Test worker] WARN com.navercorp.fixturemonkey.api.introspector.FieldReflectionArbitraryIntrospector -- Given type class java.sql.Timestamp is failed to generate due to the exception. It may be null.
java.lang.IllegalArgumentException: The given type class java.sql.Timestamp has no matching constructor. parameterTypes: []
	at com.navercorp.fixturemonkey.api.type.TypeCache.lambda$getDeclaredConstructor$6(TypeCache.java:128)
	at java.base/java.util.Optional.orElseThrow(Optional.java:403)
...이하생략

당연히 해당 필드를 localDateTime으로 변경시에는 오류 없이 잘 처리됩니다.

기존 TimeStamp 오류가 있다는 issue글이 동일하게 있길래 참조하였는데 ArbitraryIntrospector 를 사용하라는 가이드가 있었지만.. 해당 기능의 링크된 글이 사라져서 없고, kotlin 환경이 아닌 java환경이라 적용하는데 어려움이 있어 문의드려요.

확인부탁드립니다~

@mintheon mintheon added the bug Something isn't working label Sep 5, 2024
@seongahjo
Copy link
Contributor

@mintheon
안녕하세요.

Timestamp를 생성하기 위해서는 말씀주신 것처럼 Timestamp를 생성해주는 ArbitraryIntrospector을 새로 정의해야 합니다.
아래와 같이 간단하게 정의할 수 있습니다.

FixtureMonkey.builder()
	.pushExactTypeArbitraryIntrospector(
		Timestamp.class,
		context -> new ArbitraryIntrospectorResult(
			CombinableArbitrary.from(() -> new Timestamp(Arbitraries.longs().sample())))
	)
	.build();

혹시 문제가 있으시면 말씀해주세요!

감사합니다

@mintheon
Copy link
Author

감사합니다~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants