Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsamson7 committed Mar 23, 2024
1 parent a6d0005 commit 3749197
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 3 deletions.
122 changes: 119 additions & 3 deletions portal/core/src/test/java/com/serious/portal/mapper/MapperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,129 @@ class MapperTest {

// test

class From (var name: String = "")
data class From(var name: String)

data class To(var name: String)

class FooSource (var name: String, var bars: List<BarSource> = ArrayList() )

class FooDataSource (var name: String, var bars: List<BarSource> = ArrayList() )

data class FooTarget(var name: String, var bars: List<BarTarget> = ArrayList())

class BarSource (var name: String = "")

data class BarTarget(var name: String)

class ReadOnly(val name: String)

@Test()
fun testDeepCollectionLevel1Data() {
// classes

class BarSource (var name: String = "")

data class BarTarget(var name: String)

data class InnerClassSource (var bars: List<BarSource> = ArrayList() )

data class InnerClassTarget (var bars: List<BarTarget> = ArrayList() )

class Source (var name: String, var innerClass: InnerClassSource)

data class Target(var name: String, var innerClass: InnerClassTarget)


// mapper

val mapper = Mapper(
Mapping.build(Source::class, Target::class) {
map { properties("name")}
map { path("innerClass", "bars") to path("innerClass", "bars") deep true}
},
Mapping.build(BarSource::class, BarTarget::class) {
map { properties("name")}
})

val source = Source("source", InnerClassSource(arrayListOf(BarSource("bar"))))
val target = mapper.map<Target>(source)!!

assertEquals("source", target.name)
assertEquals(1, target.innerClass.bars.size)
}

@Test()
fun testDeepCollectionLevel1() {
// classes

class BarSource (var name: String = "")

data class BarTarget(var name: String)

class InnerClassSource (var bars: List<BarSource> = ArrayList() )

class InnerClassTarget (var bars: List<BarTarget> = ArrayList() )

class Source (var name: String, var innerClass: InnerClassSource)

data class Target(var name: String, var innerClass: InnerClassTarget)


// mapper

val mapper = Mapper(
Mapping.build(Source::class, Target::class) {
map { properties("name")}
map { path("innerClass", "bars") to path("innerClass", "bars") deep true}
},
Mapping.build(BarSource::class, BarTarget::class) {
map { properties("name")}
})

val foo = Source("source", InnerClassSource(arrayListOf(BarSource("bar"))))

val result = mapper.map<Target>(foo)!!

assertEquals("source", result.name)
assertEquals(1, result.innerClass.bars.size)
}

@Test()
fun testTopLevelDeepCollection() {
val mapper = Mapper(
Mapping.build(FooSource::class, FooTarget::class) {
map { properties("name")}
map { "bars" to "bars" deep true}
},
Mapping.build(BarSource::class, BarTarget::class) {
map { properties("name")}
})

val source = FooSource("source", arrayListOf(BarSource("bar")))
val target = mapper.map<FooTarget>(source)!!

assertEquals("source", target.name)
assertEquals(1, target.bars.size)
}
@Test()
fun testTopLevelDataDeepCollection() {
val mapper = Mapper(
Mapping.build(FooDataSource::class, FooTarget::class) {
map { properties("name")}
map { "bars" to "bars" deep true}
},
Mapping.build(BarSource::class, BarTarget::class) {
map { properties("name")}
})

val source = FooDataSource("source", arrayListOf(BarSource("bar")))
val target = mapper.map<FooTarget>(source)!!

assertEquals("source", target.name)
assertEquals(1, target.bars.size)
}


@Test()
fun testReadOnlyException() {
try {
Expand Down Expand Up @@ -72,8 +189,7 @@ class MapperTest {

@Test
fun test1() {
val from = From()
from.name = "from"
val from = From("from")

val mapper = Mapper(
Mapping.build(From::class, To::class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ class SynchronizerTest {

val rootResult = rootMapper.map<RootEntity>(root)!!

assertEquals(1, rootResult.bars.size)

// add another bar and remap

root.bars.add(Bar(2))

rootMapper.map(root, rootResult)

assertEquals(2, rootResult.bars.size)
}
}

0 comments on commit 3749197

Please sign in to comment.