@@ -446,6 +446,26 @@ class DefaultMergeCellMigratorTest extends AbstractMergeCellMigratorTest {
446446 assertEquals (expectedFilter, filter. filterTerm)
447447 }
448448
449+ @CompileStatic (TypeCheckingMode .SKIP )
450+ private void typeFilterCheck (Cell migrated , String expectedFilter ) {
451+ JaxbAlignmentIO . printCell(migrated, System . out)
452+
453+ // the condition should be present on the source
454+ def source = CellUtil . getFirstEntity(migrated. source). definition
455+ assertNotNull (source. filter)
456+ assertEquals (expectedFilter, source. filter. filterTerm)
457+ }
458+
459+ @CompileStatic (TypeCheckingMode .SKIP )
460+ private void filterCheckNull (Cell migrated ) {
461+ JaxbAlignmentIO . printCell(migrated, System . out)
462+
463+ // the condition should be present on the source
464+ def source = CellUtil . getFirstEntity(migrated. source). definition
465+ def filter = source. propertyPath. empty ? source. filter : source. propertyPath[0 ]. condition?. filter
466+ assertNull (filter)
467+ }
468+
449469 @Test
450470 void testTypeFilter1 () {
451471 def toMigrate = this . class. getResource(' /testcases/type-filter/B-to-C.halex' )
@@ -481,7 +501,33 @@ class DefaultMergeCellMigratorTest extends AbstractMergeCellMigratorTest {
481501
482502 // filter
483503 assertEquals (1 , migrated. size())
484- filterCheck(migrated[0 ], " bb = 'test'" ) // the filter should be retained
504+ // filter is now dropped (because bb is not mapped for B2)
505+ filterCheckNull(migrated[0 ])
506+
507+ // there should be a message about the condition
508+ def messages = getMigrationMessages(migrated[0 ])
509+ assertTrue (messages. any { msg ->
510+ msg. text. toLowerCase(). contains(' condition' )
511+ })
512+ assertTrue (messages. any { msg ->
513+ msg. text. toLowerCase(). contains(' removed because no matches' )
514+ })
515+ }
516+
517+ @Test
518+ void testTypeFilter2Present () {
519+ def toMigrate = this . class. getResource(' /testcases/type-filter-props-mapped/B-to-C.halex' )
520+ def cellId = ' B2-C2' // Retype
521+
522+ def matching = this . class. getResource(' /testcases/type-filter-props-mapped/A-to-B.halex' )
523+
524+ def migrated = merge(cellId, toMigrate, matching)
525+
526+ // do checks
527+
528+ // filter
529+ assertEquals (1 , migrated. size())
530+ filterCheck(migrated[0 ], " ab = 'test'" )
485531
486532 // there should be a message about the condition
487533 def messages = getMigrationMessages(migrated[0 ])
@@ -491,7 +537,6 @@ class DefaultMergeCellMigratorTest extends AbstractMergeCellMigratorTest {
491537 }
492538
493539 @Test
494- @CompileStatic (TypeCheckingMode .SKIP )
495540 void testTypeFilter2Property () {
496541 def toMigrate = this . class. getResource(' /testcases/type-filter/B-to-C.halex' )
497542 def cellId = ' B2C2a' // Rename
@@ -502,11 +547,34 @@ class DefaultMergeCellMigratorTest extends AbstractMergeCellMigratorTest {
502547
503548 // do checks
504549
505- // type filter should be retained
506- def source = CellUtil . getFirstEntity(migrated[0 ]. source). definition
507- def filter = source. filter
508- assertNotNull (filter)
509- assertEquals (" bb = 'test'" , filter. filterTerm)
550+ // filter is now dropped (because bb is not mapped for B2)
551+ assertEquals (1 , migrated. size())
552+ filterCheckNull(migrated[0 ])
553+
554+ // there should be a message about the condition
555+ def messages = getMigrationMessages(migrated[0 ])
556+ assertTrue (messages. any { msg ->
557+ msg. text. toLowerCase(). contains(' condition' )
558+ })
559+ assertTrue (messages. any { msg ->
560+ msg. text. toLowerCase(). contains(' removed because no matches' )
561+ })
562+ }
563+
564+ @Test
565+ void testTypeFilter2PropertyPresent () {
566+ def toMigrate = this . class. getResource(' /testcases/type-filter-props-mapped/B-to-C.halex' )
567+ def cellId = ' B2C2a' // Rename
568+
569+ def matching = this . class. getResource(' /testcases/type-filter-props-mapped/A-to-B.halex' )
570+
571+ def migrated = merge(cellId, toMigrate, matching)
572+
573+ // do checks
574+
575+ // filter
576+ assertEquals (1 , migrated. size())
577+ typeFilterCheck(migrated[0 ], " ab = 'test'" )
510578
511579 // there should be a message about the condition
512580 def messages = getMigrationMessages(migrated[0 ])
@@ -526,9 +594,34 @@ class DefaultMergeCellMigratorTest extends AbstractMergeCellMigratorTest {
526594
527595 // do checks
528596
597+ // filter is now dropped (because bc is not mapped for B3)
598+ assertEquals (1 , migrated. size())
599+ filterCheckNull(migrated[0 ])
600+
601+ // there should be a message about the condition
602+ def messages = getMigrationMessages(migrated[0 ])
603+ assertTrue (messages. any { msg ->
604+ msg. text. toLowerCase(). contains(' condition' )
605+ })
606+ assertTrue (messages. any { msg ->
607+ msg. text. toLowerCase(). contains(' removed because no matches' )
608+ })
609+ }
610+
611+ @Test
612+ void testTypeFilter3Present () {
613+ def toMigrate = this . class. getResource(' /testcases/type-filter-props-mapped/B-to-C.halex' )
614+ def cellId = ' B3-C3' // Merge
615+
616+ def matching = this . class. getResource(' /testcases/type-filter-props-mapped/A-to-B.halex' )
617+
618+ def migrated = merge(cellId, toMigrate, matching)
619+
620+ // do checks
621+
529622 // filter
530623 assertEquals (1 , migrated. size())
531- filterCheck(migrated[0 ], " bc = 'test'" )
624+ filterCheck(migrated[0 ], " ac = 'test'" )
532625
533626 // there should be a message about the condition
534627 def messages = getMigrationMessages(migrated[0 ])
@@ -572,6 +665,46 @@ class DefaultMergeCellMigratorTest extends AbstractMergeCellMigratorTest {
572665
573666 // do checks
574667
668+ // filter
669+ assertEquals (1 , migrated. size())
670+ JaxbAlignmentIO . printCell(migrated[0 ], System . out)
671+ // expect filters to be present on A5 source
672+ assertNotNull (migrated[0 ]. source)
673+ assertEquals (2 , migrated[0 ]. source. size())
674+ Collection<? extends Entity > source = migrated[0 ]. source. values()
675+ ((Collection<Entity > ) source). each { e ->
676+ def filter = e. definition. filter
677+ if (e. definition. definition. name. localPart == ' A5' ) {
678+ // filter is now dropped (because ba and bb are not mapped for B5)
679+ assertNull (filter)
680+ }
681+ else {
682+ assertNull (filter)
683+ }
684+ }
685+
686+ // there should be a message about the conditions being dropped
687+ def messages = getMigrationMessages(migrated[0 ])
688+ assertTrue (messages. any { msg ->
689+ msg. text. toLowerCase(). contains(' condition' )
690+ })
691+ assertTrue (messages. any { msg ->
692+ msg. text. toLowerCase(). contains(' removed because no matches' )
693+ })
694+ }
695+
696+ @CompileStatic (TypeCheckingMode .SKIP )
697+ @Test
698+ void testTypeFilter5Present () {
699+ def toMigrate = this . class. getResource(' /testcases/type-filter-props-mapped/B-to-C.halex' )
700+ def cellId = ' Join' // Join
701+
702+ def matching = this . class. getResource(' /testcases/type-filter-props-mapped/A-to-B.halex' )
703+
704+ def migrated = merge(cellId, toMigrate, matching)
705+
706+ // do checks
707+
575708 // filter
576709 assertEquals (1 , migrated. size())
577710 JaxbAlignmentIO . printCell(migrated[0 ], System . out)
@@ -583,7 +716,8 @@ class DefaultMergeCellMigratorTest extends AbstractMergeCellMigratorTest {
583716 def filter = e. definition. filter
584717 if (e. definition. definition. name. localPart == ' A5' ) {
585718 assertNotNull (filter)
586- assertEquals (' ba = \' test\' AND NOT (bb = \' test\' )' , filter. filterTerm)
719+ assertEquals (' (aa = \' test\' AND NOT (ab = \' test\' ))' , filter. filterTerm)
720+ // assertEquals('aa = \'test\' and ab <> \'test\'', filter.filterTerm)
587721 }
588722 else {
589723 assertNull (filter)
@@ -608,6 +742,39 @@ class DefaultMergeCellMigratorTest extends AbstractMergeCellMigratorTest {
608742
609743 // do checks
610744
745+ // filter
746+ assertEquals (1 , migrated. size())
747+ JaxbAlignmentIO . printCell(migrated[0 ], System . out)
748+ // expect filters to be present on both sources
749+ assertNotNull (migrated[0 ]. source)
750+ assertEquals (2 , migrated[0 ]. source. size())
751+ Collection<? extends Entity > source = migrated[0 ]. source. values()
752+ ((Collection<Entity > ) source). each { e ->
753+ def filter = e. definition. filter
754+ assertNull (filter)
755+ }
756+
757+ // there should be a message about the conditions being dropped
758+ def messages = getMigrationMessages(migrated[0 ])
759+ assertTrue (messages. any { msg ->
760+ msg. text. toLowerCase(). contains(' condition' )
761+ })
762+ assertTrue (messages. any { msg ->
763+ msg. text. toLowerCase(). contains(' removed because no matches' )
764+ })
765+ }
766+
767+ @Test
768+ void testTypeFilter6Present () {
769+ def toMigrate = this . class. getResource(' /testcases/type-filter-props-mapped/B-to-C.halex' )
770+ def cellId = ' GJoin' // Groovy Join
771+
772+ def matching = this . class. getResource(' /testcases/type-filter-props-mapped/A-to-B.halex' )
773+
774+ def migrated = merge(cellId, toMigrate, matching)
775+
776+ // do checks
777+
611778 // filter
612779 assertEquals (1 , migrated. size())
613780 JaxbAlignmentIO . printCell(migrated[0 ], System . out)
0 commit comments