-
Notifications
You must be signed in to change notification settings - Fork 92
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 KotlinAndJavaCompositeArbitraryIntrospector for supporting instantiating kotlin class with java reference Type #948
Merged
seongahjo
merged 18 commits into
naver:main
from
jinia91:kotlin-java-composition-object-generate
Mar 18, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b1a0be5
add test code and enhance kotlin plugin for supporting kotlin and jav…
jinia91 2177a84
klint formatting
jinia91 6b914d2
add file documentation and mv kotlin plugin test specs
jinia91 2f5f902
formatting and rollback ununecessary refac
jinia91 4fe9074
refac dbb assertion
jinia91 4ad828e
add KotlinAndJavaCompositeArbitraryIntrospector and change kotlin plu…
jinia91 8194dcf
formatting
jinia91 52f4a6e
change to jqwik test
jinia91 c21262d
change to jqwik test
jinia91 b989348
del unused import
jinia91 c12168a
add file docu for licence
jinia91 4433d51
feedback(seongahjo) : refac property name and use exist method
jinia91 612404a
feedback(seongahjo) : del using kjcompositArbitraryIntrospector in ko…
jinia91 7d0db75
add kotlinAndJavaCompositeArbitraryIntrospector doc
jinia91 c1bb28f
Merge branch 'main' into kotlin-java-composition-object-generate
jinia91 cba737c
formating
jinia91 2e3ed9c
java and kotlin composite class benchmark test
jinia91 3f718bc
change contributor nick name ^
jinia91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
34 changes: 34 additions & 0 deletions
34
...kotlin/src/jmh/kotlin/com/navercorp/fixturemonkey/kotlin/KotlinJavaCompositeOrderSheet.kt
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,34 @@ | ||
package com.navercorp.fixturemonkey.kotlin | ||
|
||
import com.navercorp.fixturemonkey.OrderSheet | ||
import java.math.BigDecimal | ||
import java.time.Instant | ||
import javax.validation.constraints.Size | ||
|
||
data class KotlinJavaCompositeOrderSheet( | ||
val id: String, | ||
val backUrl: String?, | ||
val userNo: Long?, | ||
@field:Size(min = 1, max = 1) | ||
val products: List<OrderSheet.OrderSheetProduct>, | ||
val merchantsByMerchantNo: Map.Entry<Long, OrderSheetMerchant>?, | ||
val registeredDateTime: Instant?, | ||
@field:Size(min = 1, max = 1) | ||
val bundleDeliveryFeesByDeliveryGroupKey: Map<String, OrderSheetBundleDeliveryFee>? | ||
) { | ||
data class OrderSheetMerchant( | ||
val talkInterlockAccountId: String?, | ||
val logeyeRequestId: String?, | ||
val logeyeInflowPathName: String?, | ||
val logeyePayAccumulation: Boolean? | ||
) | ||
|
||
data class OrderSheetBundleDeliveryFee( | ||
val deliveryFee: BigDecimal?, | ||
val type: BundleType | ||
) | ||
|
||
enum class BundleType { | ||
MANUALLY, IDENTICAL_PRODUCT | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import com.navercorp.fixturemonkey.OrderSheet | |
import com.navercorp.fixturemonkey.FixtureMonkey | ||
import com.navercorp.fixturemonkey.api.introspector.BeanArbitraryIntrospector | ||
import com.navercorp.fixturemonkey.api.type.TypeCache | ||
import com.navercorp.fixturemonkey.kotlin.introspector.KotlinAndJavaCompositeArbitraryIntrospector | ||
import java.util.concurrent.TimeUnit | ||
import org.openjdk.jmh.annotations.Benchmark | ||
import org.openjdk.jmh.annotations.BenchmarkMode | ||
|
@@ -48,4 +49,16 @@ open class KotlinObjectGenerationBenchMark { | |
|
||
private fun generateKotlinOrderSheet(fixtureMonkey: FixtureMonkey): List<KotlinOrderSheet> = | ||
List(COUNT) { fixtureMonkey.giveMeOne(KotlinOrderSheet::class.java) } | ||
|
||
@Benchmark | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add benchmark for |
||
fun beanGenerateKotlinJavaCompositeOrderSheetWithFixtureMonkey(blackhole: Blackhole) { | ||
val fixtureMonkey = FixtureMonkey.builder() | ||
.plugin(KotlinPlugin()) | ||
.objectIntrospector(KotlinAndJavaCompositeArbitraryIntrospector()) | ||
.build() | ||
blackhole.consume(generateKotlinJavaCompositeOrderSheet(fixtureMonkey)) | ||
} | ||
|
||
private fun generateKotlinJavaCompositeOrderSheet(fixtureMonkey: FixtureMonkey): List<KotlinJavaCompositeOrderSheet> = | ||
List(COUNT) { fixtureMonkey.giveMeOne(KotlinJavaCompositeOrderSheet::class.java) } | ||
} |
50 changes: 50 additions & 0 deletions
50
...avercorp/fixturemonkey/kotlin/introspector/KotlinAndJavaCompositeArbitraryIntrospector.kt
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,50 @@ | ||
/* | ||
* Fixture Monkey | ||
* | ||
* Copyright (c) 2021-present NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.fixturemonkey.kotlin.introspector | ||
|
||
import com.navercorp.fixturemonkey.api.generator.ArbitraryGeneratorContext | ||
import com.navercorp.fixturemonkey.api.introspector.ArbitraryIntrospector | ||
import com.navercorp.fixturemonkey.api.introspector.ArbitraryIntrospectorResult | ||
import com.navercorp.fixturemonkey.api.introspector.BeanArbitraryIntrospector | ||
import com.navercorp.fixturemonkey.kotlin.type.actualType | ||
import com.navercorp.fixturemonkey.kotlin.type.isKotlinType | ||
import org.slf4j.LoggerFactory | ||
|
||
class KotlinAndJavaCompositeArbitraryIntrospector( | ||
private val kotlinArbitraryIntrospector: ArbitraryIntrospector = PrimaryConstructorArbitraryIntrospector.INSTANCE, | ||
private val javaArbitraryIntrospector: ArbitraryIntrospector = BeanArbitraryIntrospector.INSTANCE, | ||
) : ArbitraryIntrospector { | ||
override fun introspect(context: ArbitraryGeneratorContext): ArbitraryIntrospectorResult { | ||
val type = context.resolvedType.actualType() | ||
try { | ||
return if (type.isKotlinType()) { | ||
kotlinArbitraryIntrospector.introspect(context) | ||
} else { | ||
javaArbitraryIntrospector.introspect(context) | ||
} | ||
} catch (e: Exception) { | ||
LOGGER.warn("Given type $type is failed to generated due to the exception.", e) | ||
return ArbitraryIntrospectorResult.NOT_INTROSPECTED | ||
} | ||
} | ||
|
||
companion object { | ||
private val LOGGER = LoggerFactory.getLogger(KotlinAndJavaCompositeArbitraryIntrospector::class.java) | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...om/navercorp/fixturemonkey/kotlin/test/KotlinAndJavaCompositeArbitraryIntrospectorTest.kt
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,78 @@ | ||
/* | ||
* Fixture Monkey | ||
* | ||
* Copyright (c) 2021-present NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.fixturemonkey.kotlin.test | ||
|
||
import com.navercorp.fixturemonkey.FixtureMonkey | ||
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector | ||
import com.navercorp.fixturemonkey.kotlin.KotlinPlugin | ||
import com.navercorp.fixturemonkey.kotlin.giveMeOne | ||
import com.navercorp.fixturemonkey.kotlin.introspector.KotlinAndJavaCompositeArbitraryIntrospector | ||
import net.jqwik.api.Property | ||
import org.assertj.core.api.BDDAssertions.then | ||
|
||
class KotlinAndJavaCompositeArbitraryIntrospectorTest { | ||
@Property | ||
fun kotlinClassWithJavaClass() { | ||
// given | ||
val sut: FixtureMonkey = FixtureMonkey.builder() | ||
.plugin(KotlinPlugin()) | ||
.objectIntrospector(KotlinAndJavaCompositeArbitraryIntrospector()) | ||
.build() | ||
|
||
// when | ||
val actual = sut.giveMeOne<KotlinClassWithJavaClass>() | ||
|
||
then(actual).isNotNull | ||
then(actual.javaObject).isNotNull | ||
} | ||
|
||
@Property | ||
fun kotlinClassWithJavaClassUsingOtherIntrospector() { | ||
// given | ||
val sut: FixtureMonkey = FixtureMonkey.builder() | ||
.plugin(KotlinPlugin()) | ||
.objectIntrospector( | ||
KotlinAndJavaCompositeArbitraryIntrospector( | ||
javaArbitraryIntrospector = ConstructorPropertiesArbitraryIntrospector.INSTANCE | ||
) | ||
) | ||
.build() | ||
|
||
// when | ||
val actual = sut.giveMeOne<KotlinClassWithJavaClass>() | ||
|
||
then(actual).isNotNull | ||
then(actual.javaObject).isNotNull | ||
} | ||
|
||
@Property | ||
fun sampleMapValue() { | ||
// given | ||
val sut: FixtureMonkey = FixtureMonkey.builder() | ||
.plugin(KotlinPlugin()) | ||
.objectIntrospector(KotlinAndJavaCompositeArbitraryIntrospector()) | ||
.build() | ||
|
||
// when | ||
val actual = sut.giveMeOne<MapValue>() | ||
|
||
then(actual).isNotNull | ||
then(actual.map).isNotNull | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...vercorp/fixturemonkey/kotlin/test/KotlinAndJavaCompositeArbitraryIntrospectorTestSpecs.kt
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,25 @@ | ||
/* | ||
* Fixture Monkey | ||
* | ||
* Copyright (c) 2021-present NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.fixturemonkey.kotlin.test | ||
|
||
import com.navercorp.fixturemonkey.kotlin.spec.JavaObject | ||
|
||
class KotlinClassWithJavaClass(val javaObject: JavaObject) | ||
|
||
class MapValue(val map: Map<String, String>) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it okay to change my nickname? 🥲